Skip to contentSkip to conversation

Rockchip ISP1 Driver

PATCH Superseded Jacob Chen 5 participants 26 messages Nov 24, 2017 – Nov 30, 2017 Page 2 of 2

Subsystems (4)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#14 lore raw

Re: [PATCH v2 04/11] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

In reply to Hans Verkuil

++ Joao, ++ Luis

Hi Hans,

We will take a look into this. Thanks for pointing this out!

Best Regards,
Jose Miguel Abreu

Quoted 856 lines · Hans Verkuil

I'm CC-ing Jose Abreu from Synopsys to this. Jose, can you or a colleague take a look at this as well?

Jacob, I have some high-level questions first:

1) to what extend is this code rockchip-specific as opposed to be more synopsys-generic?

2) I don't quite see how this works when there are two sensors. Is only one active at a time? Or are they multiplexed somehow?

3) Same as for the previous patch: some more comments would be welcome.

Quoted 500 lines · Jacob Chen

From: Jacob Chen <[email protected]>

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

The phy driver is kind of independent compare to the other parts, but i'd like to keep it in rkisp1 driver, unless people want to generalize it

---
 drivers/media/platform/rockchip/isp1/Makefile      |   1 +
 .../media/platform/rockchip/isp1/mipi_dphy_sy.c    | 805 +++++++++++++++++++++
 2 files changed, 806 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
drivers/media/platform/rockchip/isp1/Makefile +1 -0
index 8f52f959398e..18af64853734 100644
@@ -4,4 +4,5 @@ video_rkisp1-objs 	   += 	rkisp1.o \
 				regs.o \
 				isp_stats.o \
 				isp_params.o \
