Skip to contentSkip to conversation

STLC2500 updated patch

PATCH In review Fabien Chevalier 2 participants 7 messages Oct 8, 2007 – Oct 9, 2007 Bluetooth drivers

lore
Share & tools
lore
maintainer
#1 lore raw
In reply to Fabien Chevalier

Hi Fabien,

Quoted 10 lines

Here is an updated version of the STLC2500 patch. Compared to previous patch versions, it adds support to speeds up to 4000000 bps.

* Add support for speed up to 4000000 bps.
* Makes the firmware & parameters download optional : even though those are supposed to be mandatory, practive shows that the chip can run without them.
* Cleanup the speed setting step : call the Ericsson routines directly instead of duplicating the code.
* Reset the chip only once after all settings & downloads have been done.

please break this down into four separate patches. I hate big patches that try to fix everything in one go.

Regards

Marcel

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#0 lore raw

PATCH 1/1 STLC2500 updated patch

Marcel & all,

Here is an updated version of the STLC2500 patch. Compared to previous patch versions, it adds support to speeds up to 4000000 bps.

* Add support for speed up to 4000000 bps.
* Makes the firmware & parameters download optional : even though those are supposed to be mandatory, practive shows that the chip can run without them.
* Cleanup the speed setting step : call the Ericsson routines directly instead of duplicating the code.
* Reset the chip only once after all settings & downloads have been done.

Cheers,

Fabien

hciattach.c +25 -47
Index: tools/hciattach.c
===================================================================
@@ -117,12 +117,22 @@
 	case 1000000:
 		return B1000000;
 	case 1152000:
 		return B1152000;
 	case 1500000:
 		return B1500000;
+	case 2000000:
+		return B2000000;
+	case 2500000:
+		return B2500000;
+	case 3000000:
+		return B3000000;
+	case 3500000:
+		return B3500000;
+	case 4000000:
+		return B4000000;
 	default:
 		return B57600;
 	}
 }
 
 static int set_speed(int fd, struct termios *ti, int speed)
@@ -203,15 +213,25 @@
 	case 460800:
 		cmd[4] = 0x00;
 		break;
 	case 921600:
 		cmd[4] = 0x20;
 		break;
+	case 2000000:
+		cmd[4] = 0x25;
+		break;
+	case 3000000:
+		cmd[4] = 0x27;
+		break;
+	case 4000000:
+		cmd[4] = 0x2B;
+		break;
 	default:
 		cmd[4] = 0x03;
 		u->speed = 57600;
