From d2b9a8a9162d3dd1986a7fddae5de0d5e569d937 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Mon, 11 Dec 2006 14:20:05 -0800 Subject: [PATCH] V4L: omap camera builds again Fix some bitrot, including basic build/load functionality: - ov9640 code had syntax errors (!) and referenced missing fields - camera core included all kinds of crap, but not the v4l2 stuff - both omap16xx and 17xx used the wrong base clock - 16xx oopsed because its base clock did not exist - misuse of machine_is_omap_h3() in place of cpu_is_omap1710() - several exported symbols were goofed up - used bad call to reserve mem region - didn't destroy platform device correctly - ov9640 needed MODULE_LICENSE("GPL") It's probably best to think of this as just making the camera code build again, load/unload as modules, stop oopsing on 16xx, and be a smidgeon cleaner ... since my (early/prototype) Mistral board won't actually get to UBoot when a camera is connected. :( Signed-off-by: David Brownell Signed-off-by: Tony Lindgren --- drivers/media/video/omap/camera_core.c | 51 +++++++------------ drivers/media/video/omap/camera_core.h | 2 +- drivers/media/video/omap/camera_hw_if.h | 4 +- drivers/media/video/omap/omap16xxcam.c | 62 +++++++++++++----------- drivers/media/video/omap/sensor_if.h | 4 +- drivers/media/video/omap/sensor_ov9640.c | 27 +++++++---- 6 files changed, 77 insertions(+), 73 deletions(-) diff --git a/drivers/media/video/omap/camera_core.c b/drivers/media/video/omap/camera_core.c index f2662647ee8..ab91cc100c7 100644 --- a/drivers/media/video/omap/camera_core.c +++ b/drivers/media/video/omap/camera_core.c @@ -20,40 +20,24 @@ * History: * 27/03/05 Vladimir Barinov - Added support for power management */ - #include #include #include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include #include -#include -#include #include #include +#include + #include -#include -#include #include "sensor_if.h" #include "camera_hw_if.h" #include "camera_core.h" - -struct camera_device *camera_dev; -extern struct omap_camera_sensor camera_sensor_if; -extern struct camera_hardware camera_hardware_if; - + + +static struct camera_device *camera_dev; static void camera_core_sgdma_process(struct camera_device *cam); /* module parameters */ @@ -1165,39 +1149,38 @@ static struct platform_driver camera_core_driver = { #endif }; -static struct platform_device camera_core_device = { - .name = CAM_NAME, - .dev = { - .release = NULL, - }, - .id = 0, -}; +/* FIXME register omap16xx or omap24xx camera device in arch/arm/... + * system init code, with its resources and mux setup, NOT here. + * Then MODULE_ALIAS(CAM_NAME) so it hotplugs and coldplugs; this + * "legacy" driver style is trouble. + */ +static struct platform_device *cam; -void __exit +static void __exit camera_core_cleanup(void) { platform_driver_unregister(&camera_core_driver); - platform_device_unregister(&camera_core_device); - - return; + platform_device_unregister(cam); } static char banner[] __initdata = KERN_INFO "OMAP Camera driver initialzing\n"; -int __init +static int __init camera_core_init(void) { printk(banner); - platform_device_register(&camera_core_device); platform_driver_register(&camera_core_driver); + cam = platform_device_register_simple(CAM_NAME, -1, NULL, 0); + return 0; } MODULE_AUTHOR("Texas Instruments."); MODULE_DESCRIPTION("OMAP Video for Linux camera driver"); MODULE_LICENSE("GPL"); + module_param(video_nr, int, 0); MODULE_PARM_DESC(video_nr, "Minor number for video device (-1 ==> auto assign)"); diff --git a/drivers/media/video/omap/camera_core.h b/drivers/media/video/omap/camera_core.h index 3c9210adca3..0f944461171 100644 --- a/drivers/media/video/omap/camera_core.h +++ b/drivers/media/video/omap/camera_core.h @@ -151,6 +151,6 @@ struct camera_fh { struct videobuf_queue vbq; }; -#define CAM_NAME "omap-camera" +#define CAM_NAME "omap_camera" #endif /* CAMERA_CORE__H */ diff --git a/drivers/media/video/omap/camera_hw_if.h b/drivers/media/video/omap/camera_hw_if.h index 2c941b5b2a7..0976e45bd44 100644 --- a/drivers/media/video/omap/camera_hw_if.h +++ b/drivers/media/video/omap/camera_hw_if.h @@ -44,5 +44,7 @@ struct camera_hardware { void *, void *, void *); int (*finish_dma)(void *); }; - + +extern struct camera_hardware camera_hardware_if; + #endif /* OMAP_CAMERA_HW_IF_H */ diff --git a/drivers/media/video/omap/omap16xxcam.c b/drivers/media/video/omap/omap16xxcam.c index b36773a2d7c..3b8065891f2 100644 --- a/drivers/media/video/omap/omap16xxcam.c +++ b/drivers/media/video/omap/omap16xxcam.c @@ -38,7 +38,8 @@ #include "omap16xxcam.h" #include "camera_hw_if.h" #include "camera_core.h" - + + #define CONF_CAMERAIF_RESET_R 5 #define EN_PER 0 @@ -68,7 +69,9 @@ struct omap16xxcam { unsigned long iobase_phys; /* frequncy (in Hz) of camera interface functional clock (ocp_clk) */ - unsigned long ocp_clk; + unsigned long ocp_clk; + + struct clk *func_clk; /* dma related stuff */ spinlock_t dma_lock; @@ -79,7 +82,7 @@ struct omap16xxcam { int dma_channel_number2; wait_queue_head_t vsync_wait; - + int new; }; static struct omap16xxcam hardware_data; @@ -124,15 +127,10 @@ omap16xx_cam_init(void) OMAP1610_RESET_CONTROL); /* Enable peripheral reset */ - omap_writew(omap_readw(ARM_RSTCT2) | (1 << EN_PER), ARM_RSTCT2); + omap_writew(omap_readw(ARM_RSTCT2) | (1 << EN_PER), ARM_RSTCT2); /* enable peripheral clock */ - if (machine_is_omap_h3()) - clk_enable(clk_get(0, "tc2_ck")); - else { - clk_enable(clk_get(0, "armper_ck")); - clk_enable(clk_get(0, "armxor_ck")); - } + clk_enable(hardware_data.func_clk); } static void @@ -321,8 +319,8 @@ omap16xxcam_start_dma(struct sgdma_state *sgdma, data->camdma[count].callback = callback; data->camdma[count].arg1 = arg1; data->camdma[count].arg2 = arg2; - - if (machine_is_omap_h3()) + + if (cpu_is_omap1710()) omap_set_dma_src_params(dmach, OMAP_DMA_PORT_OCP_T1, OMAP_DMA_AMODE_CONSTANT, CAM_CAMDATA_REG, 0, 0); @@ -507,19 +505,25 @@ omap16xxcam_cleanup(void *priv) { struct omap16xxcam *data = (struct omap16xxcam *) priv; + if (!data->camera_regs) + return -EINVAL; + omap16xxcam_disable(data); - if (machine_is_omap_h3()) { - if (data->camera_regs) { - iounmap((void *)data->camera_regs); - data->camera_regs= NULL; - } - } + if (cpu_is_omap1710()) + iounmap((void *)data->camera_regs); + data->camera_regs= NULL; if (data->iobase_phys) { release_mem_region(data->iobase_phys, CAMERA_IOSIZE); data->iobase_phys = 0; } + if (hardware_data.func_clk) { + clk_disable(hardware_data.func_clk); + clk_put(hardware_data.func_clk); + hardware_data.func_clk = NULL; + } + return 0; } @@ -529,13 +533,15 @@ omap16xxcam_init(void) { unsigned long cam_iobase; - if (!request_region(CAMERA_BASE, CAMERA_IOSIZE, "OAMP16xx Camera")) { - printk ("OMAP16XX Parallel Camera Interface is already in use\n"); + if (!request_mem_region(CAMERA_BASE, CAMERA_IOSIZE, + camera_hardware_if.name)) { + pr_debug("%s is already in use\n", camera_hardware_if.name); return NULL; } - if (machine_is_omap_h3()) { - cam_iobase = (unsigned long) ioremap (CAMERA_BASE, CAMERA_IOSIZE); + if (cpu_is_omap1710()) { + cam_iobase = (unsigned long) ioremap (CAMERA_BASE, + CAMERA_IOSIZE); if (!cam_iobase) { printk("CANNOT MAP CAMERA REGISTER\n"); return NULL; @@ -547,11 +553,13 @@ omap16xxcam_init(void) /* Set the base address of the camera registers */ hardware_data.camera_regs = (camera_regs_t *)cam_iobase; hardware_data.iobase_phys = (unsigned long) CAMERA_BASE; - /* get the input clock value to camera interface and store it */ - if (machine_is_omap_h3()) - hardware_data.ocp_clk = clk_get_rate(clk_get(0, "tc_ck")); + + /* get the input clock value to camera interface and store it */ + if (cpu_is_omap1710()) + hardware_data.func_clk = clk_get(0, "tc2_ck"); else - hardware_data.ocp_clk = clk_get_rate(clk_get(0, "mpuper_ck")); + hardware_data.func_clk = clk_get(0, "armper_ck"); + hardware_data.ocp_clk = clk_get_rate(hardware_data.func_clk); /* Init the camera IF */ omap16xx_cam_init(); @@ -566,7 +574,7 @@ omap16xxcam_init(void) struct camera_hardware camera_hardware_if = { .version = 0x01, - .name = "OMAP16xx Camera Parallel", + .name = "OMAP16xx Parallel Camera", .init = omap16xxcam_init, .cleanup = omap16xxcam_cleanup, .open = omap16xxcam_open, diff --git a/drivers/media/video/omap/sensor_if.h b/drivers/media/video/omap/sensor_if.h index b5fc6082779..47bb7168f21 100644 --- a/drivers/media/video/omap/sensor_if.h +++ b/drivers/media/video/omap/sensor_if.h @@ -44,5 +44,7 @@ struct omap_camera_sensor { int (*set_control)(struct v4l2_control *, void *); }; - + +extern struct omap_camera_sensor camera_sensor_if; + #endif diff --git a/drivers/media/video/omap/sensor_ov9640.c b/drivers/media/video/omap/sensor_ov9640.c index 5291cc8ed64..78c8250d0b5 100644 --- a/drivers/media/video/omap/sensor_ov9640.c +++ b/drivers/media/video/omap/sensor_ov9640.c @@ -20,14 +20,13 @@ #include #include #include +#include #include "sensor_if.h" #include "ov9640.h" #include "h3sensorpower.h" #include "h4sensorpower.h" -#define CAMERA_OV9640 -#ifdef CAMERA_OV9640 struct ov9640_sensor { /* I2C parameters */ @@ -696,6 +695,11 @@ ov9640_powerup(void) if (machine_is_omap_h2()) return 0; +#ifdef CONFIG_OMAP_OSK_MISTRAL + if (machine_is_omap_osk()) + omap_set_gpio_dataout(11, 1); +#endif + if (machine_is_omap_h3()) { err = h3_sensor_powerup(); if (err) @@ -718,6 +722,11 @@ ov9640_powerdown(void) if (machine_is_omap_h2()) return 0; +#ifdef CONFIG_OMAP_OSK_MISTRAL + if (machine_is_omap_osk()) + omap_set_gpio_dataout(11, 0); +#endif + if (machine_is_omap_h3()) { err = h3_sensor_powerdown(); if (err) @@ -806,6 +815,7 @@ ov9640_i2c_attach_client(struct i2c_adapter *adap, int addr, int probe) client->addr = addr; client->driver = &ov9640sensor_i2c_driver; client->adapter = adap; + strcpy(client->name, ov9640sensor_i2c_driver.driver.name); err = i2c_attach_client(client); if (err) { @@ -1125,7 +1135,7 @@ ov9640sensor_cleanup(void *priv) static struct i2c_driver ov9640sensor_i2c_driver = { - .driver { + .driver = { .name = "ov9640", }, .id = I2C_DRIVERID_MISC, /*FIXME:accroding to i2c-ids.h */ @@ -1180,10 +1190,6 @@ ov9640sensor_init(struct v4l2_pix_format *pix) struct omap_camera_sensor camera_sensor_if = { .version = 0x01, .name = "OV9640", - .parallel_mode = PAR_MODE_NOBT8, - .hs_polarity = SYNC_ACTIVE_HIGH, - .vs_polarity = SYNC_ACTIVE_LOW, - .image_swap = 0, .init = ov9640sensor_init, .cleanup = ov9640sensor_cleanup, .enum_pixformat = ov9640sensor_enum_pixformat, @@ -1196,7 +1202,11 @@ struct omap_camera_sensor camera_sensor_if = { .power_on = ov9640sensor_power_on, .power_off = ov9640sensor_power_off, }; +EXPORT_SYMBOL_GPL(camera_sensor_if); +MODULE_LICENSE("GPL"); + +#if 0 void print_ov9640_regs(void *priv) { struct ov9640_sensor *sensor = (struct ov9640_sensor *) priv; @@ -1207,5 +1217,4 @@ void print_ov9640_regs(void *priv) else printk("reg %x = %x\n", reg, val); } - -#endif /* ifdef CAMERA_OV9640 */ +#endif -- 2.41.0