2020-03-30 07:16:23

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH 0/4] add mipi_csi_xx gate clocks for SC9863A

From: Chunyan Zhang <[email protected]>

mipi_csi_xx clocks are used by camera sensors. These clocks cannot be
accessed (even read) if their parent gate clock is disabled. So this
patchset also add a check to parent clocks when reading these gate
clocks which marked with the specific flag (SPRD_GATE_NON_AON).

Chunyan Zhang (4):
clk: sprd: check its parent status before reading gate clock
dt-bindings: clk: sprd: add mipi_csi_xx clocks for SC9863A
clk: sprd: add dt-bindings include for mipi_csi_xx clocks
clk: sprd: add mipi_csi_xx gate clocks

.../bindings/clock/sprd,sc9863a-clk.yaml | 1 +
drivers/clk/sprd/gate.c | 8 +++++
drivers/clk/sprd/gate.h | 9 ++++++
drivers/clk/sprd/sc9863a-clk.c | 32 +++++++++++++++++++
include/dt-bindings/clock/sprd,sc9863a-clk.h | 5 +++
5 files changed, 55 insertions(+)

--
2.20.1


2020-03-30 07:16:33

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH 1/4] clk: sprd: check its parent status before reading gate clock

From: Chunyan Zhang <[email protected]>

Some clocks only can be accessed if their parent is enabled. mipi_csi_xx
clocks on SC9863A are examples. We have to ensure the parent clock is
enabled when reading those clocks.

Signed-off-by: Chunyan Zhang <[email protected]>
---
drivers/clk/sprd/gate.c | 8 ++++++++
drivers/clk/sprd/gate.h | 9 +++++++++
2 files changed, 17 insertions(+)

diff --git a/drivers/clk/sprd/gate.c b/drivers/clk/sprd/gate.c
index 574cfc116bbc..8d14073b9cb8 100644
--- a/drivers/clk/sprd/gate.c
+++ b/drivers/clk/sprd/gate.c
@@ -5,6 +5,7 @@
// Copyright (C) 2017 Spreadtrum, Inc.
// Author: Chunyan Zhang <[email protected]>

+#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/regmap.h>

@@ -94,8 +95,15 @@ static int sprd_gate_is_enabled(struct clk_hw *hw)
{
struct sprd_gate *sg = hw_to_sprd_gate(hw);
struct sprd_clk_common *common = &sg->common;
+ struct clk_hw *parent;
unsigned int reg;

+ if (sg->flags & SPRD_GATE_NON_AON) {
+ parent = clk_hw_get_parent(hw);
+ if (!parent || !clk_hw_is_enabled(parent))
+ return 0;
+ }
+
regmap_read(common->regmap, common->reg, &reg);

if (sg->flags & CLK_GATE_SET_TO_DISABLE)
diff --git a/drivers/clk/sprd/gate.h b/drivers/clk/sprd/gate.h
index b55817869367..aa4d72381788 100644
--- a/drivers/clk/sprd/gate.h
+++ b/drivers/clk/sprd/gate.h
@@ -19,6 +19,15 @@ struct sprd_gate {
struct sprd_clk_common common;
};

+/*
+ * sprd_gate->flags is used for:
+ * CLK_GATE_SET_TO_DISABLE BIT(0)
+ * CLK_GATE_HIWORD_MASK BIT(1)
+ * CLK_GATE_BIG_ENDIAN BIT(2)
+ * so we define new flags from BIT(3)
+ */
+#define SPRD_GATE_NON_AON BIT(3) /* not alway on, need to check before read */
+
#define SPRD_SC_GATE_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, \
_sc_offset, _enable_mask, _flags, \
_gate_flags, _udelay, _ops, _fn) \
--
2.20.1

2020-03-30 07:16:35

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH 2/4] dt-bindings: clk: sprd: add mipi_csi_xx clocks for SC9863A

From: Chunyan Zhang <[email protected]>

mipi_csi_xx clocks are used by camera sensors.

Signed-off-by: Chunyan Zhang <[email protected]>
---
Documentation/devicetree/bindings/clock/sprd,sc9863a-clk.yaml | 1 +
1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/clock/sprd,sc9863a-clk.yaml b/Documentation/devicetree/bindings/clock/sprd,sc9863a-clk.yaml
index bb3a78d8105e..87e8349a539a 100644
--- a/Documentation/devicetree/bindings/clock/sprd,sc9863a-clk.yaml
+++ b/Documentation/devicetree/bindings/clock/sprd,sc9863a-clk.yaml
@@ -28,6 +28,7 @@ properties:
- sprd,sc9863a-rpll
- sprd,sc9863a-dpll
- sprd,sc9863a-mm-gate
+ - sprd,sc9863a-mm-clk
- sprd,sc9863a-apapb-gate

