Commit 80495120 authored by Xi Pardee's avatar Xi Pardee Committed by Hans de Goede

platform/x86:intel/pmc: Combine core_init() and core_configure()

Combine core_init() and core_configure() functions to have a
cleaner setup for platforms.
Signed-off-by: default avatarXi Pardee <xi.pardee@intel.com>
Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20230613225347.2720665-3-rajvi.jingar@linux.intel.comSigned-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 9682cfd1
...@@ -309,17 +309,20 @@ const struct pmc_reg_map adl_reg_map = { ...@@ -309,17 +309,20 @@ const struct pmc_reg_map adl_reg_map = {
.lpm_live_status_offset = ADL_LPM_LIVE_STATUS_OFFSET, .lpm_live_status_offset = ADL_LPM_LIVE_STATUS_OFFSET,
}; };
void adl_core_configure(struct pmc_dev *pmcdev) int adl_core_init(struct pmc_dev *pmcdev)
{ {
int ret;
pmcdev->map = &adl_reg_map;
ret = get_primary_reg_base(pmcdev);
if (ret)
return ret;
/* Due to a hardware limitation, the GBE LTR blocks PC10 /* Due to a hardware limitation, the GBE LTR blocks PC10
* when a cable is attached. Tell the PMC to ignore it. * when a cable is attached. Tell the PMC to ignore it.
*/ */
dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n"); dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n");
pmc_core_send_ltr_ignore(pmcdev, 3); pmc_core_send_ltr_ignore(pmcdev, 3);
}
void adl_core_init(struct pmc_dev *pmcdev) return 0;
{
pmcdev->map = &adl_reg_map;
pmcdev->core_configure = adl_core_configure;
} }
...@@ -204,7 +204,20 @@ const struct pmc_reg_map cnp_reg_map = { ...@@ -204,7 +204,20 @@ const struct pmc_reg_map cnp_reg_map = {
.etr3_offset = ETR3_OFFSET, .etr3_offset = ETR3_OFFSET,
}; };
void cnp_core_init(struct pmc_dev *pmcdev) int cnp_core_init(struct pmc_dev *pmcdev)
{ {
int ret;
pmcdev->map = &cnp_reg_map; pmcdev->map = &cnp_reg_map;
ret = get_primary_reg_base(pmcdev);
if (ret)
return ret;
/* Due to a hardware limitation, the GBE LTR blocks PC10
* when a cable is attached. Tell the PMC to ignore it.
*/
dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n");
pmc_core_send_ltr_ignore(pmcdev, 3);
return 0;
} }
...@@ -948,6 +948,25 @@ static void pmc_core_get_low_power_modes(struct platform_device *pdev) ...@@ -948,6 +948,25 @@ static void pmc_core_get_low_power_modes(struct platform_device *pdev)
} }
} }
int get_primary_reg_base(struct pmc_dev *pmcdev)
{
u64 slp_s0_addr;
if (lpit_read_residency_count_address(&slp_s0_addr)) {
pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;
if (page_is_ram(PHYS_PFN(pmcdev->base_addr)))
return -ENODEV;
} else {
pmcdev->base_addr = slp_s0_addr - pmcdev->map->slp_s0_offset;
}
pmcdev->regbase = ioremap(pmcdev->base_addr, pmcdev->map->regmap_length);
if (!pmcdev->regbase)
return -ENOMEM;
return 0;
}
static void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev) static void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev)
{ {
debugfs_remove_recursive(pmcdev->dbgfs_dir); debugfs_remove_recursive(pmcdev->dbgfs_dir);
...@@ -1099,8 +1118,8 @@ static int pmc_core_probe(struct platform_device *pdev) ...@@ -1099,8 +1118,8 @@ static int pmc_core_probe(struct platform_device *pdev)
static bool device_initialized; static bool device_initialized;
struct pmc_dev *pmcdev; struct pmc_dev *pmcdev;
const struct x86_cpu_id *cpu_id; const struct x86_cpu_id *cpu_id;
void (*core_init)(struct pmc_dev *pmcdev); int (*core_init)(struct pmc_dev *pmcdev);
u64 slp_s0_addr; int ret;
if (device_initialized) if (device_initialized)
return -ENODEV; return -ENODEV;
...@@ -1116,7 +1135,7 @@ static int pmc_core_probe(struct platform_device *pdev) ...@@ -1116,7 +1135,7 @@ static int pmc_core_probe(struct platform_device *pdev)
if (!cpu_id) if (!cpu_id)
return -ENODEV; return -ENODEV;
core_init = (void (*)(struct pmc_dev *))cpu_id->driver_data; core_init = (int (*)(struct pmc_dev *))cpu_id->driver_data;
/* /*
* Coffee Lake has CPU ID of Kaby Lake and Cannon Lake PCH. So here * Coffee Lake has CPU ID of Kaby Lake and Cannon Lake PCH. So here
...@@ -1127,26 +1146,12 @@ static int pmc_core_probe(struct platform_device *pdev) ...@@ -1127,26 +1146,12 @@ static int pmc_core_probe(struct platform_device *pdev)
core_init = cnp_core_init; core_init = cnp_core_init;
mutex_init(&pmcdev->lock); mutex_init(&pmcdev->lock);
core_init(pmcdev); ret = core_init(pmcdev);
if (ret) {
mutex_destroy(&pmcdev->lock);
if (lpit_read_residency_count_address(&slp_s0_addr)) { return ret;
pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;
if (page_is_ram(PHYS_PFN(pmcdev->base_addr)))
return -ENODEV;
} else {
pmcdev->base_addr = slp_s0_addr - pmcdev->map->slp_s0_offset;
} }
pmcdev->regbase = ioremap(pmcdev->base_addr,
pmcdev->map->regmap_length);
if (!pmcdev->regbase)
return -ENOMEM;
if (pmcdev->core_configure)
pmcdev->core_configure(pmcdev);
pmcdev->pmc_xram_read_bit = pmc_core_check_read_lock_bit(pmcdev); pmcdev->pmc_xram_read_bit = pmc_core_check_read_lock_bit(pmcdev);
pmc_core_get_low_power_modes(pdev); pmc_core_get_low_power_modes(pdev);
pmc_core_do_dmi_quirks(pmcdev); pmc_core_do_dmi_quirks(pmcdev);
......
...@@ -334,7 +334,6 @@ struct pmc_reg_map { ...@@ -334,7 +334,6 @@ struct pmc_reg_map {
* @num_lpm_modes: Count of enabled modes * @num_lpm_modes: Count of enabled modes
* @lpm_en_modes: Array of enabled modes from lowest to highest priority * @lpm_en_modes: Array of enabled modes from lowest to highest priority
* @lpm_req_regs: List of substate requirements * @lpm_req_regs: List of substate requirements
* @core_configure: Function pointer to configure the platform
* @resume: Function to perform platform specific resume * @resume: Function to perform platform specific resume
* *
* pmc_dev contains info about power management controller device. * pmc_dev contains info about power management controller device.
...@@ -353,7 +352,6 @@ struct pmc_dev { ...@@ -353,7 +352,6 @@ struct pmc_dev {
int num_lpm_modes; int num_lpm_modes;
int lpm_en_modes[LPM_MAX_NUM_MODES]; int lpm_en_modes[LPM_MAX_NUM_MODES];
u32 *lpm_req_regs; u32 *lpm_req_regs;
void (*core_configure)(struct pmc_dev *pmcdev);
int (*resume)(struct pmc_dev *pmcdev); int (*resume)(struct pmc_dev *pmcdev);
}; };
...@@ -427,15 +425,14 @@ extern void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev); ...@@ -427,15 +425,14 @@ extern void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev);
extern int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value); extern int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value);
int pmc_core_resume_common(struct pmc_dev *pmcdev); int pmc_core_resume_common(struct pmc_dev *pmcdev);
void spt_core_init(struct pmc_dev *pmcdev); int get_primary_reg_base(struct pmc_dev *pmcdev);
void cnp_core_init(struct pmc_dev *pmcdev);
void icl_core_init(struct pmc_dev *pmcdev); int spt_core_init(struct pmc_dev *pmcdev);
void tgl_core_init(struct pmc_dev *pmcdev); int cnp_core_init(struct pmc_dev *pmcdev);
void adl_core_init(struct pmc_dev *pmcdev); int icl_core_init(struct pmc_dev *pmcdev);
void mtl_core_init(struct pmc_dev *pmcdev); int tgl_core_init(struct pmc_dev *pmcdev);
void tgl_core_configure(struct pmc_dev *pmcdev); int adl_core_init(struct pmc_dev *pmcdev);
void adl_core_configure(struct pmc_dev *pmcdev); int mtl_core_init(struct pmc_dev *pmcdev);
void mtl_core_configure(struct pmc_dev *pmcdev);
#define pmc_for_each_mode(i, mode, pmcdev) \ #define pmc_for_each_mode(i, mode, pmcdev) \
for (i = 0, mode = pmcdev->lpm_en_modes[i]; \ for (i = 0, mode = pmcdev->lpm_en_modes[i]; \
......
...@@ -50,7 +50,8 @@ const struct pmc_reg_map icl_reg_map = { ...@@ -50,7 +50,8 @@ const struct pmc_reg_map icl_reg_map = {
.etr3_offset = ETR3_OFFSET, .etr3_offset = ETR3_OFFSET,
}; };
void icl_core_init(struct pmc_dev *pmcdev) int icl_core_init(struct pmc_dev *pmcdev)
{ {
pmcdev->map = &icl_reg_map; pmcdev->map = &icl_reg_map;
return get_primary_reg_base(pmcdev);
} }
...@@ -467,15 +467,6 @@ const struct pmc_reg_map mtl_socm_reg_map = { ...@@ -467,15 +467,6 @@ const struct pmc_reg_map mtl_socm_reg_map = {
.lpm_live_status_offset = MTL_LPM_LIVE_STATUS_OFFSET, .lpm_live_status_offset = MTL_LPM_LIVE_STATUS_OFFSET,
}; };
void mtl_core_configure(struct pmc_dev *pmcdev)
{
/* Due to a hardware limitation, the GBE LTR blocks PC10
* when a cable is attached. Tell the PMC to ignore it.
*/
dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n");
pmc_core_send_ltr_ignore(pmcdev, 3);
}
#define MTL_GNA_PCI_DEV 0x7e4c #define MTL_GNA_PCI_DEV 0x7e4c
#define MTL_IPU_PCI_DEV 0x7d19 #define MTL_IPU_PCI_DEV 0x7d19
#define MTL_VPU_PCI_DEV 0x7d1d #define MTL_VPU_PCI_DEV 0x7d1d
...@@ -515,12 +506,25 @@ static int mtl_resume(struct pmc_dev *pmcdev) ...@@ -515,12 +506,25 @@ static int mtl_resume(struct pmc_dev *pmcdev)
return pmc_core_resume_common(pmcdev); return pmc_core_resume_common(pmcdev);
} }
void mtl_core_init(struct pmc_dev *pmcdev) int mtl_core_init(struct pmc_dev *pmcdev)
{ {
int ret;
pmcdev->map = &mtl_socm_reg_map; pmcdev->map = &mtl_socm_reg_map;
pmcdev->core_configure = mtl_core_configure;
mtl_d3_fixup(); mtl_d3_fixup();
pmcdev->resume = mtl_resume; pmcdev->resume = mtl_resume;
ret = get_primary_reg_base(pmcdev);
if (ret)
return ret;
/* Due to a hardware limitation, the GBE LTR blocks PC10
* when a cable is attached. Tell the PMC to ignore it.
*/
dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n");
pmc_core_send_ltr_ignore(pmcdev, 3);
return 0;
} }
...@@ -134,7 +134,8 @@ const struct pmc_reg_map spt_reg_map = { ...@@ -134,7 +134,8 @@ const struct pmc_reg_map spt_reg_map = {
.pm_vric1_offset = SPT_PMC_VRIC1_OFFSET, .pm_vric1_offset = SPT_PMC_VRIC1_OFFSET,
}; };
void spt_core_init(struct pmc_dev *pmcdev) int spt_core_init(struct pmc_dev *pmcdev)
{ {
pmcdev->map = &spt_reg_map; pmcdev->map = &spt_reg_map;
return get_primary_reg_base(pmcdev);
} }
...@@ -252,18 +252,21 @@ void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev) ...@@ -252,18 +252,21 @@ void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev)
ACPI_FREE(out_obj); ACPI_FREE(out_obj);
} }
void tgl_core_configure(struct pmc_dev *pmcdev) int tgl_core_init(struct pmc_dev *pmcdev)
{ {
int ret;
pmcdev->map = &tgl_reg_map;
ret = get_primary_reg_base(pmcdev);
if (ret)
return ret;
pmc_core_get_tgl_lpm_reqs(pmcdev->pdev); pmc_core_get_tgl_lpm_reqs(pmcdev->pdev);
/* Due to a hardware limitation, the GBE LTR blocks PC10 /* Due to a hardware limitation, the GBE LTR blocks PC10
* when a cable is attached. Tell the PMC to ignore it. * when a cable is attached. Tell the PMC to ignore it.
*/ */
dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n"); dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n");
pmc_core_send_ltr_ignore(pmcdev, 3); pmc_core_send_ltr_ignore(pmcdev, 3);
}
void tgl_core_init(struct pmc_dev *pmcdev) return 0;
{
pmcdev->map = &tgl_reg_map;
pmcdev->core_configure = tgl_core_configure;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment