cs35l32.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * cs35l32.c -- CS35L32 ALSA SoC audio driver
  3. *
  4. * Copyright 2014 CirrusLogic, Inc.
  5. *
  6. * Author: Brian Austin <brian.austin@cirrus.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/version.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/delay.h>
  19. #include <linux/i2c.h>
  20. #include <linux/gpio.h>
  21. #include <linux/regmap.h>
  22. #include <linux/slab.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/regulator/consumer.h>
  25. #include <linux/gpio/consumer.h>
  26. #include <linux/of_device.h>
  27. #include <sound/core.h>
  28. #include <sound/pcm.h>
  29. #include <sound/pcm_params.h>
  30. #include <sound/soc.h>
  31. #include <sound/soc-dapm.h>
  32. #include <sound/initval.h>
  33. #include <sound/tlv.h>
  34. #include <dt-bindings/sound/cs35l32.h>
  35. #include "cs35l32.h"
  36. #define CS35L32_NUM_SUPPLIES 2
  37. static const char *const cs35l32_supply_names[CS35L32_NUM_SUPPLIES] = {
  38. "VA",
  39. "VP",
  40. };
  41. struct cs35l32_private {
  42. struct regmap *regmap;
  43. struct snd_soc_codec *codec;
  44. struct regulator_bulk_data supplies[CS35L32_NUM_SUPPLIES];
  45. struct cs35l32_platform_data pdata;
  46. struct gpio_desc *reset_gpio;
  47. };
  48. static const struct reg_default cs35l32_reg_defaults[] = {
  49. { 0x06, 0x04 }, /* Power Ctl 1 */
  50. { 0x07, 0xE8 }, /* Power Ctl 2 */
  51. { 0x08, 0x40 }, /* Clock Ctl */
  52. { 0x09, 0x20 }, /* Low Battery Threshold */
  53. { 0x0A, 0x00 }, /* Voltage Monitor [RO] */
  54. { 0x0B, 0x40 }, /* Conv Peak Curr Protection CTL */
  55. { 0x0C, 0x07 }, /* IMON Scaling */
  56. { 0x0D, 0x03 }, /* Audio/LED Pwr Manager */
  57. { 0x0F, 0x20 }, /* Serial Port Control */
  58. { 0x10, 0x14 }, /* Class D Amp CTL */
  59. { 0x11, 0x00 }, /* Protection Release CTL */
  60. { 0x12, 0xFF }, /* Interrupt Mask 1 */
  61. { 0x13, 0xFF }, /* Interrupt Mask 2 */
  62. { 0x14, 0xFF }, /* Interrupt Mask 3 */
  63. { 0x19, 0x00 }, /* LED Flash Mode Current */
  64. { 0x1A, 0x00 }, /* LED Movie Mode Current */
  65. { 0x1B, 0x20 }, /* LED Flash Timer */
  66. { 0x1C, 0x00 }, /* LED Flash Inhibit Current */
  67. };
  68. static bool cs35l32_readable_register(struct device *dev, unsigned int reg)
  69. {
  70. switch (reg) {
  71. case CS35L32_DEVID_AB:
  72. case CS35L32_DEVID_CD:
  73. case CS35L32_DEVID_E:
  74. case CS35L32_FAB_ID:
  75. case CS35L32_REV_ID:
  76. case CS35L32_PWRCTL1:
  77. case CS35L32_PWRCTL2:
  78. case CS35L32_CLK_CTL:
  79. case CS35L32_BATT_THRESHOLD:
  80. case CS35L32_VMON:
  81. case CS35L32_BST_CPCP_CTL:
  82. case CS35L32_IMON_SCALING:
  83. case CS35L32_AUDIO_LED_MNGR:
  84. case CS35L32_ADSP_CTL:
  85. case CS35L32_CLASSD_CTL:
  86. case CS35L32_PROTECT_CTL:
  87. case CS35L32_INT_MASK_1:
  88. case CS35L32_INT_MASK_2:
  89. case CS35L32_INT_MASK_3:
  90. case CS35L32_INT_STATUS_1:
  91. case CS35L32_INT_STATUS_2:
  92. case CS35L32_INT_STATUS_3:
  93. case CS35L32_LED_STATUS:
  94. case CS35L32_FLASH_MODE:
  95. case CS35L32_MOVIE_MODE:
  96. case CS35L32_FLASH_TIMER:
  97. case CS35L32_FLASH_INHIBIT:
  98. return true;
  99. default:
  100. return false;
  101. }
  102. }
  103. static bool cs35l32_volatile_register(struct device *dev, unsigned int reg)
  104. {
  105. switch (reg) {
  106. case CS35L32_DEVID_AB:
  107. case CS35L32_DEVID_CD:
  108. case CS35L32_DEVID_E:
  109. case CS35L32_FAB_ID:
  110. case CS35L32_REV_ID:
  111. case CS35L32_INT_STATUS_1:
  112. case CS35L32_INT_STATUS_2:
  113. case CS35L32_INT_STATUS_3:
  114. case CS35L32_LED_STATUS:
  115. return true;
  116. default:
  117. return false;
  118. }
  119. }
  120. static bool cs35l32_precious_register(struct device *dev, unsigned int reg)
  121. {
  122. switch (reg) {
  123. case CS35L32_INT_STATUS_1:
  124. case CS35L32_INT_STATUS_2:
  125. case CS35L32_INT_STATUS_3:
  126. case CS35L32_LED_STATUS:
  127. return true;
  128. default:
  129. return false;
  130. }
  131. }
  132. static DECLARE_TLV_DB_SCALE(classd_ctl_tlv, 900, 300, 0);
  133. static const struct snd_kcontrol_new imon_ctl =
  134. SOC_DAPM_SINGLE("Switch", CS35L32_PWRCTL2, 6, 1, 1);
  135. static const struct snd_kcontrol_new vmon_ctl =
  136. SOC_DAPM_SINGLE("Switch", CS35L32_PWRCTL2, 7, 1, 1);
  137. static const struct snd_kcontrol_new vpmon_ctl =
  138. SOC_DAPM_SINGLE("Switch", CS35L32_PWRCTL2, 5, 1, 1);
  139. static const struct snd_kcontrol_new cs35l32_snd_controls[] = {
  140. SOC_SINGLE_TLV("Speaker Volume", CS35L32_CLASSD_CTL,
  141. 3, 0x04, 1, classd_ctl_tlv),
  142. SOC_SINGLE("Zero Cross Switch", CS35L32_CLASSD_CTL, 2, 1, 0),
  143. SOC_SINGLE("Gain Manager Switch", CS35L32_AUDIO_LED_MNGR, 3, 1, 0),
  144. };
  145. static const struct snd_soc_dapm_widget cs35l32_dapm_widgets[] = {
  146. SND_SOC_DAPM_SUPPLY("BOOST", CS35L32_PWRCTL1, 2, 1, NULL, 0),
  147. SND_SOC_DAPM_OUT_DRV("Speaker", CS35L32_PWRCTL1, 7, 1, NULL, 0),
  148. SND_SOC_DAPM_AIF_OUT("SDOUT", NULL, 0, CS35L32_PWRCTL2, 3, 1),
  149. SND_SOC_DAPM_INPUT("VP"),
  150. SND_SOC_DAPM_INPUT("ISENSE"),
  151. SND_SOC_DAPM_INPUT("VSENSE"),
  152. SND_SOC_DAPM_SWITCH("VMON ADC", CS35L32_PWRCTL2, 7, 1, &vmon_ctl),
  153. SND_SOC_DAPM_SWITCH("IMON ADC", CS35L32_PWRCTL2, 6, 1, &imon_ctl),
  154. SND_SOC_DAPM_SWITCH("VPMON ADC", CS35L32_PWRCTL2, 5, 1, &vpmon_ctl),
  155. };
  156. static const struct snd_soc_dapm_route cs35l32_audio_map[] = {
  157. {"Speaker", NULL, "BOOST"},
  158. {"VMON ADC", NULL, "VSENSE"},
  159. {"IMON ADC", NULL, "ISENSE"},
  160. {"VPMON ADC", NULL, "VP"},
  161. {"SDOUT", "Switch", "VMON ADC"},
  162. {"SDOUT", "Switch", "IMON ADC"},
  163. {"SDOUT", "Switch", "VPMON ADC"},
  164. {"Capture", NULL, "SDOUT"},
  165. };
  166. static int cs35l32_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
  167. {
  168. struct snd_soc_codec *codec = codec_dai->codec;
  169. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  170. case SND_SOC_DAIFMT_CBM_CFM:
  171. snd_soc_update_bits(codec, CS35L32_ADSP_CTL,
  172. CS35L32_ADSP_MASTER_MASK,
  173. CS35L32_ADSP_MASTER_MASK);
  174. break;
  175. case SND_SOC_DAIFMT_CBS_CFS:
  176. snd_soc_update_bits(codec, CS35L32_ADSP_CTL,
  177. CS35L32_ADSP_MASTER_MASK, 0);
  178. break;
  179. default:
  180. return -EINVAL;
  181. }
  182. return 0;
  183. }
  184. static int cs35l32_set_tristate(struct snd_soc_dai *dai, int tristate)
  185. {
  186. struct snd_soc_codec *codec = dai->codec;
  187. return snd_soc_update_bits(codec, CS35L32_PWRCTL2,
  188. CS35L32_SDOUT_3ST, tristate << 3);
  189. }
  190. static const struct snd_soc_dai_ops cs35l32_ops = {
  191. .set_fmt = cs35l32_set_dai_fmt,
  192. .set_tristate = cs35l32_set_tristate,
  193. };
  194. static struct snd_soc_dai_driver cs35l32_dai[] = {
  195. {
  196. .name = "cs35l32-monitor",
  197. .id = 0,
  198. .capture = {
  199. .stream_name = "Capture",
  200. .channels_min = 2,
  201. .channels_max = 2,
  202. .rates = CS35L32_RATES,
  203. .formats = CS35L32_FORMATS,
  204. },
  205. .ops = &cs35l32_ops,
  206. .symmetric_rates = 1,
  207. }
  208. };
  209. static int cs35l32_codec_set_sysclk(struct snd_soc_codec *codec,
  210. int clk_id, int source, unsigned int freq, int dir)
  211. {
  212. unsigned int val;
  213. switch (freq) {
  214. case 6000000:
  215. val = CS35L32_MCLK_RATIO;
  216. break;
  217. case 12000000:
  218. val = CS35L32_MCLK_DIV2_MASK | CS35L32_MCLK_RATIO;
  219. break;
  220. case 6144000:
  221. val = 0;
  222. break;
  223. case 12288000:
  224. val = CS35L32_MCLK_DIV2_MASK;
  225. break;
  226. default:
  227. return -EINVAL;
  228. }
  229. return snd_soc_update_bits(codec, CS35L32_CLK_CTL,
  230. CS35L32_MCLK_DIV2_MASK | CS35L32_MCLK_RATIO_MASK, val);
  231. }
  232. static struct snd_soc_codec_driver soc_codec_dev_cs35l32 = {
  233. .set_sysclk = cs35l32_codec_set_sysclk,
  234. .dapm_widgets = cs35l32_dapm_widgets,
  235. .num_dapm_widgets = ARRAY_SIZE(cs35l32_dapm_widgets),
  236. .dapm_routes = cs35l32_audio_map,
  237. .num_dapm_routes = ARRAY_SIZE(cs35l32_audio_map),
  238. .controls = cs35l32_snd_controls,
  239. .num_controls = ARRAY_SIZE(cs35l32_snd_controls),
  240. };
  241. /* Current and threshold powerup sequence Pg37 in datasheet */
  242. static const struct reg_default cs35l32_monitor_patch[] = {
  243. { 0x00, 0x99 },
  244. { 0x48, 0x17 },
  245. { 0x49, 0x56 },
  246. { 0x43, 0x01 },
  247. { 0x3B, 0x62 },
  248. { 0x3C, 0x80 },
  249. { 0x00, 0x00 },
  250. };
  251. static struct regmap_config cs35l32_regmap = {
  252. .reg_bits = 8,
  253. .val_bits = 8,
  254. .max_register = CS35L32_MAX_REGISTER,
  255. .reg_defaults = cs35l32_reg_defaults,
  256. .num_reg_defaults = ARRAY_SIZE(cs35l32_reg_defaults),
  257. .volatile_reg = cs35l32_volatile_register,
  258. .readable_reg = cs35l32_readable_register,
  259. .precious_reg = cs35l32_precious_register,
  260. .cache_type = REGCACHE_RBTREE,
  261. };
  262. static int cs35l32_handle_of_data(struct i2c_client *i2c_client,
  263. struct cs35l32_platform_data *pdata)
  264. {
  265. struct device_node *np = i2c_client->dev.of_node;
  266. unsigned int val;
  267. if (of_property_read_u32(np, "cirrus,sdout-share", &val) >= 0)
  268. pdata->sdout_share = val;
  269. of_property_read_u32(np, "cirrus,boost-manager", &val);
  270. switch (val) {
  271. case CS35L32_BOOST_MGR_AUTO:
  272. case CS35L32_BOOST_MGR_AUTO_AUDIO:
  273. case CS35L32_BOOST_MGR_BYPASS:
  274. case CS35L32_BOOST_MGR_FIXED:
  275. pdata->boost_mng = val;
  276. break;
  277. default:
  278. dev_err(&i2c_client->dev,
  279. "Wrong cirrus,boost-manager DT value %d\n", val);
  280. pdata->boost_mng = CS35L32_BOOST_MGR_BYPASS;
  281. }
  282. of_property_read_u32(np, "cirrus,sdout-datacfg", &val);
  283. switch (val) {
  284. case CS35L32_DATA_CFG_LR_VP:
  285. case CS35L32_DATA_CFG_LR_STAT:
  286. case CS35L32_DATA_CFG_LR:
  287. case CS35L32_DATA_CFG_LR_VPSTAT:
  288. pdata->sdout_datacfg = val;
  289. break;
  290. default:
  291. dev_err(&i2c_client->dev,
  292. "Wrong cirrus,sdout-datacfg DT value %d\n", val);
  293. pdata->sdout_datacfg = CS35L32_DATA_CFG_LR;
  294. }
  295. of_property_read_u32(np, "cirrus,battery-threshold", &val);
  296. switch (val) {
  297. case CS35L32_BATT_THRESH_3_1V:
  298. case CS35L32_BATT_THRESH_3_2V:
  299. case CS35L32_BATT_THRESH_3_3V:
  300. case CS35L32_BATT_THRESH_3_4V:
  301. pdata->batt_thresh = val;
  302. break;
  303. default:
  304. dev_err(&i2c_client->dev,
  305. "Wrong cirrus,battery-threshold DT value %d\n", val);
  306. pdata->batt_thresh = CS35L32_BATT_THRESH_3_3V;
  307. }
  308. of_property_read_u32(np, "cirrus,battery-recovery", &val);
  309. switch (val) {
  310. case CS35L32_BATT_RECOV_3_1V:
  311. case CS35L32_BATT_RECOV_3_2V:
  312. case CS35L32_BATT_RECOV_3_3V:
  313. case CS35L32_BATT_RECOV_3_4V:
  314. case CS35L32_BATT_RECOV_3_5V:
  315. case CS35L32_BATT_RECOV_3_6V:
  316. pdata->batt_recov = val;
  317. break;
  318. default:
  319. dev_err(&i2c_client->dev,
  320. "Wrong cirrus,battery-recovery DT value %d\n", val);
  321. pdata->batt_recov = CS35L32_BATT_RECOV_3_4V;
  322. }
  323. return 0;
  324. }
  325. static int cs35l32_i2c_probe(struct i2c_client *i2c_client,
  326. const struct i2c_device_id *id)
  327. {
  328. struct cs35l32_private *cs35l32;
  329. struct cs35l32_platform_data *pdata =
  330. dev_get_platdata(&i2c_client->dev);
  331. int ret, i;
  332. unsigned int devid = 0;
  333. unsigned int reg;
  334. cs35l32 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs35l32_private),
  335. GFP_KERNEL);
  336. if (!cs35l32) {
  337. dev_err(&i2c_client->dev, "could not allocate codec\n");
  338. return -ENOMEM;
  339. }
  340. i2c_set_clientdata(i2c_client, cs35l32);
  341. cs35l32->regmap = devm_regmap_init_i2c(i2c_client, &cs35l32_regmap);
  342. if (IS_ERR(cs35l32->regmap)) {
  343. ret = PTR_ERR(cs35l32->regmap);
  344. dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret);
  345. return ret;
  346. }
  347. if (pdata) {
  348. cs35l32->pdata = *pdata;
  349. } else {
  350. pdata = devm_kzalloc(&i2c_client->dev,
  351. sizeof(struct cs35l32_platform_data),
  352. GFP_KERNEL);
  353. if (!pdata) {
  354. dev_err(&i2c_client->dev, "could not allocate pdata\n");
  355. return -ENOMEM;
  356. }
  357. if (i2c_client->dev.of_node) {
  358. ret = cs35l32_handle_of_data(i2c_client,
  359. &cs35l32->pdata);
  360. if (ret != 0)
  361. return ret;
  362. }
  363. }
  364. for (i = 0; i < ARRAY_SIZE(cs35l32->supplies); i++)
  365. cs35l32->supplies[i].supply = cs35l32_supply_names[i];
  366. ret = devm_regulator_bulk_get(&i2c_client->dev,
  367. ARRAY_SIZE(cs35l32->supplies),
  368. cs35l32->supplies);
  369. if (ret != 0) {
  370. dev_err(&i2c_client->dev,
  371. "Failed to request supplies: %d\n", ret);
  372. return ret;
  373. }
  374. ret = regulator_bulk_enable(ARRAY_SIZE(cs35l32->supplies),
  375. cs35l32->supplies);
  376. if (ret != 0) {
  377. dev_err(&i2c_client->dev,
  378. "Failed to enable supplies: %d\n", ret);
  379. return ret;
  380. }
  381. /* Reset the Device */
  382. cs35l32->reset_gpio = devm_gpiod_get(&i2c_client->dev,
  383. "reset-gpios");
  384. if (IS_ERR(cs35l32->reset_gpio)) {
  385. ret = PTR_ERR(cs35l32->reset_gpio);
  386. if (ret != -ENOENT && ret != -ENOSYS)
  387. return ret;
  388. cs35l32->reset_gpio = NULL;
  389. } else {
  390. ret = gpiod_direction_output(cs35l32->reset_gpio, 0);
  391. if (ret)
  392. return ret;
  393. gpiod_set_value_cansleep(cs35l32->reset_gpio, 1);
  394. }
  395. /* initialize codec */
  396. ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_AB, &reg);
  397. devid = (reg & 0xFF) << 12;
  398. ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_CD, &reg);
  399. devid |= (reg & 0xFF) << 4;
  400. ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_E, &reg);
  401. devid |= (reg & 0xF0) >> 4;
  402. if (devid != CS35L32_CHIP_ID) {
  403. ret = -ENODEV;
  404. dev_err(&i2c_client->dev,
  405. "CS35L32 Device ID (%X). Expected %X\n",
  406. devid, CS35L32_CHIP_ID);
  407. return ret;
  408. }
  409. ret = regmap_read(cs35l32->regmap, CS35L32_REV_ID, &reg);
  410. if (ret < 0) {
  411. dev_err(&i2c_client->dev, "Get Revision ID failed\n");
  412. return ret;
  413. }
  414. ret = regmap_register_patch(cs35l32->regmap, cs35l32_monitor_patch,
  415. ARRAY_SIZE(cs35l32_monitor_patch));
  416. if (ret < 0) {
  417. dev_err(&i2c_client->dev, "Failed to apply errata patch\n");
  418. return ret;
  419. }
  420. dev_info(&i2c_client->dev,
  421. "Cirrus Logic CS35L32, Revision: %02X\n", reg & 0xFF);
  422. /* Setup VBOOST Management */
  423. if (cs35l32->pdata.boost_mng)
  424. regmap_update_bits(cs35l32->regmap, CS35L32_AUDIO_LED_MNGR,
  425. CS35L32_BOOST_MASK,
  426. cs35l32->pdata.boost_mng);
  427. /* Setup ADSP Format Config */
  428. if (cs35l32->pdata.sdout_share)
  429. regmap_update_bits(cs35l32->regmap, CS35L32_ADSP_CTL,
  430. CS35L32_ADSP_SHARE_MASK,
  431. cs35l32->pdata.sdout_share << 3);
  432. /* Setup ADSP Data Configuration */
  433. if (cs35l32->pdata.sdout_datacfg)
  434. regmap_update_bits(cs35l32->regmap, CS35L32_ADSP_CTL,
  435. CS35L32_ADSP_DATACFG_MASK,
  436. cs35l32->pdata.sdout_datacfg << 4);
  437. /* Setup Low Battery Recovery */
  438. if (cs35l32->pdata.batt_recov)
  439. regmap_update_bits(cs35l32->regmap, CS35L32_BATT_THRESHOLD,
  440. CS35L32_BATT_REC_MASK,
  441. cs35l32->pdata.batt_recov << 1);
  442. /* Setup Low Battery Threshold */
  443. if (cs35l32->pdata.batt_thresh)
  444. regmap_update_bits(cs35l32->regmap, CS35L32_BATT_THRESHOLD,
  445. CS35L32_BATT_THRESH_MASK,
  446. cs35l32->pdata.batt_thresh << 4);
  447. /* Power down the AMP */
  448. regmap_update_bits(cs35l32->regmap, CS35L32_PWRCTL1, CS35L32_PDN_AMP,
  449. CS35L32_PDN_AMP);
  450. /* Clear MCLK Error Bit since we don't have the clock yet */
  451. ret = regmap_read(cs35l32->regmap, CS35L32_INT_STATUS_1, &reg);
  452. ret = snd_soc_register_codec(&i2c_client->dev,
  453. &soc_codec_dev_cs35l32, cs35l32_dai,
  454. ARRAY_SIZE(cs35l32_dai));
  455. if (ret < 0)
  456. goto err_disable;
  457. return 0;
  458. err_disable:
  459. regulator_bulk_disable(ARRAY_SIZE(cs35l32->supplies),
  460. cs35l32->supplies);
  461. return ret;
  462. }
  463. static int cs35l32_i2c_remove(struct i2c_client *i2c_client)
  464. {
  465. struct cs35l32_private *cs35l32 = i2c_get_clientdata(i2c_client);
  466. snd_soc_unregister_codec(&i2c_client->dev);
  467. /* Hold down reset */
  468. if (cs35l32->reset_gpio)
  469. gpiod_set_value_cansleep(cs35l32->reset_gpio, 0);
  470. return 0;
  471. }
  472. #ifdef CONFIG_PM_RUNTIME
  473. static int cs35l32_runtime_suspend(struct device *dev)
  474. {
  475. struct cs35l32_private *cs35l32 = dev_get_drvdata(dev);
  476. regcache_cache_only(cs35l32->regmap, true);
  477. regcache_mark_dirty(cs35l32->regmap);
  478. /* Hold down reset */
  479. if (cs35l32->reset_gpio)
  480. gpiod_set_value_cansleep(cs35l32->reset_gpio, 0);
  481. /* remove power */
  482. regulator_bulk_disable(ARRAY_SIZE(cs35l32->supplies),
  483. cs35l32->supplies);
  484. return 0;
  485. }
  486. static int cs35l32_runtime_resume(struct device *dev)
  487. {
  488. struct cs35l32_private *cs35l32 = dev_get_drvdata(dev);
  489. int ret;
  490. /* Enable power */
  491. ret = regulator_bulk_enable(ARRAY_SIZE(cs35l32->supplies),
  492. cs35l32->supplies);
  493. if (ret != 0) {
  494. dev_err(dev, "Failed to enable supplies: %d\n",
  495. ret);
  496. return ret;
  497. }
  498. if (cs35l32->reset_gpio)
  499. gpiod_set_value_cansleep(cs35l32->reset_gpio, 1);
  500. regcache_cache_only(cs35l32->regmap, false);
  501. regcache_sync(cs35l32->regmap);
  502. return 0;
  503. }
  504. #endif
  505. static const struct dev_pm_ops cs35l32_runtime_pm = {
  506. SET_RUNTIME_PM_OPS(cs35l32_runtime_suspend, cs35l32_runtime_resume,
  507. NULL)
  508. };
  509. static const struct of_device_id cs35l32_of_match[] = {
  510. { .compatible = "cirrus,cs35l32", },
  511. {},
  512. };
  513. MODULE_DEVICE_TABLE(of, cs35l32_of_match);
  514. static const struct i2c_device_id cs35l32_id[] = {
  515. {"cs35l32", 0},
  516. {}
  517. };
  518. MODULE_DEVICE_TABLE(i2c, cs35l32_id);
  519. static struct i2c_driver cs35l32_i2c_driver = {
  520. .driver = {
  521. .name = "cs35l32",
  522. .owner = THIS_MODULE,
  523. .pm = &cs35l32_runtime_pm,
  524. .of_match_table = cs35l32_of_match,
  525. },
  526. .id_table = cs35l32_id,
  527. .probe = cs35l32_i2c_probe,
  528. .remove = cs35l32_i2c_remove,
  529. };
  530. module_i2c_driver(cs35l32_i2c_driver);
  531. MODULE_DESCRIPTION("ASoC CS35L32 driver");
  532. MODULE_AUTHOR("Brian Austin, Cirrus Logic Inc, <brian.austin@cirrus.com>");
  533. MODULE_LICENSE("GPL");