* [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers
@ 2022-09-22 8:30 Yang Yingliang
2022-09-22 8:30 ` [PATCH -next v2 1/6] spi: oc-tiny: Switch to use __devm_spi_alloc_controller() Yang Yingliang
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Yang Yingliang @ 2022-09-22 8:30 UTC (permalink / raw)
To: linux-spi; +Cc: broonie, yangyingliang
This patchset is trying to replace spi_alloc_master() with
__devm_spi_alloc_controller() in some spi drivers. With this
helper, spi_master_put() is called in devres_release_all()
whenever the device is unbound, so the spi_master_put() in
error path can be removed.
v2:
Using controller named struct and functions:
Using struct spi_controller instead of struct spi_master
Using __devm_spi_alloc_controller() instead of devm_spi_alloc_master()
Using spi_controller_get_devdata() instead of spi_master_get_devdata()
Using devm_spi_register_master() instead of devm_spi_register_controller()
Yang Yingliang (6):
spi: oc-tiny: Switch to use __devm_spi_alloc_controller()
spi: ath79: Switch to use __devm_spi_alloc_controller()
spi: omap-uwire: Switch to use __devm_spi_alloc_controller()
spi: ppc4xx: Switch to use __devm_spi_alloc_controller()
spi: sh-sci: Switch to use __devm_spi_alloc_controller()
spi: altera: Switch to use __devm_spi_alloc_controller()
drivers/spi/spi-altera-platform.c | 55 ++++++++++++++-----------------
drivers/spi/spi-ath79.c | 40 ++++++++++------------
drivers/spi/spi-oc-tiny.c | 34 ++++++++-----------
drivers/spi/spi-omap-uwire.c | 28 ++++++++--------
drivers/spi/spi-ppc4xx.c | 29 +++++++---------
drivers/spi/spi-sh-sci.c | 44 ++++++++++---------------
6 files changed, 98 insertions(+), 132 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH -next v2 1/6] spi: oc-tiny: Switch to use __devm_spi_alloc_controller()
2022-09-22 8:30 [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers Yang Yingliang
@ 2022-09-22 8:30 ` Yang Yingliang
2022-09-22 8:30 ` [PATCH -next v2 2/6] spi: ath79: " Yang Yingliang
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Yang Yingliang @ 2022-09-22 8:30 UTC (permalink / raw)
To: linux-spi; +Cc: broonie, yangyingliang
With using __devm_spi_alloc_controller(), spi_controller_put() is called in
devres_release_all() whenever the device is unbound, so the spi_master_put()
in error path can be removed. Also replace spi_master_get_devdata() with
spi_controller_get_devdata().
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/spi/spi-oc-tiny.c | 34 ++++++++++++++--------------------
1 file changed, 14 insertions(+), 20 deletions(-)
diff --git a/drivers/spi/spi-oc-tiny.c b/drivers/spi/spi-oc-tiny.c
index 38c14c4e4e21..3514824f9f24 100644
--- a/drivers/spi/spi-oc-tiny.c
+++ b/drivers/spi/spi-oc-tiny.c
@@ -212,33 +212,31 @@ static int tiny_spi_probe(struct platform_device *pdev)
{
struct tiny_spi_platform_data *platp = dev_get_platdata(&pdev->dev);
struct tiny_spi *hw;
- struct spi_master *master;
+ struct spi_controller *ctlr;
int err = -ENODEV;
- master = spi_alloc_master(&pdev->dev, sizeof(struct tiny_spi));
- if (!master)
+ ctlr = __devm_spi_alloc_controller(&pdev->dev, sizeof(*hw), false);
+ if (!ctlr)
return err;
/* setup the master state. */
- master->bus_num = pdev->id;
- master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
- master->setup = tiny_spi_setup;
- master->use_gpio_descriptors = true;
+ ctlr->bus_num = pdev->id;
+ ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
+ ctlr->setup = tiny_spi_setup;
+ ctlr->use_gpio_descriptors = true;
- hw = spi_master_get_devdata(master);
+ hw = spi_controller_get_devdata(ctlr);
platform_set_drvdata(pdev, hw);
/* setup the state for the bitbang driver */
- hw->bitbang.master = master;
+ hw->bitbang.master = ctlr;
hw->bitbang.setup_transfer = tiny_spi_setup_transfer;
hw->bitbang.txrx_bufs = tiny_spi_txrx_bufs;
/* find and map our resources */
hw->base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(hw->base)) {
- err = PTR_ERR(hw->base);
- goto exit;
- }
+ if (IS_ERR(hw->base))
+ return PTR_ERR(hw->base);
/* irq is optional */
hw->irq = platform_get_irq(pdev, 0);
if (hw->irq >= 0) {
@@ -246,7 +244,7 @@ static int tiny_spi_probe(struct platform_device *pdev)
err = devm_request_irq(&pdev->dev, hw->irq, tiny_spi_irq, 0,
pdev->name, hw);
if (err)
- goto exit;
+ return err;
}
/* find platform data */
if (platp) {
@@ -255,20 +253,16 @@ static int tiny_spi_probe(struct platform_device *pdev)
} else {
err = tiny_spi_of_probe(pdev);
if (err)
- goto exit;
+ return err;
}
/* register our spi controller */
err = spi_bitbang_start(&hw->bitbang);
if (err)
- goto exit;
+ return err;
dev_info(&pdev->dev, "base %p, irq %d\n", hw->base, hw->irq);
return 0;
-
-exit:
- spi_master_put(master);
- return err;
}
static int tiny_spi_remove(struct platform_device *pdev)
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH -next v2 2/6] spi: ath79: Switch to use __devm_spi_alloc_controller()
2022-09-22 8:30 [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers Yang Yingliang
2022-09-22 8:30 ` [PATCH -next v2 1/6] spi: oc-tiny: Switch to use __devm_spi_alloc_controller() Yang Yingliang
@ 2022-09-22 8:30 ` Yang Yingliang
2022-09-22 8:31 ` [PATCH -next v2 3/6] spi: omap-uwire: " Yang Yingliang
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Yang Yingliang @ 2022-09-22 8:30 UTC (permalink / raw)
To: linux-spi; +Cc: broonie, yangyingliang
With using __devm_spi_alloc_controller(), spi_controller_put() is called in
devres_release_all() whenever the device is unbound, so the spi_master_put()
in error path can be removed. Also replace spi_master_get_devdata() with
spi_controller_get_devdata().
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/spi/spi-ath79.c | 40 +++++++++++++++++-----------------------
1 file changed, 17 insertions(+), 23 deletions(-)
diff --git a/drivers/spi/spi-ath79.c b/drivers/spi/spi-ath79.c
index 607e7a49fb89..3b9dbe4b8f16 100644
--- a/drivers/spi/spi-ath79.c
+++ b/drivers/spi/spi-ath79.c
@@ -168,47 +168,43 @@ static const struct spi_controller_mem_ops ath79_mem_ops = {
static int ath79_spi_probe(struct platform_device *pdev)
{
- struct spi_master *master;
+ struct spi_controller *ctlr;
struct ath79_spi *sp;
unsigned long rate;
int ret;
- master = spi_alloc_master(&pdev->dev, sizeof(*sp));
- if (master == NULL) {
- dev_err(&pdev->dev, "failed to allocate spi master\n");
+ ctlr = __devm_spi_alloc_controller(&pdev->dev, sizeof(*sp), false);
+ if (!ctlr) {
+ dev_err(&pdev->dev, "failed to allocate spi controller\n");
return -ENOMEM;
}
- sp = spi_master_get_devdata(master);
- master->dev.of_node = pdev->dev.of_node;
+ sp = spi_controller_get_devdata(ctlr);
+ ctlr->dev.of_node = pdev->dev.of_node;
platform_set_drvdata(pdev, sp);
- master->use_gpio_descriptors = true;
- master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
- master->flags = SPI_MASTER_GPIO_SS;
- master->num_chipselect = 3;
- master->mem_ops = &ath79_mem_ops;
+ ctlr->use_gpio_descriptors = true;
+ ctlr->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
+ ctlr->flags = SPI_MASTER_GPIO_SS;
+ ctlr->num_chipselect = 3;
+ ctlr->mem_ops = &ath79_mem_ops;
- sp->bitbang.master = master;
+ sp->bitbang.master = ctlr;
sp->bitbang.chipselect = ath79_spi_chipselect;
sp->bitbang.txrx_word[SPI_MODE_0] = ath79_spi_txrx_mode0;
sp->bitbang.flags = SPI_CS_HIGH;
sp->base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(sp->base)) {
- ret = PTR_ERR(sp->base);
- goto err_put_master;
- }
+ if (IS_ERR(sp->base))
+ return PTR_ERR(sp->base);
sp->clk = devm_clk_get(&pdev->dev, "ahb");
- if (IS_ERR(sp->clk)) {
- ret = PTR_ERR(sp->clk);
- goto err_put_master;
- }
+ if (IS_ERR(sp->clk))
+ return PTR_ERR(sp->clk);
ret = clk_prepare_enable(sp->clk);
if (ret)
- goto err_put_master;
+ return ret;
rate = DIV_ROUND_UP(clk_get_rate(sp->clk), MHZ);
if (!rate) {
@@ -231,8 +227,6 @@ static int ath79_spi_probe(struct platform_device *pdev)
ath79_spi_disable(sp);
err_clk_disable:
clk_disable_unprepare(sp->clk);
-err_put_master:
- spi_master_put(sp->bitbang.master);
return ret;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH -next v2 3/6] spi: omap-uwire: Switch to use __devm_spi_alloc_controller()
2022-09-22 8:30 [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers Yang Yingliang
2022-09-22 8:30 ` [PATCH -next v2 1/6] spi: oc-tiny: Switch to use __devm_spi_alloc_controller() Yang Yingliang
2022-09-22 8:30 ` [PATCH -next v2 2/6] spi: ath79: " Yang Yingliang
@ 2022-09-22 8:31 ` Yang Yingliang
2022-09-22 8:31 ` [PATCH -next v2 4/6] spi: ppc4xx: " Yang Yingliang
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Yang Yingliang @ 2022-09-22 8:31 UTC (permalink / raw)
To: linux-spi; +Cc: broonie, yangyingliang
With using __devm_spi_alloc_controller(), spi_controller_put() is called in
devres_release_all() whenever the device is unbound, so the spi_master_put()
in error path can be removed. Also replace spi_master_get_devdata() with
spi_controller_get_devdata().
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/spi/spi-omap-uwire.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/drivers/spi/spi-omap-uwire.c b/drivers/spi/spi-omap-uwire.c
index 29198e6815b2..9fc8f3342ea4 100644
--- a/drivers/spi/spi-omap-uwire.c
+++ b/drivers/spi/spi-omap-uwire.c
@@ -448,25 +448,23 @@ static void uwire_off(struct uwire_spi *uwire)
{
uwire_write_reg(UWIRE_SR3, 0);
clk_disable_unprepare(uwire->ck);
- spi_master_put(uwire->bitbang.master);
}
static int uwire_probe(struct platform_device *pdev)
{
- struct spi_master *master;
+ struct spi_controller *ctlr;
struct uwire_spi *uwire;
int status;
- master = spi_alloc_master(&pdev->dev, sizeof(*uwire));
- if (!master)
+ ctlr = __devm_spi_alloc_controller(&pdev->dev, sizeof(*uwire), false);
+ if (!ctlr)
return -ENODEV;
- uwire = spi_master_get_devdata(master);
+ uwire = spi_controller_get_devdata(ctlr);
uwire_base = devm_ioremap(&pdev->dev, UWIRE_BASE_PHYS, UWIRE_IO_SIZE);
if (!uwire_base) {
dev_dbg(&pdev->dev, "can't ioremap UWIRE\n");
- spi_master_put(master);
return -ENOMEM;
}
@@ -476,7 +474,6 @@ static int uwire_probe(struct platform_device *pdev)
if (IS_ERR(uwire->ck)) {
status = PTR_ERR(uwire->ck);
dev_dbg(&pdev->dev, "no functional clock?\n");
- spi_master_put(master);
return status;
}
clk_prepare_enable(uwire->ck);
@@ -489,16 +486,16 @@ static int uwire_probe(struct platform_device *pdev)
uwire_write_reg(UWIRE_SR3, 1);
/* the spi->mode bits understood by this driver: */
- master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
- master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 16);
- master->flags = SPI_MASTER_HALF_DUPLEX;
+ ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
+ ctlr->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 16);
+ ctlr->flags = SPI_MASTER_HALF_DUPLEX;
- master->bus_num = 2; /* "official" */
- master->num_chipselect = 4;
- master->setup = uwire_setup;
- master->cleanup = uwire_cleanup;
+ ctlr->bus_num = 2; /* "official" */
+ ctlr->num_chipselect = 4;
+ ctlr->setup = uwire_setup;
+ ctlr->cleanup = uwire_cleanup;
- uwire->bitbang.master = master;
+ uwire->bitbang.master = ctlr;
uwire->bitbang.chipselect = uwire_chipselect;
uwire->bitbang.setup_transfer = uwire_setup_transfer;
uwire->bitbang.txrx_bufs = uwire_txrx;
@@ -518,6 +515,7 @@ static int uwire_remove(struct platform_device *pdev)
spi_bitbang_stop(&uwire->bitbang);
uwire_off(uwire);
+ spi_master_put(uwire->bitbang.master);
return 0;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH -next v2 4/6] spi: ppc4xx: Switch to use __devm_spi_alloc_controller()
2022-09-22 8:30 [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers Yang Yingliang
` (2 preceding siblings ...)
2022-09-22 8:31 ` [PATCH -next v2 3/6] spi: omap-uwire: " Yang Yingliang
@ 2022-09-22 8:31 ` Yang Yingliang
2022-09-22 8:31 ` [PATCH -next v2 5/6] spi: sh-sci: " Yang Yingliang
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Yang Yingliang @ 2022-09-22 8:31 UTC (permalink / raw)
To: linux-spi; +Cc: broonie, yangyingliang
With using __devm_spi_alloc_controller(), spi_controller_put() is called in
devres_release_all() whenever the device is unbound, so the spi_master_put()
in error path can be removed. Also replace spi_master_get_devdata() with
spi_controller_get_devdata().
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/spi/spi-ppc4xx.c | 29 ++++++++++++-----------------
1 file changed, 12 insertions(+), 17 deletions(-)
diff --git a/drivers/spi/spi-ppc4xx.c b/drivers/spi/spi-ppc4xx.c
index d65f047b6c82..89ea6ee0afdb 100644
--- a/drivers/spi/spi-ppc4xx.c
+++ b/drivers/spi/spi-ppc4xx.c
@@ -340,7 +340,7 @@ static void spi_ppc4xx_enable(struct ppc4xx_spi *hw)
static int spi_ppc4xx_of_probe(struct platform_device *op)
{
struct ppc4xx_spi *hw;
- struct spi_master *master;
+ struct spi_controller *ctlr;
struct spi_bitbang *bbp;
struct resource resource;
struct device_node *np = op->dev.of_node;
@@ -349,13 +349,13 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
int ret;
const unsigned int *clk;
- master = spi_alloc_master(dev, sizeof(*hw));
- if (master == NULL)
+ ctlr = __devm_spi_alloc_controller(dev, sizeof(*hw), false);
+ if (!ctlr)
return -ENOMEM;
- master->dev.of_node = np;
- platform_set_drvdata(op, master);
- hw = spi_master_get_devdata(master);
- hw->master = master;
+ ctlr->dev.of_node = np;
+ platform_set_drvdata(op, ctlr);
+ hw = spi_controller_get_devdata(ctlr);
+ hw->master = ctlr;
hw->dev = dev;
init_completion(&hw->done);
@@ -384,16 +384,14 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
opbnp = of_find_compatible_node(NULL, NULL, "ibm,opb");
if (opbnp == NULL) {
dev_err(dev, "OPB: cannot find node\n");
- ret = -ENODEV;
- goto free_master;
+ return -ENODEV;
}
/* Get the clock (Hz) for the OPB */
clk = of_get_property(opbnp, "clock-frequency", NULL);
if (clk == NULL) {
dev_err(dev, "OPB: no clock-frequency property set\n");
of_node_put(opbnp);
- ret = -ENODEV;
- goto free_master;
+ return -ENODEV;
}
hw->opb_freq = *clk;
hw->opb_freq >>= 2;
@@ -402,7 +400,7 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
ret = of_address_to_resource(np, 0, &resource);
if (ret) {
dev_err(dev, "error while parsing device node resource\n");
- goto free_master;
+ return ret;
}
hw->mapbase = resource.start;
hw->mapsize = resource_size(&resource);
@@ -410,8 +408,7 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
/* Sanity check */
if (hw->mapsize < sizeof(struct spi_ppc4xx_regs)) {
dev_err(dev, "too small to map registers\n");
- ret = -EINVAL;
- goto free_master;
+ return -EINVAL;
}
/* Request IRQ */
@@ -420,7 +417,7 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
0, "spi_ppc4xx_of", (void *)hw);
if (ret) {
dev_err(dev, "unable to allocate interrupt\n");
- goto free_master;
+ return ret;
}
if (!request_mem_region(hw->mapbase, hw->mapsize, DRIVER_NAME)) {
@@ -457,8 +454,6 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
release_mem_region(hw->mapbase, hw->mapsize);
request_mem_error:
free_irq(hw->irqnum, hw);
-free_master:
- spi_master_put(master);
dev_err(dev, "initialization failed\n");
return ret;
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH -next v2 5/6] spi: sh-sci: Switch to use __devm_spi_alloc_controller()
2022-09-22 8:30 [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers Yang Yingliang
` (3 preceding siblings ...)
2022-09-22 8:31 ` [PATCH -next v2 4/6] spi: ppc4xx: " Yang Yingliang
@ 2022-09-22 8:31 ` Yang Yingliang
2022-09-22 8:31 ` [PATCH -next v2 6/6] spi: altera: " Yang Yingliang
2022-09-23 4:45 ` [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers Lukas Wunner
6 siblings, 0 replies; 8+ messages in thread
From: Yang Yingliang @ 2022-09-22 8:31 UTC (permalink / raw)
To: linux-spi; +Cc: broonie, yangyingliang
With using __devm_spi_alloc_controller(), spi_controller_put() is called in
devres_release_all() whenever the device is unbound, so the spi_master_put()
in error path can be removed. Also replace spi_master_get_devdata() with
spi_controller_get_devdata().
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/spi/spi-sh-sci.c | 44 ++++++++++++++++------------------------
1 file changed, 18 insertions(+), 26 deletions(-)
diff --git a/drivers/spi/spi-sh-sci.c b/drivers/spi/spi-sh-sci.c
index 8f30531e1418..64f9d85cce0f 100644
--- a/drivers/spi/spi-sh-sci.c
+++ b/drivers/spi/spi-sh-sci.c
@@ -114,29 +114,27 @@ static void sh_sci_spi_chipselect(struct spi_device *dev, int value)
static int sh_sci_spi_probe(struct platform_device *dev)
{
struct resource *r;
- struct spi_master *master;
+ struct spi_controller *ctlr;
struct sh_sci_spi *sp;
int ret;
- master = spi_alloc_master(&dev->dev, sizeof(struct sh_sci_spi));
- if (master == NULL) {
- dev_err(&dev->dev, "failed to allocate spi master\n");
- ret = -ENOMEM;
- goto err0;
+ ctlr = __devm_spi_alloc_controller(&dev->dev, sizeof(*sp), false);
+ if (!ctlr) {
+ dev_err(&dev->dev, "failed to allocate spi controller\n");
+ return -ENOMEM;
}
- sp = spi_master_get_devdata(master);
+ sp = spi_controller_get_devdata(ctlr);
platform_set_drvdata(dev, sp);
sp->info = dev_get_platdata(&dev->dev);
if (!sp->info) {
dev_err(&dev->dev, "platform data is missing\n");
- ret = -ENOENT;
- goto err1;
+ return -ENOENT;
}
/* setup spi bitbang adaptor */
- sp->bitbang.master = master;
+ sp->bitbang.master = ctlr;
sp->bitbang.master->bus_num = sp->info->bus_num;
sp->bitbang.master->num_chipselect = sp->info->num_chipselect;
sp->bitbang.chipselect = sh_sci_spi_chipselect;
@@ -147,28 +145,22 @@ static int sh_sci_spi_probe(struct platform_device *dev)
sp->bitbang.txrx_word[SPI_MODE_3] = sh_sci_spi_txrx_mode3;
r = platform_get_resource(dev, IORESOURCE_MEM, 0);
- if (r == NULL) {
- ret = -ENOENT;
- goto err1;
- }
+ if (r == NULL)
+ return -ENOENT;
sp->membase = ioremap(r->start, resource_size(r));
- if (!sp->membase) {
- ret = -ENXIO;
- goto err1;
- }
+ if (!sp->membase)
+ return -ENXIO;
sp->val = ioread8(SCSPTR(sp));
setbits(sp, PIN_INIT, 1);
ret = spi_bitbang_start(&sp->bitbang);
- if (!ret)
- return 0;
+ if (ret) {
+ setbits(sp, PIN_INIT, 0);
+ iounmap(sp->membase);
+ return ret;
+ }
- setbits(sp, PIN_INIT, 0);
- iounmap(sp->membase);
- err1:
- spi_master_put(sp->bitbang.master);
- err0:
- return ret;
+ return 0;
}
static int sh_sci_spi_remove(struct platform_device *dev)
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH -next v2 6/6] spi: altera: Switch to use __devm_spi_alloc_controller()
2022-09-22 8:30 [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers Yang Yingliang
` (4 preceding siblings ...)
2022-09-22 8:31 ` [PATCH -next v2 5/6] spi: sh-sci: " Yang Yingliang
@ 2022-09-22 8:31 ` Yang Yingliang
2022-09-23 4:45 ` [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers Lukas Wunner
6 siblings, 0 replies; 8+ messages in thread
From: Yang Yingliang @ 2022-09-22 8:31 UTC (permalink / raw)
To: linux-spi; +Cc: broonie, yangyingliang
With using __devm_spi_alloc_controller(), spi_controller_put() is called in
devres_release_all() whenever the device is unbound, so the spi_master_put()
in error path can be removed.
Also replace spi_master_get_devdata() and devm_spi_register_master() with
spi_controller_get_devdata() and devm_spi_register_controller().
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/spi/spi-altera-platform.c | 55 ++++++++++++++-----------------
1 file changed, 24 insertions(+), 31 deletions(-)
diff --git a/drivers/spi/spi-altera-platform.c b/drivers/spi/spi-altera-platform.c
index 65147aae82a1..7404e5eaaeb2 100644
--- a/drivers/spi/spi-altera-platform.c
+++ b/drivers/spi/spi-altera-platform.c
@@ -39,38 +39,37 @@ static int altera_spi_probe(struct platform_device *pdev)
struct altera_spi_platform_data *pdata = dev_get_platdata(&pdev->dev);
enum altera_spi_type type = ALTERA_SPI_TYPE_UNKNOWN;
struct altera_spi *hw;
- struct spi_master *master;
+ struct spi_controller *ctlr;
int err = -ENODEV;
u16 i;
- master = spi_alloc_master(&pdev->dev, sizeof(struct altera_spi));
- if (!master)
+ ctlr = __devm_spi_alloc_controller(&pdev->dev, sizeof(*hw), false);
+ if (!ctlr)
return err;
- /* setup the master state. */
- master->bus_num = -1;
+ /* setup the controller state. */
+ ctlr->bus_num = -1;
if (pdata) {
if (pdata->num_chipselect > ALTERA_SPI_MAX_CS) {
dev_err(&pdev->dev,
"Invalid number of chipselect: %u\n",
pdata->num_chipselect);
- err = -EINVAL;
- goto exit;
+ return -EINVAL;
}
- master->num_chipselect = pdata->num_chipselect;
- master->mode_bits = pdata->mode_bits;
- master->bits_per_word_mask = pdata->bits_per_word_mask;
+ ctlr->num_chipselect = pdata->num_chipselect;
+ ctlr->mode_bits = pdata->mode_bits;
+ ctlr->bits_per_word_mask = pdata->bits_per_word_mask;
} else {
- master->num_chipselect = 16;
- master->mode_bits = SPI_CS_HIGH;
- master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 16);
+ ctlr->num_chipselect = 16;
+ ctlr->mode_bits = SPI_CS_HIGH;
+ ctlr->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 16);
}
- master->dev.of_node = pdev->dev.of_node;
+ ctlr->dev.of_node = pdev->dev.of_node;
- hw = spi_master_get_devdata(master);
+ hw = spi_controller_get_devdata(ctlr);
hw->dev = &pdev->dev;
if (platid)
@@ -83,7 +82,7 @@ static int altera_spi_probe(struct platform_device *pdev)
hw->regmap = dev_get_regmap(pdev->dev.parent, NULL);
if (!hw->regmap) {
dev_err(&pdev->dev, "get regmap failed\n");
- goto exit;
+ return err;
}
regoff = platform_get_resource(pdev, IORESOURCE_REG, 0);
@@ -93,38 +92,35 @@ static int altera_spi_probe(struct platform_device *pdev)
void __iomem *res;
res = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(res)) {
- err = PTR_ERR(res);
- goto exit;
- }
+ if (IS_ERR(res))
+ return PTR_ERR(res);
hw->regmap = devm_regmap_init_mmio(&pdev->dev, res,
&spi_altera_config);
if (IS_ERR(hw->regmap)) {
dev_err(&pdev->dev, "regmap mmio init failed\n");
- err = PTR_ERR(hw->regmap);
- goto exit;
+ return PTR_ERR(hw->regmap);
}
}
- altera_spi_init_master(master);
+ altera_spi_init_master(ctlr);
/* irq is optional */
hw->irq = platform_get_irq(pdev, 0);
if (hw->irq >= 0) {
err = devm_request_irq(&pdev->dev, hw->irq, altera_spi_irq, 0,
- pdev->name, master);
+ pdev->name, ctlr);
if (err)
- goto exit;
+ return err;
}
- err = devm_spi_register_master(&pdev->dev, master);
+ err = devm_spi_register_controller(&pdev->dev, ctlr);
if (err)
- goto exit;
+ return err;
if (pdata) {
for (i = 0; i < pdata->num_devices; i++) {
- if (!spi_new_device(master, pdata->devices + i))
+ if (!spi_new_device(ctlr, pdata->devices + i))
dev_warn(&pdev->dev,
"unable to create SPI device: %s\n",
pdata->devices[i].modalias);
@@ -134,9 +130,6 @@ static int altera_spi_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "regoff %u, irq %d\n", hw->regoff, hw->irq);
return 0;
-exit:
- spi_master_put(master);
- return err;
}
#ifdef CONFIG_OF
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers
2022-09-22 8:30 [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers Yang Yingliang
` (5 preceding siblings ...)
2022-09-22 8:31 ` [PATCH -next v2 6/6] spi: altera: " Yang Yingliang
@ 2022-09-23 4:45 ` Lukas Wunner
6 siblings, 0 replies; 8+ messages in thread
From: Lukas Wunner @ 2022-09-23 4:45 UTC (permalink / raw)
To: Yang Yingliang; +Cc: linux-spi, broonie
On Thu, Sep 22, 2022 at 04:30:57PM +0800, Yang Yingliang wrote:
> This patchset is trying to replace spi_alloc_master() with
> __devm_spi_alloc_controller() in some spi drivers.
NAK for v2 of this series, drivers should never call
__devm_spi_alloc_controller() directly.
Thanks,
Lukas
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-09-23 4:45 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-22 8:30 [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers Yang Yingliang
2022-09-22 8:30 ` [PATCH -next v2 1/6] spi: oc-tiny: Switch to use __devm_spi_alloc_controller() Yang Yingliang
2022-09-22 8:30 ` [PATCH -next v2 2/6] spi: ath79: " Yang Yingliang
2022-09-22 8:31 ` [PATCH -next v2 3/6] spi: omap-uwire: " Yang Yingliang
2022-09-22 8:31 ` [PATCH -next v2 4/6] spi: ppc4xx: " Yang Yingliang
2022-09-22 8:31 ` [PATCH -next v2 5/6] spi: sh-sci: " Yang Yingliang
2022-09-22 8:31 ` [PATCH -next v2 6/6] spi: altera: " Yang Yingliang
2022-09-23 4:45 ` [PATCH -next v2 0/6] spi: Switch to use __devm_spi_alloc_controller() in some drivers Lukas Wunner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).