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>
28 static void riva_gpio_setscl(void* data, int state)
30 struct riva_i2c_chan *chan = data;
31 struct riva_par *par = chan->par;
34 VGA_WR08(par->riva.PCIO, 0x3d4, chan->ddc_base + 1);
35 val = VGA_RD08(par->riva.PCIO, 0x3d5) & 0xf0;
42 VGA_WR08(par->riva.PCIO, 0x3d4, chan->ddc_base + 1);
43 VGA_WR08(par->riva.PCIO, 0x3d5, val | 0x1);
46 static void riva_gpio_setsda(void* data, int state)
48 struct riva_i2c_chan *chan = data;
49 struct riva_par *par = chan->par;
52 VGA_WR08(par->riva.PCIO, 0x3d4, chan->ddc_base + 1);
53 val = VGA_RD08(par->riva.PCIO, 0x3d5) & 0xf0;
60 VGA_WR08(par->riva.PCIO, 0x3d4, chan->ddc_base + 1);
61 VGA_WR08(par->riva.PCIO, 0x3d5, val | 0x1);
64 static int riva_gpio_getscl(void* data)
66 struct riva_i2c_chan *chan = data;
67 struct riva_par *par = chan->par;
70 VGA_WR08(par->riva.PCIO, 0x3d4, chan->ddc_base);
71 if (VGA_RD08(par->riva.PCIO, 0x3d5) & 0x04)
74 val = VGA_RD08(par->riva.PCIO, 0x3d5);
79 static int riva_gpio_getsda(void* data)
81 struct riva_i2c_chan *chan = data;
82 struct riva_par *par = chan->par;
85 VGA_WR08(par->riva.PCIO, 0x3d4, chan->ddc_base);
86 if (VGA_RD08(par->riva.PCIO, 0x3d5) & 0x08)
92 static int riva_setup_i2c_bus(struct riva_i2c_chan *chan, const char *name)
96 strcpy(chan->adapter.name, name);
97 chan->adapter.owner = THIS_MODULE;
98 chan->adapter.id = I2C_HW_B_RIVA;
99 chan->adapter.algo_data = &chan->algo;
100 chan->adapter.dev.parent = &chan->par->pdev->dev;
101 chan->algo.setsda = riva_gpio_setsda;
102 chan->algo.setscl = riva_gpio_setscl;
103 chan->algo.getsda = riva_gpio_getsda;
104 chan->algo.getscl = riva_gpio_getscl;
105 chan->algo.udelay = 40;
106 chan->algo.timeout = msecs_to_jiffies(2);
107 chan->algo.data = chan;
109 i2c_set_adapdata(&chan->adapter, chan);
111 /* Raise SCL and SDA */
112 riva_gpio_setsda(chan, 1);
113 riva_gpio_setscl(chan, 1);
116 rc = i2c_bit_add_bus(&chan->adapter);
118 dev_dbg(&chan->par->pdev->dev, "I2C bus %s registered.\n", name);
120 dev_warn(&chan->par->pdev->dev,
121 "Failed to register I2C bus %s.\n", name);
128 void riva_create_i2c_busses(struct riva_par *par)
132 par->chan[0].par = par;
133 par->chan[1].par = par;
134 par->chan[2].par = par;
136 par->chan[0].ddc_base = 0x3e;
137 par->chan[1].ddc_base = 0x36;
138 par->chan[2].ddc_base = 0x50;
139 riva_setup_i2c_bus(&par->chan[0], "BUS1");
140 riva_setup_i2c_bus(&par->chan[1], "BUS2");
141 riva_setup_i2c_bus(&par->chan[2], "BUS3");
144 void riva_delete_i2c_busses(struct riva_par *par)
146 if (par->chan[0].par)
147 i2c_del_adapter(&par->chan[0].adapter);
148 par->chan[0].par = NULL;
150 if (par->chan[1].par)
151 i2c_del_adapter(&par->chan[1].adapter);
152 par->chan[1].par = NULL;
154 if (par->chan[2].par)
155 i2c_del_adapter(&par->chan[2].adapter);
156 par->chan[2].par = NULL;
159 int riva_probe_i2c_connector(struct riva_par *par, int conn, u8 **out_edid)
163 edid = fb_ddc_read(&par->chan[conn-1].adapter);