fsl_asrc.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Freescale ASRC ALSA SoC Digital Audio Interface (DAI) driver
  4. //
  5. // Copyright (C) 2014 Freescale Semiconductor, Inc.
  6. //
  7. // Author: Nicolin Chen <nicoleotsuka@gmail.com>
  8. #include <linux/clk.h>
  9. #include <linux/delay.h>
  10. #include <linux/dma-mapping.h>
  11. #include <linux/module.h>
  12. #include <linux/of_platform.h>
  13. #include <linux/dma/imx-dma.h>
  14. #include <linux/pm_runtime.h>
  15. #include <sound/dmaengine_pcm.h>
  16. #include <sound/pcm_params.h>
  17. #include "fsl_asrc.h"
  18. #define IDEAL_RATIO_DECIMAL_DEPTH 26
  19. #define DIVIDER_NUM 64
  20. #define INIT_RETRY_NUM 50
  21. #define pair_err(fmt, ...) \
  22. dev_err(&asrc->pdev->dev, "Pair %c: " fmt, 'A' + index, ##__VA_ARGS__)
  23. #define pair_dbg(fmt, ...) \
  24. dev_dbg(&asrc->pdev->dev, "Pair %c: " fmt, 'A' + index, ##__VA_ARGS__)
  25. #define pair_warn(fmt, ...) \
  26. dev_warn(&asrc->pdev->dev, "Pair %c: " fmt, 'A' + index, ##__VA_ARGS__)
  27. /* Corresponding to process_option */
  28. static unsigned int supported_asrc_rate[] = {
  29. 5512, 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000,
  30. 64000, 88200, 96000, 128000, 176400, 192000,
  31. };
  32. static struct snd_pcm_hw_constraint_list fsl_asrc_rate_constraints = {
  33. .count = ARRAY_SIZE(supported_asrc_rate),
  34. .list = supported_asrc_rate,
  35. };
  36. /*
  37. * The following tables map the relationship between asrc_inclk/asrc_outclk in
  38. * fsl_asrc.h and the registers of ASRCSR
  39. */
  40. static unsigned char input_clk_map_imx35[ASRC_CLK_MAP_LEN] = {
  41. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
  42. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  43. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  44. };
  45. static unsigned char output_clk_map_imx35[ASRC_CLK_MAP_LEN] = {
  46. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
  47. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  48. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  49. };
  50. /* i.MX53 uses the same map for input and output */
  51. static unsigned char input_clk_map_imx53[ASRC_CLK_MAP_LEN] = {
  52. /* 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf */
  53. 0x0, 0x1, 0x2, 0x7, 0x4, 0x5, 0x6, 0x3, 0x8, 0x9, 0xa, 0xb, 0xc, 0xf, 0xe, 0xd,
  54. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  55. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  56. };
  57. static unsigned char output_clk_map_imx53[ASRC_CLK_MAP_LEN] = {
  58. /* 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf */
  59. 0x8, 0x9, 0xa, 0x7, 0xc, 0x5, 0x6, 0xb, 0x0, 0x1, 0x2, 0x3, 0x4, 0xf, 0xe, 0xd,
  60. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  61. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  62. };
  63. /*
  64. * i.MX8QM/i.MX8QXP uses the same map for input and output.
  65. * clk_map_imx8qm[0] is for i.MX8QM asrc0
  66. * clk_map_imx8qm[1] is for i.MX8QM asrc1
  67. * clk_map_imx8qxp[0] is for i.MX8QXP asrc0
  68. * clk_map_imx8qxp[1] is for i.MX8QXP asrc1
  69. */
  70. static unsigned char clk_map_imx8qm[2][ASRC_CLK_MAP_LEN] = {
  71. {
  72. 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x0,
  73. 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
  74. 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf,
  75. },
  76. {
  77. 0xf, 0xf, 0xf, 0xf, 0xf, 0x7, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x0,
  78. 0x0, 0x1, 0x2, 0x3, 0xb, 0xc, 0xf, 0xf, 0xd, 0xe, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf,
  79. 0x4, 0x5, 0x6, 0xf, 0x8, 0x9, 0xa, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf,
  80. },
  81. };
  82. static unsigned char clk_map_imx8qxp[2][ASRC_CLK_MAP_LEN] = {
  83. {
  84. 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x0,
  85. 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0xf, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xf, 0xf,
  86. 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf,
  87. },
  88. {
  89. 0xf, 0xf, 0xf, 0xf, 0xf, 0x7, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x0,
  90. 0x0, 0x1, 0x2, 0x3, 0x7, 0x8, 0xf, 0xf, 0x9, 0xa, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf,
  91. 0xf, 0xf, 0x6, 0xf, 0xf, 0xf, 0xa, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf,
  92. },
  93. };
  94. static unsigned char clk_map_imx952[ASRC_CLK_MAP_LEN] = {
  95. 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x0,
  96. 0x0, 0x1, 0x2, 0x3, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x4, 0x5, 0x6, 0x8, 0xf, 0xf,
  97. 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x7, 0x9, 0xa, 0xb, 0xc, 0xd, 0xf, 0xf, 0xf, 0xf,
  98. };
  99. /*
  100. * According to RM, the divider range is 1 ~ 8,
  101. * prescaler is power of 2 from 1 ~ 128.
  102. */
  103. static int asrc_clk_divider[DIVIDER_NUM] = {
  104. 1, 2, 4, 8, 16, 32, 64, 128, /* divider = 1 */
  105. 2, 4, 8, 16, 32, 64, 128, 256, /* divider = 2 */
  106. 3, 6, 12, 24, 48, 96, 192, 384, /* divider = 3 */
  107. 4, 8, 16, 32, 64, 128, 256, 512, /* divider = 4 */
  108. 5, 10, 20, 40, 80, 160, 320, 640, /* divider = 5 */
  109. 6, 12, 24, 48, 96, 192, 384, 768, /* divider = 6 */
  110. 7, 14, 28, 56, 112, 224, 448, 896, /* divider = 7 */
  111. 8, 16, 32, 64, 128, 256, 512, 1024, /* divider = 8 */
  112. };
  113. /*
  114. * Check if the divider is available for internal ratio mode
  115. */
  116. static bool fsl_asrc_divider_avail(int clk_rate, int rate, int *div)
  117. {
  118. u32 rem, i;
  119. u64 n;
  120. if (div)
  121. *div = 0;
  122. if (clk_rate == 0 || rate == 0)
  123. return false;
  124. n = clk_rate;
  125. rem = do_div(n, rate);
  126. if (div)
  127. *div = n;
  128. if (rem != 0)
  129. return false;
  130. for (i = 0; i < DIVIDER_NUM; i++) {
  131. if (n == asrc_clk_divider[i])
  132. break;
  133. }
  134. if (i == DIVIDER_NUM)
  135. return false;
  136. return true;
  137. }
  138. /**
  139. * fsl_asrc_sel_proc - Select the pre-processing and post-processing options
  140. * @inrate: input sample rate
  141. * @outrate: output sample rate
  142. * @pre_proc: return value for pre-processing option
  143. * @post_proc: return value for post-processing option
  144. *
  145. * Make sure to exclude following unsupported cases before
  146. * calling this function:
  147. * 1) inrate > 8.125 * outrate
  148. * 2) inrate > 16.125 * outrate
  149. *
  150. */
  151. static void fsl_asrc_sel_proc(int inrate, int outrate,
  152. int *pre_proc, int *post_proc)
  153. {
  154. bool post_proc_cond2;
  155. bool post_proc_cond0;
  156. /* select pre_proc between [0, 2] */
  157. if (inrate * 8 > 33 * outrate)
  158. *pre_proc = 2;
  159. else if (inrate * 8 > 15 * outrate) {
  160. if (inrate > 152000)
  161. *pre_proc = 2;
  162. else
  163. *pre_proc = 1;
  164. } else if (inrate < 76000)
  165. *pre_proc = 0;
  166. else if (inrate > 152000)
  167. *pre_proc = 2;
  168. else
  169. *pre_proc = 1;
  170. /* Condition for selection of post-processing */
  171. post_proc_cond2 = (inrate * 15 > outrate * 16 && outrate < 56000) ||
  172. (inrate > 56000 && outrate < 56000);
  173. post_proc_cond0 = inrate * 23 < outrate * 8;
  174. if (post_proc_cond2)
  175. *post_proc = 2;
  176. else if (post_proc_cond0)
  177. *post_proc = 0;
  178. else
  179. *post_proc = 1;
  180. }
  181. /**
  182. * fsl_asrc_request_pair - Request ASRC pair
  183. * @channels: number of channels
  184. * @pair: pointer to pair
  185. *
  186. * It assigns pair by the order of A->C->B because allocation of pair B,
  187. * within range [ANCA, ANCA+ANCB-1], depends on the channels of pair A
  188. * while pair A and pair C are comparatively independent.
  189. */
  190. static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair)
  191. {
  192. enum asrc_pair_index index = ASRC_INVALID_PAIR;
  193. struct fsl_asrc *asrc = pair->asrc;
  194. struct device *dev = &asrc->pdev->dev;
  195. unsigned long lock_flags;
  196. int i, ret = 0;
  197. spin_lock_irqsave(&asrc->lock, lock_flags);
  198. for (i = ASRC_PAIR_A; i < ASRC_PAIR_MAX_NUM; i++) {
  199. if (asrc->pair[i] != NULL)
  200. continue;
  201. index = i;
  202. if (i != ASRC_PAIR_B)
  203. break;
  204. }
  205. if (index == ASRC_INVALID_PAIR) {
  206. dev_err(dev, "all pairs are busy now\n");
  207. ret = -EBUSY;
  208. } else if (asrc->channel_avail < channels) {
  209. dev_err(dev, "can't afford required channels: %d\n", channels);
  210. ret = -EINVAL;
  211. } else {
  212. asrc->channel_avail -= channels;
  213. asrc->pair[index] = pair;
  214. pair->channels = channels;
  215. pair->index = index;
  216. }
  217. spin_unlock_irqrestore(&asrc->lock, lock_flags);
  218. return ret;
  219. }
  220. /**
  221. * fsl_asrc_release_pair - Release ASRC pair
  222. * @pair: pair to release
  223. *
  224. * It clears the resource from asrc and releases the occupied channels.
  225. */
  226. static void fsl_asrc_release_pair(struct fsl_asrc_pair *pair)
  227. {
  228. struct fsl_asrc *asrc = pair->asrc;
  229. enum asrc_pair_index index = pair->index;
  230. unsigned long lock_flags;
  231. /* Make sure the pair is disabled */
  232. regmap_update_bits(asrc->regmap, REG_ASRCTR,
  233. ASRCTR_ASRCEi_MASK(index), 0);
  234. spin_lock_irqsave(&asrc->lock, lock_flags);
  235. asrc->channel_avail += pair->channels;
  236. asrc->pair[index] = NULL;
  237. pair->error = 0;
  238. spin_unlock_irqrestore(&asrc->lock, lock_flags);
  239. }
  240. /**
  241. * fsl_asrc_set_watermarks- configure input and output thresholds
  242. * @pair: pointer to pair
  243. * @in: input threshold
  244. * @out: output threshold
  245. */
  246. static void fsl_asrc_set_watermarks(struct fsl_asrc_pair *pair, u32 in, u32 out)
  247. {
  248. struct fsl_asrc *asrc = pair->asrc;
  249. enum asrc_pair_index index = pair->index;
  250. regmap_update_bits(asrc->regmap, REG_ASRMCR(index),
  251. ASRMCRi_EXTTHRSHi_MASK |
  252. ASRMCRi_INFIFO_THRESHOLD_MASK |
  253. ASRMCRi_OUTFIFO_THRESHOLD_MASK,
  254. ASRMCRi_EXTTHRSHi |
  255. ASRMCRi_INFIFO_THRESHOLD(in) |
  256. ASRMCRi_OUTFIFO_THRESHOLD(out));
  257. }
  258. /**
  259. * fsl_asrc_cal_asrck_divisor - Calculate the total divisor between asrck clock rate and sample rate
  260. * @pair: pointer to pair
  261. * @div: divider
  262. *
  263. * It follows the formula clk_rate = samplerate * (2 ^ prescaler) * divider
  264. */
  265. static u32 fsl_asrc_cal_asrck_divisor(struct fsl_asrc_pair *pair, u32 div)
  266. {
  267. u32 ps;
  268. /* Calculate the divisors: prescaler [2^0, 2^7], divder [1, 8] */
  269. for (ps = 0; div > 8; ps++)
  270. div >>= 1;
  271. return ((div - 1) << ASRCDRi_AxCPi_WIDTH) | ps;
  272. }
  273. /**
  274. * fsl_asrc_set_ideal_ratio - Calculate and set the ratio for Ideal Ratio mode only
  275. * @pair: pointer to pair
  276. * @inrate: input rate
  277. * @outrate: output rate
  278. *
  279. * The ratio is a 32-bit fixed point value with 26 fractional bits.
  280. */
  281. static int fsl_asrc_set_ideal_ratio(struct fsl_asrc_pair *pair,
  282. int inrate, int outrate)
  283. {
  284. struct fsl_asrc *asrc = pair->asrc;
  285. enum asrc_pair_index index = pair->index;
  286. unsigned long ratio;
  287. int i;
  288. if (!outrate) {
  289. pair_err("output rate should not be zero\n");
  290. return -EINVAL;
  291. }
  292. /* Calculate the intergal part of the ratio */
  293. ratio = (inrate / outrate) << IDEAL_RATIO_DECIMAL_DEPTH;
  294. /* ... and then the 26 depth decimal part */
  295. inrate %= outrate;
  296. for (i = 1; i <= IDEAL_RATIO_DECIMAL_DEPTH; i++) {
  297. inrate <<= 1;
  298. if (inrate < outrate)
  299. continue;
  300. ratio |= 1 << (IDEAL_RATIO_DECIMAL_DEPTH - i);
  301. inrate -= outrate;
  302. if (!inrate)
  303. break;
  304. }
  305. regmap_write(asrc->regmap, REG_ASRIDRL(index), ratio);
  306. regmap_write(asrc->regmap, REG_ASRIDRH(index), ratio >> 24);
  307. return 0;
  308. }
  309. /**
  310. * fsl_asrc_config_pair - Configure the assigned ASRC pair
  311. * @pair: pointer to pair
  312. * @use_ideal_rate: boolean configuration
  313. *
  314. * It configures those ASRC registers according to a configuration instance
  315. * of struct asrc_config which includes in/output sample rate, width, channel
  316. * and clock settings.
  317. *
  318. * Note:
  319. * The ideal ratio configuration can work with a flexible clock rate setting.
  320. * Using IDEAL_RATIO_RATE gives a faster converting speed but overloads ASRC.
  321. * For a regular audio playback, the clock rate should not be slower than an
  322. * clock rate aligning with the output sample rate; For a use case requiring
  323. * faster conversion, set use_ideal_rate to have the faster speed.
  324. */
  325. static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair, bool use_ideal_rate)
  326. {
  327. struct fsl_asrc_pair_priv *pair_priv = pair->private;
  328. struct asrc_config *config = pair_priv->config;
  329. struct fsl_asrc *asrc = pair->asrc;
  330. struct fsl_asrc_priv *asrc_priv = asrc->private;
  331. enum asrc_pair_index index = pair->index;
  332. enum asrc_word_width input_word_width;
  333. enum asrc_word_width output_word_width;
  334. u32 inrate, outrate, indiv, outdiv;
  335. u32 clk_index[2], div[2];
  336. u64 clk_rate;
  337. int in, out, channels;
  338. int pre_proc, post_proc;
  339. struct clk *clk;
  340. bool ideal, div_avail;
  341. if (!config) {
  342. pair_err("invalid pair config\n");
  343. return -EINVAL;
  344. }
  345. /* Validate channels */
  346. if (config->channel_num < 1 || config->channel_num > 10) {
  347. pair_err("does not support %d channels\n", config->channel_num);
  348. return -EINVAL;
  349. }
  350. switch (snd_pcm_format_width(config->input_format)) {
  351. case 8:
  352. input_word_width = ASRC_WIDTH_8_BIT;
  353. break;
  354. case 16:
  355. input_word_width = ASRC_WIDTH_16_BIT;
  356. break;
  357. case 24:
  358. input_word_width = ASRC_WIDTH_24_BIT;
  359. break;
  360. default:
  361. pair_err("does not support this input format, %d\n",
  362. config->input_format);
  363. return -EINVAL;
  364. }
  365. switch (snd_pcm_format_width(config->output_format)) {
  366. case 16:
  367. output_word_width = ASRC_WIDTH_16_BIT;
  368. break;
  369. case 24:
  370. output_word_width = ASRC_WIDTH_24_BIT;
  371. break;
  372. default:
  373. pair_err("does not support this output format, %d\n",
  374. config->output_format);
  375. return -EINVAL;
  376. }
  377. inrate = config->input_sample_rate;
  378. outrate = config->output_sample_rate;
  379. ideal = config->inclk == INCLK_NONE;
  380. /* Validate input and output sample rates */
  381. for (in = 0; in < ARRAY_SIZE(supported_asrc_rate); in++)
  382. if (inrate == supported_asrc_rate[in])
  383. break;
  384. if (in == ARRAY_SIZE(supported_asrc_rate)) {
  385. pair_err("unsupported input sample rate: %dHz\n", inrate);
  386. return -EINVAL;
  387. }
  388. for (out = 0; out < ARRAY_SIZE(supported_asrc_rate); out++)
  389. if (outrate == supported_asrc_rate[out])
  390. break;
  391. if (out == ARRAY_SIZE(supported_asrc_rate)) {
  392. pair_err("unsupported output sample rate: %dHz\n", outrate);
  393. return -EINVAL;
  394. }
  395. if ((outrate >= 5512 && outrate <= 30000) &&
  396. (outrate > 24 * inrate || inrate > 8 * outrate)) {
  397. pair_err("exceed supported ratio range [1/24, 8] for \
  398. inrate/outrate: %d/%d\n", inrate, outrate);
  399. return -EINVAL;
  400. }
  401. /* Validate input and output clock sources */
  402. clk_index[IN] = asrc_priv->clk_map[IN][config->inclk];
  403. clk_index[OUT] = asrc_priv->clk_map[OUT][config->outclk];
  404. /* We only have output clock for ideal ratio mode */
  405. clk = asrc_priv->asrck_clk[clk_index[ideal ? OUT : IN]];
  406. clk_rate = clk_get_rate(clk);
  407. div_avail = fsl_asrc_divider_avail(clk_rate, inrate, &div[IN]);
  408. /*
  409. * The divider range is [1, 1024], defined by the hardware. For non-
  410. * ideal ratio configuration, clock rate has to be strictly aligned
  411. * with the sample rate. For ideal ratio configuration, clock rates
  412. * only result in different converting speeds. So remainder does not
  413. * matter, as long as we keep the divider within its valid range.
  414. */
  415. if (div[IN] == 0 || (!ideal && !div_avail)) {
  416. pair_err("failed to support input sample rate %dHz by asrck_%x\n",
  417. inrate, clk_index[ideal ? OUT : IN]);
  418. return -EINVAL;
  419. }
  420. div[IN] = min_t(u32, 1024, div[IN]);
  421. clk = asrc_priv->asrck_clk[clk_index[OUT]];
  422. clk_rate = clk_get_rate(clk);
  423. if (ideal && use_ideal_rate)
  424. div_avail = fsl_asrc_divider_avail(clk_rate, IDEAL_RATIO_RATE, &div[OUT]);
  425. else
  426. div_avail = fsl_asrc_divider_avail(clk_rate, outrate, &div[OUT]);
  427. /* Output divider has the same limitation as the input one */
  428. if (div[OUT] == 0 || (!ideal && !div_avail)) {
  429. pair_err("failed to support output sample rate %dHz by asrck_%x\n",
  430. outrate, clk_index[OUT]);
  431. return -EINVAL;
  432. }
  433. div[OUT] = min_t(u32, 1024, div[OUT]);
  434. /* Set the channel number */
  435. channels = config->channel_num;
  436. if (asrc_priv->soc->channel_bits < 4)
  437. channels /= 2;
  438. /* Update channels for current pair */
  439. regmap_update_bits(asrc->regmap, REG_ASRCNCR,
  440. ASRCNCR_ANCi_MASK(index, asrc_priv->soc->channel_bits),
  441. ASRCNCR_ANCi(index, channels, asrc_priv->soc->channel_bits));
  442. /* Default setting: Automatic selection for processing mode */
  443. regmap_update_bits(asrc->regmap, REG_ASRCTR,
  444. ASRCTR_ATSi_MASK(index), ASRCTR_ATS(index));
  445. regmap_update_bits(asrc->regmap, REG_ASRCTR,
  446. ASRCTR_IDRi_MASK(index) | ASRCTR_USRi_MASK(index),
  447. ASRCTR_USR(index));
  448. /* Set the input and output clock sources */
  449. regmap_update_bits(asrc->regmap, REG_ASRCSR,
  450. ASRCSR_AICSi_MASK(index) | ASRCSR_AOCSi_MASK(index),
  451. ASRCSR_AICS(index, clk_index[IN]) |
  452. ASRCSR_AOCS(index, clk_index[OUT]));
  453. /* Calculate the input clock divisors */
  454. indiv = fsl_asrc_cal_asrck_divisor(pair, div[IN]);
  455. outdiv = fsl_asrc_cal_asrck_divisor(pair, div[OUT]);
  456. /* Suppose indiv and outdiv includes prescaler, so add its MASK too */
  457. regmap_update_bits(asrc->regmap, REG_ASRCDR(index),
  458. ASRCDRi_AOCPi_MASK(index) | ASRCDRi_AICPi_MASK(index) |
  459. ASRCDRi_AOCDi_MASK(index) | ASRCDRi_AICDi_MASK(index),
  460. ASRCDRi_AOCP(index, outdiv) | ASRCDRi_AICP(index, indiv));
  461. /* Implement word_width configurations */
  462. regmap_update_bits(asrc->regmap, REG_ASRMCR1(index),
  463. ASRMCR1i_OW16_MASK | ASRMCR1i_IWD_MASK,
  464. ASRMCR1i_OW16(output_word_width) |
  465. ASRMCR1i_IWD(input_word_width));
  466. /* Enable BUFFER STALL */
  467. regmap_update_bits(asrc->regmap, REG_ASRMCR(index),
  468. ASRMCRi_BUFSTALLi_MASK, ASRMCRi_BUFSTALLi);
  469. /* Set default thresholds for input and output FIFO */
  470. fsl_asrc_set_watermarks(pair, ASRC_INPUTFIFO_THRESHOLD,
  471. ASRC_INPUTFIFO_THRESHOLD);
  472. /* Configure the following only for Ideal Ratio mode */
  473. if (!ideal)
  474. return 0;
  475. /* Clear ASTSx bit to use Ideal Ratio mode */
  476. regmap_update_bits(asrc->regmap, REG_ASRCTR,
  477. ASRCTR_ATSi_MASK(index), 0);
  478. /* Enable Ideal Ratio mode */
  479. regmap_update_bits(asrc->regmap, REG_ASRCTR,
  480. ASRCTR_IDRi_MASK(index) | ASRCTR_USRi_MASK(index),
  481. ASRCTR_IDR(index) | ASRCTR_USR(index));
  482. fsl_asrc_sel_proc(inrate, outrate, &pre_proc, &post_proc);
  483. /* Apply configurations for pre- and post-processing */
  484. regmap_update_bits(asrc->regmap, REG_ASRCFG,
  485. ASRCFG_PREMODi_MASK(index) | ASRCFG_POSTMODi_MASK(index),
  486. ASRCFG_PREMOD(index, pre_proc) |
  487. ASRCFG_POSTMOD(index, post_proc));
  488. return fsl_asrc_set_ideal_ratio(pair, inrate, outrate);
  489. }
  490. /**
  491. * fsl_asrc_start_pair - Start the assigned ASRC pair
  492. * @pair: pointer to pair
  493. *
  494. * It enables the assigned pair and makes it stopped at the stall level.
  495. */
  496. static void fsl_asrc_start_pair(struct fsl_asrc_pair *pair)
  497. {
  498. struct fsl_asrc *asrc = pair->asrc;
  499. enum asrc_pair_index index = pair->index;
  500. int reg, retry = INIT_RETRY_NUM, i;
  501. /* Enable the current pair */
  502. regmap_update_bits(asrc->regmap, REG_ASRCTR,
  503. ASRCTR_ASRCEi_MASK(index), ASRCTR_ASRCE(index));
  504. /* Wait for status of initialization */
  505. do {
  506. udelay(5);
  507. regmap_read(asrc->regmap, REG_ASRCFG, &reg);
  508. reg &= ASRCFG_INIRQi_MASK(index);
  509. } while (!reg && --retry);
  510. /* NOTE: Doesn't treat initialization timeout as an error */
  511. if (!retry)
  512. pair_warn("initialization isn't finished\n");
  513. /* Make the input fifo to ASRC STALL level */
  514. regmap_read(asrc->regmap, REG_ASRCNCR, &reg);
  515. for (i = 0; i < pair->channels * 4; i++)
  516. regmap_write(asrc->regmap, REG_ASRDI(index), 0);
  517. /* Enable overload interrupt */
  518. regmap_write(asrc->regmap, REG_ASRIER, ASRIER_AOLIE);
  519. }
  520. /**
  521. * fsl_asrc_stop_pair - Stop the assigned ASRC pair
  522. * @pair: pointer to pair
  523. */
  524. static void fsl_asrc_stop_pair(struct fsl_asrc_pair *pair)
  525. {
  526. struct fsl_asrc *asrc = pair->asrc;
  527. enum asrc_pair_index index = pair->index;
  528. /* Stop the current pair */
  529. regmap_update_bits(asrc->regmap, REG_ASRCTR,
  530. ASRCTR_ASRCEi_MASK(index), 0);
  531. }
  532. /**
  533. * fsl_asrc_get_dma_channel- Get DMA channel according to the pair and direction.
  534. * @pair: pointer to pair
  535. * @dir: DMA direction
  536. */
  537. static struct dma_chan *fsl_asrc_get_dma_channel(struct fsl_asrc_pair *pair,
  538. bool dir)
  539. {
  540. struct fsl_asrc *asrc = pair->asrc;
  541. enum asrc_pair_index index = pair->index;
  542. char name[4];
  543. sprintf(name, "%cx%c", dir == IN ? 'r' : 't', index + 'a');
  544. return dma_request_slave_channel(&asrc->pdev->dev, name);
  545. }
  546. static int fsl_asrc_dai_startup(struct snd_pcm_substream *substream,
  547. struct snd_soc_dai *dai)
  548. {
  549. struct fsl_asrc *asrc = snd_soc_dai_get_drvdata(dai);
  550. struct fsl_asrc_priv *asrc_priv = asrc->private;
  551. /* Odd channel number is not valid for older ASRC (channel_bits==3) */
  552. if (asrc_priv->soc->channel_bits == 3)
  553. snd_pcm_hw_constraint_step(substream->runtime, 0,
  554. SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  555. return snd_pcm_hw_constraint_list(substream->runtime, 0,
  556. SNDRV_PCM_HW_PARAM_RATE, &fsl_asrc_rate_constraints);
  557. }
  558. /* Select proper clock source for internal ratio mode */
  559. static void fsl_asrc_select_clk(struct fsl_asrc_priv *asrc_priv,
  560. struct fsl_asrc_pair *pair,
  561. int in_rate,
  562. int out_rate)
  563. {
  564. struct fsl_asrc_pair_priv *pair_priv = pair->private;
  565. struct asrc_config *config = pair_priv->config;
  566. int rate[2], select_clk[2]; /* Array size 2 means IN and OUT */
  567. int clk_rate, clk_index;
  568. int i, j;
  569. rate[IN] = in_rate;
  570. rate[OUT] = out_rate;
  571. /* Select proper clock source for internal ratio mode */
  572. for (j = 0; j < 2; j++) {
  573. for (i = 0; i < ASRC_CLK_MAP_LEN; i++) {
  574. clk_index = asrc_priv->clk_map[j][i];
  575. clk_rate = clk_get_rate(asrc_priv->asrck_clk[clk_index]);
  576. /* Only match a perfect clock source with no remainder */
  577. if (fsl_asrc_divider_avail(clk_rate, rate[j], NULL))
  578. break;
  579. }
  580. select_clk[j] = i;
  581. }
  582. /* Switch to ideal ratio mode if there is no proper clock source */
  583. if (select_clk[IN] == ASRC_CLK_MAP_LEN || select_clk[OUT] == ASRC_CLK_MAP_LEN) {
  584. select_clk[IN] = INCLK_NONE;
  585. select_clk[OUT] = OUTCLK_ASRCK1_CLK;
  586. }
  587. config->inclk = select_clk[IN];
  588. config->outclk = select_clk[OUT];
  589. }
  590. static int fsl_asrc_dai_hw_params(struct snd_pcm_substream *substream,
  591. struct snd_pcm_hw_params *params,
  592. struct snd_soc_dai *dai)
  593. {
  594. struct fsl_asrc *asrc = snd_soc_dai_get_drvdata(dai);
  595. struct fsl_asrc_priv *asrc_priv = asrc->private;
  596. struct snd_pcm_runtime *runtime = substream->runtime;
  597. struct fsl_asrc_pair *pair = runtime->private_data;
  598. struct fsl_asrc_pair_priv *pair_priv = pair->private;
  599. unsigned int channels = params_channels(params);
  600. unsigned int rate = params_rate(params);
  601. struct asrc_config config;
  602. int ret;
  603. ret = fsl_asrc_request_pair(channels, pair);
  604. if (ret) {
  605. dev_err(dai->dev, "fail to request asrc pair\n");
  606. return ret;
  607. }
  608. pair_priv->config = &config;
  609. config.pair = pair->index;
  610. config.channel_num = channels;
  611. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  612. config.input_format = params_format(params);
  613. config.output_format = asrc->asrc_format;
  614. config.input_sample_rate = rate;
  615. config.output_sample_rate = asrc->asrc_rate;
  616. } else {
  617. config.input_format = asrc->asrc_format;
  618. config.output_format = params_format(params);
  619. config.input_sample_rate = asrc->asrc_rate;
  620. config.output_sample_rate = rate;
  621. }
  622. fsl_asrc_select_clk(asrc_priv, pair,
  623. config.input_sample_rate,
  624. config.output_sample_rate);
  625. ret = fsl_asrc_config_pair(pair, false);
  626. if (ret) {
  627. dev_err(dai->dev, "fail to config asrc pair\n");
  628. return ret;
  629. }
  630. return 0;
  631. }
  632. static int fsl_asrc_dai_hw_free(struct snd_pcm_substream *substream,
  633. struct snd_soc_dai *dai)
  634. {
  635. struct snd_pcm_runtime *runtime = substream->runtime;
  636. struct fsl_asrc_pair *pair = runtime->private_data;
  637. if (pair)
  638. fsl_asrc_release_pair(pair);
  639. return 0;
  640. }
  641. static int fsl_asrc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
  642. struct snd_soc_dai *dai)
  643. {
  644. struct snd_pcm_runtime *runtime = substream->runtime;
  645. struct fsl_asrc_pair *pair = runtime->private_data;
  646. switch (cmd) {
  647. case SNDRV_PCM_TRIGGER_START:
  648. case SNDRV_PCM_TRIGGER_RESUME:
  649. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  650. fsl_asrc_start_pair(pair);
  651. break;
  652. case SNDRV_PCM_TRIGGER_STOP:
  653. case SNDRV_PCM_TRIGGER_SUSPEND:
  654. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  655. fsl_asrc_stop_pair(pair);
  656. break;
  657. default:
  658. return -EINVAL;
  659. }
  660. return 0;
  661. }
  662. static int fsl_asrc_dai_probe(struct snd_soc_dai *dai)
  663. {
  664. struct fsl_asrc *asrc = snd_soc_dai_get_drvdata(dai);
  665. snd_soc_dai_init_dma_data(dai, &asrc->dma_params_tx,
  666. &asrc->dma_params_rx);
  667. return 0;
  668. }
  669. static const struct snd_soc_dai_ops fsl_asrc_dai_ops = {
  670. .probe = fsl_asrc_dai_probe,
  671. .startup = fsl_asrc_dai_startup,
  672. .hw_params = fsl_asrc_dai_hw_params,
  673. .hw_free = fsl_asrc_dai_hw_free,
  674. .trigger = fsl_asrc_dai_trigger,
  675. };
  676. #define FSL_ASRC_FORMATS (SNDRV_PCM_FMTBIT_S24_LE | \
  677. SNDRV_PCM_FMTBIT_S16_LE | \
  678. SNDRV_PCM_FMTBIT_S24_3LE)
  679. static struct snd_soc_dai_driver fsl_asrc_dai = {
  680. .playback = {
  681. .stream_name = "ASRC-Playback",
  682. .channels_min = 1,
  683. .channels_max = 10,
  684. .rate_min = 5512,
  685. .rate_max = 192000,
  686. .rates = SNDRV_PCM_RATE_KNOT,
  687. .formats = FSL_ASRC_FORMATS |
  688. SNDRV_PCM_FMTBIT_S8,
  689. },
  690. .capture = {
  691. .stream_name = "ASRC-Capture",
  692. .channels_min = 1,
  693. .channels_max = 10,
  694. .rate_min = 5512,
  695. .rate_max = 192000,
  696. .rates = SNDRV_PCM_RATE_KNOT,
  697. .formats = FSL_ASRC_FORMATS,
  698. },
  699. .ops = &fsl_asrc_dai_ops,
  700. };
  701. static bool fsl_asrc_readable_reg(struct device *dev, unsigned int reg)
  702. {
  703. switch (reg) {
  704. case REG_ASRCTR:
  705. case REG_ASRIER:
  706. case REG_ASRCNCR:
  707. case REG_ASRCFG:
  708. case REG_ASRCSR:
  709. case REG_ASRCDR1:
  710. case REG_ASRCDR2:
  711. case REG_ASRSTR:
  712. case REG_ASRPM1:
  713. case REG_ASRPM2:
  714. case REG_ASRPM3:
  715. case REG_ASRPM4:
  716. case REG_ASRPM5:
  717. case REG_ASRTFR1:
  718. case REG_ASRCCR:
  719. case REG_ASRDOA:
  720. case REG_ASRDOB:
  721. case REG_ASRDOC:
  722. case REG_ASRIDRHA:
  723. case REG_ASRIDRLA:
  724. case REG_ASRIDRHB:
  725. case REG_ASRIDRLB:
  726. case REG_ASRIDRHC:
  727. case REG_ASRIDRLC:
  728. case REG_ASR76K:
  729. case REG_ASR56K:
  730. case REG_ASRMCRA:
  731. case REG_ASRFSTA:
  732. case REG_ASRMCRB:
  733. case REG_ASRFSTB:
  734. case REG_ASRMCRC:
  735. case REG_ASRFSTC:
  736. case REG_ASRMCR1A:
  737. case REG_ASRMCR1B:
  738. case REG_ASRMCR1C:
  739. return true;
  740. default:
  741. return false;
  742. }
  743. }
  744. static bool fsl_asrc_volatile_reg(struct device *dev, unsigned int reg)
  745. {
  746. switch (reg) {
  747. case REG_ASRSTR:
  748. case REG_ASRDIA:
  749. case REG_ASRDIB:
  750. case REG_ASRDIC:
  751. case REG_ASRDOA:
  752. case REG_ASRDOB:
  753. case REG_ASRDOC:
  754. case REG_ASRFSTA:
  755. case REG_ASRFSTB:
  756. case REG_ASRFSTC:
  757. case REG_ASRCFG:
  758. return true;
  759. default:
  760. return false;
  761. }
  762. }
  763. static bool fsl_asrc_writeable_reg(struct device *dev, unsigned int reg)
  764. {
  765. switch (reg) {
  766. case REG_ASRCTR:
  767. case REG_ASRIER:
  768. case REG_ASRCNCR:
  769. case REG_ASRCFG:
  770. case REG_ASRCSR:
  771. case REG_ASRCDR1:
  772. case REG_ASRCDR2:
  773. case REG_ASRSTR:
  774. case REG_ASRPM1:
  775. case REG_ASRPM2:
  776. case REG_ASRPM3:
  777. case REG_ASRPM4:
  778. case REG_ASRPM5:
  779. case REG_ASRTFR1:
  780. case REG_ASRCCR:
  781. case REG_ASRDIA:
  782. case REG_ASRDIB:
  783. case REG_ASRDIC:
  784. case REG_ASRIDRHA:
  785. case REG_ASRIDRLA:
  786. case REG_ASRIDRHB:
  787. case REG_ASRIDRLB:
  788. case REG_ASRIDRHC:
  789. case REG_ASRIDRLC:
  790. case REG_ASR76K:
  791. case REG_ASR56K:
  792. case REG_ASRMCRA:
  793. case REG_ASRMCRB:
  794. case REG_ASRMCRC:
  795. case REG_ASRMCR1A:
  796. case REG_ASRMCR1B:
  797. case REG_ASRMCR1C:
  798. return true;
  799. default:
  800. return false;
  801. }
  802. }
  803. static const struct reg_default fsl_asrc_reg[] = {
  804. { REG_ASRCTR, 0x0000 }, { REG_ASRIER, 0x0000 },
  805. { REG_ASRCNCR, 0x0000 }, { REG_ASRCFG, 0x0000 },
  806. { REG_ASRCSR, 0x0000 }, { REG_ASRCDR1, 0x0000 },
  807. { REG_ASRCDR2, 0x0000 }, { REG_ASRSTR, 0x0000 },
  808. { REG_ASRRA, 0x0000 }, { REG_ASRRB, 0x0000 },
  809. { REG_ASRRC, 0x0000 }, { REG_ASRPM1, 0x0000 },
  810. { REG_ASRPM2, 0x0000 }, { REG_ASRPM3, 0x0000 },
  811. { REG_ASRPM4, 0x0000 }, { REG_ASRPM5, 0x0000 },
  812. { REG_ASRTFR1, 0x0000 }, { REG_ASRCCR, 0x0000 },
  813. { REG_ASRDIA, 0x0000 }, { REG_ASRDOA, 0x0000 },
  814. { REG_ASRDIB, 0x0000 }, { REG_ASRDOB, 0x0000 },
  815. { REG_ASRDIC, 0x0000 }, { REG_ASRDOC, 0x0000 },
  816. { REG_ASRIDRHA, 0x0000 }, { REG_ASRIDRLA, 0x0000 },
  817. { REG_ASRIDRHB, 0x0000 }, { REG_ASRIDRLB, 0x0000 },
  818. { REG_ASRIDRHC, 0x0000 }, { REG_ASRIDRLC, 0x0000 },
  819. { REG_ASR76K, 0x0A47 }, { REG_ASR56K, 0x0DF3 },
  820. { REG_ASRMCRA, 0x0000 }, { REG_ASRFSTA, 0x0000 },
  821. { REG_ASRMCRB, 0x0000 }, { REG_ASRFSTB, 0x0000 },
  822. { REG_ASRMCRC, 0x0000 }, { REG_ASRFSTC, 0x0000 },
  823. { REG_ASRMCR1A, 0x0000 }, { REG_ASRMCR1B, 0x0000 },
  824. { REG_ASRMCR1C, 0x0000 },
  825. };
  826. static const struct regmap_config fsl_asrc_regmap_config = {
  827. .reg_bits = 32,
  828. .reg_stride = 4,
  829. .val_bits = 32,
  830. .max_register = REG_ASRMCR1C,
  831. .reg_defaults = fsl_asrc_reg,
  832. .num_reg_defaults = ARRAY_SIZE(fsl_asrc_reg),
  833. .readable_reg = fsl_asrc_readable_reg,
  834. .volatile_reg = fsl_asrc_volatile_reg,
  835. .writeable_reg = fsl_asrc_writeable_reg,
  836. .cache_type = REGCACHE_FLAT,
  837. };
  838. /**
  839. * fsl_asrc_init - Initialize ASRC registers with a default configuration
  840. * @asrc: ASRC context
  841. */
  842. static int fsl_asrc_init(struct fsl_asrc *asrc)
  843. {
  844. unsigned long ipg_rate;
  845. /* Halt ASRC internal FP when input FIFO needs data for pair A, B, C */
  846. regmap_write(asrc->regmap, REG_ASRCTR, ASRCTR_ASRCEN);
  847. /* Disable interrupt by default */
  848. regmap_write(asrc->regmap, REG_ASRIER, 0x0);
  849. /* Apply recommended settings for parameters from Reference Manual */
  850. regmap_write(asrc->regmap, REG_ASRPM1, 0x7fffff);
  851. regmap_write(asrc->regmap, REG_ASRPM2, 0x255555);
  852. regmap_write(asrc->regmap, REG_ASRPM3, 0xff7280);
  853. regmap_write(asrc->regmap, REG_ASRPM4, 0xff7280);
  854. regmap_write(asrc->regmap, REG_ASRPM5, 0xff7280);
  855. /* Base address for task queue FIFO. Set to 0x7C */
  856. regmap_update_bits(asrc->regmap, REG_ASRTFR1,
  857. ASRTFR1_TF_BASE_MASK, ASRTFR1_TF_BASE(0xfc));
  858. /*
  859. * Set the period of the 76KHz and 56KHz sampling clocks based on
  860. * the ASRC processing clock.
  861. * On iMX6, ipg_clk = 133MHz, REG_ASR76K = 0x06D6, REG_ASR56K = 0x0947
  862. */
  863. ipg_rate = clk_get_rate(asrc->ipg_clk);
  864. regmap_write(asrc->regmap, REG_ASR76K, ipg_rate / 76000);
  865. return regmap_write(asrc->regmap, REG_ASR56K, ipg_rate / 56000);
  866. }
  867. /**
  868. * fsl_asrc_isr- Interrupt handler for ASRC
  869. * @irq: irq number
  870. * @dev_id: ASRC context
  871. */
  872. static irqreturn_t fsl_asrc_isr(int irq, void *dev_id)
  873. {
  874. struct fsl_asrc *asrc = (struct fsl_asrc *)dev_id;
  875. struct device *dev = &asrc->pdev->dev;
  876. enum asrc_pair_index index;
  877. u32 status;
  878. regmap_read(asrc->regmap, REG_ASRSTR, &status);
  879. /* Clean overload error */
  880. regmap_write(asrc->regmap, REG_ASRSTR, ASRSTR_AOLE);
  881. /*
  882. * We here use dev_dbg() for all exceptions because ASRC itself does
  883. * not care if FIFO overflowed or underrun while a warning in the
  884. * interrupt would result a ridged conversion.
  885. */
  886. for (index = ASRC_PAIR_A; index < ASRC_PAIR_MAX_NUM; index++) {
  887. if (!asrc->pair[index])
  888. continue;
  889. if (status & ASRSTR_ATQOL) {
  890. asrc->pair[index]->error |= ASRC_TASK_Q_OVERLOAD;
  891. dev_dbg(dev, "ASRC Task Queue FIFO overload\n");
  892. }
  893. if (status & ASRSTR_AOOL(index)) {
  894. asrc->pair[index]->error |= ASRC_OUTPUT_TASK_OVERLOAD;
  895. pair_dbg("Output Task Overload\n");
  896. }
  897. if (status & ASRSTR_AIOL(index)) {
  898. asrc->pair[index]->error |= ASRC_INPUT_TASK_OVERLOAD;
  899. pair_dbg("Input Task Overload\n");
  900. }
  901. if (status & ASRSTR_AODO(index)) {
  902. asrc->pair[index]->error |= ASRC_OUTPUT_BUFFER_OVERFLOW;
  903. pair_dbg("Output Data Buffer has overflowed\n");
  904. }
  905. if (status & ASRSTR_AIDU(index)) {
  906. asrc->pair[index]->error |= ASRC_INPUT_BUFFER_UNDERRUN;
  907. pair_dbg("Input Data Buffer has underflowed\n");
  908. }
  909. }
  910. return IRQ_HANDLED;
  911. }
  912. static int fsl_asrc_get_fifo_addr(u8 dir, enum asrc_pair_index index)
  913. {
  914. return REG_ASRDx(dir, index);
  915. }
  916. /* Get sample numbers in FIFO */
  917. static unsigned int fsl_asrc_get_output_fifo_size(struct fsl_asrc_pair *pair)
  918. {
  919. struct fsl_asrc *asrc = pair->asrc;
  920. enum asrc_pair_index index = pair->index;
  921. u32 val;
  922. regmap_read(asrc->regmap, REG_ASRFST(index), &val);
  923. val &= ASRFSTi_OUTPUT_FIFO_MASK;
  924. return val >> ASRFSTi_OUTPUT_FIFO_SHIFT;
  925. }
  926. static bool fsl_asrc_m2m_output_ready(struct fsl_asrc_pair *pair)
  927. {
  928. struct fsl_asrc *asrc = pair->asrc;
  929. enum asrc_pair_index index = pair->index;
  930. u32 val;
  931. int ret;
  932. /* Check output fifo status if it exceeds the watermark. */
  933. ret = regmap_read_poll_timeout(asrc->regmap, REG_ASRFST(index), val,
  934. (ASRFSTi_OUTPUT_FIFO_FILL(val) >= ASRC_M2M_OUTPUTFIFO_WML),
  935. 1, 1000);
  936. if (ret) {
  937. pair_warn("output is not ready\n");
  938. return false;
  939. }
  940. return true;
  941. }
  942. static int fsl_asrc_m2m_prepare(struct fsl_asrc_pair *pair)
  943. {
  944. struct fsl_asrc_pair_priv *pair_priv = pair->private;
  945. struct fsl_asrc *asrc = pair->asrc;
  946. struct device *dev = &asrc->pdev->dev;
  947. struct asrc_config config;
  948. int ret;
  949. /* fill config */
  950. config.pair = pair->index;
  951. config.channel_num = pair->channels;
  952. config.input_sample_rate = pair->rate[IN];
  953. config.output_sample_rate = pair->rate[OUT];
  954. config.input_format = pair->sample_format[IN];
  955. config.output_format = pair->sample_format[OUT];
  956. config.inclk = INCLK_NONE;
  957. config.outclk = OUTCLK_ASRCK1_CLK;
  958. pair_priv->config = &config;
  959. ret = fsl_asrc_config_pair(pair, true);
  960. if (ret) {
  961. dev_err(dev, "failed to config pair: %d\n", ret);
  962. return ret;
  963. }
  964. pair->first_convert = 1;
  965. return 0;
  966. }
  967. static int fsl_asrc_m2m_start(struct fsl_asrc_pair *pair)
  968. {
  969. if (pair->first_convert) {
  970. fsl_asrc_start_pair(pair);
  971. pair->first_convert = 0;
  972. }
  973. /*
  974. * Clear DMA request during the stall state of ASRC:
  975. * During STALL state, the remaining in input fifo would never be
  976. * smaller than the input threshold while the output fifo would not
  977. * be bigger than output one. Thus the DMA request would be cleared.
  978. */
  979. fsl_asrc_set_watermarks(pair, ASRC_FIFO_THRESHOLD_MIN,
  980. ASRC_FIFO_THRESHOLD_MAX);
  981. /* Update the real input threshold to raise DMA request */
  982. fsl_asrc_set_watermarks(pair, ASRC_M2M_INPUTFIFO_WML,
  983. ASRC_M2M_OUTPUTFIFO_WML);
  984. return 0;
  985. }
  986. static int fsl_asrc_m2m_stop(struct fsl_asrc_pair *pair)
  987. {
  988. if (!pair->first_convert) {
  989. fsl_asrc_stop_pair(pair);
  990. pair->first_convert = 1;
  991. }
  992. return 0;
  993. }
  994. /* calculate capture data length according to output data length and sample rate */
  995. static int fsl_asrc_m2m_calc_out_len(struct fsl_asrc_pair *pair, int input_buffer_length)
  996. {
  997. unsigned int in_width, out_width;
  998. unsigned int channels = pair->channels;
  999. unsigned int in_samples, out_samples;
  1000. unsigned int out_length;
  1001. in_width = snd_pcm_format_physical_width(pair->sample_format[IN]) / 8;
  1002. out_width = snd_pcm_format_physical_width(pair->sample_format[OUT]) / 8;
  1003. in_samples = input_buffer_length / in_width / channels;
  1004. out_samples = pair->rate[OUT] * in_samples / pair->rate[IN];
  1005. out_length = (out_samples - ASRC_OUTPUT_LAST_SAMPLE) * out_width * channels;
  1006. return out_length;
  1007. }
  1008. static int fsl_asrc_m2m_get_maxburst(u8 dir, struct fsl_asrc_pair *pair)
  1009. {
  1010. struct fsl_asrc *asrc = pair->asrc;
  1011. struct fsl_asrc_priv *asrc_priv = asrc->private;
  1012. int wml = (dir == IN) ? ASRC_M2M_INPUTFIFO_WML : ASRC_M2M_OUTPUTFIFO_WML;
  1013. if (!asrc_priv->soc->use_edma)
  1014. return wml * pair->channels;
  1015. else
  1016. return 1;
  1017. }
  1018. static int fsl_asrc_m2m_get_cap(struct fsl_asrc_m2m_cap *cap)
  1019. {
  1020. cap->fmt_in = FSL_ASRC_FORMATS;
  1021. cap->fmt_out = FSL_ASRC_FORMATS | SNDRV_PCM_FMTBIT_S8;
  1022. cap->rate_in = supported_asrc_rate;
  1023. cap->rate_in_count = ARRAY_SIZE(supported_asrc_rate);
  1024. cap->rate_out = supported_asrc_rate;
  1025. cap->rate_out_count = ARRAY_SIZE(supported_asrc_rate);
  1026. cap->chan_min = 1;
  1027. cap->chan_max = 10;
  1028. return 0;
  1029. }
  1030. static int fsl_asrc_m2m_pair_resume(struct fsl_asrc_pair *pair)
  1031. {
  1032. struct fsl_asrc *asrc = pair->asrc;
  1033. int i;
  1034. for (i = 0; i < pair->channels * 4; i++)
  1035. regmap_write(asrc->regmap, REG_ASRDI(pair->index), 0);
  1036. pair->first_convert = 1;
  1037. return 0;
  1038. }
  1039. static int fsl_asrc_runtime_resume(struct device *dev);
  1040. static int fsl_asrc_runtime_suspend(struct device *dev);
  1041. static int fsl_asrc_probe(struct platform_device *pdev)
  1042. {
  1043. struct device_node *np = pdev->dev.of_node;
  1044. struct fsl_asrc_priv *asrc_priv;
  1045. struct fsl_asrc *asrc;
  1046. struct resource *res;
  1047. void __iomem *regs;
  1048. int irq, ret, i;
  1049. u32 asrc_fmt = 0;
  1050. u32 map_idx;
  1051. char tmp[16];
  1052. u32 width;
  1053. asrc = devm_kzalloc(&pdev->dev, sizeof(*asrc), GFP_KERNEL);
  1054. if (!asrc)
  1055. return -ENOMEM;
  1056. asrc_priv = devm_kzalloc(&pdev->dev, sizeof(*asrc_priv), GFP_KERNEL);
  1057. if (!asrc_priv)
  1058. return -ENOMEM;
  1059. asrc->pdev = pdev;
  1060. asrc->private = asrc_priv;
  1061. /* Get the addresses and IRQ */
  1062. regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
  1063. if (IS_ERR(regs))
  1064. return PTR_ERR(regs);
  1065. asrc->paddr = res->start;
  1066. asrc->regmap = devm_regmap_init_mmio(&pdev->dev, regs, &fsl_asrc_regmap_config);
  1067. if (IS_ERR(asrc->regmap)) {
  1068. dev_err(&pdev->dev, "failed to init regmap\n");
  1069. return PTR_ERR(asrc->regmap);
  1070. }
  1071. irq = platform_get_irq(pdev, 0);
  1072. if (irq < 0)
  1073. return irq;
  1074. ret = devm_request_irq(&pdev->dev, irq, fsl_asrc_isr, 0,
  1075. dev_name(&pdev->dev), asrc);
  1076. if (ret) {
  1077. dev_err(&pdev->dev, "failed to claim irq %u: %d\n", irq, ret);
  1078. return ret;
  1079. }
  1080. asrc->mem_clk = devm_clk_get(&pdev->dev, "mem");
  1081. if (IS_ERR(asrc->mem_clk)) {
  1082. dev_err(&pdev->dev, "failed to get mem clock\n");
  1083. return PTR_ERR(asrc->mem_clk);
  1084. }
  1085. asrc->ipg_clk = devm_clk_get(&pdev->dev, "ipg");
  1086. if (IS_ERR(asrc->ipg_clk)) {
  1087. dev_err(&pdev->dev, "failed to get ipg clock\n");
  1088. return PTR_ERR(asrc->ipg_clk);
  1089. }
  1090. asrc->spba_clk = devm_clk_get(&pdev->dev, "spba");
  1091. if (IS_ERR(asrc->spba_clk))
  1092. dev_warn(&pdev->dev, "failed to get spba clock\n");
  1093. for (i = 0; i < ASRC_CLK_MAX_NUM; i++) {
  1094. sprintf(tmp, "asrck_%x", i);
  1095. asrc_priv->asrck_clk[i] = devm_clk_get(&pdev->dev, tmp);
  1096. if (IS_ERR(asrc_priv->asrck_clk[i])) {
  1097. dev_err(&pdev->dev, "failed to get %s clock\n", tmp);
  1098. return PTR_ERR(asrc_priv->asrck_clk[i]);
  1099. }
  1100. }
  1101. asrc_priv->soc = of_device_get_match_data(&pdev->dev);
  1102. asrc->use_edma = asrc_priv->soc->use_edma;
  1103. asrc->start_before_dma = asrc_priv->soc->start_before_dma;
  1104. asrc->get_dma_channel = fsl_asrc_get_dma_channel;
  1105. asrc->request_pair = fsl_asrc_request_pair;
  1106. asrc->release_pair = fsl_asrc_release_pair;
  1107. asrc->get_fifo_addr = fsl_asrc_get_fifo_addr;
  1108. asrc->pair_priv_size = sizeof(struct fsl_asrc_pair_priv);
  1109. asrc->m2m_prepare = fsl_asrc_m2m_prepare;
  1110. asrc->m2m_start = fsl_asrc_m2m_start;
  1111. asrc->m2m_stop = fsl_asrc_m2m_stop;
  1112. asrc->get_output_fifo_size = fsl_asrc_get_output_fifo_size;
  1113. asrc->m2m_calc_out_len = fsl_asrc_m2m_calc_out_len;
  1114. asrc->m2m_get_maxburst = fsl_asrc_m2m_get_maxburst;
  1115. asrc->m2m_pair_resume = fsl_asrc_m2m_pair_resume;
  1116. asrc->m2m_get_cap = fsl_asrc_m2m_get_cap;
  1117. asrc->m2m_output_ready = fsl_asrc_m2m_output_ready;
  1118. if (of_device_is_compatible(np, "fsl,imx35-asrc")) {
  1119. asrc_priv->clk_map[IN] = input_clk_map_imx35;
  1120. asrc_priv->clk_map[OUT] = output_clk_map_imx35;
  1121. } else if (of_device_is_compatible(np, "fsl,imx53-asrc")) {
  1122. asrc_priv->clk_map[IN] = input_clk_map_imx53;
  1123. asrc_priv->clk_map[OUT] = output_clk_map_imx53;
  1124. } else if (of_device_is_compatible(np, "fsl,imx8qm-asrc") ||
  1125. of_device_is_compatible(np, "fsl,imx8qxp-asrc")) {
  1126. ret = of_property_read_u32(np, "fsl,asrc-clk-map", &map_idx);
  1127. if (ret) {
  1128. dev_err(&pdev->dev, "failed to get clk map index\n");
  1129. return ret;
  1130. }
  1131. if (map_idx > 1) {
  1132. dev_err(&pdev->dev, "unsupported clk map index\n");
  1133. return -EINVAL;
  1134. }
  1135. if (of_device_is_compatible(np, "fsl,imx8qm-asrc")) {
  1136. asrc_priv->clk_map[IN] = clk_map_imx8qm[map_idx];
  1137. asrc_priv->clk_map[OUT] = clk_map_imx8qm[map_idx];
  1138. } else {
  1139. asrc_priv->clk_map[IN] = clk_map_imx8qxp[map_idx];
  1140. asrc_priv->clk_map[OUT] = clk_map_imx8qxp[map_idx];
  1141. }
  1142. } else if (of_device_is_compatible(np, "fsl,imx952-asrc")) {
  1143. asrc_priv->clk_map[IN] = clk_map_imx952;
  1144. asrc_priv->clk_map[OUT] = clk_map_imx952;
  1145. }
  1146. asrc->channel_avail = 10;
  1147. ret = of_property_read_u32(np, "fsl,asrc-rate",
  1148. &asrc->asrc_rate);
  1149. if (ret) {
  1150. dev_err(&pdev->dev, "failed to get output rate\n");
  1151. return ret;
  1152. }
  1153. ret = of_property_read_u32(np, "fsl,asrc-format", &asrc_fmt);
  1154. asrc->asrc_format = (__force snd_pcm_format_t)asrc_fmt;
  1155. if (ret) {
  1156. ret = of_property_read_u32(np, "fsl,asrc-width", &width);
  1157. if (ret) {
  1158. dev_err(&pdev->dev, "failed to decide output format\n");
  1159. return ret;
  1160. }
  1161. switch (width) {
  1162. case 16:
  1163. asrc->asrc_format = SNDRV_PCM_FORMAT_S16_LE;
  1164. break;
  1165. case 24:
  1166. asrc->asrc_format = SNDRV_PCM_FORMAT_S24_LE;
  1167. break;
  1168. default:
  1169. dev_warn(&pdev->dev,
  1170. "unsupported width, use default S24_LE\n");
  1171. asrc->asrc_format = SNDRV_PCM_FORMAT_S24_LE;
  1172. break;
  1173. }
  1174. }
  1175. if (!(FSL_ASRC_FORMATS & pcm_format_to_bits(asrc->asrc_format))) {
  1176. dev_warn(&pdev->dev, "unsupported width, use default S24_LE\n");
  1177. asrc->asrc_format = SNDRV_PCM_FORMAT_S24_LE;
  1178. }
  1179. platform_set_drvdata(pdev, asrc);
  1180. spin_lock_init(&asrc->lock);
  1181. pm_runtime_enable(&pdev->dev);
  1182. if (!pm_runtime_enabled(&pdev->dev)) {
  1183. ret = fsl_asrc_runtime_resume(&pdev->dev);
  1184. if (ret)
  1185. goto err_pm_disable;
  1186. }
  1187. ret = pm_runtime_resume_and_get(&pdev->dev);
  1188. if (ret < 0)
  1189. goto err_pm_get_sync;
  1190. ret = fsl_asrc_init(asrc);
  1191. if (ret) {
  1192. dev_err(&pdev->dev, "failed to init asrc %d\n", ret);
  1193. goto err_pm_get_sync;
  1194. }
  1195. ret = pm_runtime_put_sync(&pdev->dev);
  1196. if (ret < 0 && ret != -ENOSYS)
  1197. goto err_pm_get_sync;
  1198. ret = devm_snd_soc_register_component(&pdev->dev, &fsl_asrc_component,
  1199. &fsl_asrc_dai, 1);
  1200. if (ret) {
  1201. dev_err(&pdev->dev, "failed to register ASoC DAI\n");
  1202. goto err_pm_get_sync;
  1203. }
  1204. ret = fsl_asrc_m2m_init(asrc);
  1205. if (ret) {
  1206. dev_err(&pdev->dev, "failed to init m2m device %d\n", ret);
  1207. return ret;
  1208. }
  1209. return 0;
  1210. err_pm_get_sync:
  1211. if (!pm_runtime_status_suspended(&pdev->dev))
  1212. fsl_asrc_runtime_suspend(&pdev->dev);
  1213. err_pm_disable:
  1214. pm_runtime_disable(&pdev->dev);
  1215. return ret;
  1216. }
  1217. static void fsl_asrc_remove(struct platform_device *pdev)
  1218. {
  1219. struct fsl_asrc *asrc = dev_get_drvdata(&pdev->dev);
  1220. fsl_asrc_m2m_exit(asrc);
  1221. pm_runtime_disable(&pdev->dev);
  1222. if (!pm_runtime_status_suspended(&pdev->dev))
  1223. fsl_asrc_runtime_suspend(&pdev->dev);
  1224. }
  1225. static int fsl_asrc_runtime_resume(struct device *dev)
  1226. {
  1227. struct fsl_asrc *asrc = dev_get_drvdata(dev);
  1228. struct fsl_asrc_priv *asrc_priv = asrc->private;
  1229. int reg, retry = INIT_RETRY_NUM;
  1230. int i, ret;
  1231. u32 asrctr;
  1232. ret = clk_prepare_enable(asrc->mem_clk);
  1233. if (ret)
  1234. return ret;
  1235. ret = clk_prepare_enable(asrc->ipg_clk);
  1236. if (ret)
  1237. goto disable_mem_clk;
  1238. if (!IS_ERR(asrc->spba_clk)) {
  1239. ret = clk_prepare_enable(asrc->spba_clk);
  1240. if (ret)
  1241. goto disable_ipg_clk;
  1242. }
  1243. for (i = 0; i < ASRC_CLK_MAX_NUM; i++) {
  1244. ret = clk_prepare_enable(asrc_priv->asrck_clk[i]);
  1245. if (ret)
  1246. goto disable_asrck_clk;
  1247. }
  1248. /* Stop all pairs provisionally */
  1249. regmap_read(asrc->regmap, REG_ASRCTR, &asrctr);
  1250. regmap_update_bits(asrc->regmap, REG_ASRCTR,
  1251. ASRCTR_ASRCEi_ALL_MASK, 0);
  1252. /* Restore all registers */
  1253. regcache_cache_only(asrc->regmap, false);
  1254. regcache_mark_dirty(asrc->regmap);
  1255. regcache_sync(asrc->regmap);
  1256. regmap_update_bits(asrc->regmap, REG_ASRCFG,
  1257. ASRCFG_NDPRi_ALL_MASK | ASRCFG_POSTMODi_ALL_MASK |
  1258. ASRCFG_PREMODi_ALL_MASK, asrc_priv->regcache_cfg);
  1259. /* Restart enabled pairs */
  1260. regmap_update_bits(asrc->regmap, REG_ASRCTR,
  1261. ASRCTR_ASRCEi_ALL_MASK, asrctr);
  1262. /* Wait for status of initialization for all enabled pairs */
  1263. do {
  1264. udelay(5);
  1265. regmap_read(asrc->regmap, REG_ASRCFG, &reg);
  1266. reg = (reg >> ASRCFG_INIRQi_SHIFT(0)) & 0x7;
  1267. } while ((reg != ((asrctr >> ASRCTR_ASRCEi_SHIFT(0)) & 0x7)) && --retry);
  1268. /*
  1269. * NOTE: Doesn't treat initialization timeout as an error
  1270. * Some of the pairs may success, then still can continue.
  1271. */
  1272. if (!retry) {
  1273. for (i = ASRC_PAIR_A; i < ASRC_PAIR_MAX_NUM; i++) {
  1274. if ((asrctr & ASRCTR_ASRCEi_MASK(i)) && !(reg & (1 << i)))
  1275. dev_warn(dev, "Pair %c initialization isn't finished\n", 'A' + i);
  1276. }
  1277. }
  1278. return 0;
  1279. disable_asrck_clk:
  1280. for (i--; i >= 0; i--)
  1281. clk_disable_unprepare(asrc_priv->asrck_clk[i]);
  1282. if (!IS_ERR(asrc->spba_clk))
  1283. clk_disable_unprepare(asrc->spba_clk);
  1284. disable_ipg_clk:
  1285. clk_disable_unprepare(asrc->ipg_clk);
  1286. disable_mem_clk:
  1287. clk_disable_unprepare(asrc->mem_clk);
  1288. return ret;
  1289. }
  1290. static int fsl_asrc_runtime_suspend(struct device *dev)
  1291. {
  1292. struct fsl_asrc *asrc = dev_get_drvdata(dev);
  1293. struct fsl_asrc_priv *asrc_priv = asrc->private;
  1294. int i;
  1295. regmap_read(asrc->regmap, REG_ASRCFG,
  1296. &asrc_priv->regcache_cfg);
  1297. regcache_cache_only(asrc->regmap, true);
  1298. for (i = 0; i < ASRC_CLK_MAX_NUM; i++)
  1299. clk_disable_unprepare(asrc_priv->asrck_clk[i]);
  1300. if (!IS_ERR(asrc->spba_clk))
  1301. clk_disable_unprepare(asrc->spba_clk);
  1302. clk_disable_unprepare(asrc->ipg_clk);
  1303. clk_disable_unprepare(asrc->mem_clk);
  1304. return 0;
  1305. }
  1306. static int fsl_asrc_suspend(struct device *dev)
  1307. {
  1308. struct fsl_asrc *asrc = dev_get_drvdata(dev);
  1309. int ret;
  1310. fsl_asrc_m2m_suspend(asrc);
  1311. ret = pm_runtime_force_suspend(dev);
  1312. return ret;
  1313. }
  1314. static int fsl_asrc_resume(struct device *dev)
  1315. {
  1316. struct fsl_asrc *asrc = dev_get_drvdata(dev);
  1317. int ret;
  1318. ret = pm_runtime_force_resume(dev);
  1319. fsl_asrc_m2m_resume(asrc);
  1320. return ret;
  1321. }
  1322. static const struct dev_pm_ops fsl_asrc_pm = {
  1323. RUNTIME_PM_OPS(fsl_asrc_runtime_suspend, fsl_asrc_runtime_resume, NULL)
  1324. SYSTEM_SLEEP_PM_OPS(fsl_asrc_suspend, fsl_asrc_resume)
  1325. };
  1326. static const struct fsl_asrc_soc_data fsl_asrc_imx35_data = {
  1327. .use_edma = false,
  1328. .channel_bits = 3,
  1329. };
  1330. static const struct fsl_asrc_soc_data fsl_asrc_imx53_data = {
  1331. .use_edma = false,
  1332. .channel_bits = 4,
  1333. };
  1334. static const struct fsl_asrc_soc_data fsl_asrc_imx8qm_data = {
  1335. .use_edma = true,
  1336. .channel_bits = 4,
  1337. };
  1338. static const struct fsl_asrc_soc_data fsl_asrc_imx8qxp_data = {
  1339. .use_edma = true,
  1340. .channel_bits = 4,
  1341. };
  1342. static const struct fsl_asrc_soc_data fsl_asrc_imx952_data = {
  1343. .use_edma = true,
  1344. .channel_bits = 4,
  1345. .start_before_dma = true,
  1346. };
  1347. static const struct of_device_id fsl_asrc_ids[] = {
  1348. { .compatible = "fsl,imx35-asrc", .data = &fsl_asrc_imx35_data },
  1349. { .compatible = "fsl,imx53-asrc", .data = &fsl_asrc_imx53_data },
  1350. { .compatible = "fsl,imx8qm-asrc", .data = &fsl_asrc_imx8qm_data },
  1351. { .compatible = "fsl,imx8qxp-asrc", .data = &fsl_asrc_imx8qxp_data },
  1352. { .compatible = "fsl,imx952-asrc", .data = &fsl_asrc_imx952_data },
  1353. {}
  1354. };
  1355. MODULE_DEVICE_TABLE(of, fsl_asrc_ids);
  1356. static struct platform_driver fsl_asrc_driver = {
  1357. .probe = fsl_asrc_probe,
  1358. .remove = fsl_asrc_remove,
  1359. .driver = {
  1360. .name = "fsl-asrc",
  1361. .of_match_table = fsl_asrc_ids,
  1362. .pm = pm_ptr(&fsl_asrc_pm),
  1363. },
  1364. };
  1365. module_platform_driver(fsl_asrc_driver);
  1366. MODULE_DESCRIPTION("Freescale ASRC ASoC driver");
  1367. MODULE_AUTHOR("Nicolin Chen <nicoleotsuka@gmail.com>");
  1368. MODULE_ALIAS("platform:fsl-asrc");
  1369. MODULE_LICENSE("GPL v2");