aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/savage/savagefb-i2c.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/video/savage/savagefb-i2c.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/video/savage/savagefb-i2c.c')
-rw-r--r--drivers/video/savage/savagefb-i2c.c282
1 files changed, 282 insertions, 0 deletions
diff --git a/drivers/video/savage/savagefb-i2c.c b/drivers/video/savage/savagefb-i2c.c
new file mode 100644
index 000000000000..024a0cecff15
--- /dev/null
+++ b/drivers/video/savage/savagefb-i2c.c
@@ -0,0 +1,282 @@
1/*
2 * linux/drivers/video/savage/savagefb-i2c.c - S3 Savage DDC2
3 *
4 * Copyright 2004 Antonino A. Daplas <adaplas @pol.net>
5 *
6 * Based partly on rivafb-i2c.c
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive
10 * for more details.
11 */
12
13#include <linux/config.h>
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/sched.h>
17#include <linux/delay.h>
18#include <linux/pci.h>
19#include <linux/fb.h>
20
21#include <asm/io.h>
22#include "savagefb.h"
23
24#define SAVAGE_DDC 0x50
25
26#define VGA_CR_IX 0x3d4
27#define VGA_CR_DATA 0x3d5
28
29#define CR_SERIAL1 0xa0 /* I2C serial communications interface */
30#define MM_SERIAL1 0xff20
31#define CR_SERIAL2 0xb1 /* DDC2 monitor communications interface */
32
33/* based on vt8365 documentation */
34#define PROSAVAGE_I2C_ENAB 0x10
35#define PROSAVAGE_I2C_SCL_OUT 0x01
36#define PROSAVAGE_I2C_SDA_OUT 0x02
37#define PROSAVAGE_I2C_SCL_IN 0x04
38#define PROSAVAGE_I2C_SDA_IN 0x08
39
40#define SAVAGE4_I2C_ENAB 0x00000020
41#define SAVAGE4_I2C_SCL_OUT 0x00000001
42#define SAVAGE4_I2C_SDA_OUT 0x00000002
43#define SAVAGE4_I2C_SCL_IN 0x00000008
44#define SAVAGE4_I2C_SDA_IN 0x00000010
45
46#define SET_CR_IX(base, val) writeb((val), base + 0x8000 + VGA_CR_IX)
47#define SET_CR_DATA(base, val) writeb((val), base + 0x8000 + VGA_CR_DATA)
48#define GET_CR_DATA(base) readb(base + 0x8000 + VGA_CR_DATA)
49
50static void savage4_gpio_setscl(void *data, int val)
51{
52 struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
53 unsigned int r;
54
55 r = readl(chan->ioaddr + chan->reg);
56 if(val)
57 r |= SAVAGE4_I2C_SCL_OUT;
58 else
59 r &= ~SAVAGE4_I2C_SCL_OUT;
60 writel(r, chan->ioaddr + chan->reg);
61 readl(chan->ioaddr + chan->reg); /* flush posted write */
62}
63
64static void savage4_gpio_setsda(void *data, int val)
65{
66 struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
67
68 unsigned int r;
69 r = readl(chan->ioaddr + chan->reg);
70 if(val)
71 r |= SAVAGE4_I2C_SDA_OUT;
72 else
73 r &= ~SAVAGE4_I2C_SDA_OUT;
74 writel(r, chan->ioaddr + chan->reg);
75 readl(chan->ioaddr + chan->reg); /* flush posted write */
76}
77
78static int savage4_gpio_getscl(void *data)
79{
80 struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
81
82 return (0 != (readl(chan->ioaddr + chan->reg) & SAVAGE4_I2C_SCL_IN));
83}
84
85static int savage4_gpio_getsda(void *data)
86{
87 struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
88
89 return (0 != (readl(chan->ioaddr + chan->reg) & SAVAGE4_I2C_SDA_IN));
90}
91
92static void prosavage_gpio_setscl(void* data, int val)
93{
94 struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
95 u32 r;
96
97 SET_CR_IX(chan->ioaddr, chan->reg);
98 r = GET_CR_DATA(chan->ioaddr);
99 r |= PROSAVAGE_I2C_ENAB;
100 if (val) {
101 r |= PROSAVAGE_I2C_SCL_OUT;
102 } else {
103 r &= ~PROSAVAGE_I2C_SCL_OUT;
104 }
105 SET_CR_DATA(chan->ioaddr, r);
106}
107
108static void prosavage_gpio_setsda(void* data, int val)
109{
110 struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
111 unsigned int r;
112
113 SET_CR_IX(chan->ioaddr, chan->reg);
114 r = GET_CR_DATA(chan->ioaddr);
115 r |= PROSAVAGE_I2C_ENAB;
116 if (val) {
117 r |= PROSAVAGE_I2C_SDA_OUT;
118 } else {
119 r &= ~PROSAVAGE_I2C_SDA_OUT;
120 }
121 SET_CR_DATA(chan->ioaddr, r);
122}
123
124static int prosavage_gpio_getscl(void* data)
125{
126 struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
127
128 SET_CR_IX(chan->ioaddr, chan->reg);
129 return (0 != (GET_CR_DATA(chan->ioaddr) & PROSAVAGE_I2C_SCL_IN));
130}
131
132static int prosavage_gpio_getsda(void* data)
133{
134 struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
135
136 SET_CR_IX(chan->ioaddr, chan->reg);
137 return (0 != (GET_CR_DATA(chan->ioaddr) & PROSAVAGE_I2C_SDA_IN));
138}
139
140#define I2C_ALGO_SAVAGE 0x0f0000
141static int savage_setup_i2c_bus(struct savagefb_i2c_chan *chan,
142 const char *name)
143{
144 int (*add_bus)(struct i2c_adapter *) = symbol_get(i2c_bit_add_bus);
145 int rc = 0;
146
147 if (add_bus && chan->par) {
148 strcpy(chan->adapter.name, name);
149 chan->adapter.owner = THIS_MODULE;
150 chan->adapter.id = I2C_ALGO_SAVAGE;
151 chan->adapter.algo_data = &chan->algo;
152 chan->adapter.dev.parent = &chan->par->pcidev->dev;
153 chan->algo.udelay = 40;
154 chan->algo.mdelay = 5;
155 chan->algo.timeout = 20;
156 chan->algo.data = chan;
157
158 i2c_set_adapdata(&chan->adapter, chan);
159
160 /* Raise SCL and SDA */
161 chan->algo.setsda(chan, 1);
162 chan->algo.setscl(chan, 1);
163 udelay(20);
164
165 rc = add_bus(&chan->adapter);
166
167 if (rc == 0)
168 dev_dbg(&chan->par->pcidev->dev,
169 "I2C bus %s registered.\n", name);
170 else
171 dev_warn(&chan->par->pcidev->dev,
172 "Failed to register I2C bus %s.\n", name);
173
174 symbol_put(i2c_bit_add_bus);
175 } else
176 chan->par = NULL;
177
178 return rc;
179}
180
181void savagefb_create_i2c_busses(struct fb_info *info)
182{
183 struct savagefb_par *par = (struct savagefb_par *)info->par;
184 par->chan.par = par;
185
186 switch(info->fix.accel) {
187 case FB_ACCEL_PROSAVAGE_DDRK:
188 case FB_ACCEL_PROSAVAGE_PM:
189 par->chan.reg = CR_SERIAL2;
190 par->chan.ioaddr = par->mmio.vbase;
191 par->chan.algo.setsda = prosavage_gpio_setsda;
192 par->chan.algo.setscl = prosavage_gpio_setscl;
193 par->chan.algo.getsda = prosavage_gpio_getsda;
194 par->chan.algo.getscl = prosavage_gpio_getscl;
195 break;
196 case FB_ACCEL_SAVAGE4:
197 par->chan.reg = 0xff20;
198 par->chan.ioaddr = par->mmio.vbase;
199 par->chan.algo.setsda = savage4_gpio_setsda;
200 par->chan.algo.setscl = savage4_gpio_setscl;
201 par->chan.algo.getsda = savage4_gpio_getsda;
202 par->chan.algo.getscl = savage4_gpio_getscl;
203 break;
204 default:
205 par->chan.par = NULL;
206 }
207
208 savage_setup_i2c_bus(&par->chan, "SAVAGE DDC2");
209}
210
211void savagefb_delete_i2c_busses(struct fb_info *info)
212{
213 struct savagefb_par *par = (struct savagefb_par *)info->par;
214 int (*del_bus)(struct i2c_adapter *) =
215 symbol_get(i2c_bit_del_bus);
216
217 if (del_bus && par->chan.par) {
218 del_bus(&par->chan.adapter);
219 symbol_put(i2c_bit_del_bus);
220 }
221
222 par->chan.par = NULL;
223}
224
225static u8 *savage_do_probe_i2c_edid(struct savagefb_i2c_chan *chan)
226{
227 u8 start = 0x0;
228 int (*transfer)(struct i2c_adapter *, struct i2c_msg *, int) =
229 symbol_get(i2c_transfer);
230 struct i2c_msg msgs[] = {
231 {
232 .addr = SAVAGE_DDC,
233 .len = 1,
234 .buf = &start,
235 }, {
236 .addr = SAVAGE_DDC,
237 .flags = I2C_M_RD,
238 .len = EDID_LENGTH,
239 },
240 };
241 u8 *buf = NULL;
242
243 if (transfer && chan->par) {
244 buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
245
246 if (buf) {
247 msgs[1].buf = buf;
248
249 if (transfer(&chan->adapter, msgs, 2) != 2) {
250 dev_dbg(&chan->par->pcidev->dev,
251 "Unable to read EDID block.\n");
252 kfree(buf);
253 buf = NULL;
254 }
255 }
256
257 symbol_put(i2c_transfer);
258 }
259
260 return buf;
261}
262
263int savagefb_probe_i2c_connector(struct savagefb_par *par, u8 **out_edid)
264{
265 u8 *edid = NULL;
266 int i;
267
268 for (i = 0; i < 3; i++) {
269 /* Do the real work */
270 edid = savage_do_probe_i2c_edid(&par->chan);
271 if (edid)
272 break;
273 }
274 if (out_edid)
275 *out_edid = edid;
276 if (!edid)
277 return 1;
278
279 return 0;
280}
281
282MODULE_LICENSE("GPL");