GPIO控制器

4 篇文章 0 订阅

结构体 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: gpio_rtcm@18890000 {                            
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);                                            

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值