Skip to contentSkip to conversation

Add support for the rockchip mmc clock phases using the framework

PATCH Applied Alexandru M Stan 2 participants 4 messages Nov 27, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover Add support for the rockchip mmc clock phases using the framework

For now all I have is the getter and setter for the phase, nothing that uses it (that is ready). You can test the getter like this:
localhost ~ # cat /sys/kernel/debug/clk/clk_summary|grep sample -C 1
sclk_sdio1 0 0 24000000 0 0

	sdio1_sample                       0            0    12000000          0 0
	sdio1_drv                          0            0    12000000          0 90

--
sclk_sdmmc 1 1 297000000 0 0
sdmmc_sample 0 0 148500000 0 134
sdmmc_drv 0 0 148500000 0 90
--
sclk_sdio0 1 1 100000000 0 0
sdio0_sample 0 0 50000000 0 0
sdio0_drv 0 0 50000000 0 90
sclk_emmc 1 1 100000000 0 0
emmc_sample 0 0 50000000 0 0
emmc_drv 0 0 50000000 0 180

Next thing that will come is some dts changes that will make use of these new clocks, and eventually mmc code will be changed to tune with these clocks. You can see some WIP on https://chromium-review.googlesource.com/#/c/227240

Changes in v4:
- Changed set_phase to 22.5 increments, it seems better for tuning, better at splitting up big ranges where we might have used an iffy phase from the middle.
- renamed ROCKCHIP_MMC_DELAY_ELEMENT_PSEC
- saner mask of 0x07ff
- only set ROCKCHIP_MMC_DELAYNUM_OFFSET when we need it

Changes in v3:
- renamed everything internal from phase to just mmc_clock or mmc
- added RK3288_MMC_CLKGEN_DIV instead of the magic number
- added new paragraph to commit message

Changes in v2:
- fixed my cc/to list
- removed dangling #DEFINE DEBUG

Alexandru M Stan (2):
clk: rockchip: add bindings for the mmc clocks
clk: rockchip: Add support for the mmc clock phases using the
framework

 drivers/clk/rockchip/Makefile          |   1 +
 drivers/clk/rockchip/clk-mmc-phase.c   | 154 +++++++++++++++++++++++++++++++++
 drivers/clk/rockchip/clk-rk3288.c      |  12 +++
 drivers/clk/rockchip/clk.c             |   8 ++
 drivers/clk/rockchip/clk.h             |  23 +++++
 include/dt-bindings/clock/rk3288-cru.h |  10 +++
 6 files changed, 208 insertions(+)
 create mode 100644 drivers/clk/rockchip/clk-mmc-phase.c
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#1 lore raw

PATCH v4 1/2 clk: rockchip: add bindings for the mmc clocks

These clocks represent the physical clocks (including phases) and they will later be used for clock phase tuning.

---
Changes in v4: None
Changes in v3: None
Changes in v2: None

 include/dt-bindings/clock/rk3288-cru.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/dt-bindings/clock/rk3288-cru.h +10 -0
index 100a08c..b4e9142 100644
@@ -72,6 +72,16 @@
 #define SCLK_HEVC_CABAC		111
 #define SCLK_HEVC_CORE		112
 
+#define SCLK_SDMMC_DRV		113
+#define SCLK_SDIO0_DRV		114
+#define SCLK_SDIO1_DRV		115
+#define SCLK_EMMC_DRV		116
+
+#define SCLK_SDMMC_SAMPLE	117
+#define SCLK_SDIO0_SAMPLE	118
+#define SCLK_SDIO1_SAMPLE	119
+#define SCLK_EMMC_SAMPLE	120
+
 #define DCLK_VOP0		190
 #define DCLK_VOP1		191
 
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#2 lore raw

PATCH v4 2/2 clk: rockchip: Add support for the mmc clock phases using the framework

In reply to Alexandru M Stan

This patch adds the 2 physical clocks for the mmc (drive and sample). They're mostly there for the phase properties, but they also show the true clock (by dividing by RK3288_MMC_CLKGEN_DIV).

The drive and sample phases are generated by dividing an upstream parent clock by 2, this allows us to adjust the phase by 90 deg.

There's also an option to have up to 255 delay elements (40-80 picoseconds long). This driver uses those elements (under the assumption that they're 60 ps long) to generate approximate 22.5 degrees options. 67.5 (22.5*3) might be as high as 90 deg if the delay elements are as big as 80 ps, so a finer division (smaller than 22.5) was not picked because the phase might not be monotonic anymore.

---
Changes in v4:
- Changed set_phase to 22.5 increments, it seems better for tuning, better at splitting up big ranges where we might have used an iffy phase from the middle.
- renamed ROCKCHIP_MMC_DELAY_ELEMENT_PSEC
- saner mask of 0x07ff
- only set ROCKCHIP_MMC_DELAYNUM_OFFSET when we need it

Changes in v3:
- renamed everything internal from phase to just mmc_clock or mmc
- added RK3288_MMC_CLKGEN_DIV instead of the magic number
- added new paragraph to commit message

Changes in v2:
- fixed my cc/to list
- removed dangling #DEFINE DEBUG

 drivers/clk/rockchip/Makefile        |   1 +
 drivers/clk/rockchip/clk-mmc-phase.c | 154 +++++++++++++++++++++++++++++++++++
 drivers/clk/rockchip/clk-rk3288.c    |  12 +++
 drivers/clk/rockchip/clk.c           |   8 ++
 drivers/clk/rockchip/clk.h           |  23 ++++++
 5 files changed, 198 insertions(+)
 create mode 100644 drivers/clk/rockchip/clk-mmc-phase.c
drivers/clk/rockchip/Makefile +1 -0
index bd8514d..2714097 100644
@@ -6,6 +6,7 @@ obj-y	+= clk-rockchip.o
 obj-y	+= clk.o
 obj-y	+= clk-pll.o
 obj-y	+= clk-cpu.o
+obj-y	+= clk-mmc-phase.o
 obj-$(CONFIG_RESET_CONTROLLER)	+= softrst.o
 
 obj-y	+= clk-rk3188.o
drivers/clk/rockchip/clk-mmc-phase.c new file +154 -0

154 lines not on this page · raw message

drivers/clk/rockchip/clk-rk3288.c +12 -0
index 2327829..f415f84 100644
@@ -483,6 +483,18 @@ static struct rockchip_clk_branch rk3288_clk_branches[] __initdata = {
 			RK3288_CLKSEL_CON(12), 14, 2, MFLAGS, 8, 6, DFLAGS,
 			RK3288_CLKGATE_CON(13), 3, GFLAGS),
 
+	MMC(SCLK_SDMMC_DRV,    "sdmmc_drv",    "sclk_sdmmc", RK3288_SDMMC_CON0, 1),
+	MMC(SCLK_SDMMC_SAMPLE, "sdmmc_sample", "sclk_sdmmc", RK3288_SDMMC_CON1, 0),
+
+	MMC(SCLK_SDIO0_DRV,    "sdio0_drv",    "sclk_sdio0", RK3288_SDIO0_CON0, 1),
+	MMC(SCLK_SDIO0_SAMPLE, "sdio0_sample", "sclk_sdio0", RK3288_SDIO0_CON1, 0),
+
+	MMC(SCLK_SDIO1_DRV,    "sdio1_drv",    "sclk_sdio1", RK3288_SDIO1_CON0, 1),
+	MMC(SCLK_SDIO1_SAMPLE, "sdio1_sample", "sclk_sdio1", RK3288_SDIO1_CON1, 0),
+
+	MMC(SCLK_EMMC_DRV,     "emmc_drv",     "sclk_emmc",  RK3288_EMMC_CON0,  1),
+	MMC(SCLK_EMMC_SAMPLE,  "emmc_sample",  "sclk_emmc",  RK3288_EMMC_CON1,  0),
+
 	COMPOSITE(0, "sclk_tspout", mux_tspout_p, 0,
 			RK3288_CLKSEL_CON(35), 14, 2, MFLAGS, 8, 5, DFLAGS,
 			RK3288_CLKGATE_CON(4), 11, GFLAGS),
drivers/clk/rockchip/clk.c +8 -0
index 1e68bff..ae143f8 100644
@@ -279,6 +279,14 @@ void __init rockchip_clk_register_branches(
 				list->gate_offset, list->gate_shift,
 				list->gate_flags, flags, &clk_lock);
 			break;
+		case branch_mmc:
+			clk = rockchip_clk_register_mmc(
+				list->name,
+				list->parent_names, list->num_parents,
+				reg_base + list->muxdiv_offset,
+				list->div_shift
+			);
+			break;
 		}
 
 		/* none of the cases above matched */
drivers/clk/rockchip/clk.h +23 -0
index ca009ab..136e8a9 100644
@@ -48,6 +48,14 @@
 #define RK3288_GLB_SRST_SND		0x1b4
 #define RK3288_SOFTRST_CON(x)		(x * 0x4 + 0x1b8)
 #define RK3288_MISC_CON			0x1e8
+#define RK3288_SDMMC_CON0		0x200
+#define RK3288_SDMMC_CON1		0x204
+#define RK3288_SDIO0_CON0		0x208
+#define RK3288_SDIO0_CON1		0x20c
+#define RK3288_SDIO1_CON0		0x210
+#define RK3288_SDIO1_CON1		0x214
+#define RK3288_EMMC_CON0		0x218
+#define RK3288_EMMC_CON1		0x21c
 
 enum rockchip_pll_type {
 	pll_rk3066,
@@ -152,6 +160,10 @@ struct clk *rockchip_clk_register_cpuclk(const char *name,
 			const struct rockchip_cpuclk_rate_table *rates,
 			int nrates, void __iomem *reg_base, spinlock_t *lock);
 
+struct clk *rockchip_clk_register_mmc(const char *name,
+				const char **parent_names, u8 num_parents,
+				void __iomem *reg, int shift);
+
 #define PNAME(x) static const char *x[] __initconst
 
 enum rockchip_clk_branch_type {
@@ -160,6 +172,7 @@ enum rockchip_clk_branch_type {
 	branch_divider,
 	branch_fraction_divider,
 	branch_gate,
+	branch_mmc,
 };
 
 struct rockchip_clk_branch {
@@ -352,6 +365,16 @@ struct rockchip_clk_branch {
 		.gate_flags	= gf,				\
 	}
 
+#define MMC(_id, cname, pname, offset, shift)			\
+	{							\
+		.id		= _id,				\
+		.branch_type	= branch_mmc,			\
+		.name		= cname,			\
+		.parent_names	= (const char *[]){ pname },	\
+		.num_parents	= 1,				\
+		.muxdiv_offset	= offset,			\
+		.div_shift	= shift,			\
+	}
 
 void rockchip_clk_init(struct device_node *np, void __iomem *base,
 		       unsigned long nr_clks);
Signature · 1 line
2.2.0.rc0.207.ga3a616c
maintainer Applied
#3 lore raw
In reply to Alexandru M Stan

Am Mittwoch, 26. November 2014, 17:30:25 schrieb Alexandru M Stan:

Quoted 9 lines

For now all I have is the getter and setter for the phase, nothing that uses it (that is ready). You can test the getter like this:
localhost ~ # cat /sys/kernel/debug/clk/clk_summary|grep sample -C 1
sclk_sdio1 0 0 24000000 0

0 sdio1_sample                       0            0    12000000          0
0 sdio1_drv                          0            0    12000000          0

90 --
sclk_sdmmc 1 1 297000000 0 0
sdmmc_sample 0 0 148500000 0

134

Quoted 1 line

sdmmc_drv 0 0 148500000 0

90

Quoted 4 lines

--
sclk_sdio0 1 1 100000000 0 0
sdio0_sample 0 0 50000000 0 0
sdio0_drv 0 0 50000000 0

90

Quoted 3 lines

sclk_emmc 1 1 100000000 0 0
emmc_sample 0 0 50000000 0 0
emmc_drv 0 0 50000000 0

180

Quoted 5 lines

Next thing that will come is some dts changes that will make use of these new clocks, and eventually mmc code will be changed to tune with these clocks. You can see some WIP on
https://chromium-review.googlesource.com/#/c/227240

I've applied both patches to my clk branch.

Heiko