1 // SPDX-License-Identifier: GPL-2.0
3 * Synaptics AS370 SoC Hardware Monitoring Driver
5 * Copyright (C) 2018 Synaptics Incorporated
6 * Author: Jisheng Zhang <jszhang@kernel.org>
9 #include <linux/bitops.h>
10 #include <linux/hwmon.h>
11 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/mod_devicetable.h>
15 #include <linux/platform_device.h>
22 #define NMOS_SEL BIT(8)
23 #define PMOS_SEL BIT(9)
25 #define BN_MASK GENMASK(11, 0)
32 static void init_pvt(struct as370_hwmon
*hwmon
)
35 void __iomem
*addr
= hwmon
->base
+ CTRL
;
38 writel_relaxed(val
, addr
);
40 writel_relaxed(val
, addr
);
42 writel_relaxed(val
, addr
);
44 writel_relaxed(val
, addr
);
47 static int as370_hwmon_read(struct device
*dev
, enum hwmon_sensor_types type
,
48 u32 attr
, int channel
, long *temp
)
51 struct as370_hwmon
*hwmon
= dev_get_drvdata(dev
);
54 case hwmon_temp_input
:
55 val
= readl_relaxed(hwmon
->base
+ STS
) & BN_MASK
;
56 *temp
= DIV_ROUND_CLOSEST(val
* 251802, 4096) - 85525;
66 as370_hwmon_is_visible(const void *data
, enum hwmon_sensor_types type
,
67 u32 attr
, int channel
)
69 if (type
!= hwmon_temp
)
73 case hwmon_temp_input
:
80 static const struct hwmon_channel_info
* const as370_hwmon_info
[] = {
81 HWMON_CHANNEL_INFO(temp
, HWMON_T_INPUT
),
85 static const struct hwmon_ops as370_hwmon_ops
= {
86 .is_visible
= as370_hwmon_is_visible
,
87 .read
= as370_hwmon_read
,
90 static const struct hwmon_chip_info as370_chip_info
= {
91 .ops
= &as370_hwmon_ops
,
92 .info
= as370_hwmon_info
,
95 static int as370_hwmon_probe(struct platform_device
*pdev
)
97 struct device
*hwmon_dev
;
98 struct as370_hwmon
*hwmon
;
99 struct device
*dev
= &pdev
->dev
;
101 hwmon
= devm_kzalloc(dev
, sizeof(*hwmon
), GFP_KERNEL
);
105 hwmon
->base
= devm_platform_ioremap_resource(pdev
, 0);
106 if (IS_ERR(hwmon
->base
))
107 return PTR_ERR(hwmon
->base
);
111 hwmon_dev
= devm_hwmon_device_register_with_info(dev
,
116 return PTR_ERR_OR_ZERO(hwmon_dev
);
119 static const struct of_device_id as370_hwmon_match
[] = {
120 { .compatible
= "syna,as370-hwmon" },
123 MODULE_DEVICE_TABLE(of
, as370_hwmon_match
);
125 static struct platform_driver as370_hwmon_driver
= {
126 .probe
= as370_hwmon_probe
,
128 .name
= "as370-hwmon",
129 .of_match_table
= as370_hwmon_match
,
132 module_platform_driver(as370_hwmon_driver
);
134 MODULE_AUTHOR("Jisheng Zhang<jszhang@kernel.org>");
135 MODULE_DESCRIPTION("Synaptics AS370 SoC hardware monitor");
136 MODULE_LICENSE("GPL v2");