Skip to contentSkip to conversation

Beginning of migration of MPC8xx to DM model

RFC PATCH Superseded Christophe Leroy 3 participants 11 messages Mar 16, 2018 – May 4, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Beginning of migration of MPC8xx to DM model

This serie is the beginning of MPC8xx migration to DM model.

It applies on top of the serie "[v4] Powerpc: mpc8xx: cleanup before migration to DM model"

Christophe Leroy (6):
board: MCR3000: Activate CONFIG_DM and CONFIG_OF_CONTROL
drivers: watchdog: add a DM driver for the MPC8xx watchdog
board: MCR3000: use new DM watchdog
drivers: serial: migrate mpc8xx to DM
board: MCR3000: migrate to DM_SERIAL
drivers: serial: get rid of non DM mpc8xx driver

Change since initial RFC:
Migrated serial driver in addition
Few changes on the watchdog

 arch/powerpc/dts/Makefile      | 16 ++++++++++
 arch/powerpc/dts/mcr3000.dts   | 22 ++++++++++++++
 board/cssi/MCR3000/MCR3000.c   | 16 ++++++++++
 board/cssi/MCR3000/u-boot.lds  |  6 ++++
 configs/MCR3000_defconfig      |  6 ++++
 drivers/serial/serial.c        |  2 --
 drivers/serial/serial_mpc8xx.c | 66 ++++++++++++++++++++++--------------------
 drivers/watchdog/Kconfig       |  7 +++++
 drivers/watchdog/mpc8xx_wdt.c  | 51 ++++++++++++++++++++++++++++++++
 include/configs/MCR3000.h      |  1 +
 include/serial.h               |  1 -
 11 files changed, 159 insertions(+), 35 deletions(-)
 create mode 100644 arch/powerpc/dts/Makefile
 create mode 100644 arch/powerpc/dts/mcr3000.dts
Signature · 1 line
2.13.3
#1 lore raw

RFC PATCH v2 1/6 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     | 16 ++++++++++++++++
 arch/powerpc/dts/mcr3000.dts  | 12 ++++++++++++
 board/cssi/MCR3000/u-boot.lds |  6 ++++++
 configs/MCR3000_defconfig     |  3 +++
 4 files changed, 37 insertions(+)
 create mode 100644 arch/powerpc/dts/Makefile
 create mode 100644 arch/powerpc/dts/mcr3000.dts
arch/powerpc/dts/Makefile new file +16 -0
new file mode 100644
index 00000000000..c1c5d9c6dd3
@@ -0,0 +1,16 @@
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+dtb-$(CONFIG_MCR3000) += mcr3000.dtb
+
+targets += $(dtb-y)
+
+# Add any required device tree compiler flags here
+DTC_FLAGS +=
+
+PHONY += dtbs
+dtbs: $(addprefix $(obj)/, $(dtb-y))
+	@:
+
+clean-files := *.dtb
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 990cca4ebb6..46cbbab6c4b 100644
@@ -70,6 +70,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 df8ac064877..10667ab0218 100644
@@ -71,3 +71,6 @@ CONFIG_LZMA=y
 CONFIG_OF_LIBFDT=y
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="run flashboot"
+CONFIG_DM=y
+CONFIG_OF_CONTROL=y
+CONFIG_DEFAULT_DEVICE_TREE="mcr3000"
Signature · 1 line
2.13.3
#2 lore raw

RFC PATCH v2 2/6 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 fc46b6774d5..21c2c2498eb 100644
@@ -78,4 +78,11 @@ config WDT_ORION
 	   Select this to enable Orion watchdog timer, which can be found on some
 	   Marvell Armada chips.
 
+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

RFC PATCH v2 3/6 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    |  2 ++
 include/configs/MCR3000.h    |  1 +
 4 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 6939a2cf617..15713484680 100644
@@ -13,6 +13,8 @@
 #include <mpc8xx.h>
 #include <fdt_support.h>
 #include <asm/io.h>
+#include <dm/uclass.h>
+#include <wdt.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -144,3 +146,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 +2 -0
index 10667ab0218..f3dc571be22 100644
@@ -74,3 +74,5 @@ CONFIG_BOOTCOMMAND="run flashboot"
 CONFIG_DM=y
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="mcr3000"
+CONFIG_WDT=y
+CONFIG_WDT_MPC8xx=y
include/configs/MCR3000.h +1 -0
index aeda4742aab..a35caa661db 100644
@@ -10,6 +10,7 @@
 
 /* High Level Configuration Options */
 #define CONFIG_MISC_INIT_R		1	/* Call misc_init_r	*/
+#define CONFIG_BOARD_EARLY_INIT_R	1
 
 #define CONFIG_EXTRA_ENV_SETTINGS					\
 	"sdram_type=SDRAM\0"						\
Signature · 1 line
2.13.3
#4 lore raw