+				mipi_dphy_sy.o \
 				capture.o
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +468 -0
new file mode 100644
index 000000000000..56deff2be6fd
@@ -0,0 +1,805 @@
+/*
+ * 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 <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
+#include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-fwnode.h>
+#include <media/v4l2-subdev.h>
+
+#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,
+	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] = PHY_REG(RK3399_GRF_SOC_CON23, 4, 4),
+	[GRF_DPHY_TX1RX1_FORCETXSTOPMODE] = PHY_REG(RK3399_GRF_SOC_CON23, 4, 8),
+	[GRF_DPHY_TX1RX1_TURNDISABLE] = PHY_REG(RK3399_GRF_SOC_CON23, 4, 12),
+	[GRF_DPHY_TX1RX1_TURNREQUEST] = PHY_REG(RK3399_GRF_SOC_CON24, 4, 0),
+	[GRF_DPHY_RX1_SRC_SEL] = PHY_REG(RK3399_GRF_SOC_CON24, 1, 4),
+	[GRF_DPHY_TX1RX1_BASEDIR] = PHY_REG(RK3399_GRF_SOC_CON24, 1, 5),
+	[GRF_DPHY_TX1RX1_ENABLECLK] = PHY_REG(RK3399_GRF_SOC_CON24, 1, 6),
+	[GRF_DPHY_TX1RX1_MASTERSLAVEZ] = PHY_REG(RK3399_GRF_SOC_CON24, 1, 7),
+	[GRF_DPHY_RX0_TESTDIN] = PHY_REG(RK3399_GRF_SOC_CON25, 8, 0),
+	[GRF_DPHY_RX0_TESTEN] = PHY_REG(RK3399_GRF_SOC_CON25, 1, 8),
+	[GRF_DPHY_RX0_TESTCLK] = PHY_REG(RK3399_GRF_SOC_CON25, 1, 9),
+	[GRF_DPHY_RX0_TESTCLR] = PHY_REG(RK3399_GRF_SOC_CON25, 1, 10),
+	[GRF_DPHY_RX0_TESTDOUT] = PHY_REG(RK3399_GRF_SOC_STATUS1, 8, 0),
+};
+
+static const struct dphy_reg rk3288_grf_dphy_regs[] = {
+	[GRF_CON_DISABLE_ISP] = PHY_REG(RK3288_GRF_SOC_CON6, 1, 0),
+	[GRF_CON_ISP_DPHY_SEL] = PHY_REG(RK3288_GRF_SOC_CON6, 1, 1),
+	[GRF_DSI_CSI_TESTBUS_SEL] = PHY_REG(RK3288_GRF_SOC_CON6, 1, 14),
+	[GRF_DPHY_TX0_TURNDISABLE] = PHY_REG(RK3288_GRF_SOC_CON8, 4, 0),
+	[GRF_DPHY_TX0_FORCERXMODE] = PHY_REG(RK3288_GRF_SOC_CON8, 4, 4),
+	[GRF_DPHY_TX0_FORCETXSTOPMODE] = PHY_REG(RK3288_GRF_SOC_CON8, 4, 8),
+	[GRF_DPHY_TX1RX1_TURNDISABLE] = PHY_REG(RK3288_GRF_SOC_CON9, 4, 0),
+	[GRF_DPHY_TX1RX1_FORCERXMODE] = PHY_REG(RK3288_GRF_SOC_CON9, 4, 4),
+	[GRF_DPHY_TX1RX1_FORCETXSTOPMODE] = PHY_REG(RK3288_GRF_SOC_CON9, 4, 8),
+	[GRF_DPHY_TX1RX1_ENABLE] = PHY_REG(RK3288_GRF_SOC_CON9, 4, 12),
+	[GRF_DPHY_RX0_TURNDISABLE] = PHY_REG(RK3288_GRF_SOC_CON10, 4, 0),
+	[GRF_DPHY_RX0_FORCERXMODE] = PHY_REG(RK3288_GRF_SOC_CON10, 4, 4),
+	[GRF_DPHY_RX0_FORCETXSTOPMODE] = PHY_REG(RK3288_GRF_SOC_CON10, 4, 8),
+	[GRF_DPHY_RX0_ENABLE] = PHY_REG(RK3288_GRF_SOC_CON10, 4, 12),
+	[GRF_DPHY_RX0_TESTCLR] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 0),
+	[GRF_DPHY_RX0_TESTCLK] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 1),
+	[GRF_DPHY_RX0_TESTEN] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 2),
+	[GRF_DPHY_RX0_TESTDIN] = PHY_REG(RK3288_GRF_SOC_CON14, 8, 3),
+	[GRF_DPHY_TX1RX1_ENABLECLK] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 12),
+	[GRF_DPHY_RX1_SRC_SEL] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 13),
+	[GRF_DPHY_TX1RX1_MASTERSLAVEZ] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 14),
+	[GRF_DPHY_TX1RX1_BASEDIR] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 15),
+	[GRF_DPHY_RX0_TURNREQUEST] = PHY_REG(RK3288_GRF_SOC_CON15, 4, 0),
+	[GRF_DPHY_TX1RX1_TURNREQUEST] = PHY_REG(RK3288_GRF_SOC_CON15, 4, 4),
+	[GRF_DPHY_TX0_TURNREQUEST] = PHY_REG(RK3288_GRF_SOC_CON15, 3, 8),
+	[GRF_DVP_V18SEL] = PHY_REG(RK3288_GRF_IO_VSEL, 1, 1),
+	[GRF_DPHY_RX0_TESTDOUT] = PHY_REG(RK3288_GRF_SOC_STATUS21, 8, 0),
+};
+
+struct hsfreq_range {
+	u32 range_h;
+	u8 cfg_bit;
+};
+
+struct dphy_drv_data {
+	const char * const *clks;
+	int num_clks;
+	const struct hsfreq_range *hsfreq_ranges;
+	int num_hsfreq_ranges;
+	const struct dphy_reg *regs;
+};
+
+struct sensor_async_subdev {
+	struct v4l2_async_subdev asd;
+	struct v4l2_mbus_config mbus;
+	int lanes;
+};
+
+#define MAX_DPHY_CLK		8
+#define MAX_DPHY_SENSORS	2
+
+struct mipidphy_sensor {
+	struct v4l2_subdev *sd;
+	struct v4l2_mbus_config mbus;
+	int lanes;
+};
+
+struct mipidphy_priv {
+	struct device *dev;
+	struct regmap *regmap_grf;
+	const struct dphy_reg *grf_regs;
+	struct clk *clks[MAX_DPHY_CLK];
+	const struct dphy_drv_data *drv_data;
+	u64 data_rate_mbps;
+	struct v4l2_async_notifier notifier;
+	struct v4l2_subdev sd;
+	struct media_pad pads[MIPI_DPHY_SY_PADS_NUM];
+	struct mipidphy_sensor sensors[MAX_DPHY_SENSORS];
+	int num_sensors;
+	bool is_streaming;
+};
+
+static inline struct mipidphy_priv *to_dphy_priv(struct v4l2_subdev *subdev)
+{
+	return container_of(subdev, struct mipidphy_priv, sd);
+}
+
+static inline void write_reg(struct mipidphy_priv *priv, int index, u8 value)
+{
+	const struct dphy_reg *reg = &priv->grf_regs[index];
+	unsigned int val = HIWORD_UPDATE(value, reg->mask, reg->shift);
+
+	WARN_ON(!reg->offset);
+	regmap_write(priv->regmap_grf, reg->offset, val);
+}
+
+static void mipidphy_wr_reg(struct mipidphy_priv *priv,
+			    u8 test_code, u8 test_data)
+{
+	/*
+	 * With the falling edge on TESTCLK, the TESTDIN[7:0] signal content
+	 * is latched internally as the current test code. Test data is
+	 * programmed internally by rising edge on TESTCLK.
+	 */
+	write_reg(priv, GRF_DPHY_RX0_TESTCLK, 1);
+	write_reg(priv, GRF_DPHY_RX0_TESTDIN, test_code);
+	write_reg(priv, GRF_DPHY_RX0_TESTEN, 1);
+	write_reg(priv, GRF_DPHY_RX0_TESTCLK, 0);
+	write_reg(priv, GRF_DPHY_RX0_TESTEN, 0);
+	write_reg(priv, GRF_DPHY_RX0_TESTDIN, test_data);
+	write_reg(priv, GRF_DPHY_RX0_TESTCLK, 1);
+}
+
+static struct v4l2_subdev *get_remote_sensor(struct v4l2_subdev *sd)
+{
+	struct media_pad *local, *remote;
+	struct media_entity *sensor_me;
+
+	local = &sd->entity.pads[MIPI_DPHY_SY_PAD_SINK];
+	remote = media_entity_remote_pad(local);
+	if (!remote) {
+		v4l2_warn(sd, "No link between dphy and sensor\n");
+		return NULL;
+	}
+
+	sensor_me = media_entity_remote_pad(local)->entity;
+	return media_entity_to_v4l2_subdev(sensor_me);
+}
+
+static struct mipidphy_sensor *sd_to_sensor(struct mipidphy_priv *priv,
+					    struct v4l2_subdev *sd)
+{
+	int i;
+
+	for (i = 0; i < priv->num_sensors; ++i)
+		if (priv->sensors[i].sd == sd)
+			return &priv->sensors[i];
+
+	return NULL;
+}
+
+static int mipidphy_get_sensor_data_rate(struct v4l2_subdev *sd)
+{
+	struct mipidphy_priv *priv = to_dphy_priv(sd);
+	struct v4l2_subdev *sensor_sd = get_remote_sensor(sd);
+	struct v4l2_ctrl *link_freq;
+	struct v4l2_querymenu qm = { .id = V4L2_CID_LINK_FREQ, };
+	int ret;
+
+	link_freq = v4l2_ctrl_find(sensor_sd->ctrl_handler, V4L2_CID_LINK_FREQ);
+	if (!link_freq) {
+		v4l2_warn(sd, "No pixel rate control in subdev\n");
+		return -EPIPE;
+	}
+
+	qm.index = v4l2_ctrl_g_ctrl(link_freq);
+	ret = v4l2_querymenu(sensor_sd->ctrl_handler, &qm);
+	if (ret < 0) {
+		v4l2_err(sd, "Failed to get menu item\n");
+		return ret;
+	}
+
+	if (!qm.value) {
+		v4l2_err(sd, "Invalid link_freq\n");
+		return -EINVAL;
+	}
+	priv->data_rate_mbps = qm.value * 2;
+	do_div(priv->data_rate_mbps, 1000 * 1000);
+
+	return 0;
+}
+
+static int mipidphy_s_stream_start(struct v4l2_subdev *sd)
+{
+	struct mipidphy_priv *priv = to_dphy_priv(sd);
+	const struct dphy_drv_data *drv_data = priv->drv_data;
+	const struct hsfreq_range *hsfreq_ranges = drv_data->hsfreq_ranges;
+	int num_hsfreq_ranges = drv_data->num_hsfreq_ranges;
+	struct v4l2_subdev *sensor_sd = get_remote_sensor(sd);
+	struct mipidphy_sensor *sensor = sd_to_sensor(priv, sensor_sd);
+	int i, ret, hsfreq = 0;
+
+	if (priv->is_streaming)
+		return 0;
+
+	ret = mipidphy_get_sensor_data_rate(sd);
+	if (ret < 0)
+		return ret;
+
+	for (i = 0; i < num_hsfreq_ranges; i++) {
+		if (hsfreq_ranges[i].range_h >= priv->data_rate_mbps) {
+			hsfreq = hsfreq_ranges[i].cfg_bit;
+			break;
+		}
+	}
+
+	write_reg(priv, GRF_DPHY_RX0_FORCERXMODE, 0);
+	write_reg(priv, GRF_DPHY_RX0_FORCETXSTOPMODE, 0);
+	/* Disable lan turn around, which is ignored in receive mode */
+	write_reg(priv, GRF_DPHY_RX0_TURNREQUEST, 0);
+	write_reg(priv, GRF_DPHY_RX0_TURNDISABLE, 0xf);
+
+	write_reg(priv, GRF_DPHY_RX0_ENABLE, GENMASK(sensor->lanes - 1, 0));
+
+	/* dphy start */
+	write_reg(priv, GRF_DPHY_RX0_TESTCLK, 1);
+	write_reg(priv, GRF_DPHY_RX0_TESTCLR, 1);
+	usleep_range(100, 150);
+	write_reg(priv, GRF_DPHY_RX0_TESTCLR, 0);
+	usleep_range(100, 150);
+
+	/* set clock lane */
+	/* HS hsfreq_range & lane 0  settle bypass */
+	mipidphy_wr_reg(priv, CLOCK_LANE_HS_RX_CONTROL, 0);
+	/* HS RX Control of lane0 */
+	mipidphy_wr_reg(priv, LANE0_HS_RX_CONTROL, hsfreq << 1);
+	/* HS RX Control of lane1 */
+	mipidphy_wr_reg(priv, LANE1_HS_RX_CONTROL, 0);
+	/* HS RX Control of lane2 */
+	mipidphy_wr_reg(priv, LANE2_HS_RX_CONTROL, 0);
+	/* HS RX Control of lane3 */
+	mipidphy_wr_reg(priv, LANE3_HS_RX_CONTROL, 0);
+	/* HS RX Data Lanes Settle State Time Control */
+	mipidphy_wr_reg(priv, HS_RX_DATA_LANES_THS_SETTLE__CONTROL, 0x04);
+
+	/* Normal operation */
+	mipidphy_wr_reg(priv, 0x0, 0);
+
+	priv->is_streaming = true;
+
+	return 0;
+}
+
+static int mipidphy_s_stream_stop(struct v4l2_subdev *sd)
+{
+	struct mipidphy_priv *priv = to_dphy_priv(sd);
+
+	if (!priv->is_streaming)
+		return 0;
+
+	priv->is_streaming = false;
+
+	return 0;
+}
+
+static int mipidphy_s_stream(struct v4l2_subdev *sd, int on)
+{
+	if (on)
+		return mipidphy_s_stream_start(sd);
+	else
+		return mipidphy_s_stream_stop(sd);
+}
+
+static int mipidphy_g_mbus_config(struct v4l2_subdev *sd,
+				  struct v4l2_mbus_config *config)
+{
+	struct mipidphy_priv *priv = to_dphy_priv(sd);
+	struct v4l2_subdev *sensor_sd = get_remote_sensor(sd);
+	struct mipidphy_sensor *sensor = sd_to_sensor(priv, sensor_sd);
+
+	*config = sensor->mbus;
+
+	return 0;
+}
+
+static int mipidphy_s_power(struct v4l2_subdev *sd, int on)
+{
+	struct mipidphy_priv *priv = to_dphy_priv(sd);
+
+	if (on)
+		return pm_runtime_get_sync(priv->dev);
+	else
+		return pm_runtime_put(priv->dev);
+}
+
+static int mipidphy_runtime_suspend(struct device *dev)
+{
+	struct media_entity *me = dev_get_drvdata(dev);
+	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(me);
+	struct mipidphy_priv *priv = to_dphy_priv(sd);
+	int i, num_clks;
+
+	num_clks = priv->drv_data->num_clks;
+	for (i = num_clks - 1; i >= 0; i--)
+		clk_disable_unprepare(priv->clks[i]);
+
+	return 0;
+}
+
+static int mipidphy_runtime_resume(struct device *dev)
+{
+	struct media_entity *me = dev_get_drvdata(dev);
+	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(me);
+	struct mipidphy_priv *priv = to_dphy_priv(sd);
+	int i, num_clks, ret;
+
+	num_clks = priv->drv_data->num_clks;
+	for (i = 0; i < num_clks; i++) {
+		ret = clk_prepare_enable(priv->clks[i]);
+		if (ret < 0)
+			goto err;
+	}
+
+	return 0;
+err:
+	while (--i >= 0)
+		clk_disable_unprepare(priv->clks[i]);
+	return ret;
+}
+
+/* dphy accepts all fmt/size from sensor */
+static int mipidphy_get_set_fmt(struct v4l2_subdev *sd,
+				struct v4l2_subdev_pad_config *cfg,
+				struct v4l2_subdev_format *fmt)
+{
+	struct v4l2_subdev *sensor = get_remote_sensor(sd);
+
+	/*
+	 * Do not allow format changes and just relay whatever
+	 * set currently in the sensor.
+	 */
+	return v4l2_subdev_call(sensor, pad, get_fmt, NULL, fmt);
+}
+
+static const struct v4l2_subdev_pad_ops mipidphy_subdev_pad_ops = {

drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c line 478

Quoted 10 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +10 -0
+	.set_fmt = mipidphy_get_set_fmt,
+	.get_fmt = mipidphy_get_set_fmt,
+};
+
+static const struct v4l2_subdev_core_ops mipidphy_core_ops = {
+	.s_power = mipidphy_s_power,
+};
+
+static const struct v4l2_subdev_video_ops mipidphy_video_ops = {
+	.g_mbus_config = mipidphy_g_mbus_config,

Why do you need this?

Quoted 318 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +317 -0
+	.s_stream = mipidphy_s_stream,
+};
+
+static const struct v4l2_subdev_ops mipidphy_subdev_ops = {
+	.core = &mipidphy_core_ops,
+	.video = &mipidphy_video_ops,
+	.pad = &mipidphy_subdev_pad_ops,
+};
+
+/* These tables must be sorted by .range_h ascending. */
+static const struct hsfreq_range rk3288_mipidphy_hsfreq_ranges[] = {
+	{  89, 0x00}, {  99, 0x10}, { 109, 0x20}, { 129, 0x01},
+	{ 139, 0x11}, { 149, 0x21}, { 169, 0x02}, { 179, 0x12},
+	{ 199, 0x22}, { 219, 0x03}, { 239, 0x13}, { 249, 0x23},
+	{ 269, 0x04}, { 299, 0x14}, { 329, 0x05}, { 359, 0x15},
+	{ 399, 0x25}, { 449, 0x06}, { 499, 0x16}, { 549, 0x07},
+	{ 599, 0x17}, { 649, 0x08}, { 699, 0x18}, { 749, 0x09},
+	{ 799, 0x19}, { 849, 0x29}, { 899, 0x39}, { 949, 0x0a},
+	{ 999, 0x1a}
+};
+
+static const struct hsfreq_range rk3399_mipidphy_hsfreq_ranges[] = {
+	{  89, 0x00}, {  99, 0x10}, { 109, 0x20}, { 129, 0x01},
+	{ 139, 0x11}, { 149, 0x21}, { 169, 0x02}, { 179, 0x12},
+	{ 199, 0x22}, { 219, 0x03}, { 239, 0x13}, { 249, 0x23},
+	{ 269, 0x04}, { 299, 0x14}, { 329, 0x05}, { 359, 0x15},
+	{ 399, 0x25}, { 449, 0x06}, { 499, 0x16}, { 549, 0x07},
+	{ 599, 0x17}, { 649, 0x08}, { 699, 0x18}, { 749, 0x09},
+	{ 799, 0x19}, { 849, 0x29}, { 899, 0x39}, { 949, 0x0a},
+	{ 999, 0x1a}, {1049, 0x2a}, {1099, 0x3a}, {1149, 0x0b},
+	{1199, 0x1b}, {1249, 0x2b}, {1299, 0x3b}, {1349, 0x0c},
+	{1399, 0x1c}, {1449, 0x2c}, {1500, 0x3c}
+};
+
+static const char * const rk3399_mipidphy_clks[] = {
+	"dphy-ref",
+	"dphy-cfg",
+	"grf",
+};
+
+static const char * const rk3288_mipidphy_clks[] = {
+	"dphy-ref",
+	"pclk",
+};
+
+static const struct dphy_drv_data rk3288_mipidphy_drv_data = {
+	.clks = rk3288_mipidphy_clks,
+	.num_clks = ARRAY_SIZE(rk3288_mipidphy_clks),
+	.hsfreq_ranges = rk3288_mipidphy_hsfreq_ranges,
+	.num_hsfreq_ranges = ARRAY_SIZE(rk3288_mipidphy_hsfreq_ranges),
+	.regs = rk3288_grf_dphy_regs,
+};
+
+static const struct dphy_drv_data rk3399_mipidphy_drv_data = {
+	.clks = rk3399_mipidphy_clks,
+	.num_clks = ARRAY_SIZE(rk3399_mipidphy_clks),
+	.hsfreq_ranges = rk3399_mipidphy_hsfreq_ranges,
+	.num_hsfreq_ranges = ARRAY_SIZE(rk3399_mipidphy_hsfreq_ranges),
+	.regs = rk3399_grf_dphy_regs,
+};
+
+static const struct of_device_id rockchip_mipidphy_match_id[] = {
+	{
+		.compatible = "rockchip,rk3399-mipi-dphy",
+		.data = &rk3399_mipidphy_drv_data,
+	},
+	{
+		.compatible = "rockchip,rk3288-mipi-dphy",
+		.data = &rk3288_mipidphy_drv_data,
+	},
+	{}
+};
+MODULE_DEVICE_TABLE(of, rockchip_mipidphy_match_id);
+
+/* The .bound() notifier callback when a match is found */
+static int
+rockchip_mipidphy_notifier_bound(struct v4l2_async_notifier *notifier,
+				 struct v4l2_subdev *sd,
+				 struct v4l2_async_subdev *asd)
+{
+	struct mipidphy_priv *priv = container_of(notifier,
+						  struct mipidphy_priv,
+						  notifier);
+	struct sensor_async_subdev *s_asd = container_of(asd,
+					struct sensor_async_subdev, asd);
+	struct mipidphy_sensor *sensor;
+
+	if (priv->num_sensors == ARRAY_SIZE(priv->sensors))
+		return -EBUSY;
+
+	sensor = &priv->sensors[priv->num_sensors++];
+	sensor->lanes = s_asd->lanes;
+	sensor->mbus = s_asd->mbus;
+	sensor->sd = sd;
+
+	return 0;
+}
+
+/* The .unbind callback */
+static void
+rockchip_mipidphy_notifier_unbind(struct v4l2_async_notifier *notifier,
+				  struct v4l2_subdev *sd,
+				  struct v4l2_async_subdev *asd)
+{
+	struct mipidphy_priv *priv = container_of(notifier,
+						  struct mipidphy_priv,
+						  notifier);
+	struct mipidphy_sensor *sensor = sd_to_sensor(priv, sd);
+
+	sensor->sd = NULL;
+}
+
+/* .complete() is called after all subdevices have been located */
+static int
+rockchip_mipidphy_notifier_complete(struct v4l2_async_notifier *notifier)
+{
+	struct mipidphy_priv *priv = container_of(notifier,
+						  struct mipidphy_priv,
+						  notifier);
+	unsigned int pad;
+	int ret;
+	int i;
+
+	for (i = 0; i < priv->num_sensors; ++i) {
+		struct mipidphy_sensor *sensor = &priv->sensors[i];
+
+		for (pad = 0; pad < sensor->sd->entity.num_pads; pad++)
+			if (sensor->sd->entity.pads[pad].flags
+						& MEDIA_PAD_FL_SOURCE)
+				break;
+
+		if (pad == sensor->sd->entity.num_pads) {
+			dev_err(priv->dev,
+				"failed to find src pad for %s\n",
+				sensor->sd->name);
+
+			return -ENXIO;
+		}
+
+		ret = media_create_pad_link(
+				&sensor->sd->entity, pad,
+				&priv->sd.entity, MIPI_DPHY_SY_PAD_SINK,
+				i ? 0 : MEDIA_LNK_FL_ENABLED);
+		if (ret) {
+			dev_err(priv->dev,
+				"failed to create link for %s\n",
+				sensor->sd->name);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static const
+struct v4l2_async_notifier_operationsrockchip_mipidphy_async_ops = {
+	.bound = rockchip_mipidphy_notifier_bound,
+	.unbind = rockchip_mipidphy_notifier_unbind,
+	.complete = rockchip_mipidphy_notifier_complete,
+};
+
+static int rockchip_mipidphy_fwnode_parse(struct device *dev,
+			     struct v4l2_fwnode_endpoint *vep,
+			     struct v4l2_async_subdev *asd)
+{
+	struct sensor_async_subdev *s_asd =
+			container_of(asd, struct sensor_async_subdev, asd);
+	struct v4l2_mbus_config *config = &s_asd->mbus;
+
+	if (vep->bus_type != V4L2_MBUS_CSI2) {
+		dev_err(dev, "Only CSI2 bus type is currently supported\n");
+		return -EINVAL;
+	}
+
+	if (vep->base.port != 0) {
+		dev_err(dev, "The PHY has only port 0\n");
+		return -EINVAL;
+	}
+
+	config->type = V4L2_MBUS_CSI2;
+	config->flags = vep->bus.mipi_csi2.flags;
+	s_asd->lanes = vep->bus.mipi_csi2.num_data_lanes;
+
+	switch (vep->bus.mipi_csi2.num_data_lanes) {
+	case 1:
+		config->flags |= V4L2_MBUS_CSI2_1_LANE;
+		break;
+	case 2:
+		config->flags |= V4L2_MBUS_CSI2_2_LANE;
+		break;
+	case 3:
+		config->flags |= V4L2_MBUS_CSI2_3_LANE;
+		break;
+	case 4:
+		config->flags |= V4L2_MBUS_CSI2_4_LANE;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int rockchip_mipidphy_media_init(struct mipidphy_priv *priv)
+{
+	int ret;
+
+	priv->pads[MIPI_DPHY_SY_PAD_SOURCE].flags =
+		MEDIA_PAD_FL_SOURCE | MEDIA_PAD_FL_MUST_CONNECT;
+	priv->pads[MIPI_DPHY_SY_PAD_SINK].flags =
+		MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
+
+	ret = media_entity_pads_init(&priv->sd.entity,
+				 MIPI_DPHY_SY_PADS_NUM, priv->pads);
+	if (ret < 0)
+		return ret;
+
+	ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
+		priv->dev, &priv->notifier,
+		sizeof(struct sensor_async_subdev), 0,
+		rockchip_mipidphy_fwnode_parse);
+	if (ret < 0)
+		return ret;
+
+	if (!priv->notifier.num_subdevs)
+		return -ENODEV;	/* no endpoint */
+
+	priv->sd.subdev_notifier = &priv->notifier;
+	priv->notifier.ops = &rockchip_mipidphy_async_ops;
+	ret = v4l2_async_subdev_notifier_register(&priv->sd, &priv->notifier);
+	if (ret) {
+		dev_err(priv->dev,
+			"failed to register async notifier : %d\n", ret);
+		v4l2_async_notifier_cleanup(&priv->notifier);
+		return ret;
+	}
+
+	return v4l2_async_register_subdev(&priv->sd);
+}
+
+static int rockchip_mipidphy_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct v4l2_subdev *sd;
+	struct mipidphy_priv *priv;
+	struct regmap *grf;
+	const struct of_device_id *of_id;
+	const struct dphy_drv_data *drv_data;
+	int i, ret;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+	priv->dev = dev;
+
+	of_id = of_match_device(rockchip_mipidphy_match_id, dev);
+	if (!of_id)
+		return -EINVAL;
+
+	grf = syscon_node_to_regmap(dev->parent->of_node);
+	if (IS_ERR(grf)) {
+		dev_err(dev, "Can't find GRF syscon\n");
+		return -ENODEV;
+	}
+	priv->regmap_grf = grf;
+
+	drv_data = of_id->data;
+	for (i = 0; i < drv_data->num_clks; i++) {
+		priv->clks[i] = devm_clk_get(dev, drv_data->clks[i]);
+
+		if (IS_ERR(priv->clks[i])) {
+			dev_err(dev, "Failed to get %s\n", drv_data->clks[i]);
+			return PTR_ERR(priv->clks[i]);
+		}
+	}
+
+	priv->grf_regs = drv_data->regs;
+	priv->drv_data = drv_data;
+
+	sd = &priv->sd;
+	v4l2_subdev_init(sd, &mipidphy_subdev_ops);
+	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	snprintf(sd->name, sizeof(sd->name), "rockchip-sy-mipi-dphy");
+	sd->dev = dev;
+
+	platform_set_drvdata(pdev, &sd->entity);
+
+	ret = rockchip_mipidphy_media_init(priv);
+	if (ret < 0)
+		return ret;
+
+	pm_runtime_enable(&pdev->dev);
+
+	return 0;
+}
+
+static int rockchip_mipidphy_remove(struct platform_device *pdev)
+{
+	struct media_entity *me = platform_get_drvdata(pdev);
+	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(me);
+
+	media_entity_cleanup(&sd->entity);
+
+	pm_runtime_disable(&pdev->dev);
+
+	return 0;
+}
+
+static const struct dev_pm_ops rockchip_mipidphy_pm_ops = {
+	SET_RUNTIME_PM_OPS(mipidphy_runtime_suspend,
+			   mipidphy_runtime_resume, NULL)
+};
+
+static struct platform_driver rockchip_isp_mipidphy_driver = {
+	.probe = rockchip_mipidphy_probe,
+	.remove = rockchip_mipidphy_remove,
+	.driver = {

drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c line 805

Quoted 10 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +10 -0
+			.name = "rockchip-sy-mipi-dphy",
+			.pm = &rockchip_mipidphy_pm_ops,
+			.of_match_table = rockchip_mipidphy_match_id,
+	},
+};
+
+module_platform_driver(rockchip_isp_mipidphy_driver);
+MODULE_AUTHOR("Rockchip Camera/ISP team");
+MODULE_DESCRIPTION("Rockchip MIPI DPHY driver");
+MODULE_LICENSE("Dual BSD/GPL");

Regards,

Hans

author
#15 lore raw

Re: [PATCH v2 04/11] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

Hi Hans,

2017-11-27 22:15 GMT+08:00 Jose Abreu <[email protected]>:

Quoted 16 lines

++ Joao, ++ Luis

Hi Hans,

We will take a look into this. Thanks for pointing this out!

Best Regards,
Jose Miguel Abreu

Quoted 6 lines · Hans Verkuil

I'm CC-ing Jose Abreu from Synopsys to this. Jose, can you or a colleague take a look at this as well?

Jacob, I have some high-level questions first:

1) to what extend is this code rockchip-specific as opposed to be more synopsys-generic?

See below.

Quoted 4 lines
Quoted 4 lines

2) I don't quite see how this works when there are two sensors. Is only one active at a time? Or are they multiplexed somehow?

For one mipi-rx-phy and one isp, only one sensor is active at a time(selected by enabled media-link).
For example, a tablet with a front sensor and a rear sensor.

Quoted 283 lines
Quoted 283 lines

3) Same as for the previous patch: some more comments would be welcome.

