kernel: bump 4.9 to 4.9.118
[openwrt/openwrt.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,12 +123,15 @@ 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 @@ -133,7 +144,11 @@ static int gen_74x164_probe(struct spi_d
51 chip->gpio_chip.get = gen_74x164_get_value;
52 chip->gpio_chip.set = gen_74x164_set_value;
53 chip->gpio_chip.set_multiple = gen_74x164_set_multiple;
54 - chip->gpio_chip.base = -1;
55 + if (np)
56 + chip->gpio_chip.base = -1;
57 + else if (pdata)
58 + chip->gpio_chip.base = pdata->base;
59 +
60
61 chip->registers = nregs;
62 chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers;
63 @@ -142,6 +157,9 @@ static int gen_74x164_probe(struct spi_d
64 chip->gpio_chip.parent = &spi->dev;
65 chip->gpio_chip.owner = THIS_MODULE;
66
67 + if (pdata && pdata->init_data)
68 + memcpy(chip->buffer, pdata->init_data, chip->registers);
69 +
70 mutex_init(&chip->lock);
71
72 ret = __gen_74x164_write_config(chip);
73 @@ -170,17 +188,19 @@ static int gen_74x164_remove(struct spi_
74 return 0;
75 }
76
77 +#ifdef CONFIG_OF
78 static const struct of_device_id gen_74x164_dt_ids[] = {
79 { .compatible = "fairchild,74hc595" },
80 { .compatible = "nxp,74lvc594" },
81 {},
82 };
83 MODULE_DEVICE_TABLE(of, gen_74x164_dt_ids);
84 +#endif
85
86 static struct spi_driver gen_74x164_driver = {
87 .driver = {
88 .name = "74x164",
89 - .of_match_table = gen_74x164_dt_ids,
90 + .of_match_table = of_match_ptr(gen_74x164_dt_ids),
91 },
92 .probe = gen_74x164_probe,
93 .remove = gen_74x164_remove,
94 --- /dev/null
95 +++ b/include/linux/spi/74x164.h
96 @@ -0,0 +1,13 @@
97 +#ifndef LINUX_SPI_74X164_H
98 +#define LINUX_SPI_74X164_H
99 +
100 +struct gen_74x164_chip_platform_data {
101 + /* number assigned to the first GPIO */
102 + unsigned base;
103 + /* number of chained registers */
104 + unsigned num_registers;
105 + /* address of a buffer containing initial data */
106 + u8 *init_data;
107 +};
108 +
109 +#endif
110 --- a/drivers/gpio/Kconfig
111 +++ b/drivers/gpio/Kconfig
112 @@ -1154,7 +1154,6 @@ menu "SPI GPIO expanders"
113
114 config GPIO_74X164
115 tristate "74x164 serial-in/parallel-out 8-bits shift register"
116 - depends on OF_GPIO
117 help
118 Driver for 74x164 compatible serial-in/parallel-out 8-outputs
119 shift registers. This driver can be used to provide access