1 #include <linux/module.h>
2 #include <linux/kernel.h>
3 #include <linux/sched.h>
4 #include <linux/delay.h>
10 #include <linux/i2c-id.h>
11 #include <linux/i2c-algo-bit.h>
15 #include <video/radeon.h>
19 #define RADEON_DDC 0x50
21 static void radeon_gpio_setscl(void* data
, int state
)
23 struct radeon_i2c_chan
*chan
= data
;
24 struct radeonfb_info
*rinfo
= chan
->rinfo
;
27 val
= INREG(chan
->ddc_reg
) & ~(VGA_DDC_CLK_OUT_EN
);
29 val
|= VGA_DDC_CLK_OUT_EN
;
31 OUTREG(chan
->ddc_reg
, val
);
32 (void)INREG(chan
->ddc_reg
);
35 static void radeon_gpio_setsda(void* data
, int state
)
37 struct radeon_i2c_chan
*chan
= data
;
38 struct radeonfb_info
*rinfo
= chan
->rinfo
;
41 val
= INREG(chan
->ddc_reg
) & ~(VGA_DDC_DATA_OUT_EN
);
43 val
|= VGA_DDC_DATA_OUT_EN
;
45 OUTREG(chan
->ddc_reg
, val
);
46 (void)INREG(chan
->ddc_reg
);
49 static int radeon_gpio_getscl(void* data
)
51 struct radeon_i2c_chan
*chan
= data
;
52 struct radeonfb_info
*rinfo
= chan
->rinfo
;
55 val
= INREG(chan
->ddc_reg
);
57 return (val
& VGA_DDC_CLK_INPUT
) ? 1 : 0;
60 static int radeon_gpio_getsda(void* data
)
62 struct radeon_i2c_chan
*chan
= data
;
63 struct radeonfb_info
*rinfo
= chan
->rinfo
;
66 val
= INREG(chan
->ddc_reg
);
68 return (val
& VGA_DDC_DATA_INPUT
) ? 1 : 0;
71 static int radeon_setup_i2c_bus(struct radeon_i2c_chan
*chan
, const char *name
)
75 strcpy(chan
->adapter
.name
, name
);
76 chan
->adapter
.owner
= THIS_MODULE
;
77 chan
->adapter
.id
= I2C_HW_B_RADEON
;
78 chan
->adapter
.algo_data
= &chan
->algo
;
79 chan
->adapter
.dev
.parent
= &chan
->rinfo
->pdev
->dev
;
80 chan
->algo
.setsda
= radeon_gpio_setsda
;
81 chan
->algo
.setscl
= radeon_gpio_setscl
;
82 chan
->algo
.getsda
= radeon_gpio_getsda
;
83 chan
->algo
.getscl
= radeon_gpio_getscl
;
84 chan
->algo
.udelay
= 40;
85 chan
->algo
.timeout
= 20;
86 chan
->algo
.data
= chan
;
88 i2c_set_adapdata(&chan
->adapter
, chan
);
90 /* Raise SCL and SDA */
91 radeon_gpio_setsda(chan
, 1);
92 radeon_gpio_setscl(chan
, 1);
95 rc
= i2c_bit_add_bus(&chan
->adapter
);
97 dev_dbg(&chan
->rinfo
->pdev
->dev
, "I2C bus %s registered.\n", name
);
99 dev_warn(&chan
->rinfo
->pdev
->dev
, "Failed to register I2C bus %s.\n", name
);
103 void radeon_create_i2c_busses(struct radeonfb_info
*rinfo
)
105 rinfo
->i2c
[0].rinfo
= rinfo
;
106 rinfo
->i2c
[0].ddc_reg
= GPIO_MONID
;
107 radeon_setup_i2c_bus(&rinfo
->i2c
[0], "monid");
109 rinfo
->i2c
[1].rinfo
= rinfo
;
110 rinfo
->i2c
[1].ddc_reg
= GPIO_DVI_DDC
;
111 radeon_setup_i2c_bus(&rinfo
->i2c
[1], "dvi");
113 rinfo
->i2c
[2].rinfo
= rinfo
;
114 rinfo
->i2c
[2].ddc_reg
= GPIO_VGA_DDC
;
115 radeon_setup_i2c_bus(&rinfo
->i2c
[2], "vga");
117 rinfo
->i2c
[3].rinfo
= rinfo
;
118 rinfo
->i2c
[3].ddc_reg
= GPIO_CRT2_DDC
;
119 radeon_setup_i2c_bus(&rinfo
->i2c
[3], "crt2");
122 void radeon_delete_i2c_busses(struct radeonfb_info
*rinfo
)
124 if (rinfo
->i2c
[0].rinfo
)
125 i2c_bit_del_bus(&rinfo
->i2c
[0].adapter
);
126 rinfo
->i2c
[0].rinfo
= NULL
;
128 if (rinfo
->i2c
[1].rinfo
)
129 i2c_bit_del_bus(&rinfo
->i2c
[1].adapter
);
130 rinfo
->i2c
[1].rinfo
= NULL
;
132 if (rinfo
->i2c
[2].rinfo
)
133 i2c_bit_del_bus(&rinfo
->i2c
[2].adapter
);
134 rinfo
->i2c
[2].rinfo
= NULL
;
136 if (rinfo
->i2c
[3].rinfo
)
137 i2c_bit_del_bus(&rinfo
->i2c
[3].adapter
);
138 rinfo
->i2c
[3].rinfo
= NULL
;
142 static u8
*radeon_do_probe_i2c_edid(struct radeon_i2c_chan
*chan
)
145 struct i2c_msg msgs
[] = {
158 buf
= kmalloc(EDID_LENGTH
, GFP_KERNEL
);
160 dev_warn(&chan
->rinfo
->pdev
->dev
, "Out of memory!\n");
165 if (i2c_transfer(&chan
->adapter
, msgs
, 2) == 2)
167 dev_dbg(&chan
->rinfo
->pdev
->dev
, "Unable to read EDID block.\n");
173 int radeon_probe_i2c_connector(struct radeonfb_info
*rinfo
, int conn
, u8
**out_edid
)
175 u32 reg
= rinfo
->i2c
[conn
-1].ddc_reg
;
179 OUTREG(reg
, INREG(reg
) &
180 ~(VGA_DDC_DATA_OUTPUT
| VGA_DDC_CLK_OUTPUT
));
182 OUTREG(reg
, INREG(reg
) & ~(VGA_DDC_CLK_OUT_EN
));
185 for (i
= 0; i
< 3; i
++) {
186 /* For some old monitors we need the
187 * following process to initialize/stop DDC
189 OUTREG(reg
, INREG(reg
) & ~(VGA_DDC_DATA_OUT_EN
));
193 OUTREG(reg
, INREG(reg
) & ~(VGA_DDC_CLK_OUT_EN
));
195 for (j
= 0; j
< 5; j
++) {
197 if (INREG(reg
) & VGA_DDC_CLK_INPUT
)
203 OUTREG(reg
, INREG(reg
) | VGA_DDC_DATA_OUT_EN
);
206 OUTREG(reg
, INREG(reg
) | VGA_DDC_CLK_OUT_EN
);
209 OUTREG(reg
, INREG(reg
) & ~(VGA_DDC_DATA_OUT_EN
));
213 /* Do the real work */
214 edid
= radeon_do_probe_i2c_edid(&rinfo
->i2c
[conn
-1]);
216 OUTREG(reg
, INREG(reg
) |
217 (VGA_DDC_DATA_OUT_EN
| VGA_DDC_CLK_OUT_EN
));
221 OUTREG(reg
, INREG(reg
) & ~(VGA_DDC_CLK_OUT_EN
));
223 for (j
= 0; j
< 10; j
++) {
225 if (INREG(reg
) & VGA_DDC_CLK_INPUT
)
229 OUTREG(reg
, INREG(reg
) & ~(VGA_DDC_DATA_OUT_EN
));
232 OUTREG(reg
, INREG(reg
) |
233 (VGA_DDC_DATA_OUT_EN
| VGA_DDC_CLK_OUT_EN
));
238 /* Release the DDC lines when done or the Apple Cinema HD display
241 OUTREG(reg
, INREG(reg
) & ~(VGA_DDC_CLK_OUT_EN
| VGA_DDC_DATA_OUT_EN
));
247 RTRACE("radeonfb: I2C (port %d) ... not found\n", conn
);
250 if (edid
[0x14] & 0x80) {
251 /* Fix detection using BIOS tables */
252 if (rinfo
->is_mobility
/*&& conn == ddc_dvi*/ &&
253 (INREG(LVDS_GEN_CNTL
) & LVDS_ON
)) {
254 RTRACE("radeonfb: I2C (port %d) ... found LVDS panel\n", conn
);
257 RTRACE("radeonfb: I2C (port %d) ... found TMDS panel\n", conn
);
261 RTRACE("radeonfb: I2C (port %d) ... found CRT display\n", conn
);