3 #include <linux/module.h>
4 #include <linux/kernel.h>
5 #include <linux/delay.h>
10 #include <linux/i2c-id.h>
11 #include <linux/i2c-algo-bit.h>
15 #include <video/radeon.h>
18 static void radeon_gpio_setscl(void* data
, int state
)
20 struct radeon_i2c_chan
*chan
= data
;
21 struct radeonfb_info
*rinfo
= chan
->rinfo
;
24 val
= INREG(chan
->ddc_reg
) & ~(VGA_DDC_CLK_OUT_EN
);
26 val
|= VGA_DDC_CLK_OUT_EN
;
28 OUTREG(chan
->ddc_reg
, val
);
29 (void)INREG(chan
->ddc_reg
);
32 static void radeon_gpio_setsda(void* data
, int state
)
34 struct radeon_i2c_chan
*chan
= data
;
35 struct radeonfb_info
*rinfo
= chan
->rinfo
;
38 val
= INREG(chan
->ddc_reg
) & ~(VGA_DDC_DATA_OUT_EN
);
40 val
|= VGA_DDC_DATA_OUT_EN
;
42 OUTREG(chan
->ddc_reg
, val
);
43 (void)INREG(chan
->ddc_reg
);
46 static int radeon_gpio_getscl(void* data
)
48 struct radeon_i2c_chan
*chan
= data
;
49 struct radeonfb_info
*rinfo
= chan
->rinfo
;
52 val
= INREG(chan
->ddc_reg
);
54 return (val
& VGA_DDC_CLK_INPUT
) ? 1 : 0;
57 static int radeon_gpio_getsda(void* data
)
59 struct radeon_i2c_chan
*chan
= data
;
60 struct radeonfb_info
*rinfo
= chan
->rinfo
;
63 val
= INREG(chan
->ddc_reg
);
65 return (val
& VGA_DDC_DATA_INPUT
) ? 1 : 0;
68 static int radeon_setup_i2c_bus(struct radeon_i2c_chan
*chan
, const char *name
)
72 strcpy(chan
->adapter
.name
, name
);
73 chan
->adapter
.owner
= THIS_MODULE
;
74 chan
->adapter
.id
= I2C_HW_B_RADEON
;
75 chan
->adapter
.algo_data
= &chan
->algo
;
76 chan
->adapter
.dev
.parent
= &chan
->rinfo
->pdev
->dev
;
77 chan
->algo
.setsda
= radeon_gpio_setsda
;
78 chan
->algo
.setscl
= radeon_gpio_setscl
;
79 chan
->algo
.getsda
= radeon_gpio_getsda
;
80 chan
->algo
.getscl
= radeon_gpio_getscl
;
81 chan
->algo
.udelay
= 10;
82 chan
->algo
.timeout
= 20;
83 chan
->algo
.data
= chan
;
85 i2c_set_adapdata(&chan
->adapter
, chan
);
87 /* Raise SCL and SDA */
88 radeon_gpio_setsda(chan
, 1);
89 radeon_gpio_setscl(chan
, 1);
92 rc
= i2c_bit_add_bus(&chan
->adapter
);
94 dev_dbg(&chan
->rinfo
->pdev
->dev
, "I2C bus %s registered.\n", name
);
96 dev_warn(&chan
->rinfo
->pdev
->dev
, "Failed to register I2C bus %s.\n", name
);
100 void radeon_create_i2c_busses(struct radeonfb_info
*rinfo
)
102 rinfo
->i2c
[0].rinfo
= rinfo
;
103 rinfo
->i2c
[0].ddc_reg
= GPIO_MONID
;
104 radeon_setup_i2c_bus(&rinfo
->i2c
[0], "monid");
106 rinfo
->i2c
[1].rinfo
= rinfo
;
107 rinfo
->i2c
[1].ddc_reg
= GPIO_DVI_DDC
;
108 radeon_setup_i2c_bus(&rinfo
->i2c
[1], "dvi");
110 rinfo
->i2c
[2].rinfo
= rinfo
;
111 rinfo
->i2c
[2].ddc_reg
= GPIO_VGA_DDC
;
112 radeon_setup_i2c_bus(&rinfo
->i2c
[2], "vga");
114 rinfo
->i2c
[3].rinfo
= rinfo
;
115 rinfo
->i2c
[3].ddc_reg
= GPIO_CRT2_DDC
;
116 radeon_setup_i2c_bus(&rinfo
->i2c
[3], "crt2");
119 void radeon_delete_i2c_busses(struct radeonfb_info
*rinfo
)
121 if (rinfo
->i2c
[0].rinfo
)
122 i2c_del_adapter(&rinfo
->i2c
[0].adapter
);
123 rinfo
->i2c
[0].rinfo
= NULL
;
125 if (rinfo
->i2c
[1].rinfo
)
126 i2c_del_adapter(&rinfo
->i2c
[1].adapter
);
127 rinfo
->i2c
[1].rinfo
= NULL
;
129 if (rinfo
->i2c
[2].rinfo
)
130 i2c_del_adapter(&rinfo
->i2c
[2].adapter
);
131 rinfo
->i2c
[2].rinfo
= NULL
;
133 if (rinfo
->i2c
[3].rinfo
)
134 i2c_del_adapter(&rinfo
->i2c
[3].adapter
);
135 rinfo
->i2c
[3].rinfo
= NULL
;
138 int radeon_probe_i2c_connector(struct radeonfb_info
*rinfo
, int conn
,
141 u32 reg
= rinfo
->i2c
[conn
-1].ddc_reg
;
144 OUTREG(reg
, INREG(reg
) &
145 ~(VGA_DDC_DATA_OUTPUT
| VGA_DDC_CLK_OUTPUT
));
147 edid
= fb_ddc_read(&rinfo
->i2c
[conn
-1].adapter
);
152 pr_debug("radeonfb: I2C (port %d) ... not found\n", conn
);
155 if (edid
[0x14] & 0x80) {
156 /* Fix detection using BIOS tables */
157 if (rinfo
->is_mobility
/*&& conn == ddc_dvi*/ &&
158 (INREG(LVDS_GEN_CNTL
) & LVDS_ON
)) {
159 pr_debug("radeonfb: I2C (port %d) ... found LVDS panel\n", conn
);
162 pr_debug("radeonfb: I2C (port %d) ... found TMDS panel\n", conn
);
166 pr_debug("radeonfb: I2C (port %d) ... found CRT display\n", conn
);