tegra30_i2s.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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_startup(struct snd_pcm_substream *substream,
  65. struct snd_soc_dai *dai)
  66. {
  67. struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  68. int ret;
  69. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  70. ret = tegra30_ahub_allocate_tx_fifo(&i2s->playback_fifo_cif,
  71. &i2s->playback_dma_data.addr,
  72. &i2s->playback_dma_data.slave_id);
  73. i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  74. i2s->playback_dma_data.maxburst = 4;
  75. tegra30_ahub_set_rx_cif_source(i2s->playback_i2s_cif,
  76. i2s->playback_fifo_cif);
  77. } else {
  78. ret = tegra30_ahub_allocate_rx_fifo(&i2s->capture_fifo_cif,
  79. &i2s->capture_dma_data.addr,
  80. &i2s->capture_dma_data.slave_id);
  81. i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  82. i2s->capture_dma_data.maxburst = 4;
  83. tegra30_ahub_set_rx_cif_source(i2s->capture_fifo_cif,
  84. i2s->capture_i2s_cif);
  85. }
  86. return ret;
  87. }
  88. static void tegra30_i2s_shutdown(struct snd_pcm_substream *substream,
  89. struct snd_soc_dai *dai)
  90. {
  91. struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  92. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  93. tegra30_ahub_unset_rx_cif_source(i2s->playback_i2s_cif);
  94. tegra30_ahub_free_tx_fifo(i2s->playback_fifo_cif);
  95. } else {
  96. tegra30_ahub_unset_rx_cif_source(i2s->capture_fifo_cif);
  97. tegra30_ahub_free_rx_fifo(i2s->capture_fifo_cif);
  98. }
  99. }
  100. static int tegra30_i2s_set_fmt(struct snd_soc_dai *dai,
  101. unsigned int fmt)
  102. {
  103. struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  104. unsigned int mask, val;
  105. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  106. case SND_SOC_DAIFMT_NB_NF:
  107. break;
  108. default:
  109. return -EINVAL;
  110. }
  111. mask = TEGRA30_I2S_CTRL_MASTER_ENABLE;
  112. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  113. case SND_SOC_DAIFMT_CBS_CFS:
  114. val = TEGRA30_I2S_CTRL_MASTER_ENABLE;
  115. break;
  116. case SND_SOC_DAIFMT_CBM_CFM:
  117. break;
  118. default:
  119. return -EINVAL;
  120. }
  121. mask |= TEGRA30_I2S_CTRL_FRAME_FORMAT_MASK |
  122. TEGRA30_I2S_CTRL_LRCK_MASK;
  123. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  124. case SND_SOC_DAIFMT_DSP_A:
  125. val |= TEGRA30_I2S_CTRL_FRAME_FORMAT_FSYNC;
  126. val |= TEGRA30_I2S_CTRL_LRCK_L_LOW;
  127. break;
  128. case SND_SOC_DAIFMT_DSP_B:
  129. val |= TEGRA30_I2S_CTRL_FRAME_FORMAT_FSYNC;
  130. val |= TEGRA30_I2S_CTRL_LRCK_R_LOW;
  131. break;
  132. case SND_SOC_DAIFMT_I2S:
  133. val |= TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK;
  134. val |= TEGRA30_I2S_CTRL_LRCK_L_LOW;
  135. break;
  136. case SND_SOC_DAIFMT_RIGHT_J:
  137. val |= TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK;
  138. val |= TEGRA30_I2S_CTRL_LRCK_L_LOW;
  139. break;
  140. case SND_SOC_DAIFMT_LEFT_J:
  141. val |= TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK;
  142. val |= TEGRA30_I2S_CTRL_LRCK_L_LOW;
  143. break;
  144. default:
  145. return -EINVAL;
  146. }
  147. pm_runtime_get_sync(dai->dev);
  148. regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL, mask, val);
  149. pm_runtime_put(dai->dev);
  150. return 0;
  151. }
  152. static int tegra30_i2s_hw_params(struct snd_pcm_substream *substream,
  153. struct snd_pcm_hw_params *params,
  154. struct snd_soc_dai *dai)
  155. {
  156. struct device *dev = dai->dev;
  157. struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  158. unsigned int mask, val, reg;
  159. int ret, sample_size, srate, i2sclock, bitcnt;
  160. struct tegra30_ahub_cif_conf cif_conf;
  161. if (params_channels(params) != 2)
  162. return -EINVAL;
  163. mask = TEGRA30_I2S_CTRL_BIT_SIZE_MASK;
  164. switch (params_format(params)) {
  165. case SNDRV_PCM_FORMAT_S16_LE:
  166. val = TEGRA30_I2S_CTRL_BIT_SIZE_16;
  167. sample_size = 16;
  168. break;
  169. default:
  170. return -EINVAL;
  171. }
  172. regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL, mask, val);
  173. srate = params_rate(params);
  174. /* Final "* 2" required by Tegra hardware */
  175. i2sclock = srate * params_channels(params) * sample_size * 2;
  176. bitcnt = (i2sclock / (2 * srate)) - 1;
  177. if (bitcnt < 0 || bitcnt > TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US)
  178. return -EINVAL;
  179. ret = clk_set_rate(i2s->clk_i2s, i2sclock);
  180. if (ret) {
  181. dev_err(dev, "Can't set I2S clock rate: %d\n", ret);
  182. return ret;
  183. }
  184. val = bitcnt << TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT;
  185. if (i2sclock % (2 * srate))
  186. val |= TEGRA30_I2S_TIMING_NON_SYM_ENABLE;
  187. regmap_write(i2s->regmap, TEGRA30_I2S_TIMING, val);
  188. cif_conf.threshold = 0;
  189. cif_conf.audio_channels = 2;
  190. cif_conf.client_channels = 2;
  191. cif_conf.audio_bits = TEGRA30_AUDIOCIF_BITS_16;
  192. cif_conf.client_bits = TEGRA30_AUDIOCIF_BITS_16;
  193. cif_conf.expand = 0;
  194. cif_conf.stereo_conv = 0;
  195. cif_conf.replicate = 0;
  196. cif_conf.truncate = 0;
  197. cif_conf.mono_conv = 0;
  198. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  199. cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_RX;
  200. reg = TEGRA30_I2S_CIF_RX_CTRL;
  201. } else {
  202. cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_TX;
  203. reg = TEGRA30_I2S_CIF_TX_CTRL;
  204. }
  205. i2s->soc_data->set_audio_cif(i2s->regmap, reg, &cif_conf);
  206. val = (1 << TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT) |
  207. (1 << TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_SHIFT);
  208. regmap_write(i2s->regmap, TEGRA30_I2S_OFFSET, val);
  209. return 0;
  210. }
  211. static void tegra30_i2s_start_playback(struct tegra30_i2s *i2s)
  212. {
  213. tegra30_ahub_enable_tx_fifo(i2s->playback_fifo_cif);
  214. regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL,
  215. TEGRA30_I2S_CTRL_XFER_EN_TX,
  216. TEGRA30_I2S_CTRL_XFER_EN_TX);
  217. }
  218. static void tegra30_i2s_stop_playback(struct tegra30_i2s *i2s)
  219. {
  220. tegra30_ahub_disable_tx_fifo(i2s->playback_fifo_cif);
  221. regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL,
  222. TEGRA30_I2S_CTRL_XFER_EN_TX, 0);
  223. }
  224. static void tegra30_i2s_start_capture(struct tegra30_i2s *i2s)
  225. {
  226. tegra30_ahub_enable_rx_fifo(i2s->capture_fifo_cif);
  227. regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL,
  228. TEGRA30_I2S_CTRL_XFER_EN_RX,
  229. TEGRA30_I2S_CTRL_XFER_EN_RX);
  230. }
  231. static void tegra30_i2s_stop_capture(struct tegra30_i2s *i2s)
  232. {
  233. tegra30_ahub_disable_rx_fifo(i2s->capture_fifo_cif);
  234. regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL,
  235. TEGRA30_I2S_CTRL_XFER_EN_RX, 0);
  236. }
  237. static int tegra30_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  238. struct snd_soc_dai *dai)
  239. {
  240. struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  241. switch (cmd) {
  242. case SNDRV_PCM_TRIGGER_START:
  243. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  244. case SNDRV_PCM_TRIGGER_RESUME:
  245. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  246. tegra30_i2s_start_playback(i2s);
  247. else
  248. tegra30_i2s_start_capture(i2s);
  249. break;
  250. case SNDRV_PCM_TRIGGER_STOP:
  251. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  252. case SNDRV_PCM_TRIGGER_SUSPEND:
  253. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  254. tegra30_i2s_stop_playback(i2s);
  255. else
  256. tegra30_i2s_stop_capture(i2s);
  257. break;
  258. default:
  259. return -EINVAL;
  260. }
  261. return 0;
  262. }
  263. static int tegra30_i2s_probe(struct snd_soc_dai *dai)
  264. {
  265. struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  266. dai->capture_dma_data = &i2s->capture_dma_data;
  267. dai->playback_dma_data = &i2s->playback_dma_data;
  268. return 0;
  269. }
  270. static struct snd_soc_dai_ops tegra30_i2s_dai_ops = {
  271. .startup = tegra30_i2s_startup,
  272. .shutdown = tegra30_i2s_shutdown,
  273. .set_fmt = tegra30_i2s_set_fmt,
  274. .hw_params = tegra30_i2s_hw_params,
  275. .trigger = tegra30_i2s_trigger,
  276. };
  277. static const struct snd_soc_dai_driver tegra30_i2s_dai_template = {
  278. .probe = tegra30_i2s_probe,
  279. .playback = {
  280. .stream_name = "Playback",
  281. .channels_min = 2,
  282. .channels_max = 2,
  283. .rates = SNDRV_PCM_RATE_8000_96000,
  284. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  285. },
  286. .capture = {
  287. .stream_name = "Capture",
  288. .channels_min = 2,
  289. .channels_max = 2,
  290. .rates = SNDRV_PCM_RATE_8000_96000,
  291. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  292. },
  293. .ops = &tegra30_i2s_dai_ops,
  294. .symmetric_rates = 1,
  295. };
  296. static const struct snd_soc_component_driver tegra30_i2s_component = {
  297. .name = DRV_NAME,
  298. };
  299. static bool tegra30_i2s_wr_rd_reg(struct device *dev, unsigned int reg)
  300. {
  301. switch (reg) {
  302. case TEGRA30_I2S_CTRL:
  303. case TEGRA30_I2S_TIMING:
  304. case TEGRA30_I2S_OFFSET:
  305. case TEGRA30_I2S_CH_CTRL:
  306. case TEGRA30_I2S_SLOT_CTRL:
  307. case TEGRA30_I2S_CIF_RX_CTRL:
  308. case TEGRA30_I2S_CIF_TX_CTRL:
  309. case TEGRA30_I2S_FLOWCTL:
  310. case TEGRA30_I2S_TX_STEP:
  311. case TEGRA30_I2S_FLOW_STATUS:
  312. case TEGRA30_I2S_FLOW_TOTAL:
  313. case TEGRA30_I2S_FLOW_OVER:
  314. case TEGRA30_I2S_FLOW_UNDER:
  315. case TEGRA30_I2S_LCOEF_1_4_0:
  316. case TEGRA30_I2S_LCOEF_1_4_1:
  317. case TEGRA30_I2S_LCOEF_1_4_2:
  318. case TEGRA30_I2S_LCOEF_1_4_3:
  319. case TEGRA30_I2S_LCOEF_1_4_4:
  320. case TEGRA30_I2S_LCOEF_1_4_5:
  321. case TEGRA30_I2S_LCOEF_2_4_0:
  322. case TEGRA30_I2S_LCOEF_2_4_1:
  323. case TEGRA30_I2S_LCOEF_2_4_2:
  324. return true;
  325. default:
  326. return false;
  327. };
  328. }
  329. static bool tegra30_i2s_volatile_reg(struct device *dev, unsigned int reg)
  330. {
  331. switch (reg) {
  332. case TEGRA30_I2S_FLOW_STATUS:
  333. case TEGRA30_I2S_FLOW_TOTAL:
  334. case TEGRA30_I2S_FLOW_OVER:
  335. case TEGRA30_I2S_FLOW_UNDER:
  336. return true;
  337. default:
  338. return false;
  339. };
  340. }
  341. static const struct regmap_config tegra30_i2s_regmap_config = {
  342. .reg_bits = 32,
  343. .reg_stride = 4,
  344. .val_bits = 32,
  345. .max_register = TEGRA30_I2S_LCOEF_2_4_2,
  346. .writeable_reg = tegra30_i2s_wr_rd_reg,
  347. .readable_reg = tegra30_i2s_wr_rd_reg,
  348. .volatile_reg = tegra30_i2s_volatile_reg,
  349. .cache_type = REGCACHE_RBTREE,
  350. };
  351. static const struct tegra30_i2s_soc_data tegra30_i2s_config = {
  352. .set_audio_cif = tegra30_ahub_set_cif,
  353. };
  354. static const struct tegra30_i2s_soc_data tegra124_i2s_config = {
  355. .set_audio_cif = tegra124_ahub_set_cif,
  356. };
  357. static const struct of_device_id tegra30_i2s_of_match[] = {
  358. { .compatible = "nvidia,tegra124-i2s", .data = &tegra124_i2s_config },
  359. { .compatible = "nvidia,tegra30-i2s", .data = &tegra30_i2s_config },
  360. {},
  361. };
  362. static int tegra30_i2s_platform_probe(struct platform_device *pdev)
  363. {
  364. struct tegra30_i2s *i2s;
  365. const struct of_device_id *match;
  366. u32 cif_ids[2];
  367. struct resource *mem, *memregion;
  368. void __iomem *regs;
  369. int ret;
  370. i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_i2s), GFP_KERNEL);
  371. if (!i2s) {
  372. dev_err(&pdev->dev, "Can't allocate tegra30_i2s\n");
  373. ret = -ENOMEM;
  374. goto err;
  375. }
  376. dev_set_drvdata(&pdev->dev, i2s);
  377. match = of_match_device(tegra30_i2s_of_match, &pdev->dev);
  378. if (!match) {
  379. dev_err(&pdev->dev, "Error: No device match found\n");
  380. ret = -ENODEV;
  381. goto err;
  382. }
  383. i2s->soc_data = (struct tegra30_i2s_soc_data *)match->data;
  384. i2s->dai = tegra30_i2s_dai_template;
  385. i2s->dai.name = dev_name(&pdev->dev);
  386. ret = of_property_read_u32_array(pdev->dev.of_node,
  387. "nvidia,ahub-cif-ids", cif_ids,
  388. ARRAY_SIZE(cif_ids));
  389. if (ret < 0)
  390. goto err;
  391. i2s->playback_i2s_cif = cif_ids[0];
  392. i2s->capture_i2s_cif = cif_ids[1];
  393. i2s->clk_i2s = clk_get(&pdev->dev, NULL);
  394. if (IS_ERR(i2s->clk_i2s)) {
  395. dev_err(&pdev->dev, "Can't retrieve i2s clock\n");
  396. ret = PTR_ERR(i2s->clk_i2s);
  397. goto err;
  398. }
  399. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  400. if (!mem) {
  401. dev_err(&pdev->dev, "No memory resource\n");
  402. ret = -ENODEV;
  403. goto err_clk_put;
  404. }
  405. memregion = devm_request_mem_region(&pdev->dev, mem->start,
  406. resource_size(mem), DRV_NAME);
  407. if (!memregion) {
  408. dev_err(&pdev->dev, "Memory region already claimed\n");
  409. ret = -EBUSY;
  410. goto err_clk_put;
  411. }
  412. regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
  413. if (!regs) {
  414. dev_err(&pdev->dev, "ioremap failed\n");
  415. ret = -ENOMEM;
  416. goto err_clk_put;
  417. }
  418. i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
  419. &tegra30_i2s_regmap_config);
  420. if (IS_ERR(i2s->regmap)) {
  421. dev_err(&pdev->dev, "regmap init failed\n");
  422. ret = PTR_ERR(i2s->regmap);
  423. goto err_clk_put;
  424. }
  425. regcache_cache_only(i2s->regmap, true);
  426. pm_runtime_enable(&pdev->dev);
  427. if (!pm_runtime_enabled(&pdev->dev)) {
  428. ret = tegra30_i2s_runtime_resume(&pdev->dev);
  429. if (ret)
  430. goto err_pm_disable;
  431. }
  432. ret = snd_soc_register_component(&pdev->dev, &tegra30_i2s_component,
  433. &i2s->dai, 1);
  434. if (ret) {
  435. dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  436. ret = -ENOMEM;
  437. goto err_suspend;
  438. }
  439. ret = tegra_pcm_platform_register(&pdev->dev);
  440. if (ret) {
  441. dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  442. goto err_unregister_component;
  443. }
  444. return 0;
  445. err_unregister_component:
  446. snd_soc_unregister_component(&pdev->dev);
  447. err_suspend:
  448. if (!pm_runtime_status_suspended(&pdev->dev))
  449. tegra30_i2s_runtime_suspend(&pdev->dev);
  450. err_pm_disable:
  451. pm_runtime_disable(&pdev->dev);
  452. err_clk_put:
  453. clk_put(i2s->clk_i2s);
  454. err:
  455. return ret;
  456. }
  457. static int tegra30_i2s_platform_remove(struct platform_device *pdev)
  458. {
  459. struct tegra30_i2s *i2s = dev_get_drvdata(&pdev->dev);
  460. pm_runtime_disable(&pdev->dev);
  461. if (!pm_runtime_status_suspended(&pdev->dev))
  462. tegra30_i2s_runtime_suspend(&pdev->dev);
  463. tegra_pcm_platform_unregister(&pdev->dev);
  464. snd_soc_unregister_component(&pdev->dev);
  465. clk_put(i2s->clk_i2s);
  466. return 0;
  467. }
  468. #ifdef CONFIG_PM_SLEEP
  469. static int tegra30_i2s_suspend(struct device *dev)
  470. {
  471. struct tegra30_i2s *i2s = dev_get_drvdata(dev);
  472. regcache_mark_dirty(i2s->regmap);
  473. return 0;
  474. }
  475. static int tegra30_i2s_resume(struct device *dev)
  476. {
  477. struct tegra30_i2s *i2s = dev_get_drvdata(dev);
  478. int ret;
  479. ret = pm_runtime_get_sync(dev);
  480. if (ret < 0)
  481. return ret;
  482. ret = regcache_sync(i2s->regmap);
  483. pm_runtime_put(dev);
  484. return ret;
  485. }
  486. #endif
  487. static const struct dev_pm_ops tegra30_i2s_pm_ops = {
  488. SET_RUNTIME_PM_OPS(tegra30_i2s_runtime_suspend,
  489. tegra30_i2s_runtime_resume, NULL)
  490. SET_SYSTEM_SLEEP_PM_OPS(tegra30_i2s_suspend, tegra30_i2s_resume)
  491. };
  492. static struct platform_driver tegra30_i2s_driver = {
  493. .driver = {
  494. .name = DRV_NAME,
  495. .owner = THIS_MODULE,
  496. .of_match_table = tegra30_i2s_of_match,
  497. .pm = &tegra30_i2s_pm_ops,
  498. },
  499. .probe = tegra30_i2s_platform_probe,
  500. .remove = tegra30_i2s_platform_remove,
  501. };
  502. module_platform_driver(tegra30_i2s_driver);
  503. MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
  504. MODULE_DESCRIPTION("Tegra30 I2S ASoC driver");
  505. MODULE_LICENSE("GPL");
  506. MODULE_ALIAS("platform:" DRV_NAME);
  507. MODULE_DEVICE_TABLE(of, tegra30_i2s_of_match);