2 cx88-i2c.c -- all the i2c code is here
4 Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
5 & Marcus Metzler (mocm@thp.uni-koeln.de)
6 (c) 2002 Yurij Sysoev <yurij@naturesoft.net>
7 (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define __NO_VERSION__ 1
27 #include <linux/module.h>
28 #include <linux/init.h>
34 /* ----------------------------------------------------------------------- */
36 void cx8800_bit_setscl(void *data, int state)
38 struct cx8800_dev *dev = data;
41 dev->i2c_state |= 0x02;
43 dev->i2c_state &= ~0x02;
44 cx_write(MO_I2C, dev->i2c_state);
48 void cx8800_bit_setsda(void *data, int state)
50 struct cx8800_dev *dev = data;
53 dev->i2c_state |= 0x01;
55 dev->i2c_state &= ~0x01;
56 cx_write(MO_I2C, dev->i2c_state);
60 static int cx8800_bit_getscl(void *data)
62 struct cx8800_dev *dev = data;
65 state = cx_read(MO_I2C);
66 return state & 0x02 ? 1 : 0;
69 static int cx8800_bit_getsda(void *data)
71 struct cx8800_dev *dev = data;
74 state = cx_read(MO_I2C);
78 /* ----------------------------------------------------------------------- */
81 static void cx8800_inc_use(struct i2c_adapter *adap)
86 static void cx8800_dec_use(struct i2c_adapter *adap)
92 static int attach_inform(struct i2c_client *client)
94 struct cx8800_dev *dev = i2c_get_adapdata(client->adapter);
96 if (dev->tuner_type != UNSET)
97 cx8800_call_i2c_clients(dev,TUNER_SET_TYPE,&dev->tuner_type);
99 if (1 /* fixme: debug */)
100 printk("%s: i2c attach [client=%s]\n",
101 dev->name, i2c_clientname(client));
105 void cx8800_call_i2c_clients(struct cx8800_dev *dev, unsigned int cmd, void *arg)
107 if (0 != dev->i2c_rc)
109 i2c_clients_command(&dev->i2c_adap, cmd, arg);
112 static struct i2c_algo_bit_data cx8800_i2c_algo_template = {
113 .setsda = cx8800_bit_setsda,
114 .setscl = cx8800_bit_setscl,
115 .getsda = cx8800_bit_getsda,
116 .getscl = cx8800_bit_getscl,
122 /* ----------------------------------------------------------------------- */
124 static struct i2c_adapter cx8800_i2c_adap_template = {
126 .owner = THIS_MODULE,
128 .inc_use = cx8800_inc_use,
129 .dec_use = cx8800_dec_use,
131 #ifdef I2C_ADAP_CLASS_TV_ANALOG
132 .class = I2C_ADAP_CLASS_TV_ANALOG,
134 I2C_DEVNAME("cx2388x"),
135 .id = I2C_HW_B_BT848,
136 .client_register = attach_inform,
139 static struct i2c_client cx8800_i2c_client_template = {
140 I2C_DEVNAME("cx88xx internal"),
144 /* init + register i2c algo-bit adapter */
145 int __devinit cx8800_i2c_init(struct cx8800_dev *dev)
147 memcpy(&dev->i2c_adap, &cx8800_i2c_adap_template,
148 sizeof(dev->i2c_adap));
149 memcpy(&dev->i2c_algo, &cx8800_i2c_algo_template,
150 sizeof(dev->i2c_algo));
151 memcpy(&dev->i2c_client, &cx8800_i2c_client_template,
152 sizeof(dev->i2c_client));
154 dev->i2c_adap.dev.parent = &dev->pci->dev;
155 strlcpy(dev->i2c_adap.name,dev->name,sizeof(dev->i2c_adap.name));
156 dev->i2c_algo.data = dev;
157 i2c_set_adapdata(&dev->i2c_adap,dev);
158 dev->i2c_adap.algo_data = &dev->i2c_algo;
159 dev->i2c_client.adapter = &dev->i2c_adap;
161 cx8800_bit_setscl(dev,1);
162 cx8800_bit_setsda(dev,1);
164 dev->i2c_rc = i2c_bit_add_bus(&dev->i2c_adap);
165 printk("%s: i2c register %s\n", dev->name,
166 (0 == dev->i2c_rc) ? "ok" : "FAILED");