Quoted 280 lines · Jacob Chen

From: Jacob Chen <[email protected]>

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

The phy driver is kind of independent compare to the other parts, but i'd like to keep it in rkisp1 driver, unless people want to generalize it

---
 drivers/media/platform/rockchip/isp1/Makefile      |   1 +
 .../media/platform/rockchip/isp1/mipi_dphy_sy.c    | 805 +++++++++++++++++++++
 2 files changed, 806 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
drivers/media/platform/rockchip/isp1/Makefile +1 -0
index 8f52f959398e..18af64853734 100644
@@ -4,4 +4,5 @@ video_rkisp1-objs       +=   rkisp1.o \
                             regs.o \
                             isp_stats.o \
                             isp_params.o \
+                            mipi_dphy_sy.o \
                             capture.o
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +248 -0
new file mode 100644
index 000000000000..56deff2be6fd
@@ -0,0 +1,805 @@
+/*
+ * 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 <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
+#include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-fwnode.h>
+#include <media/v4l2-subdev.h>
+
+#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,
+    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] = PHY_REG(RK3399_GRF_SOC_CON23, 4, 4),
+    [GRF_DPHY_TX1RX1_FORCETXSTOPMODE] = PHY_REG(RK3399_GRF_SOC_CON23, 4, 8),
+    [GRF_DPHY_TX1RX1_TURNDISABLE] = PHY_REG(RK3399_GRF_SOC_CON23, 4, 12),
+    [GRF_DPHY_TX1RX1_TURNREQUEST] = PHY_REG(RK3399_GRF_SOC_CON24, 4, 0),
+    [GRF_DPHY_RX1_SRC_SEL] = PHY_REG(RK3399_GRF_SOC_CON24, 1, 4),
+    [GRF_DPHY_TX1RX1_BASEDIR] = PHY_REG(RK3399_GRF_SOC_CON24, 1, 5),
+    [GRF_DPHY_TX1RX1_ENABLECLK] = PHY_REG(RK3399_GRF_SOC_CON24, 1, 6),
+    [GRF_DPHY_TX1RX1_MASTERSLAVEZ] = PHY_REG(RK3399_GRF_SOC_CON24, 1, 7),
+    [GRF_DPHY_RX0_TESTDIN] = PHY_REG(RK3399_GRF_SOC_CON25, 8, 0),
+    [GRF_DPHY_RX0_TESTEN] = PHY_REG(RK3399_GRF_SOC_CON25, 1, 8),
+    [GRF_DPHY_RX0_TESTCLK] = PHY_REG(RK3399_GRF_SOC_CON25, 1, 9),
+    [GRF_DPHY_RX0_TESTCLR] = PHY_REG(RK3399_GRF_SOC_CON25, 1, 10),
+    [GRF_DPHY_RX0_TESTDOUT] = PHY_REG(RK3399_GRF_SOC_STATUS1, 8, 0),
+};
+
+static const struct dphy_reg rk3288_grf_dphy_regs[] = {
+    [GRF_CON_DISABLE_ISP] = PHY_REG(RK3288_GRF_SOC_CON6, 1, 0),
+    [GRF_CON_ISP_DPHY_SEL] = PHY_REG(RK3288_GRF_SOC_CON6, 1, 1),
+    [GRF_DSI_CSI_TESTBUS_SEL] = PHY_REG(RK3288_GRF_SOC_CON6, 1, 14),
+    [GRF_DPHY_TX0_TURNDISABLE] = PHY_REG(RK3288_GRF_SOC_CON8, 4, 0),
+    [GRF_DPHY_TX0_FORCERXMODE] = PHY_REG(RK3288_GRF_SOC_CON8, 4, 4),
+    [GRF_DPHY_TX0_FORCETXSTOPMODE] = PHY_REG(RK3288_GRF_SOC_CON8, 4, 8),
+    [GRF_DPHY_TX1RX1_TURNDISABLE] = PHY_REG(RK3288_GRF_SOC_CON9, 4, 0),
+    [GRF_DPHY_TX1RX1_FORCERXMODE] = PHY_REG(RK3288_GRF_SOC_CON9, 4, 4),
+    [GRF_DPHY_TX1RX1_FORCETXSTOPMODE] = PHY_REG(RK3288_GRF_SOC_CON9, 4, 8),
+    [GRF_DPHY_TX1RX1_ENABLE] = PHY_REG(RK3288_GRF_SOC_CON9, 4, 12),
+    [GRF_DPHY_RX0_TURNDISABLE] = PHY_REG(RK3288_GRF_SOC_CON10, 4, 0),
+    [GRF_DPHY_RX0_FORCERXMODE] = PHY_REG(RK3288_GRF_SOC_CON10, 4, 4),
+    [GRF_DPHY_RX0_FORCETXSTOPMODE] = PHY_REG(RK3288_GRF_SOC_CON10, 4, 8),
+    [GRF_DPHY_RX0_ENABLE] = PHY_REG(RK3288_GRF_SOC_CON10, 4, 12),
+    [GRF_DPHY_RX0_TESTCLR] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 0),
+    [GRF_DPHY_RX0_TESTCLK] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 1),
+    [GRF_DPHY_RX0_TESTEN] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 2),
+    [GRF_DPHY_RX0_TESTDIN] = PHY_REG(RK3288_GRF_SOC_CON14, 8, 3),
+    [GRF_DPHY_TX1RX1_ENABLECLK] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 12),
+    [GRF_DPHY_RX1_SRC_SEL] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 13),
+    [GRF_DPHY_TX1RX1_MASTERSLAVEZ] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 14),
+    [GRF_DPHY_TX1RX1_BASEDIR] = PHY_REG(RK3288_GRF_SOC_CON14, 1, 15),
+    [GRF_DPHY_RX0_TURNREQUEST] = PHY_REG(RK3288_GRF_SOC_CON15, 4, 0),
+    [GRF_DPHY_TX1RX1_TURNREQUEST] = PHY_REG(RK3288_GRF_SOC_CON15, 4, 4),
+    [GRF_DPHY_TX0_TURNREQUEST] = PHY_REG(RK3288_GRF_SOC_CON15, 3, 8),
+    [GRF_DVP_V18SEL] = PHY_REG(RK3288_GRF_IO_VSEL, 1, 1),
+    [GRF_DPHY_RX0_TESTDOUT] = PHY_REG(RK3288_GRF_SOC_STATUS21, 8, 0),
+};
+
+struct hsfreq_range {
+    u32 range_h;
+    u8 cfg_bit;
+};
+
+struct dphy_drv_data {
+    const char * const *clks;
+    int num_clks;
+    const struct hsfreq_range *hsfreq_ranges;
+    int num_hsfreq_ranges;
+    const struct dphy_reg *regs;
+};
+
+struct sensor_async_subdev {
+    struct v4l2_async_subdev asd;
+    struct v4l2_mbus_config mbus;
+    int lanes;
+};
+
+#define MAX_DPHY_CLK                8
+#define MAX_DPHY_SENSORS    2
+
+struct mipidphy_sensor {
+    struct v4l2_subdev *sd;
+    struct v4l2_mbus_config mbus;
+    int lanes;
+};
+
+struct mipidphy_priv {
+    struct device *dev;
+    struct regmap *regmap_grf;
+    const struct dphy_reg *grf_regs;
+    struct clk *clks[MAX_DPHY_CLK];
+    const struct dphy_drv_data *drv_data;
+    u64 data_rate_mbps;
+    struct v4l2_async_notifier notifier;
+    struct v4l2_subdev sd;
+    struct media_pad pads[MIPI_DPHY_SY_PADS_NUM];
+    struct mipidphy_sensor sensors[MAX_DPHY_SENSORS];
+    int num_sensors;
+    bool is_streaming;
+};
+
+static inline struct mipidphy_priv *to_dphy_priv(struct v4l2_subdev *subdev)
+{
+    return container_of(subdev, struct mipidphy_priv, sd);
+}
+
+static inline void write_reg(struct mipidphy_priv *priv, int index, u8 value)
+{
+    const struct dphy_reg *reg = &priv->grf_regs[index];
+    unsigned int val = HIWORD_UPDATE(value, reg->mask, reg->shift);
+
+    WARN_ON(!reg->offset);
+    regmap_write(priv->regmap_grf, reg->offset, val);
+}
+
+static void mipidphy_wr_reg(struct mipidphy_priv *priv,
+                        u8 test_code, u8 test_data)
+{
+    /*
+     * With the falling edge on TESTCLK, the TESTDIN[7:0] signal content
+     * is latched internally as the current test code. Test data is
+     * programmed internally by rising edge on TESTCLK.
+     */
+    write_reg(priv, GRF_DPHY_RX0_TESTCLK, 1);
Quoted 8 lines
Quoted 8 lines

drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c line 256

Quoted 8 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +8 -0
+    write_reg(priv, GRF_DPHY_RX0_TESTDIN, test_code);
+    write_reg(priv, GRF_DPHY_RX0_TESTEN, 1);
+    write_reg(priv, GRF_DPHY_RX0_TESTCLK, 0);
+    write_reg(priv, GRF_DPHY_RX0_TESTEN, 0);
+    write_reg(priv, GRF_DPHY_RX0_TESTDIN, test_data);
+    write_reg(priv, GRF_DPHY_RX0_TESTCLK, 1);
+}
+

It's rockchip spefic, since MIPI-DPHY-RX0 in rockchip SOC write phy reg through grf.

The other phy, like MIPI-DPHY-TXRX0 in rockchip SOC, write phy reg like this:
https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/rockchip/dw-mipi-dsi.c#L388

Quoted 107 lines
Quoted 107 lines
Quoted 107 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +107 -0
+static struct v4l2_subdev *get_remote_sensor(struct v4l2_subdev *sd)
+{
+    struct media_pad *local, *remote;
+    struct media_entity *sensor_me;
+
+    local = &sd->entity.pads[MIPI_DPHY_SY_PAD_SINK];
+    remote = media_entity_remote_pad(local);
+    if (!remote) {
+            v4l2_warn(sd, "No link between dphy and sensor\n");
+            return NULL;
+    }
+
+    sensor_me = media_entity_remote_pad(local)->entity;
+    return media_entity_to_v4l2_subdev(sensor_me);
+}
+
+static struct mipidphy_sensor *sd_to_sensor(struct mipidphy_priv *priv,
+                                        struct v4l2_subdev *sd)
+{
+    int i;
+
+    for (i = 0; i < priv->num_sensors; ++i)
+            if (priv->sensors[i].sd == sd)
+                    return &priv->sensors[i];
+
+    return NULL;
+}
+
+static int mipidphy_get_sensor_data_rate(struct v4l2_subdev *sd)
+{
+    struct mipidphy_priv *priv = to_dphy_priv(sd);
+    struct v4l2_subdev *sensor_sd = get_remote_sensor(sd);
+    struct v4l2_ctrl *link_freq;
+    struct v4l2_querymenu qm = { .id = V4L2_CID_LINK_FREQ, };
+    int ret;
+
+    link_freq = v4l2_ctrl_find(sensor_sd->ctrl_handler, V4L2_CID_LINK_FREQ);
+    if (!link_freq) {
+            v4l2_warn(sd, "No pixel rate control in subdev\n");
+            return -EPIPE;
+    }
+
+    qm.index = v4l2_ctrl_g_ctrl(link_freq);
+    ret = v4l2_querymenu(sensor_sd->ctrl_handler, &qm);
+    if (ret < 0) {
+            v4l2_err(sd, "Failed to get menu item\n");
+            return ret;
+    }
+
+    if (!qm.value) {
+            v4l2_err(sd, "Invalid link_freq\n");
+            return -EINVAL;
+    }
+    priv->data_rate_mbps = qm.value * 2;
+    do_div(priv->data_rate_mbps, 1000 * 1000);
+
+    return 0;
+}
+
+static int mipidphy_s_stream_start(struct v4l2_subdev *sd)
+{
+    struct mipidphy_priv *priv = to_dphy_priv(sd);
+    const struct dphy_drv_data *drv_data = priv->drv_data;
+    const struct hsfreq_range *hsfreq_ranges = drv_data->hsfreq_ranges;
+    int num_hsfreq_ranges = drv_data->num_hsfreq_ranges;
+    struct v4l2_subdev *sensor_sd = get_remote_sensor(sd);
+    struct mipidphy_sensor *sensor = sd_to_sensor(priv, sensor_sd);
+    int i, ret, hsfreq = 0;
+
+    if (priv->is_streaming)
+            return 0;
+
+    ret = mipidphy_get_sensor_data_rate(sd);
+    if (ret < 0)
+            return ret;
+
+    for (i = 0; i < num_hsfreq_ranges; i++) {
+            if (hsfreq_ranges[i].range_h >= priv->data_rate_mbps) {
+                    hsfreq = hsfreq_ranges[i].cfg_bit;
+                    break;
+            }
+    }
+
+    write_reg(priv, GRF_DPHY_RX0_FORCERXMODE, 0);
+    write_reg(priv, GRF_DPHY_RX0_FORCETXSTOPMODE, 0);
+    /* Disable lan turn around, which is ignored in receive mode */
+    write_reg(priv, GRF_DPHY_RX0_TURNREQUEST, 0);
+    write_reg(priv, GRF_DPHY_RX0_TURNDISABLE, 0xf);
+
+    write_reg(priv, GRF_DPHY_RX0_ENABLE, GENMASK(sensor->lanes - 1, 0));
+
+    /* dphy start */
+    write_reg(priv, GRF_DPHY_RX0_TESTCLK, 1);
+    write_reg(priv, GRF_DPHY_RX0_TESTCLR, 1);
+    usleep_range(100, 150);
+    write_reg(priv, GRF_DPHY_RX0_TESTCLR, 0);
+    usleep_range(100, 150);
+
+    /* set clock lane */
+    /* HS hsfreq_range & lane 0  settle bypass */
+    mipidphy_wr_reg(priv, CLOCK_LANE_HS_RX_CONTROL, 0);
+    /* HS RX Control of lane0 */
+    mipidphy_wr_reg(priv, LANE0_HS_RX_CONTROL, hsfreq << 1);
+    /* HS RX Control of lane1 */
+    mipidphy_wr_reg(priv, LANE1_HS_RX_CONTROL, 0);
+    /* HS RX Control of lane2 */
+    mipidphy_wr_reg(priv, LANE2_HS_RX_CONTROL, 0);
Quoted 8 lines
Quoted 8 lines

drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c line 371

Quoted 8 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +8 -0
+    /* HS RX Control of lane3 */
+    mipidphy_wr_reg(priv, LANE3_HS_RX_CONTROL, 0);
+    /* HS RX Data Lanes Settle State Time Control */
+    mipidphy_wr_reg(priv, HS_RX_DATA_LANES_THS_SETTLE__CONTROL, 0x04);
+
+    /* Normal operation */
+    mipidphy_wr_reg(priv, 0x0, 0);
+

Those phy reg operations might be synopsys-generic.

Quoted 162 lines
Quoted 162 lines
Quoted 97 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +97 -0
+    priv->is_streaming = true;
+
+    return 0;
+}
+
+static int mipidphy_s_stream_stop(struct v4l2_subdev *sd)
+{
+    struct mipidphy_priv *priv = to_dphy_priv(sd);
+
+    if (!priv->is_streaming)
+            return 0;
+
+    priv->is_streaming = false;
+
+    return 0;
+}
+
+static int mipidphy_s_stream(struct v4l2_subdev *sd, int on)
+{
+    if (on)
+            return mipidphy_s_stream_start(sd);
+    else
+            return mipidphy_s_stream_stop(sd);
+}
+
+static int mipidphy_g_mbus_config(struct v4l2_subdev *sd,
+                              struct v4l2_mbus_config *config)
+{
+    struct mipidphy_priv *priv = to_dphy_priv(sd);
+    struct v4l2_subdev *sensor_sd = get_remote_sensor(sd);
+    struct mipidphy_sensor *sensor = sd_to_sensor(priv, sensor_sd);
+
+    *config = sensor->mbus;
+
+    return 0;
+}
+
+static int mipidphy_s_power(struct v4l2_subdev *sd, int on)
+{
+    struct mipidphy_priv *priv = to_dphy_priv(sd);
+
+    if (on)
+            return pm_runtime_get_sync(priv->dev);
+    else
+            return pm_runtime_put(priv->dev);
+}
+
+static int mipidphy_runtime_suspend(struct device *dev)
+{
+    struct media_entity *me = dev_get_drvdata(dev);
+    struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(me);
+    struct mipidphy_priv *priv = to_dphy_priv(sd);
+    int i, num_clks;
+
+    num_clks = priv->drv_data->num_clks;
+    for (i = num_clks - 1; i >= 0; i--)
+            clk_disable_unprepare(priv->clks[i]);
+
+    return 0;
+}
+
+static int mipidphy_runtime_resume(struct device *dev)
+{
+    struct media_entity *me = dev_get_drvdata(dev);
+    struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(me);
+    struct mipidphy_priv *priv = to_dphy_priv(sd);
+    int i, num_clks, ret;
+
+    num_clks = priv->drv_data->num_clks;
+    for (i = 0; i < num_clks; i++) {
+            ret = clk_prepare_enable(priv->clks[i]);
+            if (ret < 0)
+                    goto err;
+    }
+
+    return 0;
+err:
+    while (--i >= 0)
+            clk_disable_unprepare(priv->clks[i]);
+    return ret;
+}
+
+/* dphy accepts all fmt/size from sensor */
+static int mipidphy_get_set_fmt(struct v4l2_subdev *sd,
+                            struct v4l2_subdev_pad_config *cfg,
+                            struct v4l2_subdev_format *fmt)
+{
+    struct v4l2_subdev *sensor = get_remote_sensor(sd);
+
+    /*
+     * Do not allow format changes and just relay whatever
+     * set currently in the sensor.
+     */
+    return v4l2_subdev_call(sensor, pad, get_fmt, NULL, fmt);
+}
+
+static const struct v4l2_subdev_pad_ops mipidphy_subdev_pad_ops = {

drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c line 478

Quoted 10 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +10 -0
+    .set_fmt = mipidphy_get_set_fmt,
+    .get_fmt = mipidphy_get_set_fmt,
+};
+
+static const struct v4l2_subdev_core_ops mipidphy_core_ops = {
+    .s_power = mipidphy_s_power,
+};
+
+static const struct v4l2_subdev_video_ops mipidphy_video_ops = {
+    .g_mbus_config = mipidphy_g_mbus_config,

Why do you need this?

Quoted 53 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +53 -0
+    .s_stream = mipidphy_s_stream,
+};
+
+static const struct v4l2_subdev_ops mipidphy_subdev_ops = {
+    .core = &mipidphy_core_ops,
+    .video = &mipidphy_video_ops,
+    .pad = &mipidphy_subdev_pad_ops,
+};
+
+/* These tables must be sorted by .range_h ascending. */
+static const struct hsfreq_range rk3288_mipidphy_hsfreq_ranges[] = {
+    {  89, 0x00}, {  99, 0x10}, { 109, 0x20}, { 129, 0x01},
+    { 139, 0x11}, { 149, 0x21}, { 169, 0x02}, { 179, 0x12},
+    { 199, 0x22}, { 219, 0x03}, { 239, 0x13}, { 249, 0x23},
+    { 269, 0x04}, { 299, 0x14}, { 329, 0x05}, { 359, 0x15},
+    { 399, 0x25}, { 449, 0x06}, { 499, 0x16}, { 549, 0x07},
+    { 599, 0x17}, { 649, 0x08}, { 699, 0x18}, { 749, 0x09},
+    { 799, 0x19}, { 849, 0x29}, { 899, 0x39}, { 949, 0x0a},
+    { 999, 0x1a}
+};
+
+static const struct hsfreq_range rk3399_mipidphy_hsfreq_ranges[] = {
+    {  89, 0x00}, {  99, 0x10}, { 109, 0x20}, { 129, 0x01},
+    { 139, 0x11}, { 149, 0x21}, { 169, 0x02}, { 179, 0x12},
+    { 199, 0x22}, { 219, 0x03}, { 239, 0x13}, { 249, 0x23},
+    { 269, 0x04}, { 299, 0x14}, { 329, 0x05}, { 359, 0x15},
+    { 399, 0x25}, { 449, 0x06}, { 499, 0x16}, { 549, 0x07},
+    { 599, 0x17}, { 649, 0x08}, { 699, 0x18}, { 749, 0x09},
+    { 799, 0x19}, { 849, 0x29}, { 899, 0x39}, { 949, 0x0a},
+    { 999, 0x1a}, {1049, 0x2a}, {1099, 0x3a}, {1149, 0x0b},
+    {1199, 0x1b}, {1249, 0x2b}, {1299, 0x3b}, {1349, 0x0c},
+    {1399, 0x1c}, {1449, 0x2c}, {1500, 0x3c}
+};
+
+static const char * const rk3399_mipidphy_clks[] = {
+    "dphy-ref",
+    "dphy-cfg",
+    "grf",
+};
+
+static const char * const rk3288_mipidphy_clks[] = {
+    "dphy-ref",
+    "pclk",
+};
+
+static const struct dphy_drv_data rk3288_mipidphy_drv_data = {
+    .clks = rk3288_mipidphy_clks,
+    .num_clks = ARRAY_SIZE(rk3288_mipidphy_clks),
+    .hsfreq_ranges = rk3288_mipidphy_hsfreq_ranges,
+    .num_hsfreq_ranges = ARRAY_SIZE(rk3288_mipidphy_hsfreq_ranges),
+    .regs = rk3288_grf_dphy_regs,
+};
+
Quoted 8 lines
Quoted 8 lines

drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c line 539

Quoted 8 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +8 -0
+static const struct dphy_drv_data rk3399_mipidphy_drv_data = {
+    .clks = rk3399_mipidphy_clks,
+    .num_clks = ARRAY_SIZE(rk3399_mipidphy_clks),
+    .hsfreq_ranges = rk3399_mipidphy_hsfreq_ranges,
+    .num_hsfreq_ranges = ARRAY_SIZE(rk3399_mipidphy_hsfreq_ranges),
+    .regs = rk3399_grf_dphy_regs,
+};
+

clocks are rockchip-generic.

Quoted 170 lines
Quoted 170 lines
Quoted 170 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +170 -0
+static const struct of_device_id rockchip_mipidphy_match_id[] = {
+    {
+            .compatible = "rockchip,rk3399-mipi-dphy",
+            .data = &rk3399_mipidphy_drv_data,
+    },
+    {
+            .compatible = "rockchip,rk3288-mipi-dphy",
+            .data = &rk3288_mipidphy_drv_data,
+    },
+    {}
+};
+MODULE_DEVICE_TABLE(of, rockchip_mipidphy_match_id);
+
+/* The .bound() notifier callback when a match is found */
+static int
+rockchip_mipidphy_notifier_bound(struct v4l2_async_notifier *notifier,
+                             struct v4l2_subdev *sd,
+                             struct v4l2_async_subdev *asd)
+{
+    struct mipidphy_priv *priv = container_of(notifier,
+                                              struct mipidphy_priv,
+                                              notifier);
+    struct sensor_async_subdev *s_asd = container_of(asd,
+                                    struct sensor_async_subdev, asd);
+    struct mipidphy_sensor *sensor;
+
+    if (priv->num_sensors == ARRAY_SIZE(priv->sensors))
+            return -EBUSY;
+
+    sensor = &priv->sensors[priv->num_sensors++];
+    sensor->lanes = s_asd->lanes;
+    sensor->mbus = s_asd->mbus;
+    sensor->sd = sd;
+
+    return 0;
+}
+
+/* The .unbind callback */
+static void
+rockchip_mipidphy_notifier_unbind(struct v4l2_async_notifier *notifier,
+                              struct v4l2_subdev *sd,
+                              struct v4l2_async_subdev *asd)
+{
+    struct mipidphy_priv *priv = container_of(notifier,
+                                              struct mipidphy_priv,
+                                              notifier);
+    struct mipidphy_sensor *sensor = sd_to_sensor(priv, sd);
+
+    sensor->sd = NULL;
+}
+
+/* .complete() is called after all subdevices have been located */
+static int
+rockchip_mipidphy_notifier_complete(struct v4l2_async_notifier *notifier)
+{
+    struct mipidphy_priv *priv = container_of(notifier,
+                                              struct mipidphy_priv,
+                                              notifier);
+    unsigned int pad;
+    int ret;
+    int i;
+
+    for (i = 0; i < priv->num_sensors; ++i) {
+            struct mipidphy_sensor *sensor = &priv->sensors[i];
+
+            for (pad = 0; pad < sensor->sd->entity.num_pads; pad++)
+                    if (sensor->sd->entity.pads[pad].flags
+                                            & MEDIA_PAD_FL_SOURCE)
+                            break;
+
+            if (pad == sensor->sd->entity.num_pads) {
+                    dev_err(priv->dev,
+                            "failed to find src pad for %s\n",
+                            sensor->sd->name);
+
+                    return -ENXIO;
+            }
+
+            ret = media_create_pad_link(
+                            &sensor->sd->entity, pad,
+                            &priv->sd.entity, MIPI_DPHY_SY_PAD_SINK,
+                            i ? 0 : MEDIA_LNK_FL_ENABLED);
+            if (ret) {
+                    dev_err(priv->dev,
+                            "failed to create link for %s\n",
+                            sensor->sd->name);
+                    return ret;
+            }
+    }
+
+    return 0;
+}
+
+static const
+struct v4l2_async_notifier_operationsrockchip_mipidphy_async_ops = {
+    .bound = rockchip_mipidphy_notifier_bound,
+    .unbind = rockchip_mipidphy_notifier_unbind,
+    .complete = rockchip_mipidphy_notifier_complete,
+};
+
+static int rockchip_mipidphy_fwnode_parse(struct device *dev,
+                         struct v4l2_fwnode_endpoint *vep,
+                         struct v4l2_async_subdev *asd)
+{
+    struct sensor_async_subdev *s_asd =
+                    container_of(asd, struct sensor_async_subdev, asd);
+    struct v4l2_mbus_config *config = &s_asd->mbus;
+
+    if (vep->bus_type != V4L2_MBUS_CSI2) {
+            dev_err(dev, "Only CSI2 bus type is currently supported\n");
+            return -EINVAL;
+    }
+
+    if (vep->base.port != 0) {
+            dev_err(dev, "The PHY has only port 0\n");
+            return -EINVAL;
+    }
+
+    config->type = V4L2_MBUS_CSI2;
+    config->flags = vep->bus.mipi_csi2.flags;
+    s_asd->lanes = vep->bus.mipi_csi2.num_data_lanes;
+
+    switch (vep->bus.mipi_csi2.num_data_lanes) {
+    case 1:
+            config->flags |= V4L2_MBUS_CSI2_1_LANE;
+            break;
+    case 2:
+            config->flags |= V4L2_MBUS_CSI2_2_LANE;
+            break;
+    case 3:
+            config->flags |= V4L2_MBUS_CSI2_3_LANE;
+            break;
+    case 4:
+            config->flags |= V4L2_MBUS_CSI2_4_LANE;
+            break;
+    default:
+            return -EINVAL;
+    }
+
+    return 0;
+}
+
+static int rockchip_mipidphy_media_init(struct mipidphy_priv *priv)
+{
+    int ret;
+
+    priv->pads[MIPI_DPHY_SY_PAD_SOURCE].flags =
+            MEDIA_PAD_FL_SOURCE | MEDIA_PAD_FL_MUST_CONNECT;
+    priv->pads[MIPI_DPHY_SY_PAD_SINK].flags =
+            MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
+
+    ret = media_entity_pads_init(&priv->sd.entity,
+                             MIPI_DPHY_SY_PADS_NUM, priv->pads);
+    if (ret < 0)
+            return ret;
+
+    ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
+            priv->dev, &priv->notifier,
+            sizeof(struct sensor_async_subdev), 0,
+            rockchip_mipidphy_fwnode_parse);
+    if (ret < 0)
+            return ret;
+
+    if (!priv->notifier.num_subdevs)
+            return -ENODEV; /* no endpoint */
+
+    priv->sd.subdev_notifier = &priv->notifier;
+    priv->notifier.ops = &rockchip_mipidphy_async_ops;
+    ret = v4l2_async_subdev_notifier_register(&priv->sd, &priv->notifier);
+    if (ret) {
Quoted 8 lines
Quoted 8 lines

drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c line 717

Quoted 8 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +8 -0
+            dev_err(priv->dev,
+                    "failed to register async notifier : %d\n", ret);
+            v4l2_async_notifier_cleanup(&priv->notifier);
+            return ret;
+    }
+
+    return v4l2_async_register_subdev(&priv->sd);
+}

Those code are used to pass sensor info from mipi-phy driver to isp driver. I'm not sure if they will be helpful to the other platform.

Quoted 93 lines
Quoted 92 lines
Quoted 79 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +78 -0
+
+static int rockchip_mipidphy_probe(struct platform_device *pdev)
+{
+    struct device *dev = &pdev->dev;
+    struct v4l2_subdev *sd;
+    struct mipidphy_priv *priv;
+    struct regmap *grf;
+    const struct of_device_id *of_id;
+    const struct dphy_drv_data *drv_data;
+    int i, ret;
+
+    priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+    if (!priv)
+            return -ENOMEM;
+    priv->dev = dev;
+
+    of_id = of_match_device(rockchip_mipidphy_match_id, dev);
+    if (!of_id)
+            return -EINVAL;
+
+    grf = syscon_node_to_regmap(dev->parent->of_node);
+    if (IS_ERR(grf)) {
+            dev_err(dev, "Can't find GRF syscon\n");
+            return -ENODEV;
+    }
+    priv->regmap_grf = grf;
+
+    drv_data = of_id->data;
+    for (i = 0; i < drv_data->num_clks; i++) {
+            priv->clks[i] = devm_clk_get(dev, drv_data->clks[i]);
+
+            if (IS_ERR(priv->clks[i])) {
+                    dev_err(dev, "Failed to get %s\n", drv_data->clks[i]);
+                    return PTR_ERR(priv->clks[i]);
+            }
+    }
+
+    priv->grf_regs = drv_data->regs;
+    priv->drv_data = drv_data;
+
+    sd = &priv->sd;
+    v4l2_subdev_init(sd, &mipidphy_subdev_ops);
+    sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+    snprintf(sd->name, sizeof(sd->name), "rockchip-sy-mipi-dphy");
+    sd->dev = dev;
+
+    platform_set_drvdata(pdev, &sd->entity);
+
+    ret = rockchip_mipidphy_media_init(priv);
+    if (ret < 0)
+            return ret;
+
+    pm_runtime_enable(&pdev->dev);
+
+    return 0;
+}
+
+static int rockchip_mipidphy_remove(struct platform_device *pdev)
+{
+    struct media_entity *me = platform_get_drvdata(pdev);
+    struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(me);
+
+    media_entity_cleanup(&sd->entity);
+
+    pm_runtime_disable(&pdev->dev);
+
+    return 0;
+}
+
+static const struct dev_pm_ops rockchip_mipidphy_pm_ops = {
+    SET_RUNTIME_PM_OPS(mipidphy_runtime_suspend,
+                       mipidphy_runtime_resume, NULL)
+};
+
+static struct platform_driver rockchip_isp_mipidphy_driver = {
+    .probe = rockchip_mipidphy_probe,
+    .remove = rockchip_mipidphy_remove,
+    .driver = {

drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c line 805

Quoted 10 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +10 -0
+                    .name = "rockchip-sy-mipi-dphy",
+                    .pm = &rockchip_mipidphy_pm_ops,
+                    .of_match_table = rockchip_mipidphy_match_id,
+    },
+};
+
+module_platform_driver(rockchip_isp_mipidphy_driver);
+MODULE_AUTHOR("Rockchip Camera/ISP team");
+MODULE_DESCRIPTION("Rockchip MIPI DPHY driver");
+MODULE_LICENSE("Dual BSD/GPL");

