Skip to contentSkip to conversation

powerpc, mpc8xx: clear top of stack

PATCH Superseded Christophe Leroy 2 participants 12 messages Nov 6, 2018 – Nov 20, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/9 powerpc, mpc8xx: clear top of stack

---
 arch/powerpc/cpu/mpc8xx/start.S | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/cpu/mpc8xx/start.S +3 -1
index 8dde4beeea1..b8bdaaec2fa 100644
@@ -144,9 +144,11 @@ in_flash:
 	ori	r2, r2, CONFIG_SYS_DER at l
 	mtspr	DER, r2
 
-	/* set up the stack in internal DPRAM */
+	/* set up the stack on top of internal DPRAM */
 	lis	r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@h
 	ori	r3, r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@l
+	stw	r0, -4(r3)
+	stw	r0, -8(r3)
 	addi	r1, r3, -8
 
 	bl	board_init_f_alloc_reserve
Signature · 1 line
2.13.3
#1 lore raw

PATCH 2/9 board: MCR3000: Activate CONFIG_DM and CONFIG_OF_CONTROL

Add mcr3000 device tree and activate CONFIG_DM and CONFIG_OF_CONTROL

---
 arch/powerpc/dts/Makefile     |  1 +
 arch/powerpc/dts/mcr3000.dts  | 12 ++++++++++++
 board/cssi/MCR3000/u-boot.lds |  6 ++++++
 configs/MCR3000_defconfig     |  3 +++
 4 files changed, 22 insertions(+)
 create mode 100644 arch/powerpc/dts/mcr3000.dts
arch/powerpc/dts/Makefile +1 -0
index a19aa56300d..172bed4c202 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 dtb-$(CONFIG_TARGET_T2080QDS) += t2080qds.dtb
+dtb-$(CONFIG_MCR3000) += mcr3000.dtb
 
 targets += $(dtb-y)
 
arch/powerpc/dts/mcr3000.dts new file +12 -0
new file mode 100644
index 00000000000..e4b222857b5
@@ -0,0 +1,12 @@
+/*
+ * MCR3000 Device Tree Source
+ *
+ * Copyright 2017 CS Systemes d'Information
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+/dts-v1/;
+
+/ {
+};
board/cssi/MCR3000/u-boot.lds +6 -0
index a32c0e721e8..447ffded814 100644
@@ -69,6 +69,12 @@ SECTIONS
 	__ex_table : { *(__ex_table) }
 	__stop___ex_table = .;
 
+	/*
+	 * _end - This is end of u-boot.bin image.
+	 * dtb will be appended here to make u-boot-dtb.bin
+	 */
+	_end = .;
+
 	. = ALIGN(4096);
 	__init_begin = .;
 	.text.init : { *(.text.init) }
configs/MCR3000_defconfig +3 -0
index 29a60e3a986..6d7dda82a21 100644
@@ -73,3 +73,6 @@ CONFIG_MPC8XX_FEC=y
 CONFIG_SHA256=y
 CONFIG_LZMA=y
 CONFIG_OF_LIBFDT=y
+CONFIG_DM=y
+CONFIG_OF_CONTROL=y
+CONFIG_DEFAULT_DEVICE_TREE="mcr3000"
Signature · 1 line
2.13.3
#2 lore raw

PATCH 3/9 drivers: watchdog: add a DM driver for the MPC8xx watchdog

In reply to Christophe Leroy

This patch adds a DM driver for the MPC8xx watchdog. Basically, the watchdog is enabled by default from the start and SYPCR register has to be writen once to set the timeout and/or deactivate the watchdog. Once written, it cannot be written again.

It means that wdt_stop() can be called before wdt_start() to stop the watchdog, but cannot be called if wdt_start() has been called.

---
 drivers/watchdog/Kconfig      |  7 ++++++
 drivers/watchdog/mpc8xx_wdt.c | 51 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)
