diff options
Diffstat (limited to 'drivers/gpu/drm/radeon/radeon_i2c.c')
-rw-r--r-- | drivers/gpu/drm/radeon/radeon_i2c.c | 153 |
1 files changed, 73 insertions, 80 deletions
diff --git a/drivers/gpu/drm/radeon/radeon_i2c.c b/drivers/gpu/drm/radeon/radeon_i2c.c index 4ae50c19589f..5def6f5dff38 100644 --- a/drivers/gpu/drm/radeon/radeon_i2c.c +++ b/drivers/gpu/drm/radeon/radeon_i2c.c | |||
@@ -59,6 +59,7 @@ bool radeon_ddc_probe(struct radeon_connector *radeon_connector) | |||
59 | return false; | 59 | return false; |
60 | } | 60 | } |
61 | 61 | ||
62 | /* bit banging i2c */ | ||
62 | 63 | ||
63 | static void radeon_i2c_do_lock(struct radeon_i2c_chan *i2c, int lock_state) | 64 | static void radeon_i2c_do_lock(struct radeon_i2c_chan *i2c, int lock_state) |
64 | { | 65 | { |
@@ -181,13 +182,30 @@ static void set_data(void *i2c_priv, int data) | |||
181 | WREG32(rec->en_data_reg, val); | 182 | WREG32(rec->en_data_reg, val); |
182 | } | 183 | } |
183 | 184 | ||
185 | static int pre_xfer(struct i2c_adapter *i2c_adap) | ||
186 | { | ||
187 | struct radeon_i2c_chan *i2c = i2c_get_adapdata(i2c_adap); | ||
188 | |||
189 | radeon_i2c_do_lock(i2c, 1); | ||
190 | |||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static void post_xfer(struct i2c_adapter *i2c_adap) | ||
195 | { | ||
196 | struct radeon_i2c_chan *i2c = i2c_get_adapdata(i2c_adap); | ||
197 | |||
198 | radeon_i2c_do_lock(i2c, 0); | ||
199 | } | ||
200 | |||
201 | /* hw i2c */ | ||
202 | |||
184 | static u32 radeon_get_i2c_prescale(struct radeon_device *rdev) | 203 | static u32 radeon_get_i2c_prescale(struct radeon_device *rdev) |
185 | { | 204 | { |
186 | struct radeon_pll *spll = &rdev->clock.spll; | ||
187 | u32 sclk = radeon_get_engine_clock(rdev); | 205 | u32 sclk = radeon_get_engine_clock(rdev); |
188 | u32 prescale = 0; | 206 | u32 prescale = 0; |
189 | u32 n, m; | 207 | u32 nm; |
190 | u8 loop; | 208 | u8 n, m, loop; |
191 | int i2c_clock; | 209 | int i2c_clock; |
192 | 210 | ||
193 | switch (rdev->family) { | 211 | switch (rdev->family) { |
@@ -203,13 +221,15 @@ static u32 radeon_get_i2c_prescale(struct radeon_device *rdev) | |||
203 | case CHIP_R300: | 221 | case CHIP_R300: |
204 | case CHIP_R350: | 222 | case CHIP_R350: |
205 | case CHIP_RV350: | 223 | case CHIP_RV350: |
206 | n = (spll->reference_freq) / (4 * 6); | 224 | i2c_clock = 60; |
225 | nm = (sclk * 10) / (i2c_clock * 4); | ||
207 | for (loop = 1; loop < 255; loop++) { | 226 | for (loop = 1; loop < 255; loop++) { |
208 | if ((loop * (loop - 1)) > n) | 227 | if ((nm / loop) < loop) |
209 | break; | 228 | break; |
210 | } | 229 | } |
211 | m = loop - 1; | 230 | n = loop - 1; |
212 | prescale = m | (loop << 8); | 231 | m = loop - 2; |
232 | prescale = m | (n << 8); | ||
213 | break; | 233 | break; |
214 | case CHIP_RV380: | 234 | case CHIP_RV380: |
215 | case CHIP_RS400: | 235 | case CHIP_RS400: |
@@ -217,7 +237,6 @@ static u32 radeon_get_i2c_prescale(struct radeon_device *rdev) | |||
217 | case CHIP_R420: | 237 | case CHIP_R420: |
218 | case CHIP_R423: | 238 | case CHIP_R423: |
219 | case CHIP_RV410: | 239 | case CHIP_RV410: |
220 | sclk = radeon_get_engine_clock(rdev); | ||
221 | prescale = (((sclk * 10)/(4 * 128 * 100) + 1) << 8) + 128; | 240 | prescale = (((sclk * 10)/(4 * 128 * 100) + 1) << 8) + 128; |
222 | break; | 241 | break; |
223 | case CHIP_RS600: | 242 | case CHIP_RS600: |
@@ -232,7 +251,6 @@ static u32 radeon_get_i2c_prescale(struct radeon_device *rdev) | |||
232 | case CHIP_RV570: | 251 | case CHIP_RV570: |
233 | case CHIP_R580: | 252 | case CHIP_R580: |
234 | i2c_clock = 50; | 253 | i2c_clock = 50; |
235 | sclk = radeon_get_engine_clock(rdev); | ||
236 | if (rdev->family == CHIP_R520) | 254 | if (rdev->family == CHIP_R520) |
237 | prescale = (127 << 8) + ((sclk * 10) / (4 * 127 * i2c_clock)); | 255 | prescale = (127 << 8) + ((sclk * 10) / (4 * 127 * i2c_clock)); |
238 | else | 256 | else |
@@ -291,6 +309,7 @@ static int r100_hw_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
291 | prescale = radeon_get_i2c_prescale(rdev); | 309 | prescale = radeon_get_i2c_prescale(rdev); |
292 | 310 | ||
293 | reg = ((prescale << RADEON_I2C_PRESCALE_SHIFT) | | 311 | reg = ((prescale << RADEON_I2C_PRESCALE_SHIFT) | |
312 | RADEON_I2C_DRIVE_EN | | ||
294 | RADEON_I2C_START | | 313 | RADEON_I2C_START | |
295 | RADEON_I2C_STOP | | 314 | RADEON_I2C_STOP | |
296 | RADEON_I2C_GO); | 315 | RADEON_I2C_GO); |
@@ -757,26 +776,13 @@ done: | |||
757 | return ret; | 776 | return ret; |
758 | } | 777 | } |
759 | 778 | ||
760 | static int radeon_sw_i2c_xfer(struct i2c_adapter *i2c_adap, | 779 | static int radeon_hw_i2c_xfer(struct i2c_adapter *i2c_adap, |
761 | struct i2c_msg *msgs, int num) | 780 | struct i2c_msg *msgs, int num) |
762 | { | 781 | { |
763 | struct radeon_i2c_chan *i2c = i2c_get_adapdata(i2c_adap); | 782 | struct radeon_i2c_chan *i2c = i2c_get_adapdata(i2c_adap); |
764 | int ret; | ||
765 | |||
766 | radeon_i2c_do_lock(i2c, 1); | ||
767 | ret = i2c_transfer(&i2c->algo.radeon.bit_adapter, msgs, num); | ||
768 | radeon_i2c_do_lock(i2c, 0); | ||
769 | |||
770 | return ret; | ||
771 | } | ||
772 | |||
773 | static int radeon_i2c_xfer(struct i2c_adapter *i2c_adap, | ||
774 | struct i2c_msg *msgs, int num) | ||
775 | { | ||
776 | struct radeon_i2c_chan *i2c = i2c_get_adapdata(i2c_adap); | ||
777 | struct radeon_device *rdev = i2c->dev->dev_private; | 783 | struct radeon_device *rdev = i2c->dev->dev_private; |
778 | struct radeon_i2c_bus_rec *rec = &i2c->rec; | 784 | struct radeon_i2c_bus_rec *rec = &i2c->rec; |
779 | int ret; | 785 | int ret = 0; |
780 | 786 | ||
781 | switch (rdev->family) { | 787 | switch (rdev->family) { |
782 | case CHIP_R100: | 788 | case CHIP_R100: |
@@ -797,16 +803,12 @@ static int radeon_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
797 | case CHIP_RV410: | 803 | case CHIP_RV410: |
798 | case CHIP_RS400: | 804 | case CHIP_RS400: |
799 | case CHIP_RS480: | 805 | case CHIP_RS480: |
800 | if (rec->hw_capable) | 806 | ret = r100_hw_i2c_xfer(i2c_adap, msgs, num); |
801 | ret = r100_hw_i2c_xfer(i2c_adap, msgs, num); | ||
802 | else | ||
803 | ret = radeon_sw_i2c_xfer(i2c_adap, msgs, num); | ||
804 | break; | 807 | break; |
805 | case CHIP_RS600: | 808 | case CHIP_RS600: |
806 | case CHIP_RS690: | 809 | case CHIP_RS690: |
807 | case CHIP_RS740: | 810 | case CHIP_RS740: |
808 | /* XXX fill in hw i2c implementation */ | 811 | /* XXX fill in hw i2c implementation */ |
809 | ret = radeon_sw_i2c_xfer(i2c_adap, msgs, num); | ||
810 | break; | 812 | break; |
811 | case CHIP_RV515: | 813 | case CHIP_RV515: |
812 | case CHIP_R520: | 814 | case CHIP_R520: |
@@ -814,20 +816,16 @@ static int radeon_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
814 | case CHIP_RV560: | 816 | case CHIP_RV560: |
815 | case CHIP_RV570: | 817 | case CHIP_RV570: |
816 | case CHIP_R580: | 818 | case CHIP_R580: |
817 | if (rec->hw_capable) { | 819 | if (rec->mm_i2c) |
818 | if (rec->mm_i2c) | 820 | ret = r100_hw_i2c_xfer(i2c_adap, msgs, num); |
819 | ret = r100_hw_i2c_xfer(i2c_adap, msgs, num); | 821 | else |
820 | else | 822 | ret = r500_hw_i2c_xfer(i2c_adap, msgs, num); |
821 | ret = r500_hw_i2c_xfer(i2c_adap, msgs, num); | ||
822 | } else | ||
823 | ret = radeon_sw_i2c_xfer(i2c_adap, msgs, num); | ||
824 | break; | 823 | break; |
825 | case CHIP_R600: | 824 | case CHIP_R600: |
826 | case CHIP_RV610: | 825 | case CHIP_RV610: |
827 | case CHIP_RV630: | 826 | case CHIP_RV630: |
828 | case CHIP_RV670: | 827 | case CHIP_RV670: |
829 | /* XXX fill in hw i2c implementation */ | 828 | /* XXX fill in hw i2c implementation */ |
830 | ret = radeon_sw_i2c_xfer(i2c_adap, msgs, num); | ||
831 | break; | 829 | break; |
832 | case CHIP_RV620: | 830 | case CHIP_RV620: |
833 | case CHIP_RV635: | 831 | case CHIP_RV635: |
@@ -838,7 +836,6 @@ static int radeon_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
838 | case CHIP_RV710: | 836 | case CHIP_RV710: |
839 | case CHIP_RV740: | 837 | case CHIP_RV740: |
840 | /* XXX fill in hw i2c implementation */ | 838 | /* XXX fill in hw i2c implementation */ |
841 | ret = radeon_sw_i2c_xfer(i2c_adap, msgs, num); | ||
842 | break; | 839 | break; |
843 | case CHIP_CEDAR: | 840 | case CHIP_CEDAR: |
844 | case CHIP_REDWOOD: | 841 | case CHIP_REDWOOD: |
@@ -846,7 +843,6 @@ static int radeon_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
846 | case CHIP_CYPRESS: | 843 | case CHIP_CYPRESS: |
847 | case CHIP_HEMLOCK: | 844 | case CHIP_HEMLOCK: |
848 | /* XXX fill in hw i2c implementation */ | 845 | /* XXX fill in hw i2c implementation */ |
849 | ret = radeon_sw_i2c_xfer(i2c_adap, msgs, num); | ||
850 | break; | 846 | break; |
851 | default: | 847 | default: |
852 | DRM_ERROR("i2c: unhandled radeon chip\n"); | 848 | DRM_ERROR("i2c: unhandled radeon chip\n"); |
@@ -857,20 +853,21 @@ static int radeon_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
857 | return ret; | 853 | return ret; |
858 | } | 854 | } |
859 | 855 | ||
860 | static u32 radeon_i2c_func(struct i2c_adapter *adap) | 856 | static u32 radeon_hw_i2c_func(struct i2c_adapter *adap) |
861 | { | 857 | { |
862 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; | 858 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; |
863 | } | 859 | } |
864 | 860 | ||
865 | static const struct i2c_algorithm radeon_i2c_algo = { | 861 | static const struct i2c_algorithm radeon_i2c_algo = { |
866 | .master_xfer = radeon_i2c_xfer, | 862 | .master_xfer = radeon_hw_i2c_xfer, |
867 | .functionality = radeon_i2c_func, | 863 | .functionality = radeon_hw_i2c_func, |
868 | }; | 864 | }; |
869 | 865 | ||
870 | struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev, | 866 | struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev, |
871 | struct radeon_i2c_bus_rec *rec, | 867 | struct radeon_i2c_bus_rec *rec, |
872 | const char *name) | 868 | const char *name) |
873 | { | 869 | { |
870 | struct radeon_device *rdev = dev->dev_private; | ||
874 | struct radeon_i2c_chan *i2c; | 871 | struct radeon_i2c_chan *i2c; |
875 | int ret; | 872 | int ret; |
876 | 873 | ||
@@ -878,37 +875,43 @@ struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev, | |||
878 | if (i2c == NULL) | 875 | if (i2c == NULL) |
879 | return NULL; | 876 | return NULL; |
880 | 877 | ||
881 | /* set the internal bit adapter */ | ||
882 | i2c->algo.radeon.bit_adapter.owner = THIS_MODULE; | ||
883 | i2c_set_adapdata(&i2c->algo.radeon.bit_adapter, i2c); | ||
884 | sprintf(i2c->algo.radeon.bit_adapter.name, "Radeon internal i2c bit bus %s", name); | ||
885 | i2c->algo.radeon.bit_adapter.algo_data = &i2c->algo.radeon.bit_data; | ||
886 | i2c->algo.radeon.bit_data.setsda = set_data; | ||
887 | i2c->algo.radeon.bit_data.setscl = set_clock; | ||
888 | i2c->algo.radeon.bit_data.getsda = get_data; | ||
889 | i2c->algo.radeon.bit_data.getscl = get_clock; | ||
890 | i2c->algo.radeon.bit_data.udelay = 20; | ||
891 | /* vesa says 2.2 ms is enough, 1 jiffy doesn't seem to always | ||
892 | * make this, 2 jiffies is a lot more reliable */ | ||
893 | i2c->algo.radeon.bit_data.timeout = 2; | ||
894 | i2c->algo.radeon.bit_data.data = i2c; | ||
895 | ret = i2c_bit_add_bus(&i2c->algo.radeon.bit_adapter); | ||
896 | if (ret) { | ||
897 | DRM_ERROR("Failed to register internal bit i2c %s\n", name); | ||
898 | goto out_free; | ||
899 | } | ||
900 | /* set the radeon i2c adapter */ | ||
901 | i2c->dev = dev; | ||
902 | i2c->rec = *rec; | 878 | i2c->rec = *rec; |
903 | i2c->adapter.owner = THIS_MODULE; | 879 | i2c->adapter.owner = THIS_MODULE; |
880 | i2c->dev = dev; | ||
904 | i2c_set_adapdata(&i2c->adapter, i2c); | 881 | i2c_set_adapdata(&i2c->adapter, i2c); |
905 | sprintf(i2c->adapter.name, "Radeon i2c %s", name); | 882 | if (rec->mm_i2c || |
906 | i2c->adapter.algo_data = &i2c->algo.radeon; | 883 | (rec->hw_capable && |
907 | i2c->adapter.algo = &radeon_i2c_algo; | 884 | radeon_hw_i2c && |
908 | ret = i2c_add_adapter(&i2c->adapter); | 885 | ((rdev->family <= CHIP_RS480) || |
909 | if (ret) { | 886 | ((rdev->family >= CHIP_RV515) && (rdev->family <= CHIP_R580))))) { |
910 | DRM_ERROR("Failed to register i2c %s\n", name); | 887 | /* set the radeon hw i2c adapter */ |
911 | goto out_free; | 888 | sprintf(i2c->adapter.name, "Radeon i2c hw bus %s", name); |
889 | i2c->adapter.algo = &radeon_i2c_algo; | ||
890 | ret = i2c_add_adapter(&i2c->adapter); | ||
891 | if (ret) { | ||
892 | DRM_ERROR("Failed to register hw i2c %s\n", name); | ||
893 | goto out_free; | ||
894 | } | ||
895 | } else { | ||
896 | /* set the radeon bit adapter */ | ||
897 | sprintf(i2c->adapter.name, "Radeon i2c bit bus %s", name); | ||
898 | i2c->adapter.algo_data = &i2c->algo.bit; | ||
899 | i2c->algo.bit.pre_xfer = pre_xfer; | ||
900 | i2c->algo.bit.post_xfer = post_xfer; | ||
901 | i2c->algo.bit.setsda = set_data; | ||
902 | i2c->algo.bit.setscl = set_clock; | ||
903 | i2c->algo.bit.getsda = get_data; | ||
904 | i2c->algo.bit.getscl = get_clock; | ||
905 | i2c->algo.bit.udelay = 20; | ||
906 | /* vesa says 2.2 ms is enough, 1 jiffy doesn't seem to always | ||
907 | * make this, 2 jiffies is a lot more reliable */ | ||
908 | i2c->algo.bit.timeout = 2; | ||
909 | i2c->algo.bit.data = i2c; | ||
910 | ret = i2c_bit_add_bus(&i2c->adapter); | ||
911 | if (ret) { | ||
912 | DRM_ERROR("Failed to register bit i2c %s\n", name); | ||
913 | goto out_free; | ||
914 | } | ||
912 | } | 915 | } |
913 | 916 | ||
914 | return i2c; | 917 | return i2c; |
@@ -953,16 +956,6 @@ void radeon_i2c_destroy(struct radeon_i2c_chan *i2c) | |||
953 | { | 956 | { |
954 | if (!i2c) | 957 | if (!i2c) |
955 | return; | 958 | return; |
956 | i2c_del_adapter(&i2c->algo.radeon.bit_adapter); | ||
957 | i2c_del_adapter(&i2c->adapter); | ||
958 | kfree(i2c); | ||
959 | } | ||
960 | |||
961 | void radeon_i2c_destroy_dp(struct radeon_i2c_chan *i2c) | ||
962 | { | ||
963 | if (!i2c) | ||
964 | return; | ||
965 | |||
966 | i2c_del_adapter(&i2c->adapter); | 959 | i2c_del_adapter(&i2c->adapter); |
967 | kfree(i2c); | 960 | kfree(i2c); |
968 | } | 961 | } |