* [PATCH 1/2] spi: spi-mpc512x-psc: init mode bits supported by the driver @ 2013-01-14 20:27 Anatolij Gustschin [not found] ` <1358195221-18488-1-git-send-email-agust-ynQEQJNshbs@public.gmane.org> 0 siblings, 1 reply; 8+ messages in thread From: Anatolij Gustschin @ 2013-01-14 20:27 UTC (permalink / raw) To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f The driver should setup mode bits it supports, otherwise adding an SPI device might fail even if the driver supports the requested SPI mode. Signed-off-by: Anatolij Gustschin <agust-ynQEQJNshbs@public.gmane.org> --- drivers/spi/spi-mpc512x-psc.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c index 88e5441..89480b2 100644 --- a/drivers/spi/spi-mpc512x-psc.c +++ b/drivers/spi/spi-mpc512x-psc.c @@ -438,6 +438,7 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, master->num_chipselect = pdata->max_chipselect; } + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST; master->setup = mpc512x_psc_spi_setup; master->transfer = mpc512x_psc_spi_transfer; master->cleanup = mpc512x_psc_spi_cleanup; -- 1.7.5.4 ------------------------------------------------------------------------------ Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122412 ^ permalink raw reply related [flat|nested] 8+ messages in thread
[parent not found: <1358195221-18488-1-git-send-email-agust-ynQEQJNshbs@public.gmane.org>]
* [PATCH 2/2] spi: spi-mpc512x-psc: add support for gpio chip selects [not found] ` <1358195221-18488-1-git-send-email-agust-ynQEQJNshbs@public.gmane.org> @ 2013-01-14 20:27 ` Anatolij Gustschin [not found] ` <1358195221-18488-2-git-send-email-agust-ynQEQJNshbs@public.gmane.org> 2013-02-05 14:16 ` [PATCH 1/2] spi: spi-mpc512x-psc: init mode bits supported by the driver Grant Likely 1 sibling, 1 reply; 8+ messages in thread From: Anatolij Gustschin @ 2013-01-14 20:27 UTC (permalink / raw) To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f Currently the driver only uses one internal chip select. Add support for gpio chip selects configured by gpio specifiers in the device tree. Signed-off-by: Anatolij Gustschin <agust-ynQEQJNshbs@public.gmane.org> --- drivers/spi/spi-mpc512x-psc.c | 80 ++++++++++++++++++++++++++++++++++++++--- 1 files changed, 75 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c index 89480b2..4b2f391 100644 --- a/drivers/spi/spi-mpc512x-psc.c +++ b/drivers/spi/spi-mpc512x-psc.c @@ -20,6 +20,7 @@ #include <linux/errno.h> #include <linux/interrupt.h> #include <linux/of_address.h> +#include <linux/of_gpio.h> #include <linux/of_platform.h> #include <linux/workqueue.h> #include <linux/completion.h> @@ -50,6 +51,8 @@ struct mpc512x_psc_spi { spinlock_t lock; /* Message queue lock */ struct completion done; + int num_cs; + int chipselects[0]; }; /* controller state */ @@ -277,6 +280,7 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi) { struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); struct mpc512x_psc_spi_cs *cs = spi->controller_state; + int gpio = mps->chipselects[spi->chip_select]; unsigned long flags; if (spi->bits_per_word % 8) @@ -292,6 +296,9 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi) cs->bits_per_word = spi->bits_per_word; cs->speed_hz = spi->max_speed_hz; + if (gpio_is_valid(gpio)) + gpio_direction_output(gpio, spi->mode & SPI_CS_HIGH ? 0 : 1); + spin_lock_irqsave(&mps->lock, flags); if (!mps->busy) mpc512x_psc_spi_deactivate_cs(spi); @@ -405,6 +412,27 @@ static irqreturn_t mpc512x_psc_spi_isr(int irq, void *dev_id) return IRQ_NONE; } +static void mpc512x_spi_cs_control(struct spi_device *spi, bool on) +{ + struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); + int gpio = mps->chipselects[spi->chip_select]; + + gpio_set_value(gpio, on); +} + +static int mpc512x_spi_cs_num(struct device *dev) +{ + int num_cs, ret; + + ret = of_property_read_u32(dev->of_node, "num-cs", &num_cs); + if (ret < 0) { + dev_warn(dev, "no num-cs property\n"); + return of_gpio_named_count(dev->of_node, "cs-gpios"); + } + + return num_cs; +} + /* bus_num is used only for the case dev->platform_data == NULL */ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, u32 size, unsigned int irq, @@ -415,8 +443,17 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, struct spi_master *master; int ret; void *tempp; + int i = 0, max_cs_num = 0; + int use_internal_cs = 0; + int num_cs; + + num_cs = mpc512x_spi_cs_num(dev); + if (!num_cs) + use_internal_cs = 1; - master = spi_alloc_master(dev, sizeof *mps); + dev_dbg(dev, "using %d gpio chipselects\n", num_cs); + + master = spi_alloc_master(dev, sizeof(*mps) + sizeof(int) * num_cs); if (master == NULL) return -ENOMEM; @@ -425,12 +462,14 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, mps->irq = irq; if (pdata == NULL) { - dev_err(dev, "probe called without platform data, no " - "cs_control function will be called\n"); - mps->cs_control = NULL; mps->sysclk = 0; master->bus_num = bus_num; - master->num_chipselect = 255; + if (use_internal_cs) { + mps->cs_control = NULL; + master->num_chipselect = 1; + } else { + mps->cs_control = mpc512x_spi_cs_control; + } } else { mps->cs_control = pdata->cs_control; mps->sysclk = pdata->sysclk; @@ -438,6 +477,28 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, master->num_chipselect = pdata->max_chipselect; } + if (!pdata && !use_internal_cs) { + for (i = 0; i < num_cs; i++) { + int cs_gpio = of_get_named_gpio(dev->of_node, + "cs-gpios", i); + + dev_dbg(dev, "cs %d: gpio %d\n", i, cs_gpio); + mps->chipselects[i] = cs_gpio; + if (!gpio_is_valid(cs_gpio)) + continue; + + max_cs_num = max(max_cs_num, cs_gpio); + ret = gpio_request(mps->chipselects[i], + "psc-spi cs"); + if (ret) { + dev_err(dev, "can't get CS gpio: %d\n", ret); + goto free_cs_gpios; + } + } + master->num_chipselect = max_cs_num; + mps->num_cs = num_cs; + } + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST; master->setup = mpc512x_psc_spi_setup; master->transfer = mpc512x_psc_spi_transfer; @@ -485,6 +546,11 @@ unreg_master: destroy_workqueue(mps->workqueue); free_irq: free_irq(mps->irq, mps); +free_cs_gpios: + while (--i >= 0) { + if (gpio_is_valid(mps->chipselects[i])) + gpio_free(mps->chipselects[i]); + } free_master: if (mps->psc) iounmap(mps->psc); @@ -497,6 +563,7 @@ static int mpc512x_psc_spi_do_remove(struct device *dev) { struct spi_master *master = spi_master_get(dev_get_drvdata(dev)); struct mpc512x_psc_spi *mps = spi_master_get_devdata(master); + int i; flush_workqueue(mps->workqueue); destroy_workqueue(mps->workqueue); @@ -504,6 +571,9 @@ static int mpc512x_psc_spi_do_remove(struct device *dev) free_irq(mps->irq, mps); if (mps->psc) iounmap(mps->psc); + for (i = 0; i < mps->num_cs; i++) + if (gpio_is_valid(mps->chipselects[i])) + gpio_free(mps->chipselects[i]); spi_master_put(master); return 0; -- 1.7.5.4 ------------------------------------------------------------------------------ Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122412 ^ permalink raw reply related [flat|nested] 8+ messages in thread
[parent not found: <1358195221-18488-2-git-send-email-agust-ynQEQJNshbs@public.gmane.org>]
* Re: [PATCH 2/2] spi: spi-mpc512x-psc: add support for gpio chip selects [not found] ` <1358195221-18488-2-git-send-email-agust-ynQEQJNshbs@public.gmane.org> @ 2013-02-05 14:18 ` Grant Likely 2013-03-11 22:45 ` Anatolij Gustschin 2013-03-11 23:23 ` [PATCH v2] " Anatolij Gustschin 0 siblings, 2 replies; 8+ messages in thread From: Grant Likely @ 2013-02-05 14:18 UTC (permalink / raw) To: Anatolij Gustschin, spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f On Mon, 14 Jan 2013 21:27:01 +0100, Anatolij Gustschin <agust-ynQEQJNshbs@public.gmane.org> wrote: > Currently the driver only uses one internal chip select. Add support > for gpio chip selects configured by gpio specifiers in the device tree. > > Signed-off-by: Anatolij Gustschin <agust-ynQEQJNshbs@public.gmane.org> GPIO chip selects are now in the core spi library. Take a look at master->cs_gpios and Documentation/devicetree/bindings/spi/spi-bus.txt. You don't need to parse them manually. g. > --- > drivers/spi/spi-mpc512x-psc.c | 80 ++++++++++++++++++++++++++++++++++++++--- > 1 files changed, 75 insertions(+), 5 deletions(-) > > diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c > index 89480b2..4b2f391 100644 > --- a/drivers/spi/spi-mpc512x-psc.c > +++ b/drivers/spi/spi-mpc512x-psc.c > @@ -20,6 +20,7 @@ > #include <linux/errno.h> > #include <linux/interrupt.h> > #include <linux/of_address.h> > +#include <linux/of_gpio.h> > #include <linux/of_platform.h> > #include <linux/workqueue.h> > #include <linux/completion.h> > @@ -50,6 +51,8 @@ struct mpc512x_psc_spi { > spinlock_t lock; /* Message queue lock */ > > struct completion done; > + int num_cs; > + int chipselects[0]; > }; > > /* controller state */ > @@ -277,6 +280,7 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi) > { > struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); > struct mpc512x_psc_spi_cs *cs = spi->controller_state; > + int gpio = mps->chipselects[spi->chip_select]; > unsigned long flags; > > if (spi->bits_per_word % 8) > @@ -292,6 +296,9 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi) > cs->bits_per_word = spi->bits_per_word; > cs->speed_hz = spi->max_speed_hz; > > + if (gpio_is_valid(gpio)) > + gpio_direction_output(gpio, spi->mode & SPI_CS_HIGH ? 0 : 1); > + > spin_lock_irqsave(&mps->lock, flags); > if (!mps->busy) > mpc512x_psc_spi_deactivate_cs(spi); > @@ -405,6 +412,27 @@ static irqreturn_t mpc512x_psc_spi_isr(int irq, void *dev_id) > return IRQ_NONE; > } > > +static void mpc512x_spi_cs_control(struct spi_device *spi, bool on) > +{ > + struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); > + int gpio = mps->chipselects[spi->chip_select]; > + > + gpio_set_value(gpio, on); > +} > + > +static int mpc512x_spi_cs_num(struct device *dev) > +{ > + int num_cs, ret; > + > + ret = of_property_read_u32(dev->of_node, "num-cs", &num_cs); > + if (ret < 0) { > + dev_warn(dev, "no num-cs property\n"); > + return of_gpio_named_count(dev->of_node, "cs-gpios"); > + } > + > + return num_cs; > +} > + > /* bus_num is used only for the case dev->platform_data == NULL */ > static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, > u32 size, unsigned int irq, > @@ -415,8 +443,17 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, > struct spi_master *master; > int ret; > void *tempp; > + int i = 0, max_cs_num = 0; > + int use_internal_cs = 0; > + int num_cs; > + > + num_cs = mpc512x_spi_cs_num(dev); > + if (!num_cs) > + use_internal_cs = 1; > > - master = spi_alloc_master(dev, sizeof *mps); > + dev_dbg(dev, "using %d gpio chipselects\n", num_cs); > + > + master = spi_alloc_master(dev, sizeof(*mps) + sizeof(int) * num_cs); > if (master == NULL) > return -ENOMEM; > > @@ -425,12 +462,14 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, > mps->irq = irq; > > if (pdata == NULL) { > - dev_err(dev, "probe called without platform data, no " > - "cs_control function will be called\n"); > - mps->cs_control = NULL; > mps->sysclk = 0; > master->bus_num = bus_num; > - master->num_chipselect = 255; > + if (use_internal_cs) { > + mps->cs_control = NULL; > + master->num_chipselect = 1; > + } else { > + mps->cs_control = mpc512x_spi_cs_control; > + } > } else { > mps->cs_control = pdata->cs_control; > mps->sysclk = pdata->sysclk; > @@ -438,6 +477,28 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, > master->num_chipselect = pdata->max_chipselect; > } > > + if (!pdata && !use_internal_cs) { > + for (i = 0; i < num_cs; i++) { > + int cs_gpio = of_get_named_gpio(dev->of_node, > + "cs-gpios", i); > + > + dev_dbg(dev, "cs %d: gpio %d\n", i, cs_gpio); > + mps->chipselects[i] = cs_gpio; > + if (!gpio_is_valid(cs_gpio)) > + continue; > + > + max_cs_num = max(max_cs_num, cs_gpio); > + ret = gpio_request(mps->chipselects[i], > + "psc-spi cs"); > + if (ret) { > + dev_err(dev, "can't get CS gpio: %d\n", ret); > + goto free_cs_gpios; > + } > + } > + master->num_chipselect = max_cs_num; > + mps->num_cs = num_cs; > + } > + > master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST; > master->setup = mpc512x_psc_spi_setup; > master->transfer = mpc512x_psc_spi_transfer; > @@ -485,6 +546,11 @@ unreg_master: > destroy_workqueue(mps->workqueue); > free_irq: > free_irq(mps->irq, mps); > +free_cs_gpios: > + while (--i >= 0) { > + if (gpio_is_valid(mps->chipselects[i])) > + gpio_free(mps->chipselects[i]); > + } > free_master: > if (mps->psc) > iounmap(mps->psc); > @@ -497,6 +563,7 @@ static int mpc512x_psc_spi_do_remove(struct device *dev) > { > struct spi_master *master = spi_master_get(dev_get_drvdata(dev)); > struct mpc512x_psc_spi *mps = spi_master_get_devdata(master); > + int i; > > flush_workqueue(mps->workqueue); > destroy_workqueue(mps->workqueue); > @@ -504,6 +571,9 @@ static int mpc512x_psc_spi_do_remove(struct device *dev) > free_irq(mps->irq, mps); > if (mps->psc) > iounmap(mps->psc); > + for (i = 0; i < mps->num_cs; i++) > + if (gpio_is_valid(mps->chipselects[i])) > + gpio_free(mps->chipselects[i]); > spi_master_put(master); > > return 0; > -- > 1.7.5.4 > -- Grant Likely, B.Sc, P.Eng. Secret Lab Technologies, Ltd. ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] spi: spi-mpc512x-psc: add support for gpio chip selects 2013-02-05 14:18 ` Grant Likely @ 2013-03-11 22:45 ` Anatolij Gustschin 2013-03-11 23:23 ` [PATCH v2] " Anatolij Gustschin 1 sibling, 0 replies; 8+ messages in thread From: Anatolij Gustschin @ 2013-03-11 22:45 UTC (permalink / raw) To: Grant Likely; +Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f On Tue, 05 Feb 2013 14:18:46 +0000 Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org> wrote: > On Mon, 14 Jan 2013 21:27:01 +0100, Anatolij Gustschin <agust-ynQEQJNshbs@public.gmane.org> wrote: > > Currently the driver only uses one internal chip select. Add support > > for gpio chip selects configured by gpio specifiers in the device tree. > > > > Signed-off-by: Anatolij Gustschin <agust-ynQEQJNshbs@public.gmane.org> > > GPIO chip selects are now in the core spi library. Take a look at > master->cs_gpios and Documentation/devicetree/bindings/spi/spi-bus.txt. > You don't need to parse them manually. Thanks for the hint! I'll rework the patch and resubmit. Anatolij ------------------------------------------------------------------------------ Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the endpoint security space. For insight on selecting the right partner to tackle endpoint security challenges, access the full report. http://p.sf.net/sfu/symantec-dev2dev ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2] spi: spi-mpc512x-psc: add support for gpio chip selects 2013-02-05 14:18 ` Grant Likely 2013-03-11 22:45 ` Anatolij Gustschin @ 2013-03-11 23:23 ` Anatolij Gustschin [not found] ` <1363044215-24061-1-git-send-email-agust-ynQEQJNshbs@public.gmane.org> 1 sibling, 1 reply; 8+ messages in thread From: Anatolij Gustschin @ 2013-03-11 23:23 UTC (permalink / raw) To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f; +Cc: Anatolij Gustschin Currently the driver only uses one internal chip select. Add support for gpio chip selects configured by cs-gpios DT binding. Signed-off-by: Anatolij Gustschin <agust-ynQEQJNshbs@public.gmane.org> --- v2: - do not parse GPIO chip selects manually drivers/spi/spi-mpc512x-psc.c | 31 +++++++++++++++++++++++++------ 1 files changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c index 89480b2..4263ed4 100644 --- a/drivers/spi/spi-mpc512x-psc.c +++ b/drivers/spi/spi-mpc512x-psc.c @@ -28,6 +28,7 @@ #include <linux/clk.h> #include <linux/spi/spi.h> #include <linux/fsl_devices.h> +#include <linux/gpio.h> #include <asm/mpc52xx_psc.h> struct mpc512x_psc_spi { @@ -113,7 +114,7 @@ static void mpc512x_psc_spi_activate_cs(struct spi_device *spi) out_be32(&psc->ccr, ccr); mps->bits_per_word = cs->bits_per_word; - if (mps->cs_control) + if (mps->cs_control && gpio_is_valid(spi->cs_gpio)) mps->cs_control(spi, (spi->mode & SPI_CS_HIGH) ? 1 : 0); } @@ -121,7 +122,7 @@ static void mpc512x_psc_spi_deactivate_cs(struct spi_device *spi) { struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); - if (mps->cs_control) + if (mps->cs_control && gpio_is_valid(spi->cs_gpio)) mps->cs_control(spi, (spi->mode & SPI_CS_HIGH) ? 0 : 1); } @@ -278,6 +279,7 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi) struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); struct mpc512x_psc_spi_cs *cs = spi->controller_state; unsigned long flags; + int ret; if (spi->bits_per_word % 8) return -EINVAL; @@ -286,6 +288,19 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi) cs = kzalloc(sizeof *cs, GFP_KERNEL); if (!cs) return -ENOMEM; + + if (gpio_is_valid(spi->cs_gpio)) { + ret = gpio_request(spi->cs_gpio, dev_name(&spi->dev)); + if (ret) { + dev_err(&spi->dev, "can't get CS gpio: %d\n", + ret); + kfree(cs); + return ret; + } + gpio_direction_output(spi->cs_gpio, + spi->mode & SPI_CS_HIGH ? 0 : 1); + } + spi->controller_state = cs; } @@ -319,6 +334,8 @@ static int mpc512x_psc_spi_transfer(struct spi_device *spi, static void mpc512x_psc_spi_cleanup(struct spi_device *spi) { + if (gpio_is_valid(spi->cs_gpio)) + gpio_free(spi->cs_gpio); kfree(spi->controller_state); } @@ -405,6 +422,11 @@ static irqreturn_t mpc512x_psc_spi_isr(int irq, void *dev_id) return IRQ_NONE; } +static void mpc512x_spi_cs_control(struct spi_device *spi, bool onoff) +{ + gpio_set_value(spi->cs_gpio, onoff); +} + /* bus_num is used only for the case dev->platform_data == NULL */ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, u32 size, unsigned int irq, @@ -425,12 +447,9 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, mps->irq = irq; if (pdata == NULL) { - dev_err(dev, "probe called without platform data, no " - "cs_control function will be called\n"); - mps->cs_control = NULL; + mps->cs_control = mpc512x_spi_cs_control; mps->sysclk = 0; master->bus_num = bus_num; - master->num_chipselect = 255; } else { mps->cs_control = pdata->cs_control; mps->sysclk = pdata->sysclk; -- 1.7.5.4 ------------------------------------------------------------------------------ Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the endpoint security space. For insight on selecting the right partner to tackle endpoint security challenges, access the full report. http://p.sf.net/sfu/symantec-dev2dev ^ permalink raw reply related [flat|nested] 8+ messages in thread
[parent not found: <1363044215-24061-1-git-send-email-agust-ynQEQJNshbs@public.gmane.org>]
* [PATCH v2 RESEND] spi: spi-mpc512x-psc: add support for gpio chip selects [not found] ` <1363044215-24061-1-git-send-email-agust-ynQEQJNshbs@public.gmane.org> @ 2013-04-01 15:29 ` Anatolij Gustschin [not found] ` <20130409165322.GS9243@opensource.wolfsonmicro.com> 0 siblings, 1 reply; 8+ messages in thread From: Anatolij Gustschin @ 2013-04-01 15:29 UTC (permalink / raw) To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Mark Brown Cc: Anatolij Gustschin Currently the driver only uses one internal chip select. Add support for gpio chip selects configured by cs-gpios DT binding. Signed-off-by: Anatolij Gustschin <agust-ynQEQJNshbs@public.gmane.org> --- v2 resend: - no changes, resend to Mark v2: - do not parse GPIO chip selects manually drivers/spi/spi-mpc512x-psc.c | 31 +++++++++++++++++++++++++------ 1 files changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c index 3e490ee..da60f26 100644 --- a/drivers/spi/spi-mpc512x-psc.c +++ b/drivers/spi/spi-mpc512x-psc.c @@ -28,6 +28,7 @@ #include <linux/clk.h> #include <linux/spi/spi.h> #include <linux/fsl_devices.h> +#include <linux/gpio.h> #include <asm/mpc52xx_psc.h> struct mpc512x_psc_spi { @@ -113,7 +114,7 @@ static void mpc512x_psc_spi_activate_cs(struct spi_device *spi) out_be32(&psc->ccr, ccr); mps->bits_per_word = cs->bits_per_word; - if (mps->cs_control) + if (mps->cs_control && gpio_is_valid(spi->cs_gpio)) mps->cs_control(spi, (spi->mode & SPI_CS_HIGH) ? 1 : 0); } @@ -121,7 +122,7 @@ static void mpc512x_psc_spi_deactivate_cs(struct spi_device *spi) { struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); - if (mps->cs_control) + if (mps->cs_control && gpio_is_valid(spi->cs_gpio)) mps->cs_control(spi, (spi->mode & SPI_CS_HIGH) ? 0 : 1); } @@ -278,6 +279,7 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi) struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); struct mpc512x_psc_spi_cs *cs = spi->controller_state; unsigned long flags; + int ret; if (spi->bits_per_word % 8) return -EINVAL; @@ -286,6 +288,19 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi) cs = kzalloc(sizeof *cs, GFP_KERNEL); if (!cs) return -ENOMEM; + + if (gpio_is_valid(spi->cs_gpio)) { + ret = gpio_request(spi->cs_gpio, dev_name(&spi->dev)); + if (ret) { + dev_err(&spi->dev, "can't get CS gpio: %d\n", + ret); + kfree(cs); + return ret; + } + gpio_direction_output(spi->cs_gpio, + spi->mode & SPI_CS_HIGH ? 0 : 1); + } + spi->controller_state = cs; } @@ -319,6 +334,8 @@ static int mpc512x_psc_spi_transfer(struct spi_device *spi, static void mpc512x_psc_spi_cleanup(struct spi_device *spi) { + if (gpio_is_valid(spi->cs_gpio)) + gpio_free(spi->cs_gpio); kfree(spi->controller_state); } @@ -405,6 +422,11 @@ static irqreturn_t mpc512x_psc_spi_isr(int irq, void *dev_id) return IRQ_NONE; } +static void mpc512x_spi_cs_control(struct spi_device *spi, bool onoff) +{ + gpio_set_value(spi->cs_gpio, onoff); +} + /* bus_num is used only for the case dev->platform_data == NULL */ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, u32 size, unsigned int irq, @@ -425,12 +447,9 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, mps->irq = irq; if (pdata == NULL) { - dev_err(dev, "probe called without platform data, no " - "cs_control function will be called\n"); - mps->cs_control = NULL; + mps->cs_control = mpc512x_spi_cs_control; mps->sysclk = 0; master->bus_num = bus_num; - master->num_chipselect = 255; } else { mps->cs_control = pdata->cs_control; mps->sysclk = pdata->sysclk; -- 1.7.5.4 ------------------------------------------------------------------------------ Own the Future-Intel® Level Up Game Demo Contest 2013 Rise to greatness in Intel's independent game demo contest. Compete for recognition, cash, and the chance to get your game on Steam. $5K grand prize plus 10 genre and skill prizes. Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d ^ permalink raw reply related [flat|nested] 8+ messages in thread
[parent not found: <20130409165322.GS9243@opensource.wolfsonmicro.com>]
[parent not found: <20130409165322.GS9243-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>]
* Re: [PATCH v2 RESEND] spi: spi-mpc512x-psc: add support for gpio chip selects [not found] ` <20130409165322.GS9243-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org> @ 2013-04-09 17:04 ` Anatolij Gustschin 0 siblings, 0 replies; 8+ messages in thread From: Anatolij Gustschin @ 2013-04-09 17:04 UTC (permalink / raw) To: Mark Brown; +Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f On Tue, 9 Apr 2013 17:53:22 +0100 Mark Brown <broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org> wrote: > On Mon, Apr 01, 2013 at 05:29:21PM +0200, Anatolij Gustschin wrote: > > Currently the driver only uses one internal chip select. > > Add support for gpio chip selects configured by cs-gpios > > DT binding. > > Applied, thanks - I'm assuming the binding is already covered in the > generic SPI DT coverage? yes, this DT binding and documentation already exists. Thanks, Anatolij ------------------------------------------------------------------------------ Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] spi: spi-mpc512x-psc: init mode bits supported by the driver [not found] ` <1358195221-18488-1-git-send-email-agust-ynQEQJNshbs@public.gmane.org> 2013-01-14 20:27 ` [PATCH 2/2] spi: spi-mpc512x-psc: add support for gpio chip selects Anatolij Gustschin @ 2013-02-05 14:16 ` Grant Likely 1 sibling, 0 replies; 8+ messages in thread From: Grant Likely @ 2013-02-05 14:16 UTC (permalink / raw) To: Anatolij Gustschin, spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f On Mon, 14 Jan 2013 21:27:00 +0100, Anatolij Gustschin <agust-ynQEQJNshbs@public.gmane.org> wrote: > The driver should setup mode bits it supports, otherwise > adding an SPI device might fail even if the driver supports > the requested SPI mode. > > Signed-off-by: Anatolij Gustschin <agust-ynQEQJNshbs@public.gmane.org> Applied, thanks. g. > --- > drivers/spi/spi-mpc512x-psc.c | 1 + > 1 files changed, 1 insertions(+), 0 deletions(-) > > diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c > index 88e5441..89480b2 100644 > --- a/drivers/spi/spi-mpc512x-psc.c > +++ b/drivers/spi/spi-mpc512x-psc.c > @@ -438,6 +438,7 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, > master->num_chipselect = pdata->max_chipselect; > } > > + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST; > master->setup = mpc512x_psc_spi_setup; > master->transfer = mpc512x_psc_spi_transfer; > master->cleanup = mpc512x_psc_spi_cleanup; > -- > 1.7.5.4 > -- Grant Likely, B.Sc, P.Eng. Secret Lab Technologies, Ltd. ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-04-09 17:04 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-01-14 20:27 [PATCH 1/2] spi: spi-mpc512x-psc: init mode bits supported by the driver Anatolij Gustschin [not found] ` <1358195221-18488-1-git-send-email-agust-ynQEQJNshbs@public.gmane.org> 2013-01-14 20:27 ` [PATCH 2/2] spi: spi-mpc512x-psc: add support for gpio chip selects Anatolij Gustschin [not found] ` <1358195221-18488-2-git-send-email-agust-ynQEQJNshbs@public.gmane.org> 2013-02-05 14:18 ` Grant Likely 2013-03-11 22:45 ` Anatolij Gustschin 2013-03-11 23:23 ` [PATCH v2] " Anatolij Gustschin [not found] ` <1363044215-24061-1-git-send-email-agust-ynQEQJNshbs@public.gmane.org> 2013-04-01 15:29 ` [PATCH v2 RESEND] " Anatolij Gustschin [not found] ` <20130409165322.GS9243@opensource.wolfsonmicro.com> [not found] ` <20130409165322.GS9243-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org> 2013-04-09 17:04 ` Anatolij Gustschin 2013-02-05 14:16 ` [PATCH 1/2] spi: spi-mpc512x-psc: init mode bits supported by the driver Grant Likely
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).