| 1 | |
| 2 | |
| 3 | * Functions to access SY3686A power management chip temperature
|
| 4 | *
|
| 5 | * Copyright (C) 2021 reMarkable AS - http://www.remarkable.com/
|
| 6 | *
|
| 7 | * Authors: Lars Ivar Miljeteig <[email protected]>
|
| 8 | * Alistair Francis <[email protected]>
|
| 9 |
|
| 10 |
|
| 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>
|
| 18 |
|
| 19 | #include <linux/mfd/sy7636a.h>
|
| 20 |
|
| 21 | static int sy7636a_read(struct device *dev, enum hwmon_sensor_types type,
|
| 22 | u32 attr, int channel, long *temp)
|
| 23 | {
|
| 24 | struct regmap *regmap = dev_get_drvdata(dev);
|
| 25 | int ret, reg_val;
|
| 26 |
|
| 27 | ret = regmap_read(regmap,
|
| 28 | SY7636A_REG_TERMISTOR_READOUT, ®_val);
|
| 29 | if (ret)
|
| 30 | return ret;
|
| 31 |
|
| 32 | *temp = reg_val * 1000;
|
| 33 |
|
| 34 | return 0;
|
| 35 | }
|
| 36 |
|
| 37 | static umode_t sy7636a_is_visible(const void *data,
|
| 38 | enum hwmon_sensor_types type,
|
| 39 | u32 attr, int channel)
|
| 40 | {
|
| 41 | if (type != hwmon_temp)
|
| 42 | return 0;
|
| 43 |
|
| 44 | if (attr != hwmon_temp_input)
|
| 45 | return 0;
|
| 46 |
|
| 47 | return 0444;
|
| 48 | }
|
| 49 |
|
| 50 | static const struct hwmon_ops sy7636a_hwmon_ops = {
|
| 51 | .is_visible = sy7636a_is_visible,
|
| 52 | .read = sy7636a_read,
|
| 53 | };
|
| 54 |
|
| 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),
|
| 58 | NULL
|
| 59 | };
|
| 60 |
|
| 61 | static const struct hwmon_chip_info sy7636a_chip_info = {
|
| 62 | .ops = &sy7636a_hwmon_ops,
|
| 63 | .info = sy7636a_info,
|
| 64 | };
|
| 65 |
|
| 66 | static int sy7636a_sensor_probe(struct platform_device *pdev)
|
| 67 | {
|
| 68 | struct regmap *regmap = dev_get_regmap(pdev->dev.parent, NULL);
|
| 69 | struct device *hwmon_dev;
|
| 70 | int err;
|
| 71 |
|
| 72 | if (!regmap)
|
| 73 | return -EPROBE_DEFER;
|
| 74 |
|
| 75 | err = devm_regulator_get_enable(&pdev->dev, "vcom");
|
| 76 | if (err)
|
| 77 | return err;
|
| 78 |
|
| 79 | hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev,
|
| 80 | "sy7636a_temperature", regmap,
|
| 81 | &sy7636a_chip_info, NULL);
|
| 82 |
|
| 83 | if (IS_ERR(hwmon_dev)) {
|
| 84 | err = PTR_ERR(hwmon_dev);
|
| 85 | dev_err(&pdev->dev, "Unable to register hwmon device, returned %d\n", err);
|
| 86 | return err;
|
| 87 | }
|
| 88 |
|
| 89 | return 0;
|
| 90 | }
|
| 91 |
|
| 92 | static struct platform_driver sy7636a_sensor_driver = {
|
| 93 | .probe = sy7636a_sensor_probe,
|
| 94 | .driver = {
|
| 95 | .name = "sy7636a-temperature",
|
| 96 | },
|
| 97 | };
|
| 98 | module_platform_driver(sy7636a_sensor_driver);
|
| 99 |
|
| 100 | MODULE_DESCRIPTION("SY7636A sensor driver");
|
| 101 | MODULE_LICENSE("GPL");
|
| 102 | MODULE_ALIAS("platform:sy7636a-temperature");
|