天天看点

GPIO控制器

结构体 atlas7_gpio_chip

357 struct atlas7_gpio_chip {                                                       
 358         const char *name;                                                       
 359         void __iomem *reg;                                                      
 360         struct clk *clk;                                                                                                                                                                                
 361         int nbank;                                                              
 362         spinlock_t lock;                                                        
 363         struct gpio_chip chip;                                                  
 364         struct atlas7_gpio_bank banks[0];                                       
 365 };
           

说明:

reg—>gpio物理寄存器的虚拟地址

dts的配置

3329                         gpio_2: [email protected] {                            
3330                                 #gpio-cells = <2>;                              
3331                                 #interrupt-cells = <2>;                         
3332                                 compatible = "sirf,atlas7-gpio";                
3333                                 reg = <0x18890000 0x1000>;                      
3334                                 interrupts = <0 47 0>;                          
3335                                 gpio-controller;                                
3336                                 interrupt-controller;                           
3337                                 status = "disabled";                            
3338                                                                                 
3339                                 gpio-banks = <1>;                                                                                                                                                       
3340                                 gpio-ranges = <&pinctrl 0 0 0>;                 
3341                                 gpio-ranges-group-names = "rtc_gpio_grp";       
3342                         };   
           

A7 GPIO的入口函数

6003 static int atlas7_gpio_probe(struct platform_device *pdev)                      
6004 {                                                                                                                                                                                                       
6005         printk(KERN_ERR "tom atlas7_gpio_probe\r\n");                           
6006         struct device_node *np = pdev->dev.of_node;                             
6007         struct atlas7_gpio_chip *a7gc;                                          
6008         struct gpio_chip *chip;                                                 
6009         u32 nbank;                                                              
6010         int ret, idx;                                                           
6011                                                                                 
6012         ret = of_property_read_u32(np, "gpio-banks", &nbank);                   
6013         if (ret) {                                                              
6014                 dev_err(&pdev->dev,                                             
6015                         "Could not find GPIO bank info,ret=%d!\n",              
6016                         ret);                                                   
6017                 return ret;                                                     
6018         }                                                                       
6019                                                                                 
6020         /* retrieve gpio descriptor data */                                     
6021         a7gc = devm_kzalloc(&pdev->dev, sizeof(*a7gc) +                         
6022                         sizeof(struct atlas7_gpio_bank) * nbank, GFP_KERNEL);   
6023         if (!a7gc)                                                              
6024                 return -ENOMEM;                                                 
6025                                                                                 
6026         /* Get Gpio clk */                                                      
6027         a7gc->clk = of_clk_get(np, 0);                                          
6028         if (!IS_ERR(a7gc->clk)) {                                               
6029                 ret = clk_prepare_enable(a7gc->clk);                            
6030                 if (ret) {                                                      
6031                         dev_err(&pdev->dev,                                     
6032                                 "Could not enable clock!\n");                   
6033                         return ret;                                             
6034                 }                                                               
6035         }                                                                       
6036                                                                                 
6037         /* Get Gpio Registers */                                                
6038         a7gc->reg = of_iomap(np, 0);                                            
6039                                                                                 
6040         printk(KERN_ERR "tom a7gc->reg=%x %x\r\n",(int*)a7gc->reg,*((int*)a7gc->reg));
6041         if (!a7gc->reg) {                                                       
6042                 dev_err(&pdev->dev, "Could not map GPIO Registers!\n");         
6043                 return -ENOMEM;                                                 
6044         }                                                                       
6045                                                                                 
6046         a7gc->nbank = nbank;                                                    
6047         spin_lock_init(&a7gc->lock);                                            

           

继续阅读