drivers/watchdog/Kconfig +7 -0
index 02f4e1e32fc..f581a7ea660 100644
@@ -118,4 +118,11 @@ config IMX_WATCHDOG
 	   Select this to enable the IMX and LSCH2 of Layerscape watchdog
 	   driver.
 
+config WDT_MPC8xx
+	bool "MPC8xx watchdog timer support"
+	depends on WDT && MPC8xx
+	select CONFIG_MPC8xx_WATCHDOG
+	help
+	   Select this to enable mpc8xx watchdog timer
+
 endmenu
drivers/watchdog/mpc8xx_wdt.c +51 -0

60 lines not on this page · raw message

Signature · 1 line
2.13.3
#3 lore raw

PATCH 4/9 board: MCR3000: use new DM watchdog

In reply to Christophe Leroy
---
 arch/powerpc/dts/mcr3000.dts |  3 +++
 board/cssi/MCR3000/MCR3000.c | 16 ++++++++++++++++
 configs/MCR3000_defconfig    |  3 +++
 3 files changed, 22 insertions(+)
arch/powerpc/dts/mcr3000.dts +3 -0
index e4b222857b5..ef423d73c20 100644
@@ -9,4 +9,7 @@
 /dts-v1/;
 
 / {
+	WDT: watchdog at 0 {
+		compatible = "fsl,pq1-wdt";
+	};
 };
board/cssi/MCR3000/MCR3000.c +16 -0
index ffbeb14ed0f..d26ac35b440 100644
@@ -12,6 +12,8 @@
 #include <mpc8xx.h>
 #include <fdt_support.h>
 #include <asm/io.h>
+#include <dm/uclass.h>
+#include <wdt.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -143,3 +145,17 @@ int board_early_init_f(void)
 
 	return 0;
 }
+
+int board_early_init_r(void)
+{
+	struct udevice *watchdog_dev = NULL;
+
+	if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) {
+		puts("Cannot find watchdog!\n");
+	} else {
+		puts("Enabling watchdog.\n");
+		wdt_start(watchdog_dev, 0xffff, 0);
+	}
+
+	return 0;
+}
configs/MCR3000_defconfig +3 -0
index 6d7dda82a21..2e79425bdbc 100644
@@ -42,6 +42,7 @@ CONFIG_BOOTDELAY=5
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="run flashboot"
 CONFIG_MISC_INIT_R=y
+CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_HUSH_PARSER=y
 # CONFIG_AUTO_COMPLETE is not set
 CONFIG_SYS_PROMPT="S3K> "
@@ -76,3 +77,5 @@ CONFIG_OF_LIBFDT=y
 CONFIG_DM=y
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="mcr3000"
+CONFIG_WDT=y
+CONFIG_WDT_MPC8xx=y
Signature · 1 line
2.13.3
#4 lore raw

PATCH 4/9 board: MCR3000: use new DM watchdog

Quoted 6 lines · Christophe Leroy
---
 arch/powerpc/dts/mcr3000.dts |  3 +++
 board/cssi/MCR3000/MCR3000.c | 16 ++++++++++++++++
 configs/MCR3000_defconfig    |  3 +++
 3 files changed, 22 insertions(+)

This fails to build for me in travis currently:
powerpc: + MCR3000
+(MCR3000) u-boot.lds:12 cannot move location counter backwards (from 000000000400400c to 0000000004004000) +(MCR3000) make[1]: *** [u-boot] Error 1
+(MCR3000) make: *** [sub-make] Error 2

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181120/da8a593b/attachment.sig>
#5 lore raw

PATCH 4/9 board: MCR3000: use new DM watchdog

Le 20/11/2018 à 15:56, Tom Rini a écrit :

Quoted 11 lines · Christophe Leroy
Quoted 7 lines
---
  arch/powerpc/dts/mcr3000.dts |  3 +++
  board/cssi/MCR3000/MCR3000.c | 16 ++++++++++++++++
  configs/MCR3000_defconfig    |  3 +++
  3 files changed, 22 insertions(+)

This fails to build for me in travis currently:

    powerpc:  +   MCR3000

