9 #include <linux/module.h>
12 #include <linux/slab.h>
26 #define CACHE_NR_REGS 4
27 #define CACHE_NR_BANKS 3
48 static int tc3589x_gpio_get(
struct gpio_chip *
chip,
unsigned offset)
53 u8 mask = 1 << (offset % 8);
63 static void tc3589x_gpio_set(
struct gpio_chip *chip,
unsigned offset,
int val)
65 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
66 struct tc3589x *tc3589x = tc3589x_gpio->
tc3589x;
68 unsigned pos = offset % 8;
74 static int tc3589x_gpio_direction_output(
struct gpio_chip *chip,
75 unsigned offset,
int val)
77 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
78 struct tc3589x *tc3589x = tc3589x_gpio->
tc3589x;
80 unsigned pos = offset % 8;
82 tc3589x_gpio_set(chip, offset, val);
87 static int tc3589x_gpio_direction_input(
struct gpio_chip *chip,
90 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
91 struct tc3589x *tc3589x = tc3589x_gpio->
tc3589x;
93 unsigned pos = offset % 8;
106 static int tc3589x_gpio_irq_get_virq(
struct tc3589x_gpio *tc3589x_gpio,
115 static int tc3589x_gpio_to_irq(
struct gpio_chip *chip,
unsigned offset)
117 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
119 return tc3589x_gpio_irq_get_virq(tc3589x_gpio, offset);
122 static struct gpio_chip template_chip = {
125 .direction_input = tc3589x_gpio_direction_input,
126 .get = tc3589x_gpio_get,
127 .direction_output = tc3589x_gpio_direction_output,
128 .set = tc3589x_gpio_set,
129 .to_irq = tc3589x_gpio_to_irq,
133 static int tc3589x_gpio_irq_set_type(
struct irq_data *
d,
unsigned int type)
135 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
136 int offset = d->
hwirq;
137 int regoffset = offset / 8;
138 int mask = 1 << (offset % 8);
150 tc3589x_gpio->
regs[
REG_IS][regoffset] &= ~mask;
160 static void tc3589x_gpio_irq_lock(
struct irq_data *d)
162 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
167 static void tc3589x_gpio_irq_sync_unlock(
struct irq_data *d)
169 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
170 struct tc3589x *tc3589x = tc3589x_gpio->
tc3589x;
195 static void tc3589x_gpio_irq_mask(
struct irq_data *d)
197 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
198 int offset = d->
hwirq;
199 int regoffset = offset / 8;
200 int mask = 1 << (offset % 8);
202 tc3589x_gpio->
regs[
REG_IE][regoffset] &= ~mask;
205 static void tc3589x_gpio_irq_unmask(
struct irq_data *d)
207 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
208 int offset = d->
hwirq;
209 int regoffset = offset / 8;
210 int mask = 1 << (offset % 8);
215 static struct irq_chip tc3589x_gpio_irq_chip = {
216 .name =
"tc3589x-gpio",
217 .irq_bus_lock = tc3589x_gpio_irq_lock,
218 .irq_bus_sync_unlock = tc3589x_gpio_irq_sync_unlock,
219 .irq_mask = tc3589x_gpio_irq_mask,
220 .irq_unmask = tc3589x_gpio_irq_unmask,
221 .irq_set_type = tc3589x_gpio_irq_set_type,
226 struct tc3589x_gpio *tc3589x_gpio =
dev;
227 struct tc3589x *tc3589x = tc3589x_gpio->
tc3589x;
238 unsigned int stat = status[
i];
245 int virq = tc3589x_gpio_irq_get_virq(tc3589x_gpio, line);
257 static int tc3589x_gpio_irq_map(
struct irq_domain *d,
unsigned int virq,
260 struct tc3589x *tc3589x_gpio = d->
host_data;
263 irq_set_chip_and_handler(virq, &tc3589x_gpio_irq_chip,
265 irq_set_nested_thread(virq, 1);
269 irq_set_noprobe(virq);
275 static void tc3589x_gpio_irq_unmap(
struct irq_domain *d,
unsigned int virq)
280 irq_set_chip_and_handler(virq,
NULL,
NULL);
285 .map = tc3589x_gpio_irq_map,
286 .unmap = tc3589x_gpio_irq_unmap,
290 static int tc3589x_gpio_irq_init(
struct tc3589x_gpio *tc3589x_gpio,
297 NULL, tc3589x_gpio->
chip.ngpio, base,
298 0, &tc3589x_irq_ops, tc3589x_gpio);
302 np, tc3589x_gpio->
chip.ngpio,
303 &tc3589x_irq_ops, tc3589x_gpio);
306 if (!tc3589x_gpio->
domain) {
307 dev_err(tc3589x_gpio->
dev,
"Failed to create irqdomain\n");
319 struct tc3589x_gpio *tc3589x_gpio;
323 pdata = tc3589x->
pdata->gpio;
325 if (!(pdata || np)) {
326 dev_err(&pdev->
dev,
"No platform data or Device Tree found\n");
334 tc3589x_gpio = kzalloc(
sizeof(
struct tc3589x_gpio),
GFP_KERNEL);
340 tc3589x_gpio->
dev = &pdev->
dev;
343 tc3589x_gpio->
chip = template_chip;
345 tc3589x_gpio->
chip.dev = &pdev->
dev;
348 #ifdef CONFIG_OF_GPIO
349 tc3589x_gpio->
chip.of_node = np;
361 ret = tc3589x_gpio_irq_init(tc3589x_gpio, np);
366 "tc3589x-gpio", tc3589x_gpio);
368 dev_err(&pdev->
dev,
"unable to get irq: %d\n", ret);
374 dev_err(&pdev->
dev,
"unable to add gpiochip: %d\n", ret);
378 if (pdata && pdata->
setup)
379 pdata->
setup(tc3589x, tc3589x_gpio->
chip.base);
381 platform_set_drvdata(pdev, tc3589x_gpio);
394 struct tc3589x_gpio *tc3589x_gpio = platform_get_drvdata(pdev);
395 struct tc3589x *tc3589x = tc3589x_gpio->
tc3589x;
400 if (pdata && pdata->
remove)
401 pdata->
remove(tc3589x, tc3589x_gpio->
chip.base);
406 "unable to remove gpiochip: %d\n", ret);
412 platform_set_drvdata(pdev,
NULL);
419 .driver.name =
"tc3589x-gpio",
421 .probe = tc3589x_gpio_probe,
425 static int __init tc3589x_gpio_init(
void)
431 static void __exit tc3589x_gpio_exit(
void)