diff options
author | Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> | 2013-02-08 16:47:30 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2013-02-13 14:40:23 -0500 |
commit | 2fd7f398d32a0d490d28de75b613263502918e51 (patch) | |
tree | b11b789538b8cdb40db3b69c92d8b7bb8fcee359 /drivers/media | |
parent | b940a2219c9d59171339cc4510462154934fcb49 (diff) |
[media] media: rc: gpio-ir-recv: add support for device tree parsing
This patch adds device tree parsing for gpio_ir_recv platform_data and
the mandatory binding documentation. It basically follows what we already
have for e.g. gpio_keys. All required device tree properties are OS
independent but an optional property allows linux specific support for rc
maps.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/rc/gpio-ir-recv.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/drivers/media/rc/gpio-ir-recv.c b/drivers/media/rc/gpio-ir-recv.c index 382f362b69af..8b82ae9bd686 100644 --- a/drivers/media/rc/gpio-ir-recv.c +++ b/drivers/media/rc/gpio-ir-recv.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/interrupt.h> | 16 | #include <linux/interrupt.h> |
17 | #include <linux/gpio.h> | 17 | #include <linux/gpio.h> |
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/of_gpio.h> | ||
19 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
20 | #include <linux/irq.h> | 21 | #include <linux/irq.h> |
21 | #include <media/rc-core.h> | 22 | #include <media/rc-core.h> |
@@ -30,6 +31,45 @@ struct gpio_rc_dev { | |||
30 | bool active_low; | 31 | bool active_low; |
31 | }; | 32 | }; |
32 | 33 | ||
34 | #ifdef CONFIG_OF | ||
35 | /* | ||
36 | * Translate OpenFirmware node properties into platform_data | ||
37 | */ | ||
38 | static int gpio_ir_recv_get_devtree_pdata(struct device *dev, | ||
39 | struct gpio_ir_recv_platform_data *pdata) | ||
40 | { | ||
41 | struct device_node *np = dev->of_node; | ||
42 | enum of_gpio_flags flags; | ||
43 | int gpio; | ||
44 | |||
45 | gpio = of_get_gpio_flags(np, 0, &flags); | ||
46 | if (gpio < 0) { | ||
47 | if (gpio != -EPROBE_DEFER) | ||
48 | dev_err(dev, "Failed to get gpio flags (%d)\n", gpio); | ||
49 | return gpio; | ||
50 | } | ||
51 | |||
52 | pdata->gpio_nr = gpio; | ||
53 | pdata->active_low = (flags & OF_GPIO_ACTIVE_LOW); | ||
54 | /* probe() takes care of map_name == NULL or allowed_protos == 0 */ | ||
55 | pdata->map_name = of_get_property(np, "linux,rc-map-name", NULL); | ||
56 | pdata->allowed_protos = 0; | ||
57 | |||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | static struct of_device_id gpio_ir_recv_of_match[] = { | ||
62 | { .compatible = "gpio-ir-receiver", }, | ||
63 | { }, | ||
64 | }; | ||
65 | MODULE_DEVICE_TABLE(of, gpio_ir_recv_of_match); | ||
66 | |||
67 | #else /* !CONFIG_OF */ | ||
68 | |||
69 | #define gpio_ir_recv_get_devtree_pdata(dev, pdata) (-ENOSYS) | ||
70 | |||
71 | #endif | ||
72 | |||
33 | static irqreturn_t gpio_ir_recv_irq(int irq, void *dev_id) | 73 | static irqreturn_t gpio_ir_recv_irq(int irq, void *dev_id) |
34 | { | 74 | { |
35 | struct gpio_rc_dev *gpio_dev = dev_id; | 75 | struct gpio_rc_dev *gpio_dev = dev_id; |
@@ -66,6 +106,17 @@ static int gpio_ir_recv_probe(struct platform_device *pdev) | |||
66 | pdev->dev.platform_data; | 106 | pdev->dev.platform_data; |
67 | int rc; | 107 | int rc; |
68 | 108 | ||
109 | if (pdev->dev.of_node) { | ||
110 | struct gpio_ir_recv_platform_data *dtpdata = | ||
111 | devm_kzalloc(&pdev->dev, sizeof(*dtpdata), GFP_KERNEL); | ||
112 | if (!dtpdata) | ||
113 | return -ENOMEM; | ||
114 | rc = gpio_ir_recv_get_devtree_pdata(&pdev->dev, dtpdata); | ||
115 | if (rc) | ||
116 | return rc; | ||
117 | pdata = dtpdata; | ||
118 | } | ||
119 | |||
69 | if (!pdata) | 120 | if (!pdata) |
70 | return -EINVAL; | 121 | return -EINVAL; |
71 | 122 | ||
@@ -191,6 +242,7 @@ static struct platform_driver gpio_ir_recv_driver = { | |||
191 | .driver = { | 242 | .driver = { |
192 | .name = GPIO_IR_DRIVER_NAME, | 243 | .name = GPIO_IR_DRIVER_NAME, |
193 | .owner = THIS_MODULE, | 244 | .owner = THIS_MODULE, |
245 | .of_match_table = of_match_ptr(gpio_ir_recv_of_match), | ||
194 | #ifdef CONFIG_PM | 246 | #ifdef CONFIG_PM |
195 | .pm = &gpio_ir_recv_pm_ops, | 247 | .pm = &gpio_ir_recv_pm_ops, |
196 | #endif | 248 | #endif |