blob: 20800425c51ed5d1f5c4e08f82ecaf183d75deec [file] [log] [blame]
Chris Pascoefc40b262006-01-09 15:25:35 -02001/*
2
3 cx88-vp3054-i2c.c -- support for the secondary I2C bus of the
4 DNTV Live! DVB-T Pro (VP-3054), wired as:
5 GPIO[0] -> SCL, GPIO[1] -> SDA
6
7 (c) 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
8
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.
13
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.
18
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.
22
23*/
24
25#include <linux/module.h>
Chris Pascoefc40b262006-01-09 15:25:35 -020026#include <linux/init.h>
27
28#include <asm/io.h>
29
30#include "cx88.h"
31#include "cx88-vp3054-i2c.h"
32
Mauro Carvalho Chehab45bf2da2006-01-13 14:10:24 -020033MODULE_DESCRIPTION("driver for cx2388x VP3054 design");
34MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
35MODULE_LICENSE("GPL");
36
Chris Pascoefc40b262006-01-09 15:25:35 -020037/* ----------------------------------------------------------------------- */
38
39static void vp3054_bit_setscl(void *data, int state)
40{
41 struct cx8802_dev *dev = data;
42 struct cx88_core *core = dev->core;
Trent Piephof0ad9092007-10-14 02:52:16 -030043 struct vp3054_i2c_state *vp3054_i2c = dev->vp3054;
Chris Pascoefc40b262006-01-09 15:25:35 -020044
45 if (state) {
46 vp3054_i2c->state |= 0x0001; /* SCL high */
47 vp3054_i2c->state &= ~0x0100; /* external pullup */
48 } else {
49 vp3054_i2c->state &= ~0x0001; /* SCL low */
50 vp3054_i2c->state |= 0x0100; /* drive pin */
51 }
52 cx_write(MO_GP0_IO, 0x010000 | vp3054_i2c->state);
53 cx_read(MO_GP0_IO);
54}
55
56static void vp3054_bit_setsda(void *data, int state)
57{
58 struct cx8802_dev *dev = data;
59 struct cx88_core *core = dev->core;
Trent Piephof0ad9092007-10-14 02:52:16 -030060 struct vp3054_i2c_state *vp3054_i2c = dev->vp3054;
Chris Pascoefc40b262006-01-09 15:25:35 -020061
62 if (state) {
63 vp3054_i2c->state |= 0x0002; /* SDA high */
64 vp3054_i2c->state &= ~0x0200; /* tristate pin */
65 } else {
66 vp3054_i2c->state &= ~0x0002; /* SDA low */
67 vp3054_i2c->state |= 0x0200; /* drive pin */
68 }
69 cx_write(MO_GP0_IO, 0x020000 | vp3054_i2c->state);
70 cx_read(MO_GP0_IO);
71}
72
73static int vp3054_bit_getscl(void *data)
74{
75 struct cx8802_dev *dev = data;
76 struct cx88_core *core = dev->core;
77 u32 state;
78
79 state = cx_read(MO_GP0_IO);
80 return (state & 0x01) ? 1 : 0;
81}
82
83static int vp3054_bit_getsda(void *data)
84{
85 struct cx8802_dev *dev = data;
86 struct cx88_core *core = dev->core;
87 u32 state;
88
89 state = cx_read(MO_GP0_IO);
90 return (state & 0x02) ? 1 : 0;
91}
92
93/* ----------------------------------------------------------------------- */
94
Jean Delvare7e520d02007-07-01 18:37:51 -030095static const struct i2c_algo_bit_data vp3054_i2c_algo_template = {
Chris Pascoefc40b262006-01-09 15:25:35 -020096 .setsda = vp3054_bit_setsda,
97 .setscl = vp3054_bit_setscl,
98 .getsda = vp3054_bit_getsda,
99 .getscl = vp3054_bit_getscl,
100 .udelay = 16,
Chris Pascoefc40b262006-01-09 15:25:35 -0200101 .timeout = 200,
102};
103
104/* ----------------------------------------------------------------------- */
105
Chris Pascoefc40b262006-01-09 15:25:35 -0200106int vp3054_i2c_probe(struct cx8802_dev *dev)
107{
108 struct cx88_core *core = dev->core;
109 struct vp3054_i2c_state *vp3054_i2c;
110 int rc;
111
Trent Piepho6a59d642007-08-15 14:41:57 -0300112 if (core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
Chris Pascoefc40b262006-01-09 15:25:35 -0200113 return 0;
114
Trent Piephof0ad9092007-10-14 02:52:16 -0300115 vp3054_i2c = kzalloc(sizeof(*vp3054_i2c), GFP_KERNEL);
116 if (vp3054_i2c == NULL)
Chris Pascoefc40b262006-01-09 15:25:35 -0200117 return -ENOMEM;
Trent Piephof0ad9092007-10-14 02:52:16 -0300118 dev->vp3054 = vp3054_i2c;
Chris Pascoefc40b262006-01-09 15:25:35 -0200119
Chris Pascoefc40b262006-01-09 15:25:35 -0200120 memcpy(&vp3054_i2c->algo, &vp3054_i2c_algo_template,
121 sizeof(vp3054_i2c->algo));
Chris Pascoefc40b262006-01-09 15:25:35 -0200122
123 vp3054_i2c->adap.class |= I2C_CLASS_TV_DIGITAL;
124
125 vp3054_i2c->adap.dev.parent = &dev->pci->dev;
126 strlcpy(vp3054_i2c->adap.name, core->name,
127 sizeof(vp3054_i2c->adap.name));
Jean Delvare7e520d02007-07-01 18:37:51 -0300128 vp3054_i2c->adap.owner = THIS_MODULE;
129 vp3054_i2c->adap.id = I2C_HW_B_CX2388x;
Chris Pascoefc40b262006-01-09 15:25:35 -0200130 vp3054_i2c->algo.data = dev;
131 i2c_set_adapdata(&vp3054_i2c->adap, dev);
132 vp3054_i2c->adap.algo_data = &vp3054_i2c->algo;
Chris Pascoefc40b262006-01-09 15:25:35 -0200133
134 vp3054_bit_setscl(dev,1);
135 vp3054_bit_setsda(dev,1);
136
137 rc = i2c_bit_add_bus(&vp3054_i2c->adap);
138 if (0 != rc) {
139 printk("%s: vp3054_i2c register FAILED\n", core->name);
140
Trent Piephof0ad9092007-10-14 02:52:16 -0300141 kfree(dev->vp3054);
142 dev->vp3054 = NULL;
Chris Pascoefc40b262006-01-09 15:25:35 -0200143 }
144
145 return rc;
146}
147
148void vp3054_i2c_remove(struct cx8802_dev *dev)
149{
Trent Piephof0ad9092007-10-14 02:52:16 -0300150 struct vp3054_i2c_state *vp3054_i2c = dev->vp3054;
Chris Pascoefc40b262006-01-09 15:25:35 -0200151
152 if (vp3054_i2c == NULL ||
Trent Piepho6a59d642007-08-15 14:41:57 -0300153 dev->core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
Chris Pascoefc40b262006-01-09 15:25:35 -0200154 return;
155
Jean Delvare32697112006-12-10 21:21:33 +0100156 i2c_del_adapter(&vp3054_i2c->adap);
Chris Pascoefc40b262006-01-09 15:25:35 -0200157 kfree(vp3054_i2c);
158}
159
160EXPORT_SYMBOL(vp3054_i2c_probe);
161EXPORT_SYMBOL(vp3054_i2c_remove);