Re: [PATCH v3 4/5] clk: qcom: add video clock controller driver for SM8150

2020-10-13 Thread Stephen Boyd
Quoting Jonathan Marek (2020-09-23 09:06:30)
> Add support for the video clock controller found on SM8150 based devices.
> 
> Derived from the downstream driver.
> 
> Signed-off-by: Jonathan Marek 
> ---

Applied to clk-next


[PATCH v3 4/5] clk: qcom: add video clock controller driver for SM8150

2020-09-23 Thread Jonathan Marek
Add support for the video clock controller found on SM8150 based devices.

Derived from the downstream driver.

Signed-off-by: Jonathan Marek 
---
 drivers/clk/qcom/Kconfig  |   9 +
 drivers/clk/qcom/Makefile |   1 +
 drivers/clk/qcom/videocc-sm8150.c | 276 ++
 3 files changed, 286 insertions(+)
 create mode 100644 drivers/clk/qcom/videocc-sm8150.c

diff --git a/drivers/clk/qcom/Kconfig b/drivers/clk/qcom/Kconfig
index 058327310c25..40d7ee9886c9 100644
--- a/drivers/clk/qcom/Kconfig
+++ b/drivers/clk/qcom/Kconfig
@@ -444,6 +444,15 @@ config SM_GPUCC_8250
  Say Y if you want to support graphics controller devices and
  functionality such as 3D graphics.
 
+config SM_VIDEOCC_8150
+   tristate "SM8150 Video Clock Controller"
+   select SDM_GCC_8150
+   select QCOM_GDSC
+   help
+ Support for the video clock controller on SM8150 devices.
+ Say Y if you want to support video devices and functionality such as
+ video encode and decode.
+
 config SPMI_PMIC_CLKDIV
tristate "SPMI PMIC clkdiv Support"
depends on SPMI || COMPILE_TEST
diff --git a/drivers/clk/qcom/Makefile b/drivers/clk/qcom/Makefile
index 9677e769e7e9..6f4c580d2728 100644
--- a/drivers/clk/qcom/Makefile
+++ b/drivers/clk/qcom/Makefile
@@ -68,6 +68,7 @@ obj-$(CONFIG_SM_GCC_8150) += gcc-sm8150.o
 obj-$(CONFIG_SM_GCC_8250) += gcc-sm8250.o
 obj-$(CONFIG_SM_GPUCC_8150) += gpucc-sm8150.o
 obj-$(CONFIG_SM_GPUCC_8250) += gpucc-sm8250.o
+obj-$(CONFIG_SM_VIDEOCC_8150) += videocc-sm8150.o
 obj-$(CONFIG_SPMI_PMIC_CLKDIV) += clk-spmi-pmic-div.o
 obj-$(CONFIG_KPSS_XCC) += kpss-xcc.o
 obj-$(CONFIG_QCOM_HFPLL) += hfpll.o
diff --git a/drivers/clk/qcom/videocc-sm8150.c 
b/drivers/clk/qcom/videocc-sm8150.c
new file mode 100644
index ..3087e2ec8fd4
--- /dev/null
+++ b/drivers/clk/qcom/videocc-sm8150.c
@@ -0,0 +1,276 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "common.h"
+#include "clk-alpha-pll.h"
+#include "clk-branch.h"
+#include "clk-rcg.h"
+#include "clk-regmap.h"
+#include "reset.h"
+#include "gdsc.h"
+
+enum {
+   P_BI_TCXO,
+   P_CHIP_SLEEP_CLK,
+   P_CORE_BI_PLL_TEST_SE,
+   P_VIDEO_PLL0_OUT_EVEN,
+   P_VIDEO_PLL0_OUT_MAIN,
+   P_VIDEO_PLL0_OUT_ODD,
+};
+
+static struct pll_vco trion_vco[] = {
+   { 24960, 20, 0 },
+};
+
+static struct alpha_pll_config video_pll0_config = {
+   .l = 0x14,
+   .alpha = 0xD555,
+   .config_ctl_val = 0x20485699,
+   .config_ctl_hi_val = 0x2267,
+   .config_ctl_hi1_val = 0x0024,
+   .user_ctl_val = 0x,
+   .user_ctl_hi_val = 0x0805,
+   .user_ctl_hi1_val = 0x00D0,
+};
+
+static struct clk_alpha_pll video_pll0 = {
+   .offset = 0x42c,
+   .vco_table = trion_vco,
+   .num_vco = ARRAY_SIZE(trion_vco),
+   .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_TRION],
+   .clkr = {
+   .hw.init = &(struct clk_init_data){
+   .name = "video_pll0",
+   .parent_data = &(const struct clk_parent_data){
+   .fw_name = "bi_tcxo",
+   },
+   .num_parents = 1,
+   .ops = _alpha_pll_trion_ops,
+   },
+   },
+};
+
+static const struct parent_map video_cc_parent_map_0[] = {
+   { P_BI_TCXO, 0 },
+   { P_VIDEO_PLL0_OUT_MAIN, 1 },
+};
+
+static const struct clk_parent_data video_cc_parent_data_0[] = {
+   { .fw_name = "bi_tcxo" },
+   { .hw = _pll0.clkr.hw },
+};
+
+static const struct freq_tbl ftbl_video_cc_iris_clk_src[] = {
+   F(1920, P_BI_TCXO, 1, 0, 0),
+   F(2, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
+   F(24000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
+   F(33800, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
+   F(36500, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
+   F(44400, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
+   F(53300, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
+   { }
+};
+
+static struct clk_rcg2 video_cc_iris_clk_src = {
+   .cmd_rcgr = 0x7f0,
+   .mnd_width = 0,
+   .hid_width = 5,
+   .parent_map = video_cc_parent_map_0,
+   .freq_tbl = ftbl_video_cc_iris_clk_src,
+   .clkr.hw.init = &(struct clk_init_data){
+   .name = "video_cc_iris_clk_src",
+   .parent_data = video_cc_parent_data_0,
+   .num_parents = ARRAY_SIZE(video_cc_parent_data_0),
+   .flags = CLK_SET_RATE_PARENT,
+   .ops = _rcg2_shared_ops,
+   },
+};
+
+static struct clk_branch video_cc_iris_ahb_clk = {
+   .halt_reg = 0x8f4,
+   .halt_check = BRANCH_VOTED,
+   .clkr = {
+   .enable_reg = 0x8f4,
+   .enable_mask = BIT(0),
+   .hw.init = &(struct clk_init_data){
+