Skip to content

Commit 83d9c5e

Browse files
bgodavarholtmann
authored andcommitted
Bluetooth: hci_qca: Add wrapper functions for setting UART speed
In function qca_setup, we set initial and operating speeds for Qualcomm Bluetooth SoC's. This block of code is common across different Qualcomm Bluetooth SoC's. Instead of duplicating the code, created a wrapper function to set the speeds. So that future coming SoC's can use these wrapper functions to set speeds. Signed-off-by: Balakrishna Godavarthi <[email protected]> Reviewed-by: Matthias Kaehlcke <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent aadebac commit 83d9c5e

File tree

1 file changed

+70
-23
lines changed

1 file changed

+70
-23
lines changed

drivers/bluetooth/hci_qca.c

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ struct qca_data {
119119
u64 votes_off;
120120
};
121121

122+
enum qca_speed_type {
123+
QCA_INIT_SPEED = 1,
124+
QCA_OPER_SPEED
125+
};
126+
122127
struct qca_serdev {
123128
struct hci_uart serdev_hu;
124129
struct gpio_desc *bt_en;
@@ -923,6 +928,61 @@ static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
923928
hci_uart_set_baudrate(hu, speed);
924929
}
925930

931+
static unsigned int qca_get_speed(struct hci_uart *hu,
932+
enum qca_speed_type speed_type)
933+
{
934+
unsigned int speed = 0;
935+
936+
if (speed_type == QCA_INIT_SPEED) {
937+
if (hu->init_speed)
938+
speed = hu->init_speed;
939+
else if (hu->proto->init_speed)
940+
speed = hu->proto->init_speed;
941+
} else {
942+
if (hu->oper_speed)
943+
speed = hu->oper_speed;
944+
else if (hu->proto->oper_speed)
945+
speed = hu->proto->oper_speed;
946+
}
947+
948+
return speed;
949+
}
950+
951+
static int qca_check_speeds(struct hci_uart *hu)
952+
{
953+
if (!qca_get_speed(hu, QCA_INIT_SPEED) ||
954+
!qca_get_speed(hu, QCA_OPER_SPEED))
955+
return -EINVAL;
956+
957+
return 0;
958+
}
959+
960+
static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
961+
{
962+
unsigned int speed, qca_baudrate;
963+
int ret;
964+
965+
if (speed_type == QCA_INIT_SPEED) {
966+
speed = qca_get_speed(hu, QCA_INIT_SPEED);
967+
if (speed)
968+
host_set_baudrate(hu, speed);
969+
} else {
970+
speed = qca_get_speed(hu, QCA_OPER_SPEED);
971+
if (!speed)
972+
return 0;
973+
974+
qca_baudrate = qca_get_baudrate_value(speed);
975+
bt_dev_info(hu->hdev, "Set UART speed to %d", speed);
976+
ret = qca_set_baudrate(hu->hdev, qca_baudrate);
977+
if (ret)
978+
return ret;
979+
980+
host_set_baudrate(hu, speed);
981+
}
982+
983+
return 0;
984+
}
985+
926986
static int qca_setup(struct hci_uart *hu)
927987
{
928988
struct hci_dev *hdev = hu->hdev;
@@ -933,37 +993,24 @@ static int qca_setup(struct hci_uart *hu)
933993

934994
bt_dev_info(hdev, "ROME setup");
935995

996+
ret = qca_check_speeds(hu);
997+
if (ret)
998+
return ret;
999+
9361000
/* Patch downloading has to be done without IBS mode */
9371001
clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags);
9381002

9391003
/* Setup initial baudrate */
940-
speed = 0;
941-
if (hu->init_speed)
942-
speed = hu->init_speed;
943-
else if (hu->proto->init_speed)
944-
speed = hu->proto->init_speed;
945-
946-
if (speed)
947-
host_set_baudrate(hu, speed);
1004+
qca_set_speed(hu, QCA_INIT_SPEED);
9481005

9491006
/* Setup user speed if needed */
950-
speed = 0;
951-
if (hu->oper_speed)
952-
speed = hu->oper_speed;
953-
else if (hu->proto->oper_speed)
954-
speed = hu->proto->oper_speed;
955-
1007+
speed = qca_get_speed(hu, QCA_OPER_SPEED);
9561008
if (speed) {
957-
qca_baudrate = qca_get_baudrate_value(speed);
958-
959-
bt_dev_info(hdev, "Set UART speed to %d", speed);
960-
ret = qca_set_baudrate(hdev, qca_baudrate);
961-
if (ret) {
962-
bt_dev_err(hdev, "Failed to change the baud rate (%d)",
963-
ret);
1009+
ret = qca_set_speed(hu, QCA_OPER_SPEED);
1010+
if (ret)
9641011
return ret;
965-
}
966-
host_set_baudrate(hu, speed);
1012+
1013+
qca_baudrate = qca_get_baudrate_value(speed);
9671014
}
9681015

9691016
/* Get QCA version information */

0 commit comments

Comments
 (0)