071-m5445x_i2c.patch 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. From e1618e943f60a4f8f778c4f7c389e2fa13eb0a83 Mon Sep 17 00:00:00 2001
  2. From: Kurt Mahan <[email protected]>
  3. Date: Thu, 26 Jun 2008 16:29:56 -0600
  4. Subject: [PATCH] Add I2C support for the M5445x platforms.
  5. LTIBName: m5445x-i2c
  6. Signed-off-by: Kurt Mahan <[email protected]>
  7. ---
  8. drivers/i2c/busses/Kconfig | 10 +
  9. drivers/i2c/busses/Makefile | 1 +
  10. drivers/i2c/busses/i2c-mcf.c | 573 ++++++++++++++++++++++++++++++++++++++++++
  11. drivers/i2c/busses/i2c-mcf.h | 75 ++++++
  12. 4 files changed, 659 insertions(+), 0 deletions(-)
  13. create mode 100644 drivers/i2c/busses/i2c-mcf.c
  14. create mode 100644 drivers/i2c/busses/i2c-mcf.h
  15. --- a/drivers/i2c/busses/Kconfig
  16. +++ b/drivers/i2c/busses/Kconfig
  17. @@ -302,6 +302,16 @@ config I2C_POWERMAC
  18. This support is also available as a module. If so, the module
  19. will be called i2c-powermac.
  20. +config I2C_MCF
  21. + tristate "MCF ColdFire"
  22. + depends on I2C && EXPERIMENTAL
  23. + help
  24. + If you say yes to this option, support will be included for the
  25. + I2C on most ColdFire CPUs
  26. +
  27. + This driver can also be built as a module. If so, the module
  28. + will be called i2c-mcf.
  29. +
  30. config I2C_MPC
  31. tristate "MPC107/824x/85xx/52xx/86xx"
  32. depends on PPC32
  33. --- a/drivers/i2c/busses/Makefile
  34. +++ b/drivers/i2c/busses/Makefile
  35. @@ -53,6 +53,7 @@ obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3
  36. obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
  37. obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o
  38. obj-$(CONFIG_I2C_MCF548x) += i2c-mcf548x.o
  39. +obj-$(CONFIG_I2C_MCF) += i2c-mcf.o
  40. ifeq ($(CONFIG_I2C_DEBUG_BUS),y)
  41. EXTRA_CFLAGS += -DDEBUG
  42. --- /dev/null
  43. +++ b/drivers/i2c/busses/i2c-mcf.c
  44. @@ -0,0 +1,573 @@
  45. +/*
  46. + i2c-mcf.c - Part of lm_sensors, Linux kernel modules for hardware monitoring
  47. +
  48. + Copyright (c) 2005, Derek CL Cheung <[email protected]>
  49. + <http://www3.sympatico.ca/derek.cheung>
  50. +
  51. + Copyright (c) 2006-2007, emlix
  52. + Sebastian Hess <[email protected]>
  53. +
  54. + Copyright (c) 2006-2007 Freescale Semiconductor, Inc
  55. + Yaroslav Vinogradov <[email protected]>
  56. + Matt Waddel <[email protected]>
  57. +
  58. + This program is free software; you can redistribute it and/or modify
  59. + it under the terms of the GNU General Public License as published by
  60. + the Free Software Foundation; either version 2 of the License, or
  61. + (at your option) any later version.
  62. +
  63. + This program is distributed in the hope that it will be useful,
  64. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  65. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  66. + GNU General Public License for more details.
  67. +
  68. + You should have received a copy of the GNU General Public License
  69. + along with this program; if not, write to the Free Software
  70. + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  71. +
  72. + Changes:
  73. + v0.1 26 March 2005
  74. + Initial Release - developed on uClinux with 2.6.9 kernel
  75. +
  76. + v0.2 29 May 2006
  77. + Modified to be more generic and added support for
  78. + i2c_master_xfer
  79. +
  80. + This I2C adaptor supports the ColdFire CPU I2C module. Since most Coldfire
  81. + CPUs' I2C module use the same register set (e.g., MCF5249), the code is very
  82. + portable and re-usable to other Coldfire CPUs.
  83. +
  84. + The transmission frequency is set at about 100KHz for the CPU board with
  85. + 8MHz crystal. If the CPU board uses different system clock frequency, you
  86. + should change the following line:
  87. + static int __init i2c_coldfire_init(void)
  88. + {
  89. + .........
  90. + // Set transmission frequency 0x15 = ~100kHz
  91. + *MCF_I2C_I2FDR = 0x15;
  92. + ........
  93. + }
  94. +
  95. + Remember to perform a dummy read to set the ColdFire CPU's I2C module for
  96. + read before reading the actual byte from a device
  97. +
  98. + The I2C_SM_BUS_BLOCK_DATA function are not yet ready but most lm_senors
  99. + do not care
  100. +*/
  101. +
  102. +#include <linux/init.h>
  103. +#include <linux/module.h>
  104. +#include <linux/kernel.h>
  105. +#include <linux/errno.h>
  106. +#include <linux/i2c.h>
  107. +#include <linux/delay.h>
  108. +#include <linux/string.h>
  109. +#include <asm/coldfire.h>
  110. +#include <asm/mcfsim.h>
  111. +#include <asm/types.h>
  112. +#include <linux/platform_device.h>
  113. +#include "i2c-mcf.h"
  114. +
  115. +
  116. +static struct i2c_algorithm coldfire_algorithm = {
  117. + /*.name = "ColdFire I2C algorithm",
  118. + .id = I2C_ALGO_SMBUS,*/
  119. + .smbus_xfer = coldfire_i2c_access,
  120. + .master_xfer = coldfire_i2c_master,
  121. + .functionality = coldfire_func,
  122. +};
  123. +
  124. +
  125. +static struct i2c_adapter coldfire_adapter = {
  126. + .owner = THIS_MODULE,
  127. + .class = I2C_CLASS_HWMON,
  128. + .algo = &coldfire_algorithm,
  129. + .name = "ColdFire I2C adapter",
  130. +};
  131. +
  132. +
  133. +__u16 lastaddr;
  134. +__u16 lastop;
  135. +
  136. +static inline int coldfire_do_first_start(__u16 addr,__u16 flags)
  137. +{
  138. + int err;
  139. + /*
  140. + * Generate a stop and put the I2C module into slave mode
  141. + */
  142. + *MCF_I2C_I2CR &= ~MCF_I2C_I2CR_MSTA;
  143. +
  144. + /*
  145. + * Generate a new Start signal
  146. + */
  147. + err = coldfire_i2c_start(flags & I2C_M_RD ? I2C_SMBUS_READ : I2C_SMBUS_WRITE,
  148. + addr, FIRST_START);
  149. + if(err) return err;
  150. +
  151. + lastaddr = addr;
  152. + lastop = flags & I2C_M_RD; /* Ensure everything for new start */
  153. + return 0;
  154. +}
  155. +
  156. +
  157. +/*
  158. + * read one byte data from the I2C bus
  159. + */
  160. +static int coldfire_read_data(u8 * const rxData, const enum I2C_ACK_TYPE ackType) {
  161. +
  162. + int timeout;
  163. +
  164. + *MCF_I2C_I2CR &= ~MCF_I2C_I2CR_MTX; /* master receive mode*/
  165. +
  166. + if (ackType == NACK)
  167. + *MCF_I2C_I2CR |= MCF_I2C_I2CR_TXAK; /* generate NA */
  168. + else
  169. + *MCF_I2C_I2CR &= ~MCF_I2C_I2CR_TXAK; /* generate ACK */
  170. +
  171. +
  172. + /* read data from the I2C bus */
  173. + *rxData = *MCF_I2C_I2DR;
  174. +
  175. + /* printk(">>> %s I2DR data is %.2x \n", __FUNCTION__, *rxData); */
  176. +
  177. + /* wait for data transfer to complete */
  178. + timeout = 500;
  179. + while (timeout-- && !(*MCF_I2C_I2SR & MCF_I2C_I2SR_IIF))
  180. + udelay(1);
  181. + if (timeout <= 0)
  182. + printk("%s - I2C IIF never set. Timeout is %d \n", __FUNCTION__,
  183. + timeout);
  184. +
  185. +
  186. + /* reset the interrupt bit */
  187. + *MCF_I2C_I2SR &= ~MCF_I2C_I2SR_IIF;
  188. +
  189. + if (timeout <= 0 )
  190. + return -1;
  191. + else
  192. + return 0;
  193. +
  194. +};
  195. +
  196. +
  197. +/*
  198. + * write one byte data onto the I2C bus
  199. + */
  200. +static int coldfire_write_data(const u8 txData) {
  201. +
  202. + int timeout;
  203. +
  204. + timeout = 500;
  205. +
  206. + *MCF_I2C_I2CR |= MCF_I2C_I2CR_MTX; /* I2C module into TX mode */
  207. + *MCF_I2C_I2DR = txData; /* send the data */
  208. +
  209. + /* wait for data transfer to complete */
  210. + /* rely on the interrupt handling bit */
  211. + timeout = 500;
  212. + while (timeout-- && !(*MCF_I2C_I2SR & MCF_I2C_I2SR_IIF))
  213. + udelay(1);
  214. + if (timeout <=0)
  215. + printk("%s - I2C IIF never set. Timeout is %d \n", __FUNCTION__,
  216. + timeout);
  217. +
  218. +
  219. + /* reset the interrupt bit */
  220. + *MCF_I2C_I2SR &= ~MCF_I2C_I2SR_IIF;
  221. +
  222. + if (timeout <= 0 )
  223. + return -1;
  224. + else
  225. + return 0;
  226. +
  227. +};
  228. +
  229. +
  230. +
  231. +
  232. +/*
  233. + * Generate I2C start or repeat start signal
  234. + * Combine the 7 bit target_address and the R/W bit and put it onto the I2C bus
  235. + */
  236. +static int coldfire_i2c_start(const char read_write, const u16 target_address, const enum I2C_START_TYPE start_type) {
  237. +
  238. + int timeout;
  239. +
  240. + /* printk(">>> %s START TYPE %s \n", __FUNCTION__,
  241. + start_type == FIRST_START ? "FIRST_START":"REPEAT_START");*/
  242. +
  243. + *MCF_I2C_I2CR |= MCF_I2C_I2CR_IEN;
  244. +
  245. + if (start_type == FIRST_START) {
  246. + /* Make sure the I2C bus is idle */
  247. + timeout = 500; /* 500us timeout */
  248. + while (timeout-- && (*MCF_I2C_I2SR & MCF_I2C_I2SR_IBB))
  249. + udelay(1);
  250. + if (timeout <= 0) {
  251. + printk("%s - I2C bus always busy in the past 500us timeout is %d \n", __FUNCTION__, timeout);
  252. + goto check_rc;
  253. + }
  254. + /* generate a START and put the I2C module into MASTER TX mode*/
  255. + *MCF_I2C_I2CR |= (MCF_I2C_I2CR_MSTA | MCF_I2C_I2CR_MTX);
  256. +
  257. + /* wait for bus busy to be set */
  258. + timeout = 500;
  259. + while (timeout-- && !(*MCF_I2C_I2SR & MCF_I2C_I2SR_IBB))
  260. + udelay(1);
  261. + if (timeout <= 0) {
  262. + printk("%s - I2C bus is never busy after START. Timeout is %d \n", __FUNCTION__, timeout);
  263. + goto check_rc;
  264. + }
  265. +
  266. + } else {
  267. + /* this is repeat START */
  268. + udelay(500); /* need some delay before repeat start */
  269. + *MCF_I2C_I2CR |= (MCF_I2C_I2CR_MSTA | MCF_I2C_I2CR_RSTA);
  270. + }
  271. +
  272. +
  273. + /* combine the R/W bit and the 7 bit target address and put it onto
  274. + the I2C bus */
  275. + *MCF_I2C_I2DR = ((target_address & 0x7F) << 1) | (read_write == I2C_SMBUS_WRITE ? 0x00 : 0x01);
  276. +
  277. + /* wait for bus transfer to complete */
  278. + /* when one byte transfer is completed, IIF set at the faling edge of
  279. + the 9th clock */
  280. + timeout = 500;
  281. + while (timeout-- && !(*MCF_I2C_I2SR & MCF_I2C_I2SR_IIF))
  282. + udelay(1);
  283. + if (timeout <= 0)
  284. + printk("%s - I2C IIF never set. Timeout is %d \n", __FUNCTION__, timeout);
  285. +
  286. +
  287. +check_rc:
  288. + /* reset the interrupt bit */
  289. + *MCF_I2C_I2SR &= ~MCF_I2C_I2SR_IIF;
  290. +
  291. + if (timeout <= 0)
  292. + return -1;
  293. + else
  294. + return 0;
  295. +};
  296. +
  297. +
  298. +/*
  299. + * 5282 SMBUS supporting functions
  300. + */
  301. +
  302. +static s32 coldfire_i2c_access(struct i2c_adapter *adap, u16 addr,
  303. + unsigned short flags, char read_write,
  304. + u8 command, int size, union i2c_smbus_data *data)
  305. +{
  306. + int rc = 0;
  307. + u8 rxData, tempRxData[2];
  308. +
  309. + switch (size) {
  310. + case I2C_SMBUS_QUICK:
  311. + rc = coldfire_i2c_start(read_write, addr, FIRST_START); /* generate START */
  312. + break;
  313. + case I2C_SMBUS_BYTE:
  314. + rc = coldfire_i2c_start(read_write, addr, FIRST_START);
  315. + *MCF_I2C_I2CR |= MCF_I2C_I2CR_TXAK; /*generate NA */
  316. + if (read_write == I2C_SMBUS_WRITE)
  317. + rc += coldfire_write_data(command);
  318. + else {
  319. + coldfire_read_data(&rxData, NACK);/*dummy read*/
  320. + rc += coldfire_read_data(&rxData, NACK);
  321. + data->byte = rxData;
  322. + }
  323. + *MCF_I2C_I2CR &= ~MCF_I2C_I2CR_TXAK; /* reset ACK bit */
  324. + break;
  325. + case I2C_SMBUS_BYTE_DATA:
  326. + rc = coldfire_i2c_start(I2C_SMBUS_WRITE, addr, FIRST_START);
  327. + rc += coldfire_write_data(command);
  328. + if (read_write == I2C_SMBUS_WRITE)
  329. + rc += coldfire_write_data(data->byte);
  330. + else {
  331. + /* This is SMBus READ Byte Data Request.
  332. + Perform REPEAT START */
  333. + rc += coldfire_i2c_start(I2C_SMBUS_READ, addr,
  334. + REPEAT_START);
  335. + coldfire_read_data(&rxData, ACK);/* dummy read*/
  336. + /* Disable Acknowledge, generate STOP after
  337. + next byte transfer */
  338. + rc += coldfire_read_data(&rxData, NACK);
  339. + data->byte = rxData;
  340. + }
  341. + *MCF_I2C_I2CR &= ~MCF_I2C_I2CR_TXAK;/* reset to normal ACk */
  342. + break;
  343. + case I2C_SMBUS_PROC_CALL:
  344. + case I2C_SMBUS_WORD_DATA:
  345. + dev_info(&adap->dev, "size = I2C_SMBUS_WORD_DATA \n");
  346. + rc = coldfire_i2c_start(I2C_SMBUS_WRITE, addr,
  347. + FIRST_START);
  348. + rc += coldfire_write_data(command);
  349. + if (read_write == I2C_SMBUS_WRITE) {
  350. + rc += coldfire_write_data(data->word & 0x00FF);
  351. + rc += coldfire_write_data((data->word & 0x00FF) >> 8);
  352. + } else {
  353. + /* This is SMBUS READ WORD request.
  354. + Peform REPEAT START */
  355. + rc += coldfire_i2c_start(I2C_SMBUS_READ, addr,
  356. + REPEAT_START);
  357. + coldfire_read_data(&rxData, ACK);/* dummy read*/
  358. + /* Disable Acknowledge, generate STOP after
  359. + next byte transfer */
  360. + /* read the MS byte from the device */
  361. + rc += coldfire_read_data(&rxData, NACK);
  362. + tempRxData[1] = rxData;
  363. + /* read the LS byte from the device */
  364. + rc += coldfire_read_data(&rxData, NACK);
  365. + tempRxData[0] = rxData;
  366. + /* the host driver expect little endian
  367. + convention. Swap the byte */
  368. + data->word = (tempRxData[0] << 8)|tempRxData[1];
  369. + }
  370. + *MCF_I2C_I2CR &= ~MCF_I2C_I2CR_TXAK;
  371. + break;
  372. + case I2C_SMBUS_BLOCK_DATA:
  373. + /* Not done yet */
  374. + break;
  375. + default:
  376. + printk("Unsupported I2C size \n");
  377. + rc = -1;
  378. + break;
  379. + };
  380. +
  381. + /* Generate a STOP and put I2C module into slave mode */
  382. + *MCF_I2C_I2CR &= ~MCF_I2C_I2CR_MSTA;
  383. +
  384. + /* restore interrupt */
  385. + *MCF_I2C_I2CR |= MCF_I2C_I2CR_IIEN;
  386. +
  387. + if (rc < 0)
  388. + return -1;
  389. + else
  390. + return 0;
  391. +};
  392. +
  393. +
  394. +/*
  395. + * List the SMBUS functions supported by this I2C adaptor
  396. + * Also tell the I2C Subsystem that we are able of master_xfer()
  397. + */
  398. +static u32 coldfire_func(struct i2c_adapter *adapter)
  399. +{
  400. + return(I2C_FUNC_SMBUS_QUICK |
  401. + I2C_FUNC_SMBUS_BYTE |
  402. + I2C_FUNC_SMBUS_PROC_CALL |
  403. + I2C_FUNC_SMBUS_BYTE_DATA |
  404. + I2C_FUNC_SMBUS_WORD_DATA |
  405. + I2C_FUNC_I2C |
  406. + I2C_FUNC_SMBUS_BLOCK_DATA);
  407. +};
  408. +
  409. +static int coldfire_i2c_master(struct i2c_adapter *adap,struct i2c_msg *msgs,
  410. + int num)
  411. +{
  412. + u8 dummyRead;
  413. + struct i2c_msg *p;
  414. + int i, err = 0;
  415. + int ic=0;
  416. +
  417. + lastaddr = 0;
  418. + lastop = 8;
  419. +
  420. + /* disable the IRQ, we are doing polling */
  421. + *MCF_I2C_I2CR &= ~MCF_I2C_I2CR_IIEN;
  422. +
  423. + dev_dbg(&adap->dev,"Num of actions: %d\n", num);
  424. +
  425. + for (i = 0; !err && i < num; i++) {
  426. + p = &msgs[i];
  427. +
  428. +
  429. + if (!p->len)
  430. + {
  431. + dev_dbg(&adap->dev,"p->len == 0!\n");
  432. + continue;
  433. + }
  434. + /*
  435. + * Generate a new Start, if the target address differs from
  436. + * the last target, generate a stop in this case first
  437. + */
  438. + if(p->addr != lastaddr)
  439. + {
  440. + err = coldfire_do_first_start(p->addr,p->flags);
  441. + if(err)
  442. + {
  443. + dev_dbg(&adap->dev,"First Init failed!\n");
  444. + break;
  445. + }
  446. + }
  447. +
  448. + else if((p->flags & I2C_M_RD) != lastop)
  449. + {
  450. + /*
  451. + * If the Operational Mode changed, we need to do this
  452. + * here ...
  453. + */
  454. + dev_dbg(&adap->dev,"%s(): Direction changed, was: %d; is now: %d\n", __FUNCTION__, lastop, p->flags & I2C_M_RD);
  455. +
  456. + /* Last op was an read, now it's write: complete stop
  457. + and reinit */
  458. + if (lastop & I2C_M_RD)
  459. + {
  460. + dev_dbg(&adap->dev,"%s(): The device is in read state, we must reset!\n", __FUNCTION__);
  461. + if((err = coldfire_do_first_start(p->addr,p->flags)))
  462. + break;
  463. + }
  464. + else
  465. + {
  466. + dev_dbg(&adap->dev,"%s(): We switchted to read mode\n",__FUNCTION__);
  467. + if((err = coldfire_i2c_start((p->flags & I2C_M_RD) ? I2C_SMBUS_READ : I2C_SMBUS_WRITE,
  468. + p->addr, REPEAT_START)))
  469. + break;
  470. + }
  471. +
  472. + lastop = p->flags & I2C_M_RD; /* Save the last op */
  473. + }
  474. +
  475. + if (p->flags & I2C_M_RD)
  476. + {
  477. + /*
  478. + * When ever we get here, a new session was activated,
  479. + * so read a dummy byte
  480. + */
  481. + coldfire_read_data(&dummyRead, ACK);
  482. + /*
  483. + * read p->len -1 bytes with ACK to the slave,
  484. + * read the last byte without the ACK, to inform him
  485. + * about the stop afterwards
  486. + */
  487. + ic = 0;
  488. + while(!err && (ic < p->len-1 ))
  489. + {
  490. + err = coldfire_read_data(p->buf+ic, ACK );
  491. + ic++;
  492. + }
  493. + if(!err)
  494. + err = coldfire_read_data(p->buf+ic, NACK);
  495. + dev_dbg(&coldfire_adapter.dev,"read: %2x\n",p->buf[ic]);
  496. + }
  497. + else
  498. + {
  499. + if(p->len == 2)
  500. + dev_dbg(&coldfire_adapter.dev,"writing: 0x %2x %2x\n", p->buf[0], p->buf[1]);
  501. +
  502. + /*
  503. + * Write data to the slave
  504. + */
  505. + for(ic=0; !err && ic < p->len; ic++)
  506. + {
  507. + err = coldfire_write_data(p->buf[ic]);
  508. + if(err)
  509. + {
  510. + dev_dbg(&coldfire_adapter.dev, "Failed to write data\n");
  511. + }
  512. + }
  513. + }
  514. + }
  515. +
  516. + /*
  517. + * Put the device into slave mode to enable the STOP Generation
  518. + * (the RTC needs this)
  519. + */
  520. + *MCF_I2C_I2CR &= ~MCF_I2C_I2CR_MSTA;
  521. +
  522. + *MCF_I2C_I2CR &= ~MCF_I2C_I2CR_TXAK; /* reset the ACK bit */
  523. +
  524. + /* restore interrupt */
  525. + *MCF_I2C_I2CR |= MCF_I2C_I2CR_IIEN;
  526. +
  527. + /* Return the number of messages processed, or the error code. */
  528. + if (err == 0)
  529. + err = num;
  530. + return err;
  531. +}
  532. +
  533. +
  534. +/*
  535. + * Initalize the 5282 I2C module
  536. + * Disable the 5282 I2C interrupt capability. Just use callback
  537. + */
  538. +
  539. +static int __init i2c_coldfire_init(void)
  540. +{
  541. + int retval;
  542. + u8 dummyRead;
  543. +
  544. +#if defined(CONFIG_M532x) || defined(CONFIG_M5445X)
  545. + /*
  546. + * Initialize the GPIOs for I2C
  547. + */
  548. + MCF_GPIO_PAR_FECI2C |= (0
  549. + | MCF_GPIO_PAR_FECI2C_PAR_SDA(3)
  550. + | MCF_GPIO_PAR_FECI2C_PAR_SCL(3));
  551. +#elif defined(CONFIG_M5253)
  552. + {
  553. + volatile u32 *reg;
  554. + /* GPIO Bit 41 = SCL0, Bit 42 = SDA0 */
  555. + reg = (volatile u32 *)(MCF_MBAR2 + MCFSIM2_GPIO1FUNC);
  556. + *reg &= 0xFFFFF9FF;
  557. + }
  558. +#else
  559. + /* Initialize PASP0 and PASP1 to I2C functions, 5282 user guide 26-19 */
  560. + /* Port AS Pin Assignment Register (PASPAR) */
  561. + /* PASPA1 = 11 = AS1 pin is I2C SDA */
  562. + /* PASPA0 = 11 = AS0 pin is I2C SCL */
  563. + *MCF_GPIO_PASPAR |= 0x000F; /* u16 declaration */
  564. +#endif
  565. +
  566. +
  567. + /* Set transmission frequency 0x15 = ~100kHz */
  568. + *MCF_I2C_I2FDR = 0x15;
  569. +
  570. + /* set the 5282 I2C slave address though we never use it */
  571. + *MCF_I2C_I2ADR = 0x6A;
  572. +
  573. + /* Enable I2C module and if IBB is set, do the special initialzation */
  574. + /* procedures as are documented at the 5282 User Guide page 24-11 */
  575. + *MCF_I2C_I2CR |= MCF_I2C_I2CR_IEN;
  576. + if ((*MCF_I2C_I2SR & MCF_I2C_I2SR_IBB) == 1) {
  577. + printk("%s - do special 5282 I2C init procedures \n",
  578. + __FUNCTION__);
  579. + *MCF_I2C_I2CR = 0x00;
  580. + *MCF_I2C_I2CR = 0xA0;
  581. + dummyRead = *MCF_I2C_I2DR;
  582. + *MCF_I2C_I2SR = 0x00;
  583. + *MCF_I2C_I2CR = 0x00;
  584. + }
  585. +
  586. + /* default I2C mode is - slave and receive */
  587. + *MCF_I2C_I2CR &= ~(MCF_I2C_I2CR_MSTA | MCF_I2C_I2CR_MTX);
  588. +
  589. + coldfire_adapter.dev.parent = &platform_bus;
  590. + retval = i2c_add_adapter(&coldfire_adapter);
  591. +
  592. + if (retval < 0)
  593. + printk("%s - return code is: %d \n", __FUNCTION__, retval);
  594. +
  595. + return retval;
  596. +};
  597. +
  598. +
  599. +/*
  600. + * I2C module exit function
  601. + */
  602. +
  603. +static void __exit i2c_coldfire_exit(void)
  604. +{
  605. + /* disable I2C and Interrupt */
  606. + *MCF_I2C_I2CR &= ~(MCF_I2C_I2CR_IEN | MCF_I2C_I2CR_IIEN);
  607. + i2c_del_adapter(&coldfire_adapter);
  608. +
  609. +};
  610. +
  611. +
  612. +MODULE_AUTHOR("Derek CL Cheung <[email protected]>");
  613. +MODULE_DESCRIPTION("MCF5282 I2C adaptor");
  614. +MODULE_LICENSE("GPL");
  615. +
  616. +module_init(i2c_coldfire_init);
  617. +module_exit(i2c_coldfire_exit);
  618. --- /dev/null
  619. +++ b/drivers/i2c/busses/i2c-mcf.h
  620. @@ -0,0 +1,75 @@
  621. +/*
  622. + i2c-mcf.h - header file for i2c-mcf.c
  623. +
  624. + Copyright (c) 2005, Derek CL Cheung <[email protected]>
  625. + <http://www3.sympatico.ca/derek.cheung>
  626. +
  627. + Copyright (c) 2006-2007, emlix
  628. + Sebastian Hess <[email protected]>
  629. +
  630. + Copyright (c) 2006-2007 Freescale Semiconductor, Inc
  631. + Yaroslav Vinogradov <[email protected]>
  632. + Matt Waddel <[email protected]>
  633. +
  634. + This program is free software; you can redistribute it and/or modify
  635. + it under the terms of the GNU General Public License as published by
  636. + the Free Software Foundation; either version 2 of the License, or
  637. + (at your option) any later version.
  638. +
  639. + This program is distributed in the hope that it will be useful,
  640. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  641. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  642. + GNU General Public License for more details.
  643. +
  644. + You should have received a copy of the GNU General Public License
  645. + along with this program; if not, write to the Free Software
  646. + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  647. +
  648. + Changes:
  649. + v0.1 26 March 2005
  650. + Initial Release - developed on uClinux with 2.6.9 kernel
  651. + v0.2 29 May 2006
  652. + Modified to be more generic and added support for
  653. + i2c_master_xfer
  654. +*/
  655. +
  656. +
  657. +#ifndef __I2C_MCF_H__
  658. +#define __I2C_MCF_H__
  659. +
  660. +enum I2C_START_TYPE { FIRST_START, REPEAT_START };
  661. +enum I2C_ACK_TYPE { ACK, NACK};
  662. +
  663. +/* Function prototypes */
  664. +static u32 coldfire_func(struct i2c_adapter *adapter);
  665. +static s32 coldfire_i2c_access(struct i2c_adapter *adap, u16 address,
  666. + unsigned short flags, char read_write,
  667. + u8 command, int size, union i2c_smbus_data *data);
  668. +static int coldfire_write_data(const u8 data);
  669. +static int coldfire_i2c_start(const char read_write, const u16 target_address, const enum I2C_START_TYPE i2c_start);
  670. +static int coldfire_read_data(u8 * const rxData, const enum I2C_ACK_TYPE ackType);
  671. +static int coldfire_i2c_master(struct i2c_adapter *adap,struct i2c_msg *msgs, int num);
  672. +void dumpReg(char *, u16 addr, u8 data);
  673. +
  674. +#define MCF_I2C_I2ADR_ADDR(x) (((x)&0x7F)<<0x01)
  675. +#define MCF_I2C_I2FDR_IC(x) (((x)&0x3F))
  676. +
  677. +/* I2C Control Register */
  678. +#define MCF_I2C_I2CR_IEN (0x80) /* I2C enable */
  679. +#define MCF_I2C_I2CR_IIEN (0x40) /* interrupt enable */
  680. +#define MCF_I2C_I2CR_MSTA (0x20) /* master/slave mode */
  681. +#define MCF_I2C_I2CR_MTX (0x10) /* transmit/receive mode */
  682. +#define MCF_I2C_I2CR_TXAK (0x08) /* transmit acknowledge enable */
  683. +#define MCF_I2C_I2CR_RSTA (0x04) /* repeat start */
  684. +
  685. +/* I2C Status Register */
  686. +#define MCF_I2C_I2SR_ICF (0x80) /* data transfer bit */
  687. +#define MCF_I2C_I2SR_IAAS (0x40) /* I2C addressed as a slave */
  688. +#define MCF_I2C_I2SR_IBB (0x20) /* I2C bus busy */
  689. +#define MCF_I2C_I2SR_IAL (0x10) /* aribitration lost */
  690. +#define MCF_I2C_I2SR_SRW (0x04) /* slave read/write */
  691. +#define MCF_I2C_I2SR_IIF (0x02) /* I2C interrupt */
  692. +#define MCF_I2C_I2SR_RXAK (0x01) /* received acknowledge */
  693. +
  694. +/********************************************************************/
  695. +#endif /* __I2C_MCF_H__ */