1
0
Fork 0

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 <alistair@alistair23.me>
5.4-rM2-2.2.x-imx-deep-sleep
Alistair Francis 2021-02-07 09:42:58 -08:00
parent 947d13cb95
commit 61f72c26e7
4 changed files with 165 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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 <lars.ivar.miljeteig@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.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/jiffies.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/sysfs.h>
#include <linux/platform_device.h>
#include <linux/mfd/sy7636a.h>
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, &reg_val);
if (ret)
return ret;
temp = *((signed char*)&reg_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 <lars.ivar.miljeteig@remarkable.com>");
MODULE_DESCRIPTION("Silergy SY7636A Sensor Driver");
MODULE_LICENSE("GPL v2");

View File

@ -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 <linux/i2c.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#include <linux/regmap.h>
#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 */