From patchwork Thu Dec 16 22:09:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12682841 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9D4EC4332F for ; Thu, 16 Dec 2021 22:09:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241220AbhLPWJ5 (ORCPT ); Thu, 16 Dec 2021 17:09:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241200AbhLPWJ5 (ORCPT ); Thu, 16 Dec 2021 17:09:57 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC746C061574; Thu, 16 Dec 2021 14:09:56 -0800 (PST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 04913E81; Thu, 16 Dec 2021 23:09:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1639692594; bh=cYghdh4AN8QY6h+Eugs5hQv7HOr+gZQ9M/R9C4ey45s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oelm3eT+6pKyPe3YiVRSllPWUfXp7TuNwqQ/9P0mI67aDuuKHVPwKpVaWVGZx0grH 9UH1VsuUa1wHr12QVU7S3DS67juFQHsCKu+NjoFbD4YWMOz9d4UFK66AlOkJvGPF8j rfmb/0uydDAeEK3E4DRO1RD9xGapv3MwWRzWQpc4= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Jacopo Mondi , Kieran Bingham , =?utf-8?q?Niklas_?= =?utf-8?q?S=C3=B6derlund?= , Thomas Nizan , Laurent Pinchart , devicetree@vger.kernel.org, Rob Herring Subject: [PATCH 1/3] dt-bindings: media: i2c: max9286: Add support for per-port supplies Date: Fri, 17 Dec 2021 00:09:44 +0200 Message-Id: <20211216220946.20771-2-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211216220946.20771-1-laurent.pinchart+renesas@ideasonboard.com> References: <20211216220946.20771-1-laurent.pinchart+renesas@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org From: Laurent Pinchart Power supplies for the ports can be controlled per port depending on the hardware design. Support per-port supplies in the DT bindings, mutually exclusive with the global supply. Signed-off-by: Laurent Pinchart --- .../bindings/media/i2c/maxim,max9286.yaml | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml b/Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml index 02f656e78700..33aa307e8ee5 100644 --- a/Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml +++ b/Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml @@ -39,7 +39,7 @@ properties: maxItems: 1 poc-supply: - description: Regulator providing Power over Coax to the cameras + description: Regulator providing Power over Coax to all the ports enable-gpios: description: GPIO connected to the \#PWDN pin with inverted polarity @@ -160,6 +160,10 @@ properties: additionalProperties: false +patternProperties: + "^port[0-3]-poc-supply$": + description: Regulator providing Power over Coax for a particular port + required: - compatible - reg @@ -167,6 +171,25 @@ required: - i2c-mux - gpio-controller +allOf: + - if: + required: + - poc-supply + then: + allOf: + - not: + required: + - port0-poc-supply + - not: + required: + - port1-poc-supply + - not: + required: + - port2-poc-supply + - not: + required: + - port3-poc-supply + additionalProperties: false examples: From patchwork Thu Dec 16 22:09:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12682843 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43F80C43219 for ; Thu, 16 Dec 2021 22:09:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241200AbhLPWJ5 (ORCPT ); Thu, 16 Dec 2021 17:09:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241209AbhLPWJ5 (ORCPT ); Thu, 16 Dec 2021 17:09:57 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16B54C06173E; Thu, 16 Dec 2021 14:09:57 -0800 (PST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 101731209; Thu, 16 Dec 2021 23:09:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1639692595; bh=hLx2ebGM+okJSxhT9tMuHTZ4OjNTfkXx4j7pZttIUKE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eojp+s6GwxFap4MUY9/OxkeNvEHiR/ayZjI8puA3E1TLCD1zgcjRJ1va2i2gG5S/q KEF5YZw68mDOce5QbqKNSWNyNTGW/iGHSj6LZ2TefD7X4Q7R1g2XelZac4sCcqzFnp WlgnGeMjKlOGGoyLqN0lBVvez5HTDvairtxv7eXc= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Jacopo Mondi , Kieran Bingham , =?utf-8?q?Niklas_?= =?utf-8?q?S=C3=B6derlund?= , Thomas Nizan Subject: [PATCH 2/3] media: i2c: max9286: Add support for port regulators Date: Fri, 17 Dec 2021 00:09:45 +0200 Message-Id: <20211216220946.20771-3-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211216220946.20771-1-laurent.pinchart+renesas@ideasonboard.com> References: <20211216220946.20771-1-laurent.pinchart+renesas@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org From: Thomas Nizan Allow users to use one PoC regulator per port, instead of a global regulator. The properties '^port[0-3]-poc-supply$' in the DT node are used to indicate the regulators for individual ports. Signed-off-by: Laurent Pinchart Signed-off-by: Thomas Nizan --- drivers/media/i2c/max9286.c | 112 +++++++++++++++++++++++++++++++----- 1 file changed, 98 insertions(+), 14 deletions(-) diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c index 7c663fd587bb..fa2f6a823fe6 100644 --- a/drivers/media/i2c/max9286.c +++ b/drivers/media/i2c/max9286.c @@ -136,8 +136,10 @@ #define MAX9286_SRC_PAD 4 struct max9286_source { + unsigned int index; struct v4l2_subdev *sd; struct fwnode_handle *fwnode; + struct regulator *regulator; }; struct max9286_asd { @@ -1072,6 +1074,49 @@ static int max9286_register_gpio(struct max9286_priv *priv) return ret; } +static int max9286_poc_power_on(struct max9286_priv *priv) +{ + struct max9286_source *source; + unsigned int enabled = 0; + int ret; + + /* Enable the global regulator if available. */ + if (priv->regulator) + return regulator_enable(priv->regulator); + + /* Otherwise use the per-port regulators. */ + for_each_source(priv, source) { + ret = regulator_enable(source->regulator); + if (ret < 0) + goto error; + + enabled |= BIT(source->index); + } + + return 0; + +error: + for_each_source(priv, source) { + if (enabled & BIT(source->index)) + regulator_disable(source->regulator); + } + + return ret; +} + +static void max9286_poc_power_off(struct max9286_priv *priv) +{ + struct max9286_source *source; + + if (priv->regulator) { + regulator_disable(priv->regulator); + return; + } + + for_each_source(priv, source) + regulator_disable(source->regulator); +} + static int max9286_init(struct device *dev) { struct max9286_priv *priv; @@ -1082,9 +1127,9 @@ static int max9286_init(struct device *dev) priv = i2c_get_clientdata(client); /* Enable the bus power. */ - ret = regulator_enable(priv->regulator); + ret = max9286_poc_power_on(priv); if (ret < 0) { - dev_err(&client->dev, "Unable to turn PoC on\n"); + dev_err(dev, "Unable to turn PoC on\n"); return ret; } @@ -1118,7 +1163,7 @@ static int max9286_init(struct device *dev) err_v4l2_register: max9286_v4l2_unregister(priv); err_regulator: - regulator_disable(priv->regulator); + max9286_poc_power_off(priv); return ret; } @@ -1215,6 +1260,7 @@ static int max9286_parse_dt(struct max9286_priv *priv) } source = &priv->sources[ep.port]; + source->index = ep.port; source->fwnode = fwnode_graph_get_remote_endpoint( of_fwnode_handle(node)); if (!source->fwnode) { @@ -1249,6 +1295,50 @@ static int max9286_parse_dt(struct max9286_priv *priv) return 0; } +static int max9286_get_poc_supplies(struct max9286_priv *priv) +{ + struct device *dev = &priv->client->dev; + struct max9286_source *source; + + /* + * Start by getting the global regulator. Usage of the exclusive API is + * required to receive an error in case the supply isn't specified in + * the device tree. + */ + priv->regulator = devm_regulator_get_exclusive(dev, "poc"); + if (!IS_ERR(priv->regulator)) + return 0; + + if (PTR_ERR(priv->regulator) != -ENODEV) { + if (PTR_ERR(priv->regulator) != -EPROBE_DEFER) + dev_err(dev, "Unable to get PoC regulator: %ld\n", + PTR_ERR(priv->regulator)); + return PTR_ERR(priv->regulator); + } + + /* If there's no global regulator, get per-port regulators. */ + dev_dbg(dev, + "No global PoC regulator, looking for per-port regulators\n"); + priv->regulator = NULL; + + for_each_source(priv, source) { + char name[10]; + + snprintf(name, sizeof(name), "port%u-poc", source->index); + source->regulator = devm_regulator_get_exclusive(dev, name); + if (IS_ERR(source->regulator)) { + if (PTR_ERR(source->regulator) != -EPROBE_DEFER) + dev_err(dev, + "Unable to get port %u PoC regulator: %ld\n", + source->index, + PTR_ERR(source->regulator)); + return PTR_ERR(source->regulator); + } + } + + return 0; +} + static int max9286_probe(struct i2c_client *client) { struct max9286_priv *priv; @@ -1293,17 +1383,11 @@ static int max9286_probe(struct i2c_client *client) if (ret) goto err_powerdown; - priv->regulator = devm_regulator_get(&client->dev, "poc"); - if (IS_ERR(priv->regulator)) { - if (PTR_ERR(priv->regulator) != -EPROBE_DEFER) - dev_err(&client->dev, - "Unable to get PoC regulator (%ld)\n", - PTR_ERR(priv->regulator)); - ret = PTR_ERR(priv->regulator); - goto err_powerdown; - } - ret = max9286_parse_dt(priv); + if (ret) + goto err_cleanup_dt; + + ret = max9286_get_poc_supplies(priv); if (ret) goto err_powerdown; @@ -1329,7 +1413,7 @@ static int max9286_remove(struct i2c_client *client) max9286_v4l2_unregister(priv); - regulator_disable(priv->regulator); + max9286_poc_power_off(priv); gpiod_set_value_cansleep(priv->gpiod_pwdn, 0); From patchwork Thu Dec 16 22:09:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12682845 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73C65C4321E for ; Thu, 16 Dec 2021 22:09:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241541AbhLPWJ6 (ORCPT ); Thu, 16 Dec 2021 17:09:58 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:45468 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241421AbhLPWJ6 (ORCPT ); Thu, 16 Dec 2021 17:09:58 -0500 Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D37CD1265; Thu, 16 Dec 2021 23:09:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1639692596; bh=gJz8U5632ZU+fVSVsuBaOCiBZgyAUM/FAmhXYY3/A18=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oDJeRPp0ktHdhf+TsEJ4thcejt3r+4wT6+p28ZYGaUxD6YQsNVHxS9PY7/lECN+tT ddztm+Jy2RYyIgoi5a13OYR9hYU00RQtH/JQiXebYG2wHdEIYP1f4ehYyLaPhuOfBV GD28JH+fMBnp4m4LIyJbNpaKJ6y7j0dkvQdXmxzI= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Jacopo Mondi , Kieran Bingham , =?utf-8?q?Niklas_?= =?utf-8?q?S=C3=B6derlund?= , Thomas Nizan , Laurent Pinchart Subject: [PATCH 3/3] media: i2c: max9286: Support manual framesync operation Date: Fri, 17 Dec 2021 00:09:46 +0200 Message-Id: <20211216220946.20771-4-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211216220946.20771-1-laurent.pinchart+renesas@ideasonboard.com> References: <20211216220946.20771-1-laurent.pinchart+renesas@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org From: Laurent Pinchart The MAX9286 can generate a framesync signal to synchronize the cameras, using an internal timer. Support this mode of operation and configure it through the .s_frameinterval() operation. If the frame interval is not 0, framesync is switched to manual mode with the specified interval, otherwise automatic mode is used. Signed-off-by: Laurent Pinchart --- drivers/media/i2c/max9286.c | 66 +++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c index fa2f6a823fe6..dce1146635d2 100644 --- a/drivers/media/i2c/max9286.c +++ b/drivers/media/i2c/max9286.c @@ -174,6 +174,7 @@ struct max9286_priv { struct v4l2_ctrl *pixelrate; struct v4l2_mbus_framefmt fmt[MAX9286_N_SINKS]; + struct v4l2_fract interval; /* Protects controls and fmt structures */ struct mutex mutex; @@ -474,6 +475,37 @@ static int max9286_check_config_link(struct max9286_priv *priv, return 0; } +static void max9286_set_fsync_period(struct max9286_priv *priv) +{ + u32 fsync; + + if (!priv->interval.numerator || !priv->interval.denominator) { + /* + * Special case, a null interval enables automatic FRAMESYNC + * mode. FRAMESYNC is taken from the slowest link. + */ + max9286_write(priv, 0x01, MAX9286_FSYNCMODE_INT_HIZ | + MAX9286_FSYNCMETH_AUTO); + return; + } + + /* + * Manual FRAMESYNC + * + * The FRAMESYNC generator is configured with a period expressed as a + * number of PCLK periods, which runs at 75MHz. + */ + fsync = div_u64(75000000ULL * priv->interval.numerator, + priv->interval.denominator); + + max9286_write(priv, 0x01, MAX9286_FSYNCMODE_INT_OUT | + MAX9286_FSYNCMETH_MANUAL); + + max9286_write(priv, 0x06, (fsync >> 0) & 0xff); + max9286_write(priv, 0x07, (fsync >> 8) & 0xff); + max9286_write(priv, 0x08, (fsync >> 16) & 0xff); +} + /* ----------------------------------------------------------------------------- * V4L2 Subdev */ @@ -656,6 +688,8 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable) int ret; if (enable) { + max9286_set_fsync_period(priv); + /* * The frame sync between cameras is transmitted across the * reverse channel as GPIO. We must open all channels while @@ -715,6 +749,32 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable) return 0; } +static int max9286_g_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_frame_interval *interval) +{ + struct max9286_priv *priv = sd_to_max9286(sd); + + if (interval->pad == MAX9286_SRC_PAD) + return -EINVAL; + + interval->interval = priv->interval; + + return 0; +} + +static int max9286_s_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_frame_interval *interval) +{ + struct max9286_priv *priv = sd_to_max9286(sd); + + if (interval->pad == MAX9286_SRC_PAD) + return -EINVAL; + + priv->interval = interval->interval; + + return 0; +} + static int max9286_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) @@ -806,6 +866,8 @@ static int max9286_get_fmt(struct v4l2_subdev *sd, static const struct v4l2_subdev_video_ops max9286_video_ops = { .s_stream = max9286_s_stream, + .g_frame_interval = max9286_g_frame_interval, + .s_frame_interval = max9286_s_frame_interval, }; static const struct v4l2_subdev_pad_ops max9286_pad_ops = { @@ -998,9 +1060,7 @@ static int max9286_setup(struct max9286_priv *priv) MAX9286_CSILANECNT(priv->csi2_data_lanes) | MAX9286_DATATYPE_YUV422_8BIT); - /* Automatic: FRAMESYNC taken from the slowest Link. */ - max9286_write(priv, 0x01, MAX9286_FSYNCMODE_INT_HIZ | - MAX9286_FSYNCMETH_AUTO); + max9286_set_fsync_period(priv); /* Enable HS/VS encoding, use D14/15 for HS/VS, invert VS. */ max9286_write(priv, 0x0c, MAX9286_HVEN | MAX9286_INVVS |