From 61f72c26e7dd578d6a74964eea77f6ccab0c6a9d Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Sun, 7 Feb 2021 09:42:58 -0800 Subject: [PATCH] rM2: hwmon: Copy the rM2 sy7636a-hwmon driver Copy the rM2 zero-sugar branch (https://github.com/reMarkable/linux/tree/zero-sugar) to the new kernel. Signed-off-by: Alistair Francis --- drivers/hwmon/Kconfig | 10 ++++ drivers/hwmon/Makefile | 1 + drivers/hwmon/sy7636a-hwmon.c | 105 ++++++++++++++++++++++++++++++++++ include/linux/mfd/sy7636a.h | 49 ++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 drivers/hwmon/sy7636a-hwmon.c create mode 100644 include/linux/mfd/sy7636a.h diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 2fa4666d5b07..9003a99437f1 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1424,6 +1424,16 @@ config SENSORS_SIS5595 This driver can also be built as a module. If so, the module will be called sis5595. +config SENSORS_SY7636A + tristate "Silergy SY7636A" + depends on I2C + help + If you say yes here you get support for the thermistor readout of + the Silergy SY7636A PMIC. + + This driver can also be built as a module. If so, the module + will be called sy7636a-hwmon. + config SENSORS_DME1737 tristate "SMSC DME1737, SCH311x and compatibles" depends on I2C && !PPC diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index b033e6733b56..0dd646c1e251 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -159,6 +159,7 @@ obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o obj-$(CONFIG_SENSORS_STTS751) += stts751.o +obj-$(CONFIG_SENSORS_SY7636A) += sy7636a-hwmon.o obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o obj-$(CONFIG_SENSORS_TC74) += tc74.o obj-$(CONFIG_SENSORS_THMC50) += thmc50.o diff --git a/drivers/hwmon/sy7636a-hwmon.c b/drivers/hwmon/sy7636a-hwmon.c new file mode 100644 index 000000000000..beaf9a796cfa --- /dev/null +++ b/drivers/hwmon/sy7636a-hwmon.c @@ -0,0 +1,105 @@ +/* + * Functions to access SY3686A power management chip temperature + * + * Copyright (C) 2019 reMarkable AS - http://www.remarkable.com/ + * + * Author: Lars Ivar Miljeteig + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +struct sy7636a_data { + struct sy7636a *sy7636a; + struct device *hwmon_dev; +}; + +static ssize_t show_temp(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned int reg_val; + signed char temp; + int ret; + struct sy7636a_data *data = dev_get_drvdata(dev); + + ret = regmap_read(data->sy7636a->regmap, + SY7636A_REG_TERMISTOR_READOUT, ®_val); + if (ret) + return ret; + + temp = *((signed char*)®_val); + + return snprintf(buf, PAGE_SIZE, "%d\n", temp); +} + +static SENSOR_DEVICE_ATTR(temp0, S_IRUGO, show_temp, NULL, 0); + +static struct attribute *sy7636a_attrs[] = { + &sensor_dev_attr_temp0.dev_attr.attr, + NULL +}; + +ATTRIBUTE_GROUPS(sy7636a); + +static int sy7636a_sensor_probe(struct platform_device *pdev) +{ + struct sy7636a *sy7636a = dev_get_drvdata(pdev->dev.parent); + struct sy7636a_data *data; + int err; + + if (!sy7636a) + return -EPROBE_DEFER; + + data = devm_kzalloc(&pdev->dev, sizeof(struct sy7636a_data), GFP_KERNEL); + if (!data) { + return -ENOMEM; + } + + data->sy7636a = sy7636a; + data->hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, + "sy7636a_temperature", data, sy7636a_groups); + if (IS_ERR(data->hwmon_dev)) { + err = PTR_ERR(data->hwmon_dev); + dev_err(&pdev->dev, "Unable to register hwmon device, returned %d", err); + return err; + } + + return 0; +} + +static const struct platform_device_id sy7636a_sensor_id[] = { + { "sy7636a-temperature", 0}, + { }, +}; +MODULE_DEVICE_TABLE(platform, sy7636a_sensor_id); + +static struct platform_driver sy7636a_sensor_driver = { + .probe = sy7636a_sensor_probe, + .id_table = sy7636a_sensor_id, + .driver = { + .name = "sy7636a-temperature", + }, +}; +module_platform_driver(sy7636a_sensor_driver); + +MODULE_AUTHOR("Lars Ivar Miljeteig "); +MODULE_DESCRIPTION("Silergy SY7636A Sensor Driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/mfd/sy7636a.h b/include/linux/mfd/sy7636a.h new file mode 100644 index 000000000000..e244c30da980 --- /dev/null +++ b/include/linux/mfd/sy7636a.h @@ -0,0 +1,49 @@ +/* + * Functions to access SY3686A power management chip. + * + * Copyright (C) 2019 reMarkable AS - http://www.remarkable.com/ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __LINUX_MFD_SY7636A_H +#define __LINUX_MFD_SY7636A_H + +#include +#include +#include +#include + +#define SY7636A_REG_OPERATION_MODE_CRL 0x00 +#define SY7636A_OPERATION_MODE_CRL_VCOMCTL (1 << 6) +#define SY7636A_OPERATION_MODE_CRL_ONOFF (1 << 7) +#define SY7636A_REG_VCOM_ADJUST_CTRL_L 0x01 +#define SY7636A_REG_VCOM_ADJUST_CTRL_H 0x02 +#define SY7636A_REG_VCOM_ADJUST_CTRL_MASK 0x01ff +#define SY7636A_REG_VLDO_VOLTAGE_ADJULST_CTRL 0x03 +#define SY7636A_REG_POWER_ON_DELAY_TIME 0x06 +#define SY7636A_REG_FAULT_FLAG 0x07 +#define SY7636A_FAULT_FLAG_PG (1 << 0) +#define SY7636A_REG_TERMISTOR_READOUT 0x08 + +#define SY7636A_REG_MAX 0x08 + +struct sy7636a { + struct device *dev; + struct regmap *regmap; + unsigned int vcom; + struct gpio_desc *pgood_gpio; + struct mutex reglock; +}; + +int get_vcom_voltage_mv(struct regmap *regmap); +int set_vcom_voltage_mv(struct regmap *regmap, unsigned int vcom); + +#endif /* __LINUX_MFD_SY7636A_H */