Meng Wang | 43bbb87 | 2018-12-10 12:32:05 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2 | /* |
Xiao Li | d8bb93c | 2020-01-07 12:59:05 +0800 | [diff] [blame] | 3 | * Copyright (c) 2015-2020, The Linux Foundation. All rights reserved. |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <linux/module.h> |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/slab.h> |
| 9 | #include <linux/platform_device.h> |
| 10 | #include <linux/device.h> |
| 11 | #include <linux/printk.h> |
| 12 | #include <linux/bitops.h> |
| 13 | #include <linux/regulator/consumer.h> |
| 14 | #include <linux/pm_runtime.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/gpio.h> |
| 18 | #include <linux/of_gpio.h> |
Karthikeyan Mani | 13485b7 | 2019-08-05 17:51:14 -0700 | [diff] [blame] | 19 | #include <linux/of_platform.h> |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 20 | #include <linux/regmap.h> |
| 21 | #include <linux/debugfs.h> |
Laxminath Kasam | 605b42f | 2017-08-01 22:02:15 +0530 | [diff] [blame] | 22 | #include <soc/soundwire.h> |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 23 | #include <sound/pcm.h> |
| 24 | #include <sound/pcm_params.h> |
| 25 | #include <sound/soc.h> |
| 26 | #include <sound/soc-dapm.h> |
| 27 | #include <sound/tlv.h> |
Meng Wang | 11a25cf | 2018-10-31 14:11:26 +0800 | [diff] [blame] | 28 | #include <asoc/msm-cdc-pinctrl.h> |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 29 | #include "wsa881x.h" |
| 30 | #include "wsa881x-temp-sensor.h" |
| 31 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 32 | #define DRV_NAME "wsa-codec" |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 33 | #define WSA881X_NUM_RETRY 5 |
| 34 | |
| 35 | enum { |
| 36 | G_18DB = 0, |
| 37 | G_16P5DB, |
| 38 | G_15DB, |
| 39 | G_13P5DB, |
| 40 | G_12DB, |
| 41 | G_10P5DB, |
| 42 | G_9DB, |
| 43 | G_7P5DB, |
| 44 | G_6DB, |
| 45 | G_4P5DB, |
| 46 | G_3DB, |
| 47 | G_1P5DB, |
| 48 | G_0DB, |
| 49 | }; |
| 50 | |
| 51 | enum { |
| 52 | DISABLE = 0, |
| 53 | ENABLE, |
| 54 | }; |
| 55 | |
| 56 | enum { |
| 57 | SWR_DAC_PORT, |
| 58 | SWR_COMP_PORT, |
| 59 | SWR_BOOST_PORT, |
| 60 | SWR_VISENSE_PORT, |
| 61 | }; |
| 62 | |
| 63 | struct swr_port { |
| 64 | u8 port_id; |
| 65 | u8 ch_mask; |
| 66 | u32 ch_rate; |
| 67 | u8 num_ch; |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 68 | u8 port_type; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | enum { |
| 72 | WSA881X_DEV_DOWN, |
| 73 | WSA881X_DEV_UP, |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 74 | WSA881X_DEV_READY, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /* |
| 78 | * Private data Structure for wsa881x. All parameters related to |
| 79 | * WSA881X codec needs to be defined here. |
| 80 | */ |
| 81 | struct wsa881x_priv { |
| 82 | struct regmap *regmap; |
| 83 | struct device *dev; |
| 84 | struct swr_device *swr_slave; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 85 | struct snd_soc_component *component; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 86 | bool comp_enable; |
| 87 | bool boost_enable; |
| 88 | bool visense_enable; |
| 89 | u8 pa_gain; |
| 90 | struct swr_port port[WSA881X_MAX_SWR_PORTS]; |
| 91 | int pd_gpio; |
| 92 | struct wsa881x_tz_priv tz_pdata; |
| 93 | int bg_cnt; |
| 94 | int clk_cnt; |
| 95 | int version; |
| 96 | struct mutex bg_lock; |
| 97 | struct mutex res_lock; |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 98 | struct mutex temp_lock; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 99 | struct snd_info_entry *entry; |
| 100 | struct snd_info_entry *version_entry; |
| 101 | int state; |
| 102 | struct delayed_work ocp_ctl_work; |
| 103 | struct device_node *wsa_rst_np; |
| 104 | int pa_mute; |
Karthikeyan Mani | 13485b7 | 2019-08-05 17:51:14 -0700 | [diff] [blame] | 105 | struct device_node *bolero_np; |
| 106 | struct platform_device* bolero_dev; |
| 107 | struct notifier_block bolero_nblock; |
| 108 | void *handle; |
| 109 | int (*register_notifier)(void *handle, |
| 110 | struct notifier_block *nblock, |
| 111 | bool enable); |
| 112 | }; |
| 113 | |
| 114 | /* from bolero to WSA events */ |
| 115 | enum { |
| 116 | BOLERO_WSA_EVT_TX_CH_HOLD_CLEAR = 1, |
| 117 | BOLERO_WSA_EVT_PA_OFF_PRE_SSR, |
| 118 | BOLERO_WSA_EVT_SSR_DOWN, |
| 119 | BOLERO_WSA_EVT_SSR_UP, |
Laxminath Kasam | 069df14 | 2019-09-17 23:43:34 +0530 | [diff] [blame] | 120 | BOLERO_WSA_EVT_PA_ON_POST_FSCLK, |
Laxminath Kasam | 2fe71f5 | 2020-05-15 00:39:51 +0530 | [diff] [blame] | 121 | BOLERO_WSA_EVT_PA_ON_POST_FSCLK_ADIE_LB, |
Karthikeyan Mani | 13485b7 | 2019-08-05 17:51:14 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | struct wsa_ctrl_platform_data { |
| 125 | void *handle; |
| 126 | int (*update_wsa_event)(void *handle, u16 event, u32 data); |
| 127 | int (*register_notifier)(void *handle, |
| 128 | struct notifier_block *nblock, |
| 129 | bool enable); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | #define SWR_SLV_MAX_REG_ADDR 0x390 |
| 133 | #define SWR_SLV_START_REG_ADDR 0x40 |
Aditya Bavanari | 8aacfcf | 2019-06-21 15:56:39 +0530 | [diff] [blame] | 134 | #define SWR_SLV_MAX_BUF_LEN 25 |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 135 | #define BYTES_PER_LINE 12 |
| 136 | #define SWR_SLV_RD_BUF_LEN 8 |
| 137 | #define SWR_SLV_WR_BUF_LEN 32 |
| 138 | #define SWR_SLV_MAX_DEVICES 2 |
| 139 | |
| 140 | #define WSA881X_VERSION_ENTRY_SIZE 27 |
| 141 | #define WSA881X_OCP_CTL_TIMER_SEC 2 |
| 142 | #define WSA881X_OCP_CTL_TEMP_CELSIUS 25 |
| 143 | #define WSA881X_OCP_CTL_POLL_TIMER_SEC 60 |
| 144 | |
| 145 | static int wsa881x_ocp_poll_timer_sec = WSA881X_OCP_CTL_POLL_TIMER_SEC; |
| 146 | module_param(wsa881x_ocp_poll_timer_sec, int, 0664); |
| 147 | MODULE_PARM_DESC(wsa881x_ocp_poll_timer_sec, "timer for ocp ctl polling"); |
| 148 | |
| 149 | static struct wsa881x_priv *dbgwsa881x; |
| 150 | static struct dentry *debugfs_wsa881x_dent; |
| 151 | static struct dentry *debugfs_peek; |
| 152 | static struct dentry *debugfs_poke; |
| 153 | static struct dentry *debugfs_reg_dump; |
| 154 | static unsigned int read_data; |
| 155 | static unsigned int devnum; |
| 156 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 157 | static int32_t wsa881x_resource_acquire(struct snd_soc_component *component, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 158 | bool enable); |
| 159 | |
| 160 | static const char * const wsa_pa_gain_text[] = { |
| 161 | "G_18_DB", "G_16P5_DB", "G_15_DB", "G_13P5_DB", "G_12_DB", "G_10P5_DB", |
| 162 | "G_9_DB", "G_7P5_DB", "G_6_DB", "G_4P5_DB", "G_3_DB", "G_1P5_DB", |
| 163 | "G_0_DB" |
| 164 | }; |
| 165 | |
| 166 | static const struct soc_enum wsa_pa_gain_enum = |
| 167 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(wsa_pa_gain_text), wsa_pa_gain_text); |
| 168 | |
| 169 | static int wsa_pa_gain_get(struct snd_kcontrol *kcontrol, |
| 170 | struct snd_ctl_elem_value *ucontrol) |
| 171 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 172 | struct snd_soc_component *component = |
| 173 | snd_soc_kcontrol_component(kcontrol); |
| 174 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 175 | |
| 176 | ucontrol->value.integer.value[0] = wsa881x->pa_gain; |
| 177 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 178 | dev_dbg(component->dev, "%s: PA gain = 0x%x\n", __func__, |
| 179 | wsa881x->pa_gain); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | static int wsa_pa_gain_put(struct snd_kcontrol *kcontrol, |
| 185 | struct snd_ctl_elem_value *ucontrol) |
| 186 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 187 | struct snd_soc_component *component = |
| 188 | snd_soc_kcontrol_component(kcontrol); |
| 189 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 190 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 191 | dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n", |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 192 | __func__, ucontrol->value.integer.value[0]); |
| 193 | |
| 194 | wsa881x->pa_gain = ucontrol->value.integer.value[0]; |
| 195 | |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | static int wsa881x_get_mute(struct snd_kcontrol *kcontrol, |
| 200 | struct snd_ctl_elem_value *ucontrol) |
| 201 | { |
| 202 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 203 | struct snd_soc_component *component = |
| 204 | snd_soc_kcontrol_component(kcontrol); |
| 205 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 206 | |
| 207 | ucontrol->value.integer.value[0] = wsa881x->pa_mute; |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static int wsa881x_set_mute(struct snd_kcontrol *kcontrol, |
| 213 | struct snd_ctl_elem_value *ucontrol) |
| 214 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 215 | struct snd_soc_component *component = |
| 216 | snd_soc_kcontrol_component(kcontrol); |
| 217 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 218 | int value = ucontrol->value.integer.value[0]; |
| 219 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 220 | dev_dbg(component->dev, "%s: mute current %d, new %d\n", |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 221 | __func__, wsa881x->pa_mute, value); |
| 222 | |
| 223 | if (value) |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 224 | snd_soc_component_update_bits(component, WSA881X_SPKR_DRV_EN, |
| 225 | 0x80, 0x00); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 226 | wsa881x->pa_mute = value; |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
Sudheer Papothi | c9dd3be | 2018-04-06 00:51:48 +0530 | [diff] [blame] | 231 | static int wsa881x_get_t0_init(struct snd_kcontrol *kcontrol, |
| 232 | struct snd_ctl_elem_value *ucontrol) |
| 233 | { |
| 234 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 235 | struct snd_soc_component *component = |
| 236 | snd_soc_kcontrol_component(kcontrol); |
| 237 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Sudheer Papothi | c9dd3be | 2018-04-06 00:51:48 +0530 | [diff] [blame] | 238 | struct wsa881x_tz_priv *pdata = &wsa881x->tz_pdata; |
| 239 | |
| 240 | ucontrol->value.integer.value[0] = pdata->t0_init; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 241 | dev_dbg(component->dev, "%s: t0 init %d\n", __func__, pdata->t0_init); |
Sudheer Papothi | c9dd3be | 2018-04-06 00:51:48 +0530 | [diff] [blame] | 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | static int wsa881x_set_t0_init(struct snd_kcontrol *kcontrol, |
| 247 | struct snd_ctl_elem_value *ucontrol) |
| 248 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 249 | struct snd_soc_component *component = |
| 250 | snd_soc_kcontrol_component(kcontrol); |
| 251 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Sudheer Papothi | c9dd3be | 2018-04-06 00:51:48 +0530 | [diff] [blame] | 252 | struct wsa881x_tz_priv *pdata = &wsa881x->tz_pdata; |
| 253 | |
| 254 | pdata->t0_init = ucontrol->value.integer.value[0]; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 255 | dev_dbg(component->dev, "%s: t0 init %d\n", __func__, pdata->t0_init); |
Sudheer Papothi | c9dd3be | 2018-04-06 00:51:48 +0530 | [diff] [blame] | 256 | |
| 257 | return 0; |
| 258 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 259 | |
| 260 | static const struct snd_kcontrol_new wsa_snd_controls[] = { |
| 261 | SOC_ENUM_EXT("WSA PA Gain", wsa_pa_gain_enum, |
| 262 | wsa_pa_gain_get, wsa_pa_gain_put), |
| 263 | SOC_SINGLE_EXT("WSA PA Mute", SND_SOC_NOPM, 0, 1, 0, |
| 264 | wsa881x_get_mute, wsa881x_set_mute), |
Sudheer Papothi | c9dd3be | 2018-04-06 00:51:48 +0530 | [diff] [blame] | 265 | SOC_SINGLE_EXT("WSA T0 Init", SND_SOC_NOPM, 0, 1, 0, |
| 266 | wsa881x_get_t0_init, wsa881x_set_t0_init), |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 267 | }; |
| 268 | |
| 269 | static int codec_debug_open(struct inode *inode, struct file *file) |
| 270 | { |
| 271 | file->private_data = inode->i_private; |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | static int get_parameters(char *buf, u32 *param1, int num_of_par) |
| 276 | { |
| 277 | char *token; |
| 278 | int base, cnt; |
| 279 | |
| 280 | token = strsep(&buf, " "); |
| 281 | for (cnt = 0; cnt < num_of_par; cnt++) { |
| 282 | if (token) { |
| 283 | if ((token[1] == 'x') || (token[1] == 'X')) |
| 284 | base = 16; |
| 285 | else |
| 286 | base = 10; |
| 287 | |
| 288 | if (kstrtou32(token, base, ¶m1[cnt]) != 0) |
| 289 | return -EINVAL; |
| 290 | |
| 291 | token = strsep(&buf, " "); |
| 292 | } else |
| 293 | return -EINVAL; |
| 294 | } |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static ssize_t wsa881x_codec_version_read(struct snd_info_entry *entry, |
| 299 | void *file_private_data, struct file *file, |
| 300 | char __user *buf, size_t count, loff_t pos) |
| 301 | { |
| 302 | struct wsa881x_priv *wsa881x; |
| 303 | char buffer[WSA881X_VERSION_ENTRY_SIZE]; |
| 304 | int len; |
| 305 | |
| 306 | wsa881x = (struct wsa881x_priv *) entry->private_data; |
| 307 | if (!wsa881x) { |
| 308 | pr_err("%s: wsa881x priv is null\n", __func__); |
| 309 | return -EINVAL; |
| 310 | } |
| 311 | |
| 312 | len = snprintf(buffer, sizeof(buffer), "WSA881X-SOUNDWIRE_2_0\n"); |
| 313 | |
| 314 | return simple_read_from_buffer(buf, count, &pos, buffer, len); |
| 315 | } |
| 316 | |
| 317 | static struct snd_info_entry_ops wsa881x_codec_info_ops = { |
| 318 | .read = wsa881x_codec_version_read, |
| 319 | }; |
| 320 | |
| 321 | /* |
| 322 | * wsa881x_codec_info_create_codec_entry - creates wsa881x module |
| 323 | * @codec_root: The parent directory |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 324 | * @component: Codec instance |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 325 | * |
| 326 | * Creates wsa881x module and version entry under the given |
| 327 | * parent directory. |
| 328 | * |
| 329 | * Return: 0 on success or negative error code on failure. |
| 330 | */ |
| 331 | int wsa881x_codec_info_create_codec_entry(struct snd_info_entry *codec_root, |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 332 | struct snd_soc_component *component) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 333 | { |
| 334 | struct snd_info_entry *version_entry; |
| 335 | struct wsa881x_priv *wsa881x; |
| 336 | struct snd_soc_card *card; |
| 337 | char name[80]; |
| 338 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 339 | if (!codec_root || !component) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 340 | return -EINVAL; |
| 341 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 342 | wsa881x = snd_soc_component_get_drvdata(component); |
| 343 | card = component->card; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 344 | snprintf(name, sizeof(name), "%s.%x", "wsa881x", |
| 345 | (u32)wsa881x->swr_slave->addr); |
| 346 | |
| 347 | wsa881x->entry = snd_info_create_subdir(codec_root->module, |
| 348 | (const char *)name, |
| 349 | codec_root); |
| 350 | if (!wsa881x->entry) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 351 | dev_dbg(component->dev, "%s: failed to create wsa881x entry\n", |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 352 | __func__); |
| 353 | return -ENOMEM; |
| 354 | } |
| 355 | |
| 356 | version_entry = snd_info_create_card_entry(card->snd_card, |
| 357 | "version", |
| 358 | wsa881x->entry); |
| 359 | if (!version_entry) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 360 | dev_dbg(component->dev, "%s: failed to create wsa881x version entry\n", |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 361 | __func__); |
| 362 | return -ENOMEM; |
| 363 | } |
| 364 | |
| 365 | version_entry->private_data = wsa881x; |
| 366 | version_entry->size = WSA881X_VERSION_ENTRY_SIZE; |
| 367 | version_entry->content = SNDRV_INFO_CONTENT_DATA; |
| 368 | version_entry->c.ops = &wsa881x_codec_info_ops; |
| 369 | |
| 370 | if (snd_info_register(version_entry) < 0) { |
| 371 | snd_info_free_entry(version_entry); |
| 372 | return -ENOMEM; |
| 373 | } |
| 374 | wsa881x->version_entry = version_entry; |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | EXPORT_SYMBOL(wsa881x_codec_info_create_codec_entry); |
| 379 | |
| 380 | static bool is_swr_slv_reg_readable(int reg) |
| 381 | { |
| 382 | bool ret = true; |
| 383 | |
| 384 | if (((reg > 0x46) && (reg < 0x4A)) || |
| 385 | ((reg > 0x4A) && (reg < 0x50)) || |
| 386 | ((reg > 0x55) && (reg < 0xE0)) || |
| 387 | ((reg > 0xE0) && (reg < 0xF0)) || |
| 388 | ((reg > 0xF0) && (reg < 0x100)) || |
| 389 | ((reg > 0x105) && (reg < 0x120)) || |
| 390 | ((reg > 0x128) && (reg < 0x130)) || |
| 391 | ((reg > 0x138) && (reg < 0x200)) || |
| 392 | ((reg > 0x205) && (reg < 0x220)) || |
| 393 | ((reg > 0x228) && (reg < 0x230)) || |
| 394 | ((reg > 0x238) && (reg < 0x300)) || |
| 395 | ((reg > 0x305) && (reg < 0x320)) || |
| 396 | ((reg > 0x328) && (reg < 0x330)) || |
| 397 | ((reg > 0x338) && (reg < 0x400)) || |
| 398 | ((reg > 0x405) && (reg < 0x420))) |
| 399 | ret = false; |
| 400 | |
| 401 | return ret; |
| 402 | } |
| 403 | |
| 404 | static ssize_t wsa881x_swrslave_reg_show(char __user *ubuf, size_t count, |
| 405 | loff_t *ppos) |
| 406 | { |
| 407 | int i, reg_val, len; |
| 408 | ssize_t total = 0; |
| 409 | char tmp_buf[SWR_SLV_MAX_BUF_LEN]; |
| 410 | |
| 411 | if (!ubuf || !ppos || (devnum == 0)) |
| 412 | return 0; |
| 413 | |
| 414 | for (i = (((int) *ppos / BYTES_PER_LINE) + SWR_SLV_START_REG_ADDR); |
| 415 | i <= SWR_SLV_MAX_REG_ADDR; i++) { |
| 416 | if (!is_swr_slv_reg_readable(i)) |
| 417 | continue; |
| 418 | swr_read(dbgwsa881x->swr_slave, devnum, |
| 419 | i, ®_val, 1); |
| 420 | len = snprintf(tmp_buf, 25, "0x%.3x: 0x%.2x\n", i, |
| 421 | (reg_val & 0xFF)); |
Aditya Bavanari | 8aacfcf | 2019-06-21 15:56:39 +0530 | [diff] [blame] | 422 | if (len < 0) { |
| 423 | pr_err("%s: fail to fill the buffer\n", __func__); |
| 424 | total = -EFAULT; |
| 425 | goto copy_err; |
| 426 | } |
| 427 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 428 | if ((total + len) >= count - 1) |
| 429 | break; |
| 430 | if (copy_to_user((ubuf + total), tmp_buf, len)) { |
| 431 | pr_err("%s: fail to copy reg dump\n", __func__); |
| 432 | total = -EFAULT; |
| 433 | goto copy_err; |
| 434 | } |
| 435 | *ppos += len; |
| 436 | total += len; |
| 437 | } |
| 438 | |
| 439 | copy_err: |
| 440 | return total; |
| 441 | } |
| 442 | |
| 443 | static ssize_t codec_debug_read(struct file *file, char __user *ubuf, |
| 444 | size_t count, loff_t *ppos) |
| 445 | { |
| 446 | char lbuf[SWR_SLV_RD_BUF_LEN]; |
| 447 | char *access_str; |
| 448 | ssize_t ret_cnt; |
| 449 | |
| 450 | if (!count || !file || !ppos || !ubuf) |
| 451 | return -EINVAL; |
| 452 | |
| 453 | access_str = file->private_data; |
| 454 | if (*ppos < 0) |
| 455 | return -EINVAL; |
| 456 | |
| 457 | if (!strcmp(access_str, "swrslave_peek")) { |
| 458 | snprintf(lbuf, sizeof(lbuf), "0x%x\n", (read_data & 0xFF)); |
| 459 | ret_cnt = simple_read_from_buffer(ubuf, count, ppos, lbuf, |
| 460 | strnlen(lbuf, 7)); |
| 461 | } else if (!strcmp(access_str, "swrslave_reg_dump")) { |
| 462 | ret_cnt = wsa881x_swrslave_reg_show(ubuf, count, ppos); |
| 463 | } else { |
| 464 | pr_err("%s: %s not permitted to read\n", __func__, access_str); |
| 465 | ret_cnt = -EPERM; |
| 466 | } |
| 467 | return ret_cnt; |
| 468 | } |
| 469 | |
| 470 | static ssize_t codec_debug_write(struct file *filp, |
| 471 | const char __user *ubuf, size_t cnt, loff_t *ppos) |
| 472 | { |
| 473 | char lbuf[SWR_SLV_WR_BUF_LEN]; |
| 474 | int rc; |
| 475 | u32 param[5]; |
| 476 | char *access_str; |
| 477 | |
| 478 | if (!filp || !ppos || !ubuf) |
| 479 | return -EINVAL; |
| 480 | |
| 481 | access_str = filp->private_data; |
| 482 | if (cnt > sizeof(lbuf) - 1) |
| 483 | return -EINVAL; |
| 484 | |
| 485 | rc = copy_from_user(lbuf, ubuf, cnt); |
| 486 | if (rc) |
| 487 | return -EFAULT; |
| 488 | |
| 489 | lbuf[cnt] = '\0'; |
| 490 | if (!strcmp(access_str, "swrslave_poke")) { |
| 491 | /* write */ |
| 492 | rc = get_parameters(lbuf, param, 3); |
| 493 | if ((param[0] <= SWR_SLV_MAX_REG_ADDR) && (param[1] <= 0xFF) && |
| 494 | (rc == 0)) |
| 495 | swr_write(dbgwsa881x->swr_slave, param[2], |
| 496 | param[0], ¶m[1]); |
| 497 | else |
| 498 | rc = -EINVAL; |
| 499 | } else if (!strcmp(access_str, "swrslave_peek")) { |
| 500 | /* read */ |
| 501 | rc = get_parameters(lbuf, param, 2); |
| 502 | if ((param[0] <= SWR_SLV_MAX_REG_ADDR) && (rc == 0)) |
| 503 | swr_read(dbgwsa881x->swr_slave, param[1], |
| 504 | param[0], &read_data, 1); |
| 505 | else |
| 506 | rc = -EINVAL; |
| 507 | } else if (!strcmp(access_str, "swrslave_reg_dump")) { |
| 508 | /* reg dump */ |
| 509 | rc = get_parameters(lbuf, param, 1); |
| 510 | if ((rc == 0) && (param[0] > 0) && |
| 511 | (param[0] <= SWR_SLV_MAX_DEVICES)) |
| 512 | devnum = param[0]; |
| 513 | else |
| 514 | rc = -EINVAL; |
| 515 | } |
| 516 | if (rc == 0) |
| 517 | rc = cnt; |
| 518 | else |
| 519 | pr_err("%s: rc = %d\n", __func__, rc); |
| 520 | |
| 521 | return rc; |
| 522 | } |
| 523 | |
| 524 | static const struct file_operations codec_debug_ops = { |
| 525 | .open = codec_debug_open, |
| 526 | .write = codec_debug_write, |
| 527 | .read = codec_debug_read, |
| 528 | }; |
| 529 | |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 530 | static void wsa881x_regcache_sync(struct wsa881x_priv *wsa881x) |
| 531 | { |
| 532 | mutex_lock(&wsa881x->res_lock); |
| 533 | if (wsa881x->state != WSA881X_DEV_READY) { |
| 534 | regcache_mark_dirty(wsa881x->regmap); |
| 535 | regcache_sync(wsa881x->regmap); |
| 536 | wsa881x->state = WSA881X_DEV_READY; |
| 537 | } |
| 538 | mutex_unlock(&wsa881x->res_lock); |
| 539 | } |
| 540 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 541 | static const struct reg_sequence wsa881x_pre_pmu_pa[] = { |
| 542 | {WSA881X_SPKR_DRV_GAIN, 0x41, 0}, |
| 543 | {WSA881X_SPKR_MISC_CTL1, 0x01, 0}, |
| 544 | {WSA881X_ADC_EN_DET_TEST_I, 0x01, 0}, |
| 545 | {WSA881X_ADC_EN_MODU_V, 0x02, 0}, |
| 546 | {WSA881X_ADC_EN_DET_TEST_V, 0x10, 0}, |
| 547 | {WSA881X_SPKR_PWRSTG_DBG, 0xA0, 0}, |
| 548 | }; |
| 549 | |
| 550 | static const struct reg_sequence wsa881x_pre_pmu_pa_2_0[] = { |
| 551 | {WSA881X_SPKR_DRV_GAIN, 0x41, 0}, |
| 552 | {WSA881X_SPKR_MISC_CTL1, 0x87, 0}, |
| 553 | }; |
| 554 | |
| 555 | static const struct reg_sequence wsa881x_post_pmu_pa[] = { |
| 556 | {WSA881X_SPKR_PWRSTG_DBG, 0x00, 0}, |
| 557 | {WSA881X_ADC_EN_DET_TEST_V, 0x00, 0}, |
| 558 | {WSA881X_ADC_EN_MODU_V, 0x00, 0}, |
| 559 | {WSA881X_ADC_EN_DET_TEST_I, 0x00, 0}, |
| 560 | }; |
| 561 | |
| 562 | static const struct reg_sequence wsa881x_vi_txfe_en[] = { |
| 563 | {WSA881X_SPKR_PROT_FE_VSENSE_VCM, 0x85, 0}, |
| 564 | {WSA881X_SPKR_PROT_ATEST2, 0x0A, 0}, |
| 565 | {WSA881X_SPKR_PROT_FE_GAIN, 0xCF, 0}, |
| 566 | }; |
| 567 | |
| 568 | static const struct reg_sequence wsa881x_vi_txfe_en_2_0[] = { |
| 569 | {WSA881X_SPKR_PROT_FE_VSENSE_VCM, 0x85, 0}, |
| 570 | {WSA881X_SPKR_PROT_ATEST2, 0x0A, 0}, |
| 571 | {WSA881X_SPKR_PROT_FE_GAIN, 0x47, 0}, |
| 572 | }; |
| 573 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 574 | static int wsa881x_boost_ctrl(struct snd_soc_component *component, bool enable) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 575 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 576 | dev_dbg(component->dev, "%s: enable:%d\n", __func__, enable); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 577 | if (enable) |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 578 | snd_soc_component_update_bits(component, WSA881X_BOOST_EN_CTL, |
| 579 | 0x80, 0x80); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 580 | else |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 581 | snd_soc_component_update_bits(component, WSA881X_BOOST_EN_CTL, |
| 582 | 0x80, 0x00); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 583 | /* |
| 584 | * 1.5ms sleep is needed after boost enable/disable as per |
| 585 | * HW requirement |
| 586 | */ |
| 587 | usleep_range(1500, 1510); |
| 588 | return 0; |
| 589 | } |
| 590 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 591 | static int wsa881x_visense_txfe_ctrl(struct snd_soc_component *component, |
| 592 | bool enable, u8 isense1_gain, |
| 593 | u8 isense2_gain, u8 vsense_gain) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 594 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 595 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 596 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 597 | dev_dbg(component->dev, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 598 | "%s: enable:%d, isense1 gain: %d, isense2 gain: %d, vsense_gain %d\n", |
| 599 | __func__, enable, isense1_gain, isense2_gain, vsense_gain); |
| 600 | |
| 601 | if (enable) { |
| 602 | regmap_multi_reg_write(wsa881x->regmap, |
| 603 | wsa881x_vi_txfe_en_2_0, |
| 604 | ARRAY_SIZE(wsa881x_vi_txfe_en_2_0)); |
| 605 | } else { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 606 | snd_soc_component_update_bits(component, |
| 607 | WSA881X_SPKR_PROT_FE_VSENSE_VCM, |
| 608 | 0x08, 0x08); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 609 | /* |
| 610 | * 200us sleep is needed after visense txfe disable as per |
| 611 | * HW requirement. |
| 612 | */ |
| 613 | usleep_range(200, 210); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 614 | snd_soc_component_update_bits(component, |
| 615 | WSA881X_SPKR_PROT_FE_GAIN, |
| 616 | 0x01, 0x00); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 617 | } |
| 618 | return 0; |
| 619 | } |
| 620 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 621 | static int wsa881x_visense_adc_ctrl(struct snd_soc_component *component, |
| 622 | bool enable) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 623 | { |
| 624 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 625 | dev_dbg(component->dev, "%s: enable:%d\n", __func__, enable); |
| 626 | snd_soc_component_update_bits(component, WSA881X_ADC_EN_MODU_V, |
| 627 | (0x01 << 7), (enable << 7)); |
| 628 | snd_soc_component_update_bits(component, WSA881X_ADC_EN_MODU_I, |
| 629 | (0x01 << 7), (enable << 7)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 630 | return 0; |
| 631 | } |
| 632 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 633 | static void wsa881x_bandgap_ctrl(struct snd_soc_component *component, |
| 634 | bool enable) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 635 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 636 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 637 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 638 | dev_dbg(component->dev, "%s: enable:%d, bg_count:%d\n", __func__, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 639 | enable, wsa881x->bg_cnt); |
| 640 | mutex_lock(&wsa881x->bg_lock); |
| 641 | if (enable) { |
| 642 | ++wsa881x->bg_cnt; |
| 643 | if (wsa881x->bg_cnt == 1) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 644 | snd_soc_component_update_bits(component, |
| 645 | WSA881X_TEMP_OP, |
| 646 | 0x08, 0x08); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 647 | /* 400usec sleep is needed as per HW requirement */ |
| 648 | usleep_range(400, 410); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 649 | snd_soc_component_update_bits(component, |
| 650 | WSA881X_TEMP_OP, |
| 651 | 0x04, 0x04); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 652 | } |
| 653 | } else { |
| 654 | --wsa881x->bg_cnt; |
| 655 | if (wsa881x->bg_cnt <= 0) { |
| 656 | WARN_ON(wsa881x->bg_cnt < 0); |
| 657 | wsa881x->bg_cnt = 0; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 658 | snd_soc_component_update_bits(component, |
| 659 | WSA881X_TEMP_OP, 0x04, 0x00); |
| 660 | snd_soc_component_update_bits(component, |
| 661 | WSA881X_TEMP_OP, 0x08, 0x00); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | mutex_unlock(&wsa881x->bg_lock); |
| 665 | } |
| 666 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 667 | static void wsa881x_clk_ctrl(struct snd_soc_component *component, bool enable) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 668 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 669 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 670 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 671 | dev_dbg(component->dev, "%s: enable:%d, clk_count:%d\n", __func__, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 672 | enable, wsa881x->clk_cnt); |
| 673 | mutex_lock(&wsa881x->res_lock); |
| 674 | if (enable) { |
| 675 | ++wsa881x->clk_cnt; |
| 676 | if (wsa881x->clk_cnt == 1) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 677 | snd_soc_component_write(component, |
| 678 | WSA881X_CDC_DIG_CLK_CTL, 0x01); |
| 679 | snd_soc_component_write(component, |
| 680 | WSA881X_CDC_ANA_CLK_CTL, 0x01); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 681 | } |
| 682 | } else { |
| 683 | --wsa881x->clk_cnt; |
| 684 | if (wsa881x->clk_cnt <= 0) { |
| 685 | WARN_ON(wsa881x->clk_cnt < 0); |
| 686 | wsa881x->clk_cnt = 0; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 687 | snd_soc_component_write(component, |
| 688 | WSA881X_CDC_DIG_CLK_CTL, 0x00); |
| 689 | snd_soc_component_write(component, |
| 690 | WSA881X_CDC_ANA_CLK_CTL, 0x00); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | mutex_unlock(&wsa881x->res_lock); |
| 694 | } |
| 695 | |
| 696 | static int wsa881x_get_compander(struct snd_kcontrol *kcontrol, |
| 697 | struct snd_ctl_elem_value *ucontrol) |
| 698 | { |
| 699 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 700 | struct snd_soc_component *component = |
| 701 | snd_soc_kcontrol_component(kcontrol); |
| 702 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 703 | |
| 704 | ucontrol->value.integer.value[0] = wsa881x->comp_enable; |
| 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | static int wsa881x_set_compander(struct snd_kcontrol *kcontrol, |
| 709 | struct snd_ctl_elem_value *ucontrol) |
| 710 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 711 | struct snd_soc_component *component = |
| 712 | snd_soc_kcontrol_component(kcontrol); |
| 713 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 714 | int value = ucontrol->value.integer.value[0]; |
| 715 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 716 | dev_dbg(component->dev, "%s: Compander enable current %d, new %d\n", |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 717 | __func__, wsa881x->comp_enable, value); |
| 718 | wsa881x->comp_enable = value; |
| 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | static int wsa881x_get_boost(struct snd_kcontrol *kcontrol, |
| 723 | struct snd_ctl_elem_value *ucontrol) |
| 724 | { |
| 725 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 726 | struct snd_soc_component *component = |
| 727 | snd_soc_kcontrol_component(kcontrol); |
| 728 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 729 | |
| 730 | ucontrol->value.integer.value[0] = wsa881x->boost_enable; |
| 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | static int wsa881x_set_boost(struct snd_kcontrol *kcontrol, |
| 735 | struct snd_ctl_elem_value *ucontrol) |
| 736 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 737 | struct snd_soc_component *component = |
| 738 | snd_soc_kcontrol_component(kcontrol); |
| 739 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 740 | int value = ucontrol->value.integer.value[0]; |
| 741 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 742 | dev_dbg(component->dev, "%s: Boost enable current %d, new %d\n", |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 743 | __func__, wsa881x->boost_enable, value); |
| 744 | wsa881x->boost_enable = value; |
| 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | static int wsa881x_get_visense(struct snd_kcontrol *kcontrol, |
| 749 | struct snd_ctl_elem_value *ucontrol) |
| 750 | { |
| 751 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 752 | struct snd_soc_component *component = |
| 753 | snd_soc_kcontrol_component(kcontrol); |
| 754 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 755 | |
| 756 | ucontrol->value.integer.value[0] = wsa881x->visense_enable; |
| 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | static int wsa881x_set_visense(struct snd_kcontrol *kcontrol, |
| 761 | struct snd_ctl_elem_value *ucontrol) |
| 762 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 763 | struct snd_soc_component *component = |
| 764 | snd_soc_kcontrol_component(kcontrol); |
| 765 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 766 | int value = ucontrol->value.integer.value[0]; |
| 767 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 768 | dev_dbg(component->dev, "%s: VIsense enable current %d, new %d\n", |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 769 | __func__, wsa881x->visense_enable, value); |
| 770 | wsa881x->visense_enable = value; |
| 771 | return 0; |
| 772 | } |
| 773 | |
Xiaojun Sang | fa21d8c | 2017-09-22 17:05:02 +0800 | [diff] [blame] | 774 | static int wsa881x_set_boost_level(struct snd_kcontrol *kcontrol, |
| 775 | struct snd_ctl_elem_value *ucontrol) |
| 776 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 777 | struct snd_soc_component *component = |
| 778 | snd_soc_kcontrol_component(kcontrol); |
Xiaojun Sang | fa21d8c | 2017-09-22 17:05:02 +0800 | [diff] [blame] | 779 | u8 wsa_boost_level = 0; |
| 780 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 781 | dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n", |
Xiaojun Sang | fa21d8c | 2017-09-22 17:05:02 +0800 | [diff] [blame] | 782 | __func__, ucontrol->value.integer.value[0]); |
| 783 | |
| 784 | wsa_boost_level = ucontrol->value.integer.value[0]; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 785 | snd_soc_component_update_bits(component, WSA881X_BOOST_PRESET_OUT1, |
Xiaojun Sang | fa21d8c | 2017-09-22 17:05:02 +0800 | [diff] [blame] | 786 | 0xff, wsa_boost_level); |
| 787 | |
| 788 | return 0; |
| 789 | } |
| 790 | |
| 791 | static int wsa881x_get_boost_level(struct snd_kcontrol *kcontrol, |
| 792 | struct snd_ctl_elem_value *ucontrol) |
| 793 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 794 | struct snd_soc_component *component = |
| 795 | snd_soc_kcontrol_component(kcontrol); |
Xiaojun Sang | fa21d8c | 2017-09-22 17:05:02 +0800 | [diff] [blame] | 796 | u8 wsa_boost_level = 0; |
| 797 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 798 | wsa_boost_level = snd_soc_component_read32(component, |
| 799 | WSA881X_BOOST_PRESET_OUT1); |
Xiaojun Sang | fa21d8c | 2017-09-22 17:05:02 +0800 | [diff] [blame] | 800 | ucontrol->value.integer.value[0] = wsa_boost_level; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 801 | dev_dbg(component->dev, "%s: boost level = 0x%x\n", __func__, |
Xiaojun Sang | fa21d8c | 2017-09-22 17:05:02 +0800 | [diff] [blame] | 802 | wsa_boost_level); |
| 803 | |
| 804 | return 0; |
| 805 | } |
| 806 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 807 | static const struct snd_kcontrol_new wsa881x_snd_controls[] = { |
| 808 | SOC_SINGLE_EXT("COMP Switch", SND_SOC_NOPM, 0, 1, 0, |
| 809 | wsa881x_get_compander, wsa881x_set_compander), |
| 810 | |
| 811 | SOC_SINGLE_EXT("BOOST Switch", SND_SOC_NOPM, 0, 1, 0, |
| 812 | wsa881x_get_boost, wsa881x_set_boost), |
| 813 | |
| 814 | SOC_SINGLE_EXT("VISENSE Switch", SND_SOC_NOPM, 0, 1, 0, |
| 815 | wsa881x_get_visense, wsa881x_set_visense), |
Xiaojun Sang | fa21d8c | 2017-09-22 17:05:02 +0800 | [diff] [blame] | 816 | |
| 817 | SOC_SINGLE_EXT("Boost Level", SND_SOC_NOPM, 0, 0xff, 0, |
| 818 | wsa881x_get_boost_level, wsa881x_set_boost_level), |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 819 | }; |
| 820 | |
| 821 | static const struct snd_kcontrol_new swr_dac_port[] = { |
| 822 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 823 | }; |
| 824 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 825 | static int wsa881x_set_port(struct snd_soc_component *component, int port_idx, |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 826 | u8 *port_id, u8 *num_ch, u8 *ch_mask, u32 *ch_rate, |
| 827 | u8 *port_type) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 828 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 829 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 830 | |
| 831 | *port_id = wsa881x->port[port_idx].port_id; |
| 832 | *num_ch = wsa881x->port[port_idx].num_ch; |
| 833 | *ch_mask = wsa881x->port[port_idx].ch_mask; |
| 834 | *ch_rate = wsa881x->port[port_idx].ch_rate; |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 835 | *port_type = wsa881x->port[port_idx].port_type; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | static int wsa881x_enable_swr_dac_port(struct snd_soc_dapm_widget *w, |
| 840 | struct snd_kcontrol *kcontrol, int event) |
| 841 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 842 | struct snd_soc_component *component = |
| 843 | snd_soc_dapm_to_component(w->dapm); |
| 844 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 845 | u8 port_id[WSA881X_MAX_SWR_PORTS]; |
| 846 | u8 num_ch[WSA881X_MAX_SWR_PORTS]; |
| 847 | u8 ch_mask[WSA881X_MAX_SWR_PORTS]; |
| 848 | u32 ch_rate[WSA881X_MAX_SWR_PORTS]; |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 849 | u8 port_type[WSA881X_MAX_SWR_PORTS]; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 850 | u8 num_port = 0; |
| 851 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 852 | dev_dbg(component->dev, "%s: event %d name %s\n", __func__, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 853 | event, w->name); |
| 854 | if (wsa881x == NULL) |
| 855 | return -EINVAL; |
| 856 | |
| 857 | switch (event) { |
| 858 | case SND_SOC_DAPM_PRE_PMU: |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 859 | wsa881x_set_port(component, SWR_DAC_PORT, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 860 | &port_id[num_port], &num_ch[num_port], |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 861 | &ch_mask[num_port], &ch_rate[num_port], |
| 862 | &port_type[num_port]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 863 | ++num_port; |
| 864 | |
| 865 | if (wsa881x->comp_enable) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 866 | wsa881x_set_port(component, SWR_COMP_PORT, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 867 | &port_id[num_port], &num_ch[num_port], |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 868 | &ch_mask[num_port], &ch_rate[num_port], |
| 869 | &port_type[num_port]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 870 | ++num_port; |
| 871 | } |
| 872 | if (wsa881x->boost_enable) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 873 | wsa881x_set_port(component, SWR_BOOST_PORT, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 874 | &port_id[num_port], &num_ch[num_port], |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 875 | &ch_mask[num_port], &ch_rate[num_port], |
| 876 | &port_type[num_port]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 877 | ++num_port; |
| 878 | } |
| 879 | if (wsa881x->visense_enable) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 880 | wsa881x_set_port(component, SWR_VISENSE_PORT, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 881 | &port_id[num_port], &num_ch[num_port], |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 882 | &ch_mask[num_port], &ch_rate[num_port], |
| 883 | &port_type[num_port]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 884 | ++num_port; |
| 885 | } |
| 886 | swr_connect_port(wsa881x->swr_slave, &port_id[0], num_port, |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 887 | &ch_mask[0], &ch_rate[0], &num_ch[0], |
| 888 | &port_type[0]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 889 | break; |
| 890 | case SND_SOC_DAPM_POST_PMU: |
| 891 | break; |
| 892 | case SND_SOC_DAPM_PRE_PMD: |
| 893 | break; |
| 894 | case SND_SOC_DAPM_POST_PMD: |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 895 | wsa881x_set_port(component, SWR_DAC_PORT, |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 896 | &port_id[num_port], &num_ch[num_port], |
| 897 | &ch_mask[num_port], &ch_rate[num_port], |
| 898 | &port_type[num_port]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 899 | ++num_port; |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 900 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 901 | if (wsa881x->comp_enable) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 902 | wsa881x_set_port(component, SWR_COMP_PORT, |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 903 | &port_id[num_port], &num_ch[num_port], |
| 904 | &ch_mask[num_port], &ch_rate[num_port], |
| 905 | &port_type[num_port]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 906 | ++num_port; |
| 907 | } |
| 908 | if (wsa881x->boost_enable) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 909 | wsa881x_set_port(component, SWR_BOOST_PORT, |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 910 | &port_id[num_port], &num_ch[num_port], |
| 911 | &ch_mask[num_port], &ch_rate[num_port], |
| 912 | &port_type[num_port]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 913 | ++num_port; |
| 914 | } |
| 915 | if (wsa881x->visense_enable) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 916 | wsa881x_set_port(component, SWR_VISENSE_PORT, |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 917 | &port_id[num_port], &num_ch[num_port], |
| 918 | &ch_mask[num_port], &ch_rate[num_port], |
| 919 | &port_type[num_port]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 920 | ++num_port; |
| 921 | } |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 922 | swr_disconnect_port(wsa881x->swr_slave, &port_id[0], num_port, |
| 923 | &ch_mask[0], &port_type[0]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 924 | break; |
| 925 | default: |
| 926 | break; |
| 927 | } |
| 928 | return 0; |
| 929 | } |
| 930 | |
| 931 | static int wsa881x_rdac_event(struct snd_soc_dapm_widget *w, |
| 932 | struct snd_kcontrol *kcontrol, int event) |
| 933 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 934 | struct snd_soc_component *component = |
| 935 | snd_soc_dapm_to_component(w->dapm); |
| 936 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 937 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 938 | dev_dbg(component->dev, "%s: %s %d boost %d visense %d\n", __func__, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 939 | w->name, event, wsa881x->boost_enable, |
| 940 | wsa881x->visense_enable); |
| 941 | |
| 942 | switch (event) { |
| 943 | case SND_SOC_DAPM_PRE_PMU: |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 944 | mutex_lock(&wsa881x->temp_lock); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 945 | wsa881x_resource_acquire(component, ENABLE); |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 946 | mutex_unlock(&wsa881x->temp_lock); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 947 | wsa881x_boost_ctrl(component, ENABLE); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 948 | break; |
| 949 | case SND_SOC_DAPM_POST_PMD: |
| 950 | swr_slvdev_datapath_control(wsa881x->swr_slave, |
| 951 | wsa881x->swr_slave->dev_num, |
| 952 | false); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 953 | wsa881x_boost_ctrl(component, DISABLE); |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 954 | mutex_lock(&wsa881x->temp_lock); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 955 | wsa881x_resource_acquire(component, DISABLE); |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 956 | mutex_unlock(&wsa881x->temp_lock); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 957 | break; |
| 958 | } |
| 959 | return 0; |
| 960 | } |
| 961 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 962 | static int wsa881x_ramp_pa_gain(struct snd_soc_component *component, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 963 | int min_gain, int max_gain, int udelay) |
| 964 | { |
| 965 | int val; |
| 966 | |
| 967 | for (val = min_gain; max_gain <= val; val--) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 968 | snd_soc_component_update_bits(component, WSA881X_SPKR_DRV_GAIN, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 969 | 0xF0, val << 4); |
| 970 | /* |
| 971 | * 1ms delay is needed for every step change in gain as per |
| 972 | * HW requirement. |
| 973 | */ |
| 974 | usleep_range(udelay, udelay+10); |
| 975 | } |
| 976 | return 0; |
| 977 | } |
| 978 | |
| 979 | static void wsa881x_ocp_ctl_work(struct work_struct *work) |
| 980 | { |
| 981 | struct wsa881x_priv *wsa881x; |
| 982 | struct delayed_work *dwork; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 983 | struct snd_soc_component *component; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 984 | int temp_val; |
| 985 | |
| 986 | dwork = to_delayed_work(work); |
| 987 | wsa881x = container_of(dwork, struct wsa881x_priv, ocp_ctl_work); |
| 988 | |
Prasad Kumpatla | 71fef46 | 2020-01-31 21:38:58 +0530 | [diff] [blame] | 989 | if (wsa881x->state == WSA881X_DEV_DOWN) |
| 990 | return; |
| 991 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 992 | component = wsa881x->component; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 993 | wsa881x_get_temp(wsa881x->tz_pdata.tz_dev, &temp_val); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 994 | dev_dbg(component->dev, " temp = %d\n", temp_val); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 995 | |
| 996 | if (temp_val <= WSA881X_OCP_CTL_TEMP_CELSIUS) |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 997 | snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL, |
| 998 | 0xC0, 0x00); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 999 | else |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1000 | snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL, |
| 1001 | 0xC0, 0xC0); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1002 | |
| 1003 | schedule_delayed_work(&wsa881x->ocp_ctl_work, |
| 1004 | msecs_to_jiffies(wsa881x_ocp_poll_timer_sec * 1000)); |
| 1005 | } |
| 1006 | |
| 1007 | static int wsa881x_spkr_pa_event(struct snd_soc_dapm_widget *w, |
| 1008 | struct snd_kcontrol *kcontrol, int event) |
| 1009 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1010 | struct snd_soc_component *component = |
| 1011 | snd_soc_dapm_to_component(w->dapm); |
| 1012 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1013 | int min_gain, max_gain; |
| 1014 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1015 | dev_dbg(component->dev, "%s: %s %d\n", __func__, w->name, event); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1016 | switch (event) { |
| 1017 | case SND_SOC_DAPM_PRE_PMU: |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1018 | snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL, |
| 1019 | 0xC0, 0x80); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1020 | regmap_multi_reg_write(wsa881x->regmap, |
| 1021 | wsa881x_pre_pmu_pa_2_0, |
| 1022 | ARRAY_SIZE(wsa881x_pre_pmu_pa_2_0)); |
| 1023 | swr_slvdev_datapath_control(wsa881x->swr_slave, |
| 1024 | wsa881x->swr_slave->dev_num, |
| 1025 | true); |
| 1026 | /* Set register mode if compander is not enabled */ |
| 1027 | if (!wsa881x->comp_enable) |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1028 | snd_soc_component_update_bits(component, |
| 1029 | WSA881X_SPKR_DRV_GAIN, |
| 1030 | 0x08, 0x08); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1031 | else |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1032 | snd_soc_component_update_bits(component, |
| 1033 | WSA881X_SPKR_DRV_GAIN, |
| 1034 | 0x08, 0x00); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1035 | |
| 1036 | break; |
| 1037 | case SND_SOC_DAPM_POST_PMU: |
Laxminath Kasam | 069df14 | 2019-09-17 23:43:34 +0530 | [diff] [blame] | 1038 | if (!wsa881x->bolero_dev) |
| 1039 | snd_soc_component_update_bits(component, |
| 1040 | WSA881X_SPKR_DRV_EN, |
| 1041 | 0x80, 0x80); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1042 | if (!wsa881x->comp_enable) { |
| 1043 | max_gain = wsa881x->pa_gain; |
| 1044 | /* |
| 1045 | * Gain has to set incrementally in 4 steps |
| 1046 | * as per HW sequence |
| 1047 | */ |
| 1048 | if (max_gain > G_4P5DB) |
| 1049 | min_gain = G_0DB; |
| 1050 | else |
| 1051 | min_gain = max_gain + 3; |
| 1052 | /* |
| 1053 | * 1ms delay is needed before change in gain |
| 1054 | * as per HW requirement. |
| 1055 | */ |
| 1056 | usleep_range(1000, 1010); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1057 | wsa881x_ramp_pa_gain(component, min_gain, max_gain, |
| 1058 | 1000); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1059 | } |
| 1060 | if (wsa881x->visense_enable) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1061 | wsa881x_visense_txfe_ctrl(component, ENABLE, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1062 | 0x00, 0x03, 0x01); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1063 | snd_soc_component_update_bits(component, |
| 1064 | WSA881X_ADC_EN_SEL_IBAIS, |
| 1065 | 0x07, 0x01); |
| 1066 | wsa881x_visense_adc_ctrl(component, ENABLE); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1067 | } |
| 1068 | schedule_delayed_work(&wsa881x->ocp_ctl_work, |
| 1069 | msecs_to_jiffies(WSA881X_OCP_CTL_TIMER_SEC * 1000)); |
| 1070 | /* Force remove group */ |
| 1071 | swr_remove_from_group(wsa881x->swr_slave, |
| 1072 | wsa881x->swr_slave->dev_num); |
| 1073 | break; |
| 1074 | case SND_SOC_DAPM_POST_PMD: |
Laxminath Kasam | 069df14 | 2019-09-17 23:43:34 +0530 | [diff] [blame] | 1075 | snd_soc_component_update_bits(component, |
| 1076 | WSA881X_SPKR_DRV_EN, |
| 1077 | 0x80, 0x00); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1078 | if (wsa881x->visense_enable) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1079 | wsa881x_visense_adc_ctrl(component, DISABLE); |
Laxminath Kasam | f813d50 | 2020-07-01 17:01:55 +0530 | [diff] [blame^] | 1080 | snd_soc_component_update_bits(component, |
| 1081 | WSA881X_ADC_EN_SEL_IBAIS, |
| 1082 | 0x07, 0x00); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1083 | wsa881x_visense_txfe_ctrl(component, DISABLE, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1084 | 0x00, 0x01, 0x01); |
| 1085 | } |
| 1086 | cancel_delayed_work_sync(&wsa881x->ocp_ctl_work); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1087 | snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL, |
| 1088 | 0xC0, 0xC0); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1089 | break; |
| 1090 | } |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
| 1094 | static const struct snd_soc_dapm_widget wsa881x_dapm_widgets[] = { |
| 1095 | SND_SOC_DAPM_INPUT("IN"), |
| 1096 | |
| 1097 | SND_SOC_DAPM_MIXER_E("SWR DAC_Port", SND_SOC_NOPM, 0, 0, swr_dac_port, |
| 1098 | ARRAY_SIZE(swr_dac_port), wsa881x_enable_swr_dac_port, |
| 1099 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 1100 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 1101 | |
| 1102 | SND_SOC_DAPM_DAC_E("RDAC", NULL, WSA881X_SPKR_DAC_CTL, 7, 0, |
| 1103 | wsa881x_rdac_event, |
| 1104 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1105 | |
Laxminath Kasam | 069df14 | 2019-09-17 23:43:34 +0530 | [diff] [blame] | 1106 | SND_SOC_DAPM_PGA_E("SPKR PGA", SND_SOC_NOPM, 0, 0, NULL, 0, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1107 | wsa881x_spkr_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 1108 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1109 | |
| 1110 | SND_SOC_DAPM_OUTPUT("SPKR"), |
| 1111 | }; |
| 1112 | |
| 1113 | static const struct snd_soc_dapm_route wsa881x_audio_map[] = { |
| 1114 | {"SWR DAC_Port", "Switch", "IN"}, |
| 1115 | {"RDAC", NULL, "SWR DAC_Port"}, |
| 1116 | {"SPKR PGA", NULL, "RDAC"}, |
| 1117 | {"SPKR", NULL, "SPKR PGA"}, |
| 1118 | }; |
| 1119 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1120 | int wsa881x_set_channel_map(struct snd_soc_component *component, u8 *port, |
| 1121 | u8 num_port, unsigned int *ch_mask, |
| 1122 | unsigned int *ch_rate, u8 *port_type) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1123 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1124 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1125 | int i; |
| 1126 | |
| 1127 | if (!port || !ch_mask || !ch_rate || |
| 1128 | (num_port > WSA881X_MAX_SWR_PORTS)) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1129 | dev_err(component->dev, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1130 | "%s: Invalid port=%pK, ch_mask=%pK, ch_rate=%pK\n", |
| 1131 | __func__, port, ch_mask, ch_rate); |
| 1132 | return -EINVAL; |
| 1133 | } |
| 1134 | for (i = 0; i < num_port; i++) { |
| 1135 | wsa881x->port[i].port_id = port[i]; |
| 1136 | wsa881x->port[i].ch_mask = ch_mask[i]; |
| 1137 | wsa881x->port[i].ch_rate = ch_rate[i]; |
| 1138 | wsa881x->port[i].num_ch = __sw_hweight8(ch_mask[i]); |
Ramprasad Katkam | e38aed4 | 2018-03-07 16:26:49 +0530 | [diff] [blame] | 1139 | if (port_type) |
| 1140 | wsa881x->port[i].port_type = port_type[i]; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1141 | } |
| 1142 | return 0; |
| 1143 | } |
| 1144 | EXPORT_SYMBOL(wsa881x_set_channel_map); |
| 1145 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1146 | static void wsa881x_init(struct snd_soc_component *component) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1147 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1148 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1149 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1150 | wsa881x->version = |
| 1151 | snd_soc_component_read32(component, WSA881X_CHIP_ID1); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1152 | wsa881x_regmap_defaults(wsa881x->regmap, wsa881x->version); |
Vatsal Bucha | 83716b9 | 2017-09-14 12:13:13 +0530 | [diff] [blame] | 1153 | /* Enable software reset output from soundwire slave */ |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1154 | snd_soc_component_update_bits(component, WSA881X_SWR_RESET_EN, |
| 1155 | 0x07, 0x07); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1156 | /* Bring out of analog reset */ |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1157 | snd_soc_component_update_bits(component, WSA881X_CDC_RST_CTL, |
| 1158 | 0x02, 0x02); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1159 | /* Bring out of digital reset */ |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1160 | snd_soc_component_update_bits(component, WSA881X_CDC_RST_CTL, |
| 1161 | 0x01, 0x01); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1162 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1163 | snd_soc_component_update_bits(component, WSA881X_CLOCK_CONFIG, |
| 1164 | 0x10, 0x10); |
| 1165 | snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL, |
| 1166 | 0x02, 0x02); |
| 1167 | snd_soc_component_update_bits(component, WSA881X_SPKR_MISC_CTL1, |
| 1168 | 0xC0, 0x80); |
| 1169 | snd_soc_component_update_bits(component, WSA881X_SPKR_MISC_CTL1, |
| 1170 | 0x06, 0x06); |
| 1171 | snd_soc_component_update_bits(component, WSA881X_SPKR_BIAS_INT, |
| 1172 | 0xFF, 0x00); |
| 1173 | snd_soc_component_update_bits(component, WSA881X_SPKR_PA_INT, |
| 1174 | 0xF0, 0x40); |
| 1175 | snd_soc_component_update_bits(component, WSA881X_SPKR_PA_INT, |
| 1176 | 0x0E, 0x0E); |
| 1177 | snd_soc_component_update_bits(component, WSA881X_BOOST_LOOP_STABILITY, |
| 1178 | 0x03, 0x03); |
| 1179 | snd_soc_component_update_bits(component, WSA881X_BOOST_MISC2_CTL, |
| 1180 | 0xFF, 0x14); |
| 1181 | snd_soc_component_update_bits(component, WSA881X_BOOST_START_CTL, |
| 1182 | 0x80, 0x80); |
| 1183 | snd_soc_component_update_bits(component, WSA881X_BOOST_START_CTL, |
| 1184 | 0x03, 0x00); |
| 1185 | snd_soc_component_update_bits(component, |
| 1186 | WSA881X_BOOST_SLOPE_COMP_ISENSE_FB, |
| 1187 | 0x0C, 0x04); |
| 1188 | snd_soc_component_update_bits(component, |
| 1189 | WSA881X_BOOST_SLOPE_COMP_ISENSE_FB, |
| 1190 | 0x03, 0x00); |
| 1191 | if (snd_soc_component_read32(component, WSA881X_OTP_REG_0)) |
| 1192 | snd_soc_component_update_bits(component, |
| 1193 | WSA881X_BOOST_PRESET_OUT1, |
| 1194 | 0xF0, 0x70); |
| 1195 | snd_soc_component_update_bits(component, WSA881X_BOOST_PRESET_OUT2, |
| 1196 | 0xF0, 0x30); |
| 1197 | snd_soc_component_update_bits(component, WSA881X_SPKR_DRV_EN, |
| 1198 | 0x08, 0x08); |
| 1199 | snd_soc_component_update_bits(component, WSA881X_BOOST_CURRENT_LIMIT, |
| 1200 | 0x0F, 0x08); |
| 1201 | snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL, |
| 1202 | 0x30, 0x30); |
| 1203 | snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL, |
| 1204 | 0x0C, 0x00); |
| 1205 | snd_soc_component_update_bits(component, WSA881X_OTP_REG_28, |
| 1206 | 0x3F, 0x3A); |
| 1207 | snd_soc_component_update_bits(component, WSA881X_BONGO_RESRV_REG1, |
| 1208 | 0xFF, 0xB2); |
| 1209 | snd_soc_component_update_bits(component, WSA881X_BONGO_RESRV_REG2, |
| 1210 | 0xFF, 0x05); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1211 | } |
| 1212 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1213 | static int32_t wsa881x_resource_acquire(struct snd_soc_component *component, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1214 | bool enable) |
| 1215 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1216 | wsa881x_clk_ctrl(component, enable); |
| 1217 | wsa881x_bandgap_ctrl(component, enable); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1218 | return 0; |
| 1219 | } |
| 1220 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1221 | static int32_t wsa881x_temp_reg_read(struct snd_soc_component *component, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1222 | struct wsa_temp_register *wsa_temp_reg) |
| 1223 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1224 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1225 | struct swr_device *dev; |
| 1226 | u8 retry = WSA881X_NUM_RETRY; |
| 1227 | u8 devnum = 0; |
| 1228 | |
| 1229 | if (!wsa881x) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1230 | dev_err(component->dev, "%s: wsa881x is NULL\n", __func__); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1231 | return -EINVAL; |
| 1232 | } |
| 1233 | dev = wsa881x->swr_slave; |
| 1234 | if (dev && (wsa881x->state == WSA881X_DEV_DOWN)) { |
| 1235 | while (swr_get_logical_dev_num(dev, dev->addr, &devnum) && |
| 1236 | retry--) { |
| 1237 | /* Retry after 1 msec delay */ |
| 1238 | usleep_range(1000, 1100); |
| 1239 | } |
| 1240 | if (retry == 0) { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1241 | dev_err(component->dev, |
Xiao Li | d8bb93c | 2020-01-07 12:59:05 +0800 | [diff] [blame] | 1242 | "%s get devnum %d for dev addr %llx failed\n", |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1243 | __func__, devnum, dev->addr); |
| 1244 | return -EINVAL; |
| 1245 | } |
| 1246 | } |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 1247 | wsa881x_regcache_sync(wsa881x); |
| 1248 | mutex_lock(&wsa881x->temp_lock); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1249 | wsa881x_resource_acquire(component, ENABLE); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1250 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1251 | snd_soc_component_update_bits(component, WSA881X_TADC_VALUE_CTL, |
| 1252 | 0x01, 0x00); |
| 1253 | wsa_temp_reg->dmeas_msb = snd_soc_component_read32( |
| 1254 | component, WSA881X_TEMP_MSB); |
| 1255 | wsa_temp_reg->dmeas_lsb = snd_soc_component_read32( |
| 1256 | component, WSA881X_TEMP_LSB); |
| 1257 | snd_soc_component_update_bits(component, WSA881X_TADC_VALUE_CTL, |
| 1258 | 0x01, 0x01); |
| 1259 | wsa_temp_reg->d1_msb = snd_soc_component_read32( |
| 1260 | component, WSA881X_OTP_REG_1); |
| 1261 | wsa_temp_reg->d1_lsb = snd_soc_component_read32( |
| 1262 | component, WSA881X_OTP_REG_2); |
| 1263 | wsa_temp_reg->d2_msb = snd_soc_component_read32( |
| 1264 | component, WSA881X_OTP_REG_3); |
| 1265 | wsa_temp_reg->d2_lsb = snd_soc_component_read32( |
| 1266 | component, WSA881X_OTP_REG_4); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1267 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1268 | wsa881x_resource_acquire(component, DISABLE); |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 1269 | mutex_unlock(&wsa881x->temp_lock); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1270 | |
| 1271 | return 0; |
| 1272 | } |
| 1273 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1274 | static int wsa881x_probe(struct snd_soc_component *component) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1275 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1276 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1277 | struct swr_device *dev; |
| 1278 | |
| 1279 | if (!wsa881x) |
| 1280 | return -EINVAL; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1281 | snd_soc_component_init_regmap(component, wsa881x->regmap); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1282 | |
| 1283 | dev = wsa881x->swr_slave; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1284 | wsa881x->component = component; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1285 | mutex_init(&wsa881x->bg_lock); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1286 | wsa881x_init(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1287 | snprintf(wsa881x->tz_pdata.name, sizeof(wsa881x->tz_pdata.name), |
| 1288 | "%s.%x", "wsatz", (u8)dev->addr); |
| 1289 | wsa881x->bg_cnt = 0; |
| 1290 | wsa881x->clk_cnt = 0; |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1291 | wsa881x->tz_pdata.component = component; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1292 | wsa881x->tz_pdata.wsa_temp_reg_read = wsa881x_temp_reg_read; |
| 1293 | wsa881x_init_thermal(&wsa881x->tz_pdata); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1294 | snd_soc_add_component_controls(component, wsa_snd_controls, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1295 | ARRAY_SIZE(wsa_snd_controls)); |
| 1296 | INIT_DELAYED_WORK(&wsa881x->ocp_ctl_work, wsa881x_ocp_ctl_work); |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1300 | static void wsa881x_remove(struct snd_soc_component *component) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1301 | { |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1302 | struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1303 | |
| 1304 | if (wsa881x->tz_pdata.tz_dev) |
| 1305 | wsa881x_deinit_thermal(wsa881x->tz_pdata.tz_dev); |
| 1306 | mutex_destroy(&wsa881x->bg_lock); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1307 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1308 | return; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1309 | } |
| 1310 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1311 | static const struct snd_soc_component_driver soc_codec_dev_wsa881x = { |
| 1312 | .name = DRV_NAME, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1313 | .probe = wsa881x_probe, |
| 1314 | .remove = wsa881x_remove, |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1315 | .controls = wsa881x_snd_controls, |
| 1316 | .num_controls = ARRAY_SIZE(wsa881x_snd_controls), |
| 1317 | .dapm_widgets = wsa881x_dapm_widgets, |
| 1318 | .num_dapm_widgets = ARRAY_SIZE(wsa881x_dapm_widgets), |
| 1319 | .dapm_routes = wsa881x_audio_map, |
| 1320 | .num_dapm_routes = ARRAY_SIZE(wsa881x_audio_map), |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1321 | }; |
| 1322 | |
| 1323 | static int wsa881x_gpio_ctrl(struct wsa881x_priv *wsa881x, bool enable) |
| 1324 | { |
| 1325 | int ret = 0; |
| 1326 | |
| 1327 | if (wsa881x->pd_gpio < 0) { |
| 1328 | dev_err(wsa881x->dev, "%s: gpio is not valid %d\n", |
| 1329 | __func__, wsa881x->pd_gpio); |
| 1330 | return -EINVAL; |
| 1331 | } |
| 1332 | |
| 1333 | if (wsa881x->wsa_rst_np) { |
| 1334 | if (enable) |
| 1335 | ret = msm_cdc_pinctrl_select_active_state( |
| 1336 | wsa881x->wsa_rst_np); |
| 1337 | else |
| 1338 | ret = msm_cdc_pinctrl_select_sleep_state( |
| 1339 | wsa881x->wsa_rst_np); |
| 1340 | if (ret != 0) |
| 1341 | dev_err(wsa881x->dev, |
| 1342 | "%s: Failed to turn state %d; ret=%d\n", |
| 1343 | __func__, enable, ret); |
| 1344 | } else { |
| 1345 | if (gpio_is_valid(wsa881x->pd_gpio)) |
| 1346 | gpio_direction_output(wsa881x->pd_gpio, enable); |
| 1347 | } |
| 1348 | |
| 1349 | return ret; |
| 1350 | } |
| 1351 | |
| 1352 | static int wsa881x_gpio_init(struct swr_device *pdev) |
| 1353 | { |
| 1354 | int ret = 0; |
| 1355 | struct wsa881x_priv *wsa881x; |
| 1356 | |
| 1357 | wsa881x = swr_get_dev_data(pdev); |
| 1358 | if (!wsa881x) { |
| 1359 | dev_err(&pdev->dev, "%s: wsa881x is NULL\n", __func__); |
| 1360 | return -EINVAL; |
| 1361 | } |
| 1362 | dev_dbg(&pdev->dev, "%s: gpio %d request with name %s\n", |
| 1363 | __func__, wsa881x->pd_gpio, dev_name(&pdev->dev)); |
| 1364 | ret = gpio_request(wsa881x->pd_gpio, dev_name(&pdev->dev)); |
| 1365 | if (ret) { |
| 1366 | if (ret == -EBUSY) { |
| 1367 | /* GPIO was already requested */ |
| 1368 | dev_dbg(&pdev->dev, |
| 1369 | "%s: gpio %d is already set to high\n", |
| 1370 | __func__, wsa881x->pd_gpio); |
| 1371 | ret = 0; |
| 1372 | } else { |
| 1373 | dev_err(&pdev->dev, "%s: Failed to request gpio %d, err: %d\n", |
| 1374 | __func__, wsa881x->pd_gpio, ret); |
| 1375 | } |
| 1376 | } |
| 1377 | return ret; |
| 1378 | } |
| 1379 | |
Karthikeyan Mani | 13485b7 | 2019-08-05 17:51:14 -0700 | [diff] [blame] | 1380 | static int wsa881x_event_notify(struct notifier_block *nb, |
| 1381 | unsigned long val, void *ptr) |
| 1382 | { |
| 1383 | u16 event = (val & 0xffff); |
| 1384 | struct wsa881x_priv *wsa881x = container_of(nb, struct wsa881x_priv, |
| 1385 | bolero_nblock); |
| 1386 | |
| 1387 | if (!wsa881x) |
| 1388 | return -EINVAL; |
| 1389 | |
| 1390 | switch (event) { |
| 1391 | case BOLERO_WSA_EVT_PA_OFF_PRE_SSR: |
| 1392 | snd_soc_component_update_bits(wsa881x->component, |
| 1393 | WSA881X_SPKR_DRV_GAIN, |
| 1394 | 0xF0, 0xC0); |
| 1395 | snd_soc_component_update_bits(wsa881x->component, |
| 1396 | WSA881X_SPKR_DRV_EN, |
| 1397 | 0x80, 0x00); |
| 1398 | break; |
Laxminath Kasam | 069df14 | 2019-09-17 23:43:34 +0530 | [diff] [blame] | 1399 | case BOLERO_WSA_EVT_PA_ON_POST_FSCLK: |
Laxminath Kasam | 2fe71f5 | 2020-05-15 00:39:51 +0530 | [diff] [blame] | 1400 | case BOLERO_WSA_EVT_PA_ON_POST_FSCLK_ADIE_LB: |
Laxminath Kasam | 069df14 | 2019-09-17 23:43:34 +0530 | [diff] [blame] | 1401 | if ((snd_soc_component_read32(wsa881x->component, |
| 1402 | WSA881X_SPKR_DAC_CTL) & 0x80) == 0x80) |
| 1403 | snd_soc_component_update_bits(wsa881x->component, |
| 1404 | WSA881X_SPKR_DRV_EN, |
| 1405 | 0x80, 0x80); |
Laxminath Kasam | d6b6294 | 2019-11-05 12:38:20 +0530 | [diff] [blame] | 1406 | break; |
Karthikeyan Mani | 13485b7 | 2019-08-05 17:51:14 -0700 | [diff] [blame] | 1407 | default: |
| 1408 | break; |
| 1409 | } |
| 1410 | |
| 1411 | return 0; |
| 1412 | } |
| 1413 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1414 | static int wsa881x_swr_probe(struct swr_device *pdev) |
| 1415 | { |
| 1416 | int ret = 0; |
| 1417 | struct wsa881x_priv *wsa881x; |
| 1418 | u8 devnum = 0; |
| 1419 | bool pin_state_current = false; |
Karthikeyan Mani | 13485b7 | 2019-08-05 17:51:14 -0700 | [diff] [blame] | 1420 | struct wsa_ctrl_platform_data *plat_data = NULL; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1421 | |
| 1422 | wsa881x = devm_kzalloc(&pdev->dev, sizeof(struct wsa881x_priv), |
| 1423 | GFP_KERNEL); |
| 1424 | if (!wsa881x) |
| 1425 | return -ENOMEM; |
| 1426 | wsa881x->wsa_rst_np = of_parse_phandle(pdev->dev.of_node, |
| 1427 | "qcom,spkr-sd-n-node", 0); |
| 1428 | if (!wsa881x->wsa_rst_np) { |
| 1429 | dev_dbg(&pdev->dev, "%s: Not using pinctrl, fallback to gpio\n", |
| 1430 | __func__); |
| 1431 | wsa881x->pd_gpio = of_get_named_gpio(pdev->dev.of_node, |
| 1432 | "qcom,spkr-sd-n-gpio", 0); |
| 1433 | if (wsa881x->pd_gpio < 0) { |
| 1434 | dev_err(&pdev->dev, "%s: %s property is not found %d\n", |
| 1435 | __func__, "qcom,spkr-sd-n-gpio", |
| 1436 | wsa881x->pd_gpio); |
| 1437 | goto err; |
| 1438 | } |
| 1439 | dev_dbg(&pdev->dev, "%s: reset gpio %d\n", __func__, |
| 1440 | wsa881x->pd_gpio); |
| 1441 | } |
| 1442 | swr_set_dev_data(pdev, wsa881x); |
| 1443 | |
| 1444 | wsa881x->swr_slave = pdev; |
| 1445 | |
| 1446 | if (!wsa881x->wsa_rst_np) { |
| 1447 | ret = wsa881x_gpio_init(pdev); |
| 1448 | if (ret) |
| 1449 | goto err; |
| 1450 | } |
| 1451 | if (wsa881x->wsa_rst_np) |
| 1452 | pin_state_current = msm_cdc_pinctrl_get_state( |
| 1453 | wsa881x->wsa_rst_np); |
| 1454 | wsa881x_gpio_ctrl(wsa881x, true); |
| 1455 | wsa881x->state = WSA881X_DEV_UP; |
| 1456 | |
| 1457 | if (!debugfs_wsa881x_dent) { |
| 1458 | dbgwsa881x = wsa881x; |
| 1459 | debugfs_wsa881x_dent = debugfs_create_dir( |
| 1460 | "wsa881x_swr_slave", 0); |
| 1461 | if (!IS_ERR(debugfs_wsa881x_dent)) { |
| 1462 | debugfs_peek = debugfs_create_file("swrslave_peek", |
| 1463 | S_IFREG | 0444, debugfs_wsa881x_dent, |
| 1464 | (void *) "swrslave_peek", |
| 1465 | &codec_debug_ops); |
| 1466 | |
| 1467 | debugfs_poke = debugfs_create_file("swrslave_poke", |
| 1468 | S_IFREG | 0444, debugfs_wsa881x_dent, |
| 1469 | (void *) "swrslave_poke", |
| 1470 | &codec_debug_ops); |
| 1471 | |
| 1472 | debugfs_reg_dump = debugfs_create_file( |
| 1473 | "swrslave_reg_dump", |
| 1474 | S_IFREG | 0444, |
| 1475 | debugfs_wsa881x_dent, |
| 1476 | (void *) "swrslave_reg_dump", |
| 1477 | &codec_debug_ops); |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | /* |
| 1482 | * Add 5msec delay to provide sufficient time for |
| 1483 | * soundwire auto enumeration of slave devices as |
| 1484 | * as per HW requirement. |
| 1485 | */ |
| 1486 | usleep_range(5000, 5010); |
| 1487 | ret = swr_get_logical_dev_num(pdev, pdev->addr, &devnum); |
| 1488 | if (ret) { |
| 1489 | dev_dbg(&pdev->dev, |
Xiao Li | d8bb93c | 2020-01-07 12:59:05 +0800 | [diff] [blame] | 1490 | "%s get devnum %d for dev addr %llx failed\n", |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1491 | __func__, devnum, pdev->addr); |
| 1492 | goto dev_err; |
| 1493 | } |
| 1494 | pdev->dev_num = devnum; |
| 1495 | |
| 1496 | wsa881x->regmap = devm_regmap_init_swr(pdev, |
| 1497 | &wsa881x_regmap_config); |
| 1498 | if (IS_ERR(wsa881x->regmap)) { |
| 1499 | ret = PTR_ERR(wsa881x->regmap); |
| 1500 | dev_err(&pdev->dev, "%s: regmap_init failed %d\n", |
| 1501 | __func__, ret); |
| 1502 | goto dev_err; |
| 1503 | } |
| 1504 | |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1505 | ret = snd_soc_register_component(&pdev->dev, &soc_codec_dev_wsa881x, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1506 | NULL, 0); |
| 1507 | if (ret) { |
| 1508 | dev_err(&pdev->dev, "%s: Codec registration failed\n", |
| 1509 | __func__); |
| 1510 | goto dev_err; |
| 1511 | } |
Karthikeyan Mani | 13485b7 | 2019-08-05 17:51:14 -0700 | [diff] [blame] | 1512 | |
| 1513 | wsa881x->bolero_np = of_parse_phandle(pdev->dev.of_node, |
| 1514 | "qcom,bolero-handle", 0); |
| 1515 | if (wsa881x->bolero_np) { |
| 1516 | wsa881x->bolero_dev = |
| 1517 | of_find_device_by_node(wsa881x->bolero_np); |
| 1518 | if (wsa881x->bolero_dev) { |
| 1519 | plat_data = dev_get_platdata(&wsa881x->bolero_dev->dev); |
| 1520 | if (plat_data) { |
| 1521 | wsa881x->bolero_nblock.notifier_call = |
| 1522 | wsa881x_event_notify; |
| 1523 | if (plat_data->register_notifier) |
| 1524 | plat_data->register_notifier( |
| 1525 | plat_data->handle, |
| 1526 | &wsa881x->bolero_nblock, |
| 1527 | true); |
| 1528 | wsa881x->register_notifier = |
| 1529 | plat_data->register_notifier; |
| 1530 | wsa881x->handle = plat_data->handle; |
| 1531 | } else { |
| 1532 | dev_err(&pdev->dev, "%s: plat data not found\n", |
| 1533 | __func__); |
| 1534 | } |
| 1535 | } else { |
| 1536 | dev_err(&pdev->dev, "%s: bolero dev not found\n", |
| 1537 | __func__); |
| 1538 | } |
| 1539 | } else { |
| 1540 | dev_info(&pdev->dev, "%s: bolero node not found\n", __func__); |
| 1541 | } |
| 1542 | |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 1543 | mutex_init(&wsa881x->res_lock); |
| 1544 | mutex_init(&wsa881x->temp_lock); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1545 | |
| 1546 | return 0; |
| 1547 | |
| 1548 | dev_err: |
| 1549 | if (pin_state_current == false) |
| 1550 | wsa881x_gpio_ctrl(wsa881x, false); |
| 1551 | swr_remove_device(pdev); |
| 1552 | err: |
| 1553 | return ret; |
| 1554 | } |
| 1555 | |
| 1556 | static int wsa881x_swr_remove(struct swr_device *pdev) |
| 1557 | { |
| 1558 | struct wsa881x_priv *wsa881x; |
| 1559 | |
| 1560 | wsa881x = swr_get_dev_data(pdev); |
| 1561 | if (!wsa881x) { |
| 1562 | dev_err(&pdev->dev, "%s: wsa881x is NULL\n", __func__); |
| 1563 | return -EINVAL; |
| 1564 | } |
Karthikeyan Mani | 13485b7 | 2019-08-05 17:51:14 -0700 | [diff] [blame] | 1565 | |
| 1566 | if (wsa881x->register_notifier) |
| 1567 | wsa881x->register_notifier(wsa881x->handle, |
| 1568 | &wsa881x->bolero_nblock, false); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1569 | debugfs_remove_recursive(debugfs_wsa881x_dent); |
| 1570 | debugfs_wsa881x_dent = NULL; |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 1571 | mutex_destroy(&wsa881x->res_lock); |
| 1572 | mutex_destroy(&wsa881x->temp_lock); |
Meng Wang | 15c825d | 2018-09-06 10:49:18 +0800 | [diff] [blame] | 1573 | snd_soc_unregister_component(&pdev->dev); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1574 | if (wsa881x->pd_gpio) |
| 1575 | gpio_free(wsa881x->pd_gpio); |
| 1576 | swr_set_dev_data(pdev, NULL); |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
| 1580 | static int wsa881x_swr_up(struct swr_device *pdev) |
| 1581 | { |
| 1582 | int ret; |
| 1583 | struct wsa881x_priv *wsa881x; |
| 1584 | |
| 1585 | wsa881x = swr_get_dev_data(pdev); |
| 1586 | if (!wsa881x) { |
| 1587 | dev_err(&pdev->dev, "%s: wsa881x is NULL\n", __func__); |
| 1588 | return -EINVAL; |
| 1589 | } |
| 1590 | ret = wsa881x_gpio_ctrl(wsa881x, true); |
| 1591 | if (ret) |
| 1592 | dev_err(&pdev->dev, "%s: Failed to enable gpio\n", __func__); |
| 1593 | else |
| 1594 | wsa881x->state = WSA881X_DEV_UP; |
| 1595 | |
| 1596 | return ret; |
| 1597 | } |
| 1598 | |
| 1599 | static int wsa881x_swr_down(struct swr_device *pdev) |
| 1600 | { |
| 1601 | struct wsa881x_priv *wsa881x; |
| 1602 | int ret; |
| 1603 | |
| 1604 | wsa881x = swr_get_dev_data(pdev); |
| 1605 | if (!wsa881x) { |
| 1606 | dev_err(&pdev->dev, "%s: wsa881x is NULL\n", __func__); |
| 1607 | return -EINVAL; |
| 1608 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1609 | ret = wsa881x_gpio_ctrl(wsa881x, false); |
| 1610 | if (ret) |
| 1611 | dev_err(&pdev->dev, "%s: Failed to disable gpio\n", __func__); |
| 1612 | else |
| 1613 | wsa881x->state = WSA881X_DEV_DOWN; |
| 1614 | |
| 1615 | return ret; |
| 1616 | } |
| 1617 | |
| 1618 | static int wsa881x_swr_reset(struct swr_device *pdev) |
| 1619 | { |
| 1620 | struct wsa881x_priv *wsa881x; |
| 1621 | u8 retry = WSA881X_NUM_RETRY; |
| 1622 | u8 devnum = 0; |
| 1623 | |
| 1624 | wsa881x = swr_get_dev_data(pdev); |
| 1625 | if (!wsa881x) { |
| 1626 | dev_err(&pdev->dev, "%s: wsa881x is NULL\n", __func__); |
| 1627 | return -EINVAL; |
| 1628 | } |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 1629 | if (wsa881x->state == WSA881X_DEV_READY) { |
| 1630 | dev_dbg(&pdev->dev, "%s: device already active\n", __func__); |
| 1631 | return 0; |
| 1632 | } |
| 1633 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1634 | wsa881x->bg_cnt = 0; |
| 1635 | wsa881x->clk_cnt = 0; |
| 1636 | while (swr_get_logical_dev_num(pdev, pdev->addr, &devnum) && retry--) { |
| 1637 | /* Retry after 1 msec delay */ |
| 1638 | usleep_range(1000, 1100); |
| 1639 | } |
| 1640 | pdev->dev_num = devnum; |
Laxminath Kasam | c0684fc | 2018-07-31 19:26:56 +0530 | [diff] [blame] | 1641 | wsa881x_regcache_sync(wsa881x); |
| 1642 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | #ifdef CONFIG_PM_SLEEP |
| 1647 | static int wsa881x_swr_suspend(struct device *dev) |
| 1648 | { |
| 1649 | dev_dbg(dev, "%s: system suspend\n", __func__); |
| 1650 | return 0; |
| 1651 | } |
| 1652 | |
| 1653 | static int wsa881x_swr_resume(struct device *dev) |
| 1654 | { |
| 1655 | struct wsa881x_priv *wsa881x = swr_get_dev_data(to_swr_device(dev)); |
| 1656 | |
| 1657 | if (!wsa881x) { |
| 1658 | dev_err(dev, "%s: wsa881x private data is NULL\n", __func__); |
| 1659 | return -EINVAL; |
| 1660 | } |
| 1661 | dev_dbg(dev, "%s: system resume\n", __func__); |
| 1662 | return 0; |
| 1663 | } |
| 1664 | #endif /* CONFIG_PM_SLEEP */ |
| 1665 | |
| 1666 | static const struct dev_pm_ops wsa881x_swr_pm_ops = { |
| 1667 | SET_SYSTEM_SLEEP_PM_OPS(wsa881x_swr_suspend, wsa881x_swr_resume) |
| 1668 | }; |
| 1669 | |
| 1670 | static const struct swr_device_id wsa881x_swr_id[] = { |
| 1671 | {"wsa881x", 0}, |
| 1672 | {} |
| 1673 | }; |
| 1674 | |
| 1675 | static const struct of_device_id wsa881x_swr_dt_match[] = { |
| 1676 | { |
| 1677 | .compatible = "qcom,wsa881x", |
| 1678 | }, |
| 1679 | {} |
| 1680 | }; |
| 1681 | |
| 1682 | static struct swr_driver wsa881x_codec_driver = { |
| 1683 | .driver = { |
| 1684 | .name = "wsa881x", |
| 1685 | .owner = THIS_MODULE, |
| 1686 | .pm = &wsa881x_swr_pm_ops, |
| 1687 | .of_match_table = wsa881x_swr_dt_match, |
| 1688 | }, |
| 1689 | .probe = wsa881x_swr_probe, |
| 1690 | .remove = wsa881x_swr_remove, |
| 1691 | .id_table = wsa881x_swr_id, |
| 1692 | .device_up = wsa881x_swr_up, |
| 1693 | .device_down = wsa881x_swr_down, |
| 1694 | .reset_device = wsa881x_swr_reset, |
| 1695 | }; |
| 1696 | |
| 1697 | static int __init wsa881x_codec_init(void) |
| 1698 | { |
| 1699 | return swr_driver_register(&wsa881x_codec_driver); |
| 1700 | } |
| 1701 | |
| 1702 | static void __exit wsa881x_codec_exit(void) |
| 1703 | { |
| 1704 | swr_driver_unregister(&wsa881x_codec_driver); |
| 1705 | } |
| 1706 | |
| 1707 | module_init(wsa881x_codec_init); |
| 1708 | module_exit(wsa881x_codec_exit); |
| 1709 | |
| 1710 | MODULE_DESCRIPTION("WSA881x Codec driver"); |
| 1711 | MODULE_LICENSE("GPL v2"); |