2 * TI DAVINCI I2C adapter driver.
4 * Copyright (C) 2006 Texas Instruments.
5 * Copyright (C) 2007 MontaVista Software Inc.
7 * Updated by Vinod & Sudhakar Feb 2005
9 * ----------------------------------------------------------------------------
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * ----------------------------------------------------------------------------
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/delay.h>
30 #include <linux/i2c.h>
31 #include <linux/clk.h>
32 #include <linux/errno.h>
33 #include <linux/sched.h>
34 #include <linux/err.h>
35 #include <linux/interrupt.h>
36 #include <linux/platform_device.h>
38 #include <linux/slab.h>
39 #include <linux/cpufreq.h>
40 #include <linux/gpio.h>
42 #include <mach/hardware.h>
45 /* ----- global defines ----------------------------------------------- */
47 #define DAVINCI_I2C_TIMEOUT (1*HZ)
48 #define DAVINCI_I2C_MAX_TRIES 2
49 #define I2C_DAVINCI_INTR_ALL (DAVINCI_I2C_IMR_AAS | \
50 DAVINCI_I2C_IMR_SCD | \
51 DAVINCI_I2C_IMR_ARDY | \
52 DAVINCI_I2C_IMR_NACK | \
55 #define DAVINCI_I2C_OAR_REG 0x00
56 #define DAVINCI_I2C_IMR_REG 0x04
57 #define DAVINCI_I2C_STR_REG 0x08
58 #define DAVINCI_I2C_CLKL_REG 0x0c
59 #define DAVINCI_I2C_CLKH_REG 0x10
60 #define DAVINCI_I2C_CNT_REG 0x14
61 #define DAVINCI_I2C_DRR_REG 0x18
62 #define DAVINCI_I2C_SAR_REG 0x1c
63 #define DAVINCI_I2C_DXR_REG 0x20
64 #define DAVINCI_I2C_MDR_REG 0x24
65 #define DAVINCI_I2C_IVR_REG 0x28
66 #define DAVINCI_I2C_EMDR_REG 0x2c
67 #define DAVINCI_I2C_PSC_REG 0x30
69 #define DAVINCI_I2C_IVR_AAS 0x07
70 #define DAVINCI_I2C_IVR_SCD 0x06
71 #define DAVINCI_I2C_IVR_XRDY 0x05
72 #define DAVINCI_I2C_IVR_RDR 0x04
73 #define DAVINCI_I2C_IVR_ARDY 0x03
74 #define DAVINCI_I2C_IVR_NACK 0x02
75 #define DAVINCI_I2C_IVR_AL 0x01
77 #define DAVINCI_I2C_STR_BB BIT(12)
78 #define DAVINCI_I2C_STR_RSFULL BIT(11)
79 #define DAVINCI_I2C_STR_SCD BIT(5)
80 #define DAVINCI_I2C_STR_ARDY BIT(2)
81 #define DAVINCI_I2C_STR_NACK BIT(1)
82 #define DAVINCI_I2C_STR_AL BIT(0)
84 #define DAVINCI_I2C_MDR_NACK BIT(15)
85 #define DAVINCI_I2C_MDR_STT BIT(13)
86 #define DAVINCI_I2C_MDR_STP BIT(11)
87 #define DAVINCI_I2C_MDR_MST BIT(10)
88 #define DAVINCI_I2C_MDR_TRX BIT(9)
89 #define DAVINCI_I2C_MDR_XA BIT(8)
90 #define DAVINCI_I2C_MDR_RM BIT(7)
91 #define DAVINCI_I2C_MDR_IRS BIT(5)
93 #define DAVINCI_I2C_IMR_AAS BIT(6)
94 #define DAVINCI_I2C_IMR_SCD BIT(5)
95 #define DAVINCI_I2C_IMR_XRDY BIT(4)
96 #define DAVINCI_I2C_IMR_RRDY BIT(3)
97 #define DAVINCI_I2C_IMR_ARDY BIT(2)
98 #define DAVINCI_I2C_IMR_NACK BIT(1)
99 #define DAVINCI_I2C_IMR_AL BIT(0)
101 struct davinci_i2c_dev
{
104 struct completion cmd_complete
;
112 struct i2c_adapter adapter
;
113 #ifdef CONFIG_CPU_FREQ
114 struct completion xfr_complete
;
115 struct notifier_block freq_transition
;
119 /* default platform data to use if not supplied in the platform_device */
120 static struct davinci_i2c_platform_data davinci_i2c_platform_data_default
= {
125 static inline void davinci_i2c_write_reg(struct davinci_i2c_dev
*i2c_dev
,
128 __raw_writew(val
, i2c_dev
->base
+ reg
);
131 static inline u16
davinci_i2c_read_reg(struct davinci_i2c_dev
*i2c_dev
, int reg
)
133 return __raw_readw(i2c_dev
->base
+ reg
);
136 /* Generate a pulse on the i2c clock pin. */
137 static void generic_i2c_clock_pulse(unsigned int scl_pin
)
142 /* Send high and low on the SCL line */
143 for (i
= 0; i
< 9; i
++) {
144 gpio_set_value(scl_pin
, 0);
146 gpio_set_value(scl_pin
, 1);
152 /* This routine does i2c bus recovery as specified in the
153 * i2c protocol Rev. 03 section 3.16 titled "Bus clear"
155 static void i2c_recover_bus(struct davinci_i2c_dev
*dev
)
158 struct davinci_i2c_platform_data
*pdata
= dev
->dev
->platform_data
;
160 dev_err(dev
->dev
, "initiating i2c bus recovery\n");
161 /* Send NACK to the slave */
162 flag
= davinci_i2c_read_reg(dev
, DAVINCI_I2C_MDR_REG
);
163 flag
|= DAVINCI_I2C_MDR_NACK
;
164 /* write the data into mode register */
165 davinci_i2c_write_reg(dev
, DAVINCI_I2C_MDR_REG
, flag
);
167 generic_i2c_clock_pulse(pdata
->scl_pin
);
169 flag
= davinci_i2c_read_reg(dev
, DAVINCI_I2C_MDR_REG
);
170 flag
|= DAVINCI_I2C_MDR_STP
;
171 davinci_i2c_write_reg(dev
, DAVINCI_I2C_MDR_REG
, flag
);
174 static inline void davinci_i2c_reset_ctrl(struct davinci_i2c_dev
*i2c_dev
,
179 w
= davinci_i2c_read_reg(i2c_dev
, DAVINCI_I2C_MDR_REG
);
180 if (!val
) /* put I2C into reset */
181 w
&= ~DAVINCI_I2C_MDR_IRS
;
182 else /* take I2C out of reset */
183 w
|= DAVINCI_I2C_MDR_IRS
;
185 davinci_i2c_write_reg(i2c_dev
, DAVINCI_I2C_MDR_REG
, w
);
188 static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev
*dev
)
190 struct davinci_i2c_platform_data
*pdata
= dev
->dev
->platform_data
;
196 u32 input_clock
= clk_get_rate(dev
->clk
);
198 /* NOTE: I2C Clock divider programming info
199 * As per I2C specs the following formulas provide prescaler
200 * and low/high divider values
201 * input clk --> PSC Div -----------> ICCL/H Div --> output clock
204 * output clk = module clk / (PSC + 1) [ (ICCL + d) + (ICCH + d) ]
207 * (ICCL + ICCH) = clk = (input clk / ((psc +1) * output clk)) - 2d;
209 * where if PSC == 0, d = 7,
214 /* get minimum of 7 MHz clock, but max of 12 MHz */
215 psc
= (input_clock
/ 7000000) - 1;
216 if ((input_clock
/ (psc
+ 1)) > 12000000)
217 psc
++; /* better to run under spec than over */
218 d
= (psc
>= 2) ? 5 : 7 - psc
;
220 clk
= ((input_clock
/ (psc
+ 1)) / (pdata
->bus_freq
* 1000)) - (d
<< 1);
224 davinci_i2c_write_reg(dev
, DAVINCI_I2C_PSC_REG
, psc
);
225 davinci_i2c_write_reg(dev
, DAVINCI_I2C_CLKH_REG
, clkh
);
226 davinci_i2c_write_reg(dev
, DAVINCI_I2C_CLKL_REG
, clkl
);
228 dev_dbg(dev
->dev
, "input_clock = %d, CLK = %d\n", input_clock
, clk
);
232 * This function configures I2C and brings I2C out of reset.
233 * This function is called during I2C init function. This function
234 * also gets called if I2C encounters any errors.
236 static int i2c_davinci_init(struct davinci_i2c_dev
*dev
)
238 struct davinci_i2c_platform_data
*pdata
= dev
->dev
->platform_data
;
241 pdata
= &davinci_i2c_platform_data_default
;
243 /* put I2C into reset */
244 davinci_i2c_reset_ctrl(dev
, 0);
246 /* compute clock dividers */
247 i2c_davinci_calc_clk_dividers(dev
);
249 /* Respond at reserved "SMBus Host" slave address" (and zero);
250 * we seem to have no option to not respond...
252 davinci_i2c_write_reg(dev
, DAVINCI_I2C_OAR_REG
, 0x08);
254 dev_dbg(dev
->dev
, "PSC = %d\n",
255 davinci_i2c_read_reg(dev
, DAVINCI_I2C_PSC_REG
));
256 dev_dbg(dev
->dev
, "CLKL = %d\n",
257 davinci_i2c_read_reg(dev
, DAVINCI_I2C_CLKL_REG
));
258 dev_dbg(dev
->dev
, "CLKH = %d\n",
259 davinci_i2c_read_reg(dev
, DAVINCI_I2C_CLKH_REG
));
260 dev_dbg(dev
->dev
, "bus_freq = %dkHz, bus_delay = %d\n",
261 pdata
->bus_freq
, pdata
->bus_delay
);
263 /* Take the I2C module out of reset: */
264 davinci_i2c_reset_ctrl(dev
, 1);
266 /* Enable interrupts */
267 davinci_i2c_write_reg(dev
, DAVINCI_I2C_IMR_REG
, I2C_DAVINCI_INTR_ALL
);
273 * Waiting for bus not busy
275 static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev
*dev
,
278 unsigned long timeout
;
281 timeout
= jiffies
+ dev
->adapter
.timeout
;
282 while (davinci_i2c_read_reg(dev
, DAVINCI_I2C_STR_REG
)
283 & DAVINCI_I2C_STR_BB
) {
284 if (to_cnt
<= DAVINCI_I2C_MAX_TRIES
) {
285 if (time_after(jiffies
, timeout
)) {
287 "timeout waiting for bus ready\n");
292 i2c_recover_bus(dev
);
293 i2c_davinci_init(dev
);
304 * Low level master read/write transaction. This function is called
305 * from i2c_davinci_xfer.
308 i2c_davinci_xfer_msg(struct i2c_adapter
*adap
, struct i2c_msg
*msg
, int stop
)
310 struct davinci_i2c_dev
*dev
= i2c_get_adapdata(adap
);
311 struct davinci_i2c_platform_data
*pdata
= dev
->dev
->platform_data
;
317 pdata
= &davinci_i2c_platform_data_default
;
318 /* Introduce a delay, required for some boards (e.g Davinci EVM) */
319 if (pdata
->bus_delay
)
320 udelay(pdata
->bus_delay
);
322 /* set the slave address */
323 davinci_i2c_write_reg(dev
, DAVINCI_I2C_SAR_REG
, msg
->addr
);
326 dev
->buf_len
= msg
->len
;
329 davinci_i2c_write_reg(dev
, DAVINCI_I2C_CNT_REG
, dev
->buf_len
);
331 INIT_COMPLETION(dev
->cmd_complete
);
334 /* Take I2C out of reset, configure it as master and set the
336 flag
= DAVINCI_I2C_MDR_IRS
| DAVINCI_I2C_MDR_MST
| DAVINCI_I2C_MDR_STT
;
338 /* if the slave address is ten bit address, enable XA bit */
339 if (msg
->flags
& I2C_M_TEN
)
340 flag
|= DAVINCI_I2C_MDR_XA
;
341 if (!(msg
->flags
& I2C_M_RD
))
342 flag
|= DAVINCI_I2C_MDR_TRX
;
344 flag
|= DAVINCI_I2C_MDR_STP
;
346 flag
|= DAVINCI_I2C_MDR_RM
;
347 flag
&= ~DAVINCI_I2C_MDR_STP
;
350 /* Enable receive or transmit interrupts */
351 w
= davinci_i2c_read_reg(dev
, DAVINCI_I2C_IMR_REG
);
352 if (msg
->flags
& I2C_M_RD
)
353 w
|= DAVINCI_I2C_IMR_RRDY
;
355 w
|= DAVINCI_I2C_IMR_XRDY
;
356 davinci_i2c_write_reg(dev
, DAVINCI_I2C_IMR_REG
, w
);
360 /* write the data into mode register */
361 davinci_i2c_write_reg(dev
, DAVINCI_I2C_MDR_REG
, flag
);
364 * First byte should be set here, not after interrupt,
365 * because transmit-data-ready interrupt can come before
366 * NACK-interrupt during sending of previous message and
367 * ICDXR may have wrong data
369 if ((!(msg
->flags
& I2C_M_RD
)) && dev
->buf_len
) {
370 davinci_i2c_write_reg(dev
, DAVINCI_I2C_DXR_REG
, *dev
->buf
++);
374 r
= wait_for_completion_interruptible_timeout(&dev
->cmd_complete
,
375 dev
->adapter
.timeout
);
377 dev_err(dev
->dev
, "controller timed out\n");
378 i2c_recover_bus(dev
);
379 i2c_davinci_init(dev
);
384 /* This should be 0 if all bytes were transferred
385 * or dev->cmd_err denotes an error.
386 * A signal may have aborted the transfer.
389 dev_err(dev
->dev
, "abnormal termination buf_len=%i\n",
401 if (likely(!dev
->cmd_err
))
404 /* We have an error */
405 if (dev
->cmd_err
& DAVINCI_I2C_STR_AL
) {
406 i2c_davinci_init(dev
);
410 if (dev
->cmd_err
& DAVINCI_I2C_STR_NACK
) {
411 if (msg
->flags
& I2C_M_IGNORE_NAK
)
414 w
= davinci_i2c_read_reg(dev
, DAVINCI_I2C_MDR_REG
);
415 w
|= DAVINCI_I2C_MDR_STP
;
416 davinci_i2c_write_reg(dev
, DAVINCI_I2C_MDR_REG
, w
);
424 * Prepare controller for a transaction and call i2c_davinci_xfer_msg
427 i2c_davinci_xfer(struct i2c_adapter
*adap
, struct i2c_msg msgs
[], int num
)
429 struct davinci_i2c_dev
*dev
= i2c_get_adapdata(adap
);
433 dev_dbg(dev
->dev
, "%s: msgs: %d\n", __func__
, num
);
435 ret
= i2c_davinci_wait_bus_not_busy(dev
, 1);
437 dev_warn(dev
->dev
, "timeout waiting for bus ready\n");
441 for (i
= 0; i
< num
; i
++) {
442 ret
= i2c_davinci_xfer_msg(adap
, &msgs
[i
], (i
== (num
- 1)));
443 dev_dbg(dev
->dev
, "%s [%d/%d] ret: %d\n", __func__
, i
+ 1, num
,
449 #ifdef CONFIG_CPU_FREQ
450 complete(&dev
->xfr_complete
);
456 static u32
i2c_davinci_func(struct i2c_adapter
*adap
)
458 return I2C_FUNC_I2C
| I2C_FUNC_SMBUS_EMUL
;
461 static void terminate_read(struct davinci_i2c_dev
*dev
)
463 u16 w
= davinci_i2c_read_reg(dev
, DAVINCI_I2C_MDR_REG
);
464 w
|= DAVINCI_I2C_MDR_NACK
;
465 davinci_i2c_write_reg(dev
, DAVINCI_I2C_MDR_REG
, w
);
467 /* Throw away data */
468 davinci_i2c_read_reg(dev
, DAVINCI_I2C_DRR_REG
);
470 dev_err(dev
->dev
, "RDR IRQ while no data requested\n");
472 static void terminate_write(struct davinci_i2c_dev
*dev
)
474 u16 w
= davinci_i2c_read_reg(dev
, DAVINCI_I2C_MDR_REG
);
475 w
|= DAVINCI_I2C_MDR_RM
| DAVINCI_I2C_MDR_STP
;
476 davinci_i2c_write_reg(dev
, DAVINCI_I2C_MDR_REG
, w
);
479 dev_dbg(dev
->dev
, "TDR IRQ while no data to send\n");
483 * Interrupt service routine. This gets called whenever an I2C interrupt
486 static irqreturn_t
i2c_davinci_isr(int this_irq
, void *dev_id
)
488 struct davinci_i2c_dev
*dev
= dev_id
;
493 while ((stat
= davinci_i2c_read_reg(dev
, DAVINCI_I2C_IVR_REG
))) {
494 dev_dbg(dev
->dev
, "%s: stat=0x%x\n", __func__
, stat
);
495 if (count
++ == 100) {
496 dev_warn(dev
->dev
, "Too much work in one IRQ\n");
501 case DAVINCI_I2C_IVR_AL
:
502 /* Arbitration lost, must retry */
503 dev
->cmd_err
|= DAVINCI_I2C_STR_AL
;
505 complete(&dev
->cmd_complete
);
508 case DAVINCI_I2C_IVR_NACK
:
509 dev
->cmd_err
|= DAVINCI_I2C_STR_NACK
;
511 complete(&dev
->cmd_complete
);
514 case DAVINCI_I2C_IVR_ARDY
:
515 davinci_i2c_write_reg(dev
,
516 DAVINCI_I2C_STR_REG
, DAVINCI_I2C_STR_ARDY
);
517 if (((dev
->buf_len
== 0) && (dev
->stop
!= 0)) ||
518 (dev
->cmd_err
& DAVINCI_I2C_STR_NACK
)) {
519 w
= davinci_i2c_read_reg(dev
,
520 DAVINCI_I2C_MDR_REG
);
521 w
|= DAVINCI_I2C_MDR_STP
;
522 davinci_i2c_write_reg(dev
,
523 DAVINCI_I2C_MDR_REG
, w
);
525 complete(&dev
->cmd_complete
);
528 case DAVINCI_I2C_IVR_RDR
:
531 davinci_i2c_read_reg(dev
,
532 DAVINCI_I2C_DRR_REG
);
537 davinci_i2c_write_reg(dev
,
539 DAVINCI_I2C_IMR_RRDY
);
541 /* signal can terminate transfer */
546 case DAVINCI_I2C_IVR_XRDY
:
548 davinci_i2c_write_reg(dev
, DAVINCI_I2C_DXR_REG
,
554 w
= davinci_i2c_read_reg(dev
,
555 DAVINCI_I2C_IMR_REG
);
556 w
&= ~DAVINCI_I2C_IMR_XRDY
;
557 davinci_i2c_write_reg(dev
,
561 /* signal can terminate transfer */
562 terminate_write(dev
);
566 case DAVINCI_I2C_IVR_SCD
:
567 davinci_i2c_write_reg(dev
,
568 DAVINCI_I2C_STR_REG
, DAVINCI_I2C_STR_SCD
);
569 complete(&dev
->cmd_complete
);
572 case DAVINCI_I2C_IVR_AAS
:
573 dev_dbg(dev
->dev
, "Address as slave interrupt\n");
577 dev_warn(dev
->dev
, "Unrecognized irq stat %d\n", stat
);
582 return count
? IRQ_HANDLED
: IRQ_NONE
;
585 #ifdef CONFIG_CPU_FREQ
586 static int i2c_davinci_cpufreq_transition(struct notifier_block
*nb
,
587 unsigned long val
, void *data
)
589 struct davinci_i2c_dev
*dev
;
591 dev
= container_of(nb
, struct davinci_i2c_dev
, freq_transition
);
592 if (val
== CPUFREQ_PRECHANGE
) {
593 wait_for_completion(&dev
->xfr_complete
);
594 davinci_i2c_reset_ctrl(dev
, 0);
595 } else if (val
== CPUFREQ_POSTCHANGE
) {
596 i2c_davinci_calc_clk_dividers(dev
);
597 davinci_i2c_reset_ctrl(dev
, 1);
603 static inline int i2c_davinci_cpufreq_register(struct davinci_i2c_dev
*dev
)
605 dev
->freq_transition
.notifier_call
= i2c_davinci_cpufreq_transition
;
607 return cpufreq_register_notifier(&dev
->freq_transition
,
608 CPUFREQ_TRANSITION_NOTIFIER
);
611 static inline void i2c_davinci_cpufreq_deregister(struct davinci_i2c_dev
*dev
)
613 cpufreq_unregister_notifier(&dev
->freq_transition
,
614 CPUFREQ_TRANSITION_NOTIFIER
);
617 static inline int i2c_davinci_cpufreq_register(struct davinci_i2c_dev
*dev
)
622 static inline void i2c_davinci_cpufreq_deregister(struct davinci_i2c_dev
*dev
)
627 static struct i2c_algorithm i2c_davinci_algo
= {
628 .master_xfer
= i2c_davinci_xfer
,
629 .functionality
= i2c_davinci_func
,
632 static int davinci_i2c_probe(struct platform_device
*pdev
)
634 struct davinci_i2c_dev
*dev
;
635 struct i2c_adapter
*adap
;
636 struct resource
*mem
, *irq
, *ioarea
;
639 /* NOTE: driver uses the static register mapping */
640 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
642 dev_err(&pdev
->dev
, "no mem resource?\n");
646 irq
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
648 dev_err(&pdev
->dev
, "no irq resource?\n");
652 ioarea
= request_mem_region(mem
->start
, resource_size(mem
),
655 dev_err(&pdev
->dev
, "I2C region already claimed\n");
659 dev
= kzalloc(sizeof(struct davinci_i2c_dev
), GFP_KERNEL
);
662 goto err_release_region
;
665 init_completion(&dev
->cmd_complete
);
666 #ifdef CONFIG_CPU_FREQ
667 init_completion(&dev
->xfr_complete
);
669 dev
->dev
= get_device(&pdev
->dev
);
670 dev
->irq
= irq
->start
;
671 platform_set_drvdata(pdev
, dev
);
673 dev
->clk
= clk_get(&pdev
->dev
, NULL
);
674 if (IS_ERR(dev
->clk
)) {
678 clk_enable(dev
->clk
);
680 dev
->base
= ioremap(mem
->start
, resource_size(mem
));
683 goto err_mem_ioremap
;
686 i2c_davinci_init(dev
);
688 r
= request_irq(dev
->irq
, i2c_davinci_isr
, 0, pdev
->name
, dev
);
690 dev_err(&pdev
->dev
, "failure requesting irq %i\n", dev
->irq
);
691 goto err_unuse_clocks
;
694 r
= i2c_davinci_cpufreq_register(dev
);
696 dev_err(&pdev
->dev
, "failed to register cpufreq\n");
700 adap
= &dev
->adapter
;
701 i2c_set_adapdata(adap
, dev
);
702 adap
->owner
= THIS_MODULE
;
703 adap
->class = I2C_CLASS_HWMON
;
704 strlcpy(adap
->name
, "DaVinci I2C adapter", sizeof(adap
->name
));
705 adap
->algo
= &i2c_davinci_algo
;
706 adap
->dev
.parent
= &pdev
->dev
;
707 adap
->timeout
= DAVINCI_I2C_TIMEOUT
;
710 r
= i2c_add_numbered_adapter(adap
);
712 dev_err(&pdev
->dev
, "failure adding adapter\n");
719 free_irq(dev
->irq
, dev
);
723 clk_disable(dev
->clk
);
727 platform_set_drvdata(pdev
, NULL
);
728 put_device(&pdev
->dev
);
731 release_mem_region(mem
->start
, resource_size(mem
));
736 static int davinci_i2c_remove(struct platform_device
*pdev
)
738 struct davinci_i2c_dev
*dev
= platform_get_drvdata(pdev
);
739 struct resource
*mem
;
741 i2c_davinci_cpufreq_deregister(dev
);
743 platform_set_drvdata(pdev
, NULL
);
744 i2c_del_adapter(&dev
->adapter
);
745 put_device(&pdev
->dev
);
747 clk_disable(dev
->clk
);
751 davinci_i2c_write_reg(dev
, DAVINCI_I2C_MDR_REG
, 0);
752 free_irq(IRQ_I2C
, dev
);
756 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
757 release_mem_region(mem
->start
, resource_size(mem
));
762 static int davinci_i2c_suspend(struct device
*dev
)
764 struct platform_device
*pdev
= to_platform_device(dev
);
765 struct davinci_i2c_dev
*i2c_dev
= platform_get_drvdata(pdev
);
767 /* put I2C into reset */
768 davinci_i2c_reset_ctrl(i2c_dev
, 0);
769 clk_disable(i2c_dev
->clk
);
774 static int davinci_i2c_resume(struct device
*dev
)
776 struct platform_device
*pdev
= to_platform_device(dev
);
777 struct davinci_i2c_dev
*i2c_dev
= platform_get_drvdata(pdev
);
779 clk_enable(i2c_dev
->clk
);
780 /* take I2C out of reset */
781 davinci_i2c_reset_ctrl(i2c_dev
, 1);
786 static const struct dev_pm_ops davinci_i2c_pm
= {
787 .suspend
= davinci_i2c_suspend
,
788 .resume
= davinci_i2c_resume
,
791 #define davinci_i2c_pm_ops (&davinci_i2c_pm)
793 #define davinci_i2c_pm_ops NULL
796 /* work with hotplug and coldplug */
797 MODULE_ALIAS("platform:i2c_davinci");
799 static struct platform_driver davinci_i2c_driver
= {
800 .probe
= davinci_i2c_probe
,
801 .remove
= davinci_i2c_remove
,
803 .name
= "i2c_davinci",
804 .owner
= THIS_MODULE
,
805 .pm
= davinci_i2c_pm_ops
,
809 /* I2C may be needed to bring up other drivers */
810 static int __init
davinci_i2c_init_driver(void)
812 return platform_driver_register(&davinci_i2c_driver
);
814 subsys_initcall(davinci_i2c_init_driver
);
816 static void __exit
davinci_i2c_exit_driver(void)
818 platform_driver_unregister(&davinci_i2c_driver
);
820 module_exit(davinci_i2c_exit_driver
);
822 MODULE_AUTHOR("Texas Instruments India");
823 MODULE_DESCRIPTION("TI DaVinci I2C bus adapter");
824 MODULE_LICENSE("GPL");