Skip to contentSkip to conversation

sy7636a: power the panel only during updates

PATCH Applied Pablo Mazzini 4 participants 14 messages Nov 8 – Nov 12

Subsystems (5)

v3 of 5 Applied Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover sy7636a: power the panel only during updates

The SY7636A hwmon driver keeps VCOM on from probe, so a display driver can not power the panel only during updates.

Read the temperature only while the rails are on instead, and bind the regulator to the I2C device directly, with the hwmon driver as its auxiliary driver.

v2 patches 1-3 are in regulator for-7.5, so this is based on it. Patch 3 touches the regulator, hwmon and MFD drivers and removes the MFD header, so the series should go through the regulator tree, with acks from Guenter and Lee.

Tested on a PocketBook Verse (B288).

v3:
- drop the applied patches 1-3
- new patch 1: no wait when power good is already high (Mark)
- move the I2C binding before the hwmon read change, so the hwmon driver only probes once vin is on (Andreas)
- patch 4: explain in a comment why power good gates the read, and its limitation (Guenter, Andreas)

v2:
- drop the DT patch keeping VCOM always-on (Andreas)
- only wait for power good, VCOM_EN stays as it was (Andreas)
- new patch: fix negative temperatures
- keep the temperature in drivers/hwmon as an auxiliary driver of the regulator, instead of moving it into the regulator driver (Guenter, Andreas)
- no VCOM enable at probe, which also removes the probe race
- read power good and the temperature in one transfer (Andreas)

Pablo Mazzini (5):

regulator: sy7636a: don't wait for power good if already on
hwmon: sy7636a: fix negative temperatures
regulator: sy7636a: bind to the I2C device directly
hwmon: sy7636a: read the temperature only while the rails are on
ARM: imx_v6_v7_defconfig: drop the SY7636A MFD option

 arch/arm/configs/imx_v6_v7_defconfig  |  1 -
 drivers/hwmon/Kconfig                 |  2 +-
 drivers/hwmon/sy7636a-hwmon.c         | 66 ++++++++++++--------
 drivers/mfd/Kconfig                   | 10 ---
 drivers/mfd/simple-mfd-i2c.c          | 11 ----
 drivers/regulator/Kconfig             |  4 +-
 drivers/regulator/sy7636a-regulator.c | 90 ++++++++++++++++-----------
 include/linux/mfd/sy7636a.h           | 34 ----------
 8 files changed, 99 insertions(+), 119 deletions(-)
 delete mode 100644 include/linux/mfd/sy7636a.h

base-commit: 2a1984b30e9cfcb306a076cb4b9e68d71daeb45c

Signature · 1 line
2.52.0
#1 lore raw

PATCH v3 1/5 regulator: sy7636a: don't wait for power good if already on

A boot-on regulator is already on when the core enables it, so there is no power good edge and the enable waits for the full timeout. Return early if power good is already set.

Fixes 9037a00f3845 ("regulator: sy7636a: wait for power good on enable")
---
 drivers/regulator/sy7636a-regulator.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/regulator/sy7636a-regulator.c +4 -0
index f87144e921da..6269c50348ac 100644
@@ -90,6 +90,10 @@ static int sy7636a_enable(struct regulator_dev *rdev)
 	if (ret)
 		return ret;
 
+	/* already on, e.g. a boot-on regulator left on by the bootloader */
+	if (gpiod_get_value_cansleep(data->pgood_gpio) > 0)
+		return 0;
+
 	wait_for_completion_timeout(&data->pgood_completion,
 				    msecs_to_jiffies(PGOOD_TIMEOUT_MSECS));
 	ret = gpiod_get_value_cansleep(data->pgood_gpio);
Signature · 1 line
2.52.0
#2 lore raw

PATCH v3 2/5 hwmon: sy7636a: fix negative temperatures

In reply to Pablo Mazzini

The thermistor readout is a signed 8-bit value in degrees Celsius.

Fixes de34a4053250 ("hwmon: sy7636a: Add temperature driver for sy7636a")
---
 drivers/hwmon/sy7636a-hwmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/sy7636a-hwmon.c +1 -1
