* [PATCH 18/27] ARM: shmobile: armadillo800eva: enable camera
@ 2012-06-11 3:57 Kuninori Morimoto
2012-06-11 4:35 ` Paul Mundt
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Kuninori Morimoto @ 2012-06-11 3:57 UTC (permalink / raw)
To: linux-sh
This patch enable camera support on CON1
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
arch/arm/configs/armadillo800eva_defconfig | 10 ++
arch/arm/mach-shmobile/board-armadillo800eva.c | 114 +++++++++++++++++++++++-
2 files changed, 123 insertions(+), 1 deletions(-)
diff --git a/arch/arm/configs/armadillo800eva_defconfig b/arch/arm/configs/armadillo800eva_defconfig
index f6ebdde..df1ce54 100644
--- a/arch/arm/configs/armadillo800eva_defconfig
+++ b/arch/arm/configs/armadillo800eva_defconfig
@@ -86,6 +86,16 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
CONFIG_I2C=y
CONFIG_I2C_SH_MOBILE=y
# CONFIG_HWMON is not set
+CONFIG_MEDIA_SUPPORT=y
+CONFIG_VIDEO_DEV=y
+# CONFIG_RC_CORE is not set
+# CONFIG_VIDEO_HELPER_CHIPS_AUTO is not set
+# CONFIG_V4L_USB_DRIVERS is not set
+CONFIG_V4L_PLATFORM_DRIVERS=y
+CONFIG_SOC_CAMERA=y
+CONFIG_SOC_CAMERA_MT9T112=y
+CONFIG_VIDEO_SH_MOBILE_CEU=y
+# CONFIG_RADIO_ADAPTERS is not set
CONFIG_FB=y
CONFIG_FB_SH_MOBILE_LCDC=y
CONFIG_FB_SH_MOBILE_HDMI=y
diff --git a/arch/arm/mach-shmobile/board-armadillo800eva.c b/arch/arm/mach-shmobile/board-armadillo800eva.c
index 4e6893f..d2d87d9 100644
--- a/arch/arm/mach-shmobile/board-armadillo800eva.c
+++ b/arch/arm/mach-shmobile/board-armadillo800eva.c
@@ -37,13 +37,16 @@
#include <linux/mmc/sh_mobile_sdhi.h>
#include <mach/common.h>
#include <mach/irqs.h>
+#include <mach/r8a7740.h>
+#include <media/mt9t112.h>
+#include <media/sh_mobile_ceu.h>
+#include <media/soc_camera.h>
#include <asm/page.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include <asm/mach/map.h>
#include <asm/mach/time.h>
#include <asm/hardware/cache-l2x0.h>
-#include <mach/r8a7740.h>
#include <video/sh_mobile_lcdc.h>
#include <video/sh_mobile_hdmi.h>
@@ -630,6 +633,80 @@ static struct platform_device sh_mmcif_device = {
.resource = sh_mmcif_resources,
};
+/* Camera */
+static struct clk *cam1_mclk; /* initialized on eva_clock_init() */
+static int mt9t111_power(struct device *dev, int mode)
+{
+ if (!cam1_mclk)
+ return -EINVAL;
+
+ if (mode) {
+ gpio_direction_output(GPIO_PORT158, 1);
+ clk_enable(cam1_mclk);
+ } else {
+ gpio_direction_output(GPIO_PORT158, 0);
+ clk_disable(cam1_mclk);
+ }
+
+ return 0;
+}
+
+static struct i2c_board_info i2c_camera_mt9t111 = {
+ I2C_BOARD_INFO("mt9t112", 0x3d),
+};
+
+static struct mt9t112_camera_info mt9t111_info = {
+ .divider = { 16, 0, 0, 7, 0, 10, 14, 7, 7 },
+};
+
+static struct soc_camera_link mt9t111_link = {
+ .i2c_adapter_id = 0,
+ .bus_id = 0,
+ .board_info = &i2c_camera_mt9t111,
+ .power = mt9t111_power,
+ .priv = &mt9t111_info,
+};
+
+static struct platform_device camera_device = {
+ .name = "soc-camera-pdrv",
+ .id = 0,
+ .dev = {
+ .platform_data = &mt9t111_link,
+ },
+};
+
+/* CEU0 */
+static struct sh_mobile_ceu_info sh_mobile_ceu0_info = {
+ .flags = SH_CEU_FLAG_LOWER_8BIT,
+};
+
+static struct resource ceu0_resources[] = {
+ [0] = {
+ .name = "CEU",
+ .start = 0xfe910000,
+ .end = 0xfe91009f,
+ .flags = IORESOURCE_MEM,
+ },
+ [1] = {
+ .start = intcs_evt2irq(0x0500),
+ .flags = IORESOURCE_IRQ,
+ },
+ [2] = {
+ /* place holder for contiguous memory */
+ },
+};
+
+static struct platform_device ceu0_device = {
+ .name = "sh_mobile_ceu",
+ .id = 0,
+ .num_resources = ARRAY_SIZE(ceu0_resources),
+ .resource = ceu0_resources,
+ .dev = {
+ .platform_data = &sh_mobile_ceu0_info,
+ .coherent_dma_mask = 0xffffffff,
+ },
+};
+
/* I2C */
static struct i2c_board_info i2c0_devices[] = {
{
@@ -649,6 +726,8 @@ static struct platform_device *eva_devices[] __initdata = {
&sh_mmcif_device,
&hdmi_device,
&hdmi_lcdc_device,
+ &camera_device,
+ &ceu0_device,
};
static void __init eva_clock_init(void)
@@ -664,12 +743,21 @@ static void __init eva_clock_init(void)
goto clock_error;
}
+ cam1_mclk = clk_get(NULL, "video1");
+ if (IS_ERR(cam1_mclk)) {
+ cam1_mclk = NULL;
+ goto clock_error;
+ }
+
/* armadillo 800 eva extal1 is 24MHz */
clk_set_rate(xtal1, 24000000);
/* usb24s use extal1 (= system) clock (= 24MHz) */
clk_set_parent(usb24s, system);
+ /* video1 (= CON1 camera) expect 24MHz */
+ clk_set_rate(cam1_mclk, clk_round_rate(cam1_mclk, 24000000));
+
clock_error:
if (!IS_ERR(system))
clk_put(system);
@@ -807,6 +895,30 @@ static void __init eva_init(void)
gpio_request(GPIO_FN_MMC1_D6_PORT143, NULL);
gpio_request(GPIO_FN_MMC1_D7_PORT142, NULL);
+ /* CEU0 */
+ gpio_request(GPIO_FN_VIO0_D7, NULL);
+ gpio_request(GPIO_FN_VIO0_D6, NULL);
+ gpio_request(GPIO_FN_VIO0_D5, NULL);
+ gpio_request(GPIO_FN_VIO0_D4, NULL);
+ gpio_request(GPIO_FN_VIO0_D3, NULL);
+ gpio_request(GPIO_FN_VIO0_D2, NULL);
+ gpio_request(GPIO_FN_VIO0_D1, NULL);
+ gpio_request(GPIO_FN_VIO0_D0, NULL);
+ gpio_request(GPIO_FN_VIO0_CLK, NULL);
+ gpio_request(GPIO_FN_VIO0_HD, NULL);
+ gpio_request(GPIO_FN_VIO0_VD, NULL);
+ gpio_request(GPIO_FN_VIO0_FIELD, NULL);
+ gpio_request(GPIO_FN_VIO_CKO, NULL);
+
+ /* CON1/CON15 Camera */
+ gpio_request(GPIO_PORT173, NULL); /* STANDBY */
+ gpio_request(GPIO_PORT172, NULL); /* RST */
+ gpio_direction_output(GPIO_PORT173, 0);
+ gpio_direction_output(GPIO_PORT172, 1);
+
+ gpio_request(GPIO_PORT158, NULL); /* CAM_PON */
+ gpio_direction_output(GPIO_PORT158, 0); /* see mt9t111_power() */
+
/*
* CAUTION
*
--
1.7.5.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 18/27] ARM: shmobile: armadillo800eva: enable camera
2012-06-11 3:57 [PATCH 18/27] ARM: shmobile: armadillo800eva: enable camera Kuninori Morimoto
@ 2012-06-11 4:35 ` Paul Mundt
2012-06-11 9:07 ` Simon Horman
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Paul Mundt @ 2012-06-11 4:35 UTC (permalink / raw)
To: linux-sh
On Sun, Jun 10, 2012 at 08:57:10PM -0700, Kuninori Morimoto wrote:
> @@ -630,6 +633,80 @@ static struct platform_device sh_mmcif_device = {
> .resource = sh_mmcif_resources,
> };
>
> +/* Camera */
> +static struct clk *cam1_mclk; /* initialized on eva_clock_init() */
> +static int mt9t111_power(struct device *dev, int mode)
> +{
> + if (!cam1_mclk)
> + return -EINVAL;
> +
This isn't necessary, clk_enable/disable() can handle being passed NULL
just fine. If you've gotten control of the GPIO then you can still do
meaningful work regardless of whether you have acquired the clock or not.
> + cam1_mclk = clk_get(NULL, "video1");
> + if (IS_ERR(cam1_mclk)) {
> + cam1_mclk = NULL;
> + goto clock_error;
> + }
> +
On the other hand, I don't see why you don't do this in the ->power
routine directly, where you already have a struct device passed in for
you.
> /* armadillo 800 eva extal1 is 24MHz */
> clk_set_rate(xtal1, 24000000);
>
> /* usb24s use extal1 (= system) clock (= 24MHz) */
> clk_set_parent(usb24s, system);
>
> + /* video1 (= CON1 camera) expect 24MHz */
> + clk_set_rate(cam1_mclk, clk_round_rate(cam1_mclk, 24000000));
> +
> clock_error:
> if (!IS_ERR(system))
> clk_put(system);
This error path makes absolutely no sense. If you fail to get the camera
clock for some reason you skip over xtal and usb24s initialization?
Without the xtal rate propagation pretty much every other clock in the
system is going to be broken.
This is a good indicator that this routine is getting too big and you
need to start splitting things out in to smaller initialization
subroutines that you can conditionalize.
> + /* CON1/CON15 Camera */
> + gpio_request(GPIO_PORT173, NULL); /* STANDBY */
> + gpio_request(GPIO_PORT172, NULL); /* RST */
gpio_request() can return error, and you should not be calling in to
gpio_direction_output() on a pin you have no idea if you own or not.
> + gpio_direction_output(GPIO_PORT173, 0);
> + gpio_direction_output(GPIO_PORT172, 1);
> +
> + gpio_request(GPIO_PORT158, NULL); /* CAM_PON */
> + gpio_direction_output(GPIO_PORT158, 0); /* see mt9t111_power() */
> +
Likewise, if you require these GPIOs to be successfully requested as well
as the clock then you need to check that all of these have succeeded,
roll back the work if it hasn't, and conditionalize registration of the
platform device based on this criteria.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 18/27] ARM: shmobile: armadillo800eva: enable camera
2012-06-11 3:57 [PATCH 18/27] ARM: shmobile: armadillo800eva: enable camera Kuninori Morimoto
2012-06-11 4:35 ` Paul Mundt
@ 2012-06-11 9:07 ` Simon Horman
2012-06-11 9:57 ` kuninori.morimoto.gx
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2012-06-11 9:07 UTC (permalink / raw)
To: linux-sh
On Sun, Jun 10, 2012 at 08:57:10PM -0700, Kuninori Morimoto wrote:
> This patch enable camera support on CON1
Hi Morimoto-san,
could you suggest a simple way to test this, preferably from the command line?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 18/27] ARM: shmobile: armadillo800eva: enable camera
2012-06-11 3:57 [PATCH 18/27] ARM: shmobile: armadillo800eva: enable camera Kuninori Morimoto
2012-06-11 4:35 ` Paul Mundt
2012-06-11 9:07 ` Simon Horman
@ 2012-06-11 9:57 ` kuninori.morimoto.gx
2012-06-11 10:05 ` Kuninori Morimoto
2012-06-12 1:27 ` Simon Horman
4 siblings, 0 replies; 6+ messages in thread
From: kuninori.morimoto.gx @ 2012-06-11 9:57 UTC (permalink / raw)
To: linux-sh
Hi Simon
> > This patch enable camera support on CON1
>
> Hi Morimoto-san,
>
> could you suggest a simple way to test this, preferably from the command line?
I'm using mplayer.
mplayer -tv widthd0:heightH0 tv:// -tv outfmt=uyvy -tv device=/dev/video0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 18/27] ARM: shmobile: armadillo800eva: enable camera
2012-06-11 3:57 [PATCH 18/27] ARM: shmobile: armadillo800eva: enable camera Kuninori Morimoto
` (2 preceding siblings ...)
2012-06-11 9:57 ` kuninori.morimoto.gx
@ 2012-06-11 10:05 ` Kuninori Morimoto
2012-06-12 1:27 ` Simon Horman
4 siblings, 0 replies; 6+ messages in thread
From: Kuninori Morimoto @ 2012-06-11 10:05 UTC (permalink / raw)
To: linux-sh
Hi Paul
> > +/* Camera */
> > +static struct clk *cam1_mclk; /* initialized on eva_clock_init() */
> > +static int mt9t111_power(struct device *dev, int mode)
> > +{
> > + if (!cam1_mclk)
> > + return -EINVAL;
> > +
> This isn't necessary, clk_enable/disable() can handle being passed NULL
> just fine. If you've gotten control of the GPIO then you can still do
> meaningful work regardless of whether you have acquired the clock or not.
>
> > + cam1_mclk = clk_get(NULL, "video1");
> > + if (IS_ERR(cam1_mclk)) {
> > + cam1_mclk = NULL;
> > + goto clock_error;
> > + }
> > +
>
> On the other hand, I don't see why you don't do this in the ->power
> routine directly, where you already have a struct device passed in for
> you.
>
> > /* armadillo 800 eva extal1 is 24MHz */
> > clk_set_rate(xtal1, 24000000);
> >
> > /* usb24s use extal1 (= system) clock (= 24MHz) */
> > clk_set_parent(usb24s, system);
> >
> > + /* video1 (= CON1 camera) expect 24MHz */
> > + clk_set_rate(cam1_mclk, clk_round_rate(cam1_mclk, 24000000));
> > +
> > clock_error:
> > if (!IS_ERR(system))
> > clk_put(system);
>
> This error path makes absolutely no sense. If you fail to get the camera
> clock for some reason you skip over xtal and usb24s initialization?
> Without the xtal rate propagation pretty much every other clock in the
> system is going to be broken.
>
> This is a good indicator that this routine is getting too big and you
> need to start splitting things out in to smaller initialization
> subroutines that you can conditionalize.
I see.
Indeed this cam1_mclk was special.
But I can use ->power routine in v2
Thanks
Best regards
---
Kuninori Morimoto
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 18/27] ARM: shmobile: armadillo800eva: enable camera
2012-06-11 3:57 [PATCH 18/27] ARM: shmobile: armadillo800eva: enable camera Kuninori Morimoto
` (3 preceding siblings ...)
2012-06-11 10:05 ` Kuninori Morimoto
@ 2012-06-12 1:27 ` Simon Horman
4 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2012-06-12 1:27 UTC (permalink / raw)
To: linux-sh
On Mon, Jun 11, 2012 at 02:57:17AM -0700, kuninori.morimoto.gx@renesas.com wrote:
>
> Hi Simon
>
> > > This patch enable camera support on CON1
> >
> > Hi Morimoto-san,
> >
> > could you suggest a simple way to test this, preferably from the command line?
>
> I'm using mplayer.
>
> mplayer -tv widthd0:heightH0 tv:// -tv outfmt=uyvy -tv device=/dev/video0
Thanks, looking good :)
Tested-by: Simon Horman <horms@verge.net.au>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-06-12 1:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-11 3:57 [PATCH 18/27] ARM: shmobile: armadillo800eva: enable camera Kuninori Morimoto
2012-06-11 4:35 ` Paul Mundt
2012-06-11 9:07 ` Simon Horman
2012-06-11 9:57 ` kuninori.morimoto.gx
2012-06-11 10:05 ` Kuninori Morimoto
2012-06-12 1:27 ` Simon Horman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox