[media] davinci: vpbe: pass different platform names to handle different ip's
[deliverable/linux.git] / drivers / media / platform / davinci / vpbe_venc.c
1 /*
2 * Copyright (C) 2010 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/ctype.h>
21 #include <linux/delay.h>
22 #include <linux/device.h>
23 #include <linux/interrupt.h>
24 #include <linux/platform_device.h>
25 #include <linux/videodev2.h>
26 #include <linux/slab.h>
27
28 #include <mach/hardware.h>
29 #include <mach/mux.h>
30 #include <linux/platform_data/i2c-davinci.h>
31
32 #include <linux/io.h>
33
34 #include <media/davinci/vpbe_types.h>
35 #include <media/davinci/vpbe_venc.h>
36 #include <media/davinci/vpss.h>
37 #include <media/v4l2-device.h>
38
39 #include "vpbe_venc_regs.h"
40
41 #define MODULE_NAME "davinci-vpbe-venc"
42
43 static struct platform_device_id vpbe_venc_devtype[] = {
44 {
45 .name = DM644X_VPBE_VENC_SUBDEV_NAME,
46 .driver_data = VPBE_VERSION_1,
47 }, {
48 .name = DM365_VPBE_VENC_SUBDEV_NAME,
49 .driver_data = VPBE_VERSION_2,
50 }, {
51 .name = DM355_VPBE_VENC_SUBDEV_NAME,
52 .driver_data = VPBE_VERSION_3,
53 },
54 };
55
56 MODULE_DEVICE_TABLE(platform, vpbe_venc_devtype);
57
58 static int debug = 2;
59 module_param(debug, int, 0644);
60 MODULE_PARM_DESC(debug, "Debug level 0-2");
61
62 struct venc_state {
63 struct v4l2_subdev sd;
64 struct venc_callback *callback;
65 struct venc_platform_data *pdata;
66 struct device *pdev;
67 u32 output;
68 v4l2_std_id std;
69 spinlock_t lock;
70 void __iomem *venc_base;
71 void __iomem *vdaccfg_reg;
72 enum vpbe_version venc_type;
73 };
74
75 static inline struct venc_state *to_state(struct v4l2_subdev *sd)
76 {
77 return container_of(sd, struct venc_state, sd);
78 }
79
80 static inline u32 venc_read(struct v4l2_subdev *sd, u32 offset)
81 {
82 struct venc_state *venc = to_state(sd);
83
84 return readl(venc->venc_base + offset);
85 }
86
87 static inline u32 venc_write(struct v4l2_subdev *sd, u32 offset, u32 val)
88 {
89 struct venc_state *venc = to_state(sd);
90
91 writel(val, (venc->venc_base + offset));
92
93 return val;
94 }
95
96 static inline u32 venc_modify(struct v4l2_subdev *sd, u32 offset,
97 u32 val, u32 mask)
98 {
99 u32 new_val = (venc_read(sd, offset) & ~mask) | (val & mask);
100
101 venc_write(sd, offset, new_val);
102
103 return new_val;
104 }
105
106 static inline u32 vdaccfg_write(struct v4l2_subdev *sd, u32 val)
107 {
108 struct venc_state *venc = to_state(sd);
109
110 writel(val, venc->vdaccfg_reg);
111
112 val = readl(venc->vdaccfg_reg);
113
114 return val;
115 }
116
117 #define VDAC_COMPONENT 0x543
118 #define VDAC_S_VIDEO 0x210
119 /* This function sets the dac of the VPBE for various outputs
120 */
121 static int venc_set_dac(struct v4l2_subdev *sd, u32 out_index)
122 {
123 switch (out_index) {
124 case 0:
125 v4l2_dbg(debug, 1, sd, "Setting output to Composite\n");
126 venc_write(sd, VENC_DACSEL, 0);
127 break;
128 case 1:
129 v4l2_dbg(debug, 1, sd, "Setting output to Component\n");
130 venc_write(sd, VENC_DACSEL, VDAC_COMPONENT);
131 break;
132 case 2:
133 v4l2_dbg(debug, 1, sd, "Setting output to S-video\n");
134 venc_write(sd, VENC_DACSEL, VDAC_S_VIDEO);
135 break;
136 default:
137 return -EINVAL;
138 }
139
140 return 0;
141 }
142
143 static void venc_enabledigitaloutput(struct v4l2_subdev *sd, int benable)
144 {
145 struct venc_state *venc = to_state(sd);
146
147 v4l2_dbg(debug, 2, sd, "venc_enabledigitaloutput\n");
148
149 if (benable) {
150 venc_write(sd, VENC_VMOD, 0);
151 venc_write(sd, VENC_CVBS, 0);
152 venc_write(sd, VENC_LCDOUT, 0);
153 venc_write(sd, VENC_HSPLS, 0);
154 venc_write(sd, VENC_HSTART, 0);
155 venc_write(sd, VENC_HVALID, 0);
156 venc_write(sd, VENC_HINT, 0);
157 venc_write(sd, VENC_VSPLS, 0);
158 venc_write(sd, VENC_VSTART, 0);
159 venc_write(sd, VENC_VVALID, 0);
160 venc_write(sd, VENC_VINT, 0);
161 venc_write(sd, VENC_YCCCTL, 0);
162 venc_write(sd, VENC_DACSEL, 0);
163
164 } else {
165 venc_write(sd, VENC_VMOD, 0);
166 /* disable VCLK output pin enable */
167 venc_write(sd, VENC_VIDCTL, 0x141);
168
169 /* Disable output sync pins */
170 venc_write(sd, VENC_SYNCCTL, 0);
171
172 /* Disable DCLOCK */
173 venc_write(sd, VENC_DCLKCTL, 0);
174 venc_write(sd, VENC_DRGBX1, 0x0000057C);
175
176 /* Disable LCD output control (accepting default polarity) */
177 venc_write(sd, VENC_LCDOUT, 0);
178 if (venc->venc_type != VPBE_VERSION_3)
179 venc_write(sd, VENC_CMPNT, 0x100);
180 venc_write(sd, VENC_HSPLS, 0);
181 venc_write(sd, VENC_HINT, 0);
182 venc_write(sd, VENC_HSTART, 0);
183 venc_write(sd, VENC_HVALID, 0);
184
185 venc_write(sd, VENC_VSPLS, 0);
186 venc_write(sd, VENC_VINT, 0);
187 venc_write(sd, VENC_VSTART, 0);
188 venc_write(sd, VENC_VVALID, 0);
189
190 venc_write(sd, VENC_HSDLY, 0);
191 venc_write(sd, VENC_VSDLY, 0);
192
193 venc_write(sd, VENC_YCCCTL, 0);
194 venc_write(sd, VENC_VSTARTA, 0);
195
196 /* Set OSD clock and OSD Sync Adavance registers */
197 venc_write(sd, VENC_OSDCLK0, 1);
198 venc_write(sd, VENC_OSDCLK1, 2);
199 }
200 }
201
202 #define VDAC_CONFIG_SD_V3 0x0E21A6B6
203 #define VDAC_CONFIG_SD_V2 0x081141CF
204 /*
205 * setting NTSC mode
206 */
207 static int venc_set_ntsc(struct v4l2_subdev *sd)
208 {
209 u32 val;
210 struct venc_state *venc = to_state(sd);
211 struct venc_platform_data *pdata = venc->pdata;
212
213 v4l2_dbg(debug, 2, sd, "venc_set_ntsc\n");
214
215 /* Setup clock at VPSS & VENC for SD */
216 vpss_enable_clock(VPSS_VENC_CLOCK_SEL, 1);
217 if (pdata->setup_clock(VPBE_ENC_STD, V4L2_STD_525_60) < 0)
218 return -EINVAL;
219
220 venc_enabledigitaloutput(sd, 0);
221
222 if (venc->venc_type == VPBE_VERSION_3) {
223 venc_write(sd, VENC_CLKCTL, 0x01);
224 venc_write(sd, VENC_VIDCTL, 0);
225 val = vdaccfg_write(sd, VDAC_CONFIG_SD_V3);
226 } else if (venc->venc_type == VPBE_VERSION_2) {
227 venc_write(sd, VENC_CLKCTL, 0x01);
228 venc_write(sd, VENC_VIDCTL, 0);
229 vdaccfg_write(sd, VDAC_CONFIG_SD_V2);
230 } else {
231 /* to set VENC CLK DIV to 1 - final clock is 54 MHz */
232 venc_modify(sd, VENC_VIDCTL, 0, 1 << 1);
233 /* Set REC656 Mode */
234 venc_write(sd, VENC_YCCCTL, 0x1);
235 venc_modify(sd, VENC_VDPRO, 0, VENC_VDPRO_DAFRQ);
236 venc_modify(sd, VENC_VDPRO, 0, VENC_VDPRO_DAUPS);
237 }
238
239 venc_write(sd, VENC_VMOD, 0);
240 venc_modify(sd, VENC_VMOD, (1 << VENC_VMOD_VIE_SHIFT),
241 VENC_VMOD_VIE);
242 venc_modify(sd, VENC_VMOD, (0 << VENC_VMOD_VMD), VENC_VMOD_VMD);
243 venc_modify(sd, VENC_VMOD, (0 << VENC_VMOD_TVTYP_SHIFT),
244 VENC_VMOD_TVTYP);
245 venc_write(sd, VENC_DACTST, 0x0);
246 venc_modify(sd, VENC_VMOD, VENC_VMOD_VENC, VENC_VMOD_VENC);
247
248 return 0;
249 }
250
251 /*
252 * setting PAL mode
253 */
254 static int venc_set_pal(struct v4l2_subdev *sd)
255 {
256 struct venc_state *venc = to_state(sd);
257
258 v4l2_dbg(debug, 2, sd, "venc_set_pal\n");
259
260 /* Setup clock at VPSS & VENC for SD */
261 vpss_enable_clock(VPSS_VENC_CLOCK_SEL, 1);
262 if (venc->pdata->setup_clock(VPBE_ENC_STD, V4L2_STD_625_50) < 0)
263 return -EINVAL;
264
265 venc_enabledigitaloutput(sd, 0);
266
267 if (venc->venc_type == VPBE_VERSION_3) {
268 venc_write(sd, VENC_CLKCTL, 0x1);
269 venc_write(sd, VENC_VIDCTL, 0);
270 vdaccfg_write(sd, VDAC_CONFIG_SD_V3);
271 } else if (venc->venc_type == VPBE_VERSION_2) {
272 venc_write(sd, VENC_CLKCTL, 0x1);
273 venc_write(sd, VENC_VIDCTL, 0);
274 vdaccfg_write(sd, VDAC_CONFIG_SD_V2);
275 } else {
276 /* to set VENC CLK DIV to 1 - final clock is 54 MHz */
277 venc_modify(sd, VENC_VIDCTL, 0, 1 << 1);
278 /* Set REC656 Mode */
279 venc_write(sd, VENC_YCCCTL, 0x1);
280 }
281
282 venc_modify(sd, VENC_SYNCCTL, 1 << VENC_SYNCCTL_OVD_SHIFT,
283 VENC_SYNCCTL_OVD);
284 venc_write(sd, VENC_VMOD, 0);
285 venc_modify(sd, VENC_VMOD,
286 (1 << VENC_VMOD_VIE_SHIFT),
287 VENC_VMOD_VIE);
288 venc_modify(sd, VENC_VMOD,
289 (0 << VENC_VMOD_VMD), VENC_VMOD_VMD);
290 venc_modify(sd, VENC_VMOD,
291 (1 << VENC_VMOD_TVTYP_SHIFT),
292 VENC_VMOD_TVTYP);
293 venc_write(sd, VENC_DACTST, 0x0);
294 venc_modify(sd, VENC_VMOD, VENC_VMOD_VENC, VENC_VMOD_VENC);
295
296 return 0;
297 }
298
299 #define VDAC_CONFIG_HD_V2 0x081141EF
300 /*
301 * venc_set_480p59_94
302 *
303 * This function configures the video encoder to EDTV(525p) component setting.
304 */
305 static int venc_set_480p59_94(struct v4l2_subdev *sd)
306 {
307 struct venc_state *venc = to_state(sd);
308 struct venc_platform_data *pdata = venc->pdata;
309
310 v4l2_dbg(debug, 2, sd, "venc_set_480p59_94\n");
311 if (venc->venc_type != VPBE_VERSION_1 &&
312 venc->venc_type != VPBE_VERSION_2)
313 return -EINVAL;
314
315 /* Setup clock at VPSS & VENC for SD */
316 if (pdata->setup_clock(VPBE_ENC_CUSTOM_TIMINGS, 27000000) < 0)
317 return -EINVAL;
318
319 venc_enabledigitaloutput(sd, 0);
320
321 if (venc->venc_type == VPBE_VERSION_2)
322 vdaccfg_write(sd, VDAC_CONFIG_HD_V2);
323 venc_write(sd, VENC_OSDCLK0, 0);
324 venc_write(sd, VENC_OSDCLK1, 1);
325
326 if (venc->venc_type == VPBE_VERSION_1) {
327 venc_modify(sd, VENC_VDPRO, VENC_VDPRO_DAFRQ,
328 VENC_VDPRO_DAFRQ);
329 venc_modify(sd, VENC_VDPRO, VENC_VDPRO_DAUPS,
330 VENC_VDPRO_DAUPS);
331 }
332
333 venc_write(sd, VENC_VMOD, 0);
334 venc_modify(sd, VENC_VMOD, (1 << VENC_VMOD_VIE_SHIFT),
335 VENC_VMOD_VIE);
336 venc_modify(sd, VENC_VMOD, VENC_VMOD_HDMD, VENC_VMOD_HDMD);
337 venc_modify(sd, VENC_VMOD, (HDTV_525P << VENC_VMOD_TVTYP_SHIFT),
338 VENC_VMOD_TVTYP);
339 venc_modify(sd, VENC_VMOD, VENC_VMOD_VDMD_YCBCR8 <<
340 VENC_VMOD_VDMD_SHIFT, VENC_VMOD_VDMD);
341
342 venc_modify(sd, VENC_VMOD, VENC_VMOD_VENC, VENC_VMOD_VENC);
343
344 return 0;
345 }
346
347 /*
348 * venc_set_625p
349 *
350 * This function configures the video encoder to HDTV(625p) component setting
351 */
352 static int venc_set_576p50(struct v4l2_subdev *sd)
353 {
354 struct venc_state *venc = to_state(sd);
355 struct venc_platform_data *pdata = venc->pdata;
356
357 v4l2_dbg(debug, 2, sd, "venc_set_576p50\n");
358
359 if (venc->venc_type != VPBE_VERSION_1 &&
360 venc->venc_type != VPBE_VERSION_2)
361 return -EINVAL;
362 /* Setup clock at VPSS & VENC for SD */
363 if (pdata->setup_clock(VPBE_ENC_CUSTOM_TIMINGS, 27000000) < 0)
364 return -EINVAL;
365
366 venc_enabledigitaloutput(sd, 0);
367
368 if (venc->venc_type == VPBE_VERSION_2)
369 vdaccfg_write(sd, VDAC_CONFIG_HD_V2);
370
371 venc_write(sd, VENC_OSDCLK0, 0);
372 venc_write(sd, VENC_OSDCLK1, 1);
373
374 if (venc->venc_type == VPBE_VERSION_1) {
375 venc_modify(sd, VENC_VDPRO, VENC_VDPRO_DAFRQ,
376 VENC_VDPRO_DAFRQ);
377 venc_modify(sd, VENC_VDPRO, VENC_VDPRO_DAUPS,
378 VENC_VDPRO_DAUPS);
379 }
380
381 venc_write(sd, VENC_VMOD, 0);
382 venc_modify(sd, VENC_VMOD, (1 << VENC_VMOD_VIE_SHIFT),
383 VENC_VMOD_VIE);
384 venc_modify(sd, VENC_VMOD, VENC_VMOD_HDMD, VENC_VMOD_HDMD);
385 venc_modify(sd, VENC_VMOD, (HDTV_625P << VENC_VMOD_TVTYP_SHIFT),
386 VENC_VMOD_TVTYP);
387
388 venc_modify(sd, VENC_VMOD, VENC_VMOD_VDMD_YCBCR8 <<
389 VENC_VMOD_VDMD_SHIFT, VENC_VMOD_VDMD);
390 venc_modify(sd, VENC_VMOD, VENC_VMOD_VENC, VENC_VMOD_VENC);
391
392 return 0;
393 }
394
395 /*
396 * venc_set_720p60_internal - Setup 720p60 in venc for dm365 only
397 */
398 static int venc_set_720p60_internal(struct v4l2_subdev *sd)
399 {
400 struct venc_state *venc = to_state(sd);
401 struct venc_platform_data *pdata = venc->pdata;
402
403 if (pdata->setup_clock(VPBE_ENC_CUSTOM_TIMINGS, 74250000) < 0)
404 return -EINVAL;
405
406 venc_enabledigitaloutput(sd, 0);
407
408 venc_write(sd, VENC_OSDCLK0, 0);
409 venc_write(sd, VENC_OSDCLK1, 1);
410
411 venc_write(sd, VENC_VMOD, 0);
412 /* DM365 component HD mode */
413 venc_modify(sd, VENC_VMOD, (1 << VENC_VMOD_VIE_SHIFT),
414 VENC_VMOD_VIE);
415 venc_modify(sd, VENC_VMOD, VENC_VMOD_HDMD, VENC_VMOD_HDMD);
416 venc_modify(sd, VENC_VMOD, (HDTV_720P << VENC_VMOD_TVTYP_SHIFT),
417 VENC_VMOD_TVTYP);
418 venc_modify(sd, VENC_VMOD, VENC_VMOD_VENC, VENC_VMOD_VENC);
419 venc_write(sd, VENC_XHINTVL, 0);
420 return 0;
421 }
422
423 /*
424 * venc_set_1080i30_internal - Setup 1080i30 in venc for dm365 only
425 */
426 static int venc_set_1080i30_internal(struct v4l2_subdev *sd)
427 {
428 struct venc_state *venc = to_state(sd);
429 struct venc_platform_data *pdata = venc->pdata;
430
431 if (pdata->setup_clock(VPBE_ENC_CUSTOM_TIMINGS, 74250000) < 0)
432 return -EINVAL;
433
434 venc_enabledigitaloutput(sd, 0);
435
436 venc_write(sd, VENC_OSDCLK0, 0);
437 venc_write(sd, VENC_OSDCLK1, 1);
438
439
440 venc_write(sd, VENC_VMOD, 0);
441 /* DM365 component HD mode */
442 venc_modify(sd, VENC_VMOD, (1 << VENC_VMOD_VIE_SHIFT),
443 VENC_VMOD_VIE);
444 venc_modify(sd, VENC_VMOD, VENC_VMOD_HDMD, VENC_VMOD_HDMD);
445 venc_modify(sd, VENC_VMOD, (HDTV_1080I << VENC_VMOD_TVTYP_SHIFT),
446 VENC_VMOD_TVTYP);
447 venc_modify(sd, VENC_VMOD, VENC_VMOD_VENC, VENC_VMOD_VENC);
448 venc_write(sd, VENC_XHINTVL, 0);
449 return 0;
450 }
451
452 static int venc_s_std_output(struct v4l2_subdev *sd, v4l2_std_id norm)
453 {
454 v4l2_dbg(debug, 1, sd, "venc_s_std_output\n");
455
456 if (norm & V4L2_STD_525_60)
457 return venc_set_ntsc(sd);
458 else if (norm & V4L2_STD_625_50)
459 return venc_set_pal(sd);
460
461 return -EINVAL;
462 }
463
464 static int venc_s_dv_timings(struct v4l2_subdev *sd,
465 struct v4l2_dv_timings *dv_timings)
466 {
467 struct venc_state *venc = to_state(sd);
468 u32 height = dv_timings->bt.height;
469 int ret;
470
471 v4l2_dbg(debug, 1, sd, "venc_s_dv_timings\n");
472
473 if (height == 576)
474 return venc_set_576p50(sd);
475 else if (height == 480)
476 return venc_set_480p59_94(sd);
477 else if ((height == 720) &&
478 (venc->venc_type == VPBE_VERSION_2)) {
479 /* TBD setup internal 720p mode here */
480 ret = venc_set_720p60_internal(sd);
481 /* for DM365 VPBE, there is DAC inside */
482 vdaccfg_write(sd, VDAC_CONFIG_HD_V2);
483 return ret;
484 } else if ((height == 1080) &&
485 (venc->venc_type == VPBE_VERSION_2)) {
486 /* TBD setup internal 1080i mode here */
487 ret = venc_set_1080i30_internal(sd);
488 /* for DM365 VPBE, there is DAC inside */
489 vdaccfg_write(sd, VDAC_CONFIG_HD_V2);
490 return ret;
491 }
492 return -EINVAL;
493 }
494
495 static int venc_s_routing(struct v4l2_subdev *sd, u32 input, u32 output,
496 u32 config)
497 {
498 struct venc_state *venc = to_state(sd);
499 int ret;
500
501 v4l2_dbg(debug, 1, sd, "venc_s_routing\n");
502
503 ret = venc_set_dac(sd, output);
504 if (!ret)
505 venc->output = output;
506
507 return ret;
508 }
509
510 static long venc_ioctl(struct v4l2_subdev *sd,
511 unsigned int cmd,
512 void *arg)
513 {
514 u32 val;
515
516 switch (cmd) {
517 case VENC_GET_FLD:
518 val = venc_read(sd, VENC_VSTAT);
519 *((int *)arg) = ((val & VENC_VSTAT_FIDST) ==
520 VENC_VSTAT_FIDST);
521 break;
522 default:
523 v4l2_err(sd, "Wrong IOCTL cmd\n");
524 break;
525 }
526
527 return 0;
528 }
529
530 static const struct v4l2_subdev_core_ops venc_core_ops = {
531 .ioctl = venc_ioctl,
532 };
533
534 static const struct v4l2_subdev_video_ops venc_video_ops = {
535 .s_routing = venc_s_routing,
536 .s_std_output = venc_s_std_output,
537 .s_dv_timings = venc_s_dv_timings,
538 };
539
540 static const struct v4l2_subdev_ops venc_ops = {
541 .core = &venc_core_ops,
542 .video = &venc_video_ops,
543 };
544
545 static int venc_initialize(struct v4l2_subdev *sd)
546 {
547 struct venc_state *venc = to_state(sd);
548 int ret;
549
550 /* Set default to output to composite and std to NTSC */
551 venc->output = 0;
552 venc->std = V4L2_STD_525_60;
553
554 ret = venc_s_routing(sd, 0, venc->output, 0);
555 if (ret < 0) {
556 v4l2_err(sd, "Error setting output during init\n");
557 return -EINVAL;
558 }
559
560 ret = venc_s_std_output(sd, venc->std);
561 if (ret < 0) {
562 v4l2_err(sd, "Error setting std during init\n");
563 return -EINVAL;
564 }
565
566 return ret;
567 }
568
569 static int venc_device_get(struct device *dev, void *data)
570 {
571 struct platform_device *pdev = to_platform_device(dev);
572 struct venc_state **venc = data;
573
574 if (strstr(pdev->name, "vpbe-venc") != NULL)
575 *venc = platform_get_drvdata(pdev);
576
577 return 0;
578 }
579
580 struct v4l2_subdev *venc_sub_dev_init(struct v4l2_device *v4l2_dev,
581 const char *venc_name)
582 {
583 struct venc_state *venc;
584 int err;
585
586 err = bus_for_each_dev(&platform_bus_type, NULL, &venc,
587 venc_device_get);
588 if (venc == NULL)
589 return NULL;
590
591 v4l2_subdev_init(&venc->sd, &venc_ops);
592
593 strcpy(venc->sd.name, venc_name);
594 if (v4l2_device_register_subdev(v4l2_dev, &venc->sd) < 0) {
595 v4l2_err(v4l2_dev,
596 "vpbe unable to register venc sub device\n");
597 return NULL;
598 }
599 if (venc_initialize(&venc->sd)) {
600 v4l2_err(v4l2_dev,
601 "vpbe venc initialization failed\n");
602 return NULL;
603 }
604
605 return &venc->sd;
606 }
607 EXPORT_SYMBOL(venc_sub_dev_init);
608
609 static int venc_probe(struct platform_device *pdev)
610 {
611 const struct platform_device_id *pdev_id;
612 struct venc_state *venc;
613 struct resource *res;
614 int ret;
615
616 venc = kzalloc(sizeof(struct venc_state), GFP_KERNEL);
617 if (venc == NULL)
618 return -ENOMEM;
619
620 pdev_id = platform_get_device_id(pdev);
621 if (!pdev_id) {
622 ret = -EINVAL;
623 goto free_mem;
624 }
625 venc->venc_type = pdev_id->driver_data;
626 venc->pdev = &pdev->dev;
627 venc->pdata = pdev->dev.platform_data;
628 if (NULL == venc->pdata) {
629 dev_err(venc->pdev, "Unable to get platform data for"
630 " VENC sub device");
631 ret = -ENOENT;
632 goto free_mem;
633 }
634 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
635 if (!res) {
636 dev_err(venc->pdev,
637 "Unable to get VENC register address map\n");
638 ret = -ENODEV;
639 goto free_mem;
640 }
641
642 if (!request_mem_region(res->start, resource_size(res), "venc")) {
643 dev_err(venc->pdev, "Unable to reserve VENC MMIO region\n");
644 ret = -ENODEV;
645 goto free_mem;
646 }
647
648 venc->venc_base = ioremap_nocache(res->start, resource_size(res));
649 if (!venc->venc_base) {
650 dev_err(venc->pdev, "Unable to map VENC IO space\n");
651 ret = -ENODEV;
652 goto release_venc_mem_region;
653 }
654
655 if (venc->venc_type != VPBE_VERSION_1) {
656 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
657 if (!res) {
658 dev_err(venc->pdev,
659 "Unable to get VDAC_CONFIG address map\n");
660 ret = -ENODEV;
661 goto unmap_venc_io;
662 }
663
664 if (!request_mem_region(res->start,
665 resource_size(res), "venc")) {
666 dev_err(venc->pdev,
667 "Unable to reserve VDAC_CONFIG MMIO region\n");
668 ret = -ENODEV;
669 goto unmap_venc_io;
670 }
671
672 venc->vdaccfg_reg = ioremap_nocache(res->start,
673 resource_size(res));
674 if (!venc->vdaccfg_reg) {
675 dev_err(venc->pdev,
676 "Unable to map VDAC_CONFIG IO space\n");
677 ret = -ENODEV;
678 goto release_vdaccfg_mem_region;
679 }
680 }
681 spin_lock_init(&venc->lock);
682 platform_set_drvdata(pdev, venc);
683 dev_notice(venc->pdev, "VENC sub device probe success\n");
684 return 0;
685
686 release_vdaccfg_mem_region:
687 release_mem_region(res->start, resource_size(res));
688 unmap_venc_io:
689 iounmap(venc->venc_base);
690 release_venc_mem_region:
691 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
692 release_mem_region(res->start, resource_size(res));
693 free_mem:
694 kfree(venc);
695 return ret;
696 }
697
698 static int venc_remove(struct platform_device *pdev)
699 {
700 struct venc_state *venc = platform_get_drvdata(pdev);
701 struct resource *res;
702
703 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
704 iounmap((void *)venc->venc_base);
705 release_mem_region(res->start, resource_size(res));
706 if (venc->venc_type != VPBE_VERSION_1) {
707 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
708 iounmap((void *)venc->vdaccfg_reg);
709 release_mem_region(res->start, resource_size(res));
710 }
711 kfree(venc);
712
713 return 0;
714 }
715
716 static struct platform_driver venc_driver = {
717 .probe = venc_probe,
718 .remove = venc_remove,
719 .driver = {
720 .name = MODULE_NAME,
721 .owner = THIS_MODULE,
722 },
723 .id_table = vpbe_venc_devtype
724 };
725
726 module_platform_driver(venc_driver);
727
728 MODULE_LICENSE("GPL");
729 MODULE_DESCRIPTION("VPBE VENC Driver");
730 MODULE_AUTHOR("Texas Instruments");
This page took 0.062857 seconds and 5 git commands to generate.