mhl_linux_tx.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075
  1. /*
  2. SiI8348 Linux Driver
  3. Copyright (C) 2013 Silicon Image, Inc.
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation version 2.
  7. This program is distributed AS-IS WITHOUT ANY WARRANTY of any
  8. kind, whether express or implied; INCLUDING without the implied warranty
  9. of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE or NON-INFRINGEMENT. See
  10. the GNU General Public License for more details at http://www.gnu.org/licenses/gpl-2.0.html.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/slab.h>
  15. #include <linux/hrtimer.h>
  16. #include <linux/fs.h>
  17. #include <linux/semaphore.h>
  18. #include <linux/i2c.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/cdev.h>
  21. #include <linux/stringify.h>
  22. #include <asm/uaccess.h>
  23. #include "sii_hal.h"
  24. #include "si_fw_macros.h"
  25. #include "si_mhl_defs.h"
  26. #include "si_infoframe.h"
  27. #include "si_edid.h"
  28. #include "si_mhl2_edid_3d_api.h"
  29. #include "si_mhl_tx_hw_drv_api.h"
  30. #ifdef MEDIA_DATA_TUNNEL_SUPPORT
  31. #include "si_mdt_inputdev.h"
  32. #endif
  33. #ifdef RCP_INPUTDEV_SUPPORT
  34. #include "mhl_rcp_inputdev.h"
  35. #endif
  36. #include "mhl_linux_tx.h"
  37. #include "mhl_supp.h"
  38. #include "platform.h"
  39. #include <linux/kthread.h>
  40. #include <mach/irqs.h>
  41. /*#include "mach/eint.h"*/
  42. /*#include <mach/mt_gpio.h>*/
  43. #include "hdmi_drv.h"
  44. #include "smartbook.h"
  45. #define MHL_DRIVER_MINOR_MAX 1
  46. wait_queue_head_t mhl_irq_wq;
  47. static struct task_struct *mhl_irq_task = NULL;
  48. atomic_t mhl_irq_event = ATOMIC_INIT(0);
  49. /************************** MHL TX User Layer To HAL****************************************/
  50. #ifdef CONFIG_MTK_SMARTBOOK_SUPPORT
  51. extern int smartbook_kthread(void *data);
  52. extern wait_queue_head_t smartbook_wq;
  53. static struct task_struct *smartbook_task = NULL;
  54. #endif
  55. /************************** ****************************************************/
  56. struct mhl_dev_context *si_dev_context;
  57. static char *white_space = "' ', '\t'";
  58. static dev_t dev_num;
  59. static struct class *mhl_class;
  60. static void mhl_tx_destroy_timer_support(struct mhl_dev_context *dev_context);
  61. /* Define SysFs attribute names */
  62. #define SYS_ATTR_NAME_CONN connection_state
  63. #define SYS_ATTR_NAME_RCP rcp_keycode
  64. #define SYS_ATTR_NAME_RCPK rcp_ack
  65. #define SYS_ATTR_NAME_RAP rap
  66. #define SYS_ATTR_NAME_RAP_STATUS rap_status
  67. #define SYS_ATTR_NAME_DEVCAP devcap
  68. #define SYS_ATTR_NAME_UCP ucp_keycode
  69. #define SYS_ATTR_NAME_UCPK ucp_ack
  70. #define SYS_ATTR_NAME_SPAD spad
  71. #define SYS_ATTR_NAME_DEBUG debug
  72. #define SYS_ATTR_NAME_TRACE_LEVEL trace_level
  73. /*
  74. * show_connection_state() - Handle read request to the connection_state
  75. * attribute file.
  76. */
  77. ssize_t show_connection_state(struct device *dev, struct device_attribute *attr, char *buf)
  78. {
  79. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  80. if (dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED) {
  81. return scnprintf(buf, PAGE_SIZE, "connected");
  82. } else {
  83. return scnprintf(buf, PAGE_SIZE, "not connected");
  84. }
  85. }
  86. #ifndef RCP_INPUTDEV_SUPPORT
  87. /*
  88. * show_rcp() - Handle read request to the rcp_keycode attribute file.
  89. */
  90. ssize_t show_rcp(struct device *dev, struct device_attribute *attr, char *buf)
  91. {
  92. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  93. int status = 0;
  94. if (down_interruptible(&dev_context->isr_lock))
  95. return -ERESTARTSYS;
  96. if (dev_context->mhl_flags &
  97. (MHL_STATE_FLAG_RCP_SENT | MHL_STATE_FLAG_RCP_RECEIVED)) {
  98. status = scnprintf(buf, PAGE_SIZE, "0x%02x %s",
  99. dev_context->rcp_key_code,
  100. dev_context->mhl_flags & MHL_STATE_FLAG_RCP_SENT? "sent" : "received");
  101. }
  102. up(&dev_context->isr_lock);
  103. return status;
  104. }
  105. /*
  106. * send_rcp() - Handle write request to the rcp_keycode attribute file.
  107. */
  108. ssize_t send_rcp(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  109. {
  110. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  111. unsigned long key_code;
  112. int status = -EINVAL;
  113. MHL_TX_DBG_INFO(dev_context, "send_rcp received string: ""%s""\n", buf);
  114. if (down_interruptible(&dev_context->isr_lock))
  115. return -ERESTARTSYS;
  116. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  117. status = -ENODEV;
  118. goto err_exit;
  119. }
  120. if (!(dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED))
  121. goto err_exit;
  122. if (kstrtoul(buf, 0, &key_code)) {
  123. MHL_TX_DBG_ERR(dev_context, "Unable to convert key code string\n");
  124. goto err_exit;
  125. }
  126. if (key_code >= 0xFE) {
  127. MHL_TX_DBG_ERR(dev_context, "key code (0x%lx) is too large to be valid\n", key_code);
  128. goto err_exit;
  129. }
  130. dev_context->mhl_flags &= ~(MHL_STATE_FLAG_RCP_RECEIVED |
  131. MHL_STATE_FLAG_RCP_ACK |
  132. MHL_STATE_FLAG_RCP_NAK);
  133. dev_context->mhl_flags |= MHL_STATE_FLAG_RCP_SENT;
  134. dev_context->rcp_send_status = 0;
  135. dev_context->rcp_key_code = (u8)key_code;
  136. if (!si_mhl_tx_rcp_send(dev_context, (u8)key_code))
  137. goto err_exit;
  138. status = count;
  139. err_exit:
  140. up(&dev_context->isr_lock);
  141. return status;
  142. }
  143. /*
  144. * send_rcp_ack() - Handle write request to the rcp_ack attribute file.
  145. *
  146. * This file is used to send either an ACK or NAK for a received
  147. * Remote Control Protocol (RCP) key code.
  148. *
  149. * The format of the string in buf must be:
  150. * "keycode=<keyvalue> errorcode=<errorvalue>
  151. * where: <keyvalue> is replaced with value of the RCP to be ACK'd or NAK'd
  152. * <errorvalue> 0 if the RCP key code is to be ACK'd
  153. * non-zero error code if the RCP key code is to be NAK'd
  154. */
  155. ssize_t send_rcp_ack(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  156. {
  157. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  158. unsigned long key_code = 0x100; /* initialize with invalid values */
  159. unsigned long err_code = 0x100;
  160. char *pStr;
  161. int status = -EINVAL;
  162. MHL_TX_DBG_INFO(dev_context, "received string: %s\n", buf);
  163. /* Parse the input string and extract the RCP key code and error code */
  164. pStr = strstr(buf, "keycode=");
  165. if (pStr != NULL) {
  166. key_code = simple_strtoul(pStr + 8, NULL, 0);
  167. if (key_code > 0xFF) {
  168. MHL_TX_DBG_ERR(dev_context, "Unable to convert keycode string\n");
  169. goto err_exit_2;
  170. }
  171. } else {
  172. MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""keycode"" value\n");
  173. goto err_exit_2;
  174. }
  175. pStr = strstr(buf, "errorcode=");
  176. if (pStr != NULL) {
  177. if(kstrtoul(pStr + 10, 0, &err_code)) {
  178. MHL_TX_DBG_ERR(dev_context, "Unable to convert errorcode string\n");
  179. goto err_exit_2;
  180. }
  181. } else {
  182. MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""errorcode"" value\n");
  183. goto err_exit_2;
  184. }
  185. if ((key_code > 0xFF) || (err_code > 0xFF)) {
  186. MHL_TX_DBG_ERR(dev_context, "Invalid key code or error code "\
  187. "specified, key code: 0x%02lx error code: 0x%02lx\n",
  188. key_code, err_code);
  189. goto err_exit_2;
  190. }
  191. if (down_interruptible(&dev_context->isr_lock))
  192. return -ERESTARTSYS;
  193. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  194. status = -ENODEV;
  195. goto err_exit_1;
  196. }
  197. if (dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED) {
  198. if((key_code != dev_context->rcp_key_code)
  199. || !(dev_context->mhl_flags & MHL_STATE_FLAG_RCP_RECEIVED)) {
  200. MHL_TX_DBG_ERR(dev_context, "Attempting to ACK a key code "\
  201. "that was not received! try:0x%02x(%d)\n"
  202. ,dev_context->rcp_key_code
  203. ,dev_context->rcp_key_code);
  204. goto err_exit_1;
  205. }
  206. if (err_code == 0) {
  207. if (!si_mhl_tx_rcpk_send(dev_context, (u8)key_code)) {
  208. status = -ENOMEM;
  209. goto err_exit_1;
  210. }
  211. } else {
  212. if (!si_mhl_tx_rcpe_send(dev_context, (u8)err_code))
  213. goto err_exit_1;
  214. }
  215. status = count;
  216. }
  217. err_exit_1:
  218. up(&dev_context->isr_lock);
  219. err_exit_2:
  220. return status;
  221. }
  222. /*
  223. * show_rcp_ack() - Handle read request to the rcp_ack attribute file.
  224. *
  225. * Reads from this file return a string detailing the last RCP
  226. * ACK or NAK received by the driver.
  227. *
  228. * The format of the string returned in buf is:
  229. * "keycode=<keyvalue> errorcode=<errorvalue>
  230. * where: <keyvalue> is replaced with value of the RCP key code for which
  231. * an ACK or NAK has been received.
  232. * <errorvalue> 0 if the last RCP key code was ACK'd or
  233. * non-zero error code if the RCP key code was NAK'd
  234. */
  235. ssize_t show_rcp_ack(struct device *dev, struct device_attribute *attr, char *buf)
  236. {
  237. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  238. int status = -EINVAL;
  239. MHL_TX_DBG_INFO(dev_context, "called\n");
  240. if (down_interruptible(&dev_context->isr_lock))
  241. return -ERESTARTSYS;
  242. if (dev_context->mhl_flags & (MHL_STATE_FLAG_RCP_ACK | MHL_STATE_FLAG_RCP_NAK)) {
  243. status = scnprintf(buf, PAGE_SIZE, "keycode=0x%02x errorcode=0x%02x",
  244. dev_context->rcp_key_code, dev_context->rcp_err_code);
  245. }
  246. up(&dev_context->isr_lock);
  247. return status;
  248. }
  249. #endif /* #ifndef RCP_INPUTDEV_SUPPORT */
  250. /*
  251. * show_ucp() - Handle read request to the ucp_keycode attribute file.
  252. */
  253. ssize_t show_ucp(struct device *dev, struct device_attribute *attr, char *buf)
  254. {
  255. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  256. int status = 0;
  257. MHL_TX_DBG_INFO(dev_context, "called keycode:0x%02x\n",dev_context->ucp_key_code);
  258. if (down_interruptible(&dev_context->isr_lock))
  259. return -ERESTARTSYS;
  260. if (dev_context->mhl_flags &
  261. (MHL_STATE_FLAG_UCP_SENT | MHL_STATE_FLAG_UCP_RECEIVED)) {
  262. status = scnprintf(buf, PAGE_SIZE, "0x%02x %s",
  263. dev_context->ucp_key_code,
  264. dev_context->mhl_flags & MHL_STATE_FLAG_UCP_SENT? "sent" : "received");
  265. }
  266. up(&dev_context->isr_lock);
  267. return status;
  268. }
  269. /*
  270. * send_ucp() - Handle write request to the ucp_keycode attribute file.
  271. */
  272. ssize_t send_ucp(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  273. {
  274. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  275. unsigned long key_code;
  276. int status = -EINVAL;
  277. MHL_TX_DBG_INFO(dev_context, "received string: ""%s""\n", buf);
  278. if (down_interruptible(&dev_context->isr_lock))
  279. return -ERESTARTSYS;
  280. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  281. status = -ENODEV;
  282. goto err_exit;
  283. }
  284. if (!(dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED))
  285. goto err_exit;
  286. if (kstrtoul(buf, 0, &key_code)) {
  287. MHL_TX_DBG_ERR(dev_context, "Unable to convert key code string\n");
  288. goto err_exit;
  289. }
  290. if (key_code > 0xFF) {
  291. MHL_TX_DBG_ERR(dev_context, "ucp key code (0x%lx) is too large to be valid\n", key_code);
  292. goto err_exit;
  293. }
  294. dev_context->mhl_flags &= ~(MHL_STATE_FLAG_UCP_RECEIVED |
  295. MHL_STATE_FLAG_UCP_ACK |
  296. MHL_STATE_FLAG_UCP_NAK);
  297. dev_context->mhl_flags |= MHL_STATE_FLAG_UCP_SENT;
  298. dev_context->ucp_key_code = (u8)key_code;
  299. if (!si_mhl_tx_ucp_send(dev_context, (u8)key_code))
  300. goto err_exit;
  301. status = count;
  302. err_exit:
  303. up(&dev_context->isr_lock);
  304. return status;
  305. }
  306. /*
  307. * send_ucp_ack() - Handle write request to the ucp_ack attribute file.
  308. *
  309. * This file is used to send either an ACK or NAK for a received
  310. * UTF-8 Control Protocol (UCP) key code.
  311. *
  312. * The format of the string in buf must be:
  313. * "keycode=<keyvalue> errorcode=<errorvalue>
  314. * where: <keyvalue> is replaced with value of the UCP to be ACK'd or NAK'd
  315. * <errorvalue> 0 if the UCP key code is to be ACK'd
  316. * non-zero error code if the UCP key code is to be NAK'd
  317. */
  318. ssize_t send_ucp_ack(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  319. {
  320. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  321. unsigned long key_code = 0x100; /* initialize with invalid values */
  322. unsigned long err_code = 0x100;
  323. char *pStr;
  324. int status = -EINVAL;
  325. MHL_TX_DBG_INFO(dev_context, "received string: %s\n", buf);
  326. /* Parse the input string and extract the UCP key code and error code */
  327. pStr = strstr(buf, "keycode=");
  328. if (pStr != NULL) {
  329. key_code = simple_strtoul(pStr + 8, NULL, 0);
  330. if (key_code > 0xFF) {
  331. MHL_TX_DBG_ERR(dev_context, "Unable to convert keycode string\n");
  332. goto err_exit_2;
  333. }
  334. } else {
  335. MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""keycode"" value\n");
  336. goto err_exit_2;
  337. }
  338. pStr = strstr(buf, "errorcode=");
  339. if (pStr != NULL) {
  340. if(kstrtoul(pStr + 10, 0, &err_code)) {
  341. MHL_TX_DBG_ERR(dev_context, "Unable to convert errorcode string\n");
  342. goto err_exit_2;
  343. }
  344. } else {
  345. MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""errorcode"" value\n");
  346. goto err_exit_2;
  347. }
  348. if ((key_code > 0xFF) || (err_code > 0xFF)) {
  349. MHL_TX_DBG_ERR(dev_context, "Invalid key code or error code "\
  350. "specified, key code: 0x%02lx error code: 0x%02lx\n",
  351. key_code, err_code);
  352. goto err_exit_2;
  353. }
  354. if (down_interruptible(&dev_context->isr_lock))
  355. return -ERESTARTSYS;
  356. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  357. status = -ENODEV;
  358. goto err_exit_1;
  359. }
  360. if (dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED) {
  361. if((key_code != dev_context->ucp_key_code)
  362. || !(dev_context->mhl_flags & MHL_STATE_FLAG_UCP_RECEIVED)) {
  363. MHL_TX_DBG_ERR(dev_context, "Attempting to ACK a key code that was not received!\n");
  364. goto err_exit_1;
  365. }
  366. if (err_code == 0) {
  367. if (!si_mhl_tx_ucpk_send(dev_context, (u8)key_code)) {
  368. status = -ENOMEM;
  369. goto err_exit_1;
  370. }
  371. } else {
  372. if (!si_mhl_tx_ucpe_send(dev_context, (u8)err_code)) {
  373. status = -ENOMEM;
  374. goto err_exit_1;
  375. }
  376. }
  377. status = count;
  378. }
  379. err_exit_1:
  380. up(&dev_context->isr_lock);
  381. err_exit_2:
  382. return status;
  383. }
  384. /*
  385. * show_ucp_ack() - Handle read request to the ucp_ack attribute file.
  386. *
  387. * Reads from this file return a string detailing the last UCP
  388. * ACK or NAK received by the driver.
  389. *
  390. * The format of the string returned in buf is:
  391. * "keycode=<keyvalue> errorcode=<errorvalue>
  392. * where: <keyvalue> is replaced with value of the UCP key code for which
  393. * an ACK or NAK has been received.
  394. * <errorvalue> 0 if the last UCP key code was ACK'd or
  395. * non-zero error code if the UCP key code was NAK'd
  396. */
  397. ssize_t show_ucp_ack(struct device *dev, struct device_attribute *attr,
  398. char *buf)
  399. {
  400. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  401. int status = -EINVAL;
  402. MHL_TX_DBG_INFO(dev_context, "called\n");
  403. if (down_interruptible(&dev_context->isr_lock))
  404. return -ERESTARTSYS;
  405. if (dev_context->mhl_flags & (MHL_STATE_FLAG_UCP_ACK | MHL_STATE_FLAG_UCP_NAK)) {
  406. status = scnprintf(buf, PAGE_SIZE, "keycode=0x%02x errorcode=0x%02x",
  407. dev_context->ucp_key_code, dev_context->ucp_err_code);
  408. }
  409. up(&dev_context->isr_lock);
  410. return status;
  411. }
  412. /*
  413. * show_rap() - Handle read request to the rap attribute file.
  414. *
  415. * Reads from this file return a string value indicating the last
  416. * Request Action Protocol (RAP) request received.
  417. *
  418. * The return value is the number characters written to buf, or EAGAIN
  419. * if the driver is busy and cannot service the read request immediately.
  420. * If EAGAIN is returned the caller should wait a little and retry the
  421. * read.
  422. */
  423. ssize_t show_rap(struct device *dev, struct device_attribute *attr, char *buf)
  424. {
  425. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  426. int status = -EINVAL;
  427. MHL_TX_DBG_INFO(dev_context, "called last sub-command:0x%02x\n",dev_context->rap_sub_command);
  428. if (down_interruptible(&dev_context->isr_lock)){
  429. MHL_TX_DBG_ERR(dev_context,"-ERESTARTSYS\n");
  430. return -ERESTARTSYS;
  431. }
  432. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  433. MHL_TX_DBG_ERR(dev_context,"-ENODEV\n");
  434. status = -ENODEV;
  435. goto err_exit;
  436. }
  437. *buf = '\0';
  438. if (MHL_RAP_POLL == dev_context->rap_sub_command)
  439. status = scnprintf(buf, PAGE_SIZE, "poll");
  440. else if (MHL_RAP_CONTENT_ON == dev_context->rap_sub_command)
  441. status = scnprintf(buf, PAGE_SIZE, "content_on");
  442. else if (MHL_RAP_CONTENT_OFF == dev_context->rap_sub_command)
  443. status = scnprintf(buf, PAGE_SIZE, "content_off");
  444. MHL_TX_DBG_INFO(dev_context,"buf:%c%s%c\n",'"',buf,'"');
  445. err_exit:
  446. up(&dev_context->isr_lock);
  447. return status;
  448. }
  449. /*
  450. * send_rap() - Handle write request to the rap attribute file.
  451. *
  452. * Writes to this file cause a RAP message with the specified action code
  453. * to be sent to the downstream device.
  454. */
  455. ssize_t send_rap(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  456. {
  457. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  458. int status;
  459. /* Assume success */
  460. status = count;
  461. MHL_TX_DBG_INFO(dev_context, "received string: %s\n", buf);
  462. if (down_interruptible(&dev_context->isr_lock))
  463. return -ERESTARTSYS;
  464. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  465. status = -ENODEV;
  466. goto err_exit;
  467. }
  468. if (strnicmp("poll", buf, count - 1) == 0) {
  469. if (!si_mhl_tx_rap_send(dev_context, MHL_RAP_POLL))
  470. status = -EPERM;
  471. } else if (strnicmp("content_on", buf, count - 1) == 0) {
  472. if (!si_mhl_tx_rap_send(dev_context, MHL_RAP_CONTENT_ON))
  473. status = -EPERM;
  474. } else if (strnicmp("content_off", buf, count - 1) == 0) {
  475. if (!si_mhl_tx_rap_send(dev_context, MHL_RAP_CONTENT_OFF))
  476. status = -EPERM;
  477. } else {
  478. MHL_TX_DBG_ERR(dev_context, "Invalid parameter %s received\n", buf);
  479. status = -EINVAL;
  480. }
  481. err_exit:
  482. up(&dev_context->isr_lock);
  483. return status;
  484. }
  485. //( begin rap_status interface
  486. /*
  487. * show_rap_status() - Handle read request to the rap_status attribute file.
  488. *
  489. * Reads from this file return the last setting from the customer application
  490. */
  491. ssize_t show_rap_status(struct device *dev, struct device_attribute *attr, char *buf)
  492. {
  493. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  494. int status = -EINVAL;
  495. MHL_TX_DBG_INFO(dev_context, "called last sub-command:0x%02x\n",dev_context->rap_sub_command);
  496. if (down_interruptible(&dev_context->isr_lock)){
  497. MHL_TX_DBG_ERR(dev_context,"-ERESTARTSYS\n");
  498. return -ERESTARTSYS;
  499. }
  500. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  501. MHL_TX_DBG_ERR(dev_context,"-ENODEV\n");
  502. status = -ENODEV;
  503. goto err_exit;
  504. }
  505. *buf = '\0';
  506. if (dev_context->mhl_flags & MHL_STATE_APPLICATION_RAP_BUSY){
  507. status = scnprintf(buf, PAGE_SIZE, "busy");
  508. }else{
  509. status = scnprintf(buf, PAGE_SIZE, "ready");
  510. }
  511. MHL_TX_DBG_INFO(dev_context,"buf:%c%s%c\n",'"',buf,'"');
  512. err_exit:
  513. up(&dev_context->isr_lock);
  514. return status;
  515. }
  516. /*
  517. * set_rap_status() - Handle write request to the rap attribute file.
  518. *
  519. * Writes to this file cause a RAP message with the specified action code
  520. * to be sent to the downstream device.
  521. */
  522. ssize_t set_rap_status(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  523. {
  524. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  525. int status;
  526. /* Assume success */
  527. status = count;
  528. MHL_TX_DBG_INFO(dev_context, "received string: %s\n", buf);
  529. if (down_interruptible(&dev_context->isr_lock))
  530. return -ERESTARTSYS;
  531. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  532. status = -ENODEV;
  533. goto err_exit;
  534. }
  535. if (strnicmp("busy", buf, count - 1) == 0) {
  536. dev_context->mhl_flags |= MHL_STATE_APPLICATION_RAP_BUSY;
  537. } else if (strnicmp("ready", buf, count - 1) == 0) {
  538. dev_context->mhl_flags &= ~MHL_STATE_APPLICATION_RAP_BUSY;
  539. } else {
  540. MHL_TX_DBG_ERR(dev_context, "Invalid parameter %s received\n", buf);
  541. status = -EINVAL;
  542. }
  543. err_exit:
  544. up(&dev_context->isr_lock);
  545. return status;
  546. }
  547. //) end rap_status interface
  548. /*
  549. * select_dev_cap() - Handle write request to the devcap attribute file.
  550. *
  551. * Writes to the devcap file are done to set the offset of a particular
  552. * Device Capabilities register to be returned by a subsequent read
  553. * from this file.
  554. *
  555. * All we need to do is validate the specified offset and if valid
  556. * save it for later use.
  557. */
  558. ssize_t select_dev_cap(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  559. {
  560. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  561. unsigned long offset;
  562. int status = -EINVAL;
  563. MHL_TX_DBG_INFO(dev_context, "received string: ""%s""\n", buf);
  564. if (kstrtoul(buf, 0, &offset)) {
  565. MHL_TX_DBG_ERR(dev_context, "Unable to convert register offset string\n");
  566. goto err_exit;
  567. }
  568. if (offset > 0x0F) {
  569. MHL_TX_DBG_INFO(dev_context,
  570. "dev cap offset (0x%lx) is too large to be valid\n", offset);
  571. goto err_exit;
  572. }
  573. dev_context->dev_cap_offset = (u8)offset;
  574. status = count;
  575. err_exit:
  576. return status;
  577. }
  578. /*
  579. * show_dev_cap() - Handle read request to the devcap attribute file.
  580. *
  581. * Reads from this file return the hexadecimal string value of the last
  582. * Device Capability register offset written to this file.
  583. *
  584. * The return value is the number characters written to buf, or EAGAIN
  585. * if the driver is busy and cannot service the read request immediately.
  586. * If EAGAIN is returned the caller should wait a little and retry the
  587. * read.
  588. *
  589. * The format of the string returned in buf is:
  590. * "offset:<offset>=<regvalue>
  591. * where: <offset> is the last Device Capability register offset
  592. * written to this file
  593. * <regvalue> the currentl value of the Device Capability register
  594. * specified in offset
  595. */
  596. ssize_t show_dev_cap(struct device *dev, struct device_attribute *attr, char *buf)
  597. {
  598. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  599. uint8_t regValue;
  600. int status = -EINVAL;
  601. MHL_TX_DBG_INFO(dev_context, "called\n");
  602. if (down_interruptible(&dev_context->isr_lock))
  603. return -ERESTARTSYS;
  604. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  605. status = -ENODEV;
  606. goto err_exit;
  607. }
  608. if (dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED) {
  609. status = si_mhl_tx_get_peer_dev_cap_entry(dev_context,
  610. dev_context->dev_cap_offset,
  611. &regValue);
  612. if (status != 0) {
  613. /*
  614. * Driver is busy and cannot provide the requested DEVCAP
  615. * register value right now so inform caller they need to
  616. * try again later.
  617. */
  618. status = -EAGAIN;
  619. goto err_exit;
  620. }
  621. status = scnprintf(buf, PAGE_SIZE, "offset:0x%02x=0x%02x",
  622. dev_context->dev_cap_offset, regValue);
  623. }
  624. err_exit:
  625. up(&dev_context->isr_lock);
  626. return status;
  627. }
  628. /*
  629. * send_scratch_pad() - Handle write request to the spad attribute file.
  630. *
  631. * This file is used to either initiate a write to the scratch pad registers
  632. * of an attached device, or to set the offset and byte count for a subsequent
  633. * read from the local scratch pad registers.
  634. *
  635. * The format of the string in buf must be:
  636. * offset=<offset_value> length=<Length_value> \
  637. * data=data_byte_0 ... data_byte_length-1
  638. * where: <offset_value> specifies the starting register offset to begin
  639. * read/writing within the scratch pad register space
  640. * <length_value> number of scratch pad registers to be written/read
  641. * data_byte space separated list of <length_value> data bytes
  642. * to be written. If no data bytes are present then
  643. * the write to this file will only be used to set
  644. * the offset and length for a subsequent read from
  645. * this file.
  646. */
  647. ssize_t send_scratch_pad(struct device *dev, struct device_attribute *attr,
  648. const char *buf, size_t count)
  649. {
  650. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  651. unsigned long offset = 0x100; /* initialize with invalid values */
  652. unsigned long length = 0x100;
  653. unsigned long value;
  654. u8 data[MAX_SCRATCH_PAD_TRANSFER_SIZE];
  655. u8 idx;
  656. char *str;
  657. char *endptr;
  658. enum scratch_pad_status scratch_pad_status;
  659. int status = -EINVAL;
  660. MHL_TX_DBG_ERR(dev_context, "received string: ""%s""\n", buf);
  661. /*
  662. * Parse the input string and extract the scratch pad register selection
  663. * parameters
  664. */
  665. str = strstr(buf, "offset=");
  666. if (str != NULL) {
  667. offset = simple_strtoul(str + 7, NULL, 0);
  668. if (offset > SCRATCH_PAD_SIZE) {
  669. MHL_TX_DBG_ERR(dev_context, "Invalid offset value entered\n");
  670. goto err_exit_2;
  671. }
  672. } else {
  673. MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""offset"" value\n");
  674. goto err_exit_2;
  675. }
  676. str = strstr(buf, "length=");
  677. if (str != NULL) {
  678. length = simple_strtoul(str + 7, NULL, 0);
  679. if (length > MAX_SCRATCH_PAD_TRANSFER_SIZE) {
  680. MHL_TX_DBG_ERR(dev_context, "Transfer length too large\n");
  681. goto err_exit_2;
  682. }
  683. } else {
  684. MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""length"" value\n");
  685. goto err_exit_2;
  686. }
  687. str = strstr(buf, "data=");
  688. if (str != NULL) {
  689. str += 5;
  690. endptr = str;
  691. for(idx = 0; idx < length; idx++) {
  692. endptr += strspn(endptr, white_space);
  693. str = endptr;
  694. if (*str == 0) {
  695. MHL_TX_DBG_ERR(dev_context, "Too few data values provided\n");
  696. goto err_exit_2;
  697. }
  698. value = simple_strtoul(str, &endptr, 0);
  699. if (value > 0xFF) {
  700. MHL_TX_DBG_ERR(dev_context, "Invalid scratch pad data detected\n");
  701. goto err_exit_2;
  702. }
  703. data[idx] = value;
  704. }
  705. } else {
  706. idx = 0;
  707. }
  708. if ((offset + length) > SCRATCH_PAD_SIZE) {
  709. MHL_TX_DBG_ERR(dev_context, "Invalid offset/length combination entered");
  710. goto err_exit_2;
  711. }
  712. dev_context->spad_offset = offset;
  713. dev_context->spad_xfer_length = length;
  714. if (idx == 0) {
  715. MHL_TX_DBG_INFO(dev_context, "No data specified, storing offset "\
  716. "and length for subsequent scratch pad read\n");
  717. goto err_exit_2;
  718. }
  719. if (down_interruptible(&dev_context->isr_lock))
  720. return -ERESTARTSYS;
  721. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  722. status = -ENODEV;
  723. goto err_exit_1;
  724. }
  725. /*
  726. * Make sure there is an MHL connection and that the requested
  727. * data transfer parameters don't exceed the address space of
  728. * the scratch pad. NOTE: The address space reserved for the
  729. * Scratch Pad registers is 64 bytes but sources and sink devices
  730. * are only required to implement the 1st 16 bytes.
  731. */
  732. if (!(dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED) ||
  733. (length < ADOPTER_ID_SIZE) ||
  734. (offset > (SCRATCH_PAD_SIZE - ADOPTER_ID_SIZE)) ||
  735. (offset + length > SCRATCH_PAD_SIZE)) {
  736. status = -EINVAL;
  737. goto err_exit_1;
  738. }
  739. dev_context->mhl_flags |= MHL_STATE_FLAG_SPAD_SENT;
  740. dev_context->spad_send_status = 0;
  741. scratch_pad_status = si_mhl_tx_request_write_burst(dev_context, offset, length, data);
  742. switch (scratch_pad_status) {
  743. case SCRATCHPAD_SUCCESS:
  744. /* On success return the number of bytes written to this file */
  745. status = count;
  746. break;
  747. case SCRATCHPAD_BUSY:
  748. status = -EAGAIN;
  749. break;
  750. default:
  751. status = -EFAULT;
  752. break;
  753. }
  754. err_exit_1:
  755. up(&dev_context->isr_lock);
  756. err_exit_2:
  757. return status;
  758. }
  759. /*
  760. * show_scratch_pad() - Handle read request to the spad attribute file.
  761. *
  762. * Reads from this file return one or more scratch pad register values
  763. * in hexadecimal string format. The registers returned are specified
  764. * by the offset and length values previously written to this file.
  765. *
  766. * The return value is the number characters written to buf, or EAGAIN
  767. * if the driver is busy and cannot service the read request immediately.
  768. * If EAGAIN is returned the caller should wait a little and retry the
  769. * read.
  770. *
  771. * The format of the string returned in buf is:
  772. * "offset:<offset> length:<lenvalue> data:<datavalues>
  773. * where: <offset> is the last scratch pad register offset
  774. * written to this file
  775. * <lenvalue> is the last scratch pad register transfer length
  776. * written to this file
  777. * <datavalue> space separated list of <lenvalue> scratch pad
  778. * register values in OxXX format
  779. */
  780. ssize_t show_scratch_pad(struct device *dev, struct device_attribute *attr,
  781. char *buf)
  782. {
  783. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  784. u8 data[MAX_SCRATCH_PAD_TRANSFER_SIZE];
  785. u8 idx;
  786. enum scratch_pad_status scratch_pad_status;
  787. int status = -EINVAL;
  788. MHL_TX_DBG_INFO(dev_context, "called\n");
  789. if (down_interruptible(&dev_context->isr_lock))
  790. return -ERESTARTSYS;
  791. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  792. status = -ENODEV;
  793. goto err_exit;
  794. }
  795. if (dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED) {
  796. scratch_pad_status = si_get_scratch_pad_vector(dev_context,
  797. dev_context->spad_offset,
  798. dev_context->spad_xfer_length,
  799. data);
  800. switch (scratch_pad_status) {
  801. case SCRATCHPAD_SUCCESS:
  802. status = scnprintf(buf, PAGE_SIZE, "offset:0x%02x " \
  803. "length:0x%02x data:",
  804. dev_context->spad_offset,
  805. dev_context->spad_xfer_length);
  806. for (idx = 0; idx < dev_context->spad_xfer_length; idx++) {
  807. status += scnprintf(&buf[status], PAGE_SIZE, "0x%02x ", data[idx]);
  808. }
  809. break;
  810. case SCRATCHPAD_BUSY:
  811. status = -EAGAIN;
  812. break;
  813. default:
  814. status = -EFAULT;
  815. break;
  816. }
  817. }
  818. err_exit:
  819. up(&dev_context->isr_lock);
  820. return status;
  821. }
  822. /*
  823. * send_debug() - Handle write request to the debug attribute file.
  824. *
  825. * This file is used to either perform a write to registers of the transmitter
  826. * or to set the address, offset and byte count for a subsequent from the
  827. * register(s) of the transmitter.
  828. *
  829. * The format of the string in buf must be:
  830. * address=<pageaddr> offset=<offset_value> length=<Length_value> \
  831. * data=data_byte_0 ... data_byte_length-1
  832. * where: <pageaddr> specifies the I2C register page of the register(s)
  833. * to be written/read
  834. * <offset_value> specifies the starting register offset within the
  835. * register page to begin writing/reading
  836. * <length_value> number registers to be written/read
  837. * data_byte space separated list of <length_value> data bytes
  838. * to be written. If no data bytes are present then
  839. * the write to this file will only be used to set
  840. * the page address, offset and length for a
  841. * subsequent read from this file.
  842. */
  843. ssize_t send_debug(struct device *dev, struct device_attribute *attr,
  844. const char *buf, size_t count)
  845. {
  846. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  847. unsigned long address = 0x100; /* initialize with invalid values */
  848. unsigned long offset = 0x100;
  849. unsigned long length = 0x100;
  850. unsigned long value;
  851. u8 data[MAX_DEBUG_TRANSFER_SIZE];
  852. u8 idx;
  853. char *str;
  854. char *endptr;
  855. int status = -EINVAL;
  856. MHL_TX_DBG_INFO(dev_context, "received string: ""%s""\n", buf);
  857. /*
  858. * Parse the input string and extract the scratch pad register selection
  859. * parameters
  860. */
  861. str = strstr(buf, "address=");
  862. if (str != NULL) {
  863. address = simple_strtoul(str + 8, NULL, 0);
  864. if (address > 0xFF) {
  865. MHL_TX_DBG_ERR(dev_context, "Invalid page address: 0x%02lx specified\n", address);
  866. goto err_exit_2;
  867. }
  868. } else {
  869. MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""address"" parameter\n");
  870. goto err_exit_2;
  871. }
  872. str = strstr(buf, "offset=");
  873. if (str != NULL) {
  874. offset = simple_strtoul(str + 7, NULL, 0);
  875. if (offset > 0xFF) {
  876. MHL_TX_DBG_ERR(dev_context, "Invalid page offset: 0x%02lx specified\n", offset);
  877. goto err_exit_2;
  878. }
  879. } else {
  880. MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""offset"" value\n");
  881. goto err_exit_2;
  882. }
  883. str = strstr(buf, "length=");
  884. if (str != NULL) {
  885. length = simple_strtoul(str + 7, NULL, 0);
  886. if (length > MAX_DEBUG_TRANSFER_SIZE) {
  887. MHL_TX_DBG_ERR(dev_context, "Transfer size 0x%02lx is too large\n", length);
  888. goto err_exit_2;
  889. }
  890. } else {
  891. MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""length"" value\n");
  892. goto err_exit_2;
  893. }
  894. str = strstr(buf, "data=");
  895. if (str != NULL) {
  896. str += 5;
  897. endptr = str;
  898. for(idx = 0; idx < length; idx++) {
  899. endptr += strspn(endptr, white_space);
  900. str = endptr;
  901. if (*str == 0) {
  902. MHL_TX_DBG_ERR(dev_context, "Too few data values provided\n");
  903. goto err_exit_2;
  904. }
  905. value = simple_strtoul(str, &endptr, 0);
  906. if (value > 0xFF) {
  907. MHL_TX_DBG_ERR(dev_context, "Invalid register data value detected\n");
  908. goto err_exit_2;
  909. }
  910. data[idx] = value;
  911. }
  912. } else {
  913. idx = 0;
  914. }
  915. if ((offset + length) > 0x100) {
  916. MHL_TX_DBG_ERR(dev_context
  917. , "Invalid offset/length combination entered 0x%02x/0x%02x"
  918. , offset, length);
  919. goto err_exit_2;
  920. }
  921. dev_context->debug_i2c_address = address;
  922. dev_context->debug_i2c_offset = offset;
  923. dev_context->debug_i2c_xfer_length = length;
  924. if (idx == 0) {
  925. MHL_TX_DBG_INFO(dev_context, "No data specified, storing address "\
  926. "offset and length for subsequent debug read\n");
  927. goto err_exit_2;
  928. }
  929. if (down_interruptible(&dev_context->isr_lock))
  930. return -ERESTARTSYS;
  931. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  932. status = -ENODEV;
  933. goto err_exit_1;
  934. }
  935. status = dev_context->drv_info->mhl_device_dbg_i2c_reg_xfer(
  936. &dev_context->drv_context,
  937. address, offset, length,
  938. DEBUG_I2C_WRITE, data);
  939. if (status == 0)
  940. status = count;
  941. err_exit_1:
  942. up(&dev_context->isr_lock);
  943. err_exit_2:
  944. return status;
  945. }
  946. /*
  947. * show_debug() - Handle read request to the debug attribute file.
  948. *
  949. * Reads from this file return one or more transmitter register values in
  950. * hexadecimal string format. The registers returned are specified by the
  951. * address, offset and length values previously written to this file.
  952. *
  953. * The return value is the number characters written to buf, or an error
  954. * code if the I2C read fails.
  955. *
  956. * The format of the string returned in buf is:
  957. * "address:<pageaddr> offset:<offset> length:<lenvalue> data:<datavalues>
  958. * where: <pageaddr> is the last I2C register page address written
  959. * to this file
  960. * <offset> is the last register offset written to this file
  961. * <lenvalue> is the last register transfer length written
  962. * to this file
  963. * <datavalue> space separated list of <lenvalue> register
  964. * values in OxXX format
  965. */
  966. ssize_t show_debug(struct device *dev, struct device_attribute *attr, char *buf)
  967. {
  968. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  969. u8 data[MAX_DEBUG_TRANSFER_SIZE];
  970. u8 idx;
  971. int status = -EINVAL;
  972. MHL_TX_DBG_INFO(dev_context, "called\n");
  973. if (down_interruptible(&dev_context->isr_lock))
  974. return -ERESTARTSYS;
  975. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  976. status = -ENODEV;
  977. goto no_dev;
  978. }
  979. status = dev_context->drv_info->mhl_device_dbg_i2c_reg_xfer(
  980. &dev_context->drv_context,
  981. dev_context->debug_i2c_address,
  982. dev_context->debug_i2c_offset,
  983. dev_context->debug_i2c_xfer_length,
  984. DEBUG_I2C_READ, data);
  985. no_dev:
  986. up(&dev_context->isr_lock);
  987. if (status == 0) {
  988. status = scnprintf(buf, PAGE_SIZE, "address:0x%02x offset:0x%02x " \
  989. "length:0x%02x data:",
  990. dev_context->debug_i2c_address,
  991. dev_context->debug_i2c_offset,
  992. dev_context->debug_i2c_xfer_length);
  993. for (idx = 0; idx < dev_context->debug_i2c_xfer_length; idx++) {
  994. status += scnprintf(&buf[status], PAGE_SIZE, "0x%02x ", data[idx]);
  995. }
  996. }
  997. return status;
  998. }
  999. //( begin trace_level API
  1000. /*
  1001. * show_trace_level() - Handle read request to the trace_level attribute file.
  1002. *
  1003. * The return value is the number characters written to buf, or EAGAIN
  1004. * if the driver is busy and cannot service the read request immediately.
  1005. * If EAGAIN is returned the caller should wait a little and retry the
  1006. * read.
  1007. */
  1008. ssize_t get_trace_level(struct device *dev, struct device_attribute *attr, char *buf)
  1009. {
  1010. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  1011. int status = -EINVAL;
  1012. extern int debug_msgs;
  1013. if (down_interruptible(&dev_context->isr_lock)){
  1014. MHL_TX_DBG_ERR(dev_context,"-ERESTARTSYS\n");
  1015. return -ERESTARTSYS;
  1016. }
  1017. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  1018. MHL_TX_DBG_ERR(dev_context,"-ENODEV\n");
  1019. status = -ENODEV;
  1020. goto err_exit;
  1021. }
  1022. status = scnprintf(buf, PAGE_SIZE, "level=%d",debug_msgs );
  1023. MHL_TX_DBG_INFO(dev_context,"buf:%c%s%c\n",'"',buf,'"');
  1024. err_exit:
  1025. up(&dev_context->isr_lock);
  1026. return status;
  1027. }
  1028. /*
  1029. * set_trace_level() - Handle write request to the trace_level attribute file.
  1030. *
  1031. * Writes to this file cause a RAP message with the specified action code
  1032. * to be sent to the downstream device.
  1033. */
  1034. ssize_t set_trace_level(struct device *dev, struct device_attribute *attr,
  1035. const char *buf, size_t count)
  1036. {
  1037. struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
  1038. int status;
  1039. char *str;
  1040. const char *key="level=";
  1041. extern int debug_msgs;
  1042. /* Assume success */
  1043. status = count;
  1044. MHL_TX_DBG_INFO(dev_context, "received string: %s\n", buf);
  1045. if (down_interruptible(&dev_context->isr_lock))
  1046. return -ERESTARTSYS;
  1047. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
  1048. status = -ENODEV;
  1049. goto err_exit;
  1050. }
  1051. str = strstr(buf, key);
  1052. if (str != NULL) {
  1053. debug_msgs = simple_strtol(str + strlen(key), NULL, 0);
  1054. } else {
  1055. MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find \"%s\" parameter\n",key);
  1056. }
  1057. err_exit:
  1058. up(&dev_context->isr_lock);
  1059. return status;
  1060. }
  1061. //) end trace_level API
  1062. #define MAX_EVENT_STRING_LEN 128
  1063. /*
  1064. * Handler for event notifications from the MhlTx layer.
  1065. *
  1066. */
  1067. #define MTK_MHL_NOTIFY_SYS
  1068. void mhl_event_notify(struct mhl_dev_context *dev_context, u32 event, u32 event_param, void *data)
  1069. {
  1070. char *buf;
  1071. u32 length;
  1072. MHL_TX_DBG_INFO(dev_context, "called, event: 0x%08x "\
  1073. "event_param: 0x%08x\n", event, event_param);
  1074. /*
  1075. * Save the info on the most recent event. This is done to support the
  1076. * SII_MHL_GET_MHL_TX_EVENT IOCTL. If at some point in the future the
  1077. * driver's IOCTL interface is abandoned in favor of using sysfs attributes
  1078. * this can be removed.
  1079. */
  1080. dev_context->pending_event = event;
  1081. dev_context->pending_event_data = event_param;
  1082. switch(event) {
  1083. case MHL_TX_EVENT_SMB_DATA:
  1084. case MHL_TX_EVENT_HPD_CLEAR:
  1085. case MHL_TX_EVENT_HPD_GOT:
  1086. case MHL_TX_EVENT_DEV_CAP_UPDATE:
  1087. case MHL_TX_EVENT_EDID_UPDATE:
  1088. case MHL_TX_EVENT_EDID_DONE:
  1089. Notify_AP_MHL_TX_Event(event, event_param, data);
  1090. break;
  1091. case MHL_TX_EVENT_CONNECTION:
  1092. dev_context->mhl_flags |= MHL_STATE_FLAG_CONNECTED;
  1093. #ifdef MEDIA_DATA_TUNNEL_SUPPORT
  1094. // mdt_init(dev_context);
  1095. #endif
  1096. #ifdef RCP_INPUTDEV_SUPPORT
  1097. //init_rcp_input_dev(dev_context);
  1098. #endif
  1099. #ifndef MTK_MHL_NOTIFY_SYS
  1100. sysfs_notify(&dev_context->mhl_dev->kobj, NULL,
  1101. __stringify(SYS_ATTR_NAME_CONN));
  1102. strncpy(event_string, "MHLEVENT=connected", MAX_EVENT_STRING_LEN);
  1103. kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
  1104. #else
  1105. #endif
  1106. Notify_AP_MHL_TX_Event(event, event_param, data);
  1107. break;
  1108. case MHL_TX_EVENT_DISCONNECTION:
  1109. dev_context->mhl_flags = 0;
  1110. dev_context->rcp_key_code = 0;
  1111. dev_context->rcp_err_code = 0;
  1112. dev_context->rcp_send_status = 0;
  1113. dev_context->ucp_key_code = 0;
  1114. dev_context->ucp_err_code = 0;
  1115. dev_context->spad_send_status = 0;
  1116. dev_context->misc_flags.flags.have_complete_devcap = false;//SET the para to default;
  1117. #ifdef MEDIA_DATA_TUNNEL_SUPPORT
  1118. // mdt_destroy(dev_context);
  1119. #endif
  1120. #ifdef RCP_INPUTDEV_SUPPORT
  1121. //destroy_rcp_input_dev(dev_context);
  1122. #endif
  1123. #ifndef MTK_MHL_NOTIFY_SYS
  1124. sysfs_notify(&dev_context->mhl_dev->kobj, NULL,
  1125. __stringify(SYS_ATTR_NAME_CONN));
  1126. strncpy(event_string, "MHLEVENT=disconnected", MAX_EVENT_STRING_LEN);
  1127. kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
  1128. #else
  1129. #endif
  1130. Notify_AP_MHL_TX_Event(event, event_param, data);
  1131. break;
  1132. case MHL_TX_EVENT_RCP_RECEIVED:
  1133. #ifdef RCP_INPUTDEV_SUPPORT
  1134. if (0 == generate_rcp_input_event(dev_context, (uint8_t)event_param))
  1135. si_mhl_tx_rcpk_send(dev_context, (uint8_t)event_param);
  1136. else
  1137. {
  1138. si_mhl_tx_rcpe_send(dev_context, MHL_RCPE_STATUS_INEEFECTIVE_KEY_CODE);
  1139. si_mhl_tx_rcpk_send(dev_context, (uint8_t)event_param);
  1140. }
  1141. #else
  1142. dev_context->mhl_flags &= ~MHL_STATE_FLAG_RCP_SENT;
  1143. dev_context->mhl_flags |= MHL_STATE_FLAG_RCP_RECEIVED;
  1144. dev_context->rcp_key_code = event_param;
  1145. #ifndef MTK_MHL_NOTIFY_SYS
  1146. sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_RCP));
  1147. snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_RCP key code=0x%02x", event_param);
  1148. kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
  1149. #else
  1150. #endif
  1151. break;
  1152. case MHL_TX_EVENT_RCPK_RECEIVED:
  1153. if ((dev_context->mhl_flags & MHL_STATE_FLAG_RCP_SENT)
  1154. && (dev_context->rcp_key_code == event_param)) {
  1155. dev_context->rcp_err_code = 0;
  1156. dev_context->mhl_flags |= MHL_STATE_FLAG_RCP_ACK;
  1157. MHL_TX_DBG_INFO(dev_context, "Generating RCPK received event, keycode: 0x%02x\n", event_param);
  1158. #ifndef MTK_MHL_NOTIFY_SYS
  1159. sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_RCPK));
  1160. snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_RCPK key code=0x%02x", event_param);
  1161. kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
  1162. #else
  1163. #endif
  1164. } else {
  1165. MHL_TX_DBG_ERR(dev_context, "Ignoring unexpected RCPK received event, keycode: 0x%02x\n", event_param);
  1166. }
  1167. break;
  1168. case MHL_TX_EVENT_RCPE_RECEIVED:
  1169. if (dev_context->mhl_flags & MHL_STATE_FLAG_RCP_SENT) {
  1170. dev_context->rcp_err_code = event_param;
  1171. dev_context->mhl_flags |= MHL_STATE_FLAG_RCP_NAK;
  1172. MHL_TX_DBG_INFO(dev_context, "Generating RCPE received event, error code: 0x%02x\n", event_param);
  1173. #ifndef MTK_MHL_NOTIFY_SYS
  1174. sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_RCPK));
  1175. snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_RCPE error code=0x%02x", event_param);
  1176. kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
  1177. #else
  1178. #endif
  1179. } else {
  1180. MHL_TX_DBG_ERR(dev_context, "Ignoring unexpected RCPE received event, error code: 0x%02x\n", event_param);
  1181. }
  1182. break;
  1183. #endif /* #ifdef RCP_INPUTDEV_SUPPORT */
  1184. case MHL_TX_EVENT_UCP_RECEIVED:
  1185. dev_context->mhl_flags &= ~MHL_STATE_FLAG_UCP_SENT;
  1186. dev_context->mhl_flags |= MHL_STATE_FLAG_UCP_RECEIVED;
  1187. dev_context->ucp_key_code = event_param;
  1188. #ifndef MTK_MHL_NOTIFY_SYS
  1189. sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_UCP));
  1190. snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_UCP key code=0x%02x", event_param);
  1191. kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
  1192. #else
  1193. #endif
  1194. break;
  1195. case MHL_TX_EVENT_UCPK_RECEIVED:
  1196. if ((dev_context->mhl_flags & MHL_STATE_FLAG_UCP_SENT)
  1197. && (dev_context->ucp_key_code == event_param)) {
  1198. dev_context->mhl_flags |= MHL_STATE_FLAG_UCP_ACK;
  1199. MHL_TX_DBG_INFO(dev_context, "Generating UCPK received event, keycode: 0x%02x\n", event_param);
  1200. #ifndef MTK_MHL_NOTIFY_SYS
  1201. sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_UCPK));
  1202. snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_UCPK key code=0x%02x", event_param);
  1203. kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
  1204. #else
  1205. #endif
  1206. } else {
  1207. MHL_TX_DBG_ERR(dev_context, "Ignoring unexpected UCPK received event, keycode: 0x%02x\n", event_param);
  1208. }
  1209. break;
  1210. case MHL_TX_EVENT_UCPE_RECEIVED:
  1211. if (dev_context->mhl_flags & MHL_STATE_FLAG_UCP_SENT) {
  1212. dev_context->ucp_err_code = event_param;
  1213. dev_context->mhl_flags |= MHL_STATE_FLAG_UCP_NAK;
  1214. MHL_TX_DBG_INFO(dev_context, "Generating UCPE received event, error code: 0x%02x\n", event_param);
  1215. #ifndef MTK_MHL_NOTIFY_SYS
  1216. sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_UCPK));
  1217. snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_UCPE error code=0x%02x", event_param);
  1218. kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
  1219. #else
  1220. #endif
  1221. } else {
  1222. MHL_TX_DBG_ERR(dev_context, "Ignoring unexpected UCPE received event, error code: 0x%02x\n", event_param);
  1223. }
  1224. break;
  1225. case MHL_TX_EVENT_SPAD_RECEIVED:
  1226. length = event_param;
  1227. buf = data;
  1228. #ifndef MTK_MHL_NOTIFY_SYS
  1229. sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_SPAD));
  1230. idx = snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=SPAD_CHG length=0x%02x data=", length);
  1231. count = 0;
  1232. while (idx < MAX_EVENT_STRING_LEN) {
  1233. if (count >= length)
  1234. break;
  1235. idx += snprintf(&event_string[idx], MAX_EVENT_STRING_LEN - idx, "0x%02x ", buf[count]);
  1236. count++;
  1237. }
  1238. if (idx < MAX_EVENT_STRING_LEN) {
  1239. kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
  1240. } else {
  1241. MHL_TX_DBG_ERR(dev_context, "Buffer too small to contain scratch pad data!\n");
  1242. }
  1243. #else
  1244. #endif
  1245. break;
  1246. case MHL_TX_EVENT_POW_BIT_CHG:
  1247. MHL_TX_DBG_INFO(dev_context, "Generating VBUS power bit change event, POW bit is %s\n", event_param? "ON" : "OFF");
  1248. #ifndef MTK_MHL_NOTIFY_SYS
  1249. snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=MHL VBUS power %s", event_param? "ON" : "OFF");
  1250. kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
  1251. #else
  1252. #endif
  1253. break;
  1254. case MHL_TX_EVENT_RAP_RECEIVED:
  1255. MHL_TX_DBG_INFO(dev_context, "Generating RAP received event, action code: 0x%02x\n", event_param);
  1256. #ifndef MTK_MHL_NOTIFY_SYS
  1257. sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_RAP));
  1258. snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_RAP action code=0x%02x", event_param);
  1259. kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
  1260. #else
  1261. #endif
  1262. break;
  1263. default:
  1264. MHL_TX_DBG_ERR(dev_context, "called with unrecognized event code!\n");
  1265. }
  1266. }
  1267. /*
  1268. * File operations supported by the MHL driver
  1269. */
  1270. static const struct file_operations mhl_fops = {
  1271. .owner = THIS_MODULE
  1272. };
  1273. /*
  1274. * Sysfs attribute files supported by this driver.
  1275. */
  1276. struct device_attribute driver_attribs[] = {
  1277. __ATTR(SYS_ATTR_NAME_CONN ,0444,show_connection_state, NULL),
  1278. #ifndef RCP_INPUTDEV_SUPPORT
  1279. __ATTR(SYS_ATTR_NAME_RCP ,0444,show_rcp , send_rcp),
  1280. __ATTR(SYS_ATTR_NAME_RCPK ,0444,show_rcp_ack , send_rcp_ack),
  1281. #endif
  1282. __ATTR(SYS_ATTR_NAME_RAP ,0444,show_rap , send_rap),
  1283. __ATTR(SYS_ATTR_NAME_RAP_STATUS ,0444,show_rap_status , set_rap_status),
  1284. __ATTR(SYS_ATTR_NAME_DEVCAP ,0444,show_dev_cap , select_dev_cap),
  1285. __ATTR(SYS_ATTR_NAME_UCP ,0444,show_ucp , send_ucp),
  1286. __ATTR(SYS_ATTR_NAME_UCPK ,0444,show_ucp_ack , send_ucp_ack),
  1287. __ATTR(SYS_ATTR_NAME_SPAD ,0444,show_scratch_pad , send_scratch_pad),
  1288. __ATTR(SYS_ATTR_NAME_DEBUG ,0444,show_debug , send_debug),
  1289. __ATTR(SYS_ATTR_NAME_TRACE_LEVEL ,0444,get_trace_level , set_trace_level),
  1290. __ATTR_NULL
  1291. };
  1292. extern void Unmask_MHL_Intr(void);
  1293. static void mhl_irq_handler(int irq, void *data);
  1294. static int irq_cnt = 0;
  1295. static int mhl_irq_kthread(void *data)
  1296. {
  1297. struct sched_param param = { .sched_priority = 94 }; /*RTPM_PRIO_SCRN_UPDATE*/
  1298. sched_setscheduler(current, SCHED_RR, &param);
  1299. for( ;; ) {
  1300. set_current_state(TASK_INTERRUPTIBLE);
  1301. wait_event_interruptible(mhl_irq_wq, atomic_read(&mhl_irq_event));
  1302. set_current_state(TASK_RUNNING);
  1303. irq_cnt++;
  1304. atomic_set(&mhl_irq_event, 0);
  1305. //for( i=0;i<30; i++)
  1306. mhl_irq_handler(0, si_dev_context);
  1307. Unmask_MHL_Intr();
  1308. if (kthread_should_stop())
  1309. break;
  1310. }
  1311. return 0;
  1312. }
  1313. /*
  1314. * Interrupt handler for MHL transmitter interrupts.
  1315. *
  1316. * @irq: The number of the asserted IRQ line that caused
  1317. * this handler to be called.
  1318. * @data: Data pointer passed when the interrupt was enabled,
  1319. * which in this case is a pointer to an mhl_dev_context struct.
  1320. *
  1321. * Always returns IRQ_HANDLED.
  1322. */
  1323. static void mhl_irq_handler(int irq, void *data)
  1324. {
  1325. struct mhl_dev_context *dev_context = (struct mhl_dev_context *)data;
  1326. if (!down_interruptible(&dev_context->isr_lock)) {
  1327. if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN)
  1328. goto irq_done;
  1329. if (dev_context->dev_flags & DEV_FLAG_COMM_MODE)
  1330. goto irq_done;
  1331. memset(&dev_context->intr_info, 0, sizeof(*(&dev_context->intr_info)));
  1332. dev_context->intr_info.edid_parser_context = dev_context->edid_parser_context;
  1333. dev_context->drv_info->mhl_device_isr((struct drv_hw_context *)
  1334. (&dev_context->drv_context),
  1335. &dev_context->intr_info);
  1336. /* Now post process events detected by the interrupt handler */
  1337. if(dev_context->intr_info.flags & DRV_INTR_FLAG_DISCONNECT) {
  1338. dev_context->misc_flags.flags.rap_content_on = false;
  1339. dev_context->misc_flags.flags.mhl_rsen = false;
  1340. dev_context->mhl_connection_event = true;
  1341. dev_context->mhl_connected = MHL_TX_EVENT_DISCONNECTION;
  1342. si_mhl_tx_process_events(dev_context);
  1343. } else {
  1344. if (dev_context->intr_info.flags & DRV_INTR_FLAG_CONNECT) {
  1345. dev_context->misc_flags.flags.rap_content_on = true;
  1346. dev_context->rap_sub_command = MHL_RAP_CONTENT_ON;
  1347. dev_context->misc_flags.flags.mhl_rsen = true;
  1348. dev_context->mhl_connection_event = true;
  1349. dev_context->mhl_connected = MHL_TX_EVENT_CONNECTION;
  1350. si_mhl_tx_process_events(dev_context);
  1351. }
  1352. if (dev_context->intr_info.flags & DRV_INTR_FLAG_CBUS_ABORT)
  1353. process_cbus_abort(dev_context);
  1354. if (dev_context->intr_info.flags & DRV_INTR_FLAG_WRITE_BURST)
  1355. si_mhl_tx_process_write_burst_data(dev_context);
  1356. if (dev_context->intr_info.flags & DRV_INTR_FLAG_SET_INT)
  1357. si_mhl_tx_got_mhl_intr(dev_context,
  1358. dev_context->intr_info.int_msg[0],
  1359. dev_context->intr_info.int_msg[1]);
  1360. if (dev_context->intr_info.flags & DRV_INTR_FLAG_MSC_DONE)
  1361. si_mhl_tx_msc_command_done(dev_context,
  1362. dev_context->intr_info.msc_done_data);
  1363. if (dev_context->intr_info.flags & DRV_INTR_FLAG_HPD_CHANGE)
  1364. si_mhl_tx_notify_downstream_hpd_change(dev_context,
  1365. dev_context->intr_info.hpd_status);
  1366. if (dev_context->intr_info.flags & DRV_INTR_FLAG_WRITE_STAT)
  1367. si_mhl_tx_got_mhl_status(dev_context,
  1368. dev_context->intr_info.write_stat[0],
  1369. dev_context->intr_info.write_stat[1]);
  1370. if (dev_context->intr_info.flags & DRV_INTR_FLAG_MSC_RECVD) {
  1371. dev_context->msc_msg_arrived = true;
  1372. dev_context->msc_msg_sub_command = dev_context->intr_info.msc_msg[0];
  1373. dev_context->msc_msg_data = dev_context->intr_info.msc_msg[1];
  1374. si_mhl_tx_process_events(dev_context);
  1375. }
  1376. }
  1377. /*
  1378. * Check to see if we can send any messages that may have
  1379. * been queued up as the result of interrupt processing.
  1380. */
  1381. si_mhl_tx_drive_states(dev_context);
  1382. // if(sii_mhl_connected != dev_context->mhl_connected)
  1383. // pr_err("MHL connected status %d -> %d\n",sii_mhl_connected, dev_context->mhl_connected);
  1384. irq_done:
  1385. up(&dev_context->isr_lock);
  1386. }
  1387. }
  1388. /* APIs provided by the MHL layer to the lower level driver */
  1389. /*extern void register_mhl_eint();*/
  1390. int mhl_tx_init(struct mhl_drv_info const *drv_info, struct i2c_client *client)
  1391. {
  1392. ///struct mhl_dev_context *dev_context;
  1393. int ret,dummy;
  1394. if (drv_info == NULL || client == NULL) {
  1395. pr_err("Null parameter passed to %s\n",__FUNCTION__);
  1396. return -EINVAL;
  1397. }
  1398. init_waitqueue_head(&mhl_irq_wq);
  1399. mhl_irq_task = kthread_create(mhl_irq_kthread, NULL, "mhl_irq_kthread");
  1400. wake_up_process(mhl_irq_task);
  1401. #ifdef CONFIG_MTK_SMARTBOOK_SUPPORT
  1402. init_waitqueue_head(&smartbook_wq);
  1403. smartbook_task = kthread_create(smartbook_kthread, NULL, "smartbook_kthread");
  1404. wake_up_process(smartbook_task);
  1405. #endif
  1406. si_dev_context = kzalloc(sizeof(*si_dev_context) + drv_info->drv_context_size, GFP_KERNEL);
  1407. if (!si_dev_context) {
  1408. dev_err(&client->dev, "failed to allocate driver data\n");
  1409. return -ENOMEM;
  1410. }
  1411. si_dev_context->signature = MHL_DEV_CONTEXT_SIGNATURE;
  1412. si_dev_context->drv_info = drv_info;
  1413. si_dev_context->client = client;
  1414. sema_init(&si_dev_context->isr_lock, 1);
  1415. INIT_LIST_HEAD(&si_dev_context->timer_list);
  1416. si_dev_context->timer_work_queue = create_workqueue(MHL_DRIVER_NAME);
  1417. if (si_dev_context->timer_work_queue == NULL) {
  1418. ret = -ENOMEM;
  1419. goto free_mem;
  1420. }
  1421. if (mhl_class == NULL) {
  1422. mhl_class = class_create(THIS_MODULE, "mhl");
  1423. if(IS_ERR(mhl_class)) {
  1424. ret = PTR_ERR(mhl_class);
  1425. pr_info("class_create failed %d\n", ret);
  1426. goto err_exit;
  1427. }
  1428. /*mhl_class->dev_attrs = driver_attribs;*/
  1429. ret = alloc_chrdev_region(&dev_num,
  1430. 0, MHL_DRIVER_MINOR_MAX,
  1431. MHL_DRIVER_NAME);
  1432. if (ret) {
  1433. pr_info("register_chrdev %s failed, error code: %d\n", MHL_DRIVER_NAME, ret);
  1434. goto free_class;
  1435. }
  1436. cdev_init(&si_dev_context->mhl_cdev, &mhl_fops);
  1437. si_dev_context->mhl_cdev.owner = THIS_MODULE;
  1438. ret = cdev_add(&si_dev_context->mhl_cdev, MINOR(dev_num), MHL_DRIVER_MINOR_MAX);
  1439. if (ret) {
  1440. pr_info("cdev_add %s failed %d\n", MHL_DRIVER_NAME, ret);
  1441. goto free_chrdev;
  1442. }
  1443. }
  1444. si_dev_context->mhl_dev = device_create(mhl_class, &si_dev_context->client->dev,
  1445. dev_num, si_dev_context,
  1446. "%s", MHL_DEVICE_NAME);
  1447. if (IS_ERR(si_dev_context->mhl_dev)) {
  1448. ret = PTR_ERR(si_dev_context->mhl_dev);
  1449. pr_info("device_create failed %s %d\n", MHL_DEVICE_NAME, ret);
  1450. goto free_cdev;
  1451. }
  1452. register_mhl_eint();
  1453. /* Initialize the MHL transmitter hardware. */
  1454. ret = down_interruptible(&si_dev_context->isr_lock);
  1455. if (ret) {
  1456. dev_err(&client->dev, "failed to acquire ISR semaphore, status: %d\n", ret);
  1457. goto free_irq_handler;
  1458. }
  1459. i2c_set_clientdata(client, si_dev_context);
  1460. /* initialize the PCA 950x GPIO expander, if present */
  1461. //ret = gpio_expander_init(dev_context);
  1462. //if (ret < 0) {
  1463. // dev_err(&client->dev,"failed to initialize GPIO expander, status: %d\n",ret);
  1464. // goto free_irq_handler;
  1465. //}
  1466. /* Initialize EDID parser module */
  1467. si_dev_context->edid_parser_context = si_edid_create_context(si_dev_context,&si_dev_context->drv_context);
  1468. ret = si_mhl_tx_initialize(si_dev_context, true);
  1469. up(&si_dev_context->isr_lock);
  1470. #ifdef RCP_INPUTDEV_SUPPORT
  1471. init_rcp_input_dev(si_dev_context);
  1472. #endif
  1473. MHL_TX_DBG_INFO(si_dev_context, "MHL transmitter successfully initialized\n");
  1474. return ret;
  1475. free_irq_handler:
  1476. i2c_set_clientdata(client, NULL);
  1477. dummy = down_interruptible(&si_dev_context->isr_lock);
  1478. if(si_dev_context->edid_parser_context)
  1479. si_edid_destroy_context(si_dev_context->edid_parser_context);
  1480. free_irq(si_dev_context->client->irq, si_dev_context);
  1481. /*
  1482. free_device:
  1483. device_destroy(mhl_class, dev_num);
  1484. */
  1485. free_cdev:
  1486. cdev_del(&si_dev_context->mhl_cdev);
  1487. free_chrdev:
  1488. unregister_chrdev_region(dev_num, MHL_DRIVER_MINOR_MAX);
  1489. dev_num = 0;
  1490. free_class:
  1491. class_destroy(mhl_class);
  1492. err_exit:
  1493. destroy_workqueue(si_dev_context->timer_work_queue);
  1494. free_mem:
  1495. kfree(si_dev_context);
  1496. return ret;
  1497. }
  1498. int mhl_tx_remove(struct i2c_client *client)
  1499. {
  1500. struct mhl_dev_context *dev_context;
  1501. int ret = 0;
  1502. dev_context = i2c_get_clientdata(client);
  1503. if (dev_context != NULL){
  1504. MHL_TX_DBG_INFO(dev_context, "%x\n",dev_context);
  1505. ret = down_interruptible(&dev_context->isr_lock);
  1506. dev_context->dev_flags |= DEV_FLAG_SHUTDOWN;
  1507. ret = si_mhl_tx_shutdown(dev_context);
  1508. mhl_tx_destroy_timer_support(dev_context);
  1509. up(&dev_context->isr_lock);
  1510. free_irq(dev_context->client->irq, dev_context);
  1511. device_destroy(mhl_class, dev_num);
  1512. cdev_del(&dev_context->mhl_cdev);
  1513. unregister_chrdev_region(dev_num, MHL_DRIVER_MINOR_MAX);
  1514. dev_num = 0;
  1515. class_destroy(mhl_class);
  1516. mhl_class = NULL;
  1517. #ifdef MEDIA_DATA_TUNNEL_SUPPORT
  1518. // mdt_destroy(dev_context);
  1519. #endif
  1520. #ifdef RCP_INPUTDEV_SUPPORT
  1521. destroy_rcp_input_dev(dev_context);
  1522. #endif
  1523. si_edid_destroy_context(dev_context->edid_parser_context);
  1524. //mhl_tx_delete_timer(dev_context, dev_context->cbus_abort_timer); //TB added to clean up timer object
  1525. kfree(dev_context);
  1526. MHL_TX_DBG_INFO(dev_context, "%x\n",dev_context);
  1527. }
  1528. return ret;
  1529. }
  1530. static void mhl_tx_destroy_timer_support(struct mhl_dev_context *dev_context)
  1531. {
  1532. struct timer_obj *mhl_timer;
  1533. /*
  1534. * Make sure all outstanding timer objects are canceled and the
  1535. * memory allocated for them is freed.
  1536. */
  1537. while(!list_empty(&dev_context->timer_list)) {
  1538. mhl_timer = list_first_entry(&dev_context->timer_list, struct timer_obj, list_link);
  1539. hrtimer_cancel(&mhl_timer->hr_timer);
  1540. list_del(&mhl_timer->list_link);
  1541. kfree(mhl_timer);
  1542. }
  1543. destroy_workqueue(dev_context->timer_work_queue);
  1544. dev_context->timer_work_queue = NULL;
  1545. }
  1546. static void mhl_tx_timer_work_handler(struct work_struct *work)
  1547. {
  1548. struct timer_obj *mhl_timer;
  1549. mhl_timer = container_of(work, struct timer_obj, work_item);
  1550. mhl_timer->flags |= TIMER_OBJ_FLAG_WORK_IP;
  1551. if (!down_interruptible(&mhl_timer->dev_context->isr_lock)) {
  1552. mhl_timer->timer_callback_handler(mhl_timer->callback_param);
  1553. up(&mhl_timer->dev_context->isr_lock);
  1554. }
  1555. mhl_timer->flags &= ~TIMER_OBJ_FLAG_WORK_IP;
  1556. if(mhl_timer->flags & TIMER_OBJ_FLAG_DEL_REQ) {
  1557. /*
  1558. * Deletion of this timer was requested during the execution of
  1559. * the callback handler so go ahead and delete it now.
  1560. */
  1561. kfree(mhl_timer);
  1562. }
  1563. }
  1564. static enum hrtimer_restart mhl_tx_timer_handler(struct hrtimer *timer)
  1565. {
  1566. struct timer_obj *mhl_timer;
  1567. mhl_timer = container_of(timer, struct timer_obj, hr_timer);
  1568. queue_work(mhl_timer->dev_context->timer_work_queue, &mhl_timer->work_item);
  1569. return HRTIMER_NORESTART;
  1570. }
  1571. static int is_timer_handle_valid(struct mhl_dev_context *dev_context, void *timer_handle)
  1572. {
  1573. struct timer_obj *timer;
  1574. list_for_each_entry(timer, &dev_context->timer_list, list_link) {
  1575. if (timer == timer_handle)
  1576. break;
  1577. }
  1578. if(timer != timer_handle) {
  1579. MHL_TX_DBG_ERR(dev_context, "Invalid timer handle %p received\n", timer_handle);
  1580. return -EINVAL;
  1581. }
  1582. return 0;
  1583. }
  1584. int mhl_tx_create_timer(void *context,
  1585. void (*callback_handler)(void *callback_param),
  1586. void *callback_param,
  1587. void **timer_handle)
  1588. {
  1589. struct mhl_dev_context *dev_context;
  1590. struct timer_obj *new_timer;
  1591. dev_context = get_mhl_device_context(context);
  1592. if (callback_handler == NULL)
  1593. return -EINVAL;
  1594. if (dev_context->timer_work_queue == NULL)
  1595. return -ENOMEM;
  1596. new_timer = kmalloc(sizeof(*new_timer), GFP_KERNEL);
  1597. if (new_timer == NULL)
  1598. return -ENOMEM;
  1599. new_timer->timer_callback_handler = callback_handler;
  1600. new_timer->callback_param = callback_param;
  1601. new_timer->flags = 0;
  1602. new_timer->dev_context = dev_context;
  1603. INIT_WORK(&new_timer->work_item, mhl_tx_timer_work_handler);
  1604. list_add(&new_timer->list_link, &dev_context->timer_list);
  1605. hrtimer_init(&new_timer->hr_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  1606. new_timer->hr_timer.function = mhl_tx_timer_handler;
  1607. *timer_handle = new_timer;
  1608. return 0;
  1609. }
  1610. int mhl_tx_delete_timer(void *context, void *timer_handle)
  1611. {
  1612. struct mhl_dev_context *dev_context;
  1613. struct timer_obj *timer;
  1614. int status;
  1615. dev_context = get_mhl_device_context(context);
  1616. status = is_timer_handle_valid(dev_context, timer_handle);
  1617. if (status == 0) {
  1618. timer = timer_handle;
  1619. list_del(&timer->list_link);
  1620. hrtimer_cancel(&timer->hr_timer);
  1621. if(timer->flags & TIMER_OBJ_FLAG_WORK_IP) {
  1622. /*
  1623. * Request to delete timer object came from within the timer's
  1624. * callback handler. If we were to proceed with the timer deletion
  1625. * we would deadlock at cancel_work_sync(). So instead just flag
  1626. * that the user wants the timer deleted. Later when the timer
  1627. * callback completes the timer's work handler will complete the
  1628. * process of deleting this timer.
  1629. */
  1630. timer->flags |= TIMER_OBJ_FLAG_DEL_REQ;
  1631. } else {
  1632. cancel_work_sync(&timer->work_item);
  1633. kfree(timer);
  1634. }
  1635. }
  1636. return status;
  1637. }
  1638. int mhl_tx_start_timer(void *context, void *timer_handle, uint32_t time_msec)
  1639. {
  1640. struct mhl_dev_context *dev_context;
  1641. struct timer_obj *timer;
  1642. ktime_t timer_period;
  1643. int status;
  1644. dev_context = get_mhl_device_context(context);
  1645. status = is_timer_handle_valid(dev_context, timer_handle);
  1646. if (status == 0) {
  1647. timer = timer_handle;
  1648. timer_period = ktime_set(0, MSEC_TO_NSEC(time_msec));
  1649. hrtimer_start(&timer->hr_timer, timer_period, HRTIMER_MODE_REL);
  1650. }
  1651. return status;
  1652. }
  1653. int mhl_tx_stop_timer(void *context, void *timer_handle)
  1654. {
  1655. struct mhl_dev_context *dev_context;
  1656. struct timer_obj *timer;
  1657. int status;
  1658. dev_context = get_mhl_device_context(context);
  1659. status = is_timer_handle_valid(dev_context, timer_handle);
  1660. if (status == 0) {
  1661. timer = timer_handle;
  1662. hrtimer_cancel(&timer->hr_timer);
  1663. }
  1664. return status;
  1665. }