1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * bt856 - BT856A Digital Video Encoder (Rockwell Part)
5 * Copyright (C) 1999 Mike Bernson <mike@mlb.org>
6 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
8 * Modifications for LML33/DC10plus unified driver
9 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
11 * This code was modify/ported from the saa7111 driver written
14 * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net>
15 * - moved over to linux>=2.4.x i2c protocol (9/9/2002)
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/slab.h>
21 #include <linux/ioctl.h>
22 #include <linux/uaccess.h>
23 #include <linux/i2c.h>
24 #include <linux/videodev2.h>
25 #include <media/v4l2-device.h>
27 MODULE_DESCRIPTION("Brooktree-856A video encoder driver");
28 MODULE_AUTHOR("Mike Bernson & Dave Perks");
29 MODULE_LICENSE("GPL");
32 module_param(debug
, int, 0);
33 MODULE_PARM_DESC(debug
, "Debug level (0-1)");
36 /* ----------------------------------------------------------------------- */
38 #define BT856_REG_OFFSET 0xDA
39 #define BT856_NR_REG 6
42 struct v4l2_subdev sd
;
43 unsigned char reg
[BT856_NR_REG
];
48 static inline struct bt856
*to_bt856(struct v4l2_subdev
*sd
)
50 return container_of(sd
, struct bt856
, sd
);
53 /* ----------------------------------------------------------------------- */
55 static inline int bt856_write(struct bt856
*encoder
, u8 reg
, u8 value
)
57 struct i2c_client
*client
= v4l2_get_subdevdata(&encoder
->sd
);
59 encoder
->reg
[reg
- BT856_REG_OFFSET
] = value
;
60 return i2c_smbus_write_byte_data(client
, reg
, value
);
63 static inline int bt856_setbit(struct bt856
*encoder
, u8 reg
, u8 bit
, u8 value
)
65 return bt856_write(encoder
, reg
,
66 (encoder
->reg
[reg
- BT856_REG_OFFSET
] & ~(1 << bit
)) |
67 (value
? (1 << bit
) : 0));
70 static void bt856_dump(struct bt856
*encoder
)
74 v4l2_info(&encoder
->sd
, "register dump:\n");
75 for (i
= 0; i
< BT856_NR_REG
; i
+= 2)
76 printk(KERN_CONT
" %02x", encoder
->reg
[i
]);
77 printk(KERN_CONT
"\n");
80 /* ----------------------------------------------------------------------- */
82 static int bt856_init(struct v4l2_subdev
*sd
, u32 arg
)
84 struct bt856
*encoder
= to_bt856(sd
);
86 /* This is just for testing!!! */
87 v4l2_dbg(1, debug
, sd
, "init\n");
88 bt856_write(encoder
, 0xdc, 0x18);
89 bt856_write(encoder
, 0xda, 0);
90 bt856_write(encoder
, 0xde, 0);
92 bt856_setbit(encoder
, 0xdc, 3, 1);
93 /*bt856_setbit(encoder, 0xdc, 6, 0);*/
94 bt856_setbit(encoder
, 0xdc, 4, 1);
96 if (encoder
->norm
& V4L2_STD_NTSC
)
97 bt856_setbit(encoder
, 0xdc, 2, 0);
99 bt856_setbit(encoder
, 0xdc, 2, 1);
101 bt856_setbit(encoder
, 0xdc, 1, 1);
102 bt856_setbit(encoder
, 0xde, 4, 0);
103 bt856_setbit(encoder
, 0xde, 3, 1);
109 static int bt856_s_std_output(struct v4l2_subdev
*sd
, v4l2_std_id std
)
111 struct bt856
*encoder
= to_bt856(sd
);
113 v4l2_dbg(1, debug
, sd
, "set norm %llx\n", (unsigned long long)std
);
115 if (std
& V4L2_STD_NTSC
) {
116 bt856_setbit(encoder
, 0xdc, 2, 0);
117 } else if (std
& V4L2_STD_PAL
) {
118 bt856_setbit(encoder
, 0xdc, 2, 1);
119 bt856_setbit(encoder
, 0xda, 0, 0);
120 /*bt856_setbit(encoder, 0xda, 0, 1);*/
130 static int bt856_s_routing(struct v4l2_subdev
*sd
,
131 u32 input
, u32 output
, u32 config
)
133 struct bt856
*encoder
= to_bt856(sd
);
135 v4l2_dbg(1, debug
, sd
, "set input %d\n", input
);
137 /* We only have video bus.
138 * input= 0: input is from bt819
139 * input= 1: input is from ZR36060 */
142 bt856_setbit(encoder
, 0xde, 4, 0);
143 bt856_setbit(encoder
, 0xde, 3, 1);
144 bt856_setbit(encoder
, 0xdc, 3, 1);
145 bt856_setbit(encoder
, 0xdc, 6, 0);
148 bt856_setbit(encoder
, 0xde, 4, 0);
149 bt856_setbit(encoder
, 0xde, 3, 1);
150 bt856_setbit(encoder
, 0xdc, 3, 1);
151 bt856_setbit(encoder
, 0xdc, 6, 1);
153 case 2: /* Color bar */
154 bt856_setbit(encoder
, 0xdc, 3, 0);
155 bt856_setbit(encoder
, 0xde, 4, 1);
166 /* ----------------------------------------------------------------------- */
168 static const struct v4l2_subdev_core_ops bt856_core_ops
= {
172 static const struct v4l2_subdev_video_ops bt856_video_ops
= {
173 .s_std_output
= bt856_s_std_output
,
174 .s_routing
= bt856_s_routing
,
177 static const struct v4l2_subdev_ops bt856_ops
= {
178 .core
= &bt856_core_ops
,
179 .video
= &bt856_video_ops
,
182 /* ----------------------------------------------------------------------- */
184 static int bt856_probe(struct i2c_client
*client
,
185 const struct i2c_device_id
*id
)
187 struct bt856
*encoder
;
188 struct v4l2_subdev
*sd
;
190 /* Check if the adapter supports the needed features */
191 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
194 v4l_info(client
, "chip found @ 0x%x (%s)\n",
195 client
->addr
<< 1, client
->adapter
->name
);
197 encoder
= devm_kzalloc(&client
->dev
, sizeof(*encoder
), GFP_KERNEL
);
201 v4l2_i2c_subdev_init(sd
, client
, &bt856_ops
);
202 encoder
->norm
= V4L2_STD_NTSC
;
204 bt856_write(encoder
, 0xdc, 0x18);
205 bt856_write(encoder
, 0xda, 0);
206 bt856_write(encoder
, 0xde, 0);
208 bt856_setbit(encoder
, 0xdc, 3, 1);
209 /*bt856_setbit(encoder, 0xdc, 6, 0);*/
210 bt856_setbit(encoder
, 0xdc, 4, 1);
212 if (encoder
->norm
& V4L2_STD_NTSC
)
213 bt856_setbit(encoder
, 0xdc, 2, 0);
215 bt856_setbit(encoder
, 0xdc, 2, 1);
217 bt856_setbit(encoder
, 0xdc, 1, 1);
218 bt856_setbit(encoder
, 0xde, 4, 0);
219 bt856_setbit(encoder
, 0xde, 3, 1);
226 static int bt856_remove(struct i2c_client
*client
)
228 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
230 v4l2_device_unregister_subdev(sd
);
234 static const struct i2c_device_id bt856_id
[] = {
238 MODULE_DEVICE_TABLE(i2c
, bt856_id
);
240 static struct i2c_driver bt856_driver
= {
244 .probe
= bt856_probe
,
245 .remove
= bt856_remove
,
246 .id_table
= bt856_id
,
249 module_i2c_driver(bt856_driver
);