想通过 tiny200 学习一下驱动,我知道官方已经支持 gpio-leds 的方式配置 GPIO 了,自己折腾。。。
这个是我的 device tree 配置:
// SPDX-License-Identifier: (GPL-2.0+ OR X11)
/*
* Copyright 2018 Icenowy Zheng <icenowy@aosc.io>
*/
/dts-v1/;
#include "suniv-f1c100s.dtsi"
#include <dt-bindings/gpio/gpio.h>
/ {
model = "Lichee Pi Nano";
compatible = "licheepi,licheepi-nano", "allwinner,suniv-f1c100s",
"allwinner,suniv";
aliases {
serial0 = &uart0;
spi0 = &spi0;
};
chosen {
stdout-path = "serial0:115200n8";
};
panel: panel {
compatible = "qiaodian,qd43003c0-40", "simple-panel";
#address-cells = <1>;
#size-cells = <0>;
enable-gpios = <&pio 4 6 GPIO_ACTIVE_HIGH>;
port@0 {
reg = <0>;
#address-cells = <1>;
#size-cells = <0>;
panel_input: endpoint@0 {
reg = <0>;
remote-endpoint = <&tcon0_out_lcd>;
};
};
};
reg_vcc3v3: vcc3v3 {
compatible = "regulator-fixed";
regulator-name = "vcc3v3";
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
};
tiny200 {
compatible = "hello";
beep-gpio = <&pio 4 5 GPIO_ACTIVE_HIGH>; /* PE5 */
beep2-gpio = <&pio 0 0 GPIO_ACTIVE_HIGH>; /* PA0 */
status = "okay";
};
};
&de {
status = "okay";
};
&mmc0 {
vmmc-supply = <®_vcc3v3>;
bus-width = <4>;
broken-cd;
status = "okay";
};
&otg_sram {
status = "okay";
};
&spi0 {
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins_a>;
status = "okay";
spi-max-frequency = <50000000>;
flash: w25q128@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "winbond,w25q128", "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <50000000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "u-boot";
reg = <0x000000 0x100000>;
read-only;
};
partition@100000 {
label = "dtb";
reg = <0x100000 0x10000>;
read-only;
};
partition@110000 {
label = "kernel";
reg = <0x110000 0x400000>;
read-only;
};
partition@510000 {
label = "rootfs";
reg = <0x510000 0xAF0000>;
};
};
};
};
&tcon0 {
pinctrl-names = "default";
pinctrl-0 = <&lcd_rgb666_pins>;
status = "okay";
};
&tcon0_out {
tcon0_out_lcd: endpoint@0 {
reg = <0>;
remote-endpoint = <&panel_input>;
};
};
&uart0 {
pinctrl-names = "default";
pinctrl-0 = <&uart0_pins_a>;
status = "okay";
};
&usb_otg {
dr_mode = "otg";
status = "okay";
};
&usbphy {
usb0_id_det-gpio = <&pio 4 2 GPIO_ACTIVE_HIGH>; /* PE2 */
status = "okay";
};
新增了:
tiny200 {
compatible = "hello";
beep-gpio = <&pio 4 5 GPIO_ACTIVE_HIGH>; /* PE5 */
beep2-gpio = <&pio 0 0 GPIO_ACTIVE_HIGH>; /* PA0 */
status = "okay";
};
这是我的驱动代码,of_get_named_gpio 返回总是返回 -517(EPROBE_DEFER)
printk(KERN_INFO "node name %s\n", node->name);
printk(KERN_INFO "node full_name %s\n", node->full_name);
tmp = of_find_property(node, "compatible", NULL);
if (!tmp) {
printk(KERN_ALERT "[Error] of_find_property(node, \"compatible\", NULL) err!!\n");
return -EINVAL;
}
printk(KERN_INFO "property name %s value %s\n", tmp->name, tmp->value);
tmp = of_find_property(node, "status", NULL);
if (!tmp) {
printk(KERN_ALERT "[Error] of_find_property(node, \"compatible\", NULL) err!!\n");
return -EINVAL;
}
printk(KERN_INFO "property name %s value %s\n", tmp->name, tmp->value);
//
ret = gpio_is_valid(133);
printk(KERN_INFO "gpio_is_valid(133) ret %d\n", ret);
tiny200_priv.beep[0] = of_get_named_gpio(node, "beep2-gpio", 0);
printk(KERN_INFO "tiny200_priv.beep[0] %d\n", tiny200_priv.beep[0]);
ret = gpio_is_valid(tiny200_priv.beep[0]);
printk(KERN_INFO "gpio_is_valid(tiny200_priv.beep[0]) ret %d\n", ret);
if(!ret)
{
printk(KERN_ALERT "[Error] wrong beep-gpio from dts!!\n");
return -EINVAL;
}
这是 log 打印:
[ 0.185362] node name tiny200
[ 0.185388] node full_name tiny200
[ 0.185405] property name compatible value hello
[ 0.185422] property name status value okay
[ 0.185436] gpio_is_valid(133) ret 1
[ 0.185484] tiny200_priv.beep[0] -517
[ 0.185502] gpio_is_valid(tiny200_priv.beep[0]) ret 0
[ 0.185516] [Error] wrong beep-gpio from dts!!
[ 0.185575] hello_driver_name: probe of tiny200 failed with error -22
哪位大神能指点一下,谢谢!
最近编辑记录 xiao.huang (2020-02-06 23:49:28)
离线
我没写在DTS中,直接系统起来在/sys/class/gpio中初始化
离线