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
, bool requires_extended_probe
)
40 struct i2c_msg msgs
[] = {
55 /* Read 8 bytes from i2c for extended probe of EDID header */
56 if (requires_extended_probe
)
59 /* on hw with routers, select right port */
60 if (radeon_connector
->router
.ddc_valid
)
61 radeon_router_select_ddc_port(radeon_connector
);
63 ret
= i2c_transfer(&radeon_connector
->ddc_bus
->adapter
, msgs
, 2);
65 /* Couldn't find an accessible DDC on this connector */
67 if (requires_extended_probe
) {
68 /* Probe also for valid EDID header
69 * EDID header starts with:
70 * 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00.
71 * Only the first 6 bytes must be valid as
72 * drm_edid_block_valid() can fix the last 2 bytes */
73 if (drm_edid_header_is_valid(buf
) < 6) {
74 /* Couldn't find an accessible EDID on this
84 static void radeon_i2c_do_lock(struct radeon_i2c_chan
*i2c
, int lock_state
)
86 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
87 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
90 /* RV410 appears to have a bug where the hw i2c in reset
91 * holds the i2c port in a bad state - switch hw i2c away before
92 * doing DDC - do this for all r200s/r300s/r400s for safety sake
94 if (rec
->hw_capable
) {
95 if ((rdev
->family
>= CHIP_R200
) && !ASIC_IS_AVIVO(rdev
)) {
98 if (rdev
->family
>= CHIP_RV350
)
99 reg
= RADEON_GPIO_MONID
;
100 else if ((rdev
->family
== CHIP_R300
) ||
101 (rdev
->family
== CHIP_R350
))
102 reg
= RADEON_GPIO_DVI_DDC
;
104 reg
= RADEON_GPIO_CRT2_DDC
;
106 mutex_lock(&rdev
->dc_hw_i2c_mutex
);
107 if (rec
->a_clk_reg
== reg
) {
108 WREG32(RADEON_DVI_I2C_CNTL_0
, (RADEON_I2C_SOFT_RST
|
109 R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
)));
111 WREG32(RADEON_DVI_I2C_CNTL_0
, (RADEON_I2C_SOFT_RST
|
112 R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
)));
114 mutex_unlock(&rdev
->dc_hw_i2c_mutex
);
118 /* switch the pads to ddc mode */
119 if (ASIC_IS_DCE3(rdev
) && rec
->hw_capable
) {
120 temp
= RREG32(rec
->mask_clk_reg
);
122 WREG32(rec
->mask_clk_reg
, temp
);
125 /* clear the output pin values */
126 temp
= RREG32(rec
->a_clk_reg
) & ~rec
->a_clk_mask
;
127 WREG32(rec
->a_clk_reg
, temp
);
129 temp
= RREG32(rec
->a_data_reg
) & ~rec
->a_data_mask
;
130 WREG32(rec
->a_data_reg
, temp
);
132 /* set the pins to input */
133 temp
= RREG32(rec
->en_clk_reg
) & ~rec
->en_clk_mask
;
134 WREG32(rec
->en_clk_reg
, temp
);
136 temp
= RREG32(rec
->en_data_reg
) & ~rec
->en_data_mask
;
137 WREG32(rec
->en_data_reg
, temp
);
139 /* mask the gpio pins for software use */
140 temp
= RREG32(rec
->mask_clk_reg
);
142 temp
|= rec
->mask_clk_mask
;
144 temp
&= ~rec
->mask_clk_mask
;
145 WREG32(rec
->mask_clk_reg
, temp
);
146 temp
= RREG32(rec
->mask_clk_reg
);
148 temp
= RREG32(rec
->mask_data_reg
);
150 temp
|= rec
->mask_data_mask
;
152 temp
&= ~rec
->mask_data_mask
;
153 WREG32(rec
->mask_data_reg
, temp
);
154 temp
= RREG32(rec
->mask_data_reg
);
157 static int get_clock(void *i2c_priv
)
159 struct radeon_i2c_chan
*i2c
= i2c_priv
;
160 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
161 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
164 /* read the value off the pin */
165 val
= RREG32(rec
->y_clk_reg
);
166 val
&= rec
->y_clk_mask
;
172 static int get_data(void *i2c_priv
)
174 struct radeon_i2c_chan
*i2c
= i2c_priv
;
175 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
176 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
179 /* read the value off the pin */
180 val
= RREG32(rec
->y_data_reg
);
181 val
&= rec
->y_data_mask
;
186 static void set_clock(void *i2c_priv
, int clock
)
188 struct radeon_i2c_chan
*i2c
= i2c_priv
;
189 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
190 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
193 /* set pin direction */
194 val
= RREG32(rec
->en_clk_reg
) & ~rec
->en_clk_mask
;
195 val
|= clock
? 0 : rec
->en_clk_mask
;
196 WREG32(rec
->en_clk_reg
, val
);
199 static void set_data(void *i2c_priv
, int data
)
201 struct radeon_i2c_chan
*i2c
= i2c_priv
;
202 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
203 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
206 /* set pin direction */
207 val
= RREG32(rec
->en_data_reg
) & ~rec
->en_data_mask
;
208 val
|= data
? 0 : rec
->en_data_mask
;
209 WREG32(rec
->en_data_reg
, val
);
212 static int pre_xfer(struct i2c_adapter
*i2c_adap
)
214 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
216 radeon_i2c_do_lock(i2c
, 1);
221 static void post_xfer(struct i2c_adapter
*i2c_adap
)
223 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
225 radeon_i2c_do_lock(i2c
, 0);
230 static u32
radeon_get_i2c_prescale(struct radeon_device
*rdev
)
232 u32 sclk
= rdev
->pm
.current_sclk
;
238 switch (rdev
->family
) {
252 nm
= (sclk
* 10) / (i2c_clock
* 4);
253 for (loop
= 1; loop
< 255; loop
++) {
254 if ((nm
/ loop
) < loop
)
259 prescale
= m
| (n
<< 8);
267 prescale
= (((sclk
* 10)/(4 * 128 * 100) + 1) << 8) + 128;
281 if (rdev
->family
== CHIP_R520
)
282 prescale
= (127 << 8) + ((sclk
* 10) / (4 * 127 * i2c_clock
));
284 prescale
= (((sclk
* 10)/(4 * 128 * 100) + 1) << 8) + 128;
310 DRM_ERROR("i2c: unhandled radeon chip\n");
317 /* hw i2c engine for r1xx-4xx hardware
318 * hw can buffer up to 15 bytes
320 static int r100_hw_i2c_xfer(struct i2c_adapter
*i2c_adap
,
321 struct i2c_msg
*msgs
, int num
)
323 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
324 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
325 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
327 int i
, j
, k
, ret
= num
;
329 u32 i2c_cntl_0
, i2c_cntl_1
, i2c_data
;
332 mutex_lock(&rdev
->dc_hw_i2c_mutex
);
333 /* take the pm lock since we need a constant sclk */
334 mutex_lock(&rdev
->pm
.mutex
);
336 prescale
= radeon_get_i2c_prescale(rdev
);
338 reg
= ((prescale
<< RADEON_I2C_PRESCALE_SHIFT
) |
339 RADEON_I2C_DRIVE_EN
|
344 if (rdev
->is_atom_bios
) {
345 tmp
= RREG32(RADEON_BIOS_6_SCRATCH
);
346 WREG32(RADEON_BIOS_6_SCRATCH
, tmp
| ATOM_S6_HW_I2C_BUSY_STATE
);
350 i2c_cntl_0
= RADEON_I2C_CNTL_0
;
351 i2c_cntl_1
= RADEON_I2C_CNTL_1
;
352 i2c_data
= RADEON_I2C_DATA
;
354 i2c_cntl_0
= RADEON_DVI_I2C_CNTL_0
;
355 i2c_cntl_1
= RADEON_DVI_I2C_CNTL_1
;
356 i2c_data
= RADEON_DVI_I2C_DATA
;
358 switch (rdev
->family
) {
365 switch (rec
->mask_clk_reg
) {
366 case RADEON_GPIO_DVI_DDC
:
367 /* no gpio select bit */
370 DRM_ERROR("gpio not supported with hw i2c\n");
376 /* only bit 4 on r200 */
377 switch (rec
->mask_clk_reg
) {
378 case RADEON_GPIO_DVI_DDC
:
379 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
);
381 case RADEON_GPIO_MONID
:
382 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
);
385 DRM_ERROR("gpio not supported with hw i2c\n");
393 switch (rec
->mask_clk_reg
) {
394 case RADEON_GPIO_DVI_DDC
:
395 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
);
397 case RADEON_GPIO_VGA_DDC
:
398 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC2
);
400 case RADEON_GPIO_CRT2_DDC
:
401 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
);
404 DRM_ERROR("gpio not supported with hw i2c\n");
411 /* only bit 4 on r300/r350 */
412 switch (rec
->mask_clk_reg
) {
413 case RADEON_GPIO_VGA_DDC
:
414 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
);
416 case RADEON_GPIO_DVI_DDC
:
417 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
);
420 DRM_ERROR("gpio not supported with hw i2c\n");
433 switch (rec
->mask_clk_reg
) {
434 case RADEON_GPIO_VGA_DDC
:
435 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
);
437 case RADEON_GPIO_DVI_DDC
:
438 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC2
);
440 case RADEON_GPIO_MONID
:
441 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
);
444 DRM_ERROR("gpio not supported with hw i2c\n");
450 DRM_ERROR("unsupported asic\n");
457 /* check for bus probe */
459 if ((num
== 1) && (p
->len
== 0)) {
460 WREG32(i2c_cntl_0
, (RADEON_I2C_DONE
|
463 RADEON_I2C_SOFT_RST
));
464 WREG32(i2c_data
, (p
->addr
<< 1) & 0xff);
466 WREG32(i2c_cntl_1
, ((1 << RADEON_I2C_DATA_COUNT_SHIFT
) |
467 (1 << RADEON_I2C_ADDR_COUNT_SHIFT
) |
469 (48 << RADEON_I2C_TIME_LIMIT_SHIFT
)));
470 WREG32(i2c_cntl_0
, reg
);
471 for (k
= 0; k
< 32; k
++) {
473 tmp
= RREG32(i2c_cntl_0
);
474 if (tmp
& RADEON_I2C_GO
)
476 tmp
= RREG32(i2c_cntl_0
);
477 if (tmp
& RADEON_I2C_DONE
)
480 DRM_DEBUG("i2c write error 0x%08x\n", tmp
);
481 WREG32(i2c_cntl_0
, tmp
| RADEON_I2C_ABORT
);
489 for (i
= 0; i
< num
; i
++) {
491 for (j
= 0; j
< p
->len
; j
++) {
492 if (p
->flags
& I2C_M_RD
) {
493 WREG32(i2c_cntl_0
, (RADEON_I2C_DONE
|
496 RADEON_I2C_SOFT_RST
));
497 WREG32(i2c_data
, ((p
->addr
<< 1) & 0xff) | 0x1);
498 WREG32(i2c_cntl_1
, ((1 << RADEON_I2C_DATA_COUNT_SHIFT
) |
499 (1 << RADEON_I2C_ADDR_COUNT_SHIFT
) |
501 (48 << RADEON_I2C_TIME_LIMIT_SHIFT
)));
502 WREG32(i2c_cntl_0
, reg
| RADEON_I2C_RECEIVE
);
503 for (k
= 0; k
< 32; k
++) {
505 tmp
= RREG32(i2c_cntl_0
);
506 if (tmp
& RADEON_I2C_GO
)
508 tmp
= RREG32(i2c_cntl_0
);
509 if (tmp
& RADEON_I2C_DONE
)
512 DRM_DEBUG("i2c read error 0x%08x\n", tmp
);
513 WREG32(i2c_cntl_0
, tmp
| RADEON_I2C_ABORT
);
518 p
->buf
[j
] = RREG32(i2c_data
) & 0xff;
520 WREG32(i2c_cntl_0
, (RADEON_I2C_DONE
|
523 RADEON_I2C_SOFT_RST
));
524 WREG32(i2c_data
, (p
->addr
<< 1) & 0xff);
525 WREG32(i2c_data
, p
->buf
[j
]);
526 WREG32(i2c_cntl_1
, ((1 << RADEON_I2C_DATA_COUNT_SHIFT
) |
527 (1 << RADEON_I2C_ADDR_COUNT_SHIFT
) |
529 (48 << RADEON_I2C_TIME_LIMIT_SHIFT
)));
530 WREG32(i2c_cntl_0
, reg
);
531 for (k
= 0; k
< 32; k
++) {
533 tmp
= RREG32(i2c_cntl_0
);
534 if (tmp
& RADEON_I2C_GO
)
536 tmp
= RREG32(i2c_cntl_0
);
537 if (tmp
& RADEON_I2C_DONE
)
540 DRM_DEBUG("i2c write error 0x%08x\n", tmp
);
541 WREG32(i2c_cntl_0
, tmp
| RADEON_I2C_ABORT
);
551 WREG32(i2c_cntl_0
, 0);
552 WREG32(i2c_cntl_1
, 0);
553 WREG32(i2c_cntl_0
, (RADEON_I2C_DONE
|
556 RADEON_I2C_SOFT_RST
));
558 if (rdev
->is_atom_bios
) {
559 tmp
= RREG32(RADEON_BIOS_6_SCRATCH
);
560 tmp
&= ~ATOM_S6_HW_I2C_BUSY_STATE
;
561 WREG32(RADEON_BIOS_6_SCRATCH
, tmp
);
564 mutex_unlock(&rdev
->pm
.mutex
);
565 mutex_unlock(&rdev
->dc_hw_i2c_mutex
);
570 /* hw i2c engine for r5xx hardware
571 * hw can buffer up to 15 bytes
573 static int r500_hw_i2c_xfer(struct i2c_adapter
*i2c_adap
,
574 struct i2c_msg
*msgs
, int num
)
576 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
577 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
578 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
580 int i
, j
, remaining
, current_count
, buffer_offset
, ret
= num
;
585 mutex_lock(&rdev
->dc_hw_i2c_mutex
);
586 /* take the pm lock since we need a constant sclk */
587 mutex_lock(&rdev
->pm
.mutex
);
589 prescale
= radeon_get_i2c_prescale(rdev
);
591 /* clear gpio mask bits */
592 tmp
= RREG32(rec
->mask_clk_reg
);
593 tmp
&= ~rec
->mask_clk_mask
;
594 WREG32(rec
->mask_clk_reg
, tmp
);
595 tmp
= RREG32(rec
->mask_clk_reg
);
597 tmp
= RREG32(rec
->mask_data_reg
);
598 tmp
&= ~rec
->mask_data_mask
;
599 WREG32(rec
->mask_data_reg
, tmp
);
600 tmp
= RREG32(rec
->mask_data_reg
);
602 /* clear pin values */
603 tmp
= RREG32(rec
->a_clk_reg
);
604 tmp
&= ~rec
->a_clk_mask
;
605 WREG32(rec
->a_clk_reg
, tmp
);
606 tmp
= RREG32(rec
->a_clk_reg
);
608 tmp
= RREG32(rec
->a_data_reg
);
609 tmp
&= ~rec
->a_data_mask
;
610 WREG32(rec
->a_data_reg
, tmp
);
611 tmp
= RREG32(rec
->a_data_reg
);
613 /* set the pins to input */
614 tmp
= RREG32(rec
->en_clk_reg
);
615 tmp
&= ~rec
->en_clk_mask
;
616 WREG32(rec
->en_clk_reg
, tmp
);
617 tmp
= RREG32(rec
->en_clk_reg
);
619 tmp
= RREG32(rec
->en_data_reg
);
620 tmp
&= ~rec
->en_data_mask
;
621 WREG32(rec
->en_data_reg
, tmp
);
622 tmp
= RREG32(rec
->en_data_reg
);
625 tmp
= RREG32(RADEON_BIOS_6_SCRATCH
);
626 WREG32(RADEON_BIOS_6_SCRATCH
, tmp
| ATOM_S6_HW_I2C_BUSY_STATE
);
627 saved1
= RREG32(AVIVO_DC_I2C_CONTROL1
);
628 saved2
= RREG32(0x494);
629 WREG32(0x494, saved2
| 0x1);
631 WREG32(AVIVO_DC_I2C_ARBITRATION
, AVIVO_DC_I2C_SW_WANTS_TO_USE_I2C
);
632 for (i
= 0; i
< 50; i
++) {
634 if (RREG32(AVIVO_DC_I2C_ARBITRATION
) & AVIVO_DC_I2C_SW_CAN_USE_I2C
)
638 DRM_ERROR("failed to get i2c bus\n");
643 reg
= AVIVO_DC_I2C_START
| AVIVO_DC_I2C_STOP
| AVIVO_DC_I2C_EN
;
644 switch (rec
->mask_clk_reg
) {
645 case AVIVO_DC_GPIO_DDC1_MASK
:
646 reg
|= AVIVO_DC_I2C_PIN_SELECT(AVIVO_SEL_DDC1
);
648 case AVIVO_DC_GPIO_DDC2_MASK
:
649 reg
|= AVIVO_DC_I2C_PIN_SELECT(AVIVO_SEL_DDC2
);
651 case AVIVO_DC_GPIO_DDC3_MASK
:
652 reg
|= AVIVO_DC_I2C_PIN_SELECT(AVIVO_SEL_DDC3
);
655 DRM_ERROR("gpio not supported with hw i2c\n");
660 /* check for bus probe */
662 if ((num
== 1) && (p
->len
== 0)) {
663 WREG32(AVIVO_DC_I2C_STATUS1
, (AVIVO_DC_I2C_DONE
|
666 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_SOFT_RESET
);
668 WREG32(AVIVO_DC_I2C_RESET
, 0);
670 WREG32(AVIVO_DC_I2C_DATA
, (p
->addr
<< 1) & 0xff);
671 WREG32(AVIVO_DC_I2C_DATA
, 0);
673 WREG32(AVIVO_DC_I2C_CONTROL3
, AVIVO_DC_I2C_TIME_LIMIT(48));
674 WREG32(AVIVO_DC_I2C_CONTROL2
, (AVIVO_DC_I2C_ADDR_COUNT(1) |
675 AVIVO_DC_I2C_DATA_COUNT(1) |
677 WREG32(AVIVO_DC_I2C_CONTROL1
, reg
);
678 WREG32(AVIVO_DC_I2C_STATUS1
, AVIVO_DC_I2C_GO
);
679 for (j
= 0; j
< 200; j
++) {
681 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
682 if (tmp
& AVIVO_DC_I2C_GO
)
684 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
685 if (tmp
& AVIVO_DC_I2C_DONE
)
688 DRM_DEBUG("i2c write error 0x%08x\n", tmp
);
689 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_ABORT
);
697 for (i
= 0; i
< num
; i
++) {
701 if (p
->flags
& I2C_M_RD
) {
706 current_count
= remaining
;
707 WREG32(AVIVO_DC_I2C_STATUS1
, (AVIVO_DC_I2C_DONE
|
710 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_SOFT_RESET
);
712 WREG32(AVIVO_DC_I2C_RESET
, 0);
714 WREG32(AVIVO_DC_I2C_DATA
, ((p
->addr
<< 1) & 0xff) | 0x1);
715 WREG32(AVIVO_DC_I2C_CONTROL3
, AVIVO_DC_I2C_TIME_LIMIT(48));
716 WREG32(AVIVO_DC_I2C_CONTROL2
, (AVIVO_DC_I2C_ADDR_COUNT(1) |
717 AVIVO_DC_I2C_DATA_COUNT(current_count
) |
719 WREG32(AVIVO_DC_I2C_CONTROL1
, reg
| AVIVO_DC_I2C_RECEIVE
);
720 WREG32(AVIVO_DC_I2C_STATUS1
, AVIVO_DC_I2C_GO
);
721 for (j
= 0; j
< 200; j
++) {
723 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
724 if (tmp
& AVIVO_DC_I2C_GO
)
726 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
727 if (tmp
& AVIVO_DC_I2C_DONE
)
730 DRM_DEBUG("i2c read error 0x%08x\n", tmp
);
731 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_ABORT
);
736 for (j
= 0; j
< current_count
; j
++)
737 p
->buf
[buffer_offset
+ j
] = RREG32(AVIVO_DC_I2C_DATA
) & 0xff;
738 remaining
-= current_count
;
739 buffer_offset
+= current_count
;
746 current_count
= remaining
;
747 WREG32(AVIVO_DC_I2C_STATUS1
, (AVIVO_DC_I2C_DONE
|
750 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_SOFT_RESET
);
752 WREG32(AVIVO_DC_I2C_RESET
, 0);
754 WREG32(AVIVO_DC_I2C_DATA
, (p
->addr
<< 1) & 0xff);
755 for (j
= 0; j
< current_count
; j
++)
756 WREG32(AVIVO_DC_I2C_DATA
, p
->buf
[buffer_offset
+ j
]);
758 WREG32(AVIVO_DC_I2C_CONTROL3
, AVIVO_DC_I2C_TIME_LIMIT(48));
759 WREG32(AVIVO_DC_I2C_CONTROL2
, (AVIVO_DC_I2C_ADDR_COUNT(1) |
760 AVIVO_DC_I2C_DATA_COUNT(current_count
) |
762 WREG32(AVIVO_DC_I2C_CONTROL1
, reg
);
763 WREG32(AVIVO_DC_I2C_STATUS1
, AVIVO_DC_I2C_GO
);
764 for (j
= 0; j
< 200; j
++) {
766 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
767 if (tmp
& AVIVO_DC_I2C_GO
)
769 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
770 if (tmp
& AVIVO_DC_I2C_DONE
)
773 DRM_DEBUG("i2c write error 0x%08x\n", tmp
);
774 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_ABORT
);
779 remaining
-= current_count
;
780 buffer_offset
+= current_count
;
786 WREG32(AVIVO_DC_I2C_STATUS1
, (AVIVO_DC_I2C_DONE
|
789 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_SOFT_RESET
);
791 WREG32(AVIVO_DC_I2C_RESET
, 0);
793 WREG32(AVIVO_DC_I2C_ARBITRATION
, AVIVO_DC_I2C_SW_DONE_USING_I2C
);
794 WREG32(AVIVO_DC_I2C_CONTROL1
, saved1
);
795 WREG32(0x494, saved2
);
796 tmp
= RREG32(RADEON_BIOS_6_SCRATCH
);
797 tmp
&= ~ATOM_S6_HW_I2C_BUSY_STATE
;
798 WREG32(RADEON_BIOS_6_SCRATCH
, tmp
);
800 mutex_unlock(&rdev
->pm
.mutex
);
801 mutex_unlock(&rdev
->dc_hw_i2c_mutex
);
806 static int radeon_hw_i2c_xfer(struct i2c_adapter
*i2c_adap
,
807 struct i2c_msg
*msgs
, int num
)
809 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
810 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
811 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
814 switch (rdev
->family
) {
833 ret
= r100_hw_i2c_xfer(i2c_adap
, msgs
, num
);
838 /* XXX fill in hw i2c implementation */
847 ret
= r100_hw_i2c_xfer(i2c_adap
, msgs
, num
);
849 ret
= r500_hw_i2c_xfer(i2c_adap
, msgs
, num
);
855 /* XXX fill in hw i2c implementation */
865 /* XXX fill in hw i2c implementation */
872 /* XXX fill in hw i2c implementation */
875 DRM_ERROR("i2c: unhandled radeon chip\n");
883 static u32
radeon_hw_i2c_func(struct i2c_adapter
*adap
)
885 return I2C_FUNC_I2C
| I2C_FUNC_SMBUS_EMUL
;
888 static const struct i2c_algorithm radeon_i2c_algo
= {
889 .master_xfer
= radeon_hw_i2c_xfer
,
890 .functionality
= radeon_hw_i2c_func
,
893 struct radeon_i2c_chan
*radeon_i2c_create(struct drm_device
*dev
,
894 struct radeon_i2c_bus_rec
*rec
,
897 struct radeon_device
*rdev
= dev
->dev_private
;
898 struct radeon_i2c_chan
*i2c
;
901 i2c
= kzalloc(sizeof(struct radeon_i2c_chan
), GFP_KERNEL
);
906 i2c
->adapter
.owner
= THIS_MODULE
;
907 i2c
->adapter
.class = I2C_CLASS_DDC
;
909 i2c_set_adapdata(&i2c
->adapter
, i2c
);
913 ((rdev
->family
<= CHIP_RS480
) ||
914 ((rdev
->family
>= CHIP_RV515
) && (rdev
->family
<= CHIP_R580
))))) {
915 /* set the radeon hw i2c adapter */
916 snprintf(i2c
->adapter
.name
, sizeof(i2c
->adapter
.name
),
917 "Radeon i2c hw bus %s", name
);
918 i2c
->adapter
.algo
= &radeon_i2c_algo
;
919 ret
= i2c_add_adapter(&i2c
->adapter
);
921 DRM_ERROR("Failed to register hw i2c %s\n", name
);
925 /* set the radeon bit adapter */
926 snprintf(i2c
->adapter
.name
, sizeof(i2c
->adapter
.name
),
927 "Radeon i2c bit bus %s", name
);
928 i2c
->adapter
.algo_data
= &i2c
->algo
.bit
;
929 i2c
->algo
.bit
.pre_xfer
= pre_xfer
;
930 i2c
->algo
.bit
.post_xfer
= post_xfer
;
931 i2c
->algo
.bit
.setsda
= set_data
;
932 i2c
->algo
.bit
.setscl
= set_clock
;
933 i2c
->algo
.bit
.getsda
= get_data
;
934 i2c
->algo
.bit
.getscl
= get_clock
;
935 i2c
->algo
.bit
.udelay
= 20;
936 /* vesa says 2.2 ms is enough, 1 jiffy doesn't seem to always
937 * make this, 2 jiffies is a lot more reliable */
938 i2c
->algo
.bit
.timeout
= 2;
939 i2c
->algo
.bit
.data
= i2c
;
940 ret
= i2c_bit_add_bus(&i2c
->adapter
);
942 DRM_ERROR("Failed to register bit i2c %s\n", name
);
954 struct radeon_i2c_chan
*radeon_i2c_create_dp(struct drm_device
*dev
,
955 struct radeon_i2c_bus_rec
*rec
,
958 struct radeon_i2c_chan
*i2c
;
961 i2c
= kzalloc(sizeof(struct radeon_i2c_chan
), GFP_KERNEL
);
966 i2c
->adapter
.owner
= THIS_MODULE
;
967 i2c
->adapter
.class = I2C_CLASS_DDC
;
969 snprintf(i2c
->adapter
.name
, sizeof(i2c
->adapter
.name
),
970 "Radeon aux bus %s", name
);
971 i2c_set_adapdata(&i2c
->adapter
, i2c
);
972 i2c
->adapter
.algo_data
= &i2c
->algo
.dp
;
973 i2c
->algo
.dp
.aux_ch
= radeon_dp_i2c_aux_ch
;
974 i2c
->algo
.dp
.address
= 0;
975 ret
= i2c_dp_aux_add_bus(&i2c
->adapter
);
977 DRM_INFO("Failed to register i2c %s\n", name
);
988 void radeon_i2c_destroy(struct radeon_i2c_chan
*i2c
)
992 i2c_del_adapter(&i2c
->adapter
);
996 /* Add the default buses */
997 void radeon_i2c_init(struct radeon_device
*rdev
)
999 if (rdev
->is_atom_bios
)
1000 radeon_atombios_i2c_init(rdev
);
1002 radeon_combios_i2c_init(rdev
);
1005 /* remove all the buses */
1006 void radeon_i2c_fini(struct radeon_device
*rdev
)
1010 for (i
= 0; i
< RADEON_MAX_I2C_BUS
; i
++) {
1011 if (rdev
->i2c_bus
[i
]) {
1012 radeon_i2c_destroy(rdev
->i2c_bus
[i
]);
1013 rdev
->i2c_bus
[i
] = NULL
;
1018 /* Add additional buses */
1019 void radeon_i2c_add(struct radeon_device
*rdev
,
1020 struct radeon_i2c_bus_rec
*rec
,
1023 struct drm_device
*dev
= rdev
->ddev
;
1026 for (i
= 0; i
< RADEON_MAX_I2C_BUS
; i
++) {
1027 if (!rdev
->i2c_bus
[i
]) {
1028 rdev
->i2c_bus
[i
] = radeon_i2c_create(dev
, rec
, name
);
1034 /* looks up bus based on id */
1035 struct radeon_i2c_chan
*radeon_i2c_lookup(struct radeon_device
*rdev
,
1036 struct radeon_i2c_bus_rec
*i2c_bus
)
1040 for (i
= 0; i
< RADEON_MAX_I2C_BUS
; i
++) {
1041 if (rdev
->i2c_bus
[i
] &&
1042 (rdev
->i2c_bus
[i
]->rec
.i2c_id
== i2c_bus
->i2c_id
)) {
1043 return rdev
->i2c_bus
[i
];
1049 struct drm_encoder
*radeon_best_encoder(struct drm_connector
*connector
)
1054 void radeon_i2c_get_byte(struct radeon_i2c_chan
*i2c_bus
,
1061 struct i2c_msg msgs
[] = {
1079 if (i2c_transfer(&i2c_bus
->adapter
, msgs
, 2) == 2) {
1081 DRM_DEBUG("val = 0x%02x\n", *val
);
1083 DRM_DEBUG("i2c 0x%02x 0x%02x read failed\n",
1088 void radeon_i2c_put_byte(struct radeon_i2c_chan
*i2c_bus
,
1094 struct i2c_msg msg
= {
1104 if (i2c_transfer(&i2c_bus
->adapter
, &msg
, 1) != 1)
1105 DRM_DEBUG("i2c 0x%02x 0x%02x write failed\n",
1109 /* ddc router switching */
1110 void radeon_router_select_ddc_port(struct radeon_connector
*radeon_connector
)
1114 if (!radeon_connector
->router
.ddc_valid
)
1117 if (!radeon_connector
->router_bus
)
1120 radeon_i2c_get_byte(radeon_connector
->router_bus
,
1121 radeon_connector
->router
.i2c_addr
,
1123 val
&= ~radeon_connector
->router
.ddc_mux_control_pin
;
1124 radeon_i2c_put_byte(radeon_connector
->router_bus
,
1125 radeon_connector
->router
.i2c_addr
,
1127 radeon_i2c_get_byte(radeon_connector
->router_bus
,
1128 radeon_connector
->router
.i2c_addr
,
1130 val
&= ~radeon_connector
->router
.ddc_mux_control_pin
;
1131 val
|= radeon_connector
->router
.ddc_mux_state
;
1132 radeon_i2c_put_byte(radeon_connector
->router_bus
,
1133 radeon_connector
->router
.i2c_addr
,
1137 /* clock/data router switching */
1138 void radeon_router_select_cd_port(struct radeon_connector
*radeon_connector
)
1142 if (!radeon_connector
->router
.cd_valid
)
1145 if (!radeon_connector
->router_bus
)
1148 radeon_i2c_get_byte(radeon_connector
->router_bus
,
1149 radeon_connector
->router
.i2c_addr
,
1151 val
&= ~radeon_connector
->router
.cd_mux_control_pin
;
1152 radeon_i2c_put_byte(radeon_connector
->router_bus
,
1153 radeon_connector
->router
.i2c_addr
,
1155 radeon_i2c_get_byte(radeon_connector
->router_bus
,
1156 radeon_connector
->router
.i2c_addr
,
1158 val
&= ~radeon_connector
->router
.cd_mux_control_pin
;
1159 val
|= radeon_connector
->router
.cd_mux_state
;
1160 radeon_i2c_put_byte(radeon_connector
->router_bus
,
1161 radeon_connector
->router
.i2c_addr
,