diff options
Diffstat (limited to 'drivers/media/video/upd64031a.c')
-rw-r--r-- | drivers/media/video/upd64031a.c | 193 |
1 files changed, 113 insertions, 80 deletions
diff --git a/drivers/media/video/upd64031a.c b/drivers/media/video/upd64031a.c index b4628874933b..7a609a3a6dbe 100644 --- a/drivers/media/video/upd64031a.c +++ b/drivers/media/video/upd64031a.c | |||
@@ -26,7 +26,7 @@ | |||
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/i2c.h> | 27 | #include <linux/i2c.h> |
28 | #include <linux/videodev2.h> | 28 | #include <linux/videodev2.h> |
29 | #include <media/v4l2-common.h> | 29 | #include <media/v4l2-device.h> |
30 | #include <media/v4l2-chip-ident.h> | 30 | #include <media/v4l2-chip-ident.h> |
31 | #include <media/v4l2-i2c-drv.h> | 31 | #include <media/v4l2-i2c-drv.h> |
32 | #include <media/upd64031a.h> | 32 | #include <media/upd64031a.h> |
@@ -62,6 +62,7 @@ enum { | |||
62 | }; | 62 | }; |
63 | 63 | ||
64 | struct upd64031a_state { | 64 | struct upd64031a_state { |
65 | struct v4l2_subdev sd; | ||
65 | u8 regs[TOT_REGS]; | 66 | u8 regs[TOT_REGS]; |
66 | u8 gr_mode; | 67 | u8 gr_mode; |
67 | u8 direct_3dycs_connect; | 68 | u8 direct_3dycs_connect; |
@@ -69,6 +70,11 @@ struct upd64031a_state { | |||
69 | u8 ext_vert_sync; | 70 | u8 ext_vert_sync; |
70 | }; | 71 | }; |
71 | 72 | ||
73 | static inline struct upd64031a_state *to_state(struct v4l2_subdev *sd) | ||
74 | { | ||
75 | return container_of(sd, struct upd64031a_state, sd); | ||
76 | } | ||
77 | |||
72 | static u8 upd64031a_init[] = { | 78 | static u8 upd64031a_init[] = { |
73 | 0x00, 0xb8, 0x48, 0xd2, 0xe6, | 79 | 0x00, 0xb8, 0x48, 0xd2, 0xe6, |
74 | 0x03, 0x10, 0x0b, 0xaf, 0x7f, | 80 | 0x03, 0x10, 0x0b, 0xaf, 0x7f, |
@@ -78,8 +84,9 @@ static u8 upd64031a_init[] = { | |||
78 | 84 | ||
79 | /* ------------------------------------------------------------------------ */ | 85 | /* ------------------------------------------------------------------------ */ |
80 | 86 | ||
81 | static u8 upd64031a_read(struct i2c_client *client, u8 reg) | 87 | static u8 upd64031a_read(struct v4l2_subdev *sd, u8 reg) |
82 | { | 88 | { |
89 | struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
83 | u8 buf[2]; | 90 | u8 buf[2]; |
84 | 91 | ||
85 | if (reg >= sizeof(buf)) | 92 | if (reg >= sizeof(buf)) |
@@ -90,106 +97,127 @@ static u8 upd64031a_read(struct i2c_client *client, u8 reg) | |||
90 | 97 | ||
91 | /* ------------------------------------------------------------------------ */ | 98 | /* ------------------------------------------------------------------------ */ |
92 | 99 | ||
93 | static void upd64031a_write(struct i2c_client *client, u8 reg, u8 val) | 100 | static void upd64031a_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
94 | { | 101 | { |
102 | struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
95 | u8 buf[2]; | 103 | u8 buf[2]; |
96 | 104 | ||
97 | buf[0] = reg; | 105 | buf[0] = reg; |
98 | buf[1] = val; | 106 | buf[1] = val; |
99 | v4l_dbg(1, debug, client, "write reg: %02X val: %02X\n", reg, val); | 107 | v4l2_dbg(1, debug, sd, "write reg: %02X val: %02X\n", reg, val); |
100 | if (i2c_master_send(client, buf, 2) != 2) | 108 | if (i2c_master_send(client, buf, 2) != 2) |
101 | v4l_err(client, "I/O error write 0x%02x/0x%02x\n", reg, val); | 109 | v4l2_err(sd, "I/O error write 0x%02x/0x%02x\n", reg, val); |
102 | } | 110 | } |
103 | 111 | ||
104 | /* ------------------------------------------------------------------------ */ | 112 | /* ------------------------------------------------------------------------ */ |
105 | 113 | ||
106 | /* The input changed due to new input or channel changed */ | 114 | /* The input changed due to new input or channel changed */ |
107 | static void upd64031a_change(struct i2c_client *client) | 115 | static int upd64031a_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) |
108 | { | 116 | { |
109 | struct upd64031a_state *state = i2c_get_clientdata(client); | 117 | struct upd64031a_state *state = to_state(sd); |
110 | u8 reg = state->regs[R00]; | 118 | u8 reg = state->regs[R00]; |
111 | 119 | ||
112 | v4l_dbg(1, debug, client, "changed input or channel\n"); | 120 | v4l2_dbg(1, debug, sd, "changed input or channel\n"); |
113 | upd64031a_write(client, R00, reg | 0x10); | 121 | upd64031a_write(sd, R00, reg | 0x10); |
114 | upd64031a_write(client, R00, reg & ~0x10); | 122 | upd64031a_write(sd, R00, reg & ~0x10); |
123 | return 0; | ||
115 | } | 124 | } |
116 | 125 | ||
117 | /* ------------------------------------------------------------------------ */ | 126 | /* ------------------------------------------------------------------------ */ |
118 | 127 | ||
128 | static int upd64031a_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route) | ||
129 | { | ||
130 | struct upd64031a_state *state = to_state(sd); | ||
131 | u8 r00, r05, r08; | ||
132 | |||
133 | state->gr_mode = (route->input & 3) << 6; | ||
134 | state->direct_3dycs_connect = (route->input & 0xc) << 4; | ||
135 | state->ext_comp_sync = | ||
136 | (route->input & UPD64031A_COMPOSITE_EXTERNAL) << 1; | ||
137 | state->ext_vert_sync = | ||
138 | (route->input & UPD64031A_VERTICAL_EXTERNAL) << 2; | ||
139 | r00 = (state->regs[R00] & ~GR_MODE_MASK) | state->gr_mode; | ||
140 | r05 = (state->regs[R00] & ~SYNC_CIRCUIT_MASK) | | ||
141 | state->ext_comp_sync | state->ext_vert_sync; | ||
142 | r08 = (state->regs[R08] & ~DIRECT_3DYCS_CONNECT_MASK) | | ||
143 | state->direct_3dycs_connect; | ||
144 | upd64031a_write(sd, R00, r00); | ||
145 | upd64031a_write(sd, R05, r05); | ||
146 | upd64031a_write(sd, R08, r08); | ||
147 | return upd64031a_s_frequency(sd, NULL); | ||
148 | } | ||
149 | |||
150 | static int upd64031a_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_chip_ident *chip) | ||
151 | { | ||
152 | struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
153 | |||
154 | return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_UPD64031A, 0); | ||
155 | } | ||
156 | |||
157 | static int upd64031a_log_status(struct v4l2_subdev *sd) | ||
158 | { | ||
159 | v4l2_info(sd, "Status: SA00=0x%02x SA01=0x%02x\n", | ||
160 | upd64031a_read(sd, 0), upd64031a_read(sd, 1)); | ||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | #ifdef CONFIG_VIDEO_ADV_DEBUG | ||
165 | static int upd64031a_g_register(struct v4l2_subdev *sd, struct v4l2_register *reg) | ||
166 | { | ||
167 | struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
168 | |||
169 | if (!v4l2_chip_match_i2c_client(client, | ||
170 | reg->match_type, reg->match_chip)) | ||
171 | return -EINVAL; | ||
172 | if (!capable(CAP_SYS_ADMIN)) | ||
173 | return -EPERM; | ||
174 | reg->val = upd64031a_read(sd, reg->reg & 0xff); | ||
175 | return 0; | ||
176 | } | ||
177 | |||
178 | static int upd64031a_s_register(struct v4l2_subdev *sd, struct v4l2_register *reg) | ||
179 | { | ||
180 | struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
181 | |||
182 | if (!v4l2_chip_match_i2c_client(client, | ||
183 | reg->match_type, reg->match_chip)) | ||
184 | return -EINVAL; | ||
185 | if (!capable(CAP_SYS_ADMIN)) | ||
186 | return -EPERM; | ||
187 | upd64031a_write(sd, reg->reg & 0xff, reg->val & 0xff); | ||
188 | return 0; | ||
189 | } | ||
190 | #endif | ||
191 | |||
119 | static int upd64031a_command(struct i2c_client *client, unsigned cmd, void *arg) | 192 | static int upd64031a_command(struct i2c_client *client, unsigned cmd, void *arg) |
120 | { | 193 | { |
121 | struct upd64031a_state *state = i2c_get_clientdata(client); | 194 | return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg); |
122 | struct v4l2_routing *route = arg; | 195 | } |
123 | 196 | ||
124 | switch (cmd) { | 197 | /* ----------------------------------------------------------------------- */ |
125 | case VIDIOC_S_FREQUENCY: | ||
126 | upd64031a_change(client); | ||
127 | break; | ||
128 | |||
129 | case VIDIOC_INT_G_VIDEO_ROUTING: | ||
130 | route->input = (state->gr_mode >> 6) | | ||
131 | (state->direct_3dycs_connect >> 4) | | ||
132 | (state->ext_comp_sync >> 1) | | ||
133 | (state->ext_vert_sync >> 2); | ||
134 | route->output = 0; | ||
135 | break; | ||
136 | |||
137 | case VIDIOC_INT_S_VIDEO_ROUTING: | ||
138 | { | ||
139 | u8 r00, r05, r08; | ||
140 | |||
141 | state->gr_mode = (route->input & 3) << 6; | ||
142 | state->direct_3dycs_connect = (route->input & 0xc) << 4; | ||
143 | state->ext_comp_sync = | ||
144 | (route->input & UPD64031A_COMPOSITE_EXTERNAL) << 1; | ||
145 | state->ext_vert_sync = | ||
146 | (route->input & UPD64031A_VERTICAL_EXTERNAL) << 2; | ||
147 | r00 = (state->regs[R00] & ~GR_MODE_MASK) | state->gr_mode; | ||
148 | r05 = (state->regs[R00] & ~SYNC_CIRCUIT_MASK) | | ||
149 | state->ext_comp_sync | state->ext_vert_sync; | ||
150 | r08 = (state->regs[R08] & ~DIRECT_3DYCS_CONNECT_MASK) | | ||
151 | state->direct_3dycs_connect; | ||
152 | upd64031a_write(client, R00, r00); | ||
153 | upd64031a_write(client, R05, r05); | ||
154 | upd64031a_write(client, R08, r08); | ||
155 | upd64031a_change(client); | ||
156 | break; | ||
157 | } | ||
158 | |||
159 | case VIDIOC_LOG_STATUS: | ||
160 | v4l_info(client, "Status: SA00=0x%02x SA01=0x%02x\n", | ||
161 | upd64031a_read(client, 0), upd64031a_read(client, 1)); | ||
162 | break; | ||
163 | 198 | ||
199 | static const struct v4l2_subdev_core_ops upd64031a_core_ops = { | ||
200 | .log_status = upd64031a_log_status, | ||
201 | .g_chip_ident = upd64031a_g_chip_ident, | ||
164 | #ifdef CONFIG_VIDEO_ADV_DEBUG | 202 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
165 | case VIDIOC_DBG_G_REGISTER: | 203 | .g_register = upd64031a_g_register, |
166 | case VIDIOC_DBG_S_REGISTER: | 204 | .s_register = upd64031a_s_register, |
167 | { | ||
168 | struct v4l2_register *reg = arg; | ||
169 | |||
170 | if (!v4l2_chip_match_i2c_client(client, | ||
171 | reg->match_type, reg->match_chip)) | ||
172 | return -EINVAL; | ||
173 | if (!capable(CAP_SYS_ADMIN)) | ||
174 | return -EPERM; | ||
175 | if (cmd == VIDIOC_DBG_G_REGISTER) { | ||
176 | reg->val = upd64031a_read(client, reg->reg & 0xff); | ||
177 | break; | ||
178 | } | ||
179 | upd64031a_write(client, reg->reg & 0xff, reg->val & 0xff); | ||
180 | break; | ||
181 | } | ||
182 | #endif | 205 | #endif |
206 | }; | ||
183 | 207 | ||
184 | case VIDIOC_G_CHIP_IDENT: | 208 | static const struct v4l2_subdev_tuner_ops upd64031a_tuner_ops = { |
185 | return v4l2_chip_ident_i2c_client(client, arg, | 209 | .s_frequency = upd64031a_s_frequency, |
186 | V4L2_IDENT_UPD64031A, 0); | 210 | }; |
187 | 211 | ||
188 | default: | 212 | static const struct v4l2_subdev_video_ops upd64031a_video_ops = { |
189 | break; | 213 | .s_routing = upd64031a_s_routing, |
190 | } | 214 | }; |
191 | return 0; | 215 | |
192 | } | 216 | static const struct v4l2_subdev_ops upd64031a_ops = { |
217 | .core = &upd64031a_core_ops, | ||
218 | .tuner = &upd64031a_tuner_ops, | ||
219 | .video = &upd64031a_video_ops, | ||
220 | }; | ||
193 | 221 | ||
194 | /* ------------------------------------------------------------------------ */ | 222 | /* ------------------------------------------------------------------------ */ |
195 | 223 | ||
@@ -199,6 +227,7 @@ static int upd64031a_probe(struct i2c_client *client, | |||
199 | const struct i2c_device_id *id) | 227 | const struct i2c_device_id *id) |
200 | { | 228 | { |
201 | struct upd64031a_state *state; | 229 | struct upd64031a_state *state; |
230 | struct v4l2_subdev *sd; | ||
202 | int i; | 231 | int i; |
203 | 232 | ||
204 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 233 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
@@ -210,19 +239,23 @@ static int upd64031a_probe(struct i2c_client *client, | |||
210 | state = kmalloc(sizeof(struct upd64031a_state), GFP_KERNEL); | 239 | state = kmalloc(sizeof(struct upd64031a_state), GFP_KERNEL); |
211 | if (state == NULL) | 240 | if (state == NULL) |
212 | return -ENOMEM; | 241 | return -ENOMEM; |
213 | i2c_set_clientdata(client, state); | 242 | sd = &state->sd; |
243 | v4l2_i2c_subdev_init(sd, client, &upd64031a_ops); | ||
214 | memcpy(state->regs, upd64031a_init, sizeof(state->regs)); | 244 | memcpy(state->regs, upd64031a_init, sizeof(state->regs)); |
215 | state->gr_mode = UPD64031A_GR_ON << 6; | 245 | state->gr_mode = UPD64031A_GR_ON << 6; |
216 | state->direct_3dycs_connect = UPD64031A_3DYCS_COMPOSITE << 4; | 246 | state->direct_3dycs_connect = UPD64031A_3DYCS_COMPOSITE << 4; |
217 | state->ext_comp_sync = state->ext_vert_sync = 0; | 247 | state->ext_comp_sync = state->ext_vert_sync = 0; |
218 | for (i = 0; i < TOT_REGS; i++) | 248 | for (i = 0; i < TOT_REGS; i++) |
219 | upd64031a_write(client, i, state->regs[i]); | 249 | upd64031a_write(sd, i, state->regs[i]); |
220 | return 0; | 250 | return 0; |
221 | } | 251 | } |
222 | 252 | ||
223 | static int upd64031a_remove(struct i2c_client *client) | 253 | static int upd64031a_remove(struct i2c_client *client) |
224 | { | 254 | { |
225 | kfree(i2c_get_clientdata(client)); | 255 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
256 | |||
257 | v4l2_device_unregister_subdev(sd); | ||
258 | kfree(to_state(sd)); | ||
226 | return 0; | 259 | return 0; |
227 | } | 260 | } |
228 | 261 | ||