blob: 3cbc0926232647bc3843bd7531473e0ae7d100ab [file] [log] [blame]
Darius Augulisaa11e382009-01-30 10:32:28 +02001/*
2 * Copyright (C) 2002 Motorola GSG-China
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
Darius Augulisaa11e382009-01-30 10:32:28 +020014 * Author:
15 * Darius Augulis, Teltonika Inc.
16 *
17 * Desc.:
18 * Implementation of I2C Adapter/Algorithm Driver
19 * for I2C Bus integrated in Freescale i.MX/MXC processors
20 *
21 * Derived from Motorola GSG China I2C example driver
22 *
23 * Copyright (C) 2005 Torsten Koschorrek <koschorrek at synertronixx.de
24 * Copyright (C) 2005 Matthias Blaschke <blaschke at synertronixx.de
25 * Copyright (C) 2007 RightHand Technologies, Inc.
26 * Copyright (C) 2008 Darius Augulis <darius.augulis at teltonika.lt>
27 *
Jingchang Lud533f042013-08-07 17:05:36 +080028 * Copyright 2013 Freescale Semiconductor, Inc.
29 *
Darius Augulisaa11e382009-01-30 10:32:28 +020030 */
31
32/** Includes *******************************************************************
33*******************************************************************************/
34
35#include <linux/init.h>
36#include <linux/kernel.h>
37#include <linux/module.h>
38#include <linux/errno.h>
39#include <linux/err.h>
40#include <linux/interrupt.h>
41#include <linux/delay.h>
42#include <linux/i2c.h>
43#include <linux/io.h>
44#include <linux/sched.h>
45#include <linux/platform_device.h>
46#include <linux/clk.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090047#include <linux/slab.h>
Shawn Guodfcd04b2011-09-08 15:09:35 +080048#include <linux/of.h>
49#include <linux/of_device.h>
Arnd Bergmann82906b12012-08-24 15:14:29 +020050#include <linux/platform_data/i2c-imx.h>
Darius Augulisaa11e382009-01-30 10:32:28 +020051
52/** Defines ********************************************************************
53*******************************************************************************/
54
55/* This will be the driver name the kernel reports */
56#define DRIVER_NAME "imx-i2c"
57
58/* Default value */
59#define IMX_I2C_BIT_RATE 100000 /* 100kHz */
60
Jingchang Lu8cc73312013-08-07 17:05:40 +080061/* IMX I2C registers:
62 * the I2C register offset is different between SoCs,
63 * to provid support for all these chips, split the
64 * register offset into a fixed base address and a
65 * variable shift value, then the full register offset
66 * will be calculated by
67 * reg_off = ( reg_base_addr << reg_shift)
68 */
Darius Augulisaa11e382009-01-30 10:32:28 +020069#define IMX_I2C_IADR 0x00 /* i2c slave address */
Jingchang Lu8cc73312013-08-07 17:05:40 +080070#define IMX_I2C_IFDR 0x01 /* i2c frequency divider */
71#define IMX_I2C_I2CR 0x02 /* i2c control */
72#define IMX_I2C_I2SR 0x03 /* i2c status */
73#define IMX_I2C_I2DR 0x04 /* i2c transfer data */
74
75#define IMX_I2C_REGSHIFT 2
Jingchang Luad90efa2013-08-07 17:05:43 +080076#define VF610_I2C_REGSHIFT 0
Darius Augulisaa11e382009-01-30 10:32:28 +020077
78/* Bits of IMX I2C registers */
79#define I2SR_RXAK 0x01
80#define I2SR_IIF 0x02
81#define I2SR_SRW 0x04
82#define I2SR_IAL 0x10
83#define I2SR_IBB 0x20
84#define I2SR_IAAS 0x40
85#define I2SR_ICF 0x80
86#define I2CR_RSTA 0x04
87#define I2CR_TXAK 0x08
88#define I2CR_MTX 0x10
89#define I2CR_MSTA 0x20
90#define I2CR_IIEN 0x40
91#define I2CR_IEN 0x80
92
Jingchang Lu171408c2013-08-07 17:05:41 +080093/* register bits different operating codes definition:
94 * 1) I2SR: Interrupt flags clear operation differ between SoCs:
95 * - write zero to clear(w0c) INT flag on i.MX,
96 * - but write one to clear(w1c) INT flag on Vybrid.
97 * 2) I2CR: I2C module enable operation also differ between SoCs:
98 * - set I2CR_IEN bit enable the module on i.MX,
99 * - but clear I2CR_IEN bit enable the module on Vybrid.
100 */
101#define I2SR_CLR_OPCODE_W0C 0x0
102#define I2SR_CLR_OPCODE_W1C (I2SR_IAL | I2SR_IIF)
103#define I2CR_IEN_OPCODE_0 0x0
104#define I2CR_IEN_OPCODE_1 I2CR_IEN
105
Darius Augulisaa11e382009-01-30 10:32:28 +0200106/** Variables ******************************************************************
107*******************************************************************************/
108
Darius Augulisaa11e382009-01-30 10:32:28 +0200109/*
110 * sorted list of clock divider, register value pairs
111 * taken from table 26-5, p.26-9, Freescale i.MX
112 * Integrated Portable System Processor Reference Manual
113 * Document Number: MC9328MXLRM, Rev. 5.1, 06/2007
114 *
115 * Duplicated divider values removed from list
116 */
Jingchang Lud533f042013-08-07 17:05:36 +0800117struct imx_i2c_clk_pair {
118 u16 div;
119 u16 val;
120};
Darius Augulisaa11e382009-01-30 10:32:28 +0200121
Jingchang Lu4b775022013-08-07 17:05:42 +0800122static struct imx_i2c_clk_pair imx_i2c_clk_div[] = {
Darius Augulisaa11e382009-01-30 10:32:28 +0200123 { 22, 0x20 }, { 24, 0x21 }, { 26, 0x22 }, { 28, 0x23 },
124 { 30, 0x00 }, { 32, 0x24 }, { 36, 0x25 }, { 40, 0x26 },
125 { 42, 0x03 }, { 44, 0x27 }, { 48, 0x28 }, { 52, 0x05 },
126 { 56, 0x29 }, { 60, 0x06 }, { 64, 0x2A }, { 72, 0x2B },
127 { 80, 0x2C }, { 88, 0x09 }, { 96, 0x2D }, { 104, 0x0A },
128 { 112, 0x2E }, { 128, 0x2F }, { 144, 0x0C }, { 160, 0x30 },
129 { 192, 0x31 }, { 224, 0x32 }, { 240, 0x0F }, { 256, 0x33 },
130 { 288, 0x10 }, { 320, 0x34 }, { 384, 0x35 }, { 448, 0x36 },
131 { 480, 0x13 }, { 512, 0x37 }, { 576, 0x14 }, { 640, 0x38 },
132 { 768, 0x39 }, { 896, 0x3A }, { 960, 0x17 }, { 1024, 0x3B },
133 { 1152, 0x18 }, { 1280, 0x3C }, { 1536, 0x3D }, { 1792, 0x3E },
134 { 1920, 0x1B }, { 2048, 0x3F }, { 2304, 0x1C }, { 2560, 0x1D },
135 { 3072, 0x1E }, { 3840, 0x1F }
136};
137
Jingchang Luad90efa2013-08-07 17:05:43 +0800138/* Vybrid VF610 clock divider, register value pairs */
139static struct imx_i2c_clk_pair vf610_i2c_clk_div[] = {
140 { 20, 0x00 }, { 22, 0x01 }, { 24, 0x02 }, { 26, 0x03 },
141 { 28, 0x04 }, { 30, 0x05 }, { 32, 0x09 }, { 34, 0x06 },
142 { 36, 0x0A }, { 40, 0x07 }, { 44, 0x0C }, { 48, 0x0D },
143 { 52, 0x43 }, { 56, 0x0E }, { 60, 0x45 }, { 64, 0x12 },
144 { 68, 0x0F }, { 72, 0x13 }, { 80, 0x14 }, { 88, 0x15 },
145 { 96, 0x19 }, { 104, 0x16 }, { 112, 0x1A }, { 128, 0x17 },
146 { 136, 0x4F }, { 144, 0x1C }, { 160, 0x1D }, { 176, 0x55 },
147 { 192, 0x1E }, { 208, 0x56 }, { 224, 0x22 }, { 228, 0x24 },
148 { 240, 0x1F }, { 256, 0x23 }, { 288, 0x5C }, { 320, 0x25 },
149 { 384, 0x26 }, { 448, 0x2A }, { 480, 0x27 }, { 512, 0x2B },
150 { 576, 0x2C }, { 640, 0x2D }, { 768, 0x31 }, { 896, 0x32 },
151 { 960, 0x2F }, { 1024, 0x33 }, { 1152, 0x34 }, { 1280, 0x35 },
152 { 1536, 0x36 }, { 1792, 0x3A }, { 1920, 0x37 }, { 2048, 0x3B },
153 { 2304, 0x3C }, { 2560, 0x3D }, { 3072, 0x3E }, { 3584, 0x7A },
154 { 3840, 0x3F }, { 4096, 0x7B }, { 5120, 0x7D }, { 6144, 0x7E },
155};
156
Shawn Guo5bdfba22012-09-14 15:19:00 +0800157enum imx_i2c_type {
158 IMX1_I2C,
159 IMX21_I2C,
Jingchang Luad90efa2013-08-07 17:05:43 +0800160 VF610_I2C,
Shawn Guo5bdfba22012-09-14 15:19:00 +0800161};
162
Jingchang Lu4b775022013-08-07 17:05:42 +0800163struct imx_i2c_hwdata {
164 enum imx_i2c_type devtype;
165 unsigned regshift;
166 struct imx_i2c_clk_pair *clk_div;
167 unsigned ndivs;
168 unsigned i2sr_clr_opcode;
169 unsigned i2cr_ien_opcode;
170};
171
Darius Augulisaa11e382009-01-30 10:32:28 +0200172struct imx_i2c_struct {
173 struct i2c_adapter adapter;
Darius Augulisaa11e382009-01-30 10:32:28 +0200174 struct clk *clk;
175 void __iomem *base;
Darius Augulisaa11e382009-01-30 10:32:28 +0200176 wait_queue_head_t queue;
177 unsigned long i2csr;
Wolfram Sang65de3942009-04-06 16:27:45 +0200178 unsigned int disable_delay;
Richard Zhao43309f32009-10-17 17:46:22 +0800179 int stopped;
Richard Zhaodb3a3d42009-10-17 17:46:24 +0800180 unsigned int ifdr; /* IMX_I2C_IFDR */
Fugang Duan9b2a6da2014-05-20 10:21:45 +0800181 unsigned int cur_clk;
182 unsigned int bitrate;
Jingchang Lu4b775022013-08-07 17:05:42 +0800183 const struct imx_i2c_hwdata *hwdata;
184};
185
186static const struct imx_i2c_hwdata imx1_i2c_hwdata = {
187 .devtype = IMX1_I2C,
188 .regshift = IMX_I2C_REGSHIFT,
189 .clk_div = imx_i2c_clk_div,
190 .ndivs = ARRAY_SIZE(imx_i2c_clk_div),
191 .i2sr_clr_opcode = I2SR_CLR_OPCODE_W0C,
192 .i2cr_ien_opcode = I2CR_IEN_OPCODE_1,
193
194};
195
196static const struct imx_i2c_hwdata imx21_i2c_hwdata = {
197 .devtype = IMX21_I2C,
198 .regshift = IMX_I2C_REGSHIFT,
199 .clk_div = imx_i2c_clk_div,
200 .ndivs = ARRAY_SIZE(imx_i2c_clk_div),
201 .i2sr_clr_opcode = I2SR_CLR_OPCODE_W0C,
202 .i2cr_ien_opcode = I2CR_IEN_OPCODE_1,
203
Darius Augulisaa11e382009-01-30 10:32:28 +0200204};
205
Jingchang Luad90efa2013-08-07 17:05:43 +0800206static struct imx_i2c_hwdata vf610_i2c_hwdata = {
207 .devtype = VF610_I2C,
208 .regshift = VF610_I2C_REGSHIFT,
209 .clk_div = vf610_i2c_clk_div,
210 .ndivs = ARRAY_SIZE(vf610_i2c_clk_div),
211 .i2sr_clr_opcode = I2SR_CLR_OPCODE_W1C,
212 .i2cr_ien_opcode = I2CR_IEN_OPCODE_0,
213
214};
215
Shawn Guo5bdfba22012-09-14 15:19:00 +0800216static struct platform_device_id imx_i2c_devtype[] = {
217 {
218 .name = "imx1-i2c",
Jingchang Lu4b775022013-08-07 17:05:42 +0800219 .driver_data = (kernel_ulong_t)&imx1_i2c_hwdata,
Shawn Guo5bdfba22012-09-14 15:19:00 +0800220 }, {
221 .name = "imx21-i2c",
Jingchang Lu4b775022013-08-07 17:05:42 +0800222 .driver_data = (kernel_ulong_t)&imx21_i2c_hwdata,
Shawn Guo5bdfba22012-09-14 15:19:00 +0800223 }, {
224 /* sentinel */
225 }
226};
227MODULE_DEVICE_TABLE(platform, imx_i2c_devtype);
228
Shawn Guodfcd04b2011-09-08 15:09:35 +0800229static const struct of_device_id i2c_imx_dt_ids[] = {
Jingchang Lu4b775022013-08-07 17:05:42 +0800230 { .compatible = "fsl,imx1-i2c", .data = &imx1_i2c_hwdata, },
231 { .compatible = "fsl,imx21-i2c", .data = &imx21_i2c_hwdata, },
Jingchang Luad90efa2013-08-07 17:05:43 +0800232 { .compatible = "fsl,vf610-i2c", .data = &vf610_i2c_hwdata, },
Shawn Guodfcd04b2011-09-08 15:09:35 +0800233 { /* sentinel */ }
234};
Arnaud Patard \(Rtp\)2f641a82013-06-20 23:07:06 +0200235MODULE_DEVICE_TABLE(of, i2c_imx_dt_ids);
Shawn Guodfcd04b2011-09-08 15:09:35 +0800236
Shawn Guo5bdfba22012-09-14 15:19:00 +0800237static inline int is_imx1_i2c(struct imx_i2c_struct *i2c_imx)
238{
Jingchang Lu4b775022013-08-07 17:05:42 +0800239 return i2c_imx->hwdata->devtype == IMX1_I2C;
Shawn Guo5bdfba22012-09-14 15:19:00 +0800240}
241
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800242static inline void imx_i2c_write_reg(unsigned int val,
243 struct imx_i2c_struct *i2c_imx, unsigned int reg)
244{
Jingchang Lu4b775022013-08-07 17:05:42 +0800245 writeb(val, i2c_imx->base + (reg << i2c_imx->hwdata->regshift));
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800246}
247
248static inline unsigned char imx_i2c_read_reg(struct imx_i2c_struct *i2c_imx,
249 unsigned int reg)
250{
Jingchang Lu4b775022013-08-07 17:05:42 +0800251 return readb(i2c_imx->base + (reg << i2c_imx->hwdata->regshift));
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800252}
253
Darius Augulisaa11e382009-01-30 10:32:28 +0200254/** Functions for IMX I2C adapter driver ***************************************
255*******************************************************************************/
256
Richard Zhao43309f32009-10-17 17:46:22 +0800257static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
Darius Augulisaa11e382009-01-30 10:32:28 +0200258{
259 unsigned long orig_jiffies = jiffies;
Richard Zhao43309f32009-10-17 17:46:22 +0800260 unsigned int temp;
Darius Augulisaa11e382009-01-30 10:32:28 +0200261
262 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
263
Richard Zhao43309f32009-10-17 17:46:22 +0800264 while (1) {
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800265 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
Haibo Chen639a26c2014-09-03 13:52:07 +0800266
267 /* check for arbitration lost */
268 if (temp & I2SR_IAL) {
269 temp &= ~I2SR_IAL;
270 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR);
271 return -EAGAIN;
272 }
273
Richard Zhao43309f32009-10-17 17:46:22 +0800274 if (for_busy && (temp & I2SR_IBB))
275 break;
276 if (!for_busy && !(temp & I2SR_IBB))
277 break;
Arnaud Patardda9c99f2010-03-23 17:28:28 +0100278 if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
Darius Augulisaa11e382009-01-30 10:32:28 +0200279 dev_dbg(&i2c_imx->adapter.dev,
280 "<%s> I2C bus is busy\n", __func__);
Arnaud Patardda9c99f2010-03-23 17:28:28 +0100281 return -ETIMEDOUT;
Darius Augulisaa11e382009-01-30 10:32:28 +0200282 }
283 schedule();
284 }
285
286 return 0;
287}
288
289static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
290{
Marc Kleine-Buddee39428d2010-06-21 09:27:05 +0200291 wait_event_timeout(i2c_imx->queue, i2c_imx->i2csr & I2SR_IIF, HZ / 10);
Darius Augulisaa11e382009-01-30 10:32:28 +0200292
Marc Kleine-Buddee39428d2010-06-21 09:27:05 +0200293 if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
Darius Augulisaa11e382009-01-30 10:32:28 +0200294 dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
295 return -ETIMEDOUT;
296 }
297 dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
298 i2c_imx->i2csr = 0;
299 return 0;
300}
301
302static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
303{
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800304 if (imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR) & I2SR_RXAK) {
Darius Augulisaa11e382009-01-30 10:32:28 +0200305 dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
306 return -EIO; /* No ACK */
307 }
308
309 dev_dbg(&i2c_imx->adapter.dev, "<%s> ACK received\n", __func__);
310 return 0;
311}
312
Fugang Duan9b2a6da2014-05-20 10:21:45 +0800313static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx)
314{
315 struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div;
316 unsigned int i2c_clk_rate;
317 unsigned int div;
318 int i;
319
320 /* Divider value calculation */
321 i2c_clk_rate = clk_get_rate(i2c_imx->clk);
322 if (i2c_imx->cur_clk == i2c_clk_rate)
323 return;
324 else
325 i2c_imx->cur_clk = i2c_clk_rate;
326
327 div = (i2c_clk_rate + i2c_imx->bitrate - 1) / i2c_imx->bitrate;
328 if (div < i2c_clk_div[0].div)
329 i = 0;
330 else if (div > i2c_clk_div[i2c_imx->hwdata->ndivs - 1].div)
331 i = i2c_imx->hwdata->ndivs - 1;
332 else
333 for (i = 0; i2c_clk_div[i].div < div; i++);
334
335 /* Store divider value */
336 i2c_imx->ifdr = i2c_clk_div[i].val;
337
338 /*
339 * There dummy delay is calculated.
340 * It should be about one I2C clock period long.
341 * This delay is used in I2C bus disable function
342 * to fix chip hardware bug.
343 */
344 i2c_imx->disable_delay = (500000U * i2c_clk_div[i].div
345 + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
346
347#ifdef CONFIG_I2C_DEBUG_BUS
348 dev_dbg(&i2c_imx->adapter.dev, "I2C_CLK=%d, REQ DIV=%d\n",
349 i2c_clk_rate, div);
350 dev_dbg(&i2c_imx->adapter.dev, "IFDR[IC]=0x%x, REAL DIV=%d\n",
351 i2c_clk_div[i].val, i2c_clk_div[i].div);
352#endif
353}
354
Richard Zhao43309f32009-10-17 17:46:22 +0800355static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
Darius Augulisaa11e382009-01-30 10:32:28 +0200356{
357 unsigned int temp = 0;
Richard Zhao43309f32009-10-17 17:46:22 +0800358 int result;
Darius Augulisaa11e382009-01-30 10:32:28 +0200359
360 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
361
Fugang Duan9b2a6da2014-05-20 10:21:45 +0800362 i2c_imx_set_clk(i2c_imx);
363
Fabio Estevame5bf2162013-12-04 20:21:37 -0200364 result = clk_prepare_enable(i2c_imx->clk);
365 if (result)
366 return result;
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800367 imx_i2c_write_reg(i2c_imx->ifdr, i2c_imx, IMX_I2C_IFDR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200368 /* Enable I2C controller */
Jingchang Lu4b775022013-08-07 17:05:42 +0800369 imx_i2c_write_reg(i2c_imx->hwdata->i2sr_clr_opcode, i2c_imx, IMX_I2C_I2SR);
370 imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode, i2c_imx, IMX_I2C_I2CR);
Richard Zhao43309f32009-10-17 17:46:22 +0800371
372 /* Wait controller to be stable */
373 udelay(50);
374
Darius Augulisaa11e382009-01-30 10:32:28 +0200375 /* Start I2C transaction */
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800376 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200377 temp |= I2CR_MSTA;
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800378 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
Richard Zhao43309f32009-10-17 17:46:22 +0800379 result = i2c_imx_bus_busy(i2c_imx, 1);
380 if (result)
381 return result;
382 i2c_imx->stopped = 0;
383
Darius Augulisaa11e382009-01-30 10:32:28 +0200384 temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800385 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
Richard Zhao43309f32009-10-17 17:46:22 +0800386 return result;
Darius Augulisaa11e382009-01-30 10:32:28 +0200387}
388
389static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
390{
391 unsigned int temp = 0;
392
Richard Zhao43309f32009-10-17 17:46:22 +0800393 if (!i2c_imx->stopped) {
394 /* Stop I2C transaction */
395 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800396 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
Richard Zhao43309f32009-10-17 17:46:22 +0800397 temp &= ~(I2CR_MSTA | I2CR_MTX);
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800398 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
Richard Zhao43309f32009-10-17 17:46:22 +0800399 }
Shawn Guo5bdfba22012-09-14 15:19:00 +0800400 if (is_imx1_i2c(i2c_imx)) {
Richard Zhaoa4094a72009-10-17 17:46:23 +0800401 /*
402 * This delay caused by an i.MXL hardware bug.
403 * If no (or too short) delay, no "STOP" bit will be generated.
404 */
405 udelay(i2c_imx->disable_delay);
406 }
Richard Zhao43309f32009-10-17 17:46:22 +0800407
Valentin Longchampa1ee06b2010-01-21 18:55:32 +0100408 if (!i2c_imx->stopped) {
Richard Zhao43309f32009-10-17 17:46:22 +0800409 i2c_imx_bus_busy(i2c_imx, 0);
Valentin Longchampa1ee06b2010-01-21 18:55:32 +0100410 i2c_imx->stopped = 1;
411 }
Richard Zhao43309f32009-10-17 17:46:22 +0800412
Darius Augulisaa11e382009-01-30 10:32:28 +0200413 /* Disable I2C controller */
Jingchang Lu4b775022013-08-07 17:05:42 +0800414 temp = i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN,
415 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
Richard Zhao83914332011-11-15 14:48:08 +0800416 clk_disable_unprepare(i2c_imx->clk);
Darius Augulisaa11e382009-01-30 10:32:28 +0200417}
418
Darius Augulisaa11e382009-01-30 10:32:28 +0200419static irqreturn_t i2c_imx_isr(int irq, void *dev_id)
420{
421 struct imx_i2c_struct *i2c_imx = dev_id;
422 unsigned int temp;
423
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800424 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200425 if (temp & I2SR_IIF) {
426 /* save status register */
427 i2c_imx->i2csr = temp;
428 temp &= ~I2SR_IIF;
Jingchang Lu4b775022013-08-07 17:05:42 +0800429 temp |= (i2c_imx->hwdata->i2sr_clr_opcode & I2SR_IIF);
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800430 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR);
Marc Kleine-Buddee39428d2010-06-21 09:27:05 +0200431 wake_up(&i2c_imx->queue);
Darius Augulisaa11e382009-01-30 10:32:28 +0200432 return IRQ_HANDLED;
433 }
434
435 return IRQ_NONE;
436}
437
438static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
439{
440 int i, result;
441
442 dev_dbg(&i2c_imx->adapter.dev, "<%s> write slave address: addr=0x%x\n",
443 __func__, msgs->addr << 1);
444
445 /* write slave address */
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800446 imx_i2c_write_reg(msgs->addr << 1, i2c_imx, IMX_I2C_I2DR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200447 result = i2c_imx_trx_complete(i2c_imx);
448 if (result)
449 return result;
450 result = i2c_imx_acked(i2c_imx);
451 if (result)
452 return result;
453 dev_dbg(&i2c_imx->adapter.dev, "<%s> write data\n", __func__);
454
455 /* write data */
456 for (i = 0; i < msgs->len; i++) {
457 dev_dbg(&i2c_imx->adapter.dev,
458 "<%s> write byte: B%d=0x%X\n",
459 __func__, i, msgs->buf[i]);
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800460 imx_i2c_write_reg(msgs->buf[i], i2c_imx, IMX_I2C_I2DR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200461 result = i2c_imx_trx_complete(i2c_imx);
462 if (result)
463 return result;
464 result = i2c_imx_acked(i2c_imx);
465 if (result)
466 return result;
467 }
468 return 0;
469}
470
Fugang Duan054b62d2014-04-30 14:24:58 +0800471static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bool is_lastmsg)
Darius Augulisaa11e382009-01-30 10:32:28 +0200472{
473 int i, result;
474 unsigned int temp;
Kaushal Butala8e8782c2014-04-04 14:56:10 +0200475 int block_data = msgs->flags & I2C_M_RECV_LEN;
Darius Augulisaa11e382009-01-30 10:32:28 +0200476
477 dev_dbg(&i2c_imx->adapter.dev,
478 "<%s> write slave address: addr=0x%x\n",
479 __func__, (msgs->addr << 1) | 0x01);
480
481 /* write slave address */
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800482 imx_i2c_write_reg((msgs->addr << 1) | 0x01, i2c_imx, IMX_I2C_I2DR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200483 result = i2c_imx_trx_complete(i2c_imx);
484 if (result)
485 return result;
486 result = i2c_imx_acked(i2c_imx);
487 if (result)
488 return result;
489
490 dev_dbg(&i2c_imx->adapter.dev, "<%s> setup bus\n", __func__);
491
492 /* setup bus to read data */
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800493 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200494 temp &= ~I2CR_MTX;
Kaushal Butala8e8782c2014-04-04 14:56:10 +0200495
496 /*
497 * Reset the I2CR_TXAK flag initially for SMBus block read since the
498 * length is unknown
499 */
500 if ((msgs->len - 1) || block_data)
Darius Augulisaa11e382009-01-30 10:32:28 +0200501 temp &= ~I2CR_TXAK;
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800502 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
503 imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); /* dummy read */
Darius Augulisaa11e382009-01-30 10:32:28 +0200504
505 dev_dbg(&i2c_imx->adapter.dev, "<%s> read data\n", __func__);
506
507 /* read data */
508 for (i = 0; i < msgs->len; i++) {
Kaushal Butala8e8782c2014-04-04 14:56:10 +0200509 u8 len = 0;
Darius Augulisaa11e382009-01-30 10:32:28 +0200510 result = i2c_imx_trx_complete(i2c_imx);
511 if (result)
512 return result;
Kaushal Butala8e8782c2014-04-04 14:56:10 +0200513 /*
514 * First byte is the length of remaining packet
515 * in the SMBus block data read. Add it to
516 * msgs->len.
517 */
518 if ((!i) && block_data) {
519 len = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR);
520 if ((len == 0) || (len > I2C_SMBUS_BLOCK_MAX))
521 return -EPROTO;
522 dev_dbg(&i2c_imx->adapter.dev,
523 "<%s> read length: 0x%X\n",
524 __func__, len);
525 msgs->len += len;
526 }
Darius Augulisaa11e382009-01-30 10:32:28 +0200527 if (i == (msgs->len - 1)) {
Fugang Duan054b62d2014-04-30 14:24:58 +0800528 if (is_lastmsg) {
529 /*
530 * It must generate STOP before read I2DR to prevent
531 * controller from generating another clock cycle
532 */
533 dev_dbg(&i2c_imx->adapter.dev,
534 "<%s> clear MSTA\n", __func__);
535 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
536 temp &= ~(I2CR_MSTA | I2CR_MTX);
537 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
538 i2c_imx_bus_busy(i2c_imx, 0);
539 i2c_imx->stopped = 1;
540 } else {
541 /*
542 * For i2c master receiver repeat restart operation like:
543 * read -> repeat MSTA -> read/write
544 * The controller must set MTX before read the last byte in
545 * the first read operation, otherwise the first read cost
546 * one extra clock cycle.
547 */
548 temp = readb(i2c_imx->base + IMX_I2C_I2CR);
549 temp |= I2CR_MTX;
550 writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
551 }
Darius Augulisaa11e382009-01-30 10:32:28 +0200552 } else if (i == (msgs->len - 2)) {
553 dev_dbg(&i2c_imx->adapter.dev,
554 "<%s> set TXAK\n", __func__);
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800555 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200556 temp |= I2CR_TXAK;
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800557 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200558 }
Kaushal Butala8e8782c2014-04-04 14:56:10 +0200559 if ((!i) && block_data)
560 msgs->buf[0] = len;
561 else
562 msgs->buf[i] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200563 dev_dbg(&i2c_imx->adapter.dev,
564 "<%s> read byte: B%d=0x%X\n",
565 __func__, i, msgs->buf[i]);
566 }
567 return 0;
568}
569
570static int i2c_imx_xfer(struct i2c_adapter *adapter,
571 struct i2c_msg *msgs, int num)
572{
573 unsigned int i, temp;
574 int result;
Fugang Duan054b62d2014-04-30 14:24:58 +0800575 bool is_lastmsg = false;
Darius Augulisaa11e382009-01-30 10:32:28 +0200576 struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
577
578 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
579
Richard Zhao43309f32009-10-17 17:46:22 +0800580 /* Start I2C transfer */
581 result = i2c_imx_start(i2c_imx);
Darius Augulisaa11e382009-01-30 10:32:28 +0200582 if (result)
583 goto fail0;
584
Darius Augulisaa11e382009-01-30 10:32:28 +0200585 /* read/write data */
586 for (i = 0; i < num; i++) {
Fugang Duan054b62d2014-04-30 14:24:58 +0800587 if (i == num - 1)
588 is_lastmsg = true;
589
Darius Augulisaa11e382009-01-30 10:32:28 +0200590 if (i) {
591 dev_dbg(&i2c_imx->adapter.dev,
592 "<%s> repeated start\n", __func__);
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800593 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200594 temp |= I2CR_RSTA;
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800595 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
Richard Zhao43309f32009-10-17 17:46:22 +0800596 result = i2c_imx_bus_busy(i2c_imx, 1);
597 if (result)
598 goto fail0;
Darius Augulisaa11e382009-01-30 10:32:28 +0200599 }
600 dev_dbg(&i2c_imx->adapter.dev,
601 "<%s> transfer message: %d\n", __func__, i);
602 /* write/read data */
603#ifdef CONFIG_I2C_DEBUG_BUS
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800604 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200605 dev_dbg(&i2c_imx->adapter.dev, "<%s> CONTROL: IEN=%d, IIEN=%d, "
606 "MSTA=%d, MTX=%d, TXAK=%d, RSTA=%d\n", __func__,
607 (temp & I2CR_IEN ? 1 : 0), (temp & I2CR_IIEN ? 1 : 0),
608 (temp & I2CR_MSTA ? 1 : 0), (temp & I2CR_MTX ? 1 : 0),
609 (temp & I2CR_TXAK ? 1 : 0), (temp & I2CR_RSTA ? 1 : 0));
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800610 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200611 dev_dbg(&i2c_imx->adapter.dev,
612 "<%s> STATUS: ICF=%d, IAAS=%d, IBB=%d, "
613 "IAL=%d, SRW=%d, IIF=%d, RXAK=%d\n", __func__,
614 (temp & I2SR_ICF ? 1 : 0), (temp & I2SR_IAAS ? 1 : 0),
615 (temp & I2SR_IBB ? 1 : 0), (temp & I2SR_IAL ? 1 : 0),
616 (temp & I2SR_SRW ? 1 : 0), (temp & I2SR_IIF ? 1 : 0),
617 (temp & I2SR_RXAK ? 1 : 0));
618#endif
619 if (msgs[i].flags & I2C_M_RD)
Fugang Duan054b62d2014-04-30 14:24:58 +0800620 result = i2c_imx_read(i2c_imx, &msgs[i], is_lastmsg);
Darius Augulisaa11e382009-01-30 10:32:28 +0200621 else
622 result = i2c_imx_write(i2c_imx, &msgs[i]);
Arnaud Patardda9c99f2010-03-23 17:28:28 +0100623 if (result)
624 goto fail0;
Darius Augulisaa11e382009-01-30 10:32:28 +0200625 }
626
627fail0:
628 /* Stop I2C transfer */
629 i2c_imx_stop(i2c_imx);
630
631 dev_dbg(&i2c_imx->adapter.dev, "<%s> exit with: %s: %d\n", __func__,
632 (result < 0) ? "error" : "success msg",
633 (result < 0) ? result : num);
634 return (result < 0) ? result : num;
635}
636
637static u32 i2c_imx_func(struct i2c_adapter *adapter)
638{
Kaushal Butala8e8782c2014-04-04 14:56:10 +0200639 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL
640 | I2C_FUNC_SMBUS_READ_BLOCK_DATA;
Darius Augulisaa11e382009-01-30 10:32:28 +0200641}
642
643static struct i2c_algorithm i2c_imx_algo = {
644 .master_xfer = i2c_imx_xfer,
645 .functionality = i2c_imx_func,
646};
647
Wolfram Sang36114312013-10-08 22:35:34 +0200648static int i2c_imx_probe(struct platform_device *pdev)
Darius Augulisaa11e382009-01-30 10:32:28 +0200649{
Shawn Guo5bdfba22012-09-14 15:19:00 +0800650 const struct of_device_id *of_id = of_match_device(i2c_imx_dt_ids,
651 &pdev->dev);
Darius Augulisaa11e382009-01-30 10:32:28 +0200652 struct imx_i2c_struct *i2c_imx;
653 struct resource *res;
Jingoo Han6d4028c2013-07-30 16:59:33 +0900654 struct imxi2c_platform_data *pdata = dev_get_platdata(&pdev->dev);
Darius Augulisaa11e382009-01-30 10:32:28 +0200655 void __iomem *base;
Wolfram Sang8c88ab02012-07-08 13:11:43 +0200656 int irq, ret;
Darius Augulisaa11e382009-01-30 10:32:28 +0200657
658 dev_dbg(&pdev->dev, "<%s>\n", __func__);
659
Darius Augulisaa11e382009-01-30 10:32:28 +0200660 irq = platform_get_irq(pdev, 0);
661 if (irq < 0) {
662 dev_err(&pdev->dev, "can't get irq number\n");
Wolfram Sanga8763f32013-12-12 22:51:31 +0100663 return irq;
Darius Augulisaa11e382009-01-30 10:32:28 +0200664 }
665
Wolfram Sang3cc2d002013-05-10 10:16:54 +0200666 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Thierry Reding84dbf802013-01-21 11:09:03 +0100667 base = devm_ioremap_resource(&pdev->dev, res);
668 if (IS_ERR(base))
669 return PTR_ERR(base);
Uwe Kleine-König4927fbf2010-01-08 17:23:17 +0100670
Fabio Estevamd4ffeec2014-11-07 00:44:34 -0200671 i2c_imx = devm_kzalloc(&pdev->dev, sizeof(*i2c_imx), GFP_KERNEL);
Jingoo Han46797a22014-05-13 10:51:58 +0900672 if (!i2c_imx)
Richard Zhao9f8a3e72012-06-04 19:04:25 +0800673 return -ENOMEM;
Darius Augulis309c18d2009-03-31 14:52:54 +0300674
Shawn Guo5bdfba22012-09-14 15:19:00 +0800675 if (of_id)
Jingchang Lu4b775022013-08-07 17:05:42 +0800676 i2c_imx->hwdata = of_id->data;
Jingchang Lu0fc13472013-08-07 17:05:38 +0800677 else
Jingchang Lu4b775022013-08-07 17:05:42 +0800678 i2c_imx->hwdata = (struct imx_i2c_hwdata *)
679 platform_get_device_id(pdev)->driver_data;
Shawn Guo5bdfba22012-09-14 15:19:00 +0800680
Darius Augulisaa11e382009-01-30 10:32:28 +0200681 /* Setup i2c_imx driver structure */
Wolfram Sang973c5ed2012-04-19 17:31:01 +0200682 strlcpy(i2c_imx->adapter.name, pdev->name, sizeof(i2c_imx->adapter.name));
Darius Augulisaa11e382009-01-30 10:32:28 +0200683 i2c_imx->adapter.owner = THIS_MODULE;
684 i2c_imx->adapter.algo = &i2c_imx_algo;
685 i2c_imx->adapter.dev.parent = &pdev->dev;
686 i2c_imx->adapter.nr = pdev->id;
Shawn Guodfcd04b2011-09-08 15:09:35 +0800687 i2c_imx->adapter.dev.of_node = pdev->dev.of_node;
Darius Augulisaa11e382009-01-30 10:32:28 +0200688 i2c_imx->base = base;
Darius Augulisaa11e382009-01-30 10:32:28 +0200689
690 /* Get I2C clock */
Fabio Estevam1f09c672012-07-06 15:31:32 -0300691 i2c_imx->clk = devm_clk_get(&pdev->dev, NULL);
Darius Augulisaa11e382009-01-30 10:32:28 +0200692 if (IS_ERR(i2c_imx->clk)) {
Darius Augulisaa11e382009-01-30 10:32:28 +0200693 dev_err(&pdev->dev, "can't get I2C clock\n");
Richard Zhao9f8a3e72012-06-04 19:04:25 +0800694 return PTR_ERR(i2c_imx->clk);
Darius Augulisaa11e382009-01-30 10:32:28 +0200695 }
Darius Augulisaa11e382009-01-30 10:32:28 +0200696
Jingchang Lu46f28322013-08-07 17:05:37 +0800697 ret = clk_prepare_enable(i2c_imx->clk);
698 if (ret) {
699 dev_err(&pdev->dev, "can't enable I2C clock\n");
700 return ret;
701 }
Darius Augulisaa11e382009-01-30 10:32:28 +0200702 /* Request IRQ */
Richard Zhao9f8a3e72012-06-04 19:04:25 +0800703 ret = devm_request_irq(&pdev->dev, irq, i2c_imx_isr, 0,
704 pdev->name, i2c_imx);
Darius Augulisaa11e382009-01-30 10:32:28 +0200705 if (ret) {
Richard Zhao9f8a3e72012-06-04 19:04:25 +0800706 dev_err(&pdev->dev, "can't claim irq %d\n", irq);
Fabio Estevama4ce47f2014-10-04 09:17:27 -0300707 goto clk_disable;
Darius Augulisaa11e382009-01-30 10:32:28 +0200708 }
709
710 /* Init queue */
711 init_waitqueue_head(&i2c_imx->queue);
712
713 /* Set up adapter data */
714 i2c_set_adapdata(&i2c_imx->adapter, i2c_imx);
715
716 /* Set up clock divider */
Fugang Duan9b2a6da2014-05-20 10:21:45 +0800717 i2c_imx->bitrate = IMX_I2C_BIT_RATE;
Shawn Guodfcd04b2011-09-08 15:09:35 +0800718 ret = of_property_read_u32(pdev->dev.of_node,
Fugang Duan9b2a6da2014-05-20 10:21:45 +0800719 "clock-frequency", &i2c_imx->bitrate);
Shawn Guodfcd04b2011-09-08 15:09:35 +0800720 if (ret < 0 && pdata && pdata->bitrate)
Fugang Duan9b2a6da2014-05-20 10:21:45 +0800721 i2c_imx->bitrate = pdata->bitrate;
Darius Augulisaa11e382009-01-30 10:32:28 +0200722
723 /* Set up chip registers to defaults */
Jingchang Lu4b775022013-08-07 17:05:42 +0800724 imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN,
725 i2c_imx, IMX_I2C_I2CR);
726 imx_i2c_write_reg(i2c_imx->hwdata->i2sr_clr_opcode, i2c_imx, IMX_I2C_I2SR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200727
728 /* Add I2C adapter */
729 ret = i2c_add_numbered_adapter(&i2c_imx->adapter);
730 if (ret < 0) {
731 dev_err(&pdev->dev, "registration failed\n");
Fabio Estevama4ce47f2014-10-04 09:17:27 -0300732 goto clk_disable;
Darius Augulisaa11e382009-01-30 10:32:28 +0200733 }
734
735 /* Set up platform driver data */
736 platform_set_drvdata(pdev, i2c_imx);
Jingchang Lu46f28322013-08-07 17:05:37 +0800737 clk_disable_unprepare(i2c_imx->clk);
Darius Augulisaa11e382009-01-30 10:32:28 +0200738
Richard Zhao9f8a3e72012-06-04 19:04:25 +0800739 dev_dbg(&i2c_imx->adapter.dev, "claimed irq %d\n", irq);
Xiubo Li64bdfbf2014-08-06 11:45:08 +0800740 dev_dbg(&i2c_imx->adapter.dev, "device resources: %pR\n", res);
Darius Augulisaa11e382009-01-30 10:32:28 +0200741 dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
742 i2c_imx->adapter.name);
Fabio Estevam06d141e2012-08-01 17:38:14 -0300743 dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
Darius Augulisaa11e382009-01-30 10:32:28 +0200744
745 return 0; /* Return OK */
Fabio Estevama4ce47f2014-10-04 09:17:27 -0300746
747clk_disable:
748 clk_disable_unprepare(i2c_imx->clk);
749 return ret;
Darius Augulisaa11e382009-01-30 10:32:28 +0200750}
751
Wolfram Sang36114312013-10-08 22:35:34 +0200752static int i2c_imx_remove(struct platform_device *pdev)
Darius Augulisaa11e382009-01-30 10:32:28 +0200753{
754 struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev);
Darius Augulisaa11e382009-01-30 10:32:28 +0200755
756 /* remove adapter */
757 dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n");
758 i2c_del_adapter(&i2c_imx->adapter);
Darius Augulisaa11e382009-01-30 10:32:28 +0200759
Darius Augulisaa11e382009-01-30 10:32:28 +0200760 /* setup chip registers to defaults */
Jingchang Lu1d5ef2a2013-08-07 17:05:39 +0800761 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IADR);
762 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IFDR);
763 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2CR);
764 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR);
Darius Augulisaa11e382009-01-30 10:32:28 +0200765
Darius Augulisaa11e382009-01-30 10:32:28 +0200766 return 0;
767}
768
769static struct platform_driver i2c_imx_driver = {
Wolfram Sang36114312013-10-08 22:35:34 +0200770 .probe = i2c_imx_probe,
771 .remove = i2c_imx_remove,
Darius Augulisaa11e382009-01-30 10:32:28 +0200772 .driver = {
773 .name = DRIVER_NAME,
774 .owner = THIS_MODULE,
Shawn Guodfcd04b2011-09-08 15:09:35 +0800775 .of_match_table = i2c_imx_dt_ids,
Shawn Guo5bdfba22012-09-14 15:19:00 +0800776 },
777 .id_table = imx_i2c_devtype,
Darius Augulisaa11e382009-01-30 10:32:28 +0200778};
779
780static int __init i2c_adap_imx_init(void)
781{
Wolfram Sang36114312013-10-08 22:35:34 +0200782 return platform_driver_register(&i2c_imx_driver);
Darius Augulisaa11e382009-01-30 10:32:28 +0200783}
Wolfram Sang5d3f3332009-09-19 09:09:50 +0200784subsys_initcall(i2c_adap_imx_init);
Darius Augulisaa11e382009-01-30 10:32:28 +0200785
786static void __exit i2c_adap_imx_exit(void)
787{
788 platform_driver_unregister(&i2c_imx_driver);
789}
Darius Augulisaa11e382009-01-30 10:32:28 +0200790module_exit(i2c_adap_imx_exit);
791
792MODULE_LICENSE("GPL");
793MODULE_AUTHOR("Darius Augulis");
794MODULE_DESCRIPTION("I2C adapter driver for IMX I2C bus");
795MODULE_ALIAS("platform:" DRIVER_NAME);