blob: 2dbba830d39de0df4fd8b7b4702e878846e29864 [file] [log] [blame]
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -08001/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12#include <linux/slimbus/slimbus.h>
13#include <btfm_slim.h>
14#include <btfm_slim_wcn3990.h>
15
16/* WCN3990 Port assignment */
17struct btfmslim_ch wcn3990_rxport[] = {
18 {.id = BTFM_BT_SCO_A2DP_SLIM_RX, .name = "SCO_A2P_Rx",
19 .port = CHRK_SB_PGD_PORT_RX_SCO},
20 {.id = BTFM_BT_SPLIT_A2DP_SLIM_RX, .name = "A2P_Rx",
21 .port = CHRK_SB_PGD_PORT_RX_A2P},
22 {.id = BTFM_SLIM_NUM_CODEC_DAIS, .name = "",
23 .port = BTFM_SLIM_PGD_PORT_LAST},
24};
25
26struct btfmslim_ch wcn3990_txport[] = {
27 {.id = BTFM_FM_SLIM_TX, .name = "FM_Tx1",
28 .port = CHRK_SB_PGD_PORT_TX1_FM},
29 {.id = BTFM_FM_SLIM_TX, .name = "FM_Tx2",
30 .port = CHRK_SB_PGD_PORT_TX2_FM},
31 {.id = BTFM_BT_SCO_SLIM_TX, .name = "SCO_Tx",
32 .port = CHRK_SB_PGD_PORT_TX_SCO},
33 {.id = BTFM_SLIM_NUM_CODEC_DAIS, .name = "",
34 .port = BTFM_SLIM_PGD_PORT_LAST},
35};
36
37/* Function description */
38int btfm_slim_chrk_hw_init(struct btfmslim *btfmslim)
39{
40 int ret = 0;
41 uint8_t reg_val;
Rupesh Tatiya795ac6e2017-03-02 15:33:47 +053042 uint16_t reg;
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -080043
44 BTFMSLIM_DBG("");
45
46 if (!btfmslim)
47 return -EINVAL;
48
49 /* Get SB_SLAVE_HW_REV_MSB value*/
Rupesh Tatiya795ac6e2017-03-02 15:33:47 +053050 reg = CHRK_SB_SLAVE_HW_REV_MSB;
51 ret = btfm_slim_read(btfmslim, reg, 1, &reg_val, IFD);
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -080052 if (ret) {
Rupesh Tatiya795ac6e2017-03-02 15:33:47 +053053 BTFMSLIM_ERR("failed to read (%d) reg 0x%x", ret, reg);
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -080054 goto error;
55 }
56 BTFMSLIM_DBG("Major Rev: 0x%x, Minor Rev: 0x%x",
57 (reg_val & 0xF0) >> 4, (reg_val & 0x0F));
58
59 /* Get SB_SLAVE_HW_REV_LSB value*/
Rupesh Tatiya795ac6e2017-03-02 15:33:47 +053060 reg = CHRK_SB_SLAVE_HW_REV_LSB;
61 ret = btfm_slim_read(btfmslim, reg, 1, &reg_val, IFD);
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -080062 if (ret) {
Rupesh Tatiya795ac6e2017-03-02 15:33:47 +053063 BTFMSLIM_ERR("failed to read (%d) reg 0x%x", ret, reg);
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -080064 goto error;
65 }
66 BTFMSLIM_DBG("Step Rev: 0x%x", reg_val);
67
68error:
69 return ret;
70}
71
Rupesh Tatiya6fdd3f02017-04-18 19:25:11 +053072static inline int is_fm_port(uint8_t port_num)
73{
74 if (port_num == CHRK_SB_PGD_PORT_TX1_FM ||
75 port_num == CHRK_SB_PGD_PORT_TX2_FM)
76 return 1;
77 else
78 return 0;
79}
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -080080
81int btfm_slim_chrk_enable_port(struct btfmslim *btfmslim, uint8_t port_num,
82 uint8_t rxport, uint8_t enable)
83{
84 int ret = 0;
Rupesh Tatiyafc057b52017-06-20 15:06:29 +053085 uint8_t reg_val = 0, en;
Sungjun Parkea258e42017-10-18 19:08:25 -070086 uint8_t rxport_num = 0;
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -080087 uint16_t reg;
88
Rupesh Tatiya3815c792017-02-17 12:58:01 +053089 BTFMSLIM_DBG("port(%d) enable(%d)", port_num, enable);
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -080090 if (rxport) {
Satish Kodishala5095e402017-06-14 17:44:16 +053091 if (enable) {
92 /* For SCO Rx, A2DP Rx */
Sungjun Parkea258e42017-10-18 19:08:25 -070093 if (port_num < 24) {
94 rxport_num = port_num - 16;
95 reg_val = 0x01 << rxport_num;
96 reg = CHRK_SB_PGD_RX_PORTn_MULTI_CHNL_0(
97 rxport_num);
98 } else {
99 rxport_num = port_num - 24;
100 reg_val = 0x01 << rxport_num;
101 reg = CHRK_SB_PGD_RX_PORTn_MULTI_CHNL_1(
102 rxport_num);
103 }
104
Satish Kodishala5095e402017-06-14 17:44:16 +0530105 BTFMSLIM_DBG("writing reg_val (%d) to reg(%x)",
Sungjun Parkea258e42017-10-18 19:08:25 -0700106 reg_val, reg);
Satish Kodishala75fa6662017-05-01 19:17:06 +0530107 ret = btfm_slim_write(btfmslim, reg, 1, &reg_val, IFD);
108 if (ret) {
109 BTFMSLIM_ERR("failed to write (%d) reg 0x%x",
Sungjun Parkea258e42017-10-18 19:08:25 -0700110 ret, reg);
Satish Kodishala75fa6662017-05-01 19:17:06 +0530111 goto error;
112 }
113 }
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -0800114 /* Port enable */
115 reg = CHRK_SB_PGD_PORT_RX_CFGN(port_num - 0x10);
Rupesh Tatiya795ac6e2017-03-02 15:33:47 +0530116 goto enable_disable_rxport;
117 }
Rupesh Tatiya795ac6e2017-03-02 15:33:47 +0530118 if (!enable)
119 goto enable_disable_txport;
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -0800120
Satish Kodishala75fa6662017-05-01 19:17:06 +0530121 /* txport */
122 /* Multiple Channel Setting */
Rupesh Tatiya6fdd3f02017-04-18 19:25:11 +0530123 if (is_fm_port(port_num)) {
Rupesh Tatiya795ac6e2017-03-02 15:33:47 +0530124 reg_val = (0x1 << CHRK_SB_PGD_PORT_TX1_FM) |
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -0800125 (0x1 << CHRK_SB_PGD_PORT_TX2_FM);
Rupesh Tatiya795ac6e2017-03-02 15:33:47 +0530126 reg = CHRK_SB_PGD_TX_PORTn_MULTI_CHNL_0(port_num);
127 ret = btfm_slim_write(btfmslim, reg, 1, &reg_val, IFD);
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -0800128 if (ret) {
Rupesh Tatiya795ac6e2017-03-02 15:33:47 +0530129 BTFMSLIM_ERR("failed to write (%d) reg 0x%x", ret, reg);
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -0800130 goto error;
131 }
Satish Kodishalad9ee8612017-08-18 09:09:44 +0530132 } else if (port_num == CHRK_SB_PGD_PORT_TX_SCO) {
133 /* SCO Tx */
134 reg_val = 0x1 << CHRK_SB_PGD_PORT_TX_SCO;
135 reg = CHRK_SB_PGD_TX_PORTn_MULTI_CHNL_0(port_num);
136 BTFMSLIM_DBG("writing reg_val (%d) to reg(%x)",
137 reg_val, reg);
138 ret = btfm_slim_write(btfmslim, reg, 1, &reg_val, IFD);
139 if (ret) {
140 BTFMSLIM_ERR("failed to write (%d) reg 0x%x",
141 ret, reg);
142 goto error;
143 }
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -0800144 }
145
Rupesh Tatiya795ac6e2017-03-02 15:33:47 +0530146 /* Enable Tx port hw auto recovery for underrun or overrun error */
147 reg_val = (CHRK_ENABLE_OVERRUN_AUTO_RECOVERY |
148 CHRK_ENABLE_UNDERRUN_AUTO_RECOVERY);
149 reg = CHRK_SB_PGD_PORT_TX_OR_UR_CFGN(port_num);
150 ret = btfm_slim_write(btfmslim, reg, 1, &reg_val, IFD);
151 if (ret) {
152 BTFMSLIM_ERR("failed to write (%d) reg 0x%x", ret, reg);
153 goto error;
154 }
155
156enable_disable_txport:
157 /* Port enable */
158 reg = CHRK_SB_PGD_PORT_TX_CFGN(port_num);
159
160enable_disable_rxport:
Rupesh Tatiyafc057b52017-06-20 15:06:29 +0530161 if (enable)
162 en = CHRK_SB_PGD_PORT_ENABLE;
163 else
164 en = CHRK_SB_PGD_PORT_DISABLE;
165
166 if (is_fm_port(port_num))
167 reg_val = en | CHRK_SB_PGD_PORT_WM_L8;
Satish Kodishalad9ee8612017-08-18 09:09:44 +0530168 else if (port_num == CHRK_SB_PGD_PORT_TX_SCO)
169 reg_val = enable ? en | CHRK_SB_PGD_PORT_WM_L1 : en;
Rupesh Tatiyafc057b52017-06-20 15:06:29 +0530170 else
171 reg_val = enable ? en | CHRK_SB_PGD_PORT_WM_LB : en;
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -0800172
Satish Kodishalad9ee8612017-08-18 09:09:44 +0530173 if (enable && port_num == CHRK_SB_PGD_PORT_TX_SCO)
174 BTFMSLIM_INFO("programming SCO Tx with reg_val %d to reg 0x%x",
175 reg_val, reg);
176
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -0800177 ret = btfm_slim_write(btfmslim, reg, 1, &reg_val, IFD);
178 if (ret)
Rupesh Tatiya795ac6e2017-03-02 15:33:47 +0530179 BTFMSLIM_ERR("failed to write (%d) reg 0x%x", ret, reg);
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -0800180
181error:
182 return ret;
183}