blob: bdae4caa40f6e448dc463bd5ce9bb16c65a8de0d [file] [log] [blame]
Peter Korsgaard18f98b12006-06-04 20:01:08 +02001/*
2 * i2c-ocores.c: I2C bus driver for OpenCores I2C controller
3 * (http://www.opencores.org/projects.cgi/web/i2c/overview).
4 *
5 * Peter Korsgaard <jacmet@sunsite.dk>
6 *
Andreas Larssona000b8c12012-11-15 16:50:59 +01007 * Support for the GRLIB port of the controller by
8 * Andreas Larsson <andreas@gaisler.com>
9 *
Peter Korsgaard18f98b12006-06-04 20:01:08 +020010 * This file is licensed under the terms of the GNU General Public License
11 * version 2. This program is licensed "as is" without any warranty of any
12 * kind, whether express or implied.
13 */
14
Thierry Reding84dbf802013-01-21 11:09:03 +010015#include <linux/err.h>
Peter Korsgaard18f98b12006-06-04 20:01:08 +020016#include <linux/kernel.h>
17#include <linux/module.h>
Peter Korsgaard18f98b12006-06-04 20:01:08 +020018#include <linux/init.h>
19#include <linux/errno.h>
20#include <linux/platform_device.h>
21#include <linux/i2c.h>
22#include <linux/interrupt.h>
23#include <linux/wait.h>
24#include <linux/i2c-ocores.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
H Hartley Sweeten21782182010-05-21 18:41:01 +020026#include <linux/io.h>
Ganesan Ramalingama5063f12012-05-08 18:55:28 +053027#include <linux/of_i2c.h>
Ganesan Ramalingam8bb986a2012-07-13 19:14:23 +053028#include <linux/log2.h>
Peter Korsgaard18f98b12006-06-04 20:01:08 +020029
30struct ocores_i2c {
31 void __iomem *base;
Ganesan Ramalingam8bb986a2012-07-13 19:14:23 +053032 u32 reg_shift;
Ganesan Ramalingam7326e382012-07-13 19:14:25 +053033 u32 reg_io_width;
Peter Korsgaard18f98b12006-06-04 20:01:08 +020034 wait_queue_head_t wait;
35 struct i2c_adapter adap;
36 struct i2c_msg *msg;
37 int pos;
38 int nmsgs;
39 int state; /* see STATE_ */
Manuel Lauss2373c182008-07-14 22:38:33 +020040 int clock_khz;
Andreas Larssona000b8c12012-11-15 16:50:59 +010041 void (*setreg)(struct ocores_i2c *i2c, int reg, u8 value);
42 u8 (*getreg)(struct ocores_i2c *i2c, int reg);
Peter Korsgaard18f98b12006-06-04 20:01:08 +020043};
44
45/* registers */
46#define OCI2C_PRELOW 0
47#define OCI2C_PREHIGH 1
48#define OCI2C_CONTROL 2
49#define OCI2C_DATA 3
Peter Korsgaard1ded9692006-06-12 21:40:53 +020050#define OCI2C_CMD 4 /* write only */
51#define OCI2C_STATUS 4 /* read only, same address as OCI2C_CMD */
Peter Korsgaard18f98b12006-06-04 20:01:08 +020052
53#define OCI2C_CTRL_IEN 0x40
54#define OCI2C_CTRL_EN 0x80
55
56#define OCI2C_CMD_START 0x91
57#define OCI2C_CMD_STOP 0x41
58#define OCI2C_CMD_READ 0x21
59#define OCI2C_CMD_WRITE 0x11
60#define OCI2C_CMD_READ_ACK 0x21
61#define OCI2C_CMD_READ_NACK 0x29
62#define OCI2C_CMD_IACK 0x01
63
64#define OCI2C_STAT_IF 0x01
65#define OCI2C_STAT_TIP 0x02
66#define OCI2C_STAT_ARBLOST 0x20
67#define OCI2C_STAT_BUSY 0x40
68#define OCI2C_STAT_NACK 0x80
69
70#define STATE_DONE 0
71#define STATE_START 1
72#define STATE_WRITE 2
73#define STATE_READ 3
74#define STATE_ERROR 4
75
Andreas Larssona000b8c12012-11-15 16:50:59 +010076#define TYPE_OCORES 0
77#define TYPE_GRLIB 1
78
79static void oc_setreg_8(struct ocores_i2c *i2c, int reg, u8 value)
80{
81 iowrite8(value, i2c->base + (reg << i2c->reg_shift));
82}
83
84static void oc_setreg_16(struct ocores_i2c *i2c, int reg, u8 value)
85{
86 iowrite16(value, i2c->base + (reg << i2c->reg_shift));
87}
88
89static void oc_setreg_32(struct ocores_i2c *i2c, int reg, u8 value)
90{
91 iowrite32(value, i2c->base + (reg << i2c->reg_shift));
92}
93
94static inline u8 oc_getreg_8(struct ocores_i2c *i2c, int reg)
95{
96 return ioread8(i2c->base + (reg << i2c->reg_shift));
97}
98
99static inline u8 oc_getreg_16(struct ocores_i2c *i2c, int reg)
100{
101 return ioread16(i2c->base + (reg << i2c->reg_shift));
102}
103
104static inline u8 oc_getreg_32(struct ocores_i2c *i2c, int reg)
105{
106 return ioread32(i2c->base + (reg << i2c->reg_shift));
107}
108
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200109static inline void oc_setreg(struct ocores_i2c *i2c, int reg, u8 value)
110{
Andreas Larssona000b8c12012-11-15 16:50:59 +0100111 i2c->setreg(i2c, reg, value);
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200112}
113
114static inline u8 oc_getreg(struct ocores_i2c *i2c, int reg)
115{
Andreas Larssona000b8c12012-11-15 16:50:59 +0100116 return i2c->getreg(i2c, reg);
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200117}
118
119static void ocores_process(struct ocores_i2c *i2c)
120{
121 struct i2c_msg *msg = i2c->msg;
122 u8 stat = oc_getreg(i2c, OCI2C_STATUS);
123
124 if ((i2c->state == STATE_DONE) || (i2c->state == STATE_ERROR)) {
125 /* stop has been sent */
126 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_IACK);
127 wake_up(&i2c->wait);
128 return;
129 }
130
131 /* error? */
132 if (stat & OCI2C_STAT_ARBLOST) {
133 i2c->state = STATE_ERROR;
134 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP);
135 return;
136 }
137
138 if ((i2c->state == STATE_START) || (i2c->state == STATE_WRITE)) {
139 i2c->state =
140 (msg->flags & I2C_M_RD) ? STATE_READ : STATE_WRITE;
141
142 if (stat & OCI2C_STAT_NACK) {
143 i2c->state = STATE_ERROR;
144 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP);
145 return;
146 }
147 } else
148 msg->buf[i2c->pos++] = oc_getreg(i2c, OCI2C_DATA);
149
150 /* end of msg? */
151 if (i2c->pos == msg->len) {
152 i2c->nmsgs--;
153 i2c->msg++;
154 i2c->pos = 0;
155 msg = i2c->msg;
156
157 if (i2c->nmsgs) { /* end? */
158 /* send start? */
159 if (!(msg->flags & I2C_M_NOSTART)) {
160 u8 addr = (msg->addr << 1);
161
162 if (msg->flags & I2C_M_RD)
163 addr |= 1;
164
165 i2c->state = STATE_START;
166
167 oc_setreg(i2c, OCI2C_DATA, addr);
168 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START);
169 return;
170 } else
171 i2c->state = (msg->flags & I2C_M_RD)
172 ? STATE_READ : STATE_WRITE;
173 } else {
174 i2c->state = STATE_DONE;
175 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP);
176 return;
177 }
178 }
179
180 if (i2c->state == STATE_READ) {
181 oc_setreg(i2c, OCI2C_CMD, i2c->pos == (msg->len-1) ?
182 OCI2C_CMD_READ_NACK : OCI2C_CMD_READ_ACK);
183 } else {
184 oc_setreg(i2c, OCI2C_DATA, msg->buf[i2c->pos++]);
185 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_WRITE);
186 }
187}
188
David Howells7d12e782006-10-05 14:55:46 +0100189static irqreturn_t ocores_isr(int irq, void *dev_id)
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200190{
191 struct ocores_i2c *i2c = dev_id;
192
193 ocores_process(i2c);
194
195 return IRQ_HANDLED;
196}
197
198static int ocores_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
199{
200 struct ocores_i2c *i2c = i2c_get_adapdata(adap);
201
202 i2c->msg = msgs;
203 i2c->pos = 0;
204 i2c->nmsgs = num;
205 i2c->state = STATE_START;
206
207 oc_setreg(i2c, OCI2C_DATA,
208 (i2c->msg->addr << 1) |
209 ((i2c->msg->flags & I2C_M_RD) ? 1:0));
210
211 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START);
212
213 if (wait_event_timeout(i2c->wait, (i2c->state == STATE_ERROR) ||
214 (i2c->state == STATE_DONE), HZ))
215 return (i2c->state == STATE_DONE) ? num : -EIO;
216 else
217 return -ETIMEDOUT;
218}
219
Manuel Lauss2373c182008-07-14 22:38:33 +0200220static void ocores_init(struct ocores_i2c *i2c)
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200221{
222 int prescale;
223 u8 ctrl = oc_getreg(i2c, OCI2C_CONTROL);
224
225 /* make sure the device is disabled */
226 oc_setreg(i2c, OCI2C_CONTROL, ctrl & ~(OCI2C_CTRL_EN|OCI2C_CTRL_IEN));
227
Manuel Lauss2373c182008-07-14 22:38:33 +0200228 prescale = (i2c->clock_khz / (5*100)) - 1;
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200229 oc_setreg(i2c, OCI2C_PRELOW, prescale & 0xff);
230 oc_setreg(i2c, OCI2C_PREHIGH, prescale >> 8);
231
232 /* Init the device */
233 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_IACK);
234 oc_setreg(i2c, OCI2C_CONTROL, ctrl | OCI2C_CTRL_IEN | OCI2C_CTRL_EN);
235}
236
237
238static u32 ocores_func(struct i2c_adapter *adap)
239{
240 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
241}
242
Jean Delvare8f9082c2006-09-03 22:39:46 +0200243static const struct i2c_algorithm ocores_algorithm = {
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200244 .master_xfer = ocores_xfer,
245 .functionality = ocores_func,
246};
247
248static struct i2c_adapter ocores_adapter = {
249 .owner = THIS_MODULE,
250 .name = "i2c-ocores",
Jean Delvare3401b2f2008-07-14 22:38:29 +0200251 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200252 .algo = &ocores_algorithm,
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200253};
254
Andreas Larssona000b8c12012-11-15 16:50:59 +0100255static struct of_device_id ocores_i2c_match[] = {
256 {
257 .compatible = "opencores,i2c-ocores",
258 .data = (void *)TYPE_OCORES,
259 },
260 {
261 .compatible = "aeroflexgaisler,i2cmst",
262 .data = (void *)TYPE_GRLIB,
263 },
264 {},
265};
266MODULE_DEVICE_TABLE(of, ocores_i2c_match);
267
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100268#ifdef CONFIG_OF
Andreas Larssonc5d54742012-11-19 13:17:48 +0100269/* Read and write functions for the GRLIB port of the controller. Registers are
270 * 32-bit big endian and the PRELOW and PREHIGH registers are merged into one
271 * register. The subsequent registers has their offset decreased accordingly. */
272static u8 oc_getreg_grlib(struct ocores_i2c *i2c, int reg)
273{
274 u32 rd;
275 int rreg = reg;
276 if (reg != OCI2C_PRELOW)
277 rreg--;
278 rd = ioread32be(i2c->base + (rreg << i2c->reg_shift));
279 if (reg == OCI2C_PREHIGH)
280 return (u8)(rd >> 8);
281 else
282 return (u8)rd;
283}
284
285static void oc_setreg_grlib(struct ocores_i2c *i2c, int reg, u8 value)
286{
287 u32 curr, wr;
288 int rreg = reg;
289 if (reg != OCI2C_PRELOW)
290 rreg--;
291 if (reg == OCI2C_PRELOW || reg == OCI2C_PREHIGH) {
292 curr = ioread32be(i2c->base + (rreg << i2c->reg_shift));
293 if (reg == OCI2C_PRELOW)
294 wr = (curr & 0xff00) | value;
295 else
296 wr = (((u32)value) << 8) | (curr & 0xff);
297 } else {
298 wr = value;
299 }
300 iowrite32be(wr, i2c->base + (rreg << i2c->reg_shift));
301}
302
Jayachandran C9ae97a82012-07-13 19:14:22 +0530303static int ocores_i2c_of_probe(struct platform_device *pdev,
304 struct ocores_i2c *i2c)
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100305{
Ganesan Ramalingam8bb986a2012-07-13 19:14:23 +0530306 struct device_node *np = pdev->dev.of_node;
Andreas Larssona000b8c12012-11-15 16:50:59 +0100307 const struct of_device_id *match;
Ganesan Ramalingam8bb986a2012-07-13 19:14:23 +0530308 u32 val;
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100309
Ganesan Ramalingam8bb986a2012-07-13 19:14:23 +0530310 if (of_property_read_u32(np, "reg-shift", &i2c->reg_shift)) {
311 /* no 'reg-shift', check for deprecated 'regstep' */
312 if (!of_property_read_u32(np, "regstep", &val)) {
313 if (!is_power_of_2(val)) {
314 dev_err(&pdev->dev, "invalid regstep %d\n",
315 val);
316 return -EINVAL;
317 }
318 i2c->reg_shift = ilog2(val);
319 dev_warn(&pdev->dev,
320 "regstep property deprecated, use reg-shift\n");
321 }
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100322 }
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100323
Ganesan Ramalingam8bb986a2012-07-13 19:14:23 +0530324 if (of_property_read_u32(np, "clock-frequency", &val)) {
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100325 dev_err(&pdev->dev,
Jayachandran C9ae97a82012-07-13 19:14:22 +0530326 "Missing required parameter 'clock-frequency'\n");
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100327 return -ENODEV;
328 }
Ganesan Ramalingam8bb986a2012-07-13 19:14:23 +0530329 i2c->clock_khz = val / 1000;
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100330
Ganesan Ramalingam7326e382012-07-13 19:14:25 +0530331 of_property_read_u32(pdev->dev.of_node, "reg-io-width",
332 &i2c->reg_io_width);
Andreas Larssona000b8c12012-11-15 16:50:59 +0100333
334 match = of_match_node(ocores_i2c_match, pdev->dev.of_node);
Jayachandran C6beaddf2013-02-18 21:33:19 +0000335 if (match && (long)match->data == TYPE_GRLIB) {
Andreas Larssona000b8c12012-11-15 16:50:59 +0100336 dev_dbg(&pdev->dev, "GRLIB variant of i2c-ocores\n");
337 i2c->setreg = oc_setreg_grlib;
338 i2c->getreg = oc_getreg_grlib;
339 }
340
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100341 return 0;
342}
343#else
344#define ocores_i2c_of_probe(pdev,i2c) -ENODEV
345#endif
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200346
Bill Pemberton0b255e92012-11-27 15:59:38 -0500347static int ocores_i2c_probe(struct platform_device *pdev)
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200348{
349 struct ocores_i2c *i2c;
350 struct ocores_i2c_platform_data *pdata;
Andreas Larssonf5f35a92012-11-15 16:50:58 +0100351 struct resource *res;
352 int irq;
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200353 int ret;
Richard Röjforsdd14be42009-06-05 15:40:32 +0200354 int i;
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200355
356 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
357 if (!res)
358 return -ENODEV;
359
Andreas Larssonf5f35a92012-11-15 16:50:58 +0100360 irq = platform_get_irq(pdev, 0);
361 if (irq < 0)
362 return irq;
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200363
Jonas Bonn47def5b2010-11-24 17:26:21 +0100364 i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL);
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200365 if (!i2c)
366 return -ENOMEM;
367
Thierry Reding84dbf802013-01-21 11:09:03 +0100368 i2c->base = devm_ioremap_resource(&pdev->dev, res);
369 if (IS_ERR(i2c->base))
370 return PTR_ERR(i2c->base);
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200371
Samuel Ortiz3271d382011-04-08 01:23:57 +0200372 pdata = pdev->dev.platform_data;
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100373 if (pdata) {
Ganesan Ramalingam8bb986a2012-07-13 19:14:23 +0530374 i2c->reg_shift = pdata->reg_shift;
Ganesan Ramalingam7326e382012-07-13 19:14:25 +0530375 i2c->reg_io_width = pdata->reg_io_width;
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100376 i2c->clock_khz = pdata->clock_khz;
377 } else {
378 ret = ocores_i2c_of_probe(pdev, i2c);
379 if (ret)
380 return ret;
381 }
382
Ganesan Ramalingam7326e382012-07-13 19:14:25 +0530383 if (i2c->reg_io_width == 0)
384 i2c->reg_io_width = 1; /* Set to default value */
385
Andreas Larssona000b8c12012-11-15 16:50:59 +0100386 if (!i2c->setreg || !i2c->getreg) {
387 switch (i2c->reg_io_width) {
388 case 1:
389 i2c->setreg = oc_setreg_8;
390 i2c->getreg = oc_getreg_8;
391 break;
392
393 case 2:
394 i2c->setreg = oc_setreg_16;
395 i2c->getreg = oc_getreg_16;
396 break;
397
398 case 4:
399 i2c->setreg = oc_setreg_32;
400 i2c->getreg = oc_getreg_32;
401 break;
402
403 default:
404 dev_err(&pdev->dev, "Unsupported I/O width (%d)\n",
405 i2c->reg_io_width);
406 return -EINVAL;
407 }
408 }
409
Manuel Lauss2373c182008-07-14 22:38:33 +0200410 ocores_init(i2c);
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200411
412 init_waitqueue_head(&i2c->wait);
Andreas Larssonf5f35a92012-11-15 16:50:58 +0100413 ret = devm_request_irq(&pdev->dev, irq, ocores_isr, 0,
Jonas Bonn47def5b2010-11-24 17:26:21 +0100414 pdev->name, i2c);
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200415 if (ret) {
416 dev_err(&pdev->dev, "Cannot claim IRQ\n");
Jonas Bonn47def5b2010-11-24 17:26:21 +0100417 return ret;
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200418 }
419
420 /* hook up driver to tree */
421 platform_set_drvdata(pdev, i2c);
422 i2c->adap = ocores_adapter;
423 i2c_set_adapdata(&i2c->adap, i2c);
424 i2c->adap.dev.parent = &pdev->dev;
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100425 i2c->adap.dev.of_node = pdev->dev.of_node;
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200426
427 /* add i2c adapter to i2c tree */
428 ret = i2c_add_adapter(&i2c->adap);
429 if (ret) {
430 dev_err(&pdev->dev, "Failed to add adapter\n");
Jonas Bonn47def5b2010-11-24 17:26:21 +0100431 return ret;
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200432 }
433
Richard Röjforsdd14be42009-06-05 15:40:32 +0200434 /* add in known devices to the bus */
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100435 if (pdata) {
436 for (i = 0; i < pdata->num_devices; i++)
437 i2c_new_device(&i2c->adap, pdata->devices + i);
Ganesan Ramalingama5063f12012-05-08 18:55:28 +0530438 } else {
439 of_i2c_register_devices(&i2c->adap);
Jonas Bonn049bb69d2010-11-24 17:26:20 +0100440 }
Richard Röjforsdd14be42009-06-05 15:40:32 +0200441
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200442 return 0;
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200443}
444
Bill Pemberton0b255e92012-11-27 15:59:38 -0500445static int ocores_i2c_remove(struct platform_device *pdev)
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200446{
447 struct ocores_i2c *i2c = platform_get_drvdata(pdev);
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200448
449 /* disable i2c logic */
450 oc_setreg(i2c, OCI2C_CONTROL, oc_getreg(i2c, OCI2C_CONTROL)
451 & ~(OCI2C_CTRL_EN|OCI2C_CTRL_IEN));
452
453 /* remove adapter & data */
454 i2c_del_adapter(&i2c->adap);
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200455
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200456 return 0;
457}
458
Jingoo Hanf076e912013-07-15 11:29:35 +0900459#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki84603c72012-07-11 21:24:15 +0200460static int ocores_i2c_suspend(struct device *dev)
Manuel Lauss2373c182008-07-14 22:38:33 +0200461{
Rafael J. Wysocki84603c72012-07-11 21:24:15 +0200462 struct ocores_i2c *i2c = dev_get_drvdata(dev);
Manuel Lauss2373c182008-07-14 22:38:33 +0200463 u8 ctrl = oc_getreg(i2c, OCI2C_CONTROL);
464
465 /* make sure the device is disabled */
466 oc_setreg(i2c, OCI2C_CONTROL, ctrl & ~(OCI2C_CTRL_EN|OCI2C_CTRL_IEN));
467
468 return 0;
469}
470
Rafael J. Wysocki84603c72012-07-11 21:24:15 +0200471static int ocores_i2c_resume(struct device *dev)
Manuel Lauss2373c182008-07-14 22:38:33 +0200472{
Rafael J. Wysocki84603c72012-07-11 21:24:15 +0200473 struct ocores_i2c *i2c = dev_get_drvdata(dev);
Manuel Lauss2373c182008-07-14 22:38:33 +0200474
475 ocores_init(i2c);
476
477 return 0;
478}
Rafael J. Wysocki84603c72012-07-11 21:24:15 +0200479
480static SIMPLE_DEV_PM_OPS(ocores_i2c_pm, ocores_i2c_suspend, ocores_i2c_resume);
481#define OCORES_I2C_PM (&ocores_i2c_pm)
Manuel Lauss2373c182008-07-14 22:38:33 +0200482#else
Rafael J. Wysocki84603c72012-07-11 21:24:15 +0200483#define OCORES_I2C_PM NULL
Manuel Lauss2373c182008-07-14 22:38:33 +0200484#endif
485
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200486static struct platform_driver ocores_i2c_driver = {
Manuel Lauss2373c182008-07-14 22:38:33 +0200487 .probe = ocores_i2c_probe,
Bill Pemberton0b255e92012-11-27 15:59:38 -0500488 .remove = ocores_i2c_remove,
Manuel Lauss2373c182008-07-14 22:38:33 +0200489 .driver = {
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200490 .owner = THIS_MODULE,
491 .name = "ocores-i2c",
Grant Likelyc9e358d2011-01-21 09:24:48 -0700492 .of_match_table = ocores_i2c_match,
Rafael J. Wysocki84603c72012-07-11 21:24:15 +0200493 .pm = OCORES_I2C_PM,
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200494 },
495};
496
Axel Lina3664b52012-01-12 20:32:04 +0100497module_platform_driver(ocores_i2c_driver);
Peter Korsgaard18f98b12006-06-04 20:01:08 +0200498
499MODULE_AUTHOR("Peter Korsgaard <jacmet@sunsite.dk>");
500MODULE_DESCRIPTION("OpenCores I2C bus driver");
501MODULE_LICENSE("GPL");
Axel Lina3664b52012-01-12 20:32:04 +0100502MODULE_ALIAS("platform:ocores-i2c");