2 * bt856 - BT856A Digital Video Encoder (Rockwell Part)
4 * Copyright (C) 1999 Mike Bernson <mike@mlb.org>
5 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
7 * Modifications for LML33/DC10plus unified driver
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
10 * This code was modify/ported from the saa7111 driver written
13 * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net>
14 * - moved over to linux>=2.4.x i2c protocol (9/9/2002)
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.
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.
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.
31 #include <linux/module.h>
32 #include <linux/types.h>
33 #include <linux/slab.h>
34 #include <linux/ioctl.h>
35 #include <asm/uaccess.h>
36 #include <linux/i2c.h>
37 #include <linux/videodev2.h>
38 #include <media/v4l2-device.h>
40 MODULE_DESCRIPTION("Brooktree-856A video encoder driver");
41 MODULE_AUTHOR("Mike Bernson & Dave Perks");
42 MODULE_LICENSE("GPL");
45 module_param(debug
, int, 0);
46 MODULE_PARM_DESC(debug
, "Debug level (0-1)");
49 /* ----------------------------------------------------------------------- */
51 #define BT856_REG_OFFSET 0xDA
52 #define BT856_NR_REG 6
55 struct v4l2_subdev sd
;
56 unsigned char reg
[BT856_NR_REG
];
61 static inline struct bt856
*to_bt856(struct v4l2_subdev
*sd
)
63 return container_of(sd
, struct bt856
, sd
);
66 /* ----------------------------------------------------------------------- */
68 static inline int bt856_write(struct bt856
*encoder
, u8 reg
, u8 value
)
70 struct i2c_client
*client
= v4l2_get_subdevdata(&encoder
->sd
);
72 encoder
->reg
[reg
- BT856_REG_OFFSET
] = value
;
73 return i2c_smbus_write_byte_data(client
, reg
, value
);
76 static inline int bt856_setbit(struct bt856
*encoder
, u8 reg
, u8 bit
, u8 value
)
78 return bt856_write(encoder
, reg
,
79 (encoder
->reg
[reg
- BT856_REG_OFFSET
] & ~(1 << bit
)) |
80 (value
? (1 << bit
) : 0));
83 static void bt856_dump(struct bt856
*encoder
)
87 v4l2_info(&encoder
->sd
, "register dump:\n");
88 for (i
= 0; i
< BT856_NR_REG
; i
+= 2)
89 printk(KERN_CONT
" %02x", encoder
->reg
[i
]);
90 printk(KERN_CONT
"\n");
93 /* ----------------------------------------------------------------------- */
95 static int bt856_init(struct v4l2_subdev
*sd
, u32 arg
)
97 struct bt856
*encoder
= to_bt856(sd
);
99 /* This is just for testing!!! */
100 v4l2_dbg(1, debug
, sd
, "init\n");
101 bt856_write(encoder
, 0xdc, 0x18);
102 bt856_write(encoder
, 0xda, 0);
103 bt856_write(encoder
, 0xde, 0);
105 bt856_setbit(encoder
, 0xdc, 3, 1);
106 /*bt856_setbit(encoder, 0xdc, 6, 0);*/
107 bt856_setbit(encoder
, 0xdc, 4, 1);
109 if (encoder
->norm
& V4L2_STD_NTSC
)
110 bt856_setbit(encoder
, 0xdc, 2, 0);
112 bt856_setbit(encoder
, 0xdc, 2, 1);
114 bt856_setbit(encoder
, 0xdc, 1, 1);
115 bt856_setbit(encoder
, 0xde, 4, 0);
116 bt856_setbit(encoder
, 0xde, 3, 1);
122 static int bt856_s_std_output(struct v4l2_subdev
*sd
, v4l2_std_id std
)
124 struct bt856
*encoder
= to_bt856(sd
);
126 v4l2_dbg(1, debug
, sd
, "set norm %llx\n", (unsigned long long)std
);
128 if (std
& V4L2_STD_NTSC
) {
129 bt856_setbit(encoder
, 0xdc, 2, 0);
130 } else if (std
& V4L2_STD_PAL
) {
131 bt856_setbit(encoder
, 0xdc, 2, 1);
132 bt856_setbit(encoder
, 0xda, 0, 0);
133 /*bt856_setbit(encoder, 0xda, 0, 1);*/
143 static int bt856_s_routing(struct v4l2_subdev
*sd
,
144 u32 input
, u32 output
, u32 config
)
146 struct bt856
*encoder
= to_bt856(sd
);
148 v4l2_dbg(1, debug
, sd
, "set input %d\n", input
);
150 /* We only have video bus.
151 * input= 0: input is from bt819
152 * input= 1: input is from ZR36060 */
155 bt856_setbit(encoder
, 0xde, 4, 0);
156 bt856_setbit(encoder
, 0xde, 3, 1);
157 bt856_setbit(encoder
, 0xdc, 3, 1);
158 bt856_setbit(encoder
, 0xdc, 6, 0);
161 bt856_setbit(encoder
, 0xde, 4, 0);
162 bt856_setbit(encoder
, 0xde, 3, 1);
163 bt856_setbit(encoder
, 0xdc, 3, 1);
164 bt856_setbit(encoder
, 0xdc, 6, 1);
166 case 2: /* Color bar */
167 bt856_setbit(encoder
, 0xdc, 3, 0);
168 bt856_setbit(encoder
, 0xde, 4, 1);
179 /* ----------------------------------------------------------------------- */
181 static const struct v4l2_subdev_core_ops bt856_core_ops
= {
185 static const struct v4l2_subdev_video_ops bt856_video_ops
= {
186 .s_std_output
= bt856_s_std_output
,
187 .s_routing
= bt856_s_routing
,
190 static const struct v4l2_subdev_ops bt856_ops
= {
191 .core
= &bt856_core_ops
,
192 .video
= &bt856_video_ops
,
195 /* ----------------------------------------------------------------------- */
197 static int bt856_probe(struct i2c_client
*client
,
198 const struct i2c_device_id
*id
)
200 struct bt856
*encoder
;
201 struct v4l2_subdev
*sd
;
203 /* Check if the adapter supports the needed features */
204 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
207 v4l_info(client
, "chip found @ 0x%x (%s)\n",
208 client
->addr
<< 1, client
->adapter
->name
);
210 encoder
= devm_kzalloc(&client
->dev
, sizeof(*encoder
), GFP_KERNEL
);
214 v4l2_i2c_subdev_init(sd
, client
, &bt856_ops
);
215 encoder
->norm
= V4L2_STD_NTSC
;
217 bt856_write(encoder
, 0xdc, 0x18);
218 bt856_write(encoder
, 0xda, 0);
219 bt856_write(encoder
, 0xde, 0);
221 bt856_setbit(encoder
, 0xdc, 3, 1);
222 /*bt856_setbit(encoder, 0xdc, 6, 0);*/
223 bt856_setbit(encoder
, 0xdc, 4, 1);
225 if (encoder
->norm
& V4L2_STD_NTSC
)
226 bt856_setbit(encoder
, 0xdc, 2, 0);
228 bt856_setbit(encoder
, 0xdc, 2, 1);
230 bt856_setbit(encoder
, 0xdc, 1, 1);
231 bt856_setbit(encoder
, 0xde, 4, 0);
232 bt856_setbit(encoder
, 0xde, 3, 1);
239 static int bt856_remove(struct i2c_client
*client
)
241 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
243 v4l2_device_unregister_subdev(sd
);
247 static const struct i2c_device_id bt856_id
[] = {
251 MODULE_DEVICE_TABLE(i2c
, bt856_id
);
253 static struct i2c_driver bt856_driver
= {
257 .probe
= bt856_probe
,
258 .remove
= bt856_remove
,
259 .id_table
= bt856_id
,
262 module_i2c_driver(bt856_driver
);