66
77#include <linux/err.h>
88#include <linux/gpio/driver.h>
9+ #include <linux/gpio/generic.h>
910#include <linux/interrupt.h>
1011#include <linux/io.h>
1112#include <linux/module.h>
3031
3132struct mtk_gc {
3233 struct irq_chip irq_chip ;
33- struct gpio_chip chip ;
34+ struct gpio_generic_chip chip ;
3435 spinlock_t lock ;
3536 int bank ;
3637 u32 rising ;
@@ -59,27 +60,29 @@ struct mtk {
5960static inline struct mtk_gc *
6061to_mediatek_gpio (struct gpio_chip * chip )
6162{
62- return container_of (chip , struct mtk_gc , chip );
63+ struct gpio_generic_chip * gen_gc = to_gpio_generic_chip (chip );
64+
65+ return container_of (gen_gc , struct mtk_gc , chip );
6366}
6467
6568static inline void
6669mtk_gpio_w32 (struct mtk_gc * rg , u32 offset , u32 val )
6770{
68- struct gpio_chip * gc = & rg -> chip ;
71+ struct gpio_chip * gc = & rg -> chip . gc ;
6972 struct mtk * mtk = gpiochip_get_data (gc );
7073
7174 offset = (rg -> bank * GPIO_BANK_STRIDE ) + offset ;
72- gc -> write_reg ( mtk -> base + offset , val );
75+ gpio_generic_write_reg ( & rg -> chip , mtk -> base + offset , val );
7376}
7477
7578static inline u32
7679mtk_gpio_r32 (struct mtk_gc * rg , u32 offset )
7780{
78- struct gpio_chip * gc = & rg -> chip ;
81+ struct gpio_chip * gc = & rg -> chip . gc ;
7982 struct mtk * mtk = gpiochip_get_data (gc );
8083
8184 offset = (rg -> bank * GPIO_BANK_STRIDE ) + offset ;
82- return gc -> read_reg ( mtk -> base + offset );
85+ return gpio_generic_read_reg ( & rg -> chip , mtk -> base + offset );
8386}
8487
8588static irqreturn_t
@@ -220,6 +223,7 @@ static const struct irq_chip mt7621_irq_chip = {
220223static int
221224mediatek_gpio_bank_probe (struct device * dev , int bank )
222225{
226+ struct gpio_generic_chip_config config ;
223227 struct mtk * mtk = dev_get_drvdata (dev );
224228 struct mtk_gc * rg ;
225229 void __iomem * dat , * set , * ctrl , * diro ;
@@ -236,21 +240,30 @@ mediatek_gpio_bank_probe(struct device *dev, int bank)
236240 ctrl = mtk -> base + GPIO_REG_DCLR + (rg -> bank * GPIO_BANK_STRIDE );
237241 diro = mtk -> base + GPIO_REG_CTRL + (rg -> bank * GPIO_BANK_STRIDE );
238242
239- ret = bgpio_init (& rg -> chip , dev , 4 , dat , set , ctrl , diro , NULL ,
240- BGPIOF_NO_SET_ON_INPUT );
243+ config = (struct gpio_generic_chip_config ) {
244+ .dev = dev ,
245+ .sz = 4 ,
246+ .dat = dat ,
247+ .set = set ,
248+ .clr = ctrl ,
249+ .dirout = diro ,
250+ .flags = BGPIOF_NO_SET_ON_INPUT ,
251+ };
252+
253+ ret = gpio_generic_chip_init (& rg -> chip , & config );
241254 if (ret ) {
242- dev_err (dev , "bgpio_init() failed\n" );
255+ dev_err (dev , "failed to initialize generic GPIO chip \n" );
243256 return ret ;
244257 }
245258
246- rg -> chip .of_gpio_n_cells = 2 ;
247- rg -> chip .of_xlate = mediatek_gpio_xlate ;
248- rg -> chip .label = devm_kasprintf (dev , GFP_KERNEL , "%s-bank%d" ,
259+ rg -> chip .gc . of_gpio_n_cells = 2 ;
260+ rg -> chip .gc . of_xlate = mediatek_gpio_xlate ;
261+ rg -> chip .gc . label = devm_kasprintf (dev , GFP_KERNEL , "%s-bank%d" ,
249262 dev_name (dev ), bank );
250- if (!rg -> chip .label )
263+ if (!rg -> chip .gc . label )
251264 return - ENOMEM ;
252265
253- rg -> chip .offset = bank * MTK_BANK_WIDTH ;
266+ rg -> chip .gc . offset = bank * MTK_BANK_WIDTH ;
254267
255268 if (mtk -> gpio_irq ) {
256269 struct gpio_irq_chip * girq ;
@@ -261,15 +274,15 @@ mediatek_gpio_bank_probe(struct device *dev, int bank)
261274 */
262275 ret = devm_request_irq (dev , mtk -> gpio_irq ,
263276 mediatek_gpio_irq_handler , IRQF_SHARED ,
264- rg -> chip .label , & rg -> chip );
277+ rg -> chip .gc . label , & rg -> chip . gc );
265278
266279 if (ret ) {
267280 dev_err (dev , "Error requesting IRQ %d: %d\n" ,
268281 mtk -> gpio_irq , ret );
269282 return ret ;
270283 }
271284
272- girq = & rg -> chip .irq ;
285+ girq = & rg -> chip .gc . irq ;
273286 gpio_irq_chip_set_chip (girq , & mt7621_irq_chip );
274287 /* This will let us handle the parent IRQ in the driver */
275288 girq -> parent_handler = NULL ;
@@ -279,17 +292,17 @@ mediatek_gpio_bank_probe(struct device *dev, int bank)
279292 girq -> handler = handle_simple_irq ;
280293 }
281294
282- ret = devm_gpiochip_add_data (dev , & rg -> chip , mtk );
295+ ret = devm_gpiochip_add_data (dev , & rg -> chip . gc , mtk );
283296 if (ret < 0 ) {
284297 dev_err (dev , "Could not register gpio %d, ret=%d\n" ,
285- rg -> chip .ngpio , ret );
298+ rg -> chip .gc . ngpio , ret );
286299 return ret ;
287300 }
288301
289302 /* set polarity to low for all gpios */
290303 mtk_gpio_w32 (rg , GPIO_REG_POL , 0 );
291304
292- dev_info (dev , "registering %d gpios\n" , rg -> chip .ngpio );
305+ dev_info (dev , "registering %d gpios\n" , rg -> chip .gc . ngpio );
293306
294307 return 0 ;
295308}
0 commit comments