Hi all,
I am trying to find a way to get PWM on spare GPIO pins using sysfs controls. I could not find any up to date documentation or repositories that work with the current 24.10 compilation from source.
I have found the only official documentation is this PWM emulation page from 2018, but I can't figure out the vague and probably outdated instructions. (as far as I know the way the kernel handles GPIO has changed a few years ago so it is guaranteed not to work)
I have tried this soft_pwm repo that seems to be more recent by adding it and enabling in menuconfig only to get a bunch of errors
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:52:44: error: format '%s' expects argument of type 'char *', but argument 4 has type 'unsigned int' [-Werror=format=]
52 | return scnprintf(buf, PAGE_SIZE, "%s\n", desc->duty_cycle);
| ~^ ~~~~~~~~~~~~~~~~
| | |
| char * unsigned int
| %d
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c: In function 'show_enable':
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:73:44: error: format '%s' expects argument of type 'char *', but argument 4 has type 'unsigned int' [-Werror=format=]
73 | return scnprintf(buf, PAGE_SIZE, "%s\n", desc->enable);
| ~^ ~~~~~~~~~~~~
| | |
| char * unsigned int
| %d
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c: In function 'store_enable':
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:92:11: error: implicit declaration of function '__gpio_set_value'; did you mean 'gpio_set_value'? [-Werror=implicit-function-declaration]
92 | __gpio_set_value(desc->gpio,0);
| ^~~~~~~~~~~~~~~~
| gpio_set_value
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c: In function 'show_period':
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:103:44: error: format '%s' expects argument of type 'char *', but argument 4 has type 'unsigned int' [-Werror=format=]
103 | return scnprintf(buf, PAGE_SIZE, "%s\n", desc->enable);
| ~^ ~~~~~~~~~~~~
| | |
| char * unsigned int
| %d
In file included from ./include/linux/kobject.h:20,
from ./include/linux/module.h:21,
from /home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:13:
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c: At top level:
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:205:22: error: initialization of 'ssize_t (*)(const struct class *, const struct class_attribute *, const char *, size_t)' {aka 'int (*)(const struct class *, const struct class_attribute *, const char *, unsigned int)'} from incompatible pointer type 'ssize_t (*)(struct class *, struct class_attribute *, const char *, size_t)' {aka 'int (*)(struct class *, struct class_attribute *, const char *, unsigned int)'} [-Werror=incompatible-pointer-types]
205 | static CLASS_ATTR_WO(export);
| ^~~~~~
./include/linux/sysfs.h:135:19: note: in definition of macro '__ATTR_WO'
135 | .store = _name##_store, \
| ^~~~~
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:205:8: note: in expansion of macro 'CLASS_ATTR_WO'
205 | static CLASS_ATTR_WO(export);
| ^~~~~~~~~~~~~
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:205:22: note: (near initialization for 'class_attr_export.store')
205 | static CLASS_ATTR_WO(export);
| ^~~~~~
./include/linux/sysfs.h:135:19: note: in definition of macro '__ATTR_WO'
135 | .store = _name##_store, \
| ^~~~~
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:205:8: note: in expansion of macro 'CLASS_ATTR_WO'
205 | static CLASS_ATTR_WO(export);
| ^~~~~~~~~~~~~
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:206:22: error: initialization of 'ssize_t (*)(const struct class *, const struct class_attribute *, const char *, size_t)' {aka 'int (*)(const struct class *, const struct class_attribute *, const char *, unsigned int)'} from incompatible pointer type 'ssize_t (*)(struct class *, struct class_attribute *, const char *, size_t)' {aka 'int (*)(struct class *, struct class_attribute *, const char *, unsigned int)'} [-Werror=incompatible-pointer-types]
206 | static CLASS_ATTR_WO(unexport);
| ^~~~~~~~
./include/linux/sysfs.h:135:19: note: in definition of macro '__ATTR_WO'
135 | .store = _name##_store, \
| ^~~~~
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:206:8: note: in expansion of macro 'CLASS_ATTR_WO'
206 | static CLASS_ATTR_WO(unexport);
| ^~~~~~~~~~~~~
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:206:22: note: (near initialization for 'class_attr_unexport.store')
206 | static CLASS_ATTR_WO(unexport);
| ^~~~~~~~
./include/linux/sysfs.h:135:19: note: in definition of macro '__ATTR_WO'
135 | .store = _name##_store, \
| ^~~~~
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:206:8: note: in expansion of macro 'CLASS_ATTR_WO'
206 | static CLASS_ATTR_WO(unexport);
| ^~~~~~~~~~~~~
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:220:4: error: 'struct class' has no member named 'owner'
220 | .owner = THIS_MODULE,
| ^~~~~
In file included from ./include/linux/linkage.h:7,
from ./include/linux/kernel.h:18,
from /home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:12:
./include/linux/export.h:29:21: error: initialization of 'const struct attribute_group **' from incompatible pointer type 'struct module *' [-Werror=incompatible-pointer-types]
29 | #define THIS_MODULE (&__this_module)
| ^
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:220:18: note: in expansion of macro 'THIS_MODULE'
220 | .owner = THIS_MODULE,
| ^~~~~~~~~~~
./include/linux/export.h:29:21: note: (near initialization for 'soft_pwm_class.class_groups')
29 | #define THIS_MODULE (&__this_module)
| ^
/home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.c:220:18: note: in expansion of macro 'THIS_MODULE'
220 | .owner = THIS_MODULE,
| ^~~~~~~~~~~
cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:243: /home/gerge/Downloads/wrt_hack/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/soft_pwm/soft_pwm.o] Error 1
No idea if I am even doing it right as again zero instructions provided and I don't even know if it is compatible with 24.10
I am not a kernel dev, all I know is from following the helloworld guide. I have tried searching the forum for PWM related content, but nothing came up other than a few compilation errors of the above mentioned PWM emulation.
Please help