Regards,

Hans

author
#16 lore raw

PATCH v2 5/11 dt-bindings: Document the Rockchip ISP1 bindings

In reply to Jacob Chen

From: Jacob Chen <[email protected]>

Add DT bindings documentation for Rockchip ISP1

---
 .../devicetree/bindings/media/rockchip-isp1.txt    | 61 ++++++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt
Documentation/devicetree/bindings/media/rockchip-isp1.txt new file +61 -0
new file mode 100644
index 000000000000..5e5b72edcf81
@@ -0,0 +1,61 @@
+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.
+
+Currently device tree nodes for the Rockchip ISP1 driver includes:
+MIPI D-PHY, ISP.
+
+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.
+
+Example:
+SoC-specific DT entry:
+	isp0: isp0 at ff910000 {
+		compatible = "rockchip,rk3399-cif-isp";
+		reg = <0x0 0xff910000 0x0 0x4000>;
+		interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL_HIGH 0>;
+		clocks = <&cru SCLK_ISP0>,
+			 <&cru ACLK_ISP0>, <&cru ACLK_ISP0_WRAPPER>,
+			 <&cru HCLK_ISP0>, <&cru HCLK_ISP0_WRAPPER>;
+		clock-names = "clk_isp",
+			      "aclk_isp", "aclk_isp_wrap",
+			      "hclk_isp", "hclk_isp_wrap";
+		power-domains = <&power RK3399_PD_ISP0>;
+		iommus = <&isp0_mmu>;
+		status = "disabled";
+	};
+
+Board-specific:
+	isp0: isp0 at ff910000 {
+		port {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			/* mipi */
+			isp0_mipi_in: endpoint at 0 {
+				reg = <0>;
+				remote-endpoint = <&dphy_rx0_out>;
+			};
+
+			/* parallel */
+			isp0_parallel_in: endpoint at 1 {
+				reg = <1>;
+				remote-endpoint = <&ov5640_out>;
+			};
+		};
+	};
+
+The MIPI-DPHY device binding is defined in rockchip-mipi-dphy.txt.
Signature · 1 line
2.15.0
maintainer
#17 lore raw

Re: [PATCH v2 05/11] dt-bindings: Document the Rockchip ISP1 bindings

Quoted 16 lines · Jacob Chen

From: Jacob Chen <[email protected]>

Add DT bindings documentation for Rockchip ISP1

---
 .../devicetree/bindings/media/rockchip-isp1.txt    | 61 ++++++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt
Documentation/devicetree/bindings/media/rockchip-isp1.txt new file +0 -0
new file mode 100644
index 000000000000..5e5b72edcf81

Documentation/devicetree/bindings/media/rockchip-isp1.txt line 7

Quoted 7 lines
Documentation/devicetree/bindings/media/rockchip-isp1.txt new file +7 -0
@@ -0,0 +1,61 @@
+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.
+
+Currently device tree nodes for the Rockchip ISP1 driver includes:

Bindings describe the h/w, not drivers.

Quoted 5 lines
Documentation/devicetree/bindings/media/rockchip-isp1.txt new file +5 -0
+MIPI D-PHY, ISP.
+
+Required properties:
+  - compatible: value should be one of the following
+      "rockchip,rk3288-cif-isp";

Documentation/devicetree/bindings/media/rockchip-isp1.txt line 22

Quoted 10 lines
Documentation/devicetree/bindings/media/rockchip-isp1.txt new file +10 -0
+      "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.

You need to enumerate the endpoints (mipi and parallel), too.

Quoted 9 lines
Documentation/devicetree/bindings/media/rockchip-isp1.txt new file +9 -0
+
+Example:
+SoC-specific DT entry:
+	isp0: isp0 at ff910000 {
+		compatible = "rockchip,rk3399-cif-isp";
+		reg = <0x0 0xff910000 0x0 0x4000>;
+		interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL_HIGH 0>;
+		clocks = <&cru SCLK_ISP0>,
+			 <&cru ACLK_ISP0>, <&cru ACLK_ISP0_WRAPPER>,

Documentation/devicetree/bindings/media/rockchip-isp1.txt line 41

Quoted 10 lines
Documentation/devicetree/bindings/media/rockchip-isp1.txt new file +10 -0
+			 <&cru HCLK_ISP0>, <&cru HCLK_ISP0_WRAPPER>;
+		clock-names = "clk_isp",
+			      "aclk_isp", "aclk_isp_wrap",
+			      "hclk_isp", "hclk_isp_wrap";
+		power-domains = <&power RK3399_PD_ISP0>;
+		iommus = <&isp0_mmu>;
+		status = "disabled";
+	};
+
+Board-specific:

Just show the complete example. The SoC and board split is purely source level convention.

Quoted 23 lines
Documentation/devicetree/bindings/media/rockchip-isp1.txt new file +20 -0
+	isp0: isp0 at ff910000 {
+		port {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			/* mipi */
+			isp0_mipi_in: endpoint at 0 {
+				reg = <0>;
+				remote-endpoint = <&dphy_rx0_out>;
+			};
+
+			/* parallel */
+			isp0_parallel_in: endpoint at 1 {
+				reg = <1>;
+				remote-endpoint = <&ov5640_out>;
+			};
+		};
+	};
+
+The MIPI-DPHY device binding is defined in rockchip-mipi-dphy.txt.
Signature · 1 line
2.15.0
author
#18 lore raw

PATCH v2 6/11 dt-bindings: Document the Rockchip MIPI RX D-PHY bindings

In reply to Jacob Chen

Add DT bindings documentation for Rockchip MIPI D-PHY RX

---
 .../bindings/media/rockchip-mipi-dphy.txt          | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +77 -0
new file mode 100644
index 000000000000..b5773b67c250
@@ -0,0 +1,77 @@
+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;
+
+
+Example:
+
+/* SoC properties */
+
+    mipi_dphy_rx0: mipi-dphy-rx0 {
+        compatible = "rockchip,rk3399-mipi-dphy";
+        clocks = <&cru SCLK_MIPIDPHY_REF>,
+            <&cru SCLK_DPHY_RX0_CFG>,
+            <&cru PCLK_VIO_GRF>;
+        clock-names = "dphy-ref", "dphy-cfg", "grf";
+        power-domains = <&power RK3399_PD_VIO>;
+        bus-width = <4>;
+    };
+
+/* Board properties */
+
+    &mipi_phy_rx0 {
+        ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            port at 0 {
+                reg = <0>;
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                mipi_in_wcam: endpoint at 0 {
+                    reg = <0>;
+                    remote-endpoint = <&wcam_out>;
+                    data-lanes = <1 2>;
+                };
+                mipi_in_ucam: endpoint at 1 {
+                    reg = <1>;
+                    remote-endpoint = <&ucam_out>;
+                    data-lanes = <1>;
+                };
+            };
+
+            port at 1 {
+                reg = <1>;
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                dphy_rx0_out: endpoint at 0 {
+                    reg = <0>;
+                    remote-endpoint = <&isp0_mipi_in>;
+                };
+            };
+        };
+    };
\ No newline at end of file
Signature · 1 line
2.15.0
maintainer
#19 lore raw

Re: [PATCH v2 06/11] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings

Quoted 7 lines · Jacob Chen

Add DT bindings documentation for Rockchip MIPI D-PHY RX

---
 .../bindings/media/rockchip-mipi-dphy.txt          | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt

Same comments apply to this one.

author
#20 lore raw

PATCH v2 7/11 ARM: dts: rockchip: add isp node for rk3288

In reply to Jacob Chen

From: Jacob Chen <[email protected]>

rk3288 have a Embedded 13M ISP

---
 arch/arm/boot/dts/rk3288.dtsi | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
arch/arm/boot/dts/rk3288.dtsi +17 -0
index f3e7f98c2724..30677a0167fe 100644
@@ -962,6 +962,23 @@
 		status = "disabled";
 	};
 
+	isp: isp at ff910000 {
+		compatible = "rockchip,rk3288-cif-isp";
+		reg = <0x0 0xff910000 0x0 0x4000>;
+		interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru SCLK_ISP>, <&cru ACLK_ISP>,
+			 <&cru HCLK_ISP>, <&cru PCLK_ISP_IN>,
+			 <&cru SCLK_ISP_JPE>;
+		clock-names = "clk_isp", "aclk_isp",
+			      "hclk_isp", "pclk_isp_in",
+			      "sclk_isp_jpe";
+		assigned-clocks = <&cru SCLK_ISP>;
+		assigned-clock-rates = <400000000>;
+		power-domains = <&power RK3288_PD_VIO>;
+		iommus = <&isp_mmu>;
+		status = "disabled";
+	};
+
 	isp_mmu: iommu at ff914000 {
 		compatible = "rockchip,iommu";
 		reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
Signature · 1 line
2.15.0
author
#21 lore raw

PATCH v2 8/11 ARM: dts: rockchip: add rx0 mipi-phy for rk3288

In reply to Jacob Chen

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

---
 arch/arm/boot/dts/rk3288.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/boot/dts/rk3288.dtsi +7 -0
index 30677a0167fe..8b7d5a9b521f 100644
@@ -864,6 +864,13 @@
 			status = "disabled";
 		};
 
+		mipi_phy_rx0: mipi-phy-rx0 {
+			compatible = "rockchip,rk3288-mipi-dphy";
+			clocks = <&cru SCLK_MIPIDSI_24M>, <&cru PCLK_MIPI_CSI>;
+			clock-names = "dphy-ref", "pclk";
+			status = "disabled";
+		};
+
 		io_domains: io-domains {
 			compatible = "rockchip,rk3288-io-voltage-domain";
 			status = "disabled";
Signature · 1 line
2.15.0
author
#22 lore raw

PATCH v2 9/11 arm64: dts: rockchip: add isp0 node for rk3399

In reply to Jacob Chen

From: Shunqian Zheng <[email protected]>

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

---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/arm64/boot/dts/rockchip/rk3399.dtsi +15 -0
index d340b58ab184..66a912fab5dd 100644
@@ -1588,6 +1588,21 @@
 		status = "disabled";
 	};
 
+	isp0: isp0 at ff910000 {
+		compatible = "rockchip,rk3399-cif-isp";
+		reg = <0x0 0xff910000 0x0 0x4000>;
+		interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL_HIGH 0>;
+		clocks = <&cru SCLK_ISP0>,
+			 <&cru ACLK_ISP0>, <&cru ACLK_ISP0_WRAPPER>,
+			 <&cru HCLK_ISP0>, <&cru HCLK_ISP0_WRAPPER>;
+		clock-names = "clk_isp",
+			      "aclk_isp", "aclk_isp_wrap",
+			      "hclk_isp", "hclk_isp_wrap";
+		power-domains = <&power RK3399_PD_ISP0>;
+		iommus = <&isp0_mmu>;
+		status = "disabled";
+	};
+
 	isp0_mmu: iommu at ff914000 {
 		compatible = "rockchip,iommu";
 		reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
Signature · 1 line
2.15.0
author
#23 lore raw

PATCH v2 10/11 arm64: dts: rockchip: add rx0 mipi-phy for rk3399

In reply to Jacob Chen

From: Shunqian Zheng <[email protected]>

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

---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/rockchip/rk3399.dtsi +11 -0
index 66a912fab5dd..a65b110afaf3 100644
@@ -1292,6 +1292,17 @@
 			status = "disabled";
 		};
 
+		mipi_dphy_rx0: mipi-dphy-rx0 {
+			compatible = "rockchip,rk3399-mipi-dphy";
+			clocks = <&cru SCLK_MIPIDPHY_REF>,
+				<&cru SCLK_DPHY_RX0_CFG>,
+				<&cru PCLK_VIO_GRF>;
+			clock-names = "dphy-ref", "dphy-cfg", "grf";
+			power-domains = <&power RK3399_PD_VIO>;
+			bus-width = <4>;
+			status = "disabled";
+		};
+
 		u2phy0: usb2-phy at e450 {
 			compatible = "rockchip,rk3399-usb2phy";
 			reg = <0xe450 0x10>;
Signature · 1 line
2.15.0
author
#24 lore raw

PATCH v2 11/11 MAINTAINERS: add entry for Rockchip ISP1 driver

In reply to Jacob Chen

From: Jacob Chen <[email protected]>

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.

---
 MAINTAINERS | 10 ++++++++++
 1 file changed, 10 insertions(+)
MAINTAINERS +10 -0
index b05bc2c5e85c..614196ed7265 100644
@@ -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 <[email protected]>
+M:	Shunqian Zheng <[email protected]>
+M:	Yichong Zhong <[email protected]>
+L:	linux-media at 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 <[email protected]>
 L:	linux-media at vger.kernel.org
Signature · 1 line
2.15.0
author
#25 lore raw
In reply to Jacob Chen

HI all,

2017-11-24 10:36 GMT+08:00 Jacob Chen <jacob-chen-fyOeoxGR3m/[email protected]>:

Quoted 117 lines

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

Kernel Branch:
https://github.com/wzyy2/linux/tree/rkisp1/drivers/media/platform/rockchip/isp1

Below are some infomations about driver/hardware:

Rockchip ISP1 have many Hardware Blocks(simplied):

MIPI --> ISP --> DCrop(Mainpath) --> RSZ(Mainpath) --> DMA(Mainpath)
DMA-Input --> --> DCrop(Selfpath) --> RSZ(Selfpath) --> DMA(Selfpath);)

(Acutally the TRM(rk3288, isp) could be found online...... which contains a more detailed block diagrams ;-P)

The funcitons of each hardware block:

Mainpath : up to 4k resolution, support raw/yuv format Selfpath : up tp 1080p, support rotate, support rgb/yuv format
RSZ: scaling
DCrop: crop
ISP: 3A, Color processing, Crop
MIPI: MIPI Camera interface

Media pipelines:

Mainpath, Selfpath <-- ISP subdev <-- MIPI <-- Sensor
3A stats <-- <-- 3A parms

Code struct:

capture.c : Mainpath, Selfpath, RSZ, DCROP : capture device. rkisp1.c : ISP : v4l2 sub-device.
isp_params.c : 3A parms : output device. isp_stats.c : 3A stats : capture device. mipi_dphy_sy.c : MIPI : sperated v4l2 sub-device.

Usage:
ChromiumOS:

    use below v4l2-ctl command to capture frames.

      v4l2-ctl --verbose -d /dev/video4 --stream-mmap=2
      --stream-to=/tmp/stream.out --stream-count=60 --stream-poll

    use below command to playback the video on your PC.

      mplayer /tmp/stream.out -loop 0 --demuxer=rawvideo
      --rawvideo=w=800:h=600:size=$((800*600*2)):format=yuy2
    or
      mplayer ./stream.out -loop 0 -demuxer rawvideo -rawvideo
      w=800:h=600:size=$((800*600*2)):format=yuy2

Linux:
use rkcamsrc gstreamer plugin(just a modified v4l2src) to preview.

gst-launch-1.0 rkcamsrc device=/dev/video0 io-mode=4 disable-3A=true videoconvert ! video/x-raw,format=NV12,width=640,height=480 ! kmssink

Jacob Chen (7):
media: rkisp1: add rockchip isp1 driver
media: rkisp1: add Rockchip MIPI Synopsys DPHY 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    |   61 +
 .../bindings/media/rockchip-mipi-dphy.txt          |   77 +
 MAINTAINERS                                        |   10 +
 arch/arm/boot/dts/rk3288.dtsi                      |   24 +
 arch/arm64/boot/dts/rockchip/rk3399.dtsi           |   26 +
 drivers/media/platform/Kconfig                     |   10 +
 drivers/media/platform/Makefile                    |    1 +
 drivers/media/platform/rockchip/isp1/Makefile      |    8 +
 drivers/media/platform/rockchip/isp1/capture.c     | 1691 ++++++++++++++++++++
 drivers/media/platform/rockchip/isp1/capture.h     |   46 +
 drivers/media/platform/rockchip/isp1/common.h      |  330 ++++
 drivers/media/platform/rockchip/isp1/dev.c         |  632 ++++++++
 drivers/media/platform/rockchip/isp1/isp_params.c  | 1556 ++++++++++++++++++
 drivers/media/platform/rockchip/isp1/isp_params.h  |   81 +
 drivers/media/platform/rockchip/isp1/isp_stats.c   |  537 +++++++
 drivers/media/platform/rockchip/isp1/isp_stats.h   |   81 +
 .../media/platform/rockchip/isp1/mipi_dphy_sy.c    |  805 ++++++++++
 drivers/media/platform/rockchip/isp1/regs.c        |  251 +++
 drivers/media/platform/rockchip/isp1/regs.h        | 1578 ++++++++++++++++++
 drivers/media/platform/rockchip/isp1/rkisp1.c      | 1230 ++++++++++++++
 drivers/media/platform/rockchip/isp1/rkisp1.h      |  130 ++
 drivers/media/v4l2-core/v4l2-ioctl.c               |    2 +
 include/uapi/linux/rkisp1-config.h                 |  554 +++++++
 include/uapi/linux/videodev2.h                     |    4 +
 24 files changed, 9725 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 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/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
Quoted 3 lines

--
2.15.0

Sorry, i forget to add a changelog.

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).

I resend it for now because i think v2 patch looks more clearly than the old one,
the v1 patch could just be superseded.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html