2 * linux/drivers/video/savage/savagefb-i2c.c - S3 Savage DDC2
4 * Copyright 2004 Antonino A. Daplas <adaplas @pol.net>
6 * Based partly on rivafb-i2c.c
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
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/delay.h>
16 #include <linux/pci.h>
22 #define SAVAGE_DDC 0x50
24 #define VGA_CR_IX 0x3d4
25 #define VGA_CR_DATA 0x3d5
27 #define CR_SERIAL1 0xa0 /* I2C serial communications interface */
28 #define MM_SERIAL1 0xff20
29 #define CR_SERIAL2 0xb1 /* DDC2 monitor communications interface */
31 /* based on vt8365 documentation */
32 #define PROSAVAGE_I2C_ENAB 0x10
33 #define PROSAVAGE_I2C_SCL_OUT 0x01
34 #define PROSAVAGE_I2C_SDA_OUT 0x02
35 #define PROSAVAGE_I2C_SCL_IN 0x04
36 #define PROSAVAGE_I2C_SDA_IN 0x08
38 #define SAVAGE4_I2C_ENAB 0x00000020
39 #define SAVAGE4_I2C_SCL_OUT 0x00000001
40 #define SAVAGE4_I2C_SDA_OUT 0x00000002
41 #define SAVAGE4_I2C_SCL_IN 0x00000008
42 #define SAVAGE4_I2C_SDA_IN 0x00000010
44 static void savage4_gpio_setscl(void *data
, int val
)
46 struct savagefb_i2c_chan
*chan
= data
;
49 r
= readl(chan
->ioaddr
+ chan
->reg
);
51 r
|= SAVAGE4_I2C_SCL_OUT
;
53 r
&= ~SAVAGE4_I2C_SCL_OUT
;
54 writel(r
, chan
->ioaddr
+ chan
->reg
);
55 readl(chan
->ioaddr
+ chan
->reg
); /* flush posted write */
58 static void savage4_gpio_setsda(void *data
, int val
)
60 struct savagefb_i2c_chan
*chan
= data
;
63 r
= readl(chan
->ioaddr
+ chan
->reg
);
65 r
|= SAVAGE4_I2C_SDA_OUT
;
67 r
&= ~SAVAGE4_I2C_SDA_OUT
;
68 writel(r
, chan
->ioaddr
+ chan
->reg
);
69 readl(chan
->ioaddr
+ chan
->reg
); /* flush posted write */
72 static int savage4_gpio_getscl(void *data
)
74 struct savagefb_i2c_chan
*chan
= data
;
76 return (0 != (readl(chan
->ioaddr
+ chan
->reg
) & SAVAGE4_I2C_SCL_IN
));
79 static int savage4_gpio_getsda(void *data
)
81 struct savagefb_i2c_chan
*chan
= data
;
83 return (0 != (readl(chan
->ioaddr
+ chan
->reg
) & SAVAGE4_I2C_SDA_IN
));
86 static void prosavage_gpio_setscl(void* data
, int val
)
88 struct savagefb_i2c_chan
*chan
= data
;
91 r
= VGArCR(chan
->reg
, chan
->par
);
92 r
|= PROSAVAGE_I2C_ENAB
;
94 r
|= PROSAVAGE_I2C_SCL_OUT
;
96 r
&= ~PROSAVAGE_I2C_SCL_OUT
;
99 VGAwCR(chan
->reg
, r
, chan
->par
);
102 static void prosavage_gpio_setsda(void* data
, int val
)
104 struct savagefb_i2c_chan
*chan
= data
;
107 r
= VGArCR(chan
->reg
, chan
->par
);
108 r
|= PROSAVAGE_I2C_ENAB
;
110 r
|= PROSAVAGE_I2C_SDA_OUT
;
112 r
&= ~PROSAVAGE_I2C_SDA_OUT
;
115 VGAwCR(chan
->reg
, r
, chan
->par
);
118 static int prosavage_gpio_getscl(void* data
)
120 struct savagefb_i2c_chan
*chan
= data
;
122 return (VGArCR(chan
->reg
, chan
->par
) & PROSAVAGE_I2C_SCL_IN
) ? 1 : 0;
125 static int prosavage_gpio_getsda(void* data
)
127 struct savagefb_i2c_chan
*chan
= data
;
129 return (VGArCR(chan
->reg
, chan
->par
) & PROSAVAGE_I2C_SDA_IN
) ? 1 : 0;
132 static int savage_setup_i2c_bus(struct savagefb_i2c_chan
*chan
,
138 strcpy(chan
->adapter
.name
, name
);
139 chan
->adapter
.owner
= THIS_MODULE
;
140 chan
->adapter
.id
= I2C_HW_B_SAVAGE
;
141 chan
->adapter
.algo_data
= &chan
->algo
;
142 chan
->adapter
.dev
.parent
= &chan
->par
->pcidev
->dev
;
143 chan
->algo
.udelay
= 10;
144 chan
->algo
.timeout
= 20;
145 chan
->algo
.data
= chan
;
147 i2c_set_adapdata(&chan
->adapter
, chan
);
149 /* Raise SCL and SDA */
150 chan
->algo
.setsda(chan
, 1);
151 chan
->algo
.setscl(chan
, 1);
154 rc
= i2c_bit_add_bus(&chan
->adapter
);
157 dev_dbg(&chan
->par
->pcidev
->dev
,
158 "I2C bus %s registered.\n", name
);
160 dev_warn(&chan
->par
->pcidev
->dev
,
161 "Failed to register I2C bus %s.\n", name
);
168 void savagefb_create_i2c_busses(struct fb_info
*info
)
170 struct savagefb_par
*par
= info
->par
;
173 switch(info
->fix
.accel
) {
174 case FB_ACCEL_PROSAVAGE_DDRK
:
175 case FB_ACCEL_PROSAVAGE_PM
:
176 par
->chan
.reg
= CR_SERIAL2
;
177 par
->chan
.ioaddr
= par
->mmio
.vbase
;
178 par
->chan
.algo
.setsda
= prosavage_gpio_setsda
;
179 par
->chan
.algo
.setscl
= prosavage_gpio_setscl
;
180 par
->chan
.algo
.getsda
= prosavage_gpio_getsda
;
181 par
->chan
.algo
.getscl
= prosavage_gpio_getscl
;
183 case FB_ACCEL_SAVAGE4
:
184 case FB_ACCEL_SAVAGE2000
:
185 par
->chan
.reg
= 0xff20;
186 par
->chan
.ioaddr
= par
->mmio
.vbase
;
187 par
->chan
.algo
.setsda
= savage4_gpio_setsda
;
188 par
->chan
.algo
.setscl
= savage4_gpio_setscl
;
189 par
->chan
.algo
.getsda
= savage4_gpio_getsda
;
190 par
->chan
.algo
.getscl
= savage4_gpio_getscl
;
193 par
->chan
.par
= NULL
;
196 savage_setup_i2c_bus(&par
->chan
, "SAVAGE DDC2");
199 void savagefb_delete_i2c_busses(struct fb_info
*info
)
201 struct savagefb_par
*par
= info
->par
;
204 i2c_del_adapter(&par
->chan
.adapter
);
206 par
->chan
.par
= NULL
;
209 int savagefb_probe_i2c_connector(struct fb_info
*info
, u8
**out_edid
)
211 struct savagefb_par
*par
= info
->par
;
215 edid
= fb_ddc_read(&par
->chan
.adapter
);
220 /* try to get from firmware */
221 const u8
*e
= fb_firmware_edid(info
->device
);
224 edid
= kmemdup(e
, EDID_LENGTH
, GFP_KERNEL
);
229 return (edid
) ? 0 : 1;
232 MODULE_LICENSE("GPL");