aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBalakrishna Godavarthi <bgodavar@codeaurora.org>2018-08-03 08:16:29 -0400
committerMarcel Holtmann <marcel@holtmann.org>2018-08-03 08:44:07 -0400
commit83d9c5e56687a75cd75e537f97fb35009e9ba232 (patch)
treef6e722e95e93af52147486e9262e4072316fb5b5
parentaadebac4639d84ee51a12f2a1706fea1e4760b81 (diff)
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 <bgodavar@codeaurora.org> Reviewed-by: Matthias Kaehlcke <mka@chromium.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--drivers/bluetooth/hci_qca.c93
1 files changed, 70 insertions, 23 deletions
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index 6bc8cfb982a9..41278c5852e4 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -119,6 +119,11 @@ struct qca_data {
119 u64 votes_off; 119 u64 votes_off;
120}; 120};
121 121
122enum qca_speed_type {
123 QCA_INIT_SPEED = 1,
124 QCA_OPER_SPEED
125};
126
122struct qca_serdev { 127struct qca_serdev {
123 struct hci_uart serdev_hu; 128 struct hci_uart serdev_hu;
124 struct gpio_desc *bt_en; 129 struct gpio_desc *bt_en;
@@ -923,6 +928,61 @@ static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
923 hci_uart_set_baudrate(hu, speed); 928 hci_uart_set_baudrate(hu, speed);
924} 929}
925 930
931static 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
951static 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
960static 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
926static int qca_setup(struct hci_uart *hu) 986static int qca_setup(struct hci_uart *hu)
927{ 987{
928 struct hci_dev *hdev = hu->hdev; 988 struct hci_dev *hdev = hu->hdev;
@@ -933,37 +993,24 @@ static int qca_setup(struct hci_uart *hu)
933 993
934 bt_dev_info(hdev, "ROME setup"); 994 bt_dev_info(hdev, "ROME setup");
935 995
996 ret = qca_check_speeds(hu);
997 if (ret)
998 return ret;
999
936 /* Patch downloading has to be done without IBS mode */ 1000 /* Patch downloading has to be done without IBS mode */
937 clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags); 1001 clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags);
938 1002
939 /* Setup initial baudrate */ 1003 /* Setup initial baudrate */
940 speed = 0; 1004 qca_set_speed(hu, QCA_INIT_SPEED);
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);
948 1005
949 /* Setup user speed if needed */ 1006 /* Setup user speed if needed */
950 speed = 0; 1007 speed = qca_get_speed(hu, QCA_OPER_SPEED);
951 if (hu->oper_speed)
952 speed = hu->oper_speed;
953 else if (hu->proto->oper_speed)
954 speed = hu->proto->oper_speed;
955
956 if (speed) { 1008 if (speed) {
957 qca_baudrate = qca_get_baudrate_value(speed); 1009 ret = qca_set_speed(hu, QCA_OPER_SPEED);
958 1010 if (ret)
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);
964 return ret; 1011 return ret;
965 } 1012
966 host_set_baudrate(hu, speed); 1013 qca_baudrate = qca_get_baudrate_value(speed);
967 } 1014 }
968 1015
969 /* Get QCA version information */ 1016 /* Get QCA version information */