img-i2s-in.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*
  2. * IMG I2S input controller driver
  3. *
  4. * Copyright (C) 2015 Imagination Technologies Ltd.
  5. *
  6. * Author: Damien Horsley <Damien.Horsley@imgtec.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms and conditions of the GNU General Public License,
  10. * version 2, as published by the Free Software Foundation.
  11. */
  12. #include <linux/clk.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/of.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/pm_runtime.h>
  19. #include <linux/reset.h>
  20. #include <sound/core.h>
  21. #include <sound/dmaengine_pcm.h>
  22. #include <sound/initval.h>
  23. #include <sound/pcm.h>
  24. #include <sound/pcm_params.h>
  25. #include <sound/soc.h>
  26. #define IMG_I2S_IN_RX_FIFO 0x0
  27. #define IMG_I2S_IN_CTL 0x4
  28. #define IMG_I2S_IN_CTL_ACTIVE_CHAN_MASK 0xfffffffc
  29. #define IMG_I2S_IN_CTL_ACTIVE_CH_SHIFT 2
  30. #define IMG_I2S_IN_CTL_16PACK_MASK BIT(1)
  31. #define IMG_I2S_IN_CTL_ME_MASK BIT(0)
  32. #define IMG_I2S_IN_CH_CTL 0x4
  33. #define IMG_I2S_IN_CH_CTL_CCDEL_MASK 0x38000
  34. #define IMG_I2S_IN_CH_CTL_CCDEL_SHIFT 15
  35. #define IMG_I2S_IN_CH_CTL_FEN_MASK BIT(14)
  36. #define IMG_I2S_IN_CH_CTL_FMODE_MASK BIT(13)
  37. #define IMG_I2S_IN_CH_CTL_16PACK_MASK BIT(12)
  38. #define IMG_I2S_IN_CH_CTL_JUST_MASK BIT(10)
  39. #define IMG_I2S_IN_CH_CTL_PACKH_MASK BIT(9)
  40. #define IMG_I2S_IN_CH_CTL_CLK_TRANS_MASK BIT(8)
  41. #define IMG_I2S_IN_CH_CTL_BLKP_MASK BIT(7)
  42. #define IMG_I2S_IN_CH_CTL_FIFO_FLUSH_MASK BIT(6)
  43. #define IMG_I2S_IN_CH_CTL_LRD_MASK BIT(3)
  44. #define IMG_I2S_IN_CH_CTL_FW_MASK BIT(2)
  45. #define IMG_I2S_IN_CH_CTL_SW_MASK BIT(1)
  46. #define IMG_I2S_IN_CH_CTL_ME_MASK BIT(0)
  47. #define IMG_I2S_IN_CH_STRIDE 0x20
  48. struct img_i2s_in {
  49. void __iomem *base;
  50. struct clk *clk_sys;
  51. struct snd_dmaengine_dai_dma_data dma_data;
  52. struct device *dev;
  53. unsigned int max_i2s_chan;
  54. void __iomem *channel_base;
  55. unsigned int active_channels;
  56. struct snd_soc_dai_driver dai_driver;
  57. u32 suspend_ctl;
  58. u32 *suspend_ch_ctl;
  59. };
  60. static int img_i2s_in_runtime_suspend(struct device *dev)
  61. {
  62. struct img_i2s_in *i2s = dev_get_drvdata(dev);
  63. clk_disable_unprepare(i2s->clk_sys);
  64. return 0;
  65. }
  66. static int img_i2s_in_runtime_resume(struct device *dev)
  67. {
  68. struct img_i2s_in *i2s = dev_get_drvdata(dev);
  69. int ret;
  70. ret = clk_prepare_enable(i2s->clk_sys);
  71. if (ret) {
  72. dev_err(dev, "Unable to enable sys clock\n");
  73. return ret;
  74. }
  75. return 0;
  76. }
  77. static inline void img_i2s_in_writel(struct img_i2s_in *i2s, u32 val, u32 reg)
  78. {
  79. writel(val, i2s->base + reg);
  80. }
  81. static inline u32 img_i2s_in_readl(struct img_i2s_in *i2s, u32 reg)
  82. {
  83. return readl(i2s->base + reg);
  84. }
  85. static inline void img_i2s_in_ch_writel(struct img_i2s_in *i2s, u32 chan,
  86. u32 val, u32 reg)
  87. {
  88. writel(val, i2s->channel_base + (chan * IMG_I2S_IN_CH_STRIDE) + reg);
  89. }
  90. static inline u32 img_i2s_in_ch_readl(struct img_i2s_in *i2s, u32 chan,
  91. u32 reg)
  92. {
  93. return readl(i2s->channel_base + (chan * IMG_I2S_IN_CH_STRIDE) + reg);
  94. }
  95. static inline void img_i2s_in_ch_disable(struct img_i2s_in *i2s, u32 chan)
  96. {
  97. u32 reg;
  98. reg = img_i2s_in_ch_readl(i2s, chan, IMG_I2S_IN_CH_CTL);
  99. reg &= ~IMG_I2S_IN_CH_CTL_ME_MASK;
  100. img_i2s_in_ch_writel(i2s, chan, reg, IMG_I2S_IN_CH_CTL);
  101. }
  102. static inline void img_i2s_in_ch_enable(struct img_i2s_in *i2s, u32 chan)
  103. {
  104. u32 reg;
  105. reg = img_i2s_in_ch_readl(i2s, chan, IMG_I2S_IN_CH_CTL);
  106. reg |= IMG_I2S_IN_CH_CTL_ME_MASK;
  107. img_i2s_in_ch_writel(i2s, chan, reg, IMG_I2S_IN_CH_CTL);
  108. }
  109. static inline void img_i2s_in_disable(struct img_i2s_in *i2s)
  110. {
  111. u32 reg;
  112. reg = img_i2s_in_readl(i2s, IMG_I2S_IN_CTL);
  113. reg &= ~IMG_I2S_IN_CTL_ME_MASK;
  114. img_i2s_in_writel(i2s, reg, IMG_I2S_IN_CTL);
  115. }
  116. static inline void img_i2s_in_enable(struct img_i2s_in *i2s)
  117. {
  118. u32 reg;
  119. reg = img_i2s_in_readl(i2s, IMG_I2S_IN_CTL);
  120. reg |= IMG_I2S_IN_CTL_ME_MASK;
  121. img_i2s_in_writel(i2s, reg, IMG_I2S_IN_CTL);
  122. }
  123. static inline void img_i2s_in_flush(struct img_i2s_in *i2s)
  124. {
  125. int i;
  126. u32 reg;
  127. for (i = 0; i < i2s->active_channels; i++) {
  128. reg = img_i2s_in_ch_readl(i2s, i, IMG_I2S_IN_CH_CTL);
  129. reg |= IMG_I2S_IN_CH_CTL_FIFO_FLUSH_MASK;
  130. img_i2s_in_ch_writel(i2s, i, reg, IMG_I2S_IN_CH_CTL);
  131. reg &= ~IMG_I2S_IN_CH_CTL_FIFO_FLUSH_MASK;
  132. img_i2s_in_ch_writel(i2s, i, reg, IMG_I2S_IN_CH_CTL);
  133. }
  134. }
  135. static int img_i2s_in_trigger(struct snd_pcm_substream *substream, int cmd,
  136. struct snd_soc_dai *dai)
  137. {
  138. struct img_i2s_in *i2s = snd_soc_dai_get_drvdata(dai);
  139. switch (cmd) {
  140. case SNDRV_PCM_TRIGGER_START:
  141. case SNDRV_PCM_TRIGGER_RESUME:
  142. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  143. img_i2s_in_enable(i2s);
  144. break;
  145. case SNDRV_PCM_TRIGGER_STOP:
  146. case SNDRV_PCM_TRIGGER_SUSPEND:
  147. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  148. img_i2s_in_disable(i2s);
  149. break;
  150. default:
  151. return -EINVAL;
  152. }
  153. return 0;
  154. }
  155. static int img_i2s_in_check_rate(struct img_i2s_in *i2s,
  156. unsigned int sample_rate, unsigned int frame_size,
  157. unsigned int *bclk_filter_enable,
  158. unsigned int *bclk_filter_value)
  159. {
  160. unsigned int bclk_freq, cur_freq;
  161. bclk_freq = sample_rate * frame_size;
  162. cur_freq = clk_get_rate(i2s->clk_sys);
  163. if (cur_freq >= bclk_freq * 8) {
  164. *bclk_filter_enable = 1;
  165. *bclk_filter_value = 0;
  166. } else if (cur_freq >= bclk_freq * 7) {
  167. *bclk_filter_enable = 1;
  168. *bclk_filter_value = 1;
  169. } else if (cur_freq >= bclk_freq * 6) {
  170. *bclk_filter_enable = 0;
  171. *bclk_filter_value = 0;
  172. } else {
  173. dev_err(i2s->dev,
  174. "Sys clock rate %u insufficient for sample rate %u\n",
  175. cur_freq, sample_rate);
  176. return -EINVAL;
  177. }
  178. return 0;
  179. }
  180. static int img_i2s_in_hw_params(struct snd_pcm_substream *substream,
  181. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  182. {
  183. struct img_i2s_in *i2s = snd_soc_dai_get_drvdata(dai);
  184. unsigned int rate, channels, i2s_channels, frame_size;
  185. unsigned int bclk_filter_enable, bclk_filter_value;
  186. int i, ret = 0;
  187. u32 reg, control_mask, chan_control_mask;
  188. u32 control_set = 0, chan_control_set = 0;
  189. snd_pcm_format_t format;
  190. rate = params_rate(params);
  191. format = params_format(params);
  192. channels = params_channels(params);
  193. i2s_channels = channels / 2;
  194. switch (format) {
  195. case SNDRV_PCM_FORMAT_S32_LE:
  196. frame_size = 64;
  197. chan_control_set |= IMG_I2S_IN_CH_CTL_SW_MASK;
  198. chan_control_set |= IMG_I2S_IN_CH_CTL_FW_MASK;
  199. chan_control_set |= IMG_I2S_IN_CH_CTL_PACKH_MASK;
  200. break;
  201. case SNDRV_PCM_FORMAT_S24_LE:
  202. frame_size = 64;
  203. chan_control_set |= IMG_I2S_IN_CH_CTL_SW_MASK;
  204. chan_control_set |= IMG_I2S_IN_CH_CTL_FW_MASK;
  205. break;
  206. case SNDRV_PCM_FORMAT_S16_LE:
  207. frame_size = 32;
  208. control_set |= IMG_I2S_IN_CTL_16PACK_MASK;
  209. chan_control_set |= IMG_I2S_IN_CH_CTL_16PACK_MASK;
  210. break;
  211. default:
  212. return -EINVAL;
  213. }
  214. if ((channels < 2) ||
  215. (channels > (i2s->max_i2s_chan * 2)) ||
  216. (channels % 2))
  217. return -EINVAL;
  218. control_set |= ((i2s_channels - 1) << IMG_I2S_IN_CTL_ACTIVE_CH_SHIFT);
  219. ret = img_i2s_in_check_rate(i2s, rate, frame_size,
  220. &bclk_filter_enable, &bclk_filter_value);
  221. if (ret < 0)
  222. return ret;
  223. if (bclk_filter_enable)
  224. chan_control_set |= IMG_I2S_IN_CH_CTL_FEN_MASK;
  225. if (bclk_filter_value)
  226. chan_control_set |= IMG_I2S_IN_CH_CTL_FMODE_MASK;
  227. control_mask = IMG_I2S_IN_CTL_16PACK_MASK |
  228. IMG_I2S_IN_CTL_ACTIVE_CHAN_MASK;
  229. chan_control_mask = IMG_I2S_IN_CH_CTL_16PACK_MASK |
  230. IMG_I2S_IN_CH_CTL_FEN_MASK |
  231. IMG_I2S_IN_CH_CTL_FMODE_MASK |
  232. IMG_I2S_IN_CH_CTL_SW_MASK |
  233. IMG_I2S_IN_CH_CTL_FW_MASK |
  234. IMG_I2S_IN_CH_CTL_PACKH_MASK;
  235. reg = img_i2s_in_readl(i2s, IMG_I2S_IN_CTL);
  236. reg = (reg & ~control_mask) | control_set;
  237. img_i2s_in_writel(i2s, reg, IMG_I2S_IN_CTL);
  238. for (i = 0; i < i2s->active_channels; i++)
  239. img_i2s_in_ch_disable(i2s, i);
  240. for (i = 0; i < i2s->max_i2s_chan; i++) {
  241. reg = img_i2s_in_ch_readl(i2s, i, IMG_I2S_IN_CH_CTL);
  242. reg = (reg & ~chan_control_mask) | chan_control_set;
  243. img_i2s_in_ch_writel(i2s, i, reg, IMG_I2S_IN_CH_CTL);
  244. }
  245. i2s->active_channels = i2s_channels;
  246. img_i2s_in_flush(i2s);
  247. for (i = 0; i < i2s->active_channels; i++)
  248. img_i2s_in_ch_enable(i2s, i);
  249. return 0;
  250. }
  251. static int img_i2s_in_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  252. {
  253. struct img_i2s_in *i2s = snd_soc_dai_get_drvdata(dai);
  254. int i, ret;
  255. u32 chan_control_mask, lrd_set = 0, blkp_set = 0, chan_control_set = 0;
  256. u32 reg;
  257. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  258. case SND_SOC_DAIFMT_NB_NF:
  259. lrd_set |= IMG_I2S_IN_CH_CTL_LRD_MASK;
  260. break;
  261. case SND_SOC_DAIFMT_NB_IF:
  262. break;
  263. case SND_SOC_DAIFMT_IB_NF:
  264. lrd_set |= IMG_I2S_IN_CH_CTL_LRD_MASK;
  265. blkp_set |= IMG_I2S_IN_CH_CTL_BLKP_MASK;
  266. break;
  267. case SND_SOC_DAIFMT_IB_IF:
  268. blkp_set |= IMG_I2S_IN_CH_CTL_BLKP_MASK;
  269. break;
  270. default:
  271. return -EINVAL;
  272. }
  273. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  274. case SND_SOC_DAIFMT_I2S:
  275. chan_control_set |= IMG_I2S_IN_CH_CTL_CLK_TRANS_MASK;
  276. break;
  277. case SND_SOC_DAIFMT_LEFT_J:
  278. break;
  279. default:
  280. return -EINVAL;
  281. }
  282. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  283. case SND_SOC_DAIFMT_CBM_CFM:
  284. break;
  285. default:
  286. return -EINVAL;
  287. }
  288. chan_control_mask = IMG_I2S_IN_CH_CTL_CLK_TRANS_MASK;
  289. ret = pm_runtime_get_sync(i2s->dev);
  290. if (ret < 0)
  291. return ret;
  292. for (i = 0; i < i2s->active_channels; i++)
  293. img_i2s_in_ch_disable(i2s, i);
  294. /*
  295. * BLKP and LRD must be set during separate register writes
  296. */
  297. for (i = 0; i < i2s->max_i2s_chan; i++) {
  298. reg = img_i2s_in_ch_readl(i2s, i, IMG_I2S_IN_CH_CTL);
  299. reg = (reg & ~chan_control_mask) | chan_control_set;
  300. img_i2s_in_ch_writel(i2s, i, reg, IMG_I2S_IN_CH_CTL);
  301. reg = (reg & ~IMG_I2S_IN_CH_CTL_BLKP_MASK) | blkp_set;
  302. img_i2s_in_ch_writel(i2s, i, reg, IMG_I2S_IN_CH_CTL);
  303. reg = (reg & ~IMG_I2S_IN_CH_CTL_LRD_MASK) | lrd_set;
  304. img_i2s_in_ch_writel(i2s, i, reg, IMG_I2S_IN_CH_CTL);
  305. }
  306. for (i = 0; i < i2s->active_channels; i++)
  307. img_i2s_in_ch_enable(i2s, i);
  308. pm_runtime_put(i2s->dev);
  309. return 0;
  310. }
  311. static const struct snd_soc_dai_ops img_i2s_in_dai_ops = {
  312. .trigger = img_i2s_in_trigger,
  313. .hw_params = img_i2s_in_hw_params,
  314. .set_fmt = img_i2s_in_set_fmt
  315. };
  316. static int img_i2s_in_dai_probe(struct snd_soc_dai *dai)
  317. {
  318. struct img_i2s_in *i2s = snd_soc_dai_get_drvdata(dai);
  319. snd_soc_dai_init_dma_data(dai, NULL, &i2s->dma_data);
  320. return 0;
  321. }
  322. static const struct snd_soc_component_driver img_i2s_in_component = {
  323. .name = "img-i2s-in"
  324. };
  325. static int img_i2s_in_dma_prepare_slave_config(struct snd_pcm_substream *st,
  326. struct snd_pcm_hw_params *params, struct dma_slave_config *sc)
  327. {
  328. unsigned int i2s_channels = params_channels(params) / 2;
  329. struct snd_soc_pcm_runtime *rtd = st->private_data;
  330. struct snd_dmaengine_dai_dma_data *dma_data;
  331. int ret;
  332. dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, st);
  333. ret = snd_hwparams_to_dma_slave_config(st, params, sc);
  334. if (ret)
  335. return ret;
  336. sc->src_addr = dma_data->addr;
  337. sc->src_addr_width = dma_data->addr_width;
  338. sc->src_maxburst = 4 * i2s_channels;
  339. return 0;
  340. }
  341. static const struct snd_dmaengine_pcm_config img_i2s_in_dma_config = {
  342. .prepare_slave_config = img_i2s_in_dma_prepare_slave_config
  343. };
  344. static int img_i2s_in_probe(struct platform_device *pdev)
  345. {
  346. struct img_i2s_in *i2s;
  347. struct resource *res;
  348. void __iomem *base;
  349. int ret, i;
  350. struct reset_control *rst;
  351. unsigned int max_i2s_chan_pow_2;
  352. struct device *dev = &pdev->dev;
  353. i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL);
  354. if (!i2s)
  355. return -ENOMEM;
  356. platform_set_drvdata(pdev, i2s);
  357. i2s->dev = dev;
  358. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  359. base = devm_ioremap_resource(dev, res);
  360. if (IS_ERR(base))
  361. return PTR_ERR(base);
  362. i2s->base = base;
  363. if (of_property_read_u32(pdev->dev.of_node, "img,i2s-channels",
  364. &i2s->max_i2s_chan)) {
  365. dev_err(dev, "No img,i2s-channels property\n");
  366. return -EINVAL;
  367. }
  368. max_i2s_chan_pow_2 = 1 << get_count_order(i2s->max_i2s_chan);
  369. i2s->channel_base = base + (max_i2s_chan_pow_2 * 0x20);
  370. i2s->clk_sys = devm_clk_get(dev, "sys");
  371. if (IS_ERR(i2s->clk_sys)) {
  372. if (PTR_ERR(i2s->clk_sys) != -EPROBE_DEFER)
  373. dev_err(dev, "Failed to acquire clock 'sys'\n");
  374. return PTR_ERR(i2s->clk_sys);
  375. }
  376. pm_runtime_enable(&pdev->dev);
  377. if (!pm_runtime_enabled(&pdev->dev)) {
  378. ret = img_i2s_in_runtime_resume(&pdev->dev);
  379. if (ret)
  380. goto err_pm_disable;
  381. }
  382. ret = pm_runtime_get_sync(&pdev->dev);
  383. if (ret < 0)
  384. goto err_suspend;
  385. i2s->active_channels = 1;
  386. i2s->dma_data.addr = res->start + IMG_I2S_IN_RX_FIFO;
  387. i2s->dma_data.addr_width = 4;
  388. i2s->dai_driver.probe = img_i2s_in_dai_probe;
  389. i2s->dai_driver.capture.channels_min = 2;
  390. i2s->dai_driver.capture.channels_max = i2s->max_i2s_chan * 2;
  391. i2s->dai_driver.capture.rates = SNDRV_PCM_RATE_8000_192000;
  392. i2s->dai_driver.capture.formats = SNDRV_PCM_FMTBIT_S32_LE |
  393. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE;
  394. i2s->dai_driver.ops = &img_i2s_in_dai_ops;
  395. rst = devm_reset_control_get_exclusive(dev, "rst");
  396. if (IS_ERR(rst)) {
  397. if (PTR_ERR(rst) == -EPROBE_DEFER) {
  398. ret = -EPROBE_DEFER;
  399. goto err_suspend;
  400. }
  401. dev_dbg(dev, "No top level reset found\n");
  402. img_i2s_in_disable(i2s);
  403. for (i = 0; i < i2s->max_i2s_chan; i++)
  404. img_i2s_in_ch_disable(i2s, i);
  405. } else {
  406. reset_control_assert(rst);
  407. reset_control_deassert(rst);
  408. }
  409. img_i2s_in_writel(i2s, 0, IMG_I2S_IN_CTL);
  410. for (i = 0; i < i2s->max_i2s_chan; i++)
  411. img_i2s_in_ch_writel(i2s, i,
  412. (4 << IMG_I2S_IN_CH_CTL_CCDEL_SHIFT) |
  413. IMG_I2S_IN_CH_CTL_JUST_MASK |
  414. IMG_I2S_IN_CH_CTL_FW_MASK, IMG_I2S_IN_CH_CTL);
  415. pm_runtime_put(&pdev->dev);
  416. i2s->suspend_ch_ctl = devm_kcalloc(dev,
  417. i2s->max_i2s_chan, sizeof(*i2s->suspend_ch_ctl), GFP_KERNEL);
  418. if (!i2s->suspend_ch_ctl) {
  419. ret = -ENOMEM;
  420. goto err_suspend;
  421. }
  422. ret = devm_snd_soc_register_component(dev, &img_i2s_in_component,
  423. &i2s->dai_driver, 1);
  424. if (ret)
  425. goto err_suspend;
  426. ret = devm_snd_dmaengine_pcm_register(dev, &img_i2s_in_dma_config, 0);
  427. if (ret)
  428. goto err_suspend;
  429. return 0;
  430. err_suspend:
  431. if (!pm_runtime_enabled(&pdev->dev))
  432. img_i2s_in_runtime_suspend(&pdev->dev);
  433. err_pm_disable:
  434. pm_runtime_disable(&pdev->dev);
  435. return ret;
  436. }
  437. static int img_i2s_in_dev_remove(struct platform_device *pdev)
  438. {
  439. pm_runtime_disable(&pdev->dev);
  440. if (!pm_runtime_status_suspended(&pdev->dev))
  441. img_i2s_in_runtime_suspend(&pdev->dev);
  442. return 0;
  443. }
  444. #ifdef CONFIG_PM_SLEEP
  445. static int img_i2s_in_suspend(struct device *dev)
  446. {
  447. struct img_i2s_in *i2s = dev_get_drvdata(dev);
  448. int i, ret;
  449. u32 reg;
  450. if (pm_runtime_status_suspended(dev)) {
  451. ret = img_i2s_in_runtime_resume(dev);
  452. if (ret)
  453. return ret;
  454. }
  455. for (i = 0; i < i2s->max_i2s_chan; i++) {
  456. reg = img_i2s_in_ch_readl(i2s, i, IMG_I2S_IN_CH_CTL);
  457. i2s->suspend_ch_ctl[i] = reg;
  458. }
  459. i2s->suspend_ctl = img_i2s_in_readl(i2s, IMG_I2S_IN_CTL);
  460. img_i2s_in_runtime_suspend(dev);
  461. return 0;
  462. }
  463. static int img_i2s_in_resume(struct device *dev)
  464. {
  465. struct img_i2s_in *i2s = dev_get_drvdata(dev);
  466. int i, ret;
  467. u32 reg;
  468. ret = img_i2s_in_runtime_resume(dev);
  469. if (ret)
  470. return ret;
  471. for (i = 0; i < i2s->max_i2s_chan; i++) {
  472. reg = i2s->suspend_ch_ctl[i];
  473. img_i2s_in_ch_writel(i2s, i, reg, IMG_I2S_IN_CH_CTL);
  474. }
  475. img_i2s_in_writel(i2s, i2s->suspend_ctl, IMG_I2S_IN_CTL);
  476. if (pm_runtime_status_suspended(dev))
  477. img_i2s_in_runtime_suspend(dev);
  478. return 0;
  479. }
  480. #endif
  481. static const struct of_device_id img_i2s_in_of_match[] = {
  482. { .compatible = "img,i2s-in" },
  483. {}
  484. };
  485. MODULE_DEVICE_TABLE(of, img_i2s_in_of_match);
  486. static const struct dev_pm_ops img_i2s_in_pm_ops = {
  487. SET_RUNTIME_PM_OPS(img_i2s_in_runtime_suspend,
  488. img_i2s_in_runtime_resume, NULL)
  489. SET_SYSTEM_SLEEP_PM_OPS(img_i2s_in_suspend, img_i2s_in_resume)
  490. };
  491. static struct platform_driver img_i2s_in_driver = {
  492. .driver = {
  493. .name = "img-i2s-in",
  494. .of_match_table = img_i2s_in_of_match,
  495. .pm = &img_i2s_in_pm_ops
  496. },
  497. .probe = img_i2s_in_probe,
  498. .remove = img_i2s_in_dev_remove
  499. };
  500. module_platform_driver(img_i2s_in_driver);
  501. MODULE_AUTHOR("Damien Horsley <Damien.Horsley@imgtec.com>");
  502. MODULE_DESCRIPTION("IMG I2S Input Driver");
  503. MODULE_LICENSE("GPL v2");