index d51daaf63d63..f01f368d68e5 100644
@@ -29,7 +29,7 @@ static int sy7636a_read(struct device *dev, enum hwmon_sensor_types type,
 	if (ret)
 		return ret;
 
-	*temp = reg_val * 1000;
+	*temp = (s8)reg_val * 1000;
 
 	return 0;
 }
Signature · 1 line
2.52.0
#5 lore raw

PATCH v3 3/5 regulator: sy7636a: bind to the I2C device directly

In reply to Pablo Mazzini

Bind the regulator to the chip directly, as the TPS65185 and FP9931 drivers do, and have it create an auxiliary device for the hwmon driver, instead of simple-mfd-i2c creating a cell for each. Drop the MFD glue and header. It now probes before the GPIOs may be ready, so report the power good GPIO with dev_err_probe(). The hwmon driver then only accesses the chip after vin-supply is enabled.

---
 drivers/hwmon/Kconfig                 |  2 +-
 drivers/hwmon/sy7636a-hwmon.c         | 33 +++++-----
 drivers/mfd/Kconfig                   | 10 ----
 drivers/mfd/simple-mfd-i2c.c          | 11 ----
 drivers/regulator/Kconfig             |  4 +-
 drivers/regulator/sy7636a-regulator.c | 86 ++++++++++++++++-----------
 include/linux/mfd/sy7636a.h           | 34 -----------
 7 files changed, 72 insertions(+), 108 deletions(-)
 delete mode 100644 include/linux/mfd/sy7636a.h
drivers/hwmon/Kconfig +1 -1
index 18c682e1a475..247507a4ddde 100644
@@ -2106,7 +2106,7 @@ config SENSORS_SIS5595
 
 config SENSORS_SY7636A
 	tristate "Silergy SY7636A"
-	depends on MFD_SY7636A
+	depends on REGULATOR_SY7636A
 	help
 	  If you say yes here you get support for the thermistor readout of
 	  the Silergy SY7636A PMIC.
drivers/hwmon/sy7636a-hwmon.c +18 -15
index f01f368d68e5..a6b47452e29e 100644
@@ -8,15 +8,14 @@
  *          Alistair Francis <[email protected]>
  */
 
+#include <linux/auxiliary_bus.h>
 #include <linux/err.h>
 #include <linux/hwmon.h>
-#include <linux/init.h>
 #include <linux/module.h>
-#include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/regulator/machine.h>
 
-#include <linux/mfd/sy7636a.h>
+#define SY7636A_REG_TERMISTOR_READOUT	0x08
 
 static int sy7636a_read(struct device *dev, enum hwmon_sensor_types type,
 			u32 attr, int channel, long *temp)
@@ -63,40 +62,44 @@ static const struct hwmon_chip_info sy7636a_chip_info = {
 	.info = sy7636a_info,
 };
 
-static int sy7636a_sensor_probe(struct platform_device *pdev)
+static int sy7636a_sensor_probe(struct auxiliary_device *adev,
+				const struct auxiliary_device_id *id)
 {
-	struct regmap *regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	struct regmap *regmap = dev_get_regmap(adev->dev.parent, NULL);
 	struct device *hwmon_dev;
 	int err;
 
 	if (!regmap)
-		return -EPROBE_DEFER;
+		return -ENODEV;
 
-	err = devm_regulator_get_enable(&pdev->dev, "vcom");
+	err = devm_regulator_get_enable(&adev->dev, "vcom");
 	if (err)
 		return err;
 
-	hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev,
+	hwmon_dev = devm_hwmon_device_register_with_info(&adev->dev,
 							 "sy7636a_temperature", regmap,
 							 &sy7636a_chip_info, NULL);
 
 	if (IS_ERR(hwmon_dev)) {
 		err = PTR_ERR(hwmon_dev);
-		dev_err(&pdev->dev, "Unable to register hwmon device, returned %d\n", err);
+		dev_err(&adev->dev, "Unable to register hwmon device, returned %d\n", err);
 		return err;
 	}
 
 	return 0;
 }
 
