15da589cbdc743e0b811d96e135dc39b0766e19b
[h-e-n] / arch / arm / mach-omap2 / board-rx51-camera.c
1 /*
2  * arch/arm/mach-omap2/board-rx51-camera.c
3  *
4  * Copyright (C) 2008 Nokia Corporation
5  *
6  * Contact: Sakari Ailus <sakari.ailus@nokia.com>
7  *          Tuukka Toivonen <tuukka.o.toivonen@nokia.com>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * version 2 as published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24
25 #include <linux/i2c.h>
26 #include <linux/i2c/twl4030.h>
27 #include <linux/delay.h>
28 #include <linux/mm.h>
29 #include <linux/videodev2.h>
30 #include <linux/device.h>
31
32 #include <asm/gpio.h>
33 #include <mach/control.h>
34 #include <mach/omap-pm.h>
35
36 #include "../../../drivers/media/video/omap34xxcam.h"
37 #include "../../../drivers/media/video/isp/ispreg.h"
38 #include "../../../drivers/media/video/et8ek8.h"
39 #include "../../../drivers/media/video/smia-sensor.h"
40
41 #include <media/ad5820.h>
42 #include <media/adp1653.h>
43 #include <media/smiaregs.h>
44
45 #include "board-rx51-camera.h"
46
47 #define ADP1653_GPIO_ENABLE     88      /* Used for resetting ADP1653 */
48 #define ADP1653_GPIO_INT        167     /* Fault interrupt */
49 #define ADP1653_GPIO_STROBE     126     /* Pin used in cam_strobe mode ->
50                                          * control using ISP drivers */
51
52 #define STINGRAY_RESET_GPIO     102
53 #define ACMELITE_RESET_GPIO     97      /* Used also to MUX between cameras */
54
55 #define RX51_CAMERA_STINGRAY    0
56 #define RX51_CAMERA_ACMELITE    1
57
58 #define RX51_SENSOR             1
59 #define RX51_LENS               2
60
61 #define GPIO_DIR_OUTPUT         0
62
63 /*
64  *
65  * Power control
66  *
67  */
68
69 /* Assign camera to peripheral power group P3 */
70 #define CAMERA_DEV_GRP          (0x4 << 5)
71 #define VAUX2_1V8               0x05
72 #define VAUX3_1V8               0x01
73 #define VAUX4_2V8               0x09
74
75 /* Earlier rx51 builds require VAUX3. */
76 #define NEEDS_VAUX3             (system_rev >= 0x100 && system_rev < 0x900)
77
78 static struct rx51_camera {
79         int okay;
80         int inuse;
81 } rx51_camera[2];
82
83 static DEFINE_MUTEX(rx51_camera_mutex);
84
85 /* Acquires the given slave `which' for camera if possible.
86  * Returns the bitmask containing previously acquired slaves for the device.
87  */
88 static int rx51_camera_acquire(int camera, int which)
89 {
90         int other = 1 - camera;
91         int old_which;
92
93         if (!rx51_camera[camera].okay)
94                 return -EINVAL;
95
96         if (rx51_camera[other].inuse)
97                 return -EBUSY;
98
99         old_which = rx51_camera[camera].inuse;
100         rx51_camera[camera].inuse |= which;
101
102         return old_which;
103 }
104
105 /* Releases the given slave `which' for camera.
106  * Returns the bitmask containing still acquired slaves for the device.
107  */
108 static int rx51_camera_release(int camera, int which)
109 {
110         rx51_camera[camera].inuse &= ~which;
111
112         return rx51_camera[camera].inuse;
113 }
114
115 static int rx51_camera_power_on_nolock(int camera)
116 {
117         int rval;
118
119         /* Reset Stingray */
120         gpio_set_value(STINGRAY_RESET_GPIO, 0);
121
122         /* Mux to Stingray and reset Acme Lite */
123         gpio_set_value(ACMELITE_RESET_GPIO, 0);
124
125         /* VAUX2=1.8 V (muxer voltage) */
126         rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
127                                     VAUX2_1V8, TWL4030_VAUX2_DEDICATED);
128         if (rval)
129                 goto out;
130         rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
131                                     CAMERA_DEV_GRP, TWL4030_VAUX2_DEV_GRP);
132         if (rval)
133                 goto out;
134
135         /* Off & sleep -> Active state */
136         rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
137                                     0xEE, TWL4030_VAUX2_REMAP);
138         if (rval)
139                 goto out;
140
141         /* VAUX4=2.8 V (camera VANA) */
142         rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
143                                     VAUX4_2V8, TWL4030_VAUX4_DEDICATED);
144         if (rval)
145                 goto out;
146         rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
147                                     CAMERA_DEV_GRP, TWL4030_VAUX4_DEV_GRP);
148         if (rval)
149                 goto out;
150         rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
151                                     0xEE, TWL4030_VAUX4_REMAP);
152         if (rval)
153                 goto out;
154
155         if (NEEDS_VAUX3) {
156                 /* VAUX3=1.8 V (camera VDIG) */
157                 printk(KERN_INFO "%s: VAUX3 on for old board\n", __func__);
158                 rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
159                                             VAUX3_1V8,
160                                             TWL4030_VAUX3_DEDICATED);
161                 if (rval)
162                         goto out;
163                 rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
164                                             CAMERA_DEV_GRP,
165                                             TWL4030_VAUX3_DEV_GRP);
166                 if (rval)
167                         goto out;
168                 rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
169                                             0xEE, TWL4030_VAUX3_REMAP);
170                 if (rval)
171                         goto out;
172         }
173
174         /* Let the voltages stabilize */
175         udelay(15);
176
177         /* XSHUTDOWN on, enable camera and set muxer */
178         gpio_set_value(camera == RX51_CAMERA_STINGRAY ?
179                        STINGRAY_RESET_GPIO : ACMELITE_RESET_GPIO, 1);
180
181         /* CONTROL_CSIRXFE */
182         omap_writel(
183                 /*
184                  * CSIb receiver data/clock or data/strobe mode
185                  *
186                  * Stingray uses data/strobe.
187                  */
188                 ((camera ? 0 : 1) << 10)
189                 | BIT(12)       /* Enable differential transceiver */
190                 | BIT(13)       /* Disable reset */
191                 , OMAP343X_CTRL_BASE + OMAP343X_CONTROL_CSIRXFE);
192
193         /* Let the voltages stabilize */
194         udelay(15);
195
196         return 0;
197
198 out:
199         printk(KERN_ALERT "%s: Error %d in writing to TWL4030!\n", __func__,
200                rval);
201
202         return rval;
203 }
204
205 static int rx51_camera_power_on(int camera, int which)
206 {
207         int rval;
208
209         mutex_lock(&rx51_camera_mutex);
210
211         rval = rx51_camera_acquire(camera, which);
212
213         if (!rval)
214                 rval = rx51_camera_power_on_nolock(camera);
215         else if (rval > 0)
216                 rval = 0;
217
218         mutex_unlock(&rx51_camera_mutex);
219
220         if (rval < 0)
221                 printk(KERN_INFO "%s: power_on camera %d which %d failed\n",
222                        __func__, camera, which);
223
224         return rval;
225 }
226
227 static void rx51_camera_power_off_nolock(int camera)
228 {
229         int rval;
230
231         /* Reset cameras */
232         gpio_set_value(STINGRAY_RESET_GPIO, 0);
233         gpio_set_value(ACMELITE_RESET_GPIO, 0);
234
235         /* VAUX2 (muxer voltage) off */
236         rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
237                                     0, TWL4030_VAUX2_DEV_GRP);
238         if (rval)
239                 goto out;
240         /* Off & sleep -> Off state */
241         rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
242                                     0x00, TWL4030_VAUX2_REMAP);
243         if (rval)
244                 goto out;
245
246         /* VAUX4 (camera VANA) off */
247         rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
248                                     0, TWL4030_VAUX4_DEV_GRP);
249         if (rval)
250                 goto out;
251         rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
252                                     0x00, TWL4030_VAUX4_REMAP);
253         if (rval)
254                 goto out;
255
256         if (NEEDS_VAUX3) {
257                 printk(KERN_INFO "%s: VAUX3 off for old board\n", __func__);
258                 /* VAUX3 (camera VDIG) off */
259                 rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
260                                             0, TWL4030_VAUX3_DEV_GRP);
261                 if (rval)
262                         goto out;
263                 rval = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
264                                             0x00, TWL4030_VAUX3_REMAP);
265                 if (rval)
266                         goto out;
267         }
268
269         return;
270
271 out:
272         printk(KERN_ALERT "%s: Error %d in writing to TWL4030!\n", __func__,
273                rval);
274 }
275
276 static void rx51_camera_power_off(int camera, int which)
277 {
278         int rval;
279
280         mutex_lock(&rx51_camera_mutex);
281
282         rval = rx51_camera_release(camera, which);
283         if (!rval)
284                 rx51_camera_power_off_nolock(camera);
285
286         mutex_unlock(&rx51_camera_mutex);
287 }
288
289 static void __init rx51_stingray_init(void)
290 {
291         if (gpio_request(STINGRAY_RESET_GPIO, "stingray reset") != 0) {
292                 printk(KERN_INFO "%s: unable to acquire Stingray reset gpio\n",
293                        __FUNCTION__);
294                 return;
295         }
296
297         /* XSHUTDOWN off, reset  */
298         gpio_direction_output(STINGRAY_RESET_GPIO, 0);
299         rx51_camera_power_off_nolock(RX51_CAMERA_STINGRAY);
300         rx51_camera[RX51_CAMERA_STINGRAY].okay = 1;
301         rx51_camera[RX51_CAMERA_STINGRAY].inuse = 0;
302 }
303
304 static void __init rx51_acmelite_init(void)
305 {
306         if (gpio_request(ACMELITE_RESET_GPIO, "acmelite reset") != 0) {
307                 printk(KERN_INFO "%s: unable to acquire Acme Lite reset gpio\n",
308                        __FUNCTION__);
309                 return;
310         }
311
312         /* XSHUTDOWN off, reset  */
313         gpio_direction_output(ACMELITE_RESET_GPIO, 0);
314         rx51_camera_power_off_nolock(RX51_CAMERA_ACMELITE);
315         rx51_camera[RX51_CAMERA_ACMELITE].okay = 1;
316         rx51_camera[RX51_CAMERA_ACMELITE].inuse = 0;
317 }
318
319 static int __init rx51_adp1653_init(void)
320 {
321         int err;
322
323         err = gpio_request(ADP1653_GPIO_ENABLE, "adp1653 enable");
324         if (err) {
325                 printk(KERN_ERR ADP1653_NAME
326                        " Failed to request EN gpio\n");
327                 err = -ENODEV;
328                 goto err_omap_request_gpio;
329         }
330
331         err = gpio_request(ADP1653_GPIO_INT, "adp1653 interrupt");
332         if (err) {
333                 printk(KERN_ERR ADP1653_NAME " Failed to request IRQ gpio\n");
334                 err = -ENODEV;
335                 goto err_omap_request_gpio_2;
336         }
337
338         err = gpio_request(ADP1653_GPIO_STROBE, "adp1653 strobe");
339         if (err) {
340                 printk(KERN_ERR ADP1653_NAME
341                        " Failed to request STROBE gpio\n");
342                 err = -ENODEV;
343                 goto err_omap_request_gpio_3;
344         }
345
346         gpio_direction_output(ADP1653_GPIO_ENABLE, 0);
347         gpio_direction_input(ADP1653_GPIO_INT);
348         gpio_direction_output(ADP1653_GPIO_STROBE, 0);
349
350         return 0;
351
352 err_omap_request_gpio_3:
353         gpio_free(ADP1653_GPIO_INT);
354
355 err_omap_request_gpio_2:
356         gpio_free(ADP1653_GPIO_ENABLE);
357
358 err_omap_request_gpio:
359         return err;
360 }
361
362 static int __init rx51_camera_hw_init(void)
363 {
364         int rval;
365
366         rval = rx51_adp1653_init();
367         if (rval)
368                 return rval;
369
370         mutex_init(&rx51_camera_mutex);
371         rx51_stingray_init();
372         rx51_acmelite_init();
373
374         return 0;
375 }
376
377 /*
378  *
379  * Stingray
380  *
381  */
382
383 #define STINGRAY_XCLK           OMAP34XXCAM_XCLK_A
384
385 static struct isp_interface_config rx51_stingray_config = {
386         .ccdc_par_ser = ISP_CSIB,
387         .dataline_shift = 0,
388         .hsvs_syncdetect = ISPCTRL_SYNC_DETECT_VSRISE,
389         .strobe = 0,
390         .prestrobe = 0,
391         .shutter = 0,
392         .wait_hs_vs = 1,
393         .u = {
394                 .csi = {
395                          .crc           =       1,
396                          .mode          =       0,
397                          .edge          =       1,
398                          .signalling    =       1,
399                          .strobe_clock_inv =    0,
400                          .vs_edge       =       0,
401                          .channel       =       0,
402                          .vpclk         =       1,
403                          .data_start    =       0,
404                  },
405         },
406 };
407
408 static struct omap34xxcam_hw_config rx51_stingray_omap34xxcam_hw_config = {
409         .dev_index      = 0,
410         .dev_minor      = 0,
411         .dev_type       = OMAP34XXCAM_SLAVE_SENSOR,
412         .u              = {
413                 .sensor         = {
414                          .sensor_isp    = 0,
415                          .capture_mem   = PAGE_ALIGN(2608 * 1966 * 2) * 2,
416                          .ival_default  = { 1, 30 },
417                  },
418         },
419 };
420
421 static int rx51_stingray_configure_interface(struct v4l2_int_device *s,
422                                              struct smia_mode *mode)
423 {
424         struct omap34xxcam_videodev *vdev = s->u.slave->master->priv;
425         static const int S = 8;
426
427         /* Configure sensor interface. */
428         rx51_stingray_config.u.csi.format = mode->pixel_format;
429         rx51_stingray_config.u.csi.data_size = mode->window_height;
430         /* Calculate average pixel clock per line. Assume buffers can spread
431          * the data over horizontal blanking time. Rounding upwards. */
432         rx51_stingray_config.pixelclk =
433                 mode->window_width
434                 * (((mode->pixel_clock + (1<<S) - 1) >> S) + mode->width - 1)
435                 / mode->width;
436         rx51_stingray_config.pixelclk <<= S;
437         return isp_configure_interface(vdev->cam->isp, &rx51_stingray_config);
438 }
439
440 static int rx51_stingray_set_xclk(struct v4l2_int_device *s, int hz)
441 {
442         struct omap34xxcam_videodev *vdev = s->u.slave->master->priv;
443
444         isp_set_xclk(vdev->cam->isp, hz, STINGRAY_XCLK);
445
446         return 0;
447 }
448
449 static int rx51_stingray_power_on(struct v4l2_int_device *s)
450 {
451         struct omap34xxcam_videodev *vdev = s->u.slave->master->priv;
452         struct device *dev = vdev->cam->isp;
453         int rval;
454
455         omap_pm_set_min_bus_tput(dev, OCP_INITIATOR_AGENT, 400000);
456
457         rval = rx51_camera_power_on(RX51_CAMERA_STINGRAY, RX51_SENSOR);
458
459         if (rval)
460                 omap_pm_set_min_bus_tput(dev, 2, 0);
461
462         return rval;
463 }
464
465 static int rx51_stingray_power_off(struct v4l2_int_device *s)
466 {
467         struct omap34xxcam_videodev *vdev = s->u.slave->master->priv;
468         struct device *dev = vdev->cam->isp;
469
470         rx51_camera_power_off(RX51_CAMERA_STINGRAY, RX51_SENSOR);
471
472         omap_pm_set_min_bus_tput(dev, OCP_INITIATOR_AGENT, 0);
473
474         return 0;
475 }
476
477 static int rx51_stingray_g_priv(struct v4l2_int_device *s, void *priv)
478 {
479         *(struct omap34xxcam_hw_config *)priv =
480                 rx51_stingray_omap34xxcam_hw_config;
481
482         return 0;
483 }
484
485 static struct et8ek8_platform_data et8ek8_tmp_platform_data;
486
487 static struct et8ek8_platform_data et8ek8_my_platform_data = {
488         .g_priv                 = rx51_stingray_g_priv,
489         .configure_interface    = rx51_stingray_configure_interface,
490         .set_xclk               = rx51_stingray_set_xclk,
491         .power_on               = rx51_stingray_power_on,
492         .power_off              = rx51_stingray_power_off,
493 };
494
495 /*
496  *
497  * AD5820
498  *
499  */
500
501 static struct omap34xxcam_hw_config ad5820_omap34xxcam_hw_config = {
502         .dev_index      = 0,
503         .dev_minor      = 0,
504         .dev_type       = OMAP34XXCAM_SLAVE_LENS,
505         .u              = {
506                 .lens           = {
507                  },
508         },
509 };
510
511 static int ad5820_g_priv(struct v4l2_int_device *s, void *priv)
512 {
513         *(struct omap34xxcam_hw_config *)priv = ad5820_omap34xxcam_hw_config;
514
515         return 0;
516 }
517
518 static int ad5820_s_power(struct v4l2_int_device *s, enum v4l2_power state)
519 {
520         if (state == V4L2_POWER_ON)
521                 return rx51_camera_power_on(RX51_CAMERA_STINGRAY, RX51_LENS);
522         else
523                 rx51_camera_power_off(RX51_CAMERA_STINGRAY, RX51_LENS);
524
525         return 0;
526 }
527
528 static struct ad5820_platform_data ad5820_tmp_platform_data;
529
530 static struct ad5820_platform_data ad5820_my_platform_data = {
531         .g_priv         = ad5820_g_priv,
532         .s_power        = ad5820_s_power,
533
534 };
535
536 /*
537  *
538  * ADP1653
539  *
540  */
541
542 static struct omap34xxcam_hw_config adp1653_omap34xxcam_hw_config = {
543         .dev_index      = 0,
544         .dev_minor      = 0,
545         .dev_type       = OMAP34XXCAM_SLAVE_FLASH,
546         .u              = {
547                 .flash          = {
548                  },
549         },
550 };
551
552 static int rx51_adp1653_g_priv(struct v4l2_int_device *s, void *priv)
553 {
554         *(struct omap34xxcam_hw_config *)priv = adp1653_omap34xxcam_hw_config;
555
556         return 0;
557 }
558
559 static int rx51_adp1653_power_on(struct v4l2_int_device *s)
560 {
561         gpio_set_value(ADP1653_GPIO_ENABLE, 1);
562
563         /* Some delay is apparently required. */
564         udelay(400);
565
566         return 0;
567 }
568
569 static int rx51_adp1653_power_off(struct v4l2_int_device *s)
570 {
571         gpio_set_value(ADP1653_GPIO_ENABLE, 0);
572
573         return 0;
574 }
575
576 static struct adp1653_platform_data adp1653_tmp_platform_data;
577
578 static struct adp1653_platform_data adp1653_my_platform_data = {
579         .g_priv                  = rx51_adp1653_g_priv,
580         .power_on                = rx51_adp1653_power_on,
581         .power_off               = rx51_adp1653_power_off,
582         /* Must be limited to 500 ms in RX-51 */
583         .max_flash_timeout       = 500000,              /* us */
584         /* Must be limited to 320 mA in RX-51 B3 and newer hardware */
585         .max_flash_intensity     = 19,
586         /* Must be limited to 50 mA in RX-51 */
587         .max_torch_intensity     = 1,
588         .max_indicator_intensity = ADP1653_REG_OUT_SEL_ILED_MAX,
589 };
590
591 /*
592  *
593  * Acmelite
594  *
595  */
596
597 #define ACMELITE_XCLK           OMAP34XXCAM_XCLK_A
598
599 static struct isp_interface_config rx51_acmelite_config = {
600         .ccdc_par_ser = ISP_CSIB,
601         .dataline_shift = 0,
602         .hsvs_syncdetect = ISPCTRL_SYNC_DETECT_VSRISE,
603         .strobe = 0,
604         .prestrobe = 0,
605         .shutter = 0,
606         .wait_hs_vs = 1,
607         .u = {
608                 .csi = {
609                          .crc           =       0,
610                          .mode          =       0,
611                          .edge          =       1,
612                          .signalling    =       0,
613                          .strobe_clock_inv =    0,
614                          .vs_edge       =       0,
615                          .channel       =       0,
616                          .vpclk         =       2,
617                          .data_start    =       4,
618                          .format        =       V4L2_PIX_FMT_SGRBG10,
619                  },
620         },
621 };
622
623 static struct omap34xxcam_hw_config rx51_acmelite_omap34xxcam_hw_config = {
624         .dev_index      = 1,
625         .dev_minor      = 1,
626         .dev_type       = OMAP34XXCAM_SLAVE_SENSOR,
627         .u              = {
628                 .sensor         = {
629                          .sensor_isp    = 0,
630                          .capture_mem   = PAGE_ALIGN(648 * 488 * 2) * 4,
631                          .ival_default  = { 1, 30 },
632                  },
633         },
634 };
635
636 static int rx51_acmelite_configure_interface(struct v4l2_int_device *s,
637                                              int width, int height)
638 {
639         struct omap34xxcam_videodev *vdev = s->u.slave->master->priv;
640
641         /* Configure sensor interface. */
642         rx51_acmelite_config.u.csi.data_size = height;
643
644         return isp_configure_interface(vdev->cam->isp, &rx51_acmelite_config);
645 }
646
647 static int rx51_acmelite_set_xclk(struct v4l2_int_device *s, int hz)
648 {
649         struct omap34xxcam_videodev *vdev = s->u.slave->master->priv;
650
651         isp_set_xclk(vdev->cam->isp, hz, ACMELITE_XCLK);
652
653         return 0;
654 }
655
656 static int rx51_acmelite_power_on(struct v4l2_int_device *s)
657 {
658         struct omap34xxcam_videodev *vdev = s->u.slave->master->priv;
659         struct device *dev = vdev->cam->isp;
660         int rval;
661
662         omap_pm_set_min_bus_tput(dev, OCP_INITIATOR_AGENT, 400000);
663
664         rval = rx51_camera_power_on(RX51_CAMERA_ACMELITE, RX51_SENSOR);
665
666         if (rval)
667                 omap_pm_set_min_bus_tput(dev, 2, 0);
668
669         return rval;
670 }
671
672 static int rx51_acmelite_power_off(struct v4l2_int_device *s)
673 {
674         struct omap34xxcam_videodev *vdev = s->u.slave->master->priv;
675         struct device *dev = vdev->cam->isp;
676
677         rx51_camera_power_off(RX51_CAMERA_ACMELITE, RX51_SENSOR);
678
679         omap_pm_set_min_bus_tput(dev, OCP_INITIATOR_AGENT, 0);
680
681         return 0;
682 }
683
684 static int rx51_acmelite_g_priv(struct v4l2_int_device *s, void *priv)
685 {
686         *(struct omap34xxcam_hw_config *)priv =
687                 rx51_acmelite_omap34xxcam_hw_config;
688
689         return 0;
690 }
691
692 static struct smia_sensor_platform_data smia_sensor_tmp_platform_data;
693
694 static struct smia_sensor_platform_data smia_sensor_my_platform_data = {
695         .g_priv                 = rx51_acmelite_g_priv,
696         .configure_interface    = rx51_acmelite_configure_interface,
697         .set_xclk               = rx51_acmelite_set_xclk,
698         .power_on               = rx51_acmelite_power_on,
699         .power_off              = rx51_acmelite_power_off,
700 };
701
702 /*
703  *
704  * Init it all
705  *
706  */
707
708 static int __init rx51_camera_init(void) {
709         int err;
710
711         err = rx51_camera_hw_init();
712         if (err)
713                 return err;
714
715         /* ADP1653 */
716         adp1653_tmp_platform_data = rx51_adp1653_platform_data;
717         rx51_adp1653_platform_data = adp1653_my_platform_data;
718
719         /* Stingray */
720         et8ek8_tmp_platform_data = rx51_et8ek8_platform_data;
721         rx51_et8ek8_platform_data = et8ek8_my_platform_data;
722
723         /* AD5820 */
724         ad5820_tmp_platform_data = rx51_ad5820_platform_data;
725         rx51_ad5820_platform_data = ad5820_my_platform_data;
726
727         /* Acmelite */
728         smia_sensor_tmp_platform_data = rx51_smia_sensor_platform_data;
729         rx51_smia_sensor_platform_data = smia_sensor_my_platform_data;
730
731         /* FIXME: can't unload yet. */
732         __module_get(THIS_MODULE);
733
734         /* FIXME: somehow initiate device init. */
735         v4l2_int_device_try_attach_all();
736
737         return 0;
738 }
739
740 static void __exit rx51_camera_exit(void) {
741         rx51_et8ek8_platform_data = et8ek8_tmp_platform_data;
742         rx51_ad5820_platform_data = ad5820_tmp_platform_data;
743         rx51_adp1653_platform_data = adp1653_tmp_platform_data;
744         rx51_smia_sensor_platform_data = smia_sensor_tmp_platform_data;
745
746         gpio_free(ADP1653_GPIO_ENABLE);
747         gpio_free(ADP1653_GPIO_INT);
748         gpio_free(ADP1653_GPIO_STROBE);
749 }
750
751 module_init(rx51_camera_init);
752 module_exit(rx51_camera_exit);
753
754 MODULE_LICENSE("GPL");