Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 1 | /* 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 */ |
| 17 | struct 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 | |
| 26 | struct 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 */ |
| 38 | int btfm_slim_chrk_hw_init(struct btfmslim *btfmslim) |
| 39 | { |
| 40 | int ret = 0; |
| 41 | uint8_t reg_val; |
Rupesh Tatiya | 795ac6e | 2017-03-02 15:33:47 +0530 | [diff] [blame] | 42 | uint16_t reg; |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 43 | |
| 44 | BTFMSLIM_DBG(""); |
| 45 | |
| 46 | if (!btfmslim) |
| 47 | return -EINVAL; |
| 48 | |
| 49 | /* Get SB_SLAVE_HW_REV_MSB value*/ |
Rupesh Tatiya | 795ac6e | 2017-03-02 15:33:47 +0530 | [diff] [blame] | 50 | reg = CHRK_SB_SLAVE_HW_REV_MSB; |
| 51 | ret = btfm_slim_read(btfmslim, reg, 1, ®_val, IFD); |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 52 | if (ret) { |
Rupesh Tatiya | 795ac6e | 2017-03-02 15:33:47 +0530 | [diff] [blame] | 53 | BTFMSLIM_ERR("failed to read (%d) reg 0x%x", ret, reg); |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 54 | 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 Tatiya | 795ac6e | 2017-03-02 15:33:47 +0530 | [diff] [blame] | 60 | reg = CHRK_SB_SLAVE_HW_REV_LSB; |
| 61 | ret = btfm_slim_read(btfmslim, reg, 1, ®_val, IFD); |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 62 | if (ret) { |
Rupesh Tatiya | 795ac6e | 2017-03-02 15:33:47 +0530 | [diff] [blame] | 63 | BTFMSLIM_ERR("failed to read (%d) reg 0x%x", ret, reg); |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 64 | goto error; |
| 65 | } |
| 66 | BTFMSLIM_DBG("Step Rev: 0x%x", reg_val); |
| 67 | |
| 68 | error: |
| 69 | return ret; |
| 70 | } |
| 71 | |
Rupesh Tatiya | 6fdd3f0 | 2017-04-18 19:25:11 +0530 | [diff] [blame] | 72 | static 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 Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 80 | |
| 81 | int btfm_slim_chrk_enable_port(struct btfmslim *btfmslim, uint8_t port_num, |
| 82 | uint8_t rxport, uint8_t enable) |
| 83 | { |
| 84 | int ret = 0; |
| 85 | uint8_t reg_val = 0; |
Satish Kodishala | 75fa666 | 2017-05-01 19:17:06 +0530 | [diff] [blame] | 86 | uint8_t port_bit = 0; |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 87 | uint16_t reg; |
| 88 | |
Rupesh Tatiya | 3815c79 | 2017-02-17 12:58:01 +0530 | [diff] [blame] | 89 | BTFMSLIM_DBG("port(%d) enable(%d)", port_num, enable); |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 90 | if (rxport) { |
Satish Kodishala | 93194f8 | 2017-05-18 20:11:20 +0530 | [diff] [blame] | 91 | if (enable && btfmslim->sample_rate == 48000) { |
| 92 | /* For A2DP Rx */ |
Satish Kodishala | 75fa666 | 2017-05-01 19:17:06 +0530 | [diff] [blame] | 93 | reg_val = 0x1; |
| 94 | port_bit = port_num - 0x10; |
| 95 | reg = CHRK_SB_PGD_RX_PORTn_MULTI_CHNL_0(port_bit); |
Satish Kodishala | 93194f8 | 2017-05-18 20:11:20 +0530 | [diff] [blame] | 96 | BTFMSLIM_DBG("writing reg_val (%d) to reg(%x) for A2DP", |
Satish Kodishala | 75fa666 | 2017-05-01 19:17:06 +0530 | [diff] [blame] | 97 | reg_val, reg); |
| 98 | ret = btfm_slim_write(btfmslim, reg, 1, ®_val, IFD); |
| 99 | if (ret) { |
| 100 | BTFMSLIM_ERR("failed to write (%d) reg 0x%x", |
| 101 | ret, reg); |
| 102 | goto error; |
| 103 | } |
| 104 | } |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 105 | /* Port enable */ |
| 106 | reg = CHRK_SB_PGD_PORT_RX_CFGN(port_num - 0x10); |
Rupesh Tatiya | 795ac6e | 2017-03-02 15:33:47 +0530 | [diff] [blame] | 107 | goto enable_disable_rxport; |
| 108 | } |
Rupesh Tatiya | 795ac6e | 2017-03-02 15:33:47 +0530 | [diff] [blame] | 109 | if (!enable) |
| 110 | goto enable_disable_txport; |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 111 | |
Satish Kodishala | 75fa666 | 2017-05-01 19:17:06 +0530 | [diff] [blame] | 112 | /* txport */ |
| 113 | /* Multiple Channel Setting */ |
Rupesh Tatiya | 6fdd3f0 | 2017-04-18 19:25:11 +0530 | [diff] [blame] | 114 | if (is_fm_port(port_num)) { |
Rupesh Tatiya | 795ac6e | 2017-03-02 15:33:47 +0530 | [diff] [blame] | 115 | reg_val = (0x1 << CHRK_SB_PGD_PORT_TX1_FM) | |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 116 | (0x1 << CHRK_SB_PGD_PORT_TX2_FM); |
Rupesh Tatiya | 795ac6e | 2017-03-02 15:33:47 +0530 | [diff] [blame] | 117 | reg = CHRK_SB_PGD_TX_PORTn_MULTI_CHNL_0(port_num); |
| 118 | ret = btfm_slim_write(btfmslim, reg, 1, ®_val, IFD); |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 119 | if (ret) { |
Rupesh Tatiya | 795ac6e | 2017-03-02 15:33:47 +0530 | [diff] [blame] | 120 | BTFMSLIM_ERR("failed to write (%d) reg 0x%x", ret, reg); |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 121 | goto error; |
| 122 | } |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 123 | } |
| 124 | |
Rupesh Tatiya | 795ac6e | 2017-03-02 15:33:47 +0530 | [diff] [blame] | 125 | /* Enable Tx port hw auto recovery for underrun or overrun error */ |
| 126 | reg_val = (CHRK_ENABLE_OVERRUN_AUTO_RECOVERY | |
| 127 | CHRK_ENABLE_UNDERRUN_AUTO_RECOVERY); |
| 128 | reg = CHRK_SB_PGD_PORT_TX_OR_UR_CFGN(port_num); |
| 129 | ret = btfm_slim_write(btfmslim, reg, 1, ®_val, IFD); |
| 130 | if (ret) { |
| 131 | BTFMSLIM_ERR("failed to write (%d) reg 0x%x", ret, reg); |
| 132 | goto error; |
| 133 | } |
| 134 | |
| 135 | enable_disable_txport: |
| 136 | /* Port enable */ |
| 137 | reg = CHRK_SB_PGD_PORT_TX_CFGN(port_num); |
| 138 | |
| 139 | enable_disable_rxport: |
Rupesh Tatiya | 6fdd3f0 | 2017-04-18 19:25:11 +0530 | [diff] [blame] | 140 | if (enable) { |
| 141 | if (is_fm_port(port_num)) |
| 142 | reg_val = CHRK_SB_PGD_PORT_ENABLE | |
| 143 | CHRK_SB_PGD_PORT_WM_L3; |
| 144 | else |
| 145 | reg_val = CHRK_SB_PGD_PORT_ENABLE | |
| 146 | CHRK_SB_PGD_PORT_WM_LB; |
| 147 | } else |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 148 | reg_val = CHRK_SB_PGD_PORT_DISABLE; |
| 149 | |
| 150 | ret = btfm_slim_write(btfmslim, reg, 1, ®_val, IFD); |
| 151 | if (ret) |
Rupesh Tatiya | 795ac6e | 2017-03-02 15:33:47 +0530 | [diff] [blame] | 152 | BTFMSLIM_ERR("failed to write (%d) reg 0x%x", ret, reg); |
Mahesh Kumar Sharma | 41a4d38 | 2017-01-17 17:00:51 -0800 | [diff] [blame] | 153 | |
| 154 | error: |
| 155 | return ret; |
| 156 | } |