-static struct platform_driver sy7636a_sensor_driver = {
+static const struct auxiliary_device_id sy7636a_sensor_ids[] = {
+	{ .name = "sy7636a_regulator.hwmon" },
+	{ }
+};
+MODULE_DEVICE_TABLE(auxiliary, sy7636a_sensor_ids);
+
+static struct auxiliary_driver sy7636a_sensor_driver = {
 	.probe = sy7636a_sensor_probe,
-	.driver = {
-		.name = "sy7636a-temperature",
-	},
+	.id_table = sy7636a_sensor_ids,
 };
-module_platform_driver(sy7636a_sensor_driver);
+module_auxiliary_driver(sy7636a_sensor_driver);
 
 MODULE_DESCRIPTION("SY7636A sensor driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:sy7636a-temperature");
drivers/mfd/Kconfig +0 -10
index 87ed55c155f0..c7ff8997beb1 100644
@@ -1319,16 +1319,6 @@ config MFD_SPMI_PMIC
 	  Say M here if you want to include support for the SPMI PMIC
 	  series as a module.  The module will be called "qcom-spmi-pmic".
 
-config MFD_SY7636A
-	tristate "Silergy SY7636A voltage regulator"
-	depends on I2C
-	select MFD_SIMPLE_MFD_I2C
-	help
-	  Enable support for Silergy SY7636A voltage regulator.
-
-	  To enable support for building sub-devices as modules,
-	  choose M here.
-
 config MFD_RDC321X
 	tristate "RDC R-321x southbridge"
 	select MFD_CORE
drivers/mfd/simple-mfd-i2c.c +0 -11
index ef3ce4bdf98b..0c9162034899 100644
@@ -67,16 +67,6 @@ static int simple_mfd_i2c_probe(struct i2c_client *i2c)
 	return ret;
 }
 
-static const struct mfd_cell sy7636a_cells[] = {
-	{ .name = "sy7636a-regulator", },
-	{ .name = "sy7636a-temperature", },
-};
-
-static const struct simple_mfd_data silergy_sy7636a = {
-	.mfd_cell = sy7636a_cells,
-	.mfd_cell_size = ARRAY_SIZE(sy7636a_cells),
-};
-
 static const struct mfd_cell max5970_cells[] = {
 	{ .name = "max5970-regulator", },
 	{ .name = "max5970-iio", },
@@ -124,7 +114,6 @@ static const struct of_device_id simple_mfd_i2c_of_match[] = {
 	{ .compatible = "maxim,max5970", .data = &maxim_max5970 },
 	{ .compatible = "maxim,max5978", .data = &maxim_max5970 },
 	{ .compatible = "maxim,max77705-battery", .data = &maxim_mon_max77705 },
-	{ .compatible = "silergy,sy7636a", .data = &silergy_sy7636a },
 	{ .compatible = "spacemit,p1", .data = &spacemit_p1 },
 	{}
 };
drivers/regulator/Kconfig +3 -1
index 4a57feae3560..2ed21d57df75 100644
@@ -1621,7 +1621,9 @@ config REGULATOR_SUN20I
 
 config REGULATOR_SY7636A
 	tristate "Silergy SY7636A voltage regulator"
-	depends on MFD_SY7636A
+	depends on I2C
+	select AUXILIARY_BUS
+	select REGMAP_I2C
 	help
 	  This driver supports Silergy SY7636A voltage regulator.
 
drivers/regulator/sy7636a-regulator.c +50 -36

172 lines not on this page · raw message

include/linux/mfd/sy7636a.h deleted +0 -34
deleted file mode 100644
index 22f03b2f851e..000000000000
@@ -1,34 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Functions to access SY3686A power management chip.
- *
- * Copyright (C) 2021 reMarkable AS - http://www.remarkable.com/
- */
-
-#ifndef __MFD_SY7636A_H
-#define __MFD_SY7636A_H
-
-#define SY7636A_REG_OPERATION_MODE_CRL		0x00
-/* It is set if a gpio is used to control the regulator */
-#define SY7636A_OPERATION_MODE_CRL_VCOMCTL	BIT(6)
-#define SY7636A_OPERATION_MODE_CRL_ONOFF	BIT(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			BIT(0)
-#define SY7636A_REG_TERMISTOR_READOUT		0x08
-
-#define SY7636A_REG_MAX				0x08
-
-#define VCOM_ADJUST_CTRL_MASK	0x1ff
-// Used to shift the high byte
-#define VCOM_ADJUST_CTRL_SHIFT	8
-// Used to scale from VCOM_ADJUST_CTRL to mv
-#define VCOM_ADJUST_CTRL_SCAL	10000
-
-#define FAULT_FLAG_SHIFT	1
-
-#endif /* __LINUX_MFD_SY7636A_H */
Signature · 1 line
2.52.0
#8 lore raw

PATCH v3 4/5 hwmon: sy7636a: read the temperature only while the rails are on

In reply to Pablo Mazzini

The driver enables VCOM at probe, which keeps the panel's high voltage rails on for good. Read the temperature only while the rails are on, when the chip samples it, and return -ENODATA otherwise. Read power good with it in one transfer, so the value can not be from before the first sample or after the rails went off. Register it under the chip name, as the TPS65185 and FP9931 drivers do.

---
 drivers/hwmon/sy7636a-hwmon.c | 37 +++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)
drivers/hwmon/sy7636a-hwmon.c +25 -12
index a6b47452e29e..0c0601d47b87 100644
@@ -9,26 +9,43 @@
  */
 
 #include <linux/auxiliary_bus.h>
+#include <linux/bits.h>
 #include <linux/err.h>
 #include <linux/hwmon.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
-#include <linux/regulator/machine.h>
 
-#define SY7636A_REG_TERMISTOR_READOUT	0x08
+#define SY7636A_REG_FAULT_FLAG		0x07
+#define SY7636A_FAULT_FLAG_PG		BIT(0)
 
 static int sy7636a_read(struct device *dev, enum hwmon_sensor_types type,
 			u32 attr, int channel, long *temp)
 {
 	struct regmap *regmap = dev_get_drvdata(dev);
-	int ret, reg_val;
-
-	ret = regmap_read(regmap,
-			  SY7636A_REG_TERMISTOR_READOUT, &reg_val);
+	u8 buf[2];
+	int ret;
+
+	/*
+	 * The thermistor is sampled while ON_OFF is set, but the first sample
+	 * is only ready after the ADC sampling and conversion time (ADC_SPL +
+	 * ADC_DEL in the datasheet); until then it holds its reset value, 0.
+	 * PG is only set once all rails are up, after the first sample, so
+	 * read it in the same transfer and report the temperature only while
+	 * it is set.
+	 *
+	 * With ON_OFF set but PG low (rails still ramping up, or a fault), no
+	 * temperature is reported even if one may be available. That is
+	 * accepted: the display driver reads the temperature only while it
+	 * holds the rails on, after power good.
+	 */
+	ret = regmap_bulk_read(regmap, SY7636A_REG_FAULT_FLAG, buf, sizeof(buf));
 	if (ret)
 		return ret;
 
-	*temp = (s8)reg_val * 1000;
+	if (!(buf[0] & SY7636A_FAULT_FLAG_PG))
+		return -ENODATA;
+
+	*temp = (s8)buf[1] * 1000;
 
 	return 0;
 }
