Skip to content

Commit 8049512

Browse files
xpardee-createjwrdegoede
authored andcommitted
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: Xi Pardee <xi.pardee@intel.com> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Link: https://lore.kernel.org/r/20230613225347.2720665-3-rajvi.jingar@linux.intel.com Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1 parent 9682cfd commit 8049512

File tree

8 files changed

+85
-58
lines changed

8 files changed

+85
-58
lines changed

drivers/platform/x86/intel/pmc/adl.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,20 @@ const struct pmc_reg_map adl_reg_map = {
309309
.lpm_live_status_offset = ADL_LPM_LIVE_STATUS_OFFSET,
310310
};
311311

312-
void adl_core_configure(struct pmc_dev *pmcdev)
312+
int adl_core_init(struct pmc_dev *pmcdev)
313313
{
314+
int ret;
315+
316+
pmcdev->map = &adl_reg_map;
317+
ret = get_primary_reg_base(pmcdev);
318+
if (ret)
319+
return ret;
320+
314321
/* Due to a hardware limitation, the GBE LTR blocks PC10
315322
* when a cable is attached. Tell the PMC to ignore it.
316323
*/
317324
dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n");
318325
pmc_core_send_ltr_ignore(pmcdev, 3);
319-
}
320326

321-
void adl_core_init(struct pmc_dev *pmcdev)
322-
{
323-
pmcdev->map = &adl_reg_map;
324-
pmcdev->core_configure = adl_core_configure;
327+
return 0;
325328
}

drivers/platform/x86/intel/pmc/cnp.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,20 @@ const struct pmc_reg_map cnp_reg_map = {
204204
.etr3_offset = ETR3_OFFSET,
205205
};
206206

207-
void cnp_core_init(struct pmc_dev *pmcdev)
207+
int cnp_core_init(struct pmc_dev *pmcdev)
208208
{
209+
int ret;
210+
209211
pmcdev->map = &cnp_reg_map;
212+
ret = get_primary_reg_base(pmcdev);
213+
if (ret)
214+
return ret;
215+
216+
/* Due to a hardware limitation, the GBE LTR blocks PC10
217+
* when a cable is attached. Tell the PMC to ignore it.
218+
*/
219+
dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n");
220+
pmc_core_send_ltr_ignore(pmcdev, 3);
221+
222+
return 0;
210223
}

drivers/platform/x86/intel/pmc/core.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,25 @@ static void pmc_core_get_low_power_modes(struct platform_device *pdev)
948948
}
949949
}
950950

