1 // SPDX-License-Identifier: GPL-2.0+
3 * Functions to access SY3686A power management chip temperature
5 * Copyright (C) 2021 reMarkable AS - http://www.remarkable.com/
7 * Authors: Lars Ivar Miljeteig <lars.ivar.miljeteig@remarkable.com>
8 * Alistair Francis <alistair@alistair23.me>
11 #include <linux/err.h>
12 #include <linux/hwmon.h>
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/regmap.h>
17 #include <linux/regulator/machine.h>
19 #include <linux/mfd/sy7636a.h>
21 static int sy7636a_read(struct device *dev, enum hwmon_sensor_types type,
22 u32 attr, int channel, long *temp)
24 struct regmap *regmap = dev_get_drvdata(dev);
27 ret = regmap_read(regmap,
28 SY7636A_REG_TERMISTOR_READOUT, ®_val);
32 *temp = reg_val * 1000;
37 static umode_t sy7636a_is_visible(const void *data,
38 enum hwmon_sensor_types type,
39 u32 attr, int channel)
41 if (type != hwmon_temp)
44 if (attr != hwmon_temp_input)
50 static const struct hwmon_ops sy7636a_hwmon_ops = {
51 .is_visible = sy7636a_is_visible,
55 static const struct hwmon_channel_info * const sy7636a_info[] = {
56 HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ),
57 HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
61 static const struct hwmon_chip_info sy7636a_chip_info = {
62 .ops = &sy7636a_hwmon_ops,
66 static int sy7636a_sensor_probe(struct platform_device *pdev)
68 struct regmap *regmap = dev_get_regmap(pdev->dev.parent, NULL);
69 struct regulator *regulator;
70 struct device *hwmon_dev;
76 regulator = devm_regulator_get(&pdev->dev, "vcom");
77 if (IS_ERR(regulator))
78 return PTR_ERR(regulator);
80 err = regulator_enable(regulator);
84 hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev,
85 "sy7636a_temperature", regmap,
86 &sy7636a_chip_info, NULL);
88 if (IS_ERR(hwmon_dev)) {
89 err = PTR_ERR(hwmon_dev);
90 dev_err(&pdev->dev, "Unable to register hwmon device, returned %d\n", err);
97 static struct platform_driver sy7636a_sensor_driver = {
98 .probe = sy7636a_sensor_probe,
100 .name = "sy7636a-temperature",
103 module_platform_driver(sy7636a_sensor_driver);
105 MODULE_DESCRIPTION("SY7636A sensor driver");
106 MODULE_LICENSE("GPL");