Skip to content

Commit 2f3a896

Browse files
dtorbroonie
authored andcommitted
spi: spi-mpc52xx: switch to using gpiod API
This switches the driver to use gpiod API instead of legacy gpio API, which will brings us close to removing of_get_gpio() and other OF-specific old APIs. No functional change intended beyond some differences in error messages. Signed-off-by: Dmitry Torokhov <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 9671847 commit 2f3a896

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

drivers/spi/spi-mpc52xx.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
*/
1212

1313
#include <linux/module.h>
14+
#include <linux/err.h>
1415
#include <linux/errno.h>
1516
#include <linux/of_platform.h>
1617
#include <linux/interrupt.h>
1718
#include <linux/delay.h>
1819
#include <linux/gpio/consumer.h>
1920
#include <linux/spi/spi.h>
2021
#include <linux/io.h>
21-
#include <linux/of_gpio.h>
2222
#include <linux/slab.h>
2323
#include <linux/of_address.h>
2424
#include <linux/of_irq.h>
@@ -90,7 +90,7 @@ struct mpc52xx_spi {
9090
const u8 *tx_buf;
9191
int cs_change;
9292
int gpio_cs_count;
93-
unsigned int *gpio_cs;
93+
struct gpio_desc **gpio_cs;
9494
};
9595

9696
/*
@@ -102,9 +102,10 @@ static void mpc52xx_spi_chipsel(struct mpc52xx_spi *ms, int value)
102102

103103
if (ms->gpio_cs_count > 0) {
104104
cs = ms->message->spi->chip_select;
105-
gpio_set_value(ms->gpio_cs[cs], value ? 0 : 1);
106-
} else
105+
gpiod_set_value(ms->gpio_cs[cs], value);
106+
} else {
107107
out_8(ms->regs + SPI_PORTDATA, value ? 0 : 0x08);
108+
}
108109
}
109110

110111
/*
@@ -386,10 +387,10 @@ static int mpc52xx_spi_probe(struct platform_device *op)
386387
{
387388
struct spi_master *master;
388389
struct mpc52xx_spi *ms;
390+
struct gpio_desc *gpio_cs;
389391
void __iomem *regs;
390392
u8 ctrl1;
391393
int rc, i = 0;
392-
int gpio_cs;
393394

394395
/* MMIO registers */
395396
dev_dbg(&op->dev, "probing mpc5200 SPI device\n");
@@ -451,23 +452,16 @@ static int mpc52xx_spi_probe(struct platform_device *op)
451452
}
452453

453454
for (i = 0; i < ms->gpio_cs_count; i++) {
454-
gpio_cs = of_get_gpio(op->dev.of_node, i);
455-
if (!gpio_is_valid(gpio_cs)) {
456-
dev_err(&op->dev,
457-
"could not parse the gpio field in oftree\n");
458-
rc = -ENODEV;
459-
goto err_gpio;
460-
}
461-
462-
rc = gpio_request(gpio_cs, dev_name(&op->dev));
455+
gpio_cs = gpiod_get_index(&op->dev,
456+
NULL, i, GPIOD_OUT_LOW);
457+
rc = PTR_ERR_OR_ZERO(gpio_cs);
463458
if (rc) {
464459
dev_err(&op->dev,
465-
"can't request spi cs gpio #%d on gpio line %d\n",
466-
i, gpio_cs);
460+
"failed to get spi cs gpio #%d: %d\n",
461+
i, rc);
467462
goto err_gpio;
468463
}
469464

470-
gpio_direction_output(gpio_cs, 1);
471465
ms->gpio_cs[i] = gpio_cs;
472466
}
473467
}
@@ -508,7 +502,7 @@ static int mpc52xx_spi_probe(struct platform_device *op)
508502
dev_err(&ms->master->dev, "initialization failed\n");
509503
err_gpio:
510504
while (i-- > 0)
511-
gpio_free(ms->gpio_cs[i]);
505+
gpiod_put(ms->gpio_cs[i]);
512506

513507
kfree(ms->gpio_cs);
514508
err_alloc_gpio:
@@ -529,7 +523,7 @@ static int mpc52xx_spi_remove(struct platform_device *op)
529523
free_irq(ms->irq1, ms);
530524

531525
for (i = 0; i < ms->gpio_cs_count; i++)
532-
gpio_free(ms->gpio_cs[i]);
526+
gpiod_put(ms->gpio_cs[i]);
533527

534528
kfree(ms->gpio_cs);
535529
spi_unregister_master(master);

0 commit comments

Comments
 (0)