Commit | Line | Data |
---|---|---|
d56410e0 | 1 | /* |
1da177e4 LT |
2 | * bt856 - BT856A Digital Video Encoder (Rockwell Part) |
3 | * | |
4 | * Copyright (C) 1999 Mike Bernson <mike@mlb.org> | |
5 | * Copyright (C) 1998 Dave Perks <dperks@ibm.net> | |
6 | * | |
7 | * Modifications for LML33/DC10plus unified driver | |
8 | * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx> | |
9 | * | |
10 | * This code was modify/ported from the saa7111 driver written | |
11 | * by Dave Perks. | |
12 | * | |
13 | * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net> | |
14 | * - moved over to linux>=2.4.x i2c protocol (9/9/2002) | |
15 | * | |
16 | * This program is free software; you can redistribute it and/or modify | |
17 | * it under the terms of the GNU General Public License as published by | |
18 | * the Free Software Foundation; either version 2 of the License, or | |
19 | * (at your option) any later version. | |
20 | * | |
21 | * This program is distributed in the hope that it will be useful, | |
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | * GNU General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU General Public License | |
27 | * along with this program; if not, write to the Free Software | |
28 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
29 | */ | |
30 | ||
31 | #include <linux/module.h> | |
18f3fa1e | 32 | #include <linux/types.h> |
a8c26dfe | 33 | #include <linux/ioctl.h> |
18f3fa1e | 34 | #include <asm/uaccess.h> |
a8c26dfe HV |
35 | #include <linux/i2c.h> |
36 | #include <linux/i2c-id.h> | |
a91f56e7 HV |
37 | #include <linux/videodev2.h> |
38 | #include <media/v4l2-device.h> | |
39 | #include <media/v4l2-chip-ident.h> | |
2d26698e | 40 | #include <media/v4l2-i2c-drv.h> |
1da177e4 LT |
41 | |
42 | MODULE_DESCRIPTION("Brooktree-856A video encoder driver"); | |
43 | MODULE_AUTHOR("Mike Bernson & Dave Perks"); | |
44 | MODULE_LICENSE("GPL"); | |
45 | ||
ff699e6b | 46 | static int debug; |
1da177e4 LT |
47 | module_param(debug, int, 0); |
48 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); | |
49 | ||
a91f56e7 | 50 | |
1da177e4 LT |
51 | /* ----------------------------------------------------------------------- */ |
52 | ||
187565c4 HV |
53 | #define BT856_REG_OFFSET 0xDA |
54 | #define BT856_NR_REG 6 | |
1da177e4 LT |
55 | |
56 | struct bt856 { | |
a91f56e7 | 57 | struct v4l2_subdev sd; |
f49a5eae | 58 | unsigned char reg[BT856_NR_REG]; |
1da177e4 | 59 | |
107063c6 | 60 | v4l2_std_id norm; |
1da177e4 LT |
61 | }; |
62 | ||
a91f56e7 HV |
63 | static inline struct bt856 *to_bt856(struct v4l2_subdev *sd) |
64 | { | |
65 | return container_of(sd, struct bt856, sd); | |
66 | } | |
67 | ||
1da177e4 LT |
68 | /* ----------------------------------------------------------------------- */ |
69 | ||
a91f56e7 | 70 | static inline int bt856_write(struct bt856 *encoder, u8 reg, u8 value) |
1da177e4 | 71 | { |
a91f56e7 | 72 | struct i2c_client *client = v4l2_get_subdevdata(&encoder->sd); |
1da177e4 | 73 | |
187565c4 | 74 | encoder->reg[reg - BT856_REG_OFFSET] = value; |
1da177e4 LT |
75 | return i2c_smbus_write_byte_data(client, reg, value); |
76 | } | |
77 | ||
a91f56e7 | 78 | static inline int bt856_setbit(struct bt856 *encoder, u8 reg, u8 bit, u8 value) |
1da177e4 | 79 | { |
a91f56e7 | 80 | return bt856_write(encoder, reg, |
a8c26dfe HV |
81 | (encoder->reg[reg - BT856_REG_OFFSET] & ~(1 << bit)) | |
82 | (value ? (1 << bit) : 0)); | |
1da177e4 LT |
83 | } |
84 | ||
a91f56e7 | 85 | static void bt856_dump(struct bt856 *encoder) |
1da177e4 LT |
86 | { |
87 | int i; | |
1da177e4 | 88 | |
a91f56e7 | 89 | v4l2_info(&encoder->sd, "register dump:\n"); |
f49a5eae | 90 | for (i = 0; i < BT856_NR_REG; i += 2) |
a8c26dfe HV |
91 | printk(KERN_CONT " %02x", encoder->reg[i]); |
92 | printk(KERN_CONT "\n"); | |
1da177e4 LT |
93 | } |
94 | ||
95 | /* ----------------------------------------------------------------------- */ | |
96 | ||
a91f56e7 | 97 | static int bt856_init(struct v4l2_subdev *sd, u32 arg) |
1da177e4 | 98 | { |
a91f56e7 | 99 | struct bt856 *encoder = to_bt856(sd); |
1da177e4 | 100 | |
a91f56e7 HV |
101 | /* This is just for testing!!! */ |
102 | v4l2_dbg(1, debug, sd, "init\n"); | |
103 | bt856_write(encoder, 0xdc, 0x18); | |
104 | bt856_write(encoder, 0xda, 0); | |
105 | bt856_write(encoder, 0xde, 0); | |
1da177e4 | 106 | |
a91f56e7 HV |
107 | bt856_setbit(encoder, 0xdc, 3, 1); |
108 | /*bt856_setbit(encoder, 0xdc, 6, 0);*/ | |
109 | bt856_setbit(encoder, 0xdc, 4, 1); | |
110 | ||
111 | if (encoder->norm & V4L2_STD_NTSC) | |
112 | bt856_setbit(encoder, 0xdc, 2, 0); | |
113 | else | |
114 | bt856_setbit(encoder, 0xdc, 2, 1); | |
115 | ||
116 | bt856_setbit(encoder, 0xdc, 1, 1); | |
117 | bt856_setbit(encoder, 0xde, 4, 0); | |
118 | bt856_setbit(encoder, 0xde, 3, 1); | |
119 | if (debug != 0) | |
120 | bt856_dump(encoder); | |
121 | return 0; | |
122 | } | |
123 | ||
124 | static int bt856_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std) | |
125 | { | |
126 | struct bt856 *encoder = to_bt856(sd); | |
127 | ||
cc5cef8e | 128 | v4l2_dbg(1, debug, sd, "set norm %llx\n", (unsigned long long)std); |
a91f56e7 HV |
129 | |
130 | if (std & V4L2_STD_NTSC) { | |
131 | bt856_setbit(encoder, 0xdc, 2, 0); | |
132 | } else if (std & V4L2_STD_PAL) { | |
133 | bt856_setbit(encoder, 0xdc, 2, 1); | |
134 | bt856_setbit(encoder, 0xda, 0, 0); | |
135 | /*bt856_setbit(encoder, 0xda, 0, 1);*/ | |
136 | } else { | |
137 | return -EINVAL; | |
a8c26dfe | 138 | } |
a91f56e7 HV |
139 | encoder->norm = std; |
140 | if (debug != 0) | |
141 | bt856_dump(encoder); | |
142 | return 0; | |
143 | } | |
1da177e4 | 144 | |
a91f56e7 HV |
145 | static int bt856_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route) |
146 | { | |
147 | struct bt856 *encoder = to_bt856(sd); | |
148 | ||
149 | v4l2_dbg(1, debug, sd, "set input %d\n", route->input); | |
150 | ||
151 | /* We only have video bus. | |
152 | * route->input= 0: input is from bt819 | |
153 | * route->input= 1: input is from ZR36060 */ | |
154 | switch (route->input) { | |
155 | case 0: | |
156 | bt856_setbit(encoder, 0xde, 4, 0); | |
157 | bt856_setbit(encoder, 0xde, 3, 1); | |
158 | bt856_setbit(encoder, 0xdc, 3, 1); | |
159 | bt856_setbit(encoder, 0xdc, 6, 0); | |
160 | break; | |
161 | case 1: | |
162 | bt856_setbit(encoder, 0xde, 4, 0); | |
163 | bt856_setbit(encoder, 0xde, 3, 1); | |
164 | bt856_setbit(encoder, 0xdc, 3, 1); | |
165 | bt856_setbit(encoder, 0xdc, 6, 1); | |
166 | break; | |
167 | case 2: /* Color bar */ | |
168 | bt856_setbit(encoder, 0xdc, 3, 0); | |
169 | bt856_setbit(encoder, 0xde, 4, 1); | |
170 | break; | |
1da177e4 LT |
171 | default: |
172 | return -EINVAL; | |
173 | } | |
174 | ||
a91f56e7 HV |
175 | if (debug != 0) |
176 | bt856_dump(encoder); | |
1da177e4 LT |
177 | return 0; |
178 | } | |
179 | ||
a91f56e7 HV |
180 | static int bt856_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) |
181 | { | |
182 | struct i2c_client *client = v4l2_get_subdevdata(sd); | |
183 | ||
184 | return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_BT856, 0); | |
185 | } | |
186 | ||
1da177e4 LT |
187 | /* ----------------------------------------------------------------------- */ |
188 | ||
a91f56e7 HV |
189 | static const struct v4l2_subdev_core_ops bt856_core_ops = { |
190 | .g_chip_ident = bt856_g_chip_ident, | |
191 | .init = bt856_init, | |
192 | }; | |
1da177e4 | 193 | |
a91f56e7 HV |
194 | static const struct v4l2_subdev_video_ops bt856_video_ops = { |
195 | .s_std_output = bt856_s_std_output, | |
196 | .s_routing = bt856_s_routing, | |
197 | }; | |
198 | ||
199 | static const struct v4l2_subdev_ops bt856_ops = { | |
200 | .core = &bt856_core_ops, | |
201 | .video = &bt856_video_ops, | |
202 | }; | |
203 | ||
204 | /* ----------------------------------------------------------------------- */ | |
1da177e4 | 205 | |
a8c26dfe HV |
206 | static int bt856_probe(struct i2c_client *client, |
207 | const struct i2c_device_id *id) | |
1da177e4 | 208 | { |
1da177e4 | 209 | struct bt856 *encoder; |
a91f56e7 | 210 | struct v4l2_subdev *sd; |
1da177e4 | 211 | |
1da177e4 | 212 | /* Check if the adapter supports the needed features */ |
a8c26dfe HV |
213 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
214 | return -ENODEV; | |
1da177e4 | 215 | |
a8c26dfe HV |
216 | v4l_info(client, "chip found @ 0x%x (%s)\n", |
217 | client->addr << 1, client->adapter->name); | |
1da177e4 | 218 | |
7408187d | 219 | encoder = kzalloc(sizeof(struct bt856), GFP_KERNEL); |
a8c26dfe | 220 | if (encoder == NULL) |
1da177e4 | 221 | return -ENOMEM; |
a91f56e7 HV |
222 | sd = &encoder->sd; |
223 | v4l2_i2c_subdev_init(sd, client, &bt856_ops); | |
107063c6 | 224 | encoder->norm = V4L2_STD_NTSC; |
1da177e4 | 225 | |
a91f56e7 HV |
226 | bt856_write(encoder, 0xdc, 0x18); |
227 | bt856_write(encoder, 0xda, 0); | |
228 | bt856_write(encoder, 0xde, 0); | |
1da177e4 | 229 | |
a91f56e7 HV |
230 | bt856_setbit(encoder, 0xdc, 3, 1); |
231 | /*bt856_setbit(encoder, 0xdc, 6, 0);*/ | |
232 | bt856_setbit(encoder, 0xdc, 4, 1); | |
1da177e4 | 233 | |
107063c6 | 234 | if (encoder->norm & V4L2_STD_NTSC) |
a91f56e7 | 235 | bt856_setbit(encoder, 0xdc, 2, 0); |
107063c6 | 236 | else |
a91f56e7 | 237 | bt856_setbit(encoder, 0xdc, 2, 1); |
1da177e4 | 238 | |
a91f56e7 HV |
239 | bt856_setbit(encoder, 0xdc, 1, 1); |
240 | bt856_setbit(encoder, 0xde, 4, 0); | |
241 | bt856_setbit(encoder, 0xde, 3, 1); | |
1da177e4 LT |
242 | |
243 | if (debug != 0) | |
a91f56e7 | 244 | bt856_dump(encoder); |
1da177e4 LT |
245 | return 0; |
246 | } | |
247 | ||
a8c26dfe | 248 | static int bt856_remove(struct i2c_client *client) |
1da177e4 | 249 | { |
a91f56e7 HV |
250 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
251 | ||
252 | v4l2_device_unregister_subdev(sd); | |
253 | kfree(to_bt856(sd)); | |
1da177e4 LT |
254 | return 0; |
255 | } | |
256 | ||
a8c26dfe HV |
257 | static const struct i2c_device_id bt856_id[] = { |
258 | { "bt856", 0 }, | |
259 | { } | |
260 | }; | |
261 | MODULE_DEVICE_TABLE(i2c, bt856_id); | |
1da177e4 | 262 | |
a8c26dfe HV |
263 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
264 | .name = "bt856", | |
a8c26dfe HV |
265 | .probe = bt856_probe, |
266 | .remove = bt856_remove, | |
267 | .id_table = bt856_id, | |
1da177e4 | 268 | }; |