Skip to contentSkip to conversation

ppc4xx: Initialize magnetic couplers in PLU405

PATCH Superseded Matthias Fuchs 2 participants 4 messages Oct 23, 2009

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ppc4xx: Initialize magnetic couplers in 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.

---
V2 changes:
- use C struct to access CAN controller registes

 board/esd/plu405/plu405.c |   56 +++++++++++++++++++++++++++++++++++++++++++++
 include/configs/PLU405.h  |    3 +-
 2 files changed, 58 insertions(+), 1 deletions(-)
board/esd/plu405/plu405.c +56 -0
index 1841cda..7fd24c1 100644
@@ -45,6 +45,55 @@ const unsigned char fpgadata[] =
  */
 #include "../common/fpga.c"
 
+/*
+ * SJA1000 register layout in basic can mode
+ */
+struct sja1000_basic_s {
+	u8 cr;
+	u8 cmr;
+	u8 sr;
+	u8 ir;
+	u8 ac;
+	u8 am;
+	u8 btr0;
+	u8 btr1;
+	u8 oc;
+	u8 txb[10];
+	u8 rxb[10];
+	u8 unused;
+	u8 cdr;
+};
+
+#define SJA1000_CR_RR 0x01
+#define SJA1000_OC_MODE0 0x01
+
+/*
+ * generate a short spike on the CAN tx line
+ * to bring the couplers in sync
+ */
+void init_coupler(u32 addr)
+{
+	struct sja1000_basic_s *ctrl = (struct sja1000_basic_s *)addr;
+
+	/* reset */
+	out_8(&ctrl->cr, 0x20 | SJA1000_CR_RR);
+
+	/* dominant */
+	out_8(&ctrl->btr0, 0x00); /* btr setup is required */
+	out_8(&ctrl->btr1, 0x14); /* we use 1Mbit/s */
+	out_8(&ctrl->oc, ~SJA1000_OC_MODE0);
+	out_8(&ctrl->cr, 0x20);
+
+	/* delay */
+	in_8(&ctrl->cr);
+	in_8(&ctrl->cr);
+	in_8(&ctrl->cr);
+	in_8(&ctrl->cr);
+
+	/* reset */
+	out_8(&ctrl->cr, 0x20 | SJA1000_CR_RR);
+}
+
 /* Prototypes */
 int gunzip(void *, int, unsigned char *, unsigned long *);
 
@@ -198,6 +247,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.6.1
#1 lore raw

PATCH v2 1/1 ppc4xx: Initialize magnetic couplers in PLU405

Dear Matthias Fuchs,

Quoted 3 lines · In message <[email protected]> you wrote:

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.

...

Quoted 17 lines
board/esd/plu405/plu405.c +11 -0
@@ -45,6 +45,55 @@ const unsigned char fpgadata[] =
  */
 #include "../common/fpga.c"
 
+/*
+ * SJA1000 register layout in basic can mode
+ */
+struct sja1000_basic_s {
+	u8 cr;
+	u8 cmr;
+	u8 sr;
+	u8 ir;
+	u8 ac;
+	u8 am;
+	u8 btr0;

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

Quoted 10 lines
board/esd/plu405/plu405.c +10 -0
+	u8 btr1;
+	u8 oc;
+	u8 txb[10];
+	u8 rxb[10];
+	u8 unused;
+	u8 cdr;
+};
+
+#define SJA1000_CR_RR 0x01
+#define SJA1000_OC_MODE0 0x01

Hmm... a SJA1000 is a pretty generic piece of hardware, and in no way specific to the plu405 board. Would it not make sense to create as separate header file for this? Eventually other boards will need to interface to SJA1000's, too ?

Best regards,

Wolfgang Denk

Signature · 4 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
To be awake is to be alive.        - Henry David Thoreau, in "Walden"
#2 lore raw

PATCH v2 1/1 ppc4xx: Initialize magnetic couplers in PLU405

Wolfgang,

you are right, but I didn't want to trigger a discussion about CAN in U-Boot. This has nothing to do with CAN :-)

Also I am using the controller in a slightly untypical manner. I also dont't want to add sja1000 Linux kernel headers (from SocketCAN) - a) they do not contains the wanted C struct and
b) they don't use the basic CAN mode of the chip.

So when you want me just to move the SJA1000 specific struct and the two defines into a header and place that under include, I will do so. But please nothing else.

Matthias

Quoted 44 lines · Wolfgang Denk

Dear Matthias Fuchs,

Quoted 3 lines · In message <[email protected]> you wrote:

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.

...

Quoted 17 lines
board/esd/plu405/plu405.c +11 -0
@@ -45,6 +45,55 @@ const unsigned char fpgadata[] =
  */
 #include "../common/fpga.c"
 
+/*
+ * SJA1000 register layout in basic can mode
+ */
+struct sja1000_basic_s {
+	u8 cr;
+	u8 cmr;
+	u8 sr;
+	u8 ir;
+	u8 ac;
+	u8 am;
+	u8 btr0;

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

Quoted 10 lines
board/esd/plu405/plu405.c +10 -0
+	u8 btr1;
+	u8 oc;
+	u8 txb[10];
+	u8 rxb[10];
+	u8 unused;
+	u8 cdr;
+};
+
+#define SJA1000_CR_RR 0x01
+#define SJA1000_OC_MODE0 0x01

Hmm... a SJA1000 is a pretty generic piece of hardware, and in no way specific to the plu405 board. Would it not make sense to create as separate header file for this? Eventually other boards will need to interface to SJA1000's, too ?

Best regards,

Wolfgang Denk

#3 lore raw

PATCH v2 1/1 ppc4xx: Initialize magnetic couplers in PLU405

Dear Matthias,

Quoted 3 lines · In message <[email protected]> you wrote:

you are right, but I didn't want to trigger a discussion about CAN in U-Boot. This has nothing to do with CAN :-)

Yes, I know. But then - haven't you seen requests to boot over CAN yet? ;-)

Quoted 4 lines

Also I am using the controller in a slightly untypical manner. I also dont't want to add sja1000 Linux kernel headers (from SocketCAN) - a) they do not contains the wanted C struct and
b) they don't use the basic CAN mode of the chip.

OK.

Quoted 3 lines

So when you want me just to move the SJA1000 specific struct and the two defines into a header and place that under include, I will do so. But please nothing else.

That's what I had in mind. I'm not asking for more things, unrelated to your current task. Thanks.

Best regards,

Wolfgang Denk

Signature · 4 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
I've got a bad feeling about this.