【发布时间】:2022-10-23 04:39:19
【问题描述】:
我写了一个 i2c 驱动程序。
我想让它使用的 gpio 可以从设备树中配置。
我的设备树条目当前是:
&i2c1 {
clock-frequency = <100000>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c1>;
status = "okay";
...
myi2c: myi2c@43 {
compatible = "fsl,myi2c";
reg = <0x43>;
};
我想将此行添加到 myi2c 节中:
myi2c-gpios = <&gpio4 29 GPIO_ACTIVE_HIGH>;
如果我正在编写平台驱动程序,我可以看到如何做到这一点:
https://wiki.st.com/stm32mpu/wiki/How_to_control_a_GPIO_in_kernel_space:
static int gpio_init_probe(struct platform_device *pdev)
{
int i = 0;
printk("GPIO example init\n");
/* "greenled" label is matching the device tree declaration. OUT_LOW is the value at init */
green = devm_gpiod_get(&pdev->dev, "greenled", GPIOD_OUT_LOW);
但是在我的驱动程序的i2c_probe() 中,我无法访问struct platform_device *:
static int myi2c_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
如何从设备树中读取myi2c-gpios 的值并在我的 i2c 驱动程序中使用它?
【问题讨论】:
标签: kernel linux-device-driver i2c gpio device-tree