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);
64 static void radeon_i2c_do_lock(struct radeon_i2c_chan
*i2c
, int lock_state
)
66 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
67 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
70 /* RV410 appears to have a bug where the hw i2c in reset
71 * holds the i2c port in a bad state - switch hw i2c away before
72 * doing DDC - do this for all r200s/r300s/r400s for safety sake
74 if (rec
->hw_capable
) {
75 if ((rdev
->family
>= CHIP_R200
) && !ASIC_IS_AVIVO(rdev
)) {
78 if (rdev
->family
>= CHIP_RV350
)
79 reg
= RADEON_GPIO_MONID
;
80 else if ((rdev
->family
== CHIP_R300
) ||
81 (rdev
->family
== CHIP_R350
))
82 reg
= RADEON_GPIO_DVI_DDC
;
84 reg
= RADEON_GPIO_CRT2_DDC
;
86 mutex_lock(&rdev
->dc_hw_i2c_mutex
);
87 if (rec
->a_clk_reg
== reg
) {
88 WREG32(RADEON_DVI_I2C_CNTL_0
, (RADEON_I2C_SOFT_RST
|
89 R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
)));
91 WREG32(RADEON_DVI_I2C_CNTL_0
, (RADEON_I2C_SOFT_RST
|
92 R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
)));
94 mutex_unlock(&rdev
->dc_hw_i2c_mutex
);
98 /* switch the pads to ddc mode */
99 if (ASIC_IS_DCE3(rdev
) && rec
->hw_capable
) {
100 temp
= RREG32(rec
->mask_clk_reg
);
102 WREG32(rec
->mask_clk_reg
, temp
);
105 /* clear the output pin values */
106 temp
= RREG32(rec
->a_clk_reg
) & ~rec
->a_clk_mask
;
107 WREG32(rec
->a_clk_reg
, temp
);
109 temp
= RREG32(rec
->a_data_reg
) & ~rec
->a_data_mask
;
110 WREG32(rec
->a_data_reg
, temp
);
112 /* set the pins to input */
113 temp
= RREG32(rec
->en_clk_reg
) & ~rec
->en_clk_mask
;
114 WREG32(rec
->en_clk_reg
, temp
);
116 temp
= RREG32(rec
->en_data_reg
) & ~rec
->en_data_mask
;
117 WREG32(rec
->en_data_reg
, temp
);
119 /* mask the gpio pins for software use */
120 temp
= RREG32(rec
->mask_clk_reg
);
122 temp
|= rec
->mask_clk_mask
;
124 temp
&= ~rec
->mask_clk_mask
;
125 WREG32(rec
->mask_clk_reg
, temp
);
126 temp
= RREG32(rec
->mask_clk_reg
);
128 temp
= RREG32(rec
->mask_data_reg
);
130 temp
|= rec
->mask_data_mask
;
132 temp
&= ~rec
->mask_data_mask
;
133 WREG32(rec
->mask_data_reg
, temp
);
134 temp
= RREG32(rec
->mask_data_reg
);
137 static int get_clock(void *i2c_priv
)
139 struct radeon_i2c_chan
*i2c
= i2c_priv
;
140 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
141 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
144 /* read the value off the pin */
145 val
= RREG32(rec
->y_clk_reg
);
146 val
&= rec
->y_clk_mask
;
152 static int get_data(void *i2c_priv
)
154 struct radeon_i2c_chan
*i2c
= i2c_priv
;
155 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
156 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
159 /* read the value off the pin */
160 val
= RREG32(rec
->y_data_reg
);
161 val
&= rec
->y_data_mask
;
166 static void set_clock(void *i2c_priv
, int clock
)
168 struct radeon_i2c_chan
*i2c
= i2c_priv
;
169 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
170 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
173 /* set pin direction */
174 val
= RREG32(rec
->en_clk_reg
) & ~rec
->en_clk_mask
;
175 val
|= clock
? 0 : rec
->en_clk_mask
;
176 WREG32(rec
->en_clk_reg
, val
);
179 static void set_data(void *i2c_priv
, int data
)
181 struct radeon_i2c_chan
*i2c
= i2c_priv
;
182 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
183 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
186 /* set pin direction */
187 val
= RREG32(rec
->en_data_reg
) & ~rec
->en_data_mask
;
188 val
|= data
? 0 : rec
->en_data_mask
;
189 WREG32(rec
->en_data_reg
, val
);
192 static int pre_xfer(struct i2c_adapter
*i2c_adap
)
194 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
196 radeon_i2c_do_lock(i2c
, 1);
201 static void post_xfer(struct i2c_adapter
*i2c_adap
)
203 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
205 radeon_i2c_do_lock(i2c
, 0);
210 static u32
radeon_get_i2c_prescale(struct radeon_device
*rdev
)
212 u32 sclk
= radeon_get_engine_clock(rdev
);
218 switch (rdev
->family
) {
232 nm
= (sclk
* 10) / (i2c_clock
* 4);
233 for (loop
= 1; loop
< 255; loop
++) {
234 if ((nm
/ loop
) < loop
)
239 prescale
= m
| (n
<< 8);
247 prescale
= (((sclk
* 10)/(4 * 128 * 100) + 1) << 8) + 128;
261 if (rdev
->family
== CHIP_R520
)
262 prescale
= (127 << 8) + ((sclk
* 10) / (4 * 127 * i2c_clock
));
264 prescale
= (((sclk
* 10)/(4 * 128 * 100) + 1) << 8) + 128;
290 DRM_ERROR("i2c: unhandled radeon chip\n");
297 /* hw i2c engine for r1xx-4xx hardware
298 * hw can buffer up to 15 bytes
300 static int r100_hw_i2c_xfer(struct i2c_adapter
*i2c_adap
,
301 struct i2c_msg
*msgs
, int num
)
303 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
304 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
305 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
307 int i
, j
, k
, ret
= num
;
309 u32 i2c_cntl_0
, i2c_cntl_1
, i2c_data
;
312 mutex_lock(&rdev
->dc_hw_i2c_mutex
);
313 /* take the pm lock since we need a constant sclk */
314 mutex_lock(&rdev
->pm
.mutex
);
316 prescale
= radeon_get_i2c_prescale(rdev
);
318 reg
= ((prescale
<< RADEON_I2C_PRESCALE_SHIFT
) |
319 RADEON_I2C_DRIVE_EN
|
324 if (rdev
->is_atom_bios
) {
325 tmp
= RREG32(RADEON_BIOS_6_SCRATCH
);
326 WREG32(RADEON_BIOS_6_SCRATCH
, tmp
| ATOM_S6_HW_I2C_BUSY_STATE
);
330 i2c_cntl_0
= RADEON_I2C_CNTL_0
;
331 i2c_cntl_1
= RADEON_I2C_CNTL_1
;
332 i2c_data
= RADEON_I2C_DATA
;
334 i2c_cntl_0
= RADEON_DVI_I2C_CNTL_0
;
335 i2c_cntl_1
= RADEON_DVI_I2C_CNTL_1
;
336 i2c_data
= RADEON_DVI_I2C_DATA
;
338 switch (rdev
->family
) {
345 switch (rec
->mask_clk_reg
) {
346 case RADEON_GPIO_DVI_DDC
:
347 /* no gpio select bit */
350 DRM_ERROR("gpio not supported with hw i2c\n");
356 /* only bit 4 on r200 */
357 switch (rec
->mask_clk_reg
) {
358 case RADEON_GPIO_DVI_DDC
:
359 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
);
361 case RADEON_GPIO_MONID
:
362 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
);
365 DRM_ERROR("gpio not supported with hw i2c\n");
373 switch (rec
->mask_clk_reg
) {
374 case RADEON_GPIO_DVI_DDC
:
375 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
);
377 case RADEON_GPIO_VGA_DDC
:
378 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC2
);
380 case RADEON_GPIO_CRT2_DDC
:
381 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
);
384 DRM_ERROR("gpio not supported with hw i2c\n");
391 /* only bit 4 on r300/r350 */
392 switch (rec
->mask_clk_reg
) {
393 case RADEON_GPIO_VGA_DDC
:
394 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
);
396 case RADEON_GPIO_DVI_DDC
:
397 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
);
400 DRM_ERROR("gpio not supported with hw i2c\n");
413 switch (rec
->mask_clk_reg
) {
414 case RADEON_GPIO_VGA_DDC
:
415 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1
);
417 case RADEON_GPIO_DVI_DDC
:
418 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC2
);
420 case RADEON_GPIO_MONID
:
421 reg
|= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3
);
424 DRM_ERROR("gpio not supported with hw i2c\n");
430 DRM_ERROR("unsupported asic\n");
437 /* check for bus probe */
439 if ((num
== 1) && (p
->len
== 0)) {
440 WREG32(i2c_cntl_0
, (RADEON_I2C_DONE
|
443 RADEON_I2C_SOFT_RST
));
444 WREG32(i2c_data
, (p
->addr
<< 1) & 0xff);
446 WREG32(i2c_cntl_1
, ((1 << RADEON_I2C_DATA_COUNT_SHIFT
) |
447 (1 << RADEON_I2C_ADDR_COUNT_SHIFT
) |
449 (48 << RADEON_I2C_TIME_LIMIT_SHIFT
)));
450 WREG32(i2c_cntl_0
, reg
);
451 for (k
= 0; k
< 32; k
++) {
453 tmp
= RREG32(i2c_cntl_0
);
454 if (tmp
& RADEON_I2C_GO
)
456 tmp
= RREG32(i2c_cntl_0
);
457 if (tmp
& RADEON_I2C_DONE
)
460 DRM_DEBUG("i2c write error 0x%08x\n", tmp
);
461 WREG32(i2c_cntl_0
, tmp
| RADEON_I2C_ABORT
);
469 for (i
= 0; i
< num
; i
++) {
471 for (j
= 0; j
< p
->len
; j
++) {
472 if (p
->flags
& I2C_M_RD
) {
473 WREG32(i2c_cntl_0
, (RADEON_I2C_DONE
|
476 RADEON_I2C_SOFT_RST
));
477 WREG32(i2c_data
, ((p
->addr
<< 1) & 0xff) | 0x1);
478 WREG32(i2c_cntl_1
, ((1 << RADEON_I2C_DATA_COUNT_SHIFT
) |
479 (1 << RADEON_I2C_ADDR_COUNT_SHIFT
) |
481 (48 << RADEON_I2C_TIME_LIMIT_SHIFT
)));
482 WREG32(i2c_cntl_0
, reg
| RADEON_I2C_RECEIVE
);
483 for (k
= 0; k
< 32; k
++) {
485 tmp
= RREG32(i2c_cntl_0
);
486 if (tmp
& RADEON_I2C_GO
)
488 tmp
= RREG32(i2c_cntl_0
);
489 if (tmp
& RADEON_I2C_DONE
)
492 DRM_DEBUG("i2c read error 0x%08x\n", tmp
);
493 WREG32(i2c_cntl_0
, tmp
| RADEON_I2C_ABORT
);
498 p
->buf
[j
] = RREG32(i2c_data
) & 0xff;
500 WREG32(i2c_cntl_0
, (RADEON_I2C_DONE
|
503 RADEON_I2C_SOFT_RST
));
504 WREG32(i2c_data
, (p
->addr
<< 1) & 0xff);
505 WREG32(i2c_data
, p
->buf
[j
]);
506 WREG32(i2c_cntl_1
, ((1 << RADEON_I2C_DATA_COUNT_SHIFT
) |
507 (1 << RADEON_I2C_ADDR_COUNT_SHIFT
) |
509 (48 << RADEON_I2C_TIME_LIMIT_SHIFT
)));
510 WREG32(i2c_cntl_0
, reg
);
511 for (k
= 0; k
< 32; k
++) {
513 tmp
= RREG32(i2c_cntl_0
);
514 if (tmp
& RADEON_I2C_GO
)
516 tmp
= RREG32(i2c_cntl_0
);
517 if (tmp
& RADEON_I2C_DONE
)
520 DRM_DEBUG("i2c write error 0x%08x\n", tmp
);
521 WREG32(i2c_cntl_0
, tmp
| RADEON_I2C_ABORT
);
531 WREG32(i2c_cntl_0
, 0);
532 WREG32(i2c_cntl_1
, 0);
533 WREG32(i2c_cntl_0
, (RADEON_I2C_DONE
|
536 RADEON_I2C_SOFT_RST
));
538 if (rdev
->is_atom_bios
) {
539 tmp
= RREG32(RADEON_BIOS_6_SCRATCH
);
540 tmp
&= ~ATOM_S6_HW_I2C_BUSY_STATE
;
541 WREG32(RADEON_BIOS_6_SCRATCH
, tmp
);
544 mutex_unlock(&rdev
->pm
.mutex
);
545 mutex_unlock(&rdev
->dc_hw_i2c_mutex
);
550 /* hw i2c engine for r5xx hardware
551 * hw can buffer up to 15 bytes
553 static int r500_hw_i2c_xfer(struct i2c_adapter
*i2c_adap
,
554 struct i2c_msg
*msgs
, int num
)
556 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
557 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
558 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
560 int i
, j
, remaining
, current_count
, buffer_offset
, ret
= num
;
565 mutex_lock(&rdev
->dc_hw_i2c_mutex
);
566 /* take the pm lock since we need a constant sclk */
567 mutex_lock(&rdev
->pm
.mutex
);
569 prescale
= radeon_get_i2c_prescale(rdev
);
571 /* clear gpio mask bits */
572 tmp
= RREG32(rec
->mask_clk_reg
);
573 tmp
&= ~rec
->mask_clk_mask
;
574 WREG32(rec
->mask_clk_reg
, tmp
);
575 tmp
= RREG32(rec
->mask_clk_reg
);
577 tmp
= RREG32(rec
->mask_data_reg
);
578 tmp
&= ~rec
->mask_data_mask
;
579 WREG32(rec
->mask_data_reg
, tmp
);
580 tmp
= RREG32(rec
->mask_data_reg
);
582 /* clear pin values */
583 tmp
= RREG32(rec
->a_clk_reg
);
584 tmp
&= ~rec
->a_clk_mask
;
585 WREG32(rec
->a_clk_reg
, tmp
);
586 tmp
= RREG32(rec
->a_clk_reg
);
588 tmp
= RREG32(rec
->a_data_reg
);
589 tmp
&= ~rec
->a_data_mask
;
590 WREG32(rec
->a_data_reg
, tmp
);
591 tmp
= RREG32(rec
->a_data_reg
);
593 /* set the pins to input */
594 tmp
= RREG32(rec
->en_clk_reg
);
595 tmp
&= ~rec
->en_clk_mask
;
596 WREG32(rec
->en_clk_reg
, tmp
);
597 tmp
= RREG32(rec
->en_clk_reg
);
599 tmp
= RREG32(rec
->en_data_reg
);
600 tmp
&= ~rec
->en_data_mask
;
601 WREG32(rec
->en_data_reg
, tmp
);
602 tmp
= RREG32(rec
->en_data_reg
);
605 tmp
= RREG32(RADEON_BIOS_6_SCRATCH
);
606 WREG32(RADEON_BIOS_6_SCRATCH
, tmp
| ATOM_S6_HW_I2C_BUSY_STATE
);
607 saved1
= RREG32(AVIVO_DC_I2C_CONTROL1
);
608 saved2
= RREG32(0x494);
609 WREG32(0x494, saved2
| 0x1);
611 WREG32(AVIVO_DC_I2C_ARBITRATION
, AVIVO_DC_I2C_SW_WANTS_TO_USE_I2C
);
612 for (i
= 0; i
< 50; i
++) {
614 if (RREG32(AVIVO_DC_I2C_ARBITRATION
) & AVIVO_DC_I2C_SW_CAN_USE_I2C
)
618 DRM_ERROR("failed to get i2c bus\n");
623 reg
= AVIVO_DC_I2C_START
| AVIVO_DC_I2C_STOP
| AVIVO_DC_I2C_EN
;
624 switch (rec
->mask_clk_reg
) {
625 case AVIVO_DC_GPIO_DDC1_MASK
:
626 reg
|= AVIVO_DC_I2C_PIN_SELECT(AVIVO_SEL_DDC1
);
628 case AVIVO_DC_GPIO_DDC2_MASK
:
629 reg
|= AVIVO_DC_I2C_PIN_SELECT(AVIVO_SEL_DDC2
);
631 case AVIVO_DC_GPIO_DDC3_MASK
:
632 reg
|= AVIVO_DC_I2C_PIN_SELECT(AVIVO_SEL_DDC3
);
635 DRM_ERROR("gpio not supported with hw i2c\n");
640 /* check for bus probe */
642 if ((num
== 1) && (p
->len
== 0)) {
643 WREG32(AVIVO_DC_I2C_STATUS1
, (AVIVO_DC_I2C_DONE
|
646 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_SOFT_RESET
);
648 WREG32(AVIVO_DC_I2C_RESET
, 0);
650 WREG32(AVIVO_DC_I2C_DATA
, (p
->addr
<< 1) & 0xff);
651 WREG32(AVIVO_DC_I2C_DATA
, 0);
653 WREG32(AVIVO_DC_I2C_CONTROL3
, AVIVO_DC_I2C_TIME_LIMIT(48));
654 WREG32(AVIVO_DC_I2C_CONTROL2
, (AVIVO_DC_I2C_ADDR_COUNT(1) |
655 AVIVO_DC_I2C_DATA_COUNT(1) |
657 WREG32(AVIVO_DC_I2C_CONTROL1
, reg
);
658 WREG32(AVIVO_DC_I2C_STATUS1
, AVIVO_DC_I2C_GO
);
659 for (j
= 0; j
< 200; j
++) {
661 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
662 if (tmp
& AVIVO_DC_I2C_GO
)
664 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
665 if (tmp
& AVIVO_DC_I2C_DONE
)
668 DRM_DEBUG("i2c write error 0x%08x\n", tmp
);
669 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_ABORT
);
677 for (i
= 0; i
< num
; i
++) {
681 if (p
->flags
& I2C_M_RD
) {
686 current_count
= remaining
;
687 WREG32(AVIVO_DC_I2C_STATUS1
, (AVIVO_DC_I2C_DONE
|
690 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_SOFT_RESET
);
692 WREG32(AVIVO_DC_I2C_RESET
, 0);
694 WREG32(AVIVO_DC_I2C_DATA
, ((p
->addr
<< 1) & 0xff) | 0x1);
695 WREG32(AVIVO_DC_I2C_CONTROL3
, AVIVO_DC_I2C_TIME_LIMIT(48));
696 WREG32(AVIVO_DC_I2C_CONTROL2
, (AVIVO_DC_I2C_ADDR_COUNT(1) |
697 AVIVO_DC_I2C_DATA_COUNT(current_count
) |
699 WREG32(AVIVO_DC_I2C_CONTROL1
, reg
| AVIVO_DC_I2C_RECEIVE
);
700 WREG32(AVIVO_DC_I2C_STATUS1
, AVIVO_DC_I2C_GO
);
701 for (j
= 0; j
< 200; j
++) {
703 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
704 if (tmp
& AVIVO_DC_I2C_GO
)
706 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
707 if (tmp
& AVIVO_DC_I2C_DONE
)
710 DRM_DEBUG("i2c read error 0x%08x\n", tmp
);
711 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_ABORT
);
716 for (j
= 0; j
< current_count
; j
++)
717 p
->buf
[buffer_offset
+ j
] = RREG32(AVIVO_DC_I2C_DATA
) & 0xff;
718 remaining
-= current_count
;
719 buffer_offset
+= current_count
;
726 current_count
= remaining
;
727 WREG32(AVIVO_DC_I2C_STATUS1
, (AVIVO_DC_I2C_DONE
|
730 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_SOFT_RESET
);
732 WREG32(AVIVO_DC_I2C_RESET
, 0);
734 WREG32(AVIVO_DC_I2C_DATA
, (p
->addr
<< 1) & 0xff);
735 for (j
= 0; j
< current_count
; j
++)
736 WREG32(AVIVO_DC_I2C_DATA
, p
->buf
[buffer_offset
+ j
]);
738 WREG32(AVIVO_DC_I2C_CONTROL3
, AVIVO_DC_I2C_TIME_LIMIT(48));
739 WREG32(AVIVO_DC_I2C_CONTROL2
, (AVIVO_DC_I2C_ADDR_COUNT(1) |
740 AVIVO_DC_I2C_DATA_COUNT(current_count
) |
742 WREG32(AVIVO_DC_I2C_CONTROL1
, reg
);
743 WREG32(AVIVO_DC_I2C_STATUS1
, AVIVO_DC_I2C_GO
);
744 for (j
= 0; j
< 200; j
++) {
746 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
747 if (tmp
& AVIVO_DC_I2C_GO
)
749 tmp
= RREG32(AVIVO_DC_I2C_STATUS1
);
750 if (tmp
& AVIVO_DC_I2C_DONE
)
753 DRM_DEBUG("i2c write error 0x%08x\n", tmp
);
754 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_ABORT
);
759 remaining
-= current_count
;
760 buffer_offset
+= current_count
;
766 WREG32(AVIVO_DC_I2C_STATUS1
, (AVIVO_DC_I2C_DONE
|
769 WREG32(AVIVO_DC_I2C_RESET
, AVIVO_DC_I2C_SOFT_RESET
);
771 WREG32(AVIVO_DC_I2C_RESET
, 0);
773 WREG32(AVIVO_DC_I2C_ARBITRATION
, AVIVO_DC_I2C_SW_DONE_USING_I2C
);
774 WREG32(AVIVO_DC_I2C_CONTROL1
, saved1
);
775 WREG32(0x494, saved2
);
776 tmp
= RREG32(RADEON_BIOS_6_SCRATCH
);
777 tmp
&= ~ATOM_S6_HW_I2C_BUSY_STATE
;
778 WREG32(RADEON_BIOS_6_SCRATCH
, tmp
);
780 mutex_unlock(&rdev
->pm
.mutex
);
781 mutex_unlock(&rdev
->dc_hw_i2c_mutex
);
786 static int radeon_hw_i2c_xfer(struct i2c_adapter
*i2c_adap
,
787 struct i2c_msg
*msgs
, int num
)
789 struct radeon_i2c_chan
*i2c
= i2c_get_adapdata(i2c_adap
);
790 struct radeon_device
*rdev
= i2c
->dev
->dev_private
;
791 struct radeon_i2c_bus_rec
*rec
= &i2c
->rec
;
794 switch (rdev
->family
) {
813 ret
= r100_hw_i2c_xfer(i2c_adap
, msgs
, num
);
818 /* XXX fill in hw i2c implementation */
827 ret
= r100_hw_i2c_xfer(i2c_adap
, msgs
, num
);
829 ret
= r500_hw_i2c_xfer(i2c_adap
, msgs
, num
);
835 /* XXX fill in hw i2c implementation */
845 /* XXX fill in hw i2c implementation */
852 /* XXX fill in hw i2c implementation */
855 DRM_ERROR("i2c: unhandled radeon chip\n");
863 static u32
radeon_hw_i2c_func(struct i2c_adapter
*adap
)
865 return I2C_FUNC_I2C
| I2C_FUNC_SMBUS_EMUL
;
868 static const struct i2c_algorithm radeon_i2c_algo
= {
869 .master_xfer
= radeon_hw_i2c_xfer
,
870 .functionality
= radeon_hw_i2c_func
,
873 struct radeon_i2c_chan
*radeon_i2c_create(struct drm_device
*dev
,
874 struct radeon_i2c_bus_rec
*rec
,
877 struct radeon_device
*rdev
= dev
->dev_private
;
878 struct radeon_i2c_chan
*i2c
;
881 i2c
= kzalloc(sizeof(struct radeon_i2c_chan
), GFP_KERNEL
);
886 i2c
->adapter
.owner
= THIS_MODULE
;
888 i2c_set_adapdata(&i2c
->adapter
, i2c
);
892 ((rdev
->family
<= CHIP_RS480
) ||
893 ((rdev
->family
>= CHIP_RV515
) && (rdev
->family
<= CHIP_R580
))))) {
894 /* set the radeon hw i2c adapter */
895 sprintf(i2c
->adapter
.name
, "Radeon i2c hw bus %s", name
);
896 i2c
->adapter
.algo
= &radeon_i2c_algo
;
897 ret
= i2c_add_adapter(&i2c
->adapter
);
899 DRM_ERROR("Failed to register hw i2c %s\n", name
);
903 /* set the radeon bit adapter */
904 sprintf(i2c
->adapter
.name
, "Radeon i2c bit bus %s", name
);
905 i2c
->adapter
.algo_data
= &i2c
->algo
.bit
;
906 i2c
->algo
.bit
.pre_xfer
= pre_xfer
;
907 i2c
->algo
.bit
.post_xfer
= post_xfer
;
908 i2c
->algo
.bit
.setsda
= set_data
;
909 i2c
->algo
.bit
.setscl
= set_clock
;
910 i2c
->algo
.bit
.getsda
= get_data
;
911 i2c
->algo
.bit
.getscl
= get_clock
;
912 i2c
->algo
.bit
.udelay
= 20;
913 /* vesa says 2.2 ms is enough, 1 jiffy doesn't seem to always
914 * make this, 2 jiffies is a lot more reliable */
915 i2c
->algo
.bit
.timeout
= 2;
916 i2c
->algo
.bit
.data
= i2c
;
917 ret
= i2c_bit_add_bus(&i2c
->adapter
);
919 DRM_ERROR("Failed to register bit i2c %s\n", name
);
931 struct radeon_i2c_chan
*radeon_i2c_create_dp(struct drm_device
*dev
,
932 struct radeon_i2c_bus_rec
*rec
,
935 struct radeon_i2c_chan
*i2c
;
938 i2c
= kzalloc(sizeof(struct radeon_i2c_chan
), GFP_KERNEL
);
943 i2c
->adapter
.owner
= THIS_MODULE
;
945 i2c_set_adapdata(&i2c
->adapter
, i2c
);
946 i2c
->adapter
.algo_data
= &i2c
->algo
.dp
;
947 i2c
->algo
.dp
.aux_ch
= radeon_dp_i2c_aux_ch
;
948 i2c
->algo
.dp
.address
= 0;
949 ret
= i2c_dp_aux_add_bus(&i2c
->adapter
);
951 DRM_INFO("Failed to register i2c %s\n", name
);
962 void radeon_i2c_destroy(struct radeon_i2c_chan
*i2c
)
966 i2c_del_adapter(&i2c
->adapter
);
970 struct drm_encoder
*radeon_best_encoder(struct drm_connector
*connector
)
975 void radeon_i2c_get_byte(struct radeon_i2c_chan
*i2c_bus
,
982 struct i2c_msg msgs
[] = {
1000 if (i2c_transfer(&i2c_bus
->adapter
, msgs
, 2) == 2) {
1002 DRM_DEBUG("val = 0x%02x\n", *val
);
1004 DRM_ERROR("i2c 0x%02x 0x%02x read failed\n",
1009 void radeon_i2c_put_byte(struct radeon_i2c_chan
*i2c_bus
,
1015 struct i2c_msg msg
= {
1025 if (i2c_transfer(&i2c_bus
->adapter
, &msg
, 1) != 1)
1026 DRM_ERROR("i2c 0x%02x 0x%02x write failed\n",