Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. 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/slab.h> |
| 13 | #include <linux/mutex.h> |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 14 | #include <linux/mfd/wcd9xxx/wcd9xxx-slimslave.h> |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 15 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 16 | struct wcd9xxx_slim_sch_rx { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 17 | u32 sph; |
| 18 | u32 ch_num; |
| 19 | u16 ch_h; |
| 20 | u16 grph; |
| 21 | }; |
| 22 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 23 | struct wcd9xxx_slim_sch_tx { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 24 | u32 sph; |
| 25 | u32 ch_num; |
| 26 | u16 ch_h; |
| 27 | u16 grph; |
| 28 | }; |
| 29 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 30 | struct wcd9xxx_slim_sch { |
| 31 | struct wcd9xxx_slim_sch_rx rx[SLIM_MAX_RX_PORTS]; |
| 32 | struct wcd9xxx_slim_sch_tx tx[SLIM_MAX_TX_PORTS]; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 33 | }; |
| 34 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 35 | static struct wcd9xxx_slim_sch sh_ch; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 36 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 37 | static int wcd9xxx_alloc_slim_sh_ch_rx(struct wcd9xxx *wcd9xxx, |
| 38 | u8 wcd9xxx_pgd_la); |
| 39 | static int wcd9xxx_alloc_slim_sh_ch_tx(struct wcd9xxx *wcd9xxx, |
| 40 | u8 wcd9xxx_pgd_la); |
| 41 | static int wcd9xxx_dealloc_slim_sh_ch_rx(struct wcd9xxx *wcd9xxx); |
| 42 | static int wcd9xxx_dealloc_slim_sh_ch_tx(struct wcd9xxx *wcd9xxx); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 43 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 44 | int wcd9xxx_init_slimslave(struct wcd9xxx *wcd9xxx, u8 wcd9xxx_pgd_la) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 45 | { |
| 46 | int ret = 0; |
| 47 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 48 | ret = wcd9xxx_alloc_slim_sh_ch_rx(wcd9xxx, wcd9xxx_pgd_la); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 49 | if (ret) { |
| 50 | pr_err("%s: Failed to alloc rx slimbus shared channels\n", |
| 51 | __func__); |
| 52 | goto rx_err; |
| 53 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 54 | ret = wcd9xxx_alloc_slim_sh_ch_tx(wcd9xxx, wcd9xxx_pgd_la); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 55 | if (ret) { |
| 56 | pr_err("%s: Failed to alloc tx slimbus shared channels\n", |
| 57 | __func__); |
| 58 | goto tx_err; |
| 59 | } |
| 60 | return 0; |
| 61 | tx_err: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 62 | wcd9xxx_dealloc_slim_sh_ch_rx(wcd9xxx); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 63 | rx_err: |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 68 | int wcd9xxx_deinit_slimslave(struct wcd9xxx *wcd9xxx) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 69 | { |
| 70 | int ret = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 71 | ret = wcd9xxx_dealloc_slim_sh_ch_rx(wcd9xxx); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 72 | if (ret < 0) { |
| 73 | pr_err("%s: fail to dealloc rx slim ports\n", __func__); |
| 74 | goto err; |
| 75 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 76 | ret = wcd9xxx_dealloc_slim_sh_ch_tx(wcd9xxx); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 77 | if (ret < 0) { |
| 78 | pr_err("%s: fail to dealloc tx slim ports\n", __func__); |
| 79 | goto err; |
| 80 | } |
| 81 | err: |
| 82 | return ret; |
| 83 | } |
| 84 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 85 | int wcd9xxx_get_channel(struct wcd9xxx *wcd9xxx, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 86 | unsigned int *rx_ch, |
| 87 | unsigned int *tx_ch) |
| 88 | { |
| 89 | int ch_idx = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 90 | struct wcd9xxx_slim_sch_rx *rx = sh_ch.rx; |
| 91 | struct wcd9xxx_slim_sch_tx *tx = sh_ch.tx; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 92 | |
| 93 | for (ch_idx = 0; ch_idx < SLIM_MAX_RX_PORTS; ch_idx++) |
| 94 | rx_ch[ch_idx] = rx[ch_idx].ch_num; |
| 95 | for (ch_idx = 0; ch_idx < SLIM_MAX_TX_PORTS; ch_idx++) |
| 96 | tx_ch[ch_idx] = tx[ch_idx].ch_num; |
| 97 | return 0; |
| 98 | } |
| 99 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 100 | static int wcd9xxx_alloc_slim_sh_ch_rx(struct wcd9xxx *wcd9xxx, |
| 101 | u8 wcd9xxx_pgd_la) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 102 | { |
| 103 | int ret = 0; |
| 104 | u8 ch_idx ; |
| 105 | u16 slave_port_id = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 106 | struct wcd9xxx_slim_sch_rx *rx = sh_ch.rx; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 107 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 108 | /* |
| 109 | * DSP requires channel number to be between 128 and 255. |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 110 | */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 111 | pr_debug("%s: pgd_la[%d]\n", __func__, wcd9xxx_pgd_la); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 112 | for (ch_idx = 0; ch_idx < SLIM_MAX_RX_PORTS; ch_idx++) { |
| 113 | slave_port_id = (ch_idx + 1 + |
| 114 | SB_PGD_OFFSET_OF_RX_SLAVE_DEV_PORTS); |
| 115 | rx[ch_idx].ch_num = slave_port_id + BASE_CH_NUM; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 116 | ret = slim_get_slaveport(wcd9xxx_pgd_la, slave_port_id, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 117 | &rx[ch_idx].sph, SLIM_SINK); |
| 118 | if (ret < 0) { |
| 119 | pr_err("%s: slave port failure id[%d] ret[%d]\n", |
| 120 | __func__, slave_port_id, ret); |
| 121 | goto err; |
| 122 | } |
| 123 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 124 | ret = slim_query_ch(wcd9xxx->slim, rx[ch_idx].ch_num, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 125 | &rx[ch_idx].ch_h); |
| 126 | if (ret < 0) { |
| 127 | pr_err("%s: slim_query_ch failed ch-num[%d] ret[%d]\n", |
| 128 | __func__, rx[ch_idx].ch_num, ret); |
| 129 | goto err; |
| 130 | } |
| 131 | } |
| 132 | err: |
| 133 | return ret; |
| 134 | } |
| 135 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 136 | static int wcd9xxx_alloc_slim_sh_ch_tx(struct wcd9xxx *wcd9xxx, |
| 137 | u8 wcd9xxx_pgd_la) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 138 | { |
| 139 | int ret = 0; |
| 140 | u8 ch_idx ; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 141 | struct wcd9xxx_slim_sch_tx *tx = sh_ch.tx; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 142 | u16 slave_port_id = 0; |
| 143 | |
Swaminathan Sathappan | 362a17c | 2012-04-25 18:09:46 -0700 | [diff] [blame^] | 144 | pr_debug("%s: pgd_la[%d]\n", __func__, wcd9xxx_pgd_la); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 145 | /* DSP requires channel number to be between 128 and 255. For RX port |
| 146 | * use channel numbers from 138 to 144, for TX port |
| 147 | * use channel numbers from 128 to 137 |
| 148 | */ |
| 149 | for (ch_idx = 0; ch_idx < SLIM_MAX_TX_PORTS; ch_idx++) { |
| 150 | slave_port_id = ch_idx; |
| 151 | tx[ch_idx].ch_num = slave_port_id + BASE_CH_NUM; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 152 | ret = slim_get_slaveport(wcd9xxx_pgd_la, slave_port_id, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 153 | &tx[ch_idx].sph, SLIM_SRC); |
| 154 | if (ret < 0) { |
| 155 | pr_err("%s: slave port failure id[%d] ret[%d]\n", |
| 156 | __func__, slave_port_id, ret); |
| 157 | goto err; |
| 158 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 159 | ret = slim_query_ch(wcd9xxx->slim, tx[ch_idx].ch_num, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 160 | &tx[ch_idx].ch_h); |
| 161 | if (ret < 0) { |
| 162 | pr_err("%s: slim_query_ch failed ch-num[%d] ret[%d]\n", |
| 163 | __func__, tx[ch_idx].ch_num, ret); |
| 164 | goto err; |
| 165 | } |
| 166 | } |
| 167 | err: |
| 168 | return ret; |
| 169 | } |
| 170 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 171 | static int wcd9xxx_dealloc_slim_sh_ch_rx(struct wcd9xxx *wcd9xxx) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 172 | { |
| 173 | int idx = 0; |
| 174 | int ret = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 175 | struct wcd9xxx_slim_sch_rx *rx = sh_ch.rx; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 176 | /* slim_dealloc_ch */ |
| 177 | for (idx = 0; idx < SLIM_MAX_RX_PORTS; idx++) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 178 | ret = slim_dealloc_ch(wcd9xxx->slim, rx[idx].ch_h); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 179 | if (ret < 0) { |
| 180 | pr_err("%s: slim_dealloc_ch fail ret[%d] ch_h[%d]\n", |
| 181 | __func__, ret, rx[idx].ch_h); |
| 182 | } |
| 183 | } |
| 184 | memset(sh_ch.rx, 0, sizeof(sh_ch.rx)); |
| 185 | return ret; |
| 186 | } |
| 187 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 188 | static int wcd9xxx_dealloc_slim_sh_ch_tx(struct wcd9xxx *wcd9xxx) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 189 | { |
| 190 | int idx = 0; |
| 191 | int ret = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 192 | struct wcd9xxx_slim_sch_tx *tx = sh_ch.tx; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 193 | /* slim_dealloc_ch */ |
| 194 | for (idx = 0; idx < SLIM_MAX_TX_PORTS; idx++) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 195 | ret = slim_dealloc_ch(wcd9xxx->slim, tx[idx].ch_h); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 196 | if (ret < 0) { |
| 197 | pr_err("%s: slim_dealloc_ch fail ret[%d] ch_h[%d]\n", |
| 198 | __func__, ret, tx[idx].ch_h); |
| 199 | } |
| 200 | } |
| 201 | memset(sh_ch.tx, 0, sizeof(sh_ch.tx)); |
| 202 | return ret; |
| 203 | } |
| 204 | |
| 205 | /* Enable slimbus slave device for RX path */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 206 | int wcd9xxx_cfg_slim_sch_rx(struct wcd9xxx *wcd9xxx, unsigned int *ch_num, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 207 | unsigned int ch_cnt, unsigned int rate) |
| 208 | { |
| 209 | u8 i = 0; |
| 210 | u16 grph; |
| 211 | u32 sph[SLIM_MAX_RX_PORTS] = {0}; |
| 212 | u16 ch_h[SLIM_MAX_RX_PORTS] = {0}; |
| 213 | u16 slave_port_id; |
| 214 | u8 payload_rx = 0, wm_payload = 0; |
| 215 | int ret, idx = 0; |
| 216 | unsigned short multi_chan_cfg_reg_addr; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 217 | struct wcd9xxx_slim_sch_rx *rx = sh_ch.rx; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 218 | struct slim_ch prop; |
| 219 | |
| 220 | /* Configure slave interface device */ |
Swaminathan Sathappan | 362a17c | 2012-04-25 18:09:46 -0700 | [diff] [blame^] | 221 | pr_debug("%s: ch_cnt[%d] rate=%d\n", __func__, ch_cnt, rate); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 222 | |
| 223 | for (i = 0; i < ch_cnt; i++) { |
| 224 | idx = (ch_num[i] - BASE_CH_NUM - |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 225 | SB_PGD_OFFSET_OF_RX_SLAVE_DEV_PORTS - 1); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 226 | ch_h[i] = rx[idx].ch_h; |
| 227 | sph[i] = rx[idx].sph; |
| 228 | slave_port_id = idx + 1; |
| 229 | if ((slave_port_id > SB_PGD_MAX_NUMBER_OF_RX_SLAVE_DEV_PORTS) || |
| 230 | (slave_port_id == 0)) { |
| 231 | pr_err("Slimbus: invalid slave port id: %d", |
| 232 | slave_port_id); |
| 233 | ret = -EINVAL; |
| 234 | goto err; |
| 235 | } |
| 236 | slave_port_id += SB_PGD_OFFSET_OF_RX_SLAVE_DEV_PORTS; |
| 237 | /* look for the valid port range and chose the |
| 238 | * payload accordingly |
| 239 | */ |
| 240 | if ((slave_port_id > |
| 241 | SB_PGD_TX_PORT_MULTI_CHANNEL_1_END_PORT_ID) && |
Helen Zeng | 4a7abdb | 2012-02-21 18:20:46 -0800 | [diff] [blame] | 242 | (slave_port_id <= |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 243 | SB_PGD_RX_PORT_MULTI_CHANNEL_0_END_PORT_ID)) { |
| 244 | payload_rx = payload_rx | |
| 245 | (1 << |
| 246 | (slave_port_id - |
| 247 | SB_PGD_RX_PORT_MULTI_CHANNEL_0_START_PORT_ID)); |
| 248 | } else { |
| 249 | ret = -EINVAL; |
| 250 | goto err; |
| 251 | } |
| 252 | multi_chan_cfg_reg_addr = |
| 253 | SB_PGD_RX_PORT_MULTI_CHANNEL_0(slave_port_id); |
| 254 | /* write to interface device */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 255 | ret = wcd9xxx_interface_reg_write(wcd9xxx, |
| 256 | multi_chan_cfg_reg_addr, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 257 | payload_rx); |
| 258 | if (ret < 0) { |
| 259 | pr_err("%s:Intf-dev fail reg[%d] payload[%d] ret[%d]\n", |
| 260 | __func__, |
| 261 | multi_chan_cfg_reg_addr, |
| 262 | payload_rx, ret); |
| 263 | goto err; |
| 264 | } |
| 265 | /* configure the slave port for water mark and enable*/ |
| 266 | wm_payload = (SLAVE_PORT_WATER_MARK_VALUE << |
| 267 | SLAVE_PORT_WATER_MARK_SHIFT) + |
| 268 | SLAVE_PORT_ENABLE; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 269 | ret = wcd9xxx_interface_reg_write(wcd9xxx, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 270 | SB_PGD_PORT_CFG_BYTE_ADDR(slave_port_id), |
| 271 | wm_payload); |
| 272 | if (ret < 0) { |
| 273 | pr_err("%s:watermark set failure for port[%d] ret[%d]", |
| 274 | __func__, slave_port_id, ret); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | /* slim_define_ch api */ |
| 279 | prop.prot = SLIM_AUTO_ISO; |
| 280 | prop.baser = SLIM_RATE_4000HZ; |
| 281 | prop.dataf = SLIM_CH_DATAF_NOT_DEFINED; |
| 282 | prop.auxf = SLIM_CH_AUXF_NOT_APPLICABLE; |
| 283 | prop.ratem = (rate/4000); |
| 284 | prop.sampleszbits = 16; |
| 285 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 286 | ret = slim_define_ch(wcd9xxx->slim, &prop, ch_h, ch_cnt, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 287 | true, &grph); |
| 288 | if (ret < 0) { |
| 289 | pr_err("%s: slim_define_ch failed ret[%d]\n", |
| 290 | __func__, ret); |
| 291 | goto err; |
| 292 | } |
| 293 | for (i = 0; i < ch_cnt; i++) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 294 | ret = slim_connect_sink(wcd9xxx->slim, &sph[i], |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 295 | 1, ch_h[i]); |
| 296 | if (ret < 0) { |
| 297 | pr_err("%s: slim_connect_sink failed ret[%d]\n", |
| 298 | __func__, ret); |
| 299 | goto err_close_slim_sch; |
| 300 | } |
| 301 | } |
| 302 | /* slim_control_ch */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 303 | ret = slim_control_ch(wcd9xxx->slim, grph, SLIM_CH_ACTIVATE, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 304 | true); |
| 305 | if (ret < 0) { |
| 306 | pr_err("%s: slim_control_ch failed ret[%d]\n", |
| 307 | __func__, ret); |
| 308 | goto err_close_slim_sch; |
| 309 | } |
| 310 | for (i = 0; i < ch_cnt; i++) { |
| 311 | idx = (ch_num[i] - BASE_CH_NUM - |
| 312 | SB_PGD_OFFSET_OF_RX_SLAVE_DEV_PORTS - 1); |
| 313 | rx[idx].grph = grph; |
| 314 | } |
| 315 | return 0; |
| 316 | |
| 317 | err_close_slim_sch: |
| 318 | /* release all acquired handles */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 319 | wcd9xxx_close_slim_sch_rx(wcd9xxx, ch_num, ch_cnt); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 320 | err: |
| 321 | return ret; |
| 322 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 323 | EXPORT_SYMBOL_GPL(wcd9xxx_cfg_slim_sch_rx); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 324 | |
| 325 | /* Enable slimbus slave device for RX path */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 326 | int wcd9xxx_cfg_slim_sch_tx(struct wcd9xxx *wcd9xxx, unsigned int *ch_num, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 327 | unsigned int ch_cnt, unsigned int rate) |
| 328 | { |
| 329 | u8 i = 0; |
| 330 | u8 payload_tx_0 = 0, payload_tx_1 = 0, wm_payload = 0; |
| 331 | u16 grph; |
| 332 | u32 sph[SLIM_MAX_TX_PORTS] = {0}; |
| 333 | u16 ch_h[SLIM_MAX_TX_PORTS] = {0}; |
| 334 | u16 idx = 0, slave_port_id; |
| 335 | int ret = 0; |
| 336 | unsigned short multi_chan_cfg_reg_addr; |
| 337 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 338 | struct wcd9xxx_slim_sch_tx *tx = sh_ch.tx; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 339 | struct slim_ch prop; |
| 340 | |
| 341 | pr_debug("%s: ch_cnt[%d] rate[%d]\n", __func__, ch_cnt, rate); |
| 342 | for (i = 0; i < ch_cnt; i++) { |
| 343 | idx = (ch_num[i] - BASE_CH_NUM); |
| 344 | ch_h[i] = tx[idx].ch_h; |
| 345 | sph[i] = tx[idx].sph; |
| 346 | slave_port_id = idx ; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 347 | if (slave_port_id > SB_PGD_MAX_NUMBER_OF_TX_SLAVE_DEV_PORTS) { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 348 | pr_err("SLIMbus: invalid slave port id: %d", |
| 349 | slave_port_id); |
| 350 | ret = -EINVAL; |
| 351 | goto err; |
| 352 | } |
| 353 | /* look for the valid port range and chose the |
| 354 | * payload accordingly |
| 355 | */ |
| 356 | if (slave_port_id <= |
| 357 | SB_PGD_TX_PORT_MULTI_CHANNEL_0_END_PORT_ID) { |
| 358 | payload_tx_0 = payload_tx_0 | (1 << slave_port_id); |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 359 | } else if (slave_port_id <= |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 360 | SB_PGD_TX_PORT_MULTI_CHANNEL_1_END_PORT_ID) { |
| 361 | payload_tx_1 = payload_tx_1 | |
| 362 | (1 << |
| 363 | (slave_port_id - |
| 364 | SB_PGD_TX_PORT_MULTI_CHANNEL_1_START_PORT_ID)); |
| 365 | } else { |
| 366 | ret = -EINVAL; |
| 367 | goto err; |
| 368 | } |
| 369 | multi_chan_cfg_reg_addr = |
| 370 | SB_PGD_TX_PORT_MULTI_CHANNEL_0(slave_port_id); |
| 371 | /* write to interface device */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 372 | ret = wcd9xxx_interface_reg_write(wcd9xxx, |
| 373 | multi_chan_cfg_reg_addr, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 374 | payload_tx_0); |
| 375 | if (ret < 0) { |
| 376 | pr_err("%s:Intf-dev fail reg[%d] payload[%d] ret[%d]\n", |
| 377 | __func__, |
| 378 | multi_chan_cfg_reg_addr, |
| 379 | payload_tx_0, ret); |
| 380 | goto err; |
| 381 | } |
| 382 | multi_chan_cfg_reg_addr = |
| 383 | SB_PGD_TX_PORT_MULTI_CHANNEL_1(slave_port_id); |
| 384 | /* ports 8,9 */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 385 | ret = wcd9xxx_interface_reg_write(wcd9xxx, |
| 386 | multi_chan_cfg_reg_addr, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 387 | payload_tx_1); |
| 388 | if (ret < 0) { |
| 389 | pr_err("%s:Intf-dev fail reg[%d] payload[%d] ret[%d]\n", |
| 390 | __func__, |
| 391 | multi_chan_cfg_reg_addr, |
| 392 | payload_tx_1, ret); |
| 393 | goto err; |
| 394 | } |
| 395 | /* configure the slave port for water mark and enable*/ |
| 396 | wm_payload = (SLAVE_PORT_WATER_MARK_VALUE << |
| 397 | SLAVE_PORT_WATER_MARK_SHIFT) + |
| 398 | SLAVE_PORT_ENABLE; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 399 | ret = wcd9xxx_interface_reg_write(wcd9xxx, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 400 | SB_PGD_PORT_CFG_BYTE_ADDR(slave_port_id), |
| 401 | wm_payload); |
| 402 | if (ret < 0) { |
| 403 | pr_err("%s:watermark set failure for port[%d] ret[%d]", |
| 404 | __func__, |
| 405 | slave_port_id, ret); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /* slim_define_ch api */ |
| 410 | prop.prot = SLIM_AUTO_ISO; |
| 411 | prop.baser = SLIM_RATE_4000HZ; |
| 412 | prop.dataf = SLIM_CH_DATAF_NOT_DEFINED; |
| 413 | prop.auxf = SLIM_CH_AUXF_NOT_APPLICABLE; |
| 414 | prop.ratem = (rate/4000); |
| 415 | prop.sampleszbits = 16; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 416 | ret = slim_define_ch(wcd9xxx->slim, &prop, ch_h, ch_cnt, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 417 | true, &grph); |
| 418 | if (ret < 0) { |
| 419 | pr_err("%s: slim_define_ch failed ret[%d]\n", |
| 420 | __func__, ret); |
| 421 | goto err; |
| 422 | } |
| 423 | for (i = 0; i < ch_cnt; i++) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 424 | ret = slim_connect_src(wcd9xxx->slim, sph[i], |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 425 | ch_h[i]); |
| 426 | if (ret < 0) { |
| 427 | pr_err("%s: slim_connect_src failed ret[%d]\n", |
| 428 | __func__, ret); |
| 429 | goto err; |
| 430 | } |
| 431 | } |
| 432 | /* slim_control_ch */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 433 | ret = slim_control_ch(wcd9xxx->slim, grph, SLIM_CH_ACTIVATE, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 434 | true); |
| 435 | if (ret < 0) { |
| 436 | pr_err("%s: slim_control_ch failed ret[%d]\n", |
| 437 | __func__, ret); |
| 438 | goto err; |
| 439 | } |
| 440 | for (i = 0; i < ch_cnt; i++) { |
| 441 | idx = (ch_num[i] - BASE_CH_NUM); |
| 442 | tx[idx].grph = grph; |
| 443 | } |
| 444 | return 0; |
| 445 | err: |
| 446 | /* release all acquired handles */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 447 | wcd9xxx_close_slim_sch_tx(wcd9xxx, ch_num, ch_cnt); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 448 | return ret; |
| 449 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 450 | EXPORT_SYMBOL_GPL(wcd9xxx_cfg_slim_sch_tx); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 451 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 452 | int wcd9xxx_close_slim_sch_rx(struct wcd9xxx *wcd9xxx, unsigned int *ch_num, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 453 | unsigned int ch_cnt) |
| 454 | { |
| 455 | u16 grph = 0; |
| 456 | u32 sph[SLIM_MAX_RX_PORTS] = {0}; |
| 457 | int i = 0 , idx = 0; |
| 458 | int ret = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 459 | struct wcd9xxx_slim_sch_rx *rx = sh_ch.rx; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 460 | |
Swaminathan Sathappan | 362a17c | 2012-04-25 18:09:46 -0700 | [diff] [blame^] | 461 | pr_debug("%s: ch_cnt[%d]\n", __func__, ch_cnt); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 462 | for (i = 0; i < ch_cnt; i++) { |
| 463 | idx = (ch_num[i] - BASE_CH_NUM - |
| 464 | SB_PGD_OFFSET_OF_RX_SLAVE_DEV_PORTS - 1); |
| 465 | sph[i] = rx[idx].sph; |
| 466 | grph = rx[idx].grph; |
| 467 | } |
| 468 | |
| 469 | /* slim_disconnect_port */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 470 | ret = slim_disconnect_ports(wcd9xxx->slim, sph, ch_cnt); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 471 | if (ret < 0) { |
| 472 | pr_err("%s: slim_disconnect_ports failed ret[%d]\n", |
| 473 | __func__, ret); |
| 474 | } |
| 475 | /* slim_control_ch (REMOVE) */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 476 | ret = slim_control_ch(wcd9xxx->slim, grph, SLIM_CH_REMOVE, true); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 477 | if (ret < 0) { |
| 478 | pr_err("%s: slim_control_ch failed ret[%d]\n", |
| 479 | __func__, ret); |
| 480 | goto err; |
| 481 | } |
| 482 | for (i = 0; i < ch_cnt; i++) { |
| 483 | idx = (ch_num[i] - BASE_CH_NUM - |
| 484 | SB_PGD_OFFSET_OF_RX_SLAVE_DEV_PORTS - 1); |
| 485 | rx[idx].grph = 0; |
| 486 | } |
| 487 | err: |
| 488 | return ret; |
| 489 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 490 | EXPORT_SYMBOL_GPL(wcd9xxx_close_slim_sch_rx); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 491 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 492 | int wcd9xxx_close_slim_sch_tx(struct wcd9xxx *wcd9xxx, unsigned int *ch_num, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 493 | unsigned int ch_cnt) |
| 494 | { |
| 495 | u16 grph = 0; |
| 496 | u32 sph[SLIM_MAX_TX_PORTS] = {0}; |
| 497 | int ret = 0; |
| 498 | int i = 0 , idx = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 499 | struct wcd9xxx_slim_sch_tx *tx = sh_ch.tx; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 500 | |
Swaminathan Sathappan | 362a17c | 2012-04-25 18:09:46 -0700 | [diff] [blame^] | 501 | pr_debug("%s: ch_cnt[%d]\n", __func__, ch_cnt); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 502 | for (i = 0; i < ch_cnt; i++) { |
| 503 | idx = (ch_num[i] - BASE_CH_NUM); |
| 504 | sph[i] = tx[idx].sph; |
| 505 | grph = tx[idx].grph; |
| 506 | } |
| 507 | /* slim_disconnect_port */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 508 | ret = slim_disconnect_ports(wcd9xxx->slim, sph, ch_cnt); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 509 | if (ret < 0) { |
| 510 | pr_err("%s: slim_disconnect_ports failed ret[%d]\n", |
| 511 | __func__, ret); |
| 512 | } |
| 513 | /* slim_control_ch (REMOVE) */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 514 | ret = slim_control_ch(wcd9xxx->slim, grph, SLIM_CH_REMOVE, true); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 515 | if (ret < 0) { |
| 516 | pr_err("%s: slim_control_ch failed ret[%d]\n", |
| 517 | __func__, ret); |
| 518 | goto err; |
| 519 | } |
| 520 | for (i = 0; i < ch_cnt; i++) { |
| 521 | idx = (ch_num[i] - BASE_CH_NUM); |
| 522 | tx[idx].grph = 0; |
| 523 | } |
| 524 | err: |
| 525 | return ret; |
| 526 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 527 | EXPORT_SYMBOL_GPL(wcd9xxx_close_slim_sch_tx); |