Re: [PATCH v6 04/17] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2018-05-16 Thread Jacob Chen
2018-05-16 22:39 GMT+08:00 Jacob Chen <jacobchen...@gmail.com>:
> Hi Laurent,
>
> 2018-05-16 13:20 GMT+08:00 Laurent Pinchart 
> <laurent.pinch...@ideasonboard.com>:
>> Hi Jacob,
>>
>> Thank you for the patch.
>>
>> On Thursday, 8 March 2018 11:47:54 EEST Jacob Chen wrote:
>>> From: Jacob Chen <jacob2.c...@rock-chips.com>
>>>
>>> This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver
>>
>> Should this really be a subdev driver ? After a quick look at the code, the
>> only parameters you need to configure the PHY is the number of lanes and the
>> data rate. Implementing the whole subdev API seems overcomplicated to me,
>> especially given that the D-PHY doesn't deal with video streams as such, but
>> operates one level down. Shouldn't we model the D-PHY using the Linux PHY
>> framework ? I believe all the features you need are there except for a D-PHY-
>> specific configuration function that should be very easy to add.
>>
>
> It deserves a subdev driver since the ISP is not the only user.
> Other driver, like VIP, use it too.
>
>

For example, if there are two sensors connected to a rk3399 board.

Sensor1 --> DPHY1
Sensor2 --> DPHY2

With a subdev phy driver, i can choose either ISP or VIP for
sensor1/sensor2 by enable/disable media link in the run time.
1.
Sensor1 --> DPHY1 ---> VIP
Sensor2 --> DPHY2 ---> ISP1
2.
Sensor1 --> DPHY1 ---> ISP1
Sensor2 --> DPHY2 ---> VIP



>>> Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
>>> Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
>>> Signed-off-by: Tomasz Figa <tf...@chromium.org>
>>> ---
>>>  .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 868 ++
>>>  .../media/platform/rockchip/isp1/mipi_dphy_sy.h|  15 +
>>>  2 files changed, 883 insertions(+)
>>>  create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>>>  create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.h
>>>
>>> diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>>> b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file mode 100644
>>> index ..32140960557a
>>> --- /dev/null
>>> +++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>>> @@ -0,0 +1,868 @@
>>> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
>>> +/*
>>> + * Rockchip MIPI Synopsys DPHY driver
>>> + *
>>> + * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
>>> + */
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +#define RK3288_GRF_SOC_CON6  0x025c
>>> +#define RK3288_GRF_SOC_CON8  0x0264
>>> +#define RK3288_GRF_SOC_CON9  0x0268
>>> +#define RK3288_GRF_SOC_CON10 0x026c
>>> +#define RK3288_GRF_SOC_CON14 0x027c
>>> +#define RK3288_GRF_SOC_STATUS21  0x02d4
>>> +#define RK3288_GRF_IO_VSEL   0x0380
>>> +#define RK3288_GRF_SOC_CON15 0x03a4
>>> +
>>> +#define RK3399_GRF_SOC_CON9  0x6224
>>> +#define RK3399_GRF_SOC_CON21 0x6254
>>> +#define RK3399_GRF_SOC_CON22 0x6258
>>> +#define RK3399_GRF_SOC_CON23 0x625c
>>> +#define RK3399_GRF_SOC_CON24 0x6260
>>> +#define RK3399_GRF_SOC_CON25 0x6264
>>> +#define RK3399_GRF_SOC_STATUS1   0xe2a4
>>> +
>>> +#define CLOCK_LANE_HS_RX_CONTROL 0x34
>>> +#define LANE0_HS_RX_CONTROL  0x44
>>> +#define LANE1_HS_RX_CONTROL  0x54
>>> +#define LANE2_HS_RX_CONTROL  0x84
>>> +#define LANE3_HS_RX_CONTROL  0x94
>>> +#define HS_RX_DATA_LANES_THS_SETTLE_CONTROL  0x75
>>> +
>>> +/*
>>> + * CSI HOST
>>> + */
>>> +#define CSIHOST_PHY_TEST_CTRL0   0x30
>>> +#define CSIHOST_PHY_TEST_CTRL1   0x34
>>> +#define CSIHOST_PHY_SHUTDOWNZ0x08
>>> +#define CSIHOST_DPHY_RSTZ0x0c
>>> +
>>> +#define PHY_TESTEN_ADDR  (0x1 << 16)
>>> +#define PHY_TESTEN_DATA  (0x0 << 16)
>>> +#define PHY_TESTCLK  (0x1 << 1)
>>> +#define PHY_TESTCLR  (0x1 << 0)
>>> +#de

Re: [PATCH v6 04/17] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2018-05-16 Thread Jacob Chen
2018-05-16 22:39 GMT+08:00 Jacob Chen :
> Hi Laurent,
>
> 2018-05-16 13:20 GMT+08:00 Laurent Pinchart 
> :
>> Hi Jacob,
>>
>> Thank you for the patch.
>>
>> On Thursday, 8 March 2018 11:47:54 EEST Jacob Chen wrote:
>>> From: Jacob Chen 
>>>
>>> This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver
>>
>> Should this really be a subdev driver ? After a quick look at the code, the
>> only parameters you need to configure the PHY is the number of lanes and the
>> data rate. Implementing the whole subdev API seems overcomplicated to me,
>> especially given that the D-PHY doesn't deal with video streams as such, but
>> operates one level down. Shouldn't we model the D-PHY using the Linux PHY
>> framework ? I believe all the features you need are there except for a D-PHY-
>> specific configuration function that should be very easy to add.
>>
>
> It deserves a subdev driver since the ISP is not the only user.
> Other driver, like VIP, use it too.
>
>

For example, if there are two sensors connected to a rk3399 board.

Sensor1 --> DPHY1
Sensor2 --> DPHY2

With a subdev phy driver, i can choose either ISP or VIP for
sensor1/sensor2 by enable/disable media link in the run time.
1.
Sensor1 --> DPHY1 ---> VIP
Sensor2 --> DPHY2 ---> ISP1
2.
Sensor1 --> DPHY1 ---> ISP1
Sensor2 --> DPHY2 ---> VIP



>>> Signed-off-by: Jacob Chen 
>>> Signed-off-by: Shunqian Zheng 
>>> Signed-off-by: Tomasz Figa 
>>> ---
>>>  .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 868 ++
>>>  .../media/platform/rockchip/isp1/mipi_dphy_sy.h|  15 +
>>>  2 files changed, 883 insertions(+)
>>>  create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>>>  create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.h
>>>
>>> diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>>> b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file mode 100644
>>> index ..32140960557a
>>> --- /dev/null
>>> +++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>>> @@ -0,0 +1,868 @@
>>> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
>>> +/*
>>> + * Rockchip MIPI Synopsys DPHY driver
>>> + *
>>> + * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
>>> + */
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +#define RK3288_GRF_SOC_CON6  0x025c
>>> +#define RK3288_GRF_SOC_CON8  0x0264
>>> +#define RK3288_GRF_SOC_CON9  0x0268
>>> +#define RK3288_GRF_SOC_CON10 0x026c
>>> +#define RK3288_GRF_SOC_CON14 0x027c
>>> +#define RK3288_GRF_SOC_STATUS21  0x02d4
>>> +#define RK3288_GRF_IO_VSEL   0x0380
>>> +#define RK3288_GRF_SOC_CON15 0x03a4
>>> +
>>> +#define RK3399_GRF_SOC_CON9  0x6224
>>> +#define RK3399_GRF_SOC_CON21 0x6254
>>> +#define RK3399_GRF_SOC_CON22 0x6258
>>> +#define RK3399_GRF_SOC_CON23 0x625c
>>> +#define RK3399_GRF_SOC_CON24 0x6260
>>> +#define RK3399_GRF_SOC_CON25 0x6264
>>> +#define RK3399_GRF_SOC_STATUS1   0xe2a4
>>> +
>>> +#define CLOCK_LANE_HS_RX_CONTROL 0x34
>>> +#define LANE0_HS_RX_CONTROL  0x44
>>> +#define LANE1_HS_RX_CONTROL  0x54
>>> +#define LANE2_HS_RX_CONTROL  0x84
>>> +#define LANE3_HS_RX_CONTROL  0x94
>>> +#define HS_RX_DATA_LANES_THS_SETTLE_CONTROL  0x75
>>> +
>>> +/*
>>> + * CSI HOST
>>> + */
>>> +#define CSIHOST_PHY_TEST_CTRL0   0x30
>>> +#define CSIHOST_PHY_TEST_CTRL1   0x34
>>> +#define CSIHOST_PHY_SHUTDOWNZ0x08
>>> +#define CSIHOST_DPHY_RSTZ0x0c
>>> +
>>> +#define PHY_TESTEN_ADDR  (0x1 << 16)
>>> +#define PHY_TESTEN_DATA  (0x0 << 16)
>>> +#define PHY_TESTCLK  (0x1 << 1)
>>> +#define PHY_TESTCLR  (0x1 << 0)
>>> +#define THS_SETTLE_COUNTER_THRESHOLD 0x04
>>> +
>>> +#define HIWORD_UPDATE(val, mask, shift) \
>>> + ((val) << (shift) | (mask) << ((shift) + 16))
&

Re: [PATCH v6 04/17] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2018-05-16 Thread Jacob Chen
Hi Laurent,

2018-05-16 13:20 GMT+08:00 Laurent Pinchart <laurent.pinch...@ideasonboard.com>:
> Hi Jacob,
>
> Thank you for the patch.
>
> On Thursday, 8 March 2018 11:47:54 EEST Jacob Chen wrote:
>> From: Jacob Chen <jacob2.c...@rock-chips.com>
>>
>> This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver
>
> Should this really be a subdev driver ? After a quick look at the code, the
> only parameters you need to configure the PHY is the number of lanes and the
> data rate. Implementing the whole subdev API seems overcomplicated to me,
> especially given that the D-PHY doesn't deal with video streams as such, but
> operates one level down. Shouldn't we model the D-PHY using the Linux PHY
> framework ? I believe all the features you need are there except for a D-PHY-
> specific configuration function that should be very easy to add.
>

It deserves a subdev driver since the ISP is not the only user.
Other driver, like VIP, use it too.


>> Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
>> Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
>> Signed-off-by: Tomasz Figa <tf...@chromium.org>
>> ---
>>  .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 868 ++
>>  .../media/platform/rockchip/isp1/mipi_dphy_sy.h|  15 +
>>  2 files changed, 883 insertions(+)
>>  create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>>  create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.h
>>
>> diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>> b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file mode 100644
>> index ..32140960557a
>> --- /dev/null
>> +++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>> @@ -0,0 +1,868 @@
>> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
>> +/*
>> + * Rockchip MIPI Synopsys DPHY driver
>> + *
>> + * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define RK3288_GRF_SOC_CON6  0x025c
>> +#define RK3288_GRF_SOC_CON8  0x0264
>> +#define RK3288_GRF_SOC_CON9  0x0268
>> +#define RK3288_GRF_SOC_CON10 0x026c
>> +#define RK3288_GRF_SOC_CON14 0x027c
>> +#define RK3288_GRF_SOC_STATUS21  0x02d4
>> +#define RK3288_GRF_IO_VSEL   0x0380
>> +#define RK3288_GRF_SOC_CON15 0x03a4
>> +
>> +#define RK3399_GRF_SOC_CON9  0x6224
>> +#define RK3399_GRF_SOC_CON21 0x6254
>> +#define RK3399_GRF_SOC_CON22 0x6258
>> +#define RK3399_GRF_SOC_CON23 0x625c
>> +#define RK3399_GRF_SOC_CON24 0x6260
>> +#define RK3399_GRF_SOC_CON25 0x6264
>> +#define RK3399_GRF_SOC_STATUS1   0xe2a4
>> +
>> +#define CLOCK_LANE_HS_RX_CONTROL 0x34
>> +#define LANE0_HS_RX_CONTROL  0x44
>> +#define LANE1_HS_RX_CONTROL  0x54
>> +#define LANE2_HS_RX_CONTROL  0x84
>> +#define LANE3_HS_RX_CONTROL  0x94
>> +#define HS_RX_DATA_LANES_THS_SETTLE_CONTROL  0x75
>> +
>> +/*
>> + * CSI HOST
>> + */
>> +#define CSIHOST_PHY_TEST_CTRL0   0x30
>> +#define CSIHOST_PHY_TEST_CTRL1   0x34
>> +#define CSIHOST_PHY_SHUTDOWNZ0x08
>> +#define CSIHOST_DPHY_RSTZ0x0c
>> +
>> +#define PHY_TESTEN_ADDR  (0x1 << 16)
>> +#define PHY_TESTEN_DATA  (0x0 << 16)
>> +#define PHY_TESTCLK  (0x1 << 1)
>> +#define PHY_TESTCLR  (0x1 << 0)
>> +#define THS_SETTLE_COUNTER_THRESHOLD 0x04
>> +
>> +#define HIWORD_UPDATE(val, mask, shift) \
>> + ((val) << (shift) | (mask) << ((shift) + 16))
>> +
>> +enum mipi_dphy_sy_pads {
>> + MIPI_DPHY_SY_PAD_SINK = 0,
>> + MIPI_DPHY_SY_PAD_SOURCE,
>> + MIPI_DPHY_SY_PADS_NUM,
>> +};
>> +
>> +enum dphy_reg_id {
>> + GRF_DPHY_RX0_TURNDISABLE = 0,
>> + GRF_DPHY_RX0_FORCERXMODE,
>> + GRF_DPHY_RX0_FORCETXSTOPMODE,
>> + GRF_DPHY_RX0_ENABLE,
>> + GRF_DPHY_RX0_TESTCLR,
>> + GRF_DPHY_RX0_TESTCLK,
>> + GRF_DPHY_RX0_TESTEN,
>> + GRF_DPHY_RX0_TESTDIN,
>> + GRF_DPHY_RX0_TURNREQUEST,
>> + GRF_DPHY_RX0_TESTDOUT,
>> + GRF_DPHY_TX0_TURNDISABLE,
>> + GRF_DPHY_TX0_FORCERXMODE,
>&

Re: [PATCH v6 04/17] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2018-05-16 Thread Jacob Chen
Hi Laurent,

2018-05-16 13:20 GMT+08:00 Laurent Pinchart :
> Hi Jacob,
>
> Thank you for the patch.
>
> On Thursday, 8 March 2018 11:47:54 EEST Jacob Chen wrote:
>> From: Jacob Chen 
>>
>> This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver
>
> Should this really be a subdev driver ? After a quick look at the code, the
> only parameters you need to configure the PHY is the number of lanes and the
> data rate. Implementing the whole subdev API seems overcomplicated to me,
> especially given that the D-PHY doesn't deal with video streams as such, but
> operates one level down. Shouldn't we model the D-PHY using the Linux PHY
> framework ? I believe all the features you need are there except for a D-PHY-
> specific configuration function that should be very easy to add.
>

It deserves a subdev driver since the ISP is not the only user.
Other driver, like VIP, use it too.


>> Signed-off-by: Jacob Chen 
>> Signed-off-by: Shunqian Zheng 
>> Signed-off-by: Tomasz Figa 
>> ---
>>  .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 868 ++
>>  .../media/platform/rockchip/isp1/mipi_dphy_sy.h|  15 +
>>  2 files changed, 883 insertions(+)
>>  create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>>  create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.h
>>
>> diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>> b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file mode 100644
>> index ..32140960557a
>> --- /dev/null
>> +++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>> @@ -0,0 +1,868 @@
>> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
>> +/*
>> + * Rockchip MIPI Synopsys DPHY driver
>> + *
>> + * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define RK3288_GRF_SOC_CON6  0x025c
>> +#define RK3288_GRF_SOC_CON8  0x0264
>> +#define RK3288_GRF_SOC_CON9  0x0268
>> +#define RK3288_GRF_SOC_CON10 0x026c
>> +#define RK3288_GRF_SOC_CON14 0x027c
>> +#define RK3288_GRF_SOC_STATUS21  0x02d4
>> +#define RK3288_GRF_IO_VSEL   0x0380
>> +#define RK3288_GRF_SOC_CON15 0x03a4
>> +
>> +#define RK3399_GRF_SOC_CON9  0x6224
>> +#define RK3399_GRF_SOC_CON21 0x6254
>> +#define RK3399_GRF_SOC_CON22 0x6258
>> +#define RK3399_GRF_SOC_CON23 0x625c
>> +#define RK3399_GRF_SOC_CON24 0x6260
>> +#define RK3399_GRF_SOC_CON25 0x6264
>> +#define RK3399_GRF_SOC_STATUS1   0xe2a4
>> +
>> +#define CLOCK_LANE_HS_RX_CONTROL 0x34
>> +#define LANE0_HS_RX_CONTROL  0x44
>> +#define LANE1_HS_RX_CONTROL  0x54
>> +#define LANE2_HS_RX_CONTROL  0x84
>> +#define LANE3_HS_RX_CONTROL  0x94
>> +#define HS_RX_DATA_LANES_THS_SETTLE_CONTROL  0x75
>> +
>> +/*
>> + * CSI HOST
>> + */
>> +#define CSIHOST_PHY_TEST_CTRL0   0x30
>> +#define CSIHOST_PHY_TEST_CTRL1   0x34
>> +#define CSIHOST_PHY_SHUTDOWNZ0x08
>> +#define CSIHOST_DPHY_RSTZ0x0c
>> +
>> +#define PHY_TESTEN_ADDR  (0x1 << 16)
>> +#define PHY_TESTEN_DATA  (0x0 << 16)
>> +#define PHY_TESTCLK  (0x1 << 1)
>> +#define PHY_TESTCLR  (0x1 << 0)
>> +#define THS_SETTLE_COUNTER_THRESHOLD 0x04
>> +
>> +#define HIWORD_UPDATE(val, mask, shift) \
>> + ((val) << (shift) | (mask) << ((shift) + 16))
>> +
>> +enum mipi_dphy_sy_pads {
>> + MIPI_DPHY_SY_PAD_SINK = 0,
>> + MIPI_DPHY_SY_PAD_SOURCE,
>> + MIPI_DPHY_SY_PADS_NUM,
>> +};
>> +
>> +enum dphy_reg_id {
>> + GRF_DPHY_RX0_TURNDISABLE = 0,
>> + GRF_DPHY_RX0_FORCERXMODE,
>> + GRF_DPHY_RX0_FORCETXSTOPMODE,
>> + GRF_DPHY_RX0_ENABLE,
>> + GRF_DPHY_RX0_TESTCLR,
>> + GRF_DPHY_RX0_TESTCLK,
>> + GRF_DPHY_RX0_TESTEN,
>> + GRF_DPHY_RX0_TESTDIN,
>> + GRF_DPHY_RX0_TURNREQUEST,
>> + GRF_DPHY_RX0_TESTDOUT,
>> + GRF_DPHY_TX0_TURNDISABLE,
>> + GRF_DPHY_TX0_FORCERXMODE,
>> + GRF_DPHY_TX0_FORCETXSTOPMODE,
>> + GRF_DPHY_TX0_TURNREQUEST,
>> + GRF_DPHY_TX1RX1_TURNDISABLE,
>> + GRF_DPHY_TX1RX1_FORCERXMODE,
&g

[PATCH] ARM: dts: rockchip: fix uart4 pin-num for rk3288

2018-03-15 Thread Jacob Chen
According to TRM, uart4 tx/rx should be 14/15

Signed-off-by: Jacob Chen <jacob-c...@iotwrt.com>
---
 arch/arm/boot/dts/rk3288.dtsi | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index ed05f3d77358..40327c764385 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -1938,16 +1938,16 @@
 
uart4 {
uart4_xfer: uart4-xfer {
-   rockchip,pins = <5 12 3 _pull_up>,
-   <5 13 3 _pull_none>;
+   rockchip,pins = <5 15 3 _pull_up>,
+   <5 14 3 _pull_none>;
};
 
uart4_cts: uart4-cts {
-   rockchip,pins = <5 14 3 _pull_up>;
+   rockchip,pins = <5 12 3 _pull_up>;
};
 
uart4_rts: uart4-rts {
-   rockchip,pins = <5 15 3 _pull_none>;
+   rockchip,pins = <5 13 3 _pull_none>;
};
};
 
-- 
2.16.1



[PATCH] ARM: dts: rockchip: fix uart4 pin-num for rk3288

2018-03-15 Thread Jacob Chen
According to TRM, uart4 tx/rx should be 14/15

Signed-off-by: Jacob Chen 
---
 arch/arm/boot/dts/rk3288.dtsi | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index ed05f3d77358..40327c764385 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -1938,16 +1938,16 @@
 
uart4 {
uart4_xfer: uart4-xfer {
-   rockchip,pins = <5 12 3 _pull_up>,
-   <5 13 3 _pull_none>;
+   rockchip,pins = <5 15 3 _pull_up>,
+   <5 14 3 _pull_none>;
};
 
uart4_cts: uart4-cts {
-   rockchip,pins = <5 14 3 _pull_up>;
+   rockchip,pins = <5 12 3 _pull_up>;
};
 
uart4_rts: uart4-rts {
-   rockchip,pins = <5 15 3 _pull_none>;
+   rockchip,pins = <5 13 3 _pull_none>;
};
};
 
-- 
2.16.1



Re: [PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Jacob Chen
Hi Baruch,

2018-03-09 12:09 GMT+08:00 Baruch Siach <bar...@tkos.co.il>:
> Hi Jacob,
>
> On Fri, Mar 09, 2018 at 08:53:57AM +0800, Jacob Chen wrote:
>> 2018-03-08 20:02 GMT+08:00 Baruch Siach <bar...@tkos.co.il>:
>> > On Thu, Mar 08, 2018 at 05:47:50PM +0800, Jacob Chen wrote:
>> >> This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399
>> >> SoC.
>> >>
>> >> Wiki Pages:
>> >> http://opensource.rock-chips.com/wiki_Rockchip-isp1
>> >>
>> >> The deprecated g_mbus_config op is not dropped in  V6 because i am waiting
>> >> tomasz's patches.
>> >
>> > Which tree is this series based on? On top of v4.16-rc4 I get the build
>> > failure below. The V4L2_BUF_TYPE_META_OUTPUT macro, for example, is not 
>> > even
>> > in media_tree.git.
>>
>> This series is based on v4.16-rc4 with below patch.
>> https://patchwork.kernel.org/patch/9792001/
>
> This patch does not apply on v4.16-rc4. I also tried v2 of this patch with the
> same result:
>
>   https://patchwork.linuxtv.org/patch/44682/

It need resolve merge conflict.

>
> Can you push your series to a public git repo branch?
>

Sure, I have push it to my github.
https://github.com/wzyy2/linux/tree/4.16-rc4

This commit might be a bit of a mess
https://github.com/wzyy2/linux/commit/ff68323c4804adc10f64836ea1be172c54a9d6c6

> Thanks,
> baruch
>
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1321:3: error: ‘const 
>> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_enum_fmt_meta_out’; did 
>> > you mean ‘vidioc_enum_fmt_meta_cap’?
>> >   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>> >^~~~
>> >vidioc_enum_fmt_meta_cap
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: error: 
>> > initialization from incompatible pointer type 
>> > [-Werror=incompatible-pointer-types]
>> >   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>> >   ^~~
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: note: (near 
>> > initialization for ‘rkisp1_params_ioctl.vidioc_g_std’)
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1322:3: error: ‘const 
>> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_g_fmt_meta_out’; did 
>> > you mean ‘vidioc_g_fmt_meta_cap’?
>> >   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^
>> >vidioc_g_fmt_meta_cap
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: error: 
>> > initialization from incompatible pointer type 
>> > [-Werror=incompatible-pointer-types]
>> >   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^~~~
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: note: (near 
>> > initialization for ‘rkisp1_params_ioctl.vidioc_s_std’)
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1323:3: error: ‘const 
>> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_s_fmt_meta_out’; did 
>> > you mean ‘vidioc_s_fmt_meta_cap’?
>> >   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^
>> >vidioc_s_fmt_meta_cap
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: error: 
>> > initialization from incompatible pointer type 
>> > [-Werror=incompatible-pointer-types]
>> >   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^~~~
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: note: (near 
>> > initialization for ‘rkisp1_params_ioctl.vidioc_querystd’)
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1324:3: error: ‘const 
>> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_try_fmt_meta_out’; did 
>> > you mean ‘vidioc_try_fmt_meta_cap’?
>> >   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^~~
>> >vidioc_try_fmt_meta_cap
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: error: 
>> > initialization from incompatible pointer type 
>> > [-Werror=incompatible-pointer-types]
>> >   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >  ^~~~
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: note: (near 
>> > initialization 

Re: [PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Jacob Chen
Hi Baruch,

2018-03-09 12:09 GMT+08:00 Baruch Siach :
> Hi Jacob,
>
> On Fri, Mar 09, 2018 at 08:53:57AM +0800, Jacob Chen wrote:
>> 2018-03-08 20:02 GMT+08:00 Baruch Siach :
>> > On Thu, Mar 08, 2018 at 05:47:50PM +0800, Jacob Chen wrote:
>> >> This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399
>> >> SoC.
>> >>
>> >> Wiki Pages:
>> >> http://opensource.rock-chips.com/wiki_Rockchip-isp1
>> >>
>> >> The deprecated g_mbus_config op is not dropped in  V6 because i am waiting
>> >> tomasz's patches.
>> >
>> > Which tree is this series based on? On top of v4.16-rc4 I get the build
>> > failure below. The V4L2_BUF_TYPE_META_OUTPUT macro, for example, is not 
>> > even
>> > in media_tree.git.
>>
>> This series is based on v4.16-rc4 with below patch.
>> https://patchwork.kernel.org/patch/9792001/
>
> This patch does not apply on v4.16-rc4. I also tried v2 of this patch with the
> same result:
>
>   https://patchwork.linuxtv.org/patch/44682/

It need resolve merge conflict.

>
> Can you push your series to a public git repo branch?
>

Sure, I have push it to my github.
https://github.com/wzyy2/linux/tree/4.16-rc4

This commit might be a bit of a mess
https://github.com/wzyy2/linux/commit/ff68323c4804adc10f64836ea1be172c54a9d6c6

> Thanks,
> baruch
>
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1321:3: error: ‘const 
>> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_enum_fmt_meta_out’; did 
>> > you mean ‘vidioc_enum_fmt_meta_cap’?
>> >   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>> >^~~~
>> >vidioc_enum_fmt_meta_cap
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: error: 
>> > initialization from incompatible pointer type 
>> > [-Werror=incompatible-pointer-types]
>> >   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>> >   ^~~
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: note: (near 
>> > initialization for ‘rkisp1_params_ioctl.vidioc_g_std’)
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1322:3: error: ‘const 
>> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_g_fmt_meta_out’; did 
>> > you mean ‘vidioc_g_fmt_meta_cap’?
>> >   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^
>> >vidioc_g_fmt_meta_cap
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: error: 
>> > initialization from incompatible pointer type 
>> > [-Werror=incompatible-pointer-types]
>> >   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^~~~
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: note: (near 
>> > initialization for ‘rkisp1_params_ioctl.vidioc_s_std’)
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1323:3: error: ‘const 
>> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_s_fmt_meta_out’; did 
>> > you mean ‘vidioc_s_fmt_meta_cap’?
>> >   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^
>> >vidioc_s_fmt_meta_cap
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: error: 
>> > initialization from incompatible pointer type 
>> > [-Werror=incompatible-pointer-types]
>> >   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^~~~
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: note: (near 
>> > initialization for ‘rkisp1_params_ioctl.vidioc_querystd’)
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1324:3: error: ‘const 
>> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_try_fmt_meta_out’; did 
>> > you mean ‘vidioc_try_fmt_meta_cap’?
>> >   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^~~
>> >vidioc_try_fmt_meta_cap
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: error: 
>> > initialization from incompatible pointer type 
>> > [-Werror=incompatible-pointer-types]
>> >   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >  ^~~~
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: note: (near 
>> > initialization for ‘rkisp1_params_ioctl.vidioc_enum_input’)
>

Re: [PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Jacob Chen
Hi Baruch,

2018-03-08 20:02 GMT+08:00 Baruch Siach <bar...@tkos.co.il>:
> Hi Jacob,
>
> On Thu, Mar 08, 2018 at 05:47:50PM +0800, Jacob Chen wrote:
>> This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399
>> SoC.
>>
>> Wiki Pages:
>> http://opensource.rock-chips.com/wiki_Rockchip-isp1
>>
>> The deprecated g_mbus_config op is not dropped in  V6 because i am waiting
>> tomasz's patches.
>
> Which tree is this series based on? On top of v4.16-rc4 I get the build
> failure below. The V4L2_BUF_TYPE_META_OUTPUT macro, for example, is not even
> in media_tree.git.
>

This series is based on v4.16-rc4 with below patch.
https://patchwork.kernel.org/patch/9792001/


> drivers/media/platform/rockchip/isp1/isp_params.c:1321:3: error: ‘const 
> struct v4l2_ioctl_ops’ has no member named ‘vidioc_enum_fmt_meta_out’; did 
> you mean ‘vidioc_enum_fmt_meta_cap’?
>   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>^~~~
>vidioc_enum_fmt_meta_cap
> drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: error: 
> initialization from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>   ^~~
> drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: note: (near 
> initialization for ‘rkisp1_params_ioctl.vidioc_g_std’)
> drivers/media/platform/rockchip/isp1/isp_params.c:1322:3: error: ‘const 
> struct v4l2_ioctl_ops’ has no member named ‘vidioc_g_fmt_meta_out’; did you 
> mean ‘vidioc_g_fmt_meta_cap’?
>   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^
>vidioc_g_fmt_meta_cap
> drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: error: 
> initialization from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^~~~
> drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: note: (near 
> initialization for ‘rkisp1_params_ioctl.vidioc_s_std’)
> drivers/media/platform/rockchip/isp1/isp_params.c:1323:3: error: ‘const 
> struct v4l2_ioctl_ops’ has no member named ‘vidioc_s_fmt_meta_out’; did you 
> mean ‘vidioc_s_fmt_meta_cap’?
>   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^
>vidioc_s_fmt_meta_cap
> drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: error: 
> initialization from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^~~~
> drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: note: (near 
> initialization for ‘rkisp1_params_ioctl.vidioc_querystd’)
> drivers/media/platform/rockchip/isp1/isp_params.c:1324:3: error: ‘const 
> struct v4l2_ioctl_ops’ has no member named ‘vidioc_try_fmt_meta_out’; did you 
> mean ‘vidioc_try_fmt_meta_cap’?
>   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^~~
>vidioc_try_fmt_meta_cap
> drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: error: 
> initialization from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>  ^~~~
> drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: note: (near 
> initialization for ‘rkisp1_params_ioctl.vidioc_enum_input’)
> drivers/media/platform/rockchip/isp1/isp_params.c: In function 
> ‘rkisp1_params_init_vb2_queue’:
> drivers/media/platform/rockchip/isp1/isp_params.c:1462:12: error: 
> ‘V4L2_BUF_TYPE_META_OUTPUT’ undeclared (first use in this function); did you 
> mean ‘V4L2_BUF_TYPE_SDR_OUTPUT’?
>   q->type = V4L2_BUF_TYPE_META_OUTPUT;
> ^
> V4L2_BUF_TYPE_SDR_OUTPUT
> drivers/media/platform/rockchip/isp1/isp_params.c:1462:12: note: each 
> undeclared identifier is reported only once for each function it appears in
>   CC  drivers/media/platform/rockchip/isp1/mipi_dphy_sy.o
> drivers/media/platform/rockchip/isp1/isp_params.c: In function 
> ‘rkisp1_register_params_vdev’:
> drivers/media/platform/rockchip/isp1/isp_params.c:1507:43: error: 
> ‘V4L2_CAP_META_OUTPUT’ undeclared (first use in this function); did you mean 
> ‘V4L2_CAP_VBI_OUTPUT’?
>   vdev->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_META_OUTPUT;
>^~~~
>V4L2_CAP_VBI_OUTPUT
>
> Thanks,
> baruch
>
>> Jacob Ch

Re: [PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Jacob Chen
Hi Baruch,

2018-03-08 20:02 GMT+08:00 Baruch Siach :
> Hi Jacob,
>
> On Thu, Mar 08, 2018 at 05:47:50PM +0800, Jacob Chen wrote:
>> This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399
>> SoC.
>>
>> Wiki Pages:
>> http://opensource.rock-chips.com/wiki_Rockchip-isp1
>>
>> The deprecated g_mbus_config op is not dropped in  V6 because i am waiting
>> tomasz's patches.
>
> Which tree is this series based on? On top of v4.16-rc4 I get the build
> failure below. The V4L2_BUF_TYPE_META_OUTPUT macro, for example, is not even
> in media_tree.git.
>

This series is based on v4.16-rc4 with below patch.
https://patchwork.kernel.org/patch/9792001/


> drivers/media/platform/rockchip/isp1/isp_params.c:1321:3: error: ‘const 
> struct v4l2_ioctl_ops’ has no member named ‘vidioc_enum_fmt_meta_out’; did 
> you mean ‘vidioc_enum_fmt_meta_cap’?
>   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>^~~~
>vidioc_enum_fmt_meta_cap
> drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: error: 
> initialization from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>   ^~~
> drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: note: (near 
> initialization for ‘rkisp1_params_ioctl.vidioc_g_std’)
> drivers/media/platform/rockchip/isp1/isp_params.c:1322:3: error: ‘const 
> struct v4l2_ioctl_ops’ has no member named ‘vidioc_g_fmt_meta_out’; did you 
> mean ‘vidioc_g_fmt_meta_cap’?
>   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^
>vidioc_g_fmt_meta_cap
> drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: error: 
> initialization from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^~~~
> drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: note: (near 
> initialization for ‘rkisp1_params_ioctl.vidioc_s_std’)
> drivers/media/platform/rockchip/isp1/isp_params.c:1323:3: error: ‘const 
> struct v4l2_ioctl_ops’ has no member named ‘vidioc_s_fmt_meta_out’; did you 
> mean ‘vidioc_s_fmt_meta_cap’?
>   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^
>vidioc_s_fmt_meta_cap
> drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: error: 
> initialization from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^~~~
> drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: note: (near 
> initialization for ‘rkisp1_params_ioctl.vidioc_querystd’)
> drivers/media/platform/rockchip/isp1/isp_params.c:1324:3: error: ‘const 
> struct v4l2_ioctl_ops’ has no member named ‘vidioc_try_fmt_meta_out’; did you 
> mean ‘vidioc_try_fmt_meta_cap’?
>   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^~~
>vidioc_try_fmt_meta_cap
> drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: error: 
> initialization from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>  ^~~~
> drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: note: (near 
> initialization for ‘rkisp1_params_ioctl.vidioc_enum_input’)
> drivers/media/platform/rockchip/isp1/isp_params.c: In function 
> ‘rkisp1_params_init_vb2_queue’:
> drivers/media/platform/rockchip/isp1/isp_params.c:1462:12: error: 
> ‘V4L2_BUF_TYPE_META_OUTPUT’ undeclared (first use in this function); did you 
> mean ‘V4L2_BUF_TYPE_SDR_OUTPUT’?
>   q->type = V4L2_BUF_TYPE_META_OUTPUT;
> ^
> V4L2_BUF_TYPE_SDR_OUTPUT
> drivers/media/platform/rockchip/isp1/isp_params.c:1462:12: note: each 
> undeclared identifier is reported only once for each function it appears in
>   CC  drivers/media/platform/rockchip/isp1/mipi_dphy_sy.o
> drivers/media/platform/rockchip/isp1/isp_params.c: In function 
> ‘rkisp1_register_params_vdev’:
> drivers/media/platform/rockchip/isp1/isp_params.c:1507:43: error: 
> ‘V4L2_CAP_META_OUTPUT’ undeclared (first use in this function); did you mean 
> ‘V4L2_CAP_VBI_OUTPUT’?
>   vdev->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_META_OUTPUT;
>^~~~
>V4L2_CAP_VBI_OUTPUT
>
> Thanks,
> baruch
>
>> Jacob Chen (12):
>>   media

Re: [PATCH v5 03/16] media: rkisp1: Add user space ABI definitions

2018-03-08 Thread Jacob Chen
Hi Hans,

2018-02-07 20:00 GMT+08:00 Hans Verkuil :
> On 12/29/17 08:52, Shunqian Zheng wrote:
>> From: Jeffy Chen 
>>
>> Add the header for userspace
>
> General note: I saw four cases where this documentation referred to the
> datasheet. Three comments on that:
>
> 1) You don't say which datasheet.
> 2) I assume the datasheet is under NDA?

This datasheet can't be got by customers, even under NDA.

> 3) You do need to give enough information so a reasonable default can be
>used. I mentioned in an earlier review that creating an initial params
>struct that can be used as a templete would be helpful (or even
>required), and that would be a good place to put such defaults.
>

It don't need a default config
For applcation writers, they can just init it with zero data, and only
set value for the part they concerned.

As for ABI, i have checked there is no mismatches.
Those structures is 32 bit aligned both in 64bit/32bit env, since
there is no 64bit value.
"__attribute__ ((packed))" can avoid mismatches happen when we add a
64bit value to those structures.

As robin said, enums and bools are not guaranteed to be consistent
between different compiler, so it's a potential risk.
I have replace bools with unsigned char and enums with unsigned int.


> Regards,
>
> Hans


Re: [PATCH v5 03/16] media: rkisp1: Add user space ABI definitions

2018-03-08 Thread Jacob Chen
Hi Hans,

2018-02-07 20:00 GMT+08:00 Hans Verkuil :
> On 12/29/17 08:52, Shunqian Zheng wrote:
>> From: Jeffy Chen 
>>
>> Add the header for userspace
>
> General note: I saw four cases where this documentation referred to the
> datasheet. Three comments on that:
>
> 1) You don't say which datasheet.
> 2) I assume the datasheet is under NDA?

This datasheet can't be got by customers, even under NDA.

> 3) You do need to give enough information so a reasonable default can be
>used. I mentioned in an earlier review that creating an initial params
>struct that can be used as a templete would be helpful (or even
>required), and that would be a good place to put such defaults.
>

It don't need a default config
For applcation writers, they can just init it with zero data, and only
set value for the part they concerned.

As for ABI, i have checked there is no mismatches.
Those structures is 32 bit aligned both in 64bit/32bit env, since
there is no 64bit value.
"__attribute__ ((packed))" can avoid mismatches happen when we add a
64bit value to those structures.

As robin said, enums and bools are not guaranteed to be consistent
between different compiler, so it's a potential risk.
I have replace bools with unsigned char and enums with unsigned int.


> Regards,
>
> Hans


Re: [PATCH v5 02/16] media: doc: add document for rkisp1 meta buffer format

2018-03-08 Thread Jacob Chen
Hi Hans,

2018-02-06 22:27 GMT+08:00 Hans Verkuil <hverk...@xs4all.nl>:
> On 12/29/17 08:52, Shunqian Zheng wrote:
>> From: Jacob Chen <jacob2.c...@rock-chips.com>
>>
>> This commit add docuemnt for rkisp1 meta buffer format
>>
>> Signed-off-by: Jacob Chen <jacob-c...@rock-chips.com>
>> ---
>>  Documentation/media/uapi/v4l/meta-formats.rst  |  2 ++
>>  .../media/uapi/v4l/pixfmt-meta-rkisp1-params.rst   | 17 
>> +
>>  .../media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst | 18 
>> ++
>>  3 files changed, 37 insertions(+)
>>  create mode 100644 
>> Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
>>  create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
>>
>> diff --git a/Documentation/media/uapi/v4l/meta-formats.rst 
>> b/Documentation/media/uapi/v4l/meta-formats.rst
>> index 01e24e3..1b82814 100644
>> --- a/Documentation/media/uapi/v4l/meta-formats.rst
>> +++ b/Documentation/media/uapi/v4l/meta-formats.rst
>> @@ -14,3 +14,5 @@ These formats are used for the :ref:`metadata` interface 
>> only.
>>
>>  pixfmt-meta-vsp1-hgo
>>  pixfmt-meta-vsp1-hgt
>> +pixfmt-meta-rkisp1-params
>> +pixfmt-meta-rkisp1-stat
>> diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst 
>> b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
>> new file mode 100644
>> index 000..ed344d4
>> --- /dev/null
>> +++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
>> @@ -0,0 +1,17 @@
>> +.. -*- coding: utf-8; mode: rst -*-
>> +
>> +.. _v4l2-meta-fmt-rkisp1-params:
>> +
>> +***
>> +V4L2_META_FMT_RK_ISP1_PARAMS
>> +***
>> +
>> +Rockchip ISP1 Parameters Data
>> +
>> +Description
>> +===
>> +
>> +This format describes input parameters for the Rockchip ISP1.
>> +
>> +The data use c-struct :c:type:`rkisp1_isp_params_cfg`, which is defined in
>> +the ``linux/rkisp1-config.h`` header file, See it for details.
>
> One more question: does the ISP produce a reasonable picture if it doesn't
> receive these params? If not (i.e. you always need to provide params), then
> I think you should provide a default rkisp1_isp_params_cfg struct that
> can be used as a template for application writers.
>
> Perhaps it can be part of the driver as the initial params config.
>
> I think even if the ISP does work without params it is still worthwhile
> doing this. The params are complex and having an example on how to initialize
> it would be helpful.
>

The ISP don't need a default rkisp1_isp_params_cfg to produce picture,
those params just effect image quality and stats data.

The params are not very complex.
They consist of multiple modules and each of modules can be
enabled/disable/updated individually.

> Regards,
>
> Hans
>
>> diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst 
>> b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
>> new file mode 100644
>> index 000..5ecc403
>> --- /dev/null
>> +++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
>> @@ -0,0 +1,18 @@
>> +.. -*- coding: utf-8; mode: rst -*-
>> +
>> +.. _v4l2-meta-fmt-rkisp1-stat:
>> +
>> +***
>> +V4L2_META_FMT_RK_ISP1_STAT_3A
>> +***
>> +
>> +Rockchip ISP1 Statistics Data
>> +
>> +Description
>> +===
>> +
>> +This format describes image color statistics information generated by the 
>> Rockchip
>> +ISP1.
>> +
>> +The data use c-struct :c:type:`rkisp1_stat_buffer`, which is defined in
>> +the ``linux/cifisp_stat.h`` header file, See it for details.
>>
>


Re: [PATCH v5 02/16] media: doc: add document for rkisp1 meta buffer format

2018-03-08 Thread Jacob Chen
Hi Hans,

2018-02-06 22:27 GMT+08:00 Hans Verkuil :
> On 12/29/17 08:52, Shunqian Zheng wrote:
>> From: Jacob Chen 
>>
>> This commit add docuemnt for rkisp1 meta buffer format
>>
>> Signed-off-by: Jacob Chen 
>> ---
>>  Documentation/media/uapi/v4l/meta-formats.rst  |  2 ++
>>  .../media/uapi/v4l/pixfmt-meta-rkisp1-params.rst   | 17 
>> +
>>  .../media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst | 18 
>> ++
>>  3 files changed, 37 insertions(+)
>>  create mode 100644 
>> Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
>>  create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
>>
>> diff --git a/Documentation/media/uapi/v4l/meta-formats.rst 
>> b/Documentation/media/uapi/v4l/meta-formats.rst
>> index 01e24e3..1b82814 100644
>> --- a/Documentation/media/uapi/v4l/meta-formats.rst
>> +++ b/Documentation/media/uapi/v4l/meta-formats.rst
>> @@ -14,3 +14,5 @@ These formats are used for the :ref:`metadata` interface 
>> only.
>>
>>  pixfmt-meta-vsp1-hgo
>>  pixfmt-meta-vsp1-hgt
>> +pixfmt-meta-rkisp1-params
>> +pixfmt-meta-rkisp1-stat
>> diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst 
>> b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
>> new file mode 100644
>> index 000..ed344d4
>> --- /dev/null
>> +++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
>> @@ -0,0 +1,17 @@
>> +.. -*- coding: utf-8; mode: rst -*-
>> +
>> +.. _v4l2-meta-fmt-rkisp1-params:
>> +
>> +***
>> +V4L2_META_FMT_RK_ISP1_PARAMS
>> +***
>> +
>> +Rockchip ISP1 Parameters Data
>> +
>> +Description
>> +===
>> +
>> +This format describes input parameters for the Rockchip ISP1.
>> +
>> +The data use c-struct :c:type:`rkisp1_isp_params_cfg`, which is defined in
>> +the ``linux/rkisp1-config.h`` header file, See it for details.
>
> One more question: does the ISP produce a reasonable picture if it doesn't
> receive these params? If not (i.e. you always need to provide params), then
> I think you should provide a default rkisp1_isp_params_cfg struct that
> can be used as a template for application writers.
>
> Perhaps it can be part of the driver as the initial params config.
>
> I think even if the ISP does work without params it is still worthwhile
> doing this. The params are complex and having an example on how to initialize
> it would be helpful.
>

The ISP don't need a default rkisp1_isp_params_cfg to produce picture,
those params just effect image quality and stats data.

The params are not very complex.
They consist of multiple modules and each of modules can be
enabled/disable/updated individually.

> Regards,
>
> Hans
>
>> diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst 
>> b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
>> new file mode 100644
>> index 000..5ecc403
>> --- /dev/null
>> +++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
>> @@ -0,0 +1,18 @@
>> +.. -*- coding: utf-8; mode: rst -*-
>> +
>> +.. _v4l2-meta-fmt-rkisp1-stat:
>> +
>> +***
>> +V4L2_META_FMT_RK_ISP1_STAT_3A
>> +***
>> +
>> +Rockchip ISP1 Statistics Data
>> +
>> +Description
>> +===
>> +
>> +This format describes image color statistics information generated by the 
>> Rockchip
>> +ISP1.
>> +
>> +The data use c-struct :c:type:`rkisp1_stat_buffer`, which is defined in
>> +the ``linux/cifisp_stat.h`` header file, See it for details.
>>
>


[PATCH v6 01/17] media: videodev2.h, v4l2-ioctl: add rkisp1 meta buffer format

2018-03-08 Thread Jacob Chen
From: Shunqian Zheng <zhen...@rock-chips.com>

Add the Rockchip ISP1 specific processing parameter format
V4L2_META_FMT_RK_ISP1_PARAMS and metadata format
V4L2_META_FMT_RK_ISP1_STAT_3A for 3A.

Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++
 include/uapi/linux/videodev2.h   | 4 
 2 files changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 1be54429d601..bdd469290d66 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1257,6 +1257,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_META_FMT_VSP1_HGO:descr = "R-Car VSP1 1-D Histogram"; 
break;
case V4L2_META_FMT_VSP1_HGT:descr = "R-Car VSP1 2-D Histogram"; 
break;
case V4L2_META_FMT_UVC: descr = "UVC payload header metadata"; 
break;
+   case V4L2_META_FMT_RK_ISP1_PARAMS:  descr = "Rockchip ISP1 3A 
params"; break;
+   case V4L2_META_FMT_RK_ISP1_STAT_3A: descr = "Rockchip ISP1 3A 
statistics"; break;
 
default:
/* Compressed formats */
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index e20d10df75c1..359ad8bbf9bf 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -698,6 +698,10 @@ struct v4l2_pix_format {
 #define V4L2_META_FMT_VSP1_HGTv4l2_fourcc('V', 'S', 'P', 'T') /* R-Car 
VSP1 2-D Histogram */
 #define V4L2_META_FMT_UVC v4l2_fourcc('U', 'V', 'C', 'H') /* UVC 
Payload Header metadata */
 
+/* Vendor specific - used for IPU3 camera sub-system */
+#define V4L2_META_FMT_RK_ISP1_PARAMS   v4l2_fourcc('R', 'K', '1', 'P') /* 
Rockchip ISP1 params */
+#define V4L2_META_FMT_RK_ISP1_STAT_3A  v4l2_fourcc('R', 'K', '1', 'S') /* 
Rockchip ISP1 3A statistics */
+
 /* priv field value to indicates that subsequent fields are valid. */
 #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe
 
-- 
2.16.1



[PATCH v6 01/17] media: videodev2.h, v4l2-ioctl: add rkisp1 meta buffer format

2018-03-08 Thread Jacob Chen
From: Shunqian Zheng 

Add the Rockchip ISP1 specific processing parameter format
V4L2_META_FMT_RK_ISP1_PARAMS and metadata format
V4L2_META_FMT_RK_ISP1_STAT_3A for 3A.

Signed-off-by: Shunqian Zheng 
Signed-off-by: Jacob Chen 
Acked-by: Hans Verkuil 
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++
 include/uapi/linux/videodev2.h   | 4 
 2 files changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 1be54429d601..bdd469290d66 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1257,6 +1257,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_META_FMT_VSP1_HGO:descr = "R-Car VSP1 1-D Histogram"; 
break;
case V4L2_META_FMT_VSP1_HGT:descr = "R-Car VSP1 2-D Histogram"; 
break;
case V4L2_META_FMT_UVC: descr = "UVC payload header metadata"; 
break;
+   case V4L2_META_FMT_RK_ISP1_PARAMS:  descr = "Rockchip ISP1 3A 
params"; break;
+   case V4L2_META_FMT_RK_ISP1_STAT_3A: descr = "Rockchip ISP1 3A 
statistics"; break;
 
default:
/* Compressed formats */
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index e20d10df75c1..359ad8bbf9bf 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -698,6 +698,10 @@ struct v4l2_pix_format {
 #define V4L2_META_FMT_VSP1_HGTv4l2_fourcc('V', 'S', 'P', 'T') /* R-Car 
VSP1 2-D Histogram */
 #define V4L2_META_FMT_UVC v4l2_fourcc('U', 'V', 'C', 'H') /* UVC 
Payload Header metadata */
 
+/* Vendor specific - used for IPU3 camera sub-system */
+#define V4L2_META_FMT_RK_ISP1_PARAMS   v4l2_fourcc('R', 'K', '1', 'P') /* 
Rockchip ISP1 params */
+#define V4L2_META_FMT_RK_ISP1_STAT_3A  v4l2_fourcc('R', 'K', '1', 'S') /* 
Rockchip ISP1 3A statistics */
+
 /* priv field value to indicates that subsequent fields are valid. */
 #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe
 
-- 
2.16.1



[PATCH v6 04/17] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 868 +
 .../media/platform/rockchip/isp1/mipi_dphy_sy.h|  15 +
 2 files changed, 883 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.h

diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c 
b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
new file mode 100644
index ..32140960557a
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
@@ -0,0 +1,868 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip MIPI Synopsys DPHY driver
+ *
+ * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RK3288_GRF_SOC_CON60x025c
+#define RK3288_GRF_SOC_CON80x0264
+#define RK3288_GRF_SOC_CON90x0268
+#define RK3288_GRF_SOC_CON10   0x026c
+#define RK3288_GRF_SOC_CON14   0x027c
+#define RK3288_GRF_SOC_STATUS210x02d4
+#define RK3288_GRF_IO_VSEL 0x0380
+#define RK3288_GRF_SOC_CON15   0x03a4
+
+#define RK3399_GRF_SOC_CON90x6224
+#define RK3399_GRF_SOC_CON21   0x6254
+#define RK3399_GRF_SOC_CON22   0x6258
+#define RK3399_GRF_SOC_CON23   0x625c
+#define RK3399_GRF_SOC_CON24   0x6260
+#define RK3399_GRF_SOC_CON25   0x6264
+#define RK3399_GRF_SOC_STATUS1 0xe2a4
+
+#define CLOCK_LANE_HS_RX_CONTROL   0x34
+#define LANE0_HS_RX_CONTROL0x44
+#define LANE1_HS_RX_CONTROL0x54
+#define LANE2_HS_RX_CONTROL0x84
+#define LANE3_HS_RX_CONTROL0x94
+#define HS_RX_DATA_LANES_THS_SETTLE_CONTROL0x75
+
+/*
+ * CSI HOST
+ */
+#define CSIHOST_PHY_TEST_CTRL0 0x30
+#define CSIHOST_PHY_TEST_CTRL1 0x34
+#define CSIHOST_PHY_SHUTDOWNZ  0x08
+#define CSIHOST_DPHY_RSTZ  0x0c
+
+#define PHY_TESTEN_ADDR(0x1 << 16)
+#define PHY_TESTEN_DATA(0x0 << 16)
+#define PHY_TESTCLK(0x1 << 1)
+#define PHY_TESTCLR(0x1 << 0)
+#define THS_SETTLE_COUNTER_THRESHOLD   0x04
+
+#define HIWORD_UPDATE(val, mask, shift) \
+   ((val) << (shift) | (mask) << ((shift) + 16))
+
+enum mipi_dphy_sy_pads {
+   MIPI_DPHY_SY_PAD_SINK = 0,
+   MIPI_DPHY_SY_PAD_SOURCE,
+   MIPI_DPHY_SY_PADS_NUM,
+};
+
+enum dphy_reg_id {
+   GRF_DPHY_RX0_TURNDISABLE = 0,
+   GRF_DPHY_RX0_FORCERXMODE,
+   GRF_DPHY_RX0_FORCETXSTOPMODE,
+   GRF_DPHY_RX0_ENABLE,
+   GRF_DPHY_RX0_TESTCLR,
+   GRF_DPHY_RX0_TESTCLK,
+   GRF_DPHY_RX0_TESTEN,
+   GRF_DPHY_RX0_TESTDIN,
+   GRF_DPHY_RX0_TURNREQUEST,
+   GRF_DPHY_RX0_TESTDOUT,
+   GRF_DPHY_TX0_TURNDISABLE,
+   GRF_DPHY_TX0_FORCERXMODE,
+   GRF_DPHY_TX0_FORCETXSTOPMODE,
+   GRF_DPHY_TX0_TURNREQUEST,
+   GRF_DPHY_TX1RX1_TURNDISABLE,
+   GRF_DPHY_TX1RX1_FORCERXMODE,
+   GRF_DPHY_TX1RX1_FORCETXSTOPMODE,
+   GRF_DPHY_TX1RX1_ENABLE,
+   GRF_DPHY_TX1RX1_MASTERSLAVEZ,
+   GRF_DPHY_TX1RX1_BASEDIR,
+   GRF_DPHY_TX1RX1_ENABLECLK,
+   GRF_DPHY_TX1RX1_TURNREQUEST,
+   GRF_DPHY_RX1_SRC_SEL,
+   /* rk3288 only */
+   GRF_CON_DISABLE_ISP,
+   GRF_CON_ISP_DPHY_SEL,
+   GRF_DSI_CSI_TESTBUS_SEL,
+   GRF_DVP_V18SEL,
+   /* below is for rk3399 only */
+   GRF_DPHY_RX0_CLK_INV_SEL,
+   GRF_DPHY_RX1_CLK_INV_SEL,
+};
+
+struct dphy_reg {
+   u32 offset;
+   u32 mask;
+   u32 shift;
+};
+
+#define PHY_REG(_offset, _width, _shift) \
+   { .offset = _offset, .mask = BIT(_width) - 1, .shift = _shift, }
+
+static const struct dphy_reg rk3399_grf_dphy_regs[] = {
+   [GRF_DPHY_RX0_TURNREQUEST] = PHY_REG(RK3399_GRF_SOC_CON9, 4, 0),
+   [GRF_DPHY_RX0_CLK_INV_SEL] = PHY_REG(RK3399_GRF_SOC_CON9, 1, 10),
+   [GRF_DPHY_RX1_CLK_INV_SEL] = PHY_REG(RK3399_GRF_SOC_CON9, 1, 11),
+   [GRF_DPHY_RX0_ENABLE] = PHY_REG(RK3399_GRF_SOC_CON21, 4, 0),
+   [GRF_DPHY_RX0_FORCERXMODE] = PHY_REG(RK3399_GRF_SOC_CON21, 4, 4),
+   [GRF_DPHY_RX0_FORCETXSTOPMODE] = PHY_REG(RK3399_GRF_SOC_CON21, 4, 8),
+   [GRF_DPHY_RX0_TURNDISABLE] = PHY_REG(RK3399_GRF_SOC_CON21, 4, 12),
+   [GRF_DPHY_TX0_FORCERXMODE] = PHY_REG(RK3399_GRF_SOC_CON22, 4, 0),
+   [GRF_DPHY_TX0_FORCETXSTOPMODE] = PHY_REG(RK3399_GRF_SOC_CON22, 4, 4),
+   [GRF_DPHY_TX0_TURNDISABLE] = PHY_REG(RK3399_GRF_SOC_CON22, 4, 8),
+   [GRF_DPHY_TX0_TURNREQUEST] = PHY_REG(RK3399_GRF_SOC_CON22, 4, 12),
+   [

[PATCH v6 04/17] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Tomasz Figa 
---
 .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 868 +
 .../media/platform/rockchip/isp1/mipi_dphy_sy.h|  15 +
 2 files changed, 883 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.h

diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c 
b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
new file mode 100644
index ..32140960557a
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
@@ -0,0 +1,868 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip MIPI Synopsys DPHY driver
+ *
+ * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RK3288_GRF_SOC_CON60x025c
+#define RK3288_GRF_SOC_CON80x0264
+#define RK3288_GRF_SOC_CON90x0268
+#define RK3288_GRF_SOC_CON10   0x026c
+#define RK3288_GRF_SOC_CON14   0x027c
+#define RK3288_GRF_SOC_STATUS210x02d4
+#define RK3288_GRF_IO_VSEL 0x0380
+#define RK3288_GRF_SOC_CON15   0x03a4
+
+#define RK3399_GRF_SOC_CON90x6224
+#define RK3399_GRF_SOC_CON21   0x6254
+#define RK3399_GRF_SOC_CON22   0x6258
+#define RK3399_GRF_SOC_CON23   0x625c
+#define RK3399_GRF_SOC_CON24   0x6260
+#define RK3399_GRF_SOC_CON25   0x6264
+#define RK3399_GRF_SOC_STATUS1 0xe2a4
+
+#define CLOCK_LANE_HS_RX_CONTROL   0x34
+#define LANE0_HS_RX_CONTROL0x44
+#define LANE1_HS_RX_CONTROL0x54
+#define LANE2_HS_RX_CONTROL0x84
+#define LANE3_HS_RX_CONTROL0x94
+#define HS_RX_DATA_LANES_THS_SETTLE_CONTROL0x75
+
+/*
+ * CSI HOST
+ */
+#define CSIHOST_PHY_TEST_CTRL0 0x30
+#define CSIHOST_PHY_TEST_CTRL1 0x34
+#define CSIHOST_PHY_SHUTDOWNZ  0x08
+#define CSIHOST_DPHY_RSTZ  0x0c
+
+#define PHY_TESTEN_ADDR(0x1 << 16)
+#define PHY_TESTEN_DATA(0x0 << 16)
+#define PHY_TESTCLK(0x1 << 1)
+#define PHY_TESTCLR(0x1 << 0)
+#define THS_SETTLE_COUNTER_THRESHOLD   0x04
+
+#define HIWORD_UPDATE(val, mask, shift) \
+   ((val) << (shift) | (mask) << ((shift) + 16))
+
+enum mipi_dphy_sy_pads {
+   MIPI_DPHY_SY_PAD_SINK = 0,
+   MIPI_DPHY_SY_PAD_SOURCE,
+   MIPI_DPHY_SY_PADS_NUM,
+};
+
+enum dphy_reg_id {
+   GRF_DPHY_RX0_TURNDISABLE = 0,
+   GRF_DPHY_RX0_FORCERXMODE,
+   GRF_DPHY_RX0_FORCETXSTOPMODE,
+   GRF_DPHY_RX0_ENABLE,
+   GRF_DPHY_RX0_TESTCLR,
+   GRF_DPHY_RX0_TESTCLK,
+   GRF_DPHY_RX0_TESTEN,
+   GRF_DPHY_RX0_TESTDIN,
+   GRF_DPHY_RX0_TURNREQUEST,
+   GRF_DPHY_RX0_TESTDOUT,
+   GRF_DPHY_TX0_TURNDISABLE,
+   GRF_DPHY_TX0_FORCERXMODE,
+   GRF_DPHY_TX0_FORCETXSTOPMODE,
+   GRF_DPHY_TX0_TURNREQUEST,
+   GRF_DPHY_TX1RX1_TURNDISABLE,
+   GRF_DPHY_TX1RX1_FORCERXMODE,
+   GRF_DPHY_TX1RX1_FORCETXSTOPMODE,
+   GRF_DPHY_TX1RX1_ENABLE,
+   GRF_DPHY_TX1RX1_MASTERSLAVEZ,
+   GRF_DPHY_TX1RX1_BASEDIR,
+   GRF_DPHY_TX1RX1_ENABLECLK,
+   GRF_DPHY_TX1RX1_TURNREQUEST,
+   GRF_DPHY_RX1_SRC_SEL,
+   /* rk3288 only */
+   GRF_CON_DISABLE_ISP,
+   GRF_CON_ISP_DPHY_SEL,
+   GRF_DSI_CSI_TESTBUS_SEL,
+   GRF_DVP_V18SEL,
+   /* below is for rk3399 only */
+   GRF_DPHY_RX0_CLK_INV_SEL,
+   GRF_DPHY_RX1_CLK_INV_SEL,
+};
+
+struct dphy_reg {
+   u32 offset;
+   u32 mask;
+   u32 shift;
+};
+
+#define PHY_REG(_offset, _width, _shift) \
+   { .offset = _offset, .mask = BIT(_width) - 1, .shift = _shift, }
+
+static const struct dphy_reg rk3399_grf_dphy_regs[] = {
+   [GRF_DPHY_RX0_TURNREQUEST] = PHY_REG(RK3399_GRF_SOC_CON9, 4, 0),
+   [GRF_DPHY_RX0_CLK_INV_SEL] = PHY_REG(RK3399_GRF_SOC_CON9, 1, 10),
+   [GRF_DPHY_RX1_CLK_INV_SEL] = PHY_REG(RK3399_GRF_SOC_CON9, 1, 11),
+   [GRF_DPHY_RX0_ENABLE] = PHY_REG(RK3399_GRF_SOC_CON21, 4, 0),
+   [GRF_DPHY_RX0_FORCERXMODE] = PHY_REG(RK3399_GRF_SOC_CON21, 4, 4),
+   [GRF_DPHY_RX0_FORCETXSTOPMODE] = PHY_REG(RK3399_GRF_SOC_CON21, 4, 8),
+   [GRF_DPHY_RX0_TURNDISABLE] = PHY_REG(RK3399_GRF_SOC_CON21, 4, 12),
+   [GRF_DPHY_TX0_FORCERXMODE] = PHY_REG(RK3399_GRF_SOC_CON22, 4, 0),
+   [GRF_DPHY_TX0_FORCETXSTOPMODE] = PHY_REG(RK3399_GRF_SOC_CON22, 4, 4),
+   [GRF_DPHY_TX0_TURNDISABLE] = PHY_REG(RK3399_GRF_SOC_CON22, 4, 8),
+   [GRF_DPHY_TX0_TURNREQUEST] = PHY_REG(RK3399_GRF_SOC_CON22, 4, 12),
+   [GRF_DPHY_TX1RX1_ENABLE] = PHY_REG(RK3399_GRF_SOC_CON23, 4, 0),
+   [GRF_DPHY_TX1RX1_FORCERXMODE] 

[PATCH v6 06/17] media: rkisp1: add ISP1 statistics driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add the capture video driver for rockchip isp1 statistics block.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Yichong Zhong <z...@rock-chips.com>
Signed-off-by: Jacob Chen <c...@rock-chips.com>
Signed-off-by: Eddie Cai <eddie.cai.li...@gmail.com>
Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com>
Signed-off-by: Allon Huang <allon.hu...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 drivers/media/platform/rockchip/isp1/isp_stats.c | 508 +++
 drivers/media/platform/rockchip/isp1/isp_stats.h |  58 +++
 2 files changed, 566 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.h

diff --git a/drivers/media/platform/rockchip/isp1/isp_stats.c 
b/drivers/media/platform/rockchip/isp1/isp_stats.c
new file mode 100644
index ..3ba86ccbc42d
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/isp_stats.c
@@ -0,0 +1,508 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include/* for ISP statistics */
+#include "dev.h"
+#include "regs.h"
+
+#define RKISP1_ISP_STATS_REQ_BUFS_MIN 2
+#define RKISP1_ISP_STATS_REQ_BUFS_MAX 8
+
+static int rkisp1_stats_enum_fmt_meta_cap(struct file *file, void *priv,
+ struct v4l2_fmtdesc *f)
+{
+   struct video_device *video = video_devdata(file);
+   struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(video);
+
+   if (f->index > 0 || f->type != video->queue->type)
+   return -EINVAL;
+
+   f->pixelformat = stats_vdev->vdev_fmt.fmt.meta.dataformat;
+   return 0;
+}
+
+static int rkisp1_stats_g_fmt_meta_cap(struct file *file, void *priv,
+  struct v4l2_format *f)
+{
+   struct video_device *video = video_devdata(file);
+   struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(video);
+   struct v4l2_meta_format *meta = >fmt.meta;
+
+   if (f->type != video->queue->type)
+   return -EINVAL;
+
+   memset(meta, 0, sizeof(*meta));
+   meta->dataformat = stats_vdev->vdev_fmt.fmt.meta.dataformat;
+   meta->buffersize = stats_vdev->vdev_fmt.fmt.meta.buffersize;
+
+   return 0;
+}
+
+static int rkisp1_stats_querycap(struct file *file,
+void *priv, struct v4l2_capability *cap)
+{
+   struct video_device *vdev = video_devdata(file);
+
+   strlcpy(cap->driver, DRIVER_NAME, sizeof(cap->driver));
+   strlcpy(cap->card, vdev->name, sizeof(cap->card));
+   strlcpy(cap->bus_info, "platform: " DRIVER_NAME, sizeof(cap->bus_info));
+
+   return 0;
+}
+
+/* ISP video device IOCTLs */
+static const struct v4l2_ioctl_ops rkisp1_stats_ioctl = {
+   .vidioc_reqbufs = vb2_ioctl_reqbufs,
+   .vidioc_querybuf = vb2_ioctl_querybuf,
+   .vidioc_create_bufs = vb2_ioctl_create_bufs,
+   .vidioc_qbuf = vb2_ioctl_qbuf,
+   .vidioc_dqbuf = vb2_ioctl_dqbuf,
+   .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+   .vidioc_expbuf = vb2_ioctl_expbuf,
+   .vidioc_streamon = vb2_ioctl_streamon,
+   .vidioc_streamoff = vb2_ioctl_streamoff,
+   .vidioc_enum_fmt_meta_cap = rkisp1_stats_enum_fmt_meta_cap,
+   .vidioc_g_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
+   .vidioc_s_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
+   .vidioc_try_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
+   .vidioc_querycap = rkisp1_stats_querycap,
+   .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
+   .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+};
+
+struct v4l2_file_operations rkisp1_stats_fops = {
+   .mmap = vb2_fop_mmap,
+   .unlocked_ioctl = video_ioctl2,
+   .poll = vb2_fop_poll,
+   .open = v4l2_fh_open,
+   .release = vb2_fop_release
+};
+
+static int rkisp1_stats_vb2_queue_setup(struct vb2_queue *vq,
+   unsigned int *num_buffers,
+   unsigned int *num_planes,
+   unsigned int sizes[],
+   struct device *alloc_devs[])
+{
+   struct rkisp1_isp_stats_vdev *stats_vdev = vq->drv_priv;
+
+   *num_planes = 1;
+
+   *num_buffers = clamp_t(u32, *num_buffers, RKISP1_ISP_STATS_REQ_BUFS_MIN,
+  RKISP1_ISP_STATS_REQ_BUFS_MAX);
+
+   sizes[0] = sizeof(struct rkisp1_stat_buffer);
+
+   INIT_LIST_HEAD(_vdev->stat);
+
+   return 0;
+}
+
+static void rkisp1_stats_vb2_buf_queue(struct vb2_bu

[PATCH v6 06/17] media: rkisp1: add ISP1 statistics driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add the capture video driver for rockchip isp1 statistics block.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/isp_stats.c | 508 +++
 drivers/media/platform/rockchip/isp1/isp_stats.h |  58 +++
 2 files changed, 566 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.h

diff --git a/drivers/media/platform/rockchip/isp1/isp_stats.c 
b/drivers/media/platform/rockchip/isp1/isp_stats.c
new file mode 100644
index ..3ba86ccbc42d
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/isp_stats.c
@@ -0,0 +1,508 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include/* for ISP statistics */
+#include "dev.h"
+#include "regs.h"
+
+#define RKISP1_ISP_STATS_REQ_BUFS_MIN 2
+#define RKISP1_ISP_STATS_REQ_BUFS_MAX 8
+
+static int rkisp1_stats_enum_fmt_meta_cap(struct file *file, void *priv,
+ struct v4l2_fmtdesc *f)
+{
+   struct video_device *video = video_devdata(file);
+   struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(video);
+
+   if (f->index > 0 || f->type != video->queue->type)
+   return -EINVAL;
+
+   f->pixelformat = stats_vdev->vdev_fmt.fmt.meta.dataformat;
+   return 0;
+}
+
+static int rkisp1_stats_g_fmt_meta_cap(struct file *file, void *priv,
+  struct v4l2_format *f)
+{
+   struct video_device *video = video_devdata(file);
+   struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(video);
+   struct v4l2_meta_format *meta = >fmt.meta;
+
+   if (f->type != video->queue->type)
+   return -EINVAL;
+
+   memset(meta, 0, sizeof(*meta));
+   meta->dataformat = stats_vdev->vdev_fmt.fmt.meta.dataformat;
+   meta->buffersize = stats_vdev->vdev_fmt.fmt.meta.buffersize;
+
+   return 0;
+}
+
+static int rkisp1_stats_querycap(struct file *file,
+void *priv, struct v4l2_capability *cap)
+{
+   struct video_device *vdev = video_devdata(file);
+
+   strlcpy(cap->driver, DRIVER_NAME, sizeof(cap->driver));
+   strlcpy(cap->card, vdev->name, sizeof(cap->card));
+   strlcpy(cap->bus_info, "platform: " DRIVER_NAME, sizeof(cap->bus_info));
+
+   return 0;
+}
+
+/* ISP video device IOCTLs */
+static const struct v4l2_ioctl_ops rkisp1_stats_ioctl = {
+   .vidioc_reqbufs = vb2_ioctl_reqbufs,
+   .vidioc_querybuf = vb2_ioctl_querybuf,
+   .vidioc_create_bufs = vb2_ioctl_create_bufs,
+   .vidioc_qbuf = vb2_ioctl_qbuf,
+   .vidioc_dqbuf = vb2_ioctl_dqbuf,
+   .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+   .vidioc_expbuf = vb2_ioctl_expbuf,
+   .vidioc_streamon = vb2_ioctl_streamon,
+   .vidioc_streamoff = vb2_ioctl_streamoff,
+   .vidioc_enum_fmt_meta_cap = rkisp1_stats_enum_fmt_meta_cap,
+   .vidioc_g_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
+   .vidioc_s_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
+   .vidioc_try_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
+   .vidioc_querycap = rkisp1_stats_querycap,
+   .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
+   .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+};
+
+struct v4l2_file_operations rkisp1_stats_fops = {
+   .mmap = vb2_fop_mmap,
+   .unlocked_ioctl = video_ioctl2,
+   .poll = vb2_fop_poll,
+   .open = v4l2_fh_open,
+   .release = vb2_fop_release
+};
+
+static int rkisp1_stats_vb2_queue_setup(struct vb2_queue *vq,
+   unsigned int *num_buffers,
+   unsigned int *num_planes,
+   unsigned int sizes[],
+   struct device *alloc_devs[])
+{
+   struct rkisp1_isp_stats_vdev *stats_vdev = vq->drv_priv;
+
+   *num_planes = 1;
+
+   *num_buffers = clamp_t(u32, *num_buffers, RKISP1_ISP_STATS_REQ_BUFS_MIN,
+  RKISP1_ISP_STATS_REQ_BUFS_MAX);
+
+   sizes[0] = sizeof(struct rkisp1_stat_buffer);
+
+   INIT_LIST_HEAD(_vdev->stat);
+
+   return 0;
+}
+
+static void rkisp1_stats_vb2_buf_queue(struct vb2_buffer *vb)
+{
+   struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+   struct rkisp1_buffer *stats_buf = to_rkisp1_buffer(vbuf);
+   struct vb2_queue *vq = vb->vb2_queue;
+   struct rkisp1_isp_stats_vdev *stats_dev = vq->drv_priv;
+   unsigned 

[PATCH v6 08/17] media: rkisp1: add capture device driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

This is the capture device interface driver that provides the v4l2
user interface. Frames can be received from ISP1.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Yichong Zhong <z...@rock-chips.com>
Signed-off-by: Jacob Chen <c...@rock-chips.com>
Signed-off-by: Eddie Cai <eddie.cai.li...@gmail.com>
Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com>
Signed-off-by: Allon Huang <allon.hu...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 drivers/media/platform/rockchip/isp1/capture.c | 1751 
 drivers/media/platform/rockchip/isp1/capture.h |  167 +++
 drivers/media/platform/rockchip/isp1/regs.c|  239 
 drivers/media/platform/rockchip/isp1/regs.h| 1550 +
 4 files changed, 3707 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.c
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.h
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.c
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.h

diff --git a/drivers/media/platform/rockchip/isp1/capture.c 
b/drivers/media/platform/rockchip/isp1/capture.c
new file mode 100644
index ..53484f882704
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/capture.c
@@ -0,0 +1,1751 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "dev.h"
+#include "regs.h"
+
+/*
+ * NOTE:
+ * 1. There are two capture video devices in rkisp1, selfpath and mainpath
+ * 2. Two capture device have separated memory-interface/crop/scale units.
+ * 3. Besides describing stream hardware, this file also contain entries
+ *for pipeline operations.
+ * 4. The register read/write operations in this file are put into regs.c.
+ */
+
+/*
+ * differences between selfpatch and mainpath
+ * available mp sink input: isp
+ * available sp sink input : isp, dma(TODO)
+ * available mp sink pad fmts: yuv422, raw
+ * available sp sink pad fmts: yuv422, yuv420..
+ * available mp source fmts: yuv, raw, jpeg(TODO)
+ * available sp source fmts: yuv, rgb
+ */
+
+#define CIF_ISP_REQ_BUFS_MIN 1
+#define CIF_ISP_REQ_BUFS_MAX 8
+
+#define STREAM_PAD_SINK0
+#define STREAM_PAD_SOURCE  1
+
+#define STREAM_MAX_MP_RSZ_OUTPUT_WIDTH 4416
+#define STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT3312
+#define STREAM_MAX_SP_RSZ_OUTPUT_WIDTH 1920
+#define STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT1920
+#define STREAM_MIN_RSZ_OUTPUT_WIDTH32
+#define STREAM_MIN_RSZ_OUTPUT_HEIGHT   16
+
+#define STREAM_MAX_MP_SP_INPUT_WIDTH STREAM_MAX_MP_RSZ_OUTPUT_WIDTH
+#define STREAM_MAX_MP_SP_INPUT_HEIGHT STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT
+#define STREAM_MIN_MP_SP_INPUT_WIDTH   32
+#define STREAM_MIN_MP_SP_INPUT_HEIGHT  32
+
+/* Get xsubs and ysubs for fourcc formats
+ *
+ * @xsubs: horizontal color samples in a 4*4 matrix, for yuv
+ * @ysubs: vertical color samples in a 4*4 matrix, for yuv
+ */
+static int fcc_xysubs(u32 fcc, u32 *xsubs, u32 *ysubs)
+{
+   switch (fcc) {
+   case V4L2_PIX_FMT_GREY:
+   case V4L2_PIX_FMT_YUV444M:
+   *xsubs = 1;
+   *ysubs = 1;
+   break;
+   case V4L2_PIX_FMT_YUYV:
+   case V4L2_PIX_FMT_YVYU:
+   case V4L2_PIX_FMT_VYUY:
+   case V4L2_PIX_FMT_YUV422P:
+   case V4L2_PIX_FMT_NV16:
+   case V4L2_PIX_FMT_NV61:
+   case V4L2_PIX_FMT_YVU422M:
+   *xsubs = 2;
+   *ysubs = 1;
+   break;
+   case V4L2_PIX_FMT_NV21:
+   case V4L2_PIX_FMT_NV12:
+   case V4L2_PIX_FMT_NV21M:
+   case V4L2_PIX_FMT_NV12M:
+   case V4L2_PIX_FMT_YUV420:
+   case V4L2_PIX_FMT_YVU420:
+   *xsubs = 2;
+   *ysubs = 2;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int mbus_code_xysubs(u32 code, u32 *xsubs, u32 *ysubs)
+{
+   switch (code) {
+   case MEDIA_BUS_FMT_YUYV8_2X8:
+   case MEDIA_BUS_FMT_YUYV8_1X16:
+   case MEDIA_BUS_FMT_YVYU8_1X16:
+   case MEDIA_BUS_FMT_UYVY8_1X16:
+   case MEDIA_BUS_FMT_VYUY8_1X16:
+   *xsubs = 2;
+   *ysubs = 1;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int mbus_code_sp_in_fmt(u32 code, u32 *format)
+{
+   switch (code) {
+   case MEDIA_BUS_FMT_YUYV8_2X8:
+   *format = MI_CTRL_SP_INPUT_YUV422;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   retur

[PATCH v6 08/17] media: rkisp1: add capture device driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

This is the capture device interface driver that provides the v4l2
user interface. Frames can be received from ISP1.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/capture.c | 1751 
 drivers/media/platform/rockchip/isp1/capture.h |  167 +++
 drivers/media/platform/rockchip/isp1/regs.c|  239 
 drivers/media/platform/rockchip/isp1/regs.h| 1550 +
 4 files changed, 3707 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.c
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.h
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.c
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.h

diff --git a/drivers/media/platform/rockchip/isp1/capture.c 
b/drivers/media/platform/rockchip/isp1/capture.c
new file mode 100644
index ..53484f882704
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/capture.c
@@ -0,0 +1,1751 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "dev.h"
+#include "regs.h"
+
+/*
+ * NOTE:
+ * 1. There are two capture video devices in rkisp1, selfpath and mainpath
+ * 2. Two capture device have separated memory-interface/crop/scale units.
+ * 3. Besides describing stream hardware, this file also contain entries
+ *for pipeline operations.
+ * 4. The register read/write operations in this file are put into regs.c.
+ */
+
+/*
+ * differences between selfpatch and mainpath
+ * available mp sink input: isp
+ * available sp sink input : isp, dma(TODO)
+ * available mp sink pad fmts: yuv422, raw
+ * available sp sink pad fmts: yuv422, yuv420..
+ * available mp source fmts: yuv, raw, jpeg(TODO)
+ * available sp source fmts: yuv, rgb
+ */
+
+#define CIF_ISP_REQ_BUFS_MIN 1
+#define CIF_ISP_REQ_BUFS_MAX 8
+
+#define STREAM_PAD_SINK0
+#define STREAM_PAD_SOURCE  1
+
+#define STREAM_MAX_MP_RSZ_OUTPUT_WIDTH 4416
+#define STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT3312
+#define STREAM_MAX_SP_RSZ_OUTPUT_WIDTH 1920
+#define STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT1920
+#define STREAM_MIN_RSZ_OUTPUT_WIDTH32
+#define STREAM_MIN_RSZ_OUTPUT_HEIGHT   16
+
+#define STREAM_MAX_MP_SP_INPUT_WIDTH STREAM_MAX_MP_RSZ_OUTPUT_WIDTH
+#define STREAM_MAX_MP_SP_INPUT_HEIGHT STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT
+#define STREAM_MIN_MP_SP_INPUT_WIDTH   32
+#define STREAM_MIN_MP_SP_INPUT_HEIGHT  32
+
+/* Get xsubs and ysubs for fourcc formats
+ *
+ * @xsubs: horizontal color samples in a 4*4 matrix, for yuv
+ * @ysubs: vertical color samples in a 4*4 matrix, for yuv
+ */
+static int fcc_xysubs(u32 fcc, u32 *xsubs, u32 *ysubs)
+{
+   switch (fcc) {
+   case V4L2_PIX_FMT_GREY:
+   case V4L2_PIX_FMT_YUV444M:
+   *xsubs = 1;
+   *ysubs = 1;
+   break;
+   case V4L2_PIX_FMT_YUYV:
+   case V4L2_PIX_FMT_YVYU:
+   case V4L2_PIX_FMT_VYUY:
+   case V4L2_PIX_FMT_YUV422P:
+   case V4L2_PIX_FMT_NV16:
+   case V4L2_PIX_FMT_NV61:
+   case V4L2_PIX_FMT_YVU422M:
+   *xsubs = 2;
+   *ysubs = 1;
+   break;
+   case V4L2_PIX_FMT_NV21:
+   case V4L2_PIX_FMT_NV12:
+   case V4L2_PIX_FMT_NV21M:
+   case V4L2_PIX_FMT_NV12M:
+   case V4L2_PIX_FMT_YUV420:
+   case V4L2_PIX_FMT_YVU420:
+   *xsubs = 2;
+   *ysubs = 2;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int mbus_code_xysubs(u32 code, u32 *xsubs, u32 *ysubs)
+{
+   switch (code) {
+   case MEDIA_BUS_FMT_YUYV8_2X8:
+   case MEDIA_BUS_FMT_YUYV8_1X16:
+   case MEDIA_BUS_FMT_YVYU8_1X16:
+   case MEDIA_BUS_FMT_UYVY8_1X16:
+   case MEDIA_BUS_FMT_VYUY8_1X16:
+   *xsubs = 2;
+   *ysubs = 1;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int mbus_code_sp_in_fmt(u32 code, u32 *format)
+{
+   switch (code) {
+   case MEDIA_BUS_FMT_YUYV8_2X8:
+   *format = MI_CTRL_SP_INPUT_YUV422;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static const struct capture_fmt mp_fmts[] = {
+   /* yuv422 */
+   {
+   .fourcc = V4L2_PIX_FMT_YUYV,
+   .fmt_type = FMT_YUV,
+   .bpp = { 16 },
+   .cplanes = 1,
+   .mplanes = 1,
+   .uv_swap = 0,
+

[PATCH v6 12/17] ARM: dts: rockchip: add isp node for rk3288

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

rk3288 have a Embedded 13M ISP

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 arch/arm/boot/dts/rk3288.dtsi | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index ad6bda85c85a..6c122aaf06a7 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -962,6 +962,23 @@
status = "disabled";
};
 
+   isp: isp@ff91 {
+   compatible = "rockchip,rk3288-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP>, < ACLK_ISP>,
+< HCLK_ISP>, < PCLK_ISP_IN>,
+< SCLK_ISP_JPE>;
+   clock-names = "clk_isp", "aclk_isp",
+ "hclk_isp", "pclk_isp_in",
+ "sclk_isp_jpe";
+   assigned-clocks = < SCLK_ISP>, < SCLK_ISP_JPE>;
+   assigned-clock-rates = <4>, <4>;
+   power-domains = < RK3288_PD_VIO>;
+   iommus = <_mmu>;
+   status = "disabled";
+   };
+
isp_mmu: iommu@ff914000 {
compatible = "rockchip,iommu";
reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
-- 
2.16.1



[PATCH v6 12/17] ARM: dts: rockchip: add isp node for rk3288

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

rk3288 have a Embedded 13M ISP

Signed-off-by: Jacob Chen 
---
 arch/arm/boot/dts/rk3288.dtsi | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index ad6bda85c85a..6c122aaf06a7 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -962,6 +962,23 @@
status = "disabled";
};
 
+   isp: isp@ff91 {
+   compatible = "rockchip,rk3288-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP>, < ACLK_ISP>,
+< HCLK_ISP>, < PCLK_ISP_IN>,
+< SCLK_ISP_JPE>;
+   clock-names = "clk_isp", "aclk_isp",
+ "hclk_isp", "pclk_isp_in",
+ "sclk_isp_jpe";
+   assigned-clocks = < SCLK_ISP>, < SCLK_ISP_JPE>;
+   assigned-clock-rates = <4>, <4>;
+   power-domains = < RK3288_PD_VIO>;
+   iommus = <_mmu>;
+   status = "disabled";
+   };
+
isp_mmu: iommu@ff914000 {
compatible = "rockchip,iommu";
reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
-- 
2.16.1



[PATCH v6 10/17] dt-bindings: Document the Rockchip ISP1 bindings

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add DT bindings documentation for Rockchip ISP1

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Reviewed-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/media/rockchip-isp1.txt| 69 ++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-isp1.txt 
b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
new file mode 100644
index ..4631a4b7c88a
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
@@ -0,0 +1,69 @@
+Rockchip SoC Image Signal Processing unit v1
+--
+
+Rockchip ISP1 is the Camera interface for the Rockchip series of SoCs
+which contains image processing, scaling, and compression funcitons.
+
+Required properties:
+- compatible: value should be one of the following
+   "rockchip,rk3288-cif-isp";
+   "rockchip,rk3399-cif-isp";
+- reg : offset and length of the register set for the device.
+- interrupts: should contain ISP interrupt.
+- clocks: phandle to the required clocks.
+- clock-names: required clock name.
+- iommus: required a iommu node.
+
+port node
+---
+
+The device node should contain one 'port' child node with child 'endpoint'
+nodes, according to the bindings defined in Documentation/devicetree/bindings/
+media/video-interfaces.txt.
+
+- endpoint(parallel):
+   - remote-endpoint: Connecting to a sensor with a parallel video bus.
+   - parallel_bus properties: Refer to Documentation/devicetree/bindings/
+   media/video-interfaces.txt.
+- endpoint(mipi):
+   - remote-endpoint: Connecting to Rockchip MIPI-DPHY,
+   which is defined in rockchip-mipi-dphy.txt.
+
+The port node must contain at least one endpoint, either parallel or mipi.
+It could have multiple endpoints, but please note the hardware don't support
+two sensors work at a time, they are supposed to work asynchronously.
+
+Device node example
+---
+
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   /* mipi */
+   isp0_mipi_in: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_rx0_out>;
+   };
+
+   /* parallel */
+   isp0_parallel_in: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_out>;
+   bus-width = <8>;
+   };
+   };
+   };
-- 
2.16.1



[PATCH v6 10/17] dt-bindings: Document the Rockchip ISP1 bindings

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add DT bindings documentation for Rockchip ISP1

Signed-off-by: Jacob Chen 
Reviewed-by: Rob Herring 
---
 .../devicetree/bindings/media/rockchip-isp1.txt| 69 ++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-isp1.txt 
b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
new file mode 100644
index ..4631a4b7c88a
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
@@ -0,0 +1,69 @@
+Rockchip SoC Image Signal Processing unit v1
+--
+
+Rockchip ISP1 is the Camera interface for the Rockchip series of SoCs
+which contains image processing, scaling, and compression funcitons.
+
+Required properties:
+- compatible: value should be one of the following
+   "rockchip,rk3288-cif-isp";
+   "rockchip,rk3399-cif-isp";
+- reg : offset and length of the register set for the device.
+- interrupts: should contain ISP interrupt.
+- clocks: phandle to the required clocks.
+- clock-names: required clock name.
+- iommus: required a iommu node.
+
+port node
+---
+
+The device node should contain one 'port' child node with child 'endpoint'
+nodes, according to the bindings defined in Documentation/devicetree/bindings/
+media/video-interfaces.txt.
+
+- endpoint(parallel):
+   - remote-endpoint: Connecting to a sensor with a parallel video bus.
+   - parallel_bus properties: Refer to Documentation/devicetree/bindings/
+   media/video-interfaces.txt.
+- endpoint(mipi):
+   - remote-endpoint: Connecting to Rockchip MIPI-DPHY,
+   which is defined in rockchip-mipi-dphy.txt.
+
+The port node must contain at least one endpoint, either parallel or mipi.
+It could have multiple endpoints, but please note the hardware don't support
+two sensors work at a time, they are supposed to work asynchronously.
+
+Device node example
+---
+
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   /* mipi */
+   isp0_mipi_in: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_rx0_out>;
+   };
+
+   /* parallel */
+   isp0_parallel_in: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_out>;
+   bus-width = <8>;
+   };
+   };
+   };
-- 
2.16.1



[PATCH v6 13/17] ARM: dts: rockchip: add rx0 mipi-phy for rk3288

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

It's a Designware MIPI D-PHY, used by ISP in rk3288.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 arch/arm/boot/dts/rk3288.dtsi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 6c122aaf06a7..3a530b72c057 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -864,6 +864,13 @@
status = "disabled";
};
 
+   mipi_phy_rx0: mipi-phy-rx0 {
+   compatible = "rockchip,rk3288-mipi-dphy";
+   clocks = < SCLK_MIPIDSI_24M>, < PCLK_MIPI_CSI>;
+   clock-names = "dphy-ref", "pclk";
+   status = "disabled";
+   };
+
io_domains: io-domains {
compatible = "rockchip,rk3288-io-voltage-domain";
status = "disabled";
-- 
2.16.1



[PATCH v6 15/17] arm64: dts: rockchip: add isp0 node for rk3399

2018-03-08 Thread Jacob Chen
From: Shunqian Zheng <zhen...@rock-chips.com>

rk3399 have two ISP, but we havn't test isp1, so just add isp0 at present.

Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index 2605118d4b4c..14ed016f2fdd 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1614,6 +1614,21 @@
status = "disabled";
};
 
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+   status = "disabled";
+   };
+
isp0_mmu: iommu@ff914000 {
compatible = "rockchip,iommu";
reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
-- 
2.16.1



[PATCH v6 13/17] ARM: dts: rockchip: add rx0 mipi-phy for rk3288

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

It's a Designware MIPI D-PHY, used by ISP in rk3288.

Signed-off-by: Jacob Chen 
---
 arch/arm/boot/dts/rk3288.dtsi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 6c122aaf06a7..3a530b72c057 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -864,6 +864,13 @@
status = "disabled";
};
 
+   mipi_phy_rx0: mipi-phy-rx0 {
+   compatible = "rockchip,rk3288-mipi-dphy";
+   clocks = < SCLK_MIPIDSI_24M>, < PCLK_MIPI_CSI>;
+   clock-names = "dphy-ref", "pclk";
+   status = "disabled";
+   };
+
io_domains: io-domains {
compatible = "rockchip,rk3288-io-voltage-domain";
status = "disabled";
-- 
2.16.1



[PATCH v6 15/17] arm64: dts: rockchip: add isp0 node for rk3399

2018-03-08 Thread Jacob Chen
From: Shunqian Zheng 

rk3399 have two ISP, but we havn't test isp1, so just add isp0 at present.

Signed-off-by: Shunqian Zheng 
Signed-off-by: Jacob Chen 
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index 2605118d4b4c..14ed016f2fdd 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1614,6 +1614,21 @@
status = "disabled";
};
 
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+   status = "disabled";
+   };
+
isp0_mmu: iommu@ff914000 {
compatible = "rockchip,iommu";
reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
-- 
2.16.1



[PATCH v6 17/17] MAINTAINERS: add entry for Rockchip ISP1 driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add MAINTAINERS entry for the rockchip isp1 driver.
This driver is maintained by rockchip officially and it
will be used for rockchip SoC on all linux-kernel based OS.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4623caf8d72d..7a9ff4fa4592 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11852,6 +11852,16 @@ F: drivers/hid/hid-roccat*
 F: include/linux/hid-roccat*
 F: Documentation/ABI/*/sysfs-driver-hid-roccat*
 
+ROCKCHIP ISP V1 DRIVER
+M:     Jacob chen <jacob2.c...@rock-chips.com>
+M: Shunqian Zheng <zhen...@rock-chips.com>
+M: Yichong Zhong <z...@rock-chips.com>
+L: linux-me...@vger.kernel.org
+S: Maintained
+F: drivers/media/platform/rockchip/isp1/
+F: Documentation/devicetree/bindings/media/rockchip-isp1.txt
+F: Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
+
 ROCKCHIP RASTER 2D GRAPHIC ACCELERATION UNIT DRIVER
 M: Jacob chen <jacob2.c...@rock-chips.com>
 L: linux-me...@vger.kernel.org
-- 
2.16.1



[PATCH v6 17/17] MAINTAINERS: add entry for Rockchip ISP1 driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add MAINTAINERS entry for the rockchip isp1 driver.
This driver is maintained by rockchip officially and it
will be used for rockchip SoC on all linux-kernel based OS.

Signed-off-by: Jacob Chen 
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4623caf8d72d..7a9ff4fa4592 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11852,6 +11852,16 @@ F: drivers/hid/hid-roccat*
 F: include/linux/hid-roccat*
 F: Documentation/ABI/*/sysfs-driver-hid-roccat*
 
+ROCKCHIP ISP V1 DRIVER
+M: Jacob chen 
+M: Shunqian Zheng 
+M: Yichong Zhong 
+L: linux-me...@vger.kernel.org
+S: Maintained
+F: drivers/media/platform/rockchip/isp1/
+F: Documentation/devicetree/bindings/media/rockchip-isp1.txt
+F: Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
+
 ROCKCHIP RASTER 2D GRAPHIC ACCELERATION UNIT DRIVER
 M: Jacob chen 
 L: linux-me...@vger.kernel.org
-- 
2.16.1



[PATCH v6 14/17] ARM: dts: rockchip: Add dts mipi-dphy TXRX1 node for rk3288

2018-03-08 Thread Jacob Chen
From: Wen Nuan 

Change-Id: I0b6122b2b34ae0f24f0d4ac1bbe6018cac4e
Signed-off-by: Wen Nuan 
---
 arch/arm/boot/dts/rk3288.dtsi | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 3a530b72c057..ed05f3d77358 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -1164,6 +1164,15 @@
};
};
 
+   mipi_phy_tx1rx1: mipi-phy-tx1rx1@ff968000 {
+   compatible = "rockchip,rk3288-mipi-dphy";
+   reg = <0x0 0xff968000 0x0 0x4000>;
+   rockchip,grf = <>;
+   clocks = < SCLK_MIPIDSI_24M>, < PCLK_MIPI_CSI>;
+   clock-names = "dphy-ref", "pclk";
+   status = "disabled";
+   };
+
edp: dp@ff97 {
compatible = "rockchip,rk3288-dp";
reg = <0x0 0xff97 0x0 0x4000>;
-- 
2.16.1



[PATCH v6 16/17] arm64: dts: rockchip: add rx0 mipi-phy for rk3399

2018-03-08 Thread Jacob Chen
From: Shunqian Zheng <zhen...@rock-chips.com>

It's a Designware MIPI D-PHY, used for ISP0 in rk3399.

Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index 14ed016f2fdd..d18ab8f56ef2 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1308,6 +1308,16 @@
status = "disabled";
};
 
+   mipi_dphy_rx0: mipi-dphy-rx0 {
+   compatible = "rockchip,rk3399-mipi-dphy";
+   clocks = < SCLK_MIPIDPHY_REF>,
+   < SCLK_DPHY_RX0_CFG>,
+   < PCLK_VIO_GRF>;
+   clock-names = "dphy-ref", "dphy-cfg", "grf";
+   power-domains = < RK3399_PD_VIO>;
+   status = "disabled";
+   };
+
u2phy0: usb2-phy@e450 {
compatible = "rockchip,rk3399-usb2phy";
reg = <0xe450 0x10>;
-- 
2.16.1



[PATCH v6 14/17] ARM: dts: rockchip: Add dts mipi-dphy TXRX1 node for rk3288

2018-03-08 Thread Jacob Chen
From: Wen Nuan 

Change-Id: I0b6122b2b34ae0f24f0d4ac1bbe6018cac4e
Signed-off-by: Wen Nuan 
---
 arch/arm/boot/dts/rk3288.dtsi | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 3a530b72c057..ed05f3d77358 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -1164,6 +1164,15 @@
};
};
 
+   mipi_phy_tx1rx1: mipi-phy-tx1rx1@ff968000 {
+   compatible = "rockchip,rk3288-mipi-dphy";
+   reg = <0x0 0xff968000 0x0 0x4000>;
+   rockchip,grf = <>;
+   clocks = < SCLK_MIPIDSI_24M>, < PCLK_MIPI_CSI>;
+   clock-names = "dphy-ref", "pclk";
+   status = "disabled";
+   };
+
edp: dp@ff97 {
compatible = "rockchip,rk3288-dp";
reg = <0x0 0xff97 0x0 0x4000>;
-- 
2.16.1



[PATCH v6 16/17] arm64: dts: rockchip: add rx0 mipi-phy for rk3399

2018-03-08 Thread Jacob Chen
From: Shunqian Zheng 

It's a Designware MIPI D-PHY, used for ISP0 in rk3399.

Signed-off-by: Shunqian Zheng 
Signed-off-by: Jacob Chen 
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index 14ed016f2fdd..d18ab8f56ef2 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1308,6 +1308,16 @@
status = "disabled";
};
 
+   mipi_dphy_rx0: mipi-dphy-rx0 {
+   compatible = "rockchip,rk3399-mipi-dphy";
+   clocks = < SCLK_MIPIDPHY_REF>,
+   < SCLK_DPHY_RX0_CFG>,
+   < PCLK_VIO_GRF>;
+   clock-names = "dphy-ref", "dphy-cfg", "grf";
+   power-domains = < RK3399_PD_VIO>;
+   status = "disabled";
+   };
+
u2phy0: usb2-phy@e450 {
compatible = "rockchip,rk3399-usb2phy";
reg = <0xe450 0x10>;
-- 
2.16.1



[PATCH v6 11/17] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add DT bindings documentation for Rockchip MIPI D-PHY RX

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Reviewed-by: Rob Herring <r...@kernel.org>
---
 .../bindings/media/rockchip-mipi-dphy.txt  | 90 ++
 1 file changed, 90 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt 
b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
new file mode 100644
index ..d83700faf4c4
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
@@ -0,0 +1,90 @@
+Rockchip SoC MIPI RX D-PHY
+-
+
+Required properties:
+- compatible: value should be one of the following
+   "rockchip,rk3288-mipi-dphy"
+   "rockchip,rk3399-mipi-dphy"
+- clocks : list of clock specifiers, corresponding to entries in
+   clock-names property;
+- clock-names: required clock name.
+
+MIPI RX D-PHY use registers in "general register files", it
+should be a child of the GRF.
+MIPI TXRX D-PHY have its own registers, it must have a reg property.
+
+Optional properties:
+- reg: offset and length of the register set for the device.
+- rockchip,grf: MIPI TX1RX1 D-PHY not only has its own register but also
+   the GRF, so it is only necessary for MIPI TX1RX1 D-PHY.
+
+port node
+---
+
+The device node should contain two 'port' child nodes, according to the 
bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+The first port show the sensors connected in this mipi-dphy.
+- endpoint:
+   - remote-endpoint: Linked to a sensor with a MIPI CSI-2 video bus.
+   - data-lanes : (required) an array specifying active physical MIPI-CSI2
+   data input lanes and their mapping to logical lanes; the
+   D-PHY can't reroute lanes, so the array's content should
+   be consecutive and only its length is meaningful.
+
+The port node must contain at least one endpoint. It could have multiple 
endpoints
+linked to different sensors, but please note that they are not supposed to be
+activated at the same time.
+
+The second port should be connected to isp node.
+- endpoint:
+   - remote-endpoint:  Linked to Rockchip ISP1, which is defined
+   in rockchip-isp1.txt.
+
+Device node example
+---
+
+grf: syscon@ff77 {
+   compatible = "rockchip,rk3288-grf", "syscon", "simple-mfd";
+
+...
+
+   mipi_dphy_rx0: mipi-dphy-rx0 {
+   compatible = "rockchip,rk3399-mipi-dphy";
+   clocks = < SCLK_MIPIDPHY_REF>,
+   < SCLK_DPHY_RX0_CFG>,
+   < PCLK_VIO_GRF>;
+   clock-names = "dphy-ref", "dphy-cfg", "grf";
+   power-domains = < RK3399_PD_VIO>;
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   mipi_in_wcam: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_out>;
+   data-lanes = <1 2>;
+   };
+   mipi_in_ucam: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_out>;
+   data-lanes = <1>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   dphy_rx0_out: endpoint {
+   remote-endpoint = <_mipi_in>;
+   };
+   };
+   };
+   };
+};
-- 
2.16.1



[PATCH v6 11/17] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add DT bindings documentation for Rockchip MIPI D-PHY RX

Signed-off-by: Jacob Chen 
Reviewed-by: Rob Herring 
---
 .../bindings/media/rockchip-mipi-dphy.txt  | 90 ++
 1 file changed, 90 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt 
b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
new file mode 100644
index ..d83700faf4c4
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
@@ -0,0 +1,90 @@
+Rockchip SoC MIPI RX D-PHY
+-
+
+Required properties:
+- compatible: value should be one of the following
+   "rockchip,rk3288-mipi-dphy"
+   "rockchip,rk3399-mipi-dphy"
+- clocks : list of clock specifiers, corresponding to entries in
+   clock-names property;
+- clock-names: required clock name.
+
+MIPI RX D-PHY use registers in "general register files", it
+should be a child of the GRF.
+MIPI TXRX D-PHY have its own registers, it must have a reg property.
+
+Optional properties:
+- reg: offset and length of the register set for the device.
+- rockchip,grf: MIPI TX1RX1 D-PHY not only has its own register but also
+   the GRF, so it is only necessary for MIPI TX1RX1 D-PHY.
+
+port node
+---
+
+The device node should contain two 'port' child nodes, according to the 
bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+The first port show the sensors connected in this mipi-dphy.
+- endpoint:
+   - remote-endpoint: Linked to a sensor with a MIPI CSI-2 video bus.
+   - data-lanes : (required) an array specifying active physical MIPI-CSI2
+   data input lanes and their mapping to logical lanes; the
+   D-PHY can't reroute lanes, so the array's content should
+   be consecutive and only its length is meaningful.
+
+The port node must contain at least one endpoint. It could have multiple 
endpoints
+linked to different sensors, but please note that they are not supposed to be
+activated at the same time.
+
+The second port should be connected to isp node.
+- endpoint:
+   - remote-endpoint:  Linked to Rockchip ISP1, which is defined
+   in rockchip-isp1.txt.
+
+Device node example
+---
+
+grf: syscon@ff77 {
+   compatible = "rockchip,rk3288-grf", "syscon", "simple-mfd";
+
+...
+
+   mipi_dphy_rx0: mipi-dphy-rx0 {
+   compatible = "rockchip,rk3399-mipi-dphy";
+   clocks = < SCLK_MIPIDPHY_REF>,
+   < SCLK_DPHY_RX0_CFG>,
+   < PCLK_VIO_GRF>;
+   clock-names = "dphy-ref", "dphy-cfg", "grf";
+   power-domains = < RK3399_PD_VIO>;
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   mipi_in_wcam: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_out>;
+   data-lanes = <1 2>;
+   };
+   mipi_in_ucam: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_out>;
+   data-lanes = <1>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   dphy_rx0_out: endpoint {
+   remote-endpoint = <_mipi_in>;
+   };
+   };
+   };
+   };
+};
-- 
2.16.1



[PATCH v6 03/17] media: rkisp1: Add user space ABI definitions

2018-03-08 Thread Jacob Chen
From: Jeffy Chen <jeffy.c...@rock-chips.com>

Add the header for userspace

Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com>
Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 include/uapi/linux/rkisp1-config.h | 798 +
 1 file changed, 798 insertions(+)
 create mode 100644 include/uapi/linux/rkisp1-config.h

diff --git a/include/uapi/linux/rkisp1-config.h 
b/include/uapi/linux/rkisp1-config.h
new file mode 100644
index ..1284eb9fd09d
--- /dev/null
+++ b/include/uapi/linux/rkisp1-config.h
@@ -0,0 +1,798 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+/*
+ * References:
+ * REF_01 - ISP_user_manual, Rev 2.57
+ */
+
+#ifndef _UAPI_RKISP1_CONFIG_H
+#define _UAPI_RKISP1_CONFIG_H
+
+#include 
+#include 
+
+#define CIFISP_MODULE_DPCC  (1 << 0)
+#define CIFISP_MODULE_BLS   (1 << 1)
+#define CIFISP_MODULE_SDG   (1 << 2)
+#define CIFISP_MODULE_HST   (1 << 3)
+#define CIFISP_MODULE_LSC   (1 << 4)
+#define CIFISP_MODULE_AWB_GAIN  (1 << 5)
+#define CIFISP_MODULE_FLT   (1 << 6)
+#define CIFISP_MODULE_BDM   (1 << 7)
+#define CIFISP_MODULE_CTK   (1 << 8)
+#define CIFISP_MODULE_GOC   (1 << 9)
+#define CIFISP_MODULE_CPROC (1 << 10)
+#define CIFISP_MODULE_AFC   (1 << 11)
+#define CIFISP_MODULE_AWB   (1 << 12)
+#define CIFISP_MODULE_IE(1 << 13)
+#define CIFISP_MODULE_AEC   (1 << 14)
+#define CIFISP_MODULE_WDR   (1 << 15)
+#define CIFISP_MODULE_DPF   (1 << 16)
+#define CIFISP_MODULE_DPF_STRENGTH  (1 << 17)
+
+#define CIFISP_CTK_COEFF_MAX0x100
+#define CIFISP_CTK_OFFSET_MAX   0x800
+
+#define CIFISP_AE_MEAN_MAX  25
+#define CIFISP_HIST_BIN_N_MAX   16
+#define CIFISP_AFM_MAX_WINDOWS  3
+#define CIFISP_DEGAMMA_CURVE_SIZE   17
+
+#define CIFISP_BDM_MAX_TH   0xFF
+
+/*
+ * Black level compensation
+ */
+/* maximum value for horizontal start address */
+#define CIFISP_BLS_START_H_MAX 0x0FFF
+/* maximum value for horizontal stop address */
+#define CIFISP_BLS_STOP_H_MAX  0x0FFF
+/* maximum value for vertical start address */
+#define CIFISP_BLS_START_V_MAX 0x0FFF
+/* maximum value for vertical stop address */
+#define CIFISP_BLS_STOP_V_MAX  0x0FFF
+/* maximum is 2^18 = 262144*/
+#define CIFISP_BLS_SAMPLES_MAX 0x0012
+/* maximum value for fixed black level */
+#define CIFISP_BLS_FIX_SUB_MAX 0x0FFF
+/* minimum value for fixed black level */
+#define CIFISP_BLS_FIX_SUB_MIN 0xF000
+/* 13 bit range (signed)*/
+#define CIFISP_BLS_FIX_MASK0x1FFF
+
+/*
+ * Automatic white balance measurments
+ */
+#define CIFISP_AWB_MAX_GRID1
+#define CIFISP_AWB_MAX_FRAMES  7
+
+/*
+ * Gamma out
+ */
+/* Maximum number of color samples supported */
+#define CIFISP_GAMMA_OUT_MAX_SAMPLES   17
+
+/*
+ * Lens shade correction
+ */
+#define CIFISP_LSC_GRAD_TBL_SIZE   8
+#define CIFISP_LSC_SIZE_TBL_SIZE   8
+/*
+ * The following matches the tuning process,
+ * not the max capabilities of the chip.
+ * Last value unused.
+ */
+#defineCIFISP_LSC_DATA_TBL_SIZE   290
+
+/*
+ * Histogram calculation
+ */
+/* Last 3 values unused. */
+#define CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28
+
+/*
+ * Defect Pixel Cluster Correction
+ */
+#define CIFISP_DPCC_METHODS_MAX   3
+
+/*
+ * Denoising pre filter
+ */
+#define CIFISP_DPF_MAX_NLF_COEFFS  17
+#define CIFISP_DPF_MAX_SPATIAL_COEFFS  6
+
+/*
+ * Measurement types
+ */
+#define CIFISP_STAT_AWB   (1 << 0)
+#define CIFISP_STAT_AUTOEXP   (1 << 1)
+#define CIFISP_STAT_AFM_FIN   (1 << 2)
+#define CIFISP_STAT_HIST  (1 << 3)
+
+enum cifisp_histogram_mode {
+   CIFISP_HISTOGRAM_MODE_DISABLE,
+   CIFISP_HISTOGRAM_MODE_RGB_COMBINED,
+   CIFISP_HISTOGRAM_MODE_R_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_G_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_B_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_Y_HISTOGRAM
+};
+
+enum cifisp_awb_mode_type {
+   CIFISP_AWB_MODE_MANUAL,
+   CIFISP_AWB_MODE_RGB,
+   CIFISP_AWB_MODE_YCBCR
+};
+
+enum cifisp_flt_mode {
+   CIFISP_FLT_STATIC_MODE,
+   CIFISP_FLT_DYNAMIC_MODE
+};
+
+/**
+ * enum cifisp_exp_ctrl_autostop - stop modes
+ * @CIFISP_EXP_CTRL_AUTOSTOP_0: continuous measurement
+ * @CIFISP_EXP_CTRL_AUTOSTOP_1: stop measuring after a complete frame
+ */
+enum cifisp_exp_ctrl_autostop {
+   CIFISP_EXP_CTRL_AUTOSTOP_0 = 0,
+   CIFISP_EXP_CTRL_AUTOSTOP_1 = 1,
+};
+
+/**
+ * enum cifis

[PATCH v6 03/17] media: rkisp1: Add user space ABI definitions

2018-03-08 Thread Jacob Chen
From: Jeffy Chen 

Add the header for userspace

Signed-off-by: Jeffy Chen 
Signed-off-by: Jacob Chen 
---
 include/uapi/linux/rkisp1-config.h | 798 +
 1 file changed, 798 insertions(+)
 create mode 100644 include/uapi/linux/rkisp1-config.h

diff --git a/include/uapi/linux/rkisp1-config.h 
b/include/uapi/linux/rkisp1-config.h
new file mode 100644
index ..1284eb9fd09d
--- /dev/null
+++ b/include/uapi/linux/rkisp1-config.h
@@ -0,0 +1,798 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+/*
+ * References:
+ * REF_01 - ISP_user_manual, Rev 2.57
+ */
+
+#ifndef _UAPI_RKISP1_CONFIG_H
+#define _UAPI_RKISP1_CONFIG_H
+
+#include 
+#include 
+
+#define CIFISP_MODULE_DPCC  (1 << 0)
+#define CIFISP_MODULE_BLS   (1 << 1)
+#define CIFISP_MODULE_SDG   (1 << 2)
+#define CIFISP_MODULE_HST   (1 << 3)
+#define CIFISP_MODULE_LSC   (1 << 4)
+#define CIFISP_MODULE_AWB_GAIN  (1 << 5)
+#define CIFISP_MODULE_FLT   (1 << 6)
+#define CIFISP_MODULE_BDM   (1 << 7)
+#define CIFISP_MODULE_CTK   (1 << 8)
+#define CIFISP_MODULE_GOC   (1 << 9)
+#define CIFISP_MODULE_CPROC (1 << 10)
+#define CIFISP_MODULE_AFC   (1 << 11)
+#define CIFISP_MODULE_AWB   (1 << 12)
+#define CIFISP_MODULE_IE(1 << 13)
+#define CIFISP_MODULE_AEC   (1 << 14)
+#define CIFISP_MODULE_WDR   (1 << 15)
+#define CIFISP_MODULE_DPF   (1 << 16)
+#define CIFISP_MODULE_DPF_STRENGTH  (1 << 17)
+
+#define CIFISP_CTK_COEFF_MAX0x100
+#define CIFISP_CTK_OFFSET_MAX   0x800
+
+#define CIFISP_AE_MEAN_MAX  25
+#define CIFISP_HIST_BIN_N_MAX   16
+#define CIFISP_AFM_MAX_WINDOWS  3
+#define CIFISP_DEGAMMA_CURVE_SIZE   17
+
+#define CIFISP_BDM_MAX_TH   0xFF
+
+/*
+ * Black level compensation
+ */
+/* maximum value for horizontal start address */
+#define CIFISP_BLS_START_H_MAX 0x0FFF
+/* maximum value for horizontal stop address */
+#define CIFISP_BLS_STOP_H_MAX  0x0FFF
+/* maximum value for vertical start address */
+#define CIFISP_BLS_START_V_MAX 0x0FFF
+/* maximum value for vertical stop address */
+#define CIFISP_BLS_STOP_V_MAX  0x0FFF
+/* maximum is 2^18 = 262144*/
+#define CIFISP_BLS_SAMPLES_MAX 0x0012
+/* maximum value for fixed black level */
+#define CIFISP_BLS_FIX_SUB_MAX 0x0FFF
+/* minimum value for fixed black level */
+#define CIFISP_BLS_FIX_SUB_MIN 0xF000
+/* 13 bit range (signed)*/
+#define CIFISP_BLS_FIX_MASK0x1FFF
+
+/*
+ * Automatic white balance measurments
+ */
+#define CIFISP_AWB_MAX_GRID1
+#define CIFISP_AWB_MAX_FRAMES  7
+
+/*
+ * Gamma out
+ */
+/* Maximum number of color samples supported */
+#define CIFISP_GAMMA_OUT_MAX_SAMPLES   17
+
+/*
+ * Lens shade correction
+ */
+#define CIFISP_LSC_GRAD_TBL_SIZE   8
+#define CIFISP_LSC_SIZE_TBL_SIZE   8
+/*
+ * The following matches the tuning process,
+ * not the max capabilities of the chip.
+ * Last value unused.
+ */
+#defineCIFISP_LSC_DATA_TBL_SIZE   290
+
+/*
+ * Histogram calculation
+ */
+/* Last 3 values unused. */
+#define CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28
+
+/*
+ * Defect Pixel Cluster Correction
+ */
+#define CIFISP_DPCC_METHODS_MAX   3
+
+/*
+ * Denoising pre filter
+ */
+#define CIFISP_DPF_MAX_NLF_COEFFS  17
+#define CIFISP_DPF_MAX_SPATIAL_COEFFS  6
+
+/*
+ * Measurement types
+ */
+#define CIFISP_STAT_AWB   (1 << 0)
+#define CIFISP_STAT_AUTOEXP   (1 << 1)
+#define CIFISP_STAT_AFM_FIN   (1 << 2)
+#define CIFISP_STAT_HIST  (1 << 3)
+
+enum cifisp_histogram_mode {
+   CIFISP_HISTOGRAM_MODE_DISABLE,
+   CIFISP_HISTOGRAM_MODE_RGB_COMBINED,
+   CIFISP_HISTOGRAM_MODE_R_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_G_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_B_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_Y_HISTOGRAM
+};
+
+enum cifisp_awb_mode_type {
+   CIFISP_AWB_MODE_MANUAL,
+   CIFISP_AWB_MODE_RGB,
+   CIFISP_AWB_MODE_YCBCR
+};
+
+enum cifisp_flt_mode {
+   CIFISP_FLT_STATIC_MODE,
+   CIFISP_FLT_DYNAMIC_MODE
+};
+
+/**
+ * enum cifisp_exp_ctrl_autostop - stop modes
+ * @CIFISP_EXP_CTRL_AUTOSTOP_0: continuous measurement
+ * @CIFISP_EXP_CTRL_AUTOSTOP_1: stop measuring after a complete frame
+ */
+enum cifisp_exp_ctrl_autostop {
+   CIFISP_EXP_CTRL_AUTOSTOP_0 = 0,
+   CIFISP_EXP_CTRL_AUTOSTOP_1 = 1,
+};
+
+/**
+ * enum cifisp_exp_meas_mode - Exposure measure mode
+ * @CIFISP_EXP_MEASURING_

[PATCH v6 09/17] media: rkisp1: add rockchip isp1 core driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add the core driver for rockchip isp1.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Yichong Zhong <z...@rock-chips.com>
Signed-off-by: Jacob Chen <c...@rock-chips.com>
Signed-off-by: Eddie Cai <eddie.cai.li...@gmail.com>
Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com>
Signed-off-by: Allon Huang <allon.hu...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 drivers/media/platform/Kconfig|  10 +
 drivers/media/platform/Makefile   |   1 +
 drivers/media/platform/rockchip/isp1/Makefile |   8 +
 drivers/media/platform/rockchip/isp1/common.h | 110 +
 drivers/media/platform/rockchip/isp1/dev.c| 626 ++
 drivers/media/platform/rockchip/isp1/dev.h|  93 
 6 files changed, 848 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/Makefile
 create mode 100644 drivers/media/platform/rockchip/isp1/common.h
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.c
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 614fbef08ddc..3dff763b731d 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -117,6 +117,16 @@ config VIDEO_QCOM_CAMSS
select VIDEOBUF2_DMA_SG
select V4L2_FWNODE
 
+config VIDEO_ROCKCHIP_ISP1
+   tristate "Rockchip Image Signal Processing v1 Unit driver"
+   depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on ARCH_ROCKCHIP || COMPILE_TEST
+   select VIDEOBUF2_DMA_CONTIG
+   select V4L2_FWNODE
+   default n
+   ---help---
+ Support for ISP1 on the rockchip SoC.
+
 config VIDEO_S3C_CAMIF
tristate "Samsung S3C24XX/S3C64XX SoC Camera Interface driver"
depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 7f3080437be6..0d5e1b3e6f22 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -67,6 +67,7 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1)  += rcar_fdp1.o
 obj-$(CONFIG_VIDEO_RENESAS_JPU)+= rcar_jpu.o
 obj-$(CONFIG_VIDEO_RENESAS_VSP1)   += vsp1/
 
+obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1)  += rockchip/isp1/
 obj-$(CONFIG_VIDEO_ROCKCHIP_RGA)   += rockchip/rga/
 
 obj-y  += omap/
diff --git a/drivers/media/platform/rockchip/isp1/Makefile 
b/drivers/media/platform/rockchip/isp1/Makefile
new file mode 100644
index ..18af64853734
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/Makefile
@@ -0,0 +1,8 @@
+obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) +=   video_rkisp1.o
+video_rkisp1-objs +=   rkisp1.o \
+   dev.o \
+   regs.o \
+   isp_stats.o \
+   isp_params.o \
+   mipi_dphy_sy.o \
+   capture.o
diff --git a/drivers/media/platform/rockchip/isp1/common.h 
b/drivers/media/platform/rockchip/isp1/common.h
new file mode 100644
index ..b58cdaf7da06
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/common.h
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#ifndef _RKISP1_COMMON_H
+#define _RKISP1_COMMON_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RKISP1_DEFAULT_WIDTH   800
+#define RKISP1_DEFAULT_HEIGHT  600
+
+#define RKISP1_MAX_STREAM  2
+#define RKISP1_STREAM_SP   0
+#define RKISP1_STREAM_MP   1
+
+#define RKISP1_PLANE_Y 0
+#define RKISP1_PLANE_CB1
+#define RKISP1_PLANE_CR2
+
+enum rkisp1_sd_type {
+   RKISP1_SD_SENSOR,
+   RKISP1_SD_PHY_CSI,
+   RKISP1_SD_VCM,
+   RKISP1_SD_FLASH,
+   RKISP1_SD_MAX,
+};
+
+/* One structure per video node */
+struct rkisp1_vdev_node {
+   struct vb2_queue buf_queue;
+   /* vfd lock */
+   struct mutex vlock;
+   struct video_device vdev;
+   struct media_pad pad;
+};
+
+enum rkisp1_fmt_pix_type {
+   FMT_YUV,
+   FMT_RGB,
+   FMT_BAYER,
+   FMT_JPEG,
+   FMT_MAX
+};
+
+enum rkisp1_fmt_raw_pat_type {
+   RAW_RGGB = 0,
+   RAW_GRBG,
+   RAW_GBRG,
+   RAW_BGGR,
+};
+
+enum rkisp1_state {
+   /* path not yet opened: */
+   RKISP1_STATE_DISABLED,
+   /* path opened and configured, ready for streaming: */
+   RKISP1_STATE_READY,
+   /* path is streaming: */
+   RKISP1_STATE_STREAMING
+};
+
+struct rkisp1_buffer {
+   struct vb2_v4l2_buffer vb;
+   struct list

[PATCH v6 09/17] media: rkisp1: add rockchip isp1 core driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add the core driver for rockchip isp1.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/Kconfig|  10 +
 drivers/media/platform/Makefile   |   1 +
 drivers/media/platform/rockchip/isp1/Makefile |   8 +
 drivers/media/platform/rockchip/isp1/common.h | 110 +
 drivers/media/platform/rockchip/isp1/dev.c| 626 ++
 drivers/media/platform/rockchip/isp1/dev.h|  93 
 6 files changed, 848 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/Makefile
 create mode 100644 drivers/media/platform/rockchip/isp1/common.h
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.c
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 614fbef08ddc..3dff763b731d 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -117,6 +117,16 @@ config VIDEO_QCOM_CAMSS
select VIDEOBUF2_DMA_SG
select V4L2_FWNODE
 
+config VIDEO_ROCKCHIP_ISP1
+   tristate "Rockchip Image Signal Processing v1 Unit driver"
+   depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on ARCH_ROCKCHIP || COMPILE_TEST
+   select VIDEOBUF2_DMA_CONTIG
+   select V4L2_FWNODE
+   default n
+   ---help---
+ Support for ISP1 on the rockchip SoC.
+
 config VIDEO_S3C_CAMIF
tristate "Samsung S3C24XX/S3C64XX SoC Camera Interface driver"
depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 7f3080437be6..0d5e1b3e6f22 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -67,6 +67,7 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1)  += rcar_fdp1.o
 obj-$(CONFIG_VIDEO_RENESAS_JPU)+= rcar_jpu.o
 obj-$(CONFIG_VIDEO_RENESAS_VSP1)   += vsp1/
 
+obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1)  += rockchip/isp1/
 obj-$(CONFIG_VIDEO_ROCKCHIP_RGA)   += rockchip/rga/
 
 obj-y  += omap/
diff --git a/drivers/media/platform/rockchip/isp1/Makefile 
b/drivers/media/platform/rockchip/isp1/Makefile
new file mode 100644
index ..18af64853734
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/Makefile
@@ -0,0 +1,8 @@
+obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) +=   video_rkisp1.o
+video_rkisp1-objs +=   rkisp1.o \
+   dev.o \
+   regs.o \
+   isp_stats.o \
+   isp_params.o \
+   mipi_dphy_sy.o \
+   capture.o
diff --git a/drivers/media/platform/rockchip/isp1/common.h 
b/drivers/media/platform/rockchip/isp1/common.h
new file mode 100644
index ..b58cdaf7da06
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/common.h
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#ifndef _RKISP1_COMMON_H
+#define _RKISP1_COMMON_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RKISP1_DEFAULT_WIDTH   800
+#define RKISP1_DEFAULT_HEIGHT  600
+
+#define RKISP1_MAX_STREAM  2
+#define RKISP1_STREAM_SP   0
+#define RKISP1_STREAM_MP   1
+
+#define RKISP1_PLANE_Y 0
+#define RKISP1_PLANE_CB1
+#define RKISP1_PLANE_CR2
+
+enum rkisp1_sd_type {
+   RKISP1_SD_SENSOR,
+   RKISP1_SD_PHY_CSI,
+   RKISP1_SD_VCM,
+   RKISP1_SD_FLASH,
+   RKISP1_SD_MAX,
+};
+
+/* One structure per video node */
+struct rkisp1_vdev_node {
+   struct vb2_queue buf_queue;
+   /* vfd lock */
+   struct mutex vlock;
+   struct video_device vdev;
+   struct media_pad pad;
+};
+
+enum rkisp1_fmt_pix_type {
+   FMT_YUV,
+   FMT_RGB,
+   FMT_BAYER,
+   FMT_JPEG,
+   FMT_MAX
+};
+
+enum rkisp1_fmt_raw_pat_type {
+   RAW_RGGB = 0,
+   RAW_GRBG,
+   RAW_GBRG,
+   RAW_BGGR,
+};
+
+enum rkisp1_state {
+   /* path not yet opened: */
+   RKISP1_STATE_DISABLED,
+   /* path opened and configured, ready for streaming: */
+   RKISP1_STATE_READY,
+   /* path is streaming: */
+   RKISP1_STATE_STREAMING
+};
+
+struct rkisp1_buffer {
+   struct vb2_v4l2_buffer vb;
+   struct list_head queue;
+   union {
+   u32 buff_addr[VIDEO_MAX_PLANES];
+   void *vaddr[VIDEO_MAX_PLANES];
+   };
+};
+
+struct rkisp1_dummy_buffer {
+   void *vaddr;
+   dma_addr_t dma_addr;
+   u32 size;
+};
+
+extern int rkisp1_debu

[PATCH v6 07/17] media: rkisp1: add ISP1 params driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add the output video driver that accept params from userspace.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Yichong Zhong <z...@rock-chips.com>
Signed-off-by: Jacob Chen <c...@rock-chips.com>
Signed-off-by: Eddie Cai <eddie.cai.li...@gmail.com>
Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com>
Signed-off-by: Allon Huang <allon.hu...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 drivers/media/platform/rockchip/isp1/isp_params.c | 1539 +
 drivers/media/platform/rockchip/isp1/isp_params.h |   49 +
 2 files changed, 1588 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.h

diff --git a/drivers/media/platform/rockchip/isp1/isp_params.c 
b/drivers/media/platform/rockchip/isp1/isp_params.c
new file mode 100644
index ..747108e02836
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/isp_params.c
@@ -0,0 +1,1539 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include/* for ISP params */
+#include "dev.h"
+#include "regs.h"
+
+#define RKISP1_ISP_PARAMS_REQ_BUFS_MIN 2
+#define RKISP1_ISP_PARAMS_REQ_BUFS_MAX 8
+
+#define BLS_START_H_MAX_IS_VALID(val)  ((val) < CIFISP_BLS_START_H_MAX)
+#define BLS_STOP_H_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_STOP_H_MAX)
+
+#define BLS_START_V_MAX_IS_VALID(val)  ((val) < CIFISP_BLS_START_V_MAX)
+#define BLS_STOP_V_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_STOP_V_MAX)
+
+#define BLS_SAMPLE_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_SAMPLES_MAX)
+
+#define BLS_FIX_SUB_IS_VALID(val)  \
+   ((val) > (s16) CIFISP_BLS_FIX_SUB_MIN && (val) < CIFISP_BLS_FIX_SUB_MAX)
+
+#define RKISP1_ISP_DPCC_LINE_THRESH(n) (CIF_ISP_DPCC_LINE_THRESH_1 + 0x14 * 
(n))
+#define RKISP1_ISP_DPCC_LINE_MAD_FAC(n) (CIF_ISP_DPCC_LINE_MAD_FAC_1 + 0x14 * 
(n))
+#define RKISP1_ISP_DPCC_PG_FAC(n)  (CIF_ISP_DPCC_PG_FAC_1 + 0x14 * (n))
+#define RKISP1_ISP_DPCC_RND_THRESH(n)  (CIF_ISP_DPCC_RND_THRESH_1 + 0x14 * (n))
+#define RKISP1_ISP_DPCC_RG_FAC(n)  (CIF_ISP_DPCC_RG_FAC_1 + 0x14 * (n))
+#define RKISP1_ISP_CC_COEFF(n) (CIF_ISP_CC_COEFF_0 + (n) * 4)
+
+static inline void rkisp1_iowrite32(struct rkisp1_isp_params_vdev *params_vdev,
+   u32 value, u32 addr)
+{
+   iowrite32(value, params_vdev->dev->base_addr + addr);
+}
+
+static inline u32 rkisp1_ioread32(struct rkisp1_isp_params_vdev *params_vdev,
+ u32 addr)
+{
+   return ioread32(params_vdev->dev->base_addr + addr);
+}
+
+static inline void isp_param_set_bits(struct rkisp1_isp_params_vdev
+*params_vdev,
+ u32 reg, u32 bit_mask)
+{
+   u32 val;
+
+   val = rkisp1_ioread32(params_vdev, reg);
+   rkisp1_iowrite32(params_vdev, val | bit_mask, reg);
+}
+
+static inline void isp_param_clear_bits(struct rkisp1_isp_params_vdev
+  *params_vdev,
+   u32 reg, u32 bit_mask)
+{
+   u32 val;
+
+   val = rkisp1_ioread32(params_vdev, reg);
+   rkisp1_iowrite32(params_vdev, val & ~bit_mask, reg);
+}
+
+/* ISP BP interface function */
+static void dpcc_config(struct rkisp1_isp_params_vdev *params_vdev,
+   const struct cifisp_dpcc_config *arg)
+{
+   unsigned int i;
+
+   rkisp1_iowrite32(params_vdev, arg->mode, CIF_ISP_DPCC_MODE);
+   rkisp1_iowrite32(params_vdev, arg->output_mode,
+CIF_ISP_DPCC_OUTPUT_MODE);
+   rkisp1_iowrite32(params_vdev, arg->set_use, CIF_ISP_DPCC_SET_USE);
+
+   rkisp1_iowrite32(params_vdev, arg->methods[0].method,
+CIF_ISP_DPCC_METHODS_SET_1);
+   rkisp1_iowrite32(params_vdev, arg->methods[1].method,
+CIF_ISP_DPCC_METHODS_SET_2);
+   rkisp1_iowrite32(params_vdev, arg->methods[2].method,
+CIF_ISP_DPCC_METHODS_SET_3);
+   for (i = 0; i < CIFISP_DPCC_METHODS_MAX; i++) {
+   rkisp1_iowrite32(params_vdev, arg->methods[i].line_thresh,
+RKISP1_ISP_DPCC_LINE_THRESH(i));
+   rkisp1_iowrite32(params_vdev, arg->methods[i].line_mad_fac,
+RKISP1_ISP_DPCC_LINE_MAD_FAC(i));
+   rkisp1_iowrite32(params_vdev, arg->methods[i].pg_fac,
+RKISP1_ISP_DPCC_PG_FAC(i));
+   rkisp1_iowrite32(params_vdev, arg->meth

[PATCH v6 02/17] media: doc: add document for rkisp1 meta buffer format

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

This commit add docuemnt for rkisp1 meta buffer format

Signed-off-by: Jacob Chen <jacob-c...@rock-chips.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 Documentation/media/uapi/v4l/meta-formats.rst|  2 ++
 .../media/uapi/v4l/pixfmt-meta-rkisp1-params.rst | 20 
 .../media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst   | 18 ++
 3 files changed, 40 insertions(+)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst

diff --git a/Documentation/media/uapi/v4l/meta-formats.rst 
b/Documentation/media/uapi/v4l/meta-formats.rst
index 0c4e1ecf5879..44e7edbf1dae 100644
--- a/Documentation/media/uapi/v4l/meta-formats.rst
+++ b/Documentation/media/uapi/v4l/meta-formats.rst
@@ -15,3 +15,5 @@ These formats are used for the :ref:`metadata` interface only.
 pixfmt-meta-uvc
 pixfmt-meta-vsp1-hgo
 pixfmt-meta-vsp1-hgt
+pixfmt-meta-rkisp1-params
+pixfmt-meta-rkisp1-stat
diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst 
b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
new file mode 100644
index ..2ff4f4309795
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
@@ -0,0 +1,20 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _v4l2-meta-fmt-rkisp1-params:
+
+***
+V4L2_META_FMT_RK_ISP1_PARAMS
+***
+
+Rockchip ISP1 Parameters Data
+
+Description
+===
+
+This format describes input parameters for the Rockchip ISP1.
+
+It uses c-struct :c:type:`rkisp1_isp_params_cfg`, which is defined in
+the ``linux/rkisp1-config.h`` header file, see it for details.
+
+The parameters consist of multiple modules.
+The module won't be updated if the correspond bit was not set in 
module_*_update.
diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst 
b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
new file mode 100644
index ..dca8befe58f1
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
@@ -0,0 +1,18 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _v4l2-meta-fmt-rkisp1-stat:
+
+***
+V4L2_META_FMT_RK_ISP1_STAT_3A
+***
+
+Rockchip ISP1 Statistics Data
+
+Description
+===
+
+This format describes image color statistics information generated by the 
Rockchip
+ISP1.
+
+It use c-struct :c:type:`rkisp1_stat_buffer`, which is defined in
+the ``linux/cifisp_stat.h`` header file, see it for details.
-- 
2.16.1



[PATCH v6 07/17] media: rkisp1: add ISP1 params driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add the output video driver that accept params from userspace.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/isp_params.c | 1539 +
 drivers/media/platform/rockchip/isp1/isp_params.h |   49 +
 2 files changed, 1588 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.h

diff --git a/drivers/media/platform/rockchip/isp1/isp_params.c 
b/drivers/media/platform/rockchip/isp1/isp_params.c
new file mode 100644
index ..747108e02836
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/isp_params.c
@@ -0,0 +1,1539 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include/* for ISP params */
+#include "dev.h"
+#include "regs.h"
+
+#define RKISP1_ISP_PARAMS_REQ_BUFS_MIN 2
+#define RKISP1_ISP_PARAMS_REQ_BUFS_MAX 8
+
+#define BLS_START_H_MAX_IS_VALID(val)  ((val) < CIFISP_BLS_START_H_MAX)
+#define BLS_STOP_H_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_STOP_H_MAX)
+
+#define BLS_START_V_MAX_IS_VALID(val)  ((val) < CIFISP_BLS_START_V_MAX)
+#define BLS_STOP_V_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_STOP_V_MAX)
+
+#define BLS_SAMPLE_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_SAMPLES_MAX)
+
+#define BLS_FIX_SUB_IS_VALID(val)  \
+   ((val) > (s16) CIFISP_BLS_FIX_SUB_MIN && (val) < CIFISP_BLS_FIX_SUB_MAX)
+
+#define RKISP1_ISP_DPCC_LINE_THRESH(n) (CIF_ISP_DPCC_LINE_THRESH_1 + 0x14 * 
(n))
+#define RKISP1_ISP_DPCC_LINE_MAD_FAC(n) (CIF_ISP_DPCC_LINE_MAD_FAC_1 + 0x14 * 
(n))
+#define RKISP1_ISP_DPCC_PG_FAC(n)  (CIF_ISP_DPCC_PG_FAC_1 + 0x14 * (n))
+#define RKISP1_ISP_DPCC_RND_THRESH(n)  (CIF_ISP_DPCC_RND_THRESH_1 + 0x14 * (n))
+#define RKISP1_ISP_DPCC_RG_FAC(n)  (CIF_ISP_DPCC_RG_FAC_1 + 0x14 * (n))
+#define RKISP1_ISP_CC_COEFF(n) (CIF_ISP_CC_COEFF_0 + (n) * 4)
+
+static inline void rkisp1_iowrite32(struct rkisp1_isp_params_vdev *params_vdev,
+   u32 value, u32 addr)
+{
+   iowrite32(value, params_vdev->dev->base_addr + addr);
+}
+
+static inline u32 rkisp1_ioread32(struct rkisp1_isp_params_vdev *params_vdev,
+ u32 addr)
+{
+   return ioread32(params_vdev->dev->base_addr + addr);
+}
+
+static inline void isp_param_set_bits(struct rkisp1_isp_params_vdev
+*params_vdev,
+ u32 reg, u32 bit_mask)
+{
+   u32 val;
+
+   val = rkisp1_ioread32(params_vdev, reg);
+   rkisp1_iowrite32(params_vdev, val | bit_mask, reg);
+}
+
+static inline void isp_param_clear_bits(struct rkisp1_isp_params_vdev
+  *params_vdev,
+   u32 reg, u32 bit_mask)
+{
+   u32 val;
+
+   val = rkisp1_ioread32(params_vdev, reg);
+   rkisp1_iowrite32(params_vdev, val & ~bit_mask, reg);
+}
+
+/* ISP BP interface function */
+static void dpcc_config(struct rkisp1_isp_params_vdev *params_vdev,
+   const struct cifisp_dpcc_config *arg)
+{
+   unsigned int i;
+
+   rkisp1_iowrite32(params_vdev, arg->mode, CIF_ISP_DPCC_MODE);
+   rkisp1_iowrite32(params_vdev, arg->output_mode,
+CIF_ISP_DPCC_OUTPUT_MODE);
+   rkisp1_iowrite32(params_vdev, arg->set_use, CIF_ISP_DPCC_SET_USE);
+
+   rkisp1_iowrite32(params_vdev, arg->methods[0].method,
+CIF_ISP_DPCC_METHODS_SET_1);
+   rkisp1_iowrite32(params_vdev, arg->methods[1].method,
+CIF_ISP_DPCC_METHODS_SET_2);
+   rkisp1_iowrite32(params_vdev, arg->methods[2].method,
+CIF_ISP_DPCC_METHODS_SET_3);
+   for (i = 0; i < CIFISP_DPCC_METHODS_MAX; i++) {
+   rkisp1_iowrite32(params_vdev, arg->methods[i].line_thresh,
+RKISP1_ISP_DPCC_LINE_THRESH(i));
+   rkisp1_iowrite32(params_vdev, arg->methods[i].line_mad_fac,
+RKISP1_ISP_DPCC_LINE_MAD_FAC(i));
+   rkisp1_iowrite32(params_vdev, arg->methods[i].pg_fac,
+RKISP1_ISP_DPCC_PG_FAC(i));
+   rkisp1_iowrite32(params_vdev, arg->methods[i].rnd_thresh,
+RKISP1_ISP_DPCC_RND_THRESH(i));
+   rkisp1_iowrite32(params_vdev, arg->methods[i].rg_fac,
+RKISP1_ISP_DPCC_RG_FAC(i));
+   }
+
+   rkisp1_iowrite32(params_vdev, arg->rnd_offs, CIF_ISP_DPCC_RND_OFFS);

[PATCH v6 02/17] media: doc: add document for rkisp1 meta buffer format

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

This commit add docuemnt for rkisp1 meta buffer format

Signed-off-by: Jacob Chen 
Acked-by: Hans Verkuil 
---
 Documentation/media/uapi/v4l/meta-formats.rst|  2 ++
 .../media/uapi/v4l/pixfmt-meta-rkisp1-params.rst | 20 
 .../media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst   | 18 ++
 3 files changed, 40 insertions(+)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst

diff --git a/Documentation/media/uapi/v4l/meta-formats.rst 
b/Documentation/media/uapi/v4l/meta-formats.rst
index 0c4e1ecf5879..44e7edbf1dae 100644
--- a/Documentation/media/uapi/v4l/meta-formats.rst
+++ b/Documentation/media/uapi/v4l/meta-formats.rst
@@ -15,3 +15,5 @@ These formats are used for the :ref:`metadata` interface only.
 pixfmt-meta-uvc
 pixfmt-meta-vsp1-hgo
 pixfmt-meta-vsp1-hgt
+pixfmt-meta-rkisp1-params
+pixfmt-meta-rkisp1-stat
diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst 
b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
new file mode 100644
index ..2ff4f4309795
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
@@ -0,0 +1,20 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _v4l2-meta-fmt-rkisp1-params:
+
+***
+V4L2_META_FMT_RK_ISP1_PARAMS
+***
+
+Rockchip ISP1 Parameters Data
+
+Description
+===
+
+This format describes input parameters for the Rockchip ISP1.
+
+It uses c-struct :c:type:`rkisp1_isp_params_cfg`, which is defined in
+the ``linux/rkisp1-config.h`` header file, see it for details.
+
+The parameters consist of multiple modules.
+The module won't be updated if the correspond bit was not set in 
module_*_update.
diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst 
b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
new file mode 100644
index ..dca8befe58f1
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
@@ -0,0 +1,18 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _v4l2-meta-fmt-rkisp1-stat:
+
+***
+V4L2_META_FMT_RK_ISP1_STAT_3A
+***
+
+Rockchip ISP1 Statistics Data
+
+Description
+===
+
+This format describes image color statistics information generated by the 
Rockchip
+ISP1.
+
+It use c-struct :c:type:`rkisp1_stat_buffer`, which is defined in
+the ``linux/cifisp_stat.h`` header file, see it for details.
-- 
2.16.1



[PATCH v6 05/17] media: rkisp1: add Rockchip ISP1 subdev driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add the subdev driver for rockchip isp1.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Yichong Zhong <z...@rock-chips.com>
Signed-off-by: Jacob Chen <c...@rock-chips.com>
Signed-off-by: Eddie Cai <eddie.cai.li...@gmail.com>
Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com>
Signed-off-by: Allon Huang <allon.hu...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 drivers/media/platform/rockchip/isp1/rkisp1.c | 1177 +
 drivers/media/platform/rockchip/isp1/rkisp1.h |  105 +++
 2 files changed, 1282 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.c
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.h

diff --git a/drivers/media/platform/rockchip/isp1/rkisp1.c 
b/drivers/media/platform/rockchip/isp1/rkisp1.c
new file mode 100644
index ..bb16c8118c16
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/rkisp1.c
@@ -0,0 +1,1177 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "common.h"
+#include "regs.h"
+
+#define CIF_ISP_INPUT_W_MAX4032
+#define CIF_ISP_INPUT_H_MAX3024
+#define CIF_ISP_INPUT_W_MIN32
+#define CIF_ISP_INPUT_H_MIN32
+#define CIF_ISP_OUTPUT_W_MAX   CIF_ISP_INPUT_W_MAX
+#define CIF_ISP_OUTPUT_H_MAX   CIF_ISP_INPUT_H_MAX
+#define CIF_ISP_OUTPUT_W_MIN   CIF_ISP_INPUT_W_MIN
+#define CIF_ISP_OUTPUT_H_MIN   CIF_ISP_INPUT_H_MIN
+
+/*
+ * NOTE: MIPI controller and input MUX are also configured in this file,
+ * because ISP Subdev is not only describe ISP submodule(input size,format, 
output size, format),
+ * but also a virtual route device.
+ */
+
+/*
+ * There are many variables named with format/frame in below code,
+ * please see here for their meaning.
+ *
+ * Cropping regions of ISP
+ *
+ * +-+
+ * | Sensor image|
+ * | +---+   |
+ * | | ISP_ACQ (for black level) |   |
+ * | | in_frm|   |
+ * | | ++|   |
+ * | | |ISP_OUT ||   |
+ * | | |in_crop ||   |
+ * | | |+-+ ||   |
+ * | | ||   ISP_IS| ||   |
+ * | | ||   rkisp1_isp_subdev: out_crop   | ||   |
+ * | | |+-+ ||   |
+ * | | ++|   |
+ * | +---+   |
+ * +-+
+ */
+
+static inline struct rkisp1_device *sd_to_isp_dev(struct v4l2_subdev *sd)
+{
+   return container_of(sd->v4l2_dev, struct rkisp1_device, v4l2_dev);
+}
+
+/* Get sensor by enabled media link */
+static struct v4l2_subdev *get_remote_sensor(struct v4l2_subdev *sd)
+{
+   struct media_pad *local;
+   struct media_entity *sensor_me;
+
+   local = >entity.pads[RKISP1_ISP_PAD_SINK];
+   sensor_me = media_entity_remote_pad(local)->entity;
+
+   return media_entity_to_v4l2_subdev(sensor_me);
+}
+
+static struct rkisp1_sensor_info *sd_to_sensor(struct rkisp1_device *dev,
+  struct v4l2_subdev *sd)
+{
+   int i;
+
+   for (i = 0; i < dev->num_sensors; ++i)
+   if (dev->sensors[i].sd == sd)
+   return >sensors[i];
+
+   return NULL;
+}
+
+/  register operations /
+
+/*
+ * Image Stabilization.
+ * This should only be called when configuring CIF
+ * or at the frame end interrupt
+ */
+static void rkisp1_config_ism(struct rkisp1_device *dev)
+{
+   void __iomem *base = dev->base_addr;
+   struct v4l2_rect *out_crop = >isp_sdev.out_crop;
+   u32 val;
+
+   writel(0, base + CIF_ISP_IS_RECENTER);
+   writel(0, base + CIF_ISP_IS_MAX_DX);
+   writel(0, base + CIF_ISP_IS_MAX_DY);
+   writel(0, base + CIF_ISP_IS_DISPLACE);
+   writel(out_crop->left, base + CIF_ISP_IS_H_OFFS);
+   writel(out_crop->top, base + CIF_ISP_IS_V_OFFS);
+   writel(out_crop->width, base + CIF_ISP_IS_H_SIZE);
+   writel(out_crop->height, base + CIF_ISP_IS_V_SIZE);
+
+   /* IS(Image Stabilization) is always on, working as output crop */
+   writel(1, base + CIF_ISP_IS_CTRL);
+   val = readl(base + CIF_ISP_CTRL);
+   val |= CIF_ISP_CTRL

[PATCH v6 05/17] media: rkisp1: add Rockchip ISP1 subdev driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add the subdev driver for rockchip isp1.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/rkisp1.c | 1177 +
 drivers/media/platform/rockchip/isp1/rkisp1.h |  105 +++
 2 files changed, 1282 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.c
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.h

diff --git a/drivers/media/platform/rockchip/isp1/rkisp1.c 
b/drivers/media/platform/rockchip/isp1/rkisp1.c
new file mode 100644
index ..bb16c8118c16
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/rkisp1.c
@@ -0,0 +1,1177 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "common.h"
+#include "regs.h"
+
+#define CIF_ISP_INPUT_W_MAX4032
+#define CIF_ISP_INPUT_H_MAX3024
+#define CIF_ISP_INPUT_W_MIN32
+#define CIF_ISP_INPUT_H_MIN32
+#define CIF_ISP_OUTPUT_W_MAX   CIF_ISP_INPUT_W_MAX
+#define CIF_ISP_OUTPUT_H_MAX   CIF_ISP_INPUT_H_MAX
+#define CIF_ISP_OUTPUT_W_MIN   CIF_ISP_INPUT_W_MIN
+#define CIF_ISP_OUTPUT_H_MIN   CIF_ISP_INPUT_H_MIN
+
+/*
+ * NOTE: MIPI controller and input MUX are also configured in this file,
+ * because ISP Subdev is not only describe ISP submodule(input size,format, 
output size, format),
+ * but also a virtual route device.
+ */
+
+/*
+ * There are many variables named with format/frame in below code,
+ * please see here for their meaning.
+ *
+ * Cropping regions of ISP
+ *
+ * +-+
+ * | Sensor image|
+ * | +---+   |
+ * | | ISP_ACQ (for black level) |   |
+ * | | in_frm|   |
+ * | | ++|   |
+ * | | |ISP_OUT ||   |
+ * | | |in_crop ||   |
+ * | | |+-+ ||   |
+ * | | ||   ISP_IS| ||   |
+ * | | ||   rkisp1_isp_subdev: out_crop   | ||   |
+ * | | |+-+ ||   |
+ * | | ++|   |
+ * | +---+   |
+ * +-+
+ */
+
+static inline struct rkisp1_device *sd_to_isp_dev(struct v4l2_subdev *sd)
+{
+   return container_of(sd->v4l2_dev, struct rkisp1_device, v4l2_dev);
+}
+
+/* Get sensor by enabled media link */
+static struct v4l2_subdev *get_remote_sensor(struct v4l2_subdev *sd)
+{
+   struct media_pad *local;
+   struct media_entity *sensor_me;
+
+   local = >entity.pads[RKISP1_ISP_PAD_SINK];
+   sensor_me = media_entity_remote_pad(local)->entity;
+
+   return media_entity_to_v4l2_subdev(sensor_me);
+}
+
+static struct rkisp1_sensor_info *sd_to_sensor(struct rkisp1_device *dev,
+  struct v4l2_subdev *sd)
+{
+   int i;
+
+   for (i = 0; i < dev->num_sensors; ++i)
+   if (dev->sensors[i].sd == sd)
+   return >sensors[i];
+
+   return NULL;
+}
+
+/  register operations /
+
+/*
+ * Image Stabilization.
+ * This should only be called when configuring CIF
+ * or at the frame end interrupt
+ */
+static void rkisp1_config_ism(struct rkisp1_device *dev)
+{
+   void __iomem *base = dev->base_addr;
+   struct v4l2_rect *out_crop = >isp_sdev.out_crop;
+   u32 val;
+
+   writel(0, base + CIF_ISP_IS_RECENTER);
+   writel(0, base + CIF_ISP_IS_MAX_DX);
+   writel(0, base + CIF_ISP_IS_MAX_DY);
+   writel(0, base + CIF_ISP_IS_DISPLACE);
+   writel(out_crop->left, base + CIF_ISP_IS_H_OFFS);
+   writel(out_crop->top, base + CIF_ISP_IS_V_OFFS);
+   writel(out_crop->width, base + CIF_ISP_IS_H_SIZE);
+   writel(out_crop->height, base + CIF_ISP_IS_V_SIZE);
+
+   /* IS(Image Stabilization) is always on, working as output crop */
+   writel(1, base + CIF_ISP_IS_CTRL);
+   val = readl(base + CIF_ISP_CTRL);
+   val |= CIF_ISP_CTRL_ISP_CFG_UPD;
+   writel(val, base + CIF_ISP_CTRL);
+}
+
+/*
+ * configure isp blocks with input format, size..
+ */
+static int rkisp1_config_isp(struct rkisp1_device *dev)
+{
+   struct ispsd_in_fmt *in_fmt;
+   struct ispsd_out_fmt *out_fmt;
+   struct v4l

[PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

changes in V6:
  - add mipi txrx phy support
  - remove bool and enum from uapi header
  - add buf_prepare op
  - correct some spelling problems
  - return all queued buffers when starting stream failed

changes in V5: Sync with local changes,
  - fix the SP height limit
  - speed up the second stream capture
  - the second stream can't force sync for rsz when start/stop streaming
  - add frame id to param vb2 buf
  - enable luminance maximum threshold

changes in V4:
  - fix some bugs during development
  - move quantization settings to rkisp1 subdev
  - correct some spelling problems
  - describe ports in dt-binding documents

changes in V3:
  - add some comments
  - fix wrong use of v4l2_async_subdev_notifier_register
  - optimize two paths capture at a time
  - remove compose
  - re-struct headers
  - add a tmp wiki page: http://opensource.rock-chips.com/wiki_Rockchip-isp1

changes in V2:
  mipi-phy:
- use async probing
- make it be a child device of the GRF
  isp:
- add dummy buffer
- change the way to get bus configuration, which make it possible to
add parallel sensor support in the future(without mipi-phy driver).

This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399 SoC.

Wiki Pages:
http://opensource.rock-chips.com/wiki_Rockchip-isp1

The deprecated g_mbus_config op is not dropped in  V6 because i am waiting 
tomasz's patches.

v4l2-compliance for V6(isp params/stats nodes are passed):

v4l2-compliance SHA   : 93dc5f20727fede5097d67f8b9adabe4b8046d5b

Compliance test for device /dev/video0:

Driver Info:
Driver name  : rkisp1
Card type: rkisp1
Bus info : platform:ff91.isp
Driver version   : 4.16.0
Capabilities : 0x84201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps  : 0x04201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Media Driver Info:
Driver name  : rkisp1
Model: rkisp1
Serial   : 
Bus info : 
Media version: 4.16.0
Hardware revision: 0x (0)
Driver version   : 4.16.0
Interface Info:
ID   : 0x0307
Type : V4L Video
Entity Info:
ID   : 0x0006 (6)
Name : rkisp1_selfpath
Function : V4L2 I/O
Pad 0x0109   : Sink
  Link 0x0221: from remote pad 0x104 of entity 
'rkisp1-isp-subdev': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 9 Private Controls: 0

Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
fail: v4l2-test-formats.cpp(330): !colo

[PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

changes in V6:
  - add mipi txrx phy support
  - remove bool and enum from uapi header
  - add buf_prepare op
  - correct some spelling problems
  - return all queued buffers when starting stream failed

changes in V5: Sync with local changes,
  - fix the SP height limit
  - speed up the second stream capture
  - the second stream can't force sync for rsz when start/stop streaming
  - add frame id to param vb2 buf
  - enable luminance maximum threshold

changes in V4:
  - fix some bugs during development
  - move quantization settings to rkisp1 subdev
  - correct some spelling problems
  - describe ports in dt-binding documents

changes in V3:
  - add some comments
  - fix wrong use of v4l2_async_subdev_notifier_register
  - optimize two paths capture at a time
  - remove compose
  - re-struct headers
  - add a tmp wiki page: http://opensource.rock-chips.com/wiki_Rockchip-isp1

changes in V2:
  mipi-phy:
- use async probing
- make it be a child device of the GRF
  isp:
- add dummy buffer
- change the way to get bus configuration, which make it possible to
add parallel sensor support in the future(without mipi-phy driver).

This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399 SoC.

Wiki Pages:
http://opensource.rock-chips.com/wiki_Rockchip-isp1

The deprecated g_mbus_config op is not dropped in  V6 because i am waiting 
tomasz's patches.

v4l2-compliance for V6(isp params/stats nodes are passed):

v4l2-compliance SHA   : 93dc5f20727fede5097d67f8b9adabe4b8046d5b

Compliance test for device /dev/video0:

Driver Info:
Driver name  : rkisp1
Card type: rkisp1
Bus info : platform:ff91.isp
Driver version   : 4.16.0
Capabilities : 0x84201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps  : 0x04201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Media Driver Info:
Driver name  : rkisp1
Model: rkisp1
Serial   : 
Bus info : 
Media version: 4.16.0
Hardware revision: 0x (0)
Driver version   : 4.16.0
Interface Info:
ID   : 0x0307
Type : V4L Video
Entity Info:
ID   : 0x0006 (6)
Name : rkisp1_selfpath
Function : V4L2 I/O
Pad 0x0109   : Sink
  Link 0x0221: from remote pad 0x104 of entity 
'rkisp1-isp-subdev': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 9 Private Controls: 0

Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
fail: v4l2-test-formats.cpp(330): !colorspace
fail: v4l2-test

Re: [PATCH v5 04/16] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2018-02-08 Thread Jacob Chen
Hi hans,

2018-02-06 21:21 GMT+08:00 Hans Verkuil <hverk...@xs4all.nl>:
> On 12/29/17 08:52, Shunqian Zheng wrote:
>> From: Jacob Chen <jacob2.c...@rock-chips.com>
>>
>> This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver
>>
>> Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
>> Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
>> Signed-off-by: Tomasz Figa <tf...@chromium.org>
>> ---
>>  .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 787 
>> +
>>  1 file changed, 787 insertions(+)
>>  create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>>
>> diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c 
>> b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>> new file mode 100644
>> index 000..9421183
>> --- /dev/null
>> +++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>> @@ -0,0 +1,787 @@
>> +/*
>> + * Rockchip MIPI Synopsys DPHY driver
>> + *
>> + * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
>> + *
>> + * This software is available to you under a choice of one of two
>> + * licenses.  You may choose to be licensed under the terms of the GNU
>> + * General Public License (GPL) Version 2, available from the file
>> + * COPYING in the main directory of this source tree, or the
>> + * OpenIB.org BSD license below:
>> + *
>> + * Redistribution and use in source and binary forms, with or
>> + * without modification, are permitted provided that the following
>> + * conditions are met:
>> + *
>> + *  - Redistributions of source code must retain the above
>> + *copyright notice, this list of conditions and the following
>> + *disclaimer.
>> + *
>> + *  - Redistributions in binary form must reproduce the above
>> + *copyright notice, this list of conditions and the following
>> + *disclaimer in the documentation and/or other materials
>> + *provided with the distribution.
>> + *
>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
>> + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
>> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
>> + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
>> + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
>> + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
>> + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
>> + * SOFTWARE.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define RK3288_GRF_SOC_CON6  0x025c
>> +#define RK3288_GRF_SOC_CON8  0x0264
>> +#define RK3288_GRF_SOC_CON9  0x0268
>> +#define RK3288_GRF_SOC_CON10 0x026c
>> +#define RK3288_GRF_SOC_CON14 0x027c
>> +#define RK3288_GRF_SOC_STATUS21  0x02d4
>> +#define RK3288_GRF_IO_VSEL   0x0380
>> +#define RK3288_GRF_SOC_CON15 0x03a4
>> +
>> +#define RK3399_GRF_SOC_CON9  0x6224
>> +#define RK3399_GRF_SOC_CON21 0x6254
>> +#define RK3399_GRF_SOC_CON22 0x6258
>> +#define RK3399_GRF_SOC_CON23 0x625c
>> +#define RK3399_GRF_SOC_CON24 0x6260
>> +#define RK3399_GRF_SOC_CON25 0x6264
>> +#define RK3399_GRF_SOC_STATUS1   0xe2a4
>> +
>> +#define CLOCK_LANE_HS_RX_CONTROL 0x34
>> +#define LANE0_HS_RX_CONTROL  0x44
>> +#define LANE1_HS_RX_CONTROL  0x54
>> +#define LANE2_HS_RX_CONTROL  0x84
>> +#define LANE3_HS_RX_CONTROL  0x94
>> +#define HS_RX_DATA_LANES_THS_SETTLE__CONTROL 0x75
>> +
>> +#define HIWORD_UPDATE(val, mask, shift) \
>> + ((val) << (shift) | (mask) << ((shift) + 16))
>> +
>> +enum mipi_dphy_sy_pads {
>> + MIPI_DPHY_SY_PAD_SINK = 0,
>> + MIPI_DPHY_SY_PAD_SOURCE,
>> + MIPI_DPHY_SY_PADS_NUM,
>> +};
>> +
>> +enum dphy_reg_id {
>> + GRF_DPHY_RX0_TURNDISABLE = 0,
>> + GRF_DPHY_RX0_FORCERXMODE,
>> + GRF_DPHY_RX0_FORCETXSTOPMODE,
>> + GRF_DPHY_RX0_ENABLE,
>> + GRF_DPHY_RX0_TESTCLR,
>> + GRF_DPHY_RX0_TESTCLK,
>> + GRF_DPHY_RX0_TESTEN,
>> + GRF_DPHY_RX0_TESTDIN,
>> + GRF_DPHY_RX0_TURNREQUEST,
>> + GRF_DPHY_RX0_TESTDOUT,
&

Re: [PATCH v5 04/16] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2018-02-08 Thread Jacob Chen
Hi hans,

2018-02-06 21:21 GMT+08:00 Hans Verkuil :
> On 12/29/17 08:52, Shunqian Zheng wrote:
>> From: Jacob Chen 
>>
>> This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver
>>
>> Signed-off-by: Jacob Chen 
>> Signed-off-by: Shunqian Zheng 
>> Signed-off-by: Tomasz Figa 
>> ---
>>  .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 787 
>> +
>>  1 file changed, 787 insertions(+)
>>  create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>>
>> diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c 
>> b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>> new file mode 100644
>> index 000..9421183
>> --- /dev/null
>> +++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
>> @@ -0,0 +1,787 @@
>> +/*
>> + * Rockchip MIPI Synopsys DPHY driver
>> + *
>> + * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
>> + *
>> + * This software is available to you under a choice of one of two
>> + * licenses.  You may choose to be licensed under the terms of the GNU
>> + * General Public License (GPL) Version 2, available from the file
>> + * COPYING in the main directory of this source tree, or the
>> + * OpenIB.org BSD license below:
>> + *
>> + * Redistribution and use in source and binary forms, with or
>> + * without modification, are permitted provided that the following
>> + * conditions are met:
>> + *
>> + *  - Redistributions of source code must retain the above
>> + *copyright notice, this list of conditions and the following
>> + *disclaimer.
>> + *
>> + *  - Redistributions in binary form must reproduce the above
>> + *copyright notice, this list of conditions and the following
>> + *disclaimer in the documentation and/or other materials
>> + *provided with the distribution.
>> + *
>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
>> + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
>> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
>> + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
>> + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
>> + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
>> + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
>> + * SOFTWARE.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define RK3288_GRF_SOC_CON6  0x025c
>> +#define RK3288_GRF_SOC_CON8  0x0264
>> +#define RK3288_GRF_SOC_CON9  0x0268
>> +#define RK3288_GRF_SOC_CON10 0x026c
>> +#define RK3288_GRF_SOC_CON14 0x027c
>> +#define RK3288_GRF_SOC_STATUS21  0x02d4
>> +#define RK3288_GRF_IO_VSEL   0x0380
>> +#define RK3288_GRF_SOC_CON15 0x03a4
>> +
>> +#define RK3399_GRF_SOC_CON9  0x6224
>> +#define RK3399_GRF_SOC_CON21 0x6254
>> +#define RK3399_GRF_SOC_CON22 0x6258
>> +#define RK3399_GRF_SOC_CON23 0x625c
>> +#define RK3399_GRF_SOC_CON24 0x6260
>> +#define RK3399_GRF_SOC_CON25 0x6264
>> +#define RK3399_GRF_SOC_STATUS1   0xe2a4
>> +
>> +#define CLOCK_LANE_HS_RX_CONTROL 0x34
>> +#define LANE0_HS_RX_CONTROL  0x44
>> +#define LANE1_HS_RX_CONTROL  0x54
>> +#define LANE2_HS_RX_CONTROL  0x84
>> +#define LANE3_HS_RX_CONTROL  0x94
>> +#define HS_RX_DATA_LANES_THS_SETTLE__CONTROL 0x75
>> +
>> +#define HIWORD_UPDATE(val, mask, shift) \
>> + ((val) << (shift) | (mask) << ((shift) + 16))
>> +
>> +enum mipi_dphy_sy_pads {
>> + MIPI_DPHY_SY_PAD_SINK = 0,
>> + MIPI_DPHY_SY_PAD_SOURCE,
>> + MIPI_DPHY_SY_PADS_NUM,
>> +};
>> +
>> +enum dphy_reg_id {
>> + GRF_DPHY_RX0_TURNDISABLE = 0,
>> + GRF_DPHY_RX0_FORCERXMODE,
>> + GRF_DPHY_RX0_FORCETXSTOPMODE,
>> + GRF_DPHY_RX0_ENABLE,
>> + GRF_DPHY_RX0_TESTCLR,
>> + GRF_DPHY_RX0_TESTCLK,
>> + GRF_DPHY_RX0_TESTEN,
>> + GRF_DPHY_RX0_TESTDIN,
>> + GRF_DPHY_RX0_TURNREQUEST,
>> + GRF_DPHY_RX0_TESTDOUT,
>> + GRF_DPHY_TX0_TURNDISABLE,
>> + GRF_DPHY_TX0_FORCERXMODE,
>> + GRF_DPHY_TX0_FORCETXSTOPMODE,
>> + GRF_DPHY_TX0_TURNREQUEST

Re: [PATCH 1/2] [media] Add Rockchip RK1608 driver

2017-12-21 Thread Jacob Chen
Hi leo,


2017-12-12 14:28 GMT+08:00 Leo Wen :
> Rk1608 is used as a PreISP to link on Soc, which mainly has two functions.
> One is to download the firmware of RK1608, and the other is to match the
> extra sensor such as camera and enable sensor by calling sensor's s_power.
>
> use below v4l2-ctl command to capture frames.
>
> v4l2-ctl --verbose -d /dev/video1 --stream-mmap=2
> --stream-to=/tmp/stream.out --stream-count=60 --stream-poll
>
> use below command to playback the video on your PC.
>
> mplayer ./stream.out -loop 0 -demuxer rawvideo -rawvideo
> w=640:h=480:size=$((640*480*3/2)):format=NV12
>
> Signed-off-by: Leo Wen 
> ---
>  MAINTAINERS|6 +
>  drivers/media/spi/Makefile |1 +
>  drivers/media/spi/rk1608.c | 1165 
> 
>  drivers/media/spi/rk1608.h |  366 ++
>  4 files changed, 1538 insertions(+)
>  create mode 100644 drivers/media/spi/rk1608.c
>  create mode 100644 drivers/media/spi/rk1608.h
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 82ad0ea..48235d8 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -128,6 +128,12 @@ Maintainers List (try to look for most precise areas 
> first)
>
> ---
>
> +ROCKCHIP RK1608 DRIVER
> +M: Leo Wen 
> +S: Maintained
> +F: drivers/media/platform/spi/rk1608.c
> +F: drivers/media/platform/spi/rk1608.h
> +
>  3C59X NETWORK DRIVER
>  M: Steffen Klassert 
>  L: net...@vger.kernel.org
> diff --git a/drivers/media/spi/Makefile b/drivers/media/spi/Makefile
> index ea64013..9d9d9ec 100644
> --- a/drivers/media/spi/Makefile
> +++ b/drivers/media/spi/Makefile
> @@ -1 +1,2 @@
>  obj-$(CONFIG_VIDEO_GS1662) += gs1662.o
> +obj-$(CONFIG_ROCKCHIP_RK1608) += rk1608.o
> diff --git a/drivers/media/spi/rk1608.c b/drivers/media/spi/rk1608.c
> new file mode 100644
> index 000..e646204
> --- /dev/null
> +++ b/drivers/media/spi/rk1608.c
> @@ -0,0 +1,1165 @@
> +/**
> + * Rockchip rk1608 driver
> + *
> + * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
> + *
> + * This software is available to you under a choice of one of two
> + * licenses.  You may choose to be licensed under the terms of the GNU
> + * General Public License (GPL) Version 2, available from the file
> + * COPYING in the main directory of this source tree, or the
> + * OpenIB.org BSD license below:
> + *
> + * Redistribution and use in source and binary forms, with or
> + * without modification, are permitted provided that the following
> + * conditions are met:
> + *
> + *  - Redistributions of source code must retain the above
> + *copyright notice, this list of conditions and the following
> + *disclaimer.
> + *
> + *  - Redistributions in binary form must reproduce the above
> + *copyright notice, this list of conditions and the following
> + *disclaimer in the documentation and/or other materials
> + *provided with the distribution.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
> + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
> + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
> + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "rk1608.h"
> +
> +/**
> + * Rk1608 is used as the Pre-ISP to link on Soc, which mainly has two
> + * functions. One is to download the firmware of RK1608, and the other
> + * is to match the extra sensor such as camera and enable sensor by
> + * calling sensor's s_power.
> + * |---|
> + * | Sensor Camera |
> + * |---|
> + * |---||--|
> + * |---||--|
> + * |---\/--|
> + * | Pre-ISP RK1608|
> + * |---|
> + * |---||--|
> + * |---||--|
> + * |---\/--|
> + * |  Rockchip Soc |
> + * |---|
> + * Data Transfer As shown above. In RK1608, the data received from the
> + * extra sensor,and it is passed to the Soc through ISP.
> + */
> +struct rk1608_state {
> +   struct v4l2_subdev  sd;
> +   struct v4l2_subdev  *sensor_sd;
> +   struct device   *dev;
> +   struct spi_device   *spi;
> +   struct media_padpad;
> +   struct clk  *mclk;
> +   struct mutex

Re: [PATCH 1/2] [media] Add Rockchip RK1608 driver

2017-12-21 Thread Jacob Chen
Hi leo,


2017-12-12 14:28 GMT+08:00 Leo Wen :
> Rk1608 is used as a PreISP to link on Soc, which mainly has two functions.
> One is to download the firmware of RK1608, and the other is to match the
> extra sensor such as camera and enable sensor by calling sensor's s_power.
>
> use below v4l2-ctl command to capture frames.
>
> v4l2-ctl --verbose -d /dev/video1 --stream-mmap=2
> --stream-to=/tmp/stream.out --stream-count=60 --stream-poll
>
> use below command to playback the video on your PC.
>
> mplayer ./stream.out -loop 0 -demuxer rawvideo -rawvideo
> w=640:h=480:size=$((640*480*3/2)):format=NV12
>
> Signed-off-by: Leo Wen 
> ---
>  MAINTAINERS|6 +
>  drivers/media/spi/Makefile |1 +
>  drivers/media/spi/rk1608.c | 1165 
> 
>  drivers/media/spi/rk1608.h |  366 ++
>  4 files changed, 1538 insertions(+)
>  create mode 100644 drivers/media/spi/rk1608.c
>  create mode 100644 drivers/media/spi/rk1608.h
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 82ad0ea..48235d8 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -128,6 +128,12 @@ Maintainers List (try to look for most precise areas 
> first)
>
> ---
>
> +ROCKCHIP RK1608 DRIVER
> +M: Leo Wen 
> +S: Maintained
> +F: drivers/media/platform/spi/rk1608.c
> +F: drivers/media/platform/spi/rk1608.h
> +
>  3C59X NETWORK DRIVER
>  M: Steffen Klassert 
>  L: net...@vger.kernel.org
> diff --git a/drivers/media/spi/Makefile b/drivers/media/spi/Makefile
> index ea64013..9d9d9ec 100644
> --- a/drivers/media/spi/Makefile
> +++ b/drivers/media/spi/Makefile
> @@ -1 +1,2 @@
>  obj-$(CONFIG_VIDEO_GS1662) += gs1662.o
> +obj-$(CONFIG_ROCKCHIP_RK1608) += rk1608.o
> diff --git a/drivers/media/spi/rk1608.c b/drivers/media/spi/rk1608.c
> new file mode 100644
> index 000..e646204
> --- /dev/null
> +++ b/drivers/media/spi/rk1608.c
> @@ -0,0 +1,1165 @@
> +/**
> + * Rockchip rk1608 driver
> + *
> + * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
> + *
> + * This software is available to you under a choice of one of two
> + * licenses.  You may choose to be licensed under the terms of the GNU
> + * General Public License (GPL) Version 2, available from the file
> + * COPYING in the main directory of this source tree, or the
> + * OpenIB.org BSD license below:
> + *
> + * Redistribution and use in source and binary forms, with or
> + * without modification, are permitted provided that the following
> + * conditions are met:
> + *
> + *  - Redistributions of source code must retain the above
> + *copyright notice, this list of conditions and the following
> + *disclaimer.
> + *
> + *  - Redistributions in binary form must reproduce the above
> + *copyright notice, this list of conditions and the following
> + *disclaimer in the documentation and/or other materials
> + *provided with the distribution.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
> + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
> + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
> + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "rk1608.h"
> +
> +/**
> + * Rk1608 is used as the Pre-ISP to link on Soc, which mainly has two
> + * functions. One is to download the firmware of RK1608, and the other
> + * is to match the extra sensor such as camera and enable sensor by
> + * calling sensor's s_power.
> + * |---|
> + * | Sensor Camera |
> + * |---|
> + * |---||--|
> + * |---||--|
> + * |---\/--|
> + * | Pre-ISP RK1608|
> + * |---|
> + * |---||--|
> + * |---||--|
> + * |---\/--|
> + * |  Rockchip Soc |
> + * |---|
> + * Data Transfer As shown above. In RK1608, the data received from the
> + * extra sensor,and it is passed to the Soc through ISP.
> + */
> +struct rk1608_state {
> +   struct v4l2_subdev  sd;
> +   struct v4l2_subdev  *sensor_sd;
> +   struct device   *dev;
> +   struct spi_device   *spi;
> +   struct media_padpad;
> +   struct clk  *mclk;
> +   struct mutexlock;   /* protect resource */
> +   struct mutexsensor_lock;/* protect sensor 

[PATCH v4 11/16] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add DT bindings documentation for Rockchip MIPI D-PHY RX

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 .../bindings/media/rockchip-mipi-dphy.txt  | 88 ++
 1 file changed, 88 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt 
b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
new file mode 100644
index ..0571d7f35867
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
@@ -0,0 +1,88 @@
+Rockchip SoC MIPI RX D-PHY
+-
+
+Required properties:
+- compatible: value should be one of the following
+   "rockchip,rk3288-mipi-dphy"
+   "rockchip,rk3399-mipi-dphy"
+- clocks : list of clock specifiers, corresponding to entries in
+   clock-names property;
+- clock-names: required clock name.
+
+MIPI RX0 D-PHY use registers in "general register files", it
+should be a child of the GRF.
+MIPI TXRX D-PHY have its own registers, it must have a reg property.
+
+Optional properties:
+- reg: offset and length of the register set for the device.
+
+port node
+---
+
+The device node should contain two 'port' child nodes, according to the 
bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+The first port show the sensors connected in this mipi-dphy.
+- endpoint:
+   - remote-endpoint: Linked to a sensor with a MIPI CSI-2 video bus.
+   - data-lanes : (required) an array specifying active physical MIPI-CSI2
+   data input lanes and their mapping to logical lanes; the
+   D-PHY can't reroute lanes, so the array's content should
+   be consecutive and only its length is meaningful.
+
+The port node must contain at least one endpoint. It could have multiple 
endpoints
+linked to different sensors, but please note that they are not supposed to be
+actived at the same time.
+
+The second port should be connected to isp node.
+- endpoint:
+   - remote-endpoint:  Linked to Rockchip ISP1, which is defined
+   in rockchip-isp1.txt.
+
+Device node example
+---
+
+grf: syscon@ff77 {
+   compatible = "rockchip,rk3288-grf", "syscon", "simple-mfd";
+
+...
+
+   mipi_dphy_rx0: mipi-dphy-rx0 {
+   compatible = "rockchip,rk3399-mipi-dphy";
+   clocks = < SCLK_MIPIDPHY_REF>,
+   < SCLK_DPHY_RX0_CFG>,
+   < PCLK_VIO_GRF>;
+   clock-names = "dphy-ref", "dphy-cfg", "grf";
+   power-domains = < RK3399_PD_VIO>;
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   mipi_in_wcam: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_out>;
+   data-lanes = <1 2>;
+   };
+   mipi_in_ucam: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_out>;
+   data-lanes = <1>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   dphy_rx0_out: endpoint {
+   remote-endpoint = <_mipi_in>;
+   };
+   };
+   };
+   };
+};
-- 
2.15.1



[PATCH v4 11/16] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

Add DT bindings documentation for Rockchip MIPI D-PHY RX

Signed-off-by: Jacob Chen 
---
 .../bindings/media/rockchip-mipi-dphy.txt  | 88 ++
 1 file changed, 88 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt 
b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
new file mode 100644
index ..0571d7f35867
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
@@ -0,0 +1,88 @@
+Rockchip SoC MIPI RX D-PHY
+-
+
+Required properties:
+- compatible: value should be one of the following
+   "rockchip,rk3288-mipi-dphy"
+   "rockchip,rk3399-mipi-dphy"
+- clocks : list of clock specifiers, corresponding to entries in
+   clock-names property;
+- clock-names: required clock name.
+
+MIPI RX0 D-PHY use registers in "general register files", it
+should be a child of the GRF.
+MIPI TXRX D-PHY have its own registers, it must have a reg property.
+
+Optional properties:
+- reg: offset and length of the register set for the device.
+
+port node
+---
+
+The device node should contain two 'port' child nodes, according to the 
bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+The first port show the sensors connected in this mipi-dphy.
+- endpoint:
+   - remote-endpoint: Linked to a sensor with a MIPI CSI-2 video bus.
+   - data-lanes : (required) an array specifying active physical MIPI-CSI2
+   data input lanes and their mapping to logical lanes; the
+   D-PHY can't reroute lanes, so the array's content should
+   be consecutive and only its length is meaningful.
+
+The port node must contain at least one endpoint. It could have multiple 
endpoints
+linked to different sensors, but please note that they are not supposed to be
+actived at the same time.
+
+The second port should be connected to isp node.
+- endpoint:
+   - remote-endpoint:  Linked to Rockchip ISP1, which is defined
+   in rockchip-isp1.txt.
+
+Device node example
+---
+
+grf: syscon@ff77 {
+   compatible = "rockchip,rk3288-grf", "syscon", "simple-mfd";
+
+...
+
+   mipi_dphy_rx0: mipi-dphy-rx0 {
+   compatible = "rockchip,rk3399-mipi-dphy";
+   clocks = < SCLK_MIPIDPHY_REF>,
+   < SCLK_DPHY_RX0_CFG>,
+   < PCLK_VIO_GRF>;
+   clock-names = "dphy-ref", "dphy-cfg", "grf";
+   power-domains = < RK3399_PD_VIO>;
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   mipi_in_wcam: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_out>;
+   data-lanes = <1 2>;
+   };
+   mipi_in_ucam: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_out>;
+   data-lanes = <1>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   dphy_rx0_out: endpoint {
+   remote-endpoint = <_mipi_in>;
+   };
+   };
+   };
+   };
+};
-- 
2.15.1



[PATCH v4 09/16] media: rkisp1: add rockchip isp1 core driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add the core driver for rockchip isp1.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Yichong Zhong <z...@rock-chips.com>
Signed-off-by: Jacob Chen <c...@rock-chips.com>
Signed-off-by: Eddie Cai <eddie.cai.li...@gmail.com>
Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com>
Signed-off-by: Allon Huang <allon.hu...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 drivers/media/platform/Kconfig|  10 +
 drivers/media/platform/Makefile   |   1 +
 drivers/media/platform/rockchip/isp1/Makefile |   8 +
 drivers/media/platform/rockchip/isp1/common.h | 137 ++
 drivers/media/platform/rockchip/isp1/dev.c| 653 ++
 drivers/media/platform/rockchip/isp1/dev.h| 120 +
 6 files changed, 929 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/Makefile
 create mode 100644 drivers/media/platform/rockchip/isp1/common.h
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.c
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index fd0c99859d6f..062fffc9ffb6 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -117,6 +117,16 @@ config VIDEO_QCOM_CAMSS
select VIDEOBUF2_DMA_SG
select V4L2_FWNODE
 
+config VIDEO_ROCKCHIP_ISP1
+   tristate "Rockchip Image Signal Processing v1 Unit driver"
+   depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on ARCH_ROCKCHIP || COMPILE_TEST
+   select VIDEOBUF2_DMA_CONTIG
+   select V4L2_FWNODE
+   default n
+   ---help---
+ Support for ISP1 on the rockchip SoC.
+
 config VIDEO_S3C_CAMIF
tristate "Samsung S3C24XX/S3C64XX SoC Camera Interface driver"
depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 003b0bb2cddf..d235908df63e 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -67,6 +67,7 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1)  += rcar_fdp1.o
 obj-$(CONFIG_VIDEO_RENESAS_JPU)+= rcar_jpu.o
 obj-$(CONFIG_VIDEO_RENESAS_VSP1)   += vsp1/
 
+obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1)  += rockchip/isp1/
 obj-$(CONFIG_VIDEO_ROCKCHIP_RGA)   += rockchip/rga/
 
 obj-y  += omap/
diff --git a/drivers/media/platform/rockchip/isp1/Makefile 
b/drivers/media/platform/rockchip/isp1/Makefile
new file mode 100644
index ..18af64853734
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/Makefile
@@ -0,0 +1,8 @@
+obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) +=   video_rkisp1.o
+video_rkisp1-objs +=   rkisp1.o \
+   dev.o \
+   regs.o \
+   isp_stats.o \
+   isp_params.o \
+   mipi_dphy_sy.o \
+   capture.o
diff --git a/drivers/media/platform/rockchip/isp1/common.h 
b/drivers/media/platform/rockchip/isp1/common.h
new file mode 100644
index ..1adfb9039b60
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/common.h
@@ -0,0 +1,137 @@
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef _RKISP1_COMMON_H
+#define _RKISP1_COMMON_H
+
+#include 
+

[PATCH v4 09/16] media: rkisp1: add rockchip isp1 core driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

Add the core driver for rockchip isp1.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/Kconfig|  10 +
 drivers/media/platform/Makefile   |   1 +
 drivers/media/platform/rockchip/isp1/Makefile |   8 +
 drivers/media/platform/rockchip/isp1/common.h | 137 ++
 drivers/media/platform/rockchip/isp1/dev.c| 653 ++
 drivers/media/platform/rockchip/isp1/dev.h| 120 +
 6 files changed, 929 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/Makefile
 create mode 100644 drivers/media/platform/rockchip/isp1/common.h
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.c
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index fd0c99859d6f..062fffc9ffb6 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -117,6 +117,16 @@ config VIDEO_QCOM_CAMSS
select VIDEOBUF2_DMA_SG
select V4L2_FWNODE
 
+config VIDEO_ROCKCHIP_ISP1
+   tristate "Rockchip Image Signal Processing v1 Unit driver"
+   depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on ARCH_ROCKCHIP || COMPILE_TEST
+   select VIDEOBUF2_DMA_CONTIG
+   select V4L2_FWNODE
+   default n
+   ---help---
+ Support for ISP1 on the rockchip SoC.
+
 config VIDEO_S3C_CAMIF
tristate "Samsung S3C24XX/S3C64XX SoC Camera Interface driver"
depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 003b0bb2cddf..d235908df63e 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -67,6 +67,7 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1)  += rcar_fdp1.o
 obj-$(CONFIG_VIDEO_RENESAS_JPU)+= rcar_jpu.o
 obj-$(CONFIG_VIDEO_RENESAS_VSP1)   += vsp1/
 
+obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1)  += rockchip/isp1/
 obj-$(CONFIG_VIDEO_ROCKCHIP_RGA)   += rockchip/rga/
 
 obj-y  += omap/
diff --git a/drivers/media/platform/rockchip/isp1/Makefile 
b/drivers/media/platform/rockchip/isp1/Makefile
new file mode 100644
index ..18af64853734
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/Makefile
@@ -0,0 +1,8 @@
+obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) +=   video_rkisp1.o
+video_rkisp1-objs +=   rkisp1.o \
+   dev.o \
+   regs.o \
+   isp_stats.o \
+   isp_params.o \
+   mipi_dphy_sy.o \
+   capture.o
diff --git a/drivers/media/platform/rockchip/isp1/common.h 
b/drivers/media/platform/rockchip/isp1/common.h
new file mode 100644
index ..1adfb9039b60
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/common.h
@@ -0,0 +1,137 @@
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef _RKISP1_COMMON_H
+#define _RKISP1_COMMON_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RKISP1_DEFAULT_WIDTH   800
+#define RKISP1_DEFAULT_HEIGHT  600
+
+#define RKISP1_MAX_STREAM  2
+#define RKISP1_STREAM_SP   0
+#define RKISP1_STREAM_MP   1
+
+#define RKI

[PATCH v4 15/16] arm64: dts: rockchip: add rx0 mipi-phy for rk3399

2017-12-18 Thread Jacob Chen
From: Shunqian Zheng <zhen...@rock-chips.com>

It's a Designware MIPI D-PHY, used for ISP0 in rk3399.

Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index 66a912fab5dd..8ef321f03010 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1292,6 +1292,16 @@
status = "disabled";
};
 
+   mipi_dphy_rx0: mipi-dphy-rx0 {
+   compatible = "rockchip,rk3399-mipi-dphy";
+   clocks = < SCLK_MIPIDPHY_REF>,
+   < SCLK_DPHY_RX0_CFG>,
+   < PCLK_VIO_GRF>;
+   clock-names = "dphy-ref", "dphy-cfg", "grf";
+   power-domains = < RK3399_PD_VIO>;
+   status = "disabled";
+   };
+
u2phy0: usb2-phy@e450 {
compatible = "rockchip,rk3399-usb2phy";
reg = <0xe450 0x10>;
-- 
2.15.1



[PATCH v4 14/16] arm64: dts: rockchip: add isp0 node for rk3399

2017-12-18 Thread Jacob Chen
From: Shunqian Zheng <zhen...@rock-chips.com>

rk3399 have two ISP, but we havn't test isp1, so just add isp0 at present.

Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index d340b58ab184..66a912fab5dd 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1588,6 +1588,21 @@
status = "disabled";
};
 
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+   status = "disabled";
+   };
+
isp0_mmu: iommu@ff914000 {
compatible = "rockchip,iommu";
reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
-- 
2.15.1



[PATCH v4 15/16] arm64: dts: rockchip: add rx0 mipi-phy for rk3399

2017-12-18 Thread Jacob Chen
From: Shunqian Zheng 

It's a Designware MIPI D-PHY, used for ISP0 in rk3399.

Signed-off-by: Shunqian Zheng 
Signed-off-by: Jacob Chen 
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index 66a912fab5dd..8ef321f03010 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1292,6 +1292,16 @@
status = "disabled";
};
 
+   mipi_dphy_rx0: mipi-dphy-rx0 {
+   compatible = "rockchip,rk3399-mipi-dphy";
+   clocks = < SCLK_MIPIDPHY_REF>,
+   < SCLK_DPHY_RX0_CFG>,
+   < PCLK_VIO_GRF>;
+   clock-names = "dphy-ref", "dphy-cfg", "grf";
+   power-domains = < RK3399_PD_VIO>;
+   status = "disabled";
+   };
+
u2phy0: usb2-phy@e450 {
compatible = "rockchip,rk3399-usb2phy";
reg = <0xe450 0x10>;
-- 
2.15.1



[PATCH v4 14/16] arm64: dts: rockchip: add isp0 node for rk3399

2017-12-18 Thread Jacob Chen
From: Shunqian Zheng 

rk3399 have two ISP, but we havn't test isp1, so just add isp0 at present.

Signed-off-by: Shunqian Zheng 
Signed-off-by: Jacob Chen 
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index d340b58ab184..66a912fab5dd 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1588,6 +1588,21 @@
status = "disabled";
};
 
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+   status = "disabled";
+   };
+
isp0_mmu: iommu@ff914000 {
compatible = "rockchip,iommu";
reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
-- 
2.15.1



[PATCH v4 16/16] MAINTAINERS: add entry for Rockchip ISP1 driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add MAINTAINERS entry for the rockchip isp1 driver.
This driver is maintained by rockchip officially and it
will be used for rockchip SoC on all linux-kernel based OS.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index b05bc2c5e85c..614196ed7265 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11665,6 +11665,16 @@ F: drivers/hid/hid-roccat*
 F: include/linux/hid-roccat*
 F: Documentation/ABI/*/sysfs-driver-hid-roccat*
 
+ROCKCHIP ISP V1 DRIVER
+M:     Jacob chen <jacob2.c...@rock-chips.com>
+M: Shunqian Zheng <zhen...@rock-chips.com>
+M: Yichong Zhong <z...@rock-chips.com>
+L: linux-me...@vger.kernel.org
+S: Maintained
+F: drivers/media/platform/rockchip/isp1/
+F: Documentation/devicetree/bindings/media/rockchip-isp1.txt
+F: Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
+
 ROCKCHIP RASTER 2D GRAPHIC ACCELERATION UNIT DRIVER
 M: Jacob chen <jacob2.c...@rock-chips.com>
 L: linux-me...@vger.kernel.org
-- 
2.15.1



[PATCH v4 16/16] MAINTAINERS: add entry for Rockchip ISP1 driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

Add MAINTAINERS entry for the rockchip isp1 driver.
This driver is maintained by rockchip officially and it
will be used for rockchip SoC on all linux-kernel based OS.

Signed-off-by: Jacob Chen 
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index b05bc2c5e85c..614196ed7265 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11665,6 +11665,16 @@ F: drivers/hid/hid-roccat*
 F: include/linux/hid-roccat*
 F: Documentation/ABI/*/sysfs-driver-hid-roccat*
 
+ROCKCHIP ISP V1 DRIVER
+M: Jacob chen 
+M: Shunqian Zheng 
+M: Yichong Zhong 
+L: linux-me...@vger.kernel.org
+S: Maintained
+F: drivers/media/platform/rockchip/isp1/
+F: Documentation/devicetree/bindings/media/rockchip-isp1.txt
+F: Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
+
 ROCKCHIP RASTER 2D GRAPHIC ACCELERATION UNIT DRIVER
 M: Jacob chen 
 L: linux-me...@vger.kernel.org
-- 
2.15.1



[PATCH v4 10/16] dt-bindings: Document the Rockchip ISP1 bindings

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add DT bindings documentation for Rockchip ISP1

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 .../devicetree/bindings/media/rockchip-isp1.txt| 69 ++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-isp1.txt 
b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
new file mode 100644
index ..4631a4b7c88a
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
@@ -0,0 +1,69 @@
+Rockchip SoC Image Signal Processing unit v1
+--
+
+Rockchip ISP1 is the Camera interface for the Rockchip series of SoCs
+which contains image processing, scaling, and compression funcitons.
+
+Required properties:
+- compatible: value should be one of the following
+   "rockchip,rk3288-cif-isp";
+   "rockchip,rk3399-cif-isp";
+- reg : offset and length of the register set for the device.
+- interrupts: should contain ISP interrupt.
+- clocks: phandle to the required clocks.
+- clock-names: required clock name.
+- iommus: required a iommu node.
+
+port node
+---
+
+The device node should contain one 'port' child node with child 'endpoint'
+nodes, according to the bindings defined in Documentation/devicetree/bindings/
+media/video-interfaces.txt.
+
+- endpoint(parallel):
+   - remote-endpoint: Connecting to a sensor with a parallel video bus.
+   - parallel_bus properties: Refer to Documentation/devicetree/bindings/
+   media/video-interfaces.txt.
+- endpoint(mipi):
+   - remote-endpoint: Connecting to Rockchip MIPI-DPHY,
+   which is defined in rockchip-mipi-dphy.txt.
+
+The port node must contain at least one endpoint, either parallel or mipi.
+It could have multiple endpoints, but please note the hardware don't support
+two sensors work at a time, they are supposed to work asynchronously.
+
+Device node example
+---
+
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   /* mipi */
+   isp0_mipi_in: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_rx0_out>;
+   };
+
+   /* parallel */
+   isp0_parallel_in: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_out>;
+   bus-width = <8>;
+   };
+   };
+   };
-- 
2.15.1



[PATCH v4 10/16] dt-bindings: Document the Rockchip ISP1 bindings

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

Add DT bindings documentation for Rockchip ISP1

Signed-off-by: Jacob Chen 
---
 .../devicetree/bindings/media/rockchip-isp1.txt| 69 ++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-isp1.txt 
b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
new file mode 100644
index ..4631a4b7c88a
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
@@ -0,0 +1,69 @@
+Rockchip SoC Image Signal Processing unit v1
+--
+
+Rockchip ISP1 is the Camera interface for the Rockchip series of SoCs
+which contains image processing, scaling, and compression funcitons.
+
+Required properties:
+- compatible: value should be one of the following
+   "rockchip,rk3288-cif-isp";
+   "rockchip,rk3399-cif-isp";
+- reg : offset and length of the register set for the device.
+- interrupts: should contain ISP interrupt.
+- clocks: phandle to the required clocks.
+- clock-names: required clock name.
+- iommus: required a iommu node.
+
+port node
+---
+
+The device node should contain one 'port' child node with child 'endpoint'
+nodes, according to the bindings defined in Documentation/devicetree/bindings/
+media/video-interfaces.txt.
+
+- endpoint(parallel):
+   - remote-endpoint: Connecting to a sensor with a parallel video bus.
+   - parallel_bus properties: Refer to Documentation/devicetree/bindings/
+   media/video-interfaces.txt.
+- endpoint(mipi):
+   - remote-endpoint: Connecting to Rockchip MIPI-DPHY,
+   which is defined in rockchip-mipi-dphy.txt.
+
+The port node must contain at least one endpoint, either parallel or mipi.
+It could have multiple endpoints, but please note the hardware don't support
+two sensors work at a time, they are supposed to work asynchronously.
+
+Device node example
+---
+
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   /* mipi */
+   isp0_mipi_in: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_rx0_out>;
+   };
+
+   /* parallel */
+   isp0_parallel_in: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_out>;
+   bus-width = <8>;
+   };
+   };
+   };
-- 
2.15.1



