Lines Matching +full:lock +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2015-2018 Pengutronix, Uwe Kleine-König <kernel@pengutronix.de>
13 struct mutex lock; member
29 struct gpio_siox_ddata *ddata = dev_get_drvdata(&sdevice->dev); in gpio_siox_set_data()
31 mutex_lock(&ddata->lock); in gpio_siox_set_data()
32 buf[0] = ddata->setdata[0]; in gpio_siox_set_data()
33 mutex_unlock(&ddata->lock); in gpio_siox_set_data()
40 struct gpio_siox_ddata *ddata = dev_get_drvdata(&sdevice->dev); in gpio_siox_get_data()
41 size_t offset; in gpio_siox_get_data() local
44 mutex_lock(&ddata->lock); in gpio_siox_get_data()
46 raw_spin_lock_irq(&ddata->irqlock); in gpio_siox_get_data()
48 for (offset = 0; offset < 12; ++offset) { in gpio_siox_get_data()
49 unsigned int bitpos = 11 - offset; in gpio_siox_get_data()
52 ddata->getdata[bitpos / 8] & (1 << (bitpos % 8)); in gpio_siox_get_data()
53 u32 irq_type = ddata->irq_type[offset]; in gpio_siox_get_data()
58 ddata->irq_status |= 1 << offset; in gpio_siox_get_data()
62 ddata->irq_status |= 1 << offset; in gpio_siox_get_data()
66 trigger = ddata->irq_status & ddata->irq_enable; in gpio_siox_get_data()
68 raw_spin_unlock_irq(&ddata->irqlock); in gpio_siox_get_data()
70 ddata->getdata[0] = buf[0]; in gpio_siox_get_data()
71 ddata->getdata[1] = buf[1]; in gpio_siox_get_data()
72 ddata->getdata[2] = buf[2]; in gpio_siox_get_data()
74 mutex_unlock(&ddata->lock); in gpio_siox_get_data()
76 for (offset = 0; offset < 12; ++offset) { in gpio_siox_get_data()
77 if (trigger & (1 << offset)) { in gpio_siox_get_data()
78 struct irq_domain *irqdomain = ddata->gchip.irq.domain; in gpio_siox_get_data()
79 unsigned int irq = irq_find_mapping(irqdomain, offset); in gpio_siox_get_data()
86 raw_spin_lock_irq(&ddata->irqlock); in gpio_siox_get_data()
87 ddata->irq_status &= ~(1 << offset); in gpio_siox_get_data()
88 raw_spin_unlock_irq(&ddata->irqlock); in gpio_siox_get_data()
102 raw_spin_lock(&ddata->irqlock); in gpio_siox_irq_ack()
103 ddata->irq_status &= ~(1 << d->hwirq); in gpio_siox_irq_ack()
104 raw_spin_unlock(&ddata->irqlock); in gpio_siox_irq_ack()
112 raw_spin_lock(&ddata->irqlock); in gpio_siox_irq_mask()
113 ddata->irq_enable &= ~(1 << d->hwirq); in gpio_siox_irq_mask()
114 raw_spin_unlock(&ddata->irqlock); in gpio_siox_irq_mask()
124 raw_spin_lock(&ddata->irqlock); in gpio_siox_irq_unmask()
125 ddata->irq_enable |= 1 << d->hwirq; in gpio_siox_irq_unmask()
126 raw_spin_unlock(&ddata->irqlock); in gpio_siox_irq_unmask()
134 raw_spin_lock(&ddata->irqlock); in gpio_siox_irq_set_type()
135 ddata->irq_type[d->hwirq] = type; in gpio_siox_irq_set_type()
136 raw_spin_unlock(&ddata->irqlock); in gpio_siox_irq_set_type()
141 static int gpio_siox_get(struct gpio_chip *chip, unsigned int offset) in gpio_siox_get() argument
146 mutex_lock(&ddata->lock); in gpio_siox_get()
148 if (offset >= 12) { in gpio_siox_get()
149 unsigned int bitpos = 19 - offset; in gpio_siox_get()
151 ret = ddata->setdata[0] & (1 << bitpos); in gpio_siox_get()
153 unsigned int bitpos = 11 - offset; in gpio_siox_get()
155 ret = ddata->getdata[bitpos / 8] & (1 << (bitpos % 8)); in gpio_siox_get()
158 mutex_unlock(&ddata->lock); in gpio_siox_get()
164 unsigned int offset, int value) in gpio_siox_set() argument
167 u8 mask = 1 << (19 - offset); in gpio_siox_set()
169 mutex_lock(&ddata->lock); in gpio_siox_set()
172 ddata->setdata[0] |= mask; in gpio_siox_set()
174 ddata->setdata[0] &= ~mask; in gpio_siox_set()
176 mutex_unlock(&ddata->lock); in gpio_siox_set()
180 unsigned int offset) in gpio_siox_direction_input() argument
182 if (offset >= 12) in gpio_siox_direction_input()
183 return -EINVAL; in gpio_siox_direction_input()
189 unsigned int offset, int value) in gpio_siox_direction_output() argument
191 if (offset < 12) in gpio_siox_direction_output()
192 return -EINVAL; in gpio_siox_direction_output()
194 gpio_siox_set(chip, offset, value); in gpio_siox_direction_output()
198 static int gpio_siox_get_direction(struct gpio_chip *chip, unsigned int offset) in gpio_siox_get_direction() argument
200 if (offset < 12) in gpio_siox_get_direction()
207 .name = "siox-gpio",
220 struct device *dev = &sdevice->dev; in gpio_siox_probe()
226 return -ENOMEM; in gpio_siox_probe()
230 mutex_init(&ddata->lock); in gpio_siox_probe()
231 raw_spin_lock_init(&ddata->irqlock); in gpio_siox_probe()
233 gc = &ddata->gchip; in gpio_siox_probe()
234 gc->base = -1; in gpio_siox_probe()
235 gc->can_sleep = 1; in gpio_siox_probe()
236 gc->parent = dev; in gpio_siox_probe()
237 gc->owner = THIS_MODULE; in gpio_siox_probe()
238 gc->get = gpio_siox_get; in gpio_siox_probe()
239 gc->set = gpio_siox_set; in gpio_siox_probe()
240 gc->direction_input = gpio_siox_direction_input; in gpio_siox_probe()
241 gc->direction_output = gpio_siox_direction_output; in gpio_siox_probe()
242 gc->get_direction = gpio_siox_get_direction; in gpio_siox_probe()
243 gc->ngpio = 20; in gpio_siox_probe()
245 girq = &gc->irq; in gpio_siox_probe()
247 girq->default_type = IRQ_TYPE_NONE; in gpio_siox_probe()
248 girq->handler = handle_level_irq; in gpio_siox_probe()
249 girq->threaded = true; in gpio_siox_probe()
263 .name = "gpio-siox",
268 MODULE_AUTHOR("Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>");