xref: /openbmc/linux/drivers/platform/x86/intel/pmc/tgl.c (revision 3386ee827c6279ac922dd7c24be86019363b6ce1)
192f530edSGayatri Kammela // SPDX-License-Identifier: GPL-2.0
292f530edSGayatri Kammela /*
392f530edSGayatri Kammela  * This file contains platform specific structure definitions
492f530edSGayatri Kammela  * and init function used by Tiger Lake PCH.
592f530edSGayatri Kammela  *
692f530edSGayatri Kammela  * Copyright (c) 2022, Intel Corporation.
792f530edSGayatri Kammela  * All Rights Reserved.
892f530edSGayatri Kammela  *
992f530edSGayatri Kammela  */
1092f530edSGayatri Kammela 
1192f530edSGayatri Kammela #include "core.h"
1292f530edSGayatri Kammela 
1392f530edSGayatri Kammela #define ACPI_S0IX_DSM_UUID		"57a6512e-3979-4e9d-9708-ff13b2508972"
1492f530edSGayatri Kammela #define ACPI_GET_LOW_MODE_REGISTERS	1
1592f530edSGayatri Kammela 
1692f530edSGayatri Kammela const struct pmc_bit_map tgl_pfear_map[] = {
1792f530edSGayatri Kammela 	{"PSF9",		BIT(0)},
1892f530edSGayatri Kammela 	{"RES_66",		BIT(1)},
1992f530edSGayatri Kammela 	{"RES_67",		BIT(2)},
2092f530edSGayatri Kammela 	{"RES_68",		BIT(3)},
2192f530edSGayatri Kammela 	{"RES_69",		BIT(4)},
2292f530edSGayatri Kammela 	{"RES_70",		BIT(5)},
2392f530edSGayatri Kammela 	{"TBTLSX",		BIT(6)},
2492f530edSGayatri Kammela 	{}
2592f530edSGayatri Kammela };
2692f530edSGayatri Kammela 
2792f530edSGayatri Kammela const struct pmc_bit_map *ext_tgl_pfear_map[] = {
2892f530edSGayatri Kammela 	/*
2992f530edSGayatri Kammela 	 * Check intel_pmc_core_ids[] users of tgl_reg_map for
3092f530edSGayatri Kammela 	 * a list of core SoCs using this.
3192f530edSGayatri Kammela 	 */
3292f530edSGayatri Kammela 	cnp_pfear_map,
3392f530edSGayatri Kammela 	tgl_pfear_map,
3492f530edSGayatri Kammela 	NULL
3592f530edSGayatri Kammela };
3692f530edSGayatri Kammela 
3792f530edSGayatri Kammela const struct pmc_bit_map tgl_clocksource_status_map[] = {
3892f530edSGayatri Kammela 	{"USB2PLL_OFF_STS",			BIT(18)},
3992f530edSGayatri Kammela 	{"PCIe/USB3.1_Gen2PLL_OFF_STS",		BIT(19)},
4092f530edSGayatri Kammela 	{"PCIe_Gen3PLL_OFF_STS",		BIT(20)},
4192f530edSGayatri Kammela 	{"OPIOPLL_OFF_STS",			BIT(21)},
4292f530edSGayatri Kammela 	{"OCPLL_OFF_STS",			BIT(22)},
4392f530edSGayatri Kammela 	{"MainPLL_OFF_STS",			BIT(23)},
4492f530edSGayatri Kammela 	{"MIPIPLL_OFF_STS",			BIT(24)},
4592f530edSGayatri Kammela 	{"Fast_XTAL_Osc_OFF_STS",		BIT(25)},
4692f530edSGayatri Kammela 	{"AC_Ring_Osc_OFF_STS",			BIT(26)},
4792f530edSGayatri Kammela 	{"MC_Ring_Osc_OFF_STS",			BIT(27)},
4892f530edSGayatri Kammela 	{"SATAPLL_OFF_STS",			BIT(29)},
4992f530edSGayatri Kammela 	{"XTAL_USB2PLL_OFF_STS",		BIT(31)},
5092f530edSGayatri Kammela 	{}
5192f530edSGayatri Kammela };
5292f530edSGayatri Kammela 
5392f530edSGayatri Kammela const struct pmc_bit_map tgl_power_gating_status_map[] = {
5492f530edSGayatri Kammela 	{"CSME_PG_STS",				BIT(0)},
5592f530edSGayatri Kammela 	{"SATA_PG_STS",				BIT(1)},
5692f530edSGayatri Kammela 	{"xHCI_PG_STS",				BIT(2)},
5792f530edSGayatri Kammela 	{"UFSX2_PG_STS",			BIT(3)},
5892f530edSGayatri Kammela 	{"OTG_PG_STS",				BIT(5)},
5992f530edSGayatri Kammela 	{"SPA_PG_STS",				BIT(6)},
6092f530edSGayatri Kammela 	{"SPB_PG_STS",				BIT(7)},
6192f530edSGayatri Kammela 	{"SPC_PG_STS",				BIT(8)},
6292f530edSGayatri Kammela 	{"SPD_PG_STS",				BIT(9)},
6392f530edSGayatri Kammela 	{"SPE_PG_STS",				BIT(10)},
6492f530edSGayatri Kammela 	{"SPF_PG_STS",				BIT(11)},
6592f530edSGayatri Kammela 	{"LSX_PG_STS",				BIT(13)},
6692f530edSGayatri Kammela 	{"P2SB_PG_STS",				BIT(14)},
6792f530edSGayatri Kammela 	{"PSF_PG_STS",				BIT(15)},
6892f530edSGayatri Kammela 	{"SBR_PG_STS",				BIT(16)},
6992f530edSGayatri Kammela 	{"OPIDMI_PG_STS",			BIT(17)},
7092f530edSGayatri Kammela 	{"THC0_PG_STS",				BIT(18)},
7192f530edSGayatri Kammela 	{"THC1_PG_STS",				BIT(19)},
7292f530edSGayatri Kammela 	{"GBETSN_PG_STS",			BIT(20)},
7392f530edSGayatri Kammela 	{"GBE_PG_STS",				BIT(21)},
7492f530edSGayatri Kammela 	{"LPSS_PG_STS",				BIT(22)},
7592f530edSGayatri Kammela 	{"MMP_UFSX2_PG_STS",			BIT(23)},
7692f530edSGayatri Kammela 	{"MMP_UFSX2B_PG_STS",			BIT(24)},
7792f530edSGayatri Kammela 	{"FIA_PG_STS",				BIT(25)},
7892f530edSGayatri Kammela 	{}
7992f530edSGayatri Kammela };
8092f530edSGayatri Kammela 
8192f530edSGayatri Kammela const struct pmc_bit_map tgl_d3_status_map[] = {
8292f530edSGayatri Kammela 	{"ADSP_D3_STS",				BIT(0)},
8392f530edSGayatri Kammela 	{"SATA_D3_STS",				BIT(1)},
8492f530edSGayatri Kammela 	{"xHCI0_D3_STS",			BIT(2)},
8592f530edSGayatri Kammela 	{"xDCI1_D3_STS",			BIT(5)},
8692f530edSGayatri Kammela 	{"SDX_D3_STS",				BIT(6)},
8792f530edSGayatri Kammela 	{"EMMC_D3_STS",				BIT(7)},
8892f530edSGayatri Kammela 	{"IS_D3_STS",				BIT(8)},
8992f530edSGayatri Kammela 	{"THC0_D3_STS",				BIT(9)},
9092f530edSGayatri Kammela 	{"THC1_D3_STS",				BIT(10)},
9192f530edSGayatri Kammela 	{"GBE_D3_STS",				BIT(11)},
9292f530edSGayatri Kammela 	{"GBE_TSN_D3_STS",			BIT(12)},
9392f530edSGayatri Kammela 	{}
9492f530edSGayatri Kammela };
9592f530edSGayatri Kammela 
9692f530edSGayatri Kammela const struct pmc_bit_map tgl_vnn_req_status_map[] = {
9792f530edSGayatri Kammela 	{"GPIO_COM0_VNN_REQ_STS",		BIT(1)},
9892f530edSGayatri Kammela 	{"GPIO_COM1_VNN_REQ_STS",		BIT(2)},
9992f530edSGayatri Kammela 	{"GPIO_COM2_VNN_REQ_STS",		BIT(3)},
10092f530edSGayatri Kammela 	{"GPIO_COM3_VNN_REQ_STS",		BIT(4)},
10192f530edSGayatri Kammela 	{"GPIO_COM4_VNN_REQ_STS",		BIT(5)},
10292f530edSGayatri Kammela 	{"GPIO_COM5_VNN_REQ_STS",		BIT(6)},
10392f530edSGayatri Kammela 	{"Audio_VNN_REQ_STS",			BIT(7)},
10492f530edSGayatri Kammela 	{"ISH_VNN_REQ_STS",			BIT(8)},
10592f530edSGayatri Kammela 	{"CNVI_VNN_REQ_STS",			BIT(9)},
10692f530edSGayatri Kammela 	{"eSPI_VNN_REQ_STS",			BIT(10)},
10792f530edSGayatri Kammela 	{"Display_VNN_REQ_STS",			BIT(11)},
10892f530edSGayatri Kammela 	{"DTS_VNN_REQ_STS",			BIT(12)},
10992f530edSGayatri Kammela 	{"SMBUS_VNN_REQ_STS",			BIT(14)},
11092f530edSGayatri Kammela 	{"CSME_VNN_REQ_STS",			BIT(15)},
11192f530edSGayatri Kammela 	{"SMLINK0_VNN_REQ_STS",			BIT(16)},
11292f530edSGayatri Kammela 	{"SMLINK1_VNN_REQ_STS",			BIT(17)},
11392f530edSGayatri Kammela 	{"CLINK_VNN_REQ_STS",			BIT(20)},
11492f530edSGayatri Kammela 	{"DCI_VNN_REQ_STS",			BIT(21)},
11592f530edSGayatri Kammela 	{"ITH_VNN_REQ_STS",			BIT(22)},
11692f530edSGayatri Kammela 	{"CSME_VNN_REQ_STS",			BIT(24)},
11792f530edSGayatri Kammela 	{"GBE_VNN_REQ_STS",			BIT(25)},
11892f530edSGayatri Kammela 	{}
11992f530edSGayatri Kammela };
12092f530edSGayatri Kammela 
12192f530edSGayatri Kammela const struct pmc_bit_map tgl_vnn_misc_status_map[] = {
12292f530edSGayatri Kammela 	{"CPU_C10_REQ_STS_0",			BIT(0)},
12392f530edSGayatri Kammela 	{"PCIe_LPM_En_REQ_STS_3",		BIT(3)},
12492f530edSGayatri Kammela 	{"ITH_REQ_STS_5",			BIT(5)},
12592f530edSGayatri Kammela 	{"CNVI_REQ_STS_6",			BIT(6)},
12692f530edSGayatri Kammela 	{"ISH_REQ_STS_7",			BIT(7)},
12792f530edSGayatri Kammela 	{"USB2_SUS_PG_Sys_REQ_STS_10",		BIT(10)},
12892f530edSGayatri Kammela 	{"PCIe_Clk_REQ_STS_12",			BIT(12)},
12992f530edSGayatri Kammela 	{"MPHY_Core_DL_REQ_STS_16",		BIT(16)},
13092f530edSGayatri Kammela 	{"Break-even_En_REQ_STS_17",		BIT(17)},
13192f530edSGayatri Kammela 	{"Auto-demo_En_REQ_STS_18",		BIT(18)},
13292f530edSGayatri Kammela 	{"MPHY_SUS_REQ_STS_22",			BIT(22)},
13392f530edSGayatri Kammela 	{"xDCI_attached_REQ_STS_24",		BIT(24)},
13492f530edSGayatri Kammela 	{}
13592f530edSGayatri Kammela };
13692f530edSGayatri Kammela 
13792f530edSGayatri Kammela const struct pmc_bit_map tgl_signal_status_map[] = {
13892f530edSGayatri Kammela 	{"LSX_Wake0_En_STS",			BIT(0)},
13992f530edSGayatri Kammela 	{"LSX_Wake0_Pol_STS",			BIT(1)},
14092f530edSGayatri Kammela 	{"LSX_Wake1_En_STS",			BIT(2)},
14192f530edSGayatri Kammela 	{"LSX_Wake1_Pol_STS",			BIT(3)},
14292f530edSGayatri Kammela 	{"LSX_Wake2_En_STS",			BIT(4)},
14392f530edSGayatri Kammela 	{"LSX_Wake2_Pol_STS",			BIT(5)},
14492f530edSGayatri Kammela 	{"LSX_Wake3_En_STS",			BIT(6)},
14592f530edSGayatri Kammela 	{"LSX_Wake3_Pol_STS",			BIT(7)},
14692f530edSGayatri Kammela 	{"LSX_Wake4_En_STS",			BIT(8)},
14792f530edSGayatri Kammela 	{"LSX_Wake4_Pol_STS",			BIT(9)},
14892f530edSGayatri Kammela 	{"LSX_Wake5_En_STS",			BIT(10)},
14992f530edSGayatri Kammela 	{"LSX_Wake5_Pol_STS",			BIT(11)},
15092f530edSGayatri Kammela 	{"LSX_Wake6_En_STS",			BIT(12)},
15192f530edSGayatri Kammela 	{"LSX_Wake6_Pol_STS",			BIT(13)},
15292f530edSGayatri Kammela 	{"LSX_Wake7_En_STS",			BIT(14)},
15392f530edSGayatri Kammela 	{"LSX_Wake7_Pol_STS",			BIT(15)},
15492f530edSGayatri Kammela 	{"Intel_Se_IO_Wake0_En_STS",		BIT(16)},
15592f530edSGayatri Kammela 	{"Intel_Se_IO_Wake0_Pol_STS",		BIT(17)},
15692f530edSGayatri Kammela 	{"Intel_Se_IO_Wake1_En_STS",		BIT(18)},
15792f530edSGayatri Kammela 	{"Intel_Se_IO_Wake1_Pol_STS",		BIT(19)},
15892f530edSGayatri Kammela 	{"Int_Timer_SS_Wake0_En_STS",		BIT(20)},
15992f530edSGayatri Kammela 	{"Int_Timer_SS_Wake0_Pol_STS",		BIT(21)},
16092f530edSGayatri Kammela 	{"Int_Timer_SS_Wake1_En_STS",		BIT(22)},
16192f530edSGayatri Kammela 	{"Int_Timer_SS_Wake1_Pol_STS",		BIT(23)},
16292f530edSGayatri Kammela 	{"Int_Timer_SS_Wake2_En_STS",		BIT(24)},
16392f530edSGayatri Kammela 	{"Int_Timer_SS_Wake2_Pol_STS",		BIT(25)},
16492f530edSGayatri Kammela 	{"Int_Timer_SS_Wake3_En_STS",		BIT(26)},
16592f530edSGayatri Kammela 	{"Int_Timer_SS_Wake3_Pol_STS",		BIT(27)},
16692f530edSGayatri Kammela 	{"Int_Timer_SS_Wake4_En_STS",		BIT(28)},
16792f530edSGayatri Kammela 	{"Int_Timer_SS_Wake4_Pol_STS",		BIT(29)},
16892f530edSGayatri Kammela 	{"Int_Timer_SS_Wake5_En_STS",		BIT(30)},
16992f530edSGayatri Kammela 	{"Int_Timer_SS_Wake5_Pol_STS",		BIT(31)},
17092f530edSGayatri Kammela 	{}
17192f530edSGayatri Kammela };
17292f530edSGayatri Kammela 
17392f530edSGayatri Kammela const struct pmc_bit_map *tgl_lpm_maps[] = {
17492f530edSGayatri Kammela 	tgl_clocksource_status_map,
17592f530edSGayatri Kammela 	tgl_power_gating_status_map,
17692f530edSGayatri Kammela 	tgl_d3_status_map,
17792f530edSGayatri Kammela 	tgl_vnn_req_status_map,
17892f530edSGayatri Kammela 	tgl_vnn_misc_status_map,
17992f530edSGayatri Kammela 	tgl_signal_status_map,
18092f530edSGayatri Kammela 	NULL
18192f530edSGayatri Kammela };
18292f530edSGayatri Kammela 
18392f530edSGayatri Kammela const struct pmc_reg_map tgl_reg_map = {
18492f530edSGayatri Kammela 	.pfear_sts = ext_tgl_pfear_map,
18592f530edSGayatri Kammela 	.slp_s0_offset = CNP_PMC_SLP_S0_RES_COUNTER_OFFSET,
18692f530edSGayatri Kammela 	.slp_s0_res_counter_step = TGL_PMC_SLP_S0_RES_COUNTER_STEP,
18792f530edSGayatri Kammela 	.ltr_show_sts = cnp_ltr_show_map,
18892f530edSGayatri Kammela 	.msr_sts = msr_map,
18992f530edSGayatri Kammela 	.ltr_ignore_offset = CNP_PMC_LTR_IGNORE_OFFSET,
19092f530edSGayatri Kammela 	.regmap_length = CNP_PMC_MMIO_REG_LEN,
19192f530edSGayatri Kammela 	.ppfear0_offset = CNP_PMC_HOST_PPFEAR0A,
19292f530edSGayatri Kammela 	.ppfear_buckets = ICL_PPFEAR_NUM_ENTRIES,
19392f530edSGayatri Kammela 	.pm_cfg_offset = CNP_PMC_PM_CFG_OFFSET,
19492f530edSGayatri Kammela 	.pm_read_disable_bit = CNP_PMC_READ_DISABLE_BIT,
19592f530edSGayatri Kammela 	.ltr_ignore_max = TGL_NUM_IP_IGN_ALLOWED,
19692f530edSGayatri Kammela 	.lpm_num_maps = TGL_LPM_NUM_MAPS,
19792f530edSGayatri Kammela 	.lpm_res_counter_step_x2 = TGL_PMC_LPM_RES_COUNTER_STEP_X2,
19892f530edSGayatri Kammela 	.lpm_sts_latch_en_offset = TGL_LPM_STS_LATCH_EN_OFFSET,
19992f530edSGayatri Kammela 	.lpm_en_offset = TGL_LPM_EN_OFFSET,
20092f530edSGayatri Kammela 	.lpm_priority_offset = TGL_LPM_PRI_OFFSET,
20192f530edSGayatri Kammela 	.lpm_residency_offset = TGL_LPM_RESIDENCY_OFFSET,
20292f530edSGayatri Kammela 	.lpm_sts = tgl_lpm_maps,
20392f530edSGayatri Kammela 	.lpm_status_offset = TGL_LPM_STATUS_OFFSET,
20492f530edSGayatri Kammela 	.lpm_live_status_offset = TGL_LPM_LIVE_STATUS_OFFSET,
20592f530edSGayatri Kammela 	.etr3_offset = ETR3_OFFSET,
20692f530edSGayatri Kammela };
20792f530edSGayatri Kammela 
pmc_core_get_tgl_lpm_reqs(struct platform_device * pdev)20892f530edSGayatri Kammela void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev)
20992f530edSGayatri Kammela {
21092f530edSGayatri Kammela 	struct pmc_dev *pmcdev = platform_get_drvdata(pdev);
2111c709ae1SXi Pardee 	struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
2121c709ae1SXi Pardee 	const int num_maps = pmc->map->lpm_num_maps;
21392f530edSGayatri Kammela 	u32 lpm_size = LPM_MAX_NUM_MODES * num_maps * 4;
21492f530edSGayatri Kammela 	union acpi_object *out_obj;
21592f530edSGayatri Kammela 	struct acpi_device *adev;
21692f530edSGayatri Kammela 	guid_t s0ix_dsm_guid;
21792f530edSGayatri Kammela 	u32 *lpm_req_regs, *addr;
21892f530edSGayatri Kammela 
21992f530edSGayatri Kammela 	adev = ACPI_COMPANION(&pdev->dev);
22092f530edSGayatri Kammela 	if (!adev)
22192f530edSGayatri Kammela 		return;
22292f530edSGayatri Kammela 
22392f530edSGayatri Kammela 	guid_parse(ACPI_S0IX_DSM_UUID, &s0ix_dsm_guid);
22492f530edSGayatri Kammela 
2256ab98318SAndy Shevchenko 	out_obj = acpi_evaluate_dsm_typed(adev->handle, &s0ix_dsm_guid, 0,
2266ab98318SAndy Shevchenko 					  ACPI_GET_LOW_MODE_REGISTERS, NULL, ACPI_TYPE_BUFFER);
2276ab98318SAndy Shevchenko 	if (out_obj) {
22892f530edSGayatri Kammela 		u32 size = out_obj->buffer.length;
22992f530edSGayatri Kammela 
23092f530edSGayatri Kammela 		if (size != lpm_size) {
23192f530edSGayatri Kammela 			acpi_handle_debug(adev->handle,
23292f530edSGayatri Kammela 				"_DSM returned unexpected buffer size, have %u, expect %u\n",
23392f530edSGayatri Kammela 				size, lpm_size);
23492f530edSGayatri Kammela 			goto free_acpi_obj;
23592f530edSGayatri Kammela 		}
23692f530edSGayatri Kammela 	} else {
23792f530edSGayatri Kammela 		acpi_handle_debug(adev->handle,
23892f530edSGayatri Kammela 				  "_DSM function 0 evaluation failed\n");
23992f530edSGayatri Kammela 		goto free_acpi_obj;
24092f530edSGayatri Kammela 	}
24192f530edSGayatri Kammela 
24292f530edSGayatri Kammela 	addr = (u32 *)out_obj->buffer.pointer;
24392f530edSGayatri Kammela 
24492f530edSGayatri Kammela 	lpm_req_regs = devm_kzalloc(&pdev->dev, lpm_size * sizeof(u32),
24592f530edSGayatri Kammela 				     GFP_KERNEL);
24692f530edSGayatri Kammela 	if (!lpm_req_regs)
24792f530edSGayatri Kammela 		goto free_acpi_obj;
24892f530edSGayatri Kammela 
24992f530edSGayatri Kammela 	memcpy(lpm_req_regs, addr, lpm_size);
2501c709ae1SXi Pardee 	pmc->lpm_req_regs = lpm_req_regs;
25192f530edSGayatri Kammela 
25292f530edSGayatri Kammela free_acpi_obj:
25392f530edSGayatri Kammela 	ACPI_FREE(out_obj);
25492f530edSGayatri Kammela }
25592f530edSGayatri Kammela 
tgl_core_init(struct pmc_dev * pmcdev)25680495120SXi Pardee int tgl_core_init(struct pmc_dev *pmcdev)
25792f530edSGayatri Kammela {
2581c709ae1SXi Pardee 	struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
25980495120SXi Pardee 	int ret;
26080495120SXi Pardee 
2611c709ae1SXi Pardee 	pmc->map = &tgl_reg_map;
262*33fd5fb1SDavid E. Box 
263*33fd5fb1SDavid E. Box 	pmcdev->suspend = cnl_suspend;
264*33fd5fb1SDavid E. Box 	pmcdev->resume = cnl_resume;
265*33fd5fb1SDavid E. Box 
2661c709ae1SXi Pardee 	ret = get_primary_reg_base(pmc);
26780495120SXi Pardee 	if (ret)
26880495120SXi Pardee 		return ret;
26980495120SXi Pardee 
27092f530edSGayatri Kammela 	pmc_core_get_tgl_lpm_reqs(pmcdev->pdev);
27192f530edSGayatri Kammela 
27280495120SXi Pardee 	return 0;
27392f530edSGayatri Kammela }
274