[PATCH v4 13/16] ARM: dts: rockchip: add rx0 mipi-phy for rk3288

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

It's a Designware MIPI D-PHY, used by ISP in rk3288.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 arch/arm/boot/dts/rk3288.dtsi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index ed0b17d1b116..aa9ad3a6e0a5 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -864,6 +864,13 @@
status = "disabled";
};
 
+   mipi_phy_rx0: mipi-phy-rx0 {
+   compatible = "rockchip,rk3288-mipi-dphy";
+   clocks = < SCLK_MIPIDSI_24M>, < PCLK_MIPI_CSI>;
+   clock-names = "dphy-ref", "pclk";
+   status = "disabled";
+   };
+
io_domains: io-domains {
compatible = "rockchip,rk3288-io-voltage-domain";
status = "disabled";
-- 
2.15.1



[PATCH v4 12/16] ARM: dts: rockchip: add isp node for rk3288

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

rk3288 have a Embedded 13M ISP

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 arch/arm/boot/dts/rk3288.dtsi | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index f3e7f98c2724..ed0b17d1b116 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -962,6 +962,23 @@
status = "disabled";
};
 
+   isp: isp@ff91 {
+   compatible = "rockchip,rk3288-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP>, < ACLK_ISP>,
+< HCLK_ISP>, < PCLK_ISP_IN>,
+< SCLK_ISP_JPE>;
+   clock-names = "clk_isp", "aclk_isp",
+ "hclk_isp", "pclk_isp_in",
+ "sclk_isp_jpe";
+   assigned-clocks = < SCLK_ISP>, < SCLK_ISP_JPE>;
+   assigned-clock-rates = <4>, <4>;
+   power-domains = < RK3288_PD_VIO>;
+   iommus = <_mmu>;
+   status = "disabled";
+   };
+
isp_mmu: iommu@ff914000 {
compatible = "rockchip,iommu";
reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
-- 
2.15.1



[PATCH v4 13/16] ARM: dts: rockchip: add rx0 mipi-phy for rk3288

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

It's a Designware MIPI D-PHY, used by ISP in rk3288.

Signed-off-by: Jacob Chen 
---
 arch/arm/boot/dts/rk3288.dtsi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index ed0b17d1b116..aa9ad3a6e0a5 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -864,6 +864,13 @@
status = "disabled";
};
 
