Skip to content

Commit ea1a76b

Browse files
AxelLindvhart
authored andcommitted
platform/x86: intel_pmc_ipc: Convert to use platform_device_register_full
Use platform_device_register_full() instead of open-coded. Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Darren Hart <dvhart@linux.intel.com>
1 parent b564353 commit ea1a76b

File tree

1 file changed

+33
-77
lines changed

1 file changed

+33
-77
lines changed

drivers/platform/x86/intel_pmc_ipc.c

Lines changed: 33 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -522,48 +522,36 @@ static struct resource telemetry_res[] = {
522522
static int ipc_create_punit_device(void)
523523
{
524524
struct platform_device *pdev;
525-
int ret;
526-
527-
pdev = platform_device_alloc(PUNIT_DEVICE_NAME, -1);
528-
if (!pdev) {
529-
dev_err(ipcdev.dev, "Failed to alloc punit platform device\n");
530-
return -ENOMEM;
531-
}
532-
533-
pdev->dev.parent = ipcdev.dev;
534-
ret = platform_device_add_resources(pdev, punit_res_array,
535-
ARRAY_SIZE(punit_res_array));
536-
if (ret) {
537-
dev_err(ipcdev.dev, "Failed to add platform punit resources\n");
538-
goto err;
539-
}
525+
const struct platform_device_info pdevinfo = {
526+
.parent = ipcdev.dev,
527+
.name = PUNIT_DEVICE_NAME,
528+
.id = -1,
529+
.res = punit_res_array,
530+
.num_res = ARRAY_SIZE(punit_res_array),
531+
};
532+
533+
pdev = platform_device_register_full(&pdevinfo);
534+
if (IS_ERR(pdev))
535+
return PTR_ERR(pdev);
540536

541-
ret = platform_device_add(pdev);
542-
if (ret) {
543-
dev_err(ipcdev.dev, "Failed to add punit platform device\n");
544-
goto err;
545-
}
546537
ipcdev.punit_dev = pdev;
547538

548539
return 0;
549-
err:
550-
platform_device_put(pdev);
551-
return ret;
552540
}
553541

554542
static int ipc_create_tco_device(void)
555543
{
556544
struct platform_device *pdev;
557545
struct resource *res;
558-
int ret;
559-
560-
pdev = platform_device_alloc(TCO_DEVICE_NAME, -1);
561-
if (!pdev) {
562-
dev_err(ipcdev.dev, "Failed to alloc tco platform device\n");
563-
return -ENOMEM;
564-
}
565-
566-
pdev->dev.parent = ipcdev.dev;
546+
const struct platform_device_info pdevinfo = {
547+
.parent = ipcdev.dev,
548+
.name = TCO_DEVICE_NAME,
549+
.id = -1,
550+
.res = tco_res,
551+
.num_res = ARRAY_SIZE(tco_res),
552+
.data = &tco_info,
553+
.size_data = sizeof(tco_info),
554+
};
567555

568556
res = tco_res + TCO_RESOURCE_ACPI_IO;
569557
res->start = ipcdev.acpi_io_base + TCO_BASE_OFFSET;
@@ -577,45 +565,26 @@ static int ipc_create_tco_device(void)
577565
res->start = ipcdev.gcr_base + TCO_PMC_OFFSET;
578566
res->end = res->start + TCO_PMC_SIZE - 1;
579567

580-
ret = platform_device_add_resources(pdev, tco_res, ARRAY_SIZE(tco_res));
581-
if (ret) {
582-
dev_err(ipcdev.dev, "Failed to add tco platform resources\n");
583-
goto err;
584-
}
585-
586-
ret = platform_device_add_data(pdev, &tco_info, sizeof(tco_info));
587-
if (ret) {
588-
dev_err(ipcdev.dev, "Failed to add tco platform data\n");
589-
goto err;
590-
}
568+
pdev = platform_device_register_full(&pdevinfo);
569+
if (IS_ERR(pdev))
570+
return PTR_ERR(pdev);
591571

592-
ret = platform_device_add(pdev);
593-
if (ret) {
594-
dev_err(ipcdev.dev, "Failed to add tco platform device\n");
595-
goto err;
596-
}
597572
ipcdev.tco_dev = pdev;
598573

599574
return 0;
600-
err:
601-
platform_device_put(pdev);
602-
return ret;
603575
}
604576

605577
static int ipc_create_telemetry_device(void)
606578
{
607579
struct platform_device *pdev;
608580
struct resource *res;
609-
int ret;
610-
611-
pdev = platform_device_alloc(TELEMETRY_DEVICE_NAME, -1);
612-
if (!pdev) {
613-
dev_err(ipcdev.dev,
614-
"Failed to allocate telemetry platform device\n");
615-
return -ENOMEM;
616-
}
617-
618-
pdev->dev.parent = ipcdev.dev;
581+
const struct platform_device_info pdevinfo = {
582+
.parent = ipcdev.dev,
583+
.name = TELEMETRY_DEVICE_NAME,
584+
.id = -1,
585+
.res = telemetry_res,
586+
.num_res = ARRAY_SIZE(telemetry_res),
587+
};
619588

620589
res = telemetry_res + TELEMETRY_RESOURCE_PUNIT_SSRAM;
621590
res->start = ipcdev.telem_punit_ssram_base;
@@ -625,26 +594,13 @@ static int ipc_create_telemetry_device(void)
625594
res->start = ipcdev.telem_pmc_ssram_base;
626595
res->end = res->start + ipcdev.telem_pmc_ssram_size - 1;
627596

628-
ret = platform_device_add_resources(pdev, telemetry_res,
629-
ARRAY_SIZE(telemetry_res));
630-
if (ret) {
631-
dev_err(ipcdev.dev,
632-
"Failed to add telemetry platform resources\n");
633-
goto err;
634-
}
597+
pdev = platform_device_register_full(&pdevinfo);
598+
if (IS_ERR(pdev))
599+
return PTR_ERR(pdev);
635600

636-
ret = platform_device_add(pdev);
637-
if (ret) {
638-
dev_err(ipcdev.dev,
639-
"Failed to add telemetry platform device\n");
640-
goto err;
641-
}
642601
ipcdev.telemetry_dev = pdev;
643602

644603
return 0;
645-
err:
646-
platform_device_put(pdev);
647-
return ret;
648604
}
649605

650606
static int ipc_create_pmc_devices(void)

0 commit comments

Comments
 (0)