Chinaunix首页 | 论坛 | 博客
  • 博客访问: 477044
  • 博文数量: 100
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 955
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-21 09:30
文章分类

全部博文(100)

文章存档

2017年(1)

2016年(16)

2015年(83)

我的朋友

分类: 嵌入式

2015-09-29 04:04:59

移植网卡失败,所以先来学习一下dts的使用方法。
keypad是最简单的设备之一,所以先拿这个开刀。
在s5pv210.dtsi里列举了s5pv210的soc上面的所有设备资源,注意这里是soc上的,没有描述实际连接的外设,实际的外设需要在主dts也就是s5pv210-smdkv210.dts中描述。


点击(此处)折叠或打开

  1. / {
  2. .....................

  3.         pinctrl0: pinctrl@e0200000 {
  4.             compatible = "samsung,s5pv210-pinctrl";
  5.             reg = <0xe0200000 0x1000>;
  6.             interrupt-parent = <&vic0>;
  7.             interrupts = <30>;

  8.             wakeup-interrupt-controller {
  9.                 compatible = "samsung,exynos4210-wakeup-eint";
  10.                 interrupts = <16>;
  11.                 interrupt-parent = <&vic0>;
  12.             };
  13.         };
  14.         
  15.         keypad: keypad@e1600000 {
  16.             compatible = "samsung,s5pv210-keypad";
  17.             reg = <0xe1600000 0x1000>;
  18.             interrupt-parent = <&vic2>;
  19.             interrupts = <25>;
  20.             clocks = <&clocks CLK_KEYIF>;
  21.             clock-names = "keypad";
  22.             status = "disabled";
  23.         };


pinctrl是GPIO设备为什么长度只有0x1000,我猜测这个pinctrl的作用只是给驱动源码提供一个GPIO的base address。
这里定义了一个标签keypad,方便其他地方引用。
keypad的寄存器地址是e1600000,这和手册是一致的。属性指定了中断,时钟。
但是具体用到那些gpio呢,这就要看s5pv210-smdkv210.dts了。

点击(此处)折叠或打开

  1. &keypad {
  2.     linux,input-no-autorepeat;
  3.     linux,input-wakeup;
  4.     samsung,keypad-num-rows = <8>;
  5.     samsung,keypad-num-columns = <8>;
  6.     pinctrl-names = "default";
  7.     pinctrl-0 = <&keypad_row0>, <&keypad_row1>, <&keypad_row2>,
  8.             <&keypad_row3>, <&keypad_row4>, <&keypad_row5>,
  9.             <&keypad_row6>, <&keypad_row7>,
  10.             <&keypad_col0>, <&keypad_col1>, <&keypad_col2>,
  11.             <&keypad_col3>, <&keypad_col4>, <&keypad_col5>,
  12.             <&keypad_col6>, <&keypad_col7>;
  13.     status = "okay";

  14.     key_1 {
  15.         keypad,row = <0>;
  16.         keypad,column = <3>;
  17.         linux,code = <KEY_1>;
  18.     };

  19.     key_2 {
  20.         keypad,row = <0>;
  21.         keypad,column = <4>;
  22.         linux,code = <KEY_2>;
  23.     };

  24.     key_3 {
  25.         keypad,row = <0>;
  26.         keypad,column = <5>;
  27.         linux,code = <KEY_3>;
  28.     };

  29.     key_4 {
  30.         keypad,row = <0>;
  31.         keypad,column = <6>;
  32.         linux,code = <KEY_4>;
  33.     };

  34.     key_5 {
  35.         keypad,row = <0
  36.         >;
  37.         keypad,column = <7>;
  38.         linux,code = <KEY_5>;
  39.     };

  40.     key_6 {
  41.         keypad,row = <1>;
  42.         keypad,column = <3>;
  43.         linux,code = <KEY_A>;
  44.     };
  45.     key_7 {
  46.         keypad,row = <1>;
  47.         keypad,column = <4>;
  48.         linux,code = <KEY_B>;
  49.     };

  50.     key_8 {
  51.         keypad,row = <1>;
  52.         keypad,column = <5>;
  53.         linux,code = <KEY_C>;
  54.     };

  55.     key_9 {
  56.         keypad,row = <1>;
  57.         keypad,column = <6>;
  58.         linux,code = <KEY_D>;
  59.     };

  60.     key_10 {
  61.         keypad,row = <1>;
  62.         keypad,column = <7>;
  63.         linux,code = <KEY_E>;
  64.     };
  65. };
通过&keypad引用s5pv210.dtsi中的keypad结点。我的理解就是对s5pv210.dtsi中的keypad结点添加更多属性。
这个keypad的设置为:

禁止重复按键输入,输入唤醒,8行8列。注意pinctrl-0=<&keypad_row0>    ~    <&keypad_col7>,这是重头戏,通过标签引用了16根引脚结点,这些引脚在s5pv210-pinctrl.dts中定义。
这是一个典型的client device结点(pinctrl子系统中的概念,state只有一个"default",相关知识参考 style="white-space:normal;" /> default的状态对应了pinctrl-0的配置,也就是当keypad这个设备被激活的时候,将这16根引脚设置成pinctrl-0的配置。pinctrl-0是一个句柄(phandle)列表,指向<&keypad_row0>   ~    <&keypad_col7>。

s5pv210-pinctrl.dts列出了pinctrl0的全部结点,这里只给出keypad相关的结点:

点击(此处)折叠或打开

  1. &pinctrl0 {

  2. ........

  3.        keypad_row0: keypad-row-0 {
  4.         samsung,pins = "gph3-0";
  5.         samsung,pin-function = <3>;
  6.         samsung,pin-pud = <0>;
  7.         samsung,pin-drv = <0>;
  8.     };

  9.     keypad_row1: keypad-row-1 {
  10.         samsung,pins = "gph3-1";
  11.         samsung,pin-function = <3>;
  12.         samsung,pin-pud = <0>;
  13.         samsung,pin-drv = <0>;
  14.     };

  15.     keypad_row2: keypad-row-2 {
  16.         samsung,pins = "gph3-2";
  17.         samsung,pin-function = <3>;
  18.         samsung,pin-pud = <0>;
  19.         samsung,pin-drv = <0>;
  20.     };

  21.     keypad_row3: keypad-row-3 {
  22.         samsung,pins = "gph3-3";
  23.         samsung,pin-function = <3>;
  24.         samsung,pin-pud = <0>;
  25.         samsung,pin-drv = <0>;
  26.     };

  27.     keypad_row4: keypad-row-4 {
  28.         samsung,pins = "gph3-4";
  29.         samsung,pin-function = <3>;
  30.         samsung,pin-pud = <0>;
  31.         samsung,pin-drv = <0>;
  32.     };

  33.     keypad_row5: keypad-row-5 {
  34.         samsung,pins = "gph3-5";
  35.         samsung,pin-function = <3>;
  36.         samsung,pin-pud = <0>;
  37.         samsung,pin-drv = <0>;
  38.     };

  39.     keypad_row6: keypad-row-6 {
  40.         samsung,pins = "gph3-6";
  41.         samsung,pin-function = <3>;
  42.         samsung,pin-pud = <0>;
  43.         samsung,pin-drv = <0>;
  44.     };

  45.     keypad_row7: keypad-row-7 {
  46.         samsung,pins = "gph3-7";
  47.         samsung,pin-function = <3>;
  48.         samsung,pin-pud = <0>;
  49.         samsung,pin-drv = <0>;
  50.     };

  51.     keypad_col0: keypad-col-0 {
  52.         samsung,pins = "gph2-0";
  53.         samsung,pin-function = <3>;
  54.         samsung,pin-pud = <0>;
  55.         samsung,pin-drv = <0>;
  56.     };

  57.     keypad_col1: keypad-col-1 {
  58.         samsung,pins = "gph2-1";
  59.         samsung,pin-function = <3>;
  60.         samsung,pin-pud = <0>;
  61.         samsung,pin-drv = <0>;
  62.     };

  63.     keypad_col2: keypad-col-2 {
  64.         samsung,pins = "gph2-2";
  65.         samsung,pin-function = <3>;
  66.         samsung,pin-pud = <0>;
  67.         samsung,pin-drv = <0>;
  68.     };

  69.     keypad_col3: keypad-col-3 {
  70.         samsung,pins = "gph2-3";
  71.         samsung,pin-function = <3>;
  72.         samsung,pin-pud = <0>;
  73.         samsung,pin-drv = <0>;
  74.     };

  75.     keypad_col4: keypad-col-4 {
  76.         samsung,pins = "gph2-4";
  77.         samsung,pin-function = <3>;
  78.         samsung,pin-pud = <0>;
  79.         samsung,pin-drv = <0>;
  80.     };

  81.     keypad_col5: keypad-col-5 {
  82.         samsung,pins = "gph2-5";
  83.         samsung,pin-function = <3>;
  84.         samsung,pin-pud = <0>;
  85.         samsung,pin-drv = <0>;
  86.     };

  87.     keypad_col6: keypad-col-6 {
  88.         samsung,pins = "gph2-6";
  89.         samsung,pin-function = <3>;
  90.         samsung,pin-pud = <0>;
  91.         samsung,pin-drv = <0>;
  92.     };

  93.     keypad_col7: keypad-col-7 {
  94.         samsung,pins = "gph2-7";
  95.         samsung,pin-function = <3>;
  96.         samsung,pin-pud = <0>;
  97.         samsung,pin-drv = <0>;
  98.     };
这里定义了keypad_row0   ~    keypad_col7 共16个标签,就是刚才的&keypad中的pinctrl-0引用了,这里详细列出了当使用keypad时,16个io的配置。
到这里就分析完成了。
补充说明一下s5pv210.dts中的aliaes(别名)。

点击(此处)折叠或打开

  1. / {
  2.     aliases {
  3.         csis0 = &csis0;
  4.         fimc0 = &fimc0;
  5.         fimc1 = &fimc1;
  6.         fimc2 = &fimc2;
  7.         i2c0 = &i2c0;
  8.         i2c1 = &i2c1;
  9.         i2c2 = &i2c2;
  10.         i2s0 = &i2s0;
  11.         i2s1 = &i2s1;
  12.         i2s2 = &i2s2;
  13.         pinctrl0 = &pinctrl0;
  14.         spi0 = &spi0;
  15.         spi1 = &spi1;
  16.     };
注意这里pinctrl0 = &pinctrl0;    这行代码相当于C语言中的宏定义。可以理解为#define  pinctrl0 &pinctrl0;

这样当我们在属性中写pinctrl0时,就是用&符号引用标签pinctrl0,乍一看可能感觉没什么卵用,直接写&pinctrl0不就完了,事实并非如此,对于dts文件可以用&pinctrl0的方式引用结点,但是在内核驱动源码中,就必须指定全路径了,所以这里用别名来替代全路径,方便驱动源码的识别。在根据device tree usage,别名应当是用来替代全路径的。





阅读(3211) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

fengmingqi_mcu2020-03-20 10:10:52

你好  请问一下你用的是哪个版本的uboot 和 kernel

fengmingqi_mcu2020-03-20 10:10:47

你好  请问一下你用的是哪个版本的uboot 和 kernel