Patchwork [U-Boot,2/4] spi: add spi_set_speed func

login
register
mail settings
Submitter Thomas Chou
Date Dec. 24, 2010, 7:16 a.m.
Message ID <1293174969-18653-3-git-send-email-thomas@wytron.com.tw>
Download mbox | patch
Permalink /patch/76623/
State Superseded
Headers show

Comments

Thomas Chou - Dec. 24, 2010, 7:16 a.m.
This func helps mmc_spi driver set correct speed for mmc/sd, as
mmc card needs 400KHz clock for spi mode initialization.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
 drivers/spi/Makefile |    1 +
 drivers/spi/spi.c    |    9 +++++++++
 include/spi.h        |    8 ++++++++
 3 files changed, 18 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/spi.c
Mike Frysinger - Dec. 24, 2010, 5:09 p.m.
On Friday, December 24, 2010 02:16:07 Thomas Chou wrote:
> --- /dev/null
> +++ b/drivers/spi/spi.c
> @@ -0,0 +1,9 @@
> +#include <common.h>
> +#include <spi.h>
> +
> +/* default func for SPI driver without set speed func */
> +static void __spi_set_speed(struct spi_slave *slave, uint hz)
> +{
> +}
> +void spi_set_speed(struct spi_slave *slave, uint hz)
> +	__attribute__((weak, alias("__spi_set_speed")));

let's not go this route.  just add the prototype to the header and when the 
respective spi bus maintainer wants to support this new func, they can 
implement it.  i'd rather people know about the problem up front rather than 
have things randomly not work.
-mike

Patch

diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index e34a124..c4eb627 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -25,6 +25,7 @@  include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libspi.o
 
+COBJS-$(CONFIG_MMC_SPI) += spi.o
 COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o
 COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
new file mode 100644
index 0000000..944466a
--- /dev/null
+++ b/drivers/spi/spi.c
@@ -0,0 +1,9 @@ 
+#include <common.h>
+#include <spi.h>
+
+/* default func for SPI driver without set speed func */
+static void __spi_set_speed(struct spi_slave *slave, uint hz)
+{
+}
+void spi_set_speed(struct spi_slave *slave, uint hz)
+	__attribute__((weak, alias("__spi_set_speed")));
diff --git a/include/spi.h b/include/spi.h
index 320e50e..7887d0f 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -176,6 +176,14 @@  void spi_cs_activate(struct spi_slave *slave);
 void spi_cs_deactivate(struct spi_slave *slave);
 
 /*-----------------------------------------------------------------------
+ * Set transfer speed.
+ * This sets a new speed to be applied for next spi_xfer().
+ *   slave:	The SPI slave
+ *   hz:	The transfer speed
+ */
+void spi_set_speed(struct spi_slave *slave, uint hz);
+
+/*-----------------------------------------------------------------------
  * Write 8 bits, then read 8 bits.
  *   slave:	The SPI slave we're communicating with
  *   byte:	Byte to be written