Review

Quoted 3 lines
(quoted diff) +3 -0
+(MCR3000) u-boot.lds:12 cannot move location counter backwards (from 000000000400400c to 0000000004004000)
+(MCR3000) make[1]: *** [u-boot] Error 1
+(MCR3000) make: *** [sub-make] Error 2

This means your compiler generates bigger code than mine.

u-boot.lds needs to be adjusted manually for each version of compiler, so that the amount of text before env_offset is just enough but not too much.

Christophe

#6 lore raw

PATCH 4/9 board: MCR3000: use new DM watchdog

Quoted 18 lines · Christophe LEROY

Le 20/11/2018 à 15:56, Tom Rini a écrit :

Quoted 11 lines · Christophe Leroy
Quoted 7 lines
---
 arch/powerpc/dts/mcr3000.dts |  3 +++
 board/cssi/MCR3000/MCR3000.c | 16 ++++++++++++++++
 configs/MCR3000_defconfig    |  3 +++
 3 files changed, 22 insertions(+)

This fails to build for me in travis currently:

   powerpc:  +   MCR3000

Review

Quoted 3 lines
(quoted diff) +3 -0
+(MCR3000) u-boot.lds:12 cannot move location counter backwards (from 000000000400400c to 0000000004004000)
+(MCR3000) make[1]: *** [u-boot] Error 1
+(MCR3000) make: *** [sub-make] Error 2

This means your compiler generates bigger code than mine.

Quoted 2 lines

u-boot.lds needs to be adjusted manually for each version of compiler, so that the amount of text before env_offset is just enough but not too much.

