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 #include <linux/module.h>
26 #include <linux/init.h>
32 /* ----------------------------------------------------------------------- */
34 void cx8800_bit_setscl(void *data, int state)
36 struct cx8800_dev *dev = data;
39 dev->i2c_state |= 0x02;
41 dev->i2c_state &= ~0x02;
42 cx_write(MO_I2C, dev->i2c_state);
46 void cx8800_bit_setsda(void *data, int state)
48 struct cx8800_dev *dev = data;
51 dev->i2c_state |= 0x01;
53 dev->i2c_state &= ~0x01;
54 cx_write(MO_I2C, dev->i2c_state);
58 static int cx8800_bit_getscl(void *data)
60 struct cx8800_dev *dev = data;
63 state = cx_read(MO_I2C);
64 return state & 0x02 ? 1 : 0;
67 static int cx8800_bit_getsda(void *data)
69 struct cx8800_dev *dev = data;
72 state = cx_read(MO_I2C);
76 /* ----------------------------------------------------------------------- */
79 static void cx8800_inc_use(struct i2c_adapter *adap)
84 static void cx8800_dec_use(struct i2c_adapter *adap)
90 static int attach_inform(struct i2c_client *client)
92 struct cx8800_dev *dev = i2c_get_adapdata(client->adapter);
94 if (dev->tuner_type != UNSET)
95 cx8800_call_i2c_clients(dev,TUNER_SET_TYPE,&dev->tuner_type);
97 if (1 /* fixme: debug */)
98 printk("%s: i2c attach [client=%s]\n",
99 dev->name, i2c_clientname(client));
103 void cx8800_call_i2c_clients(struct cx8800_dev *dev, unsigned int cmd, void *arg)
105 if (0 != dev->i2c_rc)
107 i2c_clients_command(&dev->i2c_adap, cmd, arg);
110 static struct i2c_algo_bit_data cx8800_i2c_algo_template = {
111 .setsda = cx8800_bit_setsda,
112 .setscl = cx8800_bit_setscl,
113 .getsda = cx8800_bit_getsda,
114 .getscl = cx8800_bit_getscl,
120 /* ----------------------------------------------------------------------- */
122 static struct i2c_adapter cx8800_i2c_adap_template = {
124 .owner = THIS_MODULE,
126 .inc_use = cx8800_inc_use,
127 .dec_use = cx8800_dec_use,
129 #ifdef I2C_CLASS_TV_ANALOG
130 .class = I2C_CLASS_TV_ANALOG,
132 I2C_DEVNAME("cx2388x"),
133 .id = I2C_HW_B_BT848,
134 .client_register = attach_inform,
137 static struct i2c_client cx8800_i2c_client_template = {
138 I2C_DEVNAME("cx88xx internal"),
142 /* init + register i2c algo-bit adapter */
143 int __devinit cx8800_i2c_init(struct cx8800_dev *dev)
145 memcpy(&dev->i2c_adap, &cx8800_i2c_adap_template,
146 sizeof(dev->i2c_adap));
147 memcpy(&dev->i2c_algo, &cx8800_i2c_algo_template,
148 sizeof(dev->i2c_algo));
149 memcpy(&dev->i2c_client, &cx8800_i2c_client_template,
150 sizeof(dev->i2c_client));
152 dev->i2c_adap.dev.parent = &dev->pci->dev;
153 strlcpy(dev->i2c_adap.name,dev->name,sizeof(dev->i2c_adap.name));
154 dev->i2c_algo.data = dev;
155 i2c_set_adapdata(&dev->i2c_adap,dev);
156 dev->i2c_adap.algo_data = &dev->i2c_algo;
157 dev->i2c_client.adapter = &dev->i2c_adap;
159 cx8800_bit_setscl(dev,1);
160 cx8800_bit_setsda(dev,1);
162 dev->i2c_rc = i2c_bit_add_bus(&dev->i2c_adap);
163 printk("%s: i2c register %s\n", dev->name,
164 (0 == dev->i2c_rc) ? "ok" : "FAILED");