bolero-cdc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /* Copyright (c) 2018, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/of_platform.h>
  13. #include <linux/module.h>
  14. #include <linux/io.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/printk.h>
  18. #include <linux/delay.h>
  19. #include <linux/kernel.h>
  20. #include "bolero-cdc.h"
  21. #include "internal.h"
  22. #define BOLERO_VERSION_1_0 0x0001
  23. #define BOLERO_VERSION_1_1 0x0002
  24. #define BOLERO_VERSION_1_2 0x0003
  25. #define BOLERO_VERSION_ENTRY_SIZE 32
  26. static struct snd_soc_codec_driver bolero;
  27. /* MCLK_MUX table for all macros */
  28. static u16 bolero_mclk_mux_tbl[MAX_MACRO][MCLK_MUX_MAX] = {
  29. {TX_MACRO, VA_MACRO},
  30. {TX_MACRO, RX_MACRO},
  31. {TX_MACRO, WSA_MACRO},
  32. {TX_MACRO, VA_MACRO},
  33. };
  34. static void bolero_ahb_write_device(char __iomem *io_base,
  35. u16 reg, u8 value)
  36. {
  37. u32 temp = (u32)(value) & 0x000000FF;
  38. iowrite32(temp, io_base + reg);
  39. }
  40. static void bolero_ahb_read_device(char __iomem *io_base,
  41. u16 reg, u8 *value)
  42. {
  43. u32 temp;
  44. temp = ioread32(io_base + reg);
  45. *value = (u8)temp;
  46. }
  47. static int __bolero_reg_read(struct bolero_priv *priv,
  48. u16 macro_id, u16 reg, u8 *val)
  49. {
  50. int ret = -EINVAL;
  51. u16 current_mclk_mux_macro;
  52. mutex_lock(&priv->clk_lock);
  53. current_mclk_mux_macro =
  54. priv->current_mclk_mux_macro[macro_id];
  55. if (!priv->macro_params[current_mclk_mux_macro].mclk_fn) {
  56. dev_dbg_ratelimited(priv->dev,
  57. "%s: mclk_fn not init for macro-id:%d, current_mclk_mux_macro:%d\n",
  58. __func__, macro_id, current_mclk_mux_macro);
  59. goto err;
  60. }
  61. ret = priv->macro_params[current_mclk_mux_macro].mclk_fn(
  62. priv->macro_params[current_mclk_mux_macro].dev, true);
  63. if (ret) {
  64. dev_dbg_ratelimited(priv->dev,
  65. "%s: clock enable failed for macro-id:%d, current_mclk_mux_macro:%d\n",
  66. __func__, macro_id, current_mclk_mux_macro);
  67. goto err;
  68. }
  69. bolero_ahb_read_device(
  70. priv->macro_params[macro_id].io_base, reg, val);
  71. priv->macro_params[current_mclk_mux_macro].mclk_fn(
  72. priv->macro_params[current_mclk_mux_macro].dev, false);
  73. err:
  74. mutex_unlock(&priv->clk_lock);
  75. return ret;
  76. }
  77. static int __bolero_reg_write(struct bolero_priv *priv,
  78. u16 macro_id, u16 reg, u8 val)
  79. {
  80. int ret = -EINVAL;
  81. u16 current_mclk_mux_macro;
  82. mutex_lock(&priv->clk_lock);
  83. current_mclk_mux_macro =
  84. priv->current_mclk_mux_macro[macro_id];
  85. if (!priv->macro_params[current_mclk_mux_macro].mclk_fn) {
  86. dev_dbg_ratelimited(priv->dev,
  87. "%s: mclk_fn not init for macro-id:%d, current_mclk_mux_macro:%d\n",
  88. __func__, macro_id, current_mclk_mux_macro);
  89. goto err;
  90. }
  91. ret = priv->macro_params[current_mclk_mux_macro].mclk_fn(
  92. priv->macro_params[current_mclk_mux_macro].dev, true);
  93. if (ret) {
  94. dev_dbg_ratelimited(priv->dev,
  95. "%s: clock enable failed for macro-id:%d, current_mclk_mux_macro:%d\n",
  96. __func__, macro_id, current_mclk_mux_macro);
  97. goto err;
  98. }
  99. bolero_ahb_write_device(
  100. priv->macro_params[macro_id].io_base, reg, val);
  101. priv->macro_params[current_mclk_mux_macro].mclk_fn(
  102. priv->macro_params[current_mclk_mux_macro].dev, false);
  103. err:
  104. mutex_unlock(&priv->clk_lock);
  105. return ret;
  106. }
  107. static bool bolero_is_valid_macro_dev(struct device *dev)
  108. {
  109. if (of_device_is_compatible(dev->parent->of_node, "qcom,bolero-codec"))
  110. return true;
  111. return false;
  112. }
  113. static bool bolero_is_valid_codec_dev(struct device *dev)
  114. {
  115. if (of_device_is_compatible(dev->of_node, "qcom,bolero-codec"))
  116. return true;
  117. return false;
  118. }
  119. /**
  120. * bolero_get_device_ptr - Get child or macro device ptr
  121. *
  122. * @dev: bolero device ptr.
  123. * @macro_id: ID of macro calling this API.
  124. *
  125. * Returns dev ptr on success or NULL on error.
  126. */
  127. struct device *bolero_get_device_ptr(struct device *dev, u16 macro_id)
  128. {
  129. struct bolero_priv *priv;
  130. if (!dev) {
  131. pr_err("%s: dev is null\n", __func__);
  132. return NULL;
  133. }
  134. if (!bolero_is_valid_codec_dev(dev)) {
  135. pr_err("%s: invalid codec\n", __func__);
  136. return NULL;
  137. }
  138. priv = dev_get_drvdata(dev);
  139. if (!priv || (macro_id >= MAX_MACRO)) {
  140. dev_err(dev, "%s: priv is null or invalid macro\n", __func__);
  141. return NULL;
  142. }
  143. return priv->macro_params[macro_id].dev;
  144. }
  145. EXPORT_SYMBOL(bolero_get_device_ptr);
  146. static int bolero_copy_dais_from_macro(struct bolero_priv *priv)
  147. {
  148. struct snd_soc_dai_driver *dai_ptr;
  149. u16 macro_idx;
  150. /* memcpy into bolero_dais all macro dais */
  151. if (!priv->bolero_dais)
  152. priv->bolero_dais = devm_kzalloc(priv->dev,
  153. priv->num_dais *
  154. sizeof(
  155. struct snd_soc_dai_driver),
  156. GFP_KERNEL);
  157. if (!priv->bolero_dais)
  158. return -ENOMEM;
  159. dai_ptr = priv->bolero_dais;
  160. for (macro_idx = START_MACRO; macro_idx < MAX_MACRO; macro_idx++) {
  161. if (priv->macro_params[macro_idx].dai_ptr) {
  162. memcpy(dai_ptr,
  163. priv->macro_params[macro_idx].dai_ptr,
  164. priv->macro_params[macro_idx].num_dais *
  165. sizeof(struct snd_soc_dai_driver));
  166. dai_ptr += priv->macro_params[macro_idx].num_dais;
  167. }
  168. }
  169. return 0;
  170. }
  171. /**
  172. * bolero_register_macro - Registers macro to bolero
  173. *
  174. * @dev: macro device ptr.
  175. * @macro_id: ID of macro calling this API.
  176. * @ops: macro params to register.
  177. *
  178. * Returns 0 on success or -EINVAL on error.
  179. */
  180. int bolero_register_macro(struct device *dev, u16 macro_id,
  181. struct macro_ops *ops)
  182. {
  183. struct bolero_priv *priv;
  184. int ret = -EINVAL;
  185. if (!dev || !ops) {
  186. pr_err("%s: dev or ops is null\n", __func__);
  187. return -EINVAL;
  188. }
  189. if (!bolero_is_valid_macro_dev(dev)) {
  190. dev_err(dev, "%s: child device for macro:%d not added yet\n",
  191. __func__, macro_id);
  192. return -EINVAL;
  193. }
  194. priv = dev_get_drvdata(dev->parent);
  195. if (!priv || (macro_id >= MAX_MACRO)) {
  196. dev_err(dev, "%s: priv is null or invalid macro\n", __func__);
  197. return -EINVAL;
  198. }
  199. priv->macro_params[macro_id].init = ops->init;
  200. priv->macro_params[macro_id].exit = ops->exit;
  201. priv->macro_params[macro_id].io_base = ops->io_base;
  202. priv->macro_params[macro_id].num_dais = ops->num_dais;
  203. priv->macro_params[macro_id].dai_ptr = ops->dai_ptr;
  204. priv->macro_params[macro_id].mclk_fn = ops->mclk_fn;
  205. priv->macro_params[macro_id].dev = dev;
  206. priv->current_mclk_mux_macro[macro_id] =
  207. bolero_mclk_mux_tbl[macro_id][MCLK_MUX0];
  208. priv->num_dais += ops->num_dais;
  209. priv->num_macros_registered++;
  210. priv->macros_supported[macro_id] = true;
  211. if (priv->num_macros_registered == priv->child_num) {
  212. ret = bolero_copy_dais_from_macro(priv);
  213. if (ret < 0) {
  214. dev_err(dev, "%s: copy_dais failed\n", __func__);
  215. return ret;
  216. }
  217. if (priv->macros_supported[TX_MACRO] == false) {
  218. bolero_mclk_mux_tbl[WSA_MACRO][MCLK_MUX0] = WSA_MACRO;
  219. priv->current_mclk_mux_macro[WSA_MACRO] = WSA_MACRO;
  220. bolero_mclk_mux_tbl[VA_MACRO][MCLK_MUX0] = VA_MACRO;
  221. priv->current_mclk_mux_macro[VA_MACRO] = VA_MACRO;
  222. }
  223. ret = snd_soc_register_codec(dev->parent, &bolero,
  224. priv->bolero_dais, priv->num_dais);
  225. if (ret < 0) {
  226. dev_err(dev, "%s: register codec failed\n", __func__);
  227. return ret;
  228. }
  229. }
  230. return 0;
  231. }
  232. EXPORT_SYMBOL(bolero_register_macro);
  233. /**
  234. * bolero_unregister_macro - De-Register macro from bolero
  235. *
  236. * @dev: macro device ptr.
  237. * @macro_id: ID of macro calling this API.
  238. *
  239. */
  240. void bolero_unregister_macro(struct device *dev, u16 macro_id)
  241. {
  242. struct bolero_priv *priv;
  243. if (!dev) {
  244. pr_err("%s: dev is null\n", __func__);
  245. return;
  246. }
  247. if (!bolero_is_valid_macro_dev(dev)) {
  248. dev_err(dev, "%s: macro:%d not in valid registered macro-list\n",
  249. __func__, macro_id);
  250. return;
  251. }
  252. priv = dev_get_drvdata(dev->parent);
  253. if (!priv || (macro_id >= MAX_MACRO)) {
  254. dev_err(dev, "%s: priv is null or invalid macro\n", __func__);
  255. return;
  256. }
  257. priv->macro_params[macro_id].init = NULL;
  258. priv->macro_params[macro_id].num_dais = 0;
  259. priv->macro_params[macro_id].dai_ptr = NULL;
  260. priv->macro_params[macro_id].mclk_fn = NULL;
  261. priv->macro_params[macro_id].dev = NULL;
  262. priv->num_dais -= priv->macro_params[macro_id].num_dais;
  263. priv->num_macros_registered--;
  264. /* UNREGISTER CODEC HERE */
  265. if (priv->child_num - 1 == priv->num_macros_registered)
  266. snd_soc_unregister_codec(dev->parent);
  267. }
  268. EXPORT_SYMBOL(bolero_unregister_macro);
  269. /**
  270. * bolero_request_clock - request for clock enable/disable
  271. *
  272. * @dev: macro device ptr.
  273. * @macro_id: ID of macro calling this API.
  274. * @mclk_mux_id: MCLK_MUX ID.
  275. * @enable: enable or disable clock flag
  276. *
  277. * Returns 0 on success or -EINVAL on error.
  278. */
  279. int bolero_request_clock(struct device *dev, u16 macro_id,
  280. enum mclk_mux mclk_mux_id,
  281. bool enable)
  282. {
  283. struct bolero_priv *priv;
  284. u16 mclk_mux0_macro, mclk_mux1_macro;
  285. int ret = 0;
  286. if (!dev) {
  287. pr_err("%s: dev is null\n", __func__);
  288. return -EINVAL;
  289. }
  290. if (!bolero_is_valid_macro_dev(dev)) {
  291. dev_err(dev, "%s: macro:%d not in valid registered macro-list\n",
  292. __func__, macro_id);
  293. return -EINVAL;
  294. }
  295. priv = dev_get_drvdata(dev->parent);
  296. if (!priv || (macro_id >= MAX_MACRO)) {
  297. dev_err(dev, "%s: priv is null or invalid macro\n", __func__);
  298. return -EINVAL;
  299. }
  300. mclk_mux0_macro = bolero_mclk_mux_tbl[macro_id][MCLK_MUX0];
  301. mutex_lock(&priv->clk_lock);
  302. switch (mclk_mux_id) {
  303. case MCLK_MUX0:
  304. ret = priv->macro_params[mclk_mux0_macro].mclk_fn(
  305. priv->macro_params[mclk_mux0_macro].dev, enable);
  306. if (ret < 0) {
  307. dev_err(dev,
  308. "%s: MCLK_MUX0 %s failed for macro:%d, mclk_mux0_macro:%d\n",
  309. __func__,
  310. enable ? "enable" : "disable",
  311. macro_id, mclk_mux0_macro);
  312. goto err;
  313. }
  314. break;
  315. case MCLK_MUX1:
  316. mclk_mux1_macro = bolero_mclk_mux_tbl[macro_id][MCLK_MUX1];
  317. ret = priv->macro_params[mclk_mux0_macro].mclk_fn(
  318. priv->macro_params[mclk_mux0_macro].dev,
  319. true);
  320. if (ret < 0) {
  321. dev_err(dev,
  322. "%s: MCLK_MUX0 en failed for macro:%d mclk_mux0_macro:%d\n",
  323. __func__, macro_id, mclk_mux0_macro);
  324. goto err;
  325. }
  326. ret = priv->macro_params[mclk_mux1_macro].mclk_fn(
  327. priv->macro_params[mclk_mux1_macro].dev, enable);
  328. if (ret < 0) {
  329. dev_err(dev,
  330. "%s: MCLK_MUX1 %s failed for macro:%d, mclk_mux1_macro:%d\n",
  331. __func__,
  332. enable ? "enable" : "disable",
  333. macro_id, mclk_mux1_macro);
  334. priv->macro_params[mclk_mux0_macro].mclk_fn(
  335. priv->macro_params[mclk_mux0_macro].dev,
  336. false);
  337. goto err;
  338. }
  339. priv->macro_params[mclk_mux0_macro].mclk_fn(
  340. priv->macro_params[mclk_mux0_macro].dev,
  341. false);
  342. break;
  343. case MCLK_MUX_MAX:
  344. default:
  345. dev_err(dev, "%s: invalid mclk_mux_id: %d\n",
  346. __func__, mclk_mux_id);
  347. ret = -EINVAL;
  348. goto err;
  349. }
  350. if (enable)
  351. priv->current_mclk_mux_macro[macro_id] =
  352. bolero_mclk_mux_tbl[macro_id][mclk_mux_id];
  353. else
  354. priv->current_mclk_mux_macro[macro_id] =
  355. bolero_mclk_mux_tbl[macro_id][MCLK_MUX0];
  356. err:
  357. mutex_unlock(&priv->clk_lock);
  358. return ret;
  359. }
  360. EXPORT_SYMBOL(bolero_request_clock);
  361. static ssize_t bolero_version_read(struct snd_info_entry *entry,
  362. void *file_private_data,
  363. struct file *file,
  364. char __user *buf, size_t count,
  365. loff_t pos)
  366. {
  367. struct bolero_priv *priv;
  368. char buffer[BOLERO_VERSION_ENTRY_SIZE];
  369. int len = 0;
  370. priv = (struct bolero_priv *) entry->private_data;
  371. if (!priv) {
  372. pr_err("%s: bolero priv is null\n", __func__);
  373. return -EINVAL;
  374. }
  375. switch (priv->version) {
  376. case BOLERO_VERSION_1_0:
  377. len = snprintf(buffer, sizeof(buffer), "BOLERO_1_0\n");
  378. break;
  379. case BOLERO_VERSION_1_1:
  380. len = snprintf(buffer, sizeof(buffer), "BOLERO_1_1\n");
  381. break;
  382. case BOLERO_VERSION_1_2:
  383. len = snprintf(buffer, sizeof(buffer), "BOLERO_1_2\n");
  384. break;
  385. default:
  386. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  387. }
  388. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  389. }
  390. static struct snd_info_entry_ops bolero_info_ops = {
  391. .read = bolero_version_read,
  392. };
  393. /*
  394. * bolero_info_create_codec_entry - creates bolero module
  395. * @codec_root: The parent directory
  396. * @codec: Codec instance
  397. *
  398. * Creates bolero module and version entry under the given
  399. * parent directory.
  400. *
  401. * Return: 0 on success or negative error code on failure.
  402. */
  403. int bolero_info_create_codec_entry(struct snd_info_entry *codec_root,
  404. struct snd_soc_codec *codec)
  405. {
  406. struct snd_info_entry *version_entry;
  407. struct bolero_priv *priv;
  408. struct snd_soc_card *card;
  409. if (!codec_root || !codec)
  410. return -EINVAL;
  411. priv = snd_soc_codec_get_drvdata(codec);
  412. if (priv->entry) {
  413. dev_dbg(priv->dev,
  414. "%s:bolero module already created\n", __func__);
  415. return 0;
  416. }
  417. card = codec->component.card;
  418. priv->entry = snd_info_create_subdir(codec_root->module,
  419. "bolero", codec_root);
  420. if (!priv->entry) {
  421. dev_dbg(codec->dev, "%s: failed to create bolero entry\n",
  422. __func__);
  423. return -ENOMEM;
  424. }
  425. version_entry = snd_info_create_card_entry(card->snd_card,
  426. "version",
  427. priv->entry);
  428. if (!version_entry) {
  429. dev_err(codec->dev, "%s: failed to create bolero version entry\n",
  430. __func__);
  431. return -ENOMEM;
  432. }
  433. version_entry->private_data = priv;
  434. version_entry->size = BOLERO_VERSION_ENTRY_SIZE;
  435. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  436. version_entry->c.ops = &bolero_info_ops;
  437. if (snd_info_register(version_entry) < 0) {
  438. snd_info_free_entry(version_entry);
  439. return -ENOMEM;
  440. }
  441. priv->version_entry = version_entry;
  442. return 0;
  443. }
  444. EXPORT_SYMBOL(bolero_info_create_codec_entry);
  445. static int bolero_soc_codec_probe(struct snd_soc_codec *codec)
  446. {
  447. struct bolero_priv *priv = dev_get_drvdata(codec->dev);
  448. int macro_idx, ret = 0;
  449. /* call init for supported macros */
  450. for (macro_idx = START_MACRO; macro_idx < MAX_MACRO; macro_idx++) {
  451. if (priv->macro_params[macro_idx].init) {
  452. ret = priv->macro_params[macro_idx].init(codec);
  453. if (ret < 0) {
  454. dev_err(codec->dev,
  455. "%s: init for macro %d failed\n",
  456. __func__, macro_idx);
  457. goto err;
  458. }
  459. }
  460. }
  461. priv->codec = codec;
  462. /*
  463. * In order for the ADIE RTC to differentiate between targets
  464. * version info is used.
  465. * Assign 1.0 for target with only one macro
  466. * Assign 1.1 for target with two macros
  467. * Assign 1.2 for target with more than two macros
  468. */
  469. if (priv->num_macros_registered == 1)
  470. priv->version = BOLERO_VERSION_1_0;
  471. else if (priv->num_macros_registered == 2)
  472. priv->version = BOLERO_VERSION_1_1;
  473. else if (priv->num_macros_registered > 2)
  474. priv->version = BOLERO_VERSION_1_2;
  475. dev_dbg(codec->dev, "%s: bolero soc codec probe success\n", __func__);
  476. err:
  477. return ret;
  478. }
  479. static int bolero_soc_codec_remove(struct snd_soc_codec *codec)
  480. {
  481. struct bolero_priv *priv = dev_get_drvdata(codec->dev);
  482. int macro_idx;
  483. /* call exit for supported macros */
  484. for (macro_idx = START_MACRO; macro_idx < MAX_MACRO; macro_idx++)
  485. if (priv->macro_params[macro_idx].exit)
  486. priv->macro_params[macro_idx].exit(codec);
  487. return 0;
  488. }
  489. static struct regmap *bolero_get_regmap(struct device *dev)
  490. {
  491. struct bolero_priv *priv = dev_get_drvdata(dev);
  492. return priv->regmap;
  493. }
  494. static struct snd_soc_codec_driver bolero = {
  495. .probe = bolero_soc_codec_probe,
  496. .remove = bolero_soc_codec_remove,
  497. .get_regmap = bolero_get_regmap,
  498. };
  499. static void bolero_add_child_devices(struct work_struct *work)
  500. {
  501. struct bolero_priv *priv;
  502. int rc;
  503. priv = container_of(work, struct bolero_priv,
  504. bolero_add_child_devices_work);
  505. if (!priv) {
  506. pr_err("%s: Memory for bolero priv does not exist\n",
  507. __func__);
  508. return;
  509. }
  510. if (!priv->dev || !priv->dev->of_node) {
  511. dev_err(priv->dev, "%s: DT node for bolero does not exist\n",
  512. __func__);
  513. return;
  514. }
  515. rc = of_platform_populate(priv->dev->of_node, NULL, NULL, priv->dev);
  516. if (rc)
  517. dev_err(priv->dev, "%s: failed to add child nodes, rc=%d\n",
  518. __func__, rc);
  519. else
  520. dev_dbg(priv->dev, "%s: added child node\n", __func__);
  521. }
  522. static int bolero_probe(struct platform_device *pdev)
  523. {
  524. struct bolero_priv *priv;
  525. u32 num_macros = 0;
  526. int ret;
  527. priv = devm_kzalloc(&pdev->dev, sizeof(struct bolero_priv),
  528. GFP_KERNEL);
  529. if (!priv)
  530. return -ENOMEM;
  531. ret = of_property_read_u32(pdev->dev.of_node, "qcom,num-macros",
  532. &num_macros);
  533. if (ret) {
  534. dev_err(&pdev->dev,
  535. "%s:num-macros property not found\n",
  536. __func__);
  537. return ret;
  538. }
  539. priv->child_num = num_macros;
  540. if (priv->child_num > MAX_MACRO) {
  541. dev_err(&pdev->dev,
  542. "%s:child_num(%d) > MAX_MACRO(%d) than supported\n",
  543. __func__, priv->child_num, MAX_MACRO);
  544. return -EINVAL;
  545. }
  546. priv->va_without_decimation = of_property_read_bool(pdev->dev.of_node,
  547. "qcom,va-without-decimation");
  548. if (priv->va_without_decimation)
  549. bolero_reg_access[VA_MACRO] = bolero_va_top_reg_access;
  550. priv->dev = &pdev->dev;
  551. priv->regmap = bolero_regmap_init(priv->dev,
  552. &bolero_regmap_config);
  553. if (IS_ERR_OR_NULL((void *)(priv->regmap))) {
  554. dev_err(&pdev->dev, "%s:regmap init failed\n", __func__);
  555. return -EINVAL;
  556. }
  557. priv->read_dev = __bolero_reg_read;
  558. priv->write_dev = __bolero_reg_write;
  559. dev_set_drvdata(&pdev->dev, priv);
  560. mutex_init(&priv->io_lock);
  561. mutex_init(&priv->clk_lock);
  562. INIT_WORK(&priv->bolero_add_child_devices_work,
  563. bolero_add_child_devices);
  564. schedule_work(&priv->bolero_add_child_devices_work);
  565. return 0;
  566. }
  567. static int bolero_remove(struct platform_device *pdev)
  568. {
  569. struct bolero_priv *priv = dev_get_drvdata(&pdev->dev);
  570. if (!priv)
  571. return -EINVAL;
  572. of_platform_depopulate(&pdev->dev);
  573. mutex_destroy(&priv->io_lock);
  574. mutex_destroy(&priv->clk_lock);
  575. return 0;
  576. }
  577. static const struct of_device_id bolero_dt_match[] = {
  578. {.compatible = "qcom,bolero-codec"},
  579. {}
  580. };
  581. MODULE_DEVICE_TABLE(of, bolero_dt_match);
  582. static struct platform_driver bolero_drv = {
  583. .driver = {
  584. .name = "bolero-codec",
  585. .owner = THIS_MODULE,
  586. .of_match_table = bolero_dt_match,
  587. },
  588. .probe = bolero_probe,
  589. .remove = bolero_remove,
  590. };
  591. module_platform_driver(bolero_drv);
  592. MODULE_DESCRIPTION("Bolero driver");
  593. MODULE_LICENSE("GPL v2");