Re: Subject: [PATCH v8] spi: Add PPC4xx SPI driver

2009-07-06 Thread Steven A. Falco
David Brownell wrote:
> On Friday 26 June 2009, Steven A. Falco wrote:
>> +
>> +   /*
>> +* If there are no chip selects at all, or if this is the special
>> +* case of a non-existent (dummy) chip select, do nothing.
>> +*/
>> +
>> +   if (!hw->master->num_chipselect || hw->gpios[cs] == -EEXIST)
>> +   return;
>> +
> 
> I'm going to send this in, but please send a followup
> patch making all this "non-existent (dummy) chip select"
> stuff use the SPI_NO_CS flag.
> 

Not sure yet how this will work.  GPIOs are detected during probe.
of_get_gpio_flags() will return EEXIST for devices without a CS,
and will return the gpio number for devices with a CS, but probe
doesn't (currently) know anything about "struct spi_device".

In fact, the devices don't exist until spi_bitbang_start is called,
near the end of the probe.  So, I've not figured out how the probe
routine will set the new SPI_NO_CS flag on a per-device basis.

There is one example of a ppc board calling spi_register_board_info,
but even that board doesn't really use it, if a device tree exists.

> 
>> +   /*
>> +* A count of zero implies a single SPI device without any 
>> chip-select.
>> +* Note that of_gpio_count counts all gpios assigned to this spi 
>> master.
>> +* This includes both "null" gpio's and real ones.
>> +*/
> 
> 
> 

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: Subject: [PATCH v8] spi: Add PPC4xx SPI driver

2009-07-02 Thread David Brownell
On Friday 26 June 2009, Steven A. Falco wrote:
> +
> +   /*
> +    * If there are no chip selects at all, or if this is the special
> +    * case of a non-existent (dummy) chip select, do nothing.
> +    */
> +
> +   if (!hw->master->num_chipselect || hw->gpios[cs] == -EEXIST)
> +   return;
> +

I'm going to send this in, but please send a followup
patch making all this "non-existent (dummy) chip select"
stuff use the SPI_NO_CS flag.


> +   /*
> +* A count of zero implies a single SPI device without any 
> chip-select.
> +* Note that of_gpio_count counts all gpios assigned to this spi 
> master.
> +* This includes both "null" gpio's and real ones.
> +*/


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Subject: [PATCH v8] spi: Add PPC4xx SPI driver

2009-06-26 Thread Steven A. Falco
This adds a SPI driver for the SPI controller found in the IBM/AMCC
4xx PowerPC's.

Signed-off-by: Stefan Roese 
Signed-off-by: Wolfgang Ocker 
Acked-by: Josh Boyer 
Signed-off-by: Steven A. Falco 
---
Changes in v8:
- Removed redundant dbg messages
- Using new master->mode_line variable
- Removed redundant test and assignment of bits_per_word
- Some white-space fixes from checkpatch

Changes in v7:
- Additional comments as per David Brownell's review
- Corrected phase in mode 2 and 3
- Corrected speed and bits_per_word logic in spi_ppc4xx_setupxfer
- Removed extraneous tests as per David's review
- Added support for "holes" in the chip-select list
- Using dynamic bus allocation
- Corrected initialization logic

Changes in v6:
- Moved comment about high interrupt load to top of file and extended it
  by explaining that the 4xx SPI controller has no FIFOs.
- Added parameter checking to setup() routine.
- Removed comment about LSB
- Used of_gpio_count() instead creating own static implementation as
  suggested by Anton.

Changes in v5:
- Don't call setupxfer() from setup() so that the baudrate etc
  won't get changed while another transfer is active, as suggested
  by David Brownell.
- module_{init,exit} moved directly to the functions to which they
  apply.
- Use __func__ instead of __FUNCTION__.

Changes in v4:
- Added fixes suggested by Josh Boyer
- Changed compatible property from "ibm,spi" to "ibm,ppc4xx-spi"

Changes in v3:
- When the device is removed the GPIOs are released. The memory
  for the GPIO array is freed.

Changes in v2:
- Now the gpios property is correctly decoded and the
  resulting gpio numbers are used as the devices chip
  selects.

 drivers/spi/Kconfig  |7 +
 drivers/spi/Makefile |1 +
 drivers/spi/spi_ppc4xx.c |  612 ++
 3 files changed, 620 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/spi_ppc4xx.c

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 2c733c2..1dd9f94 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -178,6 +178,13 @@ config SPI_PL022
  controller. If you have an embedded system with an AMBA(R)
  bus and a PL022 controller, say Y or M here.
 
+config SPI_PPC4xx
+   tristate "PPC4xx SPI Controller"
+   depends on 4xx && SPI_MASTER
+   select SPI_BITBANG
+   help
+ This selects a driver for the PPC4xx SPI Controller.
+
 config SPI_PXA2XX
tristate "PXA2xx SSP SPI master"
depends on ARCH_PXA && EXPERIMENTAL
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 3de408d..cc9a420 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_SPI_ORION)   += orion_spi.o
 obj-$(CONFIG_SPI_PL022)+= amba-pl022.o
 obj-$(CONFIG_SPI_MPC52xx_PSC)  += mpc52xx_psc_spi.o
 obj-$(CONFIG_SPI_MPC8xxx)  += spi_mpc8xxx.o
+obj-$(CONFIG_SPI_PPC4xx)   += spi_ppc4xx.o
 obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o
 obj-$(CONFIG_SPI_S3C24XX)  += spi_s3c24xx.o
 obj-$(CONFIG_SPI_TXX9) += spi_txx9.o
diff --git a/drivers/spi/spi_ppc4xx.c b/drivers/spi/spi_ppc4xx.c
new file mode 100644
index 000..140a18d
--- /dev/null
+++ b/drivers/spi/spi_ppc4xx.c
@@ -0,0 +1,612 @@
+/*
+ * SPI_PPC4XX SPI controller driver.
+ *
+ * Copyright (C) 2007 Gary Jennejohn 
+ * Copyright 2008 Stefan Roese , DENX Software Engineering
+ * Copyright 2009 Harris Corporation, Steven A. Falco 
+ *
+ * Based in part on drivers/spi/spi_s3c24xx.c
+ *
+ * Copyright (c) 2006 Ben Dooks
+ * Copyright (c) 2006 Simtec Electronics
+ * Ben Dooks 
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+/*
+ * The PPC4xx SPI controller has no FIFO so each sent/received byte will
+ * generate an interrupt to the CPU. This can cause high CPU utilization.
+ * This driver allows platforms to reduce the interrupt load on the CPU
+ * during SPI transfers by setting max_speed_hz via the device tree.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* bits in mode register - bit 0 is MSb */
+
+/*
+ * SPI_PPC4XX_MODE_SCP = 0 means "data latched on trailing edge of clock"
+ * SPI_PPC4XX_MODE_SCP = 1 means "data latched on leading edge of clock"
+ * Note: This is the inverse of CPHA.
+ */
+#define SPI_PPC4XX_MODE_SCP(0x80 >> 3)
+
+/* SPI_PPC4XX_MODE_SPE = 1 means "port enabled" */
+#define SPI_PPC4XX_MODE_SPE(0x80 >> 4)
+
+/*
+ * SPI_PPC4XX_MODE_RD = 0 means "MSB first" - this is the normal mode
+ * SPI_PPC4XX_MODE_RD = 1 means "LSB first" - this is bit-reversed mode
+ * Note: This is identical to SPI_LSB_FIRST.
+ */
+#define SPI_PPC4XX_MODE_RD (0x