swr-mstr-ctrl.c 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/irq.h>
  6. #include <linux/kernel.h>
  7. #include <linux/init.h>
  8. #include <linux/slab.h>
  9. #include <linux/io.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/delay.h>
  13. #include <linux/kthread.h>
  14. #include <linux/bitops.h>
  15. #include <linux/clk.h>
  16. #include <linux/gpio.h>
  17. #include <linux/of_gpio.h>
  18. #include <linux/pm_runtime.h>
  19. #include <linux/of.h>
  20. #include <soc/soundwire.h>
  21. #include <soc/swr-common.h>
  22. #include <linux/regmap.h>
  23. #include <dsp/msm-audio-event-notify.h>
  24. #include "swrm_registers.h"
  25. #include "swr-mstr-ctrl.h"
  26. #define SWRM_SYSTEM_RESUME_TIMEOUT_MS 700
  27. #define SWRM_SYS_SUSPEND_WAIT 1
  28. #define SWRM_DSD_PARAMS_PORT 4
  29. #define SWR_BROADCAST_CMD_ID 0x0F
  30. #define SWR_AUTO_SUSPEND_DELAY 1 /* delay in sec */
  31. #define SWR_DEV_ID_MASK 0xFFFFFFFFFFFF
  32. #define SWR_REG_VAL_PACK(data, dev, id, reg) \
  33. ((reg) | ((id) << 16) | ((dev) << 20) | ((data) << 24))
  34. #define SWR_INVALID_PARAM 0xFF
  35. #define SWR_HSTOP_MAX_VAL 0xF
  36. #define SWR_HSTART_MIN_VAL 0x0
  37. #define ERR_AUTO_SUSPEND_TIMER_VAL 0x1
  38. #define SWRM_INTERRUPT_STATUS_MASK 0x1FDFD
  39. /* pm runtime auto suspend timer in msecs */
  40. static int auto_suspend_timer = SWR_AUTO_SUSPEND_DELAY * 1000;
  41. module_param(auto_suspend_timer, int, 0664);
  42. MODULE_PARM_DESC(auto_suspend_timer, "timer for auto suspend");
  43. enum {
  44. SWR_NOT_PRESENT, /* Device is detached/not present on the bus */
  45. SWR_ATTACHED_OK, /* Device is attached */
  46. SWR_ALERT, /* Device alters master for any interrupts */
  47. SWR_RESERVED, /* Reserved */
  48. };
  49. enum {
  50. MASTER_ID_WSA = 1,
  51. MASTER_ID_RX,
  52. MASTER_ID_TX
  53. };
  54. enum {
  55. ENABLE_PENDING,
  56. DISABLE_PENDING
  57. };
  58. enum {
  59. LPASS_HW_CORE,
  60. LPASS_AUDIO_CORE,
  61. };
  62. #define TRUE 1
  63. #define FALSE 0
  64. #define SWRM_MAX_PORT_REG 120
  65. #define SWRM_MAX_INIT_REG 11
  66. #define MAX_FIFO_RD_FAIL_RETRY 3
  67. static bool swrm_lock_sleep(struct swr_mstr_ctrl *swrm);
  68. static void swrm_unlock_sleep(struct swr_mstr_ctrl *swrm);
  69. static u32 swr_master_read(struct swr_mstr_ctrl *swrm, unsigned int reg_addr);
  70. static void swr_master_write(struct swr_mstr_ctrl *swrm, u16 reg_addr, u32 val);
  71. static bool swrm_is_msm_variant(int val)
  72. {
  73. return (val == SWRM_VERSION_1_3);
  74. }
  75. #ifdef CONFIG_DEBUG_FS
  76. static int swrm_debug_open(struct inode *inode, struct file *file)
  77. {
  78. file->private_data = inode->i_private;
  79. return 0;
  80. }
  81. static int get_parameters(char *buf, u32 *param1, int num_of_par)
  82. {
  83. char *token;
  84. int base, cnt;
  85. token = strsep(&buf, " ");
  86. for (cnt = 0; cnt < num_of_par; cnt++) {
  87. if (token) {
  88. if ((token[1] == 'x') || (token[1] == 'X'))
  89. base = 16;
  90. else
  91. base = 10;
  92. if (kstrtou32(token, base, &param1[cnt]) != 0)
  93. return -EINVAL;
  94. token = strsep(&buf, " ");
  95. } else
  96. return -EINVAL;
  97. }
  98. return 0;
  99. }
  100. static ssize_t swrm_reg_show(struct swr_mstr_ctrl *swrm, char __user *ubuf,
  101. size_t count, loff_t *ppos)
  102. {
  103. int i, reg_val, len;
  104. ssize_t total = 0;
  105. char tmp_buf[SWR_MSTR_MAX_BUF_LEN];
  106. int rem = 0;
  107. if (!ubuf || !ppos)
  108. return 0;
  109. i = ((int) *ppos + SWR_MSTR_START_REG_ADDR);
  110. rem = i%4;
  111. if (rem)
  112. i = (i - rem);
  113. for (; i <= SWR_MSTR_MAX_REG_ADDR; i += 4) {
  114. usleep_range(100, 150);
  115. reg_val = swr_master_read(swrm, i);
  116. len = snprintf(tmp_buf, 25, "0x%.3x: 0x%.2x\n", i, reg_val);
  117. if (len < 0) {
  118. pr_err("%s: fail to fill the buffer\n", __func__);
  119. total = -EFAULT;
  120. goto copy_err;
  121. }
  122. if ((total + len) >= count - 1)
  123. break;
  124. if (copy_to_user((ubuf + total), tmp_buf, len)) {
  125. pr_err("%s: fail to copy reg dump\n", __func__);
  126. total = -EFAULT;
  127. goto copy_err;
  128. }
  129. *ppos += len;
  130. total += len;
  131. }
  132. copy_err:
  133. return total;
  134. }
  135. static ssize_t swrm_debug_reg_dump(struct file *file, char __user *ubuf,
  136. size_t count, loff_t *ppos)
  137. {
  138. struct swr_mstr_ctrl *swrm;
  139. if (!count || !file || !ppos || !ubuf)
  140. return -EINVAL;
  141. swrm = file->private_data;
  142. if (!swrm)
  143. return -EINVAL;
  144. if (*ppos < 0)
  145. return -EINVAL;
  146. return swrm_reg_show(swrm, ubuf, count, ppos);
  147. }
  148. static ssize_t swrm_debug_read(struct file *file, char __user *ubuf,
  149. size_t count, loff_t *ppos)
  150. {
  151. char lbuf[SWR_MSTR_RD_BUF_LEN];
  152. struct swr_mstr_ctrl *swrm = NULL;
  153. if (!count || !file || !ppos || !ubuf)
  154. return -EINVAL;
  155. swrm = file->private_data;
  156. if (!swrm)
  157. return -EINVAL;
  158. if (*ppos < 0)
  159. return -EINVAL;
  160. snprintf(lbuf, sizeof(lbuf), "0x%x\n", swrm->read_data);
  161. return simple_read_from_buffer(ubuf, count, ppos, lbuf,
  162. strnlen(lbuf, 7));
  163. }
  164. static ssize_t swrm_debug_peek_write(struct file *file, const char __user *ubuf,
  165. size_t count, loff_t *ppos)
  166. {
  167. char lbuf[SWR_MSTR_RD_BUF_LEN];
  168. int rc;
  169. u32 param[5];
  170. struct swr_mstr_ctrl *swrm = NULL;
  171. if (!count || !file || !ppos || !ubuf)
  172. return -EINVAL;
  173. swrm = file->private_data;
  174. if (!swrm)
  175. return -EINVAL;
  176. if (*ppos < 0)
  177. return -EINVAL;
  178. if (count > sizeof(lbuf) - 1)
  179. return -EINVAL;
  180. rc = copy_from_user(lbuf, ubuf, count);
  181. if (rc)
  182. return -EFAULT;
  183. lbuf[count] = '\0';
  184. rc = get_parameters(lbuf, param, 1);
  185. if ((param[0] <= SWR_MSTR_MAX_REG_ADDR) && (rc == 0))
  186. swrm->read_data = swr_master_read(swrm, param[0]);
  187. else
  188. rc = -EINVAL;
  189. if (rc == 0)
  190. rc = count;
  191. else
  192. dev_err(swrm->dev, "%s: rc = %d\n", __func__, rc);
  193. return rc;
  194. }
  195. static ssize_t swrm_debug_write(struct file *file,
  196. const char __user *ubuf, size_t count, loff_t *ppos)
  197. {
  198. char lbuf[SWR_MSTR_WR_BUF_LEN];
  199. int rc;
  200. u32 param[5];
  201. struct swr_mstr_ctrl *swrm;
  202. if (!file || !ppos || !ubuf)
  203. return -EINVAL;
  204. swrm = file->private_data;
  205. if (!swrm)
  206. return -EINVAL;
  207. if (count > sizeof(lbuf) - 1)
  208. return -EINVAL;
  209. rc = copy_from_user(lbuf, ubuf, count);
  210. if (rc)
  211. return -EFAULT;
  212. lbuf[count] = '\0';
  213. rc = get_parameters(lbuf, param, 2);
  214. if ((param[0] <= SWR_MSTR_MAX_REG_ADDR) &&
  215. (param[1] <= 0xFFFFFFFF) &&
  216. (rc == 0))
  217. swr_master_write(swrm, param[0], param[1]);
  218. else
  219. rc = -EINVAL;
  220. if (rc == 0)
  221. rc = count;
  222. else
  223. pr_err("%s: rc = %d\n", __func__, rc);
  224. return rc;
  225. }
  226. static const struct file_operations swrm_debug_read_ops = {
  227. .open = swrm_debug_open,
  228. .write = swrm_debug_peek_write,
  229. .read = swrm_debug_read,
  230. };
  231. static const struct file_operations swrm_debug_write_ops = {
  232. .open = swrm_debug_open,
  233. .write = swrm_debug_write,
  234. };
  235. static const struct file_operations swrm_debug_dump_ops = {
  236. .open = swrm_debug_open,
  237. .read = swrm_debug_reg_dump,
  238. };
  239. #endif
  240. static void swrm_reg_dump(struct swr_mstr_ctrl *swrm,
  241. u32 *reg, u32 *val, int len, const char* func)
  242. {
  243. int i = 0;
  244. for (i = 0; i < len; i++)
  245. dev_dbg(swrm->dev, "%s: reg = 0x%x val = 0x%x\n",
  246. func, reg[i], val[i]);
  247. }
  248. static int swrm_request_hw_vote(struct swr_mstr_ctrl *swrm,
  249. int core_type, bool enable)
  250. {
  251. int ret = 0;
  252. if (core_type == LPASS_HW_CORE) {
  253. if (swrm->lpass_core_hw_vote) {
  254. if (enable) {
  255. ret =
  256. clk_prepare_enable(swrm->lpass_core_hw_vote);
  257. if (ret < 0)
  258. dev_err(swrm->dev,
  259. "%s:lpass core hw enable failed\n",
  260. __func__);
  261. } else
  262. clk_disable_unprepare(swrm->lpass_core_hw_vote);
  263. }
  264. }
  265. if (core_type == LPASS_AUDIO_CORE) {
  266. if (swrm->lpass_core_audio) {
  267. if (enable) {
  268. ret =
  269. clk_prepare_enable(swrm->lpass_core_audio);
  270. if (ret < 0)
  271. dev_err(swrm->dev,
  272. "%s:lpass audio hw enable failed\n",
  273. __func__);
  274. } else
  275. clk_disable_unprepare(swrm->lpass_core_audio);
  276. }
  277. }
  278. return ret;
  279. }
  280. static int swrm_clk_request(struct swr_mstr_ctrl *swrm, bool enable)
  281. {
  282. int ret = 0;
  283. if (!swrm->clk || !swrm->handle)
  284. return -EINVAL;
  285. mutex_lock(&swrm->clklock);
  286. if (enable) {
  287. if (!swrm->dev_up) {
  288. ret = -ENODEV;
  289. goto exit;
  290. }
  291. if (swrm->core_vote) {
  292. ret = swrm->core_vote(swrm->handle, true);
  293. if (ret) {
  294. dev_err_ratelimited(swrm->dev,
  295. "%s: clock enable req failed",
  296. __func__);
  297. goto exit;
  298. }
  299. }
  300. swrm->clk_ref_count++;
  301. if (swrm->clk_ref_count == 1) {
  302. ret = swrm->clk(swrm->handle, true);
  303. if (ret) {
  304. dev_err_ratelimited(swrm->dev,
  305. "%s: clock enable req failed",
  306. __func__);
  307. --swrm->clk_ref_count;
  308. }
  309. }
  310. } else if (--swrm->clk_ref_count == 0) {
  311. swrm->clk(swrm->handle, false);
  312. complete(&swrm->clk_off_complete);
  313. }
  314. if (swrm->clk_ref_count < 0) {
  315. dev_err(swrm->dev, "%s: swrm clk count mismatch\n", __func__);
  316. swrm->clk_ref_count = 0;
  317. }
  318. exit:
  319. mutex_unlock(&swrm->clklock);
  320. return ret;
  321. }
  322. static int swrm_ahb_write(struct swr_mstr_ctrl *swrm,
  323. u16 reg, u32 *value)
  324. {
  325. u32 temp = (u32)(*value);
  326. int ret = 0;
  327. mutex_lock(&swrm->devlock);
  328. if (!swrm->dev_up)
  329. goto err;
  330. ret = swrm_clk_request(swrm, TRUE);
  331. if (ret) {
  332. dev_err_ratelimited(swrm->dev, "%s: clock request failed\n",
  333. __func__);
  334. goto err;
  335. }
  336. iowrite32(temp, swrm->swrm_dig_base + reg);
  337. swrm_clk_request(swrm, FALSE);
  338. err:
  339. mutex_unlock(&swrm->devlock);
  340. return ret;
  341. }
  342. static int swrm_ahb_read(struct swr_mstr_ctrl *swrm,
  343. u16 reg, u32 *value)
  344. {
  345. u32 temp = 0;
  346. int ret = 0;
  347. mutex_lock(&swrm->devlock);
  348. if (!swrm->dev_up)
  349. goto err;
  350. ret = swrm_clk_request(swrm, TRUE);
  351. if (ret) {
  352. dev_err_ratelimited(swrm->dev, "%s: clock request failed\n",
  353. __func__);
  354. goto err;
  355. }
  356. temp = ioread32(swrm->swrm_dig_base + reg);
  357. *value = temp;
  358. swrm_clk_request(swrm, FALSE);
  359. err:
  360. mutex_unlock(&swrm->devlock);
  361. return ret;
  362. }
  363. static u32 swr_master_read(struct swr_mstr_ctrl *swrm, unsigned int reg_addr)
  364. {
  365. u32 val = 0;
  366. if (swrm->read)
  367. val = swrm->read(swrm->handle, reg_addr);
  368. else
  369. swrm_ahb_read(swrm, reg_addr, &val);
  370. return val;
  371. }
  372. static void swr_master_write(struct swr_mstr_ctrl *swrm, u16 reg_addr, u32 val)
  373. {
  374. if (swrm->write)
  375. swrm->write(swrm->handle, reg_addr, val);
  376. else
  377. swrm_ahb_write(swrm, reg_addr, &val);
  378. }
  379. static int swr_master_bulk_write(struct swr_mstr_ctrl *swrm, u32 *reg_addr,
  380. u32 *val, unsigned int length)
  381. {
  382. int i = 0;
  383. if (swrm->bulk_write)
  384. swrm->bulk_write(swrm->handle, reg_addr, val, length);
  385. else {
  386. mutex_lock(&swrm->iolock);
  387. for (i = 0; i < length; i++) {
  388. /* wait for FIFO WR command to complete to avoid overflow */
  389. /*
  390. * Reduce sleep from 100us to 10us to meet KPIs
  391. * This still meets the hardware spec
  392. */
  393. usleep_range(10, 12);
  394. swr_master_write(swrm, reg_addr[i], val[i]);
  395. }
  396. mutex_unlock(&swrm->iolock);
  397. }
  398. return 0;
  399. }
  400. static bool swrm_is_port_en(struct swr_master *mstr)
  401. {
  402. return !!(mstr->num_port);
  403. }
  404. static void copy_port_tables(struct swr_mstr_ctrl *swrm,
  405. struct port_params *params)
  406. {
  407. u8 i;
  408. struct port_params *config = params;
  409. for (i = 0; i < SWR_MSTR_PORT_LEN; i++) {
  410. /* wsa uses single frame structure for all configurations */
  411. if (!swrm->mport_cfg[i].port_en)
  412. continue;
  413. swrm->mport_cfg[i].sinterval = config[i].si;
  414. swrm->mport_cfg[i].offset1 = config[i].off1;
  415. swrm->mport_cfg[i].offset2 = config[i].off2;
  416. swrm->mport_cfg[i].hstart = config[i].hstart;
  417. swrm->mport_cfg[i].hstop = config[i].hstop;
  418. swrm->mport_cfg[i].blk_pack_mode = config[i].bp_mode;
  419. swrm->mport_cfg[i].blk_grp_count = config[i].bgp_ctrl;
  420. swrm->mport_cfg[i].word_length = config[i].wd_len;
  421. swrm->mport_cfg[i].lane_ctrl = config[i].lane_ctrl;
  422. }
  423. }
  424. static int swrm_get_port_config(struct swr_mstr_ctrl *swrm)
  425. {
  426. struct port_params *params;
  427. u32 usecase = 0;
  428. /* TODO - Send usecase information to avoid checking for master_id */
  429. if (swrm->mport_cfg[SWRM_DSD_PARAMS_PORT].port_en &&
  430. (swrm->master_id == MASTER_ID_RX))
  431. usecase = 1;
  432. params = swrm->port_param[usecase];
  433. copy_port_tables(swrm, params);
  434. return 0;
  435. }
  436. static int swrm_get_master_port(struct swr_mstr_ctrl *swrm, u8 *mstr_port_id,
  437. u8 *mstr_ch_mask, u8 mstr_prt_type,
  438. u8 slv_port_id)
  439. {
  440. int i, j;
  441. *mstr_port_id = 0;
  442. for (i = 1; i <= swrm->num_ports; i++) {
  443. for (j = 0; j < SWR_MAX_CH_PER_PORT; j++) {
  444. if (swrm->port_mapping[i][j].port_type == mstr_prt_type)
  445. goto found;
  446. }
  447. }
  448. found:
  449. if (i > swrm->num_ports || j == SWR_MAX_CH_PER_PORT) {
  450. dev_err(swrm->dev, "%s: port type not supported by master\n",
  451. __func__);
  452. return -EINVAL;
  453. }
  454. /* id 0 corresponds to master port 1 */
  455. *mstr_port_id = i - 1;
  456. *mstr_ch_mask = swrm->port_mapping[i][j].ch_mask;
  457. return 0;
  458. }
  459. static u32 swrm_get_packed_reg_val(u8 *cmd_id, u8 cmd_data,
  460. u8 dev_addr, u16 reg_addr)
  461. {
  462. u32 val;
  463. u8 id = *cmd_id;
  464. if (id != SWR_BROADCAST_CMD_ID) {
  465. if (id < 14)
  466. id += 1;
  467. else
  468. id = 0;
  469. *cmd_id = id;
  470. }
  471. val = SWR_REG_VAL_PACK(cmd_data, dev_addr, id, reg_addr);
  472. return val;
  473. }
  474. static int swrm_cmd_fifo_rd_cmd(struct swr_mstr_ctrl *swrm, int *cmd_data,
  475. u8 dev_addr, u8 cmd_id, u16 reg_addr,
  476. u32 len)
  477. {
  478. u32 val;
  479. u32 retry_attempt = 0;
  480. mutex_lock(&swrm->iolock);
  481. val = swrm_get_packed_reg_val(&swrm->rcmd_id, len, dev_addr, reg_addr);
  482. if (swrm->read) {
  483. /* skip delay if read is handled in platform driver */
  484. swr_master_write(swrm, SWRM_CMD_FIFO_RD_CMD, val);
  485. } else {
  486. /* wait for FIFO RD to complete to avoid overflow */
  487. usleep_range(100, 105);
  488. swr_master_write(swrm, SWRM_CMD_FIFO_RD_CMD, val);
  489. /* wait for FIFO RD CMD complete to avoid overflow */
  490. usleep_range(250, 255);
  491. }
  492. retry_read:
  493. *cmd_data = swr_master_read(swrm, SWRM_CMD_FIFO_RD_FIFO_ADDR);
  494. dev_dbg(swrm->dev, "%s: reg: 0x%x, cmd_id: 0x%x, rcmd_id: 0x%x, \
  495. dev_num: 0x%x, cmd_data: 0x%x\n", __func__, reg_addr,
  496. cmd_id, swrm->rcmd_id, dev_addr, *cmd_data);
  497. if ((((*cmd_data) & 0xF00) >> 8) != swrm->rcmd_id) {
  498. if (retry_attempt < MAX_FIFO_RD_FAIL_RETRY) {
  499. /* wait 500 us before retry on fifo read failure */
  500. usleep_range(500, 505);
  501. retry_attempt++;
  502. goto retry_read;
  503. } else {
  504. dev_err_ratelimited(swrm->dev, "%s: reg: 0x%x, cmd_id: 0x%x, \
  505. rcmd_id: 0x%x, dev_num: 0x%x, cmd_data: 0x%x\n",
  506. __func__, reg_addr, cmd_id, swrm->rcmd_id,
  507. dev_addr, *cmd_data);
  508. dev_err_ratelimited(swrm->dev,
  509. "%s: failed to read fifo\n", __func__);
  510. }
  511. }
  512. mutex_unlock(&swrm->iolock);
  513. return 0;
  514. }
  515. static int swrm_cmd_fifo_wr_cmd(struct swr_mstr_ctrl *swrm, u8 cmd_data,
  516. u8 dev_addr, u8 cmd_id, u16 reg_addr)
  517. {
  518. u32 val;
  519. int ret = 0;
  520. mutex_lock(&swrm->iolock);
  521. if (!cmd_id)
  522. val = swrm_get_packed_reg_val(&swrm->wcmd_id, cmd_data,
  523. dev_addr, reg_addr);
  524. else
  525. val = swrm_get_packed_reg_val(&cmd_id, cmd_data,
  526. dev_addr, reg_addr);
  527. dev_dbg(swrm->dev, "%s: reg: 0x%x, cmd_id: 0x%x,wcmd_id: 0x%x, \
  528. dev_num: 0x%x, cmd_data: 0x%x\n", __func__,
  529. reg_addr, cmd_id, swrm->wcmd_id,dev_addr, cmd_data);
  530. swr_master_write(swrm, SWRM_CMD_FIFO_WR_CMD, val);
  531. /*
  532. * wait for FIFO WR command to complete to avoid overflow
  533. * skip delay if write is handled in platform driver.
  534. */
  535. if(!swrm->write)
  536. usleep_range(150, 155);
  537. if (cmd_id == 0xF) {
  538. /*
  539. * sleep for 10ms for MSM soundwire variant to allow broadcast
  540. * command to complete.
  541. */
  542. if (swrm_is_msm_variant(swrm->version))
  543. usleep_range(10000, 10100);
  544. else
  545. wait_for_completion_timeout(&swrm->broadcast,
  546. (2 * HZ/10));
  547. }
  548. mutex_unlock(&swrm->iolock);
  549. return ret;
  550. }
  551. static int swrm_read(struct swr_master *master, u8 dev_num, u16 reg_addr,
  552. void *buf, u32 len)
  553. {
  554. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master);
  555. int ret = 0;
  556. int val;
  557. u8 *reg_val = (u8 *)buf;
  558. if (!swrm) {
  559. dev_err(&master->dev, "%s: swrm is NULL\n", __func__);
  560. return -EINVAL;
  561. }
  562. if (!dev_num) {
  563. dev_err(&master->dev, "%s: invalid slave dev num\n", __func__);
  564. return -EINVAL;
  565. }
  566. mutex_lock(&swrm->devlock);
  567. if (!swrm->dev_up) {
  568. mutex_unlock(&swrm->devlock);
  569. return 0;
  570. }
  571. mutex_unlock(&swrm->devlock);
  572. pm_runtime_get_sync(swrm->dev);
  573. ret = swrm_cmd_fifo_rd_cmd(swrm, &val, dev_num, 0, reg_addr, len);
  574. if (!ret)
  575. *reg_val = (u8)val;
  576. pm_runtime_put_autosuspend(swrm->dev);
  577. pm_runtime_mark_last_busy(swrm->dev);
  578. return ret;
  579. }
  580. static int swrm_write(struct swr_master *master, u8 dev_num, u16 reg_addr,
  581. const void *buf)
  582. {
  583. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master);
  584. int ret = 0;
  585. u8 reg_val = *(u8 *)buf;
  586. if (!swrm) {
  587. dev_err(&master->dev, "%s: swrm is NULL\n", __func__);
  588. return -EINVAL;
  589. }
  590. if (!dev_num) {
  591. dev_err(&master->dev, "%s: invalid slave dev num\n", __func__);
  592. return -EINVAL;
  593. }
  594. mutex_lock(&swrm->devlock);
  595. if (!swrm->dev_up) {
  596. mutex_unlock(&swrm->devlock);
  597. return 0;
  598. }
  599. mutex_unlock(&swrm->devlock);
  600. pm_runtime_get_sync(swrm->dev);
  601. ret = swrm_cmd_fifo_wr_cmd(swrm, reg_val, dev_num, 0, reg_addr);
  602. pm_runtime_put_autosuspend(swrm->dev);
  603. pm_runtime_mark_last_busy(swrm->dev);
  604. return ret;
  605. }
  606. static int swrm_bulk_write(struct swr_master *master, u8 dev_num, void *reg,
  607. const void *buf, size_t len)
  608. {
  609. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master);
  610. int ret = 0;
  611. int i;
  612. u32 *val;
  613. u32 *swr_fifo_reg;
  614. if (!swrm || !swrm->handle) {
  615. dev_err(&master->dev, "%s: swrm is NULL\n", __func__);
  616. return -EINVAL;
  617. }
  618. if (len <= 0)
  619. return -EINVAL;
  620. mutex_lock(&swrm->devlock);
  621. if (!swrm->dev_up) {
  622. mutex_unlock(&swrm->devlock);
  623. return 0;
  624. }
  625. mutex_unlock(&swrm->devlock);
  626. pm_runtime_get_sync(swrm->dev);
  627. if (dev_num) {
  628. swr_fifo_reg = kcalloc(len, sizeof(u32), GFP_KERNEL);
  629. if (!swr_fifo_reg) {
  630. ret = -ENOMEM;
  631. goto err;
  632. }
  633. val = kcalloc(len, sizeof(u32), GFP_KERNEL);
  634. if (!val) {
  635. ret = -ENOMEM;
  636. goto mem_fail;
  637. }
  638. for (i = 0; i < len; i++) {
  639. val[i] = swrm_get_packed_reg_val(&swrm->wcmd_id,
  640. ((u8 *)buf)[i],
  641. dev_num,
  642. ((u16 *)reg)[i]);
  643. swr_fifo_reg[i] = SWRM_CMD_FIFO_WR_CMD;
  644. }
  645. ret = swr_master_bulk_write(swrm, swr_fifo_reg, val, len);
  646. if (ret) {
  647. dev_err(&master->dev, "%s: bulk write failed\n",
  648. __func__);
  649. ret = -EINVAL;
  650. }
  651. } else {
  652. dev_err(&master->dev,
  653. "%s: No support of Bulk write for master regs\n",
  654. __func__);
  655. ret = -EINVAL;
  656. goto err;
  657. }
  658. kfree(val);
  659. mem_fail:
  660. kfree(swr_fifo_reg);
  661. err:
  662. pm_runtime_put_autosuspend(swrm->dev);
  663. pm_runtime_mark_last_busy(swrm->dev);
  664. return ret;
  665. }
  666. static u8 get_inactive_bank_num(struct swr_mstr_ctrl *swrm)
  667. {
  668. return (swr_master_read(swrm, SWRM_MCP_STATUS) &
  669. SWRM_MCP_STATUS_BANK_NUM_MASK) ? 0 : 1;
  670. }
  671. static void enable_bank_switch(struct swr_mstr_ctrl *swrm, u8 bank,
  672. u8 row, u8 col)
  673. {
  674. swrm_cmd_fifo_wr_cmd(swrm, ((row << 3) | col), 0xF, 0xF,
  675. SWRS_SCP_FRAME_CTRL_BANK(bank));
  676. }
  677. static struct swr_port_info *swrm_get_port_req(struct swrm_mports *mport,
  678. u8 slv_port, u8 dev_num)
  679. {
  680. struct swr_port_info *port_req = NULL;
  681. list_for_each_entry(port_req, &mport->port_req_list, list) {
  682. /* Store dev_id instead of dev_num if enumeration is changed run_time */
  683. if ((port_req->slave_port_id == slv_port)
  684. && (port_req->dev_num == dev_num))
  685. return port_req;
  686. }
  687. return NULL;
  688. }
  689. static bool swrm_remove_from_group(struct swr_master *master)
  690. {
  691. struct swr_device *swr_dev;
  692. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master);
  693. bool is_removed = false;
  694. if (!swrm)
  695. goto end;
  696. mutex_lock(&swrm->mlock);
  697. if ((swrm->num_rx_chs > 1) &&
  698. (swrm->num_rx_chs == swrm->num_cfg_devs)) {
  699. list_for_each_entry(swr_dev, &master->devices,
  700. dev_list) {
  701. swr_dev->group_id = SWR_GROUP_NONE;
  702. master->gr_sid = 0;
  703. }
  704. is_removed = true;
  705. }
  706. mutex_unlock(&swrm->mlock);
  707. end:
  708. return is_removed;
  709. }
  710. static void swrm_disable_ports(struct swr_master *master,
  711. u8 bank)
  712. {
  713. u32 value;
  714. struct swr_port_info *port_req;
  715. int i;
  716. struct swrm_mports *mport;
  717. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master);
  718. if (!swrm) {
  719. pr_err("%s: swrm is null\n", __func__);
  720. return;
  721. }
  722. dev_dbg(swrm->dev, "%s: master num_port: %d\n", __func__,
  723. master->num_port);
  724. for (i = 0; i < SWR_MSTR_PORT_LEN ; i++) {
  725. mport = &(swrm->mport_cfg[i]);
  726. if (!mport->port_en)
  727. continue;
  728. list_for_each_entry(port_req, &mport->port_req_list, list) {
  729. /* skip ports with no change req's*/
  730. if (port_req->req_ch == port_req->ch_en)
  731. continue;
  732. swrm_cmd_fifo_wr_cmd(swrm, port_req->req_ch,
  733. port_req->dev_num, 0x00,
  734. SWRS_DP_CHANNEL_ENABLE_BANK(port_req->slave_port_id,
  735. bank));
  736. dev_dbg(swrm->dev, "%s: mport :%d, reg: 0x%x\n",
  737. __func__, i,
  738. (SWRM_DP_PORT_CTRL_BANK(i + 1, bank)));
  739. }
  740. value = ((mport->req_ch)
  741. << SWRM_DP_PORT_CTRL_EN_CHAN_SHFT);
  742. value |= ((mport->offset2)
  743. << SWRM_DP_PORT_CTRL_OFFSET2_SHFT);
  744. value |= ((mport->offset1)
  745. << SWRM_DP_PORT_CTRL_OFFSET1_SHFT);
  746. value |= mport->sinterval;
  747. swr_master_write(swrm,
  748. SWRM_DP_PORT_CTRL_BANK(i+1, bank),
  749. value);
  750. dev_dbg(swrm->dev, "%s: mport :%d, reg: 0x%x, val: 0x%x\n",
  751. __func__, i,
  752. (SWRM_DP_PORT_CTRL_BANK(i+1, bank)), value);
  753. }
  754. }
  755. static void swrm_cleanup_disabled_port_reqs(struct swr_master *master)
  756. {
  757. struct swr_port_info *port_req, *next;
  758. int i;
  759. struct swrm_mports *mport;
  760. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master);
  761. if (!swrm) {
  762. pr_err("%s: swrm is null\n", __func__);
  763. return;
  764. }
  765. dev_dbg(swrm->dev, "%s: master num_port: %d\n", __func__,
  766. master->num_port);
  767. for (i = 0; i < SWR_MSTR_PORT_LEN; i++) {
  768. mport = &(swrm->mport_cfg[i]);
  769. list_for_each_entry_safe(port_req, next,
  770. &mport->port_req_list, list) {
  771. /* skip ports without new ch req */
  772. if (port_req->ch_en == port_req->req_ch)
  773. continue;
  774. /* remove new ch req's*/
  775. port_req->ch_en = port_req->req_ch;
  776. /* If no streams enabled on port, remove the port req */
  777. if (port_req->ch_en == 0) {
  778. list_del(&port_req->list);
  779. kfree(port_req);
  780. }
  781. }
  782. /* remove new ch req's on mport*/
  783. mport->ch_en = mport->req_ch;
  784. if (!(mport->ch_en)) {
  785. mport->port_en = false;
  786. master->port_en_mask &= ~i;
  787. }
  788. }
  789. }
  790. static void swrm_copy_data_port_config(struct swr_master *master, u8 bank)
  791. {
  792. u32 value, slv_id;
  793. struct swr_port_info *port_req;
  794. int i;
  795. struct swrm_mports *mport;
  796. u32 reg[SWRM_MAX_PORT_REG];
  797. u32 val[SWRM_MAX_PORT_REG];
  798. int len = 0;
  799. u8 hparams;
  800. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master);
  801. if (!swrm) {
  802. pr_err("%s: swrm is null\n", __func__);
  803. return;
  804. }
  805. dev_dbg(swrm->dev, "%s: master num_port: %d\n", __func__,
  806. master->num_port);
  807. for (i = 0; i < SWR_MSTR_PORT_LEN; i++) {
  808. mport = &(swrm->mport_cfg[i]);
  809. if (!mport->port_en)
  810. continue;
  811. list_for_each_entry(port_req, &mport->port_req_list, list) {
  812. slv_id = port_req->slave_port_id;
  813. reg[len] = SWRM_CMD_FIFO_WR_CMD;
  814. val[len++] = SWR_REG_VAL_PACK(port_req->req_ch,
  815. port_req->dev_num, 0x00,
  816. SWRS_DP_CHANNEL_ENABLE_BANK(slv_id,
  817. bank));
  818. reg[len] = SWRM_CMD_FIFO_WR_CMD;
  819. val[len++] = SWR_REG_VAL_PACK(mport->sinterval,
  820. port_req->dev_num, 0x00,
  821. SWRS_DP_SAMPLE_CONTROL_1_BANK(slv_id,
  822. bank));
  823. reg[len] = SWRM_CMD_FIFO_WR_CMD;
  824. val[len++] = SWR_REG_VAL_PACK(mport->offset1,
  825. port_req->dev_num, 0x00,
  826. SWRS_DP_OFFSET_CONTROL_1_BANK(slv_id,
  827. bank));
  828. if (mport->offset2 != SWR_INVALID_PARAM) {
  829. reg[len] = SWRM_CMD_FIFO_WR_CMD;
  830. val[len++] = SWR_REG_VAL_PACK(mport->offset2,
  831. port_req->dev_num, 0x00,
  832. SWRS_DP_OFFSET_CONTROL_2_BANK(
  833. slv_id, bank));
  834. }
  835. if (mport->hstart != SWR_INVALID_PARAM
  836. && mport->hstop != SWR_INVALID_PARAM) {
  837. hparams = (mport->hstart << 4) | mport->hstop;
  838. reg[len] = SWRM_CMD_FIFO_WR_CMD;
  839. val[len++] = SWR_REG_VAL_PACK(hparams,
  840. port_req->dev_num, 0x00,
  841. SWRS_DP_HCONTROL_BANK(slv_id,
  842. bank));
  843. }
  844. if (mport->word_length != SWR_INVALID_PARAM) {
  845. reg[len] = SWRM_CMD_FIFO_WR_CMD;
  846. val[len++] =
  847. SWR_REG_VAL_PACK(mport->word_length,
  848. port_req->dev_num, 0x00,
  849. SWRS_DP_BLOCK_CONTROL_1(slv_id));
  850. }
  851. if (mport->blk_pack_mode != SWR_INVALID_PARAM
  852. && swrm->master_id != MASTER_ID_WSA) {
  853. reg[len] = SWRM_CMD_FIFO_WR_CMD;
  854. val[len++] =
  855. SWR_REG_VAL_PACK(mport->blk_pack_mode,
  856. port_req->dev_num, 0x00,
  857. SWRS_DP_BLOCK_CONTROL_3_BANK(slv_id,
  858. bank));
  859. }
  860. if (mport->blk_grp_count != SWR_INVALID_PARAM) {
  861. reg[len] = SWRM_CMD_FIFO_WR_CMD;
  862. val[len++] =
  863. SWR_REG_VAL_PACK(mport->blk_grp_count,
  864. port_req->dev_num, 0x00,
  865. SWRS_DP_BLOCK_CONTROL_2_BANK(slv_id,
  866. bank));
  867. }
  868. if (mport->lane_ctrl != SWR_INVALID_PARAM) {
  869. reg[len] = SWRM_CMD_FIFO_WR_CMD;
  870. val[len++] =
  871. SWR_REG_VAL_PACK(mport->lane_ctrl,
  872. port_req->dev_num, 0x00,
  873. SWRS_DP_LANE_CONTROL_BANK(slv_id,
  874. bank));
  875. }
  876. port_req->ch_en = port_req->req_ch;
  877. }
  878. value = ((mport->req_ch)
  879. << SWRM_DP_PORT_CTRL_EN_CHAN_SHFT);
  880. if (mport->offset2 != SWR_INVALID_PARAM)
  881. value |= ((mport->offset2)
  882. << SWRM_DP_PORT_CTRL_OFFSET2_SHFT);
  883. value |= ((mport->offset1)
  884. << SWRM_DP_PORT_CTRL_OFFSET1_SHFT);
  885. value |= mport->sinterval;
  886. reg[len] = SWRM_DP_PORT_CTRL_BANK(i + 1, bank);
  887. val[len++] = value;
  888. dev_dbg(swrm->dev, "%s: mport :%d, reg: 0x%x, val: 0x%x\n",
  889. __func__, i,
  890. (SWRM_DP_PORT_CTRL_BANK(i + 1, bank)), value);
  891. if (mport->lane_ctrl != SWR_INVALID_PARAM) {
  892. reg[len] = SWRM_DP_PORT_CTRL_2_BANK(i + 1, bank);
  893. val[len++] = mport->lane_ctrl;
  894. }
  895. if (mport->word_length != SWR_INVALID_PARAM) {
  896. reg[len] = SWRM_DP_BLOCK_CTRL_1(i + 1);
  897. val[len++] = mport->word_length;
  898. }
  899. if (mport->blk_grp_count != SWR_INVALID_PARAM) {
  900. reg[len] = SWRM_DP_BLOCK_CTRL2_BANK(i + 1, bank);
  901. val[len++] = mport->blk_grp_count;
  902. }
  903. if (mport->hstart != SWR_INVALID_PARAM
  904. && mport->hstop != SWR_INVALID_PARAM) {
  905. reg[len] = SWRM_DP_PORT_HCTRL_BANK(i + 1, bank);
  906. hparams = (mport->hstop << 4) | mport->hstart;
  907. val[len++] = hparams;
  908. } else {
  909. reg[len] = SWRM_DP_PORT_HCTRL_BANK(i + 1, bank);
  910. hparams = (SWR_HSTOP_MAX_VAL << 4) | SWR_HSTART_MIN_VAL;
  911. val[len++] = hparams;
  912. }
  913. if (mport->blk_pack_mode != SWR_INVALID_PARAM) {
  914. reg[len] = SWRM_DP_BLOCK_CTRL3_BANK(i + 1, bank);
  915. val[len++] = mport->blk_pack_mode;
  916. }
  917. mport->ch_en = mport->req_ch;
  918. }
  919. swrm_reg_dump(swrm, reg, val, len, __func__);
  920. swr_master_bulk_write(swrm, reg, val, len);
  921. }
  922. static void swrm_apply_port_config(struct swr_master *master)
  923. {
  924. u8 bank;
  925. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master);
  926. if (!swrm) {
  927. pr_err("%s: Invalid handle to swr controller\n",
  928. __func__);
  929. return;
  930. }
  931. bank = get_inactive_bank_num(swrm);
  932. dev_dbg(swrm->dev, "%s: enter bank: %d master_ports: %d\n",
  933. __func__, bank, master->num_port);
  934. swrm_cmd_fifo_wr_cmd(swrm, 0x01, 0xF, 0x00,
  935. SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(bank));
  936. swrm_copy_data_port_config(master, bank);
  937. }
  938. static int swrm_slvdev_datapath_control(struct swr_master *master, bool enable)
  939. {
  940. u8 bank;
  941. u32 value, n_row, n_col;
  942. int ret;
  943. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master);
  944. int mask = (SWRM_MCP_FRAME_CTRL_BANK_ROW_CTRL_BMSK |
  945. SWRM_MCP_FRAME_CTRL_BANK_COL_CTRL_BMSK |
  946. SWRM_MCP_FRAME_CTRL_BANK_SSP_PERIOD_BMSK);
  947. u8 inactive_bank;
  948. if (!swrm) {
  949. pr_err("%s: swrm is null\n", __func__);
  950. return -EFAULT;
  951. }
  952. mutex_lock(&swrm->mlock);
  953. /*
  954. * During disable if master is already down, which implies an ssr/pdr
  955. * scenario, just mark ports as disabled and exit
  956. */
  957. if (swrm->state == SWR_MSTR_SSR && !enable) {
  958. if (!test_bit(DISABLE_PENDING, &swrm->port_req_pending)) {
  959. dev_dbg(swrm->dev, "%s:No pending disconn port req\n",
  960. __func__);
  961. goto exit;
  962. }
  963. clear_bit(DISABLE_PENDING, &swrm->port_req_pending);
  964. swrm_cleanup_disabled_port_reqs(master);
  965. if (!swrm_is_port_en(master)) {
  966. dev_dbg(&master->dev, "%s: pm_runtime auto suspend triggered\n",
  967. __func__);
  968. pm_runtime_mark_last_busy(swrm->dev);
  969. pm_runtime_put_autosuspend(swrm->dev);
  970. }
  971. goto exit;
  972. }
  973. bank = get_inactive_bank_num(swrm);
  974. if (enable) {
  975. if (!test_bit(ENABLE_PENDING, &swrm->port_req_pending)) {
  976. dev_dbg(swrm->dev, "%s:No pending connect port req\n",
  977. __func__);
  978. goto exit;
  979. }
  980. clear_bit(ENABLE_PENDING, &swrm->port_req_pending);
  981. ret = swrm_get_port_config(swrm);
  982. if (ret) {
  983. /* cannot accommodate ports */
  984. swrm_cleanup_disabled_port_reqs(master);
  985. mutex_unlock(&swrm->mlock);
  986. return -EINVAL;
  987. }
  988. swr_master_write(swrm, SWR_MSTR_RX_SWRM_CPU_INTERRUPT_EN,
  989. SWRM_INTERRUPT_STATUS_MASK);
  990. /* apply the new port config*/
  991. swrm_apply_port_config(master);
  992. } else {
  993. if (!test_bit(DISABLE_PENDING, &swrm->port_req_pending)) {
  994. dev_dbg(swrm->dev, "%s:No pending disconn port req\n",
  995. __func__);
  996. goto exit;
  997. }
  998. clear_bit(DISABLE_PENDING, &swrm->port_req_pending);
  999. swrm_disable_ports(master, bank);
  1000. }
  1001. dev_dbg(swrm->dev, "%s: enable: %d, cfg_devs: %d\n",
  1002. __func__, enable, swrm->num_cfg_devs);
  1003. if (enable) {
  1004. /* set col = 16 */
  1005. n_col = SWR_MAX_COL;
  1006. } else {
  1007. /*
  1008. * Do not change to col = 2 if there are still active ports
  1009. */
  1010. if (!master->num_port)
  1011. n_col = SWR_MIN_COL;
  1012. else
  1013. n_col = SWR_MAX_COL;
  1014. }
  1015. /* Use default 50 * x, frame shape. Change based on mclk */
  1016. if (swrm->mclk_freq == MCLK_FREQ_NATIVE) {
  1017. dev_dbg(swrm->dev, "setting 64 x %d frameshape\n",
  1018. n_col ? 16 : 2);
  1019. n_row = SWR_ROW_64;
  1020. } else {
  1021. dev_dbg(swrm->dev, "setting 50 x %d frameshape\n",
  1022. n_col ? 16 : 2);
  1023. n_row = SWR_ROW_50;
  1024. }
  1025. value = swr_master_read(swrm, SWRM_MCP_FRAME_CTRL_BANK_ADDR(bank));
  1026. value &= (~mask);
  1027. value |= ((n_row << SWRM_MCP_FRAME_CTRL_BANK_ROW_CTRL_SHFT) |
  1028. (n_col << SWRM_MCP_FRAME_CTRL_BANK_COL_CTRL_SHFT) |
  1029. (0 << SWRM_MCP_FRAME_CTRL_BANK_SSP_PERIOD_SHFT));
  1030. swr_master_write(swrm, SWRM_MCP_FRAME_CTRL_BANK_ADDR(bank), value);
  1031. dev_dbg(swrm->dev, "%s: regaddr: 0x%x, value: 0x%x\n", __func__,
  1032. SWRM_MCP_FRAME_CTRL_BANK_ADDR(bank), value);
  1033. enable_bank_switch(swrm, bank, n_row, n_col);
  1034. inactive_bank = bank ? 0 : 1;
  1035. if (enable)
  1036. swrm_copy_data_port_config(master, inactive_bank);
  1037. else {
  1038. swrm_disable_ports(master, inactive_bank);
  1039. swrm_cleanup_disabled_port_reqs(master);
  1040. }
  1041. if (!swrm_is_port_en(master)) {
  1042. dev_dbg(&master->dev, "%s: pm_runtime auto suspend triggered\n",
  1043. __func__);
  1044. pm_runtime_mark_last_busy(swrm->dev);
  1045. pm_runtime_put_autosuspend(swrm->dev);
  1046. }
  1047. exit:
  1048. mutex_unlock(&swrm->mlock);
  1049. return 0;
  1050. }
  1051. static int swrm_connect_port(struct swr_master *master,
  1052. struct swr_params *portinfo)
  1053. {
  1054. int i;
  1055. struct swr_port_info *port_req;
  1056. int ret = 0;
  1057. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master);
  1058. struct swrm_mports *mport;
  1059. u8 mstr_port_id, mstr_ch_msk;
  1060. dev_dbg(&master->dev, "%s: enter\n", __func__);
  1061. if (!portinfo)
  1062. return -EINVAL;
  1063. if (!swrm) {
  1064. dev_err(&master->dev,
  1065. "%s: Invalid handle to swr controller\n",
  1066. __func__);
  1067. return -EINVAL;
  1068. }
  1069. mutex_lock(&swrm->mlock);
  1070. mutex_lock(&swrm->devlock);
  1071. if (!swrm->dev_up) {
  1072. mutex_unlock(&swrm->devlock);
  1073. mutex_unlock(&swrm->mlock);
  1074. return -EINVAL;
  1075. }
  1076. mutex_unlock(&swrm->devlock);
  1077. if (!swrm_is_port_en(master))
  1078. pm_runtime_get_sync(swrm->dev);
  1079. for (i = 0; i < portinfo->num_port; i++) {
  1080. ret = swrm_get_master_port(swrm, &mstr_port_id, &mstr_ch_msk,
  1081. portinfo->port_type[i],
  1082. portinfo->port_id[i]);
  1083. if (ret) {
  1084. dev_err(&master->dev,
  1085. "%s: mstr portid for slv port %d not found\n",
  1086. __func__, portinfo->port_id[i]);
  1087. goto port_fail;
  1088. }
  1089. mport = &(swrm->mport_cfg[mstr_port_id]);
  1090. /* get port req */
  1091. port_req = swrm_get_port_req(mport, portinfo->port_id[i],
  1092. portinfo->dev_num);
  1093. if (!port_req) {
  1094. dev_dbg(&master->dev, "%s: new req:port id %d dev %d\n",
  1095. __func__, portinfo->port_id[i],
  1096. portinfo->dev_num);
  1097. port_req = kzalloc(sizeof(struct swr_port_info),
  1098. GFP_KERNEL);
  1099. if (!port_req) {
  1100. ret = -ENOMEM;
  1101. goto mem_fail;
  1102. }
  1103. port_req->dev_num = portinfo->dev_num;
  1104. port_req->slave_port_id = portinfo->port_id[i];
  1105. port_req->num_ch = portinfo->num_ch[i];
  1106. port_req->ch_rate = portinfo->ch_rate[i];
  1107. port_req->ch_en = 0;
  1108. port_req->master_port_id = mstr_port_id;
  1109. list_add(&port_req->list, &mport->port_req_list);
  1110. }
  1111. port_req->req_ch |= portinfo->ch_en[i];
  1112. dev_dbg(&master->dev,
  1113. "%s: mstr port %d, slv port %d ch_rate %d num_ch %d\n",
  1114. __func__, port_req->master_port_id,
  1115. port_req->slave_port_id, port_req->ch_rate,
  1116. port_req->num_ch);
  1117. /* Put the port req on master port */
  1118. mport = &(swrm->mport_cfg[mstr_port_id]);
  1119. mport->port_en = true;
  1120. mport->req_ch |= mstr_ch_msk;
  1121. master->port_en_mask |= (1 << mstr_port_id);
  1122. }
  1123. master->num_port += portinfo->num_port;
  1124. set_bit(ENABLE_PENDING, &swrm->port_req_pending);
  1125. swr_port_response(master, portinfo->tid);
  1126. mutex_unlock(&swrm->mlock);
  1127. return 0;
  1128. port_fail:
  1129. mem_fail:
  1130. /* cleanup port reqs in error condition */
  1131. swrm_cleanup_disabled_port_reqs(master);
  1132. mutex_unlock(&swrm->mlock);
  1133. return ret;
  1134. }
  1135. static int swrm_disconnect_port(struct swr_master *master,
  1136. struct swr_params *portinfo)
  1137. {
  1138. int i, ret = 0;
  1139. struct swr_port_info *port_req;
  1140. struct swrm_mports *mport;
  1141. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master);
  1142. u8 mstr_port_id, mstr_ch_mask;
  1143. if (!swrm) {
  1144. dev_err(&master->dev,
  1145. "%s: Invalid handle to swr controller\n",
  1146. __func__);
  1147. return -EINVAL;
  1148. }
  1149. if (!portinfo) {
  1150. dev_err(&master->dev, "%s: portinfo is NULL\n", __func__);
  1151. return -EINVAL;
  1152. }
  1153. mutex_lock(&swrm->mlock);
  1154. for (i = 0; i < portinfo->num_port; i++) {
  1155. ret = swrm_get_master_port(swrm, &mstr_port_id, &mstr_ch_mask,
  1156. portinfo->port_type[i], portinfo->port_id[i]);
  1157. if (ret) {
  1158. dev_err(&master->dev,
  1159. "%s: mstr portid for slv port %d not found\n",
  1160. __func__, portinfo->port_id[i]);
  1161. mutex_unlock(&swrm->mlock);
  1162. return -EINVAL;
  1163. }
  1164. mport = &(swrm->mport_cfg[mstr_port_id]);
  1165. /* get port req */
  1166. port_req = swrm_get_port_req(mport, portinfo->port_id[i],
  1167. portinfo->dev_num);
  1168. if (!port_req) {
  1169. dev_err(&master->dev, "%s:port not enabled : port %d\n",
  1170. __func__, portinfo->port_id[i]);
  1171. mutex_unlock(&swrm->mlock);
  1172. return -EINVAL;
  1173. }
  1174. port_req->req_ch &= ~portinfo->ch_en[i];
  1175. mport->req_ch &= ~mstr_ch_mask;
  1176. }
  1177. master->num_port -= portinfo->num_port;
  1178. set_bit(DISABLE_PENDING, &swrm->port_req_pending);
  1179. swr_port_response(master, portinfo->tid);
  1180. mutex_unlock(&swrm->mlock);
  1181. return 0;
  1182. }
  1183. static int swrm_find_alert_slave(struct swr_mstr_ctrl *swrm,
  1184. int status, u8 *devnum)
  1185. {
  1186. int i;
  1187. bool found = false;
  1188. for (i = 0; i < (swrm->master.num_dev + 1); i++) {
  1189. if ((status & SWRM_MCP_SLV_STATUS_MASK) == SWR_ALERT) {
  1190. *devnum = i;
  1191. found = true;
  1192. break;
  1193. }
  1194. status >>= 2;
  1195. }
  1196. if (found)
  1197. return 0;
  1198. else
  1199. return -EINVAL;
  1200. }
  1201. static void swrm_enable_slave_irq(struct swr_mstr_ctrl *swrm)
  1202. {
  1203. int i;
  1204. int status = 0;
  1205. status = swr_master_read(swrm, SWRM_MCP_SLV_STATUS);
  1206. if (!status) {
  1207. dev_dbg_ratelimited(swrm->dev, "%s: slaves status is 0x%x\n",
  1208. __func__, status);
  1209. return;
  1210. }
  1211. dev_dbg(swrm->dev, "%s: slave status: 0x%x\n", __func__, status);
  1212. for (i = 0; i < (swrm->master.num_dev + 1); i++) {
  1213. if (status & SWRM_MCP_SLV_STATUS_MASK)
  1214. swrm_cmd_fifo_wr_cmd(swrm, 0x4, i, 0x0,
  1215. SWRS_SCP_INT_STATUS_MASK_1);
  1216. status >>= 2;
  1217. }
  1218. }
  1219. static int swrm_check_slave_change_status(struct swr_mstr_ctrl *swrm,
  1220. int status, u8 *devnum)
  1221. {
  1222. int i;
  1223. int new_sts = status;
  1224. int ret = SWR_NOT_PRESENT;
  1225. if (status != swrm->slave_status) {
  1226. for (i = 0; i < (swrm->master.num_dev + 1); i++) {
  1227. if ((status & SWRM_MCP_SLV_STATUS_MASK) !=
  1228. (swrm->slave_status & SWRM_MCP_SLV_STATUS_MASK)) {
  1229. ret = (status & SWRM_MCP_SLV_STATUS_MASK);
  1230. *devnum = i;
  1231. break;
  1232. }
  1233. status >>= 2;
  1234. swrm->slave_status >>= 2;
  1235. }
  1236. swrm->slave_status = new_sts;
  1237. }
  1238. return ret;
  1239. }
  1240. static irqreturn_t swr_mstr_interrupt(int irq, void *dev)
  1241. {
  1242. struct swr_mstr_ctrl *swrm = dev;
  1243. u32 value, intr_sts, intr_sts_masked;
  1244. u32 temp = 0;
  1245. u32 status, chg_sts, i;
  1246. u8 devnum = 0;
  1247. int ret = IRQ_HANDLED;
  1248. struct swr_device *swr_dev;
  1249. struct swr_master *mstr = &swrm->master;
  1250. if (unlikely(swrm_lock_sleep(swrm) == false)) {
  1251. dev_err(swrm->dev, "%s Failed to hold suspend\n", __func__);
  1252. return IRQ_NONE;
  1253. }
  1254. mutex_lock(&swrm->reslock);
  1255. if (swrm_clk_request(swrm, true)) {
  1256. dev_err_ratelimited(swrm->dev, "%s:clk request failed\n",
  1257. __func__);
  1258. mutex_unlock(&swrm->reslock);
  1259. goto exit;
  1260. }
  1261. mutex_unlock(&swrm->reslock);
  1262. intr_sts = swr_master_read(swrm, SWRM_INTERRUPT_STATUS);
  1263. intr_sts_masked = intr_sts & swrm->intr_mask;
  1264. handle_irq:
  1265. for (i = 0; i < SWRM_INTERRUPT_MAX; i++) {
  1266. value = intr_sts_masked & (1 << i);
  1267. if (!value)
  1268. continue;
  1269. switch (value) {
  1270. case SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ:
  1271. dev_dbg(swrm->dev, "Trigger irq to slave device\n");
  1272. status = swr_master_read(swrm, SWRM_MCP_SLV_STATUS);
  1273. ret = swrm_find_alert_slave(swrm, status, &devnum);
  1274. if (ret) {
  1275. dev_err_ratelimited(swrm->dev,
  1276. "no slave alert found.spurious interrupt\n");
  1277. break;
  1278. }
  1279. swrm_cmd_fifo_rd_cmd(swrm, &temp, devnum, 0x0,
  1280. SWRS_SCP_INT_STATUS_CLEAR_1, 1);
  1281. swrm_cmd_fifo_wr_cmd(swrm, 0x4, devnum, 0x0,
  1282. SWRS_SCP_INT_STATUS_CLEAR_1);
  1283. swrm_cmd_fifo_wr_cmd(swrm, 0x0, devnum, 0x0,
  1284. SWRS_SCP_INT_STATUS_CLEAR_1);
  1285. list_for_each_entry(swr_dev, &mstr->devices, dev_list) {
  1286. if (swr_dev->dev_num != devnum)
  1287. continue;
  1288. if (swr_dev->slave_irq) {
  1289. do {
  1290. swr_dev->slave_irq_pending = 0;
  1291. handle_nested_irq(
  1292. irq_find_mapping(
  1293. swr_dev->slave_irq, 0));
  1294. } while (swr_dev->slave_irq_pending);
  1295. }
  1296. }
  1297. break;
  1298. case SWRM_INTERRUPT_STATUS_NEW_SLAVE_ATTACHED:
  1299. dev_dbg(swrm->dev, "SWR new slave attached\n");
  1300. break;
  1301. case SWRM_INTERRUPT_STATUS_CHANGE_ENUM_SLAVE_STATUS:
  1302. status = swr_master_read(swrm, SWRM_MCP_SLV_STATUS);
  1303. if (status == swrm->slave_status) {
  1304. dev_dbg(swrm->dev,
  1305. "%s: No change in slave status: %d\n",
  1306. __func__, status);
  1307. break;
  1308. }
  1309. chg_sts = swrm_check_slave_change_status(swrm, status,
  1310. &devnum);
  1311. switch (chg_sts) {
  1312. case SWR_NOT_PRESENT:
  1313. dev_dbg(swrm->dev, "device %d got detached\n",
  1314. devnum);
  1315. break;
  1316. case SWR_ATTACHED_OK:
  1317. dev_dbg(swrm->dev, "device %d got attached\n",
  1318. devnum);
  1319. /* enable host irq from slave device*/
  1320. swrm_cmd_fifo_wr_cmd(swrm, 0xFF, devnum, 0x0,
  1321. SWRS_SCP_INT_STATUS_CLEAR_1);
  1322. swrm_cmd_fifo_wr_cmd(swrm, 0x4, devnum, 0x0,
  1323. SWRS_SCP_INT_STATUS_MASK_1);
  1324. break;
  1325. case SWR_ALERT:
  1326. dev_dbg(swrm->dev,
  1327. "device %d has pending interrupt\n",
  1328. devnum);
  1329. break;
  1330. }
  1331. break;
  1332. case SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET:
  1333. dev_err_ratelimited(swrm->dev,
  1334. "SWR bus clsh detected\n");
  1335. break;
  1336. case SWRM_INTERRUPT_STATUS_RD_FIFO_OVERFLOW:
  1337. dev_dbg(swrm->dev, "SWR read FIFO overflow\n");
  1338. break;
  1339. case SWRM_INTERRUPT_STATUS_RD_FIFO_UNDERFLOW:
  1340. dev_dbg(swrm->dev, "SWR read FIFO underflow\n");
  1341. break;
  1342. case SWRM_INTERRUPT_STATUS_WR_CMD_FIFO_OVERFLOW:
  1343. dev_dbg(swrm->dev, "SWR write FIFO overflow\n");
  1344. break;
  1345. case SWRM_INTERRUPT_STATUS_CMD_ERROR:
  1346. value = swr_master_read(swrm, SWRM_CMD_FIFO_STATUS);
  1347. dev_err_ratelimited(swrm->dev,
  1348. "SWR CMD error, fifo status 0x%x, flushing fifo\n",
  1349. value);
  1350. swr_master_write(swrm, SWRM_CMD_FIFO_CMD, 0x1);
  1351. break;
  1352. case SWRM_INTERRUPT_STATUS_DOUT_PORT_COLLISION:
  1353. dev_err_ratelimited(swrm->dev, "SWR Port collision detected\n");
  1354. swrm->intr_mask &= ~SWRM_INTERRUPT_STATUS_DOUT_PORT_COLLISION;
  1355. swr_master_write(swrm,
  1356. SWR_MSTR_RX_SWRM_CPU_INTERRUPT_EN, swrm->intr_mask);
  1357. break;
  1358. case SWRM_INTERRUPT_STATUS_READ_EN_RD_VALID_MISMATCH:
  1359. dev_dbg(swrm->dev, "SWR read enable valid mismatch\n");
  1360. swrm->intr_mask &=
  1361. ~SWRM_INTERRUPT_STATUS_READ_EN_RD_VALID_MISMATCH;
  1362. swr_master_write(swrm,
  1363. SWR_MSTR_RX_SWRM_CPU_INTERRUPT_EN, swrm->intr_mask);
  1364. break;
  1365. case SWRM_INTERRUPT_STATUS_SPECIAL_CMD_ID_FINISHED:
  1366. complete(&swrm->broadcast);
  1367. dev_dbg(swrm->dev, "SWR cmd id finished\n");
  1368. break;
  1369. case SWRM_INTERRUPT_STATUS_NEW_SLAVE_AUTO_ENUM_FINISHED:
  1370. break;
  1371. case SWRM_INTERRUPT_STATUS_AUTO_ENUM_FAILED:
  1372. break;
  1373. case SWRM_INTERRUPT_STATUS_AUTO_ENUM_TABLE_IS_FULL:
  1374. break;
  1375. case SWRM_INTERRUPT_STATUS_BUS_RESET_FINISHED:
  1376. complete(&swrm->reset);
  1377. break;
  1378. case SWRM_INTERRUPT_STATUS_CLK_STOP_FINISHED:
  1379. break;
  1380. default:
  1381. dev_err_ratelimited(swrm->dev,
  1382. "SWR unknown interrupt\n");
  1383. ret = IRQ_NONE;
  1384. break;
  1385. }
  1386. }
  1387. swr_master_write(swrm, SWRM_INTERRUPT_CLEAR, intr_sts);
  1388. swr_master_write(swrm, SWRM_INTERRUPT_CLEAR, 0x0);
  1389. intr_sts = swr_master_read(swrm, SWRM_INTERRUPT_STATUS);
  1390. intr_sts_masked = intr_sts & swrm->intr_mask;
  1391. if (intr_sts_masked) {
  1392. dev_dbg(swrm->dev, "%s: new interrupt received\n", __func__);
  1393. goto handle_irq;
  1394. }
  1395. mutex_lock(&swrm->reslock);
  1396. swrm_clk_request(swrm, false);
  1397. mutex_unlock(&swrm->reslock);
  1398. exit:
  1399. swrm_unlock_sleep(swrm);
  1400. return ret;
  1401. }
  1402. static irqreturn_t swr_mstr_interrupt_v2(int irq, void *dev)
  1403. {
  1404. struct swr_mstr_ctrl *swrm = dev;
  1405. u32 value, intr_sts, intr_sts_masked;
  1406. u32 temp = 0;
  1407. u32 status, chg_sts, i;
  1408. u8 devnum = 0;
  1409. int ret = IRQ_HANDLED;
  1410. struct swr_device *swr_dev;
  1411. struct swr_master *mstr = &swrm->master;
  1412. if (!swrm->dev_up || swrm->state == SWR_MSTR_SSR) {
  1413. complete(&swrm->broadcast);
  1414. dev_dbg(swrm->dev, "%s swrm is not up\n", __func__);
  1415. return IRQ_NONE;
  1416. }
  1417. if (unlikely(swrm_lock_sleep(swrm) == false)) {
  1418. dev_err(swrm->dev, "%s Failed to hold suspend\n", __func__);
  1419. return IRQ_NONE;
  1420. }
  1421. mutex_lock(&swrm->reslock);
  1422. if (swrm_request_hw_vote(swrm, LPASS_HW_CORE, true)) {
  1423. ret = IRQ_NONE;
  1424. goto exit;
  1425. }
  1426. if (swrm_request_hw_vote(swrm, LPASS_AUDIO_CORE, true)) {
  1427. ret = IRQ_NONE;
  1428. goto err_audio_hw_vote;
  1429. }
  1430. ret = swrm_clk_request(swrm, true);
  1431. if (ret) {
  1432. dev_err(dev, "%s: swrm clk failed\n", __func__);
  1433. ret = IRQ_NONE;
  1434. goto err_audio_core_vote;
  1435. }
  1436. mutex_unlock(&swrm->reslock);
  1437. intr_sts = swr_master_read(swrm, SWRM_INTERRUPT_STATUS);
  1438. intr_sts_masked = intr_sts & swrm->intr_mask;
  1439. dev_dbg(swrm->dev, "%s: status: 0x%x \n", __func__, intr_sts_masked);
  1440. handle_irq:
  1441. for (i = 0; i < SWRM_INTERRUPT_MAX; i++) {
  1442. value = intr_sts_masked & (1 << i);
  1443. if (!value)
  1444. continue;
  1445. switch (value) {
  1446. case SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ:
  1447. dev_dbg(swrm->dev, "%s: Trigger irq to slave device\n",
  1448. __func__);
  1449. status = swr_master_read(swrm, SWRM_MCP_SLV_STATUS);
  1450. ret = swrm_find_alert_slave(swrm, status, &devnum);
  1451. if (ret) {
  1452. dev_err_ratelimited(swrm->dev,
  1453. "%s: no slave alert found.spurious interrupt\n",
  1454. __func__);
  1455. break;
  1456. }
  1457. swrm_cmd_fifo_rd_cmd(swrm, &temp, devnum, 0x0,
  1458. SWRS_SCP_INT_STATUS_CLEAR_1, 1);
  1459. swrm_cmd_fifo_wr_cmd(swrm, 0x4, devnum, 0x0,
  1460. SWRS_SCP_INT_STATUS_CLEAR_1);
  1461. swrm_cmd_fifo_wr_cmd(swrm, 0x0, devnum, 0x0,
  1462. SWRS_SCP_INT_STATUS_CLEAR_1);
  1463. list_for_each_entry(swr_dev, &mstr->devices, dev_list) {
  1464. if (swr_dev->dev_num != devnum)
  1465. continue;
  1466. if (swr_dev->slave_irq) {
  1467. do {
  1468. handle_nested_irq(
  1469. irq_find_mapping(
  1470. swr_dev->slave_irq, 0));
  1471. } while (swr_dev->slave_irq_pending);
  1472. }
  1473. }
  1474. break;
  1475. case SWRM_INTERRUPT_STATUS_NEW_SLAVE_ATTACHED:
  1476. dev_dbg(swrm->dev, "%s: SWR new slave attached\n",
  1477. __func__);
  1478. break;
  1479. case SWRM_INTERRUPT_STATUS_CHANGE_ENUM_SLAVE_STATUS:
  1480. status = swr_master_read(swrm, SWRM_MCP_SLV_STATUS);
  1481. if (status == swrm->slave_status) {
  1482. dev_dbg(swrm->dev,
  1483. "%s: No change in slave status: %d\n",
  1484. __func__, status);
  1485. break;
  1486. }
  1487. chg_sts = swrm_check_slave_change_status(swrm, status,
  1488. &devnum);
  1489. switch (chg_sts) {
  1490. case SWR_NOT_PRESENT:
  1491. dev_dbg(swrm->dev,
  1492. "%s: device %d got detached\n",
  1493. __func__, devnum);
  1494. break;
  1495. case SWR_ATTACHED_OK:
  1496. dev_dbg(swrm->dev,
  1497. "%s: device %d got attached\n",
  1498. __func__, devnum);
  1499. /* enable host irq from slave device*/
  1500. swrm_cmd_fifo_wr_cmd(swrm, 0xFF, devnum, 0x0,
  1501. SWRS_SCP_INT_STATUS_CLEAR_1);
  1502. swrm_cmd_fifo_wr_cmd(swrm, 0x4, devnum, 0x0,
  1503. SWRS_SCP_INT_STATUS_MASK_1);
  1504. break;
  1505. case SWR_ALERT:
  1506. dev_dbg(swrm->dev,
  1507. "%s: device %d has pending interrupt\n",
  1508. __func__, devnum);
  1509. break;
  1510. }
  1511. break;
  1512. case SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET:
  1513. dev_err_ratelimited(swrm->dev,
  1514. "%s: SWR bus clsh detected\n",
  1515. __func__);
  1516. break;
  1517. case SWRM_INTERRUPT_STATUS_RD_FIFO_OVERFLOW:
  1518. dev_dbg(swrm->dev, "%s: SWR read FIFO overflow\n",
  1519. __func__);
  1520. break;
  1521. case SWRM_INTERRUPT_STATUS_RD_FIFO_UNDERFLOW:
  1522. dev_dbg(swrm->dev, "%s: SWR read FIFO underflow\n",
  1523. __func__);
  1524. break;
  1525. case SWRM_INTERRUPT_STATUS_WR_CMD_FIFO_OVERFLOW:
  1526. dev_dbg(swrm->dev, "%s: SWR write FIFO overflow\n",
  1527. __func__);
  1528. break;
  1529. case SWRM_INTERRUPT_STATUS_CMD_ERROR:
  1530. value = swr_master_read(swrm, SWRM_CMD_FIFO_STATUS);
  1531. dev_err_ratelimited(swrm->dev,
  1532. "%s: SWR CMD error, fifo status 0x%x, flushing fifo\n",
  1533. __func__, value);
  1534. swr_master_write(swrm, SWRM_CMD_FIFO_CMD, 0x1);
  1535. break;
  1536. case SWRM_INTERRUPT_STATUS_DOUT_PORT_COLLISION:
  1537. dev_err_ratelimited(swrm->dev,
  1538. "%s: SWR Port collision detected\n",
  1539. __func__);
  1540. swrm->intr_mask &= ~SWRM_INTERRUPT_STATUS_DOUT_PORT_COLLISION;
  1541. swr_master_write(swrm,
  1542. SWR_MSTR_RX_SWRM_CPU_INTERRUPT_EN, swrm->intr_mask);
  1543. break;
  1544. case SWRM_INTERRUPT_STATUS_READ_EN_RD_VALID_MISMATCH:
  1545. dev_dbg(swrm->dev,
  1546. "%s: SWR read enable valid mismatch\n",
  1547. __func__);
  1548. swrm->intr_mask &=
  1549. ~SWRM_INTERRUPT_STATUS_READ_EN_RD_VALID_MISMATCH;
  1550. swr_master_write(swrm,
  1551. SWR_MSTR_RX_SWRM_CPU_INTERRUPT_EN, swrm->intr_mask);
  1552. break;
  1553. case SWRM_INTERRUPT_STATUS_SPECIAL_CMD_ID_FINISHED:
  1554. complete(&swrm->broadcast);
  1555. dev_dbg(swrm->dev, "%s: SWR cmd id finished\n",
  1556. __func__);
  1557. break;
  1558. case SWRM_INTERRUPT_STATUS_AUTO_ENUM_FAILED_V2:
  1559. break;
  1560. case SWRM_INTERRUPT_STATUS_AUTO_ENUM_TABLE_IS_FULL_V2:
  1561. break;
  1562. case SWRM_INTERRUPT_STATUS_BUS_RESET_FINISHED_V2:
  1563. break;
  1564. case SWRM_INTERRUPT_STATUS_CLK_STOP_FINISHED_V2:
  1565. break;
  1566. case SWRM_INTERRUPT_STATUS_EXT_CLK_STOP_WAKEUP:
  1567. if (swrm->state == SWR_MSTR_UP)
  1568. dev_dbg(swrm->dev,
  1569. "%s:SWR Master is already up\n",
  1570. __func__);
  1571. else
  1572. dev_err_ratelimited(swrm->dev,
  1573. "%s: SWR wokeup during clock stop\n",
  1574. __func__);
  1575. /* It might be possible the slave device gets reset
  1576. * and slave interrupt gets missed. So re-enable
  1577. * Host IRQ and process slave pending
  1578. * interrupts, if any.
  1579. */
  1580. swrm_enable_slave_irq(swrm);
  1581. break;
  1582. default:
  1583. dev_err_ratelimited(swrm->dev,
  1584. "%s: SWR unknown interrupt value: %d\n",
  1585. __func__, value);
  1586. ret = IRQ_NONE;
  1587. break;
  1588. }
  1589. }
  1590. swr_master_write(swrm, SWRM_INTERRUPT_CLEAR, intr_sts);
  1591. swr_master_write(swrm, SWRM_INTERRUPT_CLEAR, 0x0);
  1592. intr_sts = swr_master_read(swrm, SWRM_INTERRUPT_STATUS);
  1593. intr_sts_masked = intr_sts & swrm->intr_mask;
  1594. if (intr_sts_masked) {
  1595. dev_dbg(swrm->dev, "%s: new interrupt received 0x%x\n",
  1596. __func__, intr_sts_masked);
  1597. goto handle_irq;
  1598. }
  1599. mutex_lock(&swrm->reslock);
  1600. swrm_clk_request(swrm, false);
  1601. err_audio_core_vote:
  1602. swrm_request_hw_vote(swrm, LPASS_AUDIO_CORE, false);
  1603. err_audio_hw_vote:
  1604. swrm_request_hw_vote(swrm, LPASS_HW_CORE, false);
  1605. exit:
  1606. mutex_unlock(&swrm->reslock);
  1607. swrm_unlock_sleep(swrm);
  1608. return ret;
  1609. }
  1610. static irqreturn_t swrm_wakeup_interrupt(int irq, void *dev)
  1611. {
  1612. struct swr_mstr_ctrl *swrm = dev;
  1613. int ret = IRQ_HANDLED;
  1614. if (!swrm || !(swrm->dev)) {
  1615. pr_err("%s: swrm or dev is null\n", __func__);
  1616. return IRQ_NONE;
  1617. }
  1618. mutex_lock(&swrm->devlock);
  1619. if (!swrm->dev_up) {
  1620. if (swrm->wake_irq > 0)
  1621. disable_irq_nosync(swrm->wake_irq);
  1622. mutex_unlock(&swrm->devlock);
  1623. return ret;
  1624. }
  1625. mutex_unlock(&swrm->devlock);
  1626. if (unlikely(swrm_lock_sleep(swrm) == false)) {
  1627. dev_err(swrm->dev, "%s Failed to hold suspend\n", __func__);
  1628. goto exit;
  1629. }
  1630. if (swrm->wake_irq > 0)
  1631. disable_irq_nosync(swrm->wake_irq);
  1632. pm_runtime_get_sync(swrm->dev);
  1633. pm_runtime_mark_last_busy(swrm->dev);
  1634. pm_runtime_put_autosuspend(swrm->dev);
  1635. swrm_unlock_sleep(swrm);
  1636. exit:
  1637. return ret;
  1638. }
  1639. static void swrm_wakeup_work(struct work_struct *work)
  1640. {
  1641. struct swr_mstr_ctrl *swrm;
  1642. swrm = container_of(work, struct swr_mstr_ctrl,
  1643. wakeup_work);
  1644. if (!swrm || !(swrm->dev)) {
  1645. pr_err("%s: swrm or dev is null\n", __func__);
  1646. return;
  1647. }
  1648. mutex_lock(&swrm->devlock);
  1649. if (!swrm->dev_up) {
  1650. mutex_unlock(&swrm->devlock);
  1651. goto exit;
  1652. }
  1653. mutex_unlock(&swrm->devlock);
  1654. if (unlikely(swrm_lock_sleep(swrm) == false)) {
  1655. dev_err(swrm->dev, "%s Failed to hold suspend\n", __func__);
  1656. goto exit;
  1657. }
  1658. pm_runtime_get_sync(swrm->dev);
  1659. pm_runtime_mark_last_busy(swrm->dev);
  1660. pm_runtime_put_autosuspend(swrm->dev);
  1661. swrm_unlock_sleep(swrm);
  1662. exit:
  1663. pm_relax(swrm->dev);
  1664. }
  1665. static int swrm_get_device_status(struct swr_mstr_ctrl *swrm, u8 devnum)
  1666. {
  1667. u32 val;
  1668. swrm->slave_status = swr_master_read(swrm, SWRM_MCP_SLV_STATUS);
  1669. val = (swrm->slave_status >> (devnum * 2));
  1670. val &= SWRM_MCP_SLV_STATUS_MASK;
  1671. return val;
  1672. }
  1673. static int swrm_get_logical_dev_num(struct swr_master *mstr, u64 dev_id,
  1674. u8 *dev_num)
  1675. {
  1676. int i;
  1677. u64 id = 0;
  1678. int ret = -EINVAL;
  1679. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(mstr);
  1680. struct swr_device *swr_dev;
  1681. u32 num_dev = 0;
  1682. if (!swrm) {
  1683. pr_err("%s: Invalid handle to swr controller\n",
  1684. __func__);
  1685. return ret;
  1686. }
  1687. if (swrm->num_dev)
  1688. num_dev = swrm->num_dev;
  1689. else
  1690. num_dev = mstr->num_dev;
  1691. mutex_lock(&swrm->devlock);
  1692. if (!swrm->dev_up) {
  1693. mutex_unlock(&swrm->devlock);
  1694. return ret;
  1695. }
  1696. mutex_unlock(&swrm->devlock);
  1697. pm_runtime_get_sync(swrm->dev);
  1698. for (i = 1; i < (num_dev + 1); i++) {
  1699. id = ((u64)(swr_master_read(swrm,
  1700. SWRM_ENUMERATOR_SLAVE_DEV_ID_2(i))) << 32);
  1701. id |= swr_master_read(swrm,
  1702. SWRM_ENUMERATOR_SLAVE_DEV_ID_1(i));
  1703. /*
  1704. * As pm_runtime_get_sync() brings all slaves out of reset
  1705. * update logical device number for all slaves.
  1706. */
  1707. list_for_each_entry(swr_dev, &mstr->devices, dev_list) {
  1708. if (swr_dev->addr == (id & SWR_DEV_ID_MASK)) {
  1709. u32 status = swrm_get_device_status(swrm, i);
  1710. if ((status == 0x01) || (status == 0x02)) {
  1711. swr_dev->dev_num = i;
  1712. if ((id & SWR_DEV_ID_MASK) == dev_id) {
  1713. *dev_num = i;
  1714. ret = 0;
  1715. }
  1716. dev_dbg(swrm->dev,
  1717. "%s: devnum %d is assigned for dev addr %lx\n",
  1718. __func__, i, swr_dev->addr);
  1719. }
  1720. }
  1721. }
  1722. }
  1723. if (ret)
  1724. dev_err(swrm->dev, "%s: device 0x%llx is not ready\n",
  1725. __func__, dev_id);
  1726. pm_runtime_mark_last_busy(swrm->dev);
  1727. pm_runtime_put_autosuspend(swrm->dev);
  1728. return ret;
  1729. }
  1730. static void swrm_device_wakeup_vote(struct swr_master *mstr)
  1731. {
  1732. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(mstr);
  1733. if (!swrm) {
  1734. pr_err("%s: Invalid handle to swr controller\n",
  1735. __func__);
  1736. return;
  1737. }
  1738. if (unlikely(swrm_lock_sleep(swrm) == false)) {
  1739. dev_err(swrm->dev, "%s Failed to hold suspend\n", __func__);
  1740. return;
  1741. }
  1742. if (++swrm->hw_core_clk_en == 1)
  1743. if (swrm_request_hw_vote(swrm, LPASS_HW_CORE, true)) {
  1744. dev_err(swrm->dev, "%s:lpass core hw enable failed\n",
  1745. __func__);
  1746. --swrm->hw_core_clk_en;
  1747. }
  1748. if ( ++swrm->aud_core_clk_en == 1)
  1749. if (swrm_request_hw_vote(swrm, LPASS_AUDIO_CORE, true)) {
  1750. dev_err(swrm->dev, "%s:lpass audio hw enable failed\n",
  1751. __func__);
  1752. --swrm->aud_core_clk_en;
  1753. }
  1754. dev_dbg(swrm->dev, "%s: hw_clk_en: %d audio_core_clk_en: %d\n",
  1755. __func__, swrm->hw_core_clk_en, swrm->aud_core_clk_en);
  1756. pm_runtime_get_sync(swrm->dev);
  1757. }
  1758. static void swrm_device_wakeup_unvote(struct swr_master *mstr)
  1759. {
  1760. struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(mstr);
  1761. if (!swrm) {
  1762. pr_err("%s: Invalid handle to swr controller\n",
  1763. __func__);
  1764. return;
  1765. }
  1766. pm_runtime_mark_last_busy(swrm->dev);
  1767. pm_runtime_put_autosuspend(swrm->dev);
  1768. dev_dbg(swrm->dev, "%s: hw_clk_en: %d audio_core_clk_en: %d\n",
  1769. __func__, swrm->hw_core_clk_en, swrm->aud_core_clk_en);
  1770. --swrm->aud_core_clk_en;
  1771. if (swrm->aud_core_clk_en < 0)
  1772. swrm->aud_core_clk_en = 0;
  1773. else if (swrm->aud_core_clk_en == 0)
  1774. swrm_request_hw_vote(swrm, LPASS_AUDIO_CORE, false);
  1775. --swrm->hw_core_clk_en;
  1776. if (swrm->hw_core_clk_en < 0)
  1777. swrm->hw_core_clk_en = 0;
  1778. else if (swrm->hw_core_clk_en == 0)
  1779. swrm_request_hw_vote(swrm, LPASS_HW_CORE, false);
  1780. swrm_unlock_sleep(swrm);
  1781. }
  1782. static int swrm_master_init(struct swr_mstr_ctrl *swrm)
  1783. {
  1784. int ret = 0;
  1785. u32 val;
  1786. u8 row_ctrl = SWR_ROW_50;
  1787. u8 col_ctrl = SWR_MIN_COL;
  1788. u8 ssp_period = 1;
  1789. u8 retry_cmd_num = 3;
  1790. u32 reg[SWRM_MAX_INIT_REG];
  1791. u32 value[SWRM_MAX_INIT_REG];
  1792. u32 temp = 0;
  1793. int len = 0;
  1794. /* Clear Rows and Cols */
  1795. val = ((row_ctrl << SWRM_MCP_FRAME_CTRL_BANK_ROW_CTRL_SHFT) |
  1796. (col_ctrl << SWRM_MCP_FRAME_CTRL_BANK_COL_CTRL_SHFT) |
  1797. (ssp_period << SWRM_MCP_FRAME_CTRL_BANK_SSP_PERIOD_SHFT));
  1798. reg[len] = SWRM_MCP_FRAME_CTRL_BANK_ADDR(0);
  1799. value[len++] = val;
  1800. /* Set Auto enumeration flag */
  1801. reg[len] = SWRM_ENUMERATOR_CFG_ADDR;
  1802. value[len++] = 1;
  1803. /* Configure No pings */
  1804. val = swr_master_read(swrm, SWRM_MCP_CFG_ADDR);
  1805. val &= ~SWRM_MCP_CFG_MAX_NUM_OF_CMD_NO_PINGS_BMSK;
  1806. val |= (0x1f << SWRM_MCP_CFG_MAX_NUM_OF_CMD_NO_PINGS_SHFT);
  1807. reg[len] = SWRM_MCP_CFG_ADDR;
  1808. value[len++] = val;
  1809. /* Configure number of retries of a read/write cmd */
  1810. val = (retry_cmd_num << SWRM_CMD_FIFO_CFG_NUM_OF_CMD_RETRY_SHFT);
  1811. reg[len] = SWRM_CMD_FIFO_CFG_ADDR;
  1812. value[len++] = val;
  1813. reg[len] = SWRM_MCP_BUS_CTRL_ADDR;
  1814. value[len++] = 0x2;
  1815. /* Set IRQ to PULSE */
  1816. reg[len] = SWRM_COMP_CFG_ADDR;
  1817. value[len++] = 0x02;
  1818. reg[len] = SWRM_COMP_CFG_ADDR;
  1819. value[len++] = 0x03;
  1820. reg[len] = SWRM_INTERRUPT_CLEAR;
  1821. value[len++] = 0xFFFFFFFF;
  1822. swrm->intr_mask = SWRM_INTERRUPT_STATUS_MASK;
  1823. /* Mask soundwire interrupts */
  1824. reg[len] = SWRM_INTERRUPT_MASK_ADDR;
  1825. value[len++] = swrm->intr_mask;
  1826. reg[len] = SWR_MSTR_RX_SWRM_CPU_INTERRUPT_EN;
  1827. value[len++] = swrm->intr_mask;
  1828. swr_master_bulk_write(swrm, reg, value, len);
  1829. /*
  1830. * For SWR master version 1.5.1, continue
  1831. * execute on command ignore.
  1832. */
  1833. /* Execute it for versions >= 1.5.1 */
  1834. if (swrm->version >= SWRM_VERSION_1_5_1)
  1835. swr_master_write(swrm, SWRM_CMD_FIFO_CFG_ADDR,
  1836. (swr_master_read(swrm,
  1837. SWRM_CMD_FIFO_CFG_ADDR) | 0x80000000));
  1838. /* SW workaround to gate hw_ctl for SWR version >=1.6 */
  1839. if (swrm->version >= SWRM_VERSION_1_6) {
  1840. if (swrm->swrm_hctl_reg) {
  1841. temp = ioread32(swrm->swrm_hctl_reg);
  1842. temp &= 0xFFFFFFFD;
  1843. iowrite32(temp, swrm->swrm_hctl_reg);
  1844. }
  1845. }
  1846. return ret;
  1847. }
  1848. static int swrm_event_notify(struct notifier_block *self,
  1849. unsigned long action, void *data)
  1850. {
  1851. struct swr_mstr_ctrl *swrm = container_of(self, struct swr_mstr_ctrl,
  1852. event_notifier);
  1853. if (!swrm || !(swrm->dev)) {
  1854. pr_err("%s: swrm or dev is NULL\n", __func__);
  1855. return -EINVAL;
  1856. }
  1857. switch (action) {
  1858. case MSM_AUD_DC_EVENT:
  1859. schedule_work(&(swrm->dc_presence_work));
  1860. break;
  1861. case SWR_WAKE_IRQ_EVENT:
  1862. if (swrm->ipc_wakeup && !swrm->ipc_wakeup_triggered) {
  1863. swrm->ipc_wakeup_triggered = true;
  1864. pm_stay_awake(swrm->dev);
  1865. schedule_work(&swrm->wakeup_work);
  1866. }
  1867. break;
  1868. default:
  1869. dev_err(swrm->dev, "%s: invalid event type: %lu\n",
  1870. __func__, action);
  1871. return -EINVAL;
  1872. }
  1873. return 0;
  1874. }
  1875. static void swrm_notify_work_fn(struct work_struct *work)
  1876. {
  1877. struct swr_mstr_ctrl *swrm = container_of(work, struct swr_mstr_ctrl,
  1878. dc_presence_work);
  1879. if (!swrm || !swrm->pdev) {
  1880. pr_err("%s: swrm or pdev is NULL\n", __func__);
  1881. return;
  1882. }
  1883. swrm_wcd_notify(swrm->pdev, SWR_DEVICE_DOWN, NULL);
  1884. }
  1885. static int swrm_probe(struct platform_device *pdev)
  1886. {
  1887. struct swr_mstr_ctrl *swrm;
  1888. struct swr_ctrl_platform_data *pdata;
  1889. u32 i, num_ports, port_num, port_type, ch_mask, swrm_hctl_reg = 0;
  1890. u32 *temp, map_size, map_length, ch_iter = 0, old_port_num = 0;
  1891. int ret = 0;
  1892. struct clk *lpass_core_hw_vote = NULL;
  1893. struct clk *lpass_core_audio = NULL;
  1894. /* Allocate soundwire master driver structure */
  1895. swrm = devm_kzalloc(&pdev->dev, sizeof(struct swr_mstr_ctrl),
  1896. GFP_KERNEL);
  1897. if (!swrm) {
  1898. ret = -ENOMEM;
  1899. goto err_memory_fail;
  1900. }
  1901. swrm->pdev = pdev;
  1902. swrm->dev = &pdev->dev;
  1903. platform_set_drvdata(pdev, swrm);
  1904. swr_set_ctrl_data(&swrm->master, swrm);
  1905. pdata = dev_get_platdata(&pdev->dev);
  1906. if (!pdata) {
  1907. dev_err(&pdev->dev, "%s: pdata from parent is NULL\n",
  1908. __func__);
  1909. ret = -EINVAL;
  1910. goto err_pdata_fail;
  1911. }
  1912. swrm->handle = (void *)pdata->handle;
  1913. if (!swrm->handle) {
  1914. dev_err(&pdev->dev, "%s: swrm->handle is NULL\n",
  1915. __func__);
  1916. ret = -EINVAL;
  1917. goto err_pdata_fail;
  1918. }
  1919. ret = of_property_read_u32(pdev->dev.of_node, "qcom,swr_master_id",
  1920. &swrm->master_id);
  1921. if (ret) {
  1922. dev_err(&pdev->dev, "%s: failed to get master id\n", __func__);
  1923. goto err_pdata_fail;
  1924. }
  1925. if (!(of_property_read_u32(pdev->dev.of_node,
  1926. "swrm-io-base", &swrm->swrm_base_reg)))
  1927. ret = of_property_read_u32(pdev->dev.of_node,
  1928. "swrm-io-base", &swrm->swrm_base_reg);
  1929. if (!swrm->swrm_base_reg) {
  1930. swrm->read = pdata->read;
  1931. if (!swrm->read) {
  1932. dev_err(&pdev->dev, "%s: swrm->read is NULL\n",
  1933. __func__);
  1934. ret = -EINVAL;
  1935. goto err_pdata_fail;
  1936. }
  1937. swrm->write = pdata->write;
  1938. if (!swrm->write) {
  1939. dev_err(&pdev->dev, "%s: swrm->write is NULL\n",
  1940. __func__);
  1941. ret = -EINVAL;
  1942. goto err_pdata_fail;
  1943. }
  1944. swrm->bulk_write = pdata->bulk_write;
  1945. if (!swrm->bulk_write) {
  1946. dev_err(&pdev->dev, "%s: swrm->bulk_write is NULL\n",
  1947. __func__);
  1948. ret = -EINVAL;
  1949. goto err_pdata_fail;
  1950. }
  1951. } else {
  1952. swrm->swrm_dig_base = devm_ioremap(&pdev->dev,
  1953. swrm->swrm_base_reg, SWRM_MAX_REGISTER);
  1954. }
  1955. swrm->core_vote = pdata->core_vote;
  1956. if (!(of_property_read_u32(pdev->dev.of_node,
  1957. "qcom,swrm-hctl-reg", &swrm_hctl_reg)))
  1958. swrm->swrm_hctl_reg = devm_ioremap(&pdev->dev,
  1959. swrm_hctl_reg, 0x4);
  1960. swrm->clk = pdata->clk;
  1961. if (!swrm->clk) {
  1962. dev_err(&pdev->dev, "%s: swrm->clk is NULL\n",
  1963. __func__);
  1964. ret = -EINVAL;
  1965. goto err_pdata_fail;
  1966. }
  1967. if (of_property_read_u32(pdev->dev.of_node,
  1968. "qcom,swr-clock-stop-mode0",
  1969. &swrm->clk_stop_mode0_supp)) {
  1970. swrm->clk_stop_mode0_supp = FALSE;
  1971. }
  1972. ret = of_property_read_u32(swrm->dev->of_node, "qcom,swr-num-dev",
  1973. &swrm->num_dev);
  1974. if (ret) {
  1975. dev_dbg(&pdev->dev, "%s: Looking up %s property failed\n",
  1976. __func__, "qcom,swr-num-dev");
  1977. } else {
  1978. if (swrm->num_dev > SWR_MAX_SLAVE_DEVICES) {
  1979. dev_err(&pdev->dev, "%s: num_dev %d > max limit %d\n",
  1980. __func__, swrm->num_dev, SWR_MAX_SLAVE_DEVICES);
  1981. ret = -EINVAL;
  1982. goto err_pdata_fail;
  1983. }
  1984. }
  1985. /* Parse soundwire port mapping */
  1986. ret = of_property_read_u32(pdev->dev.of_node, "qcom,swr-num-ports",
  1987. &num_ports);
  1988. if (ret) {
  1989. dev_err(swrm->dev, "%s: Failed to get num_ports\n", __func__);
  1990. goto err_pdata_fail;
  1991. }
  1992. swrm->num_ports = num_ports;
  1993. if (!of_find_property(pdev->dev.of_node, "qcom,swr-port-mapping",
  1994. &map_size)) {
  1995. dev_err(swrm->dev, "missing port mapping\n");
  1996. goto err_pdata_fail;
  1997. }
  1998. map_length = map_size / (3 * sizeof(u32));
  1999. if (num_ports > SWR_MSTR_PORT_LEN) {
  2000. dev_err(&pdev->dev, "%s:invalid number of swr ports\n",
  2001. __func__);
  2002. ret = -EINVAL;
  2003. goto err_pdata_fail;
  2004. }
  2005. temp = devm_kzalloc(&pdev->dev, map_size, GFP_KERNEL);
  2006. if (!temp) {
  2007. ret = -ENOMEM;
  2008. goto err_pdata_fail;
  2009. }
  2010. ret = of_property_read_u32_array(pdev->dev.of_node,
  2011. "qcom,swr-port-mapping", temp, 3 * map_length);
  2012. if (ret) {
  2013. dev_err(swrm->dev, "%s: Failed to read port mapping\n",
  2014. __func__);
  2015. goto err_pdata_fail;
  2016. }
  2017. for (i = 0; i < map_length; i++) {
  2018. port_num = temp[3 * i];
  2019. port_type = temp[3 * i + 1];
  2020. ch_mask = temp[3 * i + 2];
  2021. if (port_num != old_port_num)
  2022. ch_iter = 0;
  2023. swrm->port_mapping[port_num][ch_iter].port_type = port_type;
  2024. swrm->port_mapping[port_num][ch_iter++].ch_mask = ch_mask;
  2025. old_port_num = port_num;
  2026. }
  2027. devm_kfree(&pdev->dev, temp);
  2028. swrm->reg_irq = pdata->reg_irq;
  2029. swrm->master.read = swrm_read;
  2030. swrm->master.write = swrm_write;
  2031. swrm->master.bulk_write = swrm_bulk_write;
  2032. swrm->master.get_logical_dev_num = swrm_get_logical_dev_num;
  2033. swrm->master.connect_port = swrm_connect_port;
  2034. swrm->master.disconnect_port = swrm_disconnect_port;
  2035. swrm->master.slvdev_datapath_control = swrm_slvdev_datapath_control;
  2036. swrm->master.remove_from_group = swrm_remove_from_group;
  2037. swrm->master.device_wakeup_vote = swrm_device_wakeup_vote;
  2038. swrm->master.device_wakeup_unvote = swrm_device_wakeup_unvote;
  2039. swrm->master.dev.parent = &pdev->dev;
  2040. swrm->master.dev.of_node = pdev->dev.of_node;
  2041. swrm->master.num_port = 0;
  2042. swrm->rcmd_id = 0;
  2043. swrm->wcmd_id = 0;
  2044. swrm->slave_status = 0;
  2045. swrm->num_rx_chs = 0;
  2046. swrm->clk_ref_count = 0;
  2047. swrm->swr_irq_wakeup_capable = 0;
  2048. swrm->mclk_freq = MCLK_FREQ;
  2049. swrm->dev_up = true;
  2050. swrm->state = SWR_MSTR_UP;
  2051. swrm->ipc_wakeup = false;
  2052. swrm->ipc_wakeup_triggered = false;
  2053. init_completion(&swrm->reset);
  2054. init_completion(&swrm->broadcast);
  2055. init_completion(&swrm->clk_off_complete);
  2056. mutex_init(&swrm->mlock);
  2057. mutex_init(&swrm->reslock);
  2058. mutex_init(&swrm->force_down_lock);
  2059. mutex_init(&swrm->iolock);
  2060. mutex_init(&swrm->clklock);
  2061. mutex_init(&swrm->devlock);
  2062. mutex_init(&swrm->pm_lock);
  2063. swrm->wlock_holders = 0;
  2064. swrm->pm_state = SWRM_PM_SLEEPABLE;
  2065. init_waitqueue_head(&swrm->pm_wq);
  2066. pm_qos_add_request(&swrm->pm_qos_req,
  2067. PM_QOS_CPU_DMA_LATENCY,
  2068. PM_QOS_DEFAULT_VALUE);
  2069. for (i = 0 ; i < SWR_MSTR_PORT_LEN; i++)
  2070. INIT_LIST_HEAD(&swrm->mport_cfg[i].port_req_list);
  2071. /* Register LPASS core hw vote */
  2072. lpass_core_hw_vote = devm_clk_get(&pdev->dev, "lpass_core_hw_vote");
  2073. if (IS_ERR(lpass_core_hw_vote)) {
  2074. ret = PTR_ERR(lpass_core_hw_vote);
  2075. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  2076. __func__, "lpass_core_hw_vote", ret);
  2077. lpass_core_hw_vote = NULL;
  2078. ret = 0;
  2079. }
  2080. swrm->lpass_core_hw_vote = lpass_core_hw_vote;
  2081. /* Register LPASS audio core vote */
  2082. lpass_core_audio = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  2083. if (IS_ERR(lpass_core_audio)) {
  2084. ret = PTR_ERR(lpass_core_audio);
  2085. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  2086. __func__, "lpass_core_audio", ret);
  2087. lpass_core_audio = NULL;
  2088. ret = 0;
  2089. }
  2090. swrm->lpass_core_audio = lpass_core_audio;
  2091. if (swrm->reg_irq) {
  2092. ret = swrm->reg_irq(swrm->handle, swr_mstr_interrupt, swrm,
  2093. SWR_IRQ_REGISTER);
  2094. if (ret) {
  2095. dev_err(&pdev->dev, "%s: IRQ register failed ret %d\n",
  2096. __func__, ret);
  2097. goto err_irq_fail;
  2098. }
  2099. } else {
  2100. swrm->irq = platform_get_irq_byname(pdev, "swr_master_irq");
  2101. if (swrm->irq < 0) {
  2102. dev_err(swrm->dev, "%s() error getting irq hdle: %d\n",
  2103. __func__, swrm->irq);
  2104. goto err_irq_fail;
  2105. }
  2106. ret = request_threaded_irq(swrm->irq, NULL,
  2107. swr_mstr_interrupt_v2,
  2108. IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  2109. "swr_master_irq", swrm);
  2110. if (ret) {
  2111. dev_err(swrm->dev, "%s: Failed to request irq %d\n",
  2112. __func__, ret);
  2113. goto err_irq_fail;
  2114. }
  2115. }
  2116. /* Make inband tx interrupts as wakeup capable for slave irq */
  2117. ret = of_property_read_u32(pdev->dev.of_node,
  2118. "qcom,swr-mstr-irq-wakeup-capable",
  2119. &swrm->swr_irq_wakeup_capable);
  2120. if (ret)
  2121. dev_dbg(swrm->dev, "%s: swrm irq wakeup capable not defined\n",
  2122. __func__);
  2123. if (swrm->swr_irq_wakeup_capable)
  2124. irq_set_irq_wake(swrm->irq, 1);
  2125. ret = swr_register_master(&swrm->master);
  2126. if (ret) {
  2127. dev_err(&pdev->dev, "%s: error adding swr master\n", __func__);
  2128. goto err_mstr_fail;
  2129. }
  2130. /* Add devices registered with board-info as the
  2131. * controller will be up now
  2132. */
  2133. swr_master_add_boarddevices(&swrm->master);
  2134. mutex_lock(&swrm->mlock);
  2135. swrm_clk_request(swrm, true);
  2136. ret = swrm_master_init(swrm);
  2137. if (ret < 0) {
  2138. dev_err(&pdev->dev,
  2139. "%s: Error in master Initialization , err %d\n",
  2140. __func__, ret);
  2141. mutex_unlock(&swrm->mlock);
  2142. goto err_mstr_fail;
  2143. }
  2144. swrm->version = swr_master_read(swrm, SWRM_COMP_HW_VERSION);
  2145. mutex_unlock(&swrm->mlock);
  2146. INIT_WORK(&swrm->wakeup_work, swrm_wakeup_work);
  2147. if (pdev->dev.of_node)
  2148. of_register_swr_devices(&swrm->master);
  2149. #ifdef CONFIG_DEBUG_FS
  2150. swrm->debugfs_swrm_dent = debugfs_create_dir(dev_name(&pdev->dev), 0);
  2151. if (!IS_ERR(swrm->debugfs_swrm_dent)) {
  2152. swrm->debugfs_peek = debugfs_create_file("swrm_peek",
  2153. S_IFREG | 0444, swrm->debugfs_swrm_dent,
  2154. (void *) swrm, &swrm_debug_read_ops);
  2155. swrm->debugfs_poke = debugfs_create_file("swrm_poke",
  2156. S_IFREG | 0444, swrm->debugfs_swrm_dent,
  2157. (void *) swrm, &swrm_debug_write_ops);
  2158. swrm->debugfs_reg_dump = debugfs_create_file("swrm_reg_dump",
  2159. S_IFREG | 0444, swrm->debugfs_swrm_dent,
  2160. (void *) swrm,
  2161. &swrm_debug_dump_ops);
  2162. }
  2163. #endif
  2164. ret = device_init_wakeup(swrm->dev, true);
  2165. if (ret) {
  2166. dev_err(swrm->dev, "Device wakeup init failed: %d\n", ret);
  2167. goto err_irq_wakeup_fail;
  2168. }
  2169. pm_runtime_set_autosuspend_delay(&pdev->dev, auto_suspend_timer);
  2170. pm_runtime_use_autosuspend(&pdev->dev);
  2171. pm_runtime_set_active(&pdev->dev);
  2172. pm_runtime_enable(&pdev->dev);
  2173. pm_runtime_mark_last_busy(&pdev->dev);
  2174. INIT_WORK(&swrm->dc_presence_work, swrm_notify_work_fn);
  2175. swrm->event_notifier.notifier_call = swrm_event_notify;
  2176. msm_aud_evt_register_client(&swrm->event_notifier);
  2177. return 0;
  2178. err_irq_wakeup_fail:
  2179. device_init_wakeup(swrm->dev, false);
  2180. err_mstr_fail:
  2181. if (swrm->reg_irq)
  2182. swrm->reg_irq(swrm->handle, swr_mstr_interrupt,
  2183. swrm, SWR_IRQ_FREE);
  2184. else if (swrm->irq)
  2185. free_irq(swrm->irq, swrm);
  2186. err_irq_fail:
  2187. mutex_destroy(&swrm->mlock);
  2188. mutex_destroy(&swrm->reslock);
  2189. mutex_destroy(&swrm->force_down_lock);
  2190. mutex_destroy(&swrm->iolock);
  2191. mutex_destroy(&swrm->clklock);
  2192. mutex_destroy(&swrm->pm_lock);
  2193. pm_qos_remove_request(&swrm->pm_qos_req);
  2194. err_pdata_fail:
  2195. err_memory_fail:
  2196. return ret;
  2197. }
  2198. static int swrm_remove(struct platform_device *pdev)
  2199. {
  2200. struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev);
  2201. if (swrm->reg_irq)
  2202. swrm->reg_irq(swrm->handle, swr_mstr_interrupt,
  2203. swrm, SWR_IRQ_FREE);
  2204. else if (swrm->irq)
  2205. free_irq(swrm->irq, swrm);
  2206. else if (swrm->wake_irq > 0)
  2207. free_irq(swrm->wake_irq, swrm);
  2208. if (swrm->swr_irq_wakeup_capable)
  2209. irq_set_irq_wake(swrm->irq, 0);
  2210. cancel_work_sync(&swrm->wakeup_work);
  2211. pm_runtime_disable(&pdev->dev);
  2212. pm_runtime_set_suspended(&pdev->dev);
  2213. swr_unregister_master(&swrm->master);
  2214. msm_aud_evt_unregister_client(&swrm->event_notifier);
  2215. device_init_wakeup(swrm->dev, false);
  2216. mutex_destroy(&swrm->mlock);
  2217. mutex_destroy(&swrm->reslock);
  2218. mutex_destroy(&swrm->iolock);
  2219. mutex_destroy(&swrm->clklock);
  2220. mutex_destroy(&swrm->force_down_lock);
  2221. mutex_destroy(&swrm->pm_lock);
  2222. pm_qos_remove_request(&swrm->pm_qos_req);
  2223. devm_kfree(&pdev->dev, swrm);
  2224. return 0;
  2225. }
  2226. static int swrm_clk_pause(struct swr_mstr_ctrl *swrm)
  2227. {
  2228. u32 val;
  2229. dev_dbg(swrm->dev, "%s: state: %d\n", __func__, swrm->state);
  2230. swr_master_write(swrm, SWRM_INTERRUPT_MASK_ADDR, 0x1FDFD);
  2231. val = swr_master_read(swrm, SWRM_MCP_CFG_ADDR);
  2232. val |= SWRM_MCP_CFG_BUS_CLK_PAUSE_BMSK;
  2233. swr_master_write(swrm, SWRM_MCP_CFG_ADDR, val);
  2234. return 0;
  2235. }
  2236. #ifdef CONFIG_PM
  2237. static int swrm_runtime_resume(struct device *dev)
  2238. {
  2239. struct platform_device *pdev = to_platform_device(dev);
  2240. struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev);
  2241. int ret = 0;
  2242. bool swrm_clk_req_err = false;
  2243. bool hw_core_err = false;
  2244. bool aud_core_err = false;
  2245. struct swr_master *mstr = &swrm->master;
  2246. struct swr_device *swr_dev;
  2247. dev_dbg(dev, "%s: pm_runtime: resume, state:%d\n",
  2248. __func__, swrm->state);
  2249. mutex_lock(&swrm->reslock);
  2250. if (swrm_request_hw_vote(swrm, LPASS_HW_CORE, true)) {
  2251. dev_err(dev, "%s:lpass core hw enable failed\n",
  2252. __func__);
  2253. hw_core_err = true;
  2254. }
  2255. if (swrm_request_hw_vote(swrm, LPASS_AUDIO_CORE, true)) {
  2256. dev_err(dev, "%s:lpass audio hw enable failed\n",
  2257. __func__);
  2258. aud_core_err = true;
  2259. }
  2260. if ((swrm->state == SWR_MSTR_DOWN) ||
  2261. (swrm->state == SWR_MSTR_SSR && swrm->dev_up)) {
  2262. if (swrm->clk_stop_mode0_supp) {
  2263. if (swrm->ipc_wakeup)
  2264. msm_aud_evt_blocking_notifier_call_chain(
  2265. SWR_WAKE_IRQ_DEREGISTER, (void *)swrm);
  2266. }
  2267. if (swrm_clk_request(swrm, true)) {
  2268. /*
  2269. * Set autosuspend timer to 1 for
  2270. * master to enter into suspend.
  2271. */
  2272. swrm_clk_req_err = true;
  2273. goto exit;
  2274. }
  2275. if (!swrm->clk_stop_mode0_supp || swrm->state == SWR_MSTR_SSR) {
  2276. list_for_each_entry(swr_dev, &mstr->devices, dev_list) {
  2277. ret = swr_device_up(swr_dev);
  2278. if (ret == -ENODEV) {
  2279. dev_dbg(dev,
  2280. "%s slave device up not implemented\n",
  2281. __func__);
  2282. ret = 0;
  2283. } else if (ret) {
  2284. dev_err(dev,
  2285. "%s: failed to wakeup swr dev %d\n",
  2286. __func__, swr_dev->dev_num);
  2287. swrm_clk_request(swrm, false);
  2288. goto exit;
  2289. }
  2290. }
  2291. swr_master_write(swrm, SWRM_COMP_SW_RESET, 0x01);
  2292. swr_master_write(swrm, SWRM_COMP_SW_RESET, 0x01);
  2293. swrm_master_init(swrm);
  2294. /* wait for hw enumeration to complete */
  2295. usleep_range(100, 105);
  2296. swrm_cmd_fifo_wr_cmd(swrm, 0x4, 0xF, 0x0,
  2297. SWRS_SCP_INT_STATUS_MASK_1);
  2298. if (swrm->state == SWR_MSTR_SSR) {
  2299. mutex_unlock(&swrm->reslock);
  2300. enable_bank_switch(swrm, 0, SWR_ROW_50, SWR_MIN_COL);
  2301. mutex_lock(&swrm->reslock);
  2302. }
  2303. } else {
  2304. /*wake up from clock stop*/
  2305. swr_master_write(swrm, SWRM_MCP_BUS_CTRL_ADDR, 0x2);
  2306. usleep_range(100, 105);
  2307. }
  2308. swrm->state = SWR_MSTR_UP;
  2309. }
  2310. exit:
  2311. if (!aud_core_err)
  2312. swrm_request_hw_vote(swrm, LPASS_AUDIO_CORE, false);
  2313. if (!hw_core_err)
  2314. swrm_request_hw_vote(swrm, LPASS_HW_CORE, false);
  2315. if (swrm_clk_req_err)
  2316. pm_runtime_set_autosuspend_delay(&pdev->dev,
  2317. ERR_AUTO_SUSPEND_TIMER_VAL);
  2318. else
  2319. pm_runtime_set_autosuspend_delay(&pdev->dev,
  2320. auto_suspend_timer);
  2321. mutex_unlock(&swrm->reslock);
  2322. return ret;
  2323. }
  2324. static int swrm_runtime_suspend(struct device *dev)
  2325. {
  2326. struct platform_device *pdev = to_platform_device(dev);
  2327. struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev);
  2328. int ret = 0;
  2329. bool hw_core_err = false;
  2330. bool aud_core_err = false;
  2331. struct swr_master *mstr = &swrm->master;
  2332. struct swr_device *swr_dev;
  2333. int current_state = 0;
  2334. dev_dbg(dev, "%s: pm_runtime: suspend state: %d\n",
  2335. __func__, swrm->state);
  2336. mutex_lock(&swrm->reslock);
  2337. mutex_lock(&swrm->force_down_lock);
  2338. current_state = swrm->state;
  2339. mutex_unlock(&swrm->force_down_lock);
  2340. if (swrm_request_hw_vote(swrm, LPASS_HW_CORE, true)) {
  2341. dev_err(dev, "%s:lpass core hw enable failed\n",
  2342. __func__);
  2343. hw_core_err = true;
  2344. }
  2345. if (swrm_request_hw_vote(swrm, LPASS_AUDIO_CORE, true)) {
  2346. dev_err(dev, "%s:lpass audio hw enable failed\n",
  2347. __func__);
  2348. aud_core_err = true;
  2349. }
  2350. if ((current_state == SWR_MSTR_UP) ||
  2351. (current_state == SWR_MSTR_SSR)) {
  2352. if ((current_state != SWR_MSTR_SSR) &&
  2353. swrm_is_port_en(&swrm->master)) {
  2354. dev_dbg(dev, "%s ports are enabled\n", __func__);
  2355. ret = -EBUSY;
  2356. goto exit;
  2357. }
  2358. if (!swrm->clk_stop_mode0_supp || swrm->state == SWR_MSTR_SSR) {
  2359. mutex_unlock(&swrm->reslock);
  2360. enable_bank_switch(swrm, 0, SWR_ROW_50, SWR_MIN_COL);
  2361. mutex_lock(&swrm->reslock);
  2362. swrm_clk_pause(swrm);
  2363. swr_master_write(swrm, SWRM_COMP_CFG_ADDR, 0x00);
  2364. list_for_each_entry(swr_dev, &mstr->devices, dev_list) {
  2365. ret = swr_device_down(swr_dev);
  2366. if (ret == -ENODEV) {
  2367. dev_dbg_ratelimited(dev,
  2368. "%s slave device down not implemented\n",
  2369. __func__);
  2370. ret = 0;
  2371. } else if (ret) {
  2372. dev_err(dev,
  2373. "%s: failed to shutdown swr dev %d\n",
  2374. __func__, swr_dev->dev_num);
  2375. goto exit;
  2376. }
  2377. }
  2378. } else {
  2379. mutex_unlock(&swrm->reslock);
  2380. /* clock stop sequence */
  2381. swrm_cmd_fifo_wr_cmd(swrm, 0x2, 0xF, 0xF,
  2382. SWRS_SCP_CONTROL);
  2383. mutex_lock(&swrm->reslock);
  2384. usleep_range(100, 105);
  2385. }
  2386. ret = swrm_clk_request(swrm, false);
  2387. if (ret) {
  2388. dev_err(dev, "%s: swrmn clk failed\n", __func__);
  2389. ret = 0;
  2390. goto exit;
  2391. }
  2392. if (swrm->clk_stop_mode0_supp) {
  2393. if (swrm->wake_irq > 0) {
  2394. enable_irq(swrm->wake_irq);
  2395. } else if (swrm->ipc_wakeup) {
  2396. msm_aud_evt_blocking_notifier_call_chain(
  2397. SWR_WAKE_IRQ_REGISTER, (void *)swrm);
  2398. swrm->ipc_wakeup_triggered = false;
  2399. }
  2400. }
  2401. }
  2402. /* Retain SSR state until resume */
  2403. if (current_state != SWR_MSTR_SSR)
  2404. swrm->state = SWR_MSTR_DOWN;
  2405. exit:
  2406. if (!aud_core_err)
  2407. swrm_request_hw_vote(swrm, LPASS_AUDIO_CORE, false);
  2408. if (!hw_core_err)
  2409. swrm_request_hw_vote(swrm, LPASS_HW_CORE, false);
  2410. mutex_unlock(&swrm->reslock);
  2411. return ret;
  2412. }
  2413. #endif /* CONFIG_PM */
  2414. static int swrm_device_suspend(struct device *dev)
  2415. {
  2416. struct platform_device *pdev = to_platform_device(dev);
  2417. struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev);
  2418. int ret = 0;
  2419. dev_dbg(dev, "%s: swrm state: %d\n", __func__, swrm->state);
  2420. if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) {
  2421. ret = swrm_runtime_suspend(dev);
  2422. if (!ret) {
  2423. pm_runtime_disable(dev);
  2424. pm_runtime_set_suspended(dev);
  2425. pm_runtime_enable(dev);
  2426. }
  2427. }
  2428. return 0;
  2429. }
  2430. static int swrm_device_down(struct device *dev)
  2431. {
  2432. struct platform_device *pdev = to_platform_device(dev);
  2433. struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev);
  2434. dev_dbg(dev, "%s: swrm state: %d\n", __func__, swrm->state);
  2435. mutex_lock(&swrm->force_down_lock);
  2436. swrm->state = SWR_MSTR_SSR;
  2437. mutex_unlock(&swrm->force_down_lock);
  2438. swrm_device_suspend(dev);
  2439. return 0;
  2440. }
  2441. int swrm_register_wake_irq(struct swr_mstr_ctrl *swrm)
  2442. {
  2443. int ret = 0;
  2444. int irq, dir_apps_irq;
  2445. if (!swrm->ipc_wakeup) {
  2446. irq = of_get_named_gpio(swrm->dev->of_node,
  2447. "qcom,swr-wakeup-irq", 0);
  2448. if (gpio_is_valid(irq)) {
  2449. swrm->wake_irq = gpio_to_irq(irq);
  2450. if (swrm->wake_irq < 0) {
  2451. dev_err(swrm->dev,
  2452. "Unable to configure irq\n");
  2453. return swrm->wake_irq;
  2454. }
  2455. } else {
  2456. dir_apps_irq = platform_get_irq_byname(swrm->pdev,
  2457. "swr_wake_irq");
  2458. if (dir_apps_irq < 0) {
  2459. dev_err(swrm->dev,
  2460. "TLMM connect gpio not found\n");
  2461. return -EINVAL;
  2462. }
  2463. swrm->wake_irq = dir_apps_irq;
  2464. }
  2465. ret = request_threaded_irq(swrm->wake_irq, NULL,
  2466. swrm_wakeup_interrupt,
  2467. IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
  2468. "swr_wake_irq", swrm);
  2469. if (ret) {
  2470. dev_err(swrm->dev, "%s: Failed to request irq %d\n",
  2471. __func__, ret);
  2472. return -EINVAL;
  2473. }
  2474. irq_set_irq_wake(swrm->wake_irq, 1);
  2475. }
  2476. return ret;
  2477. }
  2478. static int swrm_alloc_port_mem(struct device *dev, struct swr_mstr_ctrl *swrm,
  2479. u32 uc, u32 size)
  2480. {
  2481. if (!swrm->port_param) {
  2482. swrm->port_param = devm_kzalloc(dev,
  2483. sizeof(swrm->port_param) * SWR_UC_MAX,
  2484. GFP_KERNEL);
  2485. if (!swrm->port_param)
  2486. return -ENOMEM;
  2487. }
  2488. if (!swrm->port_param[uc]) {
  2489. swrm->port_param[uc] = devm_kcalloc(dev, size,
  2490. sizeof(struct port_params),
  2491. GFP_KERNEL);
  2492. if (!swrm->port_param[uc])
  2493. return -ENOMEM;
  2494. } else {
  2495. dev_err_ratelimited(swrm->dev, "%s: called more than once\n",
  2496. __func__);
  2497. }
  2498. return 0;
  2499. }
  2500. static int swrm_copy_port_config(struct swr_mstr_ctrl *swrm,
  2501. struct swrm_port_config *port_cfg,
  2502. u32 size)
  2503. {
  2504. int idx;
  2505. struct port_params *params;
  2506. int uc = port_cfg->uc;
  2507. int ret = 0;
  2508. for (idx = 0; idx < size; idx++) {
  2509. params = &((struct port_params *)port_cfg->params)[idx];
  2510. if (!params) {
  2511. dev_err(swrm->dev, "%s: Invalid params\n", __func__);
  2512. ret = -EINVAL;
  2513. break;
  2514. }
  2515. memcpy(&swrm->port_param[uc][idx], params,
  2516. sizeof(struct port_params));
  2517. }
  2518. return ret;
  2519. }
  2520. /**
  2521. * swrm_wcd_notify - parent device can notify to soundwire master through
  2522. * this function
  2523. * @pdev: pointer to platform device structure
  2524. * @id: command id from parent to the soundwire master
  2525. * @data: data from parent device to soundwire master
  2526. */
  2527. int swrm_wcd_notify(struct platform_device *pdev, u32 id, void *data)
  2528. {
  2529. struct swr_mstr_ctrl *swrm;
  2530. int ret = 0;
  2531. struct swr_master *mstr;
  2532. struct swr_device *swr_dev;
  2533. struct swrm_port_config *port_cfg;
  2534. if (!pdev) {
  2535. pr_err("%s: pdev is NULL\n", __func__);
  2536. return -EINVAL;
  2537. }
  2538. swrm = platform_get_drvdata(pdev);
  2539. if (!swrm) {
  2540. dev_err(&pdev->dev, "%s: swrm is NULL\n", __func__);
  2541. return -EINVAL;
  2542. }
  2543. mstr = &swrm->master;
  2544. switch (id) {
  2545. case SWR_REQ_CLK_SWITCH:
  2546. /* This will put soundwire in clock stop mode and disable the
  2547. * clocks, if there is no active usecase running, so that the
  2548. * next activity on soundwire will request clock from new clock
  2549. * source.
  2550. */
  2551. mutex_lock(&swrm->mlock);
  2552. if (swrm->state == SWR_MSTR_UP)
  2553. swrm_device_suspend(&pdev->dev);
  2554. mutex_unlock(&swrm->mlock);
  2555. break;
  2556. case SWR_CLK_FREQ:
  2557. if (!data) {
  2558. dev_err(swrm->dev, "%s: data is NULL\n", __func__);
  2559. ret = -EINVAL;
  2560. } else {
  2561. mutex_lock(&swrm->mlock);
  2562. if (swrm->mclk_freq != *(int *)data) {
  2563. dev_dbg(swrm->dev, "%s: freq change: force mstr down\n", __func__);
  2564. if (swrm->state == SWR_MSTR_DOWN)
  2565. dev_dbg(swrm->dev, "%s:SWR master is already Down:%d\n",
  2566. __func__, swrm->state);
  2567. else
  2568. swrm_device_suspend(&pdev->dev);
  2569. }
  2570. swrm->mclk_freq = *(int *)data;
  2571. mutex_unlock(&swrm->mlock);
  2572. }
  2573. break;
  2574. case SWR_DEVICE_SSR_DOWN:
  2575. mutex_lock(&swrm->devlock);
  2576. swrm->dev_up = false;
  2577. mutex_unlock(&swrm->devlock);
  2578. mutex_lock(&swrm->reslock);
  2579. swrm->state = SWR_MSTR_SSR;
  2580. mutex_unlock(&swrm->reslock);
  2581. break;
  2582. case SWR_DEVICE_SSR_UP:
  2583. /* wait for clk voting to be zero */
  2584. reinit_completion(&swrm->clk_off_complete);
  2585. if (swrm->clk_ref_count &&
  2586. !wait_for_completion_timeout(&swrm->clk_off_complete,
  2587. msecs_to_jiffies(500)))
  2588. dev_err(swrm->dev, "%s: clock voting not zero\n",
  2589. __func__);
  2590. mutex_lock(&swrm->devlock);
  2591. swrm->dev_up = true;
  2592. mutex_unlock(&swrm->devlock);
  2593. break;
  2594. case SWR_DEVICE_DOWN:
  2595. dev_dbg(swrm->dev, "%s: swr master down called\n", __func__);
  2596. mutex_lock(&swrm->mlock);
  2597. if (swrm->state == SWR_MSTR_DOWN)
  2598. dev_dbg(swrm->dev, "%s:SWR master is already Down:%d\n",
  2599. __func__, swrm->state);
  2600. else
  2601. swrm_device_down(&pdev->dev);
  2602. mutex_unlock(&swrm->mlock);
  2603. break;
  2604. case SWR_DEVICE_UP:
  2605. dev_dbg(swrm->dev, "%s: swr master up called\n", __func__);
  2606. mutex_lock(&swrm->devlock);
  2607. if (!swrm->dev_up) {
  2608. dev_dbg(swrm->dev, "SSR not complete yet\n");
  2609. mutex_unlock(&swrm->devlock);
  2610. return -EBUSY;
  2611. }
  2612. mutex_unlock(&swrm->devlock);
  2613. mutex_lock(&swrm->mlock);
  2614. pm_runtime_mark_last_busy(&pdev->dev);
  2615. pm_runtime_get_sync(&pdev->dev);
  2616. mutex_lock(&swrm->reslock);
  2617. list_for_each_entry(swr_dev, &mstr->devices, dev_list) {
  2618. ret = swr_reset_device(swr_dev);
  2619. if (ret) {
  2620. dev_err(swrm->dev,
  2621. "%s: failed to reset swr device %d\n",
  2622. __func__, swr_dev->dev_num);
  2623. swrm_clk_request(swrm, false);
  2624. }
  2625. }
  2626. pm_runtime_mark_last_busy(&pdev->dev);
  2627. pm_runtime_put_autosuspend(&pdev->dev);
  2628. mutex_unlock(&swrm->reslock);
  2629. mutex_unlock(&swrm->mlock);
  2630. break;
  2631. case SWR_SET_NUM_RX_CH:
  2632. if (!data) {
  2633. dev_err(swrm->dev, "%s: data is NULL\n", __func__);
  2634. ret = -EINVAL;
  2635. } else {
  2636. mutex_lock(&swrm->mlock);
  2637. swrm->num_rx_chs = *(int *)data;
  2638. if ((swrm->num_rx_chs > 1) && !swrm->num_cfg_devs) {
  2639. list_for_each_entry(swr_dev, &mstr->devices,
  2640. dev_list) {
  2641. ret = swr_set_device_group(swr_dev,
  2642. SWR_BROADCAST);
  2643. if (ret)
  2644. dev_err(swrm->dev,
  2645. "%s: set num ch failed\n",
  2646. __func__);
  2647. }
  2648. } else {
  2649. list_for_each_entry(swr_dev, &mstr->devices,
  2650. dev_list) {
  2651. ret = swr_set_device_group(swr_dev,
  2652. SWR_GROUP_NONE);
  2653. if (ret)
  2654. dev_err(swrm->dev,
  2655. "%s: set num ch failed\n",
  2656. __func__);
  2657. }
  2658. }
  2659. mutex_unlock(&swrm->mlock);
  2660. }
  2661. break;
  2662. case SWR_REGISTER_WAKE_IRQ:
  2663. if (!data) {
  2664. dev_err(swrm->dev, "%s: reg wake irq data is NULL\n",
  2665. __func__);
  2666. ret = -EINVAL;
  2667. } else {
  2668. mutex_lock(&swrm->mlock);
  2669. swrm->ipc_wakeup = *(u32 *)data;
  2670. ret = swrm_register_wake_irq(swrm);
  2671. if (ret)
  2672. dev_err(swrm->dev, "%s: register wake_irq failed\n",
  2673. __func__);
  2674. mutex_unlock(&swrm->mlock);
  2675. }
  2676. break;
  2677. case SWR_REGISTER_WAKEUP:
  2678. msm_aud_evt_blocking_notifier_call_chain(
  2679. SWR_WAKE_IRQ_REGISTER, (void *)swrm);
  2680. break;
  2681. case SWR_DEREGISTER_WAKEUP:
  2682. msm_aud_evt_blocking_notifier_call_chain(
  2683. SWR_WAKE_IRQ_DEREGISTER, (void *)swrm);
  2684. break;
  2685. case SWR_SET_PORT_MAP:
  2686. if (!data) {
  2687. dev_err(swrm->dev, "%s: data is NULL for id=%d\n",
  2688. __func__, id);
  2689. ret = -EINVAL;
  2690. } else {
  2691. mutex_lock(&swrm->mlock);
  2692. port_cfg = (struct swrm_port_config *)data;
  2693. if (!port_cfg->size) {
  2694. ret = -EINVAL;
  2695. goto done;
  2696. }
  2697. ret = swrm_alloc_port_mem(&pdev->dev, swrm,
  2698. port_cfg->uc, port_cfg->size);
  2699. if (!ret)
  2700. swrm_copy_port_config(swrm, port_cfg,
  2701. port_cfg->size);
  2702. done:
  2703. mutex_unlock(&swrm->mlock);
  2704. }
  2705. break;
  2706. default:
  2707. dev_err(swrm->dev, "%s: swr master unknown id %d\n",
  2708. __func__, id);
  2709. break;
  2710. }
  2711. return ret;
  2712. }
  2713. EXPORT_SYMBOL(swrm_wcd_notify);
  2714. /*
  2715. * swrm_pm_cmpxchg:
  2716. * Check old state and exchange with pm new state
  2717. * if old state matches with current state
  2718. *
  2719. * @swrm: pointer to wcd core resource
  2720. * @o: pm old state
  2721. * @n: pm new state
  2722. *
  2723. * Returns old state
  2724. */
  2725. static enum swrm_pm_state swrm_pm_cmpxchg(
  2726. struct swr_mstr_ctrl *swrm,
  2727. enum swrm_pm_state o,
  2728. enum swrm_pm_state n)
  2729. {
  2730. enum swrm_pm_state old;
  2731. if (!swrm)
  2732. return o;
  2733. mutex_lock(&swrm->pm_lock);
  2734. old = swrm->pm_state;
  2735. if (old == o)
  2736. swrm->pm_state = n;
  2737. mutex_unlock(&swrm->pm_lock);
  2738. return old;
  2739. }
  2740. static bool swrm_lock_sleep(struct swr_mstr_ctrl *swrm)
  2741. {
  2742. enum swrm_pm_state os;
  2743. /*
  2744. * swrm_{lock/unlock}_sleep will be called by swr irq handler
  2745. * and slave wake up requests..
  2746. *
  2747. * If system didn't resume, we can simply return false so
  2748. * IRQ handler can return without handling IRQ.
  2749. */
  2750. mutex_lock(&swrm->pm_lock);
  2751. if (swrm->wlock_holders++ == 0) {
  2752. dev_dbg(swrm->dev, "%s: holding wake lock\n", __func__);
  2753. pm_qos_update_request(&swrm->pm_qos_req,
  2754. msm_cpuidle_get_deep_idle_latency());
  2755. pm_stay_awake(swrm->dev);
  2756. }
  2757. mutex_unlock(&swrm->pm_lock);
  2758. if (!wait_event_timeout(swrm->pm_wq,
  2759. ((os = swrm_pm_cmpxchg(swrm,
  2760. SWRM_PM_SLEEPABLE,
  2761. SWRM_PM_AWAKE)) ==
  2762. SWRM_PM_SLEEPABLE ||
  2763. (os == SWRM_PM_AWAKE)),
  2764. msecs_to_jiffies(
  2765. SWRM_SYSTEM_RESUME_TIMEOUT_MS))) {
  2766. dev_err(swrm->dev, "%s: system didn't resume within %dms, s %d, w %d\n",
  2767. __func__, SWRM_SYSTEM_RESUME_TIMEOUT_MS, swrm->pm_state,
  2768. swrm->wlock_holders);
  2769. swrm_unlock_sleep(swrm);
  2770. return false;
  2771. }
  2772. wake_up_all(&swrm->pm_wq);
  2773. return true;
  2774. }
  2775. static void swrm_unlock_sleep(struct swr_mstr_ctrl *swrm)
  2776. {
  2777. mutex_lock(&swrm->pm_lock);
  2778. if (--swrm->wlock_holders == 0) {
  2779. dev_dbg(swrm->dev, "%s: releasing wake lock pm_state %d -> %d\n",
  2780. __func__, swrm->pm_state, SWRM_PM_SLEEPABLE);
  2781. /*
  2782. * if swrm_lock_sleep failed, pm_state would be still
  2783. * swrm_PM_ASLEEP, don't overwrite
  2784. */
  2785. if (likely(swrm->pm_state == SWRM_PM_AWAKE))
  2786. swrm->pm_state = SWRM_PM_SLEEPABLE;
  2787. pm_qos_update_request(&swrm->pm_qos_req,
  2788. PM_QOS_DEFAULT_VALUE);
  2789. pm_relax(swrm->dev);
  2790. }
  2791. mutex_unlock(&swrm->pm_lock);
  2792. wake_up_all(&swrm->pm_wq);
  2793. }
  2794. #ifdef CONFIG_PM_SLEEP
  2795. static int swrm_suspend(struct device *dev)
  2796. {
  2797. int ret = -EBUSY;
  2798. struct platform_device *pdev = to_platform_device(dev);
  2799. struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev);
  2800. dev_dbg(dev, "%s: system suspend, state: %d\n", __func__, swrm->state);
  2801. mutex_lock(&swrm->pm_lock);
  2802. if (swrm->pm_state == SWRM_PM_SLEEPABLE) {
  2803. dev_dbg(swrm->dev, "%s: suspending system, state %d, wlock %d\n",
  2804. __func__, swrm->pm_state,
  2805. swrm->wlock_holders);
  2806. swrm->pm_state = SWRM_PM_ASLEEP;
  2807. } else if (swrm->pm_state == SWRM_PM_AWAKE) {
  2808. /*
  2809. * unlock to wait for pm_state == SWRM_PM_SLEEPABLE
  2810. * then set to SWRM_PM_ASLEEP
  2811. */
  2812. dev_dbg(swrm->dev, "%s: waiting to suspend system, state %d, wlock %d\n",
  2813. __func__, swrm->pm_state,
  2814. swrm->wlock_holders);
  2815. mutex_unlock(&swrm->pm_lock);
  2816. if (!(wait_event_timeout(swrm->pm_wq, swrm_pm_cmpxchg(
  2817. swrm, SWRM_PM_SLEEPABLE,
  2818. SWRM_PM_ASLEEP) ==
  2819. SWRM_PM_SLEEPABLE,
  2820. msecs_to_jiffies(
  2821. SWRM_SYS_SUSPEND_WAIT)))) {
  2822. dev_dbg(swrm->dev, "%s: suspend failed state %d, wlock %d\n",
  2823. __func__, swrm->pm_state,
  2824. swrm->wlock_holders);
  2825. return -EBUSY;
  2826. } else {
  2827. dev_dbg(swrm->dev,
  2828. "%s: done, state %d, wlock %d\n",
  2829. __func__, swrm->pm_state,
  2830. swrm->wlock_holders);
  2831. }
  2832. mutex_lock(&swrm->pm_lock);
  2833. } else if (swrm->pm_state == SWRM_PM_ASLEEP) {
  2834. dev_dbg(swrm->dev, "%s: system is already suspended, state %d, wlock %d\n",
  2835. __func__, swrm->pm_state,
  2836. swrm->wlock_holders);
  2837. }
  2838. mutex_unlock(&swrm->pm_lock);
  2839. if ((!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev))) {
  2840. ret = swrm_runtime_suspend(dev);
  2841. if (!ret) {
  2842. /*
  2843. * Synchronize runtime-pm and system-pm states:
  2844. * At this point, we are already suspended. If
  2845. * runtime-pm still thinks its active, then
  2846. * make sure its status is in sync with HW
  2847. * status. The three below calls let the
  2848. * runtime-pm know that we are suspended
  2849. * already without re-invoking the suspend
  2850. * callback
  2851. */
  2852. pm_runtime_disable(dev);
  2853. pm_runtime_set_suspended(dev);
  2854. pm_runtime_enable(dev);
  2855. }
  2856. }
  2857. if (ret == -EBUSY) {
  2858. /*
  2859. * There is a possibility that some audio stream is active
  2860. * during suspend. We dont want to return suspend failure in
  2861. * that case so that display and relevant components can still
  2862. * go to suspend.
  2863. * If there is some other error, then it should be passed-on
  2864. * to system level suspend
  2865. */
  2866. ret = 0;
  2867. }
  2868. return ret;
  2869. }
  2870. static int swrm_resume(struct device *dev)
  2871. {
  2872. int ret = 0;
  2873. struct platform_device *pdev = to_platform_device(dev);
  2874. struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev);
  2875. dev_dbg(dev, "%s: system resume, state: %d\n", __func__, swrm->state);
  2876. if (!pm_runtime_enabled(dev) || !pm_runtime_suspend(dev)) {
  2877. ret = swrm_runtime_resume(dev);
  2878. if (!ret) {
  2879. pm_runtime_mark_last_busy(dev);
  2880. pm_request_autosuspend(dev);
  2881. }
  2882. }
  2883. mutex_lock(&swrm->pm_lock);
  2884. if (swrm->pm_state == SWRM_PM_ASLEEP) {
  2885. dev_dbg(swrm->dev,
  2886. "%s: resuming system, state %d, wlock %d\n",
  2887. __func__, swrm->pm_state,
  2888. swrm->wlock_holders);
  2889. swrm->pm_state = SWRM_PM_SLEEPABLE;
  2890. } else {
  2891. dev_dbg(swrm->dev, "%s: system is already awake, state %d wlock %d\n",
  2892. __func__, swrm->pm_state,
  2893. swrm->wlock_holders);
  2894. }
  2895. mutex_unlock(&swrm->pm_lock);
  2896. wake_up_all(&swrm->pm_wq);
  2897. return ret;
  2898. }
  2899. #endif /* CONFIG_PM_SLEEP */
  2900. static const struct dev_pm_ops swrm_dev_pm_ops = {
  2901. SET_SYSTEM_SLEEP_PM_OPS(
  2902. swrm_suspend,
  2903. swrm_resume
  2904. )
  2905. SET_RUNTIME_PM_OPS(
  2906. swrm_runtime_suspend,
  2907. swrm_runtime_resume,
  2908. NULL
  2909. )
  2910. };
  2911. static const struct of_device_id swrm_dt_match[] = {
  2912. {
  2913. .compatible = "qcom,swr-mstr",
  2914. },
  2915. {}
  2916. };
  2917. static struct platform_driver swr_mstr_driver = {
  2918. .probe = swrm_probe,
  2919. .remove = swrm_remove,
  2920. .driver = {
  2921. .name = SWR_WCD_NAME,
  2922. .owner = THIS_MODULE,
  2923. .pm = &swrm_dev_pm_ops,
  2924. .of_match_table = swrm_dt_match,
  2925. .suppress_bind_attrs = true,
  2926. },
  2927. };
  2928. static int __init swrm_init(void)
  2929. {
  2930. return platform_driver_register(&swr_mstr_driver);
  2931. }
  2932. module_init(swrm_init);
  2933. static void __exit swrm_exit(void)
  2934. {
  2935. platform_driver_unregister(&swr_mstr_driver);
  2936. }
  2937. module_exit(swrm_exit);
  2938. MODULE_LICENSE("GPL v2");
  2939. MODULE_DESCRIPTION("SoundWire Master Controller");
  2940. MODULE_ALIAS("platform:swr-mstr");