+		fprintf(stderr, "Invalid speed requested, using %d bps instead\n", u->speed);
 		break;
 	}
 
 	/* Send initialization command */
 	if (write(fd, cmd, 5) != 5) {
 		perror("Failed to write init command");
@@ -829,62 +849,20 @@
 
 extern int stlc2500_init(int fd, bdaddr_t *bdaddr);
 
 static int stlc2500(int fd, struct uart_t *u, struct termios *ti)
 {
 	bdaddr_t bdaddr;
-	char cmd[5];
 	unsigned char resp[10];
 	int n;
+	int rvalue;
 
-	/* STLC2500 Set Baud Rate stuff */
-	/* We should set the baud rate first, so the firmware download */
-	/* goes much faster */
-
-	/* STLC2500 Seems to support the Ericsson set baud rate stuff */
-	/* It should also support the ST Set Baud Rate command */
-	/* (as in st() function above, but those commands never succeed */
-	cmd[0] = HCI_COMMAND_PKT;
-	cmd[1] = 0x09;
-	cmd[2] = 0xfc;
-	cmd[3] = 0x01;
-
-	switch (u->speed) {
-	case 57600:
-		cmd[4] = 0x03;
-		break;
-	case 115200:
-		cmd[4] = 0x02;
-		break;
-	case 230400:
-		cmd[4] = 0x01;
-		break;
-	case 460800:
-		cmd[4] = 0x00;
-		break;
-	case 921600:
-		cmd[4] = 0x20;
-		break;
-	default:
-		cmd[4] = 0x02;
-		u->speed = 115200;
-		break;
-	}
-
-#ifdef STLC2500_DEBUG
-	fprintf(stderr, "Sending Baud Rate %02x\n", cmd[4]);
-#endif
-	/* Send initialization command */
-	if (write(fd, cmd, 5) != 5) {
-		perror("Failed to write init command");
-		return -1;
-	}
-
-	/* Need to wait here to give a chance for the device to set baud */
-	/* But no more than 0.5 seconds */
-	usleep(200000);
+	/* STLC2500 has an ericsson core */
+	rvalue = ericsson(fd, u, ti);
+	if (rvalue != 0)
+		return rvalue;
 
 #ifdef STLC2500_DEBUG
 	fprintf(stderr, "Setting speed\n");
 #endif
 	if (set_speed(fd, ti, u->speed) < 0) {
 		perror("Can't set baud rate");
hciattach_st.c +29 -17

117 lines not on this page · raw message

begin:vcard
fn:Fabien CHEVALIER
n:CHEVALIER;Fabien
org:SILICOM
adr:;;4 rue de Jouanet; RENNES ATALANTE;;35700;FRANCE email;internet:[email protected] title:Software & Studies Engineer tel;work:+33 (0) 2 99 84 17 17
version:2.1
end:vcard

#2 lore raw
In reply to Marcel Holtmann
Quoted 4 lines

please break this down into four separate patches. I hate big patches that try to fix everything in one go.

First of the list : provide support for higher baud rates for ericcson based chipsets.

Fabien

hciattach.c +20 -0
Index: tools/hciattach.c
===================================================================
@@ -117,12 +117,22 @@
 	case 1000000:
 		return B1000000;
 	case 1152000:
 		return B1152000;
 	case 1500000:
 		return B1500000;
+	case 2000000:
+		return B2000000;
+	case 2500000:
+		return B2500000;
+	case 3000000:
+		return B3000000;
+	case 3500000:
+		return B3500000;
+	case 4000000:
+		return B4000000;
 	default:
 		return B57600;
 	}
 }
 
 static int set_speed(int fd, struct termios *ti, int speed)
@@ -203,15 +213,25 @@
 	case 460800:
 		cmd[4] = 0x00;
 		break;
 	case 921600:
 		cmd[4] = 0x20;
 		break;
+	case 2000000:
+		cmd[4] = 0x25;
+		break;
+	case 3000000:
+		cmd[4] = 0x27;
+		break;
+	case 4000000:
+		cmd[4] = 0x2B;
+		break;
 	default:
 		cmd[4] = 0x03;
 		u->speed = 57600;
+		fprintf(stderr, "Invalid speed requested, using %d bps instead\n", u->speed);
 		break;
 	}
 
 	/* Send initialization command */
 	if (write(fd, cmd, 5) != 5) {
 		perror("Failed to write init command");

begin:vcard
fn:Fabien CHEVALIER
n:CHEVALIER;Fabien
org:SILICOM
adr:;;4 rue de Jouanet; RENNES ATALANTE;;35700;FRANCE email;internet:[email protected] title:Software & Studies Engineer tel;work:+33 (0) 2 99 84 17 17
version:2.1
end:vcard

#3 lore raw
In reply to Marcel Holtmann
Quoted 3 lines · Marcel Holtmann

please break this down into four separate patches. I hate big patches that try to fix everything in one go.

Second on the list : remove duplicated code between ericsson and st initialization methods.

Fabien

hciattach.c +5 -47
Index: tools/hciattach.c
===================================================================
@@ -829,62 +849,20 @@
 
 extern int stlc2500_init(int fd, bdaddr_t *bdaddr);
 
 static int stlc2500(int fd, struct uart_t *u, struct termios *ti)
 {
 	bdaddr_t bdaddr;
-	char cmd[5];
 	unsigned char resp[10];
 	int n;
+	int rvalue;
 
-	/* STLC2500 Set Baud Rate stuff */
-	/* We should set the baud rate first, so the firmware download */
-	/* goes much faster */
-
-	/* STLC2500 Seems to support the Ericsson set baud rate stuff */
-	/* It should also support the ST Set Baud Rate command */
-	/* (as in st() function above, but those commands never succeed */
-	cmd[0] = HCI_COMMAND_PKT;
-	cmd[1] = 0x09;
-	cmd[2] = 0xfc;
-	cmd[3] = 0x01;
-
-	switch (u->speed) {
-	case 57600:
-		cmd[4] = 0x03;
-		break;
-	case 115200:
-		cmd[4] = 0x02;
-		break;
-	case 230400:
-		cmd[4] = 0x01;
-		break;
-	case 460800:
-		cmd[4] = 0x00;
-		break;
-	case 921600:
-		cmd[4] = 0x20;
-		break;
-	default:
-		cmd[4] = 0x02;
-		u->speed = 115200;
-		break;
-	}
-
-#ifdef STLC2500_DEBUG
-	fprintf(stderr, "Sending Baud Rate %02x\n", cmd[4]);
-#endif
-	/* Send initialization command */
-	if (write(fd, cmd, 5) != 5) {
-		perror("Failed to write init command");
-		return -1;
-	}
-
-	/* Need to wait here to give a chance for the device to set baud */
-	/* But no more than 0.5 seconds */
-	usleep(200000);
+	/* STLC2500 has an ericsson core */
+	rvalue = ericsson(fd, u, ti);
+	if (rvalue != 0)
+		return rvalue;
 
 #ifdef STLC2500_DEBUG
 	fprintf(stderr, "Setting speed\n");
 #endif
 	if (set_speed(fd, ti, u->speed) < 0) {
 		perror("Can't set baud rate");

begin:vcard
fn:Fabien CHEVALIER
n:CHEVALIER;Fabien
org:SILICOM
adr:;;4 rue de Jouanet; RENNES ATALANTE;;35700;FRANCE email;internet:[email protected] title:Software & Studies Engineer tel;work:+33 (0) 2 99 84 17 17
version:2.1
end:vcard

#4 lore raw
In reply to Marcel Holtmann
Quoted 4 lines

please break this down into four separate patches. I hate big patches that try to fix everything in one go.

Third on the list: Retrieve version string before anything else, remove bogus resets, add OCF & OGF comments.

Cheers,

Fabien

hciattach_st.c +10 -14
Index: tools/hciattach_st.c
===================================================================
@@ -192,46 +197,42 @@
 {
 	unsigned char cmd[16];
 	unsigned char buf[254];
 	uint16_t version;
 	int len;
 
-	len = do_command(dd, 0x04, 0x0001, NULL, 0, buf, sizeof(buf));
+	/* Hci_Cmd_Ericsson_Read_Revision_Information */	
+	len = do_command(dd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf));
 	if (len < 0)
 		return -1;
 
-	version = buf[2] << 8 | buf[1];
-
-	if (load_file(dd, version, ".ptc") < 0)
-		return -1;
+	printf("%s\n", buf);
 
-	len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf));
+	/* HCI_Read_Local_Version_Information */	
+	len = do_command(dd, 0x04, 0x0001, NULL, 0, buf, sizeof(buf));
 	if (len < 0)
 		return -1;
 
-	if (load_file(dd, buf[2] << 8 | buf[1], ".ssf") < 0)
-		return -1;
+	version = buf[2] << 8 | buf[1];
 
-	len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf));
-	if (len < 0)
+	if (load_file(dd, version, ".ptc") < 0)
 		return -1;
 
