资料下载
coding无法使用浏览器打开,必须用git工具下载:
代码语言:javascript复制git clone https://e.coding.net/weidongshan/linux/doc_and_source_for_drivers.git
视频观看
百问网驱动大全
IMX6ULL的GPIO驱动源码分析
参考资料:
- Linux 4.x内核文档
- Linux-4.9.88Documentationgpio
- Linux-4.9.88Documentationdevicetreebindingsgpiogpio.txt
- Linux-4.9.88driversgpiogpio-mxc.c
- Linux-4.9.88archarmbootdtsimx6ull.dtsi
1. 设备树
Linux-4.9.88archarmbootdtsimx6ull.dtsi:
代码语言:javascript复制aliases {
can0 = &flexcan1;
can1 = &flexcan2;
ethernet0 = &fec1;
ethernet1 = &fec2;
gpio0 = &gpio1;
};
gpio1: gpio@0209c000 {
compatible = "fsl,imx6ul-gpio", "fsl,imx35-gpio";
reg = <0x0209c000 0x4000>;
interrupts = <GIC_SPI 66 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>;
gpio-controller;
#gpio-cells = <2>;
interrupt-controller;
#interrupt-cells = <2>;
};
GPIO控制器的设备树中,有两项是必须的:
- gpio-controller : 表明这是一个GPIO控制器
- gpio-cells : 指定使用多少个cell(就是整数)来描述一个引脚
当解析设备节点中的GPIO信息时,需要用到上面的属性。
比如下面的led-gpios
,在#gpio-cells = <2>
的情况下,它表示的引脚数量是1。
myled {
compatible = "100ask,leddrv";
led-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>;
};
2. 驱动程序
Linux-4.9.88driversgpiogpio-mxc.c
2.1 分配gpio_chip
代码语言:javascript复制static int mxc_gpio_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct mxc_gpio_port *port;
struct resource *iores;
int irq_base = 0;
int err;
mxc_gpio_get_hw(pdev);
port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
if (!port)
return -ENOMEM;
2.2 设置gpio_chip
2.3 注册gpio_chip
代码语言:javascript复制 err = devm_gpiochip_add_data(&pdev->dev, &port->gc, port);
if (err)
goto out_bgio;
代码语言:javascript复制err = devm_gpiochip_add_data(&pdev->dev, &port->gc, port);
if (err)
goto out_bgio;