162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * mt8192-afe-clk.h  --  Mediatek 8192 afe clock ctrl definition
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (c) 2020 MediaTek Inc.
662306a36Sopenharmony_ci * Author: Shane Chien <shane.chien@mediatek.com>
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef _MT8192_AFE_CLOCK_CTRL_H_
1062306a36Sopenharmony_ci#define _MT8192_AFE_CLOCK_CTRL_H_
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#define AP_PLL_CON3 0x0014
1362306a36Sopenharmony_ci#define APLL1_CON0 0x0318
1462306a36Sopenharmony_ci#define APLL1_CON1 0x031c
1562306a36Sopenharmony_ci#define APLL1_CON2 0x0320
1662306a36Sopenharmony_ci#define APLL1_CON4 0x0328
1762306a36Sopenharmony_ci#define APLL1_TUNER_CON0 0x0040
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#define APLL2_CON0 0x032c
2062306a36Sopenharmony_ci#define APLL2_CON1 0x0330
2162306a36Sopenharmony_ci#define APLL2_CON2 0x0334
2262306a36Sopenharmony_ci#define APLL2_CON4 0x033c
2362306a36Sopenharmony_ci#define APLL2_TUNER_CON0 0x0044
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#define CLK_CFG_7 0x0080
2662306a36Sopenharmony_ci#define CLK_CFG_8 0x0090
2762306a36Sopenharmony_ci#define CLK_CFG_11 0x00c0
2862306a36Sopenharmony_ci#define CLK_CFG_12 0x00d0
2962306a36Sopenharmony_ci#define CLK_CFG_13 0x00e0
3062306a36Sopenharmony_ci#define CLK_CFG_15 0x0100
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define CLK_AUDDIV_0 0x0320
3362306a36Sopenharmony_ci#define CLK_AUDDIV_2 0x0328
3462306a36Sopenharmony_ci#define CLK_AUDDIV_3 0x0334
3562306a36Sopenharmony_ci#define CLK_AUDDIV_4 0x0338
3662306a36Sopenharmony_ci#define CKSYS_AUD_TOP_CFG 0x032c
3762306a36Sopenharmony_ci#define CKSYS_AUD_TOP_MON 0x0330
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#define PERI_BUS_DCM_CTRL 0x0074
4062306a36Sopenharmony_ci#define MODULE_SW_CG_1_STA 0x0094
4162306a36Sopenharmony_ci#define MODULE_SW_CG_2_STA 0x00ac
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/* CLK_AUDDIV_0 */
4462306a36Sopenharmony_ci#define APLL12_DIV0_PDN_SFT                0
4562306a36Sopenharmony_ci#define APLL12_DIV0_PDN_MASK               0x1
4662306a36Sopenharmony_ci#define APLL12_DIV0_PDN_MASK_SFT           (0x1 << 0)
4762306a36Sopenharmony_ci#define APLL12_DIV1_PDN_SFT                1
4862306a36Sopenharmony_ci#define APLL12_DIV1_PDN_MASK               0x1
4962306a36Sopenharmony_ci#define APLL12_DIV1_PDN_MASK_SFT           (0x1 << 1)
5062306a36Sopenharmony_ci#define APLL12_DIV2_PDN_SFT                2
5162306a36Sopenharmony_ci#define APLL12_DIV2_PDN_MASK               0x1
5262306a36Sopenharmony_ci#define APLL12_DIV2_PDN_MASK_SFT           (0x1 << 2)
5362306a36Sopenharmony_ci#define APLL12_DIV3_PDN_SFT                3
5462306a36Sopenharmony_ci#define APLL12_DIV3_PDN_MASK               0x1
5562306a36Sopenharmony_ci#define APLL12_DIV3_PDN_MASK_SFT           (0x1 << 3)
5662306a36Sopenharmony_ci#define APLL12_DIV4_PDN_SFT                4
5762306a36Sopenharmony_ci#define APLL12_DIV4_PDN_MASK               0x1
5862306a36Sopenharmony_ci#define APLL12_DIV4_PDN_MASK_SFT           (0x1 << 4)
5962306a36Sopenharmony_ci#define APLL12_DIVB_PDN_SFT                5
6062306a36Sopenharmony_ci#define APLL12_DIVB_PDN_MASK               0x1
6162306a36Sopenharmony_ci#define APLL12_DIVB_PDN_MASK_SFT           (0x1 << 5)
6262306a36Sopenharmony_ci#define APLL12_DIV5_PDN_SFT                6
6362306a36Sopenharmony_ci#define APLL12_DIV5_PDN_MASK               0x1
6462306a36Sopenharmony_ci#define APLL12_DIV5_PDN_MASK_SFT           (0x1 << 6)
6562306a36Sopenharmony_ci#define APLL12_DIV6_PDN_SFT                7
6662306a36Sopenharmony_ci#define APLL12_DIV6_PDN_MASK               0x1
6762306a36Sopenharmony_ci#define APLL12_DIV6_PDN_MASK_SFT           (0x1 << 7)
6862306a36Sopenharmony_ci#define APLL12_DIV7_PDN_SFT                8
6962306a36Sopenharmony_ci#define APLL12_DIV7_PDN_MASK               0x1
7062306a36Sopenharmony_ci#define APLL12_DIV7_PDN_MASK_SFT           (0x1 << 8)
7162306a36Sopenharmony_ci#define APLL12_DIV8_PDN_SFT                9
7262306a36Sopenharmony_ci#define APLL12_DIV8_PDN_MASK               0x1
7362306a36Sopenharmony_ci#define APLL12_DIV8_PDN_MASK_SFT           (0x1 << 9)
7462306a36Sopenharmony_ci#define APLL12_DIV9_PDN_SFT                10
7562306a36Sopenharmony_ci#define APLL12_DIV9_PDN_MASK               0x1
7662306a36Sopenharmony_ci#define APLL12_DIV9_PDN_MASK_SFT           (0x1 << 10)
7762306a36Sopenharmony_ci#define APLL_I2S0_MCK_SEL_SFT              16
7862306a36Sopenharmony_ci#define APLL_I2S0_MCK_SEL_MASK             0x1
7962306a36Sopenharmony_ci#define APLL_I2S0_MCK_SEL_MASK_SFT         (0x1 << 16)
8062306a36Sopenharmony_ci#define APLL_I2S1_MCK_SEL_SFT              17
8162306a36Sopenharmony_ci#define APLL_I2S1_MCK_SEL_MASK             0x1
8262306a36Sopenharmony_ci#define APLL_I2S1_MCK_SEL_MASK_SFT         (0x1 << 17)
8362306a36Sopenharmony_ci#define APLL_I2S2_MCK_SEL_SFT              18
8462306a36Sopenharmony_ci#define APLL_I2S2_MCK_SEL_MASK             0x1
8562306a36Sopenharmony_ci#define APLL_I2S2_MCK_SEL_MASK_SFT         (0x1 << 18)
8662306a36Sopenharmony_ci#define APLL_I2S3_MCK_SEL_SFT              19
8762306a36Sopenharmony_ci#define APLL_I2S3_MCK_SEL_MASK             0x1
8862306a36Sopenharmony_ci#define APLL_I2S3_MCK_SEL_MASK_SFT         (0x1 << 19)
8962306a36Sopenharmony_ci#define APLL_I2S4_MCK_SEL_SFT              20
9062306a36Sopenharmony_ci#define APLL_I2S4_MCK_SEL_MASK             0x1
9162306a36Sopenharmony_ci#define APLL_I2S4_MCK_SEL_MASK_SFT         (0x1 << 20)
9262306a36Sopenharmony_ci#define APLL_I2S5_MCK_SEL_SFT              21
9362306a36Sopenharmony_ci#define APLL_I2S5_MCK_SEL_MASK             0x1
9462306a36Sopenharmony_ci#define APLL_I2S5_MCK_SEL_MASK_SFT         (0x1 << 21)
9562306a36Sopenharmony_ci#define APLL_I2S6_MCK_SEL_SFT              22
9662306a36Sopenharmony_ci#define APLL_I2S6_MCK_SEL_MASK             0x1
9762306a36Sopenharmony_ci#define APLL_I2S6_MCK_SEL_MASK_SFT         (0x1 << 22)
9862306a36Sopenharmony_ci#define APLL_I2S7_MCK_SEL_SFT              23
9962306a36Sopenharmony_ci#define APLL_I2S7_MCK_SEL_MASK             0x1
10062306a36Sopenharmony_ci#define APLL_I2S7_MCK_SEL_MASK_SFT         (0x1 << 23)
10162306a36Sopenharmony_ci#define APLL_I2S8_MCK_SEL_SFT              24
10262306a36Sopenharmony_ci#define APLL_I2S8_MCK_SEL_MASK             0x1
10362306a36Sopenharmony_ci#define APLL_I2S8_MCK_SEL_MASK_SFT         (0x1 << 24)
10462306a36Sopenharmony_ci#define APLL_I2S9_MCK_SEL_SFT              25
10562306a36Sopenharmony_ci#define APLL_I2S9_MCK_SEL_MASK             0x1
10662306a36Sopenharmony_ci#define APLL_I2S9_MCK_SEL_MASK_SFT         (0x1 << 25)
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci/* CLK_AUDDIV_2 */
10962306a36Sopenharmony_ci#define APLL12_CK_DIV0_SFT                 0
11062306a36Sopenharmony_ci#define APLL12_CK_DIV0_MASK                0xff
11162306a36Sopenharmony_ci#define APLL12_CK_DIV0_MASK_SFT            (0xff << 0)
11262306a36Sopenharmony_ci#define APLL12_CK_DIV1_SFT                 8
11362306a36Sopenharmony_ci#define APLL12_CK_DIV1_MASK                0xff
11462306a36Sopenharmony_ci#define APLL12_CK_DIV1_MASK_SFT            (0xff << 8)
11562306a36Sopenharmony_ci#define APLL12_CK_DIV2_SFT                 16
11662306a36Sopenharmony_ci#define APLL12_CK_DIV2_MASK                0xff
11762306a36Sopenharmony_ci#define APLL12_CK_DIV2_MASK_SFT            (0xff << 16)
11862306a36Sopenharmony_ci#define APLL12_CK_DIV3_SFT                 24
11962306a36Sopenharmony_ci#define APLL12_CK_DIV3_MASK                0xff
12062306a36Sopenharmony_ci#define APLL12_CK_DIV3_MASK_SFT            (0xff << 24)
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci/* CLK_AUDDIV_3 */
12362306a36Sopenharmony_ci#define APLL12_CK_DIV4_SFT                 0
12462306a36Sopenharmony_ci#define APLL12_CK_DIV4_MASK                0xff
12562306a36Sopenharmony_ci#define APLL12_CK_DIV4_MASK_SFT            (0xff << 0)
12662306a36Sopenharmony_ci#define APLL12_CK_DIVB_SFT                 8
12762306a36Sopenharmony_ci#define APLL12_CK_DIVB_MASK                0xff
12862306a36Sopenharmony_ci#define APLL12_CK_DIVB_MASK_SFT            (0xff << 8)
12962306a36Sopenharmony_ci#define APLL12_CK_DIV5_SFT                 16
13062306a36Sopenharmony_ci#define APLL12_CK_DIV5_MASK                0xff
13162306a36Sopenharmony_ci#define APLL12_CK_DIV5_MASK_SFT            (0xff << 16)
13262306a36Sopenharmony_ci#define APLL12_CK_DIV6_SFT                 24
13362306a36Sopenharmony_ci#define APLL12_CK_DIV6_MASK                0xff
13462306a36Sopenharmony_ci#define APLL12_CK_DIV6_MASK_SFT            (0xff << 24)
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/* CLK_AUDDIV_4 */
13762306a36Sopenharmony_ci#define APLL12_CK_DIV7_SFT                 0
13862306a36Sopenharmony_ci#define APLL12_CK_DIV7_MASK                0xff
13962306a36Sopenharmony_ci#define APLL12_CK_DIV7_MASK_SFT            (0xff << 0)
14062306a36Sopenharmony_ci#define APLL12_CK_DIV8_SFT                 8
14162306a36Sopenharmony_ci#define APLL12_CK_DIV8_MASK                0xff
14262306a36Sopenharmony_ci#define APLL12_CK_DIV8_MASK_SFT            (0xff << 0)
14362306a36Sopenharmony_ci#define APLL12_CK_DIV9_SFT                 16
14462306a36Sopenharmony_ci#define APLL12_CK_DIV9_MASK                0xff
14562306a36Sopenharmony_ci#define APLL12_CK_DIV9_MASK_SFT            (0xff << 0)
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ci/* AUD_TOP_CFG */
14862306a36Sopenharmony_ci#define AUD_TOP_CFG_SFT                    0
14962306a36Sopenharmony_ci#define AUD_TOP_CFG_MASK                   0xffffffff
15062306a36Sopenharmony_ci#define AUD_TOP_CFG_MASK_SFT               (0xffffffff << 0)
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci/* AUD_TOP_MON */
15362306a36Sopenharmony_ci#define AUD_TOP_MON_SFT                    0
15462306a36Sopenharmony_ci#define AUD_TOP_MON_MASK                   0xffffffff
15562306a36Sopenharmony_ci#define AUD_TOP_MON_MASK_SFT               (0xffffffff << 0)
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci/* CLK_AUDDIV_3 */
15862306a36Sopenharmony_ci#define APLL12_CK_DIV5_MSB_SFT             0
15962306a36Sopenharmony_ci#define APLL12_CK_DIV5_MSB_MASK            0xf
16062306a36Sopenharmony_ci#define APLL12_CK_DIV5_MSB_MASK_SFT        (0xf << 0)
16162306a36Sopenharmony_ci#define RESERVED0_SFT                      4
16262306a36Sopenharmony_ci#define RESERVED0_MASK                     0xfffffff
16362306a36Sopenharmony_ci#define RESERVED0_MASK_SFT                 (0xfffffff << 4)
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci/* APLL */
16662306a36Sopenharmony_ci#define APLL1_W_NAME "APLL1"
16762306a36Sopenharmony_ci#define APLL2_W_NAME "APLL2"
16862306a36Sopenharmony_cienum {
16962306a36Sopenharmony_ci	MT8192_APLL1 = 0,
17062306a36Sopenharmony_ci	MT8192_APLL2,
17162306a36Sopenharmony_ci};
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_cienum {
17462306a36Sopenharmony_ci	CLK_AFE = 0,
17562306a36Sopenharmony_ci	CLK_TML,
17662306a36Sopenharmony_ci	CLK_APLL22M,
17762306a36Sopenharmony_ci	CLK_APLL24M,
17862306a36Sopenharmony_ci	CLK_APLL1_TUNER,
17962306a36Sopenharmony_ci	CLK_APLL2_TUNER,
18062306a36Sopenharmony_ci	CLK_NLE,
18162306a36Sopenharmony_ci	CLK_INFRA_SYS_AUDIO,
18262306a36Sopenharmony_ci	CLK_INFRA_AUDIO_26M,
18362306a36Sopenharmony_ci	CLK_MUX_AUDIO,
18462306a36Sopenharmony_ci	CLK_MUX_AUDIOINTBUS,
18562306a36Sopenharmony_ci	CLK_TOP_MAINPLL_D4_D4,
18662306a36Sopenharmony_ci	/* apll related mux */
18762306a36Sopenharmony_ci	CLK_TOP_MUX_AUD_1,
18862306a36Sopenharmony_ci	CLK_TOP_APLL1_CK,
18962306a36Sopenharmony_ci	CLK_TOP_MUX_AUD_2,
19062306a36Sopenharmony_ci	CLK_TOP_APLL2_CK,
19162306a36Sopenharmony_ci	CLK_TOP_MUX_AUD_ENG1,
19262306a36Sopenharmony_ci	CLK_TOP_APLL1_D4,
19362306a36Sopenharmony_ci	CLK_TOP_MUX_AUD_ENG2,
19462306a36Sopenharmony_ci	CLK_TOP_APLL2_D4,
19562306a36Sopenharmony_ci	CLK_TOP_MUX_AUDIO_H,
19662306a36Sopenharmony_ci	CLK_TOP_I2S0_M_SEL,
19762306a36Sopenharmony_ci	CLK_TOP_I2S1_M_SEL,
19862306a36Sopenharmony_ci	CLK_TOP_I2S2_M_SEL,
19962306a36Sopenharmony_ci	CLK_TOP_I2S3_M_SEL,
20062306a36Sopenharmony_ci	CLK_TOP_I2S4_M_SEL,
20162306a36Sopenharmony_ci	CLK_TOP_I2S5_M_SEL,
20262306a36Sopenharmony_ci	CLK_TOP_I2S6_M_SEL,
20362306a36Sopenharmony_ci	CLK_TOP_I2S7_M_SEL,
20462306a36Sopenharmony_ci	CLK_TOP_I2S8_M_SEL,
20562306a36Sopenharmony_ci	CLK_TOP_I2S9_M_SEL,
20662306a36Sopenharmony_ci	CLK_TOP_APLL12_DIV0,
20762306a36Sopenharmony_ci	CLK_TOP_APLL12_DIV1,
20862306a36Sopenharmony_ci	CLK_TOP_APLL12_DIV2,
20962306a36Sopenharmony_ci	CLK_TOP_APLL12_DIV3,
21062306a36Sopenharmony_ci	CLK_TOP_APLL12_DIV4,
21162306a36Sopenharmony_ci	CLK_TOP_APLL12_DIVB,
21262306a36Sopenharmony_ci	CLK_TOP_APLL12_DIV5,
21362306a36Sopenharmony_ci	CLK_TOP_APLL12_DIV6,
21462306a36Sopenharmony_ci	CLK_TOP_APLL12_DIV7,
21562306a36Sopenharmony_ci	CLK_TOP_APLL12_DIV8,
21662306a36Sopenharmony_ci	CLK_TOP_APLL12_DIV9,
21762306a36Sopenharmony_ci	CLK_CLK26M,
21862306a36Sopenharmony_ci	CLK_NUM
21962306a36Sopenharmony_ci};
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_cistruct mtk_base_afe;
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ciint mt8192_init_clock(struct mtk_base_afe *afe);
22462306a36Sopenharmony_ciint mt8192_afe_enable_clock(struct mtk_base_afe *afe);
22562306a36Sopenharmony_civoid mt8192_afe_disable_clock(struct mtk_base_afe *afe);
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ciint mt8192_apll1_enable(struct mtk_base_afe *afe);
22862306a36Sopenharmony_civoid mt8192_apll1_disable(struct mtk_base_afe *afe);
22962306a36Sopenharmony_ci
23062306a36Sopenharmony_ciint mt8192_apll2_enable(struct mtk_base_afe *afe);
23162306a36Sopenharmony_civoid mt8192_apll2_disable(struct mtk_base_afe *afe);
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_ciint mt8192_get_apll_rate(struct mtk_base_afe *afe, int apll);
23462306a36Sopenharmony_ciint mt8192_get_apll_by_rate(struct mtk_base_afe *afe, int rate);
23562306a36Sopenharmony_ciint mt8192_get_apll_by_name(struct mtk_base_afe *afe, const char *name);
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ci/* these will be replaced by using CCF */
23862306a36Sopenharmony_ciint mt8192_mck_enable(struct mtk_base_afe *afe, int mck_id, int rate);
23962306a36Sopenharmony_civoid mt8192_mck_disable(struct mtk_base_afe *afe, int mck_id);
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ciint mt8192_set_audio_int_bus_parent(struct mtk_base_afe *afe,
24262306a36Sopenharmony_ci				    int clk_id);
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci#endif
245