V4L/DVB (12504): soc-camera: prepare soc_camera_platform.c and its users for conversion
[linux-2.6.git] / arch / sh / boards / board-ap325rxa.c
index 25a3306..7e2d2de 100644 (file)
 #include <linux/i2c.h>
 #include <linux/smsc911x.h>
 #include <linux/gpio.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/spi_gpio.h>
+#include <media/ov772x.h>
+#include <media/soc_camera.h>
 #include <media/soc_camera_platform.h>
 #include <media/sh_mobile_ceu.h>
 #include <video/sh_mobile_lcdc.h>
@@ -163,6 +167,16 @@ static void ap320_wvga_power_on(void *board_data)
        ctrl_outw(0x100, FPGA_BKLREG);
 }
 
+static void ap320_wvga_power_off(void *board_data)
+{
+       /* backlight */
+       ctrl_outw(0, FPGA_BKLREG);
+       gpio_set_value(GPIO_PTS3, 1);
+
+       /* ASD AP-320/325 LCD OFF */
+       ctrl_outw(0, FPGA_LCDREG);
+}
+
 static struct sh_mobile_lcdc_info lcdc_info = {
        .clock_source = LCDC_CLK_EXTERNAL,
        .ch[0] = {
@@ -174,7 +188,7 @@ static struct sh_mobile_lcdc_info lcdc_info = {
                        .name = "LB070WV1",
                        .xres = 800,
                        .yres = 480,
-                       .left_margin = 40,
+                       .left_margin = 32,
                        .right_margin = 160,
                        .hsync_len = 8,
                        .upper_margin = 63,
@@ -188,6 +202,7 @@ static struct sh_mobile_lcdc_info lcdc_info = {
                },
                .board_cfg = {
                        .display_on = ap320_wvga_power_on,
+                       .display_off = ap320_wvga_power_off,
                },
        }
 };
@@ -196,7 +211,7 @@ static struct resource lcdc_resources[] = {
        [0] = {
                .name   = "LCDC",
                .start  = 0xfe940000, /* P4-only space */
-               .end    = 0xfe941fff,
+               .end    = 0xfe942fff,
                .flags  = IORESOURCE_MEM,
        },
        [1] = {
@@ -212,9 +227,19 @@ static struct platform_device lcdc_device = {
        .dev            = {
                .platform_data  = &lcdc_info,
        },
+       .archdata = {
+               .hwblk_id = HWBLK_LCDC,
+       },
 };
 
+static void camera_power(int val)
+{
+       gpio_set_value(GPIO_PTZ5, val); /* RST_CAM/RSTB */
+       mdelay(10);
+}
+
 #ifdef CONFIG_I2C
+/* support for the old ncm03j camera */
 static unsigned char camera_ncm03j_magic[] =
 {
        0x87, 0x00, 0x88, 0x08, 0x89, 0x01, 0x8A, 0xE8,
@@ -235,6 +260,26 @@ static unsigned char camera_ncm03j_magic[] =
        0x63, 0xD4, 0x64, 0xEA, 0xD6, 0x0F,
 };
 
+static int camera_probe(void)
+{
+       struct i2c_adapter *a = i2c_get_adapter(0);
+       struct i2c_msg msg;
+       int ret;
+
+       if (!a)
+               return -ENODEV;
+
+       camera_power(1);
+       msg.addr = 0x6e;
+       msg.buf = camera_ncm03j_magic;
+       msg.len = 2;
+       msg.flags = 0;
+       ret = i2c_transfer(a, &msg, 1);
+       camera_power(0);
+
+       return ret;
+}
+
 static int camera_set_capture(struct soc_camera_platform_info *info,
                              int enable)
 {
@@ -243,9 +288,11 @@ static int camera_set_capture(struct soc_camera_platform_info *info,
        int ret = 0;
        int i;
 
+       camera_power(0);
        if (!enable)
                return 0; /* no disable for now */
 
+       camera_power(1);
        for (i = 0; i < ARRAY_SIZE(camera_ncm03j_magic); i += 2) {
                u_int8_t buf[8];
 
@@ -263,6 +310,9 @@ static int camera_set_capture(struct soc_camera_platform_info *info,
        return ret;
 }
 
+static int ap325rxa_camera_add(struct soc_camera_link *icl, struct device *dev);
+static void ap325rxa_camera_del(struct soc_camera_link *icl);
+
 static struct soc_camera_platform_info camera_info = {
        .iface = 0,
        .format_name = "UYVY",
@@ -276,6 +326,10 @@ static struct soc_camera_platform_info camera_info = {
        .bus_param = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH |
        SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8,
        .set_capture = camera_set_capture,
+       .link = {
+               .add_device     = ap325rxa_camera_add,
+               .del_device     = ap325rxa_camera_del,
+       },
 };
 
 static struct platform_device camera_device = {
@@ -284,11 +338,34 @@ static struct platform_device camera_device = {
                .platform_data  = &camera_info,
        },
 };
+
+static int ap325rxa_camera_add(struct soc_camera_link *icl,
+                              struct device *dev)
+{
+       if (icl != &camera_info.link || camera_probe() <= 0)
+               return -ENODEV;
+
+       return platform_device_register(&camera_device);
+}
+
+static void ap325rxa_camera_del(struct soc_camera_link *icl)
+{
+       if (icl == &camera_info.link)
+               platform_device_unregister(&camera_device);
+}
 #endif /* CONFIG_I2C */
 
+static int ov7725_power(struct device *dev, int mode)
+{
+       camera_power(0);
+       if (mode)
+               camera_power(1);
+
+       return 0;
+}
+
 static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
-       .flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH |
-       SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8,
+       .flags = SH_CEU_FLAG_USE_8BIT_BUS,
 };
 
 static struct resource ceu_resources[] = {
@@ -315,6 +392,63 @@ static struct platform_device ceu_device = {
        .dev            = {
                .platform_data  = &sh_mobile_ceu_info,
        },
+       .archdata = {
+               .hwblk_id = HWBLK_CEU,
+       },
+};
+
+struct spi_gpio_platform_data sdcard_cn3_platform_data = {
+       .sck = GPIO_PTD0,
+       .mosi = GPIO_PTD1,
+       .miso = GPIO_PTD2,
+       .num_chipselect = 1,
+};
+
+static struct platform_device sdcard_cn3_device = {
+       .name           = "spi_gpio",
+       .dev    = {
+               .platform_data  = &sdcard_cn3_platform_data,
+       },
+};
+
+static struct i2c_board_info __initdata ap325rxa_i2c_devices[] = {
+       {
+               I2C_BOARD_INFO("pcf8563", 0x51),
+       },
+};
+
+static struct i2c_board_info ap325rxa_i2c_camera[] = {
+       {
+               I2C_BOARD_INFO("ov772x", 0x21),
+       },
+};
+
+static struct ov772x_camera_info ov7725_info = {
+       .buswidth       = SOCAM_DATAWIDTH_8,
+       .flags          = OV772X_FLAG_VFLIP | OV772X_FLAG_HFLIP,
+       .edgectrl       = OV772X_AUTO_EDGECTRL(0xf, 0),
+       .link = {
+               .power          = ov7725_power,
+               .board_info     = &ap325rxa_i2c_camera[0],
+               .i2c_adapter_id = 0,
+               .module_name    = "ov772x",
+       },
+};
+
+static struct platform_device ap325rxa_camera[] = {
+       {
+               .name   = "soc-camera-pdrv",
+               .id     = 0,
+               .dev    = {
+                       .platform_data = &ov7725_info.link,
+               },
+       }, {
+               .name   = "soc-camera-pdrv",
+               .id     = 1,
+               .dev    = {
+                       .platform_data = &camera_info.link,
+               },
+       },
 };
 
 static struct platform_device *ap325rxa_devices[] __initdata = {
@@ -322,15 +456,18 @@ static struct platform_device *ap325rxa_devices[] __initdata = {
        &ap325rxa_nor_flash_device,
        &lcdc_device,
        &ceu_device,
-#ifdef CONFIG_I2C
-       &camera_device,
-#endif
        &nand_flash_device,
+       &sdcard_cn3_device,
+       &ap325rxa_camera[0],
+       &ap325rxa_camera[1],
 };
 
-static struct i2c_board_info __initdata ap325rxa_i2c_devices[] = {
+static struct spi_board_info ap325rxa_spi_devices[] = {
        {
-               I2C_BOARD_INFO("pcf8563", 0x51),
+               .modalias = "mmc_spi",
+               .max_speed_hz = 5000000,
+               .chip_select = 0,
+               .controller_data = (void *) GPIO_PTD5,
        },
 };
 
@@ -400,7 +537,7 @@ static int __init ap325rxa_devices_setup(void)
        gpio_request(GPIO_PTZ6, NULL);
        gpio_direction_output(GPIO_PTZ6, 0); /* STBY_CAM */
        gpio_request(GPIO_PTZ5, NULL);
-       gpio_direction_output(GPIO_PTZ5, 1); /* RST_CAM */
+       gpio_direction_output(GPIO_PTZ5, 0); /* RST_CAM */
        gpio_request(GPIO_PTZ4, NULL);
        gpio_direction_output(GPIO_PTZ4, 0); /* SADDR */
 
@@ -431,11 +568,26 @@ static int __init ap325rxa_devices_setup(void)
        i2c_register_board_info(0, ap325rxa_i2c_devices,
                                ARRAY_SIZE(ap325rxa_i2c_devices));
 
+       spi_register_board_info(ap325rxa_spi_devices,
+                               ARRAY_SIZE(ap325rxa_spi_devices));
+
        return platform_add_devices(ap325rxa_devices,
                                ARRAY_SIZE(ap325rxa_devices));
 }
-device_initcall(ap325rxa_devices_setup);
+arch_initcall(ap325rxa_devices_setup);
+
+/* Return the board specific boot mode pin configuration */
+static int ap325rxa_mode_pins(void)
+{
+       /* MD0=0, MD1=0, MD2=0: Clock Mode 0
+        * MD3=0: 16-bit Area0 Bus Width
+        * MD5=1: Little Endian
+        * TSTMD=1, MD8=1: Test Mode Disabled
+        */
+       return MODE_PIN5 | MODE_PIN8;
+}
 
 static struct sh_machine_vector mv_ap325rxa __initmv = {
        .mv_name = "AP-325RXA",
+       .mv_mode_pins = ap325rxa_mode_pins,
 };