[PATCH 3/5] arch: sh: kfr2r09: Use new renesas-ceu camera driver

2018-05-28 Thread Jacopo Mondi
Use the new renesas-ceu camera driver in kfr2r09 board file instead of
the soc_camera based sh_mobile_ceu_camera driver.

Get rid of soc_camera specific components, and move clk and gpio handling
away from board file, registering the clock source and the enable gpios
for driver consumption.

Memory for the CEU video buffers is now reserved with membocks APIs,
and need to be declared as dma_coherent during machine initialization to
remove that architecture specific part from CEU driver.

While at there update license to SPDX header and sort headers alphabetically.

No need to udapte the clock source names, as
commit c2f9b05fd5c1 ("media: arch: sh: ecovec: Use new renesas-ceu camera 
driver")
already updated it to the new ceu driver name for all SH7724 boards (possibly
breaking kfr2r09 before this commit).

Compile tested only.

Signed-off-by: Jacopo Mondi 
---
 arch/sh/boards/mach-kfr2r09/setup.c | 217 +---
 1 file changed, 103 insertions(+), 114 deletions(-)

diff --git a/arch/sh/boards/mach-kfr2r09/setup.c 
b/arch/sh/boards/mach-kfr2r09/setup.c
index 6af..e59c577 100644
--- a/arch/sh/boards/mach-kfr2r09/setup.c
+++ b/arch/sh/boards/mach-kfr2r09/setup.c
@@ -1,41 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * KFR2R09 board support code
  *
  * Copyright (C) 2009 Magnus Damm
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file "COPYING" in the main directory of this archive
- * for more details.
  */
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
 #include 
-#include 
+#include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
-#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
-#include 
+
+#include 
+
+#include 
 #include 
-#include 
-#include 
+
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
+
+#define CEU_BUFFER_MEMORY_SIZE (4 << 20)
+static phys_addr_t ceu_dma_membase;
+
+/* set VIO_CKO clock to 25MHz */
+#define CEU_MCLK_FREQ  2500
+#define DRVCRB 0xA405018C
 
 static struct mtd_partition kfr2r09_nor_flash_partitions[] =
 {
@@ -230,8 +242,17 @@ static struct platform_device kfr2r09_usb0_gadget_device = 
{
.resource   = kfr2r09_usb0_gadget_resources,
 };
 
-static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
-   .flags = SH_CEU_FLAG_USE_8BIT_BUS,
+static struct ceu_platform_data ceu_pdata = {
+   .num_subdevs= 1,
+   .subdevs = {
+   { /* [0] = rj54n1cb0c */
+   .flags  = 0,
+   .bus_width  = 8,
+   .bus_shift  = 0,
+   .i2c_adapter_id = 1,
+   .i2c_address= 0x50,
+   },
+   },
 };
 
 static struct resource kfr2r09_ceu_resources[] = {
@@ -246,109 +267,35 @@ static struct resource kfr2r09_ceu_resources[] = {
.end= evt2irq(0x880),
.flags  = IORESOURCE_IRQ,
},
-   [2] = {
-   /* place holder for contiguous memory */
-   },
 };
 
 static struct platform_device kfr2r09_ceu_device = {
-   .name   = "sh_mobile_ceu",
+   .name   = "renesas-ceu",
.id = 0, /* "ceu0" clock */
.num_resources  = ARRAY_SIZE(kfr2r09_ceu_resources),
.resource   = kfr2r09_ceu_resources,
.dev= {
-   .platform_data  = _mobile_ceu_info,
+   .platform_data  = _pdata,
},
 };
 
-static struct i2c_board_info kfr2r09_i2c_camera = {
-   I2C_BOARD_INFO("rj54n1cb0c", 0x50),
-};
-
-static struct clk *camera_clk;
-
-/* set VIO_CKO clock to 25MHz */
-#define CEU_MCLK_FREQ 2500
-
-#define DRVCRB 0xA405018C
-static int camera_power(struct device *dev, int mode)
-{
-   int ret;
-
-   if (mode) {
-   long rate;
-
-   camera_clk = clk_get(NULL, "video_clk");
-   if (IS_ERR(camera_clk))
-   return PTR_ERR(camera_clk);
-
-   rate = clk_round_rate(camera_clk, CEU_MCLK_FREQ);
-   ret = clk_set_rate(camera_clk, rate);
-   if (ret < 0)
-   goto eclkrate;
-
-   /* set DRVCRB
-*
-* use 1.8 V for VccQ_VIO
-* use 2.85V for VccQ_SR
-*/
-   __raw_writew((__raw_readw(DRVCRB) & ~0x0003) | 0x0001, DRVCRB);
-
-   /* reset clear */
-   ret = gpio_request(GPIO_PTB4, NULL);
-   if (ret < 0)
-   goto eptb4;
-   ret = gpio_request(GPIO_PTB7, NULL);
-   if (ret < 0)
-   goto eptb7;
-

[PATCH 3/5] arch: sh: kfr2r09: Use new renesas-ceu camera driver

2018-05-28 Thread Jacopo Mondi
Use the new renesas-ceu camera driver in kfr2r09 board file instead of
the soc_camera based sh_mobile_ceu_camera driver.

Get rid of soc_camera specific components, and move clk and gpio handling
away from board file, registering the clock source and the enable gpios
for driver consumption.

Memory for the CEU video buffers is now reserved with membocks APIs,
and need to be declared as dma_coherent during machine initialization to
remove that architecture specific part from CEU driver.

While at there update license to SPDX header and sort headers alphabetically.

No need to udapte the clock source names, as
commit c2f9b05fd5c1 ("media: arch: sh: ecovec: Use new renesas-ceu camera 
driver")
already updated it to the new ceu driver name for all SH7724 boards (possibly
breaking kfr2r09 before this commit).

Compile tested only.

Signed-off-by: Jacopo Mondi 
---
 arch/sh/boards/mach-kfr2r09/setup.c | 217 +---
 1 file changed, 103 insertions(+), 114 deletions(-)

diff --git a/arch/sh/boards/mach-kfr2r09/setup.c 
b/arch/sh/boards/mach-kfr2r09/setup.c
index 6af..e59c577 100644
--- a/arch/sh/boards/mach-kfr2r09/setup.c
+++ b/arch/sh/boards/mach-kfr2r09/setup.c
@@ -1,41 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * KFR2R09 board support code
  *
  * Copyright (C) 2009 Magnus Damm
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file "COPYING" in the main directory of this archive
- * for more details.
  */
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
 #include 
-#include 
+#include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
-#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
-#include 
+
+#include 
+
+#include 
 #include 
-#include 
-#include 
+
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
+
+#define CEU_BUFFER_MEMORY_SIZE (4 << 20)
+static phys_addr_t ceu_dma_membase;
+
+/* set VIO_CKO clock to 25MHz */
+#define CEU_MCLK_FREQ  2500
+#define DRVCRB 0xA405018C
 
 static struct mtd_partition kfr2r09_nor_flash_partitions[] =
 {
@@ -230,8 +242,17 @@ static struct platform_device kfr2r09_usb0_gadget_device = 
{
.resource   = kfr2r09_usb0_gadget_resources,
 };
 
-static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
-   .flags = SH_CEU_FLAG_USE_8BIT_BUS,
+static struct ceu_platform_data ceu_pdata = {
+   .num_subdevs= 1,
+   .subdevs = {
+   { /* [0] = rj54n1cb0c */
+   .flags  = 0,
+   .bus_width  = 8,
+   .bus_shift  = 0,
+   .i2c_adapter_id = 1,
+   .i2c_address= 0x50,
+   },
+   },
 };
 
 static struct resource kfr2r09_ceu_resources[] = {
@@ -246,109 +267,35 @@ static struct resource kfr2r09_ceu_resources[] = {
.end= evt2irq(0x880),
.flags  = IORESOURCE_IRQ,
},
-   [2] = {
-   /* place holder for contiguous memory */
-   },
 };
 
 static struct platform_device kfr2r09_ceu_device = {
-   .name   = "sh_mobile_ceu",
+   .name   = "renesas-ceu",
.id = 0, /* "ceu0" clock */
.num_resources  = ARRAY_SIZE(kfr2r09_ceu_resources),
.resource   = kfr2r09_ceu_resources,
.dev= {
-   .platform_data  = _mobile_ceu_info,
+   .platform_data  = _pdata,
},
 };
 
-static struct i2c_board_info kfr2r09_i2c_camera = {
-   I2C_BOARD_INFO("rj54n1cb0c", 0x50),
-};
-
-static struct clk *camera_clk;
-
-/* set VIO_CKO clock to 25MHz */
-#define CEU_MCLK_FREQ 2500
-
-#define DRVCRB 0xA405018C
-static int camera_power(struct device *dev, int mode)
-{
-   int ret;
-
-   if (mode) {
-   long rate;
-
-   camera_clk = clk_get(NULL, "video_clk");
-   if (IS_ERR(camera_clk))
-   return PTR_ERR(camera_clk);
-
-   rate = clk_round_rate(camera_clk, CEU_MCLK_FREQ);
-   ret = clk_set_rate(camera_clk, rate);
-   if (ret < 0)
-   goto eclkrate;
-
-   /* set DRVCRB
-*
-* use 1.8 V for VccQ_VIO
-* use 2.85V for VccQ_SR
-*/
-   __raw_writew((__raw_readw(DRVCRB) & ~0x0003) | 0x0001, DRVCRB);
-
-   /* reset clear */
-   ret = gpio_request(GPIO_PTB4, NULL);
-   if (ret < 0)
-   goto eptb4;
-   ret = gpio_request(GPIO_PTB7, NULL);
-   if (ret < 0)
-   goto eptb7;
-
-   ret =