-	len = do_command(dd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf));
-	if (len < 0)
+	if (load_file(dd, buf[2] << 8 | buf[1], ".ssf") < 0)
 		return -1;
 
-	printf("%s\n", buf);
-
 	cmd[0] = 0xfe;
 	cmd[1] = 0x06;
 	bacpy((bdaddr_t *) (cmd + 2), bdaddr);
 
+	/* Hci_Cmd_ST_Store_In_NVDS */	
 	len = do_command(dd, 0xff, 0x0022, cmd, 8, buf, sizeof(buf));
 	if (len < 0)
 		return -1;
 
+	/* HCI_Reset : applies parameters*/
 	len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf));
 	if (len < 0)
 		return -1;
 
 	return 0;
 }

begin:vcard
fn:Fabien CHEVALIER
n:CHEVALIER;Fabien
org:SILICOM
adr:;;4 rue de Jouanet; RENNES ATALANTE;;35700;FRANCE email;internet:[email protected] title:Software & Studies Engineer tel;work:+33 (0) 2 99 84 17 17
version:2.1
end:vcard

#5 lore raw
In reply to Marcel Holtmann

And finally the last of the list:

* Makes the firmware & parameters download optional : even though those are supposed to be mandatory, practive shows that the chip can run without them.

Cheers,

Fabien

tools/hciattach_st.c renamed from hciattach_st.c +21 -5
@@ -122,7 +122,7 @@
 	unsigned char cmd[256];
 	unsigned char buf[256];
 	uint8_t seqnum = 0;
-	int fd, size, len;
+	int fd, size, len, found_fw_file;
 
 	memset(filename, 0, sizeof(filename));
 
@@ -138,6 +138,7 @@
 			return -errno;
 	}
 
+	found_fw_file = 0;	
 	while (1) {
 		d = readdir(dir);
 		if (!d)
@@ -152,10 +153,14 @@
 
 		snprintf(filename, sizeof(filename), "%s/%s",
 							pathname, d->d_name);
+		found_fw_file = 1;
 	}
 
 	closedir(dir);
 
+	if (!found_fw_file)
+		return -ENOENT;
+
 	printf("Loading file %s\n", filename);
 
 	fd = open(filename, O_RDONLY);
@@ -194,6 +199,7 @@
 	unsigned char buf[254];
 	uint16_t version;
 	int len;
+	int err;
 
 	/* Hci_Cmd_Ericsson_Read_Revision_Information */	
 	len = do_command(dd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf));
@@ -209,11 +215,21 @@
 
 	version = buf[2] << 8 | buf[1];
 
-	if (load_file(dd, version, ".ptc") < 0)
-		return -1;
+	err = load_file(dd, version, ".ptc");
+	if (err < 0) {
+		if (err == -ENOENT) 	
+			fprintf(stderr, "No ROM patch file loaded.\n");
+		else
+			return -1;
+	}
 
-	if (load_file(dd, buf[2] << 8 | buf[1], ".ssf") < 0)
-		return -1;
+	err = load_file(dd, buf[2] << 8 | buf[1], ".ssf");
+	if (err < 0) {
+		if (err == -ENOENT) 	
+			fprintf(stderr, "No static settings file loaded.\n");
+		else
+			return -1;
+	}
 
 	cmd[0] = 0xfe;
 	cmd[1] = 0x06;

begin:vcard
fn:Fabien CHEVALIER
n:CHEVALIER;Fabien
org:SILICOM
adr:;;4 rue de Jouanet; RENNES ATALANTE;;35700;FRANCE email;internet:[email protected] title:Software & Studies Engineer tel;work:+33 (0) 2 99 84 17 17
version:2.1
end:vcard

maintainer
#6 lore raw

Hi Fabien,

Quoted 1 line

And finally the last of the list:

all of them have been committed to the CVS. Thanks.

Regards

Marcel

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel