1010
1111#include <linux/device.h>
1212#include <linux/gpio/driver.h>
13+ #include <linux/gpio/generic.h>
1314#include <linux/interrupt.h>
1415#include <linux/irq.h>
1516#include <linux/mod_devicetable.h>
2829#define AR71XX_GPIO_REG_INT_MASK 0x24
2930
3031struct ath79_gpio_ctrl {
31- struct gpio_chip gc ;
32+ struct gpio_generic_chip chip ;
3233 void __iomem * base ;
3334 raw_spinlock_t lock ;
3435 unsigned long both_edges ;
@@ -37,8 +38,9 @@ struct ath79_gpio_ctrl {
3738static struct ath79_gpio_ctrl * irq_data_to_ath79_gpio (struct irq_data * data )
3839{
3940 struct gpio_chip * gc = irq_data_get_irq_chip_data (data );
41+ struct gpio_generic_chip * gen_gc = to_gpio_generic_chip (gc );
4042
41- return container_of (gc , struct ath79_gpio_ctrl , gc );
43+ return container_of (gen_gc , struct ath79_gpio_ctrl , chip );
4244}
4345
4446static u32 ath79_gpio_read (struct ath79_gpio_ctrl * ctrl , unsigned reg )
@@ -72,7 +74,7 @@ static void ath79_gpio_irq_unmask(struct irq_data *data)
7274 u32 mask = BIT (irqd_to_hwirq (data ));
7375 unsigned long flags ;
7476
75- gpiochip_enable_irq (& ctrl -> gc , irqd_to_hwirq (data ));
77+ gpiochip_enable_irq (& ctrl -> chip . gc , irqd_to_hwirq (data ));
7678 raw_spin_lock_irqsave (& ctrl -> lock , flags );
7779 ath79_gpio_update_bits (ctrl , AR71XX_GPIO_REG_INT_MASK , mask , mask );
7880 raw_spin_unlock_irqrestore (& ctrl -> lock , flags );
@@ -87,7 +89,7 @@ static void ath79_gpio_irq_mask(struct irq_data *data)
8789 raw_spin_lock_irqsave (& ctrl -> lock , flags );
8890 ath79_gpio_update_bits (ctrl , AR71XX_GPIO_REG_INT_MASK , mask , 0 );
8991 raw_spin_unlock_irqrestore (& ctrl -> lock , flags );
90- gpiochip_disable_irq (& ctrl -> gc , irqd_to_hwirq (data ));
92+ gpiochip_disable_irq (& ctrl -> chip . gc , irqd_to_hwirq (data ));
9193}
9294
9395static void ath79_gpio_irq_enable (struct irq_data * data )
@@ -187,8 +189,9 @@ static void ath79_gpio_irq_handler(struct irq_desc *desc)
187189{
188190 struct gpio_chip * gc = irq_desc_get_handler_data (desc );
189191 struct irq_chip * irqchip = irq_desc_get_chip (desc );
192+ struct gpio_generic_chip * gen_gc = to_gpio_generic_chip (gc );
190193 struct ath79_gpio_ctrl * ctrl =
191- container_of (gc , struct ath79_gpio_ctrl , gc );
194+ container_of (gen_gc , struct ath79_gpio_ctrl , chip );
192195 unsigned long flags , pending ;
193196 u32 both_edges , state ;
194197 int irq ;
@@ -224,6 +227,7 @@ MODULE_DEVICE_TABLE(of, ath79_gpio_of_match);
224227
225228static int ath79_gpio_probe (struct platform_device * pdev )
226229{
230+ struct gpio_generic_chip_config config ;
227231 struct device * dev = & pdev -> dev ;
228232 struct ath79_gpio_ctrl * ctrl ;
229233 struct gpio_irq_chip * girq ;
@@ -253,21 +257,26 @@ static int ath79_gpio_probe(struct platform_device *pdev)
253257 return PTR_ERR (ctrl -> base );
254258
255259 raw_spin_lock_init (& ctrl -> lock );
256- err = bgpio_init (& ctrl -> gc , dev , 4 ,
257- ctrl -> base + AR71XX_GPIO_REG_IN ,
258- ctrl -> base + AR71XX_GPIO_REG_SET ,
259- ctrl -> base + AR71XX_GPIO_REG_CLEAR ,
260- oe_inverted ? NULL : ctrl -> base + AR71XX_GPIO_REG_OE ,
261- oe_inverted ? ctrl -> base + AR71XX_GPIO_REG_OE : NULL ,
262- 0 );
260+
261+ config = (struct gpio_generic_chip_config ) {
262+ .dev = dev ,
263+ .sz = 4 ,
264+ .dat = ctrl -> base + AR71XX_GPIO_REG_IN ,
265+ .set = ctrl -> base + AR71XX_GPIO_REG_SET ,
266+ .clr = ctrl -> base + AR71XX_GPIO_REG_CLEAR ,
267+ .dirout = oe_inverted ? NULL : ctrl -> base + AR71XX_GPIO_REG_OE ,
268+ .dirin = oe_inverted ? ctrl -> base + AR71XX_GPIO_REG_OE : NULL ,
269+ };
270+
271+ err = gpio_generic_chip_init (& ctrl -> chip , & config );
263272 if (err ) {
264- dev_err (dev , "bgpio_init failed\n" );
273+ dev_err (dev , "failed to initialize generic GPIO chip \n" );
265274 return err ;
266275 }
267276
268277 /* Optional interrupt setup */
269278 if (device_property_read_bool (dev , "interrupt-controller" )) {
270- girq = & ctrl -> gc .irq ;
279+ girq = & ctrl -> chip . gc .irq ;
271280 gpio_irq_chip_set_chip (girq , & ath79_gpio_irqchip );
272281 girq -> parent_handler = ath79_gpio_irq_handler ;
273282 girq -> num_parents = 1 ;
@@ -280,7 +289,7 @@ static int ath79_gpio_probe(struct platform_device *pdev)
280289 girq -> handler = handle_simple_irq ;
281290 }
282291
283- return devm_gpiochip_add_data (dev , & ctrl -> gc , ctrl );
292+ return devm_gpiochip_add_data (dev , & ctrl -> chip . gc , ctrl );
284293}
285294
286295static struct platform_driver ath79_gpio_driver = {
0 commit comments