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 static int riva_setup_i2c_bus(struct riva_i2c_chan *chan, const char *name)
99 strcpy(chan->adapter.name, name);
100 chan->adapter.owner = THIS_MODULE;
101 chan->adapter.id = I2C_HW_B_RIVA;
102 chan->adapter.algo_data = &chan->algo;
103 chan->adapter.dev.parent = &chan->par->pdev->dev;
104 chan->algo.setsda = riva_gpio_setsda;
105 chan->algo.setscl = riva_gpio_setscl;
106 chan->algo.getsda = riva_gpio_getsda;
107 chan->algo.getscl = riva_gpio_getscl;
108 chan->algo.udelay = 40;
109 chan->algo.timeout = msecs_to_jiffies(2);
110 chan->algo.data = chan;
112 i2c_set_adapdata(&chan->adapter, chan);
114 /* Raise SCL and SDA */
115 riva_gpio_setsda(chan, 1);
116 riva_gpio_setscl(chan, 1);
119 rc = i2c_bit_add_bus(&chan->adapter);
121 dev_dbg(&chan->par->pdev->dev, "I2C bus %s registered.\n", name);
123 dev_warn(&chan->par->pdev->dev,
124 "Failed to register I2C bus %s.\n", name);
131 void riva_create_i2c_busses(struct riva_par *par)
135 par->chan[0].par = par;
136 par->chan[1].par = par;
137 par->chan[2].par = par;
139 par->chan[0].ddc_base = 0x3e;
140 par->chan[1].ddc_base = 0x36;
141 par->chan[2].ddc_base = 0x50;
142 riva_setup_i2c_bus(&par->chan[0], "BUS1");
143 riva_setup_i2c_bus(&par->chan[1], "BUS2");
144 riva_setup_i2c_bus(&par->chan[2], "BUS3");
147 void riva_delete_i2c_busses(struct riva_par *par)
149 if (par->chan[0].par)
150 i2c_bit_del_bus(&par->chan[0].adapter);
151 par->chan[0].par = NULL;
153 if (par->chan[1].par)
154 i2c_bit_del_bus(&par->chan[1].adapter);
155 par->chan[1].par = NULL;
157 if (par->chan[2].par)
158 i2c_bit_del_bus(&par->chan[2].adapter);
159 par->chan[2].par = NULL;
162 static u8 *riva_do_probe_i2c_edid(struct riva_i2c_chan *chan)
165 struct i2c_msg msgs[] = {
181 buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
183 dev_warn(&chan->par->pdev->dev, "Out of memory!\n");
188 if (i2c_transfer(&chan->adapter, msgs, 2) == 2)
190 dev_dbg(&chan->par->pdev->dev, "Unable to read EDID block.\n");
195 int riva_probe_i2c_connector(struct riva_par *par, int conn, u8 **out_edid)
200 for (i = 0; i < 3; i++) {
201 /* Do the real work */
202 edid = riva_do_probe_i2c_edid(&par->chan[conn-1]);