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 @@ -103,9 +104,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 @@ -115,17 +123,23 @@ 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);
52 + if (pdata && pdata->init_data)
53 + memcpy(chip->buffer, pdata->init_data, chip->registers);
55 spi_set_drvdata(spi, chip);
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;
64 + chip->gpio_chip.base = -1;
66 + chip->gpio_chip.base = pdata->base;
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_
76 static const struct of_device_id gen_74x164_dt_ids[] = {
77 { .compatible = "fairchild,74hc595" },
78 { .compatible = "nxp,74lvc594" },
81 MODULE_DEVICE_TABLE(of, gen_74x164_dt_ids);
84 static struct spi_driver gen_74x164_driver = {
87 - .of_match_table = gen_74x164_dt_ids,
88 + .of_match_table = of_match_ptr(gen_74x164_dt_ids),
90 .probe = gen_74x164_probe,
91 .remove = gen_74x164_remove,
93 +++ b/include/linux/spi/74x164.h
95 +#ifndef LINUX_SPI_74X164_H
96 +#define LINUX_SPI_74X164_H
98 +struct gen_74x164_chip_platform_data {
99 + /* number assigned to the first GPIO */
101 + /* number of chained registers */
102 + unsigned num_registers;
103 + /* address of a buffer containing initial data */
108 --- a/drivers/gpio/Kconfig
109 +++ b/drivers/gpio/Kconfig
110 @@ -1154,7 +1154,6 @@ menu "SPI GPIO expanders"
113 tristate "74x164 serial-in/parallel-out 8-bits shift register"
116 Driver for 74x164 compatible serial-in/parallel-out 8-outputs
117 shift registers. This driver can be used to provide access