RFC PATCH v2 4/6 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 7a5908f4645..b568e14328f 100644
@@ -7,6 +7,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <dm.h>
 #include <serial.h>
 #include <watchdog.h>
 #include <asm/cpm_8xx.h>
@@ -36,9 +37,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 */
@@ -72,7 +73,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)
@@ -187,11 +188,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)
 {
@@ -234,6 +237,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,
@@ -254,3 +258,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
#5 lore raw

RFC PATCH v2 5/6 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 f3dc571be22..402a299b3cd 100644
@@ -76,3 +76,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
#6 lore raw

RFC PATCH v2 6/6 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 397c6f52030..7ca61317bee 100644
@@ -113,7 +113,6 @@ serial_initfunc(atmel_serial_initialize);
 serial_initfunc(au1x00_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);
@@ -168,7 +167,6 @@ void serial_initialize(void)
 	au1x00_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 384df94ed0b..06d15317026 100644
@@ -169,7 +169,6 @@ void atmel_serial_initialize(void);
 void au1x00_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
#7 lore raw

v2 cover Beginning of migration of MPC8xx to DM model

In reply to Christophe Leroy

Hello,

Le 16/03/2018 à 17:32, Christophe Leroy a écrit :

Quoted 1 line

This serie is the beginning of MPC8xx migration to DM model.

I didn't get any feedback on this serie. I don't feel totally confortable as it is my first implementation of DM and also the first time powerpc uses DT for U-boot.

I'd rather someone look at it.

Thanks
Christophe

Quoted 30 lines

It applies on top of the serie "[v4] Powerpc: mpc8xx: cleanup before migration to DM model"

Christophe Leroy (6):
board: MCR3000: Activate CONFIG_DM and CONFIG_OF_CONTROL
drivers: watchdog: add a DM driver for the MPC8xx watchdog
board: MCR3000: use new DM watchdog
drivers: serial: migrate mpc8xx to DM
board: MCR3000: migrate to DM_SERIAL
drivers: serial: get rid of non DM mpc8xx driver

Change since initial RFC:
Migrated serial driver in addition
Few changes on the watchdog

  arch/powerpc/dts/Makefile      | 16 ++++++++++
  arch/powerpc/dts/mcr3000.dts   | 22 ++++++++++++++
  board/cssi/MCR3000/MCR3000.c   | 16 ++++++++++
  board/cssi/MCR3000/u-boot.lds  |  6 ++++
  configs/MCR3000_defconfig      |  6 ++++
  drivers/serial/serial.c        |  2 --
  drivers/serial/serial_mpc8xx.c | 66 ++++++++++++++++++++++--------------------
  drivers/watchdog/Kconfig       |  7 +++++
  drivers/watchdog/mpc8xx_wdt.c  | 51 ++++++++++++++++++++++++++++++++
  include/configs/MCR3000.h      |  1 +
  include/serial.h               |  1 -
  11 files changed, 159 insertions(+), 35 deletions(-)

create mode 100644 arch/powerpc/dts/Makefile
create mode 100644 arch/powerpc/dts/mcr3000.dts

#8 lore raw

v2 cover Beginning of migration of MPC8xx to DM model

Hi Christophe,

Quoted 5 lines · Christophe LEROY

Hello,

Quoted 1 line · Christophe Leroy
Quoted 9 lines
Quoted 1 line

This serie is the beginning of MPC8xx migration to DM model.

I didn't get any feedback on this serie. I don't feel totally confortable as it is my first implementation of DM and also the first time powerpc uses DT for U-boot.

I'd rather someone look at it.

One thing I'm noticing: Are you setting up pre-relocation malloc? Since MPC8xx is another old powerpc platform, I suspect that the start.S doesn't do it, and DM needs it to function correctly.

Maybe you can model the case of MPC8xx similarly to the ones for MPC83xx and MPC85xx (those are pretty similar):

dbcb2c0e2ba28 ("powerpc: mpc83xx: Enable pre-relocation malloc") 50689461205e0 ("powerpc: mpc85xx: Enable pre-relocation malloc for MPC85xx")

Quoted 3 lines

Thanks
Christophe

Best regards,
Mario

Quoted 35 lines
Quoted 34 lines

It applies on top of the serie "[v4] Powerpc: mpc8xx: cleanup before migration to DM model"

Christophe Leroy (6):
board: MCR3000: Activate CONFIG_DM and CONFIG_OF_CONTROL
drivers: watchdog: add a DM driver for the MPC8xx watchdog
board: MCR3000: use new DM watchdog
drivers: serial: migrate mpc8xx to DM
board: MCR3000: migrate to DM_SERIAL
drivers: serial: get rid of non DM mpc8xx driver

Change since initial RFC:
Migrated serial driver in addition
Few changes on the watchdog

  arch/powerpc/dts/Makefile      | 16 ++++++++++
  arch/powerpc/dts/mcr3000.dts   | 22 ++++++++++++++
  board/cssi/MCR3000/MCR3000.c   | 16 ++++++++++
  board/cssi/MCR3000/u-boot.lds  |  6 ++++
  configs/MCR3000_defconfig      |  6 ++++
  drivers/serial/serial.c        |  2 --
  drivers/serial/serial_mpc8xx.c | 66
++++++++++++++++++++++--------------------
  drivers/watchdog/Kconfig       |  7 +++++
  drivers/watchdog/mpc8xx_wdt.c  | 51 ++++++++++++++++++++++++++++++++
  include/configs/MCR3000.h      |  1 +
  include/serial.h               |  1 -
  11 files changed, 159 insertions(+), 35 deletions(-)

create mode 100644 arch/powerpc/dts/Makefile
create mode 100644 arch/powerpc/dts/mcr3000.dts

#9 lore raw

v2 cover Beginning of migration of MPC8xx to DM model

Hi Mario,

Le 04/05/2018 à 11:56, Mario Six a écrit :

Quoted 16 lines

Hi Christophe,

Quoted 12 lines · Christophe LEROY

Hello,

Quoted 2 lines · Christophe Leroy

This serie is the beginning of MPC8xx migration to DM model.

I didn't get any feedback on this serie. I don't feel totally confortable as it is my first implementation of DM and also the first time powerpc uses DT for U-boot.

Quoted 6 lines
Quoted 2 lines

I'd rather someone look at it.

One thing I'm noticing: Are you setting up pre-relocation malloc? Since MPC8xx is another old powerpc platform, I suspect that the start.S doesn't do it, and DM needs it to function correctly.

Yes, I did it with the following patch:

https://patchwork.ozlabs.org/patch/886980/

Best regards
Christophe

Quoted 49 lines

Maybe you can model the case of MPC8xx similarly to the ones for MPC83xx and MPC85xx (those are pretty similar):

dbcb2c0e2ba28 ("powerpc: mpc83xx: Enable pre-relocation malloc") 50689461205e0 ("powerpc: mpc85xx: Enable pre-relocation malloc for MPC85xx")

Quoted 3 lines

Thanks
Christophe

Best regards,
Mario

Quoted 35 lines
Quoted 34 lines

It applies on top of the serie "[v4] Powerpc: mpc8xx: cleanup before migration to DM model"

Christophe Leroy (6):
board: MCR3000: Activate CONFIG_DM and CONFIG_OF_CONTROL
drivers: watchdog: add a DM driver for the MPC8xx watchdog
board: MCR3000: use new DM watchdog
drivers: serial: migrate mpc8xx to DM
board: MCR3000: migrate to DM_SERIAL
drivers: serial: get rid of non DM mpc8xx driver

Change since initial RFC:
Migrated serial driver in addition
Few changes on the watchdog

   arch/powerpc/dts/Makefile      | 16 ++++++++++
   arch/powerpc/dts/mcr3000.dts   | 22 ++++++++++++++
   board/cssi/MCR3000/MCR3000.c   | 16 ++++++++++
   board/cssi/MCR3000/u-boot.lds  |  6 ++++
   configs/MCR3000_defconfig      |  6 ++++
   drivers/serial/serial.c        |  2 --
   drivers/serial/serial_mpc8xx.c | 66
++++++++++++++++++++++--------------------
   drivers/watchdog/Kconfig       |  7 +++++
   drivers/watchdog/mpc8xx_wdt.c  | 51 ++++++++++++++++++++++++++++++++
   include/configs/MCR3000.h      |  1 +
   include/serial.h               |  1 -
   11 files changed, 159 insertions(+), 35 deletions(-)

create mode 100644 arch/powerpc/dts/Makefile create mode 100644 arch/powerpc/dts/mcr3000.dts

#10 lore raw

v2 cover Beginning of migration of MPC8xx to DM model

Quoted 25 lines · Christophe LEROY

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Hi Mario,

Quoted 19 lines · Mario Six

Hi Christophe,

Quoted 14 lines · Christophe LEROY

Hello,

Quoted 2 lines · Christophe Leroy

This serie is the beginning of MPC8xx migration to DM model.

I didn't get any feedback on this serie. I don't feel totally confortable as it is my first implementation of DM and also the first time powerpc uses DT for U-boot.

I'd rather someone look at it.

Quoted 7 lines
Quoted 3 lines

One thing I'm noticing: Are you setting up pre-relocation malloc? Since MPC8xx is another old powerpc platform, I suspect that the start.S doesn't do it, and DM needs it to function correctly.

Yes, I did it with the following patch:

https://patchwork.ozlabs.org/patch/886980/

Hi

Had a quick look at that patch and it looks like you lost zeroing the
stack frame (stwu r0, -4(r1) ...) ?

Also, don't use touch r1 until the stack is ready, otherwise gdb will try accessing the stack if you single step over this part.

Jocke