1 --- a/drivers/gpio/gpio-74x164.c
2 +++ b/drivers/gpio/gpio-74x164.c
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 @@ -105,9 +106,16 @@ static int gen_74x164_direction_output(s
12 static int gen_74x164_probe(struct spi_device *spi)
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;
20 + if (!np && !pdata) {
21 + dev_err(&spi->dev, "No configuration data available.\n");
26 * bits_per_word cannot be configured in platform data
28 @@ -117,12 +125,15 @@ static int gen_74x164_probe(struct spi_d
32 - if (of_property_read_u32(spi->dev.of_node, "registers-number",
35 - "Missing registers-number property in the DT.\n");
39 + if (of_property_read_u32(np, "registers-number", &nregs)) {
41 + "Missing registers-number property in the DT.\n");
45 + nregs = pdata->num_registers;
48 chip = devm_kzalloc(&spi->dev, sizeof(*chip) + nregs, GFP_KERNEL);
50 @@ -142,7 +153,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;
56 + chip->gpio_chip.base = -1;
58 + chip->gpio_chip.base = pdata->base;
61 chip->registers = nregs;
62 chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers;
63 @@ -151,6 +166,9 @@ static int gen_74x164_probe(struct spi_d
64 chip->gpio_chip.parent = &spi->dev;
65 chip->gpio_chip.owner = THIS_MODULE;
67 + if (pdata && pdata->init_data)
68 + memcpy(chip->buffer, pdata->init_data, chip->registers);
70 mutex_init(&chip->lock);
72 ret = __gen_74x164_write_config(chip);
73 @@ -180,17 +198,19 @@ static int gen_74x164_remove(struct spi_
78 static const struct of_device_id gen_74x164_dt_ids[] = {
79 { .compatible = "fairchild,74hc595" },
80 { .compatible = "nxp,74lvc594" },
83 MODULE_DEVICE_TABLE(of, gen_74x164_dt_ids);
86 static struct spi_driver gen_74x164_driver = {
89 - .of_match_table = gen_74x164_dt_ids,
90 + .of_match_table = of_match_ptr(gen_74x164_dt_ids),
92 .probe = gen_74x164_probe,
93 .remove = gen_74x164_remove,
95 +++ b/include/linux/spi/74x164.h
97 +#ifndef LINUX_SPI_74X164_H
98 +#define LINUX_SPI_74X164_H
100 +struct gen_74x164_chip_platform_data {
101 + /* number assigned to the first GPIO */
103 + /* number of chained registers */
104 + unsigned num_registers;
105 + /* address of a buffer containing initial data */
110 --- a/drivers/gpio/Kconfig
111 +++ b/drivers/gpio/Kconfig
112 @@ -1252,7 +1252,6 @@ menu "SPI GPIO expanders"
115 tristate "74x164 serial-in/parallel-out 8-bits shift register"
118 Driver for 74x164 compatible serial-in/parallel-out 8-outputs
119 shift registers. This driver can be used to provide access