951+
int get_primary_reg_base(struct pmc_dev *pmcdev)
952+
{
953+
u64 slp_s0_addr;
954+
955+
if (lpit_read_residency_count_address(&slp_s0_addr)) {
956+
pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;
957+
958+
if (page_is_ram(PHYS_PFN(pmcdev->base_addr)))
959+
return -ENODEV;
960+
} else {
961+
pmcdev->base_addr = slp_s0_addr - pmcdev->map->slp_s0_offset;
962+
}
963+
964+
pmcdev->regbase = ioremap(pmcdev->base_addr, pmcdev->map->regmap_length);
965+
if (!pmcdev->regbase)
966+
return -ENOMEM;
967+
return 0;
968+
}
969+
951970
static void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev)
952971
{
953972
debugfs_remove_recursive(pmcdev->dbgfs_dir);
@@ -1099,8 +1118,8 @@ static int pmc_core_probe(struct platform_device *pdev)
10991118
static bool device_initialized;
11001119
struct pmc_dev *pmcdev;
11011120
const struct x86_cpu_id *cpu_id;
1102-
void (*core_init)(struct pmc_dev *pmcdev);
1103-
u64 slp_s0_addr;
1121+
int (*core_init)(struct pmc_dev *pmcdev);
1122+
int ret;
11041123

11051124
if (device_initialized)
11061125
return -ENODEV;
@@ -1116,7 +1135,7 @@ static int pmc_core_probe(struct platform_device *pdev)
11161135
if (!cpu_id)
11171136
return -ENODEV;
11181137

1119-
core_init = (void (*)(struct pmc_dev *))cpu_id->driver_data;
1138+
core_init = (int (*)(struct pmc_dev *))cpu_id->driver_data;
11201139

11211140
/*
11221141
* 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)
11271146
core_init = cnp_core_init;
11281147

11291148
mutex_init(&pmcdev->lock);
1130-
core_init(pmcdev);
1131-
1132-
1133-
if (lpit_read_residency_count_address(&slp_s0_addr)) {
1134-
pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;
1135-
1136-
if (page_is_ram(PHYS_PFN(pmcdev->base_addr)))
1137-
return -ENODEV;
1138-
} else {
1139-
pmcdev->base_addr = slp_s0_addr - pmcdev->map->slp_s0_offset;
1149+
ret = core_init(pmcdev);
1150+
if (ret) {
1151+
mutex_destroy(&pmcdev->lock);
1152+
return ret;
11401153
}
11411154

1142-
pmcdev->regbase = ioremap(pmcdev->base_addr,
1143-
pmcdev->map->regmap_length);
1144-
if (!pmcdev->regbase)
1145-
return -ENOMEM;
1146-
1147-
if (pmcdev->core_configure)
1148-
pmcdev->core_configure(pmcdev);
1149-
11501155
pmcdev->pmc_xram_read_bit = pmc_core_check_read_lock_bit(pmcdev);
11511156
pmc_core_get_low_power_modes(pdev);
11521157
pmc_core_do_dmi_quirks(pmcdev);

drivers/platform/x86/intel/pmc/core.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ struct pmc_reg_map {
334334
* @num_lpm_modes: Count of enabled modes
335335
* @lpm_en_modes: Array of enabled modes from lowest to highest priority
336336
* @lpm_req_regs: List of substate requirements
337-
* @core_configure: Function pointer to configure the platform
338337
* @resume: Function to perform platform specific resume
339338
*
340339
* pmc_dev contains info about power management controller device.
@@ -353,7 +352,6 @@ struct pmc_dev {
353352
int num_lpm_modes;
354353
int lpm_en_modes[LPM_MAX_NUM_MODES];
355354
u32 *lpm_req_regs;
356-
void (*core_configure)(struct pmc_dev *pmcdev);
357355
int (*resume)(struct pmc_dev *pmcdev);
358356
};
359357

@@ -427,15 +425,14 @@ extern void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev);
427425
extern int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value);
428426

429427
int pmc_core_resume_common(struct pmc_dev *pmcdev);
430-
void spt_core_init(struct pmc_dev *pmcdev);
431-
void cnp_core_init(struct pmc_dev *pmcdev);
432-
void icl_core_init(struct pmc_dev *pmcdev);
433-
void tgl_core_init(struct pmc_dev *pmcdev);
434-
void adl_core_init(struct pmc_dev *pmcdev);
435-
void mtl_core_init(struct pmc_dev *pmcdev);
436-
void tgl_core_configure(struct pmc_dev *pmcdev);
437-
void adl_core_configure(struct pmc_dev *pmcdev);
438-
void mtl_core_configure(struct pmc_dev *pmcdev);
428+
int get_primary_reg_base(struct pmc_dev *pmcdev);
429+
430+
int spt_core_init(struct pmc_dev *pmcdev);
431+
int cnp_core_init(struct pmc_dev *pmcdev);
432+
int icl_core_init(struct pmc_dev *pmcdev);
433+
int tgl_core_init(struct pmc_dev *pmcdev);
434+
int adl_core_init(struct pmc_dev *pmcdev);
435+
int mtl_core_init(struct pmc_dev *pmcdev);
439436

440437
#define pmc_for_each_mode(i, mode, pmcdev) \
441438
for (i = 0, mode = pmcdev->lpm_en_modes[i]; \

drivers/platform/x86/intel/pmc/icl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ const struct pmc_reg_map icl_reg_map = {
5050
.etr3_offset = ETR3_OFFSET,
5151
};
5252

53-
void icl_core_init(struct pmc_dev *pmcdev)
53+
int icl_core_init(struct pmc_dev *pmcdev)
5454
{
5555
pmcdev->map = &icl_reg_map;
56+
return get_primary_reg_base(pmcdev);
5657
}

drivers/platform/x86/intel/pmc/mtl.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,6 @@ const struct pmc_reg_map mtl_socm_reg_map = {
467467
.lpm_live_status_offset = MTL_LPM_LIVE_STATUS_OFFSET,
468468
};
469469

470-
void mtl_core_configure(struct pmc_dev *pmcdev)
471-
{
472-
/* Due to a hardware limitation, the GBE LTR blocks PC10
473-
* when a cable is attached. Tell the PMC to ignore it.
474-
*/
475-
dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n");
476-
pmc_core_send_ltr_ignore(pmcdev, 3);
477-
}
478-
479470
#define MTL_GNA_PCI_DEV 0x7e4c
480471
#define MTL_IPU_PCI_DEV 0x7d19
481472
#define MTL_VPU_PCI_DEV 0x7d1d
@@ -515,12 +506,25 @@ static int mtl_resume(struct pmc_dev *pmcdev)
515506
return pmc_core_resume_common(pmcdev);
516507
}
517508

