[ARM] pxa: update defconfig for Verdex Pro
[linux-2.6/verdex.git] / drivers / video / via / via_i2c.c
blob15543e9682489b97fd04922b23d78f5311f7e0b4
1 /*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "global.h"
24 static void via_i2c_setscl(void *data, int state)
26 u8 val;
27 struct via_i2c_stuff *via_i2c_chan = (struct via_i2c_stuff *)data;
29 val = viafb_read_reg(VIASR, via_i2c_chan->i2c_port) & 0xF0;
30 if (state)
31 val |= 0x20;
32 else
33 val &= ~0x20;
34 switch (via_i2c_chan->i2c_port) {
35 case I2CPORTINDEX:
36 val |= 0x01;
37 break;
38 case GPIOPORTINDEX:
39 val |= 0x80;
40 break;
41 default:
42 DEBUG_MSG("via_i2c: specify wrong i2c port.\n");
44 viafb_write_reg(via_i2c_chan->i2c_port, VIASR, val);
47 static int via_i2c_getscl(void *data)
49 struct via_i2c_stuff *via_i2c_chan = (struct via_i2c_stuff *)data;
51 if (viafb_read_reg(VIASR, via_i2c_chan->i2c_port) & 0x08)
52 return 1;
53 return 0;
56 static int via_i2c_getsda(void *data)
58 struct via_i2c_stuff *via_i2c_chan = (struct via_i2c_stuff *)data;
60 if (viafb_read_reg(VIASR, via_i2c_chan->i2c_port) & 0x04)
61 return 1;
62 return 0;
65 static void via_i2c_setsda(void *data, int state)
67 u8 val;
68 struct via_i2c_stuff *via_i2c_chan = (struct via_i2c_stuff *)data;
70 val = viafb_read_reg(VIASR, via_i2c_chan->i2c_port) & 0xF0;
71 if (state)
72 val |= 0x10;
73 else
74 val &= ~0x10;
75 switch (via_i2c_chan->i2c_port) {
76 case I2CPORTINDEX:
77 val |= 0x01;
78 break;
79 case GPIOPORTINDEX:
80 val |= 0x40;
81 break;
82 default:
83 DEBUG_MSG("via_i2c: specify wrong i2c port.\n");
85 viafb_write_reg(via_i2c_chan->i2c_port, VIASR, val);
88 int viafb_i2c_readbyte(u8 slave_addr, u8 index, u8 *pdata)
90 u8 mm1[] = {0x00};
91 struct i2c_msg msgs[2];
93 *pdata = 0;
94 msgs[0].flags = 0;
95 msgs[1].flags = I2C_M_RD;
96 msgs[0].addr = msgs[1].addr = slave_addr / 2;
97 mm1[0] = index;
98 msgs[0].len = 1; msgs[1].len = 1;
99 msgs[0].buf = mm1; msgs[1].buf = pdata;
100 i2c_transfer(&viaparinfo->shared->i2c_stuff.adapter, msgs, 2);
102 return 0;
105 int viafb_i2c_writebyte(u8 slave_addr, u8 index, u8 data)
107 u8 msg[2] = { index, data };
108 struct i2c_msg msgs;
110 msgs.flags = 0;
111 msgs.addr = slave_addr / 2;
112 msgs.len = 2;
113 msgs.buf = msg;
114 return i2c_transfer(&viaparinfo->shared->i2c_stuff.adapter, &msgs, 1);
117 int viafb_i2c_readbytes(u8 slave_addr, u8 index, u8 *buff, int buff_len)
119 u8 mm1[] = {0x00};
120 struct i2c_msg msgs[2];
122 msgs[0].flags = 0;
123 msgs[1].flags = I2C_M_RD;
124 msgs[0].addr = msgs[1].addr = slave_addr / 2;
125 mm1[0] = index;
126 msgs[0].len = 1; msgs[1].len = buff_len;
127 msgs[0].buf = mm1; msgs[1].buf = buff;
128 i2c_transfer(&viaparinfo->shared->i2c_stuff.adapter, msgs, 2);
129 return 0;
132 int viafb_create_i2c_bus(void *viapar)
134 int ret;
135 struct via_i2c_stuff *i2c_stuff =
136 &((struct viafb_par *)viapar)->shared->i2c_stuff;
138 strcpy(i2c_stuff->adapter.name, "via_i2c");
139 i2c_stuff->i2c_port = 0x0;
140 i2c_stuff->adapter.owner = THIS_MODULE;
141 i2c_stuff->adapter.id = 0x01FFFF;
142 i2c_stuff->adapter.class = 0;
143 i2c_stuff->adapter.algo_data = &i2c_stuff->algo;
144 i2c_stuff->adapter.dev.parent = NULL;
145 i2c_stuff->algo.setsda = via_i2c_setsda;
146 i2c_stuff->algo.setscl = via_i2c_setscl;
147 i2c_stuff->algo.getsda = via_i2c_getsda;
148 i2c_stuff->algo.getscl = via_i2c_getscl;
149 i2c_stuff->algo.udelay = 40;
150 i2c_stuff->algo.timeout = 20;
151 i2c_stuff->algo.data = i2c_stuff;
153 i2c_set_adapdata(&i2c_stuff->adapter, i2c_stuff);
155 /* Raise SCL and SDA */
156 i2c_stuff->i2c_port = I2CPORTINDEX;
157 via_i2c_setsda(i2c_stuff, 1);
158 via_i2c_setscl(i2c_stuff, 1);
160 i2c_stuff->i2c_port = GPIOPORTINDEX;
161 via_i2c_setsda(i2c_stuff, 1);
162 via_i2c_setscl(i2c_stuff, 1);
163 udelay(20);
165 ret = i2c_bit_add_bus(&i2c_stuff->adapter);
166 if (ret == 0)
167 DEBUG_MSG("I2C bus %s registered.\n", i2c_stuff->adapter.name);
168 else
169 DEBUG_MSG("Failed to register I2C bus %s.\n",
170 i2c_stuff->adapter.name);
171 return ret;
174 void viafb_delete_i2c_buss(void *par)
176 i2c_del_adapter(&((struct viafb_par *)par)->shared->i2c_stuff.adapter);