]>
Commit | Line | Data |
---|---|---|
c942fddf | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
add953ce HV |
2 | /* |
3 | * upd6408x - NEC Electronics 3-Dimensional Y/C separation driver | |
4 | * | |
5 | * 2003 by T.Adachi (tadachi@tadachi-net.com) | |
6 | * 2003 by Takeru KOMORIYA <komoriya@paken.org> | |
7 | * 2006 by Hans Verkuil <hverkuil@xs4all.nl> | |
add953ce HV |
8 | */ |
9 | ||
add953ce HV |
10 | #include <linux/module.h> |
11 | #include <linux/kernel.h> | |
12 | #include <linux/i2c.h> | |
13 | #include <linux/videodev2.h> | |
5a0e3ad6 | 14 | #include <linux/slab.h> |
cc7ca3ea | 15 | #include <media/v4l2-device.h> |
b5dcee22 | 16 | #include <media/i2c/upd64083.h> |
add953ce HV |
17 | |
18 | MODULE_DESCRIPTION("uPD64083 driver"); | |
19 | MODULE_AUTHOR("T. Adachi, Takeru KOMORIYA, Hans Verkuil"); | |
20 | MODULE_LICENSE("GPL"); | |
21 | ||
90ab5ee9 | 22 | static bool debug; |
add953ce HV |
23 | module_param(debug, bool, 0644); |
24 | ||
25 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); | |
26 | ||
add953ce HV |
27 | |
28 | enum { | |
29 | R00 = 0, R01, R02, R03, R04, | |
30 | R05, R06, R07, R08, R09, | |
31 | R0A, R0B, R0C, R0D, R0E, R0F, | |
32 | R10, R11, R12, R13, R14, | |
33 | R15, R16, | |
34 | TOT_REGS | |
35 | }; | |
36 | ||
37 | struct upd64083_state { | |
cc7ca3ea | 38 | struct v4l2_subdev sd; |
add953ce HV |
39 | u8 mode; |
40 | u8 ext_y_adc; | |
41 | u8 regs[TOT_REGS]; | |
42 | }; | |
43 | ||
cc7ca3ea HV |
44 | static inline struct upd64083_state *to_state(struct v4l2_subdev *sd) |
45 | { | |
46 | return container_of(sd, struct upd64083_state, sd); | |
47 | } | |
48 | ||
add953ce HV |
49 | /* Initial values when used in combination with the |
50 | NEC upd64031a ghost reduction chip. */ | |
51 | static u8 upd64083_init[] = { | |
52 | 0x1f, 0x01, 0xa0, 0x2d, 0x29, /* we use EXCSS=0 */ | |
53 | 0x36, 0xdd, 0x05, 0x56, 0x48, | |
54 | 0x00, 0x3a, 0xa0, 0x05, 0x08, | |
55 | 0x44, 0x60, 0x08, 0x52, 0xf8, | |
56 | 0x53, 0x60, 0x10 | |
57 | }; | |
58 | ||
59 | /* ------------------------------------------------------------------------ */ | |
60 | ||
cc7ca3ea | 61 | static void upd64083_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
add953ce | 62 | { |
cc7ca3ea | 63 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
add953ce HV |
64 | u8 buf[2]; |
65 | ||
66 | buf[0] = reg; | |
67 | buf[1] = val; | |
cc7ca3ea | 68 | v4l2_dbg(1, debug, sd, "write reg: %02x val: %02x\n", reg, val); |
add953ce | 69 | if (i2c_master_send(client, buf, 2) != 2) |
cc7ca3ea | 70 | v4l2_err(sd, "I/O error write 0x%02x/0x%02x\n", reg, val); |
add953ce HV |
71 | } |
72 | ||
73 | /* ------------------------------------------------------------------------ */ | |
74 | ||
75 | #ifdef CONFIG_VIDEO_ADV_DEBUG | |
cc7ca3ea | 76 | static u8 upd64083_read(struct v4l2_subdev *sd, u8 reg) |
add953ce | 77 | { |
cc7ca3ea | 78 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
add953ce HV |
79 | u8 buf[7]; |
80 | ||
81 | if (reg >= sizeof(buf)) | |
82 | return 0xff; | |
83 | i2c_master_recv(client, buf, sizeof(buf)); | |
84 | return buf[reg]; | |
85 | } | |
86 | #endif | |
87 | ||
88 | /* ------------------------------------------------------------------------ */ | |
89 | ||
5325b427 HV |
90 | static int upd64083_s_routing(struct v4l2_subdev *sd, |
91 | u32 input, u32 output, u32 config) | |
add953ce | 92 | { |
cc7ca3ea HV |
93 | struct upd64083_state *state = to_state(sd); |
94 | u8 r00, r02; | |
95 | ||
5325b427 | 96 | if (input > 7 || (input & 6) == 6) |
cc7ca3ea | 97 | return -EINVAL; |
5325b427 HV |
98 | state->mode = (input & 3) << 6; |
99 | state->ext_y_adc = (input & UPD64083_EXT_Y_ADC) << 3; | |
cc7ca3ea HV |
100 | r00 = (state->regs[R00] & ~(3 << 6)) | state->mode; |
101 | r02 = (state->regs[R02] & ~(1 << 5)) | state->ext_y_adc; | |
102 | upd64083_write(sd, R00, r00); | |
103 | upd64083_write(sd, R02, r02); | |
104 | return 0; | |
105 | } | |
add953ce HV |
106 | |
107 | #ifdef CONFIG_VIDEO_ADV_DEBUG | |
aecde8b5 | 108 | static int upd64083_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) |
cc7ca3ea | 109 | { |
cc7ca3ea | 110 | reg->val = upd64083_read(sd, reg->reg & 0xff); |
aecde8b5 | 111 | reg->size = 1; |
cc7ca3ea HV |
112 | return 0; |
113 | } | |
add953ce | 114 | |
977ba3b1 | 115 | static int upd64083_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) |
cc7ca3ea | 116 | { |
cc7ca3ea HV |
117 | upd64083_write(sd, reg->reg & 0xff, reg->val & 0xff); |
118 | return 0; | |
119 | } | |
add953ce | 120 | #endif |
74cab31c | 121 | |
cc7ca3ea HV |
122 | static int upd64083_log_status(struct v4l2_subdev *sd) |
123 | { | |
124 | struct i2c_client *client = v4l2_get_subdevdata(sd); | |
125 | u8 buf[7]; | |
add953ce | 126 | |
cc7ca3ea HV |
127 | i2c_master_recv(client, buf, 7); |
128 | v4l2_info(sd, "Status: SA00=%02x SA01=%02x SA02=%02x SA03=%02x " | |
129 | "SA04=%02x SA05=%02x SA06=%02x\n", | |
130 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); | |
add953ce HV |
131 | return 0; |
132 | } | |
133 | ||
cc7ca3ea HV |
134 | /* ----------------------------------------------------------------------- */ |
135 | ||
136 | static const struct v4l2_subdev_core_ops upd64083_core_ops = { | |
137 | .log_status = upd64083_log_status, | |
cc7ca3ea HV |
138 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
139 | .g_register = upd64083_g_register, | |
140 | .s_register = upd64083_s_register, | |
141 | #endif | |
142 | }; | |
143 | ||
144 | static const struct v4l2_subdev_video_ops upd64083_video_ops = { | |
145 | .s_routing = upd64083_s_routing, | |
146 | }; | |
147 | ||
148 | static const struct v4l2_subdev_ops upd64083_ops = { | |
149 | .core = &upd64083_core_ops, | |
150 | .video = &upd64083_video_ops, | |
151 | }; | |
152 | ||
add953ce HV |
153 | /* ------------------------------------------------------------------------ */ |
154 | ||
155 | /* i2c implementation */ | |
156 | ||
d2653e92 JD |
157 | static int upd64083_probe(struct i2c_client *client, |
158 | const struct i2c_device_id *id) | |
add953ce | 159 | { |
add953ce | 160 | struct upd64083_state *state; |
cc7ca3ea | 161 | struct v4l2_subdev *sd; |
add953ce HV |
162 | int i; |
163 | ||
26666977 | 164 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
188f3457 | 165 | return -EIO; |
add953ce | 166 | |
8c9fc8de HV |
167 | v4l_info(client, "chip found @ 0x%x (%s)\n", |
168 | client->addr << 1, client->adapter->name); | |
add953ce | 169 | |
c02b211d | 170 | state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); |
8c9fc8de | 171 | if (state == NULL) |
add953ce | 172 | return -ENOMEM; |
cc7ca3ea HV |
173 | sd = &state->sd; |
174 | v4l2_i2c_subdev_init(sd, client, &upd64083_ops); | |
add953ce HV |
175 | /* Initially assume that a ghost reduction chip is present */ |
176 | state->mode = 0; /* YCS mode */ | |
177 | state->ext_y_adc = (1 << 5); | |
178 | memcpy(state->regs, upd64083_init, TOT_REGS); | |
8c9fc8de | 179 | for (i = 0; i < TOT_REGS; i++) |
cc7ca3ea | 180 | upd64083_write(sd, i, state->regs[i]); |
add953ce HV |
181 | return 0; |
182 | } | |
183 | ||
26666977 | 184 | static int upd64083_remove(struct i2c_client *client) |
add953ce | 185 | { |
cc7ca3ea HV |
186 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
187 | ||
188 | v4l2_device_unregister_subdev(sd); | |
add953ce HV |
189 | return 0; |
190 | } | |
191 | ||
192 | /* ----------------------------------------------------------------------- */ | |
193 | ||
af294867 JD |
194 | static const struct i2c_device_id upd64083_id[] = { |
195 | { "upd64083", 0 }, | |
196 | { } | |
197 | }; | |
198 | MODULE_DEVICE_TABLE(i2c, upd64083_id); | |
26666977 | 199 | |
37a0cfcb HV |
200 | static struct i2c_driver upd64083_driver = { |
201 | .driver = { | |
37a0cfcb HV |
202 | .name = "upd64083", |
203 | }, | |
204 | .probe = upd64083_probe, | |
205 | .remove = upd64083_remove, | |
206 | .id_table = upd64083_id, | |
add953ce | 207 | }; |
37a0cfcb | 208 | |
c6e8d86f | 209 | module_i2c_driver(upd64083_driver); |