Hello Hans,
I have squashed in the two patches I sent on top of v1 in this series, one
fix for the build error you reported me, and reduced the patch count fixing the
style changes on the patch that removes the soc_camera dependencies.
No frame rate control, but now a TODO note makes clear that is expected
v4l2 compliance tool to report errors.
v1 -> v2:
- Fix soc_camera driver build error
- Add TODO note for missing frame rate control
- Reduce patch count
Jacopo Mondi (4):
media: i2c: Copy mt9t112 soc_camera sensor driver
media: i2c: mt9t112: Remove soc_camera dependencies
arch: sh: ecovec: Use new renesas-ceu camera driver
media: MAINTAINERS: Add entry for Aptina MT9T112
MAINTAINERS | 7 +
arch/sh/boards/mach-ecovec24/setup.c | 338 +++++-----
arch/sh/kernel/cpu/sh4a/clock-sh7724.c | 4 +-
drivers/media/i2c/Kconfig | 11 +
drivers/media/i2c/Makefile | 1 +
drivers/media/i2c/mt9t112.c | 1140 ++++++++++++++++++++++++++++++++
drivers/media/i2c/soc_camera/mt9t112.c | 2 +-
include/media/i2c/mt9t112.h | 17 +-
8 files changed, 1338 insertions(+), 182 deletions(-)
create mode 100644 drivers/media/i2c/mt9t112.c
--
2.7.4
SH4 7724 Ecovec platform uses sh_mobile_ceu camera driver, which is now
being replaced by a proper V4L2 camera driver named 'renesas-ceu'.
Get rid of soc_camera defined components used to register sensor drivers
and of platform specific enable/disable routines.
Register GPIOs for sensor drivers and declare memory reserved with
memblock APIs as dma capable to be used for CEU buffers.
While at there re-order include directives to respect alphabetical
ordering.
Signed-off-by: Jacopo Mondi <[email protected]>
---
arch/sh/boards/mach-ecovec24/setup.c | 338 ++++++++++++++++-----------------
arch/sh/kernel/cpu/sh4a/clock-sh7724.c | 4 +-
2 files changed, 171 insertions(+), 171 deletions(-)
diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c
index 6f929ab..adc61d1 100644
--- a/arch/sh/boards/mach-ecovec24/setup.c
+++ b/arch/sh/boards/mach-ecovec24/setup.c
@@ -7,44 +7,47 @@
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*/
-
-#include <linux/init.h>
+#include <asm/clock.h>
+#include <asm/heartbeat.h>
+#include <asm/suspend.h>
+#include <cpu/sh7724.h>
+#include <linux/delay.h>
#include <linux/device.h>
-#include <linux/platform_device.h>
+#include <linux/i2c.h>
+#include <linux/io.h>
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/input/sh_keysc.h>
+#include <linux/interrupt.h>
+#include <linux/memblock.h>
+#include <linux/mfd/tmio.h>
#include <linux/mmc/host.h>
#include <linux/mmc/sh_mmcif.h>
#include <linux/mtd/physmap.h>
-#include <linux/mfd/tmio.h>
#include <linux/gpio.h>
-#include <linux/interrupt.h>
-#include <linux/io.h>
-#include <linux/delay.h>
+#include <linux/gpio/machine.h>
+#include <linux/platform_data/gpio_backlight.h>
+#include <linux/platform_data/tsc2007.h>
+#include <linux/platform_device.h>
#include <linux/regulator/fixed.h>
#include <linux/regulator/machine.h>
-#include <linux/usb/r8a66597.h>
-#include <linux/usb/renesas_usbhs.h>
-#include <linux/i2c.h>
-#include <linux/platform_data/tsc2007.h>
-#include <linux/spi/spi.h>
-#include <linux/spi/sh_msiof.h>
-#include <linux/spi/mmc_spi.h>
-#include <linux/input.h>
-#include <linux/input/sh_keysc.h>
-#include <linux/platform_data/gpio_backlight.h>
#include <linux/sh_eth.h>
#include <linux/sh_intc.h>
+#include <linux/spi/mmc_spi.h>
+#include <linux/spi/sh_msiof.h>
+#include <linux/spi/spi.h>
+#include <linux/usb/r8a66597.h>
+#include <linux/usb/renesas_usbhs.h>
#include <linux/videodev2.h>
-#include <video/sh_mobile_lcdc.h>
+
+#include <media/drv-intf/renesas-ceu.h>
+#include <media/i2c/mt9t112.h>
+#include <media/i2c/tw9910.h>
+
#include <sound/sh_fsi.h>
#include <sound/simple_card.h>
-#include <media/drv-intf/sh_mobile_ceu.h>
-#include <media/soc_camera.h>
-#include <media/i2c/tw9910.h>
-#include <media/i2c/mt9t112.h>
-#include <asm/heartbeat.h>
-#include <asm/clock.h>
-#include <asm/suspend.h>
-#include <cpu/sh7724.h>
+
+#include <video/sh_mobile_lcdc.h>
/*
* Address Interface BusWidth
@@ -81,6 +84,10 @@
* amixer set 'Out Mixer Right DAC Right' on
*/
+#define CEU_BUFFER_MEMORY_SIZE (4 << 20)
+static phys_addr_t ceu0_dma_membase;
+static phys_addr_t ceu1_dma_membase;
+
/* Heartbeat */
static unsigned char led_pos[] = { 0, 1, 2, 3 };
@@ -382,8 +389,24 @@ static struct platform_device gpio_backlight_device = {
};
/* CEU0 */
-static struct sh_mobile_ceu_info sh_mobile_ceu0_info = {
- .flags = SH_CEU_FLAG_USE_8BIT_BUS,
+static struct ceu_platform_data ceu0_pdata = {
+ .num_subdevs = 2,
+ .subdevs = {
+ { /* [0] = mt9t112 */
+ .flags = 0,
+ .bus_width = 8,
+ .bus_shift = 0,
+ .i2c_adapter_id = 0,
+ .i2c_address = 0x3c,
+ },
+ { /* [1] = tw9910 */
+ .flags = 0,
+ .bus_width = 8,
+ .bus_shift = 0,
+ .i2c_adapter_id = 0,
+ .i2c_address = 0x45,
+ },
+ },
};
static struct resource ceu0_resources[] = {
@@ -397,24 +420,30 @@ static struct resource ceu0_resources[] = {
.start = evt2irq(0x880),
.flags = IORESOURCE_IRQ,
},
- [2] = {
- /* place holder for contiguous memory */
- },
};
static struct platform_device ceu0_device = {
- .name = "sh_mobile_ceu",
- .id = 0, /* "ceu0" clock */
+ .name = "renesas-ceu",
+ .id = 0, /* ceu.0 */
.num_resources = ARRAY_SIZE(ceu0_resources),
.resource = ceu0_resources,
.dev = {
- .platform_data = &sh_mobile_ceu0_info,
+ .platform_data = &ceu0_pdata,
},
};
/* CEU1 */
-static struct sh_mobile_ceu_info sh_mobile_ceu1_info = {
- .flags = SH_CEU_FLAG_USE_8BIT_BUS,
+static struct ceu_platform_data ceu1_pdata = {
+ .num_subdevs = 1,
+ .subdevs = {
+ { /* [0] = mt9t112 */
+ .flags = 0,
+ .bus_width = 8,
+ .bus_shift = 0,
+ .i2c_adapter_id = 1,
+ .i2c_address = 0x3c,
+ },
+ },
};
static struct resource ceu1_resources[] = {
@@ -428,26 +457,71 @@ static struct resource ceu1_resources[] = {
.start = evt2irq(0x9e0),
.flags = IORESOURCE_IRQ,
},
- [2] = {
- /* place holder for contiguous memory */
- },
};
static struct platform_device ceu1_device = {
- .name = "sh_mobile_ceu",
- .id = 1, /* "ceu1" clock */
+ .name = "renesas-ceu",
+ .id = 1, /* ceu.1 */
.num_resources = ARRAY_SIZE(ceu1_resources),
.resource = ceu1_resources,
.dev = {
- .platform_data = &sh_mobile_ceu1_info,
+ .platform_data = &ceu1_pdata,
+ },
+};
+
+/* Power up/down GPIOs for camera devices and video decoder */
+static struct gpiod_lookup_table tw9910_gpios = {
+ .dev_id = "0-0045",
+ .table = {
+ GPIO_LOOKUP("sh7724_pfc", GPIO_PTU2, "pdn", GPIO_ACTIVE_HIGH),
+ },
+};
+
+static struct gpiod_lookup_table mt9t112_0_gpios = {
+ .dev_id = "0-003c",
+ .table = {
+ GPIO_LOOKUP("sh7724_pfc", GPIO_PTA3, "standby",
+ GPIO_ACTIVE_HIGH),
+ },
+};
+
+static struct gpiod_lookup_table mt9t112_1_gpios = {
+ .dev_id = "1-003c",
+ .table = {
+ GPIO_LOOKUP("sh7724_pfc", GPIO_PTA4, "standby",
+ GPIO_ACTIVE_HIGH),
},
};
/* I2C device */
+static struct tw9910_video_info tw9910_info = {
+ .buswidth = 8,
+ .mpout = TW9910_MPO_FIELD,
+};
+
+static struct mt9t112_platform_data mt9t112_0_pdata = {
+ .flags = MT9T112_FLAG_PCLK_RISING_EDGE,
+ .divider = { 0x49, 0x6, 0, 6, 0, 9, 9, 6, 0 }, /* for 24MHz */
+};
+
+static struct mt9t112_platform_data mt9t112_1_pdata = {
+ .flags = MT9T112_FLAG_PCLK_RISING_EDGE,
+ .divider = { 0x49, 0x6, 0, 6, 0, 9, 9, 6, 0 }, /* for 24MHz */
+};
+
static struct i2c_board_info i2c0_devices[] = {
{
I2C_BOARD_INFO("da7210", 0x1a),
},
+ {
+ I2C_BOARD_INFO("tw9910", 0x45),
+ .platform_data = &tw9910_info,
+ },
+ {
+ /* 1st camera */
+ I2C_BOARD_INFO("mt9t112", 0x3c),
+ .platform_data = &mt9t112_0_pdata,
+ },
};
static struct i2c_board_info i2c1_devices[] = {
@@ -457,7 +531,12 @@ static struct i2c_board_info i2c1_devices[] = {
{
I2C_BOARD_INFO("lis3lv02d", 0x1c),
.irq = evt2irq(0x620),
- }
+ },
+ {
+ /* 2nd camera */
+ I2C_BOARD_INFO("mt9t112", 0x3c),
+ .platform_data = &mt9t112_1_pdata,
+ },
};
/* KEYSC */
@@ -724,115 +803,6 @@ static struct platform_device msiof0_device = {
#endif
-/* I2C Video/Camera */
-static struct i2c_board_info i2c_camera[] = {
- {
- I2C_BOARD_INFO("tw9910", 0x45),
- },
- {
- /* 1st camera */
- I2C_BOARD_INFO("mt9t112", 0x3c),
- },
- {
- /* 2nd camera */
- I2C_BOARD_INFO("mt9t112", 0x3c),
- },
-};
-
-/* tw9910 */
-static int tw9910_power(struct device *dev, int mode)
-{
- int val = mode ? 0 : 1;
-
- gpio_set_value(GPIO_PTU2, val);
- if (mode)
- mdelay(100);
-
- return 0;
-}
-
-static struct tw9910_video_info tw9910_info = {
- .buswidth = SOCAM_DATAWIDTH_8,
- .mpout = TW9910_MPO_FIELD,
-};
-
-static struct soc_camera_link tw9910_link = {
- .i2c_adapter_id = 0,
- .bus_id = 1,
- .power = tw9910_power,
- .board_info = &i2c_camera[0],
- .priv = &tw9910_info,
-};
-
-/* mt9t112 */
-static int mt9t112_power1(struct device *dev, int mode)
-{
- gpio_set_value(GPIO_PTA3, mode);
- if (mode)
- mdelay(100);
-
- return 0;
-}
-
-static struct mt9t112_camera_info mt9t112_info1 = {
- .flags = MT9T112_FLAG_PCLK_RISING_EDGE | MT9T112_FLAG_DATAWIDTH_8,
- .divider = { 0x49, 0x6, 0, 6, 0, 9, 9, 6, 0 }, /* for 24MHz */
-};
-
-static struct soc_camera_link mt9t112_link1 = {
- .i2c_adapter_id = 0,
- .power = mt9t112_power1,
- .bus_id = 0,
- .board_info = &i2c_camera[1],
- .priv = &mt9t112_info1,
-};
-
-static int mt9t112_power2(struct device *dev, int mode)
-{
- gpio_set_value(GPIO_PTA4, mode);
- if (mode)
- mdelay(100);
-
- return 0;
-}
-
-static struct mt9t112_camera_info mt9t112_info2 = {
- .flags = MT9T112_FLAG_PCLK_RISING_EDGE | MT9T112_FLAG_DATAWIDTH_8,
- .divider = { 0x49, 0x6, 0, 6, 0, 9, 9, 6, 0 }, /* for 24MHz */
-};
-
-static struct soc_camera_link mt9t112_link2 = {
- .i2c_adapter_id = 1,
- .power = mt9t112_power2,
- .bus_id = 1,
- .board_info = &i2c_camera[2],
- .priv = &mt9t112_info2,
-};
-
-static struct platform_device camera_devices[] = {
- {
- .name = "soc-camera-pdrv",
- .id = 0,
- .dev = {
- .platform_data = &tw9910_link,
- },
- },
- {
- .name = "soc-camera-pdrv",
- .id = 1,
- .dev = {
- .platform_data = &mt9t112_link1,
- },
- },
- {
- .name = "soc-camera-pdrv",
- .id = 2,
- .dev = {
- .platform_data = &mt9t112_link2,
- },
- },
-};
-
/* FSI */
static struct resource fsi_resources[] = {
[0] = {
@@ -979,6 +949,11 @@ static struct platform_device sh_mmcif_device = {
};
#endif
+static struct platform_device *ecovec_ceu_devices[] __initdata = {
+ &ceu0_device,
+ &ceu1_device,
+};
+
static struct platform_device *ecovec_devices[] __initdata = {
&heartbeat_device,
&nor_flash_device,
@@ -988,8 +963,6 @@ static struct platform_device *ecovec_devices[] __initdata = {
&usbhs_device,
&lcdc_device,
&gpio_backlight_device,
- &ceu0_device,
- &ceu1_device,
&keysc_device,
&cn12_power,
#if defined(CONFIG_MMC_SDHI) || defined(CONFIG_MMC_SDHI_MODULE)
@@ -1001,9 +974,6 @@ static struct platform_device *ecovec_devices[] __initdata = {
#else
&msiof0_device,
#endif
- &camera_devices[0],
- &camera_devices[1],
- &camera_devices[2],
&fsi_device,
&fsi_da7210_device,
&irda_device,
@@ -1240,7 +1210,6 @@ static int __init arch_setup(void)
gpio_request(GPIO_FN_VIO0_CLK, NULL);
gpio_request(GPIO_FN_VIO0_FLD, NULL);
gpio_request(GPIO_FN_VIO0_HD, NULL);
- platform_resource_setup_memory(&ceu0_device, "ceu0", 4 << 20);
/* enable CEU1 */
gpio_request(GPIO_FN_VIO1_D7, NULL);
@@ -1255,7 +1224,6 @@ static int __init arch_setup(void)
gpio_request(GPIO_FN_VIO1_HD, NULL);
gpio_request(GPIO_FN_VIO1_VD, NULL);
gpio_request(GPIO_FN_VIO1_CLK, NULL);
- platform_resource_setup_memory(&ceu1_device, "ceu1", 4 << 20);
/* enable KEYSC */
gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
@@ -1332,16 +1300,6 @@ static int __init arch_setup(void)
__raw_writew((__raw_readw(IODRIVEA) & ~0x3000) | 0x2000,
IODRIVEA);
- /* enable Video */
- gpio_request(GPIO_PTU2, NULL);
- gpio_direction_output(GPIO_PTU2, 1);
-
- /* enable Camera */
- gpio_request(GPIO_PTA3, NULL);
- gpio_request(GPIO_PTA4, NULL);
- gpio_direction_output(GPIO_PTA3, 0);
- gpio_direction_output(GPIO_PTA4, 0);
-
/* enable FSI */
gpio_request(GPIO_FN_FSIMCKB, NULL);
gpio_request(GPIO_FN_FSIIBSD, NULL);
@@ -1390,6 +1348,11 @@ static int __init arch_setup(void)
gpio_request(GPIO_PTU5, NULL);
gpio_direction_output(GPIO_PTU5, 0);
+ /* Register gpio lookup tables for cameras and video decoder */
+ gpiod_add_lookup_table(&tw9910_gpios);
+ gpiod_add_lookup_table(&mt9t112_0_gpios);
+ gpiod_add_lookup_table(&mt9t112_1_gpios);
+
/* enable I2C device */
i2c_register_board_info(0, i2c0_devices,
ARRAY_SIZE(i2c0_devices));
@@ -1431,6 +1394,25 @@ static int __init arch_setup(void)
gpio_set_value(GPIO_PTG4, 1);
#endif
+ /* Initialize CEU platform devices separately to map memory first */
+ device_initialize(&ecovec_ceu_devices[0]->dev);
+ arch_setup_pdev_archdata(ecovec_ceu_devices[0]);
+ dma_declare_coherent_memory(&ecovec_ceu_devices[0]->dev,
+ ceu0_dma_membase, ceu0_dma_membase,
+ ceu0_dma_membase +
+ CEU_BUFFER_MEMORY_SIZE - 1,
+ DMA_MEMORY_EXCLUSIVE);
+ platform_device_add(ecovec_ceu_devices[0]);
+
+ device_initialize(&ecovec_ceu_devices[1]->dev);
+ arch_setup_pdev_archdata(ecovec_ceu_devices[1]);
+ dma_declare_coherent_memory(&ecovec_ceu_devices[1]->dev,
+ ceu1_dma_membase, ceu1_dma_membase,
+ ceu1_dma_membase +
+ CEU_BUFFER_MEMORY_SIZE - 1,
+ DMA_MEMORY_EXCLUSIVE);
+ platform_device_add(ecovec_ceu_devices[1]);
+
return platform_add_devices(ecovec_devices,
ARRAY_SIZE(ecovec_devices));
}
@@ -1443,6 +1425,24 @@ static int __init devices_setup(void)
}
device_initcall(devices_setup);
+/* Reserve a portion of memory for CEU 0 and CEU 1 buffers */
+static void __init ecovec_mv_mem_reserve(void)
+{
+ phys_addr_t phys;
+ phys_addr_t size = CEU_BUFFER_MEMORY_SIZE;
+
+ phys = memblock_alloc_base(size, PAGE_SIZE, MEMBLOCK_ALLOC_ANYWHERE);
+ memblock_free(phys, size);
+ memblock_remove(phys, size);
+ ceu0_dma_membase = phys;
+
+ phys = memblock_alloc_base(size, PAGE_SIZE, MEMBLOCK_ALLOC_ANYWHERE);
+ memblock_free(phys, size);
+ memblock_remove(phys, size);
+ ceu1_dma_membase = phys;
+}
+
static struct sh_machine_vector mv_ecovec __initmv = {
.mv_name = "R0P7724 (EcoVec)",
+ .mv_mem_reserve = ecovec_mv_mem_reserve,
};
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7724.c b/arch/sh/kernel/cpu/sh4a/clock-sh7724.c
index f27c618..3194336 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7724.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7724.c
@@ -338,14 +338,14 @@ static struct clk_lookup lookups[] = {
CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[HWBLK_SDHI0]),
CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[HWBLK_SDHI1]),
CLKDEV_CON_ID("veu1", &mstp_clks[HWBLK_VEU1]),
- CLKDEV_DEV_ID("sh_mobile_ceu.1", &mstp_clks[HWBLK_CEU1]),
+ CLKDEV_DEV_ID("renesas-ceu.1", &mstp_clks[HWBLK_CEU1]),
CLKDEV_CON_ID("beu1", &mstp_clks[HWBLK_BEU1]),
CLKDEV_CON_ID("2ddmac0", &mstp_clks[HWBLK_2DDMAC]),
CLKDEV_DEV_ID("sh_fsi.0", &mstp_clks[HWBLK_SPU]),
CLKDEV_CON_ID("jpu0", &mstp_clks[HWBLK_JPU]),
CLKDEV_DEV_ID("sh-vou", &mstp_clks[HWBLK_VOU]),
CLKDEV_CON_ID("beu0", &mstp_clks[HWBLK_BEU0]),
- CLKDEV_DEV_ID("sh_mobile_ceu.0", &mstp_clks[HWBLK_CEU0]),
+ CLKDEV_DEV_ID("renesas-ceu.0", &mstp_clks[HWBLK_CEU0]),
CLKDEV_CON_ID("veu0", &mstp_clks[HWBLK_VEU0]),
CLKDEV_CON_ID("vpu0", &mstp_clks[HWBLK_VPU]),
CLKDEV_DEV_ID("sh_mobile_lcdc_fb.0", &mstp_clks[HWBLK_LCDC]),
--
2.7.4
Copy the soc_camera based driver in v4l2 sensor driver directory.
This commit just copies the original file without modifying it.
No modification to KConfig and Makefile as soc_camera framework
dependencies need to be removed first in next commit.
Signed-off-by: Jacopo Mondi <[email protected]>
---
drivers/media/i2c/mt9t112.c | 1163 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 1163 insertions(+)
create mode 100644 drivers/media/i2c/mt9t112.c
diff --git a/drivers/media/i2c/mt9t112.c b/drivers/media/i2c/mt9t112.c
new file mode 100644
index 0000000..297d22e
--- /dev/null
+++ b/drivers/media/i2c/mt9t112.c
@@ -0,0 +1,1163 @@
+/*
+ * mt9t112 Camera Driver
+ *
+ * Copyright (C) 2009 Renesas Solutions Corp.
+ * Kuninori Morimoto <[email protected]>
+ *
+ * Based on ov772x driver, mt9m111 driver,
+ *
+ * Copyright (C) 2008 Kuninori Morimoto <[email protected]>
+ * Copyright (C) 2008, Robert Jarzmik <[email protected]>
+ * Copyright 2006-7 Jonathan Corbet <[email protected]>
+ * Copyright (C) 2008 Magnus Damm
+ * Copyright (C) 2008, Guennadi Liakhovetski <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/v4l2-mediabus.h>
+#include <linux/videodev2.h>
+
+#include <media/i2c/mt9t112.h>
+#include <media/soc_camera.h>
+#include <media/v4l2-clk.h>
+#include <media/v4l2-common.h>
+#include <media/v4l2-image-sizes.h>
+
+/* you can check PLL/clock info */
+/* #define EXT_CLOCK 24000000 */
+
+/************************************************************************
+ macro
+************************************************************************/
+/*
+ * frame size
+ */
+#define MAX_WIDTH 2048
+#define MAX_HEIGHT 1536
+
+/*
+ * macro of read/write
+ */
+#define ECHECKER(ret, x) \
+ do { \
+ (ret) = (x); \
+ if ((ret) < 0) \
+ return (ret); \
+ } while (0)
+
+#define mt9t112_reg_write(ret, client, a, b) \
+ ECHECKER(ret, __mt9t112_reg_write(client, a, b))
+#define mt9t112_mcu_write(ret, client, a, b) \
+ ECHECKER(ret, __mt9t112_mcu_write(client, a, b))
+
+#define mt9t112_reg_mask_set(ret, client, a, b, c) \
+ ECHECKER(ret, __mt9t112_reg_mask_set(client, a, b, c))
+#define mt9t112_mcu_mask_set(ret, client, a, b, c) \
+ ECHECKER(ret, __mt9t112_mcu_mask_set(client, a, b, c))
+
+#define mt9t112_reg_read(ret, client, a) \
+ ECHECKER(ret, __mt9t112_reg_read(client, a))
+
+/*
+ * Logical address
+ */
+#define _VAR(id, offset, base) (base | (id & 0x1f) << 10 | (offset & 0x3ff))
+#define VAR(id, offset) _VAR(id, offset, 0x0000)
+#define VAR8(id, offset) _VAR(id, offset, 0x8000)
+
+/************************************************************************
+ struct
+************************************************************************/
+struct mt9t112_format {
+ u32 code;
+ enum v4l2_colorspace colorspace;
+ u16 fmt;
+ u16 order;
+};
+
+struct mt9t112_priv {
+ struct v4l2_subdev subdev;
+ struct mt9t112_camera_info *info;
+ struct i2c_client *client;
+ struct v4l2_rect frame;
+ struct v4l2_clk *clk;
+ const struct mt9t112_format *format;
+ int num_formats;
+ u32 flags;
+/* for flags */
+#define INIT_DONE (1 << 0)
+#define PCLK_RISING (1 << 1)
+};
+
+/************************************************************************
+ supported format
+************************************************************************/
+
+static const struct mt9t112_format mt9t112_cfmts[] = {
+ {
+ .code = MEDIA_BUS_FMT_UYVY8_2X8,
+ .colorspace = V4L2_COLORSPACE_SRGB,
+ .fmt = 1,
+ .order = 0,
+ }, {
+ .code = MEDIA_BUS_FMT_VYUY8_2X8,
+ .colorspace = V4L2_COLORSPACE_SRGB,
+ .fmt = 1,
+ .order = 1,
+ }, {
+ .code = MEDIA_BUS_FMT_YUYV8_2X8,
+ .colorspace = V4L2_COLORSPACE_SRGB,
+ .fmt = 1,
+ .order = 2,
+ }, {
+ .code = MEDIA_BUS_FMT_YVYU8_2X8,
+ .colorspace = V4L2_COLORSPACE_SRGB,
+ .fmt = 1,
+ .order = 3,
+ }, {
+ .code = MEDIA_BUS_FMT_RGB555_2X8_PADHI_LE,
+ .colorspace = V4L2_COLORSPACE_SRGB,
+ .fmt = 8,
+ .order = 2,
+ }, {
+ .code = MEDIA_BUS_FMT_RGB565_2X8_LE,
+ .colorspace = V4L2_COLORSPACE_SRGB,
+ .fmt = 4,
+ .order = 2,
+ },
+};
+
+/************************************************************************
+ general function
+************************************************************************/
+static struct mt9t112_priv *to_mt9t112(const struct i2c_client *client)
+{
+ return container_of(i2c_get_clientdata(client),
+ struct mt9t112_priv,
+ subdev);
+}
+
+static int __mt9t112_reg_read(const struct i2c_client *client, u16 command)
+{
+ struct i2c_msg msg[2];
+ u8 buf[2];
+ int ret;
+
+ command = swab16(command);
+
+ msg[0].addr = client->addr;
+ msg[0].flags = 0;
+ msg[0].len = 2;
+ msg[0].buf = (u8 *)&command;
+
+ msg[1].addr = client->addr;
+ msg[1].flags = I2C_M_RD;
+ msg[1].len = 2;
+ msg[1].buf = buf;
+
+ /*
+ * if return value of this function is < 0,
+ * it mean error.
+ * else, under 16bit is valid data.
+ */
+ ret = i2c_transfer(client->adapter, msg, 2);
+ if (ret < 0)
+ return ret;
+
+ memcpy(&ret, buf, 2);
+ return swab16(ret);
+}
+
+static int __mt9t112_reg_write(const struct i2c_client *client,
+ u16 command, u16 data)
+{
+ struct i2c_msg msg;
+ u8 buf[4];
+ int ret;
+
+ command = swab16(command);
+ data = swab16(data);
+
+ memcpy(buf + 0, &command, 2);
+ memcpy(buf + 2, &data, 2);
+
+ msg.addr = client->addr;
+ msg.flags = 0;
+ msg.len = 4;
+ msg.buf = buf;
+
+ /*
+ * i2c_transfer return message length,
+ * but this function should return 0 if correct case
+ */
+ ret = i2c_transfer(client->adapter, &msg, 1);
+ if (ret >= 0)
+ ret = 0;
+
+ return ret;
+}
+
+static int __mt9t112_reg_mask_set(const struct i2c_client *client,
+ u16 command,
+ u16 mask,
+ u16 set)
+{
+ int val = __mt9t112_reg_read(client, command);
+ if (val < 0)
+ return val;
+
+ val &= ~mask;
+ val |= set & mask;
+
+ return __mt9t112_reg_write(client, command, val);
+}
+
+/* mcu access */
+static int __mt9t112_mcu_read(const struct i2c_client *client, u16 command)
+{
+ int ret;
+
+ ret = __mt9t112_reg_write(client, 0x098E, command);
+ if (ret < 0)
+ return ret;
+
+ return __mt9t112_reg_read(client, 0x0990);
+}
+
+static int __mt9t112_mcu_write(const struct i2c_client *client,
+ u16 command, u16 data)
+{
+ int ret;
+
+ ret = __mt9t112_reg_write(client, 0x098E, command);
+ if (ret < 0)
+ return ret;
+
+ return __mt9t112_reg_write(client, 0x0990, data);
+}
+
+static int __mt9t112_mcu_mask_set(const struct i2c_client *client,
+ u16 command,
+ u16 mask,
+ u16 set)
+{
+ int val = __mt9t112_mcu_read(client, command);
+ if (val < 0)
+ return val;
+
+ val &= ~mask;
+ val |= set & mask;
+
+ return __mt9t112_mcu_write(client, command, val);
+}
+
+static int mt9t112_reset(const struct i2c_client *client)
+{
+ int ret;
+
+ mt9t112_reg_mask_set(ret, client, 0x001a, 0x0001, 0x0001);
+ msleep(1);
+ mt9t112_reg_mask_set(ret, client, 0x001a, 0x0001, 0x0000);
+
+ return ret;
+}
+
+#ifndef EXT_CLOCK
+#define CLOCK_INFO(a, b)
+#else
+#define CLOCK_INFO(a, b) mt9t112_clock_info(a, b)
+static int mt9t112_clock_info(const struct i2c_client *client, u32 ext)
+{
+ int m, n, p1, p2, p3, p4, p5, p6, p7;
+ u32 vco, clk;
+ char *enable;
+
+ ext /= 1000; /* kbyte order */
+
+ mt9t112_reg_read(n, client, 0x0012);
+ p1 = n & 0x000f;
+ n = n >> 4;
+ p2 = n & 0x000f;
+ n = n >> 4;
+ p3 = n & 0x000f;
+
+ mt9t112_reg_read(n, client, 0x002a);
+ p4 = n & 0x000f;
+ n = n >> 4;
+ p5 = n & 0x000f;
+ n = n >> 4;
+ p6 = n & 0x000f;
+
+ mt9t112_reg_read(n, client, 0x002c);
+ p7 = n & 0x000f;
+
+ mt9t112_reg_read(n, client, 0x0010);
+ m = n & 0x00ff;
+ n = (n >> 8) & 0x003f;
+
+ enable = ((6000 > ext) || (54000 < ext)) ? "X" : "";
+ dev_dbg(&client->dev, "EXTCLK : %10u K %s\n", ext, enable);
+
+ vco = 2 * m * ext / (n+1);
+ enable = ((384000 > vco) || (768000 < vco)) ? "X" : "";
+ dev_dbg(&client->dev, "VCO : %10u K %s\n", vco, enable);
+
+ clk = vco / (p1+1) / (p2+1);
+ enable = (96000 < clk) ? "X" : "";
+ dev_dbg(&client->dev, "PIXCLK : %10u K %s\n", clk, enable);
+
+ clk = vco / (p3+1);
+ enable = (768000 < clk) ? "X" : "";
+ dev_dbg(&client->dev, "MIPICLK : %10u K %s\n", clk, enable);
+
+ clk = vco / (p6+1);
+ enable = (96000 < clk) ? "X" : "";
+ dev_dbg(&client->dev, "MCU CLK : %10u K %s\n", clk, enable);
+
+ clk = vco / (p5+1);
+ enable = (54000 < clk) ? "X" : "";
+ dev_dbg(&client->dev, "SOC CLK : %10u K %s\n", clk, enable);
+
+ clk = vco / (p4+1);
+ enable = (70000 < clk) ? "X" : "";
+ dev_dbg(&client->dev, "Sensor CLK : %10u K %s\n", clk, enable);
+
+ clk = vco / (p7+1);
+ dev_dbg(&client->dev, "External sensor : %10u K\n", clk);
+
+ clk = ext / (n+1);
+ enable = ((2000 > clk) || (24000 < clk)) ? "X" : "";
+ dev_dbg(&client->dev, "PFD : %10u K %s\n", clk, enable);
+
+ return 0;
+}
+#endif
+
+static void mt9t112_frame_check(u32 *width, u32 *height, u32 *left, u32 *top)
+{
+ soc_camera_limit_side(left, width, 0, 0, MAX_WIDTH);
+ soc_camera_limit_side(top, height, 0, 0, MAX_HEIGHT);
+}
+
+static int mt9t112_set_a_frame_size(const struct i2c_client *client,
+ u16 width,
+ u16 height)
+{
+ int ret;
+ u16 wstart = (MAX_WIDTH - width) / 2;
+ u16 hstart = (MAX_HEIGHT - height) / 2;
+
+ /* (Context A) Image Width/Height */
+ mt9t112_mcu_write(ret, client, VAR(26, 0), width);
+ mt9t112_mcu_write(ret, client, VAR(26, 2), height);
+
+ /* (Context A) Output Width/Height */
+ mt9t112_mcu_write(ret, client, VAR(18, 43), 8 + width);
+ mt9t112_mcu_write(ret, client, VAR(18, 45), 8 + height);
+
+ /* (Context A) Start Row/Column */
+ mt9t112_mcu_write(ret, client, VAR(18, 2), 4 + hstart);
+ mt9t112_mcu_write(ret, client, VAR(18, 4), 4 + wstart);
+
+ /* (Context A) End Row/Column */
+ mt9t112_mcu_write(ret, client, VAR(18, 6), 11 + height + hstart);
+ mt9t112_mcu_write(ret, client, VAR(18, 8), 11 + width + wstart);
+
+ mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x06);
+
+ return ret;
+}
+
+static int mt9t112_set_pll_dividers(const struct i2c_client *client,
+ u8 m, u8 n,
+ u8 p1, u8 p2, u8 p3,
+ u8 p4, u8 p5, u8 p6,
+ u8 p7)
+{
+ int ret;
+ u16 val;
+
+ /* N/M */
+ val = (n << 8) |
+ (m << 0);
+ mt9t112_reg_mask_set(ret, client, 0x0010, 0x3fff, val);
+
+ /* P1/P2/P3 */
+ val = ((p3 & 0x0F) << 8) |
+ ((p2 & 0x0F) << 4) |
+ ((p1 & 0x0F) << 0);
+ mt9t112_reg_mask_set(ret, client, 0x0012, 0x0fff, val);
+
+ /* P4/P5/P6 */
+ val = (0x7 << 12) |
+ ((p6 & 0x0F) << 8) |
+ ((p5 & 0x0F) << 4) |
+ ((p4 & 0x0F) << 0);
+ mt9t112_reg_mask_set(ret, client, 0x002A, 0x7fff, val);
+
+ /* P7 */
+ val = (0x1 << 12) |
+ ((p7 & 0x0F) << 0);
+ mt9t112_reg_mask_set(ret, client, 0x002C, 0x100f, val);
+
+ return ret;
+}
+
+static int mt9t112_init_pll(const struct i2c_client *client)
+{
+ struct mt9t112_priv *priv = to_mt9t112(client);
+ int data, i, ret;
+
+ mt9t112_reg_mask_set(ret, client, 0x0014, 0x003, 0x0001);
+
+ /* PLL control: BYPASS PLL = 8517 */
+ mt9t112_reg_write(ret, client, 0x0014, 0x2145);
+
+ /* Replace these registers when new timing parameters are generated */
+ mt9t112_set_pll_dividers(client,
+ priv->info->divider.m,
+ priv->info->divider.n,
+ priv->info->divider.p1,
+ priv->info->divider.p2,
+ priv->info->divider.p3,
+ priv->info->divider.p4,
+ priv->info->divider.p5,
+ priv->info->divider.p6,
+ priv->info->divider.p7);
+
+ /*
+ * TEST_BYPASS on
+ * PLL_ENABLE on
+ * SEL_LOCK_DET on
+ * TEST_BYPASS off
+ */
+ mt9t112_reg_write(ret, client, 0x0014, 0x2525);
+ mt9t112_reg_write(ret, client, 0x0014, 0x2527);
+ mt9t112_reg_write(ret, client, 0x0014, 0x3427);
+ mt9t112_reg_write(ret, client, 0x0014, 0x3027);
+
+ mdelay(10);
+
+ /*
+ * PLL_BYPASS off
+ * Reference clock count
+ * I2C Master Clock Divider
+ */
+ mt9t112_reg_write(ret, client, 0x0014, 0x3046);
+ mt9t112_reg_write(ret, client, 0x0016, 0x0400); /* JPEG initialization workaround */
+ mt9t112_reg_write(ret, client, 0x0022, 0x0190);
+ mt9t112_reg_write(ret, client, 0x3B84, 0x0212);
+
+ /* External sensor clock is PLL bypass */
+ mt9t112_reg_write(ret, client, 0x002E, 0x0500);
+
+ mt9t112_reg_mask_set(ret, client, 0x0018, 0x0002, 0x0002);
+ mt9t112_reg_mask_set(ret, client, 0x3B82, 0x0004, 0x0004);
+
+ /* MCU disabled */
+ mt9t112_reg_mask_set(ret, client, 0x0018, 0x0004, 0x0004);
+
+ /* out of standby */
+ mt9t112_reg_mask_set(ret, client, 0x0018, 0x0001, 0);
+
+ mdelay(50);
+
+ /*
+ * Standby Workaround
+ * Disable Secondary I2C Pads
+ */
+ mt9t112_reg_write(ret, client, 0x0614, 0x0001);
+ mdelay(1);
+ mt9t112_reg_write(ret, client, 0x0614, 0x0001);
+ mdelay(1);
+ mt9t112_reg_write(ret, client, 0x0614, 0x0001);
+ mdelay(1);
+ mt9t112_reg_write(ret, client, 0x0614, 0x0001);
+ mdelay(1);
+ mt9t112_reg_write(ret, client, 0x0614, 0x0001);
+ mdelay(1);
+ mt9t112_reg_write(ret, client, 0x0614, 0x0001);
+ mdelay(1);
+
+ /* poll to verify out of standby. Must Poll this bit */
+ for (i = 0; i < 100; i++) {
+ mt9t112_reg_read(data, client, 0x0018);
+ if (!(0x4000 & data))
+ break;
+
+ mdelay(10);
+ }
+
+ return ret;
+}
+
+static int mt9t112_init_setting(const struct i2c_client *client)
+{
+
+ int ret;
+
+ /* Adaptive Output Clock (A) */
+ mt9t112_mcu_mask_set(ret, client, VAR(26, 160), 0x0040, 0x0000);
+
+ /* Read Mode (A) */
+ mt9t112_mcu_write(ret, client, VAR(18, 12), 0x0024);
+
+ /* Fine Correction (A) */
+ mt9t112_mcu_write(ret, client, VAR(18, 15), 0x00CC);
+
+ /* Fine IT Min (A) */
+ mt9t112_mcu_write(ret, client, VAR(18, 17), 0x01f1);
+
+ /* Fine IT Max Margin (A) */
+ mt9t112_mcu_write(ret, client, VAR(18, 19), 0x00fF);
+
+ /* Base Frame Lines (A) */
+ mt9t112_mcu_write(ret, client, VAR(18, 29), 0x032D);
+
+ /* Min Line Length (A) */
+ mt9t112_mcu_write(ret, client, VAR(18, 31), 0x073a);
+
+ /* Line Length (A) */
+ mt9t112_mcu_write(ret, client, VAR(18, 37), 0x07d0);
+
+ /* Adaptive Output Clock (B) */
+ mt9t112_mcu_mask_set(ret, client, VAR(27, 160), 0x0040, 0x0000);
+
+ /* Row Start (B) */
+ mt9t112_mcu_write(ret, client, VAR(18, 74), 0x004);
+
+ /* Column Start (B) */
+ mt9t112_mcu_write(ret, client, VAR(18, 76), 0x004);
+
+ /* Row End (B) */
+ mt9t112_mcu_write(ret, client, VAR(18, 78), 0x60B);
+
+ /* Column End (B) */
+ mt9t112_mcu_write(ret, client, VAR(18, 80), 0x80B);
+
+ /* Fine Correction (B) */
+ mt9t112_mcu_write(ret, client, VAR(18, 87), 0x008C);
+
+ /* Fine IT Min (B) */
+ mt9t112_mcu_write(ret, client, VAR(18, 89), 0x01F1);
+
+ /* Fine IT Max Margin (B) */
+ mt9t112_mcu_write(ret, client, VAR(18, 91), 0x00FF);
+
+ /* Base Frame Lines (B) */
+ mt9t112_mcu_write(ret, client, VAR(18, 101), 0x0668);
+
+ /* Min Line Length (B) */
+ mt9t112_mcu_write(ret, client, VAR(18, 103), 0x0AF0);
+
+ /* Line Length (B) */
+ mt9t112_mcu_write(ret, client, VAR(18, 109), 0x0AF0);
+
+ /*
+ * Flicker Dectection registers
+ * This section should be replaced whenever new Timing file is generated
+ * All the following registers need to be replaced
+ * Following registers are generated from Register Wizard but user can
+ * modify them. For detail see auto flicker detection tuning
+ */
+
+ /* FD_FDPERIOD_SELECT */
+ mt9t112_mcu_write(ret, client, VAR8(8, 5), 0x01);
+
+ /* PRI_B_CONFIG_FD_ALGO_RUN */
+ mt9t112_mcu_write(ret, client, VAR(27, 17), 0x0003);
+
+ /* PRI_A_CONFIG_FD_ALGO_RUN */
+ mt9t112_mcu_write(ret, client, VAR(26, 17), 0x0003);
+
+ /*
+ * AFD range detection tuning registers
+ */
+
+ /* search_f1_50 */
+ mt9t112_mcu_write(ret, client, VAR8(18, 165), 0x25);
+
+ /* search_f2_50 */
+ mt9t112_mcu_write(ret, client, VAR8(18, 166), 0x28);
+
+ /* search_f1_60 */
+ mt9t112_mcu_write(ret, client, VAR8(18, 167), 0x2C);
+
+ /* search_f2_60 */
+ mt9t112_mcu_write(ret, client, VAR8(18, 168), 0x2F);
+
+ /* period_50Hz (A) */
+ mt9t112_mcu_write(ret, client, VAR8(18, 68), 0xBA);
+
+ /* secret register by aptina */
+ /* period_50Hz (A MSB) */
+ mt9t112_mcu_write(ret, client, VAR8(18, 303), 0x00);
+
+ /* period_60Hz (A) */
+ mt9t112_mcu_write(ret, client, VAR8(18, 69), 0x9B);
+
+ /* secret register by aptina */
+ /* period_60Hz (A MSB) */
+ mt9t112_mcu_write(ret, client, VAR8(18, 301), 0x00);
+
+ /* period_50Hz (B) */
+ mt9t112_mcu_write(ret, client, VAR8(18, 140), 0x82);
+
+ /* secret register by aptina */
+ /* period_50Hz (B) MSB */
+ mt9t112_mcu_write(ret, client, VAR8(18, 304), 0x00);
+
+ /* period_60Hz (B) */
+ mt9t112_mcu_write(ret, client, VAR8(18, 141), 0x6D);
+
+ /* secret register by aptina */
+ /* period_60Hz (B) MSB */
+ mt9t112_mcu_write(ret, client, VAR8(18, 302), 0x00);
+
+ /* FD Mode */
+ mt9t112_mcu_write(ret, client, VAR8(8, 2), 0x10);
+
+ /* Stat_min */
+ mt9t112_mcu_write(ret, client, VAR8(8, 9), 0x02);
+
+ /* Stat_max */
+ mt9t112_mcu_write(ret, client, VAR8(8, 10), 0x03);
+
+ /* Min_amplitude */
+ mt9t112_mcu_write(ret, client, VAR8(8, 12), 0x0A);
+
+ /* RX FIFO Watermark (A) */
+ mt9t112_mcu_write(ret, client, VAR(18, 70), 0x0014);
+
+ /* RX FIFO Watermark (B) */
+ mt9t112_mcu_write(ret, client, VAR(18, 142), 0x0014);
+
+ /* MCLK: 16MHz
+ * PCLK: 73MHz
+ * CorePixCLK: 36.5 MHz
+ */
+ mt9t112_mcu_write(ret, client, VAR8(18, 0x0044), 133);
+ mt9t112_mcu_write(ret, client, VAR8(18, 0x0045), 110);
+ mt9t112_mcu_write(ret, client, VAR8(18, 0x008c), 130);
+ mt9t112_mcu_write(ret, client, VAR8(18, 0x008d), 108);
+
+ mt9t112_mcu_write(ret, client, VAR8(18, 0x00A5), 27);
+ mt9t112_mcu_write(ret, client, VAR8(18, 0x00a6), 30);
+ mt9t112_mcu_write(ret, client, VAR8(18, 0x00a7), 32);
+ mt9t112_mcu_write(ret, client, VAR8(18, 0x00a8), 35);
+
+ return ret;
+}
+
+static int mt9t112_auto_focus_setting(const struct i2c_client *client)
+{
+ int ret;
+
+ mt9t112_mcu_write(ret, client, VAR(12, 13), 0x000F);
+ mt9t112_mcu_write(ret, client, VAR(12, 23), 0x0F0F);
+ mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x06);
+
+ mt9t112_reg_write(ret, client, 0x0614, 0x0000);
+
+ mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x05);
+ mt9t112_mcu_write(ret, client, VAR8(12, 2), 0x02);
+ mt9t112_mcu_write(ret, client, VAR(12, 3), 0x0002);
+ mt9t112_mcu_write(ret, client, VAR(17, 3), 0x8001);
+ mt9t112_mcu_write(ret, client, VAR(17, 11), 0x0025);
+ mt9t112_mcu_write(ret, client, VAR(17, 13), 0x0193);
+ mt9t112_mcu_write(ret, client, VAR8(17, 33), 0x18);
+ mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x05);
+
+ return ret;
+}
+
+static int mt9t112_auto_focus_trigger(const struct i2c_client *client)
+{
+ int ret;
+
+ mt9t112_mcu_write(ret, client, VAR8(12, 25), 0x01);
+
+ return ret;
+}
+
+static int mt9t112_init_camera(const struct i2c_client *client)
+{
+ int ret;
+
+ ECHECKER(ret, mt9t112_reset(client));
+
+ ECHECKER(ret, mt9t112_init_pll(client));
+
+ ECHECKER(ret, mt9t112_init_setting(client));
+
+ ECHECKER(ret, mt9t112_auto_focus_setting(client));
+
+ mt9t112_reg_mask_set(ret, client, 0x0018, 0x0004, 0);
+
+ /* Analog setting B */
+ mt9t112_reg_write(ret, client, 0x3084, 0x2409);
+ mt9t112_reg_write(ret, client, 0x3092, 0x0A49);
+ mt9t112_reg_write(ret, client, 0x3094, 0x4949);
+ mt9t112_reg_write(ret, client, 0x3096, 0x4950);
+
+ /*
+ * Disable adaptive clock
+ * PRI_A_CONFIG_JPEG_OB_TX_CONTROL_VAR
+ * PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR
+ */
+ mt9t112_mcu_write(ret, client, VAR(26, 160), 0x0A2E);
+ mt9t112_mcu_write(ret, client, VAR(27, 160), 0x0A2E);
+
+ /* Configure STatus in Status_before_length Format and enable header */
+ /* PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR */
+ mt9t112_mcu_write(ret, client, VAR(27, 144), 0x0CB4);
+
+ /* Enable JPEG in context B */
+ /* PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR */
+ mt9t112_mcu_write(ret, client, VAR8(27, 142), 0x01);
+
+ /* Disable Dac_TXLO */
+ mt9t112_reg_write(ret, client, 0x316C, 0x350F);
+
+ /* Set max slew rates */
+ mt9t112_reg_write(ret, client, 0x1E, 0x777);
+
+ return ret;
+}
+
+/************************************************************************
+ v4l2_subdev_core_ops
+************************************************************************/
+
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+static int mt9t112_g_register(struct v4l2_subdev *sd,
+ struct v4l2_dbg_register *reg)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ int ret;
+
+ reg->size = 2;
+ mt9t112_reg_read(ret, client, reg->reg);
+
+ reg->val = (__u64)ret;
+
+ return 0;
+}
+
+static int mt9t112_s_register(struct v4l2_subdev *sd,
+ const struct v4l2_dbg_register *reg)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ int ret;
+
+ mt9t112_reg_write(ret, client, reg->reg, reg->val);
+
+ return ret;
+}
+#endif
+
+static int mt9t112_s_power(struct v4l2_subdev *sd, int on)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
+ struct mt9t112_priv *priv = to_mt9t112(client);
+
+ return soc_camera_set_power(&client->dev, ssdd, priv->clk, on);
+}
+
+static const struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = {
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+ .g_register = mt9t112_g_register,
+ .s_register = mt9t112_s_register,
+#endif
+ .s_power = mt9t112_s_power,
+};
+
+
+/************************************************************************
+ v4l2_subdev_video_ops
+************************************************************************/
+static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct mt9t112_priv *priv = to_mt9t112(client);
+ int ret = 0;
+
+ if (!enable) {
+ /* FIXME
+ *
+ * If user selected large output size,
+ * and used it long time,
+ * mt9t112 camera will be very warm.
+ *
+ * But current driver can not stop mt9t112 camera.
+ * So, set small size here to solve this problem.
+ */
+ mt9t112_set_a_frame_size(client, VGA_WIDTH, VGA_HEIGHT);
+ return ret;
+ }
+
+ if (!(priv->flags & INIT_DONE)) {
+ u16 param = PCLK_RISING & priv->flags ? 0x0001 : 0x0000;
+
+ ECHECKER(ret, mt9t112_init_camera(client));
+
+ /* Invert PCLK (Data sampled on falling edge of pixclk) */
+ mt9t112_reg_write(ret, client, 0x3C20, param);
+
+ mdelay(5);
+
+ priv->flags |= INIT_DONE;
+ }
+
+ mt9t112_mcu_write(ret, client, VAR(26, 7), priv->format->fmt);
+ mt9t112_mcu_write(ret, client, VAR(26, 9), priv->format->order);
+ mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x06);
+
+ mt9t112_set_a_frame_size(client,
+ priv->frame.width,
+ priv->frame.height);
+
+ ECHECKER(ret, mt9t112_auto_focus_trigger(client));
+
+ dev_dbg(&client->dev, "format : %d\n", priv->format->code);
+ dev_dbg(&client->dev, "size : %d x %d\n",
+ priv->frame.width,
+ priv->frame.height);
+
+ CLOCK_INFO(client, EXT_CLOCK);
+
+ return ret;
+}
+
+static int mt9t112_set_params(struct mt9t112_priv *priv,
+ const struct v4l2_rect *rect,
+ u32 code)
+{
+ int i;
+
+ /*
+ * get color format
+ */
+ for (i = 0; i < priv->num_formats; i++)
+ if (mt9t112_cfmts[i].code == code)
+ break;
+
+ if (i == priv->num_formats)
+ return -EINVAL;
+
+ priv->frame = *rect;
+
+ /*
+ * frame size check
+ */
+ mt9t112_frame_check(&priv->frame.width, &priv->frame.height,
+ &priv->frame.left, &priv->frame.top);
+
+ priv->format = mt9t112_cfmts + i;
+
+ return 0;
+}
+
+static int mt9t112_get_selection(struct v4l2_subdev *sd,
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_selection *sel)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct mt9t112_priv *priv = to_mt9t112(client);
+
+ if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE)
+ return -EINVAL;
+
+ switch (sel->target) {
+ case V4L2_SEL_TGT_CROP_BOUNDS:
+ sel->r.left = 0;
+ sel->r.top = 0;
+ sel->r.width = MAX_WIDTH;
+ sel->r.height = MAX_HEIGHT;
+ return 0;
+ case V4L2_SEL_TGT_CROP_DEFAULT:
+ sel->r.left = 0;
+ sel->r.top = 0;
+ sel->r.width = VGA_WIDTH;
+ sel->r.height = VGA_HEIGHT;
+ return 0;
+ case V4L2_SEL_TGT_CROP:
+ sel->r = priv->frame;
+ return 0;
+ default:
+ return -EINVAL;
+ }
+}
+
+static int mt9t112_set_selection(struct v4l2_subdev *sd,
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_selection *sel)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct mt9t112_priv *priv = to_mt9t112(client);
+ const struct v4l2_rect *rect = &sel->r;
+
+ if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE ||
+ sel->target != V4L2_SEL_TGT_CROP)
+ return -EINVAL;
+
+ return mt9t112_set_params(priv, rect, priv->format->code);
+}
+
+static int mt9t112_get_fmt(struct v4l2_subdev *sd,
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_format *format)
+{
+ struct v4l2_mbus_framefmt *mf = &format->format;
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct mt9t112_priv *priv = to_mt9t112(client);
+
+ if (format->pad)
+ return -EINVAL;
+
+ mf->width = priv->frame.width;
+ mf->height = priv->frame.height;
+ mf->colorspace = priv->format->colorspace;
+ mf->code = priv->format->code;
+ mf->field = V4L2_FIELD_NONE;
+
+ return 0;
+}
+
+static int mt9t112_s_fmt(struct v4l2_subdev *sd,
+ struct v4l2_mbus_framefmt *mf)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct mt9t112_priv *priv = to_mt9t112(client);
+ struct v4l2_rect rect = {
+ .width = mf->width,
+ .height = mf->height,
+ .left = priv->frame.left,
+ .top = priv->frame.top,
+ };
+ int ret;
+
+ ret = mt9t112_set_params(priv, &rect, mf->code);
+
+ if (!ret)
+ mf->colorspace = priv->format->colorspace;
+
+ return ret;
+}
+
+static int mt9t112_set_fmt(struct v4l2_subdev *sd,
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_format *format)
+{
+ struct v4l2_mbus_framefmt *mf = &format->format;
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct mt9t112_priv *priv = to_mt9t112(client);
+ unsigned int top, left;
+ int i;
+
+ if (format->pad)
+ return -EINVAL;
+
+ for (i = 0; i < priv->num_formats; i++)
+ if (mt9t112_cfmts[i].code == mf->code)
+ break;
+
+ if (i == priv->num_formats) {
+ mf->code = MEDIA_BUS_FMT_UYVY8_2X8;
+ mf->colorspace = V4L2_COLORSPACE_JPEG;
+ } else {
+ mf->colorspace = mt9t112_cfmts[i].colorspace;
+ }
+
+ mt9t112_frame_check(&mf->width, &mf->height, &left, &top);
+
+ mf->field = V4L2_FIELD_NONE;
+
+ if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
+ return mt9t112_s_fmt(sd, mf);
+ cfg->try_fmt = *mf;
+ return 0;
+}
+
+static int mt9t112_enum_mbus_code(struct v4l2_subdev *sd,
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_mbus_code_enum *code)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct mt9t112_priv *priv = to_mt9t112(client);
+
+ if (code->pad || code->index >= priv->num_formats)
+ return -EINVAL;
+
+ code->code = mt9t112_cfmts[code->index].code;
+
+ return 0;
+}
+
+static int mt9t112_g_mbus_config(struct v4l2_subdev *sd,
+ struct v4l2_mbus_config *cfg)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
+
+ cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH |
+ V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING;
+ cfg->type = V4L2_MBUS_PARALLEL;
+ cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
+
+ return 0;
+}
+
+static int mt9t112_s_mbus_config(struct v4l2_subdev *sd,
+ const struct v4l2_mbus_config *cfg)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
+ struct mt9t112_priv *priv = to_mt9t112(client);
+
+ if (soc_camera_apply_board_flags(ssdd, cfg) & V4L2_MBUS_PCLK_SAMPLE_RISING)
+ priv->flags |= PCLK_RISING;
+
+ return 0;
+}
+
+static const struct v4l2_subdev_video_ops mt9t112_subdev_video_ops = {
+ .s_stream = mt9t112_s_stream,
+ .g_mbus_config = mt9t112_g_mbus_config,
+ .s_mbus_config = mt9t112_s_mbus_config,
+};
+
+static const struct v4l2_subdev_pad_ops mt9t112_subdev_pad_ops = {
+ .enum_mbus_code = mt9t112_enum_mbus_code,
+ .get_selection = mt9t112_get_selection,
+ .set_selection = mt9t112_set_selection,
+ .get_fmt = mt9t112_get_fmt,
+ .set_fmt = mt9t112_set_fmt,
+};
+
+/************************************************************************
+ i2c driver
+************************************************************************/
+static const struct v4l2_subdev_ops mt9t112_subdev_ops = {
+ .core = &mt9t112_subdev_core_ops,
+ .video = &mt9t112_subdev_video_ops,
+ .pad = &mt9t112_subdev_pad_ops,
+};
+
+static int mt9t112_camera_probe(struct i2c_client *client)
+{
+ struct mt9t112_priv *priv = to_mt9t112(client);
+ const char *devname;
+ int chipid;
+ int ret;
+
+ ret = mt9t112_s_power(&priv->subdev, 1);
+ if (ret < 0)
+ return ret;
+
+ /*
+ * check and show chip ID
+ */
+ mt9t112_reg_read(chipid, client, 0x0000);
+
+ switch (chipid) {
+ case 0x2680:
+ devname = "mt9t111";
+ priv->num_formats = 1;
+ break;
+ case 0x2682:
+ devname = "mt9t112";
+ priv->num_formats = ARRAY_SIZE(mt9t112_cfmts);
+ break;
+ default:
+ dev_err(&client->dev, "Product ID error %04x\n", chipid);
+ ret = -ENODEV;
+ goto done;
+ }
+
+ dev_info(&client->dev, "%s chip ID %04x\n", devname, chipid);
+
+done:
+ mt9t112_s_power(&priv->subdev, 0);
+ return ret;
+}
+
+static int mt9t112_probe(struct i2c_client *client,
+ const struct i2c_device_id *did)
+{
+ struct mt9t112_priv *priv;
+ struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
+ struct v4l2_rect rect = {
+ .width = VGA_WIDTH,
+ .height = VGA_HEIGHT,
+ .left = (MAX_WIDTH - VGA_WIDTH) / 2,
+ .top = (MAX_HEIGHT - VGA_HEIGHT) / 2,
+ };
+ int ret;
+
+ if (!ssdd || !ssdd->drv_priv) {
+ dev_err(&client->dev, "mt9t112: missing platform data!\n");
+ return -EINVAL;
+ }
+
+ priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ priv->info = ssdd->drv_priv;
+
+ v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
+
+ priv->clk = v4l2_clk_get(&client->dev, "mclk");
+ if (IS_ERR(priv->clk))
+ return PTR_ERR(priv->clk);
+
+ ret = mt9t112_camera_probe(client);
+
+ /* Cannot fail: using the default supported pixel code */
+ if (!ret)
+ mt9t112_set_params(priv, &rect, MEDIA_BUS_FMT_UYVY8_2X8);
+ else
+ v4l2_clk_put(priv->clk);
+
+ return ret;
+}
+
+static int mt9t112_remove(struct i2c_client *client)
+{
+ struct mt9t112_priv *priv = to_mt9t112(client);
+
+ v4l2_clk_put(priv->clk);
+ return 0;
+}
+
+static const struct i2c_device_id mt9t112_id[] = {
+ { "mt9t112", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, mt9t112_id);
+
+static struct i2c_driver mt9t112_i2c_driver = {
+ .driver = {
+ .name = "mt9t112",
+ },
+ .probe = mt9t112_probe,
+ .remove = mt9t112_remove,
+ .id_table = mt9t112_id,
+};
+
+module_i2c_driver(mt9t112_i2c_driver);
+
+MODULE_DESCRIPTION("SoC Camera driver for mt9t112");
+MODULE_AUTHOR("Kuninori Morimoto");
+MODULE_LICENSE("GPL v2");
--
2.7.4
Remove soc_camera framework dependencies from mt9t112 sensor driver.
- Handle clk, gpios and power routines
- Register async subdev
- Remove deprecated g/s_mbus_config operations
- Remove driver flags
- Change driver interface and add kernel doc
- Adjust build system
- Fix code style issues reported by checkpatch in strict mode
This commit does not remove the original soc_camera based driver as long
as other platforms depends on soc_camera framework.
As I don't have access to a working camera module, this change has only
been compile tested.
Signed-off-by: Jacopo Mondi <[email protected]>
---
drivers/media/i2c/Kconfig | 11 +
drivers/media/i2c/Makefile | 1 +
drivers/media/i2c/mt9t112.c | 403 ++++++++++++++++-----------------
drivers/media/i2c/soc_camera/mt9t112.c | 2 +-
include/media/i2c/mt9t112.h | 17 +-
5 files changed, 210 insertions(+), 224 deletions(-)
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index d7bba0e..541f0d28 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -788,6 +788,17 @@ config VIDEO_MT9T001
This is a Video4Linux2 sensor-level driver for the Aptina
(Micron) mt0t001 3 Mpixel camera.
+config VIDEO_MT9T112
+ tristate "Aptina MT9T111/MT9T112 support"
+ depends on I2C && VIDEO_V4L2
+ depends on MEDIA_CAMERA_SUPPORT
+ ---help---
+ This is a Video4Linux2 sensor-level driver for the Aptina
+ (Micron) MT9T111 and MT9T112 3 Mpixel camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called mt9t112.
+
config VIDEO_MT9V011
tristate "Micron mt9v011 sensor support"
depends on I2C && VIDEO_V4L2
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index cc30178..ea34aee 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -80,6 +80,7 @@ obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o
obj-$(CONFIG_VIDEO_MT9M111) += mt9m111.o
obj-$(CONFIG_VIDEO_MT9P031) += mt9p031.o
obj-$(CONFIG_VIDEO_MT9T001) += mt9t001.o
+obj-$(CONFIG_VIDEO_MT9T112) += mt9t112.o
obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o
obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o
obj-$(CONFIG_VIDEO_SR030PC30) += sr030pc30.o
diff --git a/drivers/media/i2c/mt9t112.c b/drivers/media/i2c/mt9t112.c
index 297d22e..af8cca9 100644
--- a/drivers/media/i2c/mt9t112.c
+++ b/drivers/media/i2c/mt9t112.c
@@ -1,6 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
/*
* mt9t112 Camera Driver
*
+ * Copyright (C) 2018 Jacopo Mondi <[email protected]>
+ *
* Copyright (C) 2009 Renesas Solutions Corp.
* Kuninori Morimoto <[email protected]>
*
@@ -12,12 +15,14 @@
* Copyright (C) 2008 Magnus Damm
* Copyright (C) 2008, Guennadi Liakhovetski <[email protected]>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
+ * TODO: This driver lacks support for frame rate control due to missing
+ * register level documentation and suitable hardware for testing.
+ * v4l-utils compliance tools will report errors.
*/
+#include <linux/clk.h>
#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/module.h>
@@ -26,17 +31,16 @@
#include <linux/videodev2.h>
#include <media/i2c/mt9t112.h>
-#include <media/soc_camera.h>
-#include <media/v4l2-clk.h>
#include <media/v4l2-common.h>
#include <media/v4l2-image-sizes.h>
+#include <media/v4l2-subdev.h>
/* you can check PLL/clock info */
/* #define EXT_CLOCK 24000000 */
/************************************************************************
- macro
-************************************************************************/
+ * macro
+ ***********************************************************************/
/*
* frame size
*/
@@ -74,8 +78,8 @@
#define VAR8(id, offset) _VAR(id, offset, 0x8000)
/************************************************************************
- struct
-************************************************************************/
+ * struct
+ ***********************************************************************/
struct mt9t112_format {
u32 code;
enum v4l2_colorspace colorspace;
@@ -85,21 +89,19 @@ struct mt9t112_format {
struct mt9t112_priv {
struct v4l2_subdev subdev;
- struct mt9t112_camera_info *info;
+ struct mt9t112_platform_data *info;
struct i2c_client *client;
struct v4l2_rect frame;
- struct v4l2_clk *clk;
+ struct clk *clk;
+ struct gpio_desc *standby_gpio;
const struct mt9t112_format *format;
int num_formats;
- u32 flags;
-/* for flags */
-#define INIT_DONE (1 << 0)
-#define PCLK_RISING (1 << 1)
+ bool init_done;
};
/************************************************************************
- supported format
-************************************************************************/
+ * supported format
+ ***********************************************************************/
static const struct mt9t112_format mt9t112_cfmts[] = {
{
@@ -136,8 +138,8 @@ static const struct mt9t112_format mt9t112_cfmts[] = {
};
/************************************************************************
- general function
-************************************************************************/
+ * general function
+ ***********************************************************************/
static struct mt9t112_priv *to_mt9t112(const struct i2c_client *client)
{
return container_of(i2c_get_clientdata(client),
@@ -164,15 +166,15 @@ static int __mt9t112_reg_read(const struct i2c_client *client, u16 command)
msg[1].buf = buf;
/*
- * if return value of this function is < 0,
- * it mean error.
- * else, under 16bit is valid data.
+ * If return value of this function is < 0, it means error, else,
+ * below 16bit is valid data.
*/
ret = i2c_transfer(client->adapter, msg, 2);
if (ret < 0)
return ret;
memcpy(&ret, buf, 2);
+
return swab16(ret);
}
@@ -195,22 +197,19 @@ static int __mt9t112_reg_write(const struct i2c_client *client,
msg.buf = buf;
/*
- * i2c_transfer return message length,
- * but this function should return 0 if correct case
+ * i2c_transfer return message length, but this function should
+ * return 0 if correct case.
*/
ret = i2c_transfer(client->adapter, &msg, 1);
- if (ret >= 0)
- ret = 0;
- return ret;
+ return ret >= 0 ? 0 : ret;
}
static int __mt9t112_reg_mask_set(const struct i2c_client *client,
- u16 command,
- u16 mask,
- u16 set)
+ u16 command, u16 mask, u16 set)
{
int val = __mt9t112_reg_read(client, command);
+
if (val < 0)
return val;
@@ -245,11 +244,10 @@ static int __mt9t112_mcu_write(const struct i2c_client *client,
}
static int __mt9t112_mcu_mask_set(const struct i2c_client *client,
- u16 command,
- u16 mask,
- u16 set)
+ u16 command, u16 mask, u16 set)
{
int val = __mt9t112_mcu_read(client, command);
+
if (val < 0)
return val;
@@ -264,7 +262,7 @@ static int mt9t112_reset(const struct i2c_client *client)
int ret;
mt9t112_reg_mask_set(ret, client, 0x001a, 0x0001, 0x0001);
- msleep(1);
+ usleep_range(1000, 5000);
mt9t112_reg_mask_set(ret, client, 0x001a, 0x0001, 0x0000);
return ret;
@@ -303,71 +301,64 @@ static int mt9t112_clock_info(const struct i2c_client *client, u32 ext)
m = n & 0x00ff;
n = (n >> 8) & 0x003f;
- enable = ((6000 > ext) || (54000 < ext)) ? "X" : "";
+ enable = ((ext < 6000) || (ext > 54000)) ? "X" : "";
dev_dbg(&client->dev, "EXTCLK : %10u K %s\n", ext, enable);
- vco = 2 * m * ext / (n+1);
- enable = ((384000 > vco) || (768000 < vco)) ? "X" : "";
+ vco = 2 * m * ext / (n + 1);
+ enable = ((vco < 384000) || (vco > 768000)) ? "X" : "";
dev_dbg(&client->dev, "VCO : %10u K %s\n", vco, enable);
- clk = vco / (p1+1) / (p2+1);
- enable = (96000 < clk) ? "X" : "";
+ clk = vco / (p1 + 1) / (p2 + 1);
+ enable = (clk > 96000) ? "X" : "";
dev_dbg(&client->dev, "PIXCLK : %10u K %s\n", clk, enable);
- clk = vco / (p3+1);
- enable = (768000 < clk) ? "X" : "";
+ clk = vco / (p3 + 1);
+ enable = (clk > 768000) ? "X" : "";
dev_dbg(&client->dev, "MIPICLK : %10u K %s\n", clk, enable);
- clk = vco / (p6+1);
- enable = (96000 < clk) ? "X" : "";
+ clk = vco / (p6 + 1);
+ enable = (clk > 96000) ? "X" : "";
dev_dbg(&client->dev, "MCU CLK : %10u K %s\n", clk, enable);
- clk = vco / (p5+1);
- enable = (54000 < clk) ? "X" : "";
+ clk = vco / (p5 + 1);
+ enable = (clk > 54000) ? "X" : "";
dev_dbg(&client->dev, "SOC CLK : %10u K %s\n", clk, enable);
- clk = vco / (p4+1);
- enable = (70000 < clk) ? "X" : "";
+ clk = vco / (p4 + 1);
+ enable = (clk > 70000) ? "X" : "";
dev_dbg(&client->dev, "Sensor CLK : %10u K %s\n", clk, enable);
- clk = vco / (p7+1);
+ clk = vco / (p7 + 1);
dev_dbg(&client->dev, "External sensor : %10u K\n", clk);
- clk = ext / (n+1);
- enable = ((2000 > clk) || (24000 < clk)) ? "X" : "";
+ clk = ext / (n + 1);
+ enable = ((clk < 2000) || (clk > 24000)) ? "X" : "";
dev_dbg(&client->dev, "PFD : %10u K %s\n", clk, enable);
return 0;
}
#endif
-static void mt9t112_frame_check(u32 *width, u32 *height, u32 *left, u32 *top)
-{
- soc_camera_limit_side(left, width, 0, 0, MAX_WIDTH);
- soc_camera_limit_side(top, height, 0, 0, MAX_HEIGHT);
-}
-
static int mt9t112_set_a_frame_size(const struct i2c_client *client,
- u16 width,
- u16 height)
+ u16 width, u16 height)
{
int ret;
u16 wstart = (MAX_WIDTH - width) / 2;
u16 hstart = (MAX_HEIGHT - height) / 2;
- /* (Context A) Image Width/Height */
+ /* (Context A) Image Width/Height. */
mt9t112_mcu_write(ret, client, VAR(26, 0), width);
mt9t112_mcu_write(ret, client, VAR(26, 2), height);
- /* (Context A) Output Width/Height */
+ /* (Context A) Output Width/Height. */
mt9t112_mcu_write(ret, client, VAR(18, 43), 8 + width);
mt9t112_mcu_write(ret, client, VAR(18, 45), 8 + height);
- /* (Context A) Start Row/Column */
+ /* (Context A) Start Row/Column. */
mt9t112_mcu_write(ret, client, VAR(18, 2), 4 + hstart);
mt9t112_mcu_write(ret, client, VAR(18, 4), 4 + wstart);
- /* (Context A) End Row/Column */
+ /* (Context A) End Row/Column. */
mt9t112_mcu_write(ret, client, VAR(18, 6), 11 + height + hstart);
mt9t112_mcu_write(ret, client, VAR(18, 8), 11 + width + wstart);
@@ -377,35 +368,27 @@ static int mt9t112_set_a_frame_size(const struct i2c_client *client,
}
static int mt9t112_set_pll_dividers(const struct i2c_client *client,
- u8 m, u8 n,
- u8 p1, u8 p2, u8 p3,
- u8 p4, u8 p5, u8 p6,
- u8 p7)
+ u8 m, u8 n, u8 p1, u8 p2, u8 p3, u8 p4,
+ u8 p5, u8 p6, u8 p7)
{
int ret;
u16 val;
/* N/M */
- val = (n << 8) |
- (m << 0);
+ val = (n << 8) | (m << 0);
mt9t112_reg_mask_set(ret, client, 0x0010, 0x3fff, val);
/* P1/P2/P3 */
- val = ((p3 & 0x0F) << 8) |
- ((p2 & 0x0F) << 4) |
- ((p1 & 0x0F) << 0);
+ val = ((p3 & 0x0F) << 8) | ((p2 & 0x0F) << 4) | ((p1 & 0x0F) << 0);
mt9t112_reg_mask_set(ret, client, 0x0012, 0x0fff, val);
/* P4/P5/P6 */
- val = (0x7 << 12) |
- ((p6 & 0x0F) << 8) |
- ((p5 & 0x0F) << 4) |
+ val = (0x7 << 12) | ((p6 & 0x0F) << 8) | ((p5 & 0x0F) << 4) |
((p4 & 0x0F) << 0);
mt9t112_reg_mask_set(ret, client, 0x002A, 0x7fff, val);
/* P7 */
- val = (0x1 << 12) |
- ((p7 & 0x0F) << 0);
+ val = (0x1 << 12) | ((p7 & 0x0F) << 0);
mt9t112_reg_mask_set(ret, client, 0x002C, 0x100f, val);
return ret;
@@ -418,19 +401,15 @@ static int mt9t112_init_pll(const struct i2c_client *client)
mt9t112_reg_mask_set(ret, client, 0x0014, 0x003, 0x0001);
- /* PLL control: BYPASS PLL = 8517 */
+ /* PLL control: BYPASS PLL = 8517. */
mt9t112_reg_write(ret, client, 0x0014, 0x2145);
- /* Replace these registers when new timing parameters are generated */
+ /* Replace these registers when new timing parameters are generated. */
mt9t112_set_pll_dividers(client,
- priv->info->divider.m,
- priv->info->divider.n,
- priv->info->divider.p1,
- priv->info->divider.p2,
- priv->info->divider.p3,
- priv->info->divider.p4,
- priv->info->divider.p5,
- priv->info->divider.p6,
+ priv->info->divider.m, priv->info->divider.n,
+ priv->info->divider.p1, priv->info->divider.p2,
+ priv->info->divider.p3, priv->info->divider.p4,
+ priv->info->divider.p5, priv->info->divider.p6,
priv->info->divider.p7);
/*
@@ -452,20 +431,21 @@ static int mt9t112_init_pll(const struct i2c_client *client)
* I2C Master Clock Divider
*/
mt9t112_reg_write(ret, client, 0x0014, 0x3046);
- mt9t112_reg_write(ret, client, 0x0016, 0x0400); /* JPEG initialization workaround */
+ /* JPEG initialization workaround */
+ mt9t112_reg_write(ret, client, 0x0016, 0x0400);
mt9t112_reg_write(ret, client, 0x0022, 0x0190);
mt9t112_reg_write(ret, client, 0x3B84, 0x0212);
- /* External sensor clock is PLL bypass */
+ /* External sensor clock is PLL bypass. */
mt9t112_reg_write(ret, client, 0x002E, 0x0500);
mt9t112_reg_mask_set(ret, client, 0x0018, 0x0002, 0x0002);
mt9t112_reg_mask_set(ret, client, 0x3B82, 0x0004, 0x0004);
- /* MCU disabled */
+ /* MCU disabled. */
mt9t112_reg_mask_set(ret, client, 0x0018, 0x0004, 0x0004);
- /* out of standby */
+ /* Out of standby. */
mt9t112_reg_mask_set(ret, client, 0x0018, 0x0001, 0);
mdelay(50);
@@ -487,10 +467,10 @@ static int mt9t112_init_pll(const struct i2c_client *client)
mt9t112_reg_write(ret, client, 0x0614, 0x0001);
mdelay(1);
- /* poll to verify out of standby. Must Poll this bit */
+ /* Poll to verify out of standby. Must Poll this bit. */
for (i = 0; i < 100; i++) {
mt9t112_reg_read(data, client, 0x0018);
- if (!(0x4000 & data))
+ if (!(data & 0x4000))
break;
mdelay(10);
@@ -501,7 +481,6 @@ static int mt9t112_init_pll(const struct i2c_client *client)
static int mt9t112_init_setting(const struct i2c_client *client)
{
-
int ret;
/* Adaptive Output Clock (A) */
@@ -562,11 +541,11 @@ static int mt9t112_init_setting(const struct i2c_client *client)
mt9t112_mcu_write(ret, client, VAR(18, 109), 0x0AF0);
/*
- * Flicker Dectection registers
- * This section should be replaced whenever new Timing file is generated
- * All the following registers need to be replaced
+ * Flicker Dectection registers.
+ * This section should be replaced whenever new timing file is
+ * generated. All the following registers need to be replaced.
* Following registers are generated from Register Wizard but user can
- * modify them. For detail see auto flicker detection tuning
+ * modify them. For detail see auto flicker detection tuning.
*/
/* FD_FDPERIOD_SELECT */
@@ -579,47 +558,47 @@ static int mt9t112_init_setting(const struct i2c_client *client)
mt9t112_mcu_write(ret, client, VAR(26, 17), 0x0003);
/*
- * AFD range detection tuning registers
+ * AFD range detection tuning registers.
*/
- /* search_f1_50 */
+ /* Search_f1_50 */
mt9t112_mcu_write(ret, client, VAR8(18, 165), 0x25);
- /* search_f2_50 */
+ /* Search_f2_50 */
mt9t112_mcu_write(ret, client, VAR8(18, 166), 0x28);
- /* search_f1_60 */
+ /* Search_f1_60 */
mt9t112_mcu_write(ret, client, VAR8(18, 167), 0x2C);
- /* search_f2_60 */
+ /* Search_f2_60 */
mt9t112_mcu_write(ret, client, VAR8(18, 168), 0x2F);
- /* period_50Hz (A) */
+ /* Period_50Hz (A) */
mt9t112_mcu_write(ret, client, VAR8(18, 68), 0xBA);
- /* secret register by aptina */
- /* period_50Hz (A MSB) */
+ /* Secret register by Aptina. */
+ /* Period_50Hz (A MSB) */
mt9t112_mcu_write(ret, client, VAR8(18, 303), 0x00);
- /* period_60Hz (A) */
+ /* Period_60Hz (A) */
mt9t112_mcu_write(ret, client, VAR8(18, 69), 0x9B);
- /* secret register by aptina */
- /* period_60Hz (A MSB) */
+ /* Secret register by Aptina. */
+ /* Period_60Hz (A MSB) */
mt9t112_mcu_write(ret, client, VAR8(18, 301), 0x00);
- /* period_50Hz (B) */
+ /* Period_50Hz (B) */
mt9t112_mcu_write(ret, client, VAR8(18, 140), 0x82);
- /* secret register by aptina */
- /* period_50Hz (B) MSB */
+ /* Secret register by Aptina. */
+ /* Period_50Hz (B) MSB */
mt9t112_mcu_write(ret, client, VAR8(18, 304), 0x00);
- /* period_60Hz (B) */
+ /* Period_60Hz (B) */
mt9t112_mcu_write(ret, client, VAR8(18, 141), 0x6D);
- /* secret register by aptina */
- /* period_60Hz (B) MSB */
+ /* Secret register by Aptina. */
+ /* Period_60Hz (B) MSB */
mt9t112_mcu_write(ret, client, VAR8(18, 302), 0x00);
/* FD Mode */
@@ -693,49 +672,50 @@ static int mt9t112_init_camera(const struct i2c_client *client)
int ret;
ECHECKER(ret, mt9t112_reset(client));
-
ECHECKER(ret, mt9t112_init_pll(client));
-
ECHECKER(ret, mt9t112_init_setting(client));
-
ECHECKER(ret, mt9t112_auto_focus_setting(client));
mt9t112_reg_mask_set(ret, client, 0x0018, 0x0004, 0);
- /* Analog setting B */
+ /* Analog setting B.*/
mt9t112_reg_write(ret, client, 0x3084, 0x2409);
mt9t112_reg_write(ret, client, 0x3092, 0x0A49);
mt9t112_reg_write(ret, client, 0x3094, 0x4949);
mt9t112_reg_write(ret, client, 0x3096, 0x4950);
/*
- * Disable adaptive clock
+ * Disable adaptive clock.
* PRI_A_CONFIG_JPEG_OB_TX_CONTROL_VAR
* PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR
*/
mt9t112_mcu_write(ret, client, VAR(26, 160), 0x0A2E);
mt9t112_mcu_write(ret, client, VAR(27, 160), 0x0A2E);
- /* Configure STatus in Status_before_length Format and enable header */
- /* PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR */
+ /*
+ * Configure Status in Status_before_length Format and enable header.
+ * PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR
+ */
mt9t112_mcu_write(ret, client, VAR(27, 144), 0x0CB4);
- /* Enable JPEG in context B */
- /* PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR */
+ /*
+ * Enable JPEG in context B.
+ * PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR
+ */
mt9t112_mcu_write(ret, client, VAR8(27, 142), 0x01);
- /* Disable Dac_TXLO */
+ /* Disable Dac_TXLO. */
mt9t112_reg_write(ret, client, 0x316C, 0x350F);
- /* Set max slew rates */
+ /* Set max slew rates. */
mt9t112_reg_write(ret, client, 0x1E, 0x777);
return ret;
}
/************************************************************************
- v4l2_subdev_core_ops
-************************************************************************/
+ * v4l2_subdev_core_ops
+ ***********************************************************************/
#ifdef CONFIG_VIDEO_ADV_DEBUG
static int mt9t112_g_register(struct v4l2_subdev *sd,
@@ -764,13 +744,40 @@ static int mt9t112_s_register(struct v4l2_subdev *sd,
}
#endif
+static int mt9t112_power_on(struct mt9t112_priv *priv)
+{
+ int ret;
+
+ ret = clk_prepare_enable(priv->clk);
+ if (ret)
+ return ret;
+
+ if (priv->standby_gpio) {
+ gpiod_set_value(priv->standby_gpio, 0);
+ msleep(100);
+ }
+
+ return 0;
+}
+
+static int mt9t112_power_off(struct mt9t112_priv *priv)
+{
+ clk_disable_unprepare(priv->clk);
+ if (priv->standby_gpio) {
+ gpiod_set_value(priv->standby_gpio, 1);
+ msleep(100);
+ }
+
+ return 0;
+}
+
static int mt9t112_s_power(struct v4l2_subdev *sd, int on)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
struct mt9t112_priv *priv = to_mt9t112(client);
- return soc_camera_set_power(&client->dev, ssdd, priv->clk, on);
+ return on ? mt9t112_power_on(priv) :
+ mt9t112_power_off(priv);
}
static const struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = {
@@ -781,10 +788,9 @@ static const struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = {
.s_power = mt9t112_s_power,
};
-
/************************************************************************
- v4l2_subdev_video_ops
-************************************************************************/
+ * v4l2_subdev_video_ops
+ **********************************************************************/
static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -794,8 +800,7 @@ static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable)
if (!enable) {
/* FIXME
*
- * If user selected large output size,
- * and used it long time,
+ * If user selected large output size, and used it long time,
* mt9t112 camera will be very warm.
*
* But current driver can not stop mt9t112 camera.
@@ -805,26 +810,25 @@ static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable)
return ret;
}
- if (!(priv->flags & INIT_DONE)) {
- u16 param = PCLK_RISING & priv->flags ? 0x0001 : 0x0000;
+ if (!priv->init_done) {
+ u16 param = MT9T112_FLAG_PCLK_RISING_EDGE & priv->info->flags ?
+ 0x0001 : 0x0000;
ECHECKER(ret, mt9t112_init_camera(client));
- /* Invert PCLK (Data sampled on falling edge of pixclk) */
+ /* Invert PCLK (Data sampled on falling edge of pixclk). */
mt9t112_reg_write(ret, client, 0x3C20, param);
mdelay(5);
- priv->flags |= INIT_DONE;
+ priv->init_done = true;
}
mt9t112_mcu_write(ret, client, VAR(26, 7), priv->format->fmt);
mt9t112_mcu_write(ret, client, VAR(26, 9), priv->format->order);
mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x06);
- mt9t112_set_a_frame_size(client,
- priv->frame.width,
- priv->frame.height);
+ mt9t112_set_a_frame_size(client, priv->frame.width, priv->frame.height);
ECHECKER(ret, mt9t112_auto_focus_trigger(client));
@@ -854,13 +858,13 @@ static int mt9t112_set_params(struct mt9t112_priv *priv,
if (i == priv->num_formats)
return -EINVAL;
- priv->frame = *rect;
+ priv->frame = *rect;
/*
* frame size check
*/
- mt9t112_frame_check(&priv->frame.width, &priv->frame.height,
- &priv->frame.left, &priv->frame.top);
+ v4l_bound_align_image(&priv->frame.width, 0, MAX_WIDTH, 0,
+ &priv->frame.height, 0, MAX_HEIGHT, 0, 0);
priv->format = mt9t112_cfmts + i;
@@ -868,7 +872,7 @@ static int mt9t112_set_params(struct mt9t112_priv *priv,
}
static int mt9t112_get_selection(struct v4l2_subdev *sd,
- struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_selection *sel)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -899,8 +903,8 @@ static int mt9t112_get_selection(struct v4l2_subdev *sd,
}
static int mt9t112_set_selection(struct v4l2_subdev *sd,
- struct v4l2_subdev_pad_config *cfg,
- struct v4l2_subdev_selection *sel)
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_selection *sel)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct mt9t112_priv *priv = to_mt9t112(client);
@@ -914,8 +918,8 @@ static int mt9t112_set_selection(struct v4l2_subdev *sd,
}
static int mt9t112_get_fmt(struct v4l2_subdev *sd,
- struct v4l2_subdev_pad_config *cfg,
- struct v4l2_subdev_format *format)
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_format *format)
{
struct v4l2_mbus_framefmt *mf = &format->format;
struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -955,13 +959,12 @@ static int mt9t112_s_fmt(struct v4l2_subdev *sd,
}
static int mt9t112_set_fmt(struct v4l2_subdev *sd,
- struct v4l2_subdev_pad_config *cfg,
- struct v4l2_subdev_format *format)
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_format *format)
{
- struct v4l2_mbus_framefmt *mf = &format->format;
struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct v4l2_mbus_framefmt *mf = &format->format;
struct mt9t112_priv *priv = to_mt9t112(client);
- unsigned int top, left;
int i;
if (format->pad)
@@ -975,22 +978,24 @@ static int mt9t112_set_fmt(struct v4l2_subdev *sd,
mf->code = MEDIA_BUS_FMT_UYVY8_2X8;
mf->colorspace = V4L2_COLORSPACE_JPEG;
} else {
- mf->colorspace = mt9t112_cfmts[i].colorspace;
+ mf->colorspace = mt9t112_cfmts[i].colorspace;
}
- mt9t112_frame_check(&mf->width, &mf->height, &left, &top);
+ v4l_bound_align_image(&mf->width, 0, MAX_WIDTH, 0,
+ &mf->height, 0, MAX_HEIGHT, 0, 0);
mf->field = V4L2_FIELD_NONE;
if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
return mt9t112_s_fmt(sd, mf);
cfg->try_fmt = *mf;
+
return 0;
}
static int mt9t112_enum_mbus_code(struct v4l2_subdev *sd,
- struct v4l2_subdev_pad_config *cfg,
- struct v4l2_subdev_mbus_code_enum *code)
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_mbus_code_enum *code)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct mt9t112_priv *priv = to_mt9t112(client);
@@ -1003,42 +1008,12 @@ static int mt9t112_enum_mbus_code(struct v4l2_subdev *sd,
return 0;
}
-static int mt9t112_g_mbus_config(struct v4l2_subdev *sd,
- struct v4l2_mbus_config *cfg)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
-
- cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
- V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH |
- V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING;
- cfg->type = V4L2_MBUS_PARALLEL;
- cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
-
- return 0;
-}
-
-static int mt9t112_s_mbus_config(struct v4l2_subdev *sd,
- const struct v4l2_mbus_config *cfg)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
- struct mt9t112_priv *priv = to_mt9t112(client);
-
- if (soc_camera_apply_board_flags(ssdd, cfg) & V4L2_MBUS_PCLK_SAMPLE_RISING)
- priv->flags |= PCLK_RISING;
-
- return 0;
-}
-
static const struct v4l2_subdev_video_ops mt9t112_subdev_video_ops = {
.s_stream = mt9t112_s_stream,
- .g_mbus_config = mt9t112_g_mbus_config,
- .s_mbus_config = mt9t112_s_mbus_config,
};
static const struct v4l2_subdev_pad_ops mt9t112_subdev_pad_ops = {
- .enum_mbus_code = mt9t112_enum_mbus_code,
+ .enum_mbus_code = mt9t112_enum_mbus_code,
.get_selection = mt9t112_get_selection,
.set_selection = mt9t112_set_selection,
.get_fmt = mt9t112_get_fmt,
@@ -1046,8 +1021,8 @@ static const struct v4l2_subdev_pad_ops mt9t112_subdev_pad_ops = {
};
/************************************************************************
- i2c driver
-************************************************************************/
+ * i2c driver
+ ***********************************************************************/
static const struct v4l2_subdev_ops mt9t112_subdev_ops = {
.core = &mt9t112_subdev_core_ops,
.video = &mt9t112_subdev_video_ops,
@@ -1065,9 +1040,7 @@ static int mt9t112_camera_probe(struct i2c_client *client)
if (ret < 0)
return ret;
- /*
- * check and show chip ID
- */
+ /* Check and show chip ID. */
mt9t112_reg_read(chipid, client, 0x0000);
switch (chipid) {
@@ -1089,6 +1062,7 @@ static int mt9t112_camera_probe(struct i2c_client *client)
done:
mt9t112_s_power(&priv->subdev, 0);
+
return ret;
}
@@ -1096,16 +1070,9 @@ static int mt9t112_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{
struct mt9t112_priv *priv;
- struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
- struct v4l2_rect rect = {
- .width = VGA_WIDTH,
- .height = VGA_HEIGHT,
- .left = (MAX_WIDTH - VGA_WIDTH) / 2,
- .top = (MAX_HEIGHT - VGA_HEIGHT) / 2,
- };
int ret;
- if (!ssdd || !ssdd->drv_priv) {
+ if (!client->dev.platform_data) {
dev_err(&client->dev, "mt9t112: missing platform data!\n");
return -EINVAL;
}
@@ -1114,30 +1081,40 @@ static int mt9t112_probe(struct i2c_client *client,
if (!priv)
return -ENOMEM;
- priv->info = ssdd->drv_priv;
+ priv->info = client->dev.platform_data;
+ priv->init_done = false;
v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
- priv->clk = v4l2_clk_get(&client->dev, "mclk");
- if (IS_ERR(priv->clk))
+ priv->clk = devm_clk_get(&client->dev, "extclk");
+ if (PTR_ERR(priv->clk) == -ENOENT) {
+ priv->clk = NULL;
+ } else if (IS_ERR(priv->clk)) {
+ dev_err(&client->dev, "Unable to get clock \"extclk\"\n");
return PTR_ERR(priv->clk);
+ }
- ret = mt9t112_camera_probe(client);
+ priv->standby_gpio = devm_gpiod_get_optional(&client->dev, "standby",
+ GPIOD_OUT_HIGH);
+ if (IS_ERR(priv->standby_gpio)) {
+ dev_err(&client->dev, "Unable to get gpio \"standby\"\n");
+ return PTR_ERR(priv->standby_gpio);
+ }
- /* Cannot fail: using the default supported pixel code */
- if (!ret)
- mt9t112_set_params(priv, &rect, MEDIA_BUS_FMT_UYVY8_2X8);
- else
- v4l2_clk_put(priv->clk);
+ ret = mt9t112_camera_probe(client);
+ if (ret)
+ return ret;
- return ret;
+ return v4l2_async_register_subdev(&priv->subdev);
}
static int mt9t112_remove(struct i2c_client *client)
{
struct mt9t112_priv *priv = to_mt9t112(client);
- v4l2_clk_put(priv->clk);
+ clk_disable_unprepare(priv->clk);
+ v4l2_async_unregister_subdev(&priv->subdev);
+
return 0;
}
@@ -1158,6 +1135,6 @@ static struct i2c_driver mt9t112_i2c_driver = {
module_i2c_driver(mt9t112_i2c_driver);
-MODULE_DESCRIPTION("SoC Camera driver for mt9t112");
+MODULE_DESCRIPTION("V4L2 driver for MT9T111/MT9T112 camera sensor");
MODULE_AUTHOR("Kuninori Morimoto");
MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/i2c/soc_camera/mt9t112.c b/drivers/media/i2c/soc_camera/mt9t112.c
index 297d22e..b53c36d 100644
--- a/drivers/media/i2c/soc_camera/mt9t112.c
+++ b/drivers/media/i2c/soc_camera/mt9t112.c
@@ -85,7 +85,7 @@ struct mt9t112_format {
struct mt9t112_priv {
struct v4l2_subdev subdev;
- struct mt9t112_camera_info *info;
+ struct mt9t112_platform_data *info;
struct i2c_client *client;
struct v4l2_rect frame;
struct v4l2_clk *clk;
diff --git a/include/media/i2c/mt9t112.h b/include/media/i2c/mt9t112.h
index a43c74a..cc80d5c 100644
--- a/include/media/i2c/mt9t112.h
+++ b/include/media/i2c/mt9t112.h
@@ -1,28 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
/* mt9t112 Camera
*
* Copyright (C) 2009 Renesas Solutions Corp.
* Kuninori Morimoto <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
*/
#ifndef __MT9T112_H__
#define __MT9T112_H__
-#define MT9T112_FLAG_PCLK_RISING_EDGE (1 << 0)
-#define MT9T112_FLAG_DATAWIDTH_8 (1 << 1) /* default width is 10 */
-
struct mt9t112_pll_divider {
u8 m, n;
u8 p1, p2, p3, p4, p5, p6, p7;
};
-/*
- * mt9t112 camera info
+/**
+ * mt9t112_platform_data - mt9t112 driver interface
+ * @flags: Sensor media bus configuration.
+ * @divider: Sensor PLL configuration
*/
-struct mt9t112_camera_info {
+struct mt9t112_platform_data {
+#define MT9T112_FLAG_PCLK_RISING_EDGE BIT(0)
u32 flags;
struct mt9t112_pll_divider divider;
};
--
2.7.4
Add entry for Aptina/Micron MT9T112 camera sensor. The driver is
maintained by me for "Odd Fixes" only due to lack of suitable hardware
for testing.
Signed-off-by: Jacopo Mondi <[email protected]>
---
MAINTAINERS | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 91ed6ad..ed95cad 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9385,6 +9385,14 @@ S: Maintained
F: drivers/media/i2c/mt9t001.c
F: include/media/i2c/mt9t001.h
+MT9T112 APTINA CAMERA SENSOR
+M: Jacopo Mondi <[email protected]>
+L: [email protected]
+T: git git://linuxtv.org/media_tree.git
+S: Odd Fixes
+F: drivers/media/i2c/mt9t112.c
+F: include/media/i2c/mt9t112.h
+
MT9V032 APTINA CAMERA SENSOR
M: Laurent Pinchart <[email protected]>
L: [email protected]
--
2.7.4
Hi Jacopo,
I wonder if it'd make sense to just make all the changes to the driver and
then have it reviewed; I'm not sure the old driver can be said to have been
in a known-good state that'd be useful to compare against. I think you did
that with another driver as well.
On Mon, Mar 12, 2018 at 02:43:02PM +0100, Jacopo Mondi wrote:
> Copy the soc_camera based driver in v4l2 sensor driver directory.
> This commit just copies the original file without modifying it.
> No modification to KConfig and Makefile as soc_camera framework
> dependencies need to be removed first in next commit.
>
> Signed-off-by: Jacopo Mondi <[email protected]>
> ---
> drivers/media/i2c/mt9t112.c | 1163 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 1163 insertions(+)
> create mode 100644 drivers/media/i2c/mt9t112.c
>
> diff --git a/drivers/media/i2c/mt9t112.c b/drivers/media/i2c/mt9t112.c
> new file mode 100644
> index 0000000..297d22e
> --- /dev/null
> +++ b/drivers/media/i2c/mt9t112.c
> @@ -0,0 +1,1163 @@
> +/*
> + * mt9t112 Camera Driver
> + *
> + * Copyright (C) 2009 Renesas Solutions Corp.
> + * Kuninori Morimoto <[email protected]>
> + *
> + * Based on ov772x driver, mt9m111 driver,
> + *
> + * Copyright (C) 2008 Kuninori Morimoto <[email protected]>
> + * Copyright (C) 2008, Robert Jarzmik <[email protected]>
> + * Copyright 2006-7 Jonathan Corbet <[email protected]>
> + * Copyright (C) 2008 Magnus Damm
> + * Copyright (C) 2008, Guennadi Liakhovetski <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#include <linux/delay.h>
> +#include <linux/i2c.h>
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/v4l2-mediabus.h>
> +#include <linux/videodev2.h>
> +
> +#include <media/i2c/mt9t112.h>
> +#include <media/soc_camera.h>
> +#include <media/v4l2-clk.h>
> +#include <media/v4l2-common.h>
> +#include <media/v4l2-image-sizes.h>
> +
> +/* you can check PLL/clock info */
> +/* #define EXT_CLOCK 24000000 */
> +
> +/************************************************************************
> + macro
> +************************************************************************/
> +/*
> + * frame size
> + */
> +#define MAX_WIDTH 2048
> +#define MAX_HEIGHT 1536
> +
> +/*
> + * macro of read/write
> + */
> +#define ECHECKER(ret, x) \
> + do { \
> + (ret) = (x); \
> + if ((ret) < 0) \
> + return (ret); \
I think the code would be easier to follow without macros like this one.
> + } while (0)
> +
> +#define mt9t112_reg_write(ret, client, a, b) \
> + ECHECKER(ret, __mt9t112_reg_write(client, a, b))
> +#define mt9t112_mcu_write(ret, client, a, b) \
> + ECHECKER(ret, __mt9t112_mcu_write(client, a, b))
> +
> +#define mt9t112_reg_mask_set(ret, client, a, b, c) \
> + ECHECKER(ret, __mt9t112_reg_mask_set(client, a, b, c))
> +#define mt9t112_mcu_mask_set(ret, client, a, b, c) \
> + ECHECKER(ret, __mt9t112_mcu_mask_set(client, a, b, c))
> +
> +#define mt9t112_reg_read(ret, client, a) \
> + ECHECKER(ret, __mt9t112_reg_read(client, a))
> +
> +/*
> + * Logical address
> + */
> +#define _VAR(id, offset, base) (base | (id & 0x1f) << 10 | (offset & 0x3ff))
> +#define VAR(id, offset) _VAR(id, offset, 0x0000)
> +#define VAR8(id, offset) _VAR(id, offset, 0x8000)
> +
> +/************************************************************************
> + struct
> +************************************************************************/
> +struct mt9t112_format {
> + u32 code;
> + enum v4l2_colorspace colorspace;
> + u16 fmt;
> + u16 order;
> +};
> +
> +struct mt9t112_priv {
> + struct v4l2_subdev subdev;
> + struct mt9t112_camera_info *info;
> + struct i2c_client *client;
> + struct v4l2_rect frame;
> + struct v4l2_clk *clk;
> + const struct mt9t112_format *format;
> + int num_formats;
> + u32 flags;
> +/* for flags */
> +#define INIT_DONE (1 << 0)
> +#define PCLK_RISING (1 << 1)
> +};
> +
> +/************************************************************************
> + supported format
> +************************************************************************/
> +
> +static const struct mt9t112_format mt9t112_cfmts[] = {
> + {
> + .code = MEDIA_BUS_FMT_UYVY8_2X8,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .fmt = 1,
> + .order = 0,
> + }, {
> + .code = MEDIA_BUS_FMT_VYUY8_2X8,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .fmt = 1,
> + .order = 1,
> + }, {
> + .code = MEDIA_BUS_FMT_YUYV8_2X8,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .fmt = 1,
> + .order = 2,
> + }, {
> + .code = MEDIA_BUS_FMT_YVYU8_2X8,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .fmt = 1,
> + .order = 3,
> + }, {
> + .code = MEDIA_BUS_FMT_RGB555_2X8_PADHI_LE,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .fmt = 8,
> + .order = 2,
> + }, {
> + .code = MEDIA_BUS_FMT_RGB565_2X8_LE,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .fmt = 4,
> + .order = 2,
> + },
> +};
> +
> +/************************************************************************
> + general function
> +************************************************************************/
> +static struct mt9t112_priv *to_mt9t112(const struct i2c_client *client)
> +{
> + return container_of(i2c_get_clientdata(client),
> + struct mt9t112_priv,
> + subdev);
> +}
> +
> +static int __mt9t112_reg_read(const struct i2c_client *client, u16 command)
> +{
> + struct i2c_msg msg[2];
> + u8 buf[2];
> + int ret;
> +
> + command = swab16(command);
> +
> + msg[0].addr = client->addr;
> + msg[0].flags = 0;
> + msg[0].len = 2;
> + msg[0].buf = (u8 *)&command;
> +
> + msg[1].addr = client->addr;
> + msg[1].flags = I2C_M_RD;
> + msg[1].len = 2;
> + msg[1].buf = buf;
> +
> + /*
> + * if return value of this function is < 0,
> + * it mean error.
> + * else, under 16bit is valid data.
> + */
> + ret = i2c_transfer(client->adapter, msg, 2);
> + if (ret < 0)
> + return ret;
> +
> + memcpy(&ret, buf, 2);
> + return swab16(ret);
> +}
> +
> +static int __mt9t112_reg_write(const struct i2c_client *client,
> + u16 command, u16 data)
> +{
> + struct i2c_msg msg;
> + u8 buf[4];
> + int ret;
> +
> + command = swab16(command);
> + data = swab16(data);
Ouch. This presumably works on little endian systems *only*. Same in the
above functions.
> +
> + memcpy(buf + 0, &command, 2);
> + memcpy(buf + 2, &data, 2);
Just use put_unaligned_be16(), that's all you need.
> +
> + msg.addr = client->addr;
> + msg.flags = 0;
> + msg.len = 4;
> + msg.buf = buf;
> +
> + /*
> + * i2c_transfer return message length,
> + * but this function should return 0 if correct case
> + */
> + ret = i2c_transfer(client->adapter, &msg, 1);
> + if (ret >= 0)
> + ret = 0;
> +
> + return ret;
> +}
> +
> +static int __mt9t112_reg_mask_set(const struct i2c_client *client,
> + u16 command,
> + u16 mask,
> + u16 set)
> +{
> + int val = __mt9t112_reg_read(client, command);
> + if (val < 0)
> + return val;
> +
> + val &= ~mask;
> + val |= set & mask;
> +
> + return __mt9t112_reg_write(client, command, val);
> +}
> +
> +/* mcu access */
> +static int __mt9t112_mcu_read(const struct i2c_client *client, u16 command)
> +{
> + int ret;
> +
> + ret = __mt9t112_reg_write(client, 0x098E, command);
> + if (ret < 0)
> + return ret;
> +
> + return __mt9t112_reg_read(client, 0x0990);
> +}
> +
> +static int __mt9t112_mcu_write(const struct i2c_client *client,
> + u16 command, u16 data)
> +{
> + int ret;
> +
> + ret = __mt9t112_reg_write(client, 0x098E, command);
> + if (ret < 0)
> + return ret;
> +
> + return __mt9t112_reg_write(client, 0x0990, data);
> +}
> +
> +static int __mt9t112_mcu_mask_set(const struct i2c_client *client,
> + u16 command,
> + u16 mask,
> + u16 set)
> +{
> + int val = __mt9t112_mcu_read(client, command);
> + if (val < 0)
> + return val;
> +
> + val &= ~mask;
> + val |= set & mask;
> +
> + return __mt9t112_mcu_write(client, command, val);
> +}
> +
> +static int mt9t112_reset(const struct i2c_client *client)
> +{
> + int ret;
> +
> + mt9t112_reg_mask_set(ret, client, 0x001a, 0x0001, 0x0001);
> + msleep(1);
> + mt9t112_reg_mask_set(ret, client, 0x001a, 0x0001, 0x0000);
> +
> + return ret;
> +}
> +
> +#ifndef EXT_CLOCK
> +#define CLOCK_INFO(a, b)
> +#else
> +#define CLOCK_INFO(a, b) mt9t112_clock_info(a, b)
> +static int mt9t112_clock_info(const struct i2c_client *client, u32 ext)
> +{
> + int m, n, p1, p2, p3, p4, p5, p6, p7;
> + u32 vco, clk;
> + char *enable;
> +
> + ext /= 1000; /* kbyte order */
> +
> + mt9t112_reg_read(n, client, 0x0012);
> + p1 = n & 0x000f;
> + n = n >> 4;
> + p2 = n & 0x000f;
> + n = n >> 4;
> + p3 = n & 0x000f;
> +
> + mt9t112_reg_read(n, client, 0x002a);
> + p4 = n & 0x000f;
> + n = n >> 4;
> + p5 = n & 0x000f;
> + n = n >> 4;
> + p6 = n & 0x000f;
> +
> + mt9t112_reg_read(n, client, 0x002c);
> + p7 = n & 0x000f;
> +
> + mt9t112_reg_read(n, client, 0x0010);
> + m = n & 0x00ff;
> + n = (n >> 8) & 0x003f;
> +
> + enable = ((6000 > ext) || (54000 < ext)) ? "X" : "";
> + dev_dbg(&client->dev, "EXTCLK : %10u K %s\n", ext, enable);
> +
> + vco = 2 * m * ext / (n+1);
> + enable = ((384000 > vco) || (768000 < vco)) ? "X" : "";
> + dev_dbg(&client->dev, "VCO : %10u K %s\n", vco, enable);
> +
> + clk = vco / (p1+1) / (p2+1);
> + enable = (96000 < clk) ? "X" : "";
> + dev_dbg(&client->dev, "PIXCLK : %10u K %s\n", clk, enable);
> +
> + clk = vco / (p3+1);
> + enable = (768000 < clk) ? "X" : "";
> + dev_dbg(&client->dev, "MIPICLK : %10u K %s\n", clk, enable);
> +
> + clk = vco / (p6+1);
> + enable = (96000 < clk) ? "X" : "";
> + dev_dbg(&client->dev, "MCU CLK : %10u K %s\n", clk, enable);
> +
> + clk = vco / (p5+1);
> + enable = (54000 < clk) ? "X" : "";
> + dev_dbg(&client->dev, "SOC CLK : %10u K %s\n", clk, enable);
> +
> + clk = vco / (p4+1);
> + enable = (70000 < clk) ? "X" : "";
> + dev_dbg(&client->dev, "Sensor CLK : %10u K %s\n", clk, enable);
> +
> + clk = vco / (p7+1);
> + dev_dbg(&client->dev, "External sensor : %10u K\n", clk);
> +
> + clk = ext / (n+1);
> + enable = ((2000 > clk) || (24000 < clk)) ? "X" : "";
> + dev_dbg(&client->dev, "PFD : %10u K %s\n", clk, enable);
> +
> + return 0;
> +}
> +#endif
> +
> +static void mt9t112_frame_check(u32 *width, u32 *height, u32 *left, u32 *top)
> +{
> + soc_camera_limit_side(left, width, 0, 0, MAX_WIDTH);
> + soc_camera_limit_side(top, height, 0, 0, MAX_HEIGHT);
> +}
> +
> +static int mt9t112_set_a_frame_size(const struct i2c_client *client,
> + u16 width,
> + u16 height)
> +{
> + int ret;
> + u16 wstart = (MAX_WIDTH - width) / 2;
> + u16 hstart = (MAX_HEIGHT - height) / 2;
> +
> + /* (Context A) Image Width/Height */
> + mt9t112_mcu_write(ret, client, VAR(26, 0), width);
> + mt9t112_mcu_write(ret, client, VAR(26, 2), height);
> +
> + /* (Context A) Output Width/Height */
> + mt9t112_mcu_write(ret, client, VAR(18, 43), 8 + width);
> + mt9t112_mcu_write(ret, client, VAR(18, 45), 8 + height);
> +
> + /* (Context A) Start Row/Column */
> + mt9t112_mcu_write(ret, client, VAR(18, 2), 4 + hstart);
> + mt9t112_mcu_write(ret, client, VAR(18, 4), 4 + wstart);
> +
> + /* (Context A) End Row/Column */
> + mt9t112_mcu_write(ret, client, VAR(18, 6), 11 + height + hstart);
> + mt9t112_mcu_write(ret, client, VAR(18, 8), 11 + width + wstart);
> +
> + mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x06);
> +
> + return ret;
> +}
> +
> +static int mt9t112_set_pll_dividers(const struct i2c_client *client,
> + u8 m, u8 n,
> + u8 p1, u8 p2, u8 p3,
> + u8 p4, u8 p5, u8 p6,
> + u8 p7)
> +{
> + int ret;
> + u16 val;
> +
> + /* N/M */
> + val = (n << 8) |
> + (m << 0);
> + mt9t112_reg_mask_set(ret, client, 0x0010, 0x3fff, val);
> +
> + /* P1/P2/P3 */
> + val = ((p3 & 0x0F) << 8) |
> + ((p2 & 0x0F) << 4) |
> + ((p1 & 0x0F) << 0);
> + mt9t112_reg_mask_set(ret, client, 0x0012, 0x0fff, val);
> +
> + /* P4/P5/P6 */
> + val = (0x7 << 12) |
> + ((p6 & 0x0F) << 8) |
> + ((p5 & 0x0F) << 4) |
> + ((p4 & 0x0F) << 0);
> + mt9t112_reg_mask_set(ret, client, 0x002A, 0x7fff, val);
> +
> + /* P7 */
> + val = (0x1 << 12) |
> + ((p7 & 0x0F) << 0);
> + mt9t112_reg_mask_set(ret, client, 0x002C, 0x100f, val);
> +
> + return ret;
> +}
> +
> +static int mt9t112_init_pll(const struct i2c_client *client)
> +{
> + struct mt9t112_priv *priv = to_mt9t112(client);
> + int data, i, ret;
> +
> + mt9t112_reg_mask_set(ret, client, 0x0014, 0x003, 0x0001);
> +
> + /* PLL control: BYPASS PLL = 8517 */
> + mt9t112_reg_write(ret, client, 0x0014, 0x2145);
> +
> + /* Replace these registers when new timing parameters are generated */
> + mt9t112_set_pll_dividers(client,
> + priv->info->divider.m,
> + priv->info->divider.n,
> + priv->info->divider.p1,
> + priv->info->divider.p2,
> + priv->info->divider.p3,
> + priv->info->divider.p4,
> + priv->info->divider.p5,
> + priv->info->divider.p6,
> + priv->info->divider.p7);
> +
> + /*
> + * TEST_BYPASS on
> + * PLL_ENABLE on
> + * SEL_LOCK_DET on
> + * TEST_BYPASS off
> + */
> + mt9t112_reg_write(ret, client, 0x0014, 0x2525);
> + mt9t112_reg_write(ret, client, 0x0014, 0x2527);
> + mt9t112_reg_write(ret, client, 0x0014, 0x3427);
> + mt9t112_reg_write(ret, client, 0x0014, 0x3027);
> +
> + mdelay(10);
> +
> + /*
> + * PLL_BYPASS off
> + * Reference clock count
> + * I2C Master Clock Divider
> + */
> + mt9t112_reg_write(ret, client, 0x0014, 0x3046);
> + mt9t112_reg_write(ret, client, 0x0016, 0x0400); /* JPEG initialization workaround */
> + mt9t112_reg_write(ret, client, 0x0022, 0x0190);
> + mt9t112_reg_write(ret, client, 0x3B84, 0x0212);
> +
> + /* External sensor clock is PLL bypass */
> + mt9t112_reg_write(ret, client, 0x002E, 0x0500);
> +
> + mt9t112_reg_mask_set(ret, client, 0x0018, 0x0002, 0x0002);
> + mt9t112_reg_mask_set(ret, client, 0x3B82, 0x0004, 0x0004);
> +
> + /* MCU disabled */
> + mt9t112_reg_mask_set(ret, client, 0x0018, 0x0004, 0x0004);
> +
> + /* out of standby */
> + mt9t112_reg_mask_set(ret, client, 0x0018, 0x0001, 0);
> +
> + mdelay(50);
> +
> + /*
> + * Standby Workaround
> + * Disable Secondary I2C Pads
> + */
> + mt9t112_reg_write(ret, client, 0x0614, 0x0001);
> + mdelay(1);
> + mt9t112_reg_write(ret, client, 0x0614, 0x0001);
> + mdelay(1);
> + mt9t112_reg_write(ret, client, 0x0614, 0x0001);
> + mdelay(1);
> + mt9t112_reg_write(ret, client, 0x0614, 0x0001);
> + mdelay(1);
> + mt9t112_reg_write(ret, client, 0x0614, 0x0001);
> + mdelay(1);
> + mt9t112_reg_write(ret, client, 0x0614, 0x0001);
> + mdelay(1);
> +
> + /* poll to verify out of standby. Must Poll this bit */
> + for (i = 0; i < 100; i++) {
> + mt9t112_reg_read(data, client, 0x0018);
> + if (!(0x4000 & data))
> + break;
> +
> + mdelay(10);
> + }
> +
> + return ret;
> +}
> +
> +static int mt9t112_init_setting(const struct i2c_client *client)
> +{
> +
> + int ret;
> +
> + /* Adaptive Output Clock (A) */
> + mt9t112_mcu_mask_set(ret, client, VAR(26, 160), 0x0040, 0x0000);
> +
> + /* Read Mode (A) */
> + mt9t112_mcu_write(ret, client, VAR(18, 12), 0x0024);
> +
> + /* Fine Correction (A) */
> + mt9t112_mcu_write(ret, client, VAR(18, 15), 0x00CC);
> +
> + /* Fine IT Min (A) */
> + mt9t112_mcu_write(ret, client, VAR(18, 17), 0x01f1);
> +
> + /* Fine IT Max Margin (A) */
> + mt9t112_mcu_write(ret, client, VAR(18, 19), 0x00fF);
> +
> + /* Base Frame Lines (A) */
> + mt9t112_mcu_write(ret, client, VAR(18, 29), 0x032D);
> +
> + /* Min Line Length (A) */
> + mt9t112_mcu_write(ret, client, VAR(18, 31), 0x073a);
> +
> + /* Line Length (A) */
> + mt9t112_mcu_write(ret, client, VAR(18, 37), 0x07d0);
> +
> + /* Adaptive Output Clock (B) */
> + mt9t112_mcu_mask_set(ret, client, VAR(27, 160), 0x0040, 0x0000);
> +
> + /* Row Start (B) */
> + mt9t112_mcu_write(ret, client, VAR(18, 74), 0x004);
> +
> + /* Column Start (B) */
> + mt9t112_mcu_write(ret, client, VAR(18, 76), 0x004);
> +
> + /* Row End (B) */
> + mt9t112_mcu_write(ret, client, VAR(18, 78), 0x60B);
> +
> + /* Column End (B) */
> + mt9t112_mcu_write(ret, client, VAR(18, 80), 0x80B);
> +
> + /* Fine Correction (B) */
> + mt9t112_mcu_write(ret, client, VAR(18, 87), 0x008C);
> +
> + /* Fine IT Min (B) */
> + mt9t112_mcu_write(ret, client, VAR(18, 89), 0x01F1);
> +
> + /* Fine IT Max Margin (B) */
> + mt9t112_mcu_write(ret, client, VAR(18, 91), 0x00FF);
> +
> + /* Base Frame Lines (B) */
> + mt9t112_mcu_write(ret, client, VAR(18, 101), 0x0668);
> +
> + /* Min Line Length (B) */
> + mt9t112_mcu_write(ret, client, VAR(18, 103), 0x0AF0);
> +
> + /* Line Length (B) */
> + mt9t112_mcu_write(ret, client, VAR(18, 109), 0x0AF0);
> +
> + /*
> + * Flicker Dectection registers
> + * This section should be replaced whenever new Timing file is generated
> + * All the following registers need to be replaced
> + * Following registers are generated from Register Wizard but user can
> + * modify them. For detail see auto flicker detection tuning
> + */
> +
> + /* FD_FDPERIOD_SELECT */
> + mt9t112_mcu_write(ret, client, VAR8(8, 5), 0x01);
> +
> + /* PRI_B_CONFIG_FD_ALGO_RUN */
> + mt9t112_mcu_write(ret, client, VAR(27, 17), 0x0003);
> +
> + /* PRI_A_CONFIG_FD_ALGO_RUN */
> + mt9t112_mcu_write(ret, client, VAR(26, 17), 0x0003);
> +
> + /*
> + * AFD range detection tuning registers
> + */
> +
> + /* search_f1_50 */
> + mt9t112_mcu_write(ret, client, VAR8(18, 165), 0x25);
> +
> + /* search_f2_50 */
> + mt9t112_mcu_write(ret, client, VAR8(18, 166), 0x28);
> +
> + /* search_f1_60 */
> + mt9t112_mcu_write(ret, client, VAR8(18, 167), 0x2C);
> +
> + /* search_f2_60 */
> + mt9t112_mcu_write(ret, client, VAR8(18, 168), 0x2F);
> +
> + /* period_50Hz (A) */
> + mt9t112_mcu_write(ret, client, VAR8(18, 68), 0xBA);
> +
> + /* secret register by aptina */
> + /* period_50Hz (A MSB) */
> + mt9t112_mcu_write(ret, client, VAR8(18, 303), 0x00);
> +
> + /* period_60Hz (A) */
> + mt9t112_mcu_write(ret, client, VAR8(18, 69), 0x9B);
> +
> + /* secret register by aptina */
> + /* period_60Hz (A MSB) */
> + mt9t112_mcu_write(ret, client, VAR8(18, 301), 0x00);
> +
> + /* period_50Hz (B) */
> + mt9t112_mcu_write(ret, client, VAR8(18, 140), 0x82);
> +
> + /* secret register by aptina */
> + /* period_50Hz (B) MSB */
> + mt9t112_mcu_write(ret, client, VAR8(18, 304), 0x00);
> +
> + /* period_60Hz (B) */
> + mt9t112_mcu_write(ret, client, VAR8(18, 141), 0x6D);
> +
> + /* secret register by aptina */
> + /* period_60Hz (B) MSB */
> + mt9t112_mcu_write(ret, client, VAR8(18, 302), 0x00);
> +
> + /* FD Mode */
> + mt9t112_mcu_write(ret, client, VAR8(8, 2), 0x10);
> +
> + /* Stat_min */
> + mt9t112_mcu_write(ret, client, VAR8(8, 9), 0x02);
> +
> + /* Stat_max */
> + mt9t112_mcu_write(ret, client, VAR8(8, 10), 0x03);
> +
> + /* Min_amplitude */
> + mt9t112_mcu_write(ret, client, VAR8(8, 12), 0x0A);
> +
> + /* RX FIFO Watermark (A) */
> + mt9t112_mcu_write(ret, client, VAR(18, 70), 0x0014);
> +
> + /* RX FIFO Watermark (B) */
> + mt9t112_mcu_write(ret, client, VAR(18, 142), 0x0014);
> +
> + /* MCLK: 16MHz
> + * PCLK: 73MHz
> + * CorePixCLK: 36.5 MHz
> + */
> + mt9t112_mcu_write(ret, client, VAR8(18, 0x0044), 133);
> + mt9t112_mcu_write(ret, client, VAR8(18, 0x0045), 110);
> + mt9t112_mcu_write(ret, client, VAR8(18, 0x008c), 130);
> + mt9t112_mcu_write(ret, client, VAR8(18, 0x008d), 108);
> +
> + mt9t112_mcu_write(ret, client, VAR8(18, 0x00A5), 27);
> + mt9t112_mcu_write(ret, client, VAR8(18, 0x00a6), 30);
> + mt9t112_mcu_write(ret, client, VAR8(18, 0x00a7), 32);
> + mt9t112_mcu_write(ret, client, VAR8(18, 0x00a8), 35);
> +
> + return ret;
> +}
> +
> +static int mt9t112_auto_focus_setting(const struct i2c_client *client)
> +{
> + int ret;
> +
> + mt9t112_mcu_write(ret, client, VAR(12, 13), 0x000F);
> + mt9t112_mcu_write(ret, client, VAR(12, 23), 0x0F0F);
> + mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x06);
> +
> + mt9t112_reg_write(ret, client, 0x0614, 0x0000);
> +
> + mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x05);
> + mt9t112_mcu_write(ret, client, VAR8(12, 2), 0x02);
> + mt9t112_mcu_write(ret, client, VAR(12, 3), 0x0002);
> + mt9t112_mcu_write(ret, client, VAR(17, 3), 0x8001);
> + mt9t112_mcu_write(ret, client, VAR(17, 11), 0x0025);
> + mt9t112_mcu_write(ret, client, VAR(17, 13), 0x0193);
> + mt9t112_mcu_write(ret, client, VAR8(17, 33), 0x18);
> + mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x05);
> +
> + return ret;
> +}
> +
> +static int mt9t112_auto_focus_trigger(const struct i2c_client *client)
> +{
> + int ret;
> +
> + mt9t112_mcu_write(ret, client, VAR8(12, 25), 0x01);
> +
> + return ret;
> +}
> +
> +static int mt9t112_init_camera(const struct i2c_client *client)
> +{
> + int ret;
> +
> + ECHECKER(ret, mt9t112_reset(client));
> +
> + ECHECKER(ret, mt9t112_init_pll(client));
> +
> + ECHECKER(ret, mt9t112_init_setting(client));
> +
> + ECHECKER(ret, mt9t112_auto_focus_setting(client));
> +
> + mt9t112_reg_mask_set(ret, client, 0x0018, 0x0004, 0);
> +
> + /* Analog setting B */
> + mt9t112_reg_write(ret, client, 0x3084, 0x2409);
> + mt9t112_reg_write(ret, client, 0x3092, 0x0A49);
> + mt9t112_reg_write(ret, client, 0x3094, 0x4949);
> + mt9t112_reg_write(ret, client, 0x3096, 0x4950);
> +
> + /*
> + * Disable adaptive clock
> + * PRI_A_CONFIG_JPEG_OB_TX_CONTROL_VAR
> + * PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR
> + */
> + mt9t112_mcu_write(ret, client, VAR(26, 160), 0x0A2E);
> + mt9t112_mcu_write(ret, client, VAR(27, 160), 0x0A2E);
> +
> + /* Configure STatus in Status_before_length Format and enable header */
> + /* PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR */
> + mt9t112_mcu_write(ret, client, VAR(27, 144), 0x0CB4);
> +
> + /* Enable JPEG in context B */
> + /* PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR */
> + mt9t112_mcu_write(ret, client, VAR8(27, 142), 0x01);
> +
> + /* Disable Dac_TXLO */
> + mt9t112_reg_write(ret, client, 0x316C, 0x350F);
> +
> + /* Set max slew rates */
> + mt9t112_reg_write(ret, client, 0x1E, 0x777);
> +
> + return ret;
> +}
> +
> +/************************************************************************
> + v4l2_subdev_core_ops
> +************************************************************************/
> +
> +#ifdef CONFIG_VIDEO_ADV_DEBUG
> +static int mt9t112_g_register(struct v4l2_subdev *sd,
> + struct v4l2_dbg_register *reg)
> +{
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> + int ret;
> +
> + reg->size = 2;
> + mt9t112_reg_read(ret, client, reg->reg);
> +
> + reg->val = (__u64)ret;
> +
> + return 0;
> +}
> +
> +static int mt9t112_s_register(struct v4l2_subdev *sd,
> + const struct v4l2_dbg_register *reg)
> +{
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> + int ret;
> +
> + mt9t112_reg_write(ret, client, reg->reg, reg->val);
> +
> + return ret;
> +}
> +#endif
> +
> +static int mt9t112_s_power(struct v4l2_subdev *sd, int on)
> +{
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> + struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
> + struct mt9t112_priv *priv = to_mt9t112(client);
> +
> + return soc_camera_set_power(&client->dev, ssdd, priv->clk, on);
> +}
> +
> +static const struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = {
> +#ifdef CONFIG_VIDEO_ADV_DEBUG
> + .g_register = mt9t112_g_register,
> + .s_register = mt9t112_s_register,
> +#endif
> + .s_power = mt9t112_s_power,
> +};
> +
> +
> +/************************************************************************
> + v4l2_subdev_video_ops
> +************************************************************************/
> +static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable)
> +{
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> + struct mt9t112_priv *priv = to_mt9t112(client);
> + int ret = 0;
> +
> + if (!enable) {
> + /* FIXME
> + *
> + * If user selected large output size,
> + * and used it long time,
> + * mt9t112 camera will be very warm.
> + *
> + * But current driver can not stop mt9t112 camera.
> + * So, set small size here to solve this problem.
> + */
> + mt9t112_set_a_frame_size(client, VGA_WIDTH, VGA_HEIGHT);
> + return ret;
> + }
> +
> + if (!(priv->flags & INIT_DONE)) {
> + u16 param = PCLK_RISING & priv->flags ? 0x0001 : 0x0000;
> +
> + ECHECKER(ret, mt9t112_init_camera(client));
Would it be possible to do this in power-on instead?
> +
> + /* Invert PCLK (Data sampled on falling edge of pixclk) */
> + mt9t112_reg_write(ret, client, 0x3C20, param);
This one as well, it's known at that time.
> +
> + mdelay(5);
> +
> + priv->flags |= INIT_DONE;
> + }
> +
> + mt9t112_mcu_write(ret, client, VAR(26, 7), priv->format->fmt);
> + mt9t112_mcu_write(ret, client, VAR(26, 9), priv->format->order);
> + mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x06);
> +
> + mt9t112_set_a_frame_size(client,
> + priv->frame.width,
> + priv->frame.height);
> +
> + ECHECKER(ret, mt9t112_auto_focus_trigger(client));
> +
> + dev_dbg(&client->dev, "format : %d\n", priv->format->code);
> + dev_dbg(&client->dev, "size : %d x %d\n",
> + priv->frame.width,
> + priv->frame.height);
> +
> + CLOCK_INFO(client, EXT_CLOCK);
> +
> + return ret;
> +}
> +
> +static int mt9t112_set_params(struct mt9t112_priv *priv,
> + const struct v4l2_rect *rect,
> + u32 code)
> +{
> + int i;
> +
> + /*
> + * get color format
> + */
> + for (i = 0; i < priv->num_formats; i++)
> + if (mt9t112_cfmts[i].code == code)
> + break;
> +
> + if (i == priv->num_formats)
> + return -EINVAL;
> +
> + priv->frame = *rect;
> +
> + /*
> + * frame size check
> + */
> + mt9t112_frame_check(&priv->frame.width, &priv->frame.height,
> + &priv->frame.left, &priv->frame.top);
> +
> + priv->format = mt9t112_cfmts + i;
> +
> + return 0;
> +}
> +
> +static int mt9t112_get_selection(struct v4l2_subdev *sd,
> + struct v4l2_subdev_pad_config *cfg,
> + struct v4l2_subdev_selection *sel)
> +{
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> + struct mt9t112_priv *priv = to_mt9t112(client);
> +
> + if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> + return -EINVAL;
> +
> + switch (sel->target) {
> + case V4L2_SEL_TGT_CROP_BOUNDS:
> + sel->r.left = 0;
> + sel->r.top = 0;
> + sel->r.width = MAX_WIDTH;
> + sel->r.height = MAX_HEIGHT;
> + return 0;
> + case V4L2_SEL_TGT_CROP_DEFAULT:
> + sel->r.left = 0;
> + sel->r.top = 0;
> + sel->r.width = VGA_WIDTH;
> + sel->r.height = VGA_HEIGHT;
> + return 0;
> + case V4L2_SEL_TGT_CROP:
> + sel->r = priv->frame;
> + return 0;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int mt9t112_set_selection(struct v4l2_subdev *sd,
> + struct v4l2_subdev_pad_config *cfg,
> + struct v4l2_subdev_selection *sel)
> +{
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> + struct mt9t112_priv *priv = to_mt9t112(client);
> + const struct v4l2_rect *rect = &sel->r;
> +
> + if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE ||
> + sel->target != V4L2_SEL_TGT_CROP)
> + return -EINVAL;
> +
> + return mt9t112_set_params(priv, rect, priv->format->code);
> +}
> +
> +static int mt9t112_get_fmt(struct v4l2_subdev *sd,
> + struct v4l2_subdev_pad_config *cfg,
> + struct v4l2_subdev_format *format)
> +{
> + struct v4l2_mbus_framefmt *mf = &format->format;
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> + struct mt9t112_priv *priv = to_mt9t112(client);
> +
> + if (format->pad)
> + return -EINVAL;
If there's just one pad, the check is redundant. (It's already present in
the subdev IOCTL handling.)
> +
> + mf->width = priv->frame.width;
> + mf->height = priv->frame.height;
> + mf->colorspace = priv->format->colorspace;
> + mf->code = priv->format->code;
> + mf->field = V4L2_FIELD_NONE;
> +
> + return 0;
> +}
> +
> +static int mt9t112_s_fmt(struct v4l2_subdev *sd,
> + struct v4l2_mbus_framefmt *mf)
> +{
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> + struct mt9t112_priv *priv = to_mt9t112(client);
> + struct v4l2_rect rect = {
> + .width = mf->width,
> + .height = mf->height,
> + .left = priv->frame.left,
> + .top = priv->frame.top,
> + };
> + int ret;
> +
> + ret = mt9t112_set_params(priv, &rect, mf->code);
> +
> + if (!ret)
> + mf->colorspace = priv->format->colorspace;
> +
> + return ret;
> +}
> +
> +static int mt9t112_set_fmt(struct v4l2_subdev *sd,
> + struct v4l2_subdev_pad_config *cfg,
> + struct v4l2_subdev_format *format)
> +{
> + struct v4l2_mbus_framefmt *mf = &format->format;
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> + struct mt9t112_priv *priv = to_mt9t112(client);
> + unsigned int top, left;
> + int i;
> +
> + if (format->pad)
> + return -EINVAL;
> +
> + for (i = 0; i < priv->num_formats; i++)
> + if (mt9t112_cfmts[i].code == mf->code)
> + break;
> +
> + if (i == priv->num_formats) {
> + mf->code = MEDIA_BUS_FMT_UYVY8_2X8;
> + mf->colorspace = V4L2_COLORSPACE_JPEG;
> + } else {
> + mf->colorspace = mt9t112_cfmts[i].colorspace;
> + }
> +
> + mt9t112_frame_check(&mf->width, &mf->height, &left, &top);
> +
> + mf->field = V4L2_FIELD_NONE;
> +
> + if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> + return mt9t112_s_fmt(sd, mf);
> + cfg->try_fmt = *mf;
> + return 0;
> +}
> +
> +static int mt9t112_enum_mbus_code(struct v4l2_subdev *sd,
> + struct v4l2_subdev_pad_config *cfg,
> + struct v4l2_subdev_mbus_code_enum *code)
> +{
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> + struct mt9t112_priv *priv = to_mt9t112(client);
> +
> + if (code->pad || code->index >= priv->num_formats)
> + return -EINVAL;
> +
> + code->code = mt9t112_cfmts[code->index].code;
> +
> + return 0;
> +}
> +
> +static int mt9t112_g_mbus_config(struct v4l2_subdev *sd,
> + struct v4l2_mbus_config *cfg)
> +{
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> + struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
> +
> + cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
> + V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH |
> + V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING;
> + cfg->type = V4L2_MBUS_PARALLEL;
> + cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
> +
> + return 0;
> +}
> +
> +static int mt9t112_s_mbus_config(struct v4l2_subdev *sd,
> + const struct v4l2_mbus_config *cfg)
> +{
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> + struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
> + struct mt9t112_priv *priv = to_mt9t112(client);
> +
> + if (soc_camera_apply_board_flags(ssdd, cfg) & V4L2_MBUS_PCLK_SAMPLE_RISING)
> + priv->flags |= PCLK_RISING;
> +
> + return 0;
> +}
Do you have a DT based system where you use this? Then I think it'd be
rather easy to get rid of the mbus config stuff.
> +
> +static const struct v4l2_subdev_video_ops mt9t112_subdev_video_ops = {
> + .s_stream = mt9t112_s_stream,
> + .g_mbus_config = mt9t112_g_mbus_config,
> + .s_mbus_config = mt9t112_s_mbus_config,
> +};
> +
> +static const struct v4l2_subdev_pad_ops mt9t112_subdev_pad_ops = {
> + .enum_mbus_code = mt9t112_enum_mbus_code,
> + .get_selection = mt9t112_get_selection,
> + .set_selection = mt9t112_set_selection,
> + .get_fmt = mt9t112_get_fmt,
> + .set_fmt = mt9t112_set_fmt,
> +};
> +
> +/************************************************************************
> + i2c driver
> +************************************************************************/
> +static const struct v4l2_subdev_ops mt9t112_subdev_ops = {
> + .core = &mt9t112_subdev_core_ops,
> + .video = &mt9t112_subdev_video_ops,
> + .pad = &mt9t112_subdev_pad_ops,
> +};
> +
> +static int mt9t112_camera_probe(struct i2c_client *client)
> +{
> + struct mt9t112_priv *priv = to_mt9t112(client);
> + const char *devname;
> + int chipid;
> + int ret;
> +
> + ret = mt9t112_s_power(&priv->subdev, 1);
> + if (ret < 0)
> + return ret;
> +
> + /*
> + * check and show chip ID
> + */
> + mt9t112_reg_read(chipid, client, 0x0000);
> +
> + switch (chipid) {
> + case 0x2680:
> + devname = "mt9t111";
> + priv->num_formats = 1;
> + break;
> + case 0x2682:
> + devname = "mt9t112";
> + priv->num_formats = ARRAY_SIZE(mt9t112_cfmts);
> + break;
> + default:
> + dev_err(&client->dev, "Product ID error %04x\n", chipid);
> + ret = -ENODEV;
> + goto done;
> + }
> +
> + dev_info(&client->dev, "%s chip ID %04x\n", devname, chipid);
> +
> +done:
> + mt9t112_s_power(&priv->subdev, 0);
> + return ret;
> +}
> +
> +static int mt9t112_probe(struct i2c_client *client,
> + const struct i2c_device_id *did)
> +{
> + struct mt9t112_priv *priv;
> + struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
> + struct v4l2_rect rect = {
> + .width = VGA_WIDTH,
> + .height = VGA_HEIGHT,
> + .left = (MAX_WIDTH - VGA_WIDTH) / 2,
> + .top = (MAX_HEIGHT - VGA_HEIGHT) / 2,
> + };
> + int ret;
> +
> + if (!ssdd || !ssdd->drv_priv) {
> + dev_err(&client->dev, "mt9t112: missing platform data!\n");
> + return -EINVAL;
> + }
> +
> + priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + priv->info = ssdd->drv_priv;
> +
> + v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
> +
> + priv->clk = v4l2_clk_get(&client->dev, "mclk");
> + if (IS_ERR(priv->clk))
> + return PTR_ERR(priv->clk);
> +
> + ret = mt9t112_camera_probe(client);
> +
> + /* Cannot fail: using the default supported pixel code */
> + if (!ret)
> + mt9t112_set_params(priv, &rect, MEDIA_BUS_FMT_UYVY8_2X8);
> + else
> + v4l2_clk_put(priv->clk);
> +
> + return ret;
> +}
> +
> +static int mt9t112_remove(struct i2c_client *client)
> +{
> + struct mt9t112_priv *priv = to_mt9t112(client);
> +
> + v4l2_clk_put(priv->clk);
> + return 0;
> +}
> +
> +static const struct i2c_device_id mt9t112_id[] = {
> + { "mt9t112", 0 },
> + { }
> +};
> +MODULE_DEVICE_TABLE(i2c, mt9t112_id);
> +
> +static struct i2c_driver mt9t112_i2c_driver = {
> + .driver = {
> + .name = "mt9t112",
> + },
> + .probe = mt9t112_probe,
If you need to support OF based systems only, you could use probe_new and
drop the i2c ID table.
> + .remove = mt9t112_remove,
> + .id_table = mt9t112_id,
> +};
> +
> +module_i2c_driver(mt9t112_i2c_driver);
> +
> +MODULE_DESCRIPTION("SoC Camera driver for mt9t112");
> +MODULE_AUTHOR("Kuninori Morimoto");
> +MODULE_LICENSE("GPL v2");
--
Kind regards,
Sakari Ailus
e-mail: [email protected]
Hi Sakari,
thanks for looking into this!
On Thu, Mar 15, 2018 at 01:35:34PM +0200, Sakari Ailus wrote:
> Hi Jacopo,
>
> I wonder if it'd make sense to just make all the changes to the driver and
> then have it reviewed; I'm not sure the old driver can be said to have been
> in a known-good state that'd be useful to compare against. I think you did
> that with another driver as well.
>
Well, I understand this is still debated, and I see your point.
As far as I can tell the driver had been developed to work with SH4
Ecovec boards and there tested.
I'm not sure I fully got you here though. Are you proposing to
squash my next patch that cleans up the driver into this one and
propose it as a completely new driver to be reviewed from scratch?
In the two previous driver I touched in this "remove soc_camera"
journey (ov772x and tw9910) I have followed this same pattern: copy
the soc_camera driver without removing the existing one, and pile on
top my changes/cleanups in another patch. Then port the board code to
use the new sensor driver, and the new CEU driver as well.
Also, how would you like to proceed here? Hans sent a pull request for
the series, should I go with incremental changes on top of this?
> On Mon, Mar 12, 2018 at 02:43:02PM +0100, Jacopo Mondi wrote:
> > Copy the soc_camera based driver in v4l2 sensor driver directory.
> > This commit just copies the original file without modifying it.
> > No modification to KConfig and Makefile as soc_camera framework
> > dependencies need to be removed first in next commit.
> >
> > Signed-off-by: Jacopo Mondi <[email protected]>
> > ---
> > drivers/media/i2c/mt9t112.c | 1163 +++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 1163 insertions(+)
> > create mode 100644 drivers/media/i2c/mt9t112.c
> >
> > diff --git a/drivers/media/i2c/mt9t112.c b/drivers/media/i2c/mt9t112.c
> > new file mode 100644
> > index 0000000..297d22e
> > --- /dev/null
> > +++ b/drivers/media/i2c/mt9t112.c
> > @@ -0,0 +1,1163 @@
> > +/*
> > + * mt9t112 Camera Driver
> > + *
> > + * Copyright (C) 2009 Renesas Solutions Corp.
> > + * Kuninori Morimoto <[email protected]>
> > + *
> > + * Based on ov772x driver, mt9m111 driver,
> > + *
> > + * Copyright (C) 2008 Kuninori Morimoto <[email protected]>
> > + * Copyright (C) 2008, Robert Jarzmik <[email protected]>
> > + * Copyright 2006-7 Jonathan Corbet <[email protected]>
> > + * Copyright (C) 2008 Magnus Damm
> > + * Copyright (C) 2008, Guennadi Liakhovetski <[email protected]>
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + */
> > +
> > +#include <linux/delay.h>
> > +#include <linux/i2c.h>
> > +#include <linux/init.h>
> > +#include <linux/module.h>
> > +#include <linux/slab.h>
> > +#include <linux/v4l2-mediabus.h>
> > +#include <linux/videodev2.h>
> > +
> > +#include <media/i2c/mt9t112.h>
> > +#include <media/soc_camera.h>
> > +#include <media/v4l2-clk.h>
> > +#include <media/v4l2-common.h>
> > +#include <media/v4l2-image-sizes.h>
> > +
> > +/* you can check PLL/clock info */
> > +/* #define EXT_CLOCK 24000000 */
> > +
> > +/************************************************************************
> > + macro
> > +************************************************************************/
> > +/*
> > + * frame size
> > + */
> > +#define MAX_WIDTH 2048
> > +#define MAX_HEIGHT 1536
> > +
> > +/*
> > + * macro of read/write
> > + */
> > +#define ECHECKER(ret, x) \
> > + do { \
> > + (ret) = (x); \
> > + if ((ret) < 0) \
> > + return (ret); \
>
> I think the code would be easier to follow without macros like this one.
>
Yes, I agree, but again, not my code and already in mainline, so I
felt uncomfortable chopping away pieces with an axe just because "I didn't
like it". But if we're going for a major review I can be a bit more
aggressive and address your comments.
> > + } while (0)
> > +
> > +#define mt9t112_reg_write(ret, client, a, b) \
> > + ECHECKER(ret, __mt9t112_reg_write(client, a, b))
> > +#define mt9t112_mcu_write(ret, client, a, b) \
> > + ECHECKER(ret, __mt9t112_mcu_write(client, a, b))
> > +
> > +#define mt9t112_reg_mask_set(ret, client, a, b, c) \
> > + ECHECKER(ret, __mt9t112_reg_mask_set(client, a, b, c))
> > +#define mt9t112_mcu_mask_set(ret, client, a, b, c) \
> > + ECHECKER(ret, __mt9t112_mcu_mask_set(client, a, b, c))
> > +
> > +#define mt9t112_reg_read(ret, client, a) \
> > + ECHECKER(ret, __mt9t112_reg_read(client, a))
> > +
> > +/*
> > + * Logical address
> > + */
> > +#define _VAR(id, offset, base) (base | (id & 0x1f) << 10 | (offset & 0x3ff))
> > +#define VAR(id, offset) _VAR(id, offset, 0x0000)
> > +#define VAR8(id, offset) _VAR(id, offset, 0x8000)
> > +
> > +/************************************************************************
> > + struct
> > +************************************************************************/
> > +struct mt9t112_format {
> > + u32 code;
> > + enum v4l2_colorspace colorspace;
> > + u16 fmt;
> > + u16 order;
> > +};
> > +
> > +struct mt9t112_priv {
> > + struct v4l2_subdev subdev;
> > + struct mt9t112_camera_info *info;
> > + struct i2c_client *client;
> > + struct v4l2_rect frame;
> > + struct v4l2_clk *clk;
> > + const struct mt9t112_format *format;
> > + int num_formats;
> > + u32 flags;
> > +/* for flags */
> > +#define INIT_DONE (1 << 0)
> > +#define PCLK_RISING (1 << 1)
> > +};
> > +
> > +/************************************************************************
> > + supported format
> > +************************************************************************/
> > +
> > +static const struct mt9t112_format mt9t112_cfmts[] = {
> > + {
> > + .code = MEDIA_BUS_FMT_UYVY8_2X8,
> > + .colorspace = V4L2_COLORSPACE_SRGB,
> > + .fmt = 1,
> > + .order = 0,
> > + }, {
> > + .code = MEDIA_BUS_FMT_VYUY8_2X8,
> > + .colorspace = V4L2_COLORSPACE_SRGB,
> > + .fmt = 1,
> > + .order = 1,
> > + }, {
> > + .code = MEDIA_BUS_FMT_YUYV8_2X8,
> > + .colorspace = V4L2_COLORSPACE_SRGB,
> > + .fmt = 1,
> > + .order = 2,
> > + }, {
> > + .code = MEDIA_BUS_FMT_YVYU8_2X8,
> > + .colorspace = V4L2_COLORSPACE_SRGB,
> > + .fmt = 1,
> > + .order = 3,
> > + }, {
> > + .code = MEDIA_BUS_FMT_RGB555_2X8_PADHI_LE,
> > + .colorspace = V4L2_COLORSPACE_SRGB,
> > + .fmt = 8,
> > + .order = 2,
> > + }, {
> > + .code = MEDIA_BUS_FMT_RGB565_2X8_LE,
> > + .colorspace = V4L2_COLORSPACE_SRGB,
> > + .fmt = 4,
> > + .order = 2,
> > + },
> > +};
> > +
> > +/************************************************************************
> > + general function
> > +************************************************************************/
> > +static struct mt9t112_priv *to_mt9t112(const struct i2c_client *client)
> > +{
> > + return container_of(i2c_get_clientdata(client),
> > + struct mt9t112_priv,
> > + subdev);
> > +}
> > +
> > +static int __mt9t112_reg_read(const struct i2c_client *client, u16 command)
> > +{
> > + struct i2c_msg msg[2];
> > + u8 buf[2];
> > + int ret;
> > +
> > + command = swab16(command);
> > +
> > + msg[0].addr = client->addr;
> > + msg[0].flags = 0;
> > + msg[0].len = 2;
> > + msg[0].buf = (u8 *)&command;
> > +
> > + msg[1].addr = client->addr;
> > + msg[1].flags = I2C_M_RD;
> > + msg[1].len = 2;
> > + msg[1].buf = buf;
> > +
> > + /*
> > + * if return value of this function is < 0,
> > + * it mean error.
> > + * else, under 16bit is valid data.
> > + */
> > + ret = i2c_transfer(client->adapter, msg, 2);
> > + if (ret < 0)
> > + return ret;
> > +
> > + memcpy(&ret, buf, 2);
> > + return swab16(ret);
> > +}
> > +
> > +static int __mt9t112_reg_write(const struct i2c_client *client,
> > + u16 command, u16 data)
> > +{
> > + struct i2c_msg msg;
> > + u8 buf[4];
> > + int ret;
> > +
> > + command = swab16(command);
> > + data = swab16(data);
>
> Ouch. This presumably works on little endian systems *only*. Same in the
> above functions.
cpu_to_be16() here and everywhere else?
>
> > +
> > + memcpy(buf + 0, &command, 2);
> > + memcpy(buf + 2, &data, 2);
>
> Just use put_unaligned_be16(), that's all you need.
>
> > +
> > + msg.addr = client->addr;
> > + msg.flags = 0;
> > + msg.len = 4;
> > + msg.buf = buf;
> > +
> > + /*
> > + * i2c_transfer return message length,
> > + * but this function should return 0 if correct case
> > + */
> > + ret = i2c_transfer(client->adapter, &msg, 1);
> > + if (ret >= 0)
> > + ret = 0;
> > +
> > + return ret;
> > +}
> > +
> > +static int __mt9t112_reg_mask_set(const struct i2c_client *client,
> > + u16 command,
> > + u16 mask,
> > + u16 set)
> > +{
> > + int val = __mt9t112_reg_read(client, command);
> > + if (val < 0)
> > + return val;
> > +
> > + val &= ~mask;
> > + val |= set & mask;
> > +
> > + return __mt9t112_reg_write(client, command, val);
> > +}
> > +
> > +/* mcu access */
> > +static int __mt9t112_mcu_read(const struct i2c_client *client, u16 command)
> > +{
> > + int ret;
> > +
> > + ret = __mt9t112_reg_write(client, 0x098E, command);
> > + if (ret < 0)
> > + return ret;
> > +
> > + return __mt9t112_reg_read(client, 0x0990);
> > +}
> > +
> > +static int __mt9t112_mcu_write(const struct i2c_client *client,
> > + u16 command, u16 data)
> > +{
> > + int ret;
> > +
> > + ret = __mt9t112_reg_write(client, 0x098E, command);
> > + if (ret < 0)
> > + return ret;
> > +
> > + return __mt9t112_reg_write(client, 0x0990, data);
> > +}
> > +
> > +static int __mt9t112_mcu_mask_set(const struct i2c_client *client,
> > + u16 command,
> > + u16 mask,
> > + u16 set)
> > +{
> > + int val = __mt9t112_mcu_read(client, command);
> > + if (val < 0)
> > + return val;
> > +
> > + val &= ~mask;
> > + val |= set & mask;
> > +
> > + return __mt9t112_mcu_write(client, command, val);
> > +}
> > +
> > +static int mt9t112_reset(const struct i2c_client *client)
> > +{
> > + int ret;
> > +
> > + mt9t112_reg_mask_set(ret, client, 0x001a, 0x0001, 0x0001);
> > + msleep(1);
> > + mt9t112_reg_mask_set(ret, client, 0x001a, 0x0001, 0x0000);
> > +
> > + return ret;
> > +}
> > +
> > +#ifndef EXT_CLOCK
> > +#define CLOCK_INFO(a, b)
> > +#else
> > +#define CLOCK_INFO(a, b) mt9t112_clock_info(a, b)
> > +static int mt9t112_clock_info(const struct i2c_client *client, u32 ext)
> > +{
> > + int m, n, p1, p2, p3, p4, p5, p6, p7;
> > + u32 vco, clk;
> > + char *enable;
> > +
> > + ext /= 1000; /* kbyte order */
> > +
> > + mt9t112_reg_read(n, client, 0x0012);
> > + p1 = n & 0x000f;
> > + n = n >> 4;
> > + p2 = n & 0x000f;
> > + n = n >> 4;
> > + p3 = n & 0x000f;
> > +
> > + mt9t112_reg_read(n, client, 0x002a);
> > + p4 = n & 0x000f;
> > + n = n >> 4;
> > + p5 = n & 0x000f;
> > + n = n >> 4;
> > + p6 = n & 0x000f;
> > +
> > + mt9t112_reg_read(n, client, 0x002c);
> > + p7 = n & 0x000f;
> > +
> > + mt9t112_reg_read(n, client, 0x0010);
> > + m = n & 0x00ff;
> > + n = (n >> 8) & 0x003f;
> > +
> > + enable = ((6000 > ext) || (54000 < ext)) ? "X" : "";
> > + dev_dbg(&client->dev, "EXTCLK : %10u K %s\n", ext, enable);
> > +
> > + vco = 2 * m * ext / (n+1);
> > + enable = ((384000 > vco) || (768000 < vco)) ? "X" : "";
> > + dev_dbg(&client->dev, "VCO : %10u K %s\n", vco, enable);
> > +
> > + clk = vco / (p1+1) / (p2+1);
> > + enable = (96000 < clk) ? "X" : "";
> > + dev_dbg(&client->dev, "PIXCLK : %10u K %s\n", clk, enable);
> > +
> > + clk = vco / (p3+1);
> > + enable = (768000 < clk) ? "X" : "";
> > + dev_dbg(&client->dev, "MIPICLK : %10u K %s\n", clk, enable);
> > +
> > + clk = vco / (p6+1);
> > + enable = (96000 < clk) ? "X" : "";
> > + dev_dbg(&client->dev, "MCU CLK : %10u K %s\n", clk, enable);
> > +
> > + clk = vco / (p5+1);
> > + enable = (54000 < clk) ? "X" : "";
> > + dev_dbg(&client->dev, "SOC CLK : %10u K %s\n", clk, enable);
> > +
> > + clk = vco / (p4+1);
> > + enable = (70000 < clk) ? "X" : "";
> > + dev_dbg(&client->dev, "Sensor CLK : %10u K %s\n", clk, enable);
> > +
> > + clk = vco / (p7+1);
> > + dev_dbg(&client->dev, "External sensor : %10u K\n", clk);
> > +
> > + clk = ext / (n+1);
> > + enable = ((2000 > clk) || (24000 < clk)) ? "X" : "";
> > + dev_dbg(&client->dev, "PFD : %10u K %s\n", clk, enable);
> > +
> > + return 0;
> > +}
> > +#endif
> > +
> > +static void mt9t112_frame_check(u32 *width, u32 *height, u32 *left, u32 *top)
> > +{
> > + soc_camera_limit_side(left, width, 0, 0, MAX_WIDTH);
> > + soc_camera_limit_side(top, height, 0, 0, MAX_HEIGHT);
> > +}
> > +
> > +static int mt9t112_set_a_frame_size(const struct i2c_client *client,
> > + u16 width,
> > + u16 height)
> > +{
> > + int ret;
> > + u16 wstart = (MAX_WIDTH - width) / 2;
> > + u16 hstart = (MAX_HEIGHT - height) / 2;
> > +
> > + /* (Context A) Image Width/Height */
> > + mt9t112_mcu_write(ret, client, VAR(26, 0), width);
> > + mt9t112_mcu_write(ret, client, VAR(26, 2), height);
> > +
> > + /* (Context A) Output Width/Height */
> > + mt9t112_mcu_write(ret, client, VAR(18, 43), 8 + width);
> > + mt9t112_mcu_write(ret, client, VAR(18, 45), 8 + height);
> > +
> > + /* (Context A) Start Row/Column */
> > + mt9t112_mcu_write(ret, client, VAR(18, 2), 4 + hstart);
> > + mt9t112_mcu_write(ret, client, VAR(18, 4), 4 + wstart);
> > +
> > + /* (Context A) End Row/Column */
> > + mt9t112_mcu_write(ret, client, VAR(18, 6), 11 + height + hstart);
> > + mt9t112_mcu_write(ret, client, VAR(18, 8), 11 + width + wstart);
> > +
> > + mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x06);
> > +
> > + return ret;
> > +}
> > +
> > +static int mt9t112_set_pll_dividers(const struct i2c_client *client,
> > + u8 m, u8 n,
> > + u8 p1, u8 p2, u8 p3,
> > + u8 p4, u8 p5, u8 p6,
> > + u8 p7)
> > +{
> > + int ret;
> > + u16 val;
> > +
> > + /* N/M */
> > + val = (n << 8) |
> > + (m << 0);
> > + mt9t112_reg_mask_set(ret, client, 0x0010, 0x3fff, val);
> > +
> > + /* P1/P2/P3 */
> > + val = ((p3 & 0x0F) << 8) |
> > + ((p2 & 0x0F) << 4) |
> > + ((p1 & 0x0F) << 0);
> > + mt9t112_reg_mask_set(ret, client, 0x0012, 0x0fff, val);
> > +
> > + /* P4/P5/P6 */
> > + val = (0x7 << 12) |
> > + ((p6 & 0x0F) << 8) |
> > + ((p5 & 0x0F) << 4) |
> > + ((p4 & 0x0F) << 0);
> > + mt9t112_reg_mask_set(ret, client, 0x002A, 0x7fff, val);
> > +
> > + /* P7 */
> > + val = (0x1 << 12) |
> > + ((p7 & 0x0F) << 0);
> > + mt9t112_reg_mask_set(ret, client, 0x002C, 0x100f, val);
> > +
> > + return ret;
> > +}
> > +
> > +static int mt9t112_init_pll(const struct i2c_client *client)
> > +{
> > + struct mt9t112_priv *priv = to_mt9t112(client);
> > + int data, i, ret;
> > +
> > + mt9t112_reg_mask_set(ret, client, 0x0014, 0x003, 0x0001);
> > +
> > + /* PLL control: BYPASS PLL = 8517 */
> > + mt9t112_reg_write(ret, client, 0x0014, 0x2145);
> > +
> > + /* Replace these registers when new timing parameters are generated */
> > + mt9t112_set_pll_dividers(client,
> > + priv->info->divider.m,
> > + priv->info->divider.n,
> > + priv->info->divider.p1,
> > + priv->info->divider.p2,
> > + priv->info->divider.p3,
> > + priv->info->divider.p4,
> > + priv->info->divider.p5,
> > + priv->info->divider.p6,
> > + priv->info->divider.p7);
> > +
> > + /*
> > + * TEST_BYPASS on
> > + * PLL_ENABLE on
> > + * SEL_LOCK_DET on
> > + * TEST_BYPASS off
> > + */
> > + mt9t112_reg_write(ret, client, 0x0014, 0x2525);
> > + mt9t112_reg_write(ret, client, 0x0014, 0x2527);
> > + mt9t112_reg_write(ret, client, 0x0014, 0x3427);
> > + mt9t112_reg_write(ret, client, 0x0014, 0x3027);
> > +
> > + mdelay(10);
> > +
> > + /*
> > + * PLL_BYPASS off
> > + * Reference clock count
> > + * I2C Master Clock Divider
> > + */
> > + mt9t112_reg_write(ret, client, 0x0014, 0x3046);
> > + mt9t112_reg_write(ret, client, 0x0016, 0x0400); /* JPEG initialization workaround */
> > + mt9t112_reg_write(ret, client, 0x0022, 0x0190);
> > + mt9t112_reg_write(ret, client, 0x3B84, 0x0212);
> > +
> > + /* External sensor clock is PLL bypass */
> > + mt9t112_reg_write(ret, client, 0x002E, 0x0500);
> > +
> > + mt9t112_reg_mask_set(ret, client, 0x0018, 0x0002, 0x0002);
> > + mt9t112_reg_mask_set(ret, client, 0x3B82, 0x0004, 0x0004);
> > +
> > + /* MCU disabled */
> > + mt9t112_reg_mask_set(ret, client, 0x0018, 0x0004, 0x0004);
> > +
> > + /* out of standby */
> > + mt9t112_reg_mask_set(ret, client, 0x0018, 0x0001, 0);
> > +
> > + mdelay(50);
> > +
> > + /*
> > + * Standby Workaround
> > + * Disable Secondary I2C Pads
> > + */
> > + mt9t112_reg_write(ret, client, 0x0614, 0x0001);
> > + mdelay(1);
> > + mt9t112_reg_write(ret, client, 0x0614, 0x0001);
> > + mdelay(1);
> > + mt9t112_reg_write(ret, client, 0x0614, 0x0001);
> > + mdelay(1);
> > + mt9t112_reg_write(ret, client, 0x0614, 0x0001);
> > + mdelay(1);
> > + mt9t112_reg_write(ret, client, 0x0614, 0x0001);
> > + mdelay(1);
> > + mt9t112_reg_write(ret, client, 0x0614, 0x0001);
> > + mdelay(1);
> > +
> > + /* poll to verify out of standby. Must Poll this bit */
> > + for (i = 0; i < 100; i++) {
> > + mt9t112_reg_read(data, client, 0x0018);
> > + if (!(0x4000 & data))
> > + break;
> > +
> > + mdelay(10);
> > + }
> > +
> > + return ret;
> > +}
> > +
> > +static int mt9t112_init_setting(const struct i2c_client *client)
> > +{
> > +
> > + int ret;
> > +
> > + /* Adaptive Output Clock (A) */
> > + mt9t112_mcu_mask_set(ret, client, VAR(26, 160), 0x0040, 0x0000);
> > +
> > + /* Read Mode (A) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 12), 0x0024);
> > +
> > + /* Fine Correction (A) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 15), 0x00CC);
> > +
> > + /* Fine IT Min (A) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 17), 0x01f1);
> > +
> > + /* Fine IT Max Margin (A) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 19), 0x00fF);
> > +
> > + /* Base Frame Lines (A) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 29), 0x032D);
> > +
> > + /* Min Line Length (A) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 31), 0x073a);
> > +
> > + /* Line Length (A) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 37), 0x07d0);
> > +
> > + /* Adaptive Output Clock (B) */
> > + mt9t112_mcu_mask_set(ret, client, VAR(27, 160), 0x0040, 0x0000);
> > +
> > + /* Row Start (B) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 74), 0x004);
> > +
> > + /* Column Start (B) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 76), 0x004);
> > +
> > + /* Row End (B) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 78), 0x60B);
> > +
> > + /* Column End (B) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 80), 0x80B);
> > +
> > + /* Fine Correction (B) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 87), 0x008C);
> > +
> > + /* Fine IT Min (B) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 89), 0x01F1);
> > +
> > + /* Fine IT Max Margin (B) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 91), 0x00FF);
> > +
> > + /* Base Frame Lines (B) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 101), 0x0668);
> > +
> > + /* Min Line Length (B) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 103), 0x0AF0);
> > +
> > + /* Line Length (B) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 109), 0x0AF0);
> > +
> > + /*
> > + * Flicker Dectection registers
> > + * This section should be replaced whenever new Timing file is generated
> > + * All the following registers need to be replaced
> > + * Following registers are generated from Register Wizard but user can
> > + * modify them. For detail see auto flicker detection tuning
> > + */
> > +
> > + /* FD_FDPERIOD_SELECT */
> > + mt9t112_mcu_write(ret, client, VAR8(8, 5), 0x01);
> > +
> > + /* PRI_B_CONFIG_FD_ALGO_RUN */
> > + mt9t112_mcu_write(ret, client, VAR(27, 17), 0x0003);
> > +
> > + /* PRI_A_CONFIG_FD_ALGO_RUN */
> > + mt9t112_mcu_write(ret, client, VAR(26, 17), 0x0003);
> > +
> > + /*
> > + * AFD range detection tuning registers
> > + */
> > +
> > + /* search_f1_50 */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 165), 0x25);
> > +
> > + /* search_f2_50 */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 166), 0x28);
> > +
> > + /* search_f1_60 */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 167), 0x2C);
> > +
> > + /* search_f2_60 */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 168), 0x2F);
> > +
> > + /* period_50Hz (A) */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 68), 0xBA);
> > +
> > + /* secret register by aptina */
> > + /* period_50Hz (A MSB) */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 303), 0x00);
> > +
> > + /* period_60Hz (A) */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 69), 0x9B);
> > +
> > + /* secret register by aptina */
> > + /* period_60Hz (A MSB) */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 301), 0x00);
> > +
> > + /* period_50Hz (B) */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 140), 0x82);
> > +
> > + /* secret register by aptina */
> > + /* period_50Hz (B) MSB */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 304), 0x00);
> > +
> > + /* period_60Hz (B) */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 141), 0x6D);
> > +
> > + /* secret register by aptina */
> > + /* period_60Hz (B) MSB */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 302), 0x00);
> > +
> > + /* FD Mode */
> > + mt9t112_mcu_write(ret, client, VAR8(8, 2), 0x10);
> > +
> > + /* Stat_min */
> > + mt9t112_mcu_write(ret, client, VAR8(8, 9), 0x02);
> > +
> > + /* Stat_max */
> > + mt9t112_mcu_write(ret, client, VAR8(8, 10), 0x03);
> > +
> > + /* Min_amplitude */
> > + mt9t112_mcu_write(ret, client, VAR8(8, 12), 0x0A);
> > +
> > + /* RX FIFO Watermark (A) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 70), 0x0014);
> > +
> > + /* RX FIFO Watermark (B) */
> > + mt9t112_mcu_write(ret, client, VAR(18, 142), 0x0014);
> > +
> > + /* MCLK: 16MHz
> > + * PCLK: 73MHz
> > + * CorePixCLK: 36.5 MHz
> > + */
> > + mt9t112_mcu_write(ret, client, VAR8(18, 0x0044), 133);
> > + mt9t112_mcu_write(ret, client, VAR8(18, 0x0045), 110);
> > + mt9t112_mcu_write(ret, client, VAR8(18, 0x008c), 130);
> > + mt9t112_mcu_write(ret, client, VAR8(18, 0x008d), 108);
> > +
> > + mt9t112_mcu_write(ret, client, VAR8(18, 0x00A5), 27);
> > + mt9t112_mcu_write(ret, client, VAR8(18, 0x00a6), 30);
> > + mt9t112_mcu_write(ret, client, VAR8(18, 0x00a7), 32);
> > + mt9t112_mcu_write(ret, client, VAR8(18, 0x00a8), 35);
> > +
> > + return ret;
> > +}
> > +
> > +static int mt9t112_auto_focus_setting(const struct i2c_client *client)
> > +{
> > + int ret;
> > +
> > + mt9t112_mcu_write(ret, client, VAR(12, 13), 0x000F);
> > + mt9t112_mcu_write(ret, client, VAR(12, 23), 0x0F0F);
> > + mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x06);
> > +
> > + mt9t112_reg_write(ret, client, 0x0614, 0x0000);
> > +
> > + mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x05);
> > + mt9t112_mcu_write(ret, client, VAR8(12, 2), 0x02);
> > + mt9t112_mcu_write(ret, client, VAR(12, 3), 0x0002);
> > + mt9t112_mcu_write(ret, client, VAR(17, 3), 0x8001);
> > + mt9t112_mcu_write(ret, client, VAR(17, 11), 0x0025);
> > + mt9t112_mcu_write(ret, client, VAR(17, 13), 0x0193);
> > + mt9t112_mcu_write(ret, client, VAR8(17, 33), 0x18);
> > + mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x05);
> > +
> > + return ret;
> > +}
> > +
> > +static int mt9t112_auto_focus_trigger(const struct i2c_client *client)
> > +{
> > + int ret;
> > +
> > + mt9t112_mcu_write(ret, client, VAR8(12, 25), 0x01);
> > +
> > + return ret;
> > +}
> > +
> > +static int mt9t112_init_camera(const struct i2c_client *client)
> > +{
> > + int ret;
> > +
> > + ECHECKER(ret, mt9t112_reset(client));
> > +
> > + ECHECKER(ret, mt9t112_init_pll(client));
> > +
> > + ECHECKER(ret, mt9t112_init_setting(client));
> > +
> > + ECHECKER(ret, mt9t112_auto_focus_setting(client));
> > +
> > + mt9t112_reg_mask_set(ret, client, 0x0018, 0x0004, 0);
> > +
> > + /* Analog setting B */
> > + mt9t112_reg_write(ret, client, 0x3084, 0x2409);
> > + mt9t112_reg_write(ret, client, 0x3092, 0x0A49);
> > + mt9t112_reg_write(ret, client, 0x3094, 0x4949);
> > + mt9t112_reg_write(ret, client, 0x3096, 0x4950);
> > +
> > + /*
> > + * Disable adaptive clock
> > + * PRI_A_CONFIG_JPEG_OB_TX_CONTROL_VAR
> > + * PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR
> > + */
> > + mt9t112_mcu_write(ret, client, VAR(26, 160), 0x0A2E);
> > + mt9t112_mcu_write(ret, client, VAR(27, 160), 0x0A2E);
> > +
> > + /* Configure STatus in Status_before_length Format and enable header */
> > + /* PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR */
> > + mt9t112_mcu_write(ret, client, VAR(27, 144), 0x0CB4);
> > +
> > + /* Enable JPEG in context B */
> > + /* PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR */
> > + mt9t112_mcu_write(ret, client, VAR8(27, 142), 0x01);
> > +
> > + /* Disable Dac_TXLO */
> > + mt9t112_reg_write(ret, client, 0x316C, 0x350F);
> > +
> > + /* Set max slew rates */
> > + mt9t112_reg_write(ret, client, 0x1E, 0x777);
> > +
> > + return ret;
> > +}
> > +
> > +/************************************************************************
> > + v4l2_subdev_core_ops
> > +************************************************************************/
> > +
> > +#ifdef CONFIG_VIDEO_ADV_DEBUG
> > +static int mt9t112_g_register(struct v4l2_subdev *sd,
> > + struct v4l2_dbg_register *reg)
> > +{
> > + struct i2c_client *client = v4l2_get_subdevdata(sd);
> > + int ret;
> > +
> > + reg->size = 2;
> > + mt9t112_reg_read(ret, client, reg->reg);
> > +
> > + reg->val = (__u64)ret;
> > +
> > + return 0;
> > +}
> > +
> > +static int mt9t112_s_register(struct v4l2_subdev *sd,
> > + const struct v4l2_dbg_register *reg)
> > +{
> > + struct i2c_client *client = v4l2_get_subdevdata(sd);
> > + int ret;
> > +
> > + mt9t112_reg_write(ret, client, reg->reg, reg->val);
> > +
> > + return ret;
> > +}
> > +#endif
> > +
> > +static int mt9t112_s_power(struct v4l2_subdev *sd, int on)
> > +{
> > + struct i2c_client *client = v4l2_get_subdevdata(sd);
> > + struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
> > + struct mt9t112_priv *priv = to_mt9t112(client);
> > +
> > + return soc_camera_set_power(&client->dev, ssdd, priv->clk, on);
> > +}
> > +
> > +static const struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = {
> > +#ifdef CONFIG_VIDEO_ADV_DEBUG
> > + .g_register = mt9t112_g_register,
> > + .s_register = mt9t112_s_register,
> > +#endif
> > + .s_power = mt9t112_s_power,
> > +};
> > +
> > +
> > +/************************************************************************
> > + v4l2_subdev_video_ops
> > +************************************************************************/
> > +static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable)
> > +{
> > + struct i2c_client *client = v4l2_get_subdevdata(sd);
> > + struct mt9t112_priv *priv = to_mt9t112(client);
> > + int ret = 0;
> > +
> > + if (!enable) {
> > + /* FIXME
> > + *
> > + * If user selected large output size,
> > + * and used it long time,
> > + * mt9t112 camera will be very warm.
> > + *
> > + * But current driver can not stop mt9t112 camera.
> > + * So, set small size here to solve this problem.
> > + */
> > + mt9t112_set_a_frame_size(client, VGA_WIDTH, VGA_HEIGHT);
> > + return ret;
> > + }
> > +
> > + if (!(priv->flags & INIT_DONE)) {
> > + u16 param = PCLK_RISING & priv->flags ? 0x0001 : 0x0000;
> > +
> > + ECHECKER(ret, mt9t112_init_camera(client));
>
> Would it be possible to do this in power-on instead?
>
I guess so, yes
> > +
> > + /* Invert PCLK (Data sampled on falling edge of pixclk) */
> > + mt9t112_reg_write(ret, client, 0x3C20, param);
>
> This one as well, it's known at that time.
yes, PCLK polarity comes from platform data (or eventually device
tree)
>
> > +
> > + mdelay(5);
> > +
> > + priv->flags |= INIT_DONE;
> > + }
> > +
> > + mt9t112_mcu_write(ret, client, VAR(26, 7), priv->format->fmt);
> > + mt9t112_mcu_write(ret, client, VAR(26, 9), priv->format->order);
> > + mt9t112_mcu_write(ret, client, VAR8(1, 0), 0x06);
> > +
> > + mt9t112_set_a_frame_size(client,
> > + priv->frame.width,
> > + priv->frame.height);
> > +
> > + ECHECKER(ret, mt9t112_auto_focus_trigger(client));
> > +
> > + dev_dbg(&client->dev, "format : %d\n", priv->format->code);
> > + dev_dbg(&client->dev, "size : %d x %d\n",
> > + priv->frame.width,
> > + priv->frame.height);
> > +
> > + CLOCK_INFO(client, EXT_CLOCK);
> > +
> > + return ret;
> > +}
> > +
> > +static int mt9t112_set_params(struct mt9t112_priv *priv,
> > + const struct v4l2_rect *rect,
> > + u32 code)
> > +{
> > + int i;
> > +
> > + /*
> > + * get color format
> > + */
> > + for (i = 0; i < priv->num_formats; i++)
> > + if (mt9t112_cfmts[i].code == code)
> > + break;
> > +
> > + if (i == priv->num_formats)
> > + return -EINVAL;
> > +
> > + priv->frame = *rect;
> > +
> > + /*
> > + * frame size check
> > + */
> > + mt9t112_frame_check(&priv->frame.width, &priv->frame.height,
> > + &priv->frame.left, &priv->frame.top);
> > +
> > + priv->format = mt9t112_cfmts + i;
> > +
> > + return 0;
> > +}
> > +
> > +static int mt9t112_get_selection(struct v4l2_subdev *sd,
> > + struct v4l2_subdev_pad_config *cfg,
> > + struct v4l2_subdev_selection *sel)
> > +{
> > + struct i2c_client *client = v4l2_get_subdevdata(sd);
> > + struct mt9t112_priv *priv = to_mt9t112(client);
> > +
> > + if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> > + return -EINVAL;
> > +
> > + switch (sel->target) {
> > + case V4L2_SEL_TGT_CROP_BOUNDS:
> > + sel->r.left = 0;
> > + sel->r.top = 0;
> > + sel->r.width = MAX_WIDTH;
> > + sel->r.height = MAX_HEIGHT;
> > + return 0;
> > + case V4L2_SEL_TGT_CROP_DEFAULT:
> > + sel->r.left = 0;
> > + sel->r.top = 0;
> > + sel->r.width = VGA_WIDTH;
> > + sel->r.height = VGA_HEIGHT;
> > + return 0;
> > + case V4L2_SEL_TGT_CROP:
> > + sel->r = priv->frame;
> > + return 0;
> > + default:
> > + return -EINVAL;
> > + }
> > +}
> > +
> > +static int mt9t112_set_selection(struct v4l2_subdev *sd,
> > + struct v4l2_subdev_pad_config *cfg,
> > + struct v4l2_subdev_selection *sel)
> > +{
> > + struct i2c_client *client = v4l2_get_subdevdata(sd);
> > + struct mt9t112_priv *priv = to_mt9t112(client);
> > + const struct v4l2_rect *rect = &sel->r;
> > +
> > + if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE ||
> > + sel->target != V4L2_SEL_TGT_CROP)
> > + return -EINVAL;
> > +
> > + return mt9t112_set_params(priv, rect, priv->format->code);
> > +}
> > +
> > +static int mt9t112_get_fmt(struct v4l2_subdev *sd,
> > + struct v4l2_subdev_pad_config *cfg,
> > + struct v4l2_subdev_format *format)
> > +{
> > + struct v4l2_mbus_framefmt *mf = &format->format;
> > + struct i2c_client *client = v4l2_get_subdevdata(sd);
> > + struct mt9t112_priv *priv = to_mt9t112(client);
> > +
> > + if (format->pad)
> > + return -EINVAL;
>
> If there's just one pad, the check is redundant. (It's already present in
> the subdev IOCTL handling.)
>
> > +
> > + mf->width = priv->frame.width;
> > + mf->height = priv->frame.height;
> > + mf->colorspace = priv->format->colorspace;
> > + mf->code = priv->format->code;
> > + mf->field = V4L2_FIELD_NONE;
> > +
> > + return 0;
> > +}
> > +
> > +static int mt9t112_s_fmt(struct v4l2_subdev *sd,
> > + struct v4l2_mbus_framefmt *mf)
> > +{
> > + struct i2c_client *client = v4l2_get_subdevdata(sd);
> > + struct mt9t112_priv *priv = to_mt9t112(client);
> > + struct v4l2_rect rect = {
> > + .width = mf->width,
> > + .height = mf->height,
> > + .left = priv->frame.left,
> > + .top = priv->frame.top,
> > + };
> > + int ret;
> > +
> > + ret = mt9t112_set_params(priv, &rect, mf->code);
> > +
> > + if (!ret)
> > + mf->colorspace = priv->format->colorspace;
> > +
> > + return ret;
> > +}
> > +
> > +static int mt9t112_set_fmt(struct v4l2_subdev *sd,
> > + struct v4l2_subdev_pad_config *cfg,
> > + struct v4l2_subdev_format *format)
> > +{
> > + struct v4l2_mbus_framefmt *mf = &format->format;
> > + struct i2c_client *client = v4l2_get_subdevdata(sd);
> > + struct mt9t112_priv *priv = to_mt9t112(client);
> > + unsigned int top, left;
> > + int i;
> > +
> > + if (format->pad)
> > + return -EINVAL;
> > +
> > + for (i = 0; i < priv->num_formats; i++)
> > + if (mt9t112_cfmts[i].code == mf->code)
> > + break;
> > +
> > + if (i == priv->num_formats) {
> > + mf->code = MEDIA_BUS_FMT_UYVY8_2X8;
> > + mf->colorspace = V4L2_COLORSPACE_JPEG;
> > + } else {
> > + mf->colorspace = mt9t112_cfmts[i].colorspace;
> > + }
> > +
> > + mt9t112_frame_check(&mf->width, &mf->height, &left, &top);
> > +
> > + mf->field = V4L2_FIELD_NONE;
> > +
> > + if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> > + return mt9t112_s_fmt(sd, mf);
> > + cfg->try_fmt = *mf;
> > + return 0;
> > +}
> > +
> > +static int mt9t112_enum_mbus_code(struct v4l2_subdev *sd,
> > + struct v4l2_subdev_pad_config *cfg,
> > + struct v4l2_subdev_mbus_code_enum *code)
> > +{
> > + struct i2c_client *client = v4l2_get_subdevdata(sd);
> > + struct mt9t112_priv *priv = to_mt9t112(client);
> > +
> > + if (code->pad || code->index >= priv->num_formats)
> > + return -EINVAL;
> > +
> > + code->code = mt9t112_cfmts[code->index].code;
> > +
> > + return 0;
> > +}
> > +
> > +static int mt9t112_g_mbus_config(struct v4l2_subdev *sd,
> > + struct v4l2_mbus_config *cfg)
> > +{
> > + struct i2c_client *client = v4l2_get_subdevdata(sd);
> > + struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
> > +
> > + cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
> > + V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH |
> > + V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING;
> > + cfg->type = V4L2_MBUS_PARALLEL;
> > + cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
> > +
> > + return 0;
> > +}
> > +
> > +static int mt9t112_s_mbus_config(struct v4l2_subdev *sd,
> > + const struct v4l2_mbus_config *cfg)
> > +{
> > + struct i2c_client *client = v4l2_get_subdevdata(sd);
> > + struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
> > + struct mt9t112_priv *priv = to_mt9t112(client);
> > +
> > + if (soc_camera_apply_board_flags(ssdd, cfg) & V4L2_MBUS_PCLK_SAMPLE_RISING)
> > + priv->flags |= PCLK_RISING;
> > +
> > + return 0;
> > +}
>
> Do you have a DT based system where you use this? Then I think it'd be
> rather easy to get rid of the mbus config stuff.
>
Please see my next patch where I get rid of s/g_mbus_config (and it
does not depend on DT support, which, as you can see, it's not here at
all)
> > +
> > +static const struct v4l2_subdev_video_ops mt9t112_subdev_video_ops = {
> > + .s_stream = mt9t112_s_stream,
> > + .g_mbus_config = mt9t112_g_mbus_config,
> > + .s_mbus_config = mt9t112_s_mbus_config,
> > +};
> > +
> > +static const struct v4l2_subdev_pad_ops mt9t112_subdev_pad_ops = {
> > + .enum_mbus_code = mt9t112_enum_mbus_code,
> > + .get_selection = mt9t112_get_selection,
> > + .set_selection = mt9t112_set_selection,
> > + .get_fmt = mt9t112_get_fmt,
> > + .set_fmt = mt9t112_set_fmt,
> > +};
> > +
> > +/************************************************************************
> > + i2c driver
> > +************************************************************************/
> > +static const struct v4l2_subdev_ops mt9t112_subdev_ops = {
> > + .core = &mt9t112_subdev_core_ops,
> > + .video = &mt9t112_subdev_video_ops,
> > + .pad = &mt9t112_subdev_pad_ops,
> > +};
> > +
> > +static int mt9t112_camera_probe(struct i2c_client *client)
> > +{
> > + struct mt9t112_priv *priv = to_mt9t112(client);
> > + const char *devname;
> > + int chipid;
> > + int ret;
> > +
> > + ret = mt9t112_s_power(&priv->subdev, 1);
> > + if (ret < 0)
> > + return ret;
> > +
> > + /*
> > + * check and show chip ID
> > + */
> > + mt9t112_reg_read(chipid, client, 0x0000);
> > +
> > + switch (chipid) {
> > + case 0x2680:
> > + devname = "mt9t111";
> > + priv->num_formats = 1;
> > + break;
> > + case 0x2682:
> > + devname = "mt9t112";
> > + priv->num_formats = ARRAY_SIZE(mt9t112_cfmts);
> > + break;
> > + default:
> > + dev_err(&client->dev, "Product ID error %04x\n", chipid);
> > + ret = -ENODEV;
> > + goto done;
> > + }
> > +
> > + dev_info(&client->dev, "%s chip ID %04x\n", devname, chipid);
> > +
> > +done:
> > + mt9t112_s_power(&priv->subdev, 0);
> > + return ret;
> > +}
> > +
> > +static int mt9t112_probe(struct i2c_client *client,
> > + const struct i2c_device_id *did)
> > +{
> > + struct mt9t112_priv *priv;
> > + struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
> > + struct v4l2_rect rect = {
> > + .width = VGA_WIDTH,
> > + .height = VGA_HEIGHT,
> > + .left = (MAX_WIDTH - VGA_WIDTH) / 2,
> > + .top = (MAX_HEIGHT - VGA_HEIGHT) / 2,
> > + };
> > + int ret;
> > +
> > + if (!ssdd || !ssdd->drv_priv) {
> > + dev_err(&client->dev, "mt9t112: missing platform data!\n");
> > + return -EINVAL;
> > + }
> > +
> > + priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
> > + if (!priv)
> > + return -ENOMEM;
> > +
> > + priv->info = ssdd->drv_priv;
> > +
> > + v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
> > +
> > + priv->clk = v4l2_clk_get(&client->dev, "mclk");
> > + if (IS_ERR(priv->clk))
> > + return PTR_ERR(priv->clk);
> > +
> > + ret = mt9t112_camera_probe(client);
> > +
> > + /* Cannot fail: using the default supported pixel code */
> > + if (!ret)
> > + mt9t112_set_params(priv, &rect, MEDIA_BUS_FMT_UYVY8_2X8);
> > + else
> > + v4l2_clk_put(priv->clk);
> > +
> > + return ret;
> > +}
> > +
> > +static int mt9t112_remove(struct i2c_client *client)
> > +{
> > + struct mt9t112_priv *priv = to_mt9t112(client);
> > +
> > + v4l2_clk_put(priv->clk);
> > + return 0;
> > +}
> > +
> > +static const struct i2c_device_id mt9t112_id[] = {
> > + { "mt9t112", 0 },
> > + { }
> > +};
> > +MODULE_DEVICE_TABLE(i2c, mt9t112_id);
> > +
> > +static struct i2c_driver mt9t112_i2c_driver = {
> > + .driver = {
> > + .name = "mt9t112",
> > + },
> > + .probe = mt9t112_probe,
>
> If you need to support OF based systems only, you could use probe_new and
> drop the i2c ID table.
Actually I currently need to support non-OF system only, as this
driver was only used by SH4 Ecovec.
As you know, I hope to be able to test this driver sooner or later on
an OF capable platform and add DT support to it, but for now,
we're stuck with board files support only.
Thanks
j
>
> > + .remove = mt9t112_remove,
> > + .id_table = mt9t112_id,
> > +};
> > +
> > +module_i2c_driver(mt9t112_i2c_driver);
> > +
> > +MODULE_DESCRIPTION("SoC Camera driver for mt9t112");
> > +MODULE_AUTHOR("Kuninori Morimoto");
> > +MODULE_LICENSE("GPL v2");
>
> --
> Kind regards,
>
> Sakari Ailus
> e-mail: [email protected]
On 03/15/2018 07:38 AM, jacopo mondi wrote:
> Hi Sakari,
> thanks for looking into this!
>
> On Thu, Mar 15, 2018 at 01:35:34PM +0200, Sakari Ailus wrote:
>> Hi Jacopo,
>>
>> I wonder if it'd make sense to just make all the changes to the driver and
>> then have it reviewed; I'm not sure the old driver can be said to have been
>> in a known-good state that'd be useful to compare against. I think you did
>> that with another driver as well.
>>
>
> Well, I understand this is still debated, and I see your point.
> As far as I can tell the driver had been developed to work with SH4
> Ecovec boards and there tested.
>
> I'm not sure I fully got you here though. Are you proposing to
> squash my next patch that cleans up the driver into this one and
> propose it as a completely new driver to be reviewed from scratch?
>
> In the two previous driver I touched in this "remove soc_camera"
> journey (ov772x and tw9910) I have followed this same pattern: copy
> the soc_camera driver without removing the existing one, and pile on
> top my changes/cleanups in another patch. Then port the board code to
> use the new sensor driver, and the new CEU driver as well.
>
> Also, how would you like to proceed here? Hans sent a pull request for
> the series, should I go with incremental changes on top of this?
I don't want to postpone this conversion. The i2c/mt9t112.c is bug-compatible
with i2c/soc-camera/mt9t112.c which is good enough for me. Being able to
remove soc-camera in the (hopefully very) near future is the most important
thing here.
Once Jacopo can actually test the sensor, then that's a good time to review
the driver in more detail.
This reminded me that I actually started testing this sensor a year
ago (I bought the same sensor on ebay, I completely forgot about that!).
My attempt is here:
https://git.linuxtv.org/hverkuil/media_tree.git/log/?h=mt9t112
I never finished it because I had no documentation on the pinout and never
got around to hooking my oscilloscope up to it to figure this out. I was
testing this with the atmel-isc.c driver.
This might be of some use to you, Jacopo, once you have the sensor.
Regards,
Hans
Hi Hans,
On Thu, Mar 15, 2018 at 08:30:21AM -0700, Hans Verkuil wrote:
> On 03/15/2018 07:38 AM, jacopo mondi wrote:
> > Hi Sakari,
> > thanks for looking into this!
> >
> > On Thu, Mar 15, 2018 at 01:35:34PM +0200, Sakari Ailus wrote:
> >> Hi Jacopo,
> >>
> >> I wonder if it'd make sense to just make all the changes to the driver and
> >> then have it reviewed; I'm not sure the old driver can be said to have been
> >> in a known-good state that'd be useful to compare against. I think you did
> >> that with another driver as well.
> >>
> >
> > Well, I understand this is still debated, and I see your point.
> > As far as I can tell the driver had been developed to work with SH4
> > Ecovec boards and there tested.
> >
> > I'm not sure I fully got you here though. Are you proposing to
> > squash my next patch that cleans up the driver into this one and
> > propose it as a completely new driver to be reviewed from scratch?
> >
> > In the two previous driver I touched in this "remove soc_camera"
> > journey (ov772x and tw9910) I have followed this same pattern: copy
> > the soc_camera driver without removing the existing one, and pile on
> > top my changes/cleanups in another patch. Then port the board code to
> > use the new sensor driver, and the new CEU driver as well.
> >
> > Also, how would you like to proceed here? Hans sent a pull request for
> > the series, should I go with incremental changes on top of this?
>
> I don't want to postpone this conversion. The i2c/mt9t112.c is bug-compatible
> with i2c/soc-camera/mt9t112.c which is good enough for me. Being able to
> remove soc-camera in the (hopefully very) near future is the most important
> thing here.
>
> Once Jacopo can actually test the sensor, then that's a good time to review
> the driver in more detail.
>
> This reminded me that I actually started testing this sensor a year
> ago (I bought the same sensor on ebay, I completely forgot about that!).
>
> My attempt is here:
>
> https://git.linuxtv.org/hverkuil/media_tree.git/log/?h=mt9t112
>
> I never finished it because I had no documentation on the pinout and never
> got around to hooking my oscilloscope up to it to figure this out. I was
> testing this with the atmel-isc.c driver.
>
> This might be of some use to you, Jacopo, once you have the sensor.
Thanks for the info. I'll see what I can do. I don't have register
level document, and if the module is the same you have neither a
pinout description. This is going to be fun :/
I'll then refrain from sending more patches for this series/driver
until we cannot actually test the sensor, fixes apart, if any, of course.
Thanks
j
>
> Regards,
>
> Hans