mtk dts文件的配置

mtk dts文件的配置

一、dts学习(注:pin 包括但不属于 gpio)
    1.gpio0 node编写方法:
        gpio0:    gpio@0    {
            pins_cmd_dat {
                pins = ;                //模式
                slew-rate = <0>;                                //方向0--in    1--out
                bias-pull-down = <11>;                            //pull使能,并且pull-down【<11>功能保留,写<00>也行】
                bias-disable;                                    //pull失能,与bias-pull-down/up冲突
                output-low;                                        //设置输出low,可以output-high【方向为out才有效】
                input-schmitt-enable = <0>;
            };
        };
    2.配置pin脚用到的
        Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\pinctrl\pinconf-generic.c
        static struct pinconf_generic_dt_params dt_params[] = {
            { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
            { "bias-high-impedance", PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0 },
            { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 },
            { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
            { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
            { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 },
            { "drive-push-pull", PIN_CONFIG_DRIVE_PUSH_PULL, 0 },
            { "drive-open-drain", PIN_CONFIG_DRIVE_OPEN_DRAIN, 0 },
            { "drive-open-source", PIN_CONFIG_DRIVE_OPEN_SOURCE, 0 },
            { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
            { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 },
            { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 },
            { "input-schmitt-enable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 1 },
            { "input-schmitt-disable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 0 },
            { "input-debounce", PIN_CONFIG_INPUT_DEBOUNCE, 0 },
            { "power-source", PIN_CONFIG_POWER_SOURCE, 0 },
            { "low-power-enable", PIN_CONFIG_LOW_POWER_MODE, 1 },
            { "low-power-disable", PIN_CONFIG_LOW_POWER_MODE, 0 },
            { "output-low", PIN_CONFIG_OUTPUT, 0, },
            { "output-high", PIN_CONFIG_OUTPUT, 1, },
            { "slew-rate", PIN_CONFIG_SLEW_RATE, 0},
        };
 
二、一个alsps的dts配置与调用示例(epl259x.c)
    1.dts配置
        1.1.mt6735m.dtsi
            /{
                alsps:als_ps@0 {                                        //alsps  node
                    compatible = "mediatek,als_ps";
                };
            };
 
        1.2.dts
            &alsps {                                                //加&表示引用别处定义的node (dtsi中 alsps node)
                pinctrl-names = "pin_default", "pin_cfg";            //
                pinctrl-0 = <&alsps_intpin_default>;                //默认配置
                pinctrl-1 = <&alsps_intpin_cfg>;                    //alsps    GPIO中断配置
                status = "okay";
            };
            &pio {
                alsps_intpin_cfg: alspspincfg {                        //alsps_intpin_cfg,在driver中pinctrl_lookup_state()用到
                    pins_cmd_dat {
                        pins = ;            //模式
                        slew-rate = <0>;                            //方向0--in    1--out
                        bias-pull-up = <00>;
                    };
                };
                alsps_intpin_default: alspsdefaultcfg {                //
                };
            };
    
    2.驱动中调用dts
        Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\misc\mediatek\alsps\epl259x\epl259x.c
        void epl_sensor_update_mode(struct i2c_client *client)
        {
            struct pinctrl *pinctrl;                                        //定义一个pin脚指针
            struct pinctrl_state *pins_default;                                //
            struct pinctrl_state *pins_cfg;
            struct platform_device *alsps_pdev = get_alsps_platformdev();    //获取平台设备alsps(dtsi的 alsps node会create as a platform device)
 
            pinctrl = devm_pinctrl_get(&alsps_pdev->dev);                    //从平台设备alsps 获取pin
            pins_default = pinctrl_lookup_state(pinctrl, "pin_default");    //获取 pin 默认配置
            pins_cfg = pinctrl_lookup_state(pinctrl, "pin_cfg");            //获取 pin 配置
            pinctrl_select_state(pinctrl, pins_cfg);                        //设置pin模式
        }
 
    3.adb 查看pin脚模式
        cat /sys/class/misc/mygpio/pin
        PIN:MODE,PULL_SEL,DIN,DOUT,PULL EN,DIR,IES,SMT
        0:    1     1          1      0       1       0   1   0
        1:  0     0          0      0       1       0   1   0
        
三、i2c的dts配置与调用示例(gt1x_tpd.c)
    1.codegen.dws与cust_i2c.dtsi
        Y:\code8\mt6737_M0_MP1_V2_84\out\target\product\len6737m_35_m0\obj\PRELOADER_OBJ\inc\cust_i2c.dtsi(codegen.dws编译生成)
        &i2c1 {                                            //i2c控制器:i2c1
            CAP_TOUCH@5D {                                //i2c从设备:CAP_TOUCH
                compatible = "mediatek,CAP_TOUCH";        //
                reg = <0x5D>;                            //i2c从设备地址
            };
            I2C_LCD_BIAS@3E {                            //i2c从设备:I2C_LCD_BIAS
                compatible = "mediatek,I2C_LCD_BIAS";
                reg = <0x3E>;
            };
        };
    2.gt1x_tpd.c
        Y:\code8\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\GT1X\gt1x_tpd.c
    
    static const struct of_device_id gt1x_dt_match[] = {
        {.compatible = "mediatek,CAP_TOUCH"},            //用于匹配平台设备"mediatek,CAP_TOUCH"与dts/dws相同
        {},
    };
    static struct i2c_driver tpd_i2c_driver = {
        .probe = tpd_i2c_probe,
        .remove = tpd_i2c_remove,
        .detect = tpd_i2c_detect,
        .driver = {
           .name = GTP_DRIVER_NAME,
           .of_match_table = gt1x_dt_match,                //用于匹配平台设备
           },
        .id_table = tpd_i2c_id,
        .address_list = (const unsigned short *)forces,
    };

四、EINT

1.mt6735m.dtsi
    /{                                                        //根节点
        bus{                                                //
            touch: touch@ {                                    //touch node 隶属于bus节点
                compatible = "mediatek,mt6735-touch",
                            "mediatek,mt6735m-touch";
                vtouch-supply = <&mt_pmic_vgp1_ldo_reg>;
            };
        }
    }
2.cust_eint.dtsi
    Y:\code8\mt6737_M0_MP1_V2_84\out\target\product\len6737m_35_m0\obj\PRELOADER_OBJ\inc\cust_eint.dtsi(codegen.dws编译生成)
        &touch {
            interrupt-parent = <&eintc>;
            interrupts = <10 IRQ_TYPE_EDGE_FALLING>;
            debounce = <10 0>;
            status = "okay";
        };
3.tp驱动中request_irq
    3.1 gt9xx_driver.c
        Y:\code8\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\GT911\gt9xx_driver.c
        static int tpd_irq_registration(void)
        {
            struct device_node *node = NULL;
            node = of_find_compatible_node(NULL, NULL, "mediatek,cap_touch");        //从dts node中获取node信息
            ...
        }
    
    3.2 gt1x_tpd.c
        Y:\code8\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\GT1X\gt1x_tpd.c
        static int tpd_irq_registration(void)
        {
            struct device_node *node = NULL;
            node = of_find_matching_node(node, touch_of_match);                        //touch_of_match是一个匹配数组,匹配node
            
            of_property_read_u32_array(node , "debounce", ints, ARRAY_SIZE(ints));    //从dws/dts获取debounce信息
            gpio_set_debounce(ints[0], ints[1]);                                    //设置debounce信息(去抖动延时)
            
            
            tpd_touch_irq = irq_of_parse_and_map(node, 0);                            //获取irq number
            
            request_irq(tpd_touch_irq, (irq_handler_t)tpd_eint_interrupt_handler,     //申请中断
                IRQF_TRIGGER_RISING, "TOUCH_PANEL-eint", NULL);(node, 0);
            ...
        }
    
        #ifdef GTP_CONFIG_OF
                enable_irq(tpd_touch_irq);            //enable_irq与disable_irq要成对存在
                
        #ifdef GTP_CONFIG_OF
                disable_irq(tpd_touch_irq);
        
        
        Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\mtk_tpd.c
        struct of_device_id touch_of_match[] = {                                    //touch_of_match是一个匹配数组
            { .compatible = "mediatek,mt6735-touch", },
            { .compatible = "mediatek,mt6580-touch", },
            { .compatible = "mediatek,mt8173-touch", },
            { .compatible = "mediatek,mt6755-touch", },
            { .compatible = "mediatek,mt6797-touch", },
            { .compatible = "mediatek,mt8163-touch", },
            {},

        };



14_2.DTS-Touch_Panel
 
 
1.dts中
    1.1. mt6735m.dtsi
        Y:\code8\mt6737_M0_MP1_V2_84\out\target\product\len6737m_35_m0\obj\PRELOADER_OBJ\inc\cust_pmic.dtsi
        touch: touch@ {
            compatible = "mediatek,mt6735-touch",
                        "mediatek,mt6735m-touch";
            vtouch-supply = <&mt_pmic_vgp1_ldo_reg>;
        };
        
1.2. Y:\code8\mt6737_M0_MP1_V2_84\out\target\product\len6737m_35_m0\obj\PRELOADER_OBJ\inc\cust_pmic.dtsi(codegen.dws生成)
    &touch {
        vtouch-supply = <&mt_pmic_vgp1_ldo_reg>;
        status = "okay";
    };

1.3.  Y:\code8\mt6737_M0_MP1_V2_84\out\target\product\len6737m_35_m0\obj\PRELOADER_OBJ\inc\cust_i2c.dtsi(codegen.dws生成)
    &i2c1 {
        cap_touch@5d {
            compatible = "mediatek,cap_touch";
            reg = <0x5d>;
        };
    };
    
1.4. Y:\code8\mt6737_M0_MP1_V2_84\out\target\product\len6737m_35_m0\obj\PRELOADER_OBJ\inc\cust_eint.dtsi(codegen.dws编译生成)
    &touch {
        interrupt-parent = <&eintc>;
        interrupts = <10 IRQ_TYPE_EDGE_FALLING>;
        debounce = <10 0>;
        status = "okay";
    };

1.5 len6737m_35_m0.dts
    &touch {
        tpd-resolution = <720 1280>;                                        //tp分辨率
        use-tpd-button = <1>;                                                //tp虚拟按键使能
        tpd-key-num = <3>;                                                    //tp虚拟按键个数
        tpd-key-local= <139 172 158 0>;                                        //3个虚拟按键参数(第4个为0)
        tpd-key-dim-local = <100 1550 100 100 360 1550 100 100 620 1550 100 100 0 0 0 0>;    //3个虚拟按键参数(第4个为0)
                                                                            //4*4(x,y,weith,height)
        tpd-max-touch-num = <5>;                                            //5点触控
        tpd-filter-enable = <1>;                                            //tp过滤器使能
        tpd-filter-pixel-density = <124>;                                    //tp过滤器像素密度
        tpd-filter-custom-prameters = <0 0 0 0 0 0 0 0 0 0 0 0>;
        tpd-filter-custom-speed = <0 0 0>;
        pinctrl-names = "default", "state_eint_as_int", "state_eint_output0", "state_eint_output1",
            "state_rst_output0", "state_rst_output1";
        pinctrl-0 = <&CTP_pins_default>;
        pinctrl-1 = <&CTP_pins_eint_as_int>;
        pinctrl-2 = <&CTP_pins_eint_output0>;
        pinctrl-3 = <&CTP_pins_eint_output1>;
        pinctrl-4 = <&CTP_pins_rst_output0>;
        pinctrl-5 = <&CTP_pins_rst_output1>;
        status = "okay";
    };
        
**2.tp驱动中
    2.1 request_irq
        Y:\code8\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\GT1X\gt1x_tpd.c
        static int tpd_irq_registration(void)
        {
            struct device_node *node = NULL;
            node = of_find_matching_node(node, touch_of_match);                        //touch_of_match是一个匹配数组**
        
        of_property_read_u32_array(node , "debounce", ints, ARRAY_SIZE(ints));    //从dws/dts获取debounce信息
        gpio_set_debounce(ints[0], ints[1]);                                    //设置debounce信息(去抖动延时)
        
        
        tpd_touch_irq = irq_of_parse_and_map(node, 0);                            //获取irq number
        
        request_irq(tpd_touch_irq, (irq_handler_t)tpd_eint_interrupt_handler,     //申请中断
            IRQF_TRIGGER_RISING, "TOUCH_PANEL-eint", NULL);(node, 0);
        ...
    }

2.2 tp获取property信息--of_property_read_u32()
    Y:\code8\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\GT1X\gt1x_tpd.c
    static int __init tpd_driver_init(void)
    {
        GTP_INFO(" Goodix touch panel driver init.");
        tpd_get_dts_info();                                                        //tp获取dts信息---tpd_get_dts_info()
        if (tpd_driver_add(&tpd_device_driver) < 0)
            GTP_INFO("add generic driver failed\n");
        return 0;
    }
    
    Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\mtk_tpd.c
    struct of_device_id touch_of_match[] = {                                    //touch_of_match是一个匹配数组
        { .compatible = "mediatek,mt6735-touch", },
        { .compatible = "mediatek,mt6580-touch", },
        { .compatible = "mediatek,mt8173-touch", },
        { .compatible = "mediatek,mt6755-touch", },
        { .compatible = "mediatek,mt6797-touch", },
        { .compatible = "mediatek,mt8163-touch", },
        {},
    };
    
    struct tpd_filter_t tpd_filter;
    struct tpd_dts_info tpd_dts_data;                                            //在对应的tpd.h中用extern修改链接属性
    void tpd_get_dts_info(void)
    {
        struct device_node *node1 = NULL;
        int key_dim_local[16], i;

        node1 = of_find_matching_node(node1, touch_of_match);                    //touch_of_match是一个匹配数组,匹配node
        if (node1) {                                                            //这是一个全局变量---tpd_dts_data(touchscreen\mediatek\tpd.h)
            of_property_read_u32(node1, "tpd-key-dim-local", &tpd_dts_data.touch_max_num);    //获取node属性---of_property_read_u32();
            of_property_read_u32(node1, "use-tpd-button", &tpd_dts_data.use_tpd_button);
            pr_info("[tpd]use-tpd-button = %d\n", tpd_dts_data.use_tpd_button);
            of_property_read_u32_array(node1, "tpd-resolution",                                //获取node属性数组---of_property_read_u32_array();
                tpd_dts_data.tpd_resolution, ARRAY_SIZE(tpd_dts_data.tpd_resolution));
            if (tpd_dts_data.use_tpd_button) {
                of_property_read_u32(node1, "tpd-key-num", &tpd_dts_data.tpd_key_num);
                of_property_read_u32_array(node1, "tpd-key-local",
                    tpd_dts_data.tpd_key_local, ARRAY_SIZE(tpd_dts_data.tpd_key_local));
                of_property_read_u32_array(node1, "tpd-key-dim-local",
                    key_dim_local, ARRAY_SIZE(key_dim_local));
                memcpy(tpd_dts_data.tpd_key_dim_local, key_dim_local, sizeof(key_dim_local));
                for (i = 0; i < 4; i++) {
                    pr_info("[tpd]key[%d].key_x = %d\n", i, tpd_dts_data.tpd_key_dim_local[i].key_x);
                    pr_info("[tpd]key[%d].key_y = %d\n", i, tpd_dts_data.tpd_key_dim_local[i].key_y);
                    pr_info("[tpd]key[%d].key_W = %d\n", i, tpd_dts_data.tpd_key_dim_local[i].key_width);
                    pr_info("[tpd]key[%d].key_H = %d\n", i, tpd_dts_data.tpd_key_dim_local[i].key_height);
                }
            }
            of_property_read_u32(node1, "tpd-filter-enable", &tpd_dts_data.touch_filter.enable);
            if (tpd_dts_data.touch_filter.enable) {
                of_property_read_u32(node1, "tpd-filter-pixel-density",
                            &tpd_dts_data.touch_filter.pixel_density);
                of_property_read_u32_array(node1, "tpd-filter-custom-prameters",
                    (u32 *)tpd_dts_data.touch_filter.W_W, ARRAY_SIZE(tpd_dts_data.touch_filter.W_W));
                of_property_read_u32_array(node1, "tpd-filter-custom-speed",
                    tpd_dts_data.touch_filter.VECLOCITY_THRESHOLD,
                    ARRAY_SIZE(tpd_dts_data.touch_filter.VECLOCITY_THRESHOLD));
            }
            memcpy(&tpd_filter, &tpd_dts_data.touch_filter, sizeof(tpd_filter));
            pr_info("[tpd]tpd-filter-enable = %d, pixel_density = %d\n",
                        tpd_filter.enable, tpd_filter.pixel_density);
        } else {
            pr_err("[tpd]%s can't find touch compatible custom node\n", __func__);
        }
    }
    
    Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\tpd.h
    struct tpd_key_dim_local {
        int key_x;
        int key_y;
        int key_width;
        int key_height;
    };
    struct tpd_filter_t {
        int enable; /*0: disable, 1: enable*/
        int pixel_density; /*XXX pixel/cm*/
        int W_W[3][4];/*filter custom setting prameters*/
        unsigned int VECLOCITY_THRESHOLD[3];/*filter speed custom settings*/
    };
    struct tpd_dts_info {
        int tpd_resolution[2];
        int touch_max_num;
        int use_tpd_button;
        int tpd_key_num;
        int tpd_key_local[4];
        struct tpd_key_dim_local tpd_key_dim_local[4];
        struct tpd_filter_t touch_filter;
    };
    extern struct tpd_dts_info tpd_dts_data;                                        //这是一个全局变量

2.3 tp获取pinctrl信息--pinctrl_lookup_state()
    len6737m_35_m0.dts
    &touch {
        ...
        pinctrl-names = "default", "state_eint_as_int", "state_eint_output0", "state_eint_output1",
            "state_rst_output0", "state_rst_output1";
        pinctrl-0 = <&CTP_pins_default>;
        pinctrl-1 = <&CTP_pins_eint_as_int>;
        pinctrl-2 = <&CTP_pins_eint_output0>;
        pinctrl-3 = <&CTP_pins_eint_output1>;
        pinctrl-4 = <&CTP_pins_rst_output0>;
        pinctrl-5 = <&CTP_pins_rst_output1>;
        status = "okay";
    };
    &pio {
        CTP_pins_default: eint0default {
        };
        CTP_pins_eint_as_int: eint@0 {
            pins_cmd_dat {
                pins = ;
                slew-rate = <0>;
                bias-disable;
            };
        };
        CTP_pins_eint_output0: eintoutput0 {
            pins_cmd_dat {
                pins = ;
                slew-rate = <1>;
                output-low;
            };
        };
        CTP_pins_eint_output1: eintoutput1 {
            pins_cmd_dat {
                pins = ;
                slew-rate = <1>;
                output-high;
            };
        };
        CTP_pins_rst_output0: rstoutput0 {
            pins_cmd_dat {
                pins = ;
                slew-rate = <1>;
                output-low;
            };
        };
        CTP_pins_rst_output1: rstoutput1 {
            pins_cmd_dat {
                pins = ;
                slew-rate = <1>;
                output-high;
            };
        };
    };    
    
    Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\mtk_tpd.c    
    int tpd_get_gpio_info(struct platform_device *pdev)
    {
        int ret;
        TPD_DEBUG("[tpd %d] mt_tpd_pinctrl+++++++++++++++++\n", pdev->id);
        pinctrl1 = devm_pinctrl_get(&pdev->dev);                                    //...
        if (IS_ERR(pinctrl1)) {
            ret = PTR_ERR(pinctrl1);
            dev_err(&pdev->dev, "fwq Cannot find touch pinctrl1!\n");
            return ret;
        }
        pins_default = pinctrl_lookup_state(pinctrl1, "default");                    //获取pinctrl属性信息---pinctrl_lookup_state()
        if (IS_ERR(pins_default)) {
            ret = PTR_ERR(pins_default);
            dev_err(&pdev->dev, "fwq Cannot find touch pinctrl default %d!\n", ret);
        }
        eint_as_int = pinctrl_lookup_state(pinctrl1, "state_eint_as_int");
        if (IS_ERR(eint_as_int)) {
            ret = PTR_ERR(eint_as_int);
            dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_eint_as_int!\n");
            return ret;
        }
        eint_output0 = pinctrl_lookup_state(pinctrl1, "state_eint_output0");
        if (IS_ERR(eint_output0)) {
            ret = PTR_ERR(eint_output0);
            dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_eint_output0!\n");
            return ret;
        }
        eint_output1 = pinctrl_lookup_state(pinctrl1, "state_eint_output1");
        if (IS_ERR(eint_output1)) {
            ret = PTR_ERR(eint_output1);
            dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_eint_output1!\n");
            return ret;
        }
        rst_output0 = pinctrl_lookup_state(pinctrl1, "state_rst_output0");
        if (IS_ERR(rst_output0)) {
            ret = PTR_ERR(rst_output0);
            dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_rst_output0!\n");
            return ret;
        }
        rst_output1 = pinctrl_lookup_state(pinctrl1, "state_rst_output1");
        if (IS_ERR(rst_output1)) {
            ret = PTR_ERR(rst_output1);
            dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_rst_output1!\n");
            return ret;
        }
        TPD_DEBUG("[tpd%d] mt_tpd_pinctrl----------\n", pdev->id);
        return 0;
    }    

2.4    LCM ON / OFF 时候---tp要suspend / resume
    Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\mtk_tpd.c
    
    static struct notifier_block tpd_fb_notifier;                    //定义一个tpd_fb_notifier变量实体
    static int tpd_probe(struct platform_device *pdev)                //platform_device与platform_driver probe
        tpd_fb_notifier.notifier_call = tpd_fb_notifier_callback;    //函数指针--指向tpd_fb_notifier_callback()函数
    }
    static void touch_resume_workqueue_callback(struct work_struct *work)
    {
        TPD_DEBUG("GTP touch_resume_workqueue_callback\n");
        g_tpd_drv->resume(NULL);
        tpd_suspend_flag = 0;
    }
    static int tpd_fb_notifier_callback(struct notifier_block *self, unsigned long event, void *data)
    {
        struct fb_event *evdata = NULL;
        int blank;
        int err = 0;

        TPD_DEBUG("tpd_fb_notifier_callback\n");

        evdata = data;
        /* If we aren't interested in this event, skip it immediately ... */
        if (event != FB_EVENT_BLANK)
            return 0;

        blank = *(int *)evdata->data;
        TPD_DMESG("fb_notify(blank=%d)\n", blank);
        switch (blank) {
        case FB_BLANK_UNBLANK:                //按power亮屏--为了不卡亮屏时间--创建了一个wakequeue来处理tp_resume
            TPD_DMESG("LCD ON Notify\n");
            if (g_tpd_drv && tpd_suspend_flag) {
                err = queue_work(touch_resume_workqueue, &touch_resume_work);
                if (!err) {
                    TPD_DMESG("start touch_resume_workqueue failed\n");
                    return err;
                }
            }
            break;
        case FB_BLANK_POWERDOWN:            //按power灭屏--touch会run suspend(休眠)
            TPD_DMESG("LCD OFF Notify\n");
            if (g_tpd_drv)
                err = cancel_work_sync(&touch_resume_work);
                if (!err)
                    TPD_DMESG("cancel touch_resume_workqueue err = %d\n", err);
                g_tpd_drv->suspend(NULL);
            tpd_suspend_flag = 1;
            break;
        default:
            break;
        }
        return 0;
    }

2.5 驱动中如何操作GPIO口输出0/1    -----    tpd_gpio_output()
    Y:\code8\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\GT1X\gt1x_tpd.c
    int gt1x_power_switch(s32 state)
    {
        tpd_gpio_output(GTP_RST_PORT, 0);
        tpd_gpio_output(GTP_INT_PORT, 0);
        ...
    }

    Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\input\touchscreen\mediatek\mtk_tpd.c
    static DEFINE_MUTEX(tpd_set_gpio_mutex);
    void tpd_gpio_as_int(int pin)
    {
        mutex_lock(&tpd_set_gpio_mutex);
        TPD_DEBUG("[tpd]tpd_gpio_as_int\n");
        if (pin == 1)
            pinctrl_select_state(pinctrl1, eint_as_int);
        mutex_unlock(&tpd_set_gpio_mutex);
    }

    void tpd_gpio_output(int pin, int level)
    {
        mutex_lock(&tpd_set_gpio_mutex);
        TPD_DEBUG("[tpd]tpd_gpio_output pin = %d, level = %d\n", pin, level);
        if (pin == 1) {
            if (level)
                pinctrl_select_state(pinctrl1, eint_output1);
            else
                pinctrl_select_state(pinctrl1, eint_output0);
        } else {
            if (level)
                pinctrl_select_state(pinctrl1, rst_output1);
            else
                pinctrl_select_state(pinctrl1, rst_output0);
        }
        mutex_unlock(&tpd_set_gpio_mutex);
    }




14_3.DTS-Vibrator
 
1.dts中
    len6737m_35_m0.dts
    /{
        vibrator0:vibrator@0 {
            compatible = "mediatek,vibrator";
            vib_timer = <25>;
            vib_limit = <9>;
            vib_vol= <5>;
        };
    }



2.Projectconfig.mk
    CUSTOM_KERNEL_VIBRATOR = vibrator
    
3.len6737m_35_m0_debug_defconfig、len6737m_35_m0_defconfig
    CONFIG_MTK_VIBRATOR=y    
    
4.vibrator 驱动中(日后遇到再补充)
    Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\misc\mediatek\vibrator\vibrator_drv.c
    Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\misc\mediatek\vibrator\mt6735\vibrator.c




14_4.DTS-SPI
 
1.dts中
    1.1 mt6735m.dtsi

    spi0:spi@1100a000 {
        compatible = "mediatek,mt6735m-spi";
        cell-index = <0>;
        spi-padmacro = <0>;
        reg = <0x1100a000 0x1000>;
        interrupts = ;
    };
    
    SPI1@0x1100A000 {
        cell-index = <0>;
        spi-padmacro = <0>;
        compatible = "mediatek,SPI1";
        reg = <0x1100A000 0x1000>;
        interrupts = <0 118 0x8>;
    };

1.2 len6737m_35_m0_debug_defconfig、len6737m_35_m0_defconfig
    CONFIG_MTK_SPI=y

1.3 codegen.dws
    GPIO口初始化设置
    GPIO66---SPI0_CKA
    GPIO67---SPI0_MIA
    GPIO68---SPI0_MOA
    //SPI0_CSB

1.4 Y:\code10\mt6737_M0_MP1_V2_84\kernel-3.18\drivers\spi\mediatek\mt6735\spi-dev.c
    static struct spi_board_info spi_board_devs[] __initdata = {
        [0] = {
        .modalias = "spi-ut",
        .bus_num = 0,                    //SPI0        控制器0
        .chip_select = 1,                //SPI0.1    从设备1
        .mode = SPI_MODE_3,                //SPI模式3
        },
    };
    static int __init spi_dev_init(void)
    {
        SPIDEV_LOG("SPI_DEV_INIT.\n");
        spi_register_board_info(spi_board_devs, ARRAY_SIZE(spi_board_devs));
        return spi_register_driver(&spi_test_driver);
    }
    static struct spi_driver spi_test_driver = {
        .driver = {
            .name = "test_spi",
            .bus = &spi_bus_type,
            .owner = THIS_MODULE,
            },
        .probe = spi_test_probe,
        .remove = spi_test_remove,
        .id_table = &spi_id_table,
    };




 
14_5.DTS-Light
 
1.dts中
    1.1 mt6735m.dtsi
    
    led0:led@0 {
        compatible = "mediatek,red";
        led_mode = <0>;                //mt65xx_led_mode 之 MT65XX_LED_MODE_NONE
        data = <1>;                    //mt65xx_led_pmic 之 MT65XX_LED_MODE_PWM
        pwm_config = <0 0 0 0 0>;
    };
    ...
    led6:led@6 {
        compatible = "mediatek,lcd-backlight";
        led_mode = <5>;                //MT65XX_LED_MODE_CUST_LCM
        data = <1>;
        pwm_config = <0 0 0 0 0>;
    };

1.2 Y:\code8\mt6737_M0_MP1_V2_84\vendor\mediatek\proprietary\bootable\bootloader\lk\target\len6737m_35_m0\cust_leds.c
    static struct cust_mt65xx_led cust_led_list[MT65XX_LED_TYPE_TOTAL] = {
        {"red",               MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
        {"green",             MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
        {"blue",              MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
        {"jogball-backlight", MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
        {"keyboard-backlight",MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
        {"button-backlight",  MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
        {"lcd-backlight",     MT65XX_LED_MODE_CUST_BLS_PWM, (int)disp_bls_set_backlight,{0}},
    };

1.3 Y:\code8\mt6737_M0_MP1_V2_84\vendor\mediatek\proprietary\bootable\bootloader\lk\target\len6737m_35_m0\inc\cust_leds.h
    enum mt65xx_led_mode
    {
        MT65XX_LED_MODE_NONE,        //0
        MT65XX_LED_MODE_PWM,        //1
        MT65XX_LED_MODE_GPIO,        //2
        MT65XX_LED_MODE_PMIC,        //3
        MT65XX_LED_MODE_CUST,        //4
        MT65XX_LED_MODE_CUST_LCM,    //5
        MT65XX_LED_MODE_CUST_BLS_PWM//6
    };
    enum mt65xx_led_pmic
    {
        MT65XX_LED_PMIC_BUTTON=0,    //0
        MT65XX_LED_PMIC_LCD,        //1
        MT65XX_LED_PMIC_LCD_ISINK,
        MT65XX_LED_PMIC_LCD_BOOST,
        MT65XX_LED_PMIC_NLED_ISINK4,
        MT65XX_LED_PMIC_NLED_ISINK5,
        MT65XX_LED_PMIC_NLED_ISINK0,
        MT65XX_LED_PMIC_NLED_ISINK1,
        MT65XX_LED_PMIC_NLED_ISINK2,
        MT65XX_LED_PMIC_NLED_ISINK3,
        MT65XX_LED_PMIC_NLED_ISINK01
    };

你可能感兴趣的:(嵌入式)