1ebc57e39SAlexander Shishkin // SPDX-License-Identifier: GPL-2.0
2ebc57e39SAlexander Shishkin /*
3ebc57e39SAlexander Shishkin * Intel(R) Trace Hub ACPI driver
4ebc57e39SAlexander Shishkin *
5ebc57e39SAlexander Shishkin * Copyright (C) 2017 Intel Corporation.
6ebc57e39SAlexander Shishkin */
7ebc57e39SAlexander Shishkin
8ebc57e39SAlexander Shishkin #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9ebc57e39SAlexander Shishkin
10ebc57e39SAlexander Shishkin #include <linux/types.h>
11ebc57e39SAlexander Shishkin #include <linux/module.h>
12ebc57e39SAlexander Shishkin #include <linux/device.h>
13ebc57e39SAlexander Shishkin #include <linux/sysfs.h>
14ebc57e39SAlexander Shishkin #include <linux/platform_device.h>
15ebc57e39SAlexander Shishkin #include <linux/acpi.h>
16ebc57e39SAlexander Shishkin
17ebc57e39SAlexander Shishkin #include "intel_th.h"
18ebc57e39SAlexander Shishkin
19ebc57e39SAlexander Shishkin #define DRIVER_NAME "intel_th_acpi"
20ebc57e39SAlexander Shishkin
21ebc57e39SAlexander Shishkin static const struct intel_th_drvdata intel_th_acpi_pch = {
22ebc57e39SAlexander Shishkin .host_mode_only = 1,
23ebc57e39SAlexander Shishkin };
24ebc57e39SAlexander Shishkin
25ebc57e39SAlexander Shishkin static const struct intel_th_drvdata intel_th_acpi_uncore = {
26ebc57e39SAlexander Shishkin .host_mode_only = 1,
27ebc57e39SAlexander Shishkin };
28ebc57e39SAlexander Shishkin
29ebc57e39SAlexander Shishkin static const struct acpi_device_id intel_th_acpi_ids[] = {
30ebc57e39SAlexander Shishkin { "INTC1000", (kernel_ulong_t)&intel_th_acpi_uncore },
31ebc57e39SAlexander Shishkin { "INTC1001", (kernel_ulong_t)&intel_th_acpi_pch },
32ebc57e39SAlexander Shishkin { "", 0 },
33ebc57e39SAlexander Shishkin };
34ebc57e39SAlexander Shishkin
35ebc57e39SAlexander Shishkin MODULE_DEVICE_TABLE(acpi, intel_th_acpi_ids);
36ebc57e39SAlexander Shishkin
intel_th_acpi_probe(struct platform_device * pdev)37ebc57e39SAlexander Shishkin static int intel_th_acpi_probe(struct platform_device *pdev)
38ebc57e39SAlexander Shishkin {
39ebc57e39SAlexander Shishkin struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
40db73a059SAlexander Shishkin struct resource resource[TH_MMIO_END];
41ebc57e39SAlexander Shishkin const struct acpi_device_id *id;
42ebc57e39SAlexander Shishkin struct intel_th *th;
43*62a59302SAlexander Shishkin int i, r;
44ebc57e39SAlexander Shishkin
45ebc57e39SAlexander Shishkin id = acpi_match_device(intel_th_acpi_ids, &pdev->dev);
46ebc57e39SAlexander Shishkin if (!id)
47ebc57e39SAlexander Shishkin return -ENODEV;
48ebc57e39SAlexander Shishkin
49db73a059SAlexander Shishkin for (i = 0, r = 0; i < pdev->num_resources && r < TH_MMIO_END; i++)
50*62a59302SAlexander Shishkin if (pdev->resource[i].flags &
51*62a59302SAlexander Shishkin (IORESOURCE_IRQ | IORESOURCE_MEM))
52db73a059SAlexander Shishkin resource[r++] = pdev->resource[i];
53db73a059SAlexander Shishkin
54*62a59302SAlexander Shishkin th = intel_th_alloc(&pdev->dev, (void *)id->driver_data, resource, r);
55ebc57e39SAlexander Shishkin if (IS_ERR(th))
56ebc57e39SAlexander Shishkin return PTR_ERR(th);
57ebc57e39SAlexander Shishkin
58ebc57e39SAlexander Shishkin adev->driver_data = th;
59ebc57e39SAlexander Shishkin
60ebc57e39SAlexander Shishkin return 0;
61ebc57e39SAlexander Shishkin }
62ebc57e39SAlexander Shishkin
intel_th_acpi_remove(struct platform_device * pdev)63ebc57e39SAlexander Shishkin static int intel_th_acpi_remove(struct platform_device *pdev)
64ebc57e39SAlexander Shishkin {
65ebc57e39SAlexander Shishkin struct intel_th *th = platform_get_drvdata(pdev);
66ebc57e39SAlexander Shishkin
67ebc57e39SAlexander Shishkin intel_th_free(th);
68ebc57e39SAlexander Shishkin
69ebc57e39SAlexander Shishkin return 0;
70ebc57e39SAlexander Shishkin }
71ebc57e39SAlexander Shishkin
72ebc57e39SAlexander Shishkin static struct platform_driver intel_th_acpi_driver = {
73ebc57e39SAlexander Shishkin .probe = intel_th_acpi_probe,
74ebc57e39SAlexander Shishkin .remove = intel_th_acpi_remove,
75ebc57e39SAlexander Shishkin .driver = {
76ebc57e39SAlexander Shishkin .name = DRIVER_NAME,
77ebc57e39SAlexander Shishkin .acpi_match_table = intel_th_acpi_ids,
78ebc57e39SAlexander Shishkin },
79ebc57e39SAlexander Shishkin };
80ebc57e39SAlexander Shishkin
81ebc57e39SAlexander Shishkin module_platform_driver(intel_th_acpi_driver);
82ebc57e39SAlexander Shishkin
83ebc57e39SAlexander Shishkin MODULE_LICENSE("GPL v2");
84ebc57e39SAlexander Shishkin MODULE_DESCRIPTION("Intel(R) Trace Hub ACPI controller driver");
85ebc57e39SAlexander Shishkin MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@intel.com>");
86