platform.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  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/init.h>
  13. //#include <linux/string.h>
  14. #include <linux/module.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/kernel.h>
  17. #include <linux/slab.h>
  18. #include <linux/i2c.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/delay.h>
  21. #include <linux/err.h>
  22. #include <linux/semaphore.h>
  23. #include <linux/cdev.h>
  24. #include <linux/semaphore.h>
  25. #include <linux/mutex.h>
  26. /*#include <mach/mt_gpio.h>*/
  27. #include "sii_hal.h"
  28. #include "si_fw_macros.h"
  29. #include "si_mhl_defs.h"
  30. #include "si_infoframe.h"
  31. #include "si_edid.h"
  32. #include "si_mhl2_edid_3d_api.h"
  33. #include "si_mhl_tx_hw_drv_api.h"
  34. #ifdef MEDIA_DATA_TUNNEL_SUPPORT
  35. #include <linux/input.h>
  36. #include "si_mdt_inputdev.h"
  37. #endif
  38. #include "mhl_linux_tx.h"
  39. #include "platform.h"
  40. #include "si_8348_drv.h"
  41. #include "si_8348_regs.h"
  42. #include "si_timing_defs.h"
  43. #include <mach/irqs.h>
  44. /*#include "mach/eint.h"*/
  45. #ifdef CONFIG_MTK_LEGACY
  46. /*#include <cust_eint.h>*/
  47. #include <linux/gpio.h>
  48. #include <mt-plat/mt_gpio.h>
  49. #include <cust_gpio_usage.h>
  50. #include <mach/mt_pm_ldo.h>
  51. #endif
  52. ///#include <pmic_drv.h>
  53. /*#include "hdmi_cust.h"*/
  54. #ifdef CONFIG_OF
  55. #include <linux/of.h>
  56. #include <linux/of_irq.h>
  57. #include <linux/regulator/consumer.h>
  58. #endif
  59. /* GPIOs assigned to control various starter kit signals */
  60. #ifdef CONFIG_MTK_LEGACY
  61. #ifdef CUST_EINT_MHL_NUM
  62. #define GPIO_MHL_INT CUST_EINT_MHL_NUM // BeagleBoard pin ID for TX interrupt // 135 is pin 'SDMMC2_DAT3', which is pin 11 of EXP_HDR on BeagleBoard
  63. #else
  64. #define GPIO_MHL_INT 0
  65. #endif
  66. #endif
  67. #ifdef GPIO_MHL_RST_B_PIN
  68. #define GPIO_MHL_RESET GPIO_MHL_RST_B_PIN // BeagleBoard pin ID for TX reset // 139 is pin 'SDMMC2_DAT7', which is pin 03 of EXP_HDR on BeagleBoard
  69. #else
  70. #define GPIO_MHL_RESET 0
  71. #endif
  72. /**
  73. * LOG For HDMI Driver
  74. */
  75. #define MHL_LOG(fmt, arg...) \
  76. do { \
  77. if (hdmi_log_on) pr_err("[HDMI_Platform]%s,%d ", __func__, __LINE__); pr_debug(fmt, ##arg); \
  78. }while (0)
  79. #define MHL_FUNC() \
  80. do { \
  81. if(hdmi_log_on) pr_err("[HDMI_Platform] %s\n", __func__); \
  82. }while (0)
  83. #define MHL_DBG(fmt, arg...) \
  84. do { \
  85. pr_err("[EXTD][DISP]"fmt, ##arg); \
  86. }while (0)
  87. static struct i2c_adapter *i2c_bus_adapter = NULL;
  88. struct i2c_dev_info {
  89. uint8_t dev_addr;
  90. struct i2c_client *client;
  91. };
  92. #define I2C_DEV_INFO(addr) \
  93. {.dev_addr = addr >> 1, .client = NULL}
  94. // I2C Page config
  95. /*
  96. static struct i2c_dev_info device_addresses[] = {
  97. I2C_DEV_INFO(TX_PAGE_L0),
  98. I2C_DEV_INFO(TX_PAGE_L1),
  99. I2C_DEV_INFO(TX_PAGE_3),
  100. I2C_DEV_INFO(TX_PAGE_TPI),
  101. I2C_DEV_INFO(TX_PAGE_CBUS),
  102. I2C_DEV_INFO(TX_PAGE_DDC_EDID)
  103. };
  104. */
  105. extern int I2S_Enable;
  106. int debug_msgs = 3; // print all msgs, default should be '0'
  107. //int debug_msgs = 3; // print all msgs, default should be '0'
  108. static bool reset_on_exit = 0; // request to reset hw before unloading driver
  109. module_param(debug_msgs, int, S_IRUGO);
  110. module_param(reset_on_exit, bool, S_IRUGO);
  111. #define USE_DEFAULT_I2C_CODE 0
  112. extern struct mhl_dev_context *si_dev_context;
  113. static int mhl_i2c_status = 0;
  114. static struct mutex mhl_lock;
  115. int mhl_mutex_init(struct mutex *m)
  116. {
  117. mutex_init(m);
  118. return 0;
  119. }
  120. int mhl_sw_mutex_lock(struct mutex*m)
  121. {
  122. mutex_lock(m);
  123. return 0;
  124. }
  125. int mhl_sw_mutex_unlock(struct mutex*m)
  126. {
  127. mutex_unlock(m);
  128. return 0;
  129. }
  130. /*********************dynamic switch I2C address*******************************/
  131. extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int* rawdata);
  132. static uint8_t Need_Switch_I2C_to_High_Address;
  133. uint8_t reGetI2cAddress(uint8_t device_ID)
  134. {
  135. uint8_t address;
  136. address = 0;
  137. switch(device_ID)
  138. {
  139. case 0x72:
  140. address = 0x76;
  141. break;
  142. case 0x7A:
  143. address = 0x7E;
  144. break;
  145. case 0x9A:
  146. address = 0x9E;
  147. break;
  148. case 0x92:
  149. address = 0x96;
  150. break;
  151. case 0xC8:
  152. address = 0xCC;
  153. break;
  154. case 0xA0:
  155. address = 0xA0;
  156. break;
  157. default:
  158. MHL_DBG("Error: invaild device ID\n");
  159. }
  160. return address;
  161. }
  162. /****************************Platform I2C Read/Write*****************************/
  163. #define MAX_I2C_READ_NUM 8
  164. #define MAX_I2C_WRITE_NUM 7
  165. uint8_t mhl_i2c_read_len_bytes(struct i2c_client *client, uint8_t offset, uint8_t *buf, uint8_t len)
  166. {
  167. uint8_t regAddress = offset;
  168. int ret = 0;
  169. while(len > 0)
  170. {
  171. if(len > MAX_I2C_READ_NUM)
  172. {
  173. MHL_DBG("mhl_i2c_read_len_bytes, len: %d\n", len);
  174. ret = i2c_master_send(client, (const char*)&regAddress, sizeof(uint8_t));
  175. if(ret < 0)
  176. {
  177. MHL_DBG("[Error]mhl i2c sends command error!\n");
  178. return 0;
  179. }
  180. else
  181. {
  182. ret = i2c_master_recv(client, (char*)buf, MAX_I2C_READ_NUM);
  183. if(ret < 0)
  184. {
  185. MHL_DBG("[Error]mhl i2c recv data error!\n");
  186. }
  187. regAddress += MAX_I2C_READ_NUM;
  188. buf += MAX_I2C_READ_NUM;
  189. len -= MAX_I2C_READ_NUM;
  190. }
  191. }
  192. else
  193. {
  194. ret = i2c_master_send(client, (const char*)&regAddress, sizeof(uint8_t));
  195. if(ret < 0)
  196. {
  197. MHL_DBG("[Error1]mhl i2c sends command error!\n");
  198. return 0;
  199. }
  200. else
  201. {
  202. ret = i2c_master_recv(client, (char*)buf, len);
  203. if(ret < 0)
  204. {
  205. MHL_DBG("[Error1]mhl i2c recv data error!\n");
  206. }
  207. regAddress += len;
  208. buf += len;
  209. len -= len;
  210. }
  211. }
  212. }
  213. return 1;
  214. }
  215. uint8_t mhl_i2c_write_len_bytes(struct i2c_client *client, uint8_t offset, uint8_t *buf, uint8_t len)
  216. {
  217. uint8_t regAddress = offset;
  218. int ret = 0;
  219. int i=0;
  220. char write_data[8];
  221. while(len > 0)
  222. {
  223. if(len > MAX_I2C_WRITE_NUM)
  224. {
  225. MHL_DBG("mhl_i2c_write_len_bytes, len: %d\n", len);
  226. write_data[0] = regAddress;
  227. for(i=0; i< MAX_I2C_WRITE_NUM; i++)
  228. write_data[i+1] = *(buf+i);
  229. ret = i2c_master_send(client, write_data, MAX_I2C_WRITE_NUM+1);
  230. if(ret < 0)
  231. {
  232. MHL_DBG("[Error]mhl i2c write command/data error!\n");
  233. return 0;
  234. }
  235. regAddress += MAX_I2C_WRITE_NUM;
  236. len -= MAX_I2C_WRITE_NUM;
  237. buf += MAX_I2C_WRITE_NUM;
  238. }
  239. else
  240. {
  241. write_data[0] = regAddress;
  242. for(i=0; i< len; i++)
  243. write_data[i+1] = *(buf+i);
  244. ret = i2c_master_send(client, write_data, len+1);
  245. if(ret < 0)
  246. {
  247. MHL_DBG("[Error1]mhl i2c write command/data error!\n");
  248. return 0;
  249. }
  250. regAddress += len;
  251. len -= len;
  252. buf += len;
  253. }
  254. }
  255. return 1;
  256. }
  257. uint8_t I2C_ReadBlock(uint8_t deviceID, uint8_t offset,uint8_t *buf, uint8_t len)
  258. {
  259. uint8_t accessI2cAddr;
  260. u32 client_main_addr;
  261. uint8_t slave_addr = deviceID;
  262. mhl_sw_mutex_lock(&mhl_lock);
  263. mhl_i2c_status |= 1;
  264. if(Need_Switch_I2C_to_High_Address)
  265. {
  266. slave_addr = reGetI2cAddress(deviceID);
  267. }
  268. accessI2cAddr = slave_addr>>1;
  269. //backup addr
  270. client_main_addr = si_dev_context->client->addr;
  271. si_dev_context->client->addr = accessI2cAddr;
  272. //si_dev_context->client->addr = (accessI2cAddr & I2C_MASK_FLAG)|I2C_WR_FLAG;
  273. si_dev_context->client->timing = 100;
  274. memset(buf,0xff,len);
  275. mhl_i2c_read_len_bytes(si_dev_context->client, offset, buf, len);
  276. /*
  277. memset(buf,0xff,len);
  278. for(i = 0 ;i < len;i++)
  279. {
  280. u8 tmp;
  281. tmp = offset + i;
  282. ///gMhlDevice.pI2cClient->ext_flag |= I2C_DIRECTION_FLAG;
  283. #if 0
  284. status = i2c_master_send(si_dev_context->client, (const char*)&tmp, 1);
  285. if (status < 0)
  286. {
  287. MHL_DBG("I2C_ReadByte(0x%02x, 0x%02x), i2c_transfer error: %d\n",
  288. deviceID, offset, status);
  289. }
  290. status = i2c_master_recv(si_dev_context->client, (char*)&tmp, 1);
  291. #else
  292. status = i2c_master_send(si_dev_context->client, &tmp, 0x101);
  293. #endif
  294. *buf = tmp;
  295. buf++;
  296. }
  297. */
  298. /* restore default client address */
  299. si_dev_context->client->addr = client_main_addr;
  300. mhl_i2c_status &= 0xfe;
  301. mhl_sw_mutex_unlock(&mhl_lock);
  302. return len;
  303. }
  304. void I2C_WriteBlock(uint8_t deviceID, uint8_t offset, uint8_t *buf, uint16_t len)
  305. {
  306. uint8_t accessI2cAddr;
  307. #if USE_DEFAULT_I2C_CODE
  308. union i2c_smbus_data data;
  309. #endif
  310. u32 client_main_addr;
  311. uint8_t slave_addr = deviceID;
  312. //MHL_DBG("hdmi enter %s (0x%02x, 0x%02x, 0x%02x)\n",__func__, deviceID, offset, len);
  313. mhl_sw_mutex_lock(&mhl_lock);
  314. mhl_i2c_status |= 2;
  315. if(Need_Switch_I2C_to_High_Address)
  316. {
  317. slave_addr = reGetI2cAddress(deviceID);
  318. }
  319. accessI2cAddr = slave_addr>>1;
  320. //backup addr
  321. client_main_addr = si_dev_context->client->addr;
  322. si_dev_context->client->addr = accessI2cAddr;
  323. si_dev_context->client->timing = 100;
  324. mhl_i2c_write_len_bytes(si_dev_context->client, offset, buf, len);
  325. /*
  326. for(i = 0 ;i < len;i++)
  327. {
  328. #if USE_DEFAULT_I2C_CODE
  329. data.byte = *buf;
  330. status = i2c_smbus_xfer(si_dev_context->client->adapter, accessI2cAddr,
  331. 0, I2C_SMBUS_WRITE, offset + i, I2C_SMBUS_BYTE_DATA,
  332. &data);
  333. #else
  334. tmp[0] = offset + i;
  335. tmp[1] = *buf;
  336. ///gMhlDevice.pI2cClient->ext_flag |= I2C_DIRECTION_FLAG;
  337. status = i2c_master_send( si_dev_context->client, (const char*)tmp, 2);
  338. #endif
  339. if (status < 0)
  340. {
  341. si_dev_context->client->addr = client_main_addr;
  342. MHL_DBG("mhl I2C_WriteBlock error %s ret %d\n",__func__, status);
  343. goto done ;
  344. }
  345. buf++;
  346. }
  347. done:
  348. */
  349. /* restore default client address */
  350. si_dev_context->client->addr = client_main_addr;
  351. mhl_i2c_status &= 0xfd;
  352. mhl_sw_mutex_unlock(&mhl_lock);
  353. return ;
  354. }
  355. static inline int platform_read_i2c_block(struct i2c_adapter *i2c_bus
  356. , u8 page
  357. , u8 offset
  358. , u8 count
  359. , u8 *values
  360. )
  361. {
  362. #if 0
  363. struct i2c_msg msg[2];
  364. msg[0].flags = 0;
  365. msg[0].addr = page >> 1;
  366. msg[0].buf = &offset;
  367. msg[0].len = 1;
  368. msg[1].flags = I2C_M_RD;
  369. msg[1].addr = page >> 1;
  370. msg[1].buf = values;
  371. msg[1].len = count;
  372. return i2c_transfer(i2c_bus_adapter, msg, 2);
  373. #endif
  374. I2C_ReadBlock(page, offset,values, count);
  375. ///MHL_DBG("%s:%d I2c read page:0x%02x,offset:0x%02x,values:0x%02X,count:0x%02X\n"
  376. /// ,__FUNCTION__,__LINE__, page, offset, values, count);
  377. return 2;
  378. }
  379. static inline int platform_write_i2c_block(struct i2c_adapter *i2c_bus
  380. , u8 page
  381. , u8 offset
  382. , u16 count
  383. , u8 *values
  384. )
  385. {
  386. #if 0
  387. struct i2c_msg msg;
  388. u8 *buffer;
  389. int ret;
  390. buffer = kmalloc(count + 1, GFP_KERNEL);
  391. if (!buffer) {
  392. MHL_DBG("%s:%d buffer allocation failed\n",__FUNCTION__,__LINE__);
  393. return -ENOMEM;
  394. }
  395. buffer[0] = offset;
  396. memmove(&buffer[1], values, count);
  397. msg.flags = 0;
  398. msg.addr = page >> 1;
  399. msg.buf = buffer;
  400. msg.len = count + 1;
  401. ret = i2c_transfer(i2c_bus, &msg, 1);
  402. kfree(buffer);
  403. if (ret != 1) {
  404. MHL_DBG("%s:%d I2c write failed 0x%02x:0x%02x\n"
  405. ,__FUNCTION__,__LINE__, page, offset);
  406. ret = -EIO;
  407. } else {
  408. ret = 0;
  409. }
  410. return ret;
  411. #endif
  412. I2C_WriteBlock(page, offset, values, count);
  413. return 0;
  414. }
  415. /***************************End*******************************/
  416. ///#define ENABLE_MHL_VBUS_POWER_OUT
  417. #ifdef ENABLE_MHL_VBUS_POWER_OUT
  418. extern void mtk_disable_pmic_otg_mode(void);
  419. extern void mtk_enable_pmic_otg_mode(void);
  420. bool VBUS_state = false;
  421. #include <mach/battery_meter.h>
  422. #endif
  423. void mhl_tx_vbus_control(enum vbus_power_state power_state)
  424. {
  425. #ifdef ENABLE_MHL_VBUS_POWER_OUT
  426. ///struct mhl_dev_context *dev_context;
  427. ///dev_context = i2c_get_clientdata(device_addresses[0].client); // TODO: FD, TBC, it seems the 'client' is always 'NULL', is it right here
  428. printk("%s: mhl_tx_vbus_control3 %d-%d received!\n", __func__, VBUS_state, power_state);
  429. if(VBUS_state == power_state)
  430. return;
  431. VBUS_state = power_state;
  432. switch (power_state) {
  433. case VBUS_OFF:
  434. //set_pin(dev_context,TX2MHLRX_PWR_M,1);
  435. //set_pin(dev_context,LED_SRC_VBUS_ON,GPIO_LED_OFF);
  436. mtk_disable_pmic_otg_mode();
  437. break;
  438. case VBUS_ON:
  439. //set_pin(dev_context,TX2MHLRX_PWR_M,0);
  440. //set_pin(dev_context,LED_SRC_VBUS_ON,GPIO_LED_ON);
  441. printk( "%s: power chg %d received!\n",
  442. __func__, battery_meter_get_charger_voltage());
  443. if(battery_meter_get_charger_voltage() > 4000)
  444. VBUS_state = VBUS_OFF;
  445. else
  446. mtk_enable_pmic_otg_mode();
  447. printk( "%s: power chg %d received!\n",
  448. __func__, battery_meter_get_charger_voltage());
  449. break;
  450. default:
  451. printk( "%s: Invalid power state %d received!\n",
  452. __func__, power_state);
  453. break;
  454. }
  455. #else
  456. printk( "%s: do not support power out %d received!\n",
  457. __func__, power_state);
  458. #endif
  459. }
  460. /******************************Debug Start*****************************/
  461. int si_device_dbg_i2c_reg_xfer(void *dev_context, u8 page, u8 offset, u8 count, bool rw_flag, u8 *buffer)
  462. {
  463. if (rw_flag == DEBUG_I2C_WRITE)
  464. return mhl_tx_write_reg_block(dev_context, page, offset, count, buffer);
  465. else
  466. return mhl_tx_read_reg_block(dev_context, page, offset, count, buffer);
  467. }
  468. #define MAX_DEBUG_MSG_SIZE 1024
  469. #if defined(DEBUG)
  470. /*
  471. * Return a pointer to the file name part of the
  472. * passed path spec string.
  473. */
  474. char *find_file_name(const char *path_spec)
  475. {
  476. char *pc;
  477. for (pc = (char *)&path_spec[strlen(path_spec)]; pc != path_spec; --pc) {
  478. if ('\\' == *pc) {
  479. ++pc;
  480. break;
  481. }
  482. if ('/' == *pc) {
  483. ++pc;
  484. break;
  485. }
  486. }
  487. return pc;
  488. }
  489. void print_formatted_debug_msg(int level,
  490. char *file_spec, const char *func_name,
  491. int line_num,
  492. char *fmt, ...)
  493. {
  494. uint8_t *msg = NULL;
  495. uint8_t *msg_offset;
  496. char *file_spec_sep = NULL;
  497. int remaining_msg_len = MAX_DEBUG_MSG_SIZE;
  498. int len;
  499. va_list ap;
  500. /*
  501. * Allow informational level debug messages to be turned off
  502. * by a switch on the starter kit board
  503. */
  504. if (level > debug_msgs){
  505. return;
  506. }
  507. if (fmt == NULL)
  508. return;
  509. /*
  510. * Only want to print the file name where the debug print
  511. * statement originated, not the path to it.
  512. */
  513. if (file_spec != NULL)
  514. file_spec = find_file_name(file_spec);
  515. msg = kmalloc(remaining_msg_len, GFP_KERNEL);
  516. if(msg == NULL)
  517. return;
  518. msg_offset = msg;
  519. if (file_spec != NULL) {
  520. if (func_name != NULL)
  521. file_spec_sep = "->";
  522. else if (line_num != -1)
  523. file_spec_sep = ":";
  524. }
  525. len = scnprintf(msg_offset, remaining_msg_len, "mhl ");
  526. msg_offset += len;
  527. remaining_msg_len -= len;
  528. if (file_spec) {
  529. len = scnprintf(msg_offset, remaining_msg_len, "%s", file_spec);
  530. msg_offset += len;
  531. remaining_msg_len -= len;
  532. }
  533. if (file_spec_sep) {
  534. len = scnprintf(msg_offset, remaining_msg_len, "%s", file_spec_sep);
  535. msg_offset += len;
  536. remaining_msg_len -= len;
  537. }
  538. if (func_name) {
  539. len = scnprintf(msg_offset, remaining_msg_len, "%s", func_name);
  540. msg_offset += len;
  541. remaining_msg_len -= len;
  542. }
  543. if (line_num != -1) {
  544. if ((file_spec != NULL) || (func_name != NULL))
  545. len = scnprintf(msg_offset, remaining_msg_len, ":%d ", line_num);
  546. else
  547. len = scnprintf(msg_offset, remaining_msg_len, "%d ", line_num);
  548. msg_offset += len;
  549. remaining_msg_len -= len;
  550. }
  551. va_start(ap, fmt);
  552. len = vscnprintf(msg_offset, remaining_msg_len, fmt, ap);
  553. va_end(ap);
  554. printk(msg);
  555. kfree(msg);
  556. }
  557. void dump_i2c_transfer(void *context, u8 page, u8 offset, u16 count, u8 *values, bool write)
  558. {
  559. int buf_size = 64;
  560. u16 idx;
  561. int buf_offset;
  562. char *buf;
  563. if (count > 1) {
  564. buf_size += count * 3; /* 3 characters per byte displayed */
  565. buf_size += ((count / 16) + 1) * 8; /* plus per display row overhead */
  566. }
  567. buf = kmalloc(buf_size, GFP_KERNEL);
  568. if (!buf)
  569. return;
  570. if (count == 1) {
  571. scnprintf(buf, buf_size, " I2C_%s %02X:%02X %s %02X\n",
  572. write ? "W" : "R",
  573. page, offset,
  574. write ? "<-" : "==",
  575. values[0]);
  576. } else {
  577. idx = 0;
  578. buf_offset = scnprintf(buf, buf_size, "I2C_%sB %02X:%02X - %d bytes:",
  579. write ? "W" : "R", page, offset, count);
  580. for (idx = 0; idx < count; idx++) {
  581. if (0 == (idx & 0x0F))
  582. buf_offset += scnprintf(&buf[buf_offset], buf_size - buf_offset,
  583. "\n%04X: ", idx);
  584. buf_offset += scnprintf(&buf[buf_offset], buf_size - buf_offset,
  585. "%02X ", values[idx]);
  586. }
  587. buf_offset += scnprintf(&buf[buf_offset], buf_size - buf_offset, "\n");
  588. }
  589. print_formatted_debug_msg(DBG_MSG_LEVEL_INFO, NULL, NULL, -1, buf);
  590. kfree(buf);
  591. }
  592. #endif /* #if defined(DEBUG) */
  593. /******************************Debug End*******************************/
  594. struct i2c_client *mClient = NULL;
  595. static int mhl_eint_number = 0xffff;
  596. /*
  597. #ifdef CONFIG_MTK_LEGACY
  598. static struct gpio starter_kit_control_gpios[] =
  599. {
  600. {GPIO_MHL_INT, GPIOF_IN, "MHL_intr"},
  601. {GPIO_MHL_RESET, GPIOF_OUT_INIT_HIGH, "MHL_tx_reset"},
  602. };
  603. #endif
  604. */
  605. bool is_reset_on_exit_requested(void)
  606. {
  607. return reset_on_exit;
  608. }
  609. int mhl_tx_write_reg_block(void *drv_context, u8 page, u8 offset, u16 count, u8 *values)
  610. {
  611. DUMP_I2C_TRANSFER(drv_context, page, offset, count, values, true);
  612. return platform_write_i2c_block(i2c_bus_adapter,page, offset, count,values);
  613. }
  614. int mhl_tx_write_reg(void *drv_context, u8 page, u8 offset, u8 value)
  615. {
  616. return mhl_tx_write_reg_block(drv_context, page, offset, 1, &value);
  617. }
  618. int mhl_tx_read_reg_block(void *drv_context, u8 page, u8 offset, u8 count, u8 *values)
  619. {
  620. int ret;
  621. ret = platform_read_i2c_block(i2c_bus_adapter
  622. , page
  623. , offset
  624. , count
  625. , values
  626. );
  627. if (ret != 2) {
  628. MHL_TX_DBG_ERR(drv_context, "I2c read failed, 0x%02x:0x%02x\n", page, offset);
  629. ret = -EIO;
  630. } else {
  631. ret = 0;
  632. DUMP_I2C_TRANSFER(drv_context, page, offset, count, values, false);
  633. }
  634. return ret;
  635. }
  636. int mhl_tx_read_reg(void *drv_context, u8 page, u8 offset)
  637. {
  638. u8 byte_read;
  639. int status;
  640. status = mhl_tx_read_reg_block(drv_context, page, offset, 1, &byte_read);
  641. return status ? status : byte_read;
  642. }
  643. int mhl_tx_modify_reg(void *drv_context, u8 page, u8 offset, u8 mask, u8 value)
  644. {
  645. int reg_value;
  646. int write_status;
  647. reg_value = mhl_tx_read_reg(drv_context, page, offset);
  648. if (reg_value < 0)
  649. return reg_value;
  650. reg_value &= ~mask;
  651. reg_value |= mask & value;
  652. write_status = mhl_tx_write_reg(drv_context, page, offset, reg_value);
  653. if (write_status < 0)
  654. return write_status;
  655. else
  656. return reg_value;
  657. }
  658. /*
  659. static int32_t si_8348_mhl_tx_remove(struct i2c_client *client)
  660. {
  661. #if 1 //(
  662. if (gpio_client){
  663. struct mhl_dev_context *dev_context = i2c_get_clientdata(client);
  664. free_irq(gpio_client->irq,dev_context);
  665. }
  666. #endif //)
  667. i2c_unregister_device(gpio_client);
  668. gpio_client = NULL;
  669. //gpio_free_array(starter_kit_control_gpios_for_expander,
  670. // array_size_of_starter_kit_control_gpios_for_expander);
  671. gpio_free_array(starter_kit_control_gpios,
  672. ARRAY_SIZE(starter_kit_control_gpios));
  673. return 0;
  674. }
  675. static const struct i2c_device_id si_8348_mhl_tx_id[] = {
  676. {MHL_DEVICE_NAME, 0},
  677. {}
  678. };
  679. MODULE_DEVICE_TABLE(i2c, si_8348_mhl_tx_id);
  680. static struct i2c_driver si_8348_mhl_tx_i2c_driver = {
  681. .driver = {
  682. .owner = THIS_MODULE,
  683. .name = MHL_DRIVER_NAME,
  684. },
  685. .id_table = si_8348_mhl_tx_id,
  686. .probe = si_8348_mhl_tx_i2c_probe,
  687. .remove = si_8348_mhl_tx_remove,
  688. .command = NULL,
  689. };
  690. static struct i2c_board_info __initdata si_8348_i2c_boardinfo[] = {
  691. {
  692. I2C_BOARD_INFO(MHL_DEVICE_NAME, (TX_PAGE_L0 >> 1)),
  693. .flags = I2C_CLIENT_WAKE,
  694. .irq = CUST_EINT_MHL_NUM,
  695. }
  696. };
  697. static void __exit si_8348_exit(void)
  698. {
  699. int idx;
  700. mhl_tx_remove(device_addresses[0].client);
  701. MHL_TX_DBG_INFO(NULL, "client removed\n");
  702. i2c_del_driver(&si_8348_mhl_tx_i2c_driver);
  703. MHL_TX_DBG_INFO(NULL, "i2c driver deleted from context\n");
  704. for (idx = 0; idx < ARRAY_SIZE(device_addresses); idx++) {
  705. MHL_TX_DBG_INFO(NULL, "\n");
  706. if (device_addresses[idx].client != NULL){
  707. MHL_TX_DBG_INFO(NULL, "unregistering device:%p\n",device_addresses[idx].client);
  708. i2c_unregister_device(device_addresses[idx].client);
  709. }
  710. }
  711. }
  712. */
  713. /************************** HAL To Platform****************************************/
  714. static struct mhl_drv_info drv_info = {
  715. .drv_context_size = sizeof(struct drv_hw_context),
  716. .mhl_device_initialize = si_mhl_tx_chip_initialize,
  717. .mhl_device_isr = si_mhl_tx_drv_device_isr,
  718. .mhl_device_dbg_i2c_reg_xfer = si_device_dbg_i2c_reg_xfer,
  719. .mhl_start_video= si_mhl_tx_drv_enable_video_path,
  720. };
  721. int32_t sii_8348_tx_init(void)
  722. {
  723. int32_t ret = 0;
  724. MHL_DBG("mhl sii_8348_init\n");
  725. #ifdef ENABLE_MHL_VBUS_POWER_OUT
  726. VBUS_state = false;
  727. #endif
  728. ret = mhl_tx_init(&drv_info, mClient);
  729. MHL_DBG("mhl sii_8348_init, mClient is %p\n", mClient);
  730. return ret;
  731. }
  732. extern wait_queue_head_t mhl_irq_wq;
  733. extern atomic_t mhl_irq_event ;
  734. #ifndef CONFIG_MTK_LEGACY
  735. int get_mhl_irq_num(void)
  736. {
  737. return mhl_eint_number;
  738. }
  739. #endif
  740. void Mask_MHL_Intr(bool irq_context)
  741. {
  742. #ifdef CONFIG_MTK_LEGACY
  743. #ifdef CUST_EINT_MHL_NUM
  744. mt_eint_mask(CUST_EINT_MHL_NUM);
  745. #endif
  746. #else
  747. if(irq_context)
  748. disable_irq_nosync(get_mhl_irq_num());
  749. else
  750. disable_irq(get_mhl_irq_num());
  751. #endif
  752. return ;
  753. }
  754. void Unmask_MHL_Intr(void)
  755. {
  756. #ifdef CONFIG_MTK_LEGACY
  757. #ifdef CUST_EINT_MHL_NUM
  758. mt_eint_unmask(CUST_EINT_MHL_NUM);
  759. #endif
  760. #else
  761. enable_irq(get_mhl_irq_num());
  762. #endif
  763. }
  764. #ifdef CONFIG_MTK_LEGACY
  765. #ifdef CUST_EINT_MHL_NUM
  766. static void mhl8338_irq_handler(void)
  767. {
  768. atomic_set(&mhl_irq_event, 1);
  769. wake_up_interruptible(&mhl_irq_wq);
  770. //mt65xx_eint_unmask(CUST_EINT_HDMI_HPD_NUM);
  771. }
  772. #endif
  773. void register_mhl_eint(void)
  774. {
  775. #ifdef CUST_EINT_MHL_NUM
  776. mt_eint_registration(CUST_EINT_MHL_NUM, CUST_EINT_MHL_TYPE, &mhl8338_irq_handler, 0);
  777. MHL_DBG("%s,CUST_EINT_MHL_NUM is %d \n", __func__, CUST_EINT_MHL_NUM);
  778. #else
  779. MHL_DBG("%s,%d Error: GPIO_MHL_RST_B_PIN is not defined\n", __func__, __LINE__);
  780. #endif
  781. Mask_MHL_Intr(false);
  782. }
  783. #else
  784. static irqreturn_t mhl_eint_irq_handler(int irq, void *data)
  785. {
  786. atomic_set(&mhl_irq_event, 1);
  787. wake_up_interruptible(&mhl_irq_wq);
  788. Mask_MHL_Intr(true);
  789. return IRQ_HANDLED;
  790. }
  791. void register_mhl_eint(void)
  792. {
  793. struct device_node *node = NULL;
  794. u32 ints[2]={0, 0};
  795. node = of_find_compatible_node(NULL, NULL, "mediatek,sii8348-hdmi");
  796. if(node)
  797. {
  798. of_property_read_u32_array(node, "debounce", ints, ARRAY_SIZE(ints));
  799. ///mt_eint_set_hw_debounce(ints[0],ints[1]);
  800. /*mt_gpio_set_debounce(ints[0],ints[1]);*/
  801. mhl_eint_number = irq_of_parse_and_map(node, 0);
  802. irq_set_irq_type(mhl_eint_number,MT_LEVEL_SENSITIVE);
  803. if(request_irq(mhl_eint_number, mhl_eint_irq_handler, IRQF_TRIGGER_LOW, "mediatek,sii8348-hdmi", NULL)) ///IRQF_TRIGGER_LOW
  804. {
  805. MHL_DBG("request_irq fail\n");
  806. }
  807. else
  808. return;
  809. }
  810. Mask_MHL_Intr(false);
  811. MHL_DBG("Error: MHL EINT IRQ NOT AVAILABLE, node %p-irq %d!!\n", node, get_mhl_irq_num());
  812. }
  813. struct pinctrl *mhl_pinctrl;
  814. struct pinctrl_state *pin_state;
  815. extern struct device *ext_dev_context;
  816. struct regulator *reg_v12_power = NULL;
  817. char* dpi_gpio_name[32] = {
  818. "dpi_d0_def", "dpi_d0_cfg","dpi_d1_def", "dpi_d1_cfg","dpi_d2_def", "dpi_d2_cfg","dpi_d3_def", "dpi_d3_cfg",
  819. "dpi_d4_def", "dpi_d4_cfg","dpi_d5_def", "dpi_d5_cfg","dpi_d6_def", "dpi_d6_cfg","dpi_d7_def", "dpi_d7_cfg",
  820. "dpi_d8_def", "dpi_d8_cfg","dpi_d9_def", "dpi_d9_cfg","dpi_d10_def", "dpi_d10_cfg","dpi_d11_def", "dpi_d11_cfg",
  821. "dpi_ck_def", "dpi_ck_cfg","dpi_de_def", "dpi_de_cfg","dpi_hsync_def", "dpi_hsync_cfg","dpi_vsync_def", "dpi_vsync_cfg"
  822. };
  823. char* i2s_gpio_name[6] ={
  824. "i2s_dat_def","i2s_dat_cfg","i2s_ws_def","i2s_ws_cfg","i2s_ck_def","i2s_ck_cfg"
  825. };
  826. char* rst_gpio_name[2] ={
  827. "rst_low_cfg", "rst_high_cfg"
  828. };
  829. void dpi_gpio_ctrl(int enable)
  830. {
  831. int offset = 0;
  832. int ret = 0;
  833. MHL_DBG("dpi_gpio_ctrl+ %ld !!\n",sizeof(dpi_gpio_name));
  834. if (IS_ERR(mhl_pinctrl)) {
  835. ret = PTR_ERR(mhl_pinctrl);
  836. MHL_DBG("Cannot find MHL RST pinctrl for dpi_gpio_ctrl!\n");
  837. return;
  838. }
  839. if(enable)
  840. offset = 1;
  841. for(; offset < 32 ;)
  842. {
  843. pin_state = pinctrl_lookup_state(mhl_pinctrl, dpi_gpio_name[offset]);
  844. if (IS_ERR(pin_state)) {
  845. ret = PTR_ERR(pin_state);
  846. MHL_DBG("Cannot find MHL pinctrl--%s!!\n", dpi_gpio_name[offset]);
  847. }
  848. else
  849. pinctrl_select_state(mhl_pinctrl, pin_state);
  850. offset +=2;
  851. }
  852. }
  853. void i2s_gpio_ctrl(int enable)
  854. {
  855. int offset = 0;
  856. int ret = 0;
  857. MHL_DBG("i2s_gpio_ctrl+ %ld !!\n", sizeof(i2s_gpio_name));
  858. if (IS_ERR(mhl_pinctrl)) {
  859. ret = PTR_ERR(mhl_pinctrl);
  860. MHL_DBG("Cannot find MHL RST pinctrl for i2s_gpio_ctrl!\n");
  861. return;
  862. }
  863. if(enable)
  864. offset = 1;
  865. for(; offset < 6 ;)
  866. {
  867. pin_state = pinctrl_lookup_state(mhl_pinctrl, i2s_gpio_name[offset]);
  868. if (IS_ERR(pin_state)) {
  869. ret = PTR_ERR(pin_state);
  870. MHL_DBG("Cannot find MHL pinctrl--%s!!\n", i2s_gpio_name[offset]);
  871. }
  872. else
  873. pinctrl_select_state(mhl_pinctrl, pin_state);
  874. offset +=2;
  875. }
  876. }
  877. void mhl_power_ctrl(int enable)
  878. {
  879. }
  880. void reset_mhl_board(int hwResetPeriod, int hwResetDelay)
  881. {
  882. struct pinctrl_state *rst_low_state = NULL;
  883. struct pinctrl_state *rst_high_state = NULL;
  884. int err_cnt = 0;
  885. int ret = 0;
  886. MHL_DBG("reset_mhl_board+ %ld !!\n", sizeof(rst_gpio_name));
  887. if (IS_ERR(mhl_pinctrl)) {
  888. ret = PTR_ERR(mhl_pinctrl);
  889. MHL_DBG("Cannot find MHL RST pinctrl for reset_mhl_board!\n");
  890. return;
  891. }
  892. rst_low_state = pinctrl_lookup_state(mhl_pinctrl, rst_gpio_name[0]);
  893. if (IS_ERR(rst_low_state)) {
  894. ret = PTR_ERR(rst_low_state);
  895. MHL_DBG("Cannot find MHL pinctrl--%s!!\n", rst_gpio_name[0]);
  896. err_cnt++;
  897. }
  898. rst_high_state = pinctrl_lookup_state(mhl_pinctrl, rst_gpio_name[1]);
  899. if (IS_ERR(rst_high_state)) {
  900. ret = PTR_ERR(rst_high_state);
  901. MHL_DBG("Cannot find MHL pinctrl--%s!!\n", rst_gpio_name[1]);
  902. err_cnt++;
  903. }
  904. if(err_cnt > 0)
  905. return;
  906. pinctrl_select_state(mhl_pinctrl, rst_high_state);
  907. mdelay(hwResetPeriod);
  908. pinctrl_select_state(mhl_pinctrl, rst_low_state);
  909. mdelay(hwResetPeriod);
  910. pinctrl_select_state(mhl_pinctrl, rst_high_state);
  911. mdelay(hwResetDelay);
  912. }
  913. void cust_power_init(void)
  914. {
  915. }
  916. void cust_power_on(int enable)
  917. {
  918. /*
  919. if(enable)
  920. regulator_enable(reg_v12_power);
  921. else
  922. regulator_disable(reg_v12_power);
  923. */
  924. }
  925. void mhl_platform_init(void)
  926. {
  927. int ret =0;
  928. /*
  929. struct device_node *kd_node =NULL;
  930. const char *name = NULL;
  931. */
  932. MHL_DBG("mhl_platform_init start !!\n");
  933. if(ext_dev_context == NULL)
  934. {
  935. MHL_DBG("Cannot find device in platform_init!\n");
  936. goto plat_init_exit;
  937. }
  938. mhl_pinctrl = devm_pinctrl_get(ext_dev_context);
  939. if (IS_ERR(mhl_pinctrl)) {
  940. ret = PTR_ERR(mhl_pinctrl);
  941. MHL_DBG("Cannot find MHL Pinctrl!!!!\n");
  942. goto plat_init_exit;
  943. }
  944. pin_state = pinctrl_lookup_state(mhl_pinctrl, rst_gpio_name[1]);
  945. if (IS_ERR(pin_state)) {
  946. ret = PTR_ERR(pin_state);
  947. MHL_DBG("Cannot find MHL RST pinctrl low!!\n");
  948. }
  949. else
  950. pinctrl_select_state(mhl_pinctrl, pin_state);
  951. MHL_DBG("mhl_platform_init reset gpio init done!!\n");
  952. i2s_gpio_ctrl(0);
  953. dpi_gpio_ctrl(0);
  954. /*
  955. kd_node = of_find_compatible_node(NULL, NULL, "mediatek,regulator_supply");
  956. if(kd_node)
  957. {
  958. name = of_get_property(kd_node, "MHL_POWER_LD01", NULL);
  959. if (name == NULL)
  960. {
  961. MHL_DBG("mhl_platform_init can't get MHL_POWER_LD01!\n");
  962. if (reg_v12_power == NULL)
  963. {
  964. reg_v12_power = regulator_get(ext_dev_context, "HDMI_12v");
  965. }
  966. }
  967. else
  968. {
  969. kd_node = ext_dev_context->of_node;
  970. ext_dev_context->of_node = of_find_compatible_node(NULL,NULL,"mediatek,regulator_supply");
  971. if (reg_v12_power == NULL)
  972. {
  973. reg_v12_power = regulator_get(ext_dev_context, "mhl_12v");
  974. }
  975. MHL_DBG("mhl_platform_init regulator name !\n" );
  976. ext_dev_context->of_node = kd_node;
  977. }
  978. }
  979. else
  980. {
  981. MHL_DBG("mhl_platform_init get node failed!\n");
  982. goto plat_init_exit ;
  983. }
  984. if (IS_ERR(reg_v12_power))
  985. {
  986. MHL_DBG("mhl_platform_init ldo %p!!!!!!!!!!!!!!\n", reg_v12_power );
  987. }
  988. else
  989. {
  990. MHL_DBG("mhl_platform_init ldo init %p\n", reg_v12_power );
  991. regulator_set_voltage(reg_v12_power, 1200000, 1200000);
  992. }
  993. */
  994. plat_init_exit:
  995. MHL_DBG("mhl_platform_init init done !!\n");
  996. }
  997. #endif
  998. static int32_t si_8348_mhl_tx_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
  999. {
  1000. int ret;
  1001. MHL_DBG("%s, client=%p\n", __func__, (void *)client);
  1002. client->timing = 100;
  1003. i2c_bus_adapter = to_i2c_adapter(client->dev.parent);
  1004. /*
  1005. * On some boards the configuration switches
  1006. * are connected via an I2C controlled GPIO expander.
  1007. * At this point in the initialization, we're not
  1008. * ready to to I2C yet, so don't try to read any config
  1009. * switches here. Instead, wait until gpio_expander_init().
  1010. */
  1011. ret = mhl_tx_init(&drv_info, client);
  1012. mClient = client;
  1013. MHL_DBG("%s, mhl_tx_init ret %d\n", __func__, ret);
  1014. if (ret){
  1015. }
  1016. Unmask_MHL_Intr();
  1017. ret = 0;
  1018. return ret;
  1019. }
  1020. //"Sil_MHL" "mediatek,EXT_DISP"
  1021. struct i2c_device_id gMhlI2cIdTable[] =
  1022. {
  1023. {
  1024. "Sil_MHL",0
  1025. }
  1026. };
  1027. #ifdef CONFIG_OF
  1028. static const struct of_device_id Mhl_of_match[] = {
  1029. {.compatible = "mediatek,ext_disp"},
  1030. {},
  1031. };
  1032. #endif
  1033. #ifdef CONFIG_MTK_LEGACY
  1034. /*
  1035. static struct i2c_board_info __initdata i2c_mhl = {
  1036. .type = "Sil_MHL",
  1037. .addr = 0x39,
  1038. .irq = 8,
  1039. };
  1040. */
  1041. struct i2c_driver mhl_i2c_driver = {
  1042. .probe = si_8348_mhl_tx_i2c_probe,
  1043. .driver = { .name = "Sil_MHL",},
  1044. .id_table = gMhlI2cIdTable,
  1045. };
  1046. #else
  1047. struct i2c_driver mhl_i2c_driver = {
  1048. .probe = si_8348_mhl_tx_i2c_probe,
  1049. .id_table = gMhlI2cIdTable,
  1050. .driver = {
  1051. .name = "Sil_MHL",
  1052. #ifdef CONFIG_OF
  1053. .of_match_table = Mhl_of_match,
  1054. #endif
  1055. },
  1056. };
  1057. #endif
  1058. halReturn_t HalCloseI2cDevice(void)
  1059. {
  1060. return HAL_RET_SUCCESS;
  1061. }
  1062. #ifdef CONFIG_MTK_LEGACY
  1063. int HalOpenI2cDevice(char const *DeviceName, char const *DriverName)
  1064. {
  1065. halReturn_t retStatus;
  1066. int32_t retVal;
  1067. ///dynamic_switch_i2c_address();
  1068. /*
  1069. if(get_hdmi_i2c_addr()==0x76)
  1070. {
  1071. Need_Switch_I2C_to_High_Address = 1;
  1072. i2c_mhl.addr = 0x3B;
  1073. }
  1074. */
  1075. MHL_DBG("HalOpenI2cDevice done +\n" );
  1076. retVal = strnlen(DeviceName, I2C_NAME_SIZE);
  1077. if (retVal >= I2C_NAME_SIZE)
  1078. {
  1079. MHL_DBG("I2c device name too long!\n");
  1080. return HAL_RET_PARAMETER_ERROR;
  1081. }
  1082. /*i2c_register_board_info(get_hdmi_i2c_channel(), &i2c_mhl, 1);*/
  1083. memcpy(gMhlI2cIdTable[0].name, DeviceName, retVal);
  1084. gMhlI2cIdTable[0].name[retVal] = 0;
  1085. gMhlI2cIdTable[0].driver_data = 0;
  1086. //MHL_DBG("gMhlDevice.driver.driver.name=%s\n", gMhlDevice.driver.driver.name);
  1087. //MHL_DBG("gMhlI2cIdTable.name=%s\n", gMhlI2cIdTable[0].name);
  1088. retVal = i2c_add_driver(&mhl_i2c_driver);
  1089. if (retVal != 0)
  1090. {
  1091. MHL_DBG("I2C driver add failed, retVal=%d\n", retVal);
  1092. retStatus = HAL_RET_FAILURE;
  1093. }
  1094. else
  1095. {
  1096. {
  1097. retStatus = HAL_RET_SUCCESS;
  1098. }
  1099. }
  1100. mhl_mutex_init(&mhl_lock);
  1101. return retStatus;
  1102. }
  1103. #else
  1104. int HalOpenI2cDevice(char const *DeviceName, char const *DriverName)
  1105. {
  1106. halReturn_t retStatus;
  1107. int32_t retVal;
  1108. MHL_DBG("%s, + \n", __func__);
  1109. mhl_mutex_init(&mhl_lock);
  1110. mhl_platform_init();
  1111. retVal = i2c_add_driver(&mhl_i2c_driver);
  1112. if (retVal != 0)
  1113. {
  1114. MHL_DBG("I2C driver add failed, retVal=%d\n", retVal);
  1115. retStatus = HAL_RET_FAILURE;
  1116. }
  1117. else
  1118. {
  1119. {
  1120. retStatus = HAL_RET_SUCCESS;
  1121. }
  1122. }
  1123. MHL_DBG("%s, done %d\n", __func__, retVal);
  1124. return retStatus;
  1125. }
  1126. #endif
  1127. /************************** ****************************************************/
  1128. MODULE_DESCRIPTION("Silicon Image MHL Transmitter driver");
  1129. MODULE_AUTHOR("Silicon Image <http://www.siliconimage.com>");
  1130. MODULE_LICENSE("GPL");