提交 9f291634 编写于 作者: J Joseph Chan 提交者: Linus Torvalds

viafb: via_i2c.c, via_i2c.h, viamode.c, viamode.h

via_i2c.c, via_i2c.h: Implement i2c specification.
viamode.c, viamode.c: all support modes information.
Signed-off-by: NJoseph Chan <josephchan@via.com.tw>
Cc: Krzysztof Helt <krzysztof.h1@poczta.fm>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 b3a45d8e
/*
* Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
* Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation;
* either version 2, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE.See the GNU General Public License
* for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "global.h"
static void via_i2c_setscl(void *data, int state)
{
u8 val;
struct via_i2c_stuff *via_i2c_chan = (struct via_i2c_stuff *)data;
val = viafb_read_reg(VIASR, via_i2c_chan->i2c_port) & 0xF0;
if (state)
val |= 0x20;
else
val &= ~0x20;
switch (via_i2c_chan->i2c_port) {
case I2CPORTINDEX:
val |= 0x01;
break;
case GPIOPORTINDEX:
val |= 0x80;
break;
default:
DEBUG_MSG("via_i2c: specify wrong i2c port.\n");
}
viafb_write_reg(via_i2c_chan->i2c_port, VIASR, val);
}
static int via_i2c_getscl(void *data)
{
struct via_i2c_stuff *via_i2c_chan = (struct via_i2c_stuff *)data;
if (viafb_read_reg(VIASR, via_i2c_chan->i2c_port) & 0x08)
return 1;
return 0;
}
static int via_i2c_getsda(void *data)
{
struct via_i2c_stuff *via_i2c_chan = (struct via_i2c_stuff *)data;
if (viafb_read_reg(VIASR, via_i2c_chan->i2c_port) & 0x04)
return 1;
return 0;
}
static void via_i2c_setsda(void *data, int state)
{
u8 val;
struct via_i2c_stuff *via_i2c_chan = (struct via_i2c_stuff *)data;
val = viafb_read_reg(VIASR, via_i2c_chan->i2c_port) & 0xF0;
if (state)
val |= 0x10;
else
val &= ~0x10;
switch (via_i2c_chan->i2c_port) {
case I2CPORTINDEX:
val |= 0x01;
break;
case GPIOPORTINDEX:
val |= 0x40;
break;
default:
DEBUG_MSG("via_i2c: specify wrong i2c port.\n");
}
viafb_write_reg(via_i2c_chan->i2c_port, VIASR, val);
}
int viafb_i2c_readbyte(u8 slave_addr, u8 index, u8 *pdata)
{
u8 mm1[] = {0x00};
struct i2c_msg msgs[2];
*pdata = 0;
msgs[0].flags = 0;
msgs[1].flags = I2C_M_RD;
msgs[0].addr = msgs[1].addr = slave_addr / 2;
mm1[0] = index;
msgs[0].len = 1; msgs[1].len = 1;
msgs[0].buf = mm1; msgs[1].buf = pdata;
i2c_transfer(&viaparinfo->i2c_stuff.adapter, msgs, 2);
return 0;
}
int viafb_i2c_writebyte(u8 slave_addr, u8 index, u8 data)
{
u8 msg[2] = { index, data };
struct i2c_msg msgs;
msgs.flags = 0;
msgs.addr = slave_addr / 2;
msgs.len = 2;
msgs.buf = msg;
return i2c_transfer(&viaparinfo->i2c_stuff.adapter, &msgs, 1);
}
int viafb_i2c_readbytes(u8 slave_addr, u8 index, u8 *buff, int buff_len)
{
u8 mm1[] = {0x00};
struct i2c_msg msgs[2];
msgs[0].flags = 0;
msgs[1].flags = I2C_M_RD;
msgs[0].addr = msgs[1].addr = slave_addr / 2;
mm1[0] = index;
msgs[0].len = 1; msgs[1].len = buff_len;
msgs[0].buf = mm1; msgs[1].buf = buff;
i2c_transfer(&viaparinfo->i2c_stuff.adapter, msgs, 2);
return 0;
}
int viafb_create_i2c_bus(void *viapar)
{
int ret;
struct viafb_par *par = (struct viafb_par *)viapar;
strcpy(par->i2c_stuff.adapter.name, "via_i2c");
par->i2c_stuff.i2c_port = 0x0;
par->i2c_stuff.adapter.owner = THIS_MODULE;
par->i2c_stuff.adapter.id = 0x01FFFF;
par->i2c_stuff.adapter.class = 0;
par->i2c_stuff.adapter.algo_data = &par->i2c_stuff.algo;
par->i2c_stuff.adapter.dev.parent = NULL;
par->i2c_stuff.algo.setsda = via_i2c_setsda;
par->i2c_stuff.algo.setscl = via_i2c_setscl;
par->i2c_stuff.algo.getsda = via_i2c_getsda;
par->i2c_stuff.algo.getscl = via_i2c_getscl;
par->i2c_stuff.algo.udelay = 40;
par->i2c_stuff.algo.timeout = 20;
par->i2c_stuff.algo.data = &par->i2c_stuff;
i2c_set_adapdata(&par->i2c_stuff.adapter, &par->i2c_stuff);
/* Raise SCL and SDA */
par->i2c_stuff.i2c_port = I2CPORTINDEX;
via_i2c_setsda(&par->i2c_stuff, 1);
via_i2c_setscl(&par->i2c_stuff, 1);
par->i2c_stuff.i2c_port = GPIOPORTINDEX;
via_i2c_setsda(&par->i2c_stuff, 1);
via_i2c_setscl(&par->i2c_stuff, 1);
udelay(20);
ret = i2c_bit_add_bus(&par->i2c_stuff.adapter);
if (ret == 0)
DEBUG_MSG("I2C bus %s registered.\n",
par->i2c_stuff.adapter.name);
else
DEBUG_MSG("Failed to register I2C bus %s.\n",
par->i2c_stuff.adapter.name);
return ret;
}
void viafb_delete_i2c_buss(void *par)
{
i2c_del_adapter(&((struct viafb_par *)par)->i2c_stuff.adapter);
}
/*
* Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
* Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation;
* either version 2, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE.See the GNU General Public License
* for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __VIA_I2C_H__
#define __VIA_I2C_H__
#include <linux/i2c.h>
#include <linux/i2c-algo-bit.h>
struct via_i2c_stuff {
u16 i2c_port; /* GPIO or I2C port */
struct i2c_adapter adapter;
struct i2c_algo_bit_data algo;
};
#define I2CPORT 0x3c4
#define I2CPORTINDEX 0x31
#define GPIOPORT 0x3C4
#define GPIOPORTINDEX 0x2C
#define I2C_BUS 1
#define GPIO_BUS 2
#define DELAYPORT 0x3C3
int viafb_i2c_readbyte(u8 slave_addr, u8 index, u8 *pdata);
int viafb_i2c_writebyte(u8 slave_addr, u8 index, u8 data);
int viafb_i2c_readbytes(u8 slave_addr, u8 index, u8 *buff, int buff_len);
int viafb_create_i2c_bus(void *par);
void viafb_delete_i2c_buss(void *par);
#endif /* __VIA_I2C_H__ */
此差异已折叠。
/*
* Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
* Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation;
* either version 2, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE.See the GNU General Public License
* for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __VIAMODE_H__
#define __VIAMODE_H__
#include "global.h"
struct VPITTable {
unsigned char Misc;
unsigned char SR[StdSR];
unsigned char GR[StdGR];
unsigned char AR[StdAR];
};
struct VideoModeTable {
int ModeIndex;
struct crt_mode_table *crtc;
int mode_array;
};
struct patch_table {
int mode_index;
int table_length;
struct io_reg *io_reg_table;
};
struct res_map_refresh {
int hres;
int vres;
int pixclock;
int vmode_refresh;
};
#define NUM_TOTAL_RES_MAP_REFRESH ARRAY_SIZE(res_map_refresh_tbl)
#define NUM_TOTAL_CEA_MODES ARRAY_SIZE(CEA_HDMI_Modes)
#define NUM_TOTAL_CN400_ModeXregs ARRAY_SIZE(CN400_ModeXregs)
#define NUM_TOTAL_CN700_ModeXregs ARRAY_SIZE(CN700_ModeXregs)
#define NUM_TOTAL_KM400_ModeXregs ARRAY_SIZE(KM400_ModeXregs)
#define NUM_TOTAL_CX700_ModeXregs ARRAY_SIZE(CX700_ModeXregs)
#define NUM_TOTAL_VX800_ModeXregs ARRAY_SIZE(VX800_ModeXregs)
#define NUM_TOTAL_CLE266_ModeXregs ARRAY_SIZE(CLE266_ModeXregs)
#define NUM_TOTAL_PATCH_MODE ARRAY_SIZE(res_patch_table)
#define NUM_TOTAL_MODETABLE ARRAY_SIZE(CLE266Modes)
/********************/
/* Mode Table */
/********************/
/* 480x640 */
extern struct crt_mode_table CRTM480x640[1];
/* 640x480*/
extern struct crt_mode_table CRTM640x480[5];
/*720x480 (GTF)*/
extern struct crt_mode_table CRTM720x480[1];
/*720x576 (GTF)*/
extern struct crt_mode_table CRTM720x576[1];
/* 800x480 (CVT) */
extern struct crt_mode_table CRTM800x480[1];
/* 800x600*/
extern struct crt_mode_table CRTM800x600[5];
/* 848x480 (CVT) */
extern struct crt_mode_table CRTM848x480[1];
/*856x480 (GTF) convert to 852x480*/
extern struct crt_mode_table CRTM852x480[1];
/*1024x512 (GTF)*/
extern struct crt_mode_table CRTM1024x512[1];
/* 1024x600*/
extern struct crt_mode_table CRTM1024x600[1];
/* 1024x768*/
extern struct crt_mode_table CRTM1024x768[4];
/* 1152x864*/
extern struct crt_mode_table CRTM1152x864[1];
/* 1280x720 (HDMI 720P)*/
extern struct crt_mode_table CRTM1280x720[2];
/*1280x768 (GTF)*/
extern struct crt_mode_table CRTM1280x768[2];
/* 1280x800 (CVT) */
extern struct crt_mode_table CRTM1280x800[1];
/*1280x960*/
extern struct crt_mode_table CRTM1280x960[1];
/* 1280x1024*/
extern struct crt_mode_table CRTM1280x1024[3];
/* 1368x768 (GTF) */
extern struct crt_mode_table CRTM1368x768[1];
/*1440x1050 (GTF)*/
extern struct crt_mode_table CRTM1440x1050[1];
/* 1600x1200*/
extern struct crt_mode_table CRTM1600x1200[2];
/* 1680x1050 (CVT) */
extern struct crt_mode_table CRTM1680x1050[2];
/* 1680x1050 (CVT Reduce Blanking) */
extern struct crt_mode_table CRTM1680x1050_RB[1];
/* 1920x1080 (CVT)*/
extern struct crt_mode_table CRTM1920x1080[1];
/* 1920x1080 (CVT with Reduce Blanking) */
extern struct crt_mode_table CRTM1920x1080_RB[1];
/* 1920x1440*/
extern struct crt_mode_table CRTM1920x1440[2];
/* 1400x1050 (CVT) */
extern struct crt_mode_table CRTM1400x1050[2];
/* 1400x1050 (CVT Reduce Blanking) */
extern struct crt_mode_table CRTM1400x1050_RB[1];
/* 960x600 (CVT) */
extern struct crt_mode_table CRTM960x600[1];
/* 1000x600 (GTF) */
extern struct crt_mode_table CRTM1000x600[1];
/* 1024x576 (GTF) */
extern struct crt_mode_table CRTM1024x576[1];
/* 1088x612 (CVT) */
extern struct crt_mode_table CRTM1088x612[1];
/* 1152x720 (CVT) */
extern struct crt_mode_table CRTM1152x720[1];
/* 1200x720 (GTF) */
extern struct crt_mode_table CRTM1200x720[1];
/* 1280x600 (GTF) */
extern struct crt_mode_table CRTM1280x600[1];
/* 1360x768 (CVT) */
extern struct crt_mode_table CRTM1360x768[1];
/* 1360x768 (CVT Reduce Blanking) */
extern struct crt_mode_table CRTM1360x768_RB[1];
/* 1366x768 (GTF) */
extern struct crt_mode_table CRTM1366x768[2];
/* 1440x900 (CVT) */
extern struct crt_mode_table CRTM1440x900[2];
/* 1440x900 (CVT Reduce Blanking) */
extern struct crt_mode_table CRTM1440x900_RB[1];
/* 1600x900 (CVT) */
extern struct crt_mode_table CRTM1600x900[1];
/* 1600x900 (CVT Reduce Blanking) */
extern struct crt_mode_table CRTM1600x900_RB[1];
/* 1600x1024 (GTF) */
extern struct crt_mode_table CRTM1600x1024[1];
/* 1792x1344 (DMT) */
extern struct crt_mode_table CRTM1792x1344[1];
/* 1856x1392 (DMT) */
extern struct crt_mode_table CRTM1856x1392[1];
/* 1920x1200 (CVT) */
extern struct crt_mode_table CRTM1920x1200[1];
/* 1920x1200 (CVT with Reduce Blanking) */
extern struct crt_mode_table CRTM1920x1200_RB[1];
/* 2048x1536 (CVT) */
extern struct crt_mode_table CRTM2048x1536[1];
extern struct VideoModeTable CLE266Modes[47];
extern struct crt_mode_table CEAM1280x720[1];
extern struct crt_mode_table CEAM1920x1080[1];
extern struct VideoModeTable CEA_HDMI_Modes[2];
extern struct res_map_refresh res_map_refresh_tbl[61];
extern struct io_reg CN400_ModeXregs[52];
extern struct io_reg CN700_ModeXregs[66];
extern struct io_reg KM400_ModeXregs[55];
extern struct io_reg CX700_ModeXregs[58];
extern struct io_reg VX800_ModeXregs[58];
extern struct io_reg CLE266_ModeXregs[32];
extern struct io_reg PM1024x768[2];
extern struct patch_table res_patch_table[1];
extern struct VPITTable VPIT;
#endif /* __VIAMODE_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册