Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Sebastian Hesselbarth and committed by
Mauro Carvalho Chehab
2fd7f398 b940a221

+68
+16
Documentation/devicetree/bindings/media/gpio-ir-receiver.txt
··· 1 + Device-Tree bindings for GPIO IR receiver 2 + 3 + Required properties: 4 + - compatible: should be "gpio-ir-receiver". 5 + - gpios: specifies GPIO used for IR signal reception. 6 + 7 + Optional properties: 8 + - linux,rc-map-name: Linux specific remote control map name. 9 + 10 + Example node: 11 + 12 + ir: ir-receiver { 13 + compatible = "gpio-ir-receiver"; 14 + gpios = <&gpio0 19 1>; 15 + linux,rc-map-name = "rc-rc6-mce"; 16 + };
+52
drivers/media/rc/gpio-ir-recv.c
··· 16 16 #include <linux/interrupt.h> 17 17 #include <linux/gpio.h> 18 18 #include <linux/slab.h> 19 + #include <linux/of_gpio.h> 19 20 #include <linux/platform_device.h> 20 21 #include <linux/irq.h> 21 22 #include <media/rc-core.h> ··· 30 29 int gpio_nr; 31 30 bool active_low; 32 31 }; 32 + 33 + #ifdef CONFIG_OF 34 + /* 35 + * Translate OpenFirmware node properties into platform_data 36 + */ 37 + static int gpio_ir_recv_get_devtree_pdata(struct device *dev, 38 + struct gpio_ir_recv_platform_data *pdata) 39 + { 40 + struct device_node *np = dev->of_node; 41 + enum of_gpio_flags flags; 42 + int gpio; 43 + 44 + gpio = of_get_gpio_flags(np, 0, &flags); 45 + if (gpio < 0) { 46 + if (gpio != -EPROBE_DEFER) 47 + dev_err(dev, "Failed to get gpio flags (%d)\n", gpio); 48 + return gpio; 49 + } 50 + 51 + pdata->gpio_nr = gpio; 52 + pdata->active_low = (flags & OF_GPIO_ACTIVE_LOW); 53 + /* probe() takes care of map_name == NULL or allowed_protos == 0 */ 54 + pdata->map_name = of_get_property(np, "linux,rc-map-name", NULL); 55 + pdata->allowed_protos = 0; 56 + 57 + return 0; 58 + } 59 + 60 + static struct of_device_id gpio_ir_recv_of_match[] = { 61 + { .compatible = "gpio-ir-receiver", }, 62 + { }, 63 + }; 64 + MODULE_DEVICE_TABLE(of, gpio_ir_recv_of_match); 65 + 66 + #else /* !CONFIG_OF */ 67 + 68 + #define gpio_ir_recv_get_devtree_pdata(dev, pdata) (-ENOSYS) 69 + 70 + #endif 33 71 34 72 static irqreturn_t gpio_ir_recv_irq(int irq, void *dev_id) 35 73 { ··· 105 65 const struct gpio_ir_recv_platform_data *pdata = 106 66 pdev->dev.platform_data; 107 67 int rc; 68 + 69 + if (pdev->dev.of_node) { 70 + struct gpio_ir_recv_platform_data *dtpdata = 71 + devm_kzalloc(&pdev->dev, sizeof(*dtpdata), GFP_KERNEL); 72 + if (!dtpdata) 73 + return -ENOMEM; 74 + rc = gpio_ir_recv_get_devtree_pdata(&pdev->dev, dtpdata); 75 + if (rc) 76 + return rc; 77 + pdata = dtpdata; 78 + } 108 79 109 80 if (!pdata) 110 81 return -EINVAL; ··· 242 191 .driver = { 243 192 .name = GPIO_IR_DRIVER_NAME, 244 193 .owner = THIS_MODULE, 194 + .of_match_table = of_match_ptr(gpio_ir_recv_of_match), 245 195 #ifdef CONFIG_PM 246 196 .pm = &gpio_ir_recv_pm_ops, 247 197 #endif