--- zzzz-none-000/linux-3.10.107/drivers/gpio/gpio-74x164.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/gpio/gpio-74x164.c 2021-02-04 17:41:59.000000000 +0000 @@ -21,7 +21,6 @@ #define GEN_74X164_NUMBER_GPIOS 8 struct gen_74x164_chip { - struct spi_device *spi; u8 *buffer; struct gpio_chip gpio_chip; struct mutex lock; @@ -35,6 +34,7 @@ static int __gen_74x164_write_config(struct gen_74x164_chip *chip) { + struct spi_device *spi = to_spi_device(chip->gpio_chip.dev); struct spi_message message; struct spi_transfer *msg_buf; int i, ret = 0; @@ -55,12 +55,12 @@ * byte of the buffer will end up in the last register. */ for (i = chip->registers - 1; i >= 0; i--) { - msg_buf[i].tx_buf = chip->buffer +i; + msg_buf[i].tx_buf = chip->buffer + i; msg_buf[i].len = sizeof(u8); spi_message_add_tail(msg_buf + i, &message); } - ret = spi_sync(chip->spi, &message); + ret = spi_sync(spi, &message); kfree(msg_buf); @@ -109,10 +109,14 @@ { struct gen_74x164_chip *chip; struct gen_74x164_chip_platform_data *pdata; + struct device_node *np; int ret; - if (!spi->dev.of_node) { - dev_err(&spi->dev, "No device tree data available.\n"); + pdata = spi->dev.platform_data; + np = spi->dev.of_node; + + if (!np && !pdata) { + dev_err(&spi->dev, "No configuration data available.\n"); return -EINVAL; } @@ -129,40 +133,42 @@ if (!chip) return -ENOMEM; - pdata = spi->dev.platform_data; - if (pdata && pdata->base) - chip->gpio_chip.base = pdata->base; - else - chip->gpio_chip.base = -1; - - mutex_init(&chip->lock); - spi_set_drvdata(spi, chip); - chip->spi = spi; - chip->gpio_chip.label = spi->modalias; chip->gpio_chip.direction_output = gen_74x164_direction_output; chip->gpio_chip.get = gen_74x164_get_value; chip->gpio_chip.set = gen_74x164_set_value; + chip->gpio_chip.base = -1; - if (of_property_read_u32(spi->dev.of_node, "registers-number", &chip->registers)) { - dev_err(&spi->dev, "Missing registers-number property in the DT.\n"); - ret = -EINVAL; - goto exit_destroy; + if (np) { + if (of_property_read_u32(spi->dev.of_node, "registers-number", &chip->registers)) { + dev_err(&spi->dev, "Missing registers-number property in the DT.\n"); + ret = -EINVAL; + goto exit_destroy; + } + } else if (pdata) { + chip->gpio_chip.base = pdata->base; + chip->registers = pdata->num_registers; } + if (!chip->registers) + chip->registers = 1; + chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers; chip->buffer = devm_kzalloc(&spi->dev, chip->registers, GFP_KERNEL); - if (!chip->buffer) { - ret = -ENOMEM; - goto exit_destroy; - } + if (!chip->buffer) + return -ENOMEM; + + if (pdata && pdata->init_data) + memcpy(chip->buffer, pdata->init_data, chip->registers); - chip->gpio_chip.can_sleep = 1; + chip->gpio_chip.can_sleep = true; chip->gpio_chip.dev = &spi->dev; chip->gpio_chip.owner = THIS_MODULE; + mutex_init(&chip->lock); + ret = __gen_74x164_write_config(chip); if (ret) { dev_err(&spi->dev, "Failed writing: %d\n", ret); @@ -170,48 +176,36 @@ } ret = gpiochip_add(&chip->gpio_chip); - if (ret) - goto exit_destroy; - - return ret; + if (!ret) + return 0; exit_destroy: - spi_set_drvdata(spi, NULL); mutex_destroy(&chip->lock); + return ret; } static int gen_74x164_remove(struct spi_device *spi) { - struct gen_74x164_chip *chip; - int ret; - - chip = spi_get_drvdata(spi); - if (chip == NULL) - return -ENODEV; + struct gen_74x164_chip *chip = spi_get_drvdata(spi); - spi_set_drvdata(spi, NULL); - - ret = gpiochip_remove(&chip->gpio_chip); - if (!ret) - mutex_destroy(&chip->lock); - else - dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n", - ret); + gpiochip_remove(&chip->gpio_chip); + mutex_destroy(&chip->lock); - return ret; + return 0; } +#ifdef CONFIG_OF static const struct of_device_id gen_74x164_dt_ids[] = { { .compatible = "fairchild,74hc595" }, {}, }; MODULE_DEVICE_TABLE(of, gen_74x164_dt_ids); +#endif static struct spi_driver gen_74x164_driver = { .driver = { .name = "74x164", - .owner = THIS_MODULE, .of_match_table = of_match_ptr(gen_74x164_dt_ids), }, .probe = gen_74x164_probe,