【问题标题】:Example of use pwm_get() in linux kernel在 linux 内核中使用 pwm_get() 的示例
【发布时间】:2017-05-07 05:12:11
【问题描述】:

我想尝试在我的 Rasperry Pi 的 linux 内核模块中使用 PWM。我已经通过 SYSFS 接口成功启用了 PWM。 对于内核模块文档中 pwm 的使用说明:

新用户应该使用 pwm_get() 函数并将 消费者设备或消费者名称。 pwm_put() 用于释放 PWM 设备。这些函数的托管变体 devm_pwm_get() 和 devm_pwm_put(),也存在。

pwm_get 函数如下所示:

/**
 * pwm_get() - look up and request a PWM device
 * @dev: device for PWM consumer
 * @con_id: consumer name
....
 */
struct pwm_device *pwm_get(struct device *dev, const char *con_id)

在哪里可以找到 dev 和 con_id?我怀疑它们应该在设备树中定义,但这只是一种怀疑。

【问题讨论】:

  • 使用LXR 在内核中搜索您要查找的任何标识符或字符串。
  • 您必须通过 a) 设备树或 b) ACPI(但是,它会以另一种方式完成)或 c) 静态查找表来提供资源。

标签: linux-kernel kernel-module pwm


【解决方案1】:

pwm_get() 的一个示例可在Intel PWM backlight panel 驱动程序中找到。
在这里,它被用于通过其名称获取 PWM 源。

/* Get the PWM chip for backlight control */
panel->backlight.pwm = pwm_get(dev->dev, "pwm_backlight");

PWM 提供程序本身已定义 here...

/* PWM consumed by the Intel GFX */
static struct pwm_lookup crc_pwm_lookup[] = {
        PWM_LOOKUP("crystal_cove_pwm", 0, "0000:00:02.0", "pwm_backlight", 0, PWM_POLARITY_NORMAL),
};

...并初始化 here.

/* Add lookup table for crc-pwm */
pwm_add_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));

pwm-beeperpwm_get() 的另一个示例。

beeper->pwm = pwm_get(&pdev->dev, NULL);

设备树中存在对应的条目here

buzzer {
        compatible = "pwm-beeper";
        pwms = <&pwm 0 1000000 0>;
        pinctrl-names = "default";
        pinctrl-0 = <&pwm0_out>;
};

inline documentation of pwm_get() 描述了它的两种使用方式。

/**
* pwm_get() - look up and request a PWM device
* @dev: device for PWM consumer
* @con_id: consumer name
*
* Lookup is first attempted using DT. If the device was not instantiated from
* a device tree, a PWM chip and a relative index is looked up via a table
* supplied by board setup code (see pwm_add_table()).
*
* Once a PWM chip has been found the specified PWM device will be requested
* and is ready to be used.
*
* Returns: A pointer to the requested PWM device or an ERR_PTR()-encoded
* error code on failure.
*/

【讨论】:

    猜你喜欢
    • 2011-01-07
    • 2017-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-26
    • 1970-01-01
    • 1970-01-01
    • 2016-10-26
    相关资源
    最近更新 更多