i2c-mlxcpld.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /*
  3. * Mellanox i2c driver
  4. *
  5. * Copyright (C) 2016-2020 Mellanox Technologies
  6. */
  7. #include <linux/delay.h>
  8. #include <linux/i2c.h>
  9. #include <linux/init.h>
  10. #include <linux/io.h>
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_data/mlxreg.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/regmap.h>
  16. /* General defines */
  17. #define MLXPLAT_CPLD_LPC_I2C_BASE_ADDR 0x2000
  18. #define MLXCPLD_I2C_DEVICE_NAME "i2c_mlxcpld"
  19. #define MLXCPLD_I2C_VALID_FLAG (I2C_M_RECV_LEN | I2C_M_RD)
  20. #define MLXCPLD_I2C_BUS_NUM 1
  21. #define MLXCPLD_I2C_DATA_REG_SZ 36
  22. #define MLXCPLD_I2C_DATA_SZ_BIT BIT(5)
  23. #define MLXCPLD_I2C_DATA_SZ_MASK GENMASK(6, 5)
  24. #define MLXCPLD_I2C_SMBUS_BLK_BIT BIT(7)
  25. #define MLXCPLD_I2C_MAX_ADDR_LEN 4
  26. #define MLXCPLD_I2C_RETR_NUM 2
  27. #define MLXCPLD_I2C_XFER_TO 500000 /* usec */
  28. #define MLXCPLD_I2C_POLL_TIME 200 /* usec */
  29. /* LPC I2C registers */
  30. #define MLXCPLD_LPCI2C_CPBLTY_REG 0x0
  31. #define MLXCPLD_LPCI2C_CTRL_REG 0x1
  32. #define MLXCPLD_LPCI2C_HALF_CYC_REG 0x4
  33. #define MLXCPLD_LPCI2C_I2C_HOLD_REG 0x5
  34. #define MLXCPLD_LPCI2C_CMD_REG 0x6
  35. #define MLXCPLD_LPCI2C_NUM_DAT_REG 0x7
  36. #define MLXCPLD_LPCI2C_NUM_ADDR_REG 0x8
  37. #define MLXCPLD_LPCI2C_STATUS_REG 0x9
  38. #define MLXCPLD_LPCI2C_DATA_REG 0xa
  39. /* LPC I2C masks and parameters */
  40. #define MLXCPLD_LPCI2C_RST_SEL_MASK 0x1
  41. #define MLXCPLD_LPCI2C_TRANS_END 0x1
  42. #define MLXCPLD_LPCI2C_STATUS_NACK 0x10
  43. #define MLXCPLD_LPCI2C_NO_IND 0
  44. #define MLXCPLD_LPCI2C_ACK_IND 1
  45. #define MLXCPLD_LPCI2C_NACK_IND 2
  46. #define MLXCPLD_I2C_FREQ_1000KHZ_SET 0x04
  47. #define MLXCPLD_I2C_FREQ_400KHZ_SET 0x0e
  48. #define MLXCPLD_I2C_FREQ_100KHZ_SET 0x42
  49. enum mlxcpld_i2c_frequency {
  50. MLXCPLD_I2C_FREQ_1000KHZ = 1,
  51. MLXCPLD_I2C_FREQ_400KHZ = 2,
  52. MLXCPLD_I2C_FREQ_100KHZ = 3,
  53. };
  54. struct mlxcpld_i2c_curr_xfer {
  55. u8 cmd;
  56. u8 addr_width;
  57. u8 data_len;
  58. u8 msg_num;
  59. struct i2c_msg *msg;
  60. };
  61. struct mlxcpld_i2c_priv {
  62. struct i2c_adapter adap;
  63. u32 base_addr;
  64. struct mutex lock;
  65. struct mlxcpld_i2c_curr_xfer xfer;
  66. struct device *dev;
  67. bool smbus_block;
  68. int polling_time;
  69. };
  70. static void mlxcpld_i2c_lpc_write_buf(u8 *data, u8 len, u32 addr)
  71. {
  72. int i;
  73. for (i = 0; i < len - len % 4; i += 4)
  74. outl(*(u32 *)(data + i), addr + i);
  75. for (; i < len; ++i)
  76. outb(*(data + i), addr + i);
  77. }
  78. static void mlxcpld_i2c_lpc_read_buf(u8 *data, u8 len, u32 addr)
  79. {
  80. int i;
  81. for (i = 0; i < len - len % 4; i += 4)
  82. *(u32 *)(data + i) = inl(addr + i);
  83. for (; i < len; ++i)
  84. *(data + i) = inb(addr + i);
  85. }
  86. static void mlxcpld_i2c_read_comm(struct mlxcpld_i2c_priv *priv, u8 offs,
  87. u8 *data, u8 datalen)
  88. {
  89. u32 addr = priv->base_addr + offs;
  90. switch (datalen) {
  91. case 1:
  92. *(data) = inb(addr);
  93. break;
  94. case 2:
  95. *((u16 *)data) = inw(addr);
  96. break;
  97. case 3:
  98. *((u16 *)data) = inw(addr);
  99. *(data + 2) = inb(addr + 2);
  100. break;
  101. case 4:
  102. *((u32 *)data) = inl(addr);
  103. break;
  104. default:
  105. mlxcpld_i2c_lpc_read_buf(data, datalen, addr);
  106. break;
  107. }
  108. }
  109. static void mlxcpld_i2c_write_comm(struct mlxcpld_i2c_priv *priv, u8 offs,
  110. u8 *data, u8 datalen)
  111. {
  112. u32 addr = priv->base_addr + offs;
  113. switch (datalen) {
  114. case 1:
  115. outb(*(data), addr);
  116. break;
  117. case 2:
  118. outw(*((u16 *)data), addr);
  119. break;
  120. case 3:
  121. outw(*((u16 *)data), addr);
  122. outb(*(data + 2), addr + 2);
  123. break;
  124. case 4:
  125. outl(*((u32 *)data), addr);
  126. break;
  127. default:
  128. mlxcpld_i2c_lpc_write_buf(data, datalen, addr);
  129. break;
  130. }
  131. }
  132. /*
  133. * Check validity of received i2c messages parameters.
  134. * Returns 0 if OK, other - in case of invalid parameters.
  135. */
  136. static int mlxcpld_i2c_check_msg_params(struct mlxcpld_i2c_priv *priv,
  137. struct i2c_msg *msgs, int num)
  138. {
  139. int i;
  140. if (!num) {
  141. dev_err(priv->dev, "Incorrect 0 num of messages\n");
  142. return -EINVAL;
  143. }
  144. if (unlikely(msgs[0].addr > 0x7f)) {
  145. dev_err(priv->dev, "Invalid address 0x%03x\n",
  146. msgs[0].addr);
  147. return -EINVAL;
  148. }
  149. for (i = 0; i < num; ++i) {
  150. if (unlikely(!msgs[i].buf)) {
  151. dev_err(priv->dev, "Invalid buf in msg[%d]\n",
  152. i);
  153. return -EINVAL;
  154. }
  155. if (unlikely(msgs[0].addr != msgs[i].addr)) {
  156. dev_err(priv->dev, "Invalid addr in msg[%d]\n",
  157. i);
  158. return -EINVAL;
  159. }
  160. }
  161. return 0;
  162. }
  163. /*
  164. * Check if transfer is completed and status of operation.
  165. * Returns 0 - transfer completed (both ACK or NACK),
  166. * negative - transfer isn't finished.
  167. */
  168. static int mlxcpld_i2c_check_status(struct mlxcpld_i2c_priv *priv, int *status)
  169. {
  170. u8 val;
  171. mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_STATUS_REG, &val, 1);
  172. if (val & MLXCPLD_LPCI2C_TRANS_END) {
  173. if (val & MLXCPLD_LPCI2C_STATUS_NACK)
  174. /*
  175. * The slave is unable to accept the data. No such
  176. * slave, command not understood, or unable to accept
  177. * any more data.
  178. */
  179. *status = MLXCPLD_LPCI2C_NACK_IND;
  180. else
  181. *status = MLXCPLD_LPCI2C_ACK_IND;
  182. return 0;
  183. }
  184. *status = MLXCPLD_LPCI2C_NO_IND;
  185. return -EIO;
  186. }
  187. static void mlxcpld_i2c_set_transf_data(struct mlxcpld_i2c_priv *priv,
  188. struct i2c_msg *msgs, int num,
  189. u8 comm_len)
  190. {
  191. priv->xfer.msg = msgs;
  192. priv->xfer.msg_num = num;
  193. /*
  194. * All upper layers currently are never use transfer with more than
  195. * 2 messages. Actually, it's also not so relevant in Mellanox systems
  196. * because of HW limitation. Max size of transfer is not more than 32
  197. * or 68 bytes in the current x86 LPCI2C bridge.
  198. */
  199. priv->xfer.cmd = msgs[num - 1].flags & I2C_M_RD;
  200. if (priv->xfer.cmd == I2C_M_RD && comm_len != msgs[0].len) {
  201. priv->xfer.addr_width = msgs[0].len;
  202. priv->xfer.data_len = comm_len - priv->xfer.addr_width;
  203. } else {
  204. priv->xfer.addr_width = 0;
  205. priv->xfer.data_len = comm_len;
  206. }
  207. }
  208. /* Reset CPLD LPCI2C block */
  209. static void mlxcpld_i2c_reset(struct mlxcpld_i2c_priv *priv)
  210. {
  211. u8 val;
  212. mutex_lock(&priv->lock);
  213. mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_CTRL_REG, &val, 1);
  214. val &= ~MLXCPLD_LPCI2C_RST_SEL_MASK;
  215. mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_CTRL_REG, &val, 1);
  216. mutex_unlock(&priv->lock);
  217. }
  218. /* Make sure the CPLD is ready to start transmitting. */
  219. static int mlxcpld_i2c_check_busy(struct mlxcpld_i2c_priv *priv)
  220. {
  221. u8 val;
  222. mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_STATUS_REG, &val, 1);
  223. if (val & MLXCPLD_LPCI2C_TRANS_END)
  224. return 0;
  225. return -EIO;
  226. }
  227. static int mlxcpld_i2c_wait_for_free(struct mlxcpld_i2c_priv *priv)
  228. {
  229. int timeout = 0;
  230. do {
  231. if (!mlxcpld_i2c_check_busy(priv))
  232. break;
  233. usleep_range(priv->polling_time / 2, priv->polling_time);
  234. timeout += priv->polling_time;
  235. } while (timeout <= MLXCPLD_I2C_XFER_TO);
  236. if (timeout > MLXCPLD_I2C_XFER_TO)
  237. return -ETIMEDOUT;
  238. return 0;
  239. }
  240. /*
  241. * Wait for master transfer to complete.
  242. * It puts current process to sleep until we get interrupt or timeout expires.
  243. * Returns the number of transferred or read bytes or error (<0).
  244. */
  245. static int mlxcpld_i2c_wait_for_tc(struct mlxcpld_i2c_priv *priv)
  246. {
  247. int status, i, timeout = 0;
  248. u8 datalen, val;
  249. do {
  250. usleep_range(priv->polling_time / 2, priv->polling_time);
  251. if (!mlxcpld_i2c_check_status(priv, &status))
  252. break;
  253. timeout += priv->polling_time;
  254. } while (status == 0 && timeout < MLXCPLD_I2C_XFER_TO);
  255. switch (status) {
  256. case MLXCPLD_LPCI2C_NO_IND:
  257. return -ETIMEDOUT;
  258. case MLXCPLD_LPCI2C_ACK_IND:
  259. if (priv->xfer.cmd != I2C_M_RD)
  260. return (priv->xfer.addr_width + priv->xfer.data_len);
  261. if (priv->xfer.msg_num == 1)
  262. i = 0;
  263. else
  264. i = 1;
  265. if (!priv->xfer.msg[i].buf)
  266. return -EINVAL;
  267. /*
  268. * Actual read data len will be always the same as
  269. * requested len. 0xff (line pull-up) will be returned
  270. * if slave has no data to return. Thus don't read
  271. * MLXCPLD_LPCI2C_NUM_DAT_REG reg from CPLD. Only in case of
  272. * SMBus block read transaction data len can be different,
  273. * check this case.
  274. */
  275. mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_NUM_ADDR_REG, &val,
  276. 1);
  277. if (priv->smbus_block && (val & MLXCPLD_I2C_SMBUS_BLK_BIT)) {
  278. mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_NUM_DAT_REG,
  279. &datalen, 1);
  280. if (unlikely(datalen > I2C_SMBUS_BLOCK_MAX)) {
  281. dev_err(priv->dev, "Incorrect smbus block read message len\n");
  282. return -EPROTO;
  283. }
  284. } else {
  285. datalen = priv->xfer.data_len;
  286. }
  287. mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_DATA_REG,
  288. priv->xfer.msg[i].buf, datalen);
  289. return datalen;
  290. case MLXCPLD_LPCI2C_NACK_IND:
  291. return -ENXIO;
  292. default:
  293. return -EINVAL;
  294. }
  295. }
  296. static void mlxcpld_i2c_xfer_msg(struct mlxcpld_i2c_priv *priv)
  297. {
  298. int i, len = 0;
  299. u8 cmd, val;
  300. mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_NUM_DAT_REG,
  301. &priv->xfer.data_len, 1);
  302. val = priv->xfer.addr_width;
  303. /* Notify HW about SMBus block read transaction */
  304. if (priv->smbus_block && priv->xfer.msg_num >= 2 &&
  305. priv->xfer.msg[1].len == 1 &&
  306. (priv->xfer.msg[1].flags & I2C_M_RECV_LEN) &&
  307. (priv->xfer.msg[1].flags & I2C_M_RD))
  308. val |= MLXCPLD_I2C_SMBUS_BLK_BIT;
  309. mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_NUM_ADDR_REG, &val, 1);
  310. for (i = 0; i < priv->xfer.msg_num; i++) {
  311. if ((priv->xfer.msg[i].flags & I2C_M_RD) != I2C_M_RD) {
  312. /* Don't write to CPLD buffer in read transaction */
  313. mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_DATA_REG +
  314. len, priv->xfer.msg[i].buf,
  315. priv->xfer.msg[i].len);
  316. len += priv->xfer.msg[i].len;
  317. }
  318. }
  319. /*
  320. * Set target slave address with command for master transfer.
  321. * It should be latest executed function before CPLD transaction.
  322. */
  323. cmd = (priv->xfer.msg[0].addr << 1) | priv->xfer.cmd;
  324. mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_CMD_REG, &cmd, 1);
  325. }
  326. /*
  327. * Generic lpc-i2c transfer.
  328. * Returns the number of processed messages or error (<0).
  329. */
  330. static int mlxcpld_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
  331. int num)
  332. {
  333. struct mlxcpld_i2c_priv *priv = i2c_get_adapdata(adap);
  334. u8 comm_len = 0;
  335. int i, err;
  336. err = mlxcpld_i2c_check_msg_params(priv, msgs, num);
  337. if (err) {
  338. dev_err(priv->dev, "Incorrect message\n");
  339. return err;
  340. }
  341. for (i = 0; i < num; ++i)
  342. comm_len += msgs[i].len;
  343. /* Check bus state */
  344. if (mlxcpld_i2c_wait_for_free(priv)) {
  345. dev_err(priv->dev, "LPCI2C bridge is busy\n");
  346. /*
  347. * Usually it means something serious has happened.
  348. * We can not have unfinished previous transfer
  349. * so it doesn't make any sense to try to stop it.
  350. * Probably we were not able to recover from the
  351. * previous error.
  352. * The only reasonable thing - is soft reset.
  353. */
  354. mlxcpld_i2c_reset(priv);
  355. if (mlxcpld_i2c_check_busy(priv)) {
  356. dev_err(priv->dev, "LPCI2C bridge is busy after reset\n");
  357. return -EIO;
  358. }
  359. }
  360. mlxcpld_i2c_set_transf_data(priv, msgs, num, comm_len);
  361. mutex_lock(&priv->lock);
  362. /* Do real transfer. Can't fail */
  363. mlxcpld_i2c_xfer_msg(priv);
  364. /* Wait for transaction complete */
  365. err = mlxcpld_i2c_wait_for_tc(priv);
  366. mutex_unlock(&priv->lock);
  367. return err < 0 ? err : num;
  368. }
  369. static u32 mlxcpld_i2c_func(struct i2c_adapter *adap)
  370. {
  371. struct mlxcpld_i2c_priv *priv = i2c_get_adapdata(adap);
  372. if (priv->smbus_block)
  373. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
  374. I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_BLOCK_DATA;
  375. else
  376. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
  377. I2C_FUNC_SMBUS_I2C_BLOCK;
  378. }
  379. static const struct i2c_algorithm mlxcpld_i2c_algo = {
  380. .master_xfer = mlxcpld_i2c_xfer,
  381. .functionality = mlxcpld_i2c_func
  382. };
  383. static const struct i2c_adapter_quirks mlxcpld_i2c_quirks = {
  384. .flags = I2C_AQ_COMB_WRITE_THEN_READ,
  385. .max_read_len = MLXCPLD_I2C_DATA_REG_SZ - MLXCPLD_I2C_MAX_ADDR_LEN,
  386. .max_write_len = MLXCPLD_I2C_DATA_REG_SZ,
  387. .max_comb_1st_msg_len = 4,
  388. };
  389. static const struct i2c_adapter_quirks mlxcpld_i2c_quirks_ext = {
  390. .flags = I2C_AQ_COMB_WRITE_THEN_READ,
  391. .max_read_len = MLXCPLD_I2C_DATA_REG_SZ * 2 - MLXCPLD_I2C_MAX_ADDR_LEN,
  392. .max_write_len = MLXCPLD_I2C_DATA_REG_SZ * 2,
  393. .max_comb_1st_msg_len = 4,
  394. };
  395. static struct i2c_adapter mlxcpld_i2c_adapter = {
  396. .owner = THIS_MODULE,
  397. .name = "i2c-mlxcpld",
  398. .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
  399. .algo = &mlxcpld_i2c_algo,
  400. .quirks = &mlxcpld_i2c_quirks,
  401. .retries = MLXCPLD_I2C_RETR_NUM,
  402. .nr = MLXCPLD_I2C_BUS_NUM,
  403. };
  404. static int
  405. mlxcpld_i2c_set_frequency(struct mlxcpld_i2c_priv *priv,
  406. struct mlxreg_core_hotplug_platform_data *pdata)
  407. {
  408. struct mlxreg_core_item *item = pdata->items;
  409. struct mlxreg_core_data *data;
  410. u32 regval;
  411. u8 freq;
  412. int err;
  413. if (!item)
  414. return 0;
  415. /* Read frequency setting. */
  416. data = item->data;
  417. err = regmap_read(pdata->regmap, data->reg, &regval);
  418. if (err)
  419. return err;
  420. /* Set frequency only if it is not 100KHz, which is default. */
  421. switch ((regval & data->mask) >> data->bit) {
  422. case MLXCPLD_I2C_FREQ_1000KHZ:
  423. freq = MLXCPLD_I2C_FREQ_1000KHZ_SET;
  424. priv->polling_time /= 4;
  425. break;
  426. case MLXCPLD_I2C_FREQ_400KHZ:
  427. freq = MLXCPLD_I2C_FREQ_400KHZ_SET;
  428. priv->polling_time /= 4;
  429. break;
  430. default:
  431. return 0;
  432. }
  433. mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_HALF_CYC_REG, &freq, 1);
  434. return 0;
  435. }
  436. static int mlxcpld_i2c_probe(struct platform_device *pdev)
  437. {
  438. struct mlxreg_core_hotplug_platform_data *pdata;
  439. struct mlxcpld_i2c_priv *priv;
  440. int err;
  441. u8 val;
  442. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  443. if (!priv)
  444. return -ENOMEM;
  445. mutex_init(&priv->lock);
  446. platform_set_drvdata(pdev, priv);
  447. priv->dev = &pdev->dev;
  448. priv->base_addr = MLXPLAT_CPLD_LPC_I2C_BASE_ADDR;
  449. priv->polling_time = MLXCPLD_I2C_POLL_TIME;
  450. /* Set I2C bus frequency if platform data provides this info. */
  451. pdata = dev_get_platdata(&pdev->dev);
  452. if (pdata) {
  453. err = mlxcpld_i2c_set_frequency(priv, pdata);
  454. if (err)
  455. goto mlxcpld_i2_probe_failed;
  456. }
  457. /* Register with i2c layer */
  458. mlxcpld_i2c_adapter.timeout = usecs_to_jiffies(MLXCPLD_I2C_XFER_TO);
  459. /* Read capability register */
  460. mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_CPBLTY_REG, &val, 1);
  461. /* Check support for extended transaction length */
  462. if ((val & MLXCPLD_I2C_DATA_SZ_MASK) == MLXCPLD_I2C_DATA_SZ_BIT)
  463. mlxcpld_i2c_adapter.quirks = &mlxcpld_i2c_quirks_ext;
  464. /* Check support for smbus block transaction */
  465. if (val & MLXCPLD_I2C_SMBUS_BLK_BIT)
  466. priv->smbus_block = true;
  467. if (pdev->id >= -1)
  468. mlxcpld_i2c_adapter.nr = pdev->id;
  469. priv->adap = mlxcpld_i2c_adapter;
  470. priv->adap.dev.parent = &pdev->dev;
  471. i2c_set_adapdata(&priv->adap, priv);
  472. err = i2c_add_numbered_adapter(&priv->adap);
  473. if (err)
  474. goto mlxcpld_i2_probe_failed;
  475. /* Notify caller when adapter is added. */
  476. if (pdata && pdata->completion_notify)
  477. pdata->completion_notify(pdata->handle, mlxcpld_i2c_adapter.nr);
  478. return 0;
  479. mlxcpld_i2_probe_failed:
  480. mutex_destroy(&priv->lock);
  481. return err;
  482. }
  483. static int mlxcpld_i2c_remove(struct platform_device *pdev)
  484. {
  485. struct mlxcpld_i2c_priv *priv = platform_get_drvdata(pdev);
  486. i2c_del_adapter(&priv->adap);
  487. mutex_destroy(&priv->lock);
  488. return 0;
  489. }
  490. static struct platform_driver mlxcpld_i2c_driver = {
  491. .probe = mlxcpld_i2c_probe,
  492. .remove = mlxcpld_i2c_remove,
  493. .driver = {
  494. .name = MLXCPLD_I2C_DEVICE_NAME,
  495. },
  496. };
  497. module_platform_driver(mlxcpld_i2c_driver);
  498. MODULE_AUTHOR("Michael Shych <[email protected]>");
  499. MODULE_DESCRIPTION("Mellanox I2C-CPLD controller driver");
  500. MODULE_LICENSE("Dual BSD/GPL");
  501. MODULE_ALIAS("platform:i2c-mlxcpld");