sh_eth: R8A7740 supports packet shecksumming
[linux/fpc-iii.git] / drivers / media / pci / cx88 / cx88-vp3054-i2c.c
blob92876de3841ce4987167c7a59ca91956f47fd87c
1 /*
2 * cx88-vp3054-i2c.c -- support for the secondary I2C bus of the
3 * DNTV Live! DVB-T Pro (VP-3054), wired as:
4 * GPIO[0] -> SCL, GPIO[1] -> SDA
6 * (c) 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include "cx88.h"
20 #include "cx88-vp3054-i2c.h"
22 #include <linux/module.h>
23 #include <linux/slab.h>
24 #include <linux/init.h>
25 #include <linux/io.h>
27 MODULE_DESCRIPTION("driver for cx2388x VP3054 design");
28 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
29 MODULE_LICENSE("GPL");
31 /* ----------------------------------------------------------------------- */
33 static void vp3054_bit_setscl(void *data, int state)
35 struct cx8802_dev *dev = data;
36 struct cx88_core *core = dev->core;
37 struct vp3054_i2c_state *vp3054_i2c = dev->vp3054;
39 if (state) {
40 vp3054_i2c->state |= 0x0001; /* SCL high */
41 vp3054_i2c->state &= ~0x0100; /* external pullup */
42 } else {
43 vp3054_i2c->state &= ~0x0001; /* SCL low */
44 vp3054_i2c->state |= 0x0100; /* drive pin */
46 cx_write(MO_GP0_IO, 0x010000 | vp3054_i2c->state);
47 cx_read(MO_GP0_IO);
50 static void vp3054_bit_setsda(void *data, int state)
52 struct cx8802_dev *dev = data;
53 struct cx88_core *core = dev->core;
54 struct vp3054_i2c_state *vp3054_i2c = dev->vp3054;
56 if (state) {
57 vp3054_i2c->state |= 0x0002; /* SDA high */
58 vp3054_i2c->state &= ~0x0200; /* tristate pin */
59 } else {
60 vp3054_i2c->state &= ~0x0002; /* SDA low */
61 vp3054_i2c->state |= 0x0200; /* drive pin */
63 cx_write(MO_GP0_IO, 0x020000 | vp3054_i2c->state);
64 cx_read(MO_GP0_IO);
67 static int vp3054_bit_getscl(void *data)
69 struct cx8802_dev *dev = data;
70 struct cx88_core *core = dev->core;
71 u32 state;
73 state = cx_read(MO_GP0_IO);
74 return (state & 0x01) ? 1 : 0;
77 static int vp3054_bit_getsda(void *data)
79 struct cx8802_dev *dev = data;
80 struct cx88_core *core = dev->core;
81 u32 state;
83 state = cx_read(MO_GP0_IO);
84 return (state & 0x02) ? 1 : 0;
87 /* ----------------------------------------------------------------------- */
89 static const struct i2c_algo_bit_data vp3054_i2c_algo_template = {
90 .setsda = vp3054_bit_setsda,
91 .setscl = vp3054_bit_setscl,
92 .getsda = vp3054_bit_getsda,
93 .getscl = vp3054_bit_getscl,
94 .udelay = 16,
95 .timeout = 200,
98 /* ----------------------------------------------------------------------- */
100 int vp3054_i2c_probe(struct cx8802_dev *dev)
102 struct cx88_core *core = dev->core;
103 struct vp3054_i2c_state *vp3054_i2c;
104 int rc;
106 if (core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
107 return 0;
109 vp3054_i2c = kzalloc(sizeof(*vp3054_i2c), GFP_KERNEL);
110 if (!vp3054_i2c)
111 return -ENOMEM;
112 dev->vp3054 = vp3054_i2c;
114 vp3054_i2c->algo = vp3054_i2c_algo_template;
116 vp3054_i2c->adap.dev.parent = &dev->pci->dev;
117 strlcpy(vp3054_i2c->adap.name, core->name,
118 sizeof(vp3054_i2c->adap.name));
119 vp3054_i2c->adap.owner = THIS_MODULE;
120 vp3054_i2c->algo.data = dev;
121 i2c_set_adapdata(&vp3054_i2c->adap, dev);
122 vp3054_i2c->adap.algo_data = &vp3054_i2c->algo;
124 vp3054_bit_setscl(dev, 1);
125 vp3054_bit_setsda(dev, 1);
127 rc = i2c_bit_add_bus(&vp3054_i2c->adap);
128 if (rc != 0) {
129 pr_err("vp3054_i2c register FAILED\n");
131 kfree(dev->vp3054);
132 dev->vp3054 = NULL;
135 return rc;
137 EXPORT_SYMBOL(vp3054_i2c_probe);
139 void vp3054_i2c_remove(struct cx8802_dev *dev)
141 struct vp3054_i2c_state *vp3054_i2c = dev->vp3054;
143 if (!vp3054_i2c ||
144 dev->core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
145 return;
147 i2c_del_adapter(&vp3054_i2c->adap);
148 kfree(vp3054_i2c);
150 EXPORT_SYMBOL(vp3054_i2c_remove);