ar71xx: add LED driver NU801
[openwrt/openwrt.git] / target / linux / ar71xx / patches-4.1 / 451-gpio-74x164-improve-platform-device-support.patch
1 --- a/drivers/gpio/gpio-74x164.c
2 +++ b/drivers/gpio/gpio-74x164.c
3 @@ -12,6 +12,7 @@
4 #include <linux/init.h>
5 #include <linux/mutex.h>
6 #include <linux/spi/spi.h>
7 +#include <linux/spi/74x164.h>
8 #include <linux/gpio.h>
9 #include <linux/of_gpio.h>
10 #include <linux/slab.h>
11 @@ -107,8 +108,18 @@ static int gen_74x164_direction_output(s
12 static int gen_74x164_probe(struct spi_device *spi)
13 {
14 struct gen_74x164_chip *chip;
15 + struct gen_74x164_chip_platform_data *pdata;
16 + struct device_node *np;
17 int ret;
18
19 + pdata = spi->dev.platform_data;
20 + np = spi->dev.of_node;
21 +
22 + if (!np && !pdata) {
23 + dev_err(&spi->dev, "No configuration data available.\n");
24 + return -EINVAL;
25 + }
26 +
27 /*
28 * bits_per_word cannot be configured in platform data
29 */
30 @@ -130,18 +141,28 @@ static int gen_74x164_probe(struct spi_d
31 chip->gpio_chip.set = gen_74x164_set_value;
32 chip->gpio_chip.base = -1;
33
34 - if (of_property_read_u32(spi->dev.of_node, "registers-number",
35 - &chip->registers)) {
36 - dev_err(&spi->dev,
37 - "Missing registers-number property in the DT.\n");
38 - return -EINVAL;
39 + if (np) {
40 + if (of_property_read_u32(spi->dev.of_node, "registers-number", &chip->registers)) {
41 + dev_err(&spi->dev, "Missing registers-number property in the DT.\n");
42 + ret = -EINVAL;
43 + goto exit_destroy;
44 + }
45 + } else if (pdata) {
46 + chip->gpio_chip.base = pdata->base;
47 + chip->registers = pdata->num_registers;
48 }
49
50 + if (!chip->registers)
51 + chip->registers = 1;
52 +
53 chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers;
54 chip->buffer = devm_kzalloc(&spi->dev, chip->registers, GFP_KERNEL);
55 if (!chip->buffer)
56 return -ENOMEM;
57
58 + if (pdata && pdata->init_data)
59 + memcpy(chip->buffer, pdata->init_data, chip->registers);
60 +
61 chip->gpio_chip.can_sleep = true;
62 chip->gpio_chip.dev = &spi->dev;
63 chip->gpio_chip.owner = THIS_MODULE;
64 @@ -174,17 +195,19 @@ static int gen_74x164_remove(struct spi_
65 return 0;
66 }
67
68 +#ifdef CONFIG_OF
69 static const struct of_device_id gen_74x164_dt_ids[] = {
70 { .compatible = "fairchild,74hc595" },
71 {},
72 };
73 MODULE_DEVICE_TABLE(of, gen_74x164_dt_ids);
74 +#endif /* CONFIG_OF */
75
76 static struct spi_driver gen_74x164_driver = {
77 .driver = {
78 .name = "74x164",
79 .owner = THIS_MODULE,
80 - .of_match_table = gen_74x164_dt_ids,
81 + .of_match_table = of_match_ptr(gen_74x164_dt_ids),
82 },
83 .probe = gen_74x164_probe,
84 .remove = gen_74x164_remove,
85 --- /dev/null
86 +++ b/include/linux/spi/74x164.h
87 @@ -0,0 +1,13 @@
88 +#ifndef LINUX_SPI_74X164_H
89 +#define LINUX_SPI_74X164_H
90 +
91 +struct gen_74x164_chip_platform_data {
92 + /* number assigned to the first GPIO */
93 + unsigned base;
94 + /* number of chained registers */
95 + unsigned num_registers;
96 + /* address of a buffer containing initial data */
97 + u8 *init_data;
98 +};
99 +
100 +#endif
101 --- a/drivers/gpio/Kconfig
102 +++ b/drivers/gpio/Kconfig
103 @@ -941,7 +941,7 @@ menu "SPI GPIO expanders"
104
105 config GPIO_74X164
106 tristate "74x164 serial-in/parallel-out 8-bits shift register"
107 - depends on SPI_MASTER && OF
108 + depends on SPI_MASTER
109 help
110 Driver for 74x164 compatible serial-in/parallel-out 8-outputs
111 shift registers. This driver can be used to provide access