1
2
3
4
5
6
7
8
9#include <linux/init.h>
10#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/platform_device.h>
13#include <linux/mutex.h>
14#include <linux/gpio/driver.h>
15#include <linux/of.h>
16#include <linux/of_gpio.h>
17#include <linux/io.h>
18#include <linux/slab.h>
19
20#include <lantiq_soc.h>
21
22
23
24
25
26
27
28#define LTQ_EBU_BUSCON 0x1e7ff
29#define LTQ_EBU_WP 0x80000000
30
31struct ltq_mm {
32 struct of_mm_gpio_chip mmchip;
33 u16 shadow;
34};
35
36
37
38
39
40
41
42
43static void ltq_mm_apply(struct ltq_mm *chip)
44{
45 unsigned long flags;
46
47 spin_lock_irqsave(&ebu_lock, flags);
48 ltq_ebu_w32(LTQ_EBU_BUSCON, LTQ_EBU_BUSCON1);
49 __raw_writew(chip->shadow, chip->mmchip.regs);
50 ltq_ebu_w32(LTQ_EBU_BUSCON | LTQ_EBU_WP, LTQ_EBU_BUSCON1);
51 spin_unlock_irqrestore(&ebu_lock, flags);
52}
53
54
55
56
57
58
59
60
61
62static void ltq_mm_set(struct gpio_chip *gc, unsigned offset, int value)
63{
64 struct ltq_mm *chip = gpiochip_get_data(gc);
65
66 if (value)
67 chip->shadow |= (1 << offset);
68 else
69 chip->shadow &= ~(1 << offset);
70 ltq_mm_apply(chip);
71}
72
73
74
75
76
77
78
79
80
81static int ltq_mm_dir_out(struct gpio_chip *gc, unsigned offset, int value)
82{
83 ltq_mm_set(gc, offset, value);
84
85 return 0;
86}
87
88
89
90
91
92static void ltq_mm_save_regs(struct of_mm_gpio_chip *mm_gc)
93{
94 struct ltq_mm *chip =
95 container_of(mm_gc, struct ltq_mm, mmchip);
96
97
98 ltq_ebu_w32(CPHYSADDR(chip->mmchip.regs) | 0x1, LTQ_EBU_ADDRSEL1);
99
100 ltq_mm_apply(chip);
101}
102
103static int ltq_mm_probe(struct platform_device *pdev)
104{
105 struct ltq_mm *chip;
106 u32 shadow;
107
108 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
109 if (!chip)
110 return -ENOMEM;
111
112 platform_set_drvdata(pdev, chip);
113
114 chip->mmchip.gc.ngpio = 16;
115 chip->mmchip.gc.direction_output = ltq_mm_dir_out;
116 chip->mmchip.gc.set = ltq_mm_set;
117 chip->mmchip.save_regs = ltq_mm_save_regs;
118
119
120 if (!of_property_read_u32(pdev->dev.of_node, "lantiq,shadow", &shadow))
121 chip->shadow = shadow;
122
123 return of_mm_gpiochip_add_data(pdev->dev.of_node, &chip->mmchip, chip);
124}
125
126static int ltq_mm_remove(struct platform_device *pdev)
127{
128 struct ltq_mm *chip = platform_get_drvdata(pdev);
129
130 of_mm_gpiochip_remove(&chip->mmchip);
131
132 return 0;
133}
134
135static const struct of_device_id ltq_mm_match[] = {
136 { .compatible = "lantiq,gpio-mm" },
137 {},
138};
139MODULE_DEVICE_TABLE(of, ltq_mm_match);
140
141static struct platform_driver ltq_mm_driver = {
142 .probe = ltq_mm_probe,
143 .remove = ltq_mm_remove,
144 .driver = {
145 .name = "gpio-mm-ltq",
146 .of_match_table = ltq_mm_match,
147 },
148};
149
150static int __init ltq_mm_init(void)
151{
152 return platform_driver_register(<q_mm_driver);
153}
154
155subsys_initcall(ltq_mm_init);
156
157static void __exit ltq_mm_exit(void)
158{
159 platform_driver_unregister(<q_mm_driver);
160}
161module_exit(ltq_mm_exit);
162