ar71xx: Add kernel 4.9 support
[openwrt/staging/mkresin.git] / target / linux / ar71xx / patches-4.9 / 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 @@ -103,9 +104,16 @@ 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 = spi->dev.platform_data;
16 + struct device_node *np = spi->dev.of_node;
17 u32 nregs;
18 int ret;
19
20 + if (!np && !pdata) {
21 + dev_err(&spi->dev, "No configuration data available.\n");
22 + return -EINVAL;
23 + }
24 +
25 /*
26 * bits_per_word cannot be configured in platform data
27 */
28 @@ -115,17 +123,23 @@ static int gen_74x164_probe(struct spi_d
29 if (ret < 0)
30 return ret;
31
32 - if (of_property_read_u32(spi->dev.of_node, "registers-number",
33 - &nregs)) {
34 - dev_err(&spi->dev,
35 - "Missing registers-number property in the DT.\n");
36 - return -EINVAL;
37 - }
38 + if (np) {
39 + if (of_property_read_u32(np, "registers-number", &nregs)) {
40 + dev_err(&spi->dev,
41 + "Missing registers-number property in the DT.\n");
42 + return -EINVAL;
43 + }
44 + } else if (pdata) {
45 + nregs = pdata->num_registers;
46 + }
47
48 chip = devm_kzalloc(&spi->dev, sizeof(*chip) + nregs, GFP_KERNEL);
49 if (!chip)
50 return -ENOMEM;
51
52 + if (pdata && pdata->init_data)
53 + memcpy(chip->buffer, pdata->init_data, chip->registers);
54 +
55 spi_set_drvdata(spi, chip);
56
57 chip->gpio_chip.label = spi->modalias;
58 @@ -133,7 +147,11 @@ static int gen_74x164_probe(struct spi_d
59 chip->gpio_chip.get = gen_74x164_get_value;
60 chip->gpio_chip.set = gen_74x164_set_value;
61 chip->gpio_chip.set_multiple = gen_74x164_set_multiple;
62 - chip->gpio_chip.base = -1;
63 + if (np)
64 + chip->gpio_chip.base = -1;
65 + else if (pdata)
66 + chip->gpio_chip.base = pdata->base;
67 +
68
69 chip->registers = nregs;
70 chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers;
71 @@ -170,17 +188,19 @@ static int gen_74x164_remove(struct spi_
72 return 0;
73 }
74
75 +#ifdef CONFIG_OF
76 static const struct of_device_id gen_74x164_dt_ids[] = {
77 { .compatible = "fairchild,74hc595" },
78 { .compatible = "nxp,74lvc594" },
79 {},
80 };
81 MODULE_DEVICE_TABLE(of, gen_74x164_dt_ids);
82 +#endif
83
84 static struct spi_driver gen_74x164_driver = {
85 .driver = {
86 .name = "74x164",
87 - .of_match_table = gen_74x164_dt_ids,
88 + .of_match_table = of_match_ptr(gen_74x164_dt_ids),
89 },
90 .probe = gen_74x164_probe,
91 .remove = gen_74x164_remove,
92 --- /dev/null
93 +++ b/include/linux/spi/74x164.h
94 @@ -0,0 +1,13 @@
95 +#ifndef LINUX_SPI_74X164_H
96 +#define LINUX_SPI_74X164_H
97 +
98 +struct gen_74x164_chip_platform_data {
99 + /* number assigned to the first GPIO */
100 + unsigned base;
101 + /* number of chained registers */
102 + unsigned num_registers;
103 + /* address of a buffer containing initial data */
104 + u8 *init_data;
105 +};
106 +
107 +#endif
108 --- a/drivers/gpio/Kconfig
109 +++ b/drivers/gpio/Kconfig
110 @@ -1154,7 +1154,6 @@ menu "SPI GPIO expanders"
111
112 config GPIO_74X164
113 tristate "74x164 serial-in/parallel-out 8-bits shift register"
114 - depends on OF_GPIO
115 help
116 Driver for 74x164 compatible serial-in/parallel-out 8-outputs
117 shift registers. This driver can be used to provide access