clocks:
--
2.20.1

2020-03-30 07:16:57

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH 3/4] clk: sprd: add dt-bindings include for mipi_csi_xx clocks

From: Chunyan Zhang <[email protected]>

mipi_csi_xx clocks are used by camera sensors.

Signed-off-by: Chunyan Zhang <[email protected]>
---
include/dt-bindings/clock/sprd,sc9863a-clk.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/include/dt-bindings/clock/sprd,sc9863a-clk.h b/include/dt-bindings/clock/sprd,sc9863a-clk.h
index 901ba59676c2..4e030421641f 100644
--- a/include/dt-bindings/clock/sprd,sc9863a-clk.h
+++ b/include/dt-bindings/clock/sprd,sc9863a-clk.h
@@ -308,6 +308,11 @@
#define CLK_MCPHY_CFG_EB 14
#define CLK_MM_GATE_NUM (CLK_MCPHY_CFG_EB + 1)

+#define CLK_MIPI_CSI 0
+#define CLK_MIPI_CSI_S 1
+#define CLK_MIPI_CSI_M 2
+#define CLK_MM_CLK_NUM (CLK_MIPI_CSI_M + 1)
+
#define CLK_SIM0_EB 0
#define CLK_IIS0_EB 1
#define CLK_IIS1_EB 2
--
2.20.1

2020-03-30 07:18:07

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH 4/4] clk: sprd: add mipi_csi_xx gate clocks

From: Chunyan Zhang <[email protected]>

mipi_csi_xx clocks are used by camera sensors.

Signed-off-by: Chunyan Zhang <[email protected]>
---
drivers/clk/sprd/sc9863a-clk.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)

diff --git a/drivers/clk/sprd/sc9863a-clk.c b/drivers/clk/sprd/sc9863a-clk.c
index a0631f7756cf..24f064262814 100644
--- a/drivers/clk/sprd/sc9863a-clk.c
+++ b/drivers/clk/sprd/sc9863a-clk.c
@@ -1615,6 +1615,36 @@ static const struct sprd_clk_desc sc9863a_mm_gate_desc = {
.hw_clks = &sc9863a_mm_gate_hws,
};

+/* mm clocks */
+static SPRD_GATE_CLK_HW(mipi_csi_clk, "mipi-csi-clk", &mahb_ckg_eb.common.hw,
+ 0x20, BIT(16), 0, SPRD_GATE_NON_AON);
+static SPRD_GATE_CLK_HW(mipi_csi_s_clk, "mipi-csi-s-clk", &mahb_ckg_eb.common.hw,
+ 0x24, BIT(16), 0, SPRD_GATE_NON_AON);
+static SPRD_GATE_CLK_HW(mipi_csi_m_clk, "mipi-csi-m-clk", &mahb_ckg_eb.common.hw,
+ 0x28, BIT(16), 0, SPRD_GATE_NON_AON);
+
+static struct sprd_clk_common *sc9863a_mm_clk_clks[] = {
+ /* address base is 0x60900000 */
+ &mipi_csi_clk.common,
+ &mipi_csi_s_clk.common,
+ &mipi_csi_m_clk.common,
+};
+
+static struct clk_hw_onecell_data sc9863a_mm_clk_hws = {
+ .hws = {
+ [CLK_MIPI_CSI] = &mipi_csi_clk.common.hw,
+ [CLK_MIPI_CSI_S] = &mipi_csi_s_clk.common.hw,
+ [CLK_MIPI_CSI_M] = &mipi_csi_m_clk.common.hw,
+ },
+ .num = CLK_MM_CLK_NUM,
+};
+
+static const struct sprd_clk_desc sc9863a_mm_clk_desc = {
+ .clk_clks = sc9863a_mm_clk_clks,
+ .num_clk_clks = ARRAY_SIZE(sc9863a_mm_clk_clks),
+ .hw_clks = &sc9863a_mm_clk_hws,
+};
+
static SPRD_SC_GATE_CLK_FW_NAME(sim0_eb, "sim0-eb", "ext-26m", 0x0,
0x1000, BIT(0), 0, 0);
static SPRD_SC_GATE_CLK_FW_NAME(iis0_eb, "iis0-eb", "ext-26m", 0x0,
@@ -1737,6 +1767,8 @@ static const struct of_device_id sprd_sc9863a_clk_ids[] = {
.data = &sc9863a_aonapb_gate_desc },
{ .compatible = "sprd,sc9863a-mm-gate", /* 0x60800000 */
.data = &sc9863a_mm_gate_desc },
+ { .compatible = "sprd,sc9863a-mm-clk", /* 0x60900000 */
+ .data = &sc9863a_mm_clk_desc },
{ .compatible = "sprd,sc9863a-apapb-gate", /* 0x71300000 */
.data = &sc9863a_apapb_gate_desc },
{ }
--
2.20.1

2020-03-30 07:32:47

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH 1/4] clk: sprd: check its parent status before reading gate clock

