PWM emulation with GPIO, build error

Hi All,

We are planning to apply PWM emulation with GPIO feature to try on our device. We follow this page, but there are some build error I don't know how to fix it(I'm not familiar with kernel driver).
Error log are

  CC      drivers/pwm/pwm.o
drivers/pwm/pwm.c:508:3: error: 'struct class' has no member named 'dev_attrs'; did you mean 'class_attrs'?
  .dev_attrs = pwm_dev_attrs,
   ^~~~~~~~~
   class_attrs
drivers/pwm/pwm.c:508:15: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .dev_attrs = pwm_dev_attrs,
               ^~~~~~~~~~~~~
drivers/pwm/pwm.c:508:15: note: (near initialization for 'pwm_class.class_attrs')

Anyone can help me out? Thanks.

Hi All,

I fix the build error at pwm.c with following code.

  static DEVICE_ATTR(export, S_IRUGO | S_IWUSR, pwm_export_show, pwm_export_store);
  static DEVICE_ATTR(unexport, S_IWUSR, NULL, pwm_unexport_store);
  static DEVICE_ATTR(polarity, S_IRUGO | S_IWUSR, pwm_polarity_show, pwm_polarity_store);
  static DEVICE_ATTR(period_ns, S_IRUGO | S_IWUSR, pwm_period_ns_show, pwm_period_ns_store);
  static DEVICE_ATTR(duty_ns, S_IRUGO | S_IWUSR, pwm_duty_ns_show, pwm_duty_ns_store);
  static DEVICE_ATTR(tick_hz, S_IRUGO, pwm_tick_hz_show, NULL);
  static DEVICE_ATTR(run, S_IRUGO | S_IWUSR, pwm_run_show, pwm_run_store);
  
  static struct attribute *pwm_dev_attrs[] = {
      &dev_attr_export.attr,
      &dev_attr_unexport.attr,  
      &dev_attr_polarity.attr,
      &dev_attr_period_ns.attr,      
      &dev_attr_duty_ns.attr,
      &dev_attr_tick_hz.attr,
      &dev_attr_run.attr,                                    
      NULL
  };                                 
              
  static const struct attribute_group pwm_dev_attr_group = {
      .attrs = pwm_dev_attrs,
  };           
  
  static const struct attribute_group *pwm_dev_attr_groups[] = {
      &pwm_dev_attr_group,
      NULL                
  };
                              
  static struct class pwm_class = {
      .name       = "pwm",                 
      .owner      = THIS_MODULE,
      .dev_groups = pwm_dev_attr_groups,
  };

There is conflict build error.

drivers/built-in.o: In function `pwm_backlight_probe':
linux-4.9/drivers/video/backlight/pwm_bl.c:297: undefined reference to `devm_pwm_get'
linux-4.9/drivers/video/backlight/pwm_bl.c:297:(.text+0x137a4): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `devm_pwm_get'
drivers/built-in.o: In function `pwm_apply_args':
linux-4.9/./include/linux/pwm.h:605: undefined reference to `pwm_apply_state'
......
linux-4.9/./include/linux/pwm.h:407:(.text+0x13e24): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `pwm_apply_state'

Anyone can help? Thanks.

Hi all

I fix build on kernel part.
Before enable this driver, there is a folder /sys/class/pwm/pwmchip0.
After enable this driver pwmchip0 is gone? Why? Please help. Thanks.