518-
void mtl_core_init(struct pmc_dev *pmcdev)
509+
int mtl_core_init(struct pmc_dev *pmcdev)
519510
{
511+
int ret;
512+
520513
pmcdev->map = &mtl_socm_reg_map;
521-
pmcdev->core_configure = mtl_core_configure;
522514

523515
mtl_d3_fixup();
524516

525517
pmcdev->resume = mtl_resume;
518+
519+
ret = get_primary_reg_base(pmcdev);
520+
if (ret)
521+
return ret;
522+
523+
/* Due to a hardware limitation, the GBE LTR blocks PC10
524+
* when a cable is attached. Tell the PMC to ignore it.
525+
*/
526+
dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n");
527+
pmc_core_send_ltr_ignore(pmcdev, 3);
528+
529+
return 0;
526530
}

drivers/platform/x86/intel/pmc/spt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ const struct pmc_reg_map spt_reg_map = {
134134
.pm_vric1_offset = SPT_PMC_VRIC1_OFFSET,
135135
};
136136

137-
void spt_core_init(struct pmc_dev *pmcdev)
137+
int spt_core_init(struct pmc_dev *pmcdev)
138138
{
139139
pmcdev->map = &spt_reg_map;
140+
return get_primary_reg_base(pmcdev);
140141
}

drivers/platform/x86/intel/pmc/tgl.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,18 +252,21 @@ void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev)
252252
ACPI_FREE(out_obj);
253253
}
254254

255-
void tgl_core_configure(struct pmc_dev *pmcdev)
255+
int tgl_core_init(struct pmc_dev *pmcdev)
256256
{
257+
int ret;
258+
259+
pmcdev->map = &tgl_reg_map;
260+
ret = get_primary_reg_base(pmcdev);
261+
if (ret)
262+
return ret;
263+
257264
pmc_core_get_tgl_lpm_reqs(pmcdev->pdev);
258265
/* Due to a hardware limitation, the GBE LTR blocks PC10
259266
* when a cable is attached. Tell the PMC to ignore it.
260267
*/
261268
dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n");
262269
pmc_core_send_ltr_ignore(pmcdev, 3);
263-
}
264270

265-
void tgl_core_init(struct pmc_dev *pmcdev)
266-
{
267-
pmcdev->map = &tgl_reg_map;
268-
pmcdev->core_configure = tgl_core_configure;
271+
return 0;
269272
}

0 commit comments

Comments
 (0)