Lines Matching +full:lock +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0-only
21 #define DRIVER_NAME "timb-gpio"
36 spinlock_t lock; /* mutual exclusion */ member
43 unsigned offset, bool enabled) in timbgpio_update_bit() argument
48 spin_lock(&tgpio->lock); in timbgpio_update_bit()
49 reg = ioread32(tgpio->membase + offset); in timbgpio_update_bit()
56 iowrite32(reg, tgpio->membase + offset); in timbgpio_update_bit()
57 spin_unlock(&tgpio->lock); in timbgpio_update_bit()
72 value = ioread32(tgpio->membase + TGPIOVAL); in timbgpio_gpio_get()
88 static int timbgpio_to_irq(struct gpio_chip *gpio, unsigned offset) in timbgpio_to_irq() argument
92 if (tgpio->irq_base <= 0) in timbgpio_to_irq()
93 return -EINVAL; in timbgpio_to_irq()
95 return tgpio->irq_base + offset; in timbgpio_to_irq()
104 int offset = d->irq - tgpio->irq_base; in timbgpio_irq_disable() local
107 spin_lock_irqsave(&tgpio->lock, flags); in timbgpio_irq_disable()
108 tgpio->last_ier &= ~(1UL << offset); in timbgpio_irq_disable()
109 iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER); in timbgpio_irq_disable()
110 spin_unlock_irqrestore(&tgpio->lock, flags); in timbgpio_irq_disable()
116 int offset = d->irq - tgpio->irq_base; in timbgpio_irq_enable() local
119 spin_lock_irqsave(&tgpio->lock, flags); in timbgpio_irq_enable()
120 tgpio->last_ier |= 1UL << offset; in timbgpio_irq_enable()
121 iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER); in timbgpio_irq_enable()
122 spin_unlock_irqrestore(&tgpio->lock, flags); in timbgpio_irq_enable()
128 int offset = d->irq - tgpio->irq_base; in timbgpio_irq_type() local
134 if (offset < 0 || offset > tgpio->gpio.ngpio) in timbgpio_irq_type()
135 return -EINVAL; in timbgpio_irq_type()
137 ver = ioread32(tgpio->membase + TGPIO_VER); in timbgpio_irq_type()
139 spin_lock_irqsave(&tgpio->lock, flags); in timbgpio_irq_type()
141 lvr = ioread32(tgpio->membase + TGPIO_LVR); in timbgpio_irq_type()
142 flr = ioread32(tgpio->membase + TGPIO_FLR); in timbgpio_irq_type()
144 bflr = ioread32(tgpio->membase + TGPIO_BFLR); in timbgpio_irq_type()
147 bflr &= ~(1 << offset); in timbgpio_irq_type()
148 flr &= ~(1 << offset); in timbgpio_irq_type()
150 lvr |= 1 << offset; in timbgpio_irq_type()
152 lvr &= ~(1 << offset); in timbgpio_irq_type()
157 ret = -EINVAL; in timbgpio_irq_type()
160 flr |= 1 << offset; in timbgpio_irq_type()
161 bflr |= 1 << offset; in timbgpio_irq_type()
164 bflr &= ~(1 << offset); in timbgpio_irq_type()
165 flr |= 1 << offset; in timbgpio_irq_type()
167 lvr &= ~(1 << offset); in timbgpio_irq_type()
169 lvr |= 1 << offset; in timbgpio_irq_type()
172 iowrite32(lvr, tgpio->membase + TGPIO_LVR); in timbgpio_irq_type()
173 iowrite32(flr, tgpio->membase + TGPIO_FLR); in timbgpio_irq_type()
175 iowrite32(bflr, tgpio->membase + TGPIO_BFLR); in timbgpio_irq_type()
177 iowrite32(1 << offset, tgpio->membase + TGPIO_ICR); in timbgpio_irq_type()
180 spin_unlock_irqrestore(&tgpio->lock, flags); in timbgpio_irq_type()
189 int offset; in timbgpio_irq() local
191 data->chip->irq_ack(data); in timbgpio_irq()
192 ipr = ioread32(tgpio->membase + TGPIO_IPR); in timbgpio_irq()
193 iowrite32(ipr, tgpio->membase + TGPIO_ICR); in timbgpio_irq()
199 iowrite32(0, tgpio->membase + TGPIO_IER); in timbgpio_irq()
201 for_each_set_bit(offset, &ipr, tgpio->gpio.ngpio) in timbgpio_irq()
202 generic_handle_irq(timbgpio_to_irq(&tgpio->gpio, offset)); in timbgpio_irq()
204 iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER); in timbgpio_irq()
217 struct device *dev = &pdev->dev; in timbgpio_probe()
220 struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev); in timbgpio_probe()
223 if (!pdata || pdata->nr_pins > 32) { in timbgpio_probe()
225 return -EINVAL; in timbgpio_probe()
230 return -EINVAL; in timbgpio_probe()
232 tgpio->irq_base = pdata->irq_base; in timbgpio_probe()
234 spin_lock_init(&tgpio->lock); in timbgpio_probe()
236 tgpio->membase = devm_platform_ioremap_resource(pdev, 0); in timbgpio_probe()
237 if (IS_ERR(tgpio->membase)) in timbgpio_probe()
238 return PTR_ERR(tgpio->membase); in timbgpio_probe()
240 gc = &tgpio->gpio; in timbgpio_probe()
242 gc->label = dev_name(&pdev->dev); in timbgpio_probe()
243 gc->owner = THIS_MODULE; in timbgpio_probe()
244 gc->parent = &pdev->dev; in timbgpio_probe()
245 gc->direction_input = timbgpio_gpio_direction_input; in timbgpio_probe()
246 gc->get = timbgpio_gpio_get; in timbgpio_probe()
247 gc->direction_output = timbgpio_gpio_direction_output; in timbgpio_probe()
248 gc->set = timbgpio_gpio_set; in timbgpio_probe()
249 gc->to_irq = (irq >= 0 && tgpio->irq_base > 0) ? timbgpio_to_irq : NULL; in timbgpio_probe()
250 gc->dbg_show = NULL; in timbgpio_probe()
251 gc->base = pdata->gpio_base; in timbgpio_probe()
252 gc->ngpio = pdata->nr_pins; in timbgpio_probe()
253 gc->can_sleep = false; in timbgpio_probe()
255 err = devm_gpiochip_add_data(&pdev->dev, gc, tgpio); in timbgpio_probe()
262 iowrite32(0x0, tgpio->membase + TGPIO_IER); in timbgpio_probe()
264 if (irq < 0 || tgpio->irq_base <= 0) in timbgpio_probe()
267 for (i = 0; i < pdata->nr_pins; i++) { in timbgpio_probe()
268 irq_set_chip_and_handler(tgpio->irq_base + i, in timbgpio_probe()
270 irq_set_chip_data(tgpio->irq_base + i, tgpio); in timbgpio_probe()
271 irq_clear_status_flags(tgpio->irq_base + i, IRQ_NOREQUEST | IRQ_NOPROBE); in timbgpio_probe()
287 /*--------------------------------------------------------------------------*/