Right. Please note that for various reasons, the toolchains used by buildman (which in turn are the kernel.org ones that're generally encouraged to be used when just "a" compiler is needed, outside of the U-Boot community even) must succeed :) Please re-submit the series with it passing a run in travis, or at least a buildman of all powerpc with that toolchain, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181120/8477f38d/attachment.sig>
#7 lore raw

PATCH 5/9 drivers: serial: migrate mpc8xx to DM

In reply to Christophe Leroy
---
 drivers/serial/serial_mpc8xx.c | 77 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 74 insertions(+), 3 deletions(-)
drivers/serial/serial_mpc8xx.c +74 -3
index 292912b7ee2..f2d241417a4 100644
@@ -6,6 +6,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <dm.h>
 #include <serial.h>
 #include <watchdog.h>
 #include <asm/cpm_8xx.h>
@@ -35,9 +36,9 @@ struct serialbuffer {
 	uchar	txbuf;	/* tx buffers */
 };
 
-static void serial_setdivisor(cpm8xx_t __iomem *cp)
+static void serial_setdivisor(cpm8xx_t __iomem *cp, int baudrate)
 {
-	int divisor = (gd->cpu_clk + 8 * gd->baudrate) / 16 / gd->baudrate;
+	int divisor = (gd->cpu_clk + 8 * baudrate) / 16 / baudrate;
 
 	if (divisor / 16 > 0x1000) {
 		/* bad divisor, assume 50MHz clock and 9600 baud */
@@ -71,7 +72,7 @@ static void smc_setbrg(void)
 
 	out_be32(&cp->cp_simode, 0);
 
-	serial_setdivisor(cp);
+	serial_setdivisor(cp, gd->baudrate);
 }
 
 static int smc_init(void)
@@ -186,11 +187,13 @@ static void smc_putc(const char c)
 		WATCHDOG_RESET();
 }
 
+#ifndef CONFIG_DM_SERIAL
 static void smc_puts(const char *s)
 {
 	while (*s)
 		smc_putc(*s++);
 }
+#endif
 
 static int smc_getc(void)
 {
@@ -233,6 +236,7 @@ static int smc_tstc(void)
 	return !(in_be16(&rtx->rxbd.cbd_sc) & BD_SC_EMPTY);
 }
 
+#ifndef CONFIG_DM_SERIAL
 struct serial_device serial_smc_device = {
 	.name	= "serial_smc",
 	.start	= smc_init,
@@ -253,3 +257,70 @@ void mpc8xx_serial_initialize(void)
 {
 	serial_register(&serial_smc_device);
 }
+#endif
+
+#ifdef CONFIG_DM_SERIAL
+static int serial_mpc8xx_setbrg(struct udevice *dev, int baudrate)
+{
+	immap_t __iomem *im = (immap_t __iomem *)CONFIG_SYS_IMMR;
+	cpm8xx_t __iomem *cp = &(im->im_cpm);
+
+	/* Set up the baud rate generator.
+	 * See 8xx_io/commproc.c for details.
+	 *
+	 * Wire BRG1 to SMCx
+	 */
+
+	out_be32(&cp->cp_simode, 0);
+
+	serial_setdivisor(cp, baudrate);
+
+	return 0;
+}
+
+static int serial_mpc8xx_probe(struct udevice *dev)
+{
+	return smc_init();
+}
+
+static int serial_mpc8xx_putc(struct udevice *dev, const char ch)
+{
+	smc_putc(ch);
+
+	return 0;
+}
+
+static int serial_mpc8xx_getc(struct udevice *dev)
+{
+	return smc_getc();
+}
+
+static int serial_mpc8xx_pending(struct udevice *dev, bool input)
+{
+	if (input)
+		return smc_tstc();
+
+	return 0;
+}
+
+static const struct dm_serial_ops serial_mpc8xx_ops = {
+	.putc = serial_mpc8xx_putc,
+	.pending = serial_mpc8xx_pending,
+	.getc = serial_mpc8xx_getc,
+	.setbrg = serial_mpc8xx_setbrg,
+};
+
+static const struct udevice_id serial_mpc8xx_ids[] = {
+	{ .compatible = "fsl,pq1-smc" },
+	{ }
+};
+
+U_BOOT_DRIVER(serial_mpc8xx) = {
+	.name	= "serial_mpc8xx",
+	.id	= UCLASS_SERIAL,
+	.of_match = serial_mpc8xx_ids,
+	.probe = serial_mpc8xx_probe,
+	.ops	= &serial_mpc8xx_ops,
+	.flags = DM_FLAG_PRE_RELOC,
+};
+#endif
Signature · 1 line
2.13.3
#8 lore raw

PATCH 6/9 board: MCR3000: migrate to DM_SERIAL

In reply to Christophe Leroy
---
 arch/powerpc/dts/mcr3000.dts | 7 +++++++
 configs/MCR3000_defconfig    | 1 +
 2 files changed, 8 insertions(+)
arch/powerpc/dts/mcr3000.dts +7 -0
index ef423d73c20..5abf111dc5f 100644
@@ -12,4 +12,11 @@
 	WDT: watchdog at 0 {
 		compatible = "fsl,pq1-wdt";
 	};
+	SERIAL: smc at 0 {
+		compatible = "fsl,pq1-smc";
+	};
+
+	chosen {
+		stdout-path = &SERIAL;
+	};
 };
configs/MCR3000_defconfig +1 -0
index 2e79425bdbc..33c6073648d 100644
@@ -79,3 +79,4 @@ CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="mcr3000"
 CONFIG_WDT=y
 CONFIG_WDT_MPC8xx=y
+CONFIG_DM_SERIAL=y
Signature · 1 line
2.13.3
#9 lore raw

PATCH 7/9 drivers: serial: get rid of non DM mpc8xx driver

In reply to Christophe Leroy
---
 drivers/serial/serial.c        |  2 -
 drivers/serial/serial_mpc8xx.c | 97 ++++++------------------------------------
 include/serial.h               |  1 -
 3 files changed, 14 insertions(+), 86 deletions(-)
drivers/serial/serial.c +0 -2
index c499601f000..09365ba6a1e 100644
@@ -119,7 +119,6 @@ U_BOOT_ENV_CALLBACK(baudrate, on_baudrate);
 serial_initfunc(atmel_serial_initialize);
 serial_initfunc(mcf_serial_initialize);
 serial_initfunc(mpc85xx_serial_initialize);
-serial_initfunc(mpc8xx_serial_initialize);
 serial_initfunc(mxc_serial_initialize);
 serial_initfunc(ns16550_serial_initialize);
 serial_initfunc(pl01x_serial_initialize);
@@ -173,7 +172,6 @@ void serial_initialize(void)
 	atmel_serial_initialize();
 	mcf_serial_initialize();
 	mpc85xx_serial_initialize();
-	mpc8xx_serial_initialize();
 	mxc_serial_initialize();
 	ns16550_serial_initialize();
 	pl01x_serial_initialize();
drivers/serial/serial_mpc8xx.c +14 -83

157 lines not on this page · raw message

include/serial.h +0 -1
index 020cd392e88..2055d179645 100644
@@ -226,7 +226,6 @@ struct serial_dev_priv {
 void atmel_serial_initialize(void);
 void mcf_serial_initialize(void);
 void mpc85xx_serial_initialize(void);
-void mpc8xx_serial_initialize(void);
 void mxc_serial_initialize(void);
 void ns16550_serial_initialize(void);
 void pl01x_serial_initialize(void);
Signature · 1 line
2.13.3
#10 lore raw

PATCH 8/9 board_r: fix build with DM_SPI

In reply to Christophe Leroy

CC common/board_r.o
common/board_r.c:747:2: error: ‘initr_spi’ undeclared here (not in a function)
initr_spi,
^
make[1]: *** [common/board_r.o] Error 1

Fixes ebe76a2df9f6 ("dm: Remove spi_init() from board_r.c when using driver model")
---
 common/board_r.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/board_r.c +1 -1
index c55e33eec27..0c2129b8ceb 100644
@@ -743,7 +743,7 @@ static init_fnc_t init_sequence_r[] = {
 	/* initialize higher level parts of CPU like time base and timers */
 	cpu_init_r,
 #endif
-#ifdef CONFIG_PPC
+#if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI)
 	initr_spi,
 #endif
 #ifdef CONFIG_CMD_NAND
Signature · 1 line
2.13.3
#11 lore raw

PATCH 9/9 spi, mpc8xx: migrate to DM_SPI

In reply to Christophe Leroy
---
 drivers/spi/mpc8xx_spi.c | 179 ++++++++---------------------------------------
 1 file changed, 30 insertions(+), 149 deletions(-)
drivers/spi/mpc8xx_spi.c +30 -149
index 285fd4d2cc0..b020ce2b9d7 100644
@@ -17,64 +17,19 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <mpc8xx.h>
+#include <spi.h>
+
 #include <asm/cpm_8xx.h>
-#include <linux/ctype.h>
-#include <malloc.h>
-#include <post.h>
-#include <serial.h>
-
-#define SPI_EEPROM_WREN		0x06
-#define SPI_EEPROM_RDSR		0x05
-#define SPI_EEPROM_READ		0x03
-#define SPI_EEPROM_WRITE	0x02
-
-/* ---------------------------------------------------------------
- * Offset for initial SPI buffers in DPRAM:
- * We need a 520 byte scratch DPRAM area to use at an early stage.
- * It is used between the two initialization calls (spi_init_f()
- * and spi_init_r()).
- * The value 0xb00 makes it far enough from the start of the data
- * area (as well as from the stack pointer).
- * --------------------------------------------------------------- */
-#ifndef	CONFIG_SYS_SPI_INIT_OFFSET
-#define	CONFIG_SYS_SPI_INIT_OFFSET	0xB00
-#endif
+#include <asm/io.h>
 
 #define CPM_SPI_BASE_RX	CPM_SPI_BASE
 #define CPM_SPI_BASE_TX	(CPM_SPI_BASE + sizeof(cbd_t))
 
-/* -------------------
- * Function prototypes
- * ------------------- */
-ssize_t spi_xfer(size_t);
-
-/* -------------------
- * Variables
- * ------------------- */
-
 #define MAX_BUFFER	0x104
 
-/* ----------------------------------------------------------------------
- * Initially we place the RX and TX buffers at a fixed location in DPRAM!
- * ---------------------------------------------------------------------- */
-static uchar *rxbuf =
-	(uchar *)&((cpm8xx_t *)&((immap_t *)CONFIG_SYS_IMMR)->im_cpm)->cp_dpmem
-			[CONFIG_SYS_SPI_INIT_OFFSET];
-static uchar *txbuf =
-	(uchar *)&((cpm8xx_t *)&((immap_t *)CONFIG_SYS_IMMR)->im_cpm)->cp_dpmem
-			[CONFIG_SYS_SPI_INIT_OFFSET+MAX_BUFFER];
-
-/* **************************************************************************
- *
- *  Function:    spi_init_f
- *
- *  Description: Init SPI-Controller (ROM part)
- *
- *  return:      ---
- *
- * *********************************************************************** */
-void spi_init_f(void)
+static int mpc8xx_spi_probe(struct udevice *dev)
 {
 	immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
 	cpm8xx_t __iomem *cp = &immr->im_cpm;
@@ -180,117 +135,24 @@ void spi_init_f(void)
 	clrbits_be16(&tbdf->cbd_sc, BD_SC_READY);
 	clrbits_be16(&rbdf->cbd_sc, BD_SC_EMPTY);
 
-	/* Set the bd's rx and tx buffer address pointers */
-	out_be32(&rbdf->cbd_bufaddr, (ulong)rxbuf);
-	out_be32(&tbdf->cbd_bufaddr, (ulong)txbuf);
-
 /* 10 + 11 */
 	out_8(&cp->cp_spim, 0);			/* Mask  all SPI events */
 	out_8(&cp->cp_spie, SPI_EMASK);		/* Clear all SPI events	*/
 
-	return;
+	return 0;
 }
 
-/* **************************************************************************
- *
- *  Function:    spi_init_r
- *
- *  Description: Init SPI-Controller (RAM part) -
- *		 The malloc engine is ready and we can move our buffers to
- *		 normal RAM
- *
- *  return:      ---
- *
- * *********************************************************************** */
-void spi_init_r(void)
+static int mpc8xx_spi_xfer(struct udevice *dev, unsigned int bitlen,
+			    const void *dout, void *din, unsigned long flags)
 {
 	immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
 	cpm8xx_t __iomem *cp = &immr->im_cpm;
-	spi_t __iomem *spi = (spi_t __iomem *)&cp->cp_dparam[PROFF_SPI];
-	cbd_t __iomem *tbdf, *rbdf;
-
-	/* Disable relocation */
-	out_be16(&spi->spi_rpbase, 0);
-
-	/* tx and rx buffer descriptors */
-	tbdf = (cbd_t __iomem *)&cp->cp_dpmem[CPM_SPI_BASE_TX];
-	rbdf = (cbd_t __iomem *)&cp->cp_dpmem[CPM_SPI_BASE_RX];
-
-	/* Allocate memory for RX and TX buffers */
-	rxbuf = (uchar *)malloc(MAX_BUFFER);
-	txbuf = (uchar *)malloc(MAX_BUFFER);
-
-	out_be32(&rbdf->cbd_bufaddr, (ulong)rxbuf);
-	out_be32(&tbdf->cbd_bufaddr, (ulong)txbuf);
-
-	return;
-}
-
-/****************************************************************************
- *  Function:    spi_write
- **************************************************************************** */
-ssize_t spi_write(uchar *addr, int alen, uchar *buffer, int len)
-{
-	int i;
-
-	memset(rxbuf, 0, MAX_BUFFER);
-	memset(txbuf, 0, MAX_BUFFER);
-	*txbuf = SPI_EEPROM_WREN;		/* write enable		*/
-	spi_xfer(1);
-	memcpy(txbuf, addr, alen);
-	*txbuf = SPI_EEPROM_WRITE;		/* WRITE memory array	*/
-	memcpy(alen + txbuf, buffer, len);
-	spi_xfer(alen + len);
-						/* ignore received data	*/
-	for (i = 0; i < 1000; i++) {
-		*txbuf = SPI_EEPROM_RDSR;	/* read status		*/
-		txbuf[1] = 0;
-		spi_xfer(2);
-		if (!(rxbuf[1] & 1))
-			break;
-		udelay(1000);
-	}
-	if (i >= 1000)
-		printf("*** spi_write: Time out while writing!\n");
-
-	return len;
-}
-
-/****************************************************************************
- *  Function:    spi_read
- **************************************************************************** */
-ssize_t spi_read(uchar *addr, int alen, uchar *buffer, int len)
-{
-	memset(rxbuf, 0, MAX_BUFFER);
-	memset(txbuf, 0, MAX_BUFFER);
-	memcpy(txbuf, addr, alen);
-	*txbuf = SPI_EEPROM_READ;		/* READ memory array	*/
-
-	/*
-	 * There is a bug in 860T (?) that cuts the last byte of input
-	 * if we're reading into DPRAM. The solution we choose here is
-	 * to always read len+1 bytes (we have one extra byte at the
-	 * end of the buffer).
-	 */
-	spi_xfer(alen + len + 1);
-	memcpy(buffer, alen + rxbuf, len);
-
-	return len;
-}
-
-/****************************************************************************
- *  Function:    spi_xfer
- **************************************************************************** */
-ssize_t spi_xfer(size_t count)
-{
-	immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
-	cpm8xx_t __iomem *cp = &immr->im_cpm;
-	spi_t __iomem *spi = (spi_t __iomem *)&cp->cp_dparam[PROFF_SPI];
 	cbd_t __iomem *tbdf, *rbdf;
 	int tm;
+	size_t count = (bitlen + 7) / 8;
 
-	/* Disable relocation */
-	out_be16(&spi->spi_rpbase, 0);
+	if (count > MAX_BUFFER)
+		return -EINVAL;
 
 	tbdf = (cbd_t __iomem *)&cp->cp_dpmem[CPM_SPI_BASE_TX];
 	rbdf = (cbd_t __iomem *)&cp->cp_dpmem[CPM_SPI_BASE_RX];
@@ -299,10 +161,12 @@ ssize_t spi_xfer(size_t count)
 	clrbits_be32(&cp->cp_pbdat, 0x0001);
 
 	/* Setting tx bd status and data length */
+	out_be32(&tbdf->cbd_bufaddr, (ulong)dout);
 	out_be16(&tbdf->cbd_sc, BD_SC_READY | BD_SC_LAST | BD_SC_WRAP);
 	out_be16(&tbdf->cbd_datlen, count);
 
 	/* Setting rx bd status and data length */
+	out_be32(&rbdf->cbd_bufaddr, (ulong)din);
 	out_be16(&rbdf->cbd_sc, BD_SC_EMPTY | BD_SC_WRAP);
 	out_be16(&rbdf->cbd_datlen, 0);	 /* rx length has no significance */
 
@@ -333,3 +197,20 @@ ssize_t spi_xfer(size_t count)
 
 	return count;
 }
+
+static const struct dm_spi_ops mpc8xx_spi_ops = {
+	.xfer		= mpc8xx_spi_xfer,
+};
+
+static const struct udevice_id mpc8xx_spi_ids[] = {
+	{ .compatible = "fsl,mpc8xx-spi" },
+	{ }
+};
+
+U_BOOT_DRIVER(mpc8xx_spi) = {
+	.name	= "mpc8xx_spi",
+	.id	= UCLASS_SPI,
+	.of_match = mpc8xx_spi_ids,
+	.ops	= &mpc8xx_spi_ops,
+	.probe	= mpc8xx_spi_probe,
+};
Signature · 1 line
2.13.3