Re: [PATCH 9/9 v3] spi: add Broadcom BCM63xx SPI controller driver
On Tue, Jan 31, 2012 at 2:20 PM, Florian Fainelli wrote: > On Tuesday 31 January 2012 21:19:22 Grant Likely wrote: >> > +static const struct dev_pm_ops bcm63xx_spi_pm_ops = { >> > + .suspend = bcm63xx_spi_suspend, >> > + .resume = bcm63xx_spi_resume, >> > +}; >> > + >> > +#define BCM63XX_SPI_PM_OPS (&bcm63xx_spi_pm_ops) >> > +#else >> > +#define BCM63XX_SPI_PM_OPS NULL >> >> A bit ugly. Do this instead in the else clause and drop the >> BCM63XX_SPI_PM_OPS: >> >> #define bcm63xx_spi_pm_ops NULL > > This won't work, because driver.pm must be set to a pointer to a struct > dev_pm_ops, that's why I used this trick to make it build fine in both cases. > If I follow your advice, with driver.pm = &bcm63xx_spi_pm_ops, it won't build > for CONFIG_PM=n. Okay, fair enough. g. -- Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d ___ spi-devel-general mailing list spi-devel-general@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spi-devel-general
Re: [PATCH 9/9 v3] spi: add Broadcom BCM63xx SPI controller driver
Hello Grant, On Tuesday 31 January 2012 21:19:22 Grant Likely wrote: > On Tue, Jan 31, 2012 at 03:10:48PM +0100, Florian Fainelli wrote: > > This patch adds support for the SPI controller found on the Broadcom > > BCM63xx SoCs. > > > > Signed-off-by: Tanguy Bouzeloc > > Signed-off-by: Florian Fainelli > > --- > > Changes since v2: > > - reworked bcm63xx_spi_setup_transfer to choose closest spi transfer > > > > frequency > > > > - removed invalid 25Mhz frequency > > - fixed some minor checkpatch issues > > > > Changes since v1: > > - switched to the devm_* API which frees resources automatically > > - switched to dev_pm_ops > > - use module_platform_driver > > - remove MODULE_VERSION() > > - fixed return value when clock is not present using PTR_ERR() > > - fixed probe() error path to disable clock in case of failure > > > > drivers/spi/Kconfig |6 + > > drivers/spi/Makefile |1 + > > drivers/spi/spi-bcm63xx.c | 486 > > + 3 files changed, 493 > > insertions(+), 0 deletions(-) > > create mode 100644 drivers/spi/spi-bcm63xx.c > > Looks okay. There are a couple of problems that needs to be fixed > below, but otherwise: > > Acked-by: Grant Likely > > Merge this through the same tree as patches 1-8 > > g. > > > +static int __init bcm63xx_spi_probe(struct platform_device *pdev) > > __devinit > > > +static int __exit bcm63xx_spi_remove(struct platform_device *pdev) > > __devexit > > > +static const struct dev_pm_ops bcm63xx_spi_pm_ops = { > > + .suspend= bcm63xx_spi_suspend, > > + .resume = bcm63xx_spi_resume, > > +}; > > + > > +#define BCM63XX_SPI_PM_OPS (&bcm63xx_spi_pm_ops) > > +#else > > +#define BCM63XX_SPI_PM_OPS NULL > > A bit ugly. Do this instead in the else clause and drop the > BCM63XX_SPI_PM_OPS: > > #define bcm63xx_spi_pm_ops NULL This won't work, because driver.pm must be set to a pointer to a struct dev_pm_ops, that's why I used this trick to make it build fine in both cases. If I follow your advice, with driver.pm = &bcm63xx_spi_pm_ops, it won't build for CONFIG_PM=n. > > > +#endif > > + > > +static struct platform_driver bcm63xx_spi_driver = { > > + .driver = { > > + .name = "bcm63xx-spi", > > + .owner = THIS_MODULE, > > + .pm = BCM63XX_SPI_PM_OPS, > > + }, > > + .probe = bcm63xx_spi_probe, > > + .remove = __exit_p(bcm63xx_spi_remove), > > __devexit_p > > > +}; > > + > > +module_platform_driver(bcm63xx_spi_driver); > > + > > +MODULE_ALIAS("platform:bcm63xx_spi"); > > +MODULE_AUTHOR("Florian Fainelli "); > > +MODULE_AUTHOR("Tanguy Bouzeloc "); > > +MODULE_DESCRIPTION("Broadcom BCM63xx SPI Controller driver"); > > +MODULE_LICENSE("GPL"); -- Florian -- Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d ___ spi-devel-general mailing list spi-devel-general@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spi-devel-general
Re: [PATCH 9/9 v3] spi: add Broadcom BCM63xx SPI controller driver
On Tue, Jan 31, 2012 at 03:10:48PM +0100, Florian Fainelli wrote: > This patch adds support for the SPI controller found on the Broadcom BCM63xx > SoCs. > > Signed-off-by: Tanguy Bouzeloc > Signed-off-by: Florian Fainelli > --- > Changes since v2: > - reworked bcm63xx_spi_setup_transfer to choose closest spi transfer > frequency > - removed invalid 25Mhz frequency > - fixed some minor checkpatch issues > > Changes since v1: > - switched to the devm_* API which frees resources automatically > - switched to dev_pm_ops > - use module_platform_driver > - remove MODULE_VERSION() > - fixed return value when clock is not present using PTR_ERR() > - fixed probe() error path to disable clock in case of failure > > drivers/spi/Kconfig |6 + > drivers/spi/Makefile |1 + > drivers/spi/spi-bcm63xx.c | 486 > + > 3 files changed, 493 insertions(+), 0 deletions(-) > create mode 100644 drivers/spi/spi-bcm63xx.c > Looks okay. There are a couple of problems that needs to be fixed below, but otherwise: Acked-by: Grant Likely Merge this through the same tree as patches 1-8 g. > +static int __init bcm63xx_spi_probe(struct platform_device *pdev) __devinit > +static int __exit bcm63xx_spi_remove(struct platform_device *pdev) __devexit > +static const struct dev_pm_ops bcm63xx_spi_pm_ops = { > + .suspend= bcm63xx_spi_suspend, > + .resume = bcm63xx_spi_resume, > +}; > + > +#define BCM63XX_SPI_PM_OPS (&bcm63xx_spi_pm_ops) > +#else > +#define BCM63XX_SPI_PM_OPS NULL A bit ugly. Do this instead in the else clause and drop the BCM63XX_SPI_PM_OPS: #define bcm63xx_spi_pm_ops NULL > +#endif > + > +static struct platform_driver bcm63xx_spi_driver = { > + .driver = { > + .name = "bcm63xx-spi", > + .owner = THIS_MODULE, > + .pm = BCM63XX_SPI_PM_OPS, > + }, > + .probe = bcm63xx_spi_probe, > + .remove = __exit_p(bcm63xx_spi_remove), __devexit_p > +}; > + > +module_platform_driver(bcm63xx_spi_driver); > + > +MODULE_ALIAS("platform:bcm63xx_spi"); > +MODULE_AUTHOR("Florian Fainelli "); > +MODULE_AUTHOR("Tanguy Bouzeloc "); > +MODULE_DESCRIPTION("Broadcom BCM63xx SPI Controller driver"); > +MODULE_LICENSE("GPL"); > -- > 1.7.5.4 > -- Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d ___ spi-devel-general mailing list spi-devel-general@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spi-devel-general
Re: [PATCH 9/9 v3] spi: add Broadcom BCM63xx SPI controller driver
Hi Florian, On Tue, Jan 31, 2012 at 7:40 PM, Florian Fainelli wrote: > This patch adds support for the SPI controller found on the Broadcom BCM63xx > SoCs. > > Signed-off-by: Tanguy Bouzeloc > Signed-off-by: Florian Fainelli > --- > Changes since v2: > - reworked bcm63xx_spi_setup_transfer to choose closest spi transfer > frequency > - removed invalid 25Mhz frequency > - fixed some minor checkpatch issues > > Changes since v1: > - switched to the devm_* API which frees resources automatically > - switched to dev_pm_ops > - use module_platform_driver > - remove MODULE_VERSION() > - fixed return value when clock is not present using PTR_ERR() > - fixed probe() error path to disable clock in case of failure > > drivers/spi/Kconfig | 6 + > drivers/spi/Makefile | 1 + > drivers/spi/spi-bcm63xx.c | 486 > + > 3 files changed, 493 insertions(+), 0 deletions(-) > create mode 100644 drivers/spi/spi-bcm63xx.c > > diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig > index 3f9a47e..16818ac 100644 > --- a/drivers/spi/Kconfig > +++ b/drivers/spi/Kconfig > @@ -94,6 +94,12 @@ config SPI_AU1550 > If you say yes to this option, support will be included for the > PSC SPI controller found on Au1550, Au1200 and Au1300 series. > > +config SPI_BCM63XX > + tristate "Broadcom BCM63xx SPI controller" > + depends on BCM63XX > + help > + Enable support for the SPI controller on the Broadcom BCM63xx SoCs. > + > config SPI_BITBANG > tristate "Utilities for Bitbanging SPI masters" > help > diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile > index 61c3261..be38f73 100644 > --- a/drivers/spi/Makefile > +++ b/drivers/spi/Makefile > @@ -14,6 +14,7 @@ obj-$(CONFIG_SPI_ALTERA) += spi-altera.o > obj-$(CONFIG_SPI_ATMEL) += spi-atmel.o > obj-$(CONFIG_SPI_ATH79) += spi-ath79.o > obj-$(CONFIG_SPI_AU1550) += spi-au1550.o > +obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o > obj-$(CONFIG_SPI_BFIN) += spi-bfin5xx.o > obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o > obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o > diff --git a/drivers/spi/spi-bcm63xx.c b/drivers/spi/spi-bcm63xx.c > new file mode 100644 > index 000..eba8505 > --- /dev/null > +++ b/drivers/spi/spi-bcm63xx.c > @@ -0,0 +1,486 @@ > +/* > + * Broadcom BCM63xx SPI controller support > + * > + * Copyright (C) 2009-2011 Florian Fainelli > + * Copyright (C) 2010 Tanguy Bouzeloc > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * as published by the Free Software Foundation; either version 2 > + * of the License, or (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program; if not, write to the > + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > + > +#define PFX KBUILD_MODNAME > +#define DRV_VER "0.1.2" > + > +struct bcm63xx_spi { > + spinlock_t lock; > + int stopping; > + struct completion done; > + > + void __iomem *regs; > + int irq; > + > + /* Platform data */ > + u32 speed_hz; > + unsigned fifo_size; > + > + /* Data buffers */ > + const unsigned char *tx_ptr; > + unsigned char *rx_ptr; > + > + /* data iomem */ > + u8 __iomem *tx_io; > + const u8 __iomem *rx_io; > + > + int remaining_bytes; > + > + struct clk *clk; > + struct platform_device *pdev; > +}; > + > +static inline u8 bcm_spi_readb(struct bcm63xx_spi *bs, > + unsigned int offset) > +{ > + return bcm_readw(bs->regs + bcm63xx_spireg(offset)); are you sure it should be bcm_readw > +} > + > +static inline u16 bcm_spi_readw(struct bcm63xx_spi *bs, > + unsigned int offset) > +{ > + return bcm_readw(bs->regs + bcm63xx_spireg(offset)); > +} > + -- Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, ShareP
[PATCH 9/9 v3] spi: add Broadcom BCM63xx SPI controller driver
This patch adds support for the SPI controller found on the Broadcom BCM63xx SoCs. Signed-off-by: Tanguy Bouzeloc Signed-off-by: Florian Fainelli --- Changes since v2: - reworked bcm63xx_spi_setup_transfer to choose closest spi transfer frequency - removed invalid 25Mhz frequency - fixed some minor checkpatch issues Changes since v1: - switched to the devm_* API which frees resources automatically - switched to dev_pm_ops - use module_platform_driver - remove MODULE_VERSION() - fixed return value when clock is not present using PTR_ERR() - fixed probe() error path to disable clock in case of failure drivers/spi/Kconfig |6 + drivers/spi/Makefile |1 + drivers/spi/spi-bcm63xx.c | 486 + 3 files changed, 493 insertions(+), 0 deletions(-) create mode 100644 drivers/spi/spi-bcm63xx.c diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 3f9a47e..16818ac 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -94,6 +94,12 @@ config SPI_AU1550 If you say yes to this option, support will be included for the PSC SPI controller found on Au1550, Au1200 and Au1300 series. +config SPI_BCM63XX + tristate "Broadcom BCM63xx SPI controller" + depends on BCM63XX + help + Enable support for the SPI controller on the Broadcom BCM63xx SoCs. + config SPI_BITBANG tristate "Utilities for Bitbanging SPI masters" help diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index 61c3261..be38f73 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_SPI_ALTERA) += spi-altera.o obj-$(CONFIG_SPI_ATMEL)+= spi-atmel.o obj-$(CONFIG_SPI_ATH79)+= spi-ath79.o obj-$(CONFIG_SPI_AU1550) += spi-au1550.o +obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o obj-$(CONFIG_SPI_BFIN) += spi-bfin5xx.o obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o diff --git a/drivers/spi/spi-bcm63xx.c b/drivers/spi/spi-bcm63xx.c new file mode 100644 index 000..eba8505 --- /dev/null +++ b/drivers/spi/spi-bcm63xx.c @@ -0,0 +1,486 @@ +/* + * Broadcom BCM63xx SPI controller support + * + * Copyright (C) 2009-2011 Florian Fainelli + * Copyright (C) 2010 Tanguy Bouzeloc + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define PFXKBUILD_MODNAME +#define DRV_VER"0.1.2" + +struct bcm63xx_spi { + spinlock_t lock; + int stopping; + struct completion done; + + void __iomem*regs; + int irq; + + /* Platform data */ + u32 speed_hz; + unsignedfifo_size; + + /* Data buffers */ + const unsigned char *tx_ptr; + unsigned char *rx_ptr; + + /* data iomem */ + u8 __iomem *tx_io; + const u8 __iomem*rx_io; + + int remaining_bytes; + + struct clk *clk; + struct platform_device *pdev; +}; + +static inline u8 bcm_spi_readb(struct bcm63xx_spi *bs, + unsigned int offset) +{ + return bcm_readw(bs->regs + bcm63xx_spireg(offset)); +} + +static inline u16 bcm_spi_readw(struct bcm63xx_spi *bs, + unsigned int offset) +{ + return bcm_readw(bs->regs + bcm63xx_spireg(offset)); +} + +static inline void bcm_spi_writeb(struct bcm63xx_spi *bs, + u8 value, unsigned int offset) +{ + bcm_writeb(value, bs->regs + bcm63xx_spireg(offset)); +} + +static inline void bcm_spi_writew(struct bcm63xx_spi *bs, + u16 value, unsigned int offset) +{ + bcm_writew(value, bs->regs + bcm63xx_spireg(offset)); +} + +static const unsigned bcm63xx_spi_freq_table[SPI_CLK_MASK][2] = { + { 2000, SPI_CLK_20MHZ }, + { 1250, SPI_CLK_12_50MHZ }, + { 625, SPI_CLK_6_250MHZ }, + { 3125000, SPI_CLK_3_125MHZ }, +