@@ -72,12 +89,8 @@ static int sy7636a_sensor_probe(struct auxiliary_device *adev,
 	if (!regmap)
 		return -ENODEV;
 
-	err = devm_regulator_get_enable(&adev->dev, "vcom");
-	if (err)
-		return err;
-
 	hwmon_dev = devm_hwmon_device_register_with_info(&adev->dev,
-							 "sy7636a_temperature", regmap,
+							 "sy7636a", regmap,
 							 &sy7636a_chip_info, NULL);
 
 	if (IS_ERR(hwmon_dev)) {
Signature · 1 line
2.52.0
#12 lore raw

PATCH v3 5/5 ARM: imx_v6_v7_defconfig: drop the SY7636A MFD option

In reply to Pablo Mazzini

The SY7636A is no longer bound through an MFD.

---
 arch/arm/configs/imx_v6_v7_defconfig | 1 -
 1 file changed, 1 deletion(-)
arch/arm/configs/imx_v6_v7_defconfig +0 -1
index ed588add8d31..f02b5605e533 100644
@@ -239,7 +239,6 @@ CONFIG_MFD_DA9062=y
 CONFIG_MFD_DA9063=y
 CONFIG_MFD_MC13XXX_SPI=y
 CONFIG_MFD_MC13XXX_I2C=y
-CONFIG_MFD_SY7636A=y
 CONFIG_MFD_RN5T618=y
 CONFIG_MFD_STMPE=y
 CONFIG_MFD_ROHM_BD71828=y
Signature · 1 line
2.52.0
#3 lore raw

Re: [PATCH v3 2/5] hwmon: sy7636a: fix negative temperatures

In reply to Pablo Mazzini
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines

The thermistor readout is a signed 8-bit value in degrees Celsius.

Fixes de34a4053250 ("hwmon: sy7636a: Add temperature driver for sy7636a")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw

Re: [PATCH v3 3/5] regulator: sy7636a: bind to the I2C device directly

In reply to Pablo Mazzini
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

Bind the regulator to the chip directly, as the TPS65185 and FP9931 drivers do, and have it create an auxiliary device for the hwmon driver, instead of simple-mfd-i2c creating a cell for each. Drop the MFD glue and header. It now probes before the GPIOs may be ready, so report the power good GPIO with dev_err_probe(). The hwmon driver then only accesses the chip after vin-supply is enabled.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#9 lore raw

Re: [PATCH v3 4/5] hwmon: sy7636a: read the temperature only while the rails are on

In reply to Pablo Mazzini
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

The driver enables VCOM at probe, which keeps the panel's high voltage rails on for good. Read the temperature only while the rails are on, when the chip samples it, and return -ENODATA otherwise. Read power good with it in one transfer, so the value can not be from before the first sample or after the rails went off. Register it under the chip name, as the TPS65185 and FP9931 drivers do.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
maintainer
#10 lore raw

Re: [PATCH v3 4/5] hwmon: sy7636a: read the temperature only while the rails are on

In reply to Pablo Mazzini
Quoted 68 lines · Pablo Mazzini

The driver enables VCOM at probe, which keeps the panel's high voltage rails on for good. Read the temperature only while the rails are on, when the chip samples it, and return -ENODATA otherwise. Read power good with it in one transfer, so the value can not be from before the first sample or after the rails went off. Register it under the chip name, as the TPS65185 and FP9931 drivers do.

---
 drivers/hwmon/sy7636a-hwmon.c | 37 +++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)
drivers/hwmon/sy7636a-hwmon.c +24 -7
index a6b47452e29e..0c0601d47b87 100644
@@ -9,26 +9,43 @@
  */
 
 #include <linux/auxiliary_bus.h>
+#include <linux/bits.h>
 #include <linux/err.h>
 #include <linux/hwmon.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
-#include <linux/regulator/machine.h>
 
-#define SY7636A_REG_TERMISTOR_READOUT	0x08
+#define SY7636A_REG_FAULT_FLAG		0x07
+#define SY7636A_FAULT_FLAG_PG		BIT(0)
 
 static int sy7636a_read(struct device *dev, enum hwmon_sensor_types type,
 			u32 attr, int channel, long *temp)
 {
 	struct regmap *regmap = dev_get_drvdata(dev);
-	int ret, reg_val;
-
-	ret = regmap_read(regmap,
-			  SY7636A_REG_TERMISTOR_READOUT, &reg_val);
+	u8 buf[2];
+	int ret;
+
+	/*
+	 * The thermistor is sampled while ON_OFF is set, but the first sample
+	 * is only ready after the ADC sampling and conversion time (ADC_SPL +
+	 * ADC_DEL in the datasheet); until then it holds its reset value, 0.
+	 * PG is only set once all rails are up, after the first sample, so
+	 * read it in the same transfer and report the temperature only while
+	 * it is set.
+	 *
+	 * With ON_OFF set but PG low (rails still ramping up, or a fault), no
+	 * temperature is reported even if one may be available. That is
+	 * accepted: the display driver reads the temperature only while it
+	 * holds the rails on, after power good.
+	 */
+	ret = regmap_bulk_read(regmap, SY7636A_REG_FAULT_FLAG, buf, sizeof(buf));
 	if (ret)
 		return ret;
 
-	*temp = (s8)reg_val * 1000;
+	if (!(buf[0] & SY7636A_FAULT_FLAG_PG))
+		return -ENODATA;
+
+	*temp = (s8)buf[1] * 1000;
 
 	return 0;
 }

drivers/hwmon/sy7636a-hwmon.c static int sy7636a_sensor_probe(struct auxiliary_device *adev, · line 93

Quoted 10 lines
drivers/hwmon/sy7636a-hwmon.c +1 -5
@@ -72,12 +89,8 @@ static int sy7636a_sensor_probe(struct auxiliary_device *adev,
 	if (!regmap)
 		return -ENODEV;
 
-	err = devm_regulator_get_enable(&adev->dev, "vcom");
-	if (err)
-		return err;
-
 	hwmon_dev = devm_hwmon_device_register_with_info(&adev->dev,
-							 "sy7636a_temperature", regmap,
+							 "sy7636a", regmap,

This change is neither related to this patch nor necessary. Other drivers (unnecessarily) doing the same is not an argument.

Guenter

Quoted 3 lines
drivers/hwmon/sy7636a-hwmon.c +0 -0
 							 &sy7636a_chip_info, NULL);
 
 	if (IS_ERR(hwmon_dev)) {
#11 lore raw

Re: [PATCH v3 4/5] hwmon: sy7636a: read the temperature only while the rails are on

Quoted 6 lines · Guenter Roeck

drivers/hwmon/sy7636a-hwmon.c static int sy7636a_sensor_probe(struct auxiliary_device *adev, · line 93

Quoted 3 lines
    hwmon_dev = devm_hwmon_device_register_with_info(&adev->dev,
drivers/hwmon/sy7636a-hwmon.c +1 -1
-                                                    "sy7636a_temperature", regmap,
+                                                    "sy7636a", regmap,

This change is neither related to this patch nor necessary. Other drivers (unnecessarily) doing the same is not an argument.

Right, I'll drop it in v4.

Quoted 89 lines · Guenter Roeck
Quoted 68 lines · Pablo Mazzini

The driver enables VCOM at probe, which keeps the panel's high voltage rails on for good. Read the temperature only while the rails are on, when the chip samples it, and return -ENODATA otherwise. Read power good with it in one transfer, so the value can not be from before the first sample or after the rails went off. Register it under the chip name, as the TPS65185 and FP9931 drivers do.

---
 drivers/hwmon/sy7636a-hwmon.c | 37 +++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)
drivers/hwmon/sy7636a-hwmon.c +24 -7
index a6b47452e29e..0c0601d47b87 100644
@@ -9,26 +9,43 @@
  */
 
 #include <linux/auxiliary_bus.h>
+#include <linux/bits.h>
 #include <linux/err.h>
 #include <linux/hwmon.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
-#include <linux/regulator/machine.h>
 
-#define SY7636A_REG_TERMISTOR_READOUT        0x08
+#define SY7636A_REG_FAULT_FLAG               0x07
+#define SY7636A_FAULT_FLAG_PG                BIT(0)
 
 static int sy7636a_read(struct device *dev, enum hwmon_sensor_types type,
                      u32 attr, int channel, long *temp)
 {
      struct regmap *regmap = dev_get_drvdata(dev);
-     int ret, reg_val;
-
-     ret = regmap_read(regmap,
-                       SY7636A_REG_TERMISTOR_READOUT, &reg_val);
+     u8 buf[2];
+     int ret;
+
+     /*
+      * The thermistor is sampled while ON_OFF is set, but the first sample
+      * is only ready after the ADC sampling and conversion time (ADC_SPL +
+      * ADC_DEL in the datasheet); until then it holds its reset value, 0.
+      * PG is only set once all rails are up, after the first sample, so
+      * read it in the same transfer and report the temperature only while
+      * it is set.
+      *
+      * With ON_OFF set but PG low (rails still ramping up, or a fault), no
+      * temperature is reported even if one may be available. That is
+      * accepted: the display driver reads the temperature only while it
+      * holds the rails on, after power good.
+      */
+     ret = regmap_bulk_read(regmap, SY7636A_REG_FAULT_FLAG, buf, sizeof(buf));
      if (ret)
              return ret;
 
-     *temp = (s8)reg_val * 1000;
+     if (!(buf[0] & SY7636A_FAULT_FLAG_PG))
+             return -ENODATA;
+
+     *temp = (s8)buf[1] * 1000;
 
      return 0;
 }

drivers/hwmon/sy7636a-hwmon.c static int sy7636a_sensor_probe(struct auxiliary_device *adev, · line 93

Quoted 10 lines
drivers/hwmon/sy7636a-hwmon.c +1 -5
@@ -72,12 +89,8 @@ static int sy7636a_sensor_probe(struct auxiliary_device *adev,
      if (!regmap)
              return -ENODEV;
 
-     err = devm_regulator_get_enable(&adev->dev, "vcom");
-     if (err)
-             return err;
-
      hwmon_dev = devm_hwmon_device_register_with_info(&adev->dev,
-                                                      "sy7636a_temperature", regmap,
+                                                      "sy7636a", regmap,

This change is neither related to this patch nor necessary. Other drivers (unnecessarily) doing the same is not an argument.

Guenter

Quoted 3 lines
drivers/hwmon/sy7636a-hwmon.c +0 -0
                                                       &sy7636a_chip_info, NULL);
 
      if (IS_ERR(hwmon_dev)) {
maintainer Applied
#4 lore raw

Re: [PATCH v3 2/5] hwmon: sy7636a: fix negative temperatures

In reply to Pablo Mazzini
Quoted 4 lines · Pablo Mazzini

The thermistor readout is a signed 8-bit value in degrees Celsius.

Fixes de34a4053250 ("hwmon: sy7636a: Add temperature driver for sy7636a")

Applied.

Thanks,
Guenter

Quoted 17 lines
---
 drivers/hwmon/sy7636a-hwmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/sy7636a-hwmon.c +1 -1
index d51daaf63d63..f01f368d68e5 100644
@@ -29,7 +29,7 @@ static int sy7636a_read(struct device *dev, enum hwmon_sensor_types type,
 	if (ret)
 		return ret;
 
-	*temp = reg_val * 1000;
+	*temp = (s8)reg_val * 1000;
 
 	return 0;
 }
maintainer Acked-by on v3 3/5
#7 lore raw

Re: [PATCH v3 3/5] regulator: sy7636a: bind to the I2C device directly

In reply to Pablo Mazzini
Quoted 8 lines · Pablo Mazzini

Bind the regulator to the chip directly, as the TPS65185 and FP9931 drivers do, and have it create an auxiliary device for the hwmon driver, instead of simple-mfd-i2c creating a cell for each. Drop the MFD glue and header. It now probes before the GPIOs may be ready, so report the power good GPIO with dev_err_probe(). The hwmon driver then only accesses the chip after vin-supply is enabled.

For hwmon:

maintainer
#13 lore raw

Re: (subset) [PATCH v3 0/5] sy7636a: power the panel only during updates

In reply to Pablo Mazzini
Quoted 10 lines · Pablo Mazzini

sy7636a: power the panel only during updates

The SY7636A hwmon driver keeps VCOM on from probe, so a display driver can not power the panel only during updates.

Read the temperature only while the rails are on instead, and bind the regulator to the I2C device directly, with the hwmon driver as its auxiliary driver.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-7.5

Thanks!

[1/5] regulator: sy7636a: don't wait for power good if already on

      https://git.kernel.org/broonie/regulator/c/7d9a62b7e554
[3/5] regulator: sy7636a: bind to the I2C device directly
      https://git.kernel.org/broonie/regulator/c/5f828ac25ef9

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark