olimex: fix V2 startup errors.
Configuring modem control lines and baud rate is only required for V1 devices.
This commit is contained in:
parent
c425c497e8
commit
f501ab0843
|
@ -72,6 +72,53 @@ struct olimex_transport {
|
|||
|
||||
#define TIMEOUT 10000
|
||||
|
||||
static int v1_configure(struct olimex_transport *tr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = usb_control_msg(tr->handle, CP210x_REQTYPE_HOST_TO_DEVICE,
|
||||
CP210X_IFC_ENABLE, 0x1, 0, NULL, 0, 300);
|
||||
#ifdef DEBUG_OLIMEX
|
||||
printc("%s: %s: Sending control message "
|
||||
"CP210x_REQTYPE_HOST_TO_DEVICE, ret = %d\n",
|
||||
__FILE__, __FUNCTION__, ret);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
pr_error(__FILE__": can't enable CP210x UART");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set the baud rate to 500000 bps */
|
||||
ret = usb_control_msg(tr->handle, CP210x_REQTYPE_HOST_TO_DEVICE,
|
||||
CP210X_SET_BAUDDIV, 0x7, 0, NULL, 0, 300);
|
||||
#ifdef DEBUG_OLIMEX
|
||||
printc("%s: %s: Sending control message "
|
||||
"CP210X_SET_BAUDDIV, ret = %d\n",
|
||||
__FILE__, __FUNCTION__, ret);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
pr_error(__FILE__": can't set baud rate");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set the modem control settings.
|
||||
* Set RTS, DTR and WRITE_DTR, WRITE_RTS
|
||||
*/
|
||||
ret = usb_control_msg(tr->handle, CP210x_REQTYPE_HOST_TO_DEVICE,
|
||||
CP210X_SET_MHS, 0x303, 0, NULL, 0, 300);
|
||||
#ifdef DEBUG_OLIMEX
|
||||
printc("%s: %s: Sending control message "
|
||||
"CP210X_SET_MHS, ret %d\n",
|
||||
__FILE__, __FUNCTION__, ret);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
pr_error(__FILE__": can't set modem control");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int open_interface(struct olimex_transport *tr,
|
||||
struct usb_device *dev, int ino)
|
||||
{
|
||||
|
@ -79,7 +126,6 @@ static int open_interface(struct olimex_transport *tr,
|
|||
int drv;
|
||||
char drName[256];
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
printc(__FILE__": Trying to open interface %d on %s\n",
|
||||
ino, dev->filename);
|
||||
|
@ -118,45 +164,8 @@ static int open_interface(struct olimex_transport *tr,
|
|||
return -1;
|
||||
}
|
||||
|
||||
ret = usb_control_msg(tr->handle, CP210x_REQTYPE_HOST_TO_DEVICE,
|
||||
CP210X_IFC_ENABLE, 0x1, 0, NULL, 0, 300);
|
||||
#ifdef DEBUG_OLIMEX
|
||||
printc("%s: %s: Sending control message "
|
||||
"CP210x_REQTYPE_HOST_TO_DEVICE, ret = %d\n",
|
||||
__FILE__, __FUNCTION__, ret);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
pr_error(__FILE__": can't enable CP210x UART");
|
||||
usb_close(tr->handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set the baud rate to 500000 bps */
|
||||
ret = usb_control_msg(tr->handle, CP210x_REQTYPE_HOST_TO_DEVICE,
|
||||
CP210X_SET_BAUDDIV, 0x7, 0, NULL, 0, 300);
|
||||
#ifdef DEBUG_OLIMEX
|
||||
printc("%s: %s: Sending control message "
|
||||
"CP210X_SET_BAUDDIV, ret = %d\n",
|
||||
__FILE__, __FUNCTION__, ret);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
pr_error(__FILE__": can't set baud rate");
|
||||
usb_close(tr->handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set the modem control settings.
|
||||
* Set RTS, DTR and WRITE_DTR, WRITE_RTS
|
||||
*/
|
||||
ret = usb_control_msg(tr->handle, CP210x_REQTYPE_HOST_TO_DEVICE,
|
||||
CP210X_SET_MHS, 0x303, 0, NULL, 0, 300);
|
||||
#ifdef DEBUG_OLIMEX
|
||||
printc("%s: %s: Sending control message "
|
||||
"CP210X_SET_MHS, ret %d\n",
|
||||
__FILE__, __FUNCTION__, ret);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
pr_error(__FILE__": can't set modem control");
|
||||
if (dev->descriptor.idProduct == V1_PRODUCT && v1_configure(tr) < 0) {
|
||||
printc_err("Failed to configure for V1 device\n");
|
||||
usb_close(tr->handle);
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue