11. dts配置

  1. 一、dts學習(注:pin 包括但不屬於 gpio)  
  2.     1.gpio0 node編寫方法:  
  3.         gpio0:    gpio@0    {  
  4.             pins_cmd_dat {  
  5.                 pins = <PINMUX_GPIO0__FUNC_IDDIG>;                //模式  
  6.                 slew-rate = <0>;                                //方向0--in    1--out  
  7.                 bias-pull-down = <11>;                            //pull使能,並且pull-down【<11>功能保留,寫<00>也行】  
  8.                 bias-disable;                                    //pull失能,與bias-pull-down/up衝突  
  9.                 output-low;                                        //設置輸出low,可以output-high【方向爲out纔有效】  
  10.                 input-schmitt-enable = <0>;  
  11.             };  
  12.         };  
  13.     2.配置pin腳用到的  
  14.         Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\pinctrl\pinconf-generic.c  
  15.         static struct pinconf_generic_dt_params dt_params[] = {  
  16.             { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },  
  17.             { "bias-high-impedance", PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0 },  
  18.             { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 },  
  19.             { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },  
  20.             { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },  
  21.             { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 },  
  22.             { "drive-push-pull", PIN_CONFIG_DRIVE_PUSH_PULL, 0 },  
  23.             { "drive-open-drain", PIN_CONFIG_DRIVE_OPEN_DRAIN, 0 },  
  24.             { "drive-open-source", PIN_CONFIG_DRIVE_OPEN_SOURCE, 0 },  
  25.             { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },  
  26.             { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 },  
  27.             { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 },  
  28.             { "input-schmitt-enable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 1 },  
  29.             { "input-schmitt-disable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 0 },  
  30.             { "input-debounce", PIN_CONFIG_INPUT_DEBOUNCE, 0 },  
  31.             { "power-source", PIN_CONFIG_POWER_SOURCE, 0 },  
  32.             { "low-power-enable", PIN_CONFIG_LOW_POWER_MODE, 1 },  
  33.             { "low-power-disable", PIN_CONFIG_LOW_POWER_MODE, 0 },  
  34.             { "output-low", PIN_CONFIG_OUTPUT, 0, },  
  35.             { "output-high", PIN_CONFIG_OUTPUT, 1, },  
  36.             { "slew-rate", PIN_CONFIG_SLEW_RATE, 0},  
  37.         };  
  38.   
  39. 二、一個alsps的dts配置與調用示例(epl259x.c)  
  40.     1.dts配置  
  41.         1.1.mt6735m.dtsi  
  42.             /{  
  43.                 alsps:als_ps@0 {                                        //alsps  node  
  44.                     compatible = "mediatek,als_ps";  
  45.                 };  
  46.             };  
  47.   
  48.         1.2.dts  
  49.             &alsps {                                                //加&表示引用別處定義的node (dtsi中 alsps node)  
  50.                 pinctrl-names = "pin_default""pin_cfg";            //  
  51.                 pinctrl-0 = <&alsps_intpin_default>;                //默認配置  
  52.                 pinctrl-1 = <&alsps_intpin_cfg>;                    //alsps    GPIO中斷配置  
  53.                 status = "okay";  
  54.             };  
  55.             &pio {  
  56.                 alsps_intpin_cfg: alspspincfg {                        //alsps_intpin_cfg,在driver中pinctrl_lookup_state()用到  
  57.                     pins_cmd_dat {  
  58.                         pins = <PINMUX_GPIO4__FUNC_GPIO4>;            //模式  
  59.                         slew-rate = <0>;                            //方向0--in    1--out  
  60.                         bias-pull-up = <00>;  
  61.                     };  
  62.                 };  
  63.                 alsps_intpin_default: alspsdefaultcfg {                //  
  64.                 };  
  65.             };  
  66.       
  67.     2.驅動中調用dts  
  68.         Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\misc\mediatek\alsps\epl259x\epl259x.c  
  69.         void epl_sensor_update_mode(struct i2c_client *client)  
  70.         {  
  71.             struct pinctrl *pinctrl;                                        //定義一個pin腳指針  
  72.             struct pinctrl_state *pins_default;                                //  
  73.             struct pinctrl_state *pins_cfg;  
  74.             struct platform_device *alsps_pdev = get_alsps_platformdev();    //獲取平臺設備alsps(dtsi的 alsps node會create as a platform device)  
  75.   
  76.             pinctrl = devm_pinctrl_get(&alsps_pdev->dev);                    //從平臺設備alsps 獲取pin  
  77.             pins_default = pinctrl_lookup_state(pinctrl, "pin_default");    //獲取 pin 默認配置  
  78.             pins_cfg = pinctrl_lookup_state(pinctrl, "pin_cfg");            //獲取 pin 配置  
  79.             pinctrl_select_state(pinctrl, pins_cfg);                        //設置pin模式  
  80.         }  
  81.   
  82.     3.adb 查看pin腳模式  
  83.         cat /sys/class/misc/mygpio/pin  
  84.         PIN:MODE,PULL_SEL,DIN,DOUT,PULL EN,DIR,IES,SMT  
  85.         0:    1     1          1      0       1       0   1   0  
  86.         1:  0     0          0      0       1       0   1   0  
  87.           
  88. 三、i2c的dts配置與調用示例(gt1x_tpd.c)  
  89.     1.codegen.dws與cust_i2c.dtsi  
  90.         Y:\code8\mt6737_M0_MP1_V2_84\out\target\product\len6737m_35_m0\obj\PRELOADER_OBJ\inc\cust_i2c.dtsi(codegen.dws編譯生成)  
  91.         &i2c1 {                                            //i2c控制器:i2c1  
  92.             CAP_TOUCH@5D {                                //i2c從設備:CAP_TOUCH  
  93.                 compatible = "mediatek,CAP_TOUCH";        //  
  94.                 reg = <0x5D>;                            //i2c從設備地址  
  95.             };  
  96.             I2C_LCD_BIAS@3E {                            //i2c從設備:I2C_LCD_BIAS  
  97.                 compatible = "mediatek,I2C_LCD_BIAS";  
  98.                 reg = <0x3E>;  
  99.             };  
  100.         };  
  101.     2.gt1x_tpd.c  
  102.         Y:\code8\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\GT1X\gt1x_tpd.c  
  103.           
  104.         static const struct of_device_id gt1x_dt_match[] = {  
  105.             {.compatible = "mediatek,CAP_TOUCH"},            //用於匹配平臺設備"mediatek,CAP_TOUCH"與dts/dws相同  
  106.             {},  
  107.         };  
  108.         static struct i2c_driver tpd_i2c_driver = {  
  109.             .probe = tpd_i2c_probe,  
  110.             .remove = tpd_i2c_remove,  
  111.             .detect = tpd_i2c_detect,  
  112.             .driver = {  
  113.                .name = GTP_DRIVER_NAME,  
  114.                .of_match_table = gt1x_dt_match,                //用於匹配平臺設備  
  115.                },  
  116.             .id_table = tpd_i2c_id,  
  117.             .address_list = (const unsigned short *)forces,  
  118.         };  
  119.       
  120. 四、EINT  
  121.       
  122.     1.mt6735m.dtsi  
  123.         /{                                                        //根節點  
  124.             bus{                                                //  
  125.                 touch: touch@ {                                    //touch node 隸屬於bus節點  
  126.                     compatible = "mediatek,mt6735-touch",  
  127.                                 "mediatek,mt6735m-touch";  
  128.                     vtouch-supply = <&mt_pmic_vgp1_ldo_reg>;  
  129.                 };  
  130.             }  
  131.         }  
  132.     2.cust_eint.dtsi  
  133.         Y:\code8\mt6737_M0_MP1_V2_84\out\target\product\len6737m_35_m0\obj\PRELOADER_OBJ\inc\cust_eint.dtsi(codegen.dws編譯生成)  
  134.             &touch {  
  135.                 interrupt-parent = <&eintc>;  
  136.                 interrupts = <10 IRQ_TYPE_EDGE_FALLING>;  
  137.                 debounce = <10 0>;  
  138.                 status = "okay";  
  139.             };  
  140.     3.tp驅動中request_irq  
  141.         3.1 gt9xx_driver.c  
  142.             Y:\code8\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\GT911\gt9xx_driver.c  
  143.             static int tpd_irq_registration(void)  
  144.             {  
  145.                 struct device_node *node = NULL;  
  146.                 node = of_find_compatible_node(NULL, NULL, "mediatek,cap_touch");        //從dts node中獲取node信息  
  147.                 ...  
  148.             }  
  149.           
  150.         3.2 gt1x_tpd.c  
  151.             Y:\code8\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\GT1X\gt1x_tpd.c  
  152.             static int tpd_irq_registration(void)  
  153.             {  
  154.                 struct device_node *node = NULL;  
  155.                 node = of_find_matching_node(node, touch_of_match);                        //touch_of_match是一個匹配數組,匹配node  
  156.                   
  157.                 of_property_read_u32_array(node , "debounce", ints, ARRAY_SIZE(ints));    //從dws/dts獲取debounce信息  
  158.                 gpio_set_debounce(ints[0], ints[1]);                                    //設置debounce信息(去抖動延時)  
  159.                   
  160.                   
  161.                 tpd_touch_irq = irq_of_parse_and_map(node, 0);                            //獲取irq number  
  162.                   
  163.                 request_irq(tpd_touch_irq, (irq_handler_t)tpd_eint_interrupt_handler,     //申請中斷  
  164.                     IRQF_TRIGGER_RISING, "TOUCH_PANEL-eint", NULL);(node, 0);  
  165.                 ...  
  166.             }  
  167.           
  168.             #ifdef GTP_CONFIG_OF  
  169.                     enable_irq(tpd_touch_irq);            //enable_irq與disable_irq要成對存在  
  170.                       
  171.             #ifdef GTP_CONFIG_OF  
  172.                     disable_irq(tpd_touch_irq);  
  173.               
  174.               
  175.             Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\mtk_tpd.c  
  176.             struct of_device_id touch_of_match[] = {                                    //touch_of_match是一個匹配數組  
  177.                 { .compatible = "mediatek,mt6735-touch", },  
  178.                 { .compatible = "mediatek,mt6580-touch", },  
  179.                 { .compatible = "mediatek,mt8173-touch", },  
  180.                 { .compatible = "mediatek,mt6755-touch", },  
  181.                 { .compatible = "mediatek,mt6797-touch", },  
  182.                 { .compatible = "mediatek,mt8163-touch", },  
  183.                 {},  
  184.   
  185.             };  
  186.   
  187.   
  188. 14_2.DTS-Touch_Panel  
  189.   
  190.   
  191. 1.dts中  
  192.     1.1. mt6735m.dtsi  
  193.         Y:\code8\mt6737_M0_MP1_V2_84\out\target\product\len6737m_35_m0\obj\PRELOADER_OBJ\inc\cust_pmic.dtsi  
  194.         touch: touch@ {  
  195.             compatible = "mediatek,mt6735-touch",  
  196.                         "mediatek,mt6735m-touch";  
  197.             vtouch-supply = <&mt_pmic_vgp1_ldo_reg>;  
  198.         };  
  199.           
  200.     1.2. Y:\code8\mt6737_M0_MP1_V2_84\out\target\product\len6737m_35_m0\obj\PRELOADER_OBJ\inc\cust_pmic.dtsi(codegen.dws生成)  
  201.         &touch {  
  202.             vtouch-supply = <&mt_pmic_vgp1_ldo_reg>;  
  203.             status = "okay";  
  204.         };  
  205.       
  206.     1.3.  Y:\code8\mt6737_M0_MP1_V2_84\out\target\product\len6737m_35_m0\obj\PRELOADER_OBJ\inc\cust_i2c.dtsi(codegen.dws生成)  
  207.         &i2c1 {  
  208.             cap_touch@5d {  
  209.                 compatible = "mediatek,cap_touch";  
  210.                 reg = <0x5d>;  
  211.             };  
  212.         };  
  213.           
  214.     1.4. Y:\code8\mt6737_M0_MP1_V2_84\out\target\product\len6737m_35_m0\obj\PRELOADER_OBJ\inc\cust_eint.dtsi(codegen.dws編譯生成)  
  215.         &touch {  
  216.             interrupt-parent = <&eintc>;  
  217.             interrupts = <10 IRQ_TYPE_EDGE_FALLING>;  
  218.             debounce = <10 0>;  
  219.             status = "okay";  
  220.         };  
  221.       
  222.     1.5 len6737m_35_m0.dts  
  223.         &touch {  
  224.             tpd-resolution = <720 1280>;                                        //tp分辨率  
  225.             use-tpd-button = <1>;                                                //tp虛擬按鍵使能  
  226.             tpd-key-num = <3>;                                                    //tp虛擬按鍵個數  
  227.             tpd-key-local= <139 172 158 0>;                                        //3個虛擬按鍵參數(第4個爲0)  
  228.             tpd-key-dim-local = <100 1550 100 100 360 1550 100 100 620 1550 100 100 0 0 0 0>;    //3個虛擬按鍵參數(第4個爲0)  
  229.                                                                                 //4*4(x,y,weith,height)  
  230.             tpd-max-touch-num = <5>;                                            //5點觸控  
  231.             tpd-filter-enable = <1>;                                            //tp過濾器使能  
  232.             tpd-filter-pixel-density = <124>;                                    //tp過濾器像素密度  
  233.             tpd-filter-custom-prameters = <0 0 0 0 0 0 0 0 0 0 0 0>;  
  234.             tpd-filter-custom-speed = <0 0 0>;  
  235.             pinctrl-names = "default""state_eint_as_int""state_eint_output0""state_eint_output1",  
  236.                 "state_rst_output0""state_rst_output1";  
  237.             pinctrl-0 = <&CTP_pins_default>;  
  238.             pinctrl-1 = <&CTP_pins_eint_as_int>;  
  239.             pinctrl-2 = <&CTP_pins_eint_output0>;  
  240.             pinctrl-3 = <&CTP_pins_eint_output1>;  
  241.             pinctrl-4 = <&CTP_pins_rst_output0>;  
  242.             pinctrl-5 = <&CTP_pins_rst_output1>;  
  243.             status = "okay";  
  244.         };  
  245.           
  246. 2.tp驅動中  
  247.     2.1 request_irq  
  248.         Y:\code8\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\GT1X\gt1x_tpd.c  
  249.         static int tpd_irq_registration(void)  
  250.         {  
  251.             struct device_node *node = NULL;  
  252.             node = of_find_matching_node(node, touch_of_match);                        //touch_of_match是一個匹配數組  
  253.               
  254.             of_property_read_u32_array(node , "debounce", ints, ARRAY_SIZE(ints));    //從dws/dts獲取debounce信息  
  255.             gpio_set_debounce(ints[0], ints[1]);                                    //設置debounce信息(去抖動延時)  
  256.               
  257.               
  258.             tpd_touch_irq = irq_of_parse_and_map(node, 0);                            //獲取irq number  
  259.               
  260.             request_irq(tpd_touch_irq, (irq_handler_t)tpd_eint_interrupt_handler,     //申請中斷  
  261.                 IRQF_TRIGGER_RISING, "TOUCH_PANEL-eint", NULL);(node, 0);  
  262.             ...  
  263.         }  
  264.       
  265.     2.2 tp獲取property信息--of_property_read_u32()  
  266.         Y:\code8\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\GT1X\gt1x_tpd.c  
  267.         static int __init tpd_driver_init(void)  
  268.         {  
  269.             GTP_INFO(" Goodix touch panel driver init.");  
  270.             tpd_get_dts_info();                                                        //tp獲取dts信息---tpd_get_dts_info()  
  271.             if (tpd_driver_add(&tpd_device_driver) < 0)  
  272.                 GTP_INFO("add generic driver failed\n");  
  273.             return 0;  
  274.         }  
  275.           
  276.         Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\mtk_tpd.c  
  277.         struct of_device_id touch_of_match[] = {                                    //touch_of_match是一個匹配數組  
  278.             { .compatible = "mediatek,mt6735-touch", },  
  279.             { .compatible = "mediatek,mt6580-touch", },  
  280.             { .compatible = "mediatek,mt8173-touch", },  
  281.             { .compatible = "mediatek,mt6755-touch", },  
  282.             { .compatible = "mediatek,mt6797-touch", },  
  283.             { .compatible = "mediatek,mt8163-touch", },  
  284.             {},  
  285.         };  
  286.           
  287.         struct tpd_filter_t tpd_filter;  
  288.         struct tpd_dts_info tpd_dts_data;                                            //在對應的tpd.h中用extern修改鏈接屬性  
  289.         void tpd_get_dts_info(void)  
  290.         {  
  291.             struct device_node *node1 = NULL;  
  292.             int key_dim_local[16], i;  
  293.   
  294.             node1 = of_find_matching_node(node1, touch_of_match);                    //touch_of_match是一個匹配數組,匹配node  
  295.             if (node1) {                                                            //這是一個全局變量---tpd_dts_data(touchscreen\mediatek\tpd.h)  
  296.                 of_property_read_u32(node1, "tpd-key-dim-local", &tpd_dts_data.touch_max_num);    //獲取node屬性---of_property_read_u32();  
  297.                 of_property_read_u32(node1, "use-tpd-button", &tpd_dts_data.use_tpd_button);  
  298.                 pr_info("[tpd]use-tpd-button = %d\n", tpd_dts_data.use_tpd_button);  
  299.                 of_property_read_u32_array(node1, "tpd-resolution",                                //獲取node屬性數組---of_property_read_u32_array();  
  300.                     tpd_dts_data.tpd_resolution, ARRAY_SIZE(tpd_dts_data.tpd_resolution));  
  301.                 if (tpd_dts_data.use_tpd_button) {  
  302.                     of_property_read_u32(node1, "tpd-key-num", &tpd_dts_data.tpd_key_num);  
  303.                     of_property_read_u32_array(node1, "tpd-key-local",  
  304.                         tpd_dts_data.tpd_key_local, ARRAY_SIZE(tpd_dts_data.tpd_key_local));  
  305.                     of_property_read_u32_array(node1, "tpd-key-dim-local",  
  306.                         key_dim_local, ARRAY_SIZE(key_dim_local));  
  307.                     memcpy(tpd_dts_data.tpd_key_dim_local, key_dim_local, sizeof(key_dim_local));  
  308.                     for (i = 0; i < 4; i++) {  
  309.                         pr_info("[tpd]key[%d].key_x = %d\n", i, tpd_dts_data.tpd_key_dim_local[i].key_x);  
  310.                         pr_info("[tpd]key[%d].key_y = %d\n", i, tpd_dts_data.tpd_key_dim_local[i].key_y);  
  311.                         pr_info("[tpd]key[%d].key_W = %d\n", i, tpd_dts_data.tpd_key_dim_local[i].key_width);  
  312.                         pr_info("[tpd]key[%d].key_H = %d\n", i, tpd_dts_data.tpd_key_dim_local[i].key_height);  
  313.                     }  
  314.                 }  
  315.                 of_property_read_u32(node1, "tpd-filter-enable", &tpd_dts_data.touch_filter.enable);  
  316.                 if (tpd_dts_data.touch_filter.enable) {  
  317.                     of_property_read_u32(node1, "tpd-filter-pixel-density",  
  318.                                 &tpd_dts_data.touch_filter.pixel_density);  
  319.                     of_property_read_u32_array(node1, "tpd-filter-custom-prameters",  
  320.                         (u32 *)tpd_dts_data.touch_filter.W_W, ARRAY_SIZE(tpd_dts_data.touch_filter.W_W));  
  321.                     of_property_read_u32_array(node1, "tpd-filter-custom-speed",  
  322.                         tpd_dts_data.touch_filter.VECLOCITY_THRESHOLD,  
  323.                         ARRAY_SIZE(tpd_dts_data.touch_filter.VECLOCITY_THRESHOLD));  
  324.                 }  
  325.                 memcpy(&tpd_filter, &tpd_dts_data.touch_filter, sizeof(tpd_filter));  
  326.                 pr_info("[tpd]tpd-filter-enable = %d, pixel_density = %d\n",  
  327.                             tpd_filter.enable, tpd_filter.pixel_density);  
  328.             } else {  
  329.                 pr_err("[tpd]%s can't find touch compatible custom node\n", __func__);  
  330.             }  
  331.         }  
  332.           
  333.         Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\tpd.h  
  334.         struct tpd_key_dim_local {  
  335.             int key_x;  
  336.             int key_y;  
  337.             int key_width;  
  338.             int key_height;  
  339.         };  
  340.         struct tpd_filter_t {  
  341.             int enable; /*0: disable, 1: enable*/  
  342.             int pixel_density; /*XXX pixel/cm*/  
  343.             int W_W[3][4];/*filter custom setting prameters*/  
  344.             unsigned int VECLOCITY_THRESHOLD[3];/*filter speed custom settings*/  
  345.         };  
  346.         struct tpd_dts_info {  
  347.             int tpd_resolution[2];  
  348.             int touch_max_num;  
  349.             int use_tpd_button;  
  350.             int tpd_key_num;  
  351.             int tpd_key_local[4];  
  352.             struct tpd_key_dim_local tpd_key_dim_local[4];  
  353.             struct tpd_filter_t touch_filter;  
  354.         };  
  355.         extern struct tpd_dts_info tpd_dts_data;                                        //這是一個全局變量  
  356.       
  357.     2.3 tp獲取pinctrl信息--pinctrl_lookup_state()  
  358.         len6737m_35_m0.dts  
  359.         &touch {  
  360.             ...  
  361.             pinctrl-names = "default""state_eint_as_int""state_eint_output0""state_eint_output1",  
  362.                 "state_rst_output0""state_rst_output1";  
  363.             pinctrl-0 = <&CTP_pins_default>;  
  364.             pinctrl-1 = <&CTP_pins_eint_as_int>;  
  365.             pinctrl-2 = <&CTP_pins_eint_output0>;  
  366.             pinctrl-3 = <&CTP_pins_eint_output1>;  
  367.             pinctrl-4 = <&CTP_pins_rst_output0>;  
  368.             pinctrl-5 = <&CTP_pins_rst_output1>;  
  369.             status = "okay";  
  370.         };  
  371.         &pio {  
  372.             CTP_pins_default: eint0default {  
  373.             };  
  374.             CTP_pins_eint_as_int: eint@0 {  
  375.                 pins_cmd_dat {  
  376.                     pins = <PINMUX_GPIO10__FUNC_GPIO10>;  
  377.                     slew-rate = <0>;  
  378.                     bias-disable;  
  379.                 };  
  380.             };  
  381.             CTP_pins_eint_output0: eintoutput0 {  
  382.                 pins_cmd_dat {  
  383.                     pins = <PINMUX_GPIO10__FUNC_GPIO10>;  
  384.                     slew-rate = <1>;  
  385.                     output-low;  
  386.                 };  
  387.             };  
  388.             CTP_pins_eint_output1: eintoutput1 {  
  389.                 pins_cmd_dat {  
  390.                     pins = <PINMUX_GPIO10__FUNC_GPIO10>;  
  391.                     slew-rate = <1>;  
  392.                     output-high;  
  393.                 };  
  394.             };  
  395.             CTP_pins_rst_output0: rstoutput0 {  
  396.                 pins_cmd_dat {  
  397.                     pins = <PINMUX_GPIO62__FUNC_GPIO62>;  
  398.                     slew-rate = <1>;  
  399.                     output-low;  
  400.                 };  
  401.             };  
  402.             CTP_pins_rst_output1: rstoutput1 {  
  403.                 pins_cmd_dat {  
  404.                     pins = <PINMUX_GPIO62__FUNC_GPIO62>;  
  405.                     slew-rate = <1>;  
  406.                     output-high;  
  407.                 };  
  408.             };  
  409.         };      
  410.           
  411.         Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\mtk_tpd.c      
  412.         int tpd_get_gpio_info(struct platform_device *pdev)  
  413.         {  
  414.             int ret;  
  415.             TPD_DEBUG("[tpd %d] mt_tpd_pinctrl+++++++++++++++++\n", pdev->id);  
  416.             pinctrl1 = devm_pinctrl_get(&pdev->dev);                                    //...  
  417.             if (IS_ERR(pinctrl1)) {  
  418.                 ret = PTR_ERR(pinctrl1);  
  419.                 dev_err(&pdev->dev, "fwq Cannot find touch pinctrl1!\n");  
  420.                 return ret;  
  421.             }  
  422.             pins_default = pinctrl_lookup_state(pinctrl1, "default");                    //獲取pinctrl屬性信息---pinctrl_lookup_state()  
  423.             if (IS_ERR(pins_default)) {  
  424.                 ret = PTR_ERR(pins_default);  
  425.                 dev_err(&pdev->dev, "fwq Cannot find touch pinctrl default %d!\n", ret);  
  426.             }  
  427.             eint_as_int = pinctrl_lookup_state(pinctrl1, "state_eint_as_int");  
  428.             if (IS_ERR(eint_as_int)) {  
  429.                 ret = PTR_ERR(eint_as_int);  
  430.                 dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_eint_as_int!\n");  
  431.                 return ret;  
  432.             }  
  433.             eint_output0 = pinctrl_lookup_state(pinctrl1, "state_eint_output0");  
  434.             if (IS_ERR(eint_output0)) {  
  435.                 ret = PTR_ERR(eint_output0);  
  436.                 dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_eint_output0!\n");  
  437.                 return ret;  
  438.             }  
  439.             eint_output1 = pinctrl_lookup_state(pinctrl1, "state_eint_output1");  
  440.             if (IS_ERR(eint_output1)) {  
  441.                 ret = PTR_ERR(eint_output1);  
  442.                 dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_eint_output1!\n");  
  443.                 return ret;  
  444.             }  
  445.             rst_output0 = pinctrl_lookup_state(pinctrl1, "state_rst_output0");  
  446.             if (IS_ERR(rst_output0)) {  
  447.                 ret = PTR_ERR(rst_output0);  
  448.                 dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_rst_output0!\n");  
  449.                 return ret;  
  450.             }  
  451.             rst_output1 = pinctrl_lookup_state(pinctrl1, "state_rst_output1");  
  452.             if (IS_ERR(rst_output1)) {  
  453.                 ret = PTR_ERR(rst_output1);  
  454.                 dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_rst_output1!\n");  
  455.                 return ret;  
  456.             }  
  457.             TPD_DEBUG("[tpd%d] mt_tpd_pinctrl----------\n", pdev->id);  
  458.             return 0;  
  459.         }      
  460.       
  461.     2.4    LCM ON / OFF 時候---tp要suspend / resume  
  462.         Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\mtk_tpd.c  
  463.           
  464.         static struct notifier_block tpd_fb_notifier;                    //定義一個tpd_fb_notifier變量實體  
  465.         static int tpd_probe(struct platform_device *pdev)                //platform_device與platform_driver probe  
  466.             tpd_fb_notifier.notifier_call = tpd_fb_notifier_callback;    //函數指針--指向tpd_fb_notifier_callback()函數  
  467.         }  
  468.         static void touch_resume_workqueue_callback(struct work_struct *work)  
  469.         {  
  470.             TPD_DEBUG("GTP touch_resume_workqueue_callback\n");  
  471.             g_tpd_drv->resume(NULL);  
  472.             tpd_suspend_flag = 0;  
  473.         }  
  474.         static int tpd_fb_notifier_callback(struct notifier_block *self, unsigned long event, void *data)  
  475.         {  
  476.             struct fb_event *evdata = NULL;  
  477.             int blank;  
  478.             int err = 0;  
  479.   
  480.             TPD_DEBUG("tpd_fb_notifier_callback\n");  
  481.   
  482.             evdata = data;  
  483.             /* If we aren't interested in this event, skip it immediately ... */  
  484.             if (event != FB_EVENT_BLANK)  
  485.                 return 0;  
  486.   
  487.             blank = *(int *)evdata->data;  
  488.             TPD_DMESG("fb_notify(blank=%d)\n", blank);  
  489.             switch (blank) {  
  490.             case FB_BLANK_UNBLANK:                //按power亮屏--爲了不卡亮屏時間--創建了一個wakequeue來處理tp_resume  
  491.                 TPD_DMESG("LCD ON Notify\n");  
  492.                 if (g_tpd_drv && tpd_suspend_flag) {  
  493.                     err = queue_work(touch_resume_workqueue, &touch_resume_work);  
  494.                     if (!err) {  
  495.                         TPD_DMESG("start touch_resume_workqueue failed\n");  
  496.                         return err;  
  497.                     }  
  498.                 }  
  499.                 break;  
  500.             case FB_BLANK_POWERDOWN:            //按power滅屏--touch會run suspend(休眠)  
  501.                 TPD_DMESG("LCD OFF Notify\n");  
  502.                 if (g_tpd_drv)  
  503.                     err = cancel_work_sync(&touch_resume_work);  
  504.                     if (!err)  
  505.                         TPD_DMESG("cancel touch_resume_workqueue err = %d\n", err);  
  506.                     g_tpd_drv->suspend(NULL);  
  507.                 tpd_suspend_flag = 1;  
  508.                 break;  
  509.             default:  
  510.                 break;  
  511.             }  
  512.             return 0;  
  513.         }  
  514.       
  515.     2.5 驅動中如何操作GPIO口輸出0/1    -----    tpd_gpio_output()  
  516.         Y:\code8\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\GT1X\gt1x_tpd.c  
  517.         int gt1x_power_switch(s32 state)  
  518.         {  
  519.             tpd_gpio_output(GTP_RST_PORT, 0);  
  520.             tpd_gpio_output(GTP_INT_PORT, 0);  
  521.             ...  
  522.         }  
  523.       
  524.         Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\mtk_tpd.c  
  525.         static DEFINE_MUTEX(tpd_set_gpio_mutex);  
  526.         void tpd_gpio_as_int(int pin)  
  527.         {  
  528.             mutex_lock(&tpd_set_gpio_mutex);  
  529.             TPD_DEBUG("[tpd]tpd_gpio_as_int\n");  
  530.             if (pin == 1)  
  531.                 pinctrl_select_state(pinctrl1, eint_as_int);  
  532.             mutex_unlock(&tpd_set_gpio_mutex);  
  533.         }  
  534.   
  535.         void tpd_gpio_output(int pin, int level)  
  536.         {  
  537.             mutex_lock(&tpd_set_gpio_mutex);  
  538.             TPD_DEBUG("[tpd]tpd_gpio_output pin = %d, level = %d\n", pin, level);  
  539.             if (pin == 1) {  
  540.                 if (level)  
  541.                     pinctrl_select_state(pinctrl1, eint_output1);  
  542.                 else  
  543.                     pinctrl_select_state(pinctrl1, eint_output0);  
  544.             } else {  
  545.                 if (level)  
  546.                     pinctrl_select_state(pinctrl1, rst_output1);  
  547.                 else  
  548.                     pinctrl_select_state(pinctrl1, rst_output0);  
  549.             }  
  550.             mutex_unlock(&tpd_set_gpio_mutex);  
  551.         }  
  552.       
  553.      
  554.   
  555. 14_3.DTS-Vibrator  
  556.   
  557. 1.dts中  
  558.     len6737m_35_m0.dts  
  559.     /{  
  560.         vibrator0:vibrator@0 {  
  561.             compatible = "mediatek,vibrator";  
  562.             vib_timer = <25>;  
  563.             vib_limit = <9>;  
  564.             vib_vol= <5>;  
  565.         };  
  566.     }  
  567.   
  568. 2.Projectconfig.mk  
  569.     CUSTOM_KERNEL_VIBRATOR = vibrator  
  570.       
  571. 3.len6737m_35_m0_debug_defconfig、len6737m_35_m0_defconfig  
  572.     CONFIG_MTK_VIBRATOR=y      
  573.       
  574. 4.vibrator 驅動中(日後遇到再補充)  
  575.     Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\misc\mediatek\vibrator\vibrator_drv.c  
  576.     Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\misc\mediatek\vibrator\mt6735\vibrator.c  
  577.       
  578.       
  579.       
  580.       
  581. 14_4.DTS-SPI  
  582.   
  583. 1.dts中  
  584.     1.1 mt6735m.dtsi  
  585.       
  586.         spi0:spi@1100a000 {  
  587.             compatible = "mediatek,mt6735m-spi";  
  588.             cell-index = <0>;  
  589.             spi-padmacro = <0>;  
  590.             reg = <0x1100a000 0x1000>;  
  591.             interrupts = <GIC_SPI 118 IRQ_TYPE_LEVEL_LOW>;  
  592.         };  
  593.           
  594.         SPI1@0x1100A000 {  
  595.             cell-index = <0>;  
  596.             spi-padmacro = <0>;  
  597.             compatible = "mediatek,SPI1";  
  598.             reg = <0x1100A000 0x1000>;  
  599.             interrupts = <0 118 0x8>;  
  600.         };  
  601.   
  602.     1.2 len6737m_35_m0_debug_defconfig、len6737m_35_m0_defconfig  
  603.         CONFIG_MTK_SPI=y  
  604.       
  605.     1.3 codegen.dws  
  606.         GPIO口初始化設置  
  607.         GPIO66---SPI0_CKA  
  608.         GPIO67---SPI0_MIA  
  609.         GPIO68---SPI0_MOA  
  610.         //SPI0_CSB  
  611.       
  612.     1.4 Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\spi\mediatek\mt6735\spi-dev.c  
  613.         static struct spi_board_info spi_board_devs[] __initdata = {  
  614.             [0] = {  
  615.             .modalias = "spi-ut",  
  616.             .bus_num = 0,                    //SPI0        控制器0  
  617.             .chip_select = 1,                //SPI0.1    從設備1  
  618.             .mode = SPI_MODE_3,                //SPI模式3  
  619.             },  
  620.         };  
  621.         static int __init spi_dev_init(void)  
  622.         {  
  623.             SPIDEV_LOG("SPI_DEV_INIT.\n");  
  624.             spi_register_board_info(spi_board_devs, ARRAY_SIZE(spi_board_devs));  
  625.             return spi_register_driver(&spi_test_driver);  
  626.         }  
  627.         static struct spi_driver spi_test_driver = {  
  628.             .driver = {  
  629.                 .name = "test_spi",  
  630.                 .bus = &spi_bus_type,  
  631.                 .owner = THIS_MODULE,  
  632.                 },  
  633.             .probe = spi_test_probe,  
  634.             .remove = spi_test_remove,  
  635.             .id_table = &spi_id_table,  
  636.         };  
  637.       
  638.      
  639.   
  640.   
  641. 14_5.DTS-Light  
  642.   
  643. 1.dts中  
  644.     1.1 mt6735m.dtsi  
  645.       
  646.         led0:led@0 {  
  647.             compatible = "mediatek,red";  
  648.             led_mode = <0>;                //mt65xx_led_mode 之 MT65XX_LED_MODE_NONE  
  649.             data = <1>;                    //mt65xx_led_pmic 之 MT65XX_LED_MODE_PWM  
  650.             pwm_config = <0 0 0 0 0>;  
  651.         };  
  652.         ...  
  653.         led6:led@6 {  
  654.             compatible = "mediatek,lcd-backlight";  
  655.             led_mode = <5>;                //MT65XX_LED_MODE_CUST_LCM  
  656.             data = <1>;  
  657.             pwm_config = <0 0 0 0 0>;  
  658.         };  
  659.       
  660.     1.2 Y:\code8\mt6737_M0_MP1_V2_84\vendor\mediatek\proprietary\bootable\bootloader\lk\target\len6737m_35_m0\cust_leds.c  
  661.         static struct cust_mt65xx_led cust_led_list[MT65XX_LED_TYPE_TOTAL] = {  
  662.             {"red",               MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},  
  663.             {"green",             MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},  
  664.             {"blue",              MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},  
  665.             {"jogball-backlight", MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},  
  666.             {"keyboard-backlight",MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},  
  667.             {"button-backlight",  MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},  
  668.             {"lcd-backlight",     MT65XX_LED_MODE_CUST_BLS_PWM, (int)disp_bls_set_backlight,{0}},  
  669.         };  
  670.       
  671.     1.3 Y:\code8\mt6737_M0_MP1_V2_84\vendor\mediatek\proprietary\bootable\bootloader\lk\target\len6737m_35_m0\inc\cust_leds.h  
  672.         enum mt65xx_led_mode  
  673.         {  
  674.             MT65XX_LED_MODE_NONE,        //0  
  675.             MT65XX_LED_MODE_PWM,        //1  
  676.             MT65XX_LED_MODE_GPIO,        //2  
  677.             MT65XX_LED_MODE_PMIC,        //3  
  678.             MT65XX_LED_MODE_CUST,        //4  
  679.             MT65XX_LED_MODE_CUST_LCM,    //5  
  680.             MT65XX_LED_MODE_CUST_BLS_PWM//6  
  681.         };  
  682.         enum mt65xx_led_pmic  
  683.         {  
  684.             MT65XX_LED_PMIC_BUTTON=0,    //0  
  685.             MT65XX_LED_PMIC_LCD,        //1  
  686.             MT65XX_LED_PMIC_LCD_ISINK,  
  687.             MT65XX_LED_PMIC_LCD_BOOST,  
  688.             MT65XX_LED_PMIC_NLED_ISINK4,  
  689.             MT65XX_LED_PMIC_NLED_ISINK5,  
  690.             MT65XX_LED_PMIC_NLED_ISINK0,  
  691.             MT65XX_LED_PMIC_NLED_ISINK1,  
  692.             MT65XX_LED_PMIC_NLED_ISINK2,  
  693.             MT65XX_LED_PMIC_NLED_ISINK3,  
  694.             MT65XX_LED_PMIC_NLED_ISINK01  
  695.         };  
  696.           
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章