tegra30_i2s.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /*
  2. * tegra30_i2s.c - Tegra30 I2S driver
  3. *
  4. * Author: Stephen Warren <swarren@nvidia.com>
  5. * Copyright (c) 2010-2012, NVIDIA CORPORATION. All rights reserved.
  6. *
  7. * Based on code copyright/by:
  8. *
  9. * Copyright (c) 2009-2010, NVIDIA Corporation.
  10. * Scott Peterson <speterson@nvidia.com>
  11. *
  12. * Copyright (C) 2010 Google, Inc.
  13. * Iliyan Malchev <malchev@google.com>
  14. *
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms and conditions of the GNU General Public License,
  17. * version 2, as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope it will be useful, but WITHOUT
  20. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  21. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  22. * more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. */
  27. #include <linux/clk.h>
  28. #include <linux/device.h>
  29. #include <linux/io.h>
  30. #include <linux/module.h>
  31. #include <linux/of.h>
  32. #include <linux/of_device.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/pm_runtime.h>
  35. #include <linux/regmap.h>
  36. #include <linux/slab.h>
  37. #include <sound/core.h>
  38. #include <sound/pcm.h>
  39. #include <sound/pcm_params.h>
  40. #include <sound/soc.h>
  41. #include <sound/dmaengine_pcm.h>
  42. #include "tegra30_ahub.h"
  43. #include "tegra30_i2s.h"
  44. #define DRV_NAME "tegra30-i2s"
  45. static int tegra30_i2s_runtime_suspend(struct device *dev)
  46. {
  47. struct tegra30_i2s *i2s = dev_get_drvdata(dev);
  48. regcache_cache_only(i2s->regmap, true);
  49. clk_disable_unprepare(i2s->clk_i2s);
  50. return 0;
  51. }
  52. static int tegra30_i2s_runtime_resume(struct device *dev)
  53. {
  54. struct tegra30_i2s *i2s = dev_get_drvdata(dev);
  55. int ret;
  56. ret = clk_prepare_enable(i2s->clk_i2s);
  57. if (ret) {
  58. dev_err(dev, "clk_enable failed: %d\n", ret);
  59. return ret;
  60. }
  61. regcache_cache_only(i2s->regmap, false);
  62. return 0;
  63. }
  64. static int tegra30_i2s_set_fmt(struct snd_soc_dai *dai,
  65. unsigned int fmt)
  66. {
  67. struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  68. unsigned int mask = 0, val = 0;
  69. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  70. case SND_SOC_DAIFMT_NB_NF:
  71. break;
  72. default:
  73. return -EINVAL;
  74. }
  75. mask |= TEGRA30_I2S_CTRL_MASTER_ENABLE;
  76. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  77. case SND_SOC_DAIFMT_CBS_CFS:
  78. val |= TEGRA30_I2S_CTRL_MASTER_ENABLE;
  79. break;
  80. case SND_SOC_DAIFMT_CBM_CFM:
  81. break;
  82. default:
  83. return -EINVAL;
  84. }
  85. mask |= TEGRA30_I2S_CTRL_FRAME_FORMAT_MASK |
  86. TEGRA30_I2S_CTRL_LRCK_MASK;
  87. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  88. case SND_SOC_DAIFMT_DSP_A:
  89. val |= TEGRA30_I2S_CTRL_FRAME_FORMAT_FSYNC;
  90. val |= TEGRA30_I2S_CTRL_LRCK_L_LOW;
  91. break;
  92. case SND_SOC_DAIFMT_DSP_B:
  93. val |= TEGRA30_I2S_CTRL_FRAME_FORMAT_FSYNC;
  94. val |= TEGRA30_I2S_CTRL_LRCK_R_LOW;
  95. break;
  96. case SND_SOC_DAIFMT_I2S:
  97. val |= TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK;
  98. val |= TEGRA30_I2S_CTRL_LRCK_L_LOW;
  99. break;
  100. case SND_SOC_DAIFMT_RIGHT_J:
  101. val |= TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK;
  102. val |= TEGRA30_I2S_CTRL_LRCK_L_LOW;
  103. break;
  104. case SND_SOC_DAIFMT_LEFT_J:
  105. val |= TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK;
  106. val |= TEGRA30_I2S_CTRL_LRCK_L_LOW;
  107. break;
  108. default:
  109. return -EINVAL;
  110. }
  111. pm_runtime_get_sync(dai->dev);
  112. regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL, mask, val);
  113. pm_runtime_put(dai->dev);
  114. return 0;
  115. }
  116. static int tegra30_i2s_hw_params(struct snd_pcm_substream *substream,
  117. struct snd_pcm_hw_params *params,
  118. struct snd_soc_dai *dai)
  119. {
  120. struct device *dev = dai->dev;
  121. struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  122. unsigned int mask, val, reg;
  123. int ret, sample_size, srate, i2sclock, bitcnt;
  124. struct tegra30_ahub_cif_conf cif_conf;
  125. if (params_channels(params) != 2)
  126. return -EINVAL;
  127. mask = TEGRA30_I2S_CTRL_BIT_SIZE_MASK;
  128. switch (params_format(params)) {
  129. case SNDRV_PCM_FORMAT_S16_LE:
  130. val = TEGRA30_I2S_CTRL_BIT_SIZE_16;
  131. sample_size = 16;
  132. break;
  133. default:
  134. return -EINVAL;
  135. }
  136. regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL, mask, val);
  137. srate = params_rate(params);
  138. /* Final "* 2" required by Tegra hardware */
  139. i2sclock = srate * params_channels(params) * sample_size * 2;
  140. bitcnt = (i2sclock / (2 * srate)) - 1;
  141. if (bitcnt < 0 || bitcnt > TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US)
  142. return -EINVAL;
  143. ret = clk_set_rate(i2s->clk_i2s, i2sclock);
  144. if (ret) {
  145. dev_err(dev, "Can't set I2S clock rate: %d\n", ret);
  146. return ret;
  147. }
  148. val = bitcnt << TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT;
  149. if (i2sclock % (2 * srate))
  150. val |= TEGRA30_I2S_TIMING_NON_SYM_ENABLE;
  151. regmap_write(i2s->regmap, TEGRA30_I2S_TIMING, val);
  152. cif_conf.threshold = 0;
  153. cif_conf.audio_channels = 2;
  154. cif_conf.client_channels = 2;
  155. cif_conf.audio_bits = TEGRA30_AUDIOCIF_BITS_16;
  156. cif_conf.client_bits = TEGRA30_AUDIOCIF_BITS_16;
  157. cif_conf.expand = 0;
  158. cif_conf.stereo_conv = 0;
  159. cif_conf.replicate = 0;
  160. cif_conf.truncate = 0;
  161. cif_conf.mono_conv = 0;
  162. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  163. cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_RX;
  164. reg = TEGRA30_I2S_CIF_RX_CTRL;
  165. } else {
  166. cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_TX;
  167. reg = TEGRA30_I2S_CIF_TX_CTRL;
  168. }
  169. i2s->soc_data->set_audio_cif(i2s->regmap, reg, &cif_conf);
  170. val = (1 << TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT) |
  171. (1 << TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_SHIFT);
  172. regmap_write(i2s->regmap, TEGRA30_I2S_OFFSET, val);
  173. return 0;
  174. }
  175. static void tegra30_i2s_start_playback(struct tegra30_i2s *i2s)
  176. {
  177. tegra30_ahub_enable_tx_fifo(i2s->playback_fifo_cif);
  178. regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL,
  179. TEGRA30_I2S_CTRL_XFER_EN_TX,
  180. TEGRA30_I2S_CTRL_XFER_EN_TX);
  181. }
  182. static void tegra30_i2s_stop_playback(struct tegra30_i2s *i2s)
  183. {
  184. tegra30_ahub_disable_tx_fifo(i2s->playback_fifo_cif);
  185. regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL,
  186. TEGRA30_I2S_CTRL_XFER_EN_TX, 0);
  187. }
  188. static void tegra30_i2s_start_capture(struct tegra30_i2s *i2s)
  189. {
  190. tegra30_ahub_enable_rx_fifo(i2s->capture_fifo_cif);
  191. regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL,
  192. TEGRA30_I2S_CTRL_XFER_EN_RX,
  193. TEGRA30_I2S_CTRL_XFER_EN_RX);
  194. }
  195. static void tegra30_i2s_stop_capture(struct tegra30_i2s *i2s)
  196. {
  197. tegra30_ahub_disable_rx_fifo(i2s->capture_fifo_cif);
  198. regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL,
  199. TEGRA30_I2S_CTRL_XFER_EN_RX, 0);
  200. }
  201. static int tegra30_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  202. struct snd_soc_dai *dai)
  203. {
  204. struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  205. switch (cmd) {
  206. case SNDRV_PCM_TRIGGER_START:
  207. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  208. case SNDRV_PCM_TRIGGER_RESUME:
  209. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  210. tegra30_i2s_start_playback(i2s);
  211. else
  212. tegra30_i2s_start_capture(i2s);
  213. break;
  214. case SNDRV_PCM_TRIGGER_STOP:
  215. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  216. case SNDRV_PCM_TRIGGER_SUSPEND:
  217. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  218. tegra30_i2s_stop_playback(i2s);
  219. else
  220. tegra30_i2s_stop_capture(i2s);
  221. break;
  222. default:
  223. return -EINVAL;
  224. }
  225. return 0;
  226. }
  227. static int tegra30_i2s_probe(struct snd_soc_dai *dai)
  228. {
  229. struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  230. dai->capture_dma_data = &i2s->capture_dma_data;
  231. dai->playback_dma_data = &i2s->playback_dma_data;
  232. return 0;
  233. }
  234. static struct snd_soc_dai_ops tegra30_i2s_dai_ops = {
  235. .set_fmt = tegra30_i2s_set_fmt,
  236. .hw_params = tegra30_i2s_hw_params,
  237. .trigger = tegra30_i2s_trigger,
  238. };
  239. static const struct snd_soc_dai_driver tegra30_i2s_dai_template = {
  240. .probe = tegra30_i2s_probe,
  241. .playback = {
  242. .stream_name = "Playback",
  243. .channels_min = 2,
  244. .channels_max = 2,
  245. .rates = SNDRV_PCM_RATE_8000_96000,
  246. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  247. },
  248. .capture = {
  249. .stream_name = "Capture",
  250. .channels_min = 2,
  251. .channels_max = 2,
  252. .rates = SNDRV_PCM_RATE_8000_96000,
  253. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  254. },
  255. .ops = &tegra30_i2s_dai_ops,
  256. .symmetric_rates = 1,
  257. };
  258. static const struct snd_soc_component_driver tegra30_i2s_component = {
  259. .name = DRV_NAME,
  260. };
  261. static bool tegra30_i2s_wr_rd_reg(struct device *dev, unsigned int reg)
  262. {
  263. switch (reg) {
  264. case TEGRA30_I2S_CTRL:
  265. case TEGRA30_I2S_TIMING:
  266. case TEGRA30_I2S_OFFSET:
  267. case TEGRA30_I2S_CH_CTRL:
  268. case TEGRA30_I2S_SLOT_CTRL:
  269. case TEGRA30_I2S_CIF_RX_CTRL:
  270. case TEGRA30_I2S_CIF_TX_CTRL:
  271. case TEGRA30_I2S_FLOWCTL:
  272. case TEGRA30_I2S_TX_STEP:
  273. case TEGRA30_I2S_FLOW_STATUS:
  274. case TEGRA30_I2S_FLOW_TOTAL:
  275. case TEGRA30_I2S_FLOW_OVER:
  276. case TEGRA30_I2S_FLOW_UNDER:
  277. case TEGRA30_I2S_LCOEF_1_4_0:
  278. case TEGRA30_I2S_LCOEF_1_4_1:
  279. case TEGRA30_I2S_LCOEF_1_4_2:
  280. case TEGRA30_I2S_LCOEF_1_4_3:
  281. case TEGRA30_I2S_LCOEF_1_4_4:
  282. case TEGRA30_I2S_LCOEF_1_4_5:
  283. case TEGRA30_I2S_LCOEF_2_4_0:
  284. case TEGRA30_I2S_LCOEF_2_4_1:
  285. case TEGRA30_I2S_LCOEF_2_4_2:
  286. return true;
  287. default:
  288. return false;
  289. }
  290. }
  291. static bool tegra30_i2s_volatile_reg(struct device *dev, unsigned int reg)
  292. {
  293. switch (reg) {
  294. case TEGRA30_I2S_FLOW_STATUS:
  295. case TEGRA30_I2S_FLOW_TOTAL:
  296. case TEGRA30_I2S_FLOW_OVER:
  297. case TEGRA30_I2S_FLOW_UNDER:
  298. return true;
  299. default:
  300. return false;
  301. }
  302. }
  303. static const struct regmap_config tegra30_i2s_regmap_config = {
  304. .reg_bits = 32,
  305. .reg_stride = 4,
  306. .val_bits = 32,
  307. .max_register = TEGRA30_I2S_LCOEF_2_4_2,
  308. .writeable_reg = tegra30_i2s_wr_rd_reg,
  309. .readable_reg = tegra30_i2s_wr_rd_reg,
  310. .volatile_reg = tegra30_i2s_volatile_reg,
  311. .cache_type = REGCACHE_FLAT,
  312. };
  313. static const struct tegra30_i2s_soc_data tegra30_i2s_config = {
  314. .set_audio_cif = tegra30_ahub_set_cif,
  315. };
  316. static const struct tegra30_i2s_soc_data tegra124_i2s_config = {
  317. .set_audio_cif = tegra124_ahub_set_cif,
  318. };
  319. static const struct of_device_id tegra30_i2s_of_match[] = {
  320. { .compatible = "nvidia,tegra124-i2s", .data = &tegra124_i2s_config },
  321. { .compatible = "nvidia,tegra30-i2s", .data = &tegra30_i2s_config },
  322. {},
  323. };
  324. static int tegra30_i2s_platform_probe(struct platform_device *pdev)
  325. {
  326. struct tegra30_i2s *i2s;
  327. const struct of_device_id *match;
  328. u32 cif_ids[2];
  329. struct resource *mem;
  330. void __iomem *regs;
  331. int ret;
  332. i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_i2s), GFP_KERNEL);
  333. if (!i2s) {
  334. dev_err(&pdev->dev, "Can't allocate tegra30_i2s\n");
  335. ret = -ENOMEM;
  336. goto err;
  337. }
  338. dev_set_drvdata(&pdev->dev, i2s);
  339. match = of_match_device(tegra30_i2s_of_match, &pdev->dev);
  340. if (!match) {
  341. dev_err(&pdev->dev, "Error: No device match found\n");
  342. ret = -ENODEV;
  343. goto err;
  344. }
  345. i2s->soc_data = (struct tegra30_i2s_soc_data *)match->data;
  346. i2s->dai = tegra30_i2s_dai_template;
  347. i2s->dai.name = dev_name(&pdev->dev);
  348. ret = of_property_read_u32_array(pdev->dev.of_node,
  349. "nvidia,ahub-cif-ids", cif_ids,
  350. ARRAY_SIZE(cif_ids));
  351. if (ret < 0)
  352. goto err;
  353. i2s->playback_i2s_cif = cif_ids[0];
  354. i2s->capture_i2s_cif = cif_ids[1];
  355. i2s->clk_i2s = clk_get(&pdev->dev, NULL);
  356. if (IS_ERR(i2s->clk_i2s)) {
  357. dev_err(&pdev->dev, "Can't retrieve i2s clock\n");
  358. ret = PTR_ERR(i2s->clk_i2s);
  359. goto err;
  360. }
  361. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  362. regs = devm_ioremap_resource(&pdev->dev, mem);
  363. if (IS_ERR(regs)) {
  364. ret = PTR_ERR(regs);
  365. goto err_clk_put;
  366. }
  367. i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
  368. &tegra30_i2s_regmap_config);
  369. if (IS_ERR(i2s->regmap)) {
  370. dev_err(&pdev->dev, "regmap init failed\n");
  371. ret = PTR_ERR(i2s->regmap);
  372. goto err_clk_put;
  373. }
  374. regcache_cache_only(i2s->regmap, true);
  375. pm_runtime_enable(&pdev->dev);
  376. if (!pm_runtime_enabled(&pdev->dev)) {
  377. ret = tegra30_i2s_runtime_resume(&pdev->dev);
  378. if (ret)
  379. goto err_pm_disable;
  380. }
  381. i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  382. i2s->playback_dma_data.maxburst = 4;
  383. ret = tegra30_ahub_allocate_tx_fifo(&i2s->playback_fifo_cif,
  384. i2s->playback_dma_chan,
  385. sizeof(i2s->playback_dma_chan),
  386. &i2s->playback_dma_data.addr);
  387. if (ret) {
  388. dev_err(&pdev->dev, "Could not alloc TX FIFO: %d\n", ret);
  389. goto err_suspend;
  390. }
  391. ret = tegra30_ahub_set_rx_cif_source(i2s->playback_i2s_cif,
  392. i2s->playback_fifo_cif);
  393. if (ret) {
  394. dev_err(&pdev->dev, "Could not route TX FIFO: %d\n", ret);
  395. goto err_free_tx_fifo;
  396. }
  397. i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  398. i2s->capture_dma_data.maxburst = 4;
  399. ret = tegra30_ahub_allocate_rx_fifo(&i2s->capture_fifo_cif,
  400. i2s->capture_dma_chan,
  401. sizeof(i2s->capture_dma_chan),
  402. &i2s->capture_dma_data.addr);
  403. if (ret) {
  404. dev_err(&pdev->dev, "Could not alloc RX FIFO: %d\n", ret);
  405. goto err_unroute_tx_fifo;
  406. }
  407. ret = tegra30_ahub_set_rx_cif_source(i2s->capture_fifo_cif,
  408. i2s->capture_i2s_cif);
  409. if (ret) {
  410. dev_err(&pdev->dev, "Could not route TX FIFO: %d\n", ret);
  411. goto err_free_rx_fifo;
  412. }
  413. ret = snd_soc_register_component(&pdev->dev, &tegra30_i2s_component,
  414. &i2s->dai, 1);
  415. if (ret) {
  416. dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  417. ret = -ENOMEM;
  418. goto err_unroute_rx_fifo;
  419. }
  420. ret = tegra_pcm_platform_register_with_chan_names(&pdev->dev,
  421. &i2s->dma_config, i2s->playback_dma_chan,
  422. i2s->capture_dma_chan);
  423. if (ret) {
  424. dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  425. goto err_unregister_component;
  426. }
  427. return 0;
  428. err_unregister_component:
  429. snd_soc_unregister_component(&pdev->dev);
  430. err_unroute_rx_fifo:
  431. tegra30_ahub_unset_rx_cif_source(i2s->capture_fifo_cif);
  432. err_free_rx_fifo:
  433. tegra30_ahub_free_rx_fifo(i2s->capture_fifo_cif);
  434. err_unroute_tx_fifo:
  435. tegra30_ahub_unset_rx_cif_source(i2s->playback_i2s_cif);
  436. err_free_tx_fifo:
  437. tegra30_ahub_free_tx_fifo(i2s->playback_fifo_cif);
  438. err_suspend:
  439. if (!pm_runtime_status_suspended(&pdev->dev))
  440. tegra30_i2s_runtime_suspend(&pdev->dev);
  441. err_pm_disable:
  442. pm_runtime_disable(&pdev->dev);
  443. err_clk_put:
  444. clk_put(i2s->clk_i2s);
  445. err:
  446. return ret;
  447. }
  448. static int tegra30_i2s_platform_remove(struct platform_device *pdev)
  449. {
  450. struct tegra30_i2s *i2s = dev_get_drvdata(&pdev->dev);
  451. pm_runtime_disable(&pdev->dev);
  452. if (!pm_runtime_status_suspended(&pdev->dev))
  453. tegra30_i2s_runtime_suspend(&pdev->dev);
  454. tegra_pcm_platform_unregister(&pdev->dev);
  455. snd_soc_unregister_component(&pdev->dev);
  456. tegra30_ahub_unset_rx_cif_source(i2s->capture_fifo_cif);
  457. tegra30_ahub_free_rx_fifo(i2s->capture_fifo_cif);
  458. tegra30_ahub_unset_rx_cif_source(i2s->playback_i2s_cif);
  459. tegra30_ahub_free_tx_fifo(i2s->playback_fifo_cif);
  460. clk_put(i2s->clk_i2s);
  461. return 0;
  462. }
  463. #ifdef CONFIG_PM_SLEEP
  464. static int tegra30_i2s_suspend(struct device *dev)
  465. {
  466. struct tegra30_i2s *i2s = dev_get_drvdata(dev);
  467. regcache_mark_dirty(i2s->regmap);
  468. return 0;
  469. }
  470. static int tegra30_i2s_resume(struct device *dev)
  471. {
  472. struct tegra30_i2s *i2s = dev_get_drvdata(dev);
  473. int ret;
  474. ret = pm_runtime_get_sync(dev);
  475. if (ret < 0)
  476. return ret;
  477. ret = regcache_sync(i2s->regmap);
  478. pm_runtime_put(dev);
  479. return ret;
  480. }
  481. #endif
  482. static const struct dev_pm_ops tegra30_i2s_pm_ops = {
  483. SET_RUNTIME_PM_OPS(tegra30_i2s_runtime_suspend,
  484. tegra30_i2s_runtime_resume, NULL)
  485. SET_SYSTEM_SLEEP_PM_OPS(tegra30_i2s_suspend, tegra30_i2s_resume)
  486. };
  487. static struct platform_driver tegra30_i2s_driver = {
  488. .driver = {
  489. .name = DRV_NAME,
  490. .of_match_table = tegra30_i2s_of_match,
  491. .pm = &tegra30_i2s_pm_ops,
  492. },
  493. .probe = tegra30_i2s_platform_probe,
  494. .remove = tegra30_i2s_platform_remove,
  495. };
  496. module_platform_driver(tegra30_i2s_driver);
  497. MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
  498. MODULE_DESCRIPTION("Tegra30 I2S ASoC driver");
  499. MODULE_LICENSE("GPL");
  500. MODULE_ALIAS("platform:" DRV_NAME);
  501. MODULE_DEVICE_TABLE(of, tegra30_i2s_of_match);