我有一个Raspberry Pi 3B,在pwmchip0(pwm0 / pwm1)上有两个电机。 我通过sysfs成功控制了pwm芯片,但现在我想将其放入内核模块中。
我看到了<linux/pwm.h>
,并想使用pwm_get()
,pwm_put()
和pwm_config()
。
我找到了this post,并且还浏览了LXR上的示例,但是它对我没有太大帮助。一般来说,我对设备树和内核编程非常陌生。
我无法请求pwm_device(ERR = 1),但无法解决问题。
我已经创建了一个设备树覆盖,但是没起作用:/
/dts-v1/;
/include/ "bcm283x.dtsi"
/ {
compatible = "brcm,bcm2708";
motor-left-pwm {
compatible = "motor-left";
pwms = <&pwm 0 1000000 0>;
pinctrl-names = "default";
};
};
我尝试添加静态查找表:
static struct pwm_lookup crc_pwm_lookup[] = {
PWM_LOOKUP("pwmchip0", 0, "0000:00:02.0", "pwm_left", 0>
PWM_LOOKUP("pwmchip0", 1, "0000:00:02.0", "pwm_right", >
};
pwm_add_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
但最终结果是:
WARNING: "pwm_add_table" [/home/josh/drivers/motor/motor.ko] undefined!
insmod: ERROR: could not insert module /motor.ko: Unknown symbol in module
我在某处阅读,这意味着我无法调用此函数:/
答案 0 :(得分:0)
是的!昨天晚上我想通了!
我想我根本不了解设备树和覆盖层。 但是我在pwm-2chan.dts的帮助下解决了这个问题:
/dts-v1/;
/plugin/;
/ {
fragment@0 {
target = <&soc>;
__overlay__ {
motorpwm {
compatible = "motor";
pwms = <&pwm 0 1000000>;
pinctrl-names = "default";
pinctrl-0 = <&pwm0_gpio18>;
};
};
};
fragment@1 {
target = <&pwm>;
frag1: __overlay__ {
status = "okay";
};
};
};
然后将检测您的驱动程序:
static int my_probe(struct platform_device *pdev)
{
printk("Probed");
printk("Requesting PWM");
pwm_left = pwm_get(&pdev->dev, NULL);
if (IS_ERR(pwm_left)){
printk("Requesting PWM failed %d", ERR_CAST(pwm_left));
return -EIO;
}
printk("Requested PWM");
return 0;
}
static int my_remove(struct platform_device *dev)
{
printk("Removed");
return 0;
}
static struct of_device_id my_match_table[] = {
{
.compatible = "motor",
},
{},
};
MODULE_DEVICE_TABLE(of, my_match_table);
static struct platform_driver my_platform_driver = {
.probe = my_probe,
.remove = my_remove,
.driver = {
.name = "motor",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(my_match_table),
},
};