Skip to contentSkip to conversation

ppc4xx: Initialize magnetic couplers on PLU405

PATCH New Matthias Fuchs 2 participants 2 messages Oct 22, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ppc4xx: Initialize magnetic couplers on PLU405

This patch fixes an ugly behavior of the IL712 magnetic couplers as used on PLU405. These parts will remember their last state over a power cycle which might cause unwanted behavior.

---
 board/esd/plu405/plu405.c |   33 +++++++++++++++++++++++++++++++++
 include/configs/PLU405.h  |    3 ++-
 2 files changed, 35 insertions(+), 1 deletions(-)
board/esd/plu405/plu405.c +33 -0
index 1841cda..7e6bf3b 100644
@@ -45,6 +45,32 @@ const unsigned char fpgadata[] =
  */
 #include "../common/fpga.c"
 
+/*
+ * generate a short spike on the CAN tx line
+ * to bring the couplers in sync
+ */
+void init_coupler(u32 addr)
+{
+	u8 *ctrl = (u8*)addr;
+
+	/* reset */
+	out_8(ctrl, 0x21);
+
+	/* dominant */
+	out_8(ctrl + 6, 0x00);
+	out_8(ctrl + 7, 0x14);
+	out_8(ctrl + 8, 0xfe);
+	out_8(ctrl, 0x20);
+
+	/* delay */
+	in_8(ctrl);
+	in_8(ctrl);
+	in_8(ctrl);
+
+	/* reset */
+	out_8(ctrl, 0x21);
+}
+
 /* Prototypes */
 int gunzip(void *, int, unsigned char *, unsigned long *);
 
@@ -198,6 +224,13 @@ int misc_init_r(void)
 	out_8((void *)DUART1_BA + 1, fctr); /* write FCTR */
 	out_8((void *)DUART1_BA + 3, 0);    /* write LCR */
 
+	/*
+	 * Init magnetic couplers
+	 */
+	if (!getenv("noinitcoupler")) {
+		init_coupler(CAN0_BA);
+		init_coupler(CAN1_BA);
+	}
 	return 0;
 }
 
include/configs/PLU405.h +2 -1
index 07fc715..b6740de 100644
@@ -298,7 +298,8 @@
 /*
  * External Bus Controller (EBC) Setup
  */
-#define CAN_BA		0xF0000000	    /* CAN Base Address	        */
+#define CAN0_BA		0xF0000000	    /* CAN0 Base Address	*/
+#define CAN1_BA		0xF0000100	    /* CAN1 Base Address	*/
 #define DUART0_BA	0xF0000400	    /* DUART Base Address       */
 #define DUART1_BA	0xF0000408	    /* DUART Base Address       */
 #define RTC_BA		0xF0000500	    /* RTC Base Address         */
Signature · 1 line
1.5.6.3
#1 lore raw

PATCH 1/1 ppc4xx: Initialize magnetic couplers on PLU405

Dear Matthias Fuchs,

board/esd/plu405/plu405.c const unsigned char fpgadata[] = · line 63

Quoted 11 lines · In message <[email protected]> you wrote:
board/esd/plu405/plu405.c +10 -0
+	u8 *ctrl = (u8*)addr;
+
+	/* reset */
+	out_8(ctrl, 0x21);
+
+	/* dominant */
+	out_8(ctrl + 6, 0x00);
+	out_8(ctrl + 7, 0x14);
+	out_8(ctrl + 8, 0xfe);
+	out_8(ctrl, 0x20);

Please do not acces hardware using a base address plus offsets, please declare and use a proper C struct for this. Also, you want to add some symbolic constants (and comments) for all the magic numbers used here.

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
There are two ways of constructing a software design. One way  is  to
make  it  so  simple that there are obviously no deficiencies and the
other is to make it so complicated that there are  no  obvious  defi-
ciencies.                             - Charles Anthony Richard Hoare