From: Chunyan Zhang <[email protected]>

Some clocks only can be accessed if their parent is enabled. mipi_csi_xx
clocks on SC9863A are examples. We have to ensure the parent clock is
enabled when reading those clocks.

Signed-off-by: Chunyan Zhang <[email protected]>
---
drivers/clk/sprd/gate.c | 7 +++++++
drivers/clk/sprd/gate.h | 9 +++++++++
2 files changed, 16 insertions(+)

diff --git a/drivers/clk/sprd/gate.c b/drivers/clk/sprd/gate.c
index 574cfc116bbc..56e1714b541e 100644
--- a/drivers/clk/sprd/gate.c
+++ b/drivers/clk/sprd/gate.c
@@ -94,8 +94,15 @@ static int sprd_gate_is_enabled(struct clk_hw *hw)
{
struct sprd_gate *sg = hw_to_sprd_gate(hw);
struct sprd_clk_common *common = &sg->common;
+ struct clk_hw *parent;
unsigned int reg;

+ if (sg->flags & SPRD_GATE_NON_AON) {
+ parent = clk_hw_get_parent(hw);
+ if (!parent || !clk_hw_is_enabled(parent))
+ return 0;
+ }
+
regmap_read(common->regmap, common->reg, &reg);

if (sg->flags & CLK_GATE_SET_TO_DISABLE)
diff --git a/drivers/clk/sprd/gate.h b/drivers/clk/sprd/gate.h
index b55817869367..aa4d72381788 100644
--- a/drivers/clk/sprd/gate.h
+++ b/drivers/clk/sprd/gate.h
@@ -19,6 +19,15 @@ struct sprd_gate {
struct sprd_clk_common common;
};

+/*
+ * sprd_gate->flags is used for:
+ * CLK_GATE_SET_TO_DISABLE BIT(0)
+ * CLK_GATE_HIWORD_MASK BIT(1)
+ * CLK_GATE_BIG_ENDIAN BIT(2)
+ * so we define new flags from BIT(3)
+ */
+#define SPRD_GATE_NON_AON BIT(3) /* not alway on, need to check before read */
+
#define SPRD_SC_GATE_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, \
_sc_offset, _enable_mask, _flags, \
_gate_flags, _udelay, _ops, _fn) \
--
2.20.1

2020-04-10 17:37:43

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH 2/4] dt-bindings: clk: sprd: add mipi_csi_xx clocks for SC9863A

On Mon, 30 Mar 2020 15:14:49 +0800, Chunyan Zhang wrote:
> From: Chunyan Zhang <[email protected]>
>
> mipi_csi_xx clocks are used by camera sensors.
>
> Signed-off-by: Chunyan Zhang <[email protected]>
> ---
> Documentation/devicetree/bindings/clock/sprd,sc9863a-clk.yaml | 1 +
> 1 file changed, 1 insertion(+)
>

Acked-by: Rob Herring <[email protected]>

2020-04-10 17:39:29

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH 3/4] clk: sprd: add dt-bindings include for mipi_csi_xx clocks

On Mon, 30 Mar 2020 15:14:50 +0800, Chunyan Zhang wrote:
> From: Chunyan Zhang <[email protected]>
>
> mipi_csi_xx clocks are used by camera sensors.
>
> Signed-off-by: Chunyan Zhang <[email protected]>
> ---
> include/dt-bindings/clock/sprd,sc9863a-clk.h | 5 +++++
> 1 file changed, 5 insertions(+)
>

Acked-by: Rob Herring <[email protected]>