rpcd: iwinfo plugin fixes
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / patches-4.4 / 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,16 +195,18 @@ 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
75
76 static struct spi_driver gen_74x164_driver = {
77 .driver = {
78 .name = "74x164",
79 - .of_match_table = gen_74x164_dt_ids,
80 + .of_match_table = of_match_ptr(gen_74x164_dt_ids),
81 },
82 .probe = gen_74x164_probe,
83 .remove = gen_74x164_remove,
84 --- /dev/null
85 +++ b/include/linux/spi/74x164.h
86 @@ -0,0 +1,13 @@
87 +#ifndef LINUX_SPI_74X164_H
88 +#define LINUX_SPI_74X164_H
89 +
90 +struct gen_74x164_chip_platform_data {
91 + /* number assigned to the first GPIO */
92 + unsigned base;
93 + /* number of chained registers */
94 + unsigned num_registers;
95 + /* address of a buffer containing initial data */
96 + u8 *init_data;
97 +};
98 +
99 +#endif
100 --- a/drivers/gpio/Kconfig
101 +++ b/drivers/gpio/Kconfig
102 @@ -990,7 +990,6 @@ menu "SPI GPIO expanders"
103
104 config GPIO_74X164
105 tristate "74x164 serial-in/parallel-out 8-bits shift register"
106 - depends on OF
107 help
108 Driver for 74x164 compatible serial-in/parallel-out 8-outputs
109 shift registers. This driver can be used to provide access