From: Anusha Arun Nandi <anusha.nandi@oss.qualcomm.com>
To: Bryan O'Donoghue <bod@kernel.org>
Cc: Vinod Koul <vkoul@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Manivannan Sadhasivam <mani@kernel.org>,
gjorgji.rosikopulos@oss.qualcomm.com,
hariram.purushothaman@oss.qualcomm.com, akapatra@quicinc.com,
jigarkumar.zala@oss.qualcomm.com, linux-phy@lists.infradead.org,
linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Subject: [PATCH v4 3/5] phy: qcom-mipi-csi2: restructure D-PHY into core.c and dphy-regs.h
Date: Tue, 1 Dec 2026 13:02:05 -0800 [thread overview]
Message-ID: <20261201210207.1049452-4-anusha.nandi@oss.qualcomm.com> (raw)
In-Reply-To: <20261201210207.1049452-1-anusha.nandi@oss.qualcomm.com>
Restructure phy-qcom-mipi-csi2-3ph-dphy.c: its functions
(csi2phy_dev_to_regs(), hw_version_read()/reset()/settle_cnt_calc()/
gen2_config_lanes()/lanes_enable()/lanes_disable()) and the D-PHY
hw_ops table move into phy-qcom-mipi-csi2-core.c, while its register
data (lane_regs_x1e80100[] and the x1e80100 soc_cfg plus its clk/
supply/genpd name arrays) moves into a new
phy-qcom-mipi-csi2-dphy-regs.h. There is no longer a separate
code-bearing D-PHY source file: core.c now holds every PHY-framework
and D-PHY register-programming function plus the hw_ops table that
binds them, and the new header holds nothing but const data, #included
at the top of core.c. The per-SoC soc_cfg reaches the hw_ops table
through an extern in the shared phy-qcom-mipi-csi2.h.
This keeps the maintainability and readability.
The CSIPHY_3PH_CMN_* common-control register macros and the
CSIPHY_DEFAULT_PARAMS/_SETTLE_CNT_LOWER_BYTE/_SKEW_CAL param_type
values both move into that shared header too, since the new
dphy-regs.h's register tables need the param_type values and
core.c's register-write/read functions need the CTRL/STATUS offset
macros, the mipi_csi2_dphy_4nm_x1e extern drops out of the shared
header, since the soc_cfg object is now static and consumed only by
core.c.
No functional change: register addresses, values, and param_type
tags are unchanged.
Co-developed-by: Jigarkumar Zala <jigarkumar.zala@oss.qualcomm.com>
Signed-off-by: Jigarkumar Zala <jigarkumar.zala@oss.qualcomm.com>
Signed-off-by: Anusha Arun Nandi <anusha.nandi@oss.qualcomm.com>
---
drivers/phy/qualcomm/Makefile | 3 +-
.../phy/qualcomm/phy-qcom-mipi-csi2-core.c | 232 ++++++++++++++++-
...-dphy.c => phy-qcom-mipi-csi2-dphy-regs.h} | 238 +-----------------
drivers/phy/qualcomm/phy-qcom-mipi-csi2.h | 21 +-
4 files changed, 249 insertions(+), 245 deletions(-)
rename drivers/phy/qualcomm/{phy-qcom-mipi-csi2-3ph-dphy.c => phy-qcom-mipi-csi2-dphy-regs.h} (56%)
diff --git a/drivers/phy/qualcomm/Makefile b/drivers/phy/qualcomm/Makefile
index 4b5e6640a6fa..bae82e18c674 100644
--- a/drivers/phy/qualcomm/Makefile
+++ b/drivers/phy/qualcomm/Makefile
@@ -7,8 +7,7 @@ obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o
obj-$(CONFIG_PHY_QCOM_M31_USB) += phy-qcom-m31.o
obj-$(CONFIG_PHY_QCOM_M31_EUSB) += phy-qcom-m31-eusb2.o
-phy-qcom-mipi-csi2-objs += phy-qcom-mipi-csi2-core.o \
- phy-qcom-mipi-csi2-3ph-dphy.o
+phy-qcom-mipi-csi2-objs += phy-qcom-mipi-csi2-core.o
obj-$(CONFIG_PHY_QCOM_MIPI_CSI2) += phy-qcom-mipi-csi2.o
obj-$(CONFIG_PHY_QCOM_PCIE2) += phy-qcom-pcie2.o
diff --git a/drivers/phy/qualcomm/phy-qcom-mipi-csi2-core.c b/drivers/phy/qualcomm/phy-qcom-mipi-csi2-core.c
index 8bebc943a771..8a89ece01261 100644
--- a/drivers/phy/qualcomm/phy-qcom-mipi-csi2-core.c
+++ b/drivers/phy/qualcomm/phy-qcom-mipi-csi2-core.c
@@ -9,20 +9,233 @@
#include <linux/err.h>
#include <linux/io.h>
#include <linux/kernel.h>
+#include <linux/math64.h>
#include <linux/module.h>
#include <linux/of.h>
-#include <linux/pm_opp.h>
#include <linux/phy/phy.h>
#include <linux/phy/phy-mipi-dphy.h>
#include <linux/platform_device.h>
#include <linux/pm_domain.h>
+#include <linux/pm_opp.h>
#include <linux/pm_runtime.h>
-#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
-#include <linux/reset.h>
#include <linux/slab.h>
+#include <linux/time64.h>
#include "phy-qcom-mipi-csi2.h"
+/* D-PHY register tables and per-SoC soc_cfg objects (pure data). */
+#include "phy-qcom-mipi-csi2-dphy-regs.h"
+
+#define CSIPHY_2PH_LN_CSI_2PHASE_CTRL9n(n) ((0x200 * (n)) + 0x24)
+
+/*
+ * 3 phase CSI has 19 common status regs with only 0-10 being used
+ * and 11-18 being reserved.
+ */
+#define CSI_COMMON_STATUS_NUM 11
+/*
+ * There are a number of common control registers
+ * The offset to clear the CSIPHY IRQ status starts @ 22
+ * So to clear CSI_COMMON_STATUS0 this is CSI_COMMON_CONTROL22, STATUS1 is
+ * CONTROL23 and so on
+ */
+#define CSI_CTRL_STATUS_INDEX 22
+
+/*
+ * There are 43 COMMON_CTRL registers with regs after # 33 being reserved
+ */
+#define CSI_CTRL_MAX 33
+
+static inline const struct mipi_csi2phy_device_regs *
+csi2phy_dev_to_regs(struct mipi_csi2phy_device *csi2phy)
+{
+ return &csi2phy->soc_cfg->reg_info;
+}
+
+static void phy_qcom_mipi_csi2_hw_version_read(struct mipi_csi2phy_device *csi2phy)
+{
+ const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy);
+ u32 tmp;
+
+ writel(CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_SHOW_REV_ID, csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 6));
+
+ tmp = readl_relaxed(csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(regs->common_regs_offset, 12));
+ csi2phy->hw_version = tmp;
+
+ tmp = readl_relaxed(csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(regs->common_regs_offset, 13));
+ csi2phy->hw_version |= (tmp << 8) & 0xFF00;
+
+ tmp = readl_relaxed(csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(regs->common_regs_offset, 14));
+ csi2phy->hw_version |= (tmp << 16) & 0xFF0000;
+
+ tmp = readl_relaxed(csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(regs->common_regs_offset, 15));
+ csi2phy->hw_version |= (tmp << 24) & 0xFF000000;
+
+ dev_dbg_once(csi2phy->dev, "CSIPHY 3PH HW Version = 0x%08x\n", csi2phy->hw_version);
+}
+
+/*
+ * phy_qcom_mipi_csi2_reset - Perform software reset on CSIPHY module
+ * @csi2phy: CSIPHY device
+ */
+static void phy_qcom_mipi_csi2_reset(struct mipi_csi2phy_device *csi2phy)
+{
+ const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy);
+
+ writel(CSIPHY_3PH_CMN_CSI_COMMON_CTRL0_PHY_SW_RESET,
+ csi2phy->base + CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 0));
+ usleep_range(5000, 8000);
+ writel(0x0, csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 0));
+}
+
+static void
+phy_qcom_mipi_csi2_lanes_disable(struct mipi_csi2phy_device *csi2phy,
+ struct mipi_csi2phy_stream_cfg *cfg)
+{
+ const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy);
+
+ writel(0, csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 5));
+
+ writel(0, csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 6));
+}
+
+/*
+ * phy_qcom_mipi_csi2_settle_cnt_calc - Calculate settle count value
+ *
+ * Helper function to calculate settle count value. This is
+ * based on the CSI2 T_hs_settle parameter which in turn
+ * is calculated based on the CSI2 transmitter link frequency.
+ *
+ * Return settle count.
+ */
+static u8 phy_qcom_mipi_csi2_settle_cnt_calc(s64 link_freq, u32 timer_clk_rate)
+{
+ u32 t_hs_prepare_max_ps;
+ u32 timer_period_ps;
+ u32 t_hs_settle_ps;
+ u8 settle_cnt;
+ u32 ui_ps;
+
+ ui_ps = div64_u64(PSEC_PER_SEC, link_freq);
+ ui_ps /= 2;
+ t_hs_prepare_max_ps = 85000 + 6 * ui_ps;
+ t_hs_settle_ps = t_hs_prepare_max_ps;
+
+ timer_period_ps = div_u64(PSEC_PER_SEC, timer_clk_rate);
+
+ if ((t_hs_settle_ps / timer_period_ps) < 6)
+ return 0;
+
+ settle_cnt = t_hs_settle_ps / timer_period_ps - 6;
+
+ return settle_cnt;
+}
+
+static void
+phy_qcom_mipi_csi2_gen2_config_lanes(struct mipi_csi2phy_device *csi2phy,
+ u8 settle_cnt)
+{
+ const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy);
+ const struct mipi_csi2phy_lane_regs *r = regs->init_seq;
+ int i, array_size = regs->lane_array_size;
+ u32 val;
+
+ for (i = 0; i < array_size; i++, r++) {
+ switch (r->param_type) {
+ case CSIPHY_SETTLE_CNT_LOWER_BYTE:
+ val = settle_cnt & 0xff;
+ break;
+ case CSIPHY_SKEW_CAL:
+ /* TODO: support application of skew from dt flag */
+ continue;
+ default:
+ val = r->reg_data;
+ break;
+ }
+ writel(val, csi2phy->base + r->reg_addr);
+ if (r->delay_us)
+ udelay(r->delay_us);
+ }
+}
+
+static int phy_qcom_mipi_csi2_lanes_enable(struct mipi_csi2phy_device *csi2phy,
+ struct mipi_csi2phy_stream_cfg *cfg)
+{
+ const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy);
+ struct mipi_csi2phy_lanes_cfg *lane_cfg = &cfg->lane_cfg;
+ u8 settle_cnt;
+ u8 val;
+ int i;
+
+ if (cfg->link_freq <= 0)
+ return -EINVAL;
+
+ settle_cnt = phy_qcom_mipi_csi2_settle_cnt_calc(cfg->link_freq, csi2phy->timer_clk_rate);
+ if (!settle_cnt)
+ return -ENODEV;
+
+ /*
+ * CSI_COMMON_CTRL5 is a physical lane power-up bitmap:
+ * - Bits [0,2,4,6] → D-PHY data lanes(LN0, LN2, LN4, LN6)
+ * - Bits [1,3,5] → C-PHY trio lanes(LN1, LN3, LN5)
+ * - Bit [7] → D-PHY clock lane(LNCK) dedicated clock enable
+ */
+ val = BIT(lane_cfg->clk.pos);
+ for (i = 0; i < cfg->num_data_lanes; i++)
+ val |= BIT(lane_cfg->data[i].pos * 2);
+
+ writel(val, csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 5));
+
+ /* Lane configuration for polarity @ CSIPHY-base + CTRL9 */
+ for (i = 0; i < cfg->num_data_lanes; i++) {
+ if (lane_cfg->data[i].pol) {
+ u8 pos = lane_cfg->data[i].pos;
+
+ writel(BIT(2), csi2phy->base + CSIPHY_2PH_LN_CSI_2PHASE_CTRL9n(pos * 2));
+ }
+ }
+
+ if (lane_cfg->clk.pol)
+ writel(BIT(2), csi2phy->base + CSIPHY_2PH_LN_CSI_2PHASE_CTRL9n(lane_cfg->clk.pos));
+
+ val = CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_COMMON_PWRDN_B;
+ writel(val, csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 6));
+
+ val = 0x02;
+ writel(val, csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 7));
+
+ val = 0x00;
+ writel(val, csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 0));
+
+ phy_qcom_mipi_csi2_gen2_config_lanes(csi2phy, settle_cnt);
+
+ /* IRQ_MASK registers - disable all interrupts */
+ for (i = CSI_COMMON_STATUS_NUM; i < CSI_CTRL_STATUS_INDEX; i++) {
+ writel(0, csi2phy->base +
+ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, i));
+ }
+
+ return 0;
+}
+
+const struct mipi_csi2phy_hw_ops phy_qcom_mipi_csi2_ops_3ph_1_0 = {
+ .hw_version_read = phy_qcom_mipi_csi2_hw_version_read,
+ .reset = phy_qcom_mipi_csi2_reset,
+ .lanes_enable = phy_qcom_mipi_csi2_lanes_enable,
+ .lanes_disable = phy_qcom_mipi_csi2_lanes_disable,
+};
static int
phy_qcom_mipi_csi2_set_clock_rates(struct mipi_csi2phy_device *csi2phy,
@@ -239,11 +452,10 @@ static int phy_qcom_mipi_csi2_attach_pm_domains(struct mipi_csi2phy_device *csi2
/* Single power-domain devices are already attached by the bus core. */
if (csi2phy->soc_cfg->num_genpds == 1)
- return dev_pm_domain_attach(csi2phy->dev, 0);
+ return dev_pm_domain_attach(csi2phy->dev, false);
- pd_names = devm_kzalloc(csi2phy->dev,
- sizeof(char *) * csi2phy->soc_cfg->num_genpds,
- GFP_KERNEL);
+ pd_names = devm_kcalloc(csi2phy->dev, csi2phy->soc_cfg->num_genpds,
+ sizeof(*pd_names), GFP_KERNEL);
if (!pd_names)
return -ENOMEM;
@@ -370,7 +582,6 @@ static int phy_qcom_mipi_csi2_probe(struct platform_device *pdev)
dev_set_drvdata(dev, csi2phy);
csi2phy->soc_cfg = device_get_match_data(&pdev->dev);
-
if (!csi2phy->soc_cfg)
return -EINVAL;
@@ -392,10 +603,9 @@ static int phy_qcom_mipi_csi2_probe(struct platform_device *pdev)
if (ret < 0)
return dev_err_probe(dev, ret, "Failed to get clocks\n");
- if (num_clk != ret) {
+ if (num_clk != ret)
return dev_err_probe(dev, -ENODEV, "clock count %d expected %d\n",
ret, num_clk);
- }
for (i = 0; i < num_clk; i++) {
if (!csi2phy->clks[i].id)
@@ -420,7 +630,7 @@ static int phy_qcom_mipi_csi2_probe(struct platform_device *pdev)
}
num_supplies = csi2phy->soc_cfg->num_supplies;
- csi2phy->supplies = devm_kzalloc(dev, sizeof(*csi2phy->supplies) * num_supplies,
+ csi2phy->supplies = devm_kcalloc(dev, num_supplies, sizeof(*csi2phy->supplies),
GFP_KERNEL);
if (!csi2phy->supplies)
return -ENOMEM;
diff --git a/drivers/phy/qualcomm/phy-qcom-mipi-csi2-3ph-dphy.c b/drivers/phy/qualcomm/phy-qcom-mipi-csi2-dphy-regs.h
similarity index 56%
rename from drivers/phy/qualcomm/phy-qcom-mipi-csi2-3ph-dphy.c
rename to drivers/phy/qualcomm/phy-qcom-mipi-csi2-dphy-regs.h
index 966d79c98f9b..2f07cd487b8d 100644
--- a/drivers/phy/qualcomm/phy-qcom-mipi-csi2-3ph-dphy.c
+++ b/drivers/phy/qualcomm/phy-qcom-mipi-csi2-dphy-regs.h
@@ -1,50 +1,15 @@
-// SPDX-License-Identifier: GPL-2.0
+/* SPDX-License-Identifier: GPL-2.0 */
/*
- * Qualcomm MSM Camera Subsystem - CSIPHY Module 3phase v1.0
+ * Qualcomm MSM Camera Subsystem - CSIPHY Module 3phase v1.0, D-PHY register data
*
* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
* Copyright (C) 2016-2026 Linaro Ltd.
*/
-
-#include <linux/delay.h>
-#include <linux/interrupt.h>
-#include <linux/io.h>
-#include <linux/time64.h>
+#ifndef __PHY_QCOM_MIPI_CSI2_DPHY_REGS_H__
+#define __PHY_QCOM_MIPI_CSI2_DPHY_REGS_H__
#include "phy-qcom-mipi-csi2.h"
-#define CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(offset, n) ((offset) + 0x4 * (n))
-#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL0_PHY_SW_RESET BIT(0)
-#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL5_CLK_ENABLE BIT(7)
-#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_COMMON_PWRDN_B BIT(0)
-#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_SHOW_REV_ID BIT(1)
-#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL10_IRQ_CLEAR_CMD BIT(0)
-#define CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(offset, n) ((offset) + 0xb0 + 0x4 * (n))
-
-#define CSIPHY_2PH_LN_CSI_2PHASE_CTRL9n(n) ((0x200 * (n)) + 0x24)
-
-/*
- * 3 phase CSI has 19 common status regs with only 0-10 being used
- * and 11-18 being reserved.
- */
-#define CSI_COMMON_STATUS_NUM 11
-/*
- * There are a number of common control registers
- * The offset to clear the CSIPHY IRQ status starts @ 22
- * So to clear CSI_COMMON_STATUS0 this is CSI_COMMON_CONTROL22, STATUS1 is
- * CONTROL23 and so on
- */
-#define CSI_CTRL_STATUS_INDEX 22
-
-/*
- * There are 43 COMMON_CTRL registers with regs after # 33 being reserved
- */
-#define CSI_CTRL_MAX 33
-
-#define CSIPHY_DEFAULT_PARAMS 0
-#define CSIPHY_SETTLE_CNT_LOWER_BYTE 2
-#define CSIPHY_SKEW_CAL 7
-
/* 4nm 2PH v 2.1.2 2p5Gbps 4 lane DPHY mode */
static const struct
mipi_csi2phy_lane_regs lane_regs_x1e80100[] = {
@@ -161,197 +126,6 @@ mipi_csi2phy_lane_regs lane_regs_x1e80100[] = {
{.reg_addr = 0x0c64, .reg_data = 0x7f, .param_type = CSIPHY_SKEW_CAL},
};
-static inline const struct mipi_csi2phy_device_regs *
-csi2phy_dev_to_regs(struct mipi_csi2phy_device *csi2phy)
-{
- return &csi2phy->soc_cfg->reg_info;
-}
-
-static void phy_qcom_mipi_csi2_hw_version_read(struct mipi_csi2phy_device *csi2phy)
-{
- const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy);
- u32 tmp;
-
- writel(CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_SHOW_REV_ID, csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 6));
-
- tmp = readl_relaxed(csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(regs->common_regs_offset, 12));
- csi2phy->hw_version = tmp;
-
- tmp = readl_relaxed(csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(regs->common_regs_offset, 13));
- csi2phy->hw_version |= (tmp << 8) & 0xFF00;
-
- tmp = readl_relaxed(csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(regs->common_regs_offset, 14));
- csi2phy->hw_version |= (tmp << 16) & 0xFF0000;
-
- tmp = readl_relaxed(csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(regs->common_regs_offset, 15));
- csi2phy->hw_version |= (tmp << 24) & 0xFF000000;
-
- dev_dbg_once(csi2phy->dev, "CSIPHY 3PH HW Version = 0x%08x\n", csi2phy->hw_version);
-}
-
-/*
- * phy_qcom_mipi_csi2_reset - Perform software reset on CSIPHY module
- * @phy_qcom_mipi_csi2: CSIPHY device
- */
-static void phy_qcom_mipi_csi2_reset(struct mipi_csi2phy_device *csi2phy)
-{
- const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy);
-
- writel(CSIPHY_3PH_CMN_CSI_COMMON_CTRL0_PHY_SW_RESET,
- csi2phy->base + CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 0));
- usleep_range(5000, 8000);
- writel(0x0, csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 0));
-}
-
-/*
- * phy_qcom_mipi_csi2_settle_cnt_calc - Calculate settle count value
- *
- * Helper function to calculate settle count value. This is
- * based on the CSI2 T_hs_settle parameter which in turn
- * is calculated based on the CSI2 transmitter link frequency.
- *
- * Return settle count.
- */
-static u8 phy_qcom_mipi_csi2_settle_cnt_calc(s64 link_freq, u32 timer_clk_rate)
-{
- u32 t_hs_prepare_max_ps;
- u32 timer_period_ps;
- u32 t_hs_settle_ps;
- u8 settle_cnt;
- u32 ui_ps;
-
- ui_ps = div64_u64(PSEC_PER_SEC, link_freq);
- ui_ps /= 2;
- t_hs_prepare_max_ps = 85000 + 6 * ui_ps;
- t_hs_settle_ps = t_hs_prepare_max_ps;
-
- timer_period_ps = div_u64(PSEC_PER_SEC, timer_clk_rate);
-
- if ((t_hs_settle_ps / timer_period_ps) < 6)
- return 0;
-
- settle_cnt = t_hs_settle_ps / timer_period_ps - 6;
-
- return settle_cnt;
-}
-
-static void
-phy_qcom_mipi_csi2_gen2_config_lanes(struct mipi_csi2phy_device *csi2phy,
- u8 settle_cnt)
-{
- const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy);
- const struct mipi_csi2phy_lane_regs *r = regs->init_seq;
- int i, array_size = regs->lane_array_size;
- u32 val;
-
- for (i = 0; i < array_size; i++, r++) {
- switch (r->param_type) {
- case CSIPHY_SETTLE_CNT_LOWER_BYTE:
- val = settle_cnt & 0xff;
- break;
- case CSIPHY_SKEW_CAL:
- /* TODO: support application of skew from dt flag */
- continue;
- default:
- val = r->reg_data;
- break;
- }
- writel(val, csi2phy->base + r->reg_addr);
- if (r->delay_us)
- udelay(r->delay_us);
- }
-}
-
-static int phy_qcom_mipi_csi2_lanes_enable(struct mipi_csi2phy_device *csi2phy,
- struct mipi_csi2phy_stream_cfg *cfg)
-{
- const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy);
- struct mipi_csi2phy_lanes_cfg *lane_cfg = &cfg->lane_cfg;
- u8 settle_cnt;
- u8 val;
- int i;
-
- if (cfg->link_freq <= 0)
- return -EINVAL;
-
- settle_cnt = phy_qcom_mipi_csi2_settle_cnt_calc(cfg->link_freq, csi2phy->timer_clk_rate);
- if (!settle_cnt)
- return -ENODEV;
-
- /*
- * CSI_COMMON_CTRL5 is a physical lane power-up bitmap:
- * - Bits [0,2,4,6] → D-PHY data lanes(LN0, LN2, LN4, LN6)
- * - Bits [1,3,5] → C-PHY trio lanes(LN1, LN3, LN5)
- * - Bit [7] → D-PHY clock lane(LNCK) dedicated clock enable
- */
- val = BIT(lane_cfg->clk.pos);
- for (i = 0; i < cfg->num_data_lanes; i++)
- val |= BIT(lane_cfg->data[i].pos * 2);
-
- writel(val, csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 5));
-
- /* Lane configuration for polarity @ CSIPHY-base + CTRL9 */
- for (i = 0; i < cfg->num_data_lanes; i++) {
- if (lane_cfg->data[i].pol) {
- u8 pos = lane_cfg->data[i].pos;
-
- writel(BIT(2), csi2phy->base + CSIPHY_2PH_LN_CSI_2PHASE_CTRL9n(pos * 2));
- }
- }
-
- if (lane_cfg->clk.pol)
- writel(BIT(2), csi2phy->base + CSIPHY_2PH_LN_CSI_2PHASE_CTRL9n(lane_cfg->clk.pos));
-
- val = CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_COMMON_PWRDN_B;
- writel(val, csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 6));
-
- val = 0x02;
- writel(val, csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 7));
-
- val = 0x00;
- writel(val, csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 0));
-
- phy_qcom_mipi_csi2_gen2_config_lanes(csi2phy, settle_cnt);
-
- /* IRQ_MASK registers - disable all interrupts */
- for (i = CSI_COMMON_STATUS_NUM; i < CSI_CTRL_STATUS_INDEX; i++) {
- writel(0, csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, i));
- }
-
- return 0;
-}
-
-static void
-phy_qcom_mipi_csi2_lanes_disable(struct mipi_csi2phy_device *csi2phy,
- struct mipi_csi2phy_stream_cfg *cfg)
-{
- const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy);
-
- writel(0, csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 5));
-
- writel(0, csi2phy->base +
- CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 6));
-}
-
-static const struct mipi_csi2phy_hw_ops phy_qcom_mipi_csi2_ops_3ph_1_0 = {
- .hw_version_read = phy_qcom_mipi_csi2_hw_version_read,
- .reset = phy_qcom_mipi_csi2_reset,
- .lanes_enable = phy_qcom_mipi_csi2_lanes_enable,
- .lanes_disable = phy_qcom_mipi_csi2_lanes_disable,
-};
-
static const char * const x1e_clks[] = {
"core",
"timer",
@@ -369,7 +143,7 @@ static struct mipi_csi2_genpd x1e_genpds[] = {
{ .name = "mx", .scaled = true },
};
-const struct mipi_csi2phy_soc_cfg mipi_csi2_dphy_4nm_x1e = {
+static const struct mipi_csi2phy_soc_cfg mipi_csi2_dphy_4nm_x1e = {
.ops = &phy_qcom_mipi_csi2_ops_3ph_1_0,
.reg_info = {
.init_seq = lane_regs_x1e80100,
@@ -383,3 +157,5 @@ const struct mipi_csi2phy_soc_cfg mipi_csi2_dphy_4nm_x1e = {
.genpds = x1e_genpds,
.num_genpds = ARRAY_SIZE(x1e_genpds),
};
+
+#endif /* __PHY_QCOM_MIPI_CSI2_DPHY_REGS_H__ */
diff --git a/drivers/phy/qualcomm/phy-qcom-mipi-csi2.h b/drivers/phy/qualcomm/phy-qcom-mipi-csi2.h
index 6cf9e5b956f7..2040117123fd 100644
--- a/drivers/phy/qualcomm/phy-qcom-mipi-csi2.h
+++ b/drivers/phy/qualcomm/phy-qcom-mipi-csi2.h
@@ -13,6 +13,20 @@
#define CSI2_MAX_DATA_LANES 4
#define CSI2_DEFAULT_CLK_LANE 7
+/* 3-phase CSIPHY common-control register layout. */
+#define CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(offset, n) ((offset) + 0x4 * (n))
+#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL0_PHY_SW_RESET BIT(0)
+#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL5_CLK_ENABLE BIT(7)
+#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_COMMON_PWRDN_B BIT(0)
+#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_SHOW_REV_ID BIT(1)
+#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL10_IRQ_CLEAR_CMD BIT(0)
+#define CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(offset, n) ((offset) + 0xb0 + 0x4 * (n))
+
+/* mipi_csi2phy_lane_regs.param_type values */
+#define CSIPHY_DEFAULT_PARAMS 0
+#define CSIPHY_SETTLE_CNT_LOWER_BYTE 2
+#define CSIPHY_SKEW_CAL 7
+
struct mipi_csi2phy_lane {
u8 pos;
u8 pol;
@@ -95,6 +109,11 @@ struct mipi_csi2phy_device {
u32 hw_version;
};
-extern const struct mipi_csi2phy_soc_cfg mipi_csi2_dphy_4nm_x1e;
+/*
+ * D-PHY hw_ops table: defined in core.c next to the programming functions it
+ * binds, and referenced from the per-SoC soc_cfg objects in
+ * phy-qcom-mipi-csi2-dphy-regs.h.
+ */
+extern const struct mipi_csi2phy_hw_ops phy_qcom_mipi_csi2_ops_3ph_1_0;
#endif /* __PHY_QCOM_MIPI_CSI2_H__ */
--
2.34.1
next prev parent reply other threads:[~2026-12-01 21:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 21:02 [PATCH v4 0/5] phy: qcom-mipi-csi2: Add D-PHY support for sa8775p, qcs8300 and sc7280 Anusha Arun Nandi
2026-12-01 21:02 ` [PATCH v4 1/5] dt-bindings: phy: qcom: Add common qcom,csi2-phy Anusha Arun Nandi
2026-12-02 4:49 ` Bryan O'Donoghue
2026-12-02 8:16 ` Nihal Kumar Gupta
2026-12-01 21:02 ` [PATCH v4 2/5] phy: qcom-mipi-csi2: Make OPP table optional Anusha Arun Nandi
2026-12-02 4:55 ` Bryan O'Donoghue
2026-12-02 8:12 ` Nihal Kumar Gupta
2026-12-01 21:02 ` Anusha Arun Nandi [this message]
2026-12-02 5:20 ` [PATCH v4 3/5] phy: qcom-mipi-csi2: restructure D-PHY into core.c and dphy-regs.h Bryan O'Donoghue
2026-12-01 21:02 ` [PATCH v4 4/5] phy: qcom-mipi-csi2: Add sa8775p D-PHY support Anusha Arun Nandi
2026-12-01 21:02 ` [PATCH v4 5/5] phy: qcom-mipi-csi2: Add sc7280 D-PHY provider Anusha Arun Nandi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201210207.1049452-4-anusha.nandi@oss.qualcomm.com \
--to=anusha.nandi@oss.qualcomm.com \
--cc=akapatra@quicinc.com \
--cc=bod@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gjorgji.rosikopulos@oss.qualcomm.com \
--cc=hariram.purushothaman@oss.qualcomm.com \
--cc=jigarkumar.zala@oss.qualcomm.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=mani@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox