2 * linux/drivers/video/riva/fbdev-i2c.c - nVidia i2c
4 * Maintained by Ani Joshi <ajoshi@shell.unixbox.com>
6 * Copyright 2004 Antonino A. Daplas <adaplas @pol.net>
8 * Based on radeonfb-i2c.c
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive
15 #include <linux/config.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/sched.h>
19 #include <linux/delay.h>
20 #include <linux/pci.h>
22 #include <linux/jiffies.h>
31 static void riva_gpio_setscl(void* data
, int state
)
33 struct riva_i2c_chan
*chan
= (struct riva_i2c_chan
*)data
;
34 struct riva_par
*par
= chan
->par
;
37 VGA_WR08(par
->riva
.PCIO
, 0x3d4, chan
->ddc_base
+ 1);
38 val
= VGA_RD08(par
->riva
.PCIO
, 0x3d5) & 0xf0;
45 VGA_WR08(par
->riva
.PCIO
, 0x3d4, chan
->ddc_base
+ 1);
46 VGA_WR08(par
->riva
.PCIO
, 0x3d5, val
| 0x1);
49 static void riva_gpio_setsda(void* data
, int state
)
51 struct riva_i2c_chan
*chan
= (struct riva_i2c_chan
*)data
;
52 struct riva_par
*par
= chan
->par
;
55 VGA_WR08(par
->riva
.PCIO
, 0x3d4, chan
->ddc_base
+ 1);
56 val
= VGA_RD08(par
->riva
.PCIO
, 0x3d5) & 0xf0;
63 VGA_WR08(par
->riva
.PCIO
, 0x3d4, chan
->ddc_base
+ 1);
64 VGA_WR08(par
->riva
.PCIO
, 0x3d5, val
| 0x1);
67 static int riva_gpio_getscl(void* data
)
69 struct riva_i2c_chan
*chan
= (struct riva_i2c_chan
*)data
;
70 struct riva_par
*par
= chan
->par
;
73 VGA_WR08(par
->riva
.PCIO
, 0x3d4, chan
->ddc_base
);
74 if (VGA_RD08(par
->riva
.PCIO
, 0x3d5) & 0x04)
77 val
= VGA_RD08(par
->riva
.PCIO
, 0x3d5);
82 static int riva_gpio_getsda(void* data
)
84 struct riva_i2c_chan
*chan
= (struct riva_i2c_chan
*)data
;
85 struct riva_par
*par
= chan
->par
;
88 VGA_WR08(par
->riva
.PCIO
, 0x3d4, chan
->ddc_base
);
89 if (VGA_RD08(par
->riva
.PCIO
, 0x3d5) & 0x08)
95 #define I2C_ALGO_RIVA 0x0e0000
96 static int riva_setup_i2c_bus(struct riva_i2c_chan
*chan
, const char *name
)
100 strcpy(chan
->adapter
.name
, name
);
101 chan
->adapter
.owner
= THIS_MODULE
;
102 chan
->adapter
.id
= I2C_ALGO_RIVA
;
103 chan
->adapter
.algo_data
= &chan
->algo
;
104 chan
->adapter
.dev
.parent
= &chan
->par
->pdev
->dev
;
105 chan
->algo
.setsda
= riva_gpio_setsda
;
106 chan
->algo
.setscl
= riva_gpio_setscl
;
107 chan
->algo
.getsda
= riva_gpio_getsda
;
108 chan
->algo
.getscl
= riva_gpio_getscl
;
109 chan
->algo
.udelay
= 40;
110 chan
->algo
.timeout
= msecs_to_jiffies(2);
111 chan
->algo
.data
= chan
;
113 i2c_set_adapdata(&chan
->adapter
, chan
);
115 /* Raise SCL and SDA */
116 riva_gpio_setsda(chan
, 1);
117 riva_gpio_setscl(chan
, 1);
120 rc
= i2c_bit_add_bus(&chan
->adapter
);
122 dev_dbg(&chan
->par
->pdev
->dev
, "I2C bus %s registered.\n", name
);
124 dev_warn(&chan
->par
->pdev
->dev
,
125 "Failed to register I2C bus %s.\n", name
);
132 void riva_create_i2c_busses(struct riva_par
*par
)
136 par
->chan
[0].par
= par
;
137 par
->chan
[1].par
= par
;
138 par
->chan
[2].par
= par
;
140 par
->chan
[0].ddc_base
= 0x3e;
141 par
->chan
[1].ddc_base
= 0x36;
142 par
->chan
[2].ddc_base
= 0x50;
143 riva_setup_i2c_bus(&par
->chan
[0], "BUS1");
144 riva_setup_i2c_bus(&par
->chan
[1], "BUS2");
145 riva_setup_i2c_bus(&par
->chan
[2], "BUS3");
148 void riva_delete_i2c_busses(struct riva_par
*par
)
150 if (par
->chan
[0].par
)
151 i2c_bit_del_bus(&par
->chan
[0].adapter
);
152 par
->chan
[0].par
= NULL
;
154 if (par
->chan
[1].par
)
155 i2c_bit_del_bus(&par
->chan
[1].adapter
);
156 par
->chan
[1].par
= NULL
;
158 if (par
->chan
[2].par
)
159 i2c_bit_del_bus(&par
->chan
[2].adapter
);
160 par
->chan
[2].par
= NULL
;
163 static u8
*riva_do_probe_i2c_edid(struct riva_i2c_chan
*chan
)
166 struct i2c_msg msgs
[] = {
182 buf
= kmalloc(EDID_LENGTH
, GFP_KERNEL
);
184 dev_warn(&chan
->par
->pdev
->dev
, "Out of memory!\n");
189 if (i2c_transfer(&chan
->adapter
, msgs
, 2) == 2)
191 dev_dbg(&chan
->par
->pdev
->dev
, "Unable to read EDID block.\n");
196 int riva_probe_i2c_connector(struct riva_par
*par
, int conn
, u8
**out_edid
)
201 for (i
= 0; i
< 3; i
++) {
202 /* Do the real work */
203 edid
= riva_do_probe_i2c_edid(&par
->chan
[conn
-1]);