diff options
author | Felipe Balbi <balbi@ti.com> | 2012-09-12 06:58:02 -0400 |
---|---|---|
committer | Wolfram Sang <w.sang@pengutronix.de> | 2012-09-12 09:02:36 -0400 |
commit | 3312d25e1abdc41be8a75a1b2c3ccaa39a14ed99 (patch) | |
tree | 77f33224780f8dda593ea5b5340bb2793370f15d /drivers/i2c/busses/i2c-omap.c | |
parent | 4151e74177b68c40079d8fe98f2fda4b9792a998 (diff) |
i2c: omap: re-factor receive/transmit data loop
re-factor the common parts to a separate function,
so that code is easier to read and understand.
No functional changes.
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Diffstat (limited to 'drivers/i2c/busses/i2c-omap.c')
-rw-r--r-- | drivers/i2c/busses/i2c-omap.c | 204 |
1 files changed, 82 insertions, 122 deletions
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index fb5722186d95..2c7d7cc30e95 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c | |||
@@ -752,12 +752,81 @@ static int errata_omap3_i462(struct omap_i2c_dev *dev) | |||
752 | return 0; | 752 | return 0; |
753 | } | 753 | } |
754 | 754 | ||
755 | static void omap_i2c_receive_data(struct omap_i2c_dev *dev, u8 num_bytes, | ||
756 | bool is_rdr) | ||
757 | { | ||
758 | u16 w; | ||
759 | |||
760 | while (num_bytes--) { | ||
761 | if (!dev->buf_len) { | ||
762 | dev_err(dev->dev, "%s without data", | ||
763 | is_rdr ? "RDR" : "RRDY"); | ||
764 | break; | ||
765 | } | ||
766 | |||
767 | w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG); | ||
768 | *dev->buf++ = w; | ||
769 | dev->buf_len--; | ||
770 | |||
771 | /* | ||
772 | * Data reg in 2430, omap3 and | ||
773 | * omap4 is 8 bit wide | ||
774 | */ | ||
775 | if (dev->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) { | ||
776 | if (dev->buf_len) { | ||
777 | *dev->buf++ = w >> 8; | ||
778 | dev->buf_len--; | ||
779 | } | ||
780 | } | ||
781 | } | ||
782 | } | ||
783 | |||
784 | static int omap_i2c_transmit_data(struct omap_i2c_dev *dev, u8 num_bytes, | ||
785 | bool is_xdr) | ||
786 | { | ||
787 | u16 w; | ||
788 | |||
789 | while (num_bytes--) { | ||
790 | if (!dev->buf_len) { | ||
791 | dev_err(dev->dev, "%s without data", | ||
792 | is_xdr ? "XDR" : "XRDY"); | ||
793 | break; | ||
794 | } | ||
795 | |||
796 | w = *dev->buf++; | ||
797 | dev->buf_len--; | ||
798 | |||
799 | /* | ||
800 | * Data reg in 2430, omap3 and | ||
801 | * omap4 is 8 bit wide | ||
802 | */ | ||
803 | if (dev->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) { | ||
804 | if (dev->buf_len) { | ||
805 | w |= *dev->buf++ << 8; | ||
806 | dev->buf_len--; | ||
807 | } | ||
808 | } | ||
809 | |||
810 | if (dev->errata & I2C_OMAP_ERRATA_I462) { | ||
811 | int ret; | ||
812 | |||
813 | ret = errata_omap3_i462(dev); | ||
814 | if (ret < 0) | ||
815 | return ret; | ||
816 | } | ||
817 | |||
818 | omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); | ||
819 | } | ||
820 | |||
821 | return 0; | ||
822 | } | ||
823 | |||
755 | static irqreturn_t | 824 | static irqreturn_t |
756 | omap_i2c_isr(int this_irq, void *dev_id) | 825 | omap_i2c_isr(int this_irq, void *dev_id) |
757 | { | 826 | { |
758 | struct omap_i2c_dev *dev = dev_id; | 827 | struct omap_i2c_dev *dev = dev_id; |
759 | u16 bits; | 828 | u16 bits; |
760 | u16 stat, w; | 829 | u16 stat; |
761 | int err, count = 0; | 830 | int err, count = 0; |
762 | 831 | ||
763 | if (pm_runtime_suspended(dev->dev)) | 832 | if (pm_runtime_suspended(dev->dev)) |
@@ -810,30 +879,7 @@ complete: | |||
810 | if (dev->fifo_size) | 879 | if (dev->fifo_size) |
811 | num_bytes = dev->buf_len; | 880 | num_bytes = dev->buf_len; |
812 | 881 | ||
813 | while (num_bytes--) { | 882 | omap_i2c_receive_data(dev, num_bytes, true); |
814 | if (!dev->buf_len) { | ||
815 | dev_err(dev->dev, | ||
816 | "RDR IRQ while no data" | ||
817 | " requested\n"); | ||
818 | break; | ||
819 | } | ||
820 | |||
821 | w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG); | ||
822 | *dev->buf++ = w; | ||
823 | dev->buf_len--; | ||
824 | |||
825 | /* | ||
826 | * Data reg in 2430, omap3 and | ||
827 | * omap4 is 8 bit wide | ||
828 | */ | ||
829 | if (dev->flags & | ||
830 | OMAP_I2C_FLAG_16BIT_DATA_REG) { | ||
831 | if (dev->buf_len) { | ||
832 | *dev->buf++ = w >> 8; | ||
833 | dev->buf_len--; | ||
834 | } | ||
835 | } | ||
836 | } | ||
837 | 883 | ||
838 | if (dev->errata & I2C_OMAP_ERRATA_I207) | 884 | if (dev->errata & I2C_OMAP_ERRATA_I207) |
839 | i2c_omap_errata_i207(dev, stat); | 885 | i2c_omap_errata_i207(dev, stat); |
@@ -848,77 +894,22 @@ complete: | |||
848 | if (dev->fifo_size) | 894 | if (dev->fifo_size) |
849 | num_bytes = dev->fifo_size; | 895 | num_bytes = dev->fifo_size; |
850 | 896 | ||
851 | while (num_bytes--) { | 897 | omap_i2c_receive_data(dev, num_bytes, false); |
852 | if (!dev->buf_len) { | ||
853 | dev_err(dev->dev, | ||
854 | "RRDY IRQ while no data" | ||
855 | " requested\n"); | ||
856 | break; | ||
857 | } | ||
858 | |||
859 | w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG); | ||
860 | *dev->buf++ = w; | ||
861 | dev->buf_len--; | ||
862 | |||
863 | /* | ||
864 | * Data reg in 2430, omap3 and | ||
865 | * omap4 is 8 bit wide | ||
866 | */ | ||
867 | if (dev->flags & | ||
868 | OMAP_I2C_FLAG_16BIT_DATA_REG) { | ||
869 | if (dev->buf_len) { | ||
870 | *dev->buf++ = w >> 8; | ||
871 | dev->buf_len--; | ||
872 | } | ||
873 | } | ||
874 | } | ||
875 | |||
876 | omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RRDY); | 898 | omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RRDY); |
877 | continue; | 899 | continue; |
878 | } | 900 | } |
879 | 901 | ||
880 | if (stat & OMAP_I2C_STAT_XDR) { | 902 | if (stat & OMAP_I2C_STAT_XDR) { |
881 | u8 num_bytes = 1; | 903 | u8 num_bytes = 1; |
904 | int ret; | ||
882 | 905 | ||
883 | if (dev->fifo_size) | 906 | if (dev->fifo_size) |
884 | num_bytes = dev->buf_len; | 907 | num_bytes = dev->buf_len; |
885 | 908 | ||
886 | while (num_bytes--) { | 909 | ret = omap_i2c_transmit_data(dev, num_bytes, true); |
887 | if (!dev->buf_len) { | 910 | stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); |
888 | dev_err(dev->dev, | 911 | if (ret < 0) |
889 | "XDR IRQ while no " | 912 | goto complete; |
890 | "data to send\n"); | ||
891 | break; | ||
892 | } | ||
893 | |||
894 | w = *dev->buf++; | ||
895 | dev->buf_len--; | ||
896 | |||
897 | /* | ||
898 | * Data reg in 2430, omap3 and | ||
899 | * omap4 is 8 bit wide | ||
900 | */ | ||
901 | if (dev->flags & | ||
902 | OMAP_I2C_FLAG_16BIT_DATA_REG) { | ||
903 | if (dev->buf_len) { | ||
904 | w |= *dev->buf++ << 8; | ||
905 | dev->buf_len--; | ||
906 | } | ||
907 | } | ||
908 | |||
909 | if (dev->errata & I2C_OMAP_ERRATA_I462) { | ||
910 | int ret; | ||
911 | |||
912 | ret = errata_omap3_i462(dev); | ||
913 | stat = omap_i2c_read_reg(dev, | ||
914 | OMAP_I2C_STAT_REG); | ||
915 | |||
916 | if (ret < 0) | ||
917 | goto complete; | ||
918 | } | ||
919 | |||
920 | omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); | ||
921 | } | ||
922 | 913 | ||
923 | omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XDR); | 914 | omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XDR); |
924 | continue; | 915 | continue; |
@@ -926,46 +917,15 @@ complete: | |||
926 | 917 | ||
927 | if (stat & OMAP_I2C_STAT_XRDY) { | 918 | if (stat & OMAP_I2C_STAT_XRDY) { |
928 | u8 num_bytes = 1; | 919 | u8 num_bytes = 1; |
920 | int ret; | ||
929 | 921 | ||
930 | if (dev->fifo_size) | 922 | if (dev->fifo_size) |
931 | num_bytes = dev->fifo_size; | 923 | num_bytes = dev->fifo_size; |
932 | 924 | ||
933 | while (num_bytes--) { | 925 | ret = omap_i2c_transmit_data(dev, num_bytes, false); |
934 | if (!dev->buf_len) { | 926 | stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); |
935 | dev_err(dev->dev, | 927 | if (ret < 0) |
936 | "XRDY IRQ while no " | 928 | goto complete; |
937 | "data to send\n"); | ||
938 | break; | ||
939 | } | ||
940 | |||
941 | w = *dev->buf++; | ||
942 | dev->buf_len--; | ||
943 | |||
944 | /* | ||
945 | * Data reg in 2430, omap3 and | ||
946 | * omap4 is 8 bit wide | ||
947 | */ | ||
948 | if (dev->flags & | ||
949 | OMAP_I2C_FLAG_16BIT_DATA_REG) { | ||
950 | if (dev->buf_len) { | ||
951 | w |= *dev->buf++ << 8; | ||
952 | dev->buf_len--; | ||
953 | } | ||
954 | } | ||
955 | |||
956 | if (dev->errata & I2C_OMAP_ERRATA_I462) { | ||
957 | int ret; | ||
958 | |||
959 | ret = errata_omap3_i462(dev); | ||
960 | stat = omap_i2c_read_reg(dev, | ||
961 | OMAP_I2C_STAT_REG); | ||
962 | |||
963 | if (ret < 0) | ||
964 | goto complete; | ||
965 | } | ||
966 | |||
967 | omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); | ||
968 | } | ||
969 | 929 | ||
970 | omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XRDY); | 930 | omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XRDY); |
971 | continue; | 931 | continue; |