From: Daniel Mack <zonque-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org,
Daniel Mack <zonque-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: [PATCH 1/2] SPI: spi-gpio: store chipselect information in private structure
Date: Wed, 25 Jul 2012 13:44:11 +0200 [thread overview]
Message-ID: <1343216652-1463-1-git-send-email-zonque@gmail.com> (raw)
The spi-gpio driver currently assumes the chipselect gpio number is
stored in ->controller_data of the device's static board information.
In devicetree environments, this information is unavailable and has to
be derived from the DT node.
This patch moves the gpio storage to the controller's private data so
the DT bindings can easily build upon the driver.
Signed-off-by: Daniel Mack <zonque-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/spi/spi-gpio.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index 0094c64..e79e311 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -46,6 +46,7 @@ struct spi_gpio {
struct spi_bitbang bitbang;
struct spi_gpio_platform_data pdata;
struct platform_device *pdev;
+ int cs_gpios[0];
};
/*----------------------------------------------------------------------*/
@@ -89,15 +90,21 @@ struct spi_gpio {
/*----------------------------------------------------------------------*/
-static inline const struct spi_gpio_platform_data * __pure
-spi_to_pdata(const struct spi_device *spi)
+static inline struct spi_gpio * __pure
+spi_to_spi_gpio(const struct spi_device *spi)
{
const struct spi_bitbang *bang;
- const struct spi_gpio *spi_gpio;
+ struct spi_gpio *spi_gpio;
bang = spi_master_get_devdata(spi->master);
spi_gpio = container_of(bang, struct spi_gpio, bitbang);
- return &spi_gpio->pdata;
+ return spi_gpio;
+}
+
+static inline struct spi_gpio_platform_data * __pure
+spi_to_pdata(const struct spi_device *spi)
+{
+ return &spi_to_spi_gpio(spi)->pdata;
}
/* this is #defined to avoid unused-variable warnings when inlining */
@@ -210,7 +217,8 @@ static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi,
static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
{
- unsigned long cs = (unsigned long) spi->controller_data;
+ struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
+ unsigned int cs = spi_gpio->cs_gpios[spi->chip_select];
/* set initial clock polarity */
if (is_active)
@@ -224,8 +232,9 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
static int spi_gpio_setup(struct spi_device *spi)
{
- unsigned long cs = (unsigned long) spi->controller_data;
- int status = 0;
+ unsigned int cs = (unsigned int) spi->controller_data;
+ int status = 0;
+ struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
if (spi->bits_per_word > 32)
return -EINVAL;
@@ -238,8 +247,11 @@ static int spi_gpio_setup(struct spi_device *spi)
status = gpio_direction_output(cs, spi->mode & SPI_CS_HIGH);
}
}
- if (!status)
+ if (!status) {
status = spi_bitbang_setup(spi);
+ spi_gpio->cs_gpios[spi->chip_select] = cs;
+ }
+
if (status) {
if (!spi->controller_state && cs != SPI_GPIO_NO_CHIPSELECT)
gpio_free(cs);
@@ -249,7 +261,8 @@ static int spi_gpio_setup(struct spi_device *spi)
static void spi_gpio_cleanup(struct spi_device *spi)
{
- unsigned long cs = (unsigned long) spi->controller_data;
+ struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
+ unsigned int cs = spi_gpio->cs_gpios[spi->chip_select];
if (cs != SPI_GPIO_NO_CHIPSELECT)
gpio_free(cs);
@@ -330,7 +343,8 @@ static int __devinit spi_gpio_probe(struct platform_device *pdev)
if (status < 0)
return status;
- master = spi_alloc_master(&pdev->dev, sizeof *spi_gpio);
+ master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) +
+ (sizeof(int) * SPI_N_CHIPSEL));
if (!master) {
status = -ENOMEM;
goto gpio_free;
--
1.7.10.4
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
next reply other threads:[~2012-07-25 11:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-25 11:44 Daniel Mack [this message]
[not found] ` <1343216652-1463-1-git-send-email-zonque-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-07-25 11:44 ` [PATCH 2/2] SPI: spi-gpio: Add DT bindings Daniel Mack
[not found] ` <20120725121131.GA2628@pengutronix.de>
[not found] ` <20120725121131.GA2628-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-07-25 12:17 ` Daniel Mack
[not found] ` <20120725123244.GB2628@pengutronix.de>
[not found] ` <20120725123244.GB2628-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-07-25 12:35 ` Daniel Mack
2012-07-25 19:33 ` [PATCH 1/2] SPI: spi-gpio: store chipselect information in private structure Mark Brown
[not found] ` <20120725193359.GB9792-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2012-07-25 19:38 ` Daniel Mack
[not found] ` <50104B52.7090509-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-07-25 19:52 ` Mark Brown
[not found] ` <20120725195203.GC9792-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2012-07-25 20:00 ` Daniel Mack
[not found] ` <50105052.4000603-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-07-25 20:12 ` Mark Brown
[not found] ` <20120725201227.GE9792-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2012-07-25 20:22 ` Daniel Mack
2012-08-01 20:45 ` Daniel Mack
[not found] ` <5019955F.3030108-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-08-01 20:51 ` Mark Brown
[not found] ` <20120801205135.GA29157-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-08-01 20:58 ` Daniel Mack
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=1343216652-1463-1-git-send-email-zonque@gmail.com \
--to=zonque-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
--cc=rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org \
--cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).