Commit bcc0562c authored by Alexander Shiyan's avatar Alexander Shiyan Committed by Linus Walleij

gpio: 74x164: Driver cleanup

- Removed excess "spi" field from private data.
- Removed excess check for spi_get_drvdata() in remove().
- Removed unneeded message in remove().
- Simplify error path in probe().
- Fixed warnings by scripts/checkfile.pl.
Signed-off-by: default avatarAlexander Shiyan <shc_work@mail.ru>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 61e73804
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#define GEN_74X164_NUMBER_GPIOS 8 #define GEN_74X164_NUMBER_GPIOS 8
struct gen_74x164_chip { struct gen_74x164_chip {
struct spi_device *spi;
u8 *buffer; u8 *buffer;
struct gpio_chip gpio_chip; struct gpio_chip gpio_chip;
struct mutex lock; struct mutex lock;
...@@ -34,6 +33,7 @@ static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc) ...@@ -34,6 +33,7 @@ static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc)
static int __gen_74x164_write_config(struct gen_74x164_chip *chip) 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_message message;
struct spi_transfer *msg_buf; struct spi_transfer *msg_buf;
int i, ret = 0; int i, ret = 0;
...@@ -54,12 +54,12 @@ static int __gen_74x164_write_config(struct gen_74x164_chip *chip) ...@@ -54,12 +54,12 @@ static int __gen_74x164_write_config(struct gen_74x164_chip *chip)
* byte of the buffer will end up in the last register. * byte of the buffer will end up in the last register.
*/ */
for (i = chip->registers - 1; i >= 0; i--) { 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); msg_buf[i].len = sizeof(u8);
spi_message_add_tail(msg_buf + i, &message); spi_message_add_tail(msg_buf + i, &message);
} }
ret = spi_sync(chip->spi, &message); ret = spi_sync(spi, &message);
kfree(msg_buf); kfree(msg_buf);
...@@ -122,35 +122,32 @@ static int gen_74x164_probe(struct spi_device *spi) ...@@ -122,35 +122,32 @@ static int gen_74x164_probe(struct spi_device *spi)
if (!chip) if (!chip)
return -ENOMEM; return -ENOMEM;
mutex_init(&chip->lock);
spi_set_drvdata(spi, chip); spi_set_drvdata(spi, chip);
chip->spi = spi;
chip->gpio_chip.label = spi->modalias; chip->gpio_chip.label = spi->modalias;
chip->gpio_chip.direction_output = gen_74x164_direction_output; chip->gpio_chip.direction_output = gen_74x164_direction_output;
chip->gpio_chip.get = gen_74x164_get_value; chip->gpio_chip.get = gen_74x164_get_value;
chip->gpio_chip.set = gen_74x164_set_value; chip->gpio_chip.set = gen_74x164_set_value;
chip->gpio_chip.base = -1; chip->gpio_chip.base = -1;
if (of_property_read_u32(spi->dev.of_node, "registers-number", &chip->registers)) { if (of_property_read_u32(spi->dev.of_node, "registers-number",
dev_err(&spi->dev, "Missing registers-number property in the DT.\n"); &chip->registers)) {
ret = -EINVAL; dev_err(&spi->dev,
goto exit_destroy; "Missing registers-number property in the DT.\n");
return -EINVAL;
} }
chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers; chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers;
chip->buffer = devm_kzalloc(&spi->dev, chip->registers, GFP_KERNEL); chip->buffer = devm_kzalloc(&spi->dev, chip->registers, GFP_KERNEL);
if (!chip->buffer) { if (!chip->buffer)
ret = -ENOMEM; return -ENOMEM;
goto exit_destroy;
}
chip->gpio_chip.can_sleep = true; chip->gpio_chip.can_sleep = true;
chip->gpio_chip.dev = &spi->dev; chip->gpio_chip.dev = &spi->dev;
chip->gpio_chip.owner = THIS_MODULE; chip->gpio_chip.owner = THIS_MODULE;
mutex_init(&chip->lock);
ret = __gen_74x164_write_config(chip); ret = __gen_74x164_write_config(chip);
if (ret) { if (ret) {
dev_err(&spi->dev, "Failed writing: %d\n", ret); dev_err(&spi->dev, "Failed writing: %d\n", ret);
...@@ -158,31 +155,23 @@ static int gen_74x164_probe(struct spi_device *spi) ...@@ -158,31 +155,23 @@ static int gen_74x164_probe(struct spi_device *spi)
} }
ret = gpiochip_add(&chip->gpio_chip); ret = gpiochip_add(&chip->gpio_chip);
if (ret) if (!ret)
goto exit_destroy; return 0;
return ret;
exit_destroy: exit_destroy:
mutex_destroy(&chip->lock); mutex_destroy(&chip->lock);
return ret; return ret;
} }
static int gen_74x164_remove(struct spi_device *spi) static int gen_74x164_remove(struct spi_device *spi)
{ {
struct gen_74x164_chip *chip; struct gen_74x164_chip *chip = spi_get_drvdata(spi);
int ret; int ret;
chip = spi_get_drvdata(spi);
if (chip == NULL)
return -ENODEV;
ret = gpiochip_remove(&chip->gpio_chip); ret = gpiochip_remove(&chip->gpio_chip);
if (!ret) if (!ret)
mutex_destroy(&chip->lock); mutex_destroy(&chip->lock);
else
dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n",
ret);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment