i2c-octeon.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /*
  2. * (C) Copyright 2009-2010
  3. * Nokia Siemens Networks, michael.lawnick.ext@nsn.com
  4. *
  5. * Portions Copyright (C) 2010 Cavium Networks, Inc.
  6. *
  7. * This is a driver for the i2c adapter in Cavium Networks' OCTEON processors.
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/sched.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <linux/i2c.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/delay.h>
  21. #include <linux/platform_device.h>
  22. #include <asm/octeon/octeon.h>
  23. #define DRV_NAME "i2c-octeon"
  24. /* The previous out-of-tree version was implicitly version 1.0. */
  25. #define DRV_VERSION "2.0"
  26. /* register offsets */
  27. #define SW_TWSI 0x00
  28. #define TWSI_INT 0x10
  29. /* Controller command patterns */
  30. #define SW_TWSI_V 0x8000000000000000ull
  31. #define SW_TWSI_EOP_TWSI_DATA 0x0C00000100000000ull
  32. #define SW_TWSI_EOP_TWSI_CTL 0x0C00000200000000ull
  33. #define SW_TWSI_EOP_TWSI_CLKCTL 0x0C00000300000000ull
  34. #define SW_TWSI_EOP_TWSI_STAT 0x0C00000300000000ull
  35. #define SW_TWSI_EOP_TWSI_RST 0x0C00000700000000ull
  36. #define SW_TWSI_OP_TWSI_CLK 0x0800000000000000ull
  37. #define SW_TWSI_R 0x0100000000000000ull
  38. /* Controller command and status bits */
  39. #define TWSI_CTL_CE 0x80
  40. #define TWSI_CTL_ENAB 0x40
  41. #define TWSI_CTL_STA 0x20
  42. #define TWSI_CTL_STP 0x10
  43. #define TWSI_CTL_IFLG 0x08
  44. #define TWSI_CTL_AAK 0x04
  45. /* Some status values */
  46. #define STAT_START 0x08
  47. #define STAT_RSTART 0x10
  48. #define STAT_TXADDR_ACK 0x18
  49. #define STAT_TXDATA_ACK 0x28
  50. #define STAT_RXADDR_ACK 0x40
  51. #define STAT_RXDATA_ACK 0x50
  52. #define STAT_IDLE 0xF8
  53. struct octeon_i2c {
  54. wait_queue_head_t queue;
  55. struct i2c_adapter adap;
  56. int irq;
  57. int twsi_freq;
  58. int sys_freq;
  59. resource_size_t twsi_phys;
  60. void __iomem *twsi_base;
  61. resource_size_t regsize;
  62. struct device *dev;
  63. };
  64. /**
  65. * octeon_i2c_write_sw - write an I2C core register.
  66. * @i2c: The struct octeon_i2c.
  67. * @eop_reg: Register selector.
  68. * @data: Value to be written.
  69. *
  70. * The I2C core registers are accessed indirectly via the SW_TWSI CSR.
  71. */
  72. static void octeon_i2c_write_sw(struct octeon_i2c *i2c,
  73. u64 eop_reg,
  74. u8 data)
  75. {
  76. u64 tmp;
  77. __raw_writeq(SW_TWSI_V | eop_reg | data, i2c->twsi_base + SW_TWSI);
  78. do {
  79. tmp = __raw_readq(i2c->twsi_base + SW_TWSI);
  80. } while ((tmp & SW_TWSI_V) != 0);
  81. }
  82. /**
  83. * octeon_i2c_read_sw - write an I2C core register.
  84. * @i2c: The struct octeon_i2c.
  85. * @eop_reg: Register selector.
  86. *
  87. * Returns the data.
  88. *
  89. * The I2C core registers are accessed indirectly via the SW_TWSI CSR.
  90. */
  91. static u8 octeon_i2c_read_sw(struct octeon_i2c *i2c, u64 eop_reg)
  92. {
  93. u64 tmp;
  94. __raw_writeq(SW_TWSI_V | eop_reg | SW_TWSI_R, i2c->twsi_base + SW_TWSI);
  95. do {
  96. tmp = __raw_readq(i2c->twsi_base + SW_TWSI);
  97. } while ((tmp & SW_TWSI_V) != 0);
  98. return tmp & 0xFF;
  99. }
  100. /**
  101. * octeon_i2c_write_int - write the TWSI_INT register
  102. * @i2c: The struct octeon_i2c.
  103. * @data: Value to be written.
  104. */
  105. static void octeon_i2c_write_int(struct octeon_i2c *i2c, u64 data)
  106. {
  107. u64 tmp;
  108. __raw_writeq(data, i2c->twsi_base + TWSI_INT);
  109. tmp = __raw_readq(i2c->twsi_base + TWSI_INT);
  110. }
  111. /**
  112. * octeon_i2c_int_enable - enable the TS interrupt.
  113. * @i2c: The struct octeon_i2c.
  114. *
  115. * The interrupt will be asserted when there is non-STAT_IDLE state in
  116. * the SW_TWSI_EOP_TWSI_STAT register.
  117. */
  118. static void octeon_i2c_int_enable(struct octeon_i2c *i2c)
  119. {
  120. octeon_i2c_write_int(i2c, 0x40);
  121. }
  122. /**
  123. * octeon_i2c_int_disable - disable the TS interrupt.
  124. * @i2c: The struct octeon_i2c.
  125. */
  126. static void octeon_i2c_int_disable(struct octeon_i2c *i2c)
  127. {
  128. octeon_i2c_write_int(i2c, 0);
  129. }
  130. /**
  131. * octeon_i2c_unblock - unblock the bus.
  132. * @i2c: The struct octeon_i2c.
  133. *
  134. * If there was a reset while a device was driving 0 to bus,
  135. * bus is blocked. We toggle it free manually by some clock
  136. * cycles and send a stop.
  137. */
  138. static void octeon_i2c_unblock(struct octeon_i2c *i2c)
  139. {
  140. int i;
  141. dev_dbg(i2c->dev, "%s\n", __func__);
  142. for (i = 0; i < 9; i++) {
  143. octeon_i2c_write_int(i2c, 0x0);
  144. udelay(5);
  145. octeon_i2c_write_int(i2c, 0x200);
  146. udelay(5);
  147. }
  148. octeon_i2c_write_int(i2c, 0x300);
  149. udelay(5);
  150. octeon_i2c_write_int(i2c, 0x100);
  151. udelay(5);
  152. octeon_i2c_write_int(i2c, 0x0);
  153. }
  154. /**
  155. * octeon_i2c_isr - the interrupt service routine.
  156. * @int: The irq, unused.
  157. * @dev_id: Our struct octeon_i2c.
  158. */
  159. static irqreturn_t octeon_i2c_isr(int irq, void *dev_id)
  160. {
  161. struct octeon_i2c *i2c = dev_id;
  162. octeon_i2c_int_disable(i2c);
  163. wake_up_interruptible(&i2c->queue);
  164. return IRQ_HANDLED;
  165. }
  166. static int octeon_i2c_test_iflg(struct octeon_i2c *i2c)
  167. {
  168. return (octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_CTL) & TWSI_CTL_IFLG) != 0;
  169. }
  170. /**
  171. * octeon_i2c_wait - wait for the IFLG to be set.
  172. * @i2c: The struct octeon_i2c.
  173. *
  174. * Returns 0 on success, otherwise a negative errno.
  175. */
  176. static int octeon_i2c_wait(struct octeon_i2c *i2c)
  177. {
  178. int result;
  179. octeon_i2c_int_enable(i2c);
  180. result = wait_event_interruptible_timeout(i2c->queue,
  181. octeon_i2c_test_iflg(i2c),
  182. i2c->adap.timeout);
  183. octeon_i2c_int_disable(i2c);
  184. if (result < 0) {
  185. dev_dbg(i2c->dev, "%s: wait interrupted\n", __func__);
  186. return result;
  187. } else if (result == 0) {
  188. dev_dbg(i2c->dev, "%s: timeout\n", __func__);
  189. result = -ETIMEDOUT;
  190. }
  191. return 0;
  192. }
  193. /**
  194. * octeon_i2c_start - send START to the bus.
  195. * @i2c: The struct octeon_i2c.
  196. *
  197. * Returns 0 on success, otherwise a negative errno.
  198. */
  199. static int octeon_i2c_start(struct octeon_i2c *i2c)
  200. {
  201. u8 data;
  202. int result;
  203. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL,
  204. TWSI_CTL_ENAB | TWSI_CTL_STA);
  205. result = octeon_i2c_wait(i2c);
  206. if (result) {
  207. if (octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT) == STAT_IDLE) {
  208. /*
  209. * Controller refused to send start flag May
  210. * be a client is holding SDA low - let's try
  211. * to free it.
  212. */
  213. octeon_i2c_unblock(i2c);
  214. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL,
  215. TWSI_CTL_ENAB | TWSI_CTL_STA);
  216. result = octeon_i2c_wait(i2c);
  217. }
  218. if (result)
  219. return result;
  220. }
  221. data = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT);
  222. if ((data != STAT_START) && (data != STAT_RSTART)) {
  223. dev_err(i2c->dev, "%s: bad status (0x%x)\n", __func__, data);
  224. return -EIO;
  225. }
  226. return 0;
  227. }
  228. /**
  229. * octeon_i2c_stop - send STOP to the bus.
  230. * @i2c: The struct octeon_i2c.
  231. *
  232. * Returns 0 on success, otherwise a negative errno.
  233. */
  234. static int octeon_i2c_stop(struct octeon_i2c *i2c)
  235. {
  236. u8 data;
  237. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL,
  238. TWSI_CTL_ENAB | TWSI_CTL_STP);
  239. data = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT);
  240. if (data != STAT_IDLE) {
  241. dev_err(i2c->dev, "%s: bad status(0x%x)\n", __func__, data);
  242. return -EIO;
  243. }
  244. return 0;
  245. }
  246. /**
  247. * octeon_i2c_write - send data to the bus.
  248. * @i2c: The struct octeon_i2c.
  249. * @target: Target address.
  250. * @data: Pointer to the data to be sent.
  251. * @length: Length of the data.
  252. *
  253. * The address is sent over the bus, then the data.
  254. *
  255. * Returns 0 on success, otherwise a negative errno.
  256. */
  257. static int octeon_i2c_write(struct octeon_i2c *i2c, int target,
  258. const u8 *data, int length)
  259. {
  260. int i, result;
  261. u8 tmp;
  262. result = octeon_i2c_start(i2c);
  263. if (result)
  264. return result;
  265. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, target << 1);
  266. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB);
  267. result = octeon_i2c_wait(i2c);
  268. if (result)
  269. return result;
  270. for (i = 0; i < length; i++) {
  271. tmp = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT);
  272. if ((tmp != STAT_TXADDR_ACK) && (tmp != STAT_TXDATA_ACK)) {
  273. dev_err(i2c->dev,
  274. "%s: bad status before write (0x%x)\n",
  275. __func__, tmp);
  276. return -EIO;
  277. }
  278. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, data[i]);
  279. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB);
  280. result = octeon_i2c_wait(i2c);
  281. if (result)
  282. return result;
  283. }
  284. return 0;
  285. }
  286. /**
  287. * octeon_i2c_read - receive data from the bus.
  288. * @i2c: The struct octeon_i2c.
  289. * @target: Target address.
  290. * @data: Pointer to the location to store the datae .
  291. * @length: Length of the data.
  292. *
  293. * The address is sent over the bus, then the data is read.
  294. *
  295. * Returns 0 on success, otherwise a negative errno.
  296. */
  297. static int octeon_i2c_read(struct octeon_i2c *i2c, int target,
  298. u8 *data, int length)
  299. {
  300. int i, result;
  301. u8 tmp;
  302. if (length < 1)
  303. return -EINVAL;
  304. result = octeon_i2c_start(i2c);
  305. if (result)
  306. return result;
  307. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, (target<<1) | 1);
  308. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB);
  309. result = octeon_i2c_wait(i2c);
  310. if (result)
  311. return result;
  312. for (i = 0; i < length; i++) {
  313. tmp = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT);
  314. if ((tmp != STAT_RXDATA_ACK) && (tmp != STAT_RXADDR_ACK)) {
  315. dev_err(i2c->dev,
  316. "%s: bad status before read (0x%x)\n",
  317. __func__, tmp);
  318. return -EIO;
  319. }
  320. if (i+1 < length)
  321. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL,
  322. TWSI_CTL_ENAB | TWSI_CTL_AAK);
  323. else
  324. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL,
  325. TWSI_CTL_ENAB);
  326. result = octeon_i2c_wait(i2c);
  327. if (result)
  328. return result;
  329. data[i] = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_DATA);
  330. }
  331. return 0;
  332. }
  333. /**
  334. * octeon_i2c_xfer - The driver's master_xfer function.
  335. * @adap: Pointer to the i2c_adapter structure.
  336. * @msgs: Pointer to the messages to be processed.
  337. * @num: Length of the MSGS array.
  338. *
  339. * Returns the number of messages processed, or a negative errno on
  340. * failure.
  341. */
  342. static int octeon_i2c_xfer(struct i2c_adapter *adap,
  343. struct i2c_msg *msgs,
  344. int num)
  345. {
  346. struct i2c_msg *pmsg;
  347. int i;
  348. int ret = 0;
  349. struct octeon_i2c *i2c = i2c_get_adapdata(adap);
  350. for (i = 0; ret == 0 && i < num; i++) {
  351. pmsg = &msgs[i];
  352. dev_dbg(i2c->dev,
  353. "Doing %s %d byte(s) to/from 0x%02x - %d of %d messages\n",
  354. pmsg->flags & I2C_M_RD ? "read" : "write",
  355. pmsg->len, pmsg->addr, i + 1, num);
  356. if (pmsg->flags & I2C_M_RD)
  357. ret = octeon_i2c_read(i2c, pmsg->addr, pmsg->buf,
  358. pmsg->len);
  359. else
  360. ret = octeon_i2c_write(i2c, pmsg->addr, pmsg->buf,
  361. pmsg->len);
  362. }
  363. octeon_i2c_stop(i2c);
  364. return (ret != 0) ? ret : num;
  365. }
  366. static u32 octeon_i2c_functionality(struct i2c_adapter *adap)
  367. {
  368. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
  369. }
  370. static const struct i2c_algorithm octeon_i2c_algo = {
  371. .master_xfer = octeon_i2c_xfer,
  372. .functionality = octeon_i2c_functionality,
  373. };
  374. static struct i2c_adapter octeon_i2c_ops = {
  375. .owner = THIS_MODULE,
  376. .name = "OCTEON adapter",
  377. .algo = &octeon_i2c_algo,
  378. .timeout = 2,
  379. };
  380. /**
  381. * octeon_i2c_setclock - Calculate and set clock divisors.
  382. */
  383. static int __init octeon_i2c_setclock(struct octeon_i2c *i2c)
  384. {
  385. int tclk, thp_base, inc, thp_idx, mdiv_idx, ndiv_idx, foscl, diff;
  386. int thp = 0x18, mdiv = 2, ndiv = 0, delta_hz = 1000000;
  387. for (ndiv_idx = 0; ndiv_idx < 8 && delta_hz != 0; ndiv_idx++) {
  388. /*
  389. * An mdiv value of less than 2 seems to not work well
  390. * with ds1337 RTCs, so we constrain it to larger
  391. * values.
  392. */
  393. for (mdiv_idx = 15; mdiv_idx >= 2 && delta_hz != 0; mdiv_idx--) {
  394. /*
  395. * For given ndiv and mdiv values check the
  396. * two closest thp values.
  397. */
  398. tclk = i2c->twsi_freq * (mdiv_idx + 1) * 10;
  399. tclk *= (1 << ndiv_idx);
  400. thp_base = (i2c->sys_freq / (tclk * 2)) - 1;
  401. for (inc = 0; inc <= 1; inc++) {
  402. thp_idx = thp_base + inc;
  403. if (thp_idx < 5 || thp_idx > 0xff)
  404. continue;
  405. foscl = i2c->sys_freq / (2 * (thp_idx + 1));
  406. foscl = foscl / (1 << ndiv_idx);
  407. foscl = foscl / (mdiv_idx + 1) / 10;
  408. diff = abs(foscl - i2c->twsi_freq);
  409. if (diff < delta_hz) {
  410. delta_hz = diff;
  411. thp = thp_idx;
  412. mdiv = mdiv_idx;
  413. ndiv = ndiv_idx;
  414. }
  415. }
  416. }
  417. }
  418. octeon_i2c_write_sw(i2c, SW_TWSI_OP_TWSI_CLK, thp);
  419. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CLKCTL, (mdiv << 3) | ndiv);
  420. return 0;
  421. }
  422. static int __init octeon_i2c_initlowlevel(struct octeon_i2c *i2c)
  423. {
  424. u8 status;
  425. int tries;
  426. /* disable high level controller, enable bus access */
  427. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB);
  428. /* reset controller */
  429. octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_RST, 0);
  430. for (tries = 10; tries; tries--) {
  431. udelay(1);
  432. status = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT);
  433. if (status == STAT_IDLE)
  434. return 0;
  435. }
  436. dev_err(i2c->dev, "%s: TWSI_RST failed! (0x%x)\n", __func__, status);
  437. return -EIO;
  438. }
  439. static int __devinit octeon_i2c_probe(struct platform_device *pdev)
  440. {
  441. int irq, result = 0;
  442. struct octeon_i2c *i2c;
  443. struct octeon_i2c_data *i2c_data;
  444. struct resource *res_mem;
  445. /* All adaptors have an irq. */
  446. irq = platform_get_irq(pdev, 0);
  447. if (irq < 0)
  448. return irq;
  449. i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
  450. if (!i2c) {
  451. dev_err(&pdev->dev, "kzalloc failed\n");
  452. result = -ENOMEM;
  453. goto out;
  454. }
  455. i2c->dev = &pdev->dev;
  456. i2c_data = pdev->dev.platform_data;
  457. res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  458. if (res_mem == NULL) {
  459. dev_err(i2c->dev, "found no memory resource\n");
  460. result = -ENXIO;
  461. goto fail_region;
  462. }
  463. if (i2c_data == NULL) {
  464. dev_err(i2c->dev, "no I2C frequency data\n");
  465. result = -ENXIO;
  466. goto fail_region;
  467. }
  468. i2c->twsi_phys = res_mem->start;
  469. i2c->regsize = resource_size(res_mem);
  470. i2c->twsi_freq = i2c_data->i2c_freq;
  471. i2c->sys_freq = i2c_data->sys_freq;
  472. if (!request_mem_region(i2c->twsi_phys, i2c->regsize, res_mem->name)) {
  473. dev_err(i2c->dev, "request_mem_region failed\n");
  474. goto fail_region;
  475. }
  476. i2c->twsi_base = ioremap(i2c->twsi_phys, i2c->regsize);
  477. init_waitqueue_head(&i2c->queue);
  478. i2c->irq = irq;
  479. result = request_irq(i2c->irq, octeon_i2c_isr, 0, DRV_NAME, i2c);
  480. if (result < 0) {
  481. dev_err(i2c->dev, "failed to attach interrupt\n");
  482. goto fail_irq;
  483. }
  484. result = octeon_i2c_initlowlevel(i2c);
  485. if (result) {
  486. dev_err(i2c->dev, "init low level failed\n");
  487. goto fail_add;
  488. }
  489. result = octeon_i2c_setclock(i2c);
  490. if (result) {
  491. dev_err(i2c->dev, "clock init failed\n");
  492. goto fail_add;
  493. }
  494. i2c->adap = octeon_i2c_ops;
  495. i2c->adap.dev.parent = &pdev->dev;
  496. i2c->adap.nr = pdev->id >= 0 ? pdev->id : 0;
  497. i2c_set_adapdata(&i2c->adap, i2c);
  498. platform_set_drvdata(pdev, i2c);
  499. result = i2c_add_numbered_adapter(&i2c->adap);
  500. if (result < 0) {
  501. dev_err(i2c->dev, "failed to add adapter\n");
  502. goto fail_add;
  503. }
  504. dev_info(i2c->dev, "version %s\n", DRV_VERSION);
  505. return result;
  506. fail_add:
  507. platform_set_drvdata(pdev, NULL);
  508. free_irq(i2c->irq, i2c);
  509. fail_irq:
  510. iounmap(i2c->twsi_base);
  511. release_mem_region(i2c->twsi_phys, i2c->regsize);
  512. fail_region:
  513. kfree(i2c);
  514. out:
  515. return result;
  516. };
  517. static int __devexit octeon_i2c_remove(struct platform_device *pdev)
  518. {
  519. struct octeon_i2c *i2c = platform_get_drvdata(pdev);
  520. i2c_del_adapter(&i2c->adap);
  521. platform_set_drvdata(pdev, NULL);
  522. free_irq(i2c->irq, i2c);
  523. iounmap(i2c->twsi_base);
  524. release_mem_region(i2c->twsi_phys, i2c->regsize);
  525. kfree(i2c);
  526. return 0;
  527. };
  528. static struct platform_driver octeon_i2c_driver = {
  529. .probe = octeon_i2c_probe,
  530. .remove = __devexit_p(octeon_i2c_remove),
  531. .driver = {
  532. .owner = THIS_MODULE,
  533. .name = DRV_NAME,
  534. },
  535. };
  536. static int __init octeon_i2c_init(void)
  537. {
  538. int rv;
  539. rv = platform_driver_register(&octeon_i2c_driver);
  540. return rv;
  541. }
  542. static void __exit octeon_i2c_exit(void)
  543. {
  544. platform_driver_unregister(&octeon_i2c_driver);
  545. }
  546. MODULE_AUTHOR("Michael Lawnick <michael.lawnick.ext@nsn.com>");
  547. MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors");
  548. MODULE_LICENSE("GPL");
  549. MODULE_VERSION(DRV_VERSION);
  550. MODULE_ALIAS("platform:" DRV_NAME);
  551. module_init(octeon_i2c_init);
  552. module_exit(octeon_i2c_exit);