26 #include <linux/export.h>
63 if (radeon_connector->
router.ddc_valid)
153 static void post_xfer(
struct i2c_adapter *i2c_adap)
185 static int get_data(
void *i2c_priv)
199 static void set_clock(
void *i2c_priv,
int clock)
212 static void set_data(
void *i2c_priv,
int data)
249 nm = (sclk * 10) / (i2c_clock * 4);
250 for (loop = 1; loop < 255; loop++) {
251 if ((nm / loop) < loop)
256 prescale = m | (n << 8);
264 prescale = (((sclk * 10)/(4 * 128 * 100) + 1) << 8) + 128;
279 prescale = (127 << 8) + ((sclk * 10) / (4 * 127 * i2c_clock));
281 prescale = (((sclk * 10)/(4 * 128 * 100) + 1) << 8) + 128;
307 DRM_ERROR(
"i2c: unhandled radeon chip\n");
317 static int r100_hw_i2c_xfer(
struct i2c_adapter *i2c_adap,
333 prescale = radeon_get_i2c_prescale(rdev);
367 DRM_ERROR(
"gpio not supported with hw i2c\n");
382 DRM_ERROR(
"gpio not supported with hw i2c\n");
401 DRM_ERROR(
"gpio not supported with hw i2c\n");
417 DRM_ERROR(
"gpio not supported with hw i2c\n");
441 DRM_ERROR(
"gpio not supported with hw i2c\n");
447 DRM_ERROR(
"unsupported asic\n");
456 if ((num == 1) && (p->
len == 0)) {
468 for (k = 0; k < 32; k++) {
477 DRM_DEBUG(
"i2c write error 0x%08x\n", tmp);
486 for (i = 0; i < num; i++) {
488 for (j = 0; j < p->
len; j++) {
494 WREG32(i2c_data, ((p->
addr << 1) & 0xff) | 0x1);
500 for (k = 0; k < 32; k++) {
509 DRM_DEBUG(
"i2c read error 0x%08x\n", tmp);
528 for (k = 0; k < 32; k++) {
537 DRM_DEBUG(
"i2c write error 0x%08x\n", tmp);
570 static int r500_hw_i2c_xfer(
struct i2c_adapter *i2c_adap,
577 int i,
j, remaining, current_count, buffer_offset, ret = num;
586 prescale = radeon_get_i2c_prescale(rdev);
626 WREG32(0x494, saved2 | 0x1);
629 for (i = 0; i < 50; i++) {
635 DRM_ERROR(
"failed to get i2c bus\n");
652 DRM_ERROR(
"gpio not supported with hw i2c\n");
659 if ((num == 1) && (p->
len == 0)) {
676 for (j = 0; j < 200; j++) {
685 DRM_DEBUG(
"i2c write error 0x%08x\n", tmp);
694 for (i = 0; i < num; i++) {
703 current_count = remaining;
718 for (j = 0; j < 200; j++) {
727 DRM_DEBUG(
"i2c read error 0x%08x\n", tmp);
733 for (j = 0; j < current_count; j++)
735 remaining -= current_count;
736 buffer_offset += current_count;
743 current_count = remaining;
752 for (j = 0; j < current_count; j++)
761 for (j = 0; j < 200; j++) {
764 if (tmp & AVIVO_DC_I2C_GO)
770 DRM_DEBUG(
"i2c write error 0x%08x\n", tmp);
776 remaining -= current_count;
777 buffer_offset += current_count;
803 static int radeon_hw_i2c_xfer(
struct i2c_adapter *i2c_adap,
830 ret = r100_hw_i2c_xfer(i2c_adap, msgs, num);
844 ret = r100_hw_i2c_xfer(i2c_adap, msgs, num);
846 ret = r500_hw_i2c_xfer(i2c_adap, msgs, num);
872 DRM_ERROR(
"i2c: unhandled radeon chip\n");
886 .master_xfer = radeon_hw_i2c_xfer,
887 .functionality = radeon_hw_i2c_func,
914 i2c->
adapter.dev.parent = &dev->pdev->dev;
916 i2c_set_adapdata(&i2c->
adapter, i2c);
924 "Radeon i2c hw bus %s", name);
925 i2c->
adapter.algo = &radeon_i2c_algo;
928 DRM_ERROR(
"Failed to register hw i2c %s\n", name);
936 "Radeon i2c hw bus %s", name);
937 i2c->
adapter.algo = &radeon_atom_i2c_algo;
940 DRM_ERROR(
"Failed to register hw i2c %s\n", name);
946 "Radeon i2c bit bus %s", name);
948 i2c->
algo.
bit.pre_xfer = pre_xfer;
949 i2c->
algo.
bit.post_xfer = post_xfer;
950 i2c->
algo.
bit.setsda = set_data;
951 i2c->
algo.
bit.setscl = set_clock;
952 i2c->
algo.
bit.getsda = get_data;
959 DRM_ERROR(
"Failed to register bit i2c %s\n", name);
985 i2c->
adapter.dev.parent = &dev->pdev->dev;
988 "Radeon aux bus %s", name);
989 i2c_set_adapdata(&i2c->
adapter, i2c);
995 DRM_INFO(
"Failed to register i2c %s\n", name);
1099 DRM_DEBUG(
"val = 0x%02x\n", *val);
1101 DRM_DEBUG(
"i2c 0x%02x 0x%02x read failed\n",
1123 DRM_DEBUG(
"i2c 0x%02x 0x%02x write failed\n",
1132 if (!radeon_connector->
router.ddc_valid)
1139 radeon_connector->
router.i2c_addr,
1141 val &= ~radeon_connector->
router.ddc_mux_control_pin;
1143 radeon_connector->
router.i2c_addr,
1146 radeon_connector->
router.i2c_addr,
1148 val &= ~radeon_connector->
router.ddc_mux_control_pin;
1149 val |= radeon_connector->
router.ddc_mux_state;
1151 radeon_connector->
router.i2c_addr,
1160 if (!radeon_connector->
router.cd_valid)
1167 radeon_connector->
router.i2c_addr,
1169 val &= ~radeon_connector->
router.cd_mux_control_pin;
1171 radeon_connector->
router.i2c_addr,
1174 radeon_connector->
router.i2c_addr,
1176 val &= ~radeon_connector->
router.cd_mux_control_pin;
1177 val |= radeon_connector->
router.cd_mux_state;
1179 radeon_connector->
router.i2c_addr,