dmaengine: imx-sdma: Let the core do the device node validation
[linux/fpc-iii.git] / drivers / thermal / thermal_mmio.c
blobde3cceea23bc6372b325086bcf46be9105cd9f74
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 */
6 #include <linux/module.h>
7 #include <linux/of_address.h>
8 #include <linux/platform_device.h>
9 #include <linux/thermal.h>
11 struct thermal_mmio {
12 void __iomem *mmio_base;
13 u32 (*read_mmio)(void __iomem *mmio_base);
14 u32 mask;
15 int factor;
18 static u32 thermal_mmio_readb(void __iomem *mmio_base)
20 return readb(mmio_base);
23 static int thermal_mmio_get_temperature(void *private, int *temp)
25 int t;
26 struct thermal_mmio *sensor =
27 (struct thermal_mmio *)private;
29 t = sensor->read_mmio(sensor->mmio_base) & sensor->mask;
30 t *= sensor->factor;
32 *temp = t;
34 return 0;
37 static struct thermal_zone_of_device_ops thermal_mmio_ops = {
38 .get_temp = thermal_mmio_get_temperature,
41 static int thermal_mmio_probe(struct platform_device *pdev)
43 struct resource *resource;
44 struct thermal_mmio *sensor;
45 int (*sensor_init_func)(struct platform_device *pdev,
46 struct thermal_mmio *sensor);
47 struct thermal_zone_device *thermal_zone;
48 int ret;
49 int temperature;
51 sensor = devm_kzalloc(&pdev->dev, sizeof(*sensor), GFP_KERNEL);
52 if (!sensor)
53 return -ENOMEM;
55 resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
56 if (IS_ERR(resource)) {
57 dev_err(&pdev->dev,
58 "fail to get platform memory resource (%ld)\n",
59 PTR_ERR(resource));
60 return PTR_ERR(resource);
63 sensor->mmio_base = devm_ioremap_resource(&pdev->dev, resource);
64 if (IS_ERR(sensor->mmio_base)) {
65 dev_err(&pdev->dev, "failed to ioremap memory (%ld)\n",
66 PTR_ERR(sensor->mmio_base));
67 return PTR_ERR(sensor->mmio_base);
70 sensor_init_func = device_get_match_data(&pdev->dev);
71 if (sensor_init_func) {
72 ret = sensor_init_func(pdev, sensor);
73 if (ret) {
74 dev_err(&pdev->dev,
75 "failed to initialize sensor (%d)\n",
76 ret);
77 return ret;
81 thermal_zone = devm_thermal_zone_of_sensor_register(&pdev->dev,
83 sensor,
84 &thermal_mmio_ops);
85 if (IS_ERR(thermal_zone)) {
86 dev_err(&pdev->dev,
87 "failed to register sensor (%ld)\n",
88 PTR_ERR(thermal_zone));
89 return PTR_ERR(thermal_zone);
92 thermal_mmio_get_temperature(sensor, &temperature);
93 dev_info(&pdev->dev,
94 "thermal mmio sensor %s registered, current temperature: %d\n",
95 pdev->name, temperature);
97 return 0;
100 static int al_thermal_init(struct platform_device *pdev,
101 struct thermal_mmio *sensor)
103 sensor->read_mmio = thermal_mmio_readb;
104 sensor->mask = 0xff;
105 sensor->factor = 1000;
107 return 0;
110 static const struct of_device_id thermal_mmio_id_table[] = {
111 { .compatible = "amazon,al-thermal", .data = al_thermal_init},
114 MODULE_DEVICE_TABLE(of, thermal_mmio_id_table);
116 static struct platform_driver thermal_mmio_driver = {
117 .probe = thermal_mmio_probe,
118 .driver = {
119 .name = "thermal-mmio",
120 .owner = THIS_MODULE,
121 .of_match_table = of_match_ptr(thermal_mmio_id_table),
125 module_platform_driver(thermal_mmio_driver);
127 MODULE_AUTHOR("Talel Shenhar <talel@amazon.com>");
128 MODULE_DESCRIPTION("Thermal MMIO Driver");
129 MODULE_LICENSE("GPL v2");