野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 25238|回复: 0

[求助] 【请教linux驱动】【pwm子系统】【devm_of_pwm_get】【卡死】

[复制链接]
发表于 2021-5-13 18:29:01 | 显示全部楼层 |阅读模式
请教:设备树设置了一个PWM引脚时,工作正常,但是设置两个PWM引脚,linux加载驱动就死机了,不明觉厉。设备树根目录和iomuxc:

  1.         fs_pwm {
  2.                 compatible = "fs_pwm";
  3.                 pinctrl-names = "default";
  4.                 pinctrl-0 = <&pinctrl_fspwm>;
  5.                 pwm_power {
  6.                         pwm-names = "pwm_power";
  7.                         pwms =         <&pwm1 0 50000>;
  8.                 };
  9.                 pwm_motor {
  10.                         pwm-names = "pwm_motor";
  11.                         pwms =         <&pwm2 0 50000>;
  12.                 };

  13.         };
复制代码

  1.         pinctrl_fspwm:fspwmgrp {
  2.                 fsl,pins = <
  3.                         MX6UL_PAD_LCD_DATA00__PWM1_OUT          0x1b0b0        /*/pwm1&motor pwm*/       
  4.                         MX6UL_PAD_LCD_DATA01__PWM2_OUT          0x1b0b0        /*/pwm1&motor pwm*/       
  5.                 >;
复制代码
读取节点:


  1. struct pwm_device        *pwm_power_dev = NULL;  //定义pwm设备结构体
  2. struct pwm_device   *pwm_motor_dev = NULL;
  3. /*精简版 prob函数*/
  4. static int pwm_power_probe_new(struct platform_device *pdev)
  5. {
  6.         int ret = 0;
  7.         struct device_node * child;
  8.         struct device_node * child2;
  9.         struct device *dev = &pdev->dev;
  10.         printk("match success \n");

  11.         child = of_get_next_child(dev->of_node, NULL);
  12.     printk(""%s"'s child: "%s"\n", dev->of_node->full_name, child->full_name);
  13.     printk("%s %s line %d\r\n"__FILE__, __FUNCTION__, __LINE__);
  14.     if(NULL == child)
  15.     {
  16.         printk("of_get_next_child error\r\n");
  17.     }
  18.         if (child)
  19.         {
  20.                 pwm_power_dev = devm_of_pwm_get(dev, child, NULL);
  21.                 if (IS_ERR(pwm_power_dev))
  22.                 {
  23.                         printk(KERN_ERR" pwm_power_dev,get pwm  error!!\n");
  24.                         return -1;
  25.                 }
  26.         
  27.         //pwm_motor_dev = devm_of_pwm_get(dev, chile, )
  28.         }
  29.         else
  30.         {
  31.                 printk(KERN_ERR" pwm_power_dev of_get_next_child  error!!\n");
  32.                 return -1;
  33.         }

  34.         child2 = of_get_next_child(dev->of_node, child);
  35.    
  36.     printk(""%s"'s child2: "%s"\n", dev->of_node->full_name, child2->full_name);
  37.     printk(""%s"'s child2: "%s"\n", dev->of_node->full_name, child2->full_name);
  38.     printk(""%s"'s child2: "%s"\n", dev->of_node->full_name, child2->full_name);
  39.     printk("%s %s line %d\r\n"__FILE__, __FUNCTION__, __LINE__);
  40.     if(NULL == child2)
  41.     {
  42.         printk("of_get_next_child2 error\r\n");
  43.     }
  44.         if (child2)
  45.         {
  46.         if (IS_ERR(child2))
  47.                 {
  48.                         printk(KERN_ERR" of_get_next_child,child2  error!!\n");
  49.                         return -1;
  50.                 }

  51.         printk(""%s"'s devm_of_pwm_get: "%s"\n", dev->of_node->full_name, child2->full_name);
  52. pwm_motor_dev = devm_of_pwm_get(dev, child2, NULL);//****这句代码死机,不再往下运行

  53.                 if (IS_ERR(pwm_motor_dev))
  54.                 {
  55.                         printk(KERN_ERR" pwm_power_dev,get pwm  error!!\n");
  56.                         return -1;
  57.                 }
  58.         }
  59.         else
  60.         {
  61.                 printk(KERN_ERR" pwm_power_dev of_get_next_child  error!!\n");
  62.                 return -1;
  63.         }

  64.     printk("set pwm_power...\r\n");

  65.         /*配置频率100KHz 占空比80%*/
  66.         ret = pwm_config(pwm_power_dev, 1000, 5000);
  67.     printk("ret:%d\r\n", ret);
  68.         /*反相 频率100KHz 占空比20%*/
  69.         ret = pwm_set_polarity(pwm_power_dev, PWM_POLARITY_INVERSED);
  70.     printk("ret:%d\r\n", ret);
  71.         ret = pwm_enable(pwm_power_dev);
  72.     printk("ret:%d\r\n", ret);

  73.     printk("set pwm_motor...\r\n");
  74.         /*配置频率100KHz 占空比80%*/
  75.         ret = pwm_config(pwm_motor_dev, 1000, 5000);
  76.     printk("ret:%d\r\n", ret);
  77.         /*反相 频率100KHz 占空比20%*/
  78.         ret = pwm_set_polarity(pwm_motor_dev, PWM_POLARITY_NORMAL);
  79.     printk("ret:%d\r\n", ret);
  80.         ret = pwm_enable(pwm_motor_dev);
  81.     printk("ret:%d\r\n", ret);

  82.         return ret;
  83. }
复制代码




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-11-23 15:43 , Processed in 0.032769 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表