blob: 8654cb9787703c8a053db5252b1560c6c43ec558 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13/*
14 * QUP driver for Qualcomm MSM platforms
15 *
16 */
17
18/* #define DEBUG */
19
20#include <linux/clk.h>
21#include <linux/err.h>
22#include <linux/init.h>
23#include <linux/i2c.h>
24#include <linux/interrupt.h>
25#include <linux/platform_device.h>
26#include <linux/delay.h>
27#include <linux/io.h>
28#include <linux/mutex.h>
29#include <linux/timer.h>
30#include <linux/slab.h>
31#include <mach/board.h>
32#include <linux/slab.h>
33#include <linux/pm_runtime.h>
34#include <linux/gpio.h>
35
36MODULE_LICENSE("GPL v2");
37MODULE_VERSION("0.2");
38MODULE_ALIAS("platform:i2c_qup");
39
40/* QUP Registers */
41enum {
42 QUP_CONFIG = 0x0,
43 QUP_STATE = 0x4,
44 QUP_IO_MODE = 0x8,
45 QUP_SW_RESET = 0xC,
46 QUP_OPERATIONAL = 0x18,
47 QUP_ERROR_FLAGS = 0x1C,
48 QUP_ERROR_FLAGS_EN = 0x20,
49 QUP_MX_READ_CNT = 0x208,
50 QUP_MX_INPUT_CNT = 0x200,
51 QUP_MX_WR_CNT = 0x100,
52 QUP_OUT_DEBUG = 0x108,
53 QUP_OUT_FIFO_CNT = 0x10C,
54 QUP_OUT_FIFO_BASE = 0x110,
55 QUP_IN_READ_CUR = 0x20C,
56 QUP_IN_DEBUG = 0x210,
57 QUP_IN_FIFO_CNT = 0x214,
58 QUP_IN_FIFO_BASE = 0x218,
59 QUP_I2C_CLK_CTL = 0x400,
60 QUP_I2C_STATUS = 0x404,
61};
62
63/* QUP States and reset values */
64enum {
65 QUP_RESET_STATE = 0,
66 QUP_RUN_STATE = 1U,
67 QUP_STATE_MASK = 3U,
68 QUP_PAUSE_STATE = 3U,
69 QUP_STATE_VALID = 1U << 2,
70 QUP_I2C_MAST_GEN = 1U << 4,
71 QUP_OPERATIONAL_RESET = 0xFF0,
72 QUP_I2C_STATUS_RESET = 0xFFFFFC,
73};
74
75/* QUP OPERATIONAL FLAGS */
76enum {
77 QUP_OUT_SVC_FLAG = 1U << 8,
78 QUP_IN_SVC_FLAG = 1U << 9,
79 QUP_MX_INPUT_DONE = 1U << 11,
80};
81
82/* I2C mini core related values */
83enum {
84 I2C_MINI_CORE = 2U << 8,
85 I2C_N_VAL = 0xF,
86
87};
88
89/* Packing Unpacking words in FIFOs , and IO modes*/
90enum {
91 QUP_WR_BLK_MODE = 1U << 10,
92 QUP_RD_BLK_MODE = 1U << 12,
93 QUP_UNPACK_EN = 1U << 14,
94 QUP_PACK_EN = 1U << 15,
95};
96
97/* QUP tags */
98enum {
99 QUP_OUT_NOP = 0,
100 QUP_OUT_START = 1U << 8,
101 QUP_OUT_DATA = 2U << 8,
102 QUP_OUT_STOP = 3U << 8,
103 QUP_OUT_REC = 4U << 8,
104 QUP_IN_DATA = 5U << 8,
105 QUP_IN_STOP = 6U << 8,
106 QUP_IN_NACK = 7U << 8,
107};
108
109/* Status, Error flags */
110enum {
111 I2C_STATUS_WR_BUFFER_FULL = 1U << 0,
112 I2C_STATUS_BUS_ACTIVE = 1U << 8,
113 I2C_STATUS_ERROR_MASK = 0x38000FC,
114 QUP_I2C_NACK_FLAG = 1U << 3,
115 QUP_IN_NOT_EMPTY = 1U << 5,
116 QUP_STATUS_ERROR_FLAGS = 0x7C,
117};
118
119/* Master status clock states */
120enum {
121 I2C_CLK_RESET_BUSIDLE_STATE = 0,
122 I2C_CLK_FORCED_LOW_STATE = 5,
123};
124
125#define QUP_MAX_CLK_STATE_RETRIES 300
126
127static char const * const i2c_rsrcs[] = {"i2c_clk", "i2c_sda"};
128
129struct qup_i2c_dev {
130 struct device *dev;
131 void __iomem *base; /* virtual */
132 void __iomem *gsbi; /* virtual */
133 int in_irq;
134 int out_irq;
135 int err_irq;
136 int num_irqs;
137 struct clk *clk;
138 struct clk *pclk;
139 struct i2c_adapter adapter;
140
141 struct i2c_msg *msg;
142 int pos;
143 int cnt;
144 int err;
145 int mode;
146 int clk_ctl;
147 int one_bit_t;
148 int out_fifo_sz;
149 int in_fifo_sz;
150 int out_blk_sz;
151 int in_blk_sz;
152 int wr_sz;
153 struct msm_i2c_platform_data *pdata;
154 int suspended;
155 int clk_state;
156 struct timer_list pwr_timer;
157 struct mutex mlock;
158 void *complete;
159 int i2c_gpios[ARRAY_SIZE(i2c_rsrcs)];
160};
161
162#ifdef DEBUG
163static void
164qup_print_status(struct qup_i2c_dev *dev)
165{
166 uint32_t val;
167 val = readl_relaxed(dev->base+QUP_CONFIG);
168 dev_dbg(dev->dev, "Qup config is :0x%x\n", val);
169 val = readl_relaxed(dev->base+QUP_STATE);
170 dev_dbg(dev->dev, "Qup state is :0x%x\n", val);
171 val = readl_relaxed(dev->base+QUP_IO_MODE);
172 dev_dbg(dev->dev, "Qup mode is :0x%x\n", val);
173}
174#else
175static inline void qup_print_status(struct qup_i2c_dev *dev)
176{
177}
178#endif
179
180static irqreturn_t
181qup_i2c_interrupt(int irq, void *devid)
182{
183 struct qup_i2c_dev *dev = devid;
184 uint32_t status = readl_relaxed(dev->base + QUP_I2C_STATUS);
185 uint32_t status1 = readl_relaxed(dev->base + QUP_ERROR_FLAGS);
186 uint32_t op_flgs = readl_relaxed(dev->base + QUP_OPERATIONAL);
187 int err = 0;
188
189 if (!dev->msg || !dev->complete) {
190 /* Clear Error interrupt if it's a level triggered interrupt*/
191 if (dev->num_irqs == 1) {
192 writel_relaxed(QUP_RESET_STATE, dev->base+QUP_STATE);
193 /* Ensure that state is written before ISR exits */
194 mb();
195 }
196 return IRQ_HANDLED;
197 }
198
199 if (status & I2C_STATUS_ERROR_MASK) {
200 dev_err(dev->dev, "QUP: I2C status flags :0x%x, irq:%d\n",
201 status, irq);
202 err = status;
203 /* Clear Error interrupt if it's a level triggered interrupt*/
204 if (dev->num_irqs == 1) {
205 writel_relaxed(QUP_RESET_STATE, dev->base+QUP_STATE);
206 /* Ensure that state is written before ISR exits */
207 mb();
208 }
209 goto intr_done;
210 }
211
212 if (status1 & 0x7F) {
213 dev_err(dev->dev, "QUP: QUP status flags :0x%x\n", status1);
214 err = -status1;
215 /* Clear Error interrupt if it's a level triggered interrupt*/
216 if (dev->num_irqs == 1) {
217 writel_relaxed((status1 & QUP_STATUS_ERROR_FLAGS),
218 dev->base + QUP_ERROR_FLAGS);
219 /* Ensure that error flags are cleared before ISR
220 * exits
221 */
222 mb();
223 }
224 goto intr_done;
225 }
226
227 if ((dev->num_irqs == 3) && (dev->msg->flags == I2C_M_RD)
228 && (irq == dev->out_irq))
229 return IRQ_HANDLED;
230 if (op_flgs & QUP_OUT_SVC_FLAG) {
231 writel_relaxed(QUP_OUT_SVC_FLAG, dev->base + QUP_OPERATIONAL);
232 /* Ensure that service flag is acknowledged before ISR exits */
233 mb();
234 }
235 if (dev->msg->flags == I2C_M_RD) {
236 if ((op_flgs & QUP_MX_INPUT_DONE) ||
237 (op_flgs & QUP_IN_SVC_FLAG)) {
238 writel_relaxed(QUP_IN_SVC_FLAG, dev->base
239 + QUP_OPERATIONAL);
240 /* Ensure that service flag is acknowledged before ISR
241 * exits
242 */
243 mb();
244 } else
245 return IRQ_HANDLED;
246 }
247
248intr_done:
249 dev_dbg(dev->dev, "QUP intr= %d, i2c status=0x%x, qup status = 0x%x\n",
250 irq, status, status1);
251 qup_print_status(dev);
252 dev->err = err;
253 complete(dev->complete);
254 return IRQ_HANDLED;
255}
256
257static void
258qup_i2c_pwr_mgmt(struct qup_i2c_dev *dev, unsigned int state)
259{
260 dev->clk_state = state;
261 if (state != 0) {
262 clk_enable(dev->clk);
263 if (dev->pclk)
264 clk_enable(dev->pclk);
265 } else {
266 clk_disable(dev->clk);
267 if (dev->pclk)
268 clk_disable(dev->pclk);
269 }
270}
271
272static void
273qup_i2c_pwr_timer(unsigned long data)
274{
275 struct qup_i2c_dev *dev = (struct qup_i2c_dev *) data;
276 dev_dbg(dev->dev, "QUP_Power: Inactivity based power management\n");
277 if (dev->clk_state == 1)
278 qup_i2c_pwr_mgmt(dev, 0);
279}
280
281static int
282qup_i2c_poll_writeready(struct qup_i2c_dev *dev, int rem)
283{
284 uint32_t retries = 0;
285
286 while (retries != 2000) {
287 uint32_t status = readl_relaxed(dev->base + QUP_I2C_STATUS);
288
289 if (!(status & I2C_STATUS_WR_BUFFER_FULL)) {
290 if (((dev->msg->flags & I2C_M_RD) || (rem == 0)) &&
291 !(status & I2C_STATUS_BUS_ACTIVE))
292 return 0;
293 else if ((dev->msg->flags == 0) && (rem > 0))
294 return 0;
295 else /* 1-bit delay before we check for bus busy */
296 udelay(dev->one_bit_t);
297 }
298 if (retries++ == 1000)
299 udelay(100);
300 }
301 qup_print_status(dev);
302 return -ETIMEDOUT;
303}
304
305static int qup_i2c_poll_clock_ready(struct qup_i2c_dev *dev)
306{
307 uint32_t retries = 0;
308
309 /*
310 * Wait for the clock state to transition to either IDLE or FORCED
311 * LOW. This will usually happen within one cycle of the i2c clock.
312 */
313
314 while (retries++ < QUP_MAX_CLK_STATE_RETRIES) {
315 uint32_t status = readl_relaxed(dev->base + QUP_I2C_STATUS);
316 uint32_t clk_state = (status >> 13) & 0x7;
317
318 if (clk_state == I2C_CLK_RESET_BUSIDLE_STATE ||
319 clk_state == I2C_CLK_FORCED_LOW_STATE)
320 return 0;
321 /* 1-bit delay before we check again */
322 udelay(dev->one_bit_t);
323 }
324
325 dev_err(dev->dev, "Error waiting for clk ready\n");
326 return -ETIMEDOUT;
327}
328
329static int
Sagar Dharia518e2302011-08-05 11:03:03 -0600330qup_i2c_poll_state(struct qup_i2c_dev *dev, uint32_t req_state, bool only_valid)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700331{
332 uint32_t retries = 0;
333
Sagar Dharia518e2302011-08-05 11:03:03 -0600334 dev_dbg(dev->dev, "Polling for state:0x%x, or valid-only:%d\n",
335 req_state, only_valid);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700336
337 while (retries != 2000) {
338 uint32_t status = readl_relaxed(dev->base + QUP_STATE);
339
Sagar Dharia518e2302011-08-05 11:03:03 -0600340 /*
341 * If only valid bit needs to be checked, requested state is
342 * 'don't care'
343 */
344 if (status & QUP_STATE_VALID) {
345 if (only_valid)
346 return 0;
347 else if ((req_state & QUP_I2C_MAST_GEN) &&
348 (status & QUP_I2C_MAST_GEN))
349 return 0;
350 else if ((status & QUP_STATE_MASK) == req_state)
351 return 0;
352 }
353 if (retries++ == 1000)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700354 udelay(100);
355 }
356 return -ETIMEDOUT;
357}
358
359static inline int qup_i2c_request_gpios(struct qup_i2c_dev *dev)
360{
361 int i;
362 int result = 0;
363
364 for (i = 0; i < ARRAY_SIZE(i2c_rsrcs); ++i) {
365 if (dev->i2c_gpios[i] >= 0) {
366 result = gpio_request(dev->i2c_gpios[i], i2c_rsrcs[i]);
367 if (result) {
368 dev_err(dev->dev,
369 "gpio_request for pin %d failed\
370 with error %d\n", dev->i2c_gpios[i],
371 result);
372 goto error;
373 }
374 }
375 }
376 return 0;
377
378error:
379 for (; --i >= 0;) {
380 if (dev->i2c_gpios[i] >= 0)
381 gpio_free(dev->i2c_gpios[i]);
382 }
383 return result;
384}
385
386static inline void qup_i2c_free_gpios(struct qup_i2c_dev *dev)
387{
388 int i;
389
390 for (i = 0; i < ARRAY_SIZE(i2c_rsrcs); ++i) {
391 if (dev->i2c_gpios[i] >= 0)
392 gpio_free(dev->i2c_gpios[i]);
393 }
394}
395
396#ifdef DEBUG
397static void qup_verify_fifo(struct qup_i2c_dev *dev, uint32_t val,
398 uint32_t addr, int rdwr)
399{
400 if (rdwr)
401 dev_dbg(dev->dev, "RD:Wrote 0x%x to out_ff:0x%x\n", val, addr);
402 else
403 dev_dbg(dev->dev, "WR:Wrote 0x%x to out_ff:0x%x\n", val, addr);
404}
405#else
406static inline void qup_verify_fifo(struct qup_i2c_dev *dev, uint32_t val,
407 uint32_t addr, int rdwr)
408{
409}
410#endif
411
412static void
413qup_issue_read(struct qup_i2c_dev *dev, struct i2c_msg *msg, int *idx,
414 uint32_t carry_over)
415{
416 uint16_t addr = (msg->addr << 1) | 1;
417 /* QUP limit 256 bytes per read. By HW design, 0 in the 8-bit field
418 * is treated as 256 byte read.
419 */
420 uint16_t rd_len = ((dev->cnt == 256) ? 0 : dev->cnt);
421
422 if (*idx % 4) {
423 writel_relaxed(carry_over | ((QUP_OUT_START | addr) << 16),
424 dev->base + QUP_OUT_FIFO_BASE);/* + (*idx-2)); */
425
426 qup_verify_fifo(dev, carry_over |
427 ((QUP_OUT_START | addr) << 16), (uint32_t)dev->base
428 + QUP_OUT_FIFO_BASE + (*idx - 2), 1);
429 writel_relaxed((QUP_OUT_REC | rd_len),
430 dev->base + QUP_OUT_FIFO_BASE);/* + (*idx+2)); */
431
432 qup_verify_fifo(dev, (QUP_OUT_REC | rd_len),
433 (uint32_t)dev->base + QUP_OUT_FIFO_BASE + (*idx + 2), 1);
434 } else {
435 writel_relaxed(((QUP_OUT_REC | rd_len) << 16)
436 | QUP_OUT_START | addr,
437 dev->base + QUP_OUT_FIFO_BASE);/* + (*idx)); */
438
439 qup_verify_fifo(dev, QUP_OUT_REC << 16 | rd_len << 16 |
440 QUP_OUT_START | addr,
441 (uint32_t)dev->base + QUP_OUT_FIFO_BASE + (*idx), 1);
442 }
443 *idx += 4;
444}
445
446static void
447qup_issue_write(struct qup_i2c_dev *dev, struct i2c_msg *msg, int rem,
448 int *idx, uint32_t *carry_over)
449{
450 int entries = dev->cnt;
451 int empty_sl = dev->wr_sz - ((*idx) >> 1);
452 int i = 0;
453 uint32_t val = 0;
454 uint32_t last_entry = 0;
455 uint16_t addr = msg->addr << 1;
456
457 if (dev->pos == 0) {
458 if (*idx % 4) {
459 writel_relaxed(*carry_over | ((QUP_OUT_START |
460 addr) << 16),
461 dev->base + QUP_OUT_FIFO_BASE);
462
463 qup_verify_fifo(dev, *carry_over | QUP_OUT_DATA << 16 |
464 addr << 16, (uint32_t)dev->base +
465 QUP_OUT_FIFO_BASE + (*idx) - 2, 0);
466 } else
467 val = QUP_OUT_START | addr;
468 *idx += 2;
469 i++;
470 entries++;
471 } else {
472 /* Avoid setp time issue by adding 1 NOP when number of bytes
473 * are more than FIFO/BLOCK size. setup time issue can't appear
474 * otherwise since next byte to be written will always be ready
475 */
476 val = (QUP_OUT_NOP | 1);
477 *idx += 2;
478 i++;
479 entries++;
480 }
481 if (entries > empty_sl)
482 entries = empty_sl;
483
484 for (; i < (entries - 1); i++) {
485 if (*idx % 4) {
486 writel_relaxed(val | ((QUP_OUT_DATA |
487 msg->buf[dev->pos]) << 16),
488 dev->base + QUP_OUT_FIFO_BASE);
489
490 qup_verify_fifo(dev, val | QUP_OUT_DATA << 16 |
491 msg->buf[dev->pos] << 16, (uint32_t)dev->base +
492 QUP_OUT_FIFO_BASE + (*idx) - 2, 0);
493 } else
494 val = QUP_OUT_DATA | msg->buf[dev->pos];
495 (*idx) += 2;
496 dev->pos++;
497 }
498 if (dev->pos < (msg->len - 1))
499 last_entry = QUP_OUT_DATA;
500 else if (rem > 1) /* not last array entry */
501 last_entry = QUP_OUT_DATA;
502 else
503 last_entry = QUP_OUT_STOP;
504 if ((*idx % 4) == 0) {
505 /*
506 * If read-start and read-command end up in different fifos, it
507 * may result in extra-byte being read due to extra-read cycle.
508 * Avoid that by inserting NOP as the last entry of fifo only
509 * if write command(s) leave 1 space in fifo.
510 */
511 if (rem > 1) {
512 struct i2c_msg *next = msg + 1;
513 if (next->addr == msg->addr && (next->flags | I2C_M_RD)
514 && *idx == ((dev->wr_sz*2) - 4)) {
515 writel_relaxed(((last_entry |
516 msg->buf[dev->pos]) |
517 ((1 | QUP_OUT_NOP) << 16)), dev->base +
518 QUP_OUT_FIFO_BASE);/* + (*idx) - 2); */
519
520 qup_verify_fifo(dev,
521 ((last_entry | msg->buf[dev->pos]) |
522 ((1 | QUP_OUT_NOP) << 16)),
523 (uint32_t)dev->base +
524 QUP_OUT_FIFO_BASE + (*idx), 0);
525 *idx += 2;
526 } else if (next->flags == 0 && dev->pos == msg->len - 1
527 && *idx < (dev->wr_sz*2)) {
528 /* Last byte of an intermittent write */
529 writel_relaxed((last_entry |
530 msg->buf[dev->pos]),
531 dev->base + QUP_OUT_FIFO_BASE);
532
533 qup_verify_fifo(dev,
534 last_entry | msg->buf[dev->pos],
535 (uint32_t)dev->base +
536 QUP_OUT_FIFO_BASE + (*idx), 0);
537 *idx += 2;
538 } else
539 *carry_over = (last_entry | msg->buf[dev->pos]);
540 } else {
541 writel_relaxed((last_entry | msg->buf[dev->pos]),
542 dev->base + QUP_OUT_FIFO_BASE);/* + (*idx) - 2); */
543
544 qup_verify_fifo(dev, last_entry | msg->buf[dev->pos],
545 (uint32_t)dev->base + QUP_OUT_FIFO_BASE +
546 (*idx), 0);
547 }
548 } else {
549 writel_relaxed(val | ((last_entry | msg->buf[dev->pos]) << 16),
550 dev->base + QUP_OUT_FIFO_BASE);/* + (*idx) - 2); */
551
552 qup_verify_fifo(dev, val | (last_entry << 16) |
553 (msg->buf[dev->pos] << 16), (uint32_t)dev->base +
554 QUP_OUT_FIFO_BASE + (*idx) - 2, 0);
555 }
556
557 *idx += 2;
558 dev->pos++;
559 dev->cnt = msg->len - dev->pos;
560}
561
562static int
563qup_update_state(struct qup_i2c_dev *dev, uint32_t state)
564{
Sagar Dharia518e2302011-08-05 11:03:03 -0600565 if (qup_i2c_poll_state(dev, 0, true) != 0)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700566 return -EIO;
567 writel_relaxed(state, dev->base + QUP_STATE);
Sagar Dharia518e2302011-08-05 11:03:03 -0600568 if (qup_i2c_poll_state(dev, state, false) != 0)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700569 return -EIO;
570 return 0;
571}
572
573static void
574qup_set_read_mode(struct qup_i2c_dev *dev, int rd_len)
575{
576 uint32_t wr_mode = (dev->wr_sz < dev->out_fifo_sz) ?
577 QUP_WR_BLK_MODE : 0;
578 if (rd_len > 256) {
579 dev_dbg(dev->dev, "HW limit: Breaking reads in chunk of 256\n");
580 rd_len = 256;
581 }
582 if (rd_len <= dev->in_fifo_sz) {
583 writel_relaxed(wr_mode | QUP_PACK_EN | QUP_UNPACK_EN,
584 dev->base + QUP_IO_MODE);
585 writel_relaxed(rd_len, dev->base + QUP_MX_READ_CNT);
586 } else {
587 writel_relaxed(wr_mode | QUP_RD_BLK_MODE |
588 QUP_PACK_EN | QUP_UNPACK_EN, dev->base + QUP_IO_MODE);
589 writel_relaxed(rd_len, dev->base + QUP_MX_INPUT_CNT);
590 }
591}
592
593static int
594qup_set_wr_mode(struct qup_i2c_dev *dev, int rem)
595{
596 int total_len = 0;
597 int ret = 0;
598 if (dev->msg->len >= (dev->out_fifo_sz - 1)) {
599 total_len = dev->msg->len + 1 +
600 (dev->msg->len/(dev->out_blk_sz-1));
601 writel_relaxed(QUP_WR_BLK_MODE | QUP_PACK_EN | QUP_UNPACK_EN,
602 dev->base + QUP_IO_MODE);
603 dev->wr_sz = dev->out_blk_sz;
604 } else
605 writel_relaxed(QUP_PACK_EN | QUP_UNPACK_EN,
606 dev->base + QUP_IO_MODE);
607
608 if (rem > 1) {
609 struct i2c_msg *next = dev->msg + 1;
610 if (next->addr == dev->msg->addr &&
611 next->flags == I2C_M_RD) {
612 qup_set_read_mode(dev, next->len);
613 /* make sure read start & read command are in 1 blk */
614 if ((total_len % dev->out_blk_sz) ==
615 (dev->out_blk_sz - 1))
616 total_len += 3;
617 else
618 total_len += 2;
619 }
620 }
621 /* WRITE COUNT register valid/used only in block mode */
622 if (dev->wr_sz == dev->out_blk_sz)
623 writel_relaxed(total_len, dev->base + QUP_MX_WR_CNT);
624 return ret;
625}
626
627static int
628qup_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
629{
630 DECLARE_COMPLETION_ONSTACK(complete);
631 struct qup_i2c_dev *dev = i2c_get_adapdata(adap);
632 int ret;
633 int rem = num;
634 long timeout;
635 int err;
636
637 del_timer_sync(&dev->pwr_timer);
638 mutex_lock(&dev->mlock);
639
640 if (dev->suspended) {
641 mutex_unlock(&dev->mlock);
642 return -EIO;
643 }
644
645 if (dev->clk_state == 0) {
646 if (dev->clk_ctl == 0) {
647 if (dev->pdata->src_clk_rate > 0)
648 clk_set_rate(dev->clk,
649 dev->pdata->src_clk_rate);
650 else
651 dev->pdata->src_clk_rate = 19200000;
652 }
653 qup_i2c_pwr_mgmt(dev, 1);
654 }
655 /* Initialize QUP registers during first transfer */
656 if (dev->clk_ctl == 0) {
657 int fs_div;
658 int hs_div;
659 uint32_t fifo_reg;
660
661 if (dev->gsbi) {
662 writel_relaxed(0x2 << 4, dev->gsbi);
663 /* GSBI memory is not in the same 1K region as other
664 * QUP registers. mb() here ensures that the GSBI
665 * register is updated in correct order and that the
666 * write has gone through before programming QUP core
667 * registers
668 */
669 mb();
670 }
671
672 fs_div = ((dev->pdata->src_clk_rate
673 / dev->pdata->clk_freq) / 2) - 3;
674 hs_div = 3;
675 dev->clk_ctl = ((hs_div & 0x7) << 8) | (fs_div & 0xff);
676 fifo_reg = readl_relaxed(dev->base + QUP_IO_MODE);
677 if (fifo_reg & 0x3)
678 dev->out_blk_sz = (fifo_reg & 0x3) * 16;
679 else
680 dev->out_blk_sz = 16;
681 if (fifo_reg & 0x60)
682 dev->in_blk_sz = ((fifo_reg & 0x60) >> 5) * 16;
683 else
684 dev->in_blk_sz = 16;
685 /*
686 * The block/fifo size w.r.t. 'actual data' is 1/2 due to 'tag'
687 * associated with each byte written/received
688 */
689 dev->out_blk_sz /= 2;
690 dev->in_blk_sz /= 2;
691 dev->out_fifo_sz = dev->out_blk_sz *
692 (2 << ((fifo_reg & 0x1C) >> 2));
693 dev->in_fifo_sz = dev->in_blk_sz *
694 (2 << ((fifo_reg & 0x380) >> 7));
695 dev_dbg(dev->dev, "QUP IN:bl:%d, ff:%d, OUT:bl:%d, ff:%d\n",
696 dev->in_blk_sz, dev->in_fifo_sz,
697 dev->out_blk_sz, dev->out_fifo_sz);
698 }
699
700 writel_relaxed(1, dev->base + QUP_SW_RESET);
Sagar Dharia518e2302011-08-05 11:03:03 -0600701 ret = qup_i2c_poll_state(dev, QUP_RESET_STATE, false);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700702 if (ret) {
703 dev_err(dev->dev, "QUP Busy:Trying to recover\n");
704 goto out_err;
705 }
706
707 if (dev->num_irqs == 3) {
708 enable_irq(dev->in_irq);
709 enable_irq(dev->out_irq);
710 }
711 enable_irq(dev->err_irq);
712
713 /* Initialize QUP registers */
714 writel_relaxed(0, dev->base + QUP_CONFIG);
715 writel_relaxed(QUP_OPERATIONAL_RESET, dev->base + QUP_OPERATIONAL);
716 writel_relaxed(QUP_STATUS_ERROR_FLAGS, dev->base + QUP_ERROR_FLAGS_EN);
717
718 writel_relaxed(I2C_MINI_CORE | I2C_N_VAL, dev->base + QUP_CONFIG);
719
720 /* Initialize I2C mini core registers */
721 writel_relaxed(0, dev->base + QUP_I2C_CLK_CTL);
722 writel_relaxed(QUP_I2C_STATUS_RESET, dev->base + QUP_I2C_STATUS);
723
724 while (rem) {
725 bool filled = false;
726
727 dev->cnt = msgs->len - dev->pos;
728 dev->msg = msgs;
729
730 dev->wr_sz = dev->out_fifo_sz;
731 dev->err = 0;
732 dev->complete = &complete;
733
Sagar Dharia518e2302011-08-05 11:03:03 -0600734 if (qup_i2c_poll_state(dev, QUP_I2C_MAST_GEN, false) != 0) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700735 ret = -EIO;
736 goto out_err;
737 }
738
739 qup_print_status(dev);
740 /* HW limits Read upto 256 bytes in 1 read without stop */
741 if (dev->msg->flags & I2C_M_RD) {
742 qup_set_read_mode(dev, dev->cnt);
743 if (dev->cnt > 256)
744 dev->cnt = 256;
745 } else {
746 ret = qup_set_wr_mode(dev, rem);
747 if (ret != 0)
748 goto out_err;
749 /* Don't fill block till we get interrupt */
750 if (dev->wr_sz == dev->out_blk_sz)
751 filled = true;
752 }
753
754 err = qup_update_state(dev, QUP_RUN_STATE);
755 if (err < 0) {
756 ret = err;
757 goto out_err;
758 }
759
760 qup_print_status(dev);
761 writel_relaxed(dev->clk_ctl, dev->base + QUP_I2C_CLK_CTL);
762 /* CLK_CTL register is not in the same 1K region as other QUP
763 * registers. Ensure that clock control is written before
764 * programming other QUP registers
765 */
766 mb();
767
768 do {
769 int idx = 0;
770 uint32_t carry_over = 0;
771
772 /* Transition to PAUSE state only possible from RUN */
773 err = qup_update_state(dev, QUP_PAUSE_STATE);
774 if (err < 0) {
775 ret = err;
776 goto out_err;
777 }
778
779 qup_print_status(dev);
780 /* This operation is Write, check the next operation
781 * and decide mode
782 */
783 while (filled == false) {
784 if ((msgs->flags & I2C_M_RD))
785 qup_issue_read(dev, msgs, &idx,
786 carry_over);
787 else if (!(msgs->flags & I2C_M_RD))
788 qup_issue_write(dev, msgs, rem, &idx,
789 &carry_over);
790 if (idx >= (dev->wr_sz << 1))
791 filled = true;
792 /* Start new message */
793 if (filled == false) {
794 if (msgs->flags & I2C_M_RD)
795 filled = true;
796 else if (rem > 1) {
797 /* Only combine operations with
798 * same address
799 */
800 struct i2c_msg *next = msgs + 1;
801 if (next->addr != msgs->addr)
802 filled = true;
803 else {
804 rem--;
805 msgs++;
806 dev->msg = msgs;
807 dev->pos = 0;
808 dev->cnt = msgs->len;
809 if (msgs->len > 256)
810 dev->cnt = 256;
811 }
812 } else
813 filled = true;
814 }
815 }
816 err = qup_update_state(dev, QUP_RUN_STATE);
817 if (err < 0) {
818 ret = err;
819 goto out_err;
820 }
821 dev_dbg(dev->dev, "idx:%d, rem:%d, num:%d, mode:%d\n",
822 idx, rem, num, dev->mode);
823
824 qup_print_status(dev);
825 timeout = wait_for_completion_timeout(&complete, HZ);
826 if (!timeout) {
827 uint32_t istatus = readl_relaxed(dev->base +
828 QUP_I2C_STATUS);
829 uint32_t qstatus = readl_relaxed(dev->base +
830 QUP_ERROR_FLAGS);
831 uint32_t op_flgs = readl_relaxed(dev->base +
832 QUP_OPERATIONAL);
833
834 dev_err(dev->dev, "Transaction timed out\n");
835 dev_err(dev->dev, "I2C Status: %x\n", istatus);
836 dev_err(dev->dev, "QUP Status: %x\n", qstatus);
837 dev_err(dev->dev, "OP Flags: %x\n", op_flgs);
838 writel_relaxed(1, dev->base + QUP_SW_RESET);
839 /* Make sure that the write has gone through
840 * before returning from the function
841 */
842 mb();
843 ret = -ETIMEDOUT;
844 goto out_err;
845 }
846 if (dev->err) {
847 if (dev->err > 0 &&
848 dev->err & QUP_I2C_NACK_FLAG)
849 dev_err(dev->dev,
850 "I2C slave addr:0x%x not connected\n",
851 dev->msg->addr);
852 else if (dev->err < 0) {
853 dev_err(dev->dev,
854 "QUP data xfer error %d\n", dev->err);
855 ret = dev->err;
856 goto out_err;
857 }
858 ret = -dev->err;
859 goto out_err;
860 }
861 if (dev->msg->flags & I2C_M_RD) {
862 int i;
863 uint32_t dval = 0;
864 for (i = 0; dev->pos < dev->msg->len; i++,
865 dev->pos++) {
866 uint32_t rd_status =
867 readl_relaxed(dev->base
868 + QUP_OPERATIONAL);
869 if (i % 2 == 0) {
870 if ((rd_status &
871 QUP_IN_NOT_EMPTY) == 0)
872 break;
873 dval = readl_relaxed(dev->base +
874 QUP_IN_FIFO_BASE);
875 dev->msg->buf[dev->pos] =
876 dval & 0xFF;
877 } else
878 dev->msg->buf[dev->pos] =
879 ((dval & 0xFF0000) >>
880 16);
881 }
882 dev->cnt -= i;
883 } else
884 filled = false; /* refill output FIFO */
885 dev_dbg(dev->dev, "pos:%d, len:%d, cnt:%d\n",
886 dev->pos, msgs->len, dev->cnt);
887 } while (dev->cnt > 0);
888 if (dev->cnt == 0) {
889 if (msgs->len == dev->pos) {
890 rem--;
891 msgs++;
892 dev->pos = 0;
893 }
894 if (rem) {
895 err = qup_i2c_poll_clock_ready(dev);
896 if (err < 0) {
897 ret = err;
898 goto out_err;
899 }
900 err = qup_update_state(dev, QUP_RESET_STATE);
901 if (err < 0) {
902 ret = err;
903 goto out_err;
904 }
905 }
906 }
907 /* Wait for I2C bus to be idle */
908 ret = qup_i2c_poll_writeready(dev, rem);
909 if (ret) {
910 dev_err(dev->dev,
911 "Error waiting for write ready\n");
912 goto out_err;
913 }
914 }
915
916 ret = num;
917 out_err:
918 disable_irq(dev->err_irq);
919 if (dev->num_irqs == 3) {
920 disable_irq(dev->in_irq);
921 disable_irq(dev->out_irq);
922 }
923 dev->complete = NULL;
924 dev->msg = NULL;
925 dev->pos = 0;
926 dev->err = 0;
927 dev->cnt = 0;
928 dev->pwr_timer.expires = jiffies + 3*HZ;
929 add_timer(&dev->pwr_timer);
930 mutex_unlock(&dev->mlock);
931 return ret;
932}
933
934static u32
935qup_i2c_func(struct i2c_adapter *adap)
936{
937 return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
938}
939
940static const struct i2c_algorithm qup_i2c_algo = {
941 .master_xfer = qup_i2c_xfer,
942 .functionality = qup_i2c_func,
943};
944
945static int __devinit
946qup_i2c_probe(struct platform_device *pdev)
947{
948 struct qup_i2c_dev *dev;
949 struct resource *qup_mem, *gsbi_mem, *qup_io, *gsbi_io, *res;
950 struct resource *in_irq, *out_irq, *err_irq;
951 struct clk *clk, *pclk;
952 int ret = 0;
953 int i;
954 struct msm_i2c_platform_data *pdata;
955 const char *qup_apps_clk_name = "qup_clk";
956
957 gsbi_mem = NULL;
958 dev_dbg(&pdev->dev, "qup_i2c_probe\n");
959
960 pdata = pdev->dev.platform_data;
961 if (!pdata) {
962 dev_err(&pdev->dev, "platform data not initialized\n");
963 return -ENOSYS;
964 }
965 qup_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
966 "qup_phys_addr");
967 if (!qup_mem) {
968 dev_err(&pdev->dev, "no qup mem resource?\n");
969 return -ENODEV;
970 }
971
972 /*
973 * We only have 1 interrupt for new hardware targets and in_irq,
974 * out_irq will be NULL for those platforms
975 */
976 in_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
977 "qup_in_intr");
978
979 out_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
980 "qup_out_intr");
981
982 err_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
983 "qup_err_intr");
984 if (!err_irq) {
985 dev_err(&pdev->dev, "no error irq resource?\n");
986 return -ENODEV;
987 }
988
989 qup_io = request_mem_region(qup_mem->start, resource_size(qup_mem),
990 pdev->name);
991 if (!qup_io) {
992 dev_err(&pdev->dev, "QUP region already claimed\n");
993 return -EBUSY;
994 }
995 if (!pdata->use_gsbi_shared_mode) {
996 gsbi_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
997 "gsbi_qup_i2c_addr");
998 if (!gsbi_mem) {
999 dev_err(&pdev->dev, "no gsbi mem resource?\n");
1000 return -ENODEV;
1001 }
1002 gsbi_io = request_mem_region(gsbi_mem->start,
1003 resource_size(gsbi_mem),
1004 pdev->name);
1005 if (!gsbi_io) {
1006 dev_err(&pdev->dev, "GSBI region already claimed\n");
1007 return -EBUSY;
1008 }
1009 }
1010
1011 if (pdata->clk != NULL)
1012 qup_apps_clk_name = pdata->clk;
1013
1014 clk = clk_get(&pdev->dev, qup_apps_clk_name);
1015 if (IS_ERR(clk)) {
1016 dev_err(&pdev->dev, "Could not get clock\n");
1017 ret = PTR_ERR(clk);
1018 goto err_clk_get_failed;
1019 }
1020
1021 if (pdata->pclk != NULL) {
1022 pclk = clk_get(&pdev->dev, pdata->pclk);
1023 if (IS_ERR(pclk)) {
1024 dev_err(&pdev->dev, "Could not get pclock\n");
1025 ret = PTR_ERR(pclk);
1026 clk_put(clk);
1027 goto err_clk_get_failed;
1028 }
1029 } else
1030 pclk = NULL;
1031
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001032 /* We support frequencies upto FAST Mode(400KHz) */
1033 if (pdata->clk_freq <= 0 ||
1034 pdata->clk_freq > 400000) {
1035 dev_err(&pdev->dev, "clock frequency not supported\n");
1036 ret = -EIO;
1037 goto err_config_failed;
1038 }
1039
1040 dev = kzalloc(sizeof(struct qup_i2c_dev), GFP_KERNEL);
1041 if (!dev) {
1042 ret = -ENOMEM;
1043 goto err_alloc_dev_failed;
1044 }
1045
1046 dev->dev = &pdev->dev;
1047 if (in_irq)
1048 dev->in_irq = in_irq->start;
1049 if (out_irq)
1050 dev->out_irq = out_irq->start;
1051 dev->err_irq = err_irq->start;
1052 if (in_irq && out_irq)
1053 dev->num_irqs = 3;
1054 else
1055 dev->num_irqs = 1;
1056 dev->clk = clk;
1057 dev->pclk = pclk;
1058 dev->base = ioremap(qup_mem->start, resource_size(qup_mem));
1059 if (!dev->base) {
1060 ret = -ENOMEM;
1061 goto err_ioremap_failed;
1062 }
1063
1064 /* Configure GSBI block to use I2C functionality */
1065 if (gsbi_mem) {
1066 dev->gsbi = ioremap(gsbi_mem->start, resource_size(gsbi_mem));
1067 if (!dev->gsbi) {
1068 ret = -ENOMEM;
1069 goto err_gsbi_failed;
1070 }
1071 }
1072
1073 for (i = 0; i < ARRAY_SIZE(i2c_rsrcs); ++i) {
1074 res = platform_get_resource_byname(pdev, IORESOURCE_IO,
1075 i2c_rsrcs[i]);
1076 dev->i2c_gpios[i] = res ? res->start : -1;
1077 }
1078
1079 ret = qup_i2c_request_gpios(dev);
1080 if (ret)
1081 goto err_request_gpio_failed;
1082
1083 platform_set_drvdata(pdev, dev);
1084
1085 dev->one_bit_t = USEC_PER_SEC/pdata->clk_freq;
1086 dev->pdata = pdata;
1087 dev->clk_ctl = 0;
1088 dev->pos = 0;
1089
1090 /*
1091 * We use num_irqs to also indicate if we got 3 interrupts or just 1.
1092 * If we have just 1, we use err_irq as the general purpose irq
1093 * and handle the changes in ISR accordingly
1094 * Per Hardware guidelines, if we have 3 interrupts, they are always
1095 * edge triggering, and if we have 1, it's always level-triggering
1096 */
1097 if (dev->num_irqs == 3) {
1098 ret = request_irq(dev->in_irq, qup_i2c_interrupt,
1099 IRQF_TRIGGER_RISING, "qup_in_intr", dev);
1100 if (ret) {
1101 dev_err(&pdev->dev, "request_in_irq failed\n");
1102 goto err_request_irq_failed;
1103 }
1104 /*
1105 * We assume out_irq exists if in_irq does since platform
1106 * configuration either has 3 interrupts assigned to QUP or 1
1107 */
1108 ret = request_irq(dev->out_irq, qup_i2c_interrupt,
1109 IRQF_TRIGGER_RISING, "qup_out_intr", dev);
1110 if (ret) {
1111 dev_err(&pdev->dev, "request_out_irq failed\n");
1112 free_irq(dev->in_irq, dev);
1113 goto err_request_irq_failed;
1114 }
1115 ret = request_irq(dev->err_irq, qup_i2c_interrupt,
1116 IRQF_TRIGGER_RISING, "qup_err_intr", dev);
1117 if (ret) {
1118 dev_err(&pdev->dev, "request_err_irq failed\n");
1119 free_irq(dev->out_irq, dev);
1120 free_irq(dev->in_irq, dev);
1121 goto err_request_irq_failed;
1122 }
1123 } else {
1124 ret = request_irq(dev->err_irq, qup_i2c_interrupt,
1125 IRQF_TRIGGER_HIGH, "qup_err_intr", dev);
1126 if (ret) {
1127 dev_err(&pdev->dev, "request_err_irq failed\n");
1128 goto err_request_irq_failed;
1129 }
1130 }
1131 disable_irq(dev->err_irq);
1132 if (dev->num_irqs == 3) {
1133 disable_irq(dev->in_irq);
1134 disable_irq(dev->out_irq);
1135 }
1136 i2c_set_adapdata(&dev->adapter, dev);
1137 dev->adapter.algo = &qup_i2c_algo;
1138 strlcpy(dev->adapter.name,
1139 "QUP I2C adapter",
1140 sizeof(dev->adapter.name));
1141 dev->adapter.nr = pdev->id;
Harini Jayaramance67cf82011-08-05 09:26:06 -06001142 if (pdata->msm_i2c_config_gpio)
1143 pdata->msm_i2c_config_gpio(dev->adapter.nr, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001144
1145 dev->suspended = 0;
1146 mutex_init(&dev->mlock);
1147 dev->clk_state = 0;
1148 setup_timer(&dev->pwr_timer, qup_i2c_pwr_timer, (unsigned long) dev);
1149
1150 pm_runtime_set_active(&pdev->dev);
1151 pm_runtime_enable(&pdev->dev);
1152
1153 ret = i2c_add_numbered_adapter(&dev->adapter);
1154 if (ret) {
1155 dev_err(&pdev->dev, "i2c_add_adapter failed\n");
1156 if (dev->num_irqs == 3) {
1157 free_irq(dev->out_irq, dev);
1158 free_irq(dev->in_irq, dev);
1159 }
1160 free_irq(dev->err_irq, dev);
1161 } else
1162 return 0;
1163
1164
1165err_request_irq_failed:
1166 qup_i2c_free_gpios(dev);
1167 if (dev->gsbi)
1168 iounmap(dev->gsbi);
1169err_request_gpio_failed:
1170err_gsbi_failed:
1171 iounmap(dev->base);
1172err_ioremap_failed:
1173 kfree(dev);
1174err_alloc_dev_failed:
1175err_config_failed:
1176 clk_put(clk);
1177 if (pclk)
1178 clk_put(pclk);
1179err_clk_get_failed:
1180 if (gsbi_mem)
1181 release_mem_region(gsbi_mem->start, resource_size(gsbi_mem));
1182 release_mem_region(qup_mem->start, resource_size(qup_mem));
1183 return ret;
1184}
1185
1186static int __devexit
1187qup_i2c_remove(struct platform_device *pdev)
1188{
1189 struct qup_i2c_dev *dev = platform_get_drvdata(pdev);
1190 struct resource *qup_mem, *gsbi_mem;
1191
1192 /* Grab mutex to ensure ongoing transaction is over */
1193 mutex_lock(&dev->mlock);
1194 dev->suspended = 1;
1195 mutex_unlock(&dev->mlock);
1196 mutex_destroy(&dev->mlock);
1197 del_timer_sync(&dev->pwr_timer);
1198 if (dev->clk_state != 0)
1199 qup_i2c_pwr_mgmt(dev, 0);
1200 platform_set_drvdata(pdev, NULL);
1201 if (dev->num_irqs == 3) {
1202 free_irq(dev->out_irq, dev);
1203 free_irq(dev->in_irq, dev);
1204 }
1205 free_irq(dev->err_irq, dev);
1206 i2c_del_adapter(&dev->adapter);
1207 clk_put(dev->clk);
1208 if (dev->pclk)
1209 clk_put(dev->pclk);
1210 qup_i2c_free_gpios(dev);
1211 if (dev->gsbi)
1212 iounmap(dev->gsbi);
1213 iounmap(dev->base);
1214
1215 pm_runtime_disable(&pdev->dev);
1216
1217 kfree(dev);
1218 if (!(dev->pdata->use_gsbi_shared_mode)) {
1219 gsbi_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1220 "gsbi_qup_i2c_addr");
1221 release_mem_region(gsbi_mem->start, resource_size(gsbi_mem));
1222 }
1223 qup_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1224 "qup_phys_addr");
1225 release_mem_region(qup_mem->start, resource_size(qup_mem));
1226 return 0;
1227}
1228
1229#ifdef CONFIG_PM
1230static int qup_i2c_suspend(struct device *device)
1231{
1232 struct platform_device *pdev = to_platform_device(device);
1233 struct qup_i2c_dev *dev = platform_get_drvdata(pdev);
1234
1235 /* Grab mutex to ensure ongoing transaction is over */
1236 mutex_lock(&dev->mlock);
1237 dev->suspended = 1;
1238 mutex_unlock(&dev->mlock);
1239 del_timer_sync(&dev->pwr_timer);
1240 if (dev->clk_state != 0)
1241 qup_i2c_pwr_mgmt(dev, 0);
1242 qup_i2c_free_gpios(dev);
1243 return 0;
1244}
1245
1246static int qup_i2c_resume(struct device *device)
1247{
1248 struct platform_device *pdev = to_platform_device(device);
1249 struct qup_i2c_dev *dev = platform_get_drvdata(pdev);
1250 BUG_ON(qup_i2c_request_gpios(dev) != 0);
1251 dev->suspended = 0;
1252 return 0;
1253}
1254#endif /* CONFIG_PM */
1255
1256#ifdef CONFIG_PM_RUNTIME
1257static int i2c_qup_runtime_idle(struct device *dev)
1258{
1259 dev_dbg(dev, "pm_runtime: idle...\n");
1260 return 0;
1261}
1262
1263static int i2c_qup_runtime_suspend(struct device *dev)
1264{
1265 dev_dbg(dev, "pm_runtime: suspending...\n");
1266 return 0;
1267}
1268
1269static int i2c_qup_runtime_resume(struct device *dev)
1270{
1271 dev_dbg(dev, "pm_runtime: resuming...\n");
1272 return 0;
1273}
1274#endif
1275
1276static const struct dev_pm_ops i2c_qup_dev_pm_ops = {
1277 SET_SYSTEM_SLEEP_PM_OPS(
1278 qup_i2c_suspend,
1279 qup_i2c_resume
1280 )
1281 SET_RUNTIME_PM_OPS(
1282 i2c_qup_runtime_suspend,
1283 i2c_qup_runtime_resume,
1284 i2c_qup_runtime_idle
1285 )
1286};
1287
1288static struct platform_driver qup_i2c_driver = {
1289 .probe = qup_i2c_probe,
1290 .remove = __devexit_p(qup_i2c_remove),
1291 .driver = {
1292 .name = "qup_i2c",
1293 .owner = THIS_MODULE,
1294 .pm = &i2c_qup_dev_pm_ops,
1295 },
1296};
1297
1298/* QUP may be needed to bring up other drivers */
1299static int __init
1300qup_i2c_init_driver(void)
1301{
1302 return platform_driver_register(&qup_i2c_driver);
1303}
1304arch_initcall(qup_i2c_init_driver);
1305
1306static void __exit qup_i2c_exit_driver(void)
1307{
1308 platform_driver_unregister(&qup_i2c_driver);
1309}
1310module_exit(qup_i2c_exit_driver);
1311