drv_i2c_gpioi2c.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /* ---------------------------------------------------------------------
  2. Here we defined two functions here for I2C r/w via GPIO
  3. void DRV_GPIOI2C_WriteFun(UINT8 Mx
  4. UINT8 DeviceID
  5. UINT8 AddrLen
  6. UINT32 Addr
  7. UINT8 *pData
  8. UINT32 DataLen
  9. UINT8 Speed
  10. UINT8 *Status);
  11. UINT8 DRV_GPIOI2C_ReadFun(UINT8 Mx,
  12. UINT8 DeviceID,
  13. UINT8 AddrLen,
  14. UINT32 Addr,
  15. UINT8 *pData,
  16. UINT32 DataLen,
  17. UINT8 Speed,
  18. UINT8 *Status);
  19. --------------------------------------------------------------------- */
  20. #include <linux/time.h>
  21. #include <linux/delay.h>
  22. #include <drv_gpio.h>
  23. #include "drv_i2c_gpioi2c.h"
  24. #include "drv_i2c_main.h"
  25. #include <drv_i2c.h>
  26. #include "gpio_pin_define.h"
  27. #include "drv_gpio.h"
  28. #include "pin_config.h"
  29. extern I2C_DEV I2cDev;
  30. #if CONFIG_CHIPID == 0x330
  31. #define GPIO_I2C_CLK 21
  32. #define GPIO_I2C_DATA 22
  33. #else
  34. #define GPIO_I2C_CLK GPIO_I2C_SCL_PIN
  35. #define GPIO_I2C_DATA GPIO_I2C_SDA_PIN
  36. #endif
  37. #define GPIO_X_I2C_CLK 21
  38. #define GPIO_X_I2C_DATA 20
  39. #define LAG 8 /* 90=50k, 42 = 100k, 12 = 200k */
  40. //#define CONFIG_ENABLE_2ND_GPIO_I2C
  41. UINT8 GpioI2CSatus;
  42. void i2cGPIOOpenDrainWrite(UINT8 index, UINT32 value);
  43. void MxI2cGPIORestart(void);
  44. void MxI2cGPIOStart(void);
  45. void MxI2cGPIOStop(void);
  46. void MxI2cGPIOWriteByte(UINT8 Value);
  47. UINT8 MxI2cGPIOReadByte(UINT8 bMoreByte);
  48. UINT32 mmioRead(UINT32 addr)
  49. {
  50. volatile UINT32 dw = *((UINT32*)addr);
  51. return dw;
  52. }
  53. UINT32 mmioReadMask(UINT32 addr, UINT32 mask)
  54. {
  55. return mmioRead( addr ) & mask;
  56. }
  57. void mmioWrite(UINT32 addr, UINT32 data)
  58. {
  59. *(UINT32*)addr = data;
  60. }
  61. void mmioWriteMask(UINT32 addr, UINT32 mask, UINT32 data)
  62. {
  63. UINT32 dw;
  64. dw = mmioReadMask( addr, ~mask );
  65. mmioWrite( addr, ((data & mask) | dw) );
  66. }
  67. void i2cGPIOOpenDrainWrite(UINT8 index, UINT32 value)
  68. {
  69. UINT8 bits;
  70. // set GPIO output value
  71. bits = index ;
  72. mmioWriteMask(0xbe0f0610,(0x1 << bits),(0x0 << bits));
  73. // set GPIO input / output control register to "output mode"
  74. mmioWriteMask(0xbe0f0618,(0x1 << bits),(value << bits));
  75. // set "function selection" mux to "GPIO (set '01') "
  76. bits = (index % 16) * 2;
  77. mmioWriteMask(0xbe0f0604,(0x3 << bits),(0x1 << bits));
  78. }
  79. void MxI2cGPIOStart(void)
  80. {
  81. GpioI2CSatus = 0;
  82. i2cGPIO_writeGPIO(GPIO_I2C_CLK,1);
  83. i2cGPIO_writeGPIO(GPIO_I2C_DATA,1);
  84. udelay(LAG);
  85. i2cGPIO_writeGPIO(GPIO_I2C_DATA,0);
  86. udelay(LAG);
  87. i2cGPIO_writeGPIO(GPIO_I2C_CLK,0);
  88. udelay(LAG);
  89. }
  90. void MxI2cGPIOStop(void)
  91. {
  92. i2cGPIO_writeGPIO(GPIO_I2C_DATA,0);
  93. udelay(LAG);
  94. i2cGPIO_writeGPIO(GPIO_I2C_CLK,1);
  95. udelay(LAG);
  96. i2cGPIO_writeGPIO(GPIO_I2C_DATA,1);
  97. udelay(LAG);
  98. i2cGPIO_readGPIO(GPIO_I2C_CLK);
  99. i2cGPIO_readGPIO(GPIO_I2C_DATA);
  100. udelay(LAG);
  101. }
  102. void MxI2cGPIORestart(void)
  103. {
  104. if(GpioI2CSatus) return;
  105. i2cGPIO_writeGPIO(GPIO_I2C_DATA,1);
  106. udelay(LAG);
  107. i2cGPIO_writeGPIO(GPIO_I2C_CLK,1);
  108. udelay(LAG);
  109. i2cGPIO_writeGPIO(GPIO_I2C_DATA,0);
  110. udelay(LAG);
  111. i2cGPIO_writeGPIO(GPIO_I2C_CLK,0);
  112. udelay(LAG);
  113. }
  114. void MxI2cGPIOWriteByte(UINT8 Value)
  115. {
  116. UINT8 i;
  117. if(GpioI2CSatus) return;
  118. for(i=0;i<8;i++)
  119. {
  120. if(Value & 0x80)
  121. {
  122. i2cGPIO_writeGPIO(GPIO_I2C_DATA,1);
  123. }
  124. else
  125. {
  126. i2cGPIO_writeGPIO(GPIO_I2C_DATA,0);
  127. }
  128. udelay(LAG);
  129. i2cGPIO_writeGPIO(GPIO_I2C_CLK,1);
  130. udelay(LAG);
  131. i2cGPIO_writeGPIO(GPIO_I2C_CLK,0);
  132. udelay(LAG);
  133. Value <<= 1;
  134. }
  135. i2cGPIO_readGPIO(GPIO_I2C_DATA);
  136. udelay(LAG);
  137. i2cGPIO_writeGPIO(GPIO_I2C_CLK,1);
  138. udelay(LAG);
  139. if(i2cGPIO_readGPIO(GPIO_I2C_DATA))
  140. {
  141. GpioI2CSatus = 1;
  142. }
  143. i2cGPIO_writeGPIO(GPIO_I2C_CLK,0);
  144. udelay(LAG);
  145. }
  146. UINT8 MxI2cGPIOReadByte(UINT8 bMoreByte)
  147. {
  148. UINT8 i,Value;
  149. if(GpioI2CSatus) return 0;
  150. i2cGPIO_readGPIO(GPIO_I2C_DATA);
  151. udelay(LAG);
  152. Value = 0;
  153. for(i=0;i<8;i++)
  154. {
  155. Value <<= 1;
  156. i2cGPIO_writeGPIO(GPIO_I2C_CLK,1);
  157. udelay(LAG);
  158. if(i2cGPIO_readGPIO(GPIO_I2C_DATA))
  159. {
  160. Value |= 1;
  161. }
  162. i2cGPIO_writeGPIO(GPIO_I2C_CLK,0);
  163. udelay(LAG);
  164. }
  165. if(bMoreByte)
  166. {
  167. i2cGPIO_writeGPIO(GPIO_I2C_DATA,0);
  168. }
  169. else
  170. {
  171. i2cGPIO_writeGPIO(GPIO_I2C_DATA,1);
  172. }
  173. udelay(LAG);
  174. i2cGPIO_writeGPIO(GPIO_I2C_CLK,1);
  175. udelay(LAG);
  176. i2cGPIO_writeGPIO(GPIO_I2C_CLK,0);
  177. udelay(LAG);
  178. return Value;
  179. }
  180. void _GPIOI2C_0_WriteFun(UINT8 Mx, UINT8 DeviceID, UINT8 AddrLen, UINT32 Addr,UINT8 *pData, UINT32 DataLen,UINT8 Speed,UINT8 *Status)
  181. {
  182. UINT32 i;
  183. // printk(KERN_EMERG"Mx = %d",Mx);
  184. // printk(KERN_EMERG"DeviceID = 0x%x",DeviceID);
  185. // printk(KERN_EMERG"AddrLen = %d",AddrLen);
  186. // printk(KERN_EMERG"Addr = %d",Addr);
  187. // printk(KERN_EMERG"DataLen = %d",DataLen);
  188. // printk(KERN_EMERG"Speed = %d",Speed);
  189. DeviceID &= 0xFE;
  190. if(in_atomic())
  191. {
  192. DbgFunPrint("ID=%02x,Invalid Write Process!!",DeviceID);
  193. *Status = I2C_STATUS_DATA_ERROR;
  194. return;
  195. }
  196. down(&I2cDev.GPIOI2cMutex);
  197. MxI2cGPIOStart();
  198. MxI2cGPIOWriteByte(DeviceID);
  199. switch (AddrLen)
  200. {
  201. case ADDRESS_TYPE_BYTE:
  202. MxI2cGPIOWriteByte((UINT8) (Addr & 0xff));
  203. MxI2cGPIORestart();
  204. MxI2cGPIOWriteByte(DeviceID);
  205. break;
  206. case ADDRESS_TYPE_MULTIPLE:
  207. if( ((Addr&0x0f000000) >> 24) >= 1 ) { MxI2cGPIOWriteByte((UINT8) ((Addr>>0) & 0xff));}
  208. if( ((Addr&0x0f000000) >> 24) >= 2 ) { MxI2cGPIOWriteByte((UINT8) ((Addr>>8) & 0xff));}
  209. if( ((Addr&0x0f000000) >> 24) >= 3 ) { MxI2cGPIOWriteByte((UINT8) ((Addr>>16) & 0xff));}
  210. //if( ((Addr&0x0f000000) >> 24) >= 4 ) { MxI2cGPIOWriteByte((UINT8) ((Addr>>24) & 0xff));}
  211. MxI2cGPIORestart();
  212. MxI2cGPIOWriteByte(DeviceID);
  213. break;
  214. case ADDRESS_TYPE_NONE:
  215. break;
  216. default:
  217. printk("writeI2CviaGPIO write error:AddrLen must be equal to or less than 4.\n");
  218. GpioI2CSatus = I2C_STATUS_DATA_ERROR;
  219. break;
  220. }
  221. for(i=0;i<DataLen;i++)
  222. {
  223. MxI2cGPIOWriteByte(pData[i]);
  224. }
  225. MxI2cGPIOStop();
  226. *Status = GpioI2CSatus;
  227. up(&I2cDev.GPIOI2cMutex);
  228. }
  229. void _GPIOI2C_0_ReadFun(UINT8 Mx, UINT8 DeviceID, UINT8 AddrLen, UINT32 Addr,UINT8 *pData, UINT32 DataLen,UINT8 Speed,UINT8 *Status)
  230. {
  231. UINT32 i;
  232. // printk(KERN_EMERG"Mx = %d",Mx);
  233. // printk(KERN_EMERG"DeviceID = 0x%x",DeviceID);
  234. // printk(KERN_EMERG"AddrLen = %d",AddrLen);
  235. // printk(KERN_EMERG"Addr = %d",Addr);
  236. // printk(KERN_EMERG"DataLen = %d",DataLen);
  237. // printk(KERN_EMERG"Speed = %d",Speed);
  238. DeviceID &= 0xFE;
  239. if(in_atomic())
  240. {
  241. DbgFunPrint("ID=%02x,Invalid Read Process!!",DeviceID);
  242. *Status = I2C_STATUS_DATA_ERROR;
  243. return;
  244. }
  245. down(&I2cDev.GPIOI2cMutex);
  246. MxI2cGPIOStart();
  247. if(AddrLen != ADDRESS_TYPE_NONE)
  248. MxI2cGPIOWriteByte(DeviceID);
  249. switch (AddrLen)
  250. {
  251. case ADDRESS_TYPE_BYTE:
  252. MxI2cGPIOWriteByte((UINT8) (Addr & 0xff));
  253. break;
  254. case ADDRESS_TYPE_MULTIPLE:
  255. if( ((Addr&0x0f000000) >> 24) >= 1 ) { MxI2cGPIOWriteByte((UINT8) (Addr & 0xff));}
  256. if( ((Addr&0x0f000000) >> 24) >= 2 ) { MxI2cGPIOWriteByte((UINT8) ((Addr>>8) & 0xff));}
  257. if( ((Addr&0x0f000000) >> 24) >= 3 ) { MxI2cGPIOWriteByte((UINT8) ((Addr>>16) & 0xff));}
  258. //if( ((Addr&0x0f000000) >> 24) >= 4 ) { MxI2cGPIOWriteByte((UINT8) ((Addr>>24) & 0xff));}
  259. break;
  260. case ADDRESS_TYPE_NONE:
  261. break;
  262. default:
  263. printk(KERN_EMERG"writeI2CviaGPIO read error:DataLen must be equal to or less than 4.\n");
  264. GpioI2CSatus = I2C_STATUS_DATA_ERROR;
  265. break;
  266. }
  267. if (AddrLen != ADDRESS_TYPE_NONE)
  268. MxI2cGPIORestart();
  269. MxI2cGPIOWriteByte(DeviceID|1);
  270. for(i=0;i<DataLen-1;i++)
  271. {
  272. pData[i] = MxI2cGPIOReadByte(1);
  273. }
  274. pData[i] = MxI2cGPIOReadByte(0);
  275. MxI2cGPIOStop();
  276. *Status = GpioI2CSatus;
  277. up(&I2cDev.GPIOI2cMutex);
  278. }
  279. //EXPORT_SYMBOL(DRV_GPIOI2C_ReadFun);
  280. void i2cGPIO_writeGPIO(UINT8 idx, UINT8 val)
  281. {
  282. INT8 apiSel=0;
  283. if(apiSel == 0) i2cGPIOOpenDrainWrite(idx,val);
  284. if(apiSel == 1) GPIOWriteFun(idx,val);
  285. if(apiSel == 2)
  286. {
  287. if(idx == GPIO_I2C_CLK) GPIOSetValueByPinFunc(GPIO_PIN_GPIO_I2C_SCL, (val == 1) ? GPIO_FUNC_ONLEVEL:GPIO_FUNC_OFFLEVEL);
  288. if(idx == GPIO_I2C_DATA) GPIOSetValueByPinFunc(GPIO_PIN_GPIO_I2C_SDA, (val == 1) ? GPIO_FUNC_ONLEVEL:GPIO_FUNC_OFFLEVEL);
  289. }
  290. }
  291. UINT8 i2cGPIO_readGPIO(UINT8 idx)
  292. {
  293. INT8 apiSel=0;
  294. if(apiSel == 0) {return GPIOReadFun(idx);}
  295. else if(apiSel == 1) {return GPIOReadFun(idx);}
  296. else if(apiSel == 2)
  297. {
  298. if(idx == GPIO_I2C_CLK) return GPIOGetValueByPinFunc(GPIO_PIN_GPIO_I2C_SCL);
  299. if(idx == GPIO_I2C_DATA) return GPIOGetValueByPinFunc(GPIO_PIN_GPIO_I2C_SDA);
  300. return 0;
  301. }
  302. else return 0;
  303. }
  304. #ifdef CONFIG_ENABLE_2ND_GPIO_I2C
  305. void MxI2cXGPIOStart(void)
  306. {
  307. GpioI2CSatus = 0;
  308. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,1);
  309. i2cGPIO_writeGPIO(GPIO_X_I2C_DATA,1);
  310. udelay(LAG);
  311. i2cGPIO_writeGPIO(GPIO_X_I2C_DATA,0);
  312. udelay(LAG);
  313. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,0);
  314. udelay(LAG);
  315. }
  316. void MxI2cXGPIOStop(void)
  317. {
  318. i2cGPIO_writeGPIO(GPIO_X_I2C_DATA,0);
  319. udelay(LAG);
  320. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,1);
  321. udelay(LAG);
  322. i2cGPIO_writeGPIO(GPIO_X_I2C_DATA,1);
  323. udelay(LAG);
  324. i2cGPIO_readGPIO(GPIO_X_I2C_CLK);
  325. i2cGPIO_readGPIO(GPIO_X_I2C_DATA);
  326. udelay(LAG);
  327. }
  328. void MxI2cXGPIORestart(void)
  329. {
  330. if(GpioI2CSatus) return;
  331. i2cGPIO_writeGPIO(GPIO_X_I2C_DATA,1);
  332. udelay(LAG);
  333. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,1);
  334. udelay(LAG);
  335. i2cGPIO_writeGPIO(GPIO_X_I2C_DATA,0);
  336. udelay(LAG);
  337. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,0);
  338. udelay(LAG);
  339. }
  340. void MxI2cXGPIOWriteByte(UINT8 Value)
  341. {
  342. UINT8 i;
  343. if(GpioI2CSatus) return;
  344. for(i=0;i<8;i++)
  345. {
  346. if(Value & 0x80)
  347. {
  348. i2cGPIO_writeGPIO(GPIO_X_I2C_DATA,1);
  349. }
  350. else
  351. {
  352. i2cGPIO_writeGPIO(GPIO_X_I2C_DATA,0);
  353. }
  354. udelay(LAG);
  355. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,1);
  356. udelay(LAG);
  357. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,0);
  358. udelay(LAG);
  359. Value <<= 1;
  360. }
  361. i2cGPIO_readGPIO(GPIO_X_I2C_DATA);
  362. udelay(LAG);
  363. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,1);
  364. udelay(LAG);
  365. if(i2cGPIO_readGPIO(GPIO_X_I2C_DATA))
  366. {
  367. GpioI2CSatus = 1;
  368. }
  369. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,0);
  370. udelay(LAG);
  371. }
  372. UINT8 MxI2cXGPIOReadByte(UINT8 bMoreByte)
  373. {
  374. UINT8 i,Value;
  375. if(GpioI2CSatus) return 0;
  376. i2cGPIO_readGPIO(GPIO_X_I2C_DATA);
  377. udelay(LAG);
  378. Value = 0;
  379. for(i=0;i<8;i++)
  380. {
  381. Value <<= 1;
  382. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,1);
  383. udelay(LAG);
  384. if(i2cGPIO_readGPIO(GPIO_X_I2C_DATA))
  385. {
  386. Value |= 1;
  387. }
  388. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,0);
  389. udelay(LAG);
  390. }
  391. if(bMoreByte)
  392. {
  393. i2cGPIO_writeGPIO(GPIO_X_I2C_DATA,0);
  394. }
  395. else
  396. {
  397. i2cGPIO_writeGPIO(GPIO_X_I2C_DATA,1);
  398. }
  399. udelay(LAG);
  400. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,1);
  401. udelay(LAG);
  402. i2cGPIO_writeGPIO(GPIO_X_I2C_CLK,0);
  403. udelay(LAG);
  404. return Value;
  405. }
  406. void _GPIOI2C_1_WriteFun(UINT8 Mx, UINT8 DeviceID, UINT8 AddrLen, UINT32 Addr,UINT8 *pData, UINT32 DataLen,UINT8 Speed,UINT8 *Status)
  407. {
  408. UINT32 i;
  409. // printk(KERN_EMERG"Mx = %d",Mx);
  410. // printk(KERN_EMERG"DeviceID = 0x%x",DeviceID);
  411. // printk(KERN_EMERG"AddrLen = %d",AddrLen);
  412. // printk(KERN_EMERG"Addr = %d",Addr);
  413. // printk(KERN_EMERG"DataLen = %d",DataLen);
  414. // printk(KERN_EMERG"Speed = %d",Speed);
  415. DeviceID &= 0xFE;
  416. if(in_atomic())
  417. {
  418. DbgFunPrint("ID=%02x,Invalid Write Process!!",DeviceID);
  419. *Status = I2C_STATUS_DATA_ERROR;
  420. return;
  421. }
  422. down(&I2cDev.GPIOXI2cMutex);
  423. MxI2cXGPIOStart();
  424. MxI2cXGPIOWriteByte(DeviceID);
  425. switch (AddrLen)
  426. {
  427. case ADDRESS_TYPE_BYTE:
  428. MxI2cXGPIOWriteByte((UINT8) (Addr & 0xff));
  429. MxI2cXGPIORestart();
  430. MxI2cXGPIOWriteByte(DeviceID);
  431. break;
  432. case ADDRESS_TYPE_MULTIPLE:
  433. if( ((Addr&0x0f000000) >> 24) >= 1 ) { MxI2cXGPIOWriteByte((UINT8) ((Addr>>0) & 0xff));}
  434. if( ((Addr&0x0f000000) >> 24) >= 2 ) { MxI2cXGPIOWriteByte((UINT8) ((Addr>>8) & 0xff));}
  435. if( ((Addr&0x0f000000) >> 24) >= 3 ) { MxI2cXGPIOWriteByte((UINT8) ((Addr>>16) & 0xff));}
  436. //if( ((Addr&0x0f000000) >> 24) >= 4 ) { MxI2cXGPIOWriteByte((UINT8) ((Addr>>24) & 0xff));}
  437. MxI2cXGPIORestart();
  438. MxI2cXGPIOWriteByte(DeviceID);
  439. break;
  440. case ADDRESS_TYPE_NONE:
  441. break;
  442. default:
  443. printk("writeI2CviaGPIO write error:AddrLen must be equal to or less than 4.\n");
  444. GpioI2CSatus = I2C_STATUS_DATA_ERROR;
  445. break;
  446. }
  447. for(i=0;i<DataLen;i++)
  448. {
  449. MxI2cXGPIOWriteByte(pData[i]);
  450. }
  451. MxI2cXGPIOStop();
  452. *Status = GpioI2CSatus;
  453. up(&I2cDev.GPIOXI2cMutex);
  454. }
  455. void _GPIOI2C_1_ReadFun(UINT8 Mx, UINT8 DeviceID, UINT8 AddrLen, UINT32 Addr,UINT8 *pData, UINT32 DataLen,UINT8 Speed,UINT8 *Status)
  456. {
  457. UINT32 i;
  458. // printk(KERN_EMERG"Mx = %d",Mx);
  459. // printk(KERN_EMERG"DeviceID = 0x%x",DeviceID);
  460. // printk(KERN_EMERG"AddrLen = %d",AddrLen);
  461. // printk(KERN_EMERG"Addr = %d",Addr);
  462. // printk(KERN_EMERG"DataLen = %d",DataLen);
  463. // printk(KERN_EMERG"Speed = %d",Speed);
  464. DeviceID &= 0xFE;
  465. if(in_atomic())
  466. {
  467. DbgFunPrint("ID=%02x,Invalid Read Process!!",DeviceID);
  468. *Status = I2C_STATUS_DATA_ERROR;
  469. return;
  470. }
  471. down(&I2cDev.GPIOXI2cMutex);
  472. MxI2cXGPIOStart();
  473. if(AddrLen != ADDRESS_TYPE_NONE)
  474. MxI2cXGPIOWriteByte(DeviceID);
  475. switch (AddrLen)
  476. {
  477. case ADDRESS_TYPE_BYTE:
  478. MxI2cXGPIOWriteByte((UINT8) (Addr & 0xff));
  479. break;
  480. case ADDRESS_TYPE_MULTIPLE:
  481. if( ((Addr&0x0f000000) >> 24) >= 1 ) { MxI2cXGPIOWriteByte((UINT8) (Addr & 0xff));}
  482. if( ((Addr&0x0f000000) >> 24) >= 2 ) { MxI2cXGPIOWriteByte((UINT8) ((Addr>>8) & 0xff));}
  483. if( ((Addr&0x0f000000) >> 24) >= 3 ) { MxI2cXGPIOWriteByte((UINT8) ((Addr>>16) & 0xff));}
  484. //if( ((Addr&0x0f000000) >> 24) >= 4 ) { MxI2cXGPIOWriteByte((UINT8) ((Addr>>24) & 0xff));}
  485. break;
  486. case ADDRESS_TYPE_NONE:
  487. break;
  488. default:
  489. printk(KERN_EMERG"writeI2CviaGPIO read error:DataLen must be equal to or less than 4.\n");
  490. GpioI2CSatus = I2C_STATUS_DATA_ERROR;
  491. break;
  492. }
  493. if (AddrLen != ADDRESS_TYPE_NONE)
  494. MxI2cXGPIORestart();
  495. MxI2cXGPIOWriteByte(DeviceID|1);
  496. for(i=0;i<DataLen-1;i++)
  497. {
  498. pData[i] = MxI2cXGPIOReadByte(1);
  499. }
  500. pData[i] = MxI2cXGPIOReadByte(0);
  501. MxI2cXGPIOStop();
  502. *Status = GpioI2CSatus;
  503. up(&I2cDev.GPIOXI2cMutex);
  504. }
  505. #endif
  506. void DRV_GPIOI2C_WriteFun(UINT8 Mx, UINT8 DeviceID, UINT8 AddrLen, UINT32 Addr,UINT8 *pData, UINT32 DataLen,UINT8 Speed,UINT8 *Status)
  507. {
  508. if(Mx==0)
  509. _GPIOI2C_0_WriteFun(Mx, DeviceID, AddrLen, Addr, pData, DataLen, Speed, Status);
  510. #ifdef CONFIG_ENABLE_2ND_GPIO_I2C
  511. if(Mx==1)
  512. _GPIOI2C_1_WriteFun(Mx, DeviceID, AddrLen, Addr, pData, DataLen, Speed, Status);
  513. #endif
  514. }
  515. EXPORT_SYMBOL(DRV_GPIOI2C_WriteFun);
  516. void DRV_GPIOI2C_ReadFun(UINT8 Mx, UINT8 DeviceID, UINT8 AddrLen, UINT32 Addr,UINT8 *pData, UINT32 DataLen,UINT8 Speed,UINT8 *Status)
  517. {
  518. if(Mx==0)
  519. _GPIOI2C_0_ReadFun(Mx, DeviceID, AddrLen, Addr, pData, DataLen, Speed, Status);
  520. #ifdef CONFIG_ENABLE_2ND_GPIO_I2C
  521. if(Mx==1)
  522. _GPIOI2C_1_ReadFun(Mx, DeviceID, AddrLen, Addr, pData, DataLen, Speed, Status);
  523. #endif
  524. }
  525. EXPORT_SYMBOL(DRV_GPIOI2C_ReadFun);