diff options
Diffstat (limited to 'drivers/i2c/busses/i2c-omap.c')
-rw-r--r-- | drivers/i2c/busses/i2c-omap.c | 164 |
1 files changed, 92 insertions, 72 deletions
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index 2dfb63176856..a43d0023446a 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c | |||
@@ -42,12 +42,12 @@ | |||
42 | #include <linux/pm_runtime.h> | 42 | #include <linux/pm_runtime.h> |
43 | 43 | ||
44 | /* I2C controller revisions */ | 44 | /* I2C controller revisions */ |
45 | #define OMAP_I2C_REV_2 0x20 | 45 | #define OMAP_I2C_OMAP1_REV_2 0x20 |
46 | 46 | ||
47 | /* I2C controller revisions present on specific hardware */ | 47 | /* I2C controller revisions present on specific hardware */ |
48 | #define OMAP_I2C_REV_ON_2430 0x36 | 48 | #define OMAP_I2C_REV_ON_2430 0x36 |
49 | #define OMAP_I2C_REV_ON_3430 0x3C | 49 | #define OMAP_I2C_REV_ON_3430 0x3C |
50 | #define OMAP_I2C_REV_ON_4430 0x40 | 50 | #define OMAP_I2C_REV_ON_3530_4430 0x40 |
51 | 51 | ||
52 | /* timeout waiting for the controller to respond */ | 52 | /* timeout waiting for the controller to respond */ |
53 | #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000)) | 53 | #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000)) |
@@ -72,11 +72,12 @@ enum { | |||
72 | OMAP_I2C_SCLH_REG, | 72 | OMAP_I2C_SCLH_REG, |
73 | OMAP_I2C_SYSTEST_REG, | 73 | OMAP_I2C_SYSTEST_REG, |
74 | OMAP_I2C_BUFSTAT_REG, | 74 | OMAP_I2C_BUFSTAT_REG, |
75 | OMAP_I2C_REVNB_LO, | 75 | /* only on OMAP4430 */ |
76 | OMAP_I2C_REVNB_HI, | 76 | OMAP_I2C_IP_V2_REVNB_LO, |
77 | OMAP_I2C_IRQSTATUS_RAW, | 77 | OMAP_I2C_IP_V2_REVNB_HI, |
78 | OMAP_I2C_IRQENABLE_SET, | 78 | OMAP_I2C_IP_V2_IRQSTATUS_RAW, |
79 | OMAP_I2C_IRQENABLE_CLR, | 79 | OMAP_I2C_IP_V2_IRQENABLE_SET, |
80 | OMAP_I2C_IP_V2_IRQENABLE_CLR, | ||
80 | }; | 81 | }; |
81 | 82 | ||
82 | /* I2C Interrupt Enable Register (OMAP_I2C_IE): */ | 83 | /* I2C Interrupt Enable Register (OMAP_I2C_IE): */ |
@@ -193,7 +194,6 @@ struct omap_i2c_dev { | |||
193 | */ | 194 | */ |
194 | u8 rev; | 195 | u8 rev; |
195 | unsigned b_hw:1; /* bad h/w fixes */ | 196 | unsigned b_hw:1; /* bad h/w fixes */ |
196 | unsigned idle:1; | ||
197 | u16 iestate; /* Saved interrupt register */ | 197 | u16 iestate; /* Saved interrupt register */ |
198 | u16 pscstate; | 198 | u16 pscstate; |
199 | u16 scllstate; | 199 | u16 scllstate; |
@@ -204,7 +204,7 @@ struct omap_i2c_dev { | |||
204 | u16 errata; | 204 | u16 errata; |
205 | }; | 205 | }; |
206 | 206 | ||
207 | static const u8 reg_map[] = { | 207 | static const u8 reg_map_ip_v1[] = { |
208 | [OMAP_I2C_REV_REG] = 0x00, | 208 | [OMAP_I2C_REV_REG] = 0x00, |
209 | [OMAP_I2C_IE_REG] = 0x01, | 209 | [OMAP_I2C_IE_REG] = 0x01, |
210 | [OMAP_I2C_STAT_REG] = 0x02, | 210 | [OMAP_I2C_STAT_REG] = 0x02, |
@@ -225,7 +225,7 @@ static const u8 reg_map[] = { | |||
225 | [OMAP_I2C_BUFSTAT_REG] = 0x10, | 225 | [OMAP_I2C_BUFSTAT_REG] = 0x10, |
226 | }; | 226 | }; |
227 | 227 | ||
228 | static const u8 omap4_reg_map[] = { | 228 | static const u8 reg_map_ip_v2[] = { |
229 | [OMAP_I2C_REV_REG] = 0x04, | 229 | [OMAP_I2C_REV_REG] = 0x04, |
230 | [OMAP_I2C_IE_REG] = 0x2c, | 230 | [OMAP_I2C_IE_REG] = 0x2c, |
231 | [OMAP_I2C_STAT_REG] = 0x28, | 231 | [OMAP_I2C_STAT_REG] = 0x28, |
@@ -244,11 +244,11 @@ static const u8 omap4_reg_map[] = { | |||
244 | [OMAP_I2C_SCLH_REG] = 0xb8, | 244 | [OMAP_I2C_SCLH_REG] = 0xb8, |
245 | [OMAP_I2C_SYSTEST_REG] = 0xbC, | 245 | [OMAP_I2C_SYSTEST_REG] = 0xbC, |
246 | [OMAP_I2C_BUFSTAT_REG] = 0xc0, | 246 | [OMAP_I2C_BUFSTAT_REG] = 0xc0, |
247 | [OMAP_I2C_REVNB_LO] = 0x00, | 247 | [OMAP_I2C_IP_V2_REVNB_LO] = 0x00, |
248 | [OMAP_I2C_REVNB_HI] = 0x04, | 248 | [OMAP_I2C_IP_V2_REVNB_HI] = 0x04, |
249 | [OMAP_I2C_IRQSTATUS_RAW] = 0x24, | 249 | [OMAP_I2C_IP_V2_IRQSTATUS_RAW] = 0x24, |
250 | [OMAP_I2C_IRQENABLE_SET] = 0x2c, | 250 | [OMAP_I2C_IP_V2_IRQENABLE_SET] = 0x2c, |
251 | [OMAP_I2C_IRQENABLE_CLR] = 0x30, | 251 | [OMAP_I2C_IP_V2_IRQENABLE_CLR] = 0x30, |
252 | }; | 252 | }; |
253 | 253 | ||
254 | static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev, | 254 | static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev, |
@@ -266,17 +266,11 @@ static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg) | |||
266 | 266 | ||
267 | static void omap_i2c_unidle(struct omap_i2c_dev *dev) | 267 | static void omap_i2c_unidle(struct omap_i2c_dev *dev) |
268 | { | 268 | { |
269 | struct platform_device *pdev; | ||
270 | struct omap_i2c_bus_platform_data *pdata; | 269 | struct omap_i2c_bus_platform_data *pdata; |
271 | 270 | ||
272 | WARN_ON(!dev->idle); | 271 | pdata = dev->dev->platform_data; |
273 | 272 | ||
274 | pdev = to_platform_device(dev->dev); | 273 | if (pdata->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) { |
275 | pdata = pdev->dev.platform_data; | ||
276 | |||
277 | pm_runtime_get_sync(&pdev->dev); | ||
278 | |||
279 | if (cpu_is_omap34xx()) { | ||
280 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | 274 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
281 | omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate); | 275 | omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate); |
282 | omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, dev->scllstate); | 276 | omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, dev->scllstate); |
@@ -286,7 +280,6 @@ static void omap_i2c_unidle(struct omap_i2c_dev *dev) | |||
286 | omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate); | 280 | omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate); |
287 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); | 281 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); |
288 | } | 282 | } |
289 | dev->idle = 0; | ||
290 | 283 | ||
291 | /* | 284 | /* |
292 | * Don't write to this register if the IE state is 0 as it can | 285 | * Don't write to this register if the IE state is 0 as it can |
@@ -298,32 +291,25 @@ static void omap_i2c_unidle(struct omap_i2c_dev *dev) | |||
298 | 291 | ||
299 | static void omap_i2c_idle(struct omap_i2c_dev *dev) | 292 | static void omap_i2c_idle(struct omap_i2c_dev *dev) |
300 | { | 293 | { |
301 | struct platform_device *pdev; | ||
302 | struct omap_i2c_bus_platform_data *pdata; | 294 | struct omap_i2c_bus_platform_data *pdata; |
303 | u16 iv; | 295 | u16 iv; |
304 | 296 | ||
305 | WARN_ON(dev->idle); | 297 | pdata = dev->dev->platform_data; |
306 | |||
307 | pdev = to_platform_device(dev->dev); | ||
308 | pdata = pdev->dev.platform_data; | ||
309 | 298 | ||
310 | dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); | 299 | dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); |
311 | if (dev->rev >= OMAP_I2C_REV_ON_4430) | 300 | if (pdata->rev == OMAP_I2C_IP_VERSION_2) |
312 | omap_i2c_write_reg(dev, OMAP_I2C_IRQENABLE_CLR, 1); | 301 | omap_i2c_write_reg(dev, OMAP_I2C_IP_V2_IRQENABLE_CLR, 1); |
313 | else | 302 | else |
314 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0); | 303 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0); |
315 | 304 | ||
316 | if (dev->rev < OMAP_I2C_REV_2) { | 305 | if (dev->rev < OMAP_I2C_OMAP1_REV_2) { |
317 | iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */ | 306 | iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */ |
318 | } else { | 307 | } else { |
319 | omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, dev->iestate); | 308 | omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, dev->iestate); |
320 | 309 | ||
321 | /* Flush posted write before the dev->idle store occurs */ | 310 | /* Flush posted write */ |
322 | omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); | 311 | omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); |
323 | } | 312 | } |
324 | dev->idle = 1; | ||
325 | |||
326 | pm_runtime_put_sync(&pdev->dev); | ||
327 | } | 313 | } |
328 | 314 | ||
329 | static int omap_i2c_init(struct omap_i2c_dev *dev) | 315 | static int omap_i2c_init(struct omap_i2c_dev *dev) |
@@ -334,8 +320,11 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
334 | unsigned long timeout; | 320 | unsigned long timeout; |
335 | unsigned long internal_clk = 0; | 321 | unsigned long internal_clk = 0; |
336 | struct clk *fclk; | 322 | struct clk *fclk; |
323 | struct omap_i2c_bus_platform_data *pdata; | ||
324 | |||
325 | pdata = dev->dev->platform_data; | ||
337 | 326 | ||
338 | if (dev->rev >= OMAP_I2C_REV_2) { | 327 | if (dev->rev >= OMAP_I2C_OMAP1_REV_2) { |
339 | /* Disable I2C controller before soft reset */ | 328 | /* Disable I2C controller before soft reset */ |
340 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, | 329 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, |
341 | omap_i2c_read_reg(dev, OMAP_I2C_CON_REG) & | 330 | omap_i2c_read_reg(dev, OMAP_I2C_CON_REG) & |
@@ -378,12 +367,13 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
378 | * REVISIT: Some wkup sources might not be needed. | 367 | * REVISIT: Some wkup sources might not be needed. |
379 | */ | 368 | */ |
380 | dev->westate = OMAP_I2C_WE_ALL; | 369 | dev->westate = OMAP_I2C_WE_ALL; |
381 | omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate); | 370 | omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, |
371 | dev->westate); | ||
382 | } | 372 | } |
383 | } | 373 | } |
384 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | 374 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
385 | 375 | ||
386 | if (cpu_class_is_omap1()) { | 376 | if (pdata->flags & OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK) { |
387 | /* | 377 | /* |
388 | * The I2C functional clock is the armxor_ck, so there's | 378 | * The I2C functional clock is the armxor_ck, so there's |
389 | * no need to get "armxor_ck" separately. Now, if OMAP2420 | 379 | * no need to get "armxor_ck" separately. Now, if OMAP2420 |
@@ -407,7 +397,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
407 | psc = fclk_rate / 12000000; | 397 | psc = fclk_rate / 12000000; |
408 | } | 398 | } |
409 | 399 | ||
410 | if (!(cpu_class_is_omap1() || cpu_is_omap2420())) { | 400 | if (!(pdata->flags & OMAP_I2C_FLAG_SIMPLE_CLOCK)) { |
411 | 401 | ||
412 | /* | 402 | /* |
413 | * HSI2C controller internal clk rate should be 19.2 Mhz for | 403 | * HSI2C controller internal clk rate should be 19.2 Mhz for |
@@ -415,7 +405,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
415 | * to get longer filter period for better noise suppression. | 405 | * to get longer filter period for better noise suppression. |
416 | * The filter is iclk (fclk for HS) period. | 406 | * The filter is iclk (fclk for HS) period. |
417 | */ | 407 | */ |
418 | if (dev->speed > 400 || cpu_is_omap2430()) | 408 | if (dev->speed > 400 || |
409 | pdata->flags & OMAP_I2C_FLAG_FORCE_19200_INT_CLK) | ||
419 | internal_clk = 19200; | 410 | internal_clk = 19200; |
420 | else if (dev->speed > 100) | 411 | else if (dev->speed > 100) |
421 | internal_clk = 9600; | 412 | internal_clk = 9600; |
@@ -484,7 +475,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
484 | 475 | ||
485 | dev->errata = 0; | 476 | dev->errata = 0; |
486 | 477 | ||
487 | if (cpu_is_omap2430() || cpu_is_omap34xx()) | 478 | if (pdata->flags & OMAP_I2C_FLAG_APPLY_ERRATA_I207) |
488 | dev->errata |= I2C_OMAP_ERRATA_I207; | 479 | dev->errata |= I2C_OMAP_ERRATA_I207; |
489 | 480 | ||
490 | /* Enable interrupts */ | 481 | /* Enable interrupts */ |
@@ -493,7 +484,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
493 | OMAP_I2C_IE_AL) | ((dev->fifo_size) ? | 484 | OMAP_I2C_IE_AL) | ((dev->fifo_size) ? |
494 | (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0); | 485 | (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0); |
495 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); | 486 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); |
496 | if (cpu_is_omap34xx()) { | 487 | if (pdata->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) { |
497 | dev->pscstate = psc; | 488 | dev->pscstate = psc; |
498 | dev->scllstate = scll; | 489 | dev->scllstate = scll; |
499 | dev->sclhstate = sclh; | 490 | dev->sclhstate = sclh; |
@@ -642,7 +633,7 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
642 | int i; | 633 | int i; |
643 | int r; | 634 | int r; |
644 | 635 | ||
645 | omap_i2c_unidle(dev); | 636 | pm_runtime_get_sync(dev->dev); |
646 | 637 | ||
647 | r = omap_i2c_wait_for_bb(dev); | 638 | r = omap_i2c_wait_for_bb(dev); |
648 | if (r < 0) | 639 | if (r < 0) |
@@ -665,7 +656,7 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
665 | 656 | ||
666 | omap_i2c_wait_for_bb(dev); | 657 | omap_i2c_wait_for_bb(dev); |
667 | out: | 658 | out: |
668 | omap_i2c_idle(dev); | 659 | pm_runtime_put(dev->dev); |
669 | return r; | 660 | return r; |
670 | } | 661 | } |
671 | 662 | ||
@@ -720,12 +711,12 @@ static inline void i2c_omap_errata_i207(struct omap_i2c_dev *dev, u16 stat) | |||
720 | #ifdef CONFIG_ARCH_OMAP15XX | 711 | #ifdef CONFIG_ARCH_OMAP15XX |
721 | 712 | ||
722 | static irqreturn_t | 713 | static irqreturn_t |
723 | omap_i2c_rev1_isr(int this_irq, void *dev_id) | 714 | omap_i2c_omap1_isr(int this_irq, void *dev_id) |
724 | { | 715 | { |
725 | struct omap_i2c_dev *dev = dev_id; | 716 | struct omap_i2c_dev *dev = dev_id; |
726 | u16 iv, w; | 717 | u16 iv, w; |
727 | 718 | ||
728 | if (dev->idle) | 719 | if (pm_runtime_suspended(dev->dev)) |
729 | return IRQ_NONE; | 720 | return IRQ_NONE; |
730 | 721 | ||
731 | iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); | 722 | iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); |
@@ -774,7 +765,7 @@ omap_i2c_rev1_isr(int this_irq, void *dev_id) | |||
774 | return IRQ_HANDLED; | 765 | return IRQ_HANDLED; |
775 | } | 766 | } |
776 | #else | 767 | #else |
777 | #define omap_i2c_rev1_isr NULL | 768 | #define omap_i2c_omap1_isr NULL |
778 | #endif | 769 | #endif |
779 | 770 | ||
780 | /* | 771 | /* |
@@ -813,8 +804,11 @@ omap_i2c_isr(int this_irq, void *dev_id) | |||
813 | u16 bits; | 804 | u16 bits; |
814 | u16 stat, w; | 805 | u16 stat, w; |
815 | int err, count = 0; | 806 | int err, count = 0; |
807 | struct omap_i2c_bus_platform_data *pdata; | ||
816 | 808 | ||
817 | if (dev->idle) | 809 | pdata = dev->dev->platform_data; |
810 | |||
811 | if (pm_runtime_suspended(dev->dev)) | ||
818 | return IRQ_NONE; | 812 | return IRQ_NONE; |
819 | 813 | ||
820 | bits = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); | 814 | bits = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); |
@@ -881,8 +875,8 @@ complete: | |||
881 | * Data reg in 2430, omap3 and | 875 | * Data reg in 2430, omap3 and |
882 | * omap4 is 8 bit wide | 876 | * omap4 is 8 bit wide |
883 | */ | 877 | */ |
884 | if (cpu_class_is_omap1() || | 878 | if (pdata->flags & |
885 | cpu_is_omap2420()) { | 879 | OMAP_I2C_FLAG_16BIT_DATA_REG) { |
886 | if (dev->buf_len) { | 880 | if (dev->buf_len) { |
887 | *dev->buf++ = w >> 8; | 881 | *dev->buf++ = w >> 8; |
888 | dev->buf_len--; | 882 | dev->buf_len--; |
@@ -924,8 +918,8 @@ complete: | |||
924 | * Data reg in 2430, omap3 and | 918 | * Data reg in 2430, omap3 and |
925 | * omap4 is 8 bit wide | 919 | * omap4 is 8 bit wide |
926 | */ | 920 | */ |
927 | if (cpu_class_is_omap1() || | 921 | if (pdata->flags & |
928 | cpu_is_omap2420()) { | 922 | OMAP_I2C_FLAG_16BIT_DATA_REG) { |
929 | if (dev->buf_len) { | 923 | if (dev->buf_len) { |
930 | w |= *dev->buf++ << 8; | 924 | w |= *dev->buf++ << 8; |
931 | dev->buf_len--; | 925 | dev->buf_len--; |
@@ -1016,7 +1010,6 @@ omap_i2c_probe(struct platform_device *pdev) | |||
1016 | } | 1010 | } |
1017 | 1011 | ||
1018 | dev->speed = speed; | 1012 | dev->speed = speed; |
1019 | dev->idle = 1; | ||
1020 | dev->dev = &pdev->dev; | 1013 | dev->dev = &pdev->dev; |
1021 | dev->irq = irq->start; | 1014 | dev->irq = irq->start; |
1022 | dev->base = ioremap(mem->start, resource_size(mem)); | 1015 | dev->base = ioremap(mem->start, resource_size(mem)); |
@@ -1027,27 +1020,22 @@ omap_i2c_probe(struct platform_device *pdev) | |||
1027 | 1020 | ||
1028 | platform_set_drvdata(pdev, dev); | 1021 | platform_set_drvdata(pdev, dev); |
1029 | 1022 | ||
1030 | if (cpu_is_omap7xx()) | 1023 | dev->reg_shift = (pdata->flags >> OMAP_I2C_FLAG_BUS_SHIFT__SHIFT) & 3; |
1031 | dev->reg_shift = 1; | ||
1032 | else if (cpu_is_omap44xx()) | ||
1033 | dev->reg_shift = 0; | ||
1034 | else | ||
1035 | dev->reg_shift = 2; | ||
1036 | 1024 | ||
1037 | if (cpu_is_omap44xx()) | 1025 | if (pdata->rev == OMAP_I2C_IP_VERSION_2) |
1038 | dev->regs = (u8 *) omap4_reg_map; | 1026 | dev->regs = (u8 *)reg_map_ip_v2; |
1039 | else | 1027 | else |
1040 | dev->regs = (u8 *) reg_map; | 1028 | dev->regs = (u8 *)reg_map_ip_v1; |
1041 | 1029 | ||
1042 | pm_runtime_enable(&pdev->dev); | 1030 | pm_runtime_enable(dev->dev); |
1043 | omap_i2c_unidle(dev); | 1031 | pm_runtime_get_sync(dev->dev); |
1044 | 1032 | ||
1045 | dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; | 1033 | dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; |
1046 | 1034 | ||
1047 | if (dev->rev <= OMAP_I2C_REV_ON_3430) | 1035 | if (dev->rev <= OMAP_I2C_REV_ON_3430) |
1048 | dev->errata |= I2C_OMAP3_1P153; | 1036 | dev->errata |= I2C_OMAP3_1P153; |
1049 | 1037 | ||
1050 | if (!(cpu_class_is_omap1() || cpu_is_omap2420())) { | 1038 | if (!(pdata->flags & OMAP_I2C_FLAG_NO_FIFO)) { |
1051 | u16 s; | 1039 | u16 s; |
1052 | 1040 | ||
1053 | /* Set up the fifo size - Get total size */ | 1041 | /* Set up the fifo size - Get total size */ |
@@ -1059,7 +1047,7 @@ omap_i2c_probe(struct platform_device *pdev) | |||
1059 | * size. This is to ensure that we can handle the status on int | 1047 | * size. This is to ensure that we can handle the status on int |
1060 | * call back latencies. | 1048 | * call back latencies. |
1061 | */ | 1049 | */ |
1062 | if (dev->rev >= OMAP_I2C_REV_ON_4430) { | 1050 | if (dev->rev >= OMAP_I2C_REV_ON_3530_4430) { |
1063 | dev->fifo_size = 0; | 1051 | dev->fifo_size = 0; |
1064 | dev->b_hw = 0; /* Disable hardware fixes */ | 1052 | dev->b_hw = 0; /* Disable hardware fixes */ |
1065 | } else { | 1053 | } else { |
@@ -1075,7 +1063,8 @@ omap_i2c_probe(struct platform_device *pdev) | |||
1075 | /* reset ASAP, clearing any IRQs */ | 1063 | /* reset ASAP, clearing any IRQs */ |
1076 | omap_i2c_init(dev); | 1064 | omap_i2c_init(dev); |
1077 | 1065 | ||
1078 | isr = (dev->rev < OMAP_I2C_REV_2) ? omap_i2c_rev1_isr : omap_i2c_isr; | 1066 | isr = (dev->rev < OMAP_I2C_OMAP1_REV_2) ? omap_i2c_omap1_isr : |
1067 | omap_i2c_isr; | ||
1079 | r = request_irq(dev->irq, isr, 0, pdev->name, dev); | 1068 | r = request_irq(dev->irq, isr, 0, pdev->name, dev); |
1080 | 1069 | ||
1081 | if (r) { | 1070 | if (r) { |
@@ -1083,10 +1072,10 @@ omap_i2c_probe(struct platform_device *pdev) | |||
1083 | goto err_unuse_clocks; | 1072 | goto err_unuse_clocks; |
1084 | } | 1073 | } |
1085 | 1074 | ||
1086 | dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n", | 1075 | dev_info(dev->dev, "bus %d rev%d.%d.%d at %d kHz\n", pdev->id, |
1087 | pdev->id, dev->rev >> 4, dev->rev & 0xf, dev->speed); | 1076 | pdata->rev, dev->rev >> 4, dev->rev & 0xf, dev->speed); |
1088 | 1077 | ||
1089 | omap_i2c_idle(dev); | 1078 | pm_runtime_put(dev->dev); |
1090 | 1079 | ||
1091 | adap = &dev->adapter; | 1080 | adap = &dev->adapter; |
1092 | i2c_set_adapdata(adap, dev); | 1081 | i2c_set_adapdata(adap, dev); |
@@ -1110,7 +1099,7 @@ err_free_irq: | |||
1110 | free_irq(dev->irq, dev); | 1099 | free_irq(dev->irq, dev); |
1111 | err_unuse_clocks: | 1100 | err_unuse_clocks: |
1112 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | 1101 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
1113 | omap_i2c_idle(dev); | 1102 | pm_runtime_put(dev->dev); |
1114 | iounmap(dev->base); | 1103 | iounmap(dev->base); |
1115 | err_free_mem: | 1104 | err_free_mem: |
1116 | platform_set_drvdata(pdev, NULL); | 1105 | platform_set_drvdata(pdev, NULL); |
@@ -1139,12 +1128,43 @@ omap_i2c_remove(struct platform_device *pdev) | |||
1139 | return 0; | 1128 | return 0; |
1140 | } | 1129 | } |
1141 | 1130 | ||
1131 | #ifdef CONFIG_PM_RUNTIME | ||
1132 | static int omap_i2c_runtime_suspend(struct device *dev) | ||
1133 | { | ||
1134 | struct platform_device *pdev = to_platform_device(dev); | ||
1135 | struct omap_i2c_dev *_dev = platform_get_drvdata(pdev); | ||
1136 | |||
1137 | omap_i2c_idle(_dev); | ||
1138 | |||
1139 | return 0; | ||
1140 | } | ||
1141 | |||
1142 | static int omap_i2c_runtime_resume(struct device *dev) | ||
1143 | { | ||
1144 | struct platform_device *pdev = to_platform_device(dev); | ||
1145 | struct omap_i2c_dev *_dev = platform_get_drvdata(pdev); | ||
1146 | |||
1147 | omap_i2c_unidle(_dev); | ||
1148 | |||
1149 | return 0; | ||
1150 | } | ||
1151 | |||
1152 | static struct dev_pm_ops omap_i2c_pm_ops = { | ||
1153 | .runtime_suspend = omap_i2c_runtime_suspend, | ||
1154 | .runtime_resume = omap_i2c_runtime_resume, | ||
1155 | }; | ||
1156 | #define OMAP_I2C_PM_OPS (&omap_i2c_pm_ops) | ||
1157 | #else | ||
1158 | #define OMAP_I2C_PM_OPS NULL | ||
1159 | #endif | ||
1160 | |||
1142 | static struct platform_driver omap_i2c_driver = { | 1161 | static struct platform_driver omap_i2c_driver = { |
1143 | .probe = omap_i2c_probe, | 1162 | .probe = omap_i2c_probe, |
1144 | .remove = omap_i2c_remove, | 1163 | .remove = omap_i2c_remove, |
1145 | .driver = { | 1164 | .driver = { |
1146 | .name = "omap_i2c", | 1165 | .name = "omap_i2c", |
1147 | .owner = THIS_MODULE, | 1166 | .owner = THIS_MODULE, |
1167 | .pm = OMAP_I2C_PM_OPS, | ||
1148 | }, | 1168 | }, |
1149 | }; | 1169 | }; |
1150 | 1170 | ||