初中生
最后登录1970-1-1
在线时间 小时
注册时间2021-2-8
|
请教:设备树设置了一个PWM引脚时,工作正常,但是设置两个PWM引脚,linux加载驱动就死机了,不明觉厉。设备树根目录和iomuxc:
- fs_pwm {
- compatible = "fs_pwm";
- pinctrl-names = "default";
- pinctrl-0 = <&pinctrl_fspwm>;
- pwm_power {
- pwm-names = "pwm_power";
- pwms = <&pwm1 0 50000>;
- };
- pwm_motor {
- pwm-names = "pwm_motor";
- pwms = <&pwm2 0 50000>;
- };
- };
复制代码
- pinctrl_fspwm:fspwmgrp {
- fsl,pins = <
- MX6UL_PAD_LCD_DATA00__PWM1_OUT 0x1b0b0 /*/pwm1&motor pwm*/
- MX6UL_PAD_LCD_DATA01__PWM2_OUT 0x1b0b0 /*/pwm1&motor pwm*/
- >;
复制代码 读取节点:
- struct pwm_device *pwm_power_dev = NULL; //定义pwm设备结构体
- struct pwm_device *pwm_motor_dev = NULL;
- /*精简版 prob函数*/
- static int pwm_power_probe_new(struct platform_device *pdev)
- {
- int ret = 0;
- struct device_node * child;
- struct device_node * child2;
- struct device *dev = &pdev->dev;
- printk("match success \n");
- child = of_get_next_child(dev->of_node, NULL);
- printk(""%s"'s child: "%s"\n", dev->of_node->full_name, child->full_name);
- printk("%s %s line %d\r\n"__FILE__, __FUNCTION__, __LINE__);
- if(NULL == child)
- {
- printk("of_get_next_child error\r\n");
- }
- if (child)
- {
- pwm_power_dev = devm_of_pwm_get(dev, child, NULL);
- if (IS_ERR(pwm_power_dev))
- {
- printk(KERN_ERR" pwm_power_dev,get pwm error!!\n");
- return -1;
- }
-
- //pwm_motor_dev = devm_of_pwm_get(dev, chile, )
- }
- else
- {
- printk(KERN_ERR" pwm_power_dev of_get_next_child error!!\n");
- return -1;
- }
- child2 = of_get_next_child(dev->of_node, child);
-
- printk(""%s"'s child2: "%s"\n", dev->of_node->full_name, child2->full_name);
- printk(""%s"'s child2: "%s"\n", dev->of_node->full_name, child2->full_name);
- printk(""%s"'s child2: "%s"\n", dev->of_node->full_name, child2->full_name);
- printk("%s %s line %d\r\n"__FILE__, __FUNCTION__, __LINE__);
- if(NULL == child2)
- {
- printk("of_get_next_child2 error\r\n");
- }
- if (child2)
- {
- if (IS_ERR(child2))
- {
- printk(KERN_ERR" of_get_next_child,child2 error!!\n");
- return -1;
- }
- printk(""%s"'s devm_of_pwm_get: "%s"\n", dev->of_node->full_name, child2->full_name);
- pwm_motor_dev = devm_of_pwm_get(dev, child2, NULL);//****这句代码死机,不再往下运行
- if (IS_ERR(pwm_motor_dev))
- {
- printk(KERN_ERR" pwm_power_dev,get pwm error!!\n");
- return -1;
- }
- }
- else
- {
- printk(KERN_ERR" pwm_power_dev of_get_next_child error!!\n");
- return -1;
- }
- printk("set pwm_power...\r\n");
- /*配置频率100KHz 占空比80%*/
- ret = pwm_config(pwm_power_dev, 1000, 5000);
- printk("ret:%d\r\n", ret);
- /*反相 频率100KHz 占空比20%*/
- ret = pwm_set_polarity(pwm_power_dev, PWM_POLARITY_INVERSED);
- printk("ret:%d\r\n", ret);
- ret = pwm_enable(pwm_power_dev);
- printk("ret:%d\r\n", ret);
- printk("set pwm_motor...\r\n");
- /*配置频率100KHz 占空比80%*/
- ret = pwm_config(pwm_motor_dev, 1000, 5000);
- printk("ret:%d\r\n", ret);
- /*反相 频率100KHz 占空比20%*/
- ret = pwm_set_polarity(pwm_motor_dev, PWM_POLARITY_NORMAL);
- printk("ret:%d\r\n", ret);
- ret = pwm_enable(pwm_motor_dev);
- printk("ret:%d\r\n", ret);
- return ret;
- }
复制代码
|
|