Subject: Magma 2+1HS Sp: success!
To: None <port-sparc@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: port-sparc
Date: 01/17/2002 03:06:35
My Magma 2+1HS Sp now works, at least for smoke-test values of "works".
One serial port talks to itself with a loopback connector (pins 2 and 3
connected) and it talks to another machine at 9600 (so it doesn't have
the baudrate out by a factor of 20:25 or any such).  I haven't tried
the other serial port, but don't expect any problems.

The parallel port doesn't work and won't until someone does code for
the CD1190; if someone can send me - or tell me where to get - docs, I
may even be able to do it myself (and am certainly willing to try).

Here's what I did to dev/sbus/magma* to make it work.  This is
relative to magma.c 1.5 and magmareg.h 1.2.  You may not want the last
hunk and the last part of the second-last hunk (for magma.c); those
parts change a couple of dprintfs to printfs and adjust the info
printed slightly.

I'm not sure I have the offset for the CD1160 correct in the
supported_cards[] table, of course; what's there is just a guess.  (I
was fiddling with those numbers, trying to make it stop hanging at
boot; I finally added debugging code and discovered the actual problem,
which was a missing ++ that turned the clock speed property parsing
into an infinite loop.)

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

--- /sources/20000219/latest-usr-src/sys/dev/sbus/magma.c	Sat Feb 19 19:55:50 2000
+++ /tmp/magma.c	Thu Jan 17 02:59:16 2002
@@ -95,77 +95,82 @@
  */
 static struct magma_board_info supported_cards[] = {
 	{
-		"MAGMA,4_Sp", "Magma 4 Sp", 4, 0,
+		"MAGMA_Sp", "MAGMA,4_Sp", "Magma 4 Sp", 4, 0,
 		1, 0xa000, 0xc000, 0xe000, { 0x8000, 0, 0, 0 },
 		0, { 0, 0 }
 	},
 	{
-		"MAGMA,8_Sp", "Magma 8 Sp", 8, 0,
+		"MAGMA_Sp", "MAGMA,8_Sp", "Magma 8 Sp", 8, 0,
 		2, 0xa000, 0xc000, 0xe000, { 0x4000, 0x6000, 0, 0 },
 		0, { 0, 0 }
 	},
 	{
-		"MAGMA,_8HS_Sp", "Magma Fast 8 Sp", 8, 0,
+		"MAGMA_Sp", "MAGMA,_8HS_Sp", "Magma Fast 8 Sp", 8, 0,
 		2, 0x2000, 0x4000, 0x6000, { 0x8000, 0xa000, 0, 0 },
 		0, { 0, 0 }
 	},
 	{
-		"MAGMA,_8SP_422", "Magma 8 Sp - 422", 8, 0,
+		"MAGMA_Sp", "MAGMA,_8SP_422", "Magma 8 Sp - 422", 8, 0,
 		2, 0x2000, 0x4000, 0x6000, { 0x8000, 0xa000, 0, 0 },
 		0, { 0, 0 }
 	},
 	{
-		"MAGMA,12_Sp", "Magma 12 Sp", 12, 0,
+		"MAGMA_Sp", "MAGMA,12_Sp", "Magma 12 Sp", 12, 0,
 		3, 0xa000, 0xc000, 0xe000, { 0x2000, 0x4000, 0x6000, 0 },
 		0, { 0, 0 }
 	},
 	{
-		"MAGMA,16_Sp", "Magma 16 Sp", 16, 0,
+		"MAGMA_Sp", "MAGMA,16_Sp", "Magma 16 Sp", 16, 0,
 		4, 0xd000, 0xe000, 0xf000, { 0x8000, 0x9000, 0xa000, 0xb000 },
 		0, { 0, 0 }
 	},
 	{
-		"MAGMA,16_Sp_2", "Magma 16 Sp", 16, 0,
+		"MAGMA_Sp", "MAGMA,16_Sp_2", "Magma 16 Sp", 16, 0,
 		4, 0x2000, 0x4000, 0x6000, { 0x8000, 0xa000, 0xc000, 0xe000 },
 		0, { 0, 0 }
 	},
 	{
-		"MAGMA,16HS_Sp", "Magma Fast 16 Sp", 16, 0,
+		"MAGMA_Sp", "MAGMA,16HS_Sp", "Magma Fast 16 Sp", 16, 0,
 		4, 0x2000, 0x4000, 0x6000, { 0x8000, 0xa000, 0xc000, 0xe000 },
 		0, { 0, 0 }
 	},
 	{
-		"MAGMA,21_Sp", "Magma LC 2+1 Sp", 2, 1,
+		"MAGMA_Sp", "MAGMA,21_Sp", "Magma LC 2+1 Sp", 2, 1,
 		1, 0xa000, 0xc000, 0xe000, { 0x8000, 0, 0, 0 },
 		0, { 0, 0 }
 	},
 	{
-		"MAGMA,21HS_Sp", "Magma 2+1 Sp", 2, 1,
+		"MAGMA_Sp", "MAGMA,21HS_Sp", "Magma 2+1 Sp", 2, 1,
 		1, 0xa000, 0xc000, 0xe000, { 0x4000, 0, 0, 0 },
 		1, { 0x6000, 0 }
 	},
 	{
-		"MAGMA,41_Sp", "Magma 4+1 Sp", 4, 1,
+		"MAGMA_Sp", "MAGMA,41_Sp", "Magma 4+1 Sp", 4, 1,
 		1, 0xa000, 0xc000, 0xe000, { 0x4000, 0, 0, 0 },
 		1, { 0x6000, 0 }
 	},
 	{
-		"MAGMA,82_Sp", "Magma 8+2 Sp", 8, 2,
+		"MAGMA_Sp", "MAGMA,82_Sp", "Magma 8+2 Sp", 8, 2,
 		2, 0xd000, 0xe000, 0xf000, { 0x8000, 0x9000, 0, 0 },
 		2, { 0xa000, 0xb000 }
 	},
 	{
-		"MAGMA,P1_Sp", "Magma P1 Sp", 0, 1,
+		"MAGMA_Sp", "MAGMA,P1_Sp", "Magma P1 Sp", 0, 1,
 		0, 0, 0, 0, { 0, 0, 0, 0 },
 		1, { 0x8000, 0 }
 	},
 	{
-		"MAGMA,P2_Sp", "Magma P2 Sp", 0, 2,
+		"MAGMA_Sp", "MAGMA,P2_Sp", "Magma P2 Sp", 0, 2,
 		0, 0, 0, 0, { 0, 0, 0, 0 },
 		2, { 0x4000, 0x8000 }
 	},
 	{
-		NULL, NULL, 0, 0,
+		"MAGMA 2+1HS Sp", "", "Magma 2+1HS Sp", 2, 0,
+		1, 0xa000, 0xc000, 0xe000, { 0x4000, 0, 0, 0 },
+		1, { 0x8000, 0 }
+	},
+	{
+		0, 0, 0, 0, 0,
 		0, 0, 0, 0, { 0, 0, 0, 0 },
 		0, { 0, 0 }
 	}
@@ -308,10 +313,14 @@
 	void *aux;
 {
 	struct sbus_attach_args *sa = aux;
+	int i;
 
-	/* is it a magma Sp card? */
-	if( strcmp(sa->sa_name, "MAGMA_Sp") != 0 )
-		return(0);
+	for (i=0; ; i++) {
+		if (! supported_cards[i].mb_sbusname)
+			return(0);
+		if (! strcmp(sa->sa_name,supported_cards[i].mb_sbusname))
+			break;
+	}
 
 	dprintf(("magma: matched `%s'\n", sa->sa_name));
 	dprintf(("magma: magma_prom `%s'\n",
@@ -343,7 +352,9 @@
 	magma_prom = getpropstring(node, "magma_prom");
 
 	/* find the card type */
-	while (card->mb_name && strcmp(magma_prom, card->mb_name) != 0)
+	while ( card->mb_name &&
+		( strcmp(magma_prom,card->mb_name) ||
+		  strcmp(sa->sa_name,card->mb_sbusname) ) )
 		card++;
 
 	dprintf((" addr %p", sc));
@@ -377,20 +388,28 @@
 
 	/* init the cd1400 chips */
 	for( chip = 0 ; chip < card->mb_ncd1400 ; chip++ ) {
+		char *clockstr;
 		struct cd1400 *cd = &sc->ms_cd1400[chip];
 
 		cd->cd_reg = (caddr_t)bh + card->mb_cd1400[chip];
 
-		/* XXX getpropstring(node, "clock") */
-		cd->cd_clock = 25;
+		clockstr = getpropstring(node, "clock");
+		if (!clockstr || !*clockstr)
+			cd->cd_clock = 25;
+		else {
+			cd->cd_clock = 0;
+			while (*clockstr)
+				cd->cd_clock = (cd->cd_clock * 10) +
+							(*clockstr++ - '0');
+		}
 
 		/* getpropstring(node, "chiprev"); */
 		/* seemingly the Magma drivers just ignore the propstring */
 		cd->cd_chiprev = cd1400_read_reg(cd, CD1400_GFRCR);
 
-		dprintf(("%s attach CD1400 %d addr %p rev %x clock %dMhz\n",
+		printf("%s: CD1400 %d addr %p rev %x clock %dMhz\n",
 			sc->ms_dev.dv_xname, chip,
-			cd->cd_reg, cd->cd_chiprev, cd->cd_clock));
+			(void *)cd->cd_reg, cd->cd_chiprev, cd->cd_clock);
 
 		/* clear GFRCR */
 		cd1400_write_reg(cd, CD1400_GFRCR, 0x00);
@@ -422,9 +441,10 @@
 		struct cd1190 *cd = &sc->ms_cd1190[chip];
 
 		cd->cd_reg = (caddr_t)bh + card->mb_cd1190[chip];
-		dprintf(("%s attach CD1190 %d addr %p (failed)\n",
-			self->dv_xname, chip, cd->cd_reg));
+
 		/* XXX don't know anything about these chips yet */
+		printf("%s: CD1190 %d addr %p (failed)\n",
+			self->dv_xname, chip, cd->cd_reg);
 	}
 
 	sbus_establish(&sc->ms_sd, &sc->ms_dev);
--- /sources/20000219/latest-usr-src/sys/dev/sbus/magmareg.h	Sat Feb 19 19:55:50 2000
+++ /tmp/magmareg.h	Thu Jan 17 03:01:42 2002
@@ -69,8 +69,9 @@
  * Supported Card Types
  */
 struct magma_board_info {
-	char *mb_name;			/* cardname to match against */
-	char *mb_realname;		/* english card name */
+	const char *mb_sbusname;	/* sbus_attach_args.sa_name */
+	const char *mb_name;		/* cardname to match against */
+	const char *mb_realname;	/* english card name */
 	int mb_nser;			/* number of serial ports */
 	int mb_npar;			/* number of parallel ports */
 	int mb_ncd1400;			/* number of CD1400 chips */