2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Hardware accelerated Matrox Millennium I, II, Mystique, G100, G200, G400 and G450.
|
|
|
|
*
|
|
|
|
* (c) 1998-2002 Petr Vandrovec <vandrove@vc.cvut.cz>
|
|
|
|
*
|
|
|
|
* Version: 1.64 2002/06/10
|
|
|
|
*
|
|
|
|
* See matroxfb_base.c for contributors.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "matroxfb_base.h"
|
|
|
|
#include "matroxfb_maven.h"
|
|
|
|
#include <linux/i2c.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/i2c-algo-bit.h>
|
|
|
|
|
|
|
|
/* MGA-TVO I2C for G200, G400 */
|
|
|
|
#define MAT_CLK 0x20
|
|
|
|
#define MAT_DATA 0x10
|
|
|
|
/* primary head DDC for Mystique(?), G100, G200, G400 */
|
|
|
|
#define DDC1_CLK 0x08
|
|
|
|
#define DDC1_DATA 0x02
|
|
|
|
/* primary head DDC for Millennium, Millennium II */
|
|
|
|
#define DDC1B_CLK 0x10
|
|
|
|
#define DDC1B_DATA 0x04
|
|
|
|
/* secondary head DDC for G400 */
|
|
|
|
#define DDC2_CLK 0x04
|
|
|
|
#define DDC2_DATA 0x01
|
|
|
|
|
|
|
|
/******************************************************/
|
|
|
|
|
|
|
|
struct matroxfb_dh_maven_info {
|
|
|
|
struct i2c_bit_adapter maven;
|
|
|
|
struct i2c_bit_adapter ddc1;
|
|
|
|
struct i2c_bit_adapter ddc2;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int matroxfb_read_gpio(struct matrox_fb_info* minfo) {
|
|
|
|
unsigned long flags;
|
|
|
|
int v;
|
|
|
|
|
|
|
|
matroxfb_DAC_lock_irqsave(flags);
|
2009-09-23 07:47:49 +08:00
|
|
|
v = matroxfb_DAC_in(minfo, DAC_XGENIODATA);
|
2005-04-17 06:20:36 +08:00
|
|
|
matroxfb_DAC_unlock_irqrestore(flags);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void matroxfb_set_gpio(struct matrox_fb_info* minfo, int mask, int val) {
|
|
|
|
unsigned long flags;
|
|
|
|
int v;
|
|
|
|
|
|
|
|
matroxfb_DAC_lock_irqsave(flags);
|
2009-09-23 07:47:49 +08:00
|
|
|
v = (matroxfb_DAC_in(minfo, DAC_XGENIOCTRL) & mask) | val;
|
|
|
|
matroxfb_DAC_out(minfo, DAC_XGENIOCTRL, v);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* We must reset GENIODATA very often... XFree plays with this register */
|
2009-09-23 07:47:49 +08:00
|
|
|
matroxfb_DAC_out(minfo, DAC_XGENIODATA, 0x00);
|
2005-04-17 06:20:36 +08:00
|
|
|
matroxfb_DAC_unlock_irqrestore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* software I2C functions */
|
|
|
|
static inline void matroxfb_i2c_set(struct matrox_fb_info* minfo, int mask, int state) {
|
|
|
|
if (state)
|
|
|
|
state = 0;
|
|
|
|
else
|
|
|
|
state = mask;
|
|
|
|
matroxfb_set_gpio(minfo, ~mask, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void matroxfb_gpio_setsda(void* data, int state) {
|
|
|
|
struct i2c_bit_adapter* b = data;
|
|
|
|
matroxfb_i2c_set(b->minfo, b->mask.data, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void matroxfb_gpio_setscl(void* data, int state) {
|
|
|
|
struct i2c_bit_adapter* b = data;
|
|
|
|
matroxfb_i2c_set(b->minfo, b->mask.clock, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int matroxfb_gpio_getsda(void* data) {
|
|
|
|
struct i2c_bit_adapter* b = data;
|
|
|
|
return (matroxfb_read_gpio(b->minfo) & b->mask.data) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int matroxfb_gpio_getscl(void* data) {
|
|
|
|
struct i2c_bit_adapter* b = data;
|
|
|
|
return (matroxfb_read_gpio(b->minfo) & b->mask.clock) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2008-08-13 06:08:54 +08:00
|
|
|
static const struct i2c_algo_bit_data matrox_i2c_algo_template =
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-08-14 05:40:09 +08:00
|
|
|
.setsda = matroxfb_gpio_setsda,
|
|
|
|
.setscl = matroxfb_gpio_setscl,
|
|
|
|
.getsda = matroxfb_gpio_getsda,
|
|
|
|
.getscl = matroxfb_gpio_getscl,
|
|
|
|
.udelay = 10,
|
|
|
|
.timeout = 100,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int i2c_bus_reg(struct i2c_bit_adapter* b, struct matrox_fb_info* minfo,
|
2008-07-15 04:38:28 +08:00
|
|
|
unsigned int data, unsigned int clock, const char *name,
|
|
|
|
int class)
|
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
b->minfo = minfo;
|
|
|
|
b->mask.data = data;
|
|
|
|
b->mask.clock = clock;
|
2008-08-13 06:08:54 +08:00
|
|
|
b->adapter.owner = THIS_MODULE;
|
2007-05-02 05:26:28 +08:00
|
|
|
snprintf(b->adapter.name, sizeof(b->adapter.name), name,
|
2005-04-17 06:20:36 +08:00
|
|
|
minfo->fbcon.node);
|
|
|
|
i2c_set_adapdata(&b->adapter, b);
|
2008-07-15 04:38:28 +08:00
|
|
|
b->adapter.class = class;
|
2005-04-17 06:20:36 +08:00
|
|
|
b->adapter.algo_data = &b->bac;
|
2009-09-23 07:47:48 +08:00
|
|
|
b->adapter.dev.parent = &minfo->pcidev->dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
b->bac = matrox_i2c_algo_template;
|
|
|
|
b->bac.data = b;
|
|
|
|
err = i2c_bit_add_bus(&b->adapter);
|
|
|
|
b->initialized = !err;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_bit_bus_del(struct i2c_bit_adapter* b) {
|
|
|
|
if (b->initialized) {
|
2006-12-11 04:21:33 +08:00
|
|
|
i2c_del_adapter(&b->adapter);
|
2005-04-17 06:20:36 +08:00
|
|
|
b->initialized = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i2c_maven_done(struct matroxfb_dh_maven_info* minfo2) {
|
|
|
|
i2c_bit_bus_del(&minfo2->maven);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i2c_ddc1_done(struct matroxfb_dh_maven_info* minfo2) {
|
|
|
|
i2c_bit_bus_del(&minfo2->ddc1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i2c_ddc2_done(struct matroxfb_dh_maven_info* minfo2) {
|
|
|
|
i2c_bit_bus_del(&minfo2->ddc2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void* i2c_matroxfb_probe(struct matrox_fb_info* minfo) {
|
|
|
|
int err;
|
|
|
|
unsigned long flags;
|
|
|
|
struct matroxfb_dh_maven_info* m2info;
|
|
|
|
|
2007-02-12 16:55:07 +08:00
|
|
|
m2info = kzalloc(sizeof(*m2info), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!m2info)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
matroxfb_DAC_lock_irqsave(flags);
|
2009-09-23 07:47:49 +08:00
|
|
|
matroxfb_DAC_out(minfo, DAC_XGENIODATA, 0xFF);
|
|
|
|
matroxfb_DAC_out(minfo, DAC_XGENIOCTRL, 0x00);
|
2005-04-17 06:20:36 +08:00
|
|
|
matroxfb_DAC_unlock_irqrestore(flags);
|
|
|
|
|
2009-09-23 07:47:48 +08:00
|
|
|
switch (minfo->chip) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case MGA_2064:
|
|
|
|
case MGA_2164:
|
2008-07-15 04:38:28 +08:00
|
|
|
err = i2c_bus_reg(&m2info->ddc1, minfo,
|
|
|
|
DDC1B_DATA, DDC1B_CLK,
|
|
|
|
"DDC:fb%u #0", I2C_CLASS_DDC);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
2008-07-15 04:38:28 +08:00
|
|
|
err = i2c_bus_reg(&m2info->ddc1, minfo,
|
|
|
|
DDC1_DATA, DDC1_CLK,
|
|
|
|
"DDC:fb%u #0", I2C_CLASS_DDC);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
goto fail_ddc1;
|
2009-09-23 07:47:48 +08:00
|
|
|
if (minfo->devflags.dualhead) {
|
2008-07-15 04:38:28 +08:00
|
|
|
err = i2c_bus_reg(&m2info->ddc2, minfo,
|
|
|
|
DDC2_DATA, DDC2_CLK,
|
|
|
|
"DDC:fb%u #1", I2C_CLASS_DDC);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (err == -ENODEV) {
|
|
|
|
printk(KERN_INFO "i2c-matroxfb: VGA->TV plug detected, DDC unavailable.\n");
|
|
|
|
} else if (err)
|
|
|
|
printk(KERN_INFO "i2c-matroxfb: Could not register secondary output i2c bus. Continuing anyway.\n");
|
|
|
|
/* Register maven bus even on G450/G550 */
|
2008-07-15 04:38:28 +08:00
|
|
|
err = i2c_bus_reg(&m2info->maven, minfo,
|
|
|
|
MAT_DATA, MAT_CLK, "MAVEN:fb%u", 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (err)
|
|
|
|
printk(KERN_INFO "i2c-matroxfb: Could not register Maven i2c bus. Continuing anyway.\n");
|
2008-08-13 06:08:55 +08:00
|
|
|
else {
|
|
|
|
struct i2c_board_info maven_info = {
|
|
|
|
I2C_BOARD_INFO("maven", 0x1b),
|
|
|
|
};
|
|
|
|
unsigned short const addr_list[2] = {
|
|
|
|
0x1b, I2C_CLIENT_END
|
|
|
|
};
|
|
|
|
|
|
|
|
i2c_new_probed_device(&m2info->maven.adapter,
|
2010-08-12 00:20:56 +08:00
|
|
|
&maven_info, addr_list, NULL);
|
2008-08-13 06:08:55 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return m2info;
|
|
|
|
fail_ddc1:;
|
|
|
|
kfree(m2info);
|
|
|
|
printk(KERN_ERR "i2c-matroxfb: Could not register primary adapter DDC bus.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_matroxfb_remove(struct matrox_fb_info* minfo, void* data) {
|
|
|
|
struct matroxfb_dh_maven_info* m2info = data;
|
|
|
|
|
|
|
|
i2c_maven_done(m2info);
|
|
|
|
i2c_ddc2_done(m2info);
|
|
|
|
i2c_ddc1_done(m2info);
|
|
|
|
kfree(m2info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct matroxfb_driver i2c_matroxfb = {
|
|
|
|
.node = LIST_HEAD_INIT(i2c_matroxfb.node),
|
|
|
|
.name = "i2c-matroxfb",
|
|
|
|
.probe = i2c_matroxfb_probe,
|
|
|
|
.remove = i2c_matroxfb_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init i2c_matroxfb_init(void) {
|
|
|
|
if (matroxfb_register_driver(&i2c_matroxfb)) {
|
|
|
|
printk(KERN_ERR "i2c-matroxfb: failed to register driver\n");
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit i2c_matroxfb_exit(void) {
|
|
|
|
matroxfb_unregister_driver(&i2c_matroxfb);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR("(c) 1999-2002 Petr Vandrovec <vandrove@vc.cvut.cz>");
|
|
|
|
MODULE_DESCRIPTION("Support module providing I2C buses present on Matrox videocards");
|
|
|
|
|
|
|
|
module_init(i2c_matroxfb_init);
|
|
|
|
module_exit(i2c_matroxfb_exit);
|
|
|
|
/* no __setup required */
|
|
|
|
MODULE_LICENSE("GPL");
|