Skip to content

Commit f8896b1

Browse files
fancergregkh
authored andcommitted
hwmon: (bt1-pvt) Test sensor power supply on probe
[ Upstream commit a6db156 ] Baikal-T1 PVT sensor has got a dedicated power supply domain (feed up by the external GPVT/VPVT_18 pins). In case if it isn't powered up, the registers will be accessible, but the sensor conversion just won't happen. Due to that an attempt to read data from any PVT sensor will cause the task hanging up. For instance that will happen if XP11 jumper isn't installed on the Baikal-T1-based BFK3.1 board. Let's at least test whether the conversion work on the device probe procedure. By doing so will make sure that the PVT sensor is powered up at least at boot time. Fixes: 87976ce ("hwmon: Add Baikal-T1 PVT sensor driver") Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru> Link: https://lore.kernel.org/r/20200920110924.19741-2-Sergey.Semin@baikalelectronics.ru Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 283d315 commit f8896b1

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

‎drivers/hwmon/bt1-pvt.c‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/bitops.h>
1414
#include <linux/clk.h>
1515
#include <linux/completion.h>
16+
#include <linux/delay.h>
1617
#include <linux/device.h>
1718
#include <linux/hwmon-sysfs.h>
1819
#include <linux/hwmon.h>
@@ -982,6 +983,41 @@ static int pvt_request_clks(struct pvt_hwmon *pvt)
982983
return 0;
983984
}
984985

986+
static int pvt_check_pwr(struct pvt_hwmon *pvt)
987+
{
988+
unsigned long tout;
989+
int ret = 0;
990+
u32 data;
991+
992+
/*
993+
* Test out the sensor conversion functionality. If it is not done on
994+
* time then the domain must have been unpowered and we won't be able
995+
* to use the device later in this driver.
996+
* Note If the power source is lost during the normal driver work the
997+
* data read procedure will either return -ETIMEDOUT (for the
998+
* alarm-less driver configuration) or just stop the repeated
999+
* conversion. In the later case alas we won't be able to detect the
1000+
* problem.
1001+
*/
1002+
pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_ALL, PVT_INTR_ALL);
1003+
pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, PVT_CTRL_EN);
1004+
pvt_set_tout(pvt, 0);
1005+
readl(pvt->regs + PVT_DATA);
1006+
1007+
tout = PVT_TOUT_MIN / NSEC_PER_USEC;
1008+
usleep_range(tout, 2 * tout);
1009+
1010+
data = readl(pvt->regs + PVT_DATA);
1011+
if (!(data & PVT_DATA_VALID)) {
1012+
ret = -ENODEV;
1013+
dev_err(pvt->dev, "Sensor is powered down\n");
1014+
}
1015+
1016+
pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0);
1017+
1018+
return ret;
1019+
}
1020+
9851021
static void pvt_init_iface(struct pvt_hwmon *pvt)
9861022
{
9871023
u32 trim, temp;
@@ -1109,6 +1145,10 @@ static int pvt_probe(struct platform_device *pdev)
11091145
if (ret)
11101146
return ret;
11111147

1148+
ret = pvt_check_pwr(pvt);
1149+
if (ret)
1150+
return ret;
1151+
11121152
pvt_init_iface(pvt);
11131153

11141154
ret = pvt_request_irq(pvt);

0 commit comments

Comments
 (0)