1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/module.h>
26#include <linux/slab.h>
27#include <linux/init.h>
28
29#include <asm/io.h>
30
31#include "cx88.h"
32#include "cx88-vp3054-i2c.h"
33
34MODULE_DESCRIPTION("driver for cx2388x VP3054 design");
35MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
36MODULE_LICENSE("GPL");
37
38
39
40static void vp3054_bit_setscl(void *data, int state)
41{
42 struct cx8802_dev *dev = data;
43 struct cx88_core *core = dev->core;
44 struct vp3054_i2c_state *vp3054_i2c = dev->vp3054;
45
46 if (state) {
47 vp3054_i2c->state |= 0x0001;
48 vp3054_i2c->state &= ~0x0100;
49 } else {
50 vp3054_i2c->state &= ~0x0001;
51 vp3054_i2c->state |= 0x0100;
52 }
53 cx_write(MO_GP0_IO, 0x010000 | vp3054_i2c->state);
54 cx_read(MO_GP0_IO);
55}
56
57static void vp3054_bit_setsda(void *data, int state)
58{
59 struct cx8802_dev *dev = data;
60 struct cx88_core *core = dev->core;
61 struct vp3054_i2c_state *vp3054_i2c = dev->vp3054;
62
63 if (state) {
64 vp3054_i2c->state |= 0x0002;
65 vp3054_i2c->state &= ~0x0200;
66 } else {
67 vp3054_i2c->state &= ~0x0002;
68 vp3054_i2c->state |= 0x0200;
69 }
70 cx_write(MO_GP0_IO, 0x020000 | vp3054_i2c->state);
71 cx_read(MO_GP0_IO);
72}
73
74static int vp3054_bit_getscl(void *data)
75{
76 struct cx8802_dev *dev = data;
77 struct cx88_core *core = dev->core;
78 u32 state;
79
80 state = cx_read(MO_GP0_IO);
81 return (state & 0x01) ? 1 : 0;
82}
83
84static int vp3054_bit_getsda(void *data)
85{
86 struct cx8802_dev *dev = data;
87 struct cx88_core *core = dev->core;
88 u32 state;
89
90 state = cx_read(MO_GP0_IO);
91 return (state & 0x02) ? 1 : 0;
92}
93
94
95
96static const struct i2c_algo_bit_data vp3054_i2c_algo_template = {
97 .setsda = vp3054_bit_setsda,
98 .setscl = vp3054_bit_setscl,
99 .getsda = vp3054_bit_getsda,
100 .getscl = vp3054_bit_getscl,
101 .udelay = 16,
102 .timeout = 200,
103};
104
105
106
107int vp3054_i2c_probe(struct cx8802_dev *dev)
108{
109 struct cx88_core *core = dev->core;
110 struct vp3054_i2c_state *vp3054_i2c;
111 int rc;
112
113 if (core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
114 return 0;
115
116 vp3054_i2c = kzalloc(sizeof(*vp3054_i2c), GFP_KERNEL);
117 if (vp3054_i2c == NULL)
118 return -ENOMEM;
119 dev->vp3054 = vp3054_i2c;
120
121 vp3054_i2c->algo = vp3054_i2c_algo_template;
122
123 vp3054_i2c->adap.dev.parent = &dev->pci->dev;
124 strlcpy(vp3054_i2c->adap.name, core->name,
125 sizeof(vp3054_i2c->adap.name));
126 vp3054_i2c->adap.owner = THIS_MODULE;
127 vp3054_i2c->algo.data = dev;
128 i2c_set_adapdata(&vp3054_i2c->adap, dev);
129 vp3054_i2c->adap.algo_data = &vp3054_i2c->algo;
130
131 vp3054_bit_setscl(dev,1);
132 vp3054_bit_setsda(dev,1);
133
134 rc = i2c_bit_add_bus(&vp3054_i2c->adap);
135 if (0 != rc) {
136 printk("%s: vp3054_i2c register FAILED\n", core->name);
137
138 kfree(dev->vp3054);
139 dev->vp3054 = NULL;
140 }
141
142 return rc;
143}
144
145void vp3054_i2c_remove(struct cx8802_dev *dev)
146{
147 struct vp3054_i2c_state *vp3054_i2c = dev->vp3054;
148
149 if (vp3054_i2c == NULL ||
150 dev->core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
151 return;
152
153 i2c_del_adapter(&vp3054_i2c->adap);
154 kfree(vp3054_i2c);
155}
156
157EXPORT_SYMBOL(vp3054_i2c_probe);
158EXPORT_SYMBOL(vp3054_i2c_remove);
159