作者
彭東林
平臺
tiny4412 ADK
Linux-4.4.4
u-boot使用的U-Boot 2010.12,是友善自帶的,爲支持設備樹和uImage做了稍許改動
簡介
前面我們實現了一種設備樹下中斷的使用方法,下面介紹第二種,這種方式本質上跟前者是一樣的,使用的是platform_bus的接口。
爲了便於比較,還是以底板上面上的四個按鍵爲例分析,其中前兩個按鍵使用第二種方式,後兩個按鍵使用第一種方式。
正文
原理圖可以參考博文:基於tiny4412的Linux內核移植--- 中斷和GPIO學習(1)
下面是設備樹的改動:
diff --git a/arch/arm/boot/dts/exynos4412-tiny4412.dts b/arch/arm/boot/dts/exynos4412-tiny4412.dts
index 610202a..2e69c91
--- a/arch/arm/boot/dts/exynos4412-tiny4412.dts
+++ b/arch/arm/boot/dts/exynos4412-tiny4412.dts
@@ -, +, @@
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/usb4640/usb4640.h>
#include <dt-bindings/pwm/pwm.h>
+#include <dt-bindings/interrupt-controller/irq.h>
#include <autoconf.h> / {
@@ -, +, @@
};
};
#endif
+
+interrupt_another: interrupt_another {
+ compatible = "tiny4412,interrupt_another";
+ interrupt-parent = <&gpx3>;
+ interrupts = < IRQ_TYPE_EDGE_FALLING IRQ_TYPE_EDGE_FALLING>;
+ tiny4412,int_gpio0 = <&gpx3 GPIO_ACTIVE_HIGH>;
+ tiny4412,int_gpio1 = <&gpx3 GPIO_ACTIVE_HIGH>;
+ };
}; &rtc {
其中,interrupts屬性值的解析需要看中斷控制器gpx3在創建irq_domain時設置的回調函數exynos_eint_irqd_ops的xlate成員。以後我們再分析。而gpio屬性的值的含義則需要看gpio控制器gpx3在創建時設置的of_xlate回調函數of_gpio_simple_xlate,這個以後分析。
下面看驅動:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/interrupt.h> typedef struct
{
int gpio;
int irq;
char name[];
}int_demo_data_t; static irqreturn_t int_demo_isr_pdev(int irq, void *dev_id)
{
int_demo_data_t *data = dev_id; printk("%s enter, %s irq: %d\n", __func__, data->name, irq); return IRQ_HANDLED;
} static irqreturn_t int_demo_isr_gpio(int irq, void *dev_id)
{
int_demo_data_t *data = dev_id; printk("%s enter, %s irq: %d\n", __func__, data->name, irq);
return IRQ_HANDLED;
} static int int_demo_probe(struct platform_device *pdev) {
struct device *dev = &pdev->dev;
int irq_gpio = -;
int irq = -;
int ret = ;
int i = ;
int_demo_data_t *data = NULL; printk("%s enter.\n", __func__); if (!dev->of_node) {
dev_err(dev, "no platform data.\n");
goto err0;
} data = devm_kmalloc(dev, sizeof(*data)*, GFP_KERNEL);
if (!data) {
dev_err(dev, "no memory.\n");
goto err0;
} for (i = ; i < ; i++) {
irq = platform_get_irq(pdev, i);
sprintf(data[i].name, "tiny4412,pdev_irq_%d", i);
ret = devm_request_any_context_irq(dev, irq,
int_demo_isr_pdev, IRQF_TRIGGER_FALLING, data[i].name, data+i);
if (ret < ) {
dev_err(dev, "Unable to claim irq %d; error %d\n",
irq, ret);
goto err0;
}
printk("request irq: %d\n", irq);
} for (i = ; i < ; i++) {
sprintf(data[i+].name, "tiny4412,int_gpio%d", i);
irq_gpio = of_get_named_gpio(dev->of_node,
data[i+].name, );
if (irq_gpio < ) {
dev_err(dev, "Looking up %s property in node %s failed %d\n",
data[i].name, dev->of_node->full_name, irq_gpio);
goto err0;
} data[i+].gpio = irq_gpio; irq = gpio_to_irq(irq_gpio);
if (irq < ) {
dev_err(dev,
"Unable to get irq number for GPIO %d, error %d\n",
irq_gpio, irq);
goto err0;
} data[i+].irq = irq; printk("%s: gpio: %d ---> irq (%d)\n", __func__, irq_gpio, irq); ret = devm_request_any_context_irq(dev, irq,
int_demo_isr_gpio, IRQF_TRIGGER_FALLING, data[i+].name, data+i+);
if (ret < ) {
dev_err(dev, "Unable to claim irq %d; error %d\n",
irq, ret);
goto err0;
}
} return ; err0:
return -EINVAL;
} static int int_demo_remove(struct platform_device *pdev) { printk("%s enter.\n", __func__);
return ;
} static const struct of_device_id int_demo_dt_ids[] = {
{ .compatible = "tiny4412,interrupt_another", },
{},
}; MODULE_DEVICE_TABLE(of, int_demo_dt_ids); static struct platform_driver int_demo_driver = {
.driver = {
.name = "interrupt_another",
.of_match_table = of_match_ptr(int_demo_dt_ids),
},
.probe = int_demo_probe,
.remove = int_demo_remove,
}; static int __init int_demo_init(void)
{
int ret; ret = platform_driver_register(&int_demo_driver);
if (ret)
printk(KERN_ERR "int demo: probe failed: %d\n", ret); return ret;
}
module_init(int_demo_init); static void __exit int_demo_exit(void)
{
platform_driver_unregister(&int_demo_driver);
}
module_exit(int_demo_exit); MODULE_LICENSE("GPL");
在platform_device進行populate的時候,已經對其irq資源進行了映射,這個以後分析。
驗證
加載驅動:
[root@tiny4412 mnt]# insmod interrupt_another.ko
[ 33.330879] int_demo_probe enter.
[ 33.331896] request irq:
[ 33.332778] request irq:
[ 33.333412] int_demo_probe: gpio: ---> irq ()
[ 33.334535] int_demo_probe: gpio: ---> irq ()
依次按鍵,由於沒有加消抖處理,所以依次按鍵可能會觸發多次中斷
[root@tiny4412 mnt]# [ 1244.082303] int_demo_isr_pdev enter, tiny4412,pdev_irq_0 irq:
[ 1244.229761] int_demo_isr_pdev enter, tiny4412,pdev_irq_0 irq:
[ 1245.129735] int_demo_isr_pdev enter, tiny4412,pdev_irq_1 irq:
[ 1245.283928] int_demo_isr_pdev enter, tiny4412,pdev_irq_1 irq:
[ 1246.269231] int_demo_isr_gpio enter, tiny4412,int_gpio0 irq:
[ 1246.476101] int_demo_isr_gpio enter, tiny4412,int_gpio0 irq:
[ 1247.769903] int_demo_isr_gpio enter, tiny4412,int_gpio1 irq:
[ 1248.034338] int_demo_isr_gpio enter, tiny4412,int_gpio1 irq:
[ 1248.035396] int_demo_isr_gpio enter, tiny4412,int_gpio1 irq:
[ 1248.035858] int_demo_isr_gpio enter, tiny4412,int_gpio1 irq:
[ 1248.036218] int_demo_isr_gpio enter, tiny4412,int_gpio1 irq:
我們再看看系統中斷資源註冊情況
[root@tiny4412 mnt]# cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3
: GIC Edge mct_comp_irq
: GIC Edge MCT
: PMU Edge s3c2410-rtc alarm
: PMU Edge s3c2410-rtc tick
: GIC Edge mmc0
: GIC Edge .hsotg, .hsotg, dwc2_hsotg:usb1
: GIC Edge ehci_hcd:usb2, ohci_hcd:usb3
: GIC Edge .serial
: GIC Edge .i2c
: GIC Edge .pdma
: GIC Edge .pdma
: GIC Edge .mdma
: GIC Edge .pinctrl
: GIC Edge .pinctrl
: COMBINER Edge .pinctrl
: GIC Edge 106e0000.pinctrl
: GIC Edge dw-mci
103: 8 0 0 0 exynos4210_wkup_irq_chip 2 Edge tiny4412,pdev_irq_0
104: 4 0 0 0 exynos4210_wkup_irq_chip 3 Edge tiny4412,pdev_irq_1
: exynos4210_wkup_irq_chip Edge mma7660
: exynos_gpio_irq_chip Edge .sdhci cd
107: 6 0 0 0 exynos4210_wkup_irq_chip 4 Edge tiny4412,int_gpio0
108: 9 0 0 0 exynos4210_wkup_irq_chip 5 Edge tiny4412,int_gpio1
IPI0: CPU wakeup interrupts
IPI1: Timer broadcast interrupts
IPI2: Rescheduling interrupts
IPI3: Function call interrupts
IPI4: Single function call interrupts
IPI5: CPU stop interrupts
IPI6: IRQ work interrupts
IPI7: completion interrupts
未完待續...