From: Barry Song <Barry.Song-kQvG35nSl+M@public.gmane.org> To: <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>, <linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org> Cc: <linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>, <workgroup.linux-kQvG35nSl+M@public.gmane.org>, Qipan Li <Qipan.Li-kQvG35nSl+M@public.gmane.org>, Barry Song <Baohua.Song-kQvG35nSl+M@public.gmane.org> Subject: [PATCH 2/8] spi: sirf: request and free cs gpio in setup and cleanup callbacks Date: Tue, 2 Sep 2014 17:01:02 +0800 [thread overview] Message-ID: <1409648468-5436-3-git-send-email-Barry.Song@csr.com> (raw) In-Reply-To: <1409648468-5436-1-git-send-email-Barry.Song-kQvG35nSl+M@public.gmane.org> From: Qipan Li <Qipan.Li-kQvG35nSl+M@public.gmane.org> move spi controller's gpio request work out from probe() to spi device register stage, so after spi device register spi controller can deactive device's gpio chipselect. old code can't do it because gpio request has not be done until device register is finised in spi_bitbang_start. and add cleanup function to free CS gpio. Signed-off-by: Qipan Li <Qipan.Li-kQvG35nSl+M@public.gmane.org> Signed-off-by: Barry Song <Baohua.Song-kQvG35nSl+M@public.gmane.org> --- drivers/spi/spi-sirf.c | 58 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/drivers/spi/spi-sirf.c b/drivers/spi/spi-sirf.c index 44ec3bb..a21e423 100644 --- a/drivers/spi/spi-sirf.c +++ b/drivers/spi/spi-sirf.c @@ -626,7 +626,7 @@ spi_sirfsoc_setup_transfer(struct spi_device *spi, struct spi_transfer *t) static int spi_sirfsoc_setup(struct spi_device *spi) { struct sirfsoc_spi *sspi; - + int ret = 0; if (!spi->max_speed_hz) return -EINVAL; @@ -634,9 +634,41 @@ static int spi_sirfsoc_setup(struct spi_device *spi) if (spi->cs_gpio == -ENOENT) sspi->hw_cs = true; - else + else { sspi->hw_cs = false; - return spi_sirfsoc_setup_transfer(spi, NULL); + if (!spi_get_ctldata(spi)) { + void *cs = kmalloc(sizeof(int), GFP_KERNEL); + if (!cs) { + ret = -ENOMEM; + goto exit; + } + ret = gpio_is_valid(spi->cs_gpio); + if (!ret) { + dev_err(&spi->dev, "no valid gpio\n"); + ret = -ENOENT; + goto exit; + } + ret = gpio_request(spi->cs_gpio, DRIVER_NAME); + if (ret) { + dev_err(&spi->dev, "failed to request gpio\n"); + goto exit; + } + spi_set_ctldata(spi, cs); + } + } + writel(readl(sspi->base + SIRFSOC_SPI_CTRL) | SIRFSOC_SPI_CS_IO_MODE, + sspi->base + SIRFSOC_SPI_CTRL); + spi_sirfsoc_chipselect(spi, BITBANG_CS_INACTIVE); +exit: + return ret; +} + +static void spi_sirfsoc_cleanup(struct spi_device *spi) +{ + if (spi_get_ctldata(spi)) { + gpio_free(spi->cs_gpio); + kfree(spi_get_ctldata(spi)); + } } static int spi_sirfsoc_probe(struct platform_device *pdev) @@ -645,7 +677,7 @@ static int spi_sirfsoc_probe(struct platform_device *pdev) struct spi_master *master; struct resource *mem_res; int irq; - int i, ret; + int ret; master = spi_alloc_master(&pdev->dev, sizeof(*sspi)); if (!master) { @@ -677,6 +709,7 @@ static int spi_sirfsoc_probe(struct platform_device *pdev) sspi->bitbang.setup_transfer = spi_sirfsoc_setup_transfer; sspi->bitbang.txrx_bufs = spi_sirfsoc_transfer; sspi->bitbang.master->setup = spi_sirfsoc_setup; + sspi->bitbang.master->cleanup = spi_sirfsoc_cleanup; master->bus_num = pdev->id; master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST | SPI_CS_HIGH; master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(12) | @@ -723,22 +756,7 @@ static int spi_sirfsoc_probe(struct platform_device *pdev) ret = spi_bitbang_start(&sspi->bitbang); if (ret) - goto free_dummypage; - for (i = 0; master->cs_gpios && i < master->num_chipselect; i++) { - if (master->cs_gpios[i] == -ENOENT) - continue; - if (!gpio_is_valid(master->cs_gpios[i])) { - dev_err(&pdev->dev, "no valid gpio\n"); - ret = -EINVAL; - goto free_dummypage; - } - ret = devm_gpio_request(&pdev->dev, - master->cs_gpios[i], DRIVER_NAME); - if (ret) { - dev_err(&pdev->dev, "failed to request gpio\n"); - goto free_dummypage; - } - } + goto free_clk; dev_info(&pdev->dev, "registerred, bus number = %d\n", master->bus_num); return 0; -- 2.1.0 Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc. New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com. -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
From: Barry.Song@csr.com (Barry Song) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/8] spi: sirf: request and free cs gpio in setup and cleanup callbacks Date: Tue, 2 Sep 2014 17:01:02 +0800 [thread overview] Message-ID: <1409648468-5436-3-git-send-email-Barry.Song@csr.com> (raw) In-Reply-To: <1409648468-5436-1-git-send-email-Barry.Song@csr.com> From: Qipan Li <Qipan.Li@csr.com> move spi controller's gpio request work out from probe() to spi device register stage, so after spi device register spi controller can deactive device's gpio chipselect. old code can't do it because gpio request has not be done until device register is finised in spi_bitbang_start. and add cleanup function to free CS gpio. Signed-off-by: Qipan Li <Qipan.Li@csr.com> Signed-off-by: Barry Song <Baohua.Song@csr.com> --- drivers/spi/spi-sirf.c | 58 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/drivers/spi/spi-sirf.c b/drivers/spi/spi-sirf.c index 44ec3bb..a21e423 100644 --- a/drivers/spi/spi-sirf.c +++ b/drivers/spi/spi-sirf.c @@ -626,7 +626,7 @@ spi_sirfsoc_setup_transfer(struct spi_device *spi, struct spi_transfer *t) static int spi_sirfsoc_setup(struct spi_device *spi) { struct sirfsoc_spi *sspi; - + int ret = 0; if (!spi->max_speed_hz) return -EINVAL; @@ -634,9 +634,41 @@ static int spi_sirfsoc_setup(struct spi_device *spi) if (spi->cs_gpio == -ENOENT) sspi->hw_cs = true; - else + else { sspi->hw_cs = false; - return spi_sirfsoc_setup_transfer(spi, NULL); + if (!spi_get_ctldata(spi)) { + void *cs = kmalloc(sizeof(int), GFP_KERNEL); + if (!cs) { + ret = -ENOMEM; + goto exit; + } + ret = gpio_is_valid(spi->cs_gpio); + if (!ret) { + dev_err(&spi->dev, "no valid gpio\n"); + ret = -ENOENT; + goto exit; + } + ret = gpio_request(spi->cs_gpio, DRIVER_NAME); + if (ret) { + dev_err(&spi->dev, "failed to request gpio\n"); + goto exit; + } + spi_set_ctldata(spi, cs); + } + } + writel(readl(sspi->base + SIRFSOC_SPI_CTRL) | SIRFSOC_SPI_CS_IO_MODE, + sspi->base + SIRFSOC_SPI_CTRL); + spi_sirfsoc_chipselect(spi, BITBANG_CS_INACTIVE); +exit: + return ret; +} + +static void spi_sirfsoc_cleanup(struct spi_device *spi) +{ + if (spi_get_ctldata(spi)) { + gpio_free(spi->cs_gpio); + kfree(spi_get_ctldata(spi)); + } } static int spi_sirfsoc_probe(struct platform_device *pdev) @@ -645,7 +677,7 @@ static int spi_sirfsoc_probe(struct platform_device *pdev) struct spi_master *master; struct resource *mem_res; int irq; - int i, ret; + int ret; master = spi_alloc_master(&pdev->dev, sizeof(*sspi)); if (!master) { @@ -677,6 +709,7 @@ static int spi_sirfsoc_probe(struct platform_device *pdev) sspi->bitbang.setup_transfer = spi_sirfsoc_setup_transfer; sspi->bitbang.txrx_bufs = spi_sirfsoc_transfer; sspi->bitbang.master->setup = spi_sirfsoc_setup; + sspi->bitbang.master->cleanup = spi_sirfsoc_cleanup; master->bus_num = pdev->id; master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST | SPI_CS_HIGH; master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(12) | @@ -723,22 +756,7 @@ static int spi_sirfsoc_probe(struct platform_device *pdev) ret = spi_bitbang_start(&sspi->bitbang); if (ret) - goto free_dummypage; - for (i = 0; master->cs_gpios && i < master->num_chipselect; i++) { - if (master->cs_gpios[i] == -ENOENT) - continue; - if (!gpio_is_valid(master->cs_gpios[i])) { - dev_err(&pdev->dev, "no valid gpio\n"); - ret = -EINVAL; - goto free_dummypage; - } - ret = devm_gpio_request(&pdev->dev, - master->cs_gpios[i], DRIVER_NAME); - if (ret) { - dev_err(&pdev->dev, "failed to request gpio\n"); - goto free_dummypage; - } - } + goto free_clk; dev_info(&pdev->dev, "registerred, bus number = %d\n", master->bus_num); return 0; -- 2.1.0 Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc. New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.
next prev parent reply other threads:[~2014-09-02 9:01 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-09-02 9:01 [PATCH 0/8] spi: sirf: a bundle of fixes and cleanups Barry Song 2014-09-02 9:01 ` Barry Song [not found] ` <1409648468-5436-1-git-send-email-Barry.Song-kQvG35nSl+M@public.gmane.org> 2014-09-02 9:01 ` [PATCH 1/8] spi: sirf: correct spi gpio and hardware chipselect behaviour Barry Song 2014-09-02 9:01 ` Barry Song [not found] ` <1409648468-5436-2-git-send-email-Barry.Song-kQvG35nSl+M@public.gmane.org> 2014-09-04 19:20 ` Mark Brown 2014-09-04 19:20 ` Mark Brown 2014-09-02 9:01 ` Barry Song [this message] 2014-09-02 9:01 ` [PATCH 2/8] spi: sirf: request and free cs gpio in setup and cleanup callbacks Barry Song [not found] ` <1409648468-5436-3-git-send-email-Barry.Song-kQvG35nSl+M@public.gmane.org> 2014-09-04 19:19 ` Mark Brown 2014-09-04 19:19 ` Mark Brown [not found] ` <20140904191954.GO29327-GFdadSzt00ze9xe1eoZjHA@public.gmane.org> 2014-09-05 3:34 ` swingboard 2014-09-05 3:34 ` swingboard [not found] ` <CA+qxAP06x5uHzObuWzmcAjFz4YKHRxxH5FE5cGZYzKQNUsJdyg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2014-09-06 13:57 ` Mark Brown 2014-09-06 13:57 ` Mark Brown [not found] ` <20140906135735.GE2601-GFdadSzt00ze9xe1eoZjHA@public.gmane.org> 2014-09-07 0:50 ` Barry Song 2014-09-07 0:50 ` Barry Song [not found] ` <D031CA8D.21605%21cnbao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2015-04-28 3:36 ` Barry Song 2015-04-28 3:36 ` Barry Song [not found] ` <CAGsJ_4yhSFnzyZV6B3j90LyJbstsyBJHCnk=LZqVDsL_u8foPQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2015-04-30 10:16 ` Mark Brown 2015-04-30 10:16 ` Mark Brown 2014-09-02 9:01 ` [PATCH 3/8] spi: sirf: enable RX_IO_DMA_INT interrupt Barry Song 2014-09-02 9:01 ` Barry Song [not found] ` <1409648468-5436-4-git-send-email-Barry.Song-kQvG35nSl+M@public.gmane.org> 2014-09-04 19:27 ` Mark Brown 2014-09-04 19:27 ` Mark Brown 2014-09-02 9:01 ` [PATCH 4/8] spi: sirf: fix 'cmd_transfer' function typos Barry Song 2014-09-02 9:01 ` Barry Song [not found] ` <1409648468-5436-5-git-send-email-Barry.Song-kQvG35nSl+M@public.gmane.org> 2014-09-04 22:36 ` Mark Brown 2014-09-04 22:36 ` Mark Brown
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1409648468-5436-3-git-send-email-Barry.Song@csr.com \ --to=barry.song-kqvg35nsl+m@public.gmane.org \ --cc=Baohua.Song-kQvG35nSl+M@public.gmane.org \ --cc=Qipan.Li-kQvG35nSl+M@public.gmane.org \ --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \ --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \ --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \ --cc=workgroup.linux-kQvG35nSl+M@public.gmane.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.