+   mipi_phy_rx0: mipi-phy-rx0 {
+   compatible = "rockchip,rk3288-mipi-dphy";
+   clocks = < SCLK_MIPIDSI_24M>, < PCLK_MIPI_CSI>;
+   clock-names = "dphy-ref", "pclk";
+   status = "disabled";
+   };
+
io_domains: io-domains {
compatible = "rockchip,rk3288-io-voltage-domain";
status = "disabled";
-- 
2.15.1



[PATCH v4 12/16] ARM: dts: rockchip: add isp node for rk3288

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

rk3288 have a Embedded 13M ISP

Signed-off-by: Jacob Chen 
---
 arch/arm/boot/dts/rk3288.dtsi | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index f3e7f98c2724..ed0b17d1b116 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -962,6 +962,23 @@
status = "disabled";
};
 
+   isp: isp@ff91 {
+   compatible = "rockchip,rk3288-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP>, < ACLK_ISP>,
+< HCLK_ISP>, < PCLK_ISP_IN>,
+< SCLK_ISP_JPE>;
+   clock-names = "clk_isp", "aclk_isp",
+ "hclk_isp", "pclk_isp_in",
+ "sclk_isp_jpe";
+   assigned-clocks = < SCLK_ISP>, < SCLK_ISP_JPE>;
+   assigned-clock-rates = <4>, <4>;
+   power-domains = < RK3288_PD_VIO>;
+   iommus = <_mmu>;
+   status = "disabled";
+   };
+
isp_mmu: iommu@ff914000 {
compatible = "rockchip,iommu";
reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
-- 
2.15.1



[PATCH v4 07/16] media: rkisp1: add ISP1 params driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add the output video driver that accept params from userspace.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Yichong Zhong <z...@rock-chips.com>
Signed-off-by: Jacob Chen <c...@rock-chips.com>
Signed-off-by: Eddie Cai <eddie.cai.li...@gmail.com>
Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com>
Signed-off-by: Allon Huang <allon.hu...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 drivers/media/platform/rockchip/isp1/isp_params.c | 1537 +
 drivers/media/platform/rockchip/isp1/isp_params.h |   76 +
 2 files changed, 1613 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.h

diff --git a/drivers/media/platform/rockchip/isp1/isp_params.c 
b/drivers/media/platform/rockchip/isp1/isp_params.c
new file mode 100644
index ..287f8523dbd9
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/isp_params.c
@@ -0,0 +1,1537 @@
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include/* for ISP params */
+#include "dev.h"
+#include "regs.h"
+
+#define RKISP1_ISP_PARAMS_REQ_BUFS_MIN 2
+#define RKISP1_ISP_PARAMS_REQ_BUFS_MAX 8
+
+#define BLS_START_H_MAX_IS_VALID(val)  ((val) < CIFISP_BLS_START_H_MAX)
+#define BLS_STOP_H_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_STOP_H_MAX)
+
+#define BLS_START_V_MAX_IS_VALID(val)  ((val) < CIFISP_BLS_START_V_MAX)
+#define BLS_STOP_V_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_STOP_V_MAX)
+
+#define BLS_SAMPLE_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_SAMPLES_MAX)
+
+#define BLS_FIX_SUB_IS_VALID(val)  \
+   ((val) > (s16) CIFISP_BLS_FIX_SUB_MIN && (val) < CIFISP_BLS_FIX_SUB_MAX)
+
+#define RKISP1_ISP_DPCC_LINE_THRESH(n) (CIF_ISP_DPCC_LINE_THRESH_1 + 0x14 * 
(n))
+#define RKISP1_ISP_DPCC_LINE_MAD_FAC(n) (CIF_ISP_DPCC_LINE_MAD_FAC_1 + 0x14 * 
(n))
+#define RKISP1_ISP_DPCC_PG_FAC(n)  (CIF_ISP_DPCC_PG_FAC_1 + 0x14 * (n))
+#define RKISP1_ISP_DPCC_RND_THRESH(n)  (CIF_ISP_DPCC_RND_THRESH_1 + 0x14 * (n))
+#define RKISP1_ISP_DPCC_RG_FAC(n)  (CIF_ISP_DPCC_RG_FAC_1 + 0x14 * (n))
+#define RKISP1_ISP_CC_COEFF(n) (CIF_ISP_CC_COEFF_0 + (n) * 4)
+
+static inline void rkisp1_iowrite32(struct rkisp1_isp_params_vdev *params_vdev,
+   u32 value, u32 addr)
+{
+   iowrite32(value, params_vdev->dev->base_addr + addr);
+}
+
+static inline u32 rkisp1_ioread32(struct rkisp1_isp_params_vdev *params_vdev,
+ u32 addr)
+{
+   return ioread32(params_vdev->dev->base_addr + addr);
+}
+
+static inline void isp_param_set_bits(struct rkisp1_isp_params_vdev
+*params_vdev,
+ u32 reg, u32 bit_mask)
+{
+   u32 val;
+
+   val = rkisp1_ioread32(params_vdev, reg);
+   rkisp1_iowrite32(params_vdev, val | bit_mask, reg);
+}
+
+static inline void isp_param_clear_bits(struct rkisp1_isp_params_vdev
+  *params_vdev,
+   u32 reg, u32 bit_mask)
+{
+   u32 val;
+
+   val = rkisp1_ioread32(params_vdev, reg);
+   rkisp1_iowrite32(params_vdev, val & ~bit_mask, reg);
+}
+
+/* ISP BP interface function */
+static void dpcc_con

