66// Nintendo Wii (Hollywood) GPIO driver
77
88#include <linux/gpio/driver.h>
9+ #include <linux/gpio/generic.h>
910#include <linux/io.h>
1011#include <linux/kernel.h>
1112#include <linux/module.h>
4849#define HW_GPIO_OWNER 0x3c
4950
5051struct hlwd_gpio {
51- struct gpio_chip gpioc ;
52+ struct gpio_generic_chip gpioc ;
5253 struct device * dev ;
5354 void __iomem * regs ;
5455 int irq ;
@@ -61,45 +62,44 @@ static void hlwd_gpio_irqhandler(struct irq_desc *desc)
6162 struct hlwd_gpio * hlwd =
6263 gpiochip_get_data (irq_desc_get_handler_data (desc ));
6364 struct irq_chip * chip = irq_desc_get_chip (desc );
64- unsigned long flags ;
6565 unsigned long pending ;
6666 int hwirq ;
6767 u32 emulated_pending ;
6868
69- raw_spin_lock_irqsave ( & hlwd -> gpioc . bgpio_lock , flags );
70- pending = ioread32be (hlwd -> regs + HW_GPIOB_INTFLAG );
71- pending &= ioread32be (hlwd -> regs + HW_GPIOB_INTMASK );
69+ scoped_guard ( gpio_generic_lock_irqsave , & hlwd -> gpioc ) {
70+ pending = ioread32be (hlwd -> regs + HW_GPIOB_INTFLAG );
71+ pending &= ioread32be (hlwd -> regs + HW_GPIOB_INTMASK );
7272
73- /* Treat interrupts due to edge trigger emulation separately */
74- emulated_pending = hlwd -> edge_emulation & pending ;
75- pending &= ~emulated_pending ;
76- if (emulated_pending ) {
77- u32 level , rising , falling ;
73+ /* Treat interrupts due to edge trigger emulation separately */
74+ emulated_pending = hlwd -> edge_emulation & pending ;
75+ pending &= ~emulated_pending ;
76+ if (emulated_pending ) {
77+ u32 level , rising , falling ;
7878
79- level = ioread32be (hlwd -> regs + HW_GPIOB_INTLVL );
80- rising = level & emulated_pending ;
81- falling = ~level & emulated_pending ;
79+ level = ioread32be (hlwd -> regs + HW_GPIOB_INTLVL );
80+ rising = level & emulated_pending ;
81+ falling = ~level & emulated_pending ;
8282
83- /* Invert the levels */
84- iowrite32be (level ^ emulated_pending ,
85- hlwd -> regs + HW_GPIOB_INTLVL );
83+ /* Invert the levels */
84+ iowrite32be (level ^ emulated_pending ,
85+ hlwd -> regs + HW_GPIOB_INTLVL );
8686
87- /* Ack all emulated-edge interrupts */
88- iowrite32be (emulated_pending , hlwd -> regs + HW_GPIOB_INTFLAG );
87+ /* Ack all emulated-edge interrupts */
88+ iowrite32be (emulated_pending , hlwd -> regs + HW_GPIOB_INTFLAG );
8989
90- /* Signal interrupts only on the correct edge */
91- rising &= hlwd -> rising_edge ;
92- falling &= hlwd -> falling_edge ;
90+ /* Signal interrupts only on the correct edge */
91+ rising &= hlwd -> rising_edge ;
92+ falling &= hlwd -> falling_edge ;
9393
94- /* Mark emulated interrupts as pending */
95- pending |= rising | falling ;
94+ /* Mark emulated interrupts as pending */
95+ pending |= rising | falling ;
96+ }
9697 }
97- raw_spin_unlock_irqrestore (& hlwd -> gpioc .bgpio_lock , flags );
9898
9999 chained_irq_enter (chip , desc );
100100
101101 for_each_set_bit (hwirq , & pending , 32 )
102- generic_handle_domain_irq (hlwd -> gpioc .irq .domain , hwirq );
102+ generic_handle_domain_irq (hlwd -> gpioc .gc . irq .domain , hwirq );
103103
104104 chained_irq_exit (chip , desc );
105105}
@@ -116,30 +116,29 @@ static void hlwd_gpio_irq_mask(struct irq_data *data)
116116{
117117 struct hlwd_gpio * hlwd =
118118 gpiochip_get_data (irq_data_get_irq_chip_data (data ));
119- unsigned long flags ;
120119 u32 mask ;
121120
122- raw_spin_lock_irqsave ( & hlwd -> gpioc . bgpio_lock , flags );
123- mask = ioread32be (hlwd -> regs + HW_GPIOB_INTMASK );
124- mask &= ~BIT (data -> hwirq );
125- iowrite32be (mask , hlwd -> regs + HW_GPIOB_INTMASK );
126- raw_spin_unlock_irqrestore ( & hlwd -> gpioc . bgpio_lock , flags );
127- gpiochip_disable_irq (& hlwd -> gpioc , irqd_to_hwirq (data ));
121+ scoped_guard ( gpio_generic_lock_irqsave , & hlwd -> gpioc ) {
122+ mask = ioread32be (hlwd -> regs + HW_GPIOB_INTMASK );
123+ mask &= ~BIT (data -> hwirq );
124+ iowrite32be (mask , hlwd -> regs + HW_GPIOB_INTMASK );
125+ }
126+ gpiochip_disable_irq (& hlwd -> gpioc . gc , irqd_to_hwirq (data ));
128127}
129128
130129static void hlwd_gpio_irq_unmask (struct irq_data * data )
131130{
132131 struct hlwd_gpio * hlwd =
133132 gpiochip_get_data (irq_data_get_irq_chip_data (data ));
134- unsigned long flags ;
135133 u32 mask ;
136134
137- gpiochip_enable_irq (& hlwd -> gpioc , irqd_to_hwirq (data ));
138- raw_spin_lock_irqsave (& hlwd -> gpioc .bgpio_lock , flags );
135+ gpiochip_enable_irq (& hlwd -> gpioc .gc , irqd_to_hwirq (data ));
136+
137+ guard (gpio_generic_lock_irqsave )(& hlwd -> gpioc );
138+
139139 mask = ioread32be (hlwd -> regs + HW_GPIOB_INTMASK );
140140 mask |= BIT (data -> hwirq );
141141 iowrite32be (mask , hlwd -> regs + HW_GPIOB_INTMASK );
142- raw_spin_unlock_irqrestore (& hlwd -> gpioc .bgpio_lock , flags );
143142}
144143
145144static void hlwd_gpio_irq_enable (struct irq_data * data )
@@ -173,10 +172,9 @@ static int hlwd_gpio_irq_set_type(struct irq_data *data, unsigned int flow_type)
173172{
174173 struct hlwd_gpio * hlwd =
175174 gpiochip_get_data (irq_data_get_irq_chip_data (data ));
176- unsigned long flags ;
177175 u32 level ;
178176
179- raw_spin_lock_irqsave ( & hlwd -> gpioc . bgpio_lock , flags );
177+ guard ( gpio_generic_lock_irqsave )( & hlwd -> gpioc );
180178
181179 hlwd -> edge_emulation &= ~BIT (data -> hwirq );
182180
@@ -197,11 +195,9 @@ static int hlwd_gpio_irq_set_type(struct irq_data *data, unsigned int flow_type)
197195 hlwd_gpio_irq_setup_emulation (hlwd , data -> hwirq , flow_type );
198196 break ;
199197 default :
200- raw_spin_unlock_irqrestore (& hlwd -> gpioc .bgpio_lock , flags );
201198 return - EINVAL ;
202199 }
203200
204- raw_spin_unlock_irqrestore (& hlwd -> gpioc .bgpio_lock , flags );
205201 return 0 ;
206202}
207203
@@ -225,6 +221,7 @@ static const struct irq_chip hlwd_gpio_irq_chip = {
225221
226222static int hlwd_gpio_probe (struct platform_device * pdev )
227223{
224+ struct gpio_generic_chip_config config ;
228225 struct hlwd_gpio * hlwd ;
229226 u32 ngpios ;
230227 int res ;
@@ -244,25 +241,31 @@ static int hlwd_gpio_probe(struct platform_device *pdev)
244241 * systems where the AHBPROT memory firewall hasn't been configured to
245242 * permit PPC access to HW_GPIO_*.
246243 *
247- * Note that this has to happen before bgpio_init reads the
248- * HW_GPIOB_OUT and HW_GPIOB_DIR, because otherwise it reads the wrong
249- * values.
244+ * Note that this has to happen before gpio_generic_chip_init() reads
245+ * the HW_GPIOB_OUT and HW_GPIOB_DIR, because otherwise it reads the
246+ * wrong values.
250247 */
251248 iowrite32be (0xffffffff , hlwd -> regs + HW_GPIO_OWNER );
252249
253- res = bgpio_init (& hlwd -> gpioc , & pdev -> dev , 4 ,
254- hlwd -> regs + HW_GPIOB_IN , hlwd -> regs + HW_GPIOB_OUT ,
255- NULL , hlwd -> regs + HW_GPIOB_DIR , NULL ,
256- BGPIOF_BIG_ENDIAN_BYTE_ORDER );
250+ config = (struct gpio_generic_chip_config ) {
251+ .dev = & pdev -> dev ,
252+ .sz = 4 ,
253+ .dat = hlwd -> regs + HW_GPIOB_IN ,
254+ .set = hlwd -> regs + HW_GPIOB_OUT ,
255+ .dirout = hlwd -> regs + HW_GPIOB_DIR ,
256+ .flags = BGPIOF_BIG_ENDIAN_BYTE_ORDER ,
257+ };
258+
259+ res = gpio_generic_chip_init (& hlwd -> gpioc , & config );
257260 if (res < 0 ) {
258- dev_warn (& pdev -> dev , "bgpio_init failed: %d\n" , res );
261+ dev_warn (& pdev -> dev , "failed to initialize generic GPIO chip : %d\n" , res );
259262 return res ;
260263 }
261264
262265 res = of_property_read_u32 (pdev -> dev .of_node , "ngpios" , & ngpios );
263266 if (res )
264267 ngpios = 32 ;
265- hlwd -> gpioc .ngpio = ngpios ;
268+ hlwd -> gpioc .gc . ngpio = ngpios ;
266269
267270 /* Mask and ack all interrupts */
268271 iowrite32be (0 , hlwd -> regs + HW_GPIOB_INTMASK );
@@ -282,7 +285,7 @@ static int hlwd_gpio_probe(struct platform_device *pdev)
282285 return hlwd -> irq ;
283286 }
284287
285- girq = & hlwd -> gpioc .irq ;
288+ girq = & hlwd -> gpioc .gc . irq ;
286289 gpio_irq_chip_set_chip (girq , & hlwd_gpio_irq_chip );
287290 girq -> parent_handler = hlwd_gpio_irqhandler ;
288291 girq -> num_parents = 1 ;
@@ -296,7 +299,7 @@ static int hlwd_gpio_probe(struct platform_device *pdev)
296299 girq -> handler = handle_level_irq ;
297300 }
298301
299- return devm_gpiochip_add_data (& pdev -> dev , & hlwd -> gpioc , hlwd );
302+ return devm_gpiochip_add_data (& pdev -> dev , & hlwd -> gpioc . gc , hlwd );
300303}
301304
302305static const struct of_device_id hlwd_gpio_match [] = {
0 commit comments