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