[PATCH v4 08/16] media: rkisp1: add capture device driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

This is the capture device interface driver that provides the v4l2
user interface. Frames can be received from ISP1.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Yichong Zhong <z...@rock-chips.com>
Signed-off-by: Jacob Chen <c...@rock-chips.com>
Signed-off-by: Eddie Cai <eddie.cai.li...@gmail.com>
Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com>
Signed-off-by: Allon Huang <allon.hu...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 drivers/media/platform/rockchip/isp1/capture.c | 1704 
 drivers/media/platform/rockchip/isp1/capture.h |  194 +++
 drivers/media/platform/rockchip/isp1/regs.c|  264 
 drivers/media/platform/rockchip/isp1/regs.h| 1577 ++
 4 files changed, 3739 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.c
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.h
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.c
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.h

diff --git a/drivers/media/platform/rockchip/isp1/capture.c 
b/drivers/media/platform/rockchip/isp1/capture.c
new file mode 100644
index ..542c35223665
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/capture.c
@@ -0,0 +1,1704 @@
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "dev.h"
+#include "regs.h"
+
+/*
+ * NOTE:
+ * 1. There are two capture video devices in rkisp1, selfpath and mainpath
+ * 2. Two capture device have separated memory-interface/crop/scale units.
+ * 3. Besides describing stream hardware, this file also contain entries for 
pipeline operations.
+ * 4. The register read/write operations in this file are put into regs.c.
+ */
+
+/*
+ * differences between selfpatch and mainpath
+ * available mp sink input: isp
+ * available sp sink input : isp, dma(TODO)
+ * available mp sink pad fmts: yuv422, raw
+ * available sp sink pad fmts: yuv422, yuv420..
+ * available mp source fmts: yuv, raw, jpeg(TODO)
+ * available sp source fmts: yuv, rgb
+ */
+
+#define CIF_ISP_REQ_BUFS_MIN 1
+#define CIF_ISP_REQ_BUFS_MAX 8
+
+#define STREAM_PAD_SINK0
+#define STREAM_PAD_SOURCE  1
+
+#define STREAM_MAX_MP_RSZ_OUTPUT_WIDTH 4416
+#define STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT3312
+#define STREAM_MAX_SP_RSZ_OUTPUT_WIDTH 1920
+#define STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT1080
+#define STREAM_MIN_RSZ_OUTPUT_WIDTH32
+#define STREAM_MIN_RSZ_OUTPUT_HEIGHT   16
+
+#define STREAM_MAX_MP_SP_INPUT_WIDTH STREAM_MAX_MP_RSZ_OUTPUT_WIDTH
+#define STREAM_MAX_MP_SP_INPUT_HEIGHT STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT
+#define STREAM_MIN_MP_SP_INPUT_WIDTH   32
+#define STREAM_MIN_MP_SP_INPUT_HEIGHT  32
+
+/* Get xsubs and ysubs for fourcc formats
+ *
+ * @xsubs: horizontal color samples in a 4*4 matrix, for yuv
+ * @ysubs: vertical color samples in a 4*4 matrix, for yuv
+ */
+static int fcc_xysubs(u32 fcc, u32 *xsubs, u32 *ysubs)
+{
+   switch (fcc) {
+   case V4L2_PIX_FMT_GREY:
+   case V4L2_PIX_FMT_YUV444M:
+   *xsubs = 1;
+   *ysubs = 1;
+   break;
+   case V4L2_PIX_FMT_YUYV:
+   case V4L2_PIX_FMT_Y

[PATCH v4 06/16] media: rkisp1: add ISP1 statistics driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add the capture video driver for rockchip isp1 statistics block.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Yichong Zhong <z...@rock-chips.com>
Signed-off-by: Jacob Chen <c...@rock-chips.com>
Signed-off-by: Eddie Cai <eddie.cai.li...@gmail.com>
Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com>
Signed-off-by: Allon Huang <allon.hu...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 drivers/media/platform/rockchip/isp1/isp_stats.c | 522 +++
 drivers/media/platform/rockchip/isp1/isp_stats.h |  85 
 2 files changed, 607 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.h

diff --git a/drivers/media/platform/rockchip/isp1/isp_stats.c 
b/drivers/media/platform/rockchip/isp1/isp_stats.c
new file mode 100644
index ..dd30ebe95721
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/isp_stats.c
@@ -0,0 +1,522 @@
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include/* for ISP statistics */
+#include "dev.h"
+#include "regs.h"
+
+#define RKISP1_ISP_STATS_REQ_BUFS_MIN 2
+#define RKISP1_ISP_STATS_REQ_BUFS_MAX 8
+
+static int rkisp1_stats_enum_fmt_meta_cap(struct file *file, void *priv,
+ struct v4l2_fmtdesc *f)
+{
+   struct video_device *video = video_devdata(file);
+   struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(video);
+
+   if (f->index > 0 || f->type != video->queue->type)
+   return -EINVAL;
+
+   f->pixelformat = stats_vdev->vdev_fmt.fmt.meta.dataformat;
+   return 0;
+}
+
+static int rkisp1_stats_g_fmt_meta_cap(struct file *file, void *priv,
+  struct v4l2_format *f)
+{
+   struct video_device *video = video_devdata(file);
+   struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(video);
+   struct v4l2_meta_format *meta = >fmt.meta;
+
+   if (f->type != video->queue->type)
+   return -EINVAL;
+
+   memset(meta, 0, sizeof(*meta));
+   meta->dataformat = stats_vdev->vdev_fmt.fmt.meta.dataformat;
+   meta->buffersize = stats_vdev->vdev_fmt.fmt.meta.buffersize;
+
+   return 0;
+}
+
+static int rkisp1_stats_querycap(struct file *file,
+void *priv, struct v4l2_capability *cap)
+{
+   struct video_device *vdev = video_devdata(file);
+
+   strcpy(cap->driver, DRIVER_NAME);
+   strlcpy(cap->card, vdev->name, sizeof(cap->card));
+   strlcpy(cap->bus_info, "platform: " DRIVER_NAME, sizeof(cap->bus_info));
+
+   return 0;
+}
+
+/* ISP video device IOCTLs */
+static const struct v4l2_ioctl_ops rkisp1_stats_ioctl = {
+   .vidioc_reqbufs = vb2_ioctl_reqbufs,
+   .vidioc_querybuf = vb2_ioctl_querybuf,
+   .vidioc_create_bufs = vb2_ioctl_create_bufs,
+   .vidioc_qbuf = vb2_ioctl_qbuf,
+   .vidioc_dqbuf = vb2_ioctl_dqbuf,
+   .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+   .vidioc_expbuf = vb2_ioctl_expbuf,
+   .vidioc_streamon = vb2_ioctl_streamon,
+   .vidioc_streamoff = vb2_ioctl_streamoff,
+   .vidioc_enum_fmt_meta_cap = rkisp1_stats_enum_fmt_meta_cap,

[PATCH v4 07/16] media: rkisp1: add ISP1 params driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

Add the output video driver that accept params from userspace.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/isp_params.c | 1537 +
 drivers/media/platform/rockchip/isp1/isp_params.h |   76 +
 2 files changed, 1613 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.h

diff --git a/drivers/media/platform/rockchip/isp1/isp_params.c 
b/drivers/media/platform/rockchip/isp1/isp_params.c
new file mode 100644
index ..287f8523dbd9
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/isp_params.c
@@ -0,0 +1,1537 @@
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include/* for ISP params */
+#include "dev.h"
+#include "regs.h"
+
+#define RKISP1_ISP_PARAMS_REQ_BUFS_MIN 2
+#define RKISP1_ISP_PARAMS_REQ_BUFS_MAX 8
+
+#define BLS_START_H_MAX_IS_VALID(val)  ((val) < CIFISP_BLS_START_H_MAX)
+#define BLS_STOP_H_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_STOP_H_MAX)
+
+#define BLS_START_V_MAX_IS_VALID(val)  ((val) < CIFISP_BLS_START_V_MAX)
+#define BLS_STOP_V_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_STOP_V_MAX)
+
+#define BLS_SAMPLE_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_SAMPLES_MAX)
+
+#define BLS_FIX_SUB_IS_VALID(val)  \
+   ((val) > (s16) CIFISP_BLS_FIX_SUB_MIN && (val) < CIFISP_BLS_FIX_SUB_MAX)
+
+#define RKISP1_ISP_DPCC_LINE_THRESH(n) (CIF_ISP_DPCC_LINE_THRESH_1 + 0x14 * 
(n))
+#define RKISP1_ISP_DPCC_LINE_MAD_FAC(n) (CIF_ISP_DPCC_LINE_MAD_FAC_1 + 0x14 * 
(n))
+#define RKISP1_ISP_DPCC_PG_FAC(n)  (CIF_ISP_DPCC_PG_FAC_1 + 0x14 * (n))
+#define RKISP1_ISP_DPCC_RND_THRESH(n)  (CIF_ISP_DPCC_RND_THRESH_1 + 0x14 * (n))
+#define RKISP1_ISP_DPCC_RG_FAC(n)  (CIF_ISP_DPCC_RG_FAC_1 + 0x14 * (n))
+#define RKISP1_ISP_CC_COEFF(n) (CIF_ISP_CC_COEFF_0 + (n) * 4)
+
+static inline void rkisp1_iowrite32(struct rkisp1_isp_params_vdev *params_vdev,
+   u32 value, u32 addr)
+{
+   iowrite32(value, params_vdev->dev->base_addr + addr);
+}
+
+static inline u32 rkisp1_ioread32(struct rkisp1_isp_params_vdev *params_vdev,
+ u32 addr)
+{
+   return ioread32(params_vdev->dev->base_addr + addr);
+}
+
+static inline void isp_param_set_bits(struct rkisp1_isp_params_vdev
+*params_vdev,
+ u32 reg, u32 bit_mask)
+{
+   u32 val;
+
+   val = rkisp1_ioread32(params_vdev, reg);
+   rkisp1_iowrite32(params_vdev, val | bit_mask, reg);
+}
+
+static inline void isp_param_clear_bits(struct rkisp1_isp_params_vdev
+  *params_vdev,
+   u32 reg, u32 bit_mask)
+{
+   u32 val;
+
+   val = rkisp1_ioread32(params_vdev, reg);
+   rkisp1_iowrite32(params_vdev, val & ~bit_mask, reg);
+}
+
+/* ISP BP interface function */
+static void dpcc_config(struct rkisp1_isp_params_vdev *params_vdev,
+   const struct cifisp_dpcc_config *arg)
+{
+   unsigned int i;
+
+   rkisp1_iowrite32(params_vdev, arg->mode, CIF_ISP_DPCC_MODE);
+   rkisp1_iowrite32(params_vdev, arg->output_mode,
+  

[PATCH v4 08/16] media: rkisp1: add capture device driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

This is the capture device interface driver that provides the v4l2
user interface. Frames can be received from ISP1.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/capture.c | 1704 
 drivers/media/platform/rockchip/isp1/capture.h |  194 +++
 drivers/media/platform/rockchip/isp1/regs.c|  264 
 drivers/media/platform/rockchip/isp1/regs.h| 1577 ++
 4 files changed, 3739 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.c
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.h
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.c
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.h

diff --git a/drivers/media/platform/rockchip/isp1/capture.c 
b/drivers/media/platform/rockchip/isp1/capture.c
new file mode 100644
index ..542c35223665
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/capture.c
@@ -0,0 +1,1704 @@
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "dev.h"
+#include "regs.h"
+
+/*
+ * NOTE:
+ * 1. There are two capture video devices in rkisp1, selfpath and mainpath
+ * 2. Two capture device have separated memory-interface/crop/scale units.
+ * 3. Besides describing stream hardware, this file also contain entries for 
pipeline operations.
+ * 4. The register read/write operations in this file are put into regs.c.
+ */
+
+/*
+ * differences between selfpatch and mainpath
+ * available mp sink input: isp
+ * available sp sink input : isp, dma(TODO)
+ * available mp sink pad fmts: yuv422, raw
+ * available sp sink pad fmts: yuv422, yuv420..
+ * available mp source fmts: yuv, raw, jpeg(TODO)
+ * available sp source fmts: yuv, rgb
+ */
+
+#define CIF_ISP_REQ_BUFS_MIN 1
+#define CIF_ISP_REQ_BUFS_MAX 8
+
+#define STREAM_PAD_SINK0
+#define STREAM_PAD_SOURCE  1
+
+#define STREAM_MAX_MP_RSZ_OUTPUT_WIDTH 4416
+#define STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT3312
+#define STREAM_MAX_SP_RSZ_OUTPUT_WIDTH 1920
+#define STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT1080
+#define STREAM_MIN_RSZ_OUTPUT_WIDTH32
+#define STREAM_MIN_RSZ_OUTPUT_HEIGHT   16
+
+#define STREAM_MAX_MP_SP_INPUT_WIDTH STREAM_MAX_MP_RSZ_OUTPUT_WIDTH
+#define STREAM_MAX_MP_SP_INPUT_HEIGHT STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT
+#define STREAM_MIN_MP_SP_INPUT_WIDTH   32
+#define STREAM_MIN_MP_SP_INPUT_HEIGHT  32
+
+/* Get xsubs and ysubs for fourcc formats
+ *
+ * @xsubs: horizontal color samples in a 4*4 matrix, for yuv
+ * @ysubs: vertical color samples in a 4*4 matrix, for yuv
+ */
+static int fcc_xysubs(u32 fcc, u32 *xsubs, u32 *ysubs)
+{
+   switch (fcc) {
+   case V4L2_PIX_FMT_GREY:
+   case V4L2_PIX_FMT_YUV444M:
+   *xsubs = 1;
+   *ysubs = 1;
+   break;
+   case V4L2_PIX_FMT_YUYV:
+   case V4L2_PIX_FMT_YVYU:
+   case V4L2_PIX_FMT_VYUY:
+   case V4L2_PIX_FMT_YUV422P:
+   case V4L2_PIX_FMT_NV16:
+   case V4L2_PIX_FMT_NV61:
+   case V4L2_PIX_FMT_YVU422M:
+   *xsubs = 2;
+   *ysubs = 1;
+   break;
+   case V4L2_PIX_FMT_NV21:

[PATCH v4 06/16] media: rkisp1: add ISP1 statistics driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

Add the capture video driver for rockchip isp1 statistics block.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/isp_stats.c | 522 +++
 drivers/media/platform/rockchip/isp1/isp_stats.h |  85 
 2 files changed, 607 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.h

diff --git a/drivers/media/platform/rockchip/isp1/isp_stats.c 
b/drivers/media/platform/rockchip/isp1/isp_stats.c
new file mode 100644
index ..dd30ebe95721
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/isp_stats.c
@@ -0,0 +1,522 @@
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include/* for ISP statistics */
+#include "dev.h"
+#include "regs.h"
+
+#define RKISP1_ISP_STATS_REQ_BUFS_MIN 2
+#define RKISP1_ISP_STATS_REQ_BUFS_MAX 8
+
+static int rkisp1_stats_enum_fmt_meta_cap(struct file *file, void *priv,
+ struct v4l2_fmtdesc *f)
+{
+   struct video_device *video = video_devdata(file);
+   struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(video);
+
+   if (f->index > 0 || f->type != video->queue->type)
+   return -EINVAL;
+
+   f->pixelformat = stats_vdev->vdev_fmt.fmt.meta.dataformat;
+   return 0;
+}
+
+static int rkisp1_stats_g_fmt_meta_cap(struct file *file, void *priv,
+  struct v4l2_format *f)
+{
+   struct video_device *video = video_devdata(file);
+   struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(video);
+   struct v4l2_meta_format *meta = >fmt.meta;
+
+   if (f->type != video->queue->type)
+   return -EINVAL;
+
+   memset(meta, 0, sizeof(*meta));
+   meta->dataformat = stats_vdev->vdev_fmt.fmt.meta.dataformat;
+   meta->buffersize = stats_vdev->vdev_fmt.fmt.meta.buffersize;
+
+   return 0;
+}
+
+static int rkisp1_stats_querycap(struct file *file,
+void *priv, struct v4l2_capability *cap)
+{
+   struct video_device *vdev = video_devdata(file);
+
+   strcpy(cap->driver, DRIVER_NAME);
+   strlcpy(cap->card, vdev->name, sizeof(cap->card));
+   strlcpy(cap->bus_info, "platform: " DRIVER_NAME, sizeof(cap->bus_info));
+
+   return 0;
+}
+
+/* ISP video device IOCTLs */
+static const struct v4l2_ioctl_ops rkisp1_stats_ioctl = {
+   .vidioc_reqbufs = vb2_ioctl_reqbufs,
+   .vidioc_querybuf = vb2_ioctl_querybuf,
+   .vidioc_create_bufs = vb2_ioctl_create_bufs,
+   .vidioc_qbuf = vb2_ioctl_qbuf,
+   .vidioc_dqbuf = vb2_ioctl_dqbuf,
+   .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+   .vidioc_expbuf = vb2_ioctl_expbuf,
+   .vidioc_streamon = vb2_ioctl_streamon,
+   .vidioc_streamoff = vb2_ioctl_streamoff,
+   .vidioc_enum_fmt_meta_cap = rkisp1_stats_enum_fmt_meta_cap,
+   .vidioc_g_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
+   .vidioc_s_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
+   .vidioc_try_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
+   .vidioc_querycap = rkisp1_stats_querycap
+};
+
+struct v4l2_file_operations rkisp1_stats_fops

[PATCH v4 04/16] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 787 +
 1 file changed, 787 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c

diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c 
b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
new file mode 100644
index ..942118366f49
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
@@ -0,0 +1,787 @@
+/*
+ * Rockchip MIPI Synopsys DPHY driver
+ *
+ * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RK3288_GRF_SOC_CON60x025c
+#define RK3288_GRF_SOC_CON80x0264
+#define RK3288_GRF_SOC_CON90x0268
+#define RK3288_GRF_SOC_CON10   0x026c
+#define RK3288_GRF_SOC_CON14   0x027c
+#define RK3288_GRF_SOC_STATUS210x02d4
+#define RK3288_GRF_IO_VSEL 0x0380
+#define RK3288_GRF_SOC_CON15   0x03a4
+
+#define RK3399_GRF_SOC_CON90x6224
+#define RK3399_GRF_SOC_CON21   0x6254
+#define RK3399_GRF_SOC_CON22   0x6258
+#define RK3399_GRF_SOC_CON23   0x625c
+#define RK3399_GRF_SOC_CON24   0x6260
+#define RK3399_GRF_SOC_CON25   0x6264
+#define RK3399_GRF_SOC_STATUS1 0xe2a4
+
+#define CLOCK_LANE_HS_RX_CONTROL   0x34
+#define LANE0_HS_RX_CONTROL0x44
+#define LANE1_HS_RX_CONTROL0x54
+#define LANE2_HS_RX_CONTROL0x84
+#define LANE3_HS_RX_CONTROL0x94
+#define HS_RX_DATA_LANES_THS_SETTLE__CONTROL   0x75
+
+#define HIWORD_UPDATE(val, mask, shift) \
+   ((val) << (shift) | (mask) << ((shift) + 16))
+
+enum mipi_dphy_sy_pads {
+   MIPI_DPHY_SY_PAD_SINK = 0,
+   MIPI_DPHY_SY_PAD_SOURCE,
+   MIPI_DPHY_SY_PADS_NUM,
+};
+
+enum dphy_reg_id {
+   GRF_DPHY_RX0_TURNDISABLE = 0,
+   GRF_DPHY_RX0_FORCERXMODE,
+   GRF_DPHY_RX0_FORCETXSTOPMODE,
+   GRF_DPHY_RX0_ENABLE,
+   GRF_DPHY_RX0_TESTCLR,
+   GRF_DPHY_RX0_TESTCLK,
+   GRF_DPHY_RX0_TESTEN,
+   GRF_DPHY_RX0_TESTDIN,
+   GRF_DPHY_RX0_TURNREQUEST,
+   GRF_DPHY_RX0_TESTDOUT,
+   GRF_DPHY_TX0_TURNDISABLE,
+   GRF_DPHY_TX0_FORCERXMODE,
+   GRF_DPHY_TX0_FORCETXSTOPMODE,
+   GRF_DPHY_TX0_TURNREQUEST,
+   GRF_DPHY_TX1RX1_TURNDISABLE,
+   GRF_DPHY_TX1RX1_FORCERXMODE,
+   GRF_DPHY_TX1RX1_FORCETXSTOPMODE,
+   GRF_DPHY_TX1RX1_ENABLE,
+   GRF_DPHY_TX1RX1_MASTERSLAVEZ,
+   GRF_DPHY_TX1RX1_BASEDIR,
+   GRF_DPHY_TX1RX1_ENABLECLK,
+   GRF_DPHY_TX1RX1_TURNREQUEST,
+   GRF_DPHY_RX1_SRC_SEL,
+   /* rk3288 only */
+   GRF_CON_DISABLE_ISP,
+   GRF_CON_ISP_DPHY_SEL,
+   GRF_DSI_CSI_TESTBUS_SEL,
+   GRF_DVP_V18SEL,
+   /* below is for rk3399 only */
+   GRF_DPHY_RX0_CLK_INV_SEL,
+   GRF_DPHY_RX1_CLK_INV_SEL,
+};
+
+struct dphy_reg {
+   u32 offset;
+   u32 mask;
+   u32 shift;
+};
+
+#define PHY_REG(_offset, _width, _shift) \
+   { .offset = _offset, .mask = BIT(_width) - 1, .shift = _shift, }
+
+static const struct dphy_reg rk3399_grf_dphy_regs[] = {
+   [GRF_DPHY_RX0_TURNREQUEST] = PHY_REG(RK3399_GRF_SOC_CON9, 4, 0),
+   [GRF_DPHY_RX0_CLK

[PATCH v4 05/16] media: rkisp1: add Rockchip ISP1 subdev driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add the subdev driver for rockchip isp1.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Yichong Zhong <z...@rock-chips.com>
Signed-off-by: Jacob Chen <c...@rock-chips.com>
Signed-off-by: Eddie Cai <eddie.cai.li...@gmail.com>
Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com>
Signed-off-by: Allon Huang <allon.hu...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 drivers/media/platform/rockchip/isp1/rkisp1.c | 1211 +
 drivers/media/platform/rockchip/isp1/rkisp1.h |  132 +++
 2 files changed, 1343 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.c
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.h

diff --git a/drivers/media/platform/rockchip/isp1/rkisp1.c 
b/drivers/media/platform/rockchip/isp1/rkisp1.c
new file mode 100644
index ..abe62f30
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/rkisp1.c
@@ -0,0 +1,1211 @@
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "common.h"
+#include "regs.h"
+
+#define CIF_ISP_INPUT_W_MAX4032
+#define CIF_ISP_INPUT_H_MAX3024
+#define CIF_ISP_INPUT_W_MIN32
+#define CIF_ISP_INPUT_H_MIN32
+#define CIF_ISP_OUTPUT_W_MAX   CIF_ISP_INPUT_W_MAX
+#define CIF_ISP_OUTPUT_H_MAX   CIF_ISP_INPUT_H_MAX
+#define CIF_ISP_OUTPUT_W_MIN   CIF_ISP_INPUT_W_MIN
+#define CIF_ISP_OUTPUT_H_MIN   CIF_ISP_INPUT_H_MIN
+
+/*
+ * NOTE: MIPI controller and input MUX are also configured in this file,
+ * because ISP Subdev is not only describe ISP submodule(input size,format, 
output size, format),
+ * but also a virtual route device.
+ */
+
+/*
+ * There are many variables named with format/frame in below code,
+ * please see here for their meaning.
+ *
+ * Cropping regions of ISP
+ *
+ * +-+
+ * | Sensor image|
+ * | +---+   |
+ * | | ISP_ACQ (for black level) |   |
+ * | | in_frm|   |
+ * | | ++|   |
+ * | | |ISP_OUT ||   |
+ * | | |in_crop ||   |
+ * | | |+-+ ||   |
+ * | | ||   ISP_IS| ||   |
+ * | | ||   rkisp1_isp_subdev: out_crop   | ||   |
+ * | | |+-+ ||   |
+ * | | ++|   |
+ * | +---+   |
+ * +-+
+ */
+
+static inline struct rkisp1_device *sd_to_isp_dev(struct v4l2_subdev *sd)
+{
+   return container_of(sd->v4l2_dev, struct rkisp1_device, v4l2_dev);
+}
+
+/* Get sensor by enabled media link */
+static struct v4l2_subdev *get_remote_sensor(struct v4l2_subdev *sd)
+{
+   struct media_pad *local;
+   struct media_entity *sensor_me;
+
+   local = >entity.pads[RKISP1_ISP_PAD_SINK];
+   sensor_me = media_entity_remote_pad(local)->entity;
+
+   return media_entity_to_v4l2_subd

[PATCH v4 04/16] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Tomasz Figa 
---
 .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 787 +
 1 file changed, 787 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c

diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c 
b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
new file mode 100644
index ..942118366f49
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
@@ -0,0 +1,787 @@
+/*
+ * Rockchip MIPI Synopsys DPHY driver
+ *
+ * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RK3288_GRF_SOC_CON60x025c
+#define RK3288_GRF_SOC_CON80x0264
+#define RK3288_GRF_SOC_CON90x0268
+#define RK3288_GRF_SOC_CON10   0x026c
+#define RK3288_GRF_SOC_CON14   0x027c
+#define RK3288_GRF_SOC_STATUS210x02d4
+#define RK3288_GRF_IO_VSEL 0x0380
+#define RK3288_GRF_SOC_CON15   0x03a4
+
+#define RK3399_GRF_SOC_CON90x6224
+#define RK3399_GRF_SOC_CON21   0x6254
+#define RK3399_GRF_SOC_CON22   0x6258
+#define RK3399_GRF_SOC_CON23   0x625c
+#define RK3399_GRF_SOC_CON24   0x6260
+#define RK3399_GRF_SOC_CON25   0x6264
+#define RK3399_GRF_SOC_STATUS1 0xe2a4
+
+#define CLOCK_LANE_HS_RX_CONTROL   0x34
+#define LANE0_HS_RX_CONTROL0x44
+#define LANE1_HS_RX_CONTROL0x54
+#define LANE2_HS_RX_CONTROL0x84
+#define LANE3_HS_RX_CONTROL0x94
+#define HS_RX_DATA_LANES_THS_SETTLE__CONTROL   0x75
+
+#define HIWORD_UPDATE(val, mask, shift) \
+   ((val) << (shift) | (mask) << ((shift) + 16))
+
+enum mipi_dphy_sy_pads {
+   MIPI_DPHY_SY_PAD_SINK = 0,
+   MIPI_DPHY_SY_PAD_SOURCE,
+   MIPI_DPHY_SY_PADS_NUM,
+};
+
+enum dphy_reg_id {
+   GRF_DPHY_RX0_TURNDISABLE = 0,
+   GRF_DPHY_RX0_FORCERXMODE,
+   GRF_DPHY_RX0_FORCETXSTOPMODE,
+   GRF_DPHY_RX0_ENABLE,
+   GRF_DPHY_RX0_TESTCLR,
+   GRF_DPHY_RX0_TESTCLK,
+   GRF_DPHY_RX0_TESTEN,
+   GRF_DPHY_RX0_TESTDIN,
+   GRF_DPHY_RX0_TURNREQUEST,
+   GRF_DPHY_RX0_TESTDOUT,
+   GRF_DPHY_TX0_TURNDISABLE,
+   GRF_DPHY_TX0_FORCERXMODE,
+   GRF_DPHY_TX0_FORCETXSTOPMODE,
+   GRF_DPHY_TX0_TURNREQUEST,
+   GRF_DPHY_TX1RX1_TURNDISABLE,
+   GRF_DPHY_TX1RX1_FORCERXMODE,
+   GRF_DPHY_TX1RX1_FORCETXSTOPMODE,
+   GRF_DPHY_TX1RX1_ENABLE,
+   GRF_DPHY_TX1RX1_MASTERSLAVEZ,
+   GRF_DPHY_TX1RX1_BASEDIR,
+   GRF_DPHY_TX1RX1_ENABLECLK,
+   GRF_DPHY_TX1RX1_TURNREQUEST,
+   GRF_DPHY_RX1_SRC_SEL,
+   /* rk3288 only */
+   GRF_CON_DISABLE_ISP,
+   GRF_CON_ISP_DPHY_SEL,
+   GRF_DSI_CSI_TESTBUS_SEL,
+   GRF_DVP_V18SEL,
+   /* below is for rk3399 only */
+   GRF_DPHY_RX0_CLK_INV_SEL,
+   GRF_DPHY_RX1_CLK_INV_SEL,
+};
+
+struct dphy_reg {
+   u32 offset;
+   u32 mask;
+   u32 shift;
+};
+
+#define PHY_REG(_offset, _width, _shift) \
+   { .offset = _offset, .mask = BIT(_width) - 1, .shift = _shift, }
+
+static const struct dphy_reg rk3399_grf_dphy_regs[] = {
+   [GRF_DPHY_RX0_TURNREQUEST] = PHY_REG(RK3399_GRF_SOC_CON9, 4, 0),
+   [GRF_DPHY_RX0_CLK_INV_SEL] = PHY_REG(RK3399_GRF_SOC_CON9, 1, 10),
+   [GRF_DPHY_RX1_CLK_INV_SEL] = PHY_REG(RK3399_GRF_SOC_CON9, 1, 11),
+ 

[PATCH v4 05/16] media: rkisp1: add Rockchip ISP1 subdev driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

Add the subdev driver for rockchip isp1.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/rkisp1.c | 1211 +
 drivers/media/platform/rockchip/isp1/rkisp1.h |  132 +++
 2 files changed, 1343 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.c
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.h

diff --git a/drivers/media/platform/rockchip/isp1/rkisp1.c 
b/drivers/media/platform/rockchip/isp1/rkisp1.c
new file mode 100644
index ..abe62f30
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/rkisp1.c
@@ -0,0 +1,1211 @@
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "common.h"
+#include "regs.h"
+
+#define CIF_ISP_INPUT_W_MAX4032
+#define CIF_ISP_INPUT_H_MAX3024
+#define CIF_ISP_INPUT_W_MIN32
+#define CIF_ISP_INPUT_H_MIN32
+#define CIF_ISP_OUTPUT_W_MAX   CIF_ISP_INPUT_W_MAX
+#define CIF_ISP_OUTPUT_H_MAX   CIF_ISP_INPUT_H_MAX
+#define CIF_ISP_OUTPUT_W_MIN   CIF_ISP_INPUT_W_MIN
+#define CIF_ISP_OUTPUT_H_MIN   CIF_ISP_INPUT_H_MIN
+
+/*
+ * NOTE: MIPI controller and input MUX are also configured in this file,
+ * because ISP Subdev is not only describe ISP submodule(input size,format, 
output size, format),
+ * but also a virtual route device.
+ */
+
+/*
+ * There are many variables named with format/frame in below code,
+ * please see here for their meaning.
+ *
+ * Cropping regions of ISP
+ *
+ * +-+
+ * | Sensor image|
+ * | +---+   |
+ * | | ISP_ACQ (for black level) |   |
+ * | | in_frm|   |
+ * | | ++|   |
+ * | | |ISP_OUT ||   |
+ * | | |in_crop ||   |
+ * | | |+-+ ||   |
+ * | | ||   ISP_IS| ||   |
+ * | | ||   rkisp1_isp_subdev: out_crop   | ||   |
+ * | | |+-+ ||   |
+ * | | ++|   |
+ * | +---+   |
+ * +-+
+ */
+
+static inline struct rkisp1_device *sd_to_isp_dev(struct v4l2_subdev *sd)
+{
+   return container_of(sd->v4l2_dev, struct rkisp1_device, v4l2_dev);
+}
+
+/* Get sensor by enabled media link */
+static struct v4l2_subdev *get_remote_sensor(struct v4l2_subdev *sd)
+{
+   struct media_pad *local;
+   struct media_entity *sensor_me;
+
+   local = >entity.pads[RKISP1_ISP_PAD_SINK];
+   sensor_me = media_entity_remote_pad(local)->entity;
+
+   return media_entity_to_v4l2_subdev(sensor_me);
+}
+
+static struct rkisp1_sensor_info *sd_to_sensor(struct rkisp1_device *dev,
+  struct v4l2_subdev *sd)
+{
+   int i;
+
+   for (i = 0; i < dev->num_sensors; ++i)
+   if (dev->sensors[i].sd 

[PATCH v4 00/16] Rockchip ISP1 Driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

changes in V4:
  - fix some bugs during development
  - move quantization settings to rkisp1 subdev
  - correct some spelling problems
  - describe ports in dt-binding documents

changes in V3:
  - add some comments
  - fix wrong use of v4l2_async_subdev_notifier_register
  - optimize two paths capture at a time
  - remove compose
  - re-struct headers
  - add a tmp wiki page: http://opensource.rock-chips.com/wiki_Rockchip-isp1

changes in V2:
  mipi-phy:
- use async probing
- make it be a child device of the GRF
  isp:
- add dummy buffer
- change the way to get bus configuration, which make it possible to
add parallel sensor support in the future(without mipi-phy driver).

This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399 SoC.

Wiki Pages:
http://opensource.rock-chips.com/wiki_Rockchip-isp1

Jacob Chen (12):
  media: doc: add document for rkisp1 meta buffer format
  media: rkisp1: add Rockchip MIPI Synopsys DPHY driver
  media: rkisp1: add Rockchip ISP1 subdev driver
  media: rkisp1: add ISP1 statistics driver
  media: rkisp1: add ISP1 params driver
  media: rkisp1: add capture device driver
  media: rkisp1: add rockchip isp1 core driver
  dt-bindings: Document the Rockchip ISP1 bindings
  dt-bindings: Document the Rockchip MIPI RX D-PHY bindings
  ARM: dts: rockchip: add isp node for rk3288
  ARM: dts: rockchip: add rx0 mipi-phy for rk3288
  MAINTAINERS: add entry for Rockchip ISP1 driver

Jeffy Chen (1):
  media: rkisp1: Add user space ABI definitions

Shunqian Zheng (3):
  media: videodev2.h, v4l2-ioctl: add rkisp1 meta buffer format
  arm64: dts: rockchip: add isp0 node for rk3399
  arm64: dts: rockchip: add rx0 mipi-phy for rk3399

 .../devicetree/bindings/media/rockchip-isp1.txt|   69 +
 .../bindings/media/rockchip-mipi-dphy.txt  |   88 +
 Documentation/media/uapi/v4l/meta-formats.rst  |2 +
 .../media/uapi/v4l/pixfmt-meta-rkisp1-params.rst   |   17 +
 .../media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst |   18 +
 MAINTAINERS|   10 +
 arch/arm/boot/dts/rk3288.dtsi  |   24 +
 arch/arm64/boot/dts/rockchip/rk3399.dtsi   |   25 +
 drivers/media/platform/Kconfig |   10 +
 drivers/media/platform/Makefile|1 +
 drivers/media/platform/rockchip/isp1/Makefile  |8 +
 drivers/media/platform/rockchip/isp1/capture.c | 1704 
 drivers/media/platform/rockchip/isp1/capture.h |  194 +++
 drivers/media/platform/rockchip/isp1/common.h  |  137 ++
 drivers/media/platform/rockchip/isp1/dev.c |  653 
 drivers/media/platform/rockchip/isp1/dev.h |  120 ++
 drivers/media/platform/rockchip/isp1/isp_params.c  | 1537 ++
 drivers/media/platform/rockchip/isp1/isp_params.h  |   76 +
 drivers/media/platform/rockchip/isp1/isp_stats.c   |  522 ++
 drivers/media/platform/rockchip/isp1/isp_stats.h   |   85 +
 .../media/platform/rockchip/isp1/mipi_dphy_sy.c|  787 +
 drivers/media/platform/rockchip/isp1/regs.c|  264 +++
 drivers/media/platform/rockchip/isp1/regs.h| 1577 ++
 drivers/media/platform/rockchip/isp1/rkisp1.c  | 1211 ++
 drivers/media/platform/rockchip/isp1/rkisp1.h  |  132 ++
 drivers/media/v4l2-core/v4l2-ioctl.c   |2 +
 include/uapi/linux/rkisp1-config.h |  757 +
 include/uapi/linux/videodev2.h |4 +
 28 files changed, 10034 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt
 create mode 100644 
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
 create mode 100644 drivers/media/platform/rockchip/isp1/Makefile
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.c
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.h
 create mode 100644 drivers/media/platform/rockchip/isp1/common.h
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.c
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.h
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.h
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.h
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.c
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.h
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.c
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.h
 create mode 100644 include/uapi/linux/rkisp1-co

[PATCH v4 02/16] media: doc: add document for rkisp1 meta buffer format

2017-12-18 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

This commit add docuemnt for rkisp1 meta buffer format

Signed-off-by: Jacob Chen <jacob-c...@rock-chips.com>
---
 Documentation/media/uapi/v4l/meta-formats.rst  |  2 ++
 .../media/uapi/v4l/pixfmt-meta-rkisp1-params.rst   | 17 +
 .../media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst | 18 ++
 3 files changed, 37 insertions(+)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst

diff --git a/Documentation/media/uapi/v4l/meta-formats.rst 
b/Documentation/media/uapi/v4l/meta-formats.rst
index 01e24e3df571..1b8281423aa2 100644
--- a/Documentation/media/uapi/v4l/meta-formats.rst
+++ b/Documentation/media/uapi/v4l/meta-formats.rst
@@ -14,3 +14,5 @@ These formats are used for the :ref:`metadata` interface only.
 
 pixfmt-meta-vsp1-hgo
 pixfmt-meta-vsp1-hgt
+pixfmt-meta-rkisp1-params
+pixfmt-meta-rkisp1-stat
diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst 
b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
new file mode 100644
index ..ed344d463b52
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
@@ -0,0 +1,17 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _v4l2-meta-fmt-rkisp1-params:
+
+***
+V4L2_META_FMT_RK_ISP1_PARAMS
+***
+
+Rockchip ISP1 Parameters Data
+
+Description
+===
+
+This format describes input parameters for the Rockchip ISP1.
+
+The data use c-struct :c:type:`rkisp1_isp_params_cfg`, which is defined in
+the ``linux/rkisp1-config.h`` header file, See it for details.
diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst 
b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
new file mode 100644
index ..5ecc4031295f
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
@@ -0,0 +1,18 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _v4l2-meta-fmt-rkisp1-stat:
+
+***
+V4L2_META_FMT_RK_ISP1_STAT_3A
+***
+
+Rockchip ISP1 Statistics Data
+
+Description
+===
+
+This format describes image color statistics information generated by the 
Rockchip
+ISP1.
+
+The data use c-struct :c:type:`rkisp1_stat_buffer`, which is defined in
+the ``linux/cifisp_stat.h`` header file, See it for details.
-- 
2.15.1



[PATCH v4 00/16] Rockchip ISP1 Driver

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

changes in V4:
  - fix some bugs during development
  - move quantization settings to rkisp1 subdev
  - correct some spelling problems
  - describe ports in dt-binding documents

changes in V3:
  - add some comments
  - fix wrong use of v4l2_async_subdev_notifier_register
  - optimize two paths capture at a time
  - remove compose
  - re-struct headers
  - add a tmp wiki page: http://opensource.rock-chips.com/wiki_Rockchip-isp1

changes in V2:
  mipi-phy:
- use async probing
- make it be a child device of the GRF
  isp:
- add dummy buffer
- change the way to get bus configuration, which make it possible to
add parallel sensor support in the future(without mipi-phy driver).

This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399 SoC.

Wiki Pages:
http://opensource.rock-chips.com/wiki_Rockchip-isp1

Jacob Chen (12):
  media: doc: add document for rkisp1 meta buffer format
  media: rkisp1: add Rockchip MIPI Synopsys DPHY driver
  media: rkisp1: add Rockchip ISP1 subdev driver
  media: rkisp1: add ISP1 statistics driver
  media: rkisp1: add ISP1 params driver
  media: rkisp1: add capture device driver
  media: rkisp1: add rockchip isp1 core driver
  dt-bindings: Document the Rockchip ISP1 bindings
  dt-bindings: Document the Rockchip MIPI RX D-PHY bindings
  ARM: dts: rockchip: add isp node for rk3288
  ARM: dts: rockchip: add rx0 mipi-phy for rk3288
  MAINTAINERS: add entry for Rockchip ISP1 driver

Jeffy Chen (1):
  media: rkisp1: Add user space ABI definitions

Shunqian Zheng (3):
  media: videodev2.h, v4l2-ioctl: add rkisp1 meta buffer format
  arm64: dts: rockchip: add isp0 node for rk3399
  arm64: dts: rockchip: add rx0 mipi-phy for rk3399

 .../devicetree/bindings/media/rockchip-isp1.txt|   69 +
 .../bindings/media/rockchip-mipi-dphy.txt  |   88 +
 Documentation/media/uapi/v4l/meta-formats.rst  |2 +
 .../media/uapi/v4l/pixfmt-meta-rkisp1-params.rst   |   17 +
 .../media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst |   18 +
 MAINTAINERS|   10 +
 arch/arm/boot/dts/rk3288.dtsi  |   24 +
 arch/arm64/boot/dts/rockchip/rk3399.dtsi   |   25 +
 drivers/media/platform/Kconfig |   10 +
 drivers/media/platform/Makefile|1 +
 drivers/media/platform/rockchip/isp1/Makefile  |8 +
 drivers/media/platform/rockchip/isp1/capture.c | 1704 
 drivers/media/platform/rockchip/isp1/capture.h |  194 +++
 drivers/media/platform/rockchip/isp1/common.h  |  137 ++
 drivers/media/platform/rockchip/isp1/dev.c |  653 
 drivers/media/platform/rockchip/isp1/dev.h |  120 ++
 drivers/media/platform/rockchip/isp1/isp_params.c  | 1537 ++
 drivers/media/platform/rockchip/isp1/isp_params.h  |   76 +
 drivers/media/platform/rockchip/isp1/isp_stats.c   |  522 ++
 drivers/media/platform/rockchip/isp1/isp_stats.h   |   85 +
 .../media/platform/rockchip/isp1/mipi_dphy_sy.c|  787 +
 drivers/media/platform/rockchip/isp1/regs.c|  264 +++
 drivers/media/platform/rockchip/isp1/regs.h| 1577 ++
 drivers/media/platform/rockchip/isp1/rkisp1.c  | 1211 ++
 drivers/media/platform/rockchip/isp1/rkisp1.h  |  132 ++
 drivers/media/v4l2-core/v4l2-ioctl.c   |2 +
 include/uapi/linux/rkisp1-config.h |  757 +
 include/uapi/linux/videodev2.h |4 +
 28 files changed, 10034 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt
 create mode 100644 
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
 create mode 100644 drivers/media/platform/rockchip/isp1/Makefile
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.c
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.h
 create mode 100644 drivers/media/platform/rockchip/isp1/common.h
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.c
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.h
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.h
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.h
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.c
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.h
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.c
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.h
 create mode 100644 include/uapi/linux/rkisp1-config.h

-- 
2.15.1



[PATCH v4 02/16] media: doc: add document for rkisp1 meta buffer format

2017-12-18 Thread Jacob Chen
From: Jacob Chen 

This commit add docuemnt for rkisp1 meta buffer format

Signed-off-by: Jacob Chen 
---
 Documentation/media/uapi/v4l/meta-formats.rst  |  2 ++
 .../media/uapi/v4l/pixfmt-meta-rkisp1-params.rst   | 17 +
 .../media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst | 18 ++
 3 files changed, 37 insertions(+)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst

diff --git a/Documentation/media/uapi/v4l/meta-formats.rst 
b/Documentation/media/uapi/v4l/meta-formats.rst
index 01e24e3df571..1b8281423aa2 100644
--- a/Documentation/media/uapi/v4l/meta-formats.rst
+++ b/Documentation/media/uapi/v4l/meta-formats.rst
@@ -14,3 +14,5 @@ These formats are used for the :ref:`metadata` interface only.
 
 pixfmt-meta-vsp1-hgo
 pixfmt-meta-vsp1-hgt
+pixfmt-meta-rkisp1-params
+pixfmt-meta-rkisp1-stat
diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst 
b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
new file mode 100644
index ..ed344d463b52
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
@@ -0,0 +1,17 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _v4l2-meta-fmt-rkisp1-params:
+
+***
+V4L2_META_FMT_RK_ISP1_PARAMS
+***
+
+Rockchip ISP1 Parameters Data
+
+Description
+===
+
+This format describes input parameters for the Rockchip ISP1.
+
+The data use c-struct :c:type:`rkisp1_isp_params_cfg`, which is defined in
+the ``linux/rkisp1-config.h`` header file, See it for details.
diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst 
b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
new file mode 100644
index ..5ecc4031295f
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
@@ -0,0 +1,18 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _v4l2-meta-fmt-rkisp1-stat:
+
+***
+V4L2_META_FMT_RK_ISP1_STAT_3A
+***
+
+Rockchip ISP1 Statistics Data
+
+Description
+===
+
+This format describes image color statistics information generated by the 
Rockchip
+ISP1.
+
+The data use c-struct :c:type:`rkisp1_stat_buffer`, which is defined in
+the ``linux/cifisp_stat.h`` header file, See it for details.
-- 
2.15.1



[PATCH v4 03/16] media: rkisp1: Add user space ABI definitions

2017-12-18 Thread Jacob Chen
From: Jeffy Chen <jeffy.c...@rock-chips.com>

Add the header for userspace

Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com>
Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 include/uapi/linux/rkisp1-config.h | 757 +
 1 file changed, 757 insertions(+)
 create mode 100644 include/uapi/linux/rkisp1-config.h

diff --git a/include/uapi/linux/rkisp1-config.h 
b/include/uapi/linux/rkisp1-config.h
new file mode 100644
index ..0f9f42265a7a
--- /dev/null
+++ b/include/uapi/linux/rkisp1-config.h
@@ -0,0 +1,757 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#ifndef _UAPI_RKISP1_CONFIG_H
+#define _UAPI_RKISP1_CONFIG_H
+
+#include 
+#include 
+
+#define CIFISP_MODULE_DPCC  (1 << 0)
+#define CIFISP_MODULE_BLS   (1 << 1)
+#define CIFISP_MODULE_SDG   (1 << 2)
+#define CIFISP_MODULE_HST   (1 << 3)
+#define CIFISP_MODULE_LSC   (1 << 4)
+#define CIFISP_MODULE_AWB_GAIN  (1 << 5)
+#define CIFISP_MODULE_FLT   (1 << 6)
+#define CIFISP_MODULE_BDM   (1 << 7)
+#define CIFISP_MODULE_CTK   (1 << 8)
+#define CIFISP_MODULE_GOC   (1 << 9)
+#define CIFISP_MODULE_CPROC (1 << 10)
+#define CIFISP_MODULE_AFC   (1 << 11)
+#define CIFISP_MODULE_AWB   (1 << 12)
+#define CIFISP_MODULE_IE(1 << 13)
+#define CIFISP_MODULE_AEC   (1 << 14)
+#define CIFISP_MODULE_WDR   (1 << 15)
+#define CIFISP_MODULE_DPF   (1 << 16)
+#define CIFISP_MODULE_DPF_STRENGTH  (1 << 17)
+
+#define CIFISP_CTK_COEFF_MAX0x100
+#define CIFISP_CTK_OFFSET_MAX   0x800
+
+#define CIFISP_AE_MEAN_MAX  25
+#define CIFISP_HIST_BIN_N_MAX   16
+#define CIFISP_AFM_MAX_WINDOWS  3
+#define CIFISP_DEGAMMA_CURVE_SIZE   17
+
+#define CIFISP_BDM_MAX_TH   0xFF
+
+/*
+ * Black level compensation
+ */
+/* maximum value for horizontal start address */
+#define CIFISP_BLS_START_H_MAX 0x0FFF
+/* maximum value for horizontal stop address */
+#define CIFISP_BLS_STOP_H_MAX  0x0FFF
+/* maximum value for vertical start address */
+#define CIFISP_BLS_START_V_MAX 0x0FFF
+/* maximum value for vertical stop address */
+#define CIFISP_BLS_STOP_V_MAX  0x0FFF
+/* maximum is 2^18 = 262144*/
+#define CIFISP_BLS_SAMPLES_MAX 0x0012
+/* maximum value for fixed black level */
+#define CIFISP_BLS_FIX_SUB_MAX 0x0FFF
+/* minimum value for fixed black level */
+#define CIFISP_BLS_FIX_SUB_MIN 0xF000
+/* 13 bit range (signed)*/
+#define CIFISP_BLS_FIX_MASK0x1FFF
+
+/*
+ * Automatic white balance measurments
+ */
+#define CIFISP_AWB_MAX_GRID1
+#define CIFISP_AWB_MAX_FRAMES  7
+
+/*
+ * Gamma out
+ */
+/* Maximum number of color samples supported */
+#define CIFISP_GAMMA_OUT_MAX_SAMPLES   17
+
+/*
+ * Lens shade correction
+ */
+#define CIFISP_LSC_GRAD_TBL_SIZE   8
+#define CIFISP_LSC_SIZE_TBL_SIZE   8
+/*
+ * The following matches the tuning process,
+ * not the max capabilities of the chip.
+ * Last value unused.
+ */
+#defineCIFISP_LSC_DATA_TBL_SIZE   290
+
+/*
+ * Histogram calculation
+ */
+/* Last 3 values unused. */
+#define CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28
+
+/*
+ * Defect Pixel Cluster Correction
+ */
+#define CIFISP_DPCC_METHODS_MAX   3
+
+/*
+ * Denoising pre filter
+ */
+#define CIFISP_DPF_MAX_NLF_COEFFS  17
+#define CIFISP_DPF_MAX_SPATIAL_COEFFS  6
+
+/*
+ * Measurement types
+ */
+#define CIFISP_STAT_AWB   (1 << 0)
+#define CIFISP_STAT_AUTOEXP   (1 << 1)
+#define CIFISP_STAT_AFM_FIN   (1 << 2)
+#define CIFISP_STAT_HIST  (1 << 3)
+
+enum cifisp_histogram_mode {
+   CIFISP_HISTOGRAM_MODE_DISABLE,
+   CIFISP_HISTOGRAM_MODE_RGB_COMBINED,
+   CIFISP_HISTOGRAM_MODE_R_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_G_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_B_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_Y_HISTOGRAM
+};
+
+enum cifisp_awb_mode_type {
+   CIFISP_AWB_MODE_MANUAL,
+   CIFISP_AWB_MODE_RGB,
+   CIFISP_AWB_MODE_YCBCR
+};
+
+enum cifisp_flt_mode {
+   CIFISP_FLT_STATIC_MODE,
+   CIFISP_FLT_DYNAMIC_MODE
+};
+
+/**
+ * enum cifisp_exp_ctrl_auotostop - stop modes
+ * @CIFISP_EXP_CTRL_AUTOSTOP_0: continous measurement
+ * @CIFISP_EXP_CTRL_AUTOSTOP_1: stop measuring after a complete frame
+ */
+enum cifisp_exp_ctrl_auotostop {
+   CIFISP_EXP_CTRL_AUTOSTOP_0 = 0,
+   CIFISP_EXP_CTRL_AUTOSTOP_1 = 1,
+};
+
+/**
+ * enum cifisp_exp_meas_mode - Exposure measure mode
+ * @CIF

[PATCH v4 03/16] media: rkisp1: Add user space ABI definitions

2017-12-18 Thread Jacob Chen
From: Jeffy Chen 

Add the header for userspace

Signed-off-by: Jeffy Chen 
Signed-off-by: Jacob Chen 
---
 include/uapi/linux/rkisp1-config.h | 757 +
 1 file changed, 757 insertions(+)
 create mode 100644 include/uapi/linux/rkisp1-config.h

diff --git a/include/uapi/linux/rkisp1-config.h 
b/include/uapi/linux/rkisp1-config.h
new file mode 100644
index ..0f9f42265a7a
--- /dev/null
+++ b/include/uapi/linux/rkisp1-config.h
@@ -0,0 +1,757 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#ifndef _UAPI_RKISP1_CONFIG_H
+#define _UAPI_RKISP1_CONFIG_H
+
+#include 
+#include 
+
+#define CIFISP_MODULE_DPCC  (1 << 0)
+#define CIFISP_MODULE_BLS   (1 << 1)
+#define CIFISP_MODULE_SDG   (1 << 2)
+#define CIFISP_MODULE_HST   (1 << 3)
+#define CIFISP_MODULE_LSC   (1 << 4)
+#define CIFISP_MODULE_AWB_GAIN  (1 << 5)
+#define CIFISP_MODULE_FLT   (1 << 6)
+#define CIFISP_MODULE_BDM   (1 << 7)
+#define CIFISP_MODULE_CTK   (1 << 8)
+#define CIFISP_MODULE_GOC   (1 << 9)
+#define CIFISP_MODULE_CPROC (1 << 10)
+#define CIFISP_MODULE_AFC   (1 << 11)
+#define CIFISP_MODULE_AWB   (1 << 12)
+#define CIFISP_MODULE_IE(1 << 13)
+#define CIFISP_MODULE_AEC   (1 << 14)
+#define CIFISP_MODULE_WDR   (1 << 15)
+#define CIFISP_MODULE_DPF   (1 << 16)
+#define CIFISP_MODULE_DPF_STRENGTH  (1 << 17)
+
+#define CIFISP_CTK_COEFF_MAX0x100
+#define CIFISP_CTK_OFFSET_MAX   0x800
+
+#define CIFISP_AE_MEAN_MAX  25
+#define CIFISP_HIST_BIN_N_MAX   16
+#define CIFISP_AFM_MAX_WINDOWS  3
+#define CIFISP_DEGAMMA_CURVE_SIZE   17
+
+#define CIFISP_BDM_MAX_TH   0xFF
+
+/*
+ * Black level compensation
+ */
+/* maximum value for horizontal start address */
+#define CIFISP_BLS_START_H_MAX 0x0FFF
+/* maximum value for horizontal stop address */
+#define CIFISP_BLS_STOP_H_MAX  0x0FFF
+/* maximum value for vertical start address */
+#define CIFISP_BLS_START_V_MAX 0x0FFF
+/* maximum value for vertical stop address */
+#define CIFISP_BLS_STOP_V_MAX  0x0FFF
+/* maximum is 2^18 = 262144*/
+#define CIFISP_BLS_SAMPLES_MAX 0x0012
+/* maximum value for fixed black level */
+#define CIFISP_BLS_FIX_SUB_MAX 0x0FFF
+/* minimum value for fixed black level */
+#define CIFISP_BLS_FIX_SUB_MIN 0xF000
+/* 13 bit range (signed)*/
+#define CIFISP_BLS_FIX_MASK0x1FFF
+
+/*
+ * Automatic white balance measurments
+ */
+#define CIFISP_AWB_MAX_GRID1
+#define CIFISP_AWB_MAX_FRAMES  7
+
+/*
+ * Gamma out
+ */
+/* Maximum number of color samples supported */
+#define CIFISP_GAMMA_OUT_MAX_SAMPLES   17
+
+/*
+ * Lens shade correction
+ */
+#define CIFISP_LSC_GRAD_TBL_SIZE   8
+#define CIFISP_LSC_SIZE_TBL_SIZE   8
+/*
+ * The following matches the tuning process,
+ * not the max capabilities of the chip.
+ * Last value unused.
+ */
+#defineCIFISP_LSC_DATA_TBL_SIZE   290
+
+/*
+ * Histogram calculation
+ */
+/* Last 3 values unused. */
+#define CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28
+
+/*
+ * Defect Pixel Cluster Correction
+ */
+#define CIFISP_DPCC_METHODS_MAX   3
+
+/*
+ * Denoising pre filter
+ */
+#define CIFISP_DPF_MAX_NLF_COEFFS  17
+#define CIFISP_DPF_MAX_SPATIAL_COEFFS  6
+
+/*
+ * Measurement types
+ */
+#define CIFISP_STAT_AWB   (1 << 0)
+#define CIFISP_STAT_AUTOEXP   (1 << 1)
+#define CIFISP_STAT_AFM_FIN   (1 << 2)
+#define CIFISP_STAT_HIST  (1 << 3)
+
+enum cifisp_histogram_mode {
+   CIFISP_HISTOGRAM_MODE_DISABLE,
+   CIFISP_HISTOGRAM_MODE_RGB_COMBINED,
+   CIFISP_HISTOGRAM_MODE_R_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_G_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_B_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_Y_HISTOGRAM
+};
+
+enum cifisp_awb_mode_type {
+   CIFISP_AWB_MODE_MANUAL,
+   CIFISP_AWB_MODE_RGB,
+   CIFISP_AWB_MODE_YCBCR
+};
+
+enum cifisp_flt_mode {
+   CIFISP_FLT_STATIC_MODE,
+   CIFISP_FLT_DYNAMIC_MODE
+};
+
+/**
+ * enum cifisp_exp_ctrl_auotostop - stop modes
+ * @CIFISP_EXP_CTRL_AUTOSTOP_0: continous measurement
+ * @CIFISP_EXP_CTRL_AUTOSTOP_1: stop measuring after a complete frame
+ */
+enum cifisp_exp_ctrl_auotostop {
+   CIFISP_EXP_CTRL_AUTOSTOP_0 = 0,
+   CIFISP_EXP_CTRL_AUTOSTOP_1 = 1,
+};
+
+/**
+ * enum cifisp_exp_meas_mode - Exposure measure mode
+ * @CIFISP_EXP_MEASURING_MODE_0: Y = 16 + 0.25R + 0.5G + 0.1094B
+ * @CIFISP_EXP_MEASURING_MODE_1: Y = (R + G + B) x (85/256)
+

[PATCH v4 01/16] media: videodev2.h, v4l2-ioctl: add rkisp1 meta buffer format

2017-12-18 Thread Jacob Chen
From: Shunqian Zheng <zhen...@rock-chips.com>

Add the Rockchip ISP1 specific processing parameter format
V4L2_META_FMT_RK_ISP1_PARAMS and metadata format
V4L2_META_FMT_RK_ISP1_STAT_3A for 3A.

Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++
 include/uapi/linux/videodev2.h   | 4 
 2 files changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index d6587b3ec33e..0604ae9ea444 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1252,6 +1252,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_TCH_FMT_TU08: descr = "8-bit unsigned touch data"; 
break;
case V4L2_META_FMT_VSP1_HGO:descr = "R-Car VSP1 1-D Histogram"; 
break;
case V4L2_META_FMT_VSP1_HGT:descr = "R-Car VSP1 2-D Histogram"; 
break;
+   case V4L2_META_FMT_RK_ISP1_PARAMS:  descr = "Rockchip ISP1 3A 
params"; break;
+   case V4L2_META_FMT_RK_ISP1_STAT_3A: descr = "Rockchip ISP1 3A 
statistics"; break;
 
default:
/* Compressed formats */
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 7c871291c1fa..961545e64c12 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -691,6 +691,10 @@ struct v4l2_pix_format {
 #define V4L2_META_FMT_VSP1_HGOv4l2_fourcc('V', 'S', 'P', 'H') /* R-Car 
VSP1 1-D Histogram */
 #define V4L2_META_FMT_VSP1_HGTv4l2_fourcc('V', 'S', 'P', 'T') /* R-Car 
VSP1 2-D Histogram */
 
+/* Vendor specific - used for IPU3 camera sub-system */
+#define V4L2_META_FMT_RK_ISP1_PARAMS   v4l2_fourcc('R', 'K', '1', 'P') /* 
Rockchip ISP1 params */
+#define V4L2_META_FMT_RK_ISP1_STAT_3A  v4l2_fourcc('R', 'K', '1', 'S') /* 
Rockchip ISP1 3A statistics */
+
 /* priv field value to indicates that subsequent fields are valid. */
 #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe
 
-- 
2.15.1



[PATCH v4 01/16] media: videodev2.h, v4l2-ioctl: add rkisp1 meta buffer format

2017-12-18 Thread Jacob Chen
From: Shunqian Zheng 

Add the Rockchip ISP1 specific processing parameter format
V4L2_META_FMT_RK_ISP1_PARAMS and metadata format
V4L2_META_FMT_RK_ISP1_STAT_3A for 3A.

Signed-off-by: Shunqian Zheng 
Signed-off-by: Jacob Chen 
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++
 include/uapi/linux/videodev2.h   | 4 
 2 files changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index d6587b3ec33e..0604ae9ea444 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1252,6 +1252,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_TCH_FMT_TU08: descr = "8-bit unsigned touch data"; 
break;
case V4L2_META_FMT_VSP1_HGO:descr = "R-Car VSP1 1-D Histogram"; 
break;
case V4L2_META_FMT_VSP1_HGT:descr = "R-Car VSP1 2-D Histogram"; 
break;
+   case V4L2_META_FMT_RK_ISP1_PARAMS:  descr = "Rockchip ISP1 3A 
params"; break;
+   case V4L2_META_FMT_RK_ISP1_STAT_3A: descr = "Rockchip ISP1 3A 
statistics"; break;
 
default:
/* Compressed formats */
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 7c871291c1fa..961545e64c12 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -691,6 +691,10 @@ struct v4l2_pix_format {
 #define V4L2_META_FMT_VSP1_HGOv4l2_fourcc('V', 'S', 'P', 'H') /* R-Car 
VSP1 1-D Histogram */
 #define V4L2_META_FMT_VSP1_HGTv4l2_fourcc('V', 'S', 'P', 'T') /* R-Car 
VSP1 2-D Histogram */
 
+/* Vendor specific - used for IPU3 camera sub-system */
+#define V4L2_META_FMT_RK_ISP1_PARAMS   v4l2_fourcc('R', 'K', '1', 'P') /* 
Rockchip ISP1 params */
+#define V4L2_META_FMT_RK_ISP1_STAT_3A  v4l2_fourcc('R', 'K', '1', 'S') /* 
Rockchip ISP1 3A statistics */
+
 /* priv field value to indicates that subsequent fields are valid. */
 #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe
 
-- 
2.15.1



Re: [PATCH v3 07/12] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings

2017-12-18 Thread Jacob Chen
Hi all,

2017-12-12 0:45 GMT+08:00 Laurent Pinchart <laurent.pinch...@ideasonboard.com>:
> Hello Jacob,
>
> Thank you for the patch.
>
> On Wednesday, 6 December 2017 13:19:34 EET Jacob Chen wrote:
>> From: Jacob Chen <jacob2.c...@rock-chips.com>
>>
>> Add DT bindings documentation for Rockchip MIPI D-PHY RX
>>
>> Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
>> ---
>>  .../bindings/media/rockchip-mipi-dphy.txt  | 71 +++
>>  1 file changed, 71 insertions(+)
>>  create mode 100644
>> Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
>>
>> diff --git a/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
>> b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file
>> mode 100644
>> index ..cef9450db051
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
>> @@ -0,0 +1,71 @@
>> +Rockchip SoC MIPI RX D-PHY
>> +-
>> +
>> +Required properties:
>> +
>> +- compatible: value should be one of the following
>> +"rockchip,rk3288-mipi-dphy";
>> +"rockchip,rk3399-mipi-dphy";
>> +- rockchip,grf: GRF regs.
>> +- bus-width : maximum number of data lanes supported (SoC specific);
>
> Bus width isn't a standard property, should this be rockchip,data-lanes or
> rockchip,#data-lanes ?

I forgot to remove it, it's no unnecessary now.

>
>> +- clocks : list of clock specifiers, corresponding to entries in
>> + clock-names property;
>> +- clock-names: required clock name.
>> +
>> +The device node should contain two 'port' child node, according to the
>
> s/child node/child nodes/
>
>> bindings
>> +defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
>> +The first port should be connected to sensor nodes, and the second port
>> should be
>> +connected to isp node. The following are properties specific to those
>> nodes.
>> +
>> +endpoint node
>> +-
>> +
>> +- data-lanes : (required) an array specifying active physical MIPI-CSI2
>> + data input lanes and their mapping to logical lanes; the
>> + array's content is unused, only its length is meaningful;
>
> I assume this means that the D-PHY can't reroute lanes. I would mention that
> explicitly, and require that the data-lanes values start at one at are
> consecutive instead of ignoring them.
>
>> +Device node example
>> +---
>> +
>> +mipi_dphy_rx0: mipi-dphy-rx0 {
>> +compatible = "rockchip,rk3399-mipi-dphy";
>> +clocks = < SCLK_MIPIDPHY_REF>,
>> +< SCLK_DPHY_RX0_CFG>,
>> +< PCLK_VIO_GRF>;
>> +clock-names = "dphy-ref", "dphy-cfg", "grf";
>> +power-domains = < RK3399_PD_VIO>;
>> +bus-width = <4>;
>> +
>> +ports {
>> +#address-cells = <1>;
>> +#size-cells = <0>;
>> +
>> +port@0 {
>> +reg = <0>;
>> +#address-cells = <1>;
>> +#size-cells = <0>;
>> +
>> +mipi_in_wcam: endpoint@0 {
>> +reg = <0>;
>> +remote-endpoint = <_out>;
>> +data-lanes = <1 2>;
>> +};
>> +mipi_in_ucam: endpoint@1 {
>> +reg = <1>;
>> +remote-endpoint = <_out>;
>> +data-lanes = <1>;
>> +};
>
> What do those two camera correspond to ? Can they be active at the same time,
> or do they use the same data lanes ? If they use the same data lanes, how does
> this work, is there a multiplexer on the board ?
>

They can not be active at the same time, and there is no multiplexer.
If they use the same mipi phy, then only one sensor is allowed to be actived.

See "MIPI Details" chapter
http://opensource.rock-chips.com/wiki_Rockchip-isp1

Let me enumerates soime hardware connections that is common in
rockchip tablet desgin.

rk3288:
-
  ISP0 --> mipi TX1/RX1 --> front sensor
   --> mipi RX0 --> rear sensor

-
  ISP0 --> parallel --> front sensor
   --> mipi RX0 --> rear sensor

rk3399
-
  mipi TX1/RX1 , mipi TX0 --> dual-mipi screen
  ISP0 --> mipi RX0 --> front sensor
--> rear sensor
-
  ISP1 --> mipi TX1/RX1 --> front sensor
  ISP0 --> mipi RX0 --> rear sensor


Only the last connection allow two sensor work at same time.


>> +};
>> +
>> +port@1 {
>> +reg = <1>;
>> +#address-cells = <1>;
>> +#size-cells = <0>;
>> +
>> +dphy_rx0_out: endpoint@0 {
>> +reg = <0>;
>> +remote-endpoint = <_mipi_in>;
>> +};
>> +};
>> +};
>> +};
>> \ No newline at end of file
>
> --
> Regards,
>
> Laurent Pinchart
>




Re: [PATCH v3 07/12] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings

2017-12-18 Thread Jacob Chen
Hi all,

2017-12-12 0:45 GMT+08:00 Laurent Pinchart :
> Hello Jacob,
>
> Thank you for the patch.
>
> On Wednesday, 6 December 2017 13:19:34 EET Jacob Chen wrote:
>> From: Jacob Chen 
>>
>> Add DT bindings documentation for Rockchip MIPI D-PHY RX
>>
>> Signed-off-by: Jacob Chen 
>> ---
>>  .../bindings/media/rockchip-mipi-dphy.txt  | 71 +++
>>  1 file changed, 71 insertions(+)
>>  create mode 100644
>> Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
>>
>> diff --git a/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
>> b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file
>> mode 100644
>> index ..cef9450db051
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
>> @@ -0,0 +1,71 @@
>> +Rockchip SoC MIPI RX D-PHY
>> +-
>> +
>> +Required properties:
>> +
>> +- compatible: value should be one of the following
>> +"rockchip,rk3288-mipi-dphy";
>> +"rockchip,rk3399-mipi-dphy";
>> +- rockchip,grf: GRF regs.
>> +- bus-width : maximum number of data lanes supported (SoC specific);
>
> Bus width isn't a standard property, should this be rockchip,data-lanes or
> rockchip,#data-lanes ?

I forgot to remove it, it's no unnecessary now.

>
>> +- clocks : list of clock specifiers, corresponding to entries in
>> + clock-names property;
>> +- clock-names: required clock name.
>> +
>> +The device node should contain two 'port' child node, according to the
>
> s/child node/child nodes/
>
>> bindings
>> +defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
>> +The first port should be connected to sensor nodes, and the second port
>> should be
>> +connected to isp node. The following are properties specific to those
>> nodes.
>> +
>> +endpoint node
>> +-
>> +
>> +- data-lanes : (required) an array specifying active physical MIPI-CSI2
>> + data input lanes and their mapping to logical lanes; the
>> + array's content is unused, only its length is meaningful;
>
> I assume this means that the D-PHY can't reroute lanes. I would mention that
> explicitly, and require that the data-lanes values start at one at are
> consecutive instead of ignoring them.
>
>> +Device node example
>> +---
>> +
>> +mipi_dphy_rx0: mipi-dphy-rx0 {
>> +compatible = "rockchip,rk3399-mipi-dphy";
>> +clocks = < SCLK_MIPIDPHY_REF>,
>> +< SCLK_DPHY_RX0_CFG>,
>> +< PCLK_VIO_GRF>;
>> +clock-names = "dphy-ref", "dphy-cfg", "grf";
>> +power-domains = < RK3399_PD_VIO>;
>> +bus-width = <4>;
>> +
>> +ports {
>> +#address-cells = <1>;
>> +#size-cells = <0>;
>> +
>> +port@0 {
>> +reg = <0>;
>> +#address-cells = <1>;
>> +#size-cells = <0>;
>> +
>> +mipi_in_wcam: endpoint@0 {
>> +reg = <0>;
>> +remote-endpoint = <_out>;
>> +data-lanes = <1 2>;
>> +};
>> +mipi_in_ucam: endpoint@1 {
>> +reg = <1>;
>> +remote-endpoint = <_out>;
>> +data-lanes = <1>;
>> +};
>
> What do those two camera correspond to ? Can they be active at the same time,
> or do they use the same data lanes ? If they use the same data lanes, how does
> this work, is there a multiplexer on the board ?
>

They can not be active at the same time, and there is no multiplexer.
If they use the same mipi phy, then only one sensor is allowed to be actived.

See "MIPI Details" chapter
http://opensource.rock-chips.com/wiki_Rockchip-isp1

Let me enumerates soime hardware connections that is common in
rockchip tablet desgin.

rk3288:
-
  ISP0 --> mipi TX1/RX1 --> front sensor
   --> mipi RX0 --> rear sensor

-
  ISP0 --> parallel --> front sensor
   --> mipi RX0 --> rear sensor

rk3399
-
  mipi TX1/RX1 , mipi TX0 --> dual-mipi screen
  ISP0 --> mipi RX0 --> front sensor
--> rear sensor
-
  ISP1 --> mipi TX1/RX1 --> front sensor
  ISP0 --> mipi RX0 --> rear sensor


Only the last connection allow two sensor work at same time.


>> +};
>> +
>> +port@1 {
>> +reg = <1>;
>> +#address-cells = <1>;
>> +#size-cells = <0>;
>> +
>> +dphy_rx0_out: endpoint@0 {
>> +reg = <0>;
>> +remote-endpoint = <_mipi_in>;
>> +};
>> +};
>> +};
>> +};
>> \ No newline at end of file
>
> --
> Regards,
>
> Laurent Pinchart
>




[PATCH v3 01/12] media: videodev2.h, v4l2-ioctl: add rkisp1 meta buffer format

2017-12-06 Thread Jacob Chen
From: Shunqian Zheng <zhen...@rock-chips.com>

Add the Rockchip ISP1 specific processing parameter format
V4L2_META_FMT_RK_ISP1_PARAMS and metadata format
V4L2_META_FMT_RK_ISP1_STAT_3A for 3A.

Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++
 include/uapi/linux/videodev2.h   | 4 
 2 files changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index d6587b3ec33e..0604ae9ea444 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1252,6 +1252,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_TCH_FMT_TU08: descr = "8-bit unsigned touch data"; 
break;
case V4L2_META_FMT_VSP1_HGO:descr = "R-Car VSP1 1-D Histogram"; 
break;
case V4L2_META_FMT_VSP1_HGT:descr = "R-Car VSP1 2-D Histogram"; 
break;
+   case V4L2_META_FMT_RK_ISP1_PARAMS:  descr = "Rockchip ISP1 3A 
params"; break;
+   case V4L2_META_FMT_RK_ISP1_STAT_3A: descr = "Rockchip ISP1 3A 
statistics"; break;
 
default:
/* Compressed formats */
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 7c871291c1fa..961545e64c12 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -691,6 +691,10 @@ struct v4l2_pix_format {
 #define V4L2_META_FMT_VSP1_HGOv4l2_fourcc('V', 'S', 'P', 'H') /* R-Car 
VSP1 1-D Histogram */
 #define V4L2_META_FMT_VSP1_HGTv4l2_fourcc('V', 'S', 'P', 'T') /* R-Car 
VSP1 2-D Histogram */
 
+/* Vendor specific - used for IPU3 camera sub-system */
+#define V4L2_META_FMT_RK_ISP1_PARAMS   v4l2_fourcc('R', 'K', '1', 'P') /* 
Rockchip ISP1 params */
+#define V4L2_META_FMT_RK_ISP1_STAT_3A  v4l2_fourcc('R', 'K', '1', 'S') /* 
Rockchip ISP1 3A statistics */
+
 /* priv field value to indicates that subsequent fields are valid. */
 #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe
 
-- 
2.15.0



[PATCH v3 01/12] media: videodev2.h, v4l2-ioctl: add rkisp1 meta buffer format

2017-12-06 Thread Jacob Chen
From: Shunqian Zheng 

Add the Rockchip ISP1 specific processing parameter format
V4L2_META_FMT_RK_ISP1_PARAMS and metadata format
V4L2_META_FMT_RK_ISP1_STAT_3A for 3A.

Signed-off-by: Shunqian Zheng 
Signed-off-by: Jacob Chen 
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++
 include/uapi/linux/videodev2.h   | 4 
 2 files changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index d6587b3ec33e..0604ae9ea444 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1252,6 +1252,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_TCH_FMT_TU08: descr = "8-bit unsigned touch data"; 
break;
case V4L2_META_FMT_VSP1_HGO:descr = "R-Car VSP1 1-D Histogram"; 
break;
case V4L2_META_FMT_VSP1_HGT:descr = "R-Car VSP1 2-D Histogram"; 
break;
+   case V4L2_META_FMT_RK_ISP1_PARAMS:  descr = "Rockchip ISP1 3A 
params"; break;
+   case V4L2_META_FMT_RK_ISP1_STAT_3A: descr = "Rockchip ISP1 3A 
statistics"; break;
 
default:
/* Compressed formats */
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 7c871291c1fa..961545e64c12 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -691,6 +691,10 @@ struct v4l2_pix_format {
 #define V4L2_META_FMT_VSP1_HGOv4l2_fourcc('V', 'S', 'P', 'H') /* R-Car 
VSP1 1-D Histogram */
 #define V4L2_META_FMT_VSP1_HGTv4l2_fourcc('V', 'S', 'P', 'T') /* R-Car 
VSP1 2-D Histogram */
 
+/* Vendor specific - used for IPU3 camera sub-system */
+#define V4L2_META_FMT_RK_ISP1_PARAMS   v4l2_fourcc('R', 'K', '1', 'P') /* 
Rockchip ISP1 params */
+#define V4L2_META_FMT_RK_ISP1_STAT_3A  v4l2_fourcc('R', 'K', '1', 'S') /* 
Rockchip ISP1 3A statistics */
+
 /* priv field value to indicates that subsequent fields are valid. */
 #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe
 
-- 
2.15.0



[PATCH v3 06/12] dt-bindings: Document the Rockchip ISP1 bindings

2017-12-06 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add DT bindings documentation for Rockchip ISP1

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 .../devicetree/bindings/media/rockchip-isp1.txt| 57 ++
 1 file changed, 57 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-isp1.txt 
b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
new file mode 100644
index ..0971ed94ed69
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
@@ -0,0 +1,57 @@
+Rockchip SoC Image Signal Processing unit v1
+--
+
+Rockchip ISP1 is the Camera interface for the Rockchip series of SoCs
+which contains image processing, scaling, and compression funcitons.
+
+Required properties:
+  - compatible: value should be one of the following
+  "rockchip,rk3288-cif-isp";
+  "rockchip,rk3399-cif-isp";
+  - reg : offset and length of the register set for the device.
+  - interrupts: should contain ISP interrupt.
+  - clocks: phandle to the required clocks.
+  - clock-names: required clock name.
+  - iommus: required a iommu node.
+
+The device node should contain one 'port' child node with child 'endpoint'
+nodes, according to the bindings defined in Documentation/devicetree/bindings/
+media/video-interfaces.txt.
+
+For sensor with a parallel video bus, it could be linked directly to the isp.
+For sensor with a MIPI CSI-2 video bus, it should be linked through the
+MIPI-DPHY, which is defined in rockchip-mipi-dphy.txt.
+
+Device node example
+---
+
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+   
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   /* mipi */
+   isp0_mipi_in: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_rx0_out>;
+   };
+
+   /* parallel */
+   isp0_parallel_in: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_out>;
+   };
+   };
+   };
-- 
2.15.0



[PATCH v3 06/12] dt-bindings: Document the Rockchip ISP1 bindings

2017-12-06 Thread Jacob Chen
From: Jacob Chen 

Add DT bindings documentation for Rockchip ISP1

Signed-off-by: Jacob Chen 
---
 .../devicetree/bindings/media/rockchip-isp1.txt| 57 ++
 1 file changed, 57 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-isp1.txt 
b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
new file mode 100644
index ..0971ed94ed69
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
@@ -0,0 +1,57 @@
+Rockchip SoC Image Signal Processing unit v1
+--
+
+Rockchip ISP1 is the Camera interface for the Rockchip series of SoCs
+which contains image processing, scaling, and compression funcitons.
+
+Required properties:
+  - compatible: value should be one of the following
+  "rockchip,rk3288-cif-isp";
+  "rockchip,rk3399-cif-isp";
+  - reg : offset and length of the register set for the device.
+  - interrupts: should contain ISP interrupt.
+  - clocks: phandle to the required clocks.
+  - clock-names: required clock name.
+  - iommus: required a iommu node.
+
+The device node should contain one 'port' child node with child 'endpoint'
+nodes, according to the bindings defined in Documentation/devicetree/bindings/
+media/video-interfaces.txt.
+
+For sensor with a parallel video bus, it could be linked directly to the isp.
+For sensor with a MIPI CSI-2 video bus, it should be linked through the
+MIPI-DPHY, which is defined in rockchip-mipi-dphy.txt.
+
+Device node example
+---
+
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+   
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   /* mipi */
+   isp0_mipi_in: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_rx0_out>;
+   };
+
+   /* parallel */
+   isp0_parallel_in: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_out>;
+   };
+   };
+   };
-- 
2.15.0



[PATCH v3 07/12] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings

2017-12-06 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

Add DT bindings documentation for Rockchip MIPI D-PHY RX

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 .../bindings/media/rockchip-mipi-dphy.txt  | 71 ++
 1 file changed, 71 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt 
b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
new file mode 100644
index ..cef9450db051
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
@@ -0,0 +1,71 @@
+Rockchip SoC MIPI RX D-PHY
+-
+
+Required properties:
+
+- compatible: value should be one of the following
+"rockchip,rk3288-mipi-dphy";
+"rockchip,rk3399-mipi-dphy";
+- rockchip,grf: GRF regs.
+- bus-width : maximum number of data lanes supported (SoC specific);
+- clocks : list of clock specifiers, corresponding to entries in
+   clock-names property;
+- clock-names: required clock name.
+
+The device node should contain two 'port' child node, according to the bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+The first port should be connected to sensor nodes, and the second port should 
be
+connected to isp node. The following are properties specific to those nodes.
+
+endpoint node
+-
+
+- data-lanes : (required) an array specifying active physical MIPI-CSI2
+   data input lanes and their mapping to logical lanes; the
+   array's content is unused, only its length is meaningful;
+
+Device node example
+---
+
+mipi_dphy_rx0: mipi-dphy-rx0 {
+compatible = "rockchip,rk3399-mipi-dphy";
+clocks = < SCLK_MIPIDPHY_REF>,
+< SCLK_DPHY_RX0_CFG>,
+< PCLK_VIO_GRF>;
+clock-names = "dphy-ref", "dphy-cfg", "grf";
+power-domains = < RK3399_PD_VIO>;
+bus-width = <4>;
+
+ports {
+#address-cells = <1>;
+#size-cells = <0>;
+
+port@0 {
+reg = <0>;
+#address-cells = <1>;
+#size-cells = <0>;
+
+mipi_in_wcam: endpoint@0 {
+reg = <0>;
+remote-endpoint = <_out>;
+data-lanes = <1 2>;
+};
+mipi_in_ucam: endpoint@1 {
+reg = <1>;
+remote-endpoint = <_out>;
+data-lanes = <1>;
+};
+};
+
+port@1 {
+reg = <1>;
+#address-cells = <1>;
+#size-cells = <0>;
+
+dphy_rx0_out: endpoint@0 {
+reg = <0>;
+remote-endpoint = <_mipi_in>;
+};
+};
+};
+};
\ No newline at end of file
-- 
2.15.0



[PATCH v3 07/12] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings

2017-12-06 Thread Jacob Chen
From: Jacob Chen 

Add DT bindings documentation for Rockchip MIPI D-PHY RX

Signed-off-by: Jacob Chen 
---
 .../bindings/media/rockchip-mipi-dphy.txt  | 71 ++
 1 file changed, 71 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt 
b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
new file mode 100644
index ..cef9450db051
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
@@ -0,0 +1,71 @@
+Rockchip SoC MIPI RX D-PHY
+-
+
+Required properties:
+
+- compatible: value should be one of the following
+"rockchip,rk3288-mipi-dphy";
+"rockchip,rk3399-mipi-dphy";
+- rockchip,grf: GRF regs.
+- bus-width : maximum number of data lanes supported (SoC specific);
+- clocks : list of clock specifiers, corresponding to entries in
+   clock-names property;
+- clock-names: required clock name.
+
+The device node should contain two 'port' child node, according to the bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+The first port should be connected to sensor nodes, and the second port should 
be
+connected to isp node. The following are properties specific to those nodes.
+
+endpoint node
+-
+
+- data-lanes : (required) an array specifying active physical MIPI-CSI2
+   data input lanes and their mapping to logical lanes; the
+   array's content is unused, only its length is meaningful;
+
+Device node example
+---
+
+mipi_dphy_rx0: mipi-dphy-rx0 {
+compatible = "rockchip,rk3399-mipi-dphy";
+clocks = < SCLK_MIPIDPHY_REF>,
+< SCLK_DPHY_RX0_CFG>,
+< PCLK_VIO_GRF>;
+clock-names = "dphy-ref", "dphy-cfg", "grf";
+power-domains = < RK3399_PD_VIO>;
+bus-width = <4>;
+
+ports {
+#address-cells = <1>;
+#size-cells = <0>;
+
+port@0 {
+reg = <0>;
+#address-cells = <1>;
+#size-cells = <0>;
+
+mipi_in_wcam: endpoint@0 {
+reg = <0>;
+remote-endpoint = <_out>;
+data-lanes = <1 2>;
+};
+mipi_in_ucam: endpoint@1 {
+reg = <1>;
+remote-endpoint = <_out>;
+data-lanes = <1>;
+};
+};
+
+port@1 {
+reg = <1>;
+#address-cells = <1>;
+#size-cells = <0>;
+
+dphy_rx0_out: endpoint@0 {
+reg = <0>;
+remote-endpoint = <_mipi_in>;
+};
+};
+};
+};
\ No newline at end of file
-- 
2.15.0



[PATCH v3 05/12] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2017-12-06 Thread Jacob Chen
From: Jacob Chen <jacob2.c...@rock-chips.com>

This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver.

Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Tomasz Figa <tf...@chromium.org>
---
 drivers/media/platform/rockchip/isp1/Makefile  |   1 +
 .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 787 +
 2 files changed, 788 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c

diff --git a/drivers/media/platform/rockchip/isp1/Makefile 
b/drivers/media/platform/rockchip/isp1/Makefile
index 8f52f959398e..18af64853734 100644
--- a/drivers/media/platform/rockchip/isp1/Makefile
+++ b/drivers/media/platform/rockchip/isp1/Makefile
@@ -4,4 +4,5 @@ video_rkisp1-objs  +=   rkisp1.o \
regs.o \
isp_stats.o \
isp_params.o \
+   mipi_dphy_sy.o \
capture.o
diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c 
b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
new file mode 100644
index ..942118366f49
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
@@ -0,0 +1,787 @@
+/*
+ * Rockchip MIPI Synopsys DPHY driver
+ *
+ * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RK3288_GRF_SOC_CON60x025c
+#define RK3288_GRF_SOC_CON80x0264
+#define RK3288_GRF_SOC_CON90x0268
+#define RK3288_GRF_SOC_CON10   0x026c
+#define RK3288_GRF_SOC_CON14   0x027c
+#define RK3288_GRF_SOC_STATUS210x02d4
+#define RK3288_GRF_IO_VSEL 0x0380
+#define RK3288_GRF_SOC_CON15   0x03a4
+
+#define RK3399_GRF_SOC_CON90x6224
+#define RK3399_GRF_SOC_CON21   0x6254
+#define RK3399_GRF_SOC_CON22   0x6258
+#define RK3399_GRF_SOC_CON23   0x625c
+#define RK3399_GRF_SOC_CON24   0x6260
+#define RK3399_GRF_SOC_CON25   0x6264
+#define RK3399_GRF_SOC_STATUS1 0xe2a4
+
+#define CLOCK_LANE_HS_RX_CONTROL   0x34
+#define LANE0_HS_RX_CONTROL0x44
+#define LANE1_HS_RX_CONTROL0x54
+#define LANE2_HS_RX_CONTROL0x84
+#define LANE3_HS_RX_CONTROL0x94
+#define HS_RX_DATA_LANES_THS_SETTLE__CONTROL   0x75
+
+#define HIWORD_UPDATE(val, mask, shift) \
+   ((val) << (shift) | (mask) << ((shift) + 16))
+
+enum mipi_dphy_sy_pads {
+   MIPI_DPHY_SY_PAD_SINK = 0,
+   MIPI_DPHY_SY_PAD_SOURCE,
+   MIPI_DPHY_SY_PADS_NUM,
+};
+
+enum dphy_reg_id {
+   GRF_DPHY_RX0_TURNDISABLE = 0,
+   GRF_DPHY_RX0_FORCERXMODE,
+   GRF_DPHY_RX0_FORCETXSTOPMODE,
+   GRF_DPHY_RX0_ENABLE,
+   GRF_DPHY_RX0_TESTCLR,
+   GRF_DPHY_RX0_TESTCLK,
+   GRF_DPHY_RX0_TESTEN,
+   GRF_DPHY_RX0_TESTDIN,
+   GRF_DPHY_RX0_TURNREQUEST,
+   GRF_DPHY_RX0_TESTDOUT,
+   GRF_DPHY_TX0_TURNDISABLE,
+   GRF_DPHY_TX0_FORCERXMODE,
+   GRF_DPHY_TX0_FORCETXSTOPMODE,
+   GRF_DPHY_TX0_TURNREQUEST,
+   GRF_DPHY_TX1RX1_TURNDISABLE,
+   GRF_DPHY_TX1RX1_FORCERXMODE,
+   GRF_DPHY_TX1RX1_FORCETXSTOPMODE,
+   GRF_DPHY_TX1RX1_ENABLE,
+   GRF_DPHY_TX1RX1_MASTERSLAVEZ,
+   GRF_DPHY_TX1RX1_BASEDIR,
+   GRF_DPHY_TX1RX1_ENABLECLK,
+   GRF_DPHY_TX1RX1_TURNREQUEST,
+   GRF_DPHY_RX1_SRC_SEL,
+  

[PATCH v3 05/12] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2017-12-06 Thread Jacob Chen
From: Jacob Chen 

This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/Makefile  |   1 +
 .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 787 +
 2 files changed, 788 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c

diff --git a/drivers/media/platform/rockchip/isp1/Makefile 
b/drivers/media/platform/rockchip/isp1/Makefile
index 8f52f959398e..18af64853734 100644
--- a/drivers/media/platform/rockchip/isp1/Makefile
+++ b/drivers/media/platform/rockchip/isp1/Makefile
@@ -4,4 +4,5 @@ video_rkisp1-objs  +=   rkisp1.o \
regs.o \
isp_stats.o \
isp_params.o \
+   mipi_dphy_sy.o \
capture.o
diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c 
b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
new file mode 100644
index ..942118366f49
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
@@ -0,0 +1,787 @@
+/*
+ * Rockchip MIPI Synopsys DPHY driver
+ *
+ * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RK3288_GRF_SOC_CON60x025c
+#define RK3288_GRF_SOC_CON80x0264
+#define RK3288_GRF_SOC_CON90x0268
+#define RK3288_GRF_SOC_CON10   0x026c
+#define RK3288_GRF_SOC_CON14   0x027c
+#define RK3288_GRF_SOC_STATUS210x02d4
+#define RK3288_GRF_IO_VSEL 0x0380
+#define RK3288_GRF_SOC_CON15   0x03a4
+
+#define RK3399_GRF_SOC_CON90x6224
+#define RK3399_GRF_SOC_CON21   0x6254
+#define RK3399_GRF_SOC_CON22   0x6258
+#define RK3399_GRF_SOC_CON23   0x625c
+#define RK3399_GRF_SOC_CON24   0x6260
+#define RK3399_GRF_SOC_CON25   0x6264
+#define RK3399_GRF_SOC_STATUS1 0xe2a4
+
+#define CLOCK_LANE_HS_RX_CONTROL   0x34
+#define LANE0_HS_RX_CONTROL0x44
+#define LANE1_HS_RX_CONTROL0x54
+#define LANE2_HS_RX_CONTROL0x84
+#define LANE3_HS_RX_CONTROL0x94
+#define HS_RX_DATA_LANES_THS_SETTLE__CONTROL   0x75
+
+#define HIWORD_UPDATE(val, mask, shift) \
+   ((val) << (shift) | (mask) << ((shift) + 16))
+
+enum mipi_dphy_sy_pads {
+   MIPI_DPHY_SY_PAD_SINK = 0,
+   MIPI_DPHY_SY_PAD_SOURCE,
+   MIPI_DPHY_SY_PADS_NUM,
+};
+
+enum dphy_reg_id {
+   GRF_DPHY_RX0_TURNDISABLE = 0,
+   GRF_DPHY_RX0_FORCERXMODE,
+   GRF_DPHY_RX0_FORCETXSTOPMODE,
+   GRF_DPHY_RX0_ENABLE,
+   GRF_DPHY_RX0_TESTCLR,
+   GRF_DPHY_RX0_TESTCLK,
+   GRF_DPHY_RX0_TESTEN,
+   GRF_DPHY_RX0_TESTDIN,
+   GRF_DPHY_RX0_TURNREQUEST,
+   GRF_DPHY_RX0_TESTDOUT,
+   GRF_DPHY_TX0_TURNDISABLE,
+   GRF_DPHY_TX0_FORCERXMODE,
+   GRF_DPHY_TX0_FORCETXSTOPMODE,
+   GRF_DPHY_TX0_TURNREQUEST,
+   GRF_DPHY_TX1RX1_TURNDISABLE,
+   GRF_DPHY_TX1RX1_FORCERXMODE,
+   GRF_DPHY_TX1RX1_FORCETXSTOPMODE,
+   GRF_DPHY_TX1RX1_ENABLE,
+   GRF_DPHY_TX1RX1_MASTERSLAVEZ,
+   GRF_DPHY_TX1RX1_BASEDIR,
+   GRF_DPHY_TX1RX1_ENABLECLK,
+   GRF_DPHY_TX1RX1_TURNREQUEST,
+   GRF_DPHY_RX1_SRC_SEL,
+   /* rk3288 only */
+   GRF_CON_DISABLE_ISP,
+   GRF_CON_ISP_DPHY_SEL,
+   GRF_DSI_CSI_TESTBUS_SEL,
+   GRF_DVP_V1

[PATCH v3 10/12] arm64: dts: rockchip: add isp0 node for rk3399

2017-12-06 Thread Jacob Chen
From: Shunqian Zheng <zhen...@rock-chips.com>

rk3399 have two ISP, but we havn't test isp1, so just add isp0 at present.

Signed-off-by: Shunqian Zheng <zhen...@rock-chips.com>
Signed-off-by: Jacob Chen <jacob2.c...@rock-chips.com>
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index d340b58ab184..66a912fab5dd 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1588,6 +1588,21 @@
status = "disabled";
};
 
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+   status = "disabled";
+   };
+
isp0_mmu: iommu@ff914000 {
compatible = "rockchip,iommu";
reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
-- 
2.15.0



[PATCH v3 10/12] arm64: dts: rockchip: add isp0 node for rk3399

2017-12-06 Thread Jacob Chen
From: Shunqian Zheng 

rk3399 have two ISP, but we havn't test isp1, so just add isp0 at present.

Signed-off-by: Shunqian Zheng 
Signed-off-by: Jacob Chen 
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index d340b58ab184..66a912fab5dd 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1588,6 +1588,21 @@
status = "disabled";
};
 
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+   status = "disabled";
+   };
+
isp0_mmu: iommu@ff914000 {
compatible = "rockchip,iommu";
reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
-- 
2.15.0



  1   2   3   4   5   >