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