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 1e6daa3..7e2d2de 100644 (file)
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/mtd/physmap.h>
+#include <linux/mtd/sh_flctl.h>
 #include <linux/delay.h>
 #include <linux/i2c.h>
-#include <linux/smc911x.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>
 #include <asm/io.h>
 #include <asm/clock.h>
-#include <asm/sh7723.h>
+#include <cpu/sh7723.h>
 
-static struct smc911x_platdata smc911x_info = {
-       .flags = SMC911X_USE_32BIT,
-       .irq_flags = IRQF_TRIGGER_LOW,
+static struct smsc911x_platform_config smsc911x_config = {
+       .phy_interface  = PHY_INTERFACE_MODE_MII,
+       .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
+       .irq_type       = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
+       .flags          = SMSC911X_USE_32BIT,
 };
 
-static struct resource smc9118_resources[] = {
+static struct resource smsc9118_resources[] = {
        [0] = {
                .start  = 0xb6080000,
                .end    = 0xb60fffff,
@@ -44,13 +51,13 @@ static struct resource smc9118_resources[] = {
        }
 };
 
-static struct platform_device smc9118_device = {
-       .name           = "smc911x",
+static struct platform_device smsc9118_device = {
+       .name           = "smsc911x",
        .id             = -1,
-       .num_resources  = ARRAY_SIZE(smc9118_resources),
-       .resource       = smc9118_resources,
+       .num_resources  = ARRAY_SIZE(smsc9118_resources),
+       .resource       = smsc9118_resources,
        .dev            = {
-               .platform_data = &smc911x_info,
+               .platform_data = &smsc911x_config,
        },
 };
 
@@ -108,10 +115,45 @@ static struct platform_device ap325rxa_nor_flash_device = {
        },
 };
 
+static struct mtd_partition nand_partition_info[] = {
+       {
+               .name   = "nand_data",
+               .offset = 0,
+               .size   = MTDPART_SIZ_FULL,
+       },
+};
+
+static struct resource nand_flash_resources[] = {
+       [0] = {
+               .start  = 0xa4530000,
+               .end    = 0xa45300ff,
+               .flags  = IORESOURCE_MEM,
+       }
+};
+
+static struct sh_flctl_platform_data nand_flash_data = {
+       .parts          = nand_partition_info,
+       .nr_parts       = ARRAY_SIZE(nand_partition_info),
+       .flcmncr_val    = FCKSEL_E | TYPESEL_SET | NANWF_E,
+       .has_hwecc      = 1,
+};
+
+static struct platform_device nand_flash_device = {
+       .name           = "sh_flctl",
+       .resource       = nand_flash_resources,
+       .num_resources  = ARRAY_SIZE(nand_flash_resources),
+       .dev            = {
+               .platform_data = &nand_flash_data,
+       },
+};
+
 #define FPGA_LCDREG    0xB4100180
 #define FPGA_BKLREG    0xB4100212
 #define FPGA_LCDREG_VAL        0x0018
 #define PORT_MSELCRB   0xA4050182
+#define PORT_HIZCRC    0xA405015C
+#define PORT_DRVCRA    0xA405018A
+#define PORT_DRVCRB    0xA405018C
 
 static void ap320_wvga_power_on(void *board_data)
 {
@@ -125,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] = {
@@ -136,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,
@@ -150,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,
                },
        }
 };
@@ -158,9 +211,13 @@ static struct resource lcdc_resources[] = {
        [0] = {
                .name   = "LCDC",
                .start  = 0xfe940000, /* P4-only space */
-               .end    = 0xfe941fff,
+               .end    = 0xfe942fff,
                .flags  = IORESOURCE_MEM,
        },
+       [1] = {
+               .start  = 28,
+               .flags  = IORESOURCE_IRQ,
+       },
 };
 
 static struct platform_device lcdc_device = {
@@ -170,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,
@@ -193,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)
 {
@@ -201,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];
 
@@ -221,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",
@@ -234,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 = {
@@ -242,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[] = {
@@ -267,24 +386,89 @@ static struct resource ceu_resources[] = {
 
 static struct platform_device ceu_device = {
        .name           = "sh_mobile_ceu",
+       .id             = 0, /* "ceu0" clock */
        .num_resources  = ARRAY_SIZE(ceu_resources),
        .resource       = ceu_resources,
        .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 = {
-       &smc9118_device,
+       &smsc9118_device,
        &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[] = {
+       {
+               .modalias = "mmc_spi",
+               .max_speed_hz = 5000000,
+               .chip_select = 0,
+               .controller_data = (void *) GPIO_PTD5,
+       },
 };
 
 static int __init ap325rxa_devices_setup(void)
@@ -304,7 +488,6 @@ static int __init ap325rxa_devices_setup(void)
        gpio_export(GPIO_PTF7, 0);
 
        /* LCDC */
-       clk_always_enable("mstp200");
        gpio_request(GPIO_FN_LCDD15, NULL);
        gpio_request(GPIO_FN_LCDD14, NULL);
        gpio_request(GPIO_FN_LCDD13, NULL);
@@ -335,7 +518,6 @@ static int __init ap325rxa_devices_setup(void)
        gpio_direction_output(GPIO_PTS3, 1);
 
        /* CEU */
-       clk_always_enable("mstp203");
        gpio_request(GPIO_FN_VIO_CLK2, NULL);
        gpio_request(GPIO_FN_VIO_VD2, NULL);
        gpio_request(GPIO_FN_VIO_HD2, NULL);
@@ -355,27 +537,57 @@ 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 */
 
        ctrl_outw(ctrl_inw(PORT_MSELCRB) & ~0x0001, PORT_MSELCRB);
 
+       /* FLCTL */
+       gpio_request(GPIO_FN_FCE, NULL);
+       gpio_request(GPIO_FN_NAF7, NULL);
+       gpio_request(GPIO_FN_NAF6, NULL);
+       gpio_request(GPIO_FN_NAF5, NULL);
+       gpio_request(GPIO_FN_NAF4, NULL);
+       gpio_request(GPIO_FN_NAF3, NULL);
+       gpio_request(GPIO_FN_NAF2, NULL);
+       gpio_request(GPIO_FN_NAF1, NULL);
+       gpio_request(GPIO_FN_NAF0, NULL);
+       gpio_request(GPIO_FN_FCDE, NULL);
+       gpio_request(GPIO_FN_FOE, NULL);
+       gpio_request(GPIO_FN_FSC, NULL);
+       gpio_request(GPIO_FN_FWE, NULL);
+       gpio_request(GPIO_FN_FRB, NULL);
+
+       ctrl_outw(0, PORT_HIZCRC);
+       ctrl_outw(0xFFFF, PORT_DRVCRA);
+       ctrl_outw(0xFFFF, PORT_DRVCRB);
+
        platform_resource_setup_memory(&ceu_device, "ceu", 4 << 20);
 
        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);
 
-static void __init ap325rxa_setup(char **cmdline_p)
+/* 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_setup = ap325rxa_setup,
+       .mv_mode_pins = ap325rxa_mode_pins,
 };