mturney mturney has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
sc7180: Add clock driver
Add support for clock driver for SC7180
Developer/Reviewer, be aware of this patch from Napali: https://review.coreboot.org/c/coreboot/+/31083/6
Change-Id: I3f39252c887c36e8af43bc49289795000e4638d8 Signed-off-by: Taniya Das tdas@codeaurora.org Signed-off-by: srimuc srimuc@codeaurora.org --- M src/soc/qualcomm/sc7180/Makefile.inc M src/soc/qualcomm/sc7180/bootblock.c A src/soc/qualcomm/sc7180/clock.c M src/soc/qualcomm/sc7180/include/soc/addressmap.h A src/soc/qualcomm/sc7180/include/soc/clock.h 5 files changed, 468 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/35496/1
diff --git a/src/soc/qualcomm/sc7180/Makefile.inc b/src/soc/qualcomm/sc7180/Makefile.inc index a973724..60ad516 100644 --- a/src/soc/qualcomm/sc7180/Makefile.inc +++ b/src/soc/qualcomm/sc7180/Makefile.inc @@ -7,12 +7,14 @@ bootblock-y += timer.c bootblock-y += gpio.c bootblock-y += spi.c +bootblock-y += clock.c bootblock-$(CONFIG_DRIVERS_UART) += uart_bitbang.c
################################################################################ verstage-y += timer.c verstage-y += gpio.c verstage-y += spi.c +verstage-y += clock.c verstage-$(CONFIG_DRIVERS_UART) += uart_bitbang.c
################################################################################ @@ -23,6 +25,7 @@ romstage-y += ../common/mmu.c romstage-y += mmu.c romstage-y += spi.c +romstage-y += clock.c romstage-$(CONFIG_DRIVERS_UART) += uart_bitbang.c
################################################################################ @@ -31,6 +34,7 @@ ramstage-y += timer.c ramstage-y += gpio.c ramstage-y += spi.c +ramstage-y += clock.c ramstage-$(CONFIG_DRIVERS_UART) += uart_bitbang.c
################################################################################ diff --git a/src/soc/qualcomm/sc7180/bootblock.c b/src/soc/qualcomm/sc7180/bootblock.c index b9b8660..f073449 100644 --- a/src/soc/qualcomm/sc7180/bootblock.c +++ b/src/soc/qualcomm/sc7180/bootblock.c @@ -14,9 +14,12 @@ */
#include <bootblock_common.h> +#include <soc/clock.h> #include <soc/mmu.h> +#include <soc/clock.h>
void bootblock_soc_init(void) { sc7180_mmu_init(); + clock_init(); } diff --git a/src/soc/qualcomm/sc7180/clock.c b/src/soc/qualcomm/sc7180/clock.c new file mode 100644 index 0000000..0ccbaa6 --- /dev/null +++ b/src/soc/qualcomm/sc7180/clock.c @@ -0,0 +1,251 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2019 Qualcomm Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <assert.h> +#include <commonlib/helpers.h> +#include <device/mmio.h> +#include <soc/clock.h> +#include <types.h> + +#define DIV(div) (2 * div - 1) + +struct clock_config qup_cfg[] = { + { + .hz = 7372800, + .src = SRC_GPLL0_EVEN_300MHZ, + .div = DIV(1), + .m = 384, + .n = 15625, + .d_2 = 15625, + }, + { + .hz = 19200 * KHz, + .src = SRC_XO_19_2MHZ, + .div = DIV(1), + } +}; + +struct clock_config qspi_core_cfg[] = { + { + .hz = 19200 * KHz, + .src = SRC_XO_19_2MHZ, + .div = DIV(1), + }, + { + .hz = 100 * MHz, + .src = SRC_GPLL0_EVEN_300MHZ, + .div = DIV(3), + }, + { + .hz = 150 * MHz, + .src = SRC_GPLL0_EVEN_300MHZ, + .div = DIV(2), + }, + { + .hz = 300 * MHz, + .src = SRC_GPLL0_EVEN_300MHZ, + .div = DIV(1), + } +}; + +static int clock_configure_gpll0(void) +{ + write32(&gcc->gpll0.user_ctl_u, 0x00004805); + + /* Keep existing GPLL0 configuration, in RUN mode @600Mhz. */ + setbits_le32(&gcc->gpll0.user_ctl, + 1 << CLK_CTL_GPLL_PLLOUT_EVEN_SHFT | + 1 << CLK_CTL_GPLL_PLLOUT_MAIN_SHFT | + 1 << CLK_CTL_GPLL_PLLOUT_ODD_SHFT); + + return 0; +} + +static int clock_configure_mnd(struct sc7180_clock *clk, uint32_t m, uint32_t n, + uint32_t d_2) +{ + setbits_le32(&clk->rcg.cfg, + RCG_MODE_DUAL_EDGE << CLK_CTL_CFG_MODE_SHFT); + + write32(&clk->m, m & CLK_CTL_RCG_MND_BMSK); + write32(&clk->n, ~(n-m) & CLK_CTL_RCG_MND_BMSK); + write32(&clk->d_2, ~(d_2) & CLK_CTL_RCG_MND_BMSK); + + return 0; +} + +static int clock_configure_rcg(struct sc7180_rcg *clk, + struct clock_config *clk_cfg, + uint32_t hz, uint32_t num_perfs) +{ + uint32_t reg_val; + uint32_t idx; + + for (idx = 0; idx < num_perfs; idx++) + if (hz <= clk_cfg[idx].hz) + break; + + assert(hz == clk_cfg[idx].hz); + + reg_val = (clk_cfg[idx].src << CLK_CTL_CFG_SRC_SEL_SHFT) | + (clk_cfg[idx].div << CLK_CTL_CFG_SRC_DIV_SHFT); + + /* Set clock config */ + write32(&clk->cfg, reg_val); + + /* Commit config to RCG */ + setbits_le32(&clk->cmd, BIT(CLK_CTL_CMD_UPDATE_SHFT)); + + return 0; +} + +static int clock_configure(struct sc7180_clock *clk, + struct clock_config *clk_cfg, + uint32_t hz, uint32_t num_perfs) +{ + uint32_t reg_val; + uint32_t idx; + + for (idx = 0; idx < num_perfs; idx++) + if (hz <= clk_cfg[idx].hz) + break; + + assert(hz == clk_cfg[idx].hz); + + reg_val = (clk_cfg[idx].src << CLK_CTL_CFG_SRC_SEL_SHFT) | + (clk_cfg[idx].div << CLK_CTL_CFG_SRC_DIV_SHFT); + + /* Set clock config */ + write32(&clk->rcg.cfg, reg_val); + + if (clk_cfg[idx].m != 0) + clock_configure_mnd(clk, clk_cfg[idx].m, clk_cfg[idx].n, + clk_cfg[idx].d_2); + + /* Commit config to RCG*/ + setbits_le32(&clk->rcg.cmd, BIT(CLK_CTL_CMD_UPDATE_SHFT)); + + return 0; +} + +static bool clock_is_off(u32 *cbcr_addr) +{ + return (read32(cbcr_addr) & CLK_CTL_CBC_CLK_OFF_BMSK); +} + +static int clock_enable_vote(void *cbcr_addr, void *vote_addr, + uint32_t vote_bit) +{ + /* Set clock vote bit */ + setbits_le32(vote_addr, BIT(vote_bit)); + + /* Ensure clock is enabled */ + while (clock_is_off(cbcr_addr)) + ; + + return 0; +} + +static int clock_enable(void *cbcr_addr) +{ + /* Set clock enable bit */ + setbits_le32(cbcr_addr, BIT(CLK_CTL_CBC_CLK_EN_SHFT)); + + /* Ensure clock is enabled */ + while (clock_is_off(cbcr_addr)) + ; + + return 0; +} + +void clock_reset_aop(void) +{ + /* Bring AOP out of RESET */ + clrbits_le32(&aoss->aoss_cc_apcs_misc, BIT(AOP_RESET_SHFT)); +} + +void clock_configure_qspi(uint32_t hz) +{ + clock_configure_rcg(&gcc->qspi_core, + qspi_core_cfg, hz, + ARRAY_SIZE(qspi_core_cfg)); + clock_enable(&gcc->qspi_cnoc_ahb_cbcr); + clock_enable(&gcc->qspi_core_cbcr); +} + +int clock_reset_bcr(void *bcr_addr, bool reset) +{ + struct sc7180_bcr *bcr = bcr_addr; + + if (reset) + setbits_le32(bcr, BIT(CLK_CTL_BCR_BLK_ARES_SHFT)); + else + clrbits_le32(bcr, BIT(CLK_CTL_BCR_BLK_ARES_SHFT)); + + return 0; +} + +void clock_configure_qup(int qup, uint32_t hz) +{ + int s = qup % QUP_WRAP1_S0; + struct sc7180_qupv3_clock *qup_clk = qup < QUP_WRAP1_S0 ? + (struct sc7180_qupv3_clock *)&gcc->qup_wrap0_s[s] : + (struct sc7180_qupv3_clock *)&gcc->qup_wrap1_s[s]; + + clock_configure(&qup_clk->clk, qup_cfg, hz, ARRAY_SIZE(qup_cfg)); +} + +void clock_enable_qup(int qup) +{ + int s = qup % QUP_WRAP1_S0; + int clk_en_off = qup < QUP_WRAP1_S0 ? + QUPV3_WRAP0_CLK_ENA_S(s) : QUPV3_WRAP1_CLK_ENA_S(s); + struct sc7180_qupv3_clock *qup_clk = qup < QUP_WRAP1_S0 ? + &gcc->qup_wrap0_s[s] : &gcc->qup_wrap1_s[s]; + + clock_enable_vote(&qup_clk->clk, &gcc->apcs_clk_br_en1, + clk_en_off); +} + +void clock_init(void) +{ + clock_configure_gpll0(); + + clock_enable_vote(&gcc->qup_wrap0_core_2x_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP0_CORE_2X_CLK_ENA); + clock_enable_vote(&gcc->qup_wrap0_core_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP0_CORE_CLK_ENA); + clock_enable_vote(&gcc->qup_wrap0_m_ahb_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP_0_M_AHB_CLK_ENA); + clock_enable_vote(&gcc->qup_wrap0_s_ahb_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP_0_S_AHB_CLK_ENA); + + clock_enable_vote(&gcc->qup_wrap1_core_2x_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP1_CORE_2X_CLK_ENA); + clock_enable_vote(&gcc->qup_wrap1_core_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP1_CORE_CLK_ENA); + clock_enable_vote(&gcc->qup_wrap1_m_ahb_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP_1_M_AHB_CLK_ENA); + clock_enable_vote(&gcc->qup_wrap1_s_ahb_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP_1_S_AHB_CLK_ENA); +} diff --git a/src/soc/qualcomm/sc7180/include/soc/addressmap.h b/src/soc/qualcomm/sc7180/include/soc/addressmap.h index 93f0481..308b2fb 100644 --- a/src/soc/qualcomm/sc7180/include/soc/addressmap.h +++ b/src/soc/qualcomm/sc7180/include/soc/addressmap.h @@ -1,7 +1,7 @@ /* * This file is part of the coreboot project. * - * Copyright (c) 2018-2019 Qualcomm Technologies + * Copyright (c) 2019 Qualcomm Technologies * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -18,4 +18,8 @@
#include <stdint.h>
-#endif /* _SOC_QUALCOMM_SC7180_ADDRESS_MAP_H_ */ +#define AOSS_CC_BASE 0x0C2A0000 +#define GCC_BASE 0x00100000 +#define QSPI_BASE 0x088DC000 + +#endif /* __SOC_QUALCOMM_SC7180_ADDRESS_MAP_H__ */ diff --git a/src/soc/qualcomm/sc7180/include/soc/clock.h b/src/soc/qualcomm/sc7180/include/soc/clock.h new file mode 100644 index 0000000..d90779b --- /dev/null +++ b/src/soc/qualcomm/sc7180/include/soc/clock.h @@ -0,0 +1,204 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2019 Qualcomm Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <soc/addressmap.h> +#include <types.h> + +#ifndef __SOC_QUALCOMM_SC7180_CLOCK_H__ +#define __SOC_QUALCOMM_SC7180_CLOCK_H__ + +#define QUPV3_WRAP_0_M_AHB_CLK_ENA 6 +#define QUPV3_WRAP_0_S_AHB_CLK_ENA 7 +#define QUPV3_WRAP0_CORE_2X_CLK_ENA 9 +#define QUPV3_WRAP0_CORE_CLK_ENA 8 +#define QUPV3_WRAP1_CORE_2X_CLK_ENA 18 +#define QUPV3_WRAP1_CORE_CLK_ENA 19 +#define QUPV3_WRAP_1_M_AHB_CLK_ENA 20 +#define QUPV3_WRAP_1_S_AHB_CLK_ENA 21 +#define QUPV3_WRAP0_CLK_ENA_S(idx) (10 + idx) +#define QUPV3_WRAP1_CLK_ENA_S(idx) (22 + idx) + +#define GPLL0_EVEN_HZ (300 * MHz) +#define GPLL0_MAIN_HZ (600 * MHz) +#define QUP_WRAP_CORE_2X_19_2MHZ (19200 * KHz) + +#define SRC_XO_19_2MHZ 0 +#define SRC_GPLL0_MAIN_600MHZ 1 +#define SRC_GPLL0_EVEN_300MHZ 6 + +#define AOP_RESET_SHFT 0 +#define RCG_MODE_DUAL_EDGE 2 + +struct sc7180_rcg { + u32 cmd; + u32 cfg; +}; + +struct sc7180_clock { + u32 cbcr; + struct sc7180_rcg rcg; + u32 m; + u32 n; + u32 d_2; +}; + +struct sc7180_qupv3_clock { + struct sc7180_clock clk; + u8 _res[0x130 - 0x18]; +}; + +struct sc7180_gpll { + u32 mode; + u32 l_val; + u32 cal_l_val; + u32 user_ctl; + u32 user_ctl_u; + u32 config_ctl; + u32 config_ctl_u; + u32 test_ctl; + u32 test_ctl_u; + u8 _res[0x1000 - 0x24]; +}; + +struct sc7180_gcc { + struct sc7180_gpll gpll0; + u8 _res0[0xf000 - 0x1000]; + u32 usb30_prim_bcr; + u8 _res3[0x17000 - 0xf004]; + u32 qup_wrap0_bcr; + u32 qup_wrap0_m_ahb_cbcr; + u32 qup_wrap0_s_ahb_cbcr; + u32 qup_wrap0_core_cbcr; + u32 qup_wrap0_core_cdivr; + u32 qup_wrap0_core_2x_cbcr; + struct sc7180_rcg qup_wrap0_core_2x; + u8 _res4[0x17030 - 0x17020]; + struct sc7180_qupv3_clock qup_wrap0_s[6]; + u8 _res5[0x18000 - 0x17750]; + u32 qup_wrap1_bcr; + u32 qup_wrap1_core_2x_cbcr; + u32 qup_wrap1_core_cbcr; + u32 qup_wrap1_m_ahb_cbcr; + u32 qup_wrap1_s_ahb_cbcr; + struct sc7180_qupv3_clock qup_wrap1_s[6]; + u8 _res6[0x18994 - 0x18734]; + u32 qup_wrap1_core_cdivr; + u8 _res7[0x4b000 - 0x18998]; + u32 qspi_bcr; + u32 qspi_cnoc_ahb_cbcr; + u32 qspi_core_cbcr; + struct sc7180_rcg qspi_core; + u8 _res8[0x50000 - 0x4b014]; + u32 usb3_phy_prim_bcr; + u32 usb3phy_phy_prim_bcr; + u32 usb3_dp_phy_prim_bcr; + u32 usb3_phy_sec_bcr; + u32 usb3phy_phy_sec_bcr; + u32 usb3_dp_phy_sec_bcr; + u8 _res9[0x52008 - 0x50018]; + u32 apcs_clk_br_en1; + u8 _res10[0x1000000 - 0x5200c]; +}; + +struct sc7180_aoss { + u8 _res[0x5002c]; + u32 aoss_cc_apcs_misc; +}; + +enum clk_ctl_gpll_user_ctl { + CLK_CTL_GPLL_PLLOUT_EVEN_BMSK = 0x2, + CLK_CTL_GPLL_PLLOUT_MAIN_SHFT = 0, + CLK_CTL_GPLL_PLLOUT_EVEN_SHFT = 1, + CLK_CTL_GPLL_PLLOUT_ODD_SHFT = 2 +}; + +enum clk_ctl_cfg_rcgr { + CLK_CTL_CFG_HW_CTL_BMSK = 0x100000, + CLK_CTL_CFG_HW_CTL_SHFT = 20, + CLK_CTL_CFG_MODE_BMSK = 0x3000, + CLK_CTL_CFG_MODE_SHFT = 12, + CLK_CTL_CFG_SRC_SEL_BMSK = 0x700, + CLK_CTL_CFG_SRC_SEL_SHFT = 8, + CLK_CTL_CFG_SRC_DIV_BMSK = 0x1F, + CLK_CTL_CFG_SRC_DIV_SHFT = 0 +}; + +enum clk_ctl_cmd_rcgr { + CLK_CTL_CMD_ROOT_OFF_BMSK = 0x80000000, + CLK_CTL_CMD_ROOT_OFF_SHFT = 31, + CLK_CTL_CMD_ROOT_EN_BMSK = 0x2, + CLK_CTL_CMD_ROOT_EN_SHFT = 1, + CLK_CTL_CMD_UPDATE_BMSK = 0x1, + CLK_CTL_CMD_UPDATE_SHFT = 0 +}; + +enum clk_ctl_cbcr { + CLK_CTL_CBC_CLK_OFF_BMSK = 0x80000000, + CLK_CTL_CBC_CLK_OFF_SHFT = 31, + CLK_CTL_CBC_CLK_EN_BMSK = 0x1, + CLK_CTL_CBC_CLK_EN_SHFT = 0 +}; + +enum clk_ctl_rcg_mnd { + CLK_CTL_RCG_MND_BMSK = 0xFFFF, + CLK_CTL_RCG_MND_SHFT = 0, +}; + +enum clk_ctl_bcr { + CLK_CTL_BCR_BLK_ARES_BMSK = 0x1, + CLK_CTL_BCR_BLK_ARES_SHFT = 0, +}; + +enum clk_qup { + QUP_WRAP0_S0, + QUP_WRAP0_S1, + QUP_WRAP0_S2, + QUP_WRAP0_S3, + QUP_WRAP0_S4, + QUP_WRAP0_S5, + QUP_WRAP1_S0, + QUP_WRAP1_S1, + QUP_WRAP1_S2, + QUP_WRAP1_S3, + QUP_WRAP1_S4, + QUP_WRAP1_S5, +}; + +struct clock_config { + uint32_t hz; + uint8_t src; + uint8_t div; + uint16_t m; + uint16_t n; + uint16_t d_2; +}; + +struct mdss_clock_config { + const char *clk_name; + uintptr_t rcgr; + uintptr_t cbcr; +}; + +static struct sc7180_gcc *const gcc = (void *)GCC_BASE; +static struct sc7180_aoss *const aoss = (void *)AOSS_CC_BASE; + +void clock_init(void); +void clock_reset_aop(void); +void clock_configure_qspi(uint32_t hz); +int clock_reset_bcr(void *bcr_addr, bool reset); +void clock_configure_qup(int qup, uint32_t hz); +void clock_enable_qup(int qup); + +#endif // __SOC_QUALCOMM_SC7180_CLOCK_H__
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
Patch Set 4:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35496/4//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/35496/4//COMMIT_MSG@16 PS4, Line 16: srimuc Please use a full name.
Hello build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35496
to look at the new patch set (#5).
Change subject: sc7180: Add clock driver ......................................................................
sc7180: Add clock driver
Add support for clock driver for SC7180
Developer/Reviewer, be aware of this patch from Napali: https://review.coreboot.org/c/coreboot/+/31083/6
Change-Id: I3f39252c887c36e8af43bc49289795000e4638d8 Signed-off-by: Taniya Das tdas@codeaurora.org --- M src/soc/qualcomm/sc7180/Makefile.inc M src/soc/qualcomm/sc7180/bootblock.c A src/soc/qualcomm/sc7180/clock.c M src/soc/qualcomm/sc7180/include/soc/addressmap.h A src/soc/qualcomm/sc7180/include/soc/clock.h 5 files changed, 468 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/35496/5
Hello build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35496
to look at the new patch set (#7).
Change subject: sc7180: Add clock driver ......................................................................
sc7180: Add clock driver
Add support for clock driver for SC7180
Developer/Reviewer, be aware of this patch from Napali: https://review.coreboot.org/c/coreboot/+/31083/6
Change-Id: I3f39252c887c36e8af43bc49289795000e4638d8 Signed-off-by: Taniya Das tdas@codeaurora.org --- M src/soc/qualcomm/sc7180/Makefile.inc M src/soc/qualcomm/sc7180/bootblock.c A src/soc/qualcomm/sc7180/clock.c M src/soc/qualcomm/sc7180/include/soc/addressmap.h A src/soc/qualcomm/sc7180/include/soc/clock.h 5 files changed, 468 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/35496/7
mturney mturney has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
Patch Set 9:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35496/4//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/35496/4//COMMIT_MSG@16 PS4, Line 16: srimuc
Please use a full name.
Done
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
Patch Set 9:
(13 comments)
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/boo... File src/soc/qualcomm/sc7180/bootblock.c:
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/boo... PS9, Line 19: #include <soc/clock.h> Twice?
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... File src/soc/qualcomm/sc7180/clock.c:
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 34: 19200 * KHz This can be SRC_XO_HZ after you define it (see other file). Maybe put /* 19.2KHz */ as a comment next to it.
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 42: 19200 * KHz This too.
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 57: 300 * MHz This can be GPLL0_EVEN_HZ.
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 65: 0x00004805 This magic number needs to be split up into its individual fields and written with named constants instead.
Note that we just introduced a fancy new API to make accessing registers with bit fields easier and safer... see a demonstration from another SoC in CB:35471. With that, rather than doing
#define SOMEBIT_SHIFT 5 #define SOMEFIELD_SHIFT 7 #define SOMEFIELD_MASK 0xf
clrsetbits_le32(®, 1 << SOMEBIT_SHIFT | SOMEFIELD_MASK << SOMEFIELD_SHIFT, 1 << SOMEBIT_SHIFT | 2 << SOMEFIELD_SHIFT);
you can just do
DECLARE_BIT(SOMEBIT, 5) DECLARE_FIELD(SOMEFIELD, 10, 7)
SET32_BITFIELDS(®, SOMEBIT, 1, SOMEFIELD, 2);
We're still testing this out so it's not a requirement yet, but feel free to use it if you want to. I think it makes drivers that access a lot of registers with bitfields much easier to follow. (For consistency you should try to only use one paradigm per file though... so if you introduce it here you should also use it for other registers with multiple fields like gpll.user_ctl or rcg.cfg.)
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 89: static int clock_configure_rcg(struct sc7180_rcg *clk, Why is this here? We didn't have this in the SDM845 code, and the registers are the same.
Just use clock_configure() instead... the convention is that if the clk_cfg does not have an 'm' value, it's a pure RCG clock (without MND registers), and it should work fine for this case.
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 176: clrbits_le32(&aoss->aoss_cc_apcs_misc, BIT(AOP_RESET_SHFT)); This is the code that's needed without the "bring up AOP in QC-SEC to lock down some stuff" hack that we had in SDM845. Is that hack no longer needed on this SoC? Please explain why.
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 202: int s = qup % QUP_WRAP1_S0; Ohh... yeah... that was a bug in the SDM845 code. Good catch.
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 204: (struct sc7180_qupv3_clock *) Cast should be unnecessary?
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/inc... File src/soc/qualcomm/sc7180/include/soc/clock.h:
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/inc... PS9, Line 34: nit: please align tabs
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/inc... PS9, Line 35: #define QUP_WRAP_CORE_2X_19_2MHZ (19200 * KHz) I think it makes more sense to call this SRC_XO_HZ, because it's really the frequency of the source oscillator (regardless of whether you use it for the QUPs or something else).
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/inc... PS9, Line 49: struct sc7180_clock { Hmmm... all of this doesn't really fit great (and didn't on SDM845 either). Let's remodel this a bit. I'd suggest you get rid of sc7180_rcg (because there's never an RCG without CBCR), you change this to just
struct sc7180_clock { u32 cbcr; u32 rcg_cmd; u32 rcg_cfg; }
and then you add another
struct sc7180_clock_mnd { struct sc7180_clock clock; u32 m; u32 n; u32 d_2; }
configure_clock() would take a struct sc7180_clock, but cast it to sc7180_clock_mnd if the 'm' field in clk_cfg is non-zero.
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/inc... PS9, Line 85: u32 qup_wrap0_core_2x_cbcr; ...with the above, you can just model this as an sc7180_clock.
Hello build bot (Jenkins), Patrick Georgi, Martin Roth, Taniya Das,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35496
to look at the new patch set (#12).
Change subject: sc7180: Add clock driver ......................................................................
sc7180: Add clock driver
Add support for clock driver for SC7180
Developer/Reviewer, be aware of this patch from Napali: https://review.coreboot.org/c/coreboot/+/31083/6
Change-Id: I3f39252c887c36e8af43bc49289795000e4638d8 Signed-off-by: Taniya Das tdas@codeaurora.org --- M src/soc/qualcomm/sc7180/Makefile.inc M src/soc/qualcomm/sc7180/bootblock.c A src/soc/qualcomm/sc7180/clock.c M src/soc/qualcomm/sc7180/include/soc/addressmap.h A src/soc/qualcomm/sc7180/include/soc/clock.h 5 files changed, 463 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/35496/12
Taniya Das has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
Patch Set 12:
(13 comments)
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/boo... File src/soc/qualcomm/sc7180/bootblock.c:
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/boo... PS9, Line 19: #include <soc/clock.h>
Twice?
Done
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... File src/soc/qualcomm/sc7180/clock.c:
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 34: 19200 * KHz
This can be SRC_XO_HZ after you define it (see other file). Maybe put /* 19. […]
Done
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 42: 19200 * KHz
This too.
Done
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 57: 300 * MHz
This can be GPLL0_EVEN_HZ.
Done
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 65: 0x00004805
This magic number needs to be split up into its individual fields and written with named constants i […]
Thanks Julius. I understand that we should use the individual bits. Would take a look at the new implementation.
But would it be okay to go about with the magic number for now?
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 89: static int clock_configure_rcg(struct sc7180_rcg *clk,
Why is this here? We didn't have this in the SDM845 code, and the registers are the same. […]
Done
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 176: clrbits_le32(&aoss->aoss_cc_apcs_misc, BIT(AOP_RESET_SHFT));
This is the code that's needed without the "bring up AOP in QC-SEC to lock down some stuff" hack tha […]
Yes, I am checking internally and would update.
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 202: int s = qup % QUP_WRAP1_S0;
Ohh... yeah... that was a bug in the SDM845 code. Good catch.
Ack
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 204: (struct sc7180_qupv3_clock *)
Cast should be unnecessary?
Done
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/inc... File src/soc/qualcomm/sc7180/include/soc/clock.h:
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/inc... PS9, Line 34:
nit: please align tabs
Done
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/inc... PS9, Line 35: #define QUP_WRAP_CORE_2X_19_2MHZ (19200 * KHz)
I think it makes more sense to call this SRC_XO_HZ, because it's really the frequency of the source […]
Done
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/inc... PS9, Line 49: struct sc7180_clock {
Hmmm... all of this doesn't really fit great (and didn't on SDM845 either). […]
Done
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/inc... PS9, Line 85: u32 qup_wrap0_core_2x_cbcr;
...with the above, you can just model this as an sc7180_clock.
Done
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... File src/soc/qualcomm/sc7180/clock.c:
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 65: 0x00004805
Thanks Julius. I understand that we should use the individual bits. […]
You're welcome to use either the new (SET32_BITFIELDS) or the old way (just shifting and ORing the bits directly like for user_ctl below), but you need to use either one of those with the individual bits named and separated out. We can't submit code with magic numbers.
Ravi kumar has uploaded a new patch set (#14) to the change originally created by mturney mturney. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
sc7180: Add clock driver
Add support for clock driver for SC7180
Developer/Reviewer, be aware of this patch from Napali: https://review.coreboot.org/c/coreboot/+/31083/6
Change-Id: I3f39252c887c36e8af43bc49289795000e4638d8 Signed-off-by: Taniya Das tdas@codeaurora.org --- M src/soc/qualcomm/sc7180/Makefile.inc M src/soc/qualcomm/sc7180/bootblock.c A src/soc/qualcomm/sc7180/clock.c M src/soc/qualcomm/sc7180/include/soc/addressmap.h A src/soc/qualcomm/sc7180/include/soc/clock.h 5 files changed, 440 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/35496/14
Hello Ravi kumar, build bot (Jenkins), Taniya Das, Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35496
to look at the new patch set (#15).
Change subject: sc7180: Add clock driver ......................................................................
sc7180: Add clock driver
Add support for clock driver for SC7180
Developer/Reviewer, be aware of this patch from Napali: https://review.coreboot.org/c/coreboot/+/31083/6
Change-Id: I3f39252c887c36e8af43bc49289795000e4638d8 Signed-off-by: Taniya Das tdas@codeaurora.org --- M src/soc/qualcomm/sc7180/Makefile.inc M src/soc/qualcomm/sc7180/bootblock.c A src/soc/qualcomm/sc7180/clock.c M src/soc/qualcomm/sc7180/include/soc/addressmap.h A src/soc/qualcomm/sc7180/include/soc/clock.h 5 files changed, 439 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/35496/15
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
Patch Set 15:
(6 comments)
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/bo... File src/soc/qualcomm/sc7180/bootblock.c:
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/bo... PS15, Line 19: #include <soc/clock.h> Still twice
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/cl... File src/soc/qualcomm/sc7180/clock.c:
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/cl... PS15, Line 82: write32(&((struct sc7180_clock_mnd *)clk)->m, m & Please do something like
struct sc7180_clock_mnd *mnd = (struct sc7180_clock_mnd *)clk;
at the top of the function and then just use that.
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/cl... PS15, Line 183: &gcc->qup_wrap1_s[s]; nit: maybe fit both sides of the colon on one line now?
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/cl... PS15, Line 185: clock_configure((struct sc7180_clock *)&qup_clk->clk, qup_cfg, hz, Please pass &qup_clk->clk.clock rather than casting (maybe we should fix those names a bit to look less weird next to each other).
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/in... File src/soc/qualcomm/sc7180/include/soc/clock.h:
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/in... PS15, Line 58: struct sc7180_clock_mnd clk; nit: Maybe call this 'mnd' or 'mnd_clk' to be easier to tell it apart from the struct sc7180_clock it contains.
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/in... PS15, Line 110: }; nit: it would be good to add some offset checks for this structure so we can be certain we don't mess up the ranges when we make changes like this. something like
check_member(sc7180_gcc, qup_wrap0_bcr, 0x17000); check_member(sc7180_gcc, qup_wrap1_bcr, 0x18000); check_member(sc7180_gcc, usb3_phy_prim_bcr, 0x50000);
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
Patch Set 15:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/in... File src/soc/qualcomm/sc7180/include/soc/clock.h:
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/in... PS15, Line 110: };
nit: it would be good to add some offset checks for this structure so we can be certain we don't mes […]
edit: Oh, I guess CB:35503 is already doing some of that
Hello Ravi kumar, build bot (Jenkins), Taniya Das, Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35496
to look at the new patch set (#16).
Change subject: sc7180: Add clock driver ......................................................................
sc7180: Add clock driver
Add support for clock driver for SC7180
Developer/Reviewer, be aware of this patch from Napali: https://review.coreboot.org/c/coreboot/+/31083/6
Change-Id: I3f39252c887c36e8af43bc49289795000e4638d8 Signed-off-by: Taniya Das tdas@codeaurora.org --- M src/soc/qualcomm/sc7180/Makefile.inc M src/soc/qualcomm/sc7180/bootblock.c A src/soc/qualcomm/sc7180/clock.c M src/soc/qualcomm/sc7180/include/soc/addressmap.h A src/soc/qualcomm/sc7180/include/soc/clock.h 5 files changed, 438 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/35496/16
Hello Ravi kumar, build bot (Jenkins), Taniya Das, Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35496
to look at the new patch set (#17).
Change subject: sc7180: Add clock driver ......................................................................
sc7180: Add clock driver
Add support for clock driver for SC7180
Developer/Reviewer, be aware of this patch from Napali: https://review.coreboot.org/c/coreboot/+/31083/6
Change-Id: I3f39252c887c36e8af43bc49289795000e4638d8 Signed-off-by: Taniya Das tdas@codeaurora.org --- M src/soc/qualcomm/sc7180/Makefile.inc M src/soc/qualcomm/sc7180/bootblock.c A src/soc/qualcomm/sc7180/clock.c M src/soc/qualcomm/sc7180/include/soc/addressmap.h A src/soc/qualcomm/sc7180/include/soc/clock.h 5 files changed, 445 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/35496/17
Hello Ravi kumar, build bot (Jenkins), Taniya Das, Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35496
to look at the new patch set (#18).
Change subject: sc7180: Add clock driver ......................................................................
sc7180: Add clock driver
Add support for clock driver for SC7180
Developer/Reviewer, be aware of this patch from Napali: https://review.coreboot.org/c/coreboot/+/31083/6
Change-Id: I3f39252c887c36e8af43bc49289795000e4638d8 Signed-off-by: Taniya Das tdas@codeaurora.org --- M src/soc/qualcomm/sc7180/Makefile.inc M src/soc/qualcomm/sc7180/bootblock.c A src/soc/qualcomm/sc7180/clock.c M src/soc/qualcomm/sc7180/include/soc/addressmap.h A src/soc/qualcomm/sc7180/include/soc/clock.h 5 files changed, 445 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/35496/18
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
Patch Set 18:
Note that there are still unresolved comments from Patch Set 15, just wanna make sure we're not accidentally waiting on each other here.
Hello Ravi kumar, build bot (Jenkins), Taniya Das, Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35496
to look at the new patch set (#20).
Change subject: sc7180: Add clock driver ......................................................................
sc7180: Add clock driver
Add support for clock driver for SC7180
Developer/Reviewer, be aware of this patch from Napali: https://review.coreboot.org/c/coreboot/+/31083/6
Change-Id: I3f39252c887c36e8af43bc49289795000e4638d8 Signed-off-by: Taniya Das tdas@codeaurora.org --- M src/soc/qualcomm/sc7180/Makefile.inc M src/soc/qualcomm/sc7180/bootblock.c A src/soc/qualcomm/sc7180/clock.c M src/soc/qualcomm/sc7180/include/soc/addressmap.h A src/soc/qualcomm/sc7180/include/soc/clock.h 5 files changed, 448 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/35496/20
Taniya Das has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
Patch Set 20:
(5 comments)
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/cl... File src/soc/qualcomm/sc7180/clock.c:
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/cl... PS15, Line 82: write32(&((struct sc7180_clock_mnd *)clk)->m, m &
Please do something like […]
Done
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/cl... PS15, Line 183: &gcc->qup_wrap1_s[s];
nit: maybe fit both sides of the colon on one line now?
Done
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/cl... PS15, Line 185: clock_configure((struct sc7180_clock *)&qup_clk->clk, qup_cfg, hz,
Please pass &qup_clk->clk. […]
Done
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/in... File src/soc/qualcomm/sc7180/include/soc/clock.h:
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/in... PS15, Line 58: struct sc7180_clock_mnd clk;
nit: Maybe call this 'mnd' or 'mnd_clk' to be easier to tell it apart from the struct sc7180_clock i […]
Done
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/in... PS15, Line 110: };
edit: Oh, I guess CB:35503 is already doing some of that
Done
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
Patch Set 20: Code-Review+2
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
Patch Set 20:
(3 comments)
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/bo... File src/soc/qualcomm/sc7180/bootblock.c:
https://review.coreboot.org/c/coreboot/+/35496/15/src/soc/qualcomm/sc7180/bo... PS15, Line 19: #include <soc/clock.h>
Still twice
Ack
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... File src/soc/qualcomm/sc7180/clock.c:
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 65: 0x00004805
You're welcome to use either the new (SET32_BITFIELDS) or the old way (just shifting and ORing the b […]
Ack
https://review.coreboot.org/c/coreboot/+/35496/9/src/soc/qualcomm/sc7180/clo... PS9, Line 176: clrbits_le32(&aoss->aoss_cc_apcs_misc, BIT(AOP_RESET_SHFT));
Yes, I am checking internally and would update.
Ack
Julius Werner has submitted this change. ( https://review.coreboot.org/c/coreboot/+/35496 )
Change subject: sc7180: Add clock driver ......................................................................
sc7180: Add clock driver
Add support for clock driver for SC7180
Developer/Reviewer, be aware of this patch from Napali: https://review.coreboot.org/c/coreboot/+/31083/6
Change-Id: I3f39252c887c36e8af43bc49289795000e4638d8 Signed-off-by: Taniya Das tdas@codeaurora.org Reviewed-on: https://review.coreboot.org/c/coreboot/+/35496 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Julius Werner jwerner@chromium.org --- M src/soc/qualcomm/sc7180/Makefile.inc M src/soc/qualcomm/sc7180/bootblock.c A src/soc/qualcomm/sc7180/clock.c M src/soc/qualcomm/sc7180/include/soc/addressmap.h A src/soc/qualcomm/sc7180/include/soc/clock.h 5 files changed, 448 insertions(+), 1 deletion(-)
Approvals: build bot (Jenkins): Verified Julius Werner: Looks good to me, approved
diff --git a/src/soc/qualcomm/sc7180/Makefile.inc b/src/soc/qualcomm/sc7180/Makefile.inc index 6d2a3e7..6b492d5 100644 --- a/src/soc/qualcomm/sc7180/Makefile.inc +++ b/src/soc/qualcomm/sc7180/Makefile.inc @@ -8,12 +8,14 @@ bootblock-y += spi.c bootblock-y += gpio.c bootblock-$(CONFIG_DRIVERS_UART) += uart_bitbang.c +bootblock-y += clock.c
################################################################################ verstage-y += timer.c verstage-y += spi.c verstage-y += gpio.c verstage-$(CONFIG_DRIVERS_UART) += uart_bitbang.c +verstage-y += clock.c
################################################################################ romstage-y += cbmem.c @@ -25,6 +27,7 @@ romstage-y += spi.c romstage-y += gpio.c romstage-$(CONFIG_DRIVERS_UART) += uart_bitbang.c +romstage-y += clock.c
################################################################################ ramstage-y += soc.c @@ -32,6 +35,7 @@ ramstage-y += spi.c ramstage-y += gpio.c ramstage-$(CONFIG_DRIVERS_UART) += uart_bitbang.c +ramstage-y += clock.c
################################################################################
diff --git a/src/soc/qualcomm/sc7180/bootblock.c b/src/soc/qualcomm/sc7180/bootblock.c index b9b8660..bf80bff 100644 --- a/src/soc/qualcomm/sc7180/bootblock.c +++ b/src/soc/qualcomm/sc7180/bootblock.c @@ -14,9 +14,11 @@ */
#include <bootblock_common.h> +#include <soc/clock.h> #include <soc/mmu.h>
void bootblock_soc_init(void) { sc7180_mmu_init(); + clock_init(); } diff --git a/src/soc/qualcomm/sc7180/clock.c b/src/soc/qualcomm/sc7180/clock.c new file mode 100644 index 0000000..97b7b28 --- /dev/null +++ b/src/soc/qualcomm/sc7180/clock.c @@ -0,0 +1,227 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2019 Qualcomm Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <assert.h> +#include <commonlib/helpers.h> +#include <device/mmio.h> +#include <soc/clock.h> +#include <types.h> + +#define DIV(div) (2 * div - 1) + +struct clock_config qup_cfg[] = { + { + .hz = 7372800, + .src = SRC_GPLL0_EVEN_300MHZ, + .div = DIV(1), + .m = 384, + .n = 15625, + .d_2 = 15625, + }, + { + .hz = SRC_XO_HZ, /* 19.2KHz */ + .src = SRC_XO_19_2MHZ, + .div = DIV(1), + } +}; + +struct clock_config qspi_core_cfg[] = { + { + .hz = SRC_XO_HZ, /* 19.2KHz */ + .src = SRC_XO_19_2MHZ, + .div = DIV(1), + }, + { + .hz = 100 * MHz, + .src = SRC_GPLL0_EVEN_300MHZ, + .div = DIV(3), + }, + { + .hz = 150 * MHz, + .src = SRC_GPLL0_EVEN_300MHZ, + .div = DIV(2), + }, + { + .hz = GPLL0_EVEN_HZ, /* 300MHz */ + .src = SRC_GPLL0_EVEN_300MHZ, + .div = DIV(1), + } +}; + +static int clock_configure_gpll0(void) +{ + setbits_le32(&gcc->gpll0.user_ctl_u, 1 << SCALE_FREQ_SHFT); + + /* Keep existing GPLL0 configuration, in RUN mode @600Mhz. */ + setbits_le32(&gcc->gpll0.user_ctl, + 1 << CLK_CTL_GPLL_PLLOUT_EVEN_SHFT | + 1 << CLK_CTL_GPLL_PLLOUT_MAIN_SHFT | + 1 << CLK_CTL_GPLL_PLLOUT_ODD_SHFT); + + return 0; +} + +static int clock_configure_mnd(struct sc7180_clock *clk, uint32_t m, uint32_t n, + uint32_t d_2) +{ + struct sc7180_mnd_clock *mnd = (struct sc7180_mnd_clock *)clk; + setbits_le32(&clk->rcg_cfg, + RCG_MODE_DUAL_EDGE << CLK_CTL_CFG_MODE_SHFT); + + write32(&mnd->m, m & CLK_CTL_RCG_MND_BMSK); + write32(&mnd->n, ~(n-m) & CLK_CTL_RCG_MND_BMSK); + write32(&mnd->d_2, ~(d_2) & CLK_CTL_RCG_MND_BMSK); + + return 0; +} + +static int clock_configure(struct sc7180_clock *clk, + struct clock_config *clk_cfg, + uint32_t hz, uint32_t num_perfs) +{ + uint32_t reg_val; + uint32_t idx; + + for (idx = 0; idx < num_perfs; idx++) + if (hz <= clk_cfg[idx].hz) + break; + + assert(hz == clk_cfg[idx].hz); + + reg_val = (clk_cfg[idx].src << CLK_CTL_CFG_SRC_SEL_SHFT) | + (clk_cfg[idx].div << CLK_CTL_CFG_SRC_DIV_SHFT); + + /* Set clock config */ + write32(&clk->rcg_cfg, reg_val); + + if (clk_cfg[idx].m != 0) + clock_configure_mnd(clk, clk_cfg[idx].m, clk_cfg[idx].n, + clk_cfg[idx].d_2); + + /* Commit config to RCG*/ + setbits_le32(&clk->rcg_cmd, BIT(CLK_CTL_CMD_UPDATE_SHFT)); + + return 0; +} + +static bool clock_is_off(u32 *cbcr_addr) +{ + return (read32(cbcr_addr) & CLK_CTL_CBC_CLK_OFF_BMSK); +} + +static int clock_enable_vote(void *cbcr_addr, void *vote_addr, + uint32_t vote_bit) +{ + /* Set clock vote bit */ + setbits_le32(vote_addr, BIT(vote_bit)); + + /* Ensure clock is enabled */ + while (clock_is_off(cbcr_addr)) + ; + + return 0; +} + +static int clock_enable(void *cbcr_addr) +{ + /* Set clock enable bit */ + setbits_le32(cbcr_addr, BIT(CLK_CTL_CBC_CLK_EN_SHFT)); + + /* Ensure clock is enabled */ + while (clock_is_off(cbcr_addr)) + ; + + return 0; +} + +void clock_reset_aop(void) +{ + /* Bring AOP out of RESET */ + clrbits_le32(&aoss->aoss_cc_apcs_misc, BIT(AOP_RESET_SHFT)); +} + +void clock_configure_qspi(uint32_t hz) +{ + clock_configure(&gcc->qspi_core, + qspi_core_cfg, hz, + ARRAY_SIZE(qspi_core_cfg)); + clock_enable(&gcc->qspi_cnoc_ahb_cbcr); + clock_enable(&gcc->qspi_core.cbcr); +} + +int clock_reset_bcr(void *bcr_addr, bool reset) +{ + struct sc7180_bcr *bcr = bcr_addr; + + if (reset) + setbits_le32(bcr, BIT(CLK_CTL_BCR_BLK_ARES_SHFT)); + else + clrbits_le32(bcr, BIT(CLK_CTL_BCR_BLK_ARES_SHFT)); + + return 0; +} + +void clock_configure_qup(int qup, uint32_t hz) +{ + int s = qup % QUP_WRAP1_S0; + struct sc7180_qupv3_clock *qup_clk = qup < QUP_WRAP1_S0 ? + &gcc->qup_wrap0_s[s] : &gcc->qup_wrap1_s[s]; + + clock_configure(&qup_clk->mnd_clk.clock, qup_cfg, hz, + ARRAY_SIZE(qup_cfg)); +} + +void clock_enable_qup(int qup) +{ + int s = qup % QUP_WRAP1_S0; + int clk_en_off = qup < QUP_WRAP1_S0 ? + QUPV3_WRAP0_CLK_ENA_S(s) : QUPV3_WRAP1_CLK_ENA_S(s); + struct sc7180_qupv3_clock *qup_clk = qup < QUP_WRAP1_S0 ? + &gcc->qup_wrap0_s[s] : &gcc->qup_wrap1_s[s]; + + clock_enable_vote(&qup_clk->mnd_clk, &gcc->apcs_clk_br_en1, + clk_en_off); +} + +void clock_init(void) +{ + clock_configure_gpll0(); + + clock_enable_vote(&gcc->qup_wrap0_core_2x.cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP0_CORE_2X_CLK_ENA); + clock_enable_vote(&gcc->qup_wrap0_core_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP0_CORE_CLK_ENA); + clock_enable_vote(&gcc->qup_wrap0_m_ahb_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP_0_M_AHB_CLK_ENA); + clock_enable_vote(&gcc->qup_wrap0_s_ahb_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP_0_S_AHB_CLK_ENA); + + clock_enable_vote(&gcc->qup_wrap1_core_2x_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP1_CORE_2X_CLK_ENA); + clock_enable_vote(&gcc->qup_wrap1_core_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP1_CORE_CLK_ENA); + clock_enable_vote(&gcc->qup_wrap1_m_ahb_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP_1_M_AHB_CLK_ENA); + clock_enable_vote(&gcc->qup_wrap1_s_ahb_cbcr, + &gcc->apcs_clk_br_en1, + QUPV3_WRAP_1_S_AHB_CLK_ENA); +} diff --git a/src/soc/qualcomm/sc7180/include/soc/addressmap.h b/src/soc/qualcomm/sc7180/include/soc/addressmap.h index ffacf55..e394189 100644 --- a/src/soc/qualcomm/sc7180/include/soc/addressmap.h +++ b/src/soc/qualcomm/sc7180/include/soc/addressmap.h @@ -1,7 +1,7 @@ /* * This file is part of the coreboot project. * - * Copyright (c) 2018-2019 Qualcomm Technologies + * Copyright (c) 2019 Qualcomm Technologies * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and diff --git a/src/soc/qualcomm/sc7180/include/soc/clock.h b/src/soc/qualcomm/sc7180/include/soc/clock.h new file mode 100644 index 0000000..39cde8c --- /dev/null +++ b/src/soc/qualcomm/sc7180/include/soc/clock.h @@ -0,0 +1,214 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2019 Qualcomm Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <soc/addressmap.h> +#include <types.h> + +#ifndef __SOC_QUALCOMM_SC7180_CLOCK_H__ +#define __SOC_QUALCOMM_SC7180_CLOCK_H__ + +#define QUPV3_WRAP_0_M_AHB_CLK_ENA 6 +#define QUPV3_WRAP_0_S_AHB_CLK_ENA 7 +#define QUPV3_WRAP0_CORE_2X_CLK_ENA 9 +#define QUPV3_WRAP0_CORE_CLK_ENA 8 +#define QUPV3_WRAP1_CORE_2X_CLK_ENA 18 +#define QUPV3_WRAP1_CORE_CLK_ENA 19 +#define QUPV3_WRAP_1_M_AHB_CLK_ENA 20 +#define QUPV3_WRAP_1_S_AHB_CLK_ENA 21 +#define QUPV3_WRAP0_CLK_ENA_S(idx) (10 + idx) +#define QUPV3_WRAP1_CLK_ENA_S(idx) (22 + idx) + +#define SRC_XO_HZ (19200 * KHz) +#define GPLL0_EVEN_HZ (300 * MHz) +#define GPLL0_MAIN_HZ (600 * MHz) + +#define SRC_XO_19_2MHZ 0 +#define SRC_GPLL0_MAIN_600MHZ 1 +#define SRC_GPLL0_EVEN_300MHZ 6 + +#define AOP_RESET_SHFT 0 +#define RCG_MODE_DUAL_EDGE 2 + +#define SCALE_FREQ_SHFT 11 + +struct sc7180_clock { + u32 cbcr; + u32 rcg_cmd; + u32 rcg_cfg; +}; + +struct sc7180_mnd_clock { + struct sc7180_clock clock; + u32 m; + u32 n; + u32 d_2; +}; + +struct sc7180_qupv3_clock { + struct sc7180_mnd_clock mnd_clk; + u8 _res[0x130 - 0x18]; +}; + +struct sc7180_gpll { + u32 mode; + u32 l_val; + u32 cal_l_val; + u32 user_ctl; + u32 user_ctl_u; + u32 config_ctl; + u32 config_ctl_u; + u32 test_ctl; + u32 test_ctl_u; + u8 _res[0x1000 - 0x24]; +}; + +struct sc7180_gcc { + struct sc7180_gpll gpll0; + u8 _res0[0xf000 - 0x1000]; + u32 usb30_prim_bcr; + u8 _res1[0x17000 - 0xf004]; + u32 qup_wrap0_bcr; + u32 qup_wrap0_m_ahb_cbcr; + u32 qup_wrap0_s_ahb_cbcr; + u32 qup_wrap0_core_cbcr; + u32 qup_wrap0_core_cdivr; + struct sc7180_clock qup_wrap0_core_2x; + u8 _res2[0x17030 - 0x17020]; + struct sc7180_qupv3_clock qup_wrap0_s[6]; + u8 _res3[0x18000 - 0x17750]; + u32 qup_wrap1_bcr; + u32 qup_wrap1_core_2x_cbcr; + u32 qup_wrap1_core_cbcr; + u32 qup_wrap1_m_ahb_cbcr; + u32 qup_wrap1_s_ahb_cbcr; + struct sc7180_qupv3_clock qup_wrap1_s[6]; + u8 _res4[0x18994 - 0x18734]; + u32 qup_wrap1_core_cdivr; + u8 _res5[0x26000 - 0x18998]; + u32 qusb2phy_prim_bcr; + u8 _res6[0x4b000 - 0x26004]; + u32 qspi_bcr; + u32 qspi_cnoc_ahb_cbcr; + struct sc7180_clock qspi_core; + u8 _res7[0x50000 - 0x4b014]; + u32 usb3_phy_prim_bcr; + u32 usb3phy_phy_prim_bcr; + u32 usb3_dp_phy_prim_bcr; + u32 usb3_phy_sec_bcr; + u32 usb3phy_phy_sec_bcr; + u32 usb3_dp_phy_sec_bcr; + u8 _res8[0x52008 - 0x50018]; + u32 apcs_clk_br_en1; + u8 _res9[0x1000000 - 0x5200c]; +}; +check_member(sc7180_gcc, usb30_prim_bcr, 0xf000); +check_member(sc7180_gcc, qup_wrap0_bcr, 0x17000); +check_member(sc7180_gcc, qup_wrap1_bcr, 0x18000); +check_member(sc7180_gcc, qup_wrap1_core_cdivr, 0x18994); +check_member(sc7180_gcc, qusb2phy_prim_bcr, 0x26000); +check_member(sc7180_gcc, usb3phy_phy_prim_bcr, 0x50004); +check_member(sc7180_gcc, usb3_phy_prim_bcr, 0x50000); +check_member(sc7180_gcc, apcs_clk_br_en1, 0x52008); + +struct sc7180_aoss { + u8 _res[0x5002c]; + u32 aoss_cc_apcs_misc; +}; + +enum clk_ctl_gpll_user_ctl { + CLK_CTL_GPLL_PLLOUT_EVEN_BMSK = 0x2, + CLK_CTL_GPLL_PLLOUT_MAIN_SHFT = 0, + CLK_CTL_GPLL_PLLOUT_EVEN_SHFT = 1, + CLK_CTL_GPLL_PLLOUT_ODD_SHFT = 2 +}; + +enum clk_ctl_cfg_rcgr { + CLK_CTL_CFG_HW_CTL_BMSK = 0x100000, + CLK_CTL_CFG_HW_CTL_SHFT = 20, + CLK_CTL_CFG_MODE_BMSK = 0x3000, + CLK_CTL_CFG_MODE_SHFT = 12, + CLK_CTL_CFG_SRC_SEL_BMSK = 0x700, + CLK_CTL_CFG_SRC_SEL_SHFT = 8, + CLK_CTL_CFG_SRC_DIV_BMSK = 0x1F, + CLK_CTL_CFG_SRC_DIV_SHFT = 0 +}; + +enum clk_ctl_cmd_rcgr { + CLK_CTL_CMD_ROOT_OFF_BMSK = 0x80000000, + CLK_CTL_CMD_ROOT_OFF_SHFT = 31, + CLK_CTL_CMD_ROOT_EN_BMSK = 0x2, + CLK_CTL_CMD_ROOT_EN_SHFT = 1, + CLK_CTL_CMD_UPDATE_BMSK = 0x1, + CLK_CTL_CMD_UPDATE_SHFT = 0 +}; + +enum clk_ctl_cbcr { + CLK_CTL_CBC_CLK_OFF_BMSK = 0x80000000, + CLK_CTL_CBC_CLK_OFF_SHFT = 31, + CLK_CTL_CBC_CLK_EN_BMSK = 0x1, + CLK_CTL_CBC_CLK_EN_SHFT = 0 +}; + +enum clk_ctl_rcg_mnd { + CLK_CTL_RCG_MND_BMSK = 0xFFFF, + CLK_CTL_RCG_MND_SHFT = 0, +}; + +enum clk_ctl_bcr { + CLK_CTL_BCR_BLK_ARES_BMSK = 0x1, + CLK_CTL_BCR_BLK_ARES_SHFT = 0, +}; + +enum clk_qup { + QUP_WRAP0_S0, + QUP_WRAP0_S1, + QUP_WRAP0_S2, + QUP_WRAP0_S3, + QUP_WRAP0_S4, + QUP_WRAP0_S5, + QUP_WRAP1_S0, + QUP_WRAP1_S1, + QUP_WRAP1_S2, + QUP_WRAP1_S3, + QUP_WRAP1_S4, + QUP_WRAP1_S5, +}; + +struct clock_config { + uint32_t hz; + uint8_t src; + uint8_t div; + uint16_t m; + uint16_t n; + uint16_t d_2; +}; + +struct mdss_clock_config { + const char *clk_name; + uintptr_t rcgr; + uintptr_t cbcr; +}; + +static struct sc7180_gcc *const gcc = (void *)GCC_BASE; +static struct sc7180_aoss *const aoss = (void *)AOSS_CC_BASE; + +void clock_init(void); +void clock_reset_aop(void); +void clock_configure_qspi(uint32_t hz); +int clock_reset_bcr(void *bcr_addr, bool reset); +void clock_configure_qup(int qup, uint32_t hz); +void clock_enable_qup(int qup); + +#endif // __SOC_QUALCOMM_SC7180_CLOCK_H__