2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
23 * Authors: Dave Airlie
27 #include "radeon_drm.h"
35 bool radeon_ddc_probe(struct radeon_connector
*radeon_connector
)
37 u8 out_buf
[] = { 0x0, 0x0};
40 struct i2c_msg msgs
[] = {
55 ret
= i2c_transfer(&radeon_connector
->ddc_bus
->adapter
, msgs
, 2);
63 static void radeon_i2c_do_lock(struct radeon_i2c_chan
*i2c
, int lock_state
)
65 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
66 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
69 /* RV410 appears to have a bug where the hw i2c in reset
70 * holds the i2c port in a bad state - switch hw i2c away before
71 * doing DDC - do this for all r200s/r300s/r400s for safety sake
73 if (rec
->hw_capable
) {
74 if ((rdev
->family
>= CHIP_R200
) && !ASIC_IS_AVIVO(rdev
)) {
77 if (rdev
->family
>= CHIP_RV350
)
78 reg
= RADEON_GPIO_MONID
;
79 else if ((rdev
->family
== CHIP_R300
) ||
80 (rdev
->family
== CHIP_R350
))
81 reg
= RADEON_GPIO_DVI_DDC
;
83 reg
= RADEON_GPIO_CRT2_DDC
;
85 mutex_lock(&rdev
->dc_hw_i2c_mutex
);
86 if (rec
->a_clk_reg
== reg
) {
87 WREG32(RADEON_DVI_I2C_CNTL_0
, (RADEON_I2C_SOFT_RST
|
88 R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
)));
90 WREG32(RADEON_DVI_I2C_CNTL_0
, (RADEON_I2C_SOFT_RST
|
91 R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
)));
93 mutex_unlock(&rdev
->dc_hw_i2c_mutex
);
97 /* clear the output pin values */
98 temp
= RREG32(rec
->a_clk_reg
) & ~rec
->a_clk_mask
;
99 WREG32(rec
->a_clk_reg
, temp
);
101 temp
= RREG32(rec
->a_data_reg
) & ~rec
->a_data_mask
;
102 WREG32(rec
->a_data_reg
, temp
);
104 /* set the pins to input */
105 temp
= RREG32(rec
->en_clk_reg
) & ~rec
->en_clk_mask
;
106 WREG32(rec
->en_clk_reg
, temp
);
108 temp
= RREG32(rec
->en_data_reg
) & ~rec
->en_data_mask
;
109 WREG32(rec
->en_data_reg
, temp
);
111 /* mask the gpio pins for software use */
112 temp
= RREG32(rec
->mask_clk_reg
);
114 temp
|= rec
->mask_clk_mask
;
116 temp
&= ~rec
->mask_clk_mask
;
117 WREG32(rec
->mask_clk_reg
, temp
);
118 temp
= RREG32(rec
->mask_clk_reg
);
120 temp
= RREG32(rec
->mask_data_reg
);
122 temp
|= rec
->mask_data_mask
;
124 temp
&= ~rec
->mask_data_mask
;
125 WREG32(rec
->mask_data_reg
, temp
);
126 temp
= RREG32(rec
->mask_data_reg
);
129 static int get_clock(void *i2c_priv
)
131 struct radeon_i2c_chan
*i2c
= i2c_priv
;
132 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
133 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
136 /* read the value off the pin */
137 val
= RREG32(rec
->y_clk_reg
);
138 val
&= rec
->y_clk_mask
;
144 static int get_data(void *i2c_priv
)
146 struct radeon_i2c_chan
*i2c
= i2c_priv
;
147 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
148 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
151 /* read the value off the pin */
152 val
= RREG32(rec
->y_data_reg
);
153 val
&= rec
->y_data_mask
;
158 static void set_clock(void *i2c_priv
, int clock
)
160 struct radeon_i2c_chan
*i2c
= i2c_priv
;
161 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
162 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
165 /* set pin direction */
166 val
= RREG32(rec
->en_clk_reg
) & ~rec
->en_clk_mask
;
167 val
|= clock
? 0 : rec
->en_clk_mask
;
168 WREG32(rec
->en_clk_reg
, val
);
171 static void set_data(void *i2c_priv
, int data
)
173 struct radeon_i2c_chan
*i2c
= i2c_priv
;
174 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
175 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
178 /* set pin direction */
179 val
= RREG32(rec
->en_data_reg
) & ~rec
->en_data_mask
;
180 val
|= data
? 0 : rec
->en_data_mask
;
181 WREG32(rec
->en_data_reg
, val
);
184 /* hw i2c engine for r1xx-4xx hardware
185 * hw can buffer up to 15 bytes
187 static int r100_hw_i2c_xfer(struct i2c_adapter
*i2c_adap
,
188 struct i2c_msg
*msgs
, int num
)
190 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
191 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
192 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
194 int i
, j
, k
, ret
= num
;
196 u32 i2c_cntl_0
, i2c_cntl_1
, i2c_data
;
199 mutex_lock(&rdev
->dc_hw_i2c_mutex
);
200 /* take the pm lock since we need a constant sclk */
201 mutex_lock(&rdev
->pm
.mutex
);
203 sclk
= radeon_get_engine_clock(rdev
);
204 prescale
= (((sclk
* 10)/(4 * 128 * 100) + 1) << 8) + 128;
206 reg
= ((prescale
<< RADEON_I2C_PRESCALE_SHIFT
) |
211 if (rdev
->is_atom_bios
) {
212 tmp
= RREG32(RADEON_BIOS_6_SCRATCH
);
213 WREG32(RADEON_BIOS_6_SCRATCH
, tmp
| ATOM_S6_HW_I2C_BUSY_STATE
);
217 i2c_cntl_0
= RADEON_I2C_CNTL_0
;
218 i2c_cntl_1
= RADEON_I2C_CNTL_1
;
219 i2c_data
= RADEON_I2C_DATA
;
221 i2c_cntl_0
= RADEON_DVI_I2C_CNTL_0
;
222 i2c_cntl_1
= RADEON_DVI_I2C_CNTL_1
;
223 i2c_data
= RADEON_DVI_I2C_DATA
;
225 switch (rdev
->family
) {
232 switch (rec
->mask_clk_reg
) {
233 case RADEON_GPIO_DVI_DDC
:
234 /* no gpio select bit */
237 DRM_ERROR("gpio not supported with hw i2c\n");
243 /* only bit 4 on r200 */
244 switch (rec
->mask_clk_reg
) {
245 case RADEON_GPIO_DVI_DDC
:
246 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
);
248 case RADEON_GPIO_MONID
:
249 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
);
252 DRM_ERROR("gpio not supported with hw i2c\n");
260 switch (rec
->mask_clk_reg
) {
261 case RADEON_GPIO_DVI_DDC
:
262 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
);
264 case RADEON_GPIO_VGA_DDC
:
265 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC2
);
267 case RADEON_GPIO_CRT2_DDC
:
268 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
);
271 DRM_ERROR("gpio not supported with hw i2c\n");
278 /* only bit 4 on r300/r350 */
279 switch (rec
->mask_clk_reg
) {
280 case RADEON_GPIO_VGA_DDC
:
281 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
);
283 case RADEON_GPIO_DVI_DDC
:
284 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
);
287 DRM_ERROR("gpio not supported with hw i2c\n");
300 switch (rec
->mask_clk_reg
) {
301 case RADEON_GPIO_VGA_DDC
:
302 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
);
304 case RADEON_GPIO_DVI_DDC
:
305 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC2
);
307 case RADEON_GPIO_MONID
:
308 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
);
311 DRM_ERROR("gpio not supported with hw i2c\n");
317 DRM_ERROR("unsupported asic\n");
324 /* check for bus probe */
326 if ((num
== 1) && (p
->len
== 0)) {
327 WREG32(i2c_cntl_0
, (RADEON_I2C_DONE
|
330 RADEON_I2C_SOFT_RST
));
331 WREG32(i2c_data
, (p
->addr
<< 1) & 0xff);
333 WREG32(i2c_cntl_1
, ((1 << RADEON_I2C_DATA_COUNT_SHIFT
) |
334 (1 << RADEON_I2C_ADDR_COUNT_SHIFT
) |
336 (48 << RADEON_I2C_TIME_LIMIT_SHIFT
)));
337 WREG32(i2c_cntl_0
, reg
);
338 for (k
= 0; k
< 32; k
++) {
340 tmp
= RREG32(i2c_cntl_0
);
341 if (tmp
& RADEON_I2C_GO
)
343 tmp
= RREG32(i2c_cntl_0
);
344 if (tmp
& RADEON_I2C_DONE
)
347 DRM_DEBUG("i2c write error 0x%08x\n", tmp
);
348 WREG32(i2c_cntl_0
, tmp
| RADEON_I2C_ABORT
);
356 for (i
= 0; i
< num
; i
++) {
358 for (j
= 0; j
< p
->len
; j
++) {
359 if (p
->flags
& I2C_M_RD
) {
360 WREG32(i2c_cntl_0
, (RADEON_I2C_DONE
|
363 RADEON_I2C_SOFT_RST
));
364 WREG32(i2c_data
, ((p
->addr
<< 1) & 0xff) | 0x1);
365 WREG32(i2c_cntl_1
, ((1 << RADEON_I2C_DATA_COUNT_SHIFT
) |
366 (1 << RADEON_I2C_ADDR_COUNT_SHIFT
) |
368 (48 << RADEON_I2C_TIME_LIMIT_SHIFT
)));
369 WREG32(i2c_cntl_0
, reg
| RADEON_I2C_RECEIVE
);
370 for (k
= 0; k
< 32; k
++) {
372 tmp
= RREG32(i2c_cntl_0
);
373 if (tmp
& RADEON_I2C_GO
)
375 tmp
= RREG32(i2c_cntl_0
);
376 if (tmp
& RADEON_I2C_DONE
)
379 DRM_DEBUG("i2c read error 0x%08x\n", tmp
);
380 WREG32(i2c_cntl_0
, tmp
| RADEON_I2C_ABORT
);
385 p
->buf
[j
] = RREG32(i2c_data
) & 0xff;
387 WREG32(i2c_cntl_0
, (RADEON_I2C_DONE
|
390 RADEON_I2C_SOFT_RST
));
391 WREG32(i2c_data
, (p
->addr
<< 1) & 0xff);
392 WREG32(i2c_data
, p
->buf
[j
]);
393 WREG32(i2c_cntl_1
, ((1 << RADEON_I2C_DATA_COUNT_SHIFT
) |
394 (1 << RADEON_I2C_ADDR_COUNT_SHIFT
) |
396 (48 << RADEON_I2C_TIME_LIMIT_SHIFT
)));
397 WREG32(i2c_cntl_0
, reg
);
398 for (k
= 0; k
< 32; k
++) {
400 tmp
= RREG32(i2c_cntl_0
);
401 if (tmp
& RADEON_I2C_GO
)
403 tmp
= RREG32(i2c_cntl_0
);
404 if (tmp
& RADEON_I2C_DONE
)
407 DRM_DEBUG("i2c write error 0x%08x\n", tmp
);
408 WREG32(i2c_cntl_0
, tmp
| RADEON_I2C_ABORT
);
418 WREG32(i2c_cntl_0
, 0);
419 WREG32(i2c_cntl_1
, 0);
420 WREG32(i2c_cntl_0
, (RADEON_I2C_DONE
|
423 RADEON_I2C_SOFT_RST
));
425 if (rdev
->is_atom_bios
) {
426 tmp
= RREG32(RADEON_BIOS_6_SCRATCH
);
427 tmp
&= ~ATOM_S6_HW_I2C_BUSY_STATE
;
428 WREG32(RADEON_BIOS_6_SCRATCH
, tmp
);
431 mutex_unlock(&rdev
->pm
.mutex
);
432 mutex_unlock(&rdev
->dc_hw_i2c_mutex
);
437 /* hw i2c engine for r5xx hardware
438 * hw can buffer up to 15 bytes
440 static int r500_hw_i2c_xfer(struct i2c_adapter
*i2c_adap
,
441 struct i2c_msg
*msgs
, int num
)
443 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
444 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
445 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
448 int i
, j
, remaining
, current_count
, buffer_offset
, ret
= num
;
453 mutex_lock(&rdev
->dc_hw_i2c_mutex
);
454 /* take the pm lock since we need a constant sclk */
455 mutex_lock(&rdev
->pm
.mutex
);
457 sclk
= radeon_get_engine_clock(rdev
);
458 if (rdev
->family
== CHIP_R520
)
459 prescale
= (127 << 8) + ((sclk
* 10) / (4 * 127 * i2c_clock
));
461 prescale
= (((sclk
* 10)/(4 * 128 * 100) + 1) << 8) + 128;
463 /* clear gpio mask bits */
464 tmp
= RREG32(rec
->mask_clk_reg
);
465 tmp
&= ~rec
->mask_clk_mask
;
466 WREG32(rec
->mask_clk_reg
, tmp
);
467 tmp
= RREG32(rec
->mask_clk_reg
);
469 tmp
= RREG32(rec
->mask_data_reg
);
470 tmp
&= ~rec
->mask_data_mask
;
471 WREG32(rec
->mask_data_reg
, tmp
);
472 tmp
= RREG32(rec
->mask_data_reg
);
474 /* clear pin values */
475 tmp
= RREG32(rec
->a_clk_reg
);
476 tmp
&= ~rec
->a_clk_mask
;
477 WREG32(rec
->a_clk_reg
, tmp
);
478 tmp
= RREG32(rec
->a_clk_reg
);
480 tmp
= RREG32(rec
->a_data_reg
);
481 tmp
&= ~rec
->a_data_mask
;
482 WREG32(rec
->a_data_reg
, tmp
);
483 tmp
= RREG32(rec
->a_data_reg
);
485 /* set the pins to input */
486 tmp
= RREG32(rec
->en_clk_reg
);
487 tmp
&= ~rec
->en_clk_mask
;
488 WREG32(rec
->en_clk_reg
, tmp
);
489 tmp
= RREG32(rec
->en_clk_reg
);
491 tmp
= RREG32(rec
->en_data_reg
);
492 tmp
&= ~rec
->en_data_mask
;
493 WREG32(rec
->en_data_reg
, tmp
);
494 tmp
= RREG32(rec
->en_data_reg
);
497 tmp
= RREG32(RADEON_BIOS_6_SCRATCH
);
498 WREG32(RADEON_BIOS_6_SCRATCH
, tmp
| ATOM_S6_HW_I2C_BUSY_STATE
);
499 saved1
= RREG32(AVIVO_DC_I2C_CONTROL1
);
500 saved2
= RREG32(0x494);
501 WREG32(0x494, saved2
| 0x1);
503 WREG32(AVIVO_DC_I2C_ARBITRATION
, AVIVO_DC_I2C_SW_WANTS_TO_USE_I2C
);
504 for (i
= 0; i
< 50; i
++) {
506 if (RREG32(AVIVO_DC_I2C_ARBITRATION
) & AVIVO_DC_I2C_SW_CAN_USE_I2C
)
510 DRM_ERROR("failed to get i2c bus\n");
515 reg
= AVIVO_DC_I2C_START
| AVIVO_DC_I2C_STOP
| AVIVO_DC_I2C_EN
;
516 switch (rec
->mask_clk_reg
) {
517 case AVIVO_DC_GPIO_DDC1_MASK
:
518 reg
|= AVIVO_DC_I2C_PIN_SELECT(AVIVO_SEL_DDC1
);
520 case AVIVO_DC_GPIO_DDC2_MASK
:
521 reg
|= AVIVO_DC_I2C_PIN_SELECT(AVIVO_SEL_DDC2
);
523 case AVIVO_DC_GPIO_DDC3_MASK
:
524 reg
|= AVIVO_DC_I2C_PIN_SELECT(AVIVO_SEL_DDC3
);
527 DRM_ERROR("gpio not supported with hw i2c\n");
532 /* check for bus probe */
534 if ((num
== 1) && (p
->len
== 0)) {
535 WREG32(AVIVO_DC_I2C_STATUS1
, (AVIVO_DC_I2C_DONE
|
538 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_SOFT_RESET
);
540 WREG32(AVIVO_DC_I2C_RESET
, 0);
542 WREG32(AVIVO_DC_I2C_DATA
, (p
->addr
<< 1) & 0xff);
543 WREG32(AVIVO_DC_I2C_DATA
, 0);
545 WREG32(AVIVO_DC_I2C_CONTROL3
, AVIVO_DC_I2C_TIME_LIMIT(48));
546 WREG32(AVIVO_DC_I2C_CONTROL2
, (AVIVO_DC_I2C_ADDR_COUNT(1) |
547 AVIVO_DC_I2C_DATA_COUNT(1) |
549 WREG32(AVIVO_DC_I2C_CONTROL1
, reg
);
550 WREG32(AVIVO_DC_I2C_STATUS1
, AVIVO_DC_I2C_GO
);
551 for (j
= 0; j
< 200; j
++) {
553 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
554 if (tmp
& AVIVO_DC_I2C_GO
)
556 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
557 if (tmp
& AVIVO_DC_I2C_DONE
)
560 DRM_DEBUG("i2c write error 0x%08x\n", tmp
);
561 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_ABORT
);
569 for (i
= 0; i
< num
; i
++) {
573 if (p
->flags
& I2C_M_RD
) {
578 current_count
= remaining
;
579 WREG32(AVIVO_DC_I2C_STATUS1
, (AVIVO_DC_I2C_DONE
|
582 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_SOFT_RESET
);
584 WREG32(AVIVO_DC_I2C_RESET
, 0);
586 WREG32(AVIVO_DC_I2C_DATA
, ((p
->addr
<< 1) & 0xff) | 0x1);
587 WREG32(AVIVO_DC_I2C_CONTROL3
, AVIVO_DC_I2C_TIME_LIMIT(48));
588 WREG32(AVIVO_DC_I2C_CONTROL2
, (AVIVO_DC_I2C_ADDR_COUNT(1) |
589 AVIVO_DC_I2C_DATA_COUNT(current_count
) |
591 WREG32(AVIVO_DC_I2C_CONTROL1
, reg
| AVIVO_DC_I2C_RECEIVE
);
592 WREG32(AVIVO_DC_I2C_STATUS1
, AVIVO_DC_I2C_GO
);
593 for (j
= 0; j
< 200; j
++) {
595 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
596 if (tmp
& AVIVO_DC_I2C_GO
)
598 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
599 if (tmp
& AVIVO_DC_I2C_DONE
)
602 DRM_DEBUG("i2c read error 0x%08x\n", tmp
);
603 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_ABORT
);
608 for (j
= 0; j
< current_count
; j
++)
609 p
->buf
[buffer_offset
+ j
] = RREG32(AVIVO_DC_I2C_DATA
) & 0xff;
610 remaining
-= current_count
;
611 buffer_offset
+= current_count
;
618 current_count
= remaining
;
619 WREG32(AVIVO_DC_I2C_STATUS1
, (AVIVO_DC_I2C_DONE
|
622 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_SOFT_RESET
);
624 WREG32(AVIVO_DC_I2C_RESET
, 0);
626 WREG32(AVIVO_DC_I2C_DATA
, (p
->addr
<< 1) & 0xff);
627 for (j
= 0; j
< current_count
; j
++)
628 WREG32(AVIVO_DC_I2C_DATA
, p
->buf
[buffer_offset
+ j
]);
630 WREG32(AVIVO_DC_I2C_CONTROL3
, AVIVO_DC_I2C_TIME_LIMIT(48));
631 WREG32(AVIVO_DC_I2C_CONTROL2
, (AVIVO_DC_I2C_ADDR_COUNT(1) |
632 AVIVO_DC_I2C_DATA_COUNT(current_count
) |
634 WREG32(AVIVO_DC_I2C_CONTROL1
, reg
);
635 WREG32(AVIVO_DC_I2C_STATUS1
, AVIVO_DC_I2C_GO
);
636 for (j
= 0; j
< 200; j
++) {
638 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
639 if (tmp
& AVIVO_DC_I2C_GO
)
641 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
642 if (tmp
& AVIVO_DC_I2C_DONE
)
645 DRM_DEBUG("i2c write error 0x%08x\n", tmp
);
646 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_ABORT
);
651 remaining
-= current_count
;
652 buffer_offset
+= current_count
;
658 WREG32(AVIVO_DC_I2C_STATUS1
, (AVIVO_DC_I2C_DONE
|
661 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_SOFT_RESET
);
663 WREG32(AVIVO_DC_I2C_RESET
, 0);
665 WREG32(AVIVO_DC_I2C_ARBITRATION
, AVIVO_DC_I2C_SW_DONE_USING_I2C
);
666 WREG32(AVIVO_DC_I2C_CONTROL1
, saved1
);
667 WREG32(0x494, saved2
);
668 tmp
= RREG32(RADEON_BIOS_6_SCRATCH
);
669 tmp
&= ~ATOM_S6_HW_I2C_BUSY_STATE
;
670 WREG32(RADEON_BIOS_6_SCRATCH
, tmp
);
672 mutex_unlock(&rdev
->pm
.mutex
);
673 mutex_unlock(&rdev
->dc_hw_i2c_mutex
);
678 static int radeon_sw_i2c_xfer(struct i2c_adapter
*i2c_adap
,
679 struct i2c_msg
*msgs
, int num
)
681 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
684 radeon_i2c_do_lock(i2c
, 1);
685 ret
= i2c_transfer(&i2c
->algo
.radeon
.bit_adapter
, msgs
, num
);
686 radeon_i2c_do_lock(i2c
, 0);
691 static int radeon_i2c_xfer(struct i2c_adapter
*i2c_adap
,
692 struct i2c_msg
*msgs
, int num
)
694 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
695 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
696 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
699 switch (rdev
->family
) {
719 ret
= r100_hw_i2c_xfer(i2c_adap
, msgs
, num
);
721 ret
= radeon_sw_i2c_xfer(i2c_adap
, msgs
, num
);
726 /* XXX fill in hw i2c implementation */
727 ret
= radeon_sw_i2c_xfer(i2c_adap
, msgs
, num
);
735 if (rec
->hw_capable
) {
737 ret
= r100_hw_i2c_xfer(i2c_adap
, msgs
, num
);
739 ret
= r500_hw_i2c_xfer(i2c_adap
, msgs
, num
);
741 ret
= radeon_sw_i2c_xfer(i2c_adap
, msgs
, num
);
747 /* XXX fill in hw i2c implementation */
748 ret
= radeon_sw_i2c_xfer(i2c_adap
, msgs
, num
);
758 /* XXX fill in hw i2c implementation */
759 ret
= radeon_sw_i2c_xfer(i2c_adap
, msgs
, num
);
762 DRM_ERROR("i2c: unhandled radeon chip\n");
770 static u32
radeon_i2c_func(struct i2c_adapter
*adap
)
772 return I2C_FUNC_I2C
| I2C_FUNC_SMBUS_EMUL
;
775 static const struct i2c_algorithm radeon_i2c_algo
= {
776 .master_xfer
= radeon_i2c_xfer
,
777 .functionality
= radeon_i2c_func
,
780 struct radeon_i2c_chan
*radeon_i2c_create(struct drm_device
*dev
,
781 struct radeon_i2c_bus_rec
*rec
,
784 struct radeon_i2c_chan
*i2c
;
787 i2c
= kzalloc(sizeof(struct radeon_i2c_chan
), GFP_KERNEL
);
791 /* set the internal bit adapter */
792 i2c
->algo
.radeon
.bit_adapter
.owner
= THIS_MODULE
;
793 i2c_set_adapdata(&i2c
->algo
.radeon
.bit_adapter
, i2c
);
794 sprintf(i2c
->algo
.radeon
.bit_adapter
.name
, "Radeon internal i2c bit bus %s", name
);
795 i2c
->algo
.radeon
.bit_adapter
.algo_data
= &i2c
->algo
.radeon
.bit_data
;
796 i2c
->algo
.radeon
.bit_data
.setsda
= set_data
;
797 i2c
->algo
.radeon
.bit_data
.setscl
= set_clock
;
798 i2c
->algo
.radeon
.bit_data
.getsda
= get_data
;
799 i2c
->algo
.radeon
.bit_data
.getscl
= get_clock
;
800 i2c
->algo
.radeon
.bit_data
.udelay
= 20;
801 /* vesa says 2.2 ms is enough, 1 jiffy doesn't seem to always
802 * make this, 2 jiffies is a lot more reliable */
803 i2c
->algo
.radeon
.bit_data
.timeout
= 2;
804 i2c
->algo
.radeon
.bit_data
.data
= i2c
;
805 ret
= i2c_bit_add_bus(&i2c
->algo
.radeon
.bit_adapter
);
807 DRM_ERROR("Failed to register internal bit i2c %s\n", name
);
810 /* set the radeon i2c adapter */
813 i2c
->adapter
.owner
= THIS_MODULE
;
814 i2c_set_adapdata(&i2c
->adapter
, i2c
);
815 sprintf(i2c
->adapter
.name
, "Radeon i2c %s", name
);
816 i2c
->adapter
.algo_data
= &i2c
->algo
.radeon
;
817 i2c
->adapter
.algo
= &radeon_i2c_algo
;
818 ret
= i2c_add_adapter(&i2c
->adapter
);
820 DRM_ERROR("Failed to register i2c %s\n", name
);
831 struct radeon_i2c_chan
*radeon_i2c_create_dp(struct drm_device
*dev
,
832 struct radeon_i2c_bus_rec
*rec
,
835 struct radeon_i2c_chan
*i2c
;
838 i2c
= kzalloc(sizeof(struct radeon_i2c_chan
), GFP_KERNEL
);
843 i2c
->adapter
.owner
= THIS_MODULE
;
845 i2c_set_adapdata(&i2c
->adapter
, i2c
);
846 i2c
->adapter
.algo_data
= &i2c
->algo
.dp
;
847 i2c
->algo
.dp
.aux_ch
= radeon_dp_i2c_aux_ch
;
848 i2c
->algo
.dp
.address
= 0;
849 ret
= i2c_dp_aux_add_bus(&i2c
->adapter
);
851 DRM_INFO("Failed to register i2c %s\n", name
);
862 void radeon_i2c_destroy(struct radeon_i2c_chan
*i2c
)
866 i2c_del_adapter(&i2c
->algo
.radeon
.bit_adapter
);
867 i2c_del_adapter(&i2c
->adapter
);
871 void radeon_i2c_destroy_dp(struct radeon_i2c_chan
*i2c
)
876 i2c_del_adapter(&i2c
->adapter
);
880 struct drm_encoder
*radeon_best_encoder(struct drm_connector
*connector
)
885 void radeon_i2c_get_byte(struct radeon_i2c_chan
*i2c_bus
,
892 struct i2c_msg msgs
[] = {
910 if (i2c_transfer(&i2c_bus
->adapter
, msgs
, 2) == 2) {
912 DRM_DEBUG("val = 0x%02x\n", *val
);
914 DRM_ERROR("i2c 0x%02x 0x%02x read failed\n",
919 void radeon_i2c_put_byte(struct radeon_i2c_chan
*i2c_bus
,
925 struct i2c_msg msg
= {
935 if (i2c_transfer(&i2c_bus
->adapter
, &msg
, 1) != 1)
936 DRM_ERROR("i2c 0x%02x 0x%02x write failed\n",