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/module.h>
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
18 #include <linux/delay.h>
19 #include <linux/pci.h>
21 #include <linux/jiffies.h>
30 static void riva_gpio_setscl(void* data, int state)
32 struct riva_i2c_chan *chan = data;
33 struct riva_par *par = chan->par;
36 VGA_WR08(par->riva.PCIO, 0x3d4, chan->ddc_base + 1);
37 val = VGA_RD08(par->riva.PCIO, 0x3d5) & 0xf0;
44 VGA_WR08(par->riva.PCIO, 0x3d4, chan->ddc_base + 1);
45 VGA_WR08(par->riva.PCIO, 0x3d5, val | 0x1);
48 static void riva_gpio_setsda(void* data, int state)
50 struct riva_i2c_chan *chan = data;
51 struct riva_par *par = chan->par;
54 VGA_WR08(par->riva.PCIO, 0x3d4, chan->ddc_base + 1);
55 val = VGA_RD08(par->riva.PCIO, 0x3d5) & 0xf0;
62 VGA_WR08(par->riva.PCIO, 0x3d4, chan->ddc_base + 1);
63 VGA_WR08(par->riva.PCIO, 0x3d5, val | 0x1);
66 static int riva_gpio_getscl(void* data)
68 struct riva_i2c_chan *chan = data;
69 struct riva_par *par = chan->par;
72 VGA_WR08(par->riva.PCIO, 0x3d4, chan->ddc_base);
73 if (VGA_RD08(par->riva.PCIO, 0x3d5) & 0x04)
76 val = VGA_RD08(par->riva.PCIO, 0x3d5);
81 static int riva_gpio_getsda(void* data)
83 struct riva_i2c_chan *chan = data;
84 struct riva_par *par = chan->par;
87 VGA_WR08(par->riva.PCIO, 0x3d4, chan->ddc_base);
88 if (VGA_RD08(par->riva.PCIO, 0x3d5) & 0x08)
94 static int riva_setup_i2c_bus(struct riva_i2c_chan *chan, const char *name)
98 strcpy(chan->adapter.name, name);
99 chan->adapter.owner = THIS_MODULE;
100 chan->adapter.id = I2C_HW_B_RIVA;
101 chan->adapter.algo_data = &chan->algo;
102 chan->adapter.dev.parent = &chan->par->pdev->dev;
103 chan->algo.setsda = riva_gpio_setsda;
104 chan->algo.setscl = riva_gpio_setscl;
105 chan->algo.getsda = riva_gpio_getsda;
106 chan->algo.getscl = riva_gpio_getscl;
107 chan->algo.udelay = 40;
108 chan->algo.timeout = msecs_to_jiffies(2);
109 chan->algo.data = chan;
111 i2c_set_adapdata(&chan->adapter, chan);
113 /* Raise SCL and SDA */
114 riva_gpio_setsda(chan, 1);
115 riva_gpio_setscl(chan, 1);
118 rc = i2c_bit_add_bus(&chan->adapter);
120 dev_dbg(&chan->par->pdev->dev, "I2C bus %s registered.\n", name);
122 dev_warn(&chan->par->pdev->dev,
123 "Failed to register I2C bus %s.\n", name);
130 void riva_create_i2c_busses(struct riva_par *par)
134 par->chan[0].par = par;
135 par->chan[1].par = par;
136 par->chan[2].par = par;
138 par->chan[0].ddc_base = 0x3e;
139 par->chan[1].ddc_base = 0x36;
140 par->chan[2].ddc_base = 0x50;
141 riva_setup_i2c_bus(&par->chan[0], "BUS1");
142 riva_setup_i2c_bus(&par->chan[1], "BUS2");
143 riva_setup_i2c_bus(&par->chan[2], "BUS3");
146 void riva_delete_i2c_busses(struct riva_par *par)
148 if (par->chan[0].par)
149 i2c_bit_del_bus(&par->chan[0].adapter);
150 par->chan[0].par = NULL;
152 if (par->chan[1].par)
153 i2c_bit_del_bus(&par->chan[1].adapter);
154 par->chan[1].par = NULL;
156 if (par->chan[2].par)
157 i2c_bit_del_bus(&par->chan[2].adapter);
158 par->chan[2].par = NULL;
161 static u8 *riva_do_probe_i2c_edid(struct riva_i2c_chan *chan)
164 struct i2c_msg msgs[] = {
180 buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
182 dev_warn(&chan->par->pdev->dev, "Out of memory!\n");
187 if (i2c_transfer(&chan->adapter, msgs, 2) == 2)
189 dev_dbg(&chan->par->pdev->dev, "Unable to read EDID block.\n");
194 int riva_probe_i2c_connector(struct riva_par *par, int conn, u8 **out_edid)
199 for (i = 0; i < 3; i++) {
200 /* Do the real work */
201 edid = riva_do_probe_i2c_edid(&par->chan[conn-1]);