diff options
author | Loic Poulain <loic.poulain@intel.com> | 2014-10-22 17:08:49 +0200 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2014-10-31 09:37:06 +0200 |
commit | beb4892e96785ba9ff429fb940126a815efd47fd (patch) | |
tree | 2100e3e0e942f21e1c678a4faf497f76ff87fdf6 /tools/hciattach_bcm43xx.c | |
parent | 7a81358e60237026f00b00f34413fb47d1711f05 (diff) | |
download | bluez-beb4892e96785ba9ff429fb940126a815efd47fd.tar.gz |
hciattach: bcm43xx: Use final baudrate to download the firmware
Speed up bcm43xx init by setting the final baudrate before firmware
download.
Diffstat (limited to 'tools/hciattach_bcm43xx.c')
-rw-r--r-- | tools/hciattach_bcm43xx.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/tools/hciattach_bcm43xx.c b/tools/hciattach_bcm43xx.c index cb4bfb931..3d36c209d 100644 --- a/tools/hciattach_bcm43xx.c +++ b/tools/hciattach_bcm43xx.c @@ -154,63 +154,71 @@ static int bcm43xx_set_bdaddr(int fd, const char *bdaddr) return 0; } -static int bcm43xx_set_speed(int fd, uint32_t speed) +static int bcm43xx_set_clock(int fd, unsigned char clock) { - unsigned char cmd[] = - { HCI_COMMAND_PKT, 0x18, 0xfc, 0x06, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 }; + unsigned char cmd[] = { HCI_COMMAND_PKT, 0x45, 0xfc, 0x01, 0x00 }; unsigned char resp[CC_MIN_SIZE]; - printf("Set Controller UART speed to %d bit/s\n", speed); + printf("Set Controller clock (%d)\n", clock); - cmd[6] = (uint8_t) (speed); - cmd[7] = (uint8_t) (speed >> 8); - cmd[8] = (uint8_t) (speed >> 16); - cmd[9] = (uint8_t) (speed >> 24); + cmd[4] = clock; tcflush(fd, TCIOFLUSH); if (write(fd, cmd, sizeof(cmd)) != sizeof(cmd)) { - fprintf(stderr, "Failed to write update baudrate command\n"); + fprintf(stderr, "Failed to write update clock command\n"); return -1; } if (read_hci_event(fd, resp, sizeof(resp)) < CC_MIN_SIZE) { - fprintf(stderr, "Failed to update baudrate, invalid HCI event\n"); + fprintf(stderr, "Failed to update clock, invalid HCI event\n"); return -1; } if (resp[4] != cmd[1] || resp[5] != cmd[2] || resp[6] != CMD_SUCCESS) { - fprintf(stderr, "Failed to update baudrate, command failure\n"); + fprintf(stderr, "Failed to update clock, command failure\n"); return -1; } return 0; } -static int bcm43xx_set_clock(int fd, unsigned char clock) +static int bcm43xx_set_speed(int fd, struct termios *ti, uint32_t speed) { - unsigned char cmd[] = { HCI_COMMAND_PKT, 0x45, 0xfc, 0x01, 0x00 }; + unsigned char cmd[] = + { HCI_COMMAND_PKT, 0x18, 0xfc, 0x06, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }; unsigned char resp[CC_MIN_SIZE]; - printf("Set Controller clock (%d)\n", clock); + if (speed > 3000000 && bcm43xx_set_clock(fd, BCM43XX_CLOCK_48)) + return -1; - cmd[4] = clock; + printf("Set Controller UART speed to %d bit/s\n", speed); + + cmd[6] = (uint8_t) (speed); + cmd[7] = (uint8_t) (speed >> 8); + cmd[8] = (uint8_t) (speed >> 16); + cmd[9] = (uint8_t) (speed >> 24); tcflush(fd, TCIOFLUSH); if (write(fd, cmd, sizeof(cmd)) != sizeof(cmd)) { - fprintf(stderr, "Failed to write update clock command\n"); + fprintf(stderr, "Failed to write update baudrate command\n"); return -1; } if (read_hci_event(fd, resp, sizeof(resp)) < CC_MIN_SIZE) { - fprintf(stderr, "Failed to update clock, invalid HCI event\n"); + fprintf(stderr, "Failed to update baudrate, invalid HCI event\n"); return -1; } if (resp[4] != cmd[1] || resp[5] != cmd[2] || resp[6] != CMD_SUCCESS) { - fprintf(stderr, "Failed to update clock, command failure\n"); + fprintf(stderr, "Failed to update baudrate, command failure\n"); + return -1; + } + + if (set_speed(fd, ti, speed) < 0) { + perror("Can't set host baud rate"); return -1; } @@ -343,7 +351,8 @@ static int bcm43xx_locate_patch(const char *dir_name, return ret; } -int bcm43xx_init(int fd, int speed, struct termios *ti, const char *bdaddr) +int bcm43xx_init(int fd, int def_speed, int speed, struct termios *ti, + const char *bdaddr) { char chip_name[20]; char fw_path[PATH_MAX]; @@ -359,9 +368,18 @@ int bcm43xx_init(int fd, int speed, struct termios *ti, const char *bdaddr) if (bcm43xx_locate_patch(FIRMWARE_DIR, chip_name, fw_path)) { fprintf(stderr, "Patch not found, continue anyway\n"); } else { + if (bcm43xx_set_speed(fd, ti, speed)) + return -1; + if (bcm43xx_load_firmware(fd, fw_path)) return -1; + /* Controller speed has been reset to def speed */ + if (set_speed(fd, ti, def_speed) < 0) { + perror("Can't set host baud rate"); + return -1; + } + if (bcm43xx_reset(fd)) return -1; } @@ -369,10 +387,7 @@ int bcm43xx_init(int fd, int speed, struct termios *ti, const char *bdaddr) if (bdaddr) bcm43xx_set_bdaddr(fd, bdaddr); - if (speed > 3000000 && bcm43xx_set_clock(fd, BCM43XX_CLOCK_48)) - return -1; - - if (bcm43xx_set_speed(fd, speed)) + if (bcm43xx_set_speed(fd, ti, speed)) return -1; return 0; |