diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/i2c/busses/i2c-pxa.c | 133 |
1 files changed, 121 insertions, 12 deletions
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index da3ecf5c591b..2598d29fd7a4 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c | |||
@@ -65,6 +65,7 @@ struct pxa_i2c { | |||
65 | unsigned long iosize; | 65 | unsigned long iosize; |
66 | 66 | ||
67 | int irq; | 67 | int irq; |
68 | int use_pio; | ||
68 | }; | 69 | }; |
69 | 70 | ||
70 | #define _IBMR(i2c) ((i2c)->reg_base + 0) | 71 | #define _IBMR(i2c) ((i2c)->reg_base + 0) |
@@ -163,6 +164,7 @@ static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname) | |||
163 | #define eedbg(lvl, x...) do { if ((lvl) < 1) { printk(KERN_DEBUG "" x); } } while(0) | 164 | #define eedbg(lvl, x...) do { if ((lvl) < 1) { printk(KERN_DEBUG "" x); } } while(0) |
164 | 165 | ||
165 | static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret); | 166 | static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret); |
167 | static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id); | ||
166 | 168 | ||
167 | static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why) | 169 | static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why) |
168 | { | 170 | { |
@@ -554,6 +556,71 @@ static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c) | |||
554 | writel(icr, _ICR(i2c)); | 556 | writel(icr, _ICR(i2c)); |
555 | } | 557 | } |
556 | 558 | ||
559 | static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c) | ||
560 | { | ||
561 | /* make timeout the same as for interrupt based functions */ | ||
562 | long timeout = 2 * DEF_TIMEOUT; | ||
563 | |||
564 | /* | ||
565 | * Wait for the bus to become free. | ||
566 | */ | ||
567 | while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) { | ||
568 | udelay(1000); | ||
569 | show_state(i2c); | ||
570 | } | ||
571 | |||
572 | if (timeout <= 0) { | ||
573 | show_state(i2c); | ||
574 | dev_err(&i2c->adap.dev, | ||
575 | "i2c_pxa: timeout waiting for bus free\n"); | ||
576 | return I2C_RETRY; | ||
577 | } | ||
578 | |||
579 | /* | ||
580 | * Set master mode. | ||
581 | */ | ||
582 | writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c)); | ||
583 | |||
584 | return 0; | ||
585 | } | ||
586 | |||
587 | static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c, | ||
588 | struct i2c_msg *msg, int num) | ||
589 | { | ||
590 | unsigned long timeout = 500000; /* 5 seconds */ | ||
591 | int ret = 0; | ||
592 | |||
593 | ret = i2c_pxa_pio_set_master(i2c); | ||
594 | if (ret) | ||
595 | goto out; | ||
596 | |||
597 | i2c->msg = msg; | ||
598 | i2c->msg_num = num; | ||
599 | i2c->msg_idx = 0; | ||
600 | i2c->msg_ptr = 0; | ||
601 | i2c->irqlogidx = 0; | ||
602 | |||
603 | i2c_pxa_start_message(i2c); | ||
604 | |||
605 | while (timeout-- && i2c->msg_num > 0) { | ||
606 | i2c_pxa_handler(0, i2c); | ||
607 | udelay(10); | ||
608 | } | ||
609 | |||
610 | i2c_pxa_stop_message(i2c); | ||
611 | |||
612 | /* | ||
613 | * We place the return code in i2c->msg_idx. | ||
614 | */ | ||
615 | ret = i2c->msg_idx; | ||
616 | |||
617 | out: | ||
618 | if (timeout == 0) | ||
619 | i2c_pxa_scream_blue_murder(i2c, "timeout"); | ||
620 | |||
621 | return ret; | ||
622 | } | ||
623 | |||
557 | /* | 624 | /* |
558 | * We are protected by the adapter bus mutex. | 625 | * We are protected by the adapter bus mutex. |
559 | */ | 626 | */ |
@@ -610,6 +677,35 @@ static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num) | |||
610 | return ret; | 677 | return ret; |
611 | } | 678 | } |
612 | 679 | ||
680 | static int i2c_pxa_pio_xfer(struct i2c_adapter *adap, | ||
681 | struct i2c_msg msgs[], int num) | ||
682 | { | ||
683 | struct pxa_i2c *i2c = adap->algo_data; | ||
684 | int ret, i; | ||
685 | |||
686 | /* If the I2C controller is disabled we need to reset it | ||
687 | (probably due to a suspend/resume destroying state). We do | ||
688 | this here as we can then avoid worrying about resuming the | ||
689 | controller before its users. */ | ||
690 | if (!(readl(_ICR(i2c)) & ICR_IUE)) | ||
691 | i2c_pxa_reset(i2c); | ||
692 | |||
693 | for (i = adap->retries; i >= 0; i--) { | ||
694 | ret = i2c_pxa_do_pio_xfer(i2c, msgs, num); | ||
695 | if (ret != I2C_RETRY) | ||
696 | goto out; | ||
697 | |||
698 | if (i2c_debug) | ||
699 | dev_dbg(&adap->dev, "Retrying transmission\n"); | ||
700 | udelay(100); | ||
701 | } | ||
702 | i2c_pxa_scream_blue_murder(i2c, "exhausted retries"); | ||
703 | ret = -EREMOTEIO; | ||
704 | out: | ||
705 | i2c_pxa_set_slave(i2c, ret); | ||
706 | return ret; | ||
707 | } | ||
708 | |||
613 | /* | 709 | /* |
614 | * i2c_pxa_master_complete - complete the message and wake up. | 710 | * i2c_pxa_master_complete - complete the message and wake up. |
615 | */ | 711 | */ |
@@ -621,7 +717,8 @@ static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret) | |||
621 | i2c->msg_num = 0; | 717 | i2c->msg_num = 0; |
622 | if (ret) | 718 | if (ret) |
623 | i2c->msg_idx = ret; | 719 | i2c->msg_idx = ret; |
624 | wake_up(&i2c->wait); | 720 | if (!i2c->use_pio) |
721 | wake_up(&i2c->wait); | ||
625 | } | 722 | } |
626 | 723 | ||
627 | static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr) | 724 | static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr) |
@@ -840,6 +937,11 @@ static const struct i2c_algorithm i2c_pxa_algorithm = { | |||
840 | .functionality = i2c_pxa_functionality, | 937 | .functionality = i2c_pxa_functionality, |
841 | }; | 938 | }; |
842 | 939 | ||
940 | static const struct i2c_algorithm i2c_pxa_pio_algorithm = { | ||
941 | .master_xfer = i2c_pxa_pio_xfer, | ||
942 | .functionality = i2c_pxa_functionality, | ||
943 | }; | ||
944 | |||
843 | static void i2c_pxa_enable(struct platform_device *dev) | 945 | static void i2c_pxa_enable(struct platform_device *dev) |
844 | { | 946 | { |
845 | if (cpu_is_pxa27x()) { | 947 | if (cpu_is_pxa27x()) { |
@@ -890,7 +992,6 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
890 | } | 992 | } |
891 | 993 | ||
892 | i2c->adap.owner = THIS_MODULE; | 994 | i2c->adap.owner = THIS_MODULE; |
893 | i2c->adap.algo = &i2c_pxa_algorithm; | ||
894 | i2c->adap.retries = 5; | 995 | i2c->adap.retries = 5; |
895 | 996 | ||
896 | spin_lock_init(&i2c->lock); | 997 | spin_lock_init(&i2c->lock); |
@@ -927,20 +1028,26 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
927 | clk_enable(i2c->clk); | 1028 | clk_enable(i2c->clk); |
928 | i2c_pxa_enable(dev); | 1029 | i2c_pxa_enable(dev); |
929 | 1030 | ||
930 | ret = request_irq(irq, i2c_pxa_handler, IRQF_DISABLED, | 1031 | if (plat) { |
931 | i2c->adap.name, i2c); | 1032 | i2c->adap.class = plat->class; |
932 | if (ret) | 1033 | i2c->use_pio = plat->use_pio; |
933 | goto ereqirq; | 1034 | } |
1035 | |||
1036 | if (i2c->use_pio) { | ||
1037 | i2c->adap.algo = &i2c_pxa_pio_algorithm; | ||
1038 | } else { | ||
1039 | i2c->adap.algo = &i2c_pxa_algorithm; | ||
1040 | ret = request_irq(irq, i2c_pxa_handler, IRQF_DISABLED, | ||
1041 | i2c->adap.name, i2c); | ||
1042 | if (ret) | ||
1043 | goto ereqirq; | ||
1044 | } | ||
934 | 1045 | ||
935 | i2c_pxa_reset(i2c); | 1046 | i2c_pxa_reset(i2c); |
936 | 1047 | ||
937 | i2c->adap.algo_data = i2c; | 1048 | i2c->adap.algo_data = i2c; |
938 | i2c->adap.dev.parent = &dev->dev; | 1049 | i2c->adap.dev.parent = &dev->dev; |
939 | 1050 | ||
940 | if (plat) { | ||
941 | i2c->adap.class = plat->class; | ||
942 | } | ||
943 | |||
944 | /* | 1051 | /* |
945 | * If "dev->id" is negative we consider it as zero. | 1052 | * If "dev->id" is negative we consider it as zero. |
946 | * The reason to do so is to avoid sysfs names that only make | 1053 | * The reason to do so is to avoid sysfs names that only make |
@@ -966,7 +1073,8 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
966 | return 0; | 1073 | return 0; |
967 | 1074 | ||
968 | eadapt: | 1075 | eadapt: |
969 | free_irq(irq, i2c); | 1076 | if (!i2c->use_pio) |
1077 | free_irq(irq, i2c); | ||
970 | ereqirq: | 1078 | ereqirq: |
971 | clk_disable(i2c->clk); | 1079 | clk_disable(i2c->clk); |
972 | i2c_pxa_disable(dev); | 1080 | i2c_pxa_disable(dev); |
@@ -986,7 +1094,8 @@ static int i2c_pxa_remove(struct platform_device *dev) | |||
986 | platform_set_drvdata(dev, NULL); | 1094 | platform_set_drvdata(dev, NULL); |
987 | 1095 | ||
988 | i2c_del_adapter(&i2c->adap); | 1096 | i2c_del_adapter(&i2c->adap); |
989 | free_irq(i2c->irq, i2c); | 1097 | if (!i2c->use_pio) |
1098 | free_irq(i2c->irq, i2c); | ||
990 | 1099 | ||
991 | clk_disable(i2c->clk); | 1100 | clk_disable(i2c->clk); |
992 | clk_put(i2c->clk); | 1101 | clk_put(i2c->clk); |