aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/hwmon/gpio-fan.txt (renamed from Documentation/devicetree/bindings/gpio/gpio-fan.txt)0
-rw-r--r--Documentation/devicetree/bindings/hwmon/max1619.txt12
-rw-r--r--Documentation/devicetree/bindings/hwmon/max31785.txt22
-rw-r--r--Documentation/devicetree/bindings/trivial-devices.txt1
-rw-r--r--Documentation/hwmon/max3178551
-rw-r--r--Documentation/hwmon/sht153
-rw-r--r--arch/arm/mach-pxa/stargate2.c17
-rw-r--r--drivers/hwmon/Kconfig15
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/hwmon/asc7621.c1
-rw-r--r--drivers/hwmon/aspeed-pwm-tacho.c8
-rw-r--r--drivers/hwmon/gpio-fan.c224
-rw-r--r--drivers/hwmon/k10temp.c108
-rw-r--r--drivers/hwmon/max1619.c10
-rw-r--r--drivers/hwmon/max6621.c593
-rw-r--r--drivers/hwmon/pmbus/Kconfig10
-rw-r--r--drivers/hwmon/pmbus/Makefile1
-rw-r--r--drivers/hwmon/pmbus/max31785.c116
-rw-r--r--drivers/hwmon/pmbus/pmbus.h6
-rw-r--r--drivers/hwmon/pmbus/pmbus_core.c25
-rw-r--r--drivers/hwmon/sht15.c175
-rw-r--r--drivers/hwmon/stts751.c18
-rw-r--r--drivers/hwmon/w83793.c4
-rw-r--r--drivers/hwmon/xgene-hwmon.c39
-rw-r--r--include/linux/gpio-fan.h36
-rw-r--r--include/linux/platform_data/sht15.h38
26 files changed, 1131 insertions, 403 deletions
diff --git a/Documentation/devicetree/bindings/gpio/gpio-fan.txt b/Documentation/devicetree/bindings/hwmon/gpio-fan.txt
index 439a7430fc68..439a7430fc68 100644
--- a/Documentation/devicetree/bindings/gpio/gpio-fan.txt
+++ b/Documentation/devicetree/bindings/hwmon/gpio-fan.txt
diff --git a/Documentation/devicetree/bindings/hwmon/max1619.txt b/Documentation/devicetree/bindings/hwmon/max1619.txt
new file mode 100644
index 000000000000..c70dbbe1e56f
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/max1619.txt
@@ -0,0 +1,12 @@
1Bindings for MAX1619 Temperature Sensor
2
3Required properties:
4- compatible : "maxim,max1619"
5- reg : I2C address, one of 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, or
6 0x4d, 0x4e
7
8Example:
9 temp@4c {
10 compatible = "maxim,max1619";
11 reg = <0x4c>;
12 };
diff --git a/Documentation/devicetree/bindings/hwmon/max31785.txt b/Documentation/devicetree/bindings/hwmon/max31785.txt
new file mode 100644
index 000000000000..106e08c56aaa
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/max31785.txt
@@ -0,0 +1,22 @@
1Bindings for the Maxim MAX31785 Intelligent Fan Controller
2==========================================================
3
4Reference:
5
6https://datasheets.maximintegrated.com/en/ds/MAX31785.pdf
7
8The Maxim MAX31785 is a PMBus device providing closed-loop, multi-channel fan
9management with temperature and remote voltage sensing. Various fan control
10features are provided, including PWM frequency control, temperature hysteresis,
11dual tachometer measurements, and fan health monitoring.
12
13Required properties:
14- compatible : One of "maxim,max31785" or "maxim,max31785a"
15- reg : I2C address, one of 0x52, 0x53, 0x54, 0x55.
16
17Example:
18
19 fans@52 {
20 compatible = "maxim,max31785";
21 reg = <0x52>;
22 };
diff --git a/Documentation/devicetree/bindings/trivial-devices.txt b/Documentation/devicetree/bindings/trivial-devices.txt
index af284fbd4d23..8bcac6ee73da 100644
--- a/Documentation/devicetree/bindings/trivial-devices.txt
+++ b/Documentation/devicetree/bindings/trivial-devices.txt
@@ -71,6 +71,7 @@ isil,isl29028 Intersil ISL29028 Ambient Light and Proximity Sensor
71isil,isl29030 Intersil ISL29030 Ambient Light and Proximity Sensor 71isil,isl29030 Intersil ISL29030 Ambient Light and Proximity Sensor
72maxim,ds1050 5 Bit Programmable, Pulse-Width Modulator 72maxim,ds1050 5 Bit Programmable, Pulse-Width Modulator
73maxim,max1237 Low-Power, 4-/12-Channel, 2-Wire Serial, 12-Bit ADCs 73maxim,max1237 Low-Power, 4-/12-Channel, 2-Wire Serial, 12-Bit ADCs
74maxim,max6621 PECI-to-I2C translator for PECI-to-SMBus/I2C protocol conversion
74maxim,max6625 9-Bit/12-Bit Temperature Sensors with I²C-Compatible Serial Interface 75maxim,max6625 9-Bit/12-Bit Temperature Sensors with I²C-Compatible Serial Interface
75mc,rv3029c2 Real Time Clock Module with I2C-Bus 76mc,rv3029c2 Real Time Clock Module with I2C-Bus
76mcube,mc3230 mCube 3-axis 8-bit digital accelerometer 77mcube,mc3230 mCube 3-axis 8-bit digital accelerometer
diff --git a/Documentation/hwmon/max31785 b/Documentation/hwmon/max31785
new file mode 100644
index 000000000000..45fb6093dec2
--- /dev/null
+++ b/Documentation/hwmon/max31785
@@ -0,0 +1,51 @@
1Kernel driver max31785
2======================
3
4Supported chips:
5 * Maxim MAX31785, MAX31785A
6 Prefix: 'max31785' or 'max31785a'
7 Addresses scanned: -
8 Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31785.pdf
9
10Author: Andrew Jeffery <andrew@aj.id.au>
11
12Description
13-----------
14
15The Maxim MAX31785 is a PMBus device providing closed-loop, multi-channel fan
16management with temperature and remote voltage sensing. Various fan control
17features are provided, including PWM frequency control, temperature hysteresis,
18dual tachometer measurements, and fan health monitoring.
19
20For dual rotor fan configuration, the MAX31785 exposes the slowest rotor of the
21two in the fan[1-4]_input attributes.
22
23Usage Notes
24-----------
25
26This driver does not probe for PMBus devices. You will have to instantiate
27devices explicitly.
28
29Sysfs attributes
30----------------
31
32fan[1-4]_alarm Fan alarm.
33fan[1-4]_fault Fan fault.
34fan[1-4]_input Fan RPM.
35
36in[1-6]_crit Critical maximum output voltage
37in[1-6]_crit_alarm Output voltage critical high alarm
38in[1-6]_input Measured output voltage
39in[1-6]_label "vout[18-23]"
40in[1-6]_lcrit Critical minimum output voltage
41in[1-6]_lcrit_alarm Output voltage critical low alarm
42in[1-6]_max Maximum output voltage
43in[1-6]_max_alarm Output voltage high alarm
44in[1-6]_min Minimum output voltage
45in[1-6]_min_alarm Output voltage low alarm
46
47temp[1-11]_crit Critical high temperature
48temp[1-11]_crit_alarm Chip temperature critical high alarm
49temp[1-11]_input Measured temperature
50temp[1-11]_max Maximum temperature
51temp[1-11]_max_alarm Chip temperature high alarm
diff --git a/Documentation/hwmon/sht15 b/Documentation/hwmon/sht15
index 778987d1856f..5e3207c3b177 100644
--- a/Documentation/hwmon/sht15
+++ b/Documentation/hwmon/sht15
@@ -42,8 +42,7 @@ chip. These coefficients are used to internally calibrate the signals from the
42sensors. Disabling the reload of those coefficients allows saving 10ms for each 42sensors. Disabling the reload of those coefficients allows saving 10ms for each
43measurement and decrease power consumption, while losing on precision. 43measurement and decrease power consumption, while losing on precision.
44 44
45Some options may be set directly in the sht15_platform_data structure 45Some options may be set via sysfs attributes.
46or via sysfs attributes.
47 46
48Notes: 47Notes:
49 * The regulator supply name is set to "vcc". 48 * The regulator supply name is set to "vcc".
diff --git a/arch/arm/mach-pxa/stargate2.c b/arch/arm/mach-pxa/stargate2.c
index 2d45d18b1a5e..6b7df6fd2448 100644
--- a/arch/arm/mach-pxa/stargate2.c
+++ b/arch/arm/mach-pxa/stargate2.c
@@ -29,6 +29,7 @@
29#include <linux/platform_data/pcf857x.h> 29#include <linux/platform_data/pcf857x.h>
30#include <linux/platform_data/at24.h> 30#include <linux/platform_data/at24.h>
31#include <linux/smc91x.h> 31#include <linux/smc91x.h>
32#include <linux/gpio/machine.h>
32#include <linux/gpio.h> 33#include <linux/gpio.h>
33#include <linux/leds.h> 34#include <linux/leds.h>
34 35
@@ -52,7 +53,6 @@
52#include <linux/spi/spi.h> 53#include <linux/spi/spi.h>
53#include <linux/spi/pxa2xx_spi.h> 54#include <linux/spi/pxa2xx_spi.h>
54#include <linux/mfd/da903x.h> 55#include <linux/mfd/da903x.h>
55#include <linux/platform_data/sht15.h>
56 56
57#include "devices.h" 57#include "devices.h"
58#include "generic.h" 58#include "generic.h"
@@ -137,17 +137,18 @@ static unsigned long sg2_im2_unified_pin_config[] __initdata = {
137 GPIO10_GPIO, /* large basic connector pin 23 */ 137 GPIO10_GPIO, /* large basic connector pin 23 */
138}; 138};
139 139
140static struct sht15_platform_data platform_data_sht15 = { 140static struct gpiod_lookup_table sht15_gpiod_table = {
141 .gpio_data = 100, 141 .dev_id = "sht15",
142 .gpio_sck = 98, 142 .table = {
143 /* FIXME: should this have |GPIO_OPEN_DRAIN set? */
144 GPIO_LOOKUP("gpio-pxa", 100, "data", GPIO_ACTIVE_HIGH),
145 GPIO_LOOKUP("gpio-pxa", 98, "clk", GPIO_ACTIVE_HIGH),
146 },
143}; 147};
144 148
145static struct platform_device sht15 = { 149static struct platform_device sht15 = {
146 .name = "sht15", 150 .name = "sht15",
147 .id = -1, 151 .id = -1,
148 .dev = {
149 .platform_data = &platform_data_sht15,
150 },
151}; 152};
152 153
153static struct regulator_consumer_supply stargate2_sensor_3_con[] = { 154static struct regulator_consumer_supply stargate2_sensor_3_con[] = {
@@ -608,6 +609,7 @@ static void __init imote2_init(void)
608 609
609 imote2_stargate2_init(); 610 imote2_stargate2_init();
610 611
612 gpiod_add_lookup_table(&sht15_gpiod_table);
611 platform_add_devices(imote2_devices, ARRAY_SIZE(imote2_devices)); 613 platform_add_devices(imote2_devices, ARRAY_SIZE(imote2_devices));
612 614
613 i2c_register_board_info(0, imote2_i2c_board_info, 615 i2c_register_board_info(0, imote2_i2c_board_info,
@@ -988,6 +990,7 @@ static void __init stargate2_init(void)
988 990
989 imote2_stargate2_init(); 991 imote2_stargate2_init();
990 992
993 gpiod_add_lookup_table(&sht15_gpiod_table);
991 platform_add_devices(ARRAY_AND_SIZE(stargate2_devices)); 994 platform_add_devices(ARRAY_AND_SIZE(stargate2_devices));
992 995
993 i2c_register_board_info(0, ARRAY_AND_SIZE(stargate2_i2c_board_info)); 996 i2c_register_board_info(0, ARRAY_AND_SIZE(stargate2_i2c_board_info));
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index d65431417b17..7ad017690e3a 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -552,6 +552,7 @@ config SENSORS_G762
552 552
553config SENSORS_GPIO_FAN 553config SENSORS_GPIO_FAN
554 tristate "GPIO fan" 554 tristate "GPIO fan"
555 depends on OF_GPIO
555 depends on GPIOLIB || COMPILE_TEST 556 depends on GPIOLIB || COMPILE_TEST
556 depends on THERMAL || THERMAL=n 557 depends on THERMAL || THERMAL=n
557 help 558 help
@@ -862,6 +863,20 @@ tristate "MAX31722 temperature sensor"
862 This driver can also be built as a module. If so, the module 863 This driver can also be built as a module. If so, the module
863 will be called max31722. 864 will be called max31722.
864 865
866config SENSORS_MAX6621
867 tristate "Maxim MAX6621 sensor chip"
868 depends on I2C
869 select REGMAP_I2C
870 help
871 If you say yes here you get support for MAX6621 sensor chip.
872 MAX6621 is a PECI-to-I2C translator provides an efficient,
873 low-cost solution for PECI-to-SMBus/I2C protocol conversion.
874 It allows reading the temperature from the PECI-compliant
875 host directly from up to four PECI-enabled CPUs.
876
877 This driver can also be built as a module. If so, the module
878 will be called max6621.
879
865config SENSORS_MAX6639 880config SENSORS_MAX6639
866 tristate "Maxim MAX6639 sensor chip" 881 tristate "Maxim MAX6639 sensor chip"
867 depends on I2C 882 depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 23e195a5a2f3..0fe489fab663 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -118,6 +118,7 @@ obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
118obj-$(CONFIG_SENSORS_MAX1668) += max1668.o 118obj-$(CONFIG_SENSORS_MAX1668) += max1668.o
119obj-$(CONFIG_SENSORS_MAX197) += max197.o 119obj-$(CONFIG_SENSORS_MAX197) += max197.o
120obj-$(CONFIG_SENSORS_MAX31722) += max31722.o 120obj-$(CONFIG_SENSORS_MAX31722) += max31722.o
121obj-$(CONFIG_SENSORS_MAX6621) += max6621.o
121obj-$(CONFIG_SENSORS_MAX6639) += max6639.o 122obj-$(CONFIG_SENSORS_MAX6639) += max6639.o
122obj-$(CONFIG_SENSORS_MAX6642) += max6642.o 123obj-$(CONFIG_SENSORS_MAX6642) += max6642.o
123obj-$(CONFIG_SENSORS_MAX6650) += max6650.o 124obj-$(CONFIG_SENSORS_MAX6650) += max6650.o
diff --git a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c
index 4875e99b59c9..6d34c05a4f83 100644
--- a/drivers/hwmon/asc7621.c
+++ b/drivers/hwmon/asc7621.c
@@ -579,7 +579,6 @@ static ssize_t show_pwm_enable(struct device *dev,
579 mutex_unlock(&data->update_lock); 579 mutex_unlock(&data->update_lock);
580 580
581 val = config | (altbit << 3); 581 val = config | (altbit << 3);
582 newval = 0;
583 582
584 if (val == 3 || val >= 10) 583 if (val == 3 || val >= 10)
585 newval = 255; 584 newval = 255;
diff --git a/drivers/hwmon/aspeed-pwm-tacho.c b/drivers/hwmon/aspeed-pwm-tacho.c
index 69b97d45e3cb..63a95e23ca81 100644
--- a/drivers/hwmon/aspeed-pwm-tacho.c
+++ b/drivers/hwmon/aspeed-pwm-tacho.c
@@ -7,19 +7,19 @@
7 */ 7 */
8 8
9#include <linux/clk.h> 9#include <linux/clk.h>
10#include <linux/delay.h>
10#include <linux/errno.h> 11#include <linux/errno.h>
11#include <linux/gpio/consumer.h> 12#include <linux/gpio/consumer.h>
12#include <linux/delay.h>
13#include <linux/hwmon.h> 13#include <linux/hwmon.h>
14#include <linux/hwmon-sysfs.h> 14#include <linux/hwmon-sysfs.h>
15#include <linux/io.h> 15#include <linux/io.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/of_platform.h>
19#include <linux/of_device.h> 18#include <linux/of_device.h>
19#include <linux/of_platform.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/sysfs.h>
22#include <linux/regmap.h> 21#include <linux/regmap.h>
22#include <linux/sysfs.h>
23#include <linux/thermal.h> 23#include <linux/thermal.h>
24 24
25/* ASPEED PWM & FAN Tach Register Definition */ 25/* ASPEED PWM & FAN Tach Register Definition */
@@ -161,7 +161,7 @@
161 * 11: reserved. 161 * 11: reserved.
162 */ 162 */
163#define M_TACH_MODE 0x02 /* 10b */ 163#define M_TACH_MODE 0x02 /* 10b */
164#define M_TACH_UNIT 0x00c0 164#define M_TACH_UNIT 0x0210
165#define INIT_FAN_CTRL 0xFF 165#define INIT_FAN_CTRL 0xFF
166 166
167/* How long we sleep in us while waiting for an RPM result. */ 167/* How long we sleep in us while waiting for an RPM result. */
diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c
index 9c355b9d31c5..5c9a52599cf6 100644
--- a/drivers/hwmon/gpio-fan.c
+++ b/drivers/hwmon/gpio-fan.c
@@ -29,21 +29,24 @@
29#include <linux/err.h> 29#include <linux/err.h>
30#include <linux/mutex.h> 30#include <linux/mutex.h>
31#include <linux/hwmon.h> 31#include <linux/hwmon.h>
32#include <linux/gpio.h> 32#include <linux/gpio/consumer.h>
33#include <linux/gpio-fan.h>
34#include <linux/of.h> 33#include <linux/of.h>
35#include <linux/of_platform.h> 34#include <linux/of_platform.h>
36#include <linux/of_gpio.h>
37#include <linux/thermal.h> 35#include <linux/thermal.h>
38 36
37struct gpio_fan_speed {
38 int rpm;
39 int ctrl_val;
40};
41
39struct gpio_fan_data { 42struct gpio_fan_data {
40 struct platform_device *pdev; 43 struct device *dev;
41 struct device *hwmon_dev; 44 struct device *hwmon_dev;
42 /* Cooling device if any */ 45 /* Cooling device if any */
43 struct thermal_cooling_device *cdev; 46 struct thermal_cooling_device *cdev;
44 struct mutex lock; /* lock GPIOs operations. */ 47 struct mutex lock; /* lock GPIOs operations. */
45 int num_ctrl; 48 int num_gpios;
46 unsigned *ctrl; 49 struct gpio_desc **gpios;
47 int num_speed; 50 int num_speed;
48 struct gpio_fan_speed *speed; 51 struct gpio_fan_speed *speed;
49 int speed_index; 52 int speed_index;
@@ -51,7 +54,7 @@ struct gpio_fan_data {
51 int resume_speed; 54 int resume_speed;
52#endif 55#endif
53 bool pwm_enable; 56 bool pwm_enable;
54 struct gpio_fan_alarm *alarm; 57 struct gpio_desc *alarm_gpio;
55 struct work_struct alarm_work; 58 struct work_struct alarm_work;
56}; 59};
57 60
@@ -64,8 +67,8 @@ static void fan_alarm_notify(struct work_struct *ws)
64 struct gpio_fan_data *fan_data = 67 struct gpio_fan_data *fan_data =
65 container_of(ws, struct gpio_fan_data, alarm_work); 68 container_of(ws, struct gpio_fan_data, alarm_work);
66 69
67 sysfs_notify(&fan_data->pdev->dev.kobj, NULL, "fan1_alarm"); 70 sysfs_notify(&fan_data->dev->kobj, NULL, "fan1_alarm");
68 kobject_uevent(&fan_data->pdev->dev.kobj, KOBJ_CHANGE); 71 kobject_uevent(&fan_data->dev->kobj, KOBJ_CHANGE);
69} 72}
70 73
71static irqreturn_t fan_alarm_irq_handler(int irq, void *dev_id) 74static irqreturn_t fan_alarm_irq_handler(int irq, void *dev_id)
@@ -81,47 +84,30 @@ static ssize_t fan1_alarm_show(struct device *dev,
81 struct device_attribute *attr, char *buf) 84 struct device_attribute *attr, char *buf)
82{ 85{
83 struct gpio_fan_data *fan_data = dev_get_drvdata(dev); 86 struct gpio_fan_data *fan_data = dev_get_drvdata(dev);
84 struct gpio_fan_alarm *alarm = fan_data->alarm;
85 int value = gpio_get_value_cansleep(alarm->gpio);
86 87
87 if (alarm->active_low) 88 return sprintf(buf, "%d\n",
88 value = !value; 89 gpiod_get_value_cansleep(fan_data->alarm_gpio));
89
90 return sprintf(buf, "%d\n", value);
91} 90}
92 91
93static DEVICE_ATTR_RO(fan1_alarm); 92static DEVICE_ATTR_RO(fan1_alarm);
94 93
95static int fan_alarm_init(struct gpio_fan_data *fan_data, 94static int fan_alarm_init(struct gpio_fan_data *fan_data)
96 struct gpio_fan_alarm *alarm)
97{ 95{
98 int err;
99 int alarm_irq; 96 int alarm_irq;
100 struct platform_device *pdev = fan_data->pdev; 97 struct device *dev = fan_data->dev;
101
102 fan_data->alarm = alarm;
103
104 err = devm_gpio_request(&pdev->dev, alarm->gpio, "GPIO fan alarm");
105 if (err)
106 return err;
107
108 err = gpio_direction_input(alarm->gpio);
109 if (err)
110 return err;
111 98
112 /* 99 /*
113 * If the alarm GPIO don't support interrupts, just leave 100 * If the alarm GPIO don't support interrupts, just leave
114 * without initializing the fail notification support. 101 * without initializing the fail notification support.
115 */ 102 */
116 alarm_irq = gpio_to_irq(alarm->gpio); 103 alarm_irq = gpiod_to_irq(fan_data->alarm_gpio);
117 if (alarm_irq < 0) 104 if (alarm_irq <= 0)
118 return 0; 105 return 0;
119 106
120 INIT_WORK(&fan_data->alarm_work, fan_alarm_notify); 107 INIT_WORK(&fan_data->alarm_work, fan_alarm_notify);
121 irq_set_irq_type(alarm_irq, IRQ_TYPE_EDGE_BOTH); 108 irq_set_irq_type(alarm_irq, IRQ_TYPE_EDGE_BOTH);
122 err = devm_request_irq(&pdev->dev, alarm_irq, fan_alarm_irq_handler, 109 return devm_request_irq(dev, alarm_irq, fan_alarm_irq_handler,
123 IRQF_SHARED, "GPIO fan alarm", fan_data); 110 IRQF_SHARED, "GPIO fan alarm", fan_data);
124 return err;
125} 111}
126 112
127/* 113/*
@@ -133,8 +119,9 @@ static void __set_fan_ctrl(struct gpio_fan_data *fan_data, int ctrl_val)
133{ 119{
134 int i; 120 int i;
135 121
136 for (i = 0; i < fan_data->num_ctrl; i++) 122 for (i = 0; i < fan_data->num_gpios; i++)
137 gpio_set_value_cansleep(fan_data->ctrl[i], (ctrl_val >> i) & 1); 123 gpiod_set_value_cansleep(fan_data->gpios[i],
124 (ctrl_val >> i) & 1);
138} 125}
139 126
140static int __get_fan_ctrl(struct gpio_fan_data *fan_data) 127static int __get_fan_ctrl(struct gpio_fan_data *fan_data)
@@ -142,10 +129,10 @@ static int __get_fan_ctrl(struct gpio_fan_data *fan_data)
142 int i; 129 int i;
143 int ctrl_val = 0; 130 int ctrl_val = 0;
144 131
145 for (i = 0; i < fan_data->num_ctrl; i++) { 132 for (i = 0; i < fan_data->num_gpios; i++) {
146 int value; 133 int value;
147 134
148 value = gpio_get_value_cansleep(fan_data->ctrl[i]); 135 value = gpiod_get_value_cansleep(fan_data->gpios[i]);
149 ctrl_val |= (value << i); 136 ctrl_val |= (value << i);
150 } 137 }
151 return ctrl_val; 138 return ctrl_val;
@@ -170,7 +157,7 @@ static int get_fan_speed_index(struct gpio_fan_data *fan_data)
170 if (fan_data->speed[i].ctrl_val == ctrl_val) 157 if (fan_data->speed[i].ctrl_val == ctrl_val)
171 return i; 158 return i;
172 159
173 dev_warn(&fan_data->pdev->dev, 160 dev_warn(fan_data->dev,
174 "missing speed array entry for GPIO value 0x%x\n", ctrl_val); 161 "missing speed array entry for GPIO value 0x%x\n", ctrl_val);
175 162
176 return -ENODEV; 163 return -ENODEV;
@@ -328,9 +315,9 @@ static umode_t gpio_fan_is_visible(struct kobject *kobj,
328 struct device *dev = container_of(kobj, struct device, kobj); 315 struct device *dev = container_of(kobj, struct device, kobj);
329 struct gpio_fan_data *data = dev_get_drvdata(dev); 316 struct gpio_fan_data *data = dev_get_drvdata(dev);
330 317
331 if (index == 0 && !data->alarm) 318 if (index == 0 && !data->alarm_gpio)
332 return 0; 319 return 0;
333 if (index > 0 && !data->ctrl) 320 if (index > 0 && !data->gpios)
334 return 0; 321 return 0;
335 322
336 return attr->mode; 323 return attr->mode;
@@ -358,30 +345,25 @@ static const struct attribute_group *gpio_fan_groups[] = {
358 NULL 345 NULL
359}; 346};
360 347
361static int fan_ctrl_init(struct gpio_fan_data *fan_data, 348static int fan_ctrl_init(struct gpio_fan_data *fan_data)
362 struct gpio_fan_platform_data *pdata)
363{ 349{
364 struct platform_device *pdev = fan_data->pdev; 350 int num_gpios = fan_data->num_gpios;
365 int num_ctrl = pdata->num_ctrl; 351 struct gpio_desc **gpios = fan_data->gpios;
366 unsigned *ctrl = pdata->ctrl;
367 int i, err; 352 int i, err;
368 353
369 for (i = 0; i < num_ctrl; i++) { 354 for (i = 0; i < num_gpios; i++) {
370 err = devm_gpio_request(&pdev->dev, ctrl[i], 355 /*
371 "GPIO fan control"); 356 * The GPIO descriptors were retrieved with GPIOD_ASIS so here
372 if (err) 357 * we set the GPIO into output mode, carefully preserving the
373 return err; 358 * current value by setting it to whatever it is already set
374 359 * (no surprise changes in default fan speed).
375 err = gpio_direction_output(ctrl[i], 360 */
376 gpio_get_value_cansleep(ctrl[i])); 361 err = gpiod_direction_output(gpios[i],
362 gpiod_get_value_cansleep(gpios[i]));
377 if (err) 363 if (err)
378 return err; 364 return err;
379 } 365 }
380 366
381 fan_data->num_ctrl = num_ctrl;
382 fan_data->ctrl = ctrl;
383 fan_data->num_speed = pdata->num_speed;
384 fan_data->speed = pdata->speed;
385 fan_data->pwm_enable = true; /* Enable manual fan speed control. */ 367 fan_data->pwm_enable = true; /* Enable manual fan speed control. */
386 fan_data->speed_index = get_fan_speed_index(fan_data); 368 fan_data->speed_index = get_fan_speed_index(fan_data);
387 if (fan_data->speed_index < 0) 369 if (fan_data->speed_index < 0)
@@ -432,67 +414,47 @@ static const struct thermal_cooling_device_ops gpio_fan_cool_ops = {
432 .set_cur_state = gpio_fan_set_cur_state, 414 .set_cur_state = gpio_fan_set_cur_state,
433}; 415};
434 416
435#ifdef CONFIG_OF_GPIO
436/* 417/*
437 * Translate OpenFirmware node properties into platform_data 418 * Translate OpenFirmware node properties into platform_data
438 */ 419 */
439static int gpio_fan_get_of_pdata(struct device *dev, 420static int gpio_fan_get_of_data(struct gpio_fan_data *fan_data)
440 struct gpio_fan_platform_data *pdata)
441{ 421{
442 struct device_node *node;
443 struct gpio_fan_speed *speed; 422 struct gpio_fan_speed *speed;
444 unsigned *ctrl; 423 struct device *dev = fan_data->dev;
424 struct device_node *np = dev->of_node;
425 struct gpio_desc **gpios;
445 unsigned i; 426 unsigned i;
446 u32 u; 427 u32 u;
447 struct property *prop; 428 struct property *prop;
448 const __be32 *p; 429 const __be32 *p;
449 430
450 node = dev->of_node;
451
452 /* Alarm GPIO if one exists */ 431 /* Alarm GPIO if one exists */
453 if (of_gpio_named_count(node, "alarm-gpios") > 0) { 432 fan_data->alarm_gpio = devm_gpiod_get_optional(dev, "alarm", GPIOD_IN);
454 struct gpio_fan_alarm *alarm; 433 if (IS_ERR(fan_data->alarm_gpio))
455 int val; 434 return PTR_ERR(fan_data->alarm_gpio);
456 enum of_gpio_flags flags;
457
458 alarm = devm_kzalloc(dev, sizeof(struct gpio_fan_alarm),
459 GFP_KERNEL);
460 if (!alarm)
461 return -ENOMEM;
462
463 val = of_get_named_gpio_flags(node, "alarm-gpios", 0, &flags);
464 if (val < 0)
465 return val;
466 alarm->gpio = val;
467 alarm->active_low = flags & OF_GPIO_ACTIVE_LOW;
468
469 pdata->alarm = alarm;
470 }
471 435
472 /* Fill GPIO pin array */ 436 /* Fill GPIO pin array */
473 pdata->num_ctrl = of_gpio_count(node); 437 fan_data->num_gpios = gpiod_count(dev, NULL);
474 if (pdata->num_ctrl <= 0) { 438 if (fan_data->num_gpios <= 0) {
475 if (pdata->alarm) 439 if (fan_data->alarm_gpio)
476 return 0; 440 return 0;
477 dev_err(dev, "DT properties empty / missing"); 441 dev_err(dev, "DT properties empty / missing");
478 return -ENODEV; 442 return -ENODEV;
479 } 443 }
480 ctrl = devm_kzalloc(dev, pdata->num_ctrl * sizeof(unsigned), 444 gpios = devm_kzalloc(dev,
481 GFP_KERNEL); 445 fan_data->num_gpios * sizeof(struct gpio_desc *),
482 if (!ctrl) 446 GFP_KERNEL);
447 if (!gpios)
483 return -ENOMEM; 448 return -ENOMEM;
484 for (i = 0; i < pdata->num_ctrl; i++) { 449 for (i = 0; i < fan_data->num_gpios; i++) {
485 int val; 450 gpios[i] = devm_gpiod_get_index(dev, NULL, i, GPIOD_ASIS);
486 451 if (IS_ERR(gpios[i]))
487 val = of_get_gpio(node, i); 452 return PTR_ERR(gpios[i]);
488 if (val < 0)
489 return val;
490 ctrl[i] = val;
491 } 453 }
492 pdata->ctrl = ctrl; 454 fan_data->gpios = gpios;
493 455
494 /* Get number of RPM/ctrl_val pairs in speed map */ 456 /* Get number of RPM/ctrl_val pairs in speed map */
495 prop = of_find_property(node, "gpio-fan,speed-map", &i); 457 prop = of_find_property(np, "gpio-fan,speed-map", &i);
496 if (!prop) { 458 if (!prop) {
497 dev_err(dev, "gpio-fan,speed-map DT property missing"); 459 dev_err(dev, "gpio-fan,speed-map DT property missing");
498 return -ENODEV; 460 return -ENODEV;
@@ -502,7 +464,7 @@ static int gpio_fan_get_of_pdata(struct device *dev,
502 dev_err(dev, "gpio-fan,speed-map contains zero/odd number of entries"); 464 dev_err(dev, "gpio-fan,speed-map contains zero/odd number of entries");
503 return -ENODEV; 465 return -ENODEV;
504 } 466 }
505 pdata->num_speed = i / 2; 467 fan_data->num_speed = i / 2;
506 468
507 /* 469 /*
508 * Populate speed map 470 * Populate speed map
@@ -510,12 +472,12 @@ static int gpio_fan_get_of_pdata(struct device *dev,
510 * this needs splitting into pairs to create gpio_fan_speed structs 472 * this needs splitting into pairs to create gpio_fan_speed structs
511 */ 473 */
512 speed = devm_kzalloc(dev, 474 speed = devm_kzalloc(dev,
513 pdata->num_speed * sizeof(struct gpio_fan_speed), 475 fan_data->num_speed * sizeof(struct gpio_fan_speed),
514 GFP_KERNEL); 476 GFP_KERNEL);
515 if (!speed) 477 if (!speed)
516 return -ENOMEM; 478 return -ENOMEM;
517 p = NULL; 479 p = NULL;
518 for (i = 0; i < pdata->num_speed; i++) { 480 for (i = 0; i < fan_data->num_speed; i++) {
519 p = of_prop_next_u32(prop, p, &u); 481 p = of_prop_next_u32(prop, p, &u);
520 if (!p) 482 if (!p)
521 return -ENODEV; 483 return -ENODEV;
@@ -525,7 +487,7 @@ static int gpio_fan_get_of_pdata(struct device *dev,
525 return -ENODEV; 487 return -ENODEV;
526 speed[i].ctrl_val = u; 488 speed[i].ctrl_val = u;
527 } 489 }
528 pdata->speed = speed; 490 fan_data->speed = speed;
529 491
530 return 0; 492 return 0;
531} 493}
@@ -535,76 +497,58 @@ static const struct of_device_id of_gpio_fan_match[] = {
535 {}, 497 {},
536}; 498};
537MODULE_DEVICE_TABLE(of, of_gpio_fan_match); 499MODULE_DEVICE_TABLE(of, of_gpio_fan_match);
538#endif /* CONFIG_OF_GPIO */
539 500
540static int gpio_fan_probe(struct platform_device *pdev) 501static int gpio_fan_probe(struct platform_device *pdev)
541{ 502{
542 int err; 503 int err;
543 struct gpio_fan_data *fan_data; 504 struct gpio_fan_data *fan_data;
544 struct gpio_fan_platform_data *pdata = dev_get_platdata(&pdev->dev); 505 struct device *dev = &pdev->dev;
506 struct device_node *np = dev->of_node;
545 507
546 fan_data = devm_kzalloc(&pdev->dev, sizeof(struct gpio_fan_data), 508 fan_data = devm_kzalloc(dev, sizeof(struct gpio_fan_data),
547 GFP_KERNEL); 509 GFP_KERNEL);
548 if (!fan_data) 510 if (!fan_data)
549 return -ENOMEM; 511 return -ENOMEM;
550 512
551#ifdef CONFIG_OF_GPIO 513 fan_data->dev = dev;
552 if (!pdata) { 514 err = gpio_fan_get_of_data(fan_data);
553 pdata = devm_kzalloc(&pdev->dev, 515 if (err)
554 sizeof(struct gpio_fan_platform_data), 516 return err;
555 GFP_KERNEL);
556 if (!pdata)
557 return -ENOMEM;
558
559 err = gpio_fan_get_of_pdata(&pdev->dev, pdata);
560 if (err)
561 return err;
562 }
563#else /* CONFIG_OF_GPIO */
564 if (!pdata)
565 return -EINVAL;
566#endif /* CONFIG_OF_GPIO */
567 517
568 fan_data->pdev = pdev;
569 platform_set_drvdata(pdev, fan_data); 518 platform_set_drvdata(pdev, fan_data);
570 mutex_init(&fan_data->lock); 519 mutex_init(&fan_data->lock);
571 520
572 /* Configure alarm GPIO if available. */ 521 /* Configure alarm GPIO if available. */
573 if (pdata->alarm) { 522 if (fan_data->alarm_gpio) {
574 err = fan_alarm_init(fan_data, pdata->alarm); 523 err = fan_alarm_init(fan_data);
575 if (err) 524 if (err)
576 return err; 525 return err;
577 } 526 }
578 527
579 /* Configure control GPIOs if available. */ 528 /* Configure control GPIOs if available. */
580 if (pdata->ctrl && pdata->num_ctrl > 0) { 529 if (fan_data->gpios && fan_data->num_gpios > 0) {
581 if (!pdata->speed || pdata->num_speed <= 1) 530 if (!fan_data->speed || fan_data->num_speed <= 1)
582 return -EINVAL; 531 return -EINVAL;
583 err = fan_ctrl_init(fan_data, pdata); 532 err = fan_ctrl_init(fan_data);
584 if (err) 533 if (err)
585 return err; 534 return err;
586 } 535 }
587 536
588 /* Make this driver part of hwmon class. */ 537 /* Make this driver part of hwmon class. */
589 fan_data->hwmon_dev = 538 fan_data->hwmon_dev =
590 devm_hwmon_device_register_with_groups(&pdev->dev, 539 devm_hwmon_device_register_with_groups(dev,
591 "gpio_fan", fan_data, 540 "gpio_fan", fan_data,
592 gpio_fan_groups); 541 gpio_fan_groups);
593 if (IS_ERR(fan_data->hwmon_dev)) 542 if (IS_ERR(fan_data->hwmon_dev))
594 return PTR_ERR(fan_data->hwmon_dev); 543 return PTR_ERR(fan_data->hwmon_dev);
595#ifdef CONFIG_OF_GPIO 544
596 /* Optional cooling device register for Device tree platforms */ 545 /* Optional cooling device register for Device tree platforms */
597 fan_data->cdev = thermal_of_cooling_device_register(pdev->dev.of_node, 546 fan_data->cdev = thermal_of_cooling_device_register(np,
598 "gpio-fan", 547 "gpio-fan",
599 fan_data, 548 fan_data,
600 &gpio_fan_cool_ops); 549 &gpio_fan_cool_ops);
601#else /* CONFIG_OF_GPIO */
602 /* Optional cooling device register for non Device tree platforms */
603 fan_data->cdev = thermal_cooling_device_register("gpio-fan", fan_data,
604 &gpio_fan_cool_ops);
605#endif /* CONFIG_OF_GPIO */
606 550
607 dev_info(&pdev->dev, "GPIO fan initialized\n"); 551 dev_info(dev, "GPIO fan initialized\n");
608 552
609 return 0; 553 return 0;
610} 554}
@@ -616,7 +560,7 @@ static int gpio_fan_remove(struct platform_device *pdev)
616 if (!IS_ERR(fan_data->cdev)) 560 if (!IS_ERR(fan_data->cdev))
617 thermal_cooling_device_unregister(fan_data->cdev); 561 thermal_cooling_device_unregister(fan_data->cdev);
618 562
619 if (fan_data->ctrl) 563 if (fan_data->gpios)
620 set_fan_speed(fan_data, 0); 564 set_fan_speed(fan_data, 0);
621 565
622 return 0; 566 return 0;
@@ -632,7 +576,7 @@ static int gpio_fan_suspend(struct device *dev)
632{ 576{
633 struct gpio_fan_data *fan_data = dev_get_drvdata(dev); 577 struct gpio_fan_data *fan_data = dev_get_drvdata(dev);
634 578
635 if (fan_data->ctrl) { 579 if (fan_data->gpios) {
636 fan_data->resume_speed = fan_data->speed_index; 580 fan_data->resume_speed = fan_data->speed_index;
637 set_fan_speed(fan_data, 0); 581 set_fan_speed(fan_data, 0);
638 } 582 }
@@ -644,7 +588,7 @@ static int gpio_fan_resume(struct device *dev)
644{ 588{
645 struct gpio_fan_data *fan_data = dev_get_drvdata(dev); 589 struct gpio_fan_data *fan_data = dev_get_drvdata(dev);
646 590
647 if (fan_data->ctrl) 591 if (fan_data->gpios)
648 set_fan_speed(fan_data, fan_data->resume_speed); 592 set_fan_speed(fan_data, fan_data->resume_speed);
649 593
650 return 0; 594 return 0;
@@ -663,9 +607,7 @@ static struct platform_driver gpio_fan_driver = {
663 .driver = { 607 .driver = {
664 .name = "gpio-fan", 608 .name = "gpio-fan",
665 .pm = GPIO_FAN_PM, 609 .pm = GPIO_FAN_PM,
666#ifdef CONFIG_OF_GPIO
667 .of_match_table = of_match_ptr(of_gpio_fan_match), 610 .of_match_table = of_match_ptr(of_gpio_fan_match),
668#endif
669 }, 611 },
670}; 612};
671 613
diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c
index ce3b91f22e30..46a54ed23410 100644
--- a/drivers/hwmon/k10temp.c
+++ b/drivers/hwmon/k10temp.c
@@ -36,6 +36,10 @@ MODULE_PARM_DESC(force, "force loading on processors with erratum 319");
36/* Provide lock for writing to NB_SMU_IND_ADDR */ 36/* Provide lock for writing to NB_SMU_IND_ADDR */
37static DEFINE_MUTEX(nb_smu_ind_mutex); 37static DEFINE_MUTEX(nb_smu_ind_mutex);
38 38
39#ifndef PCI_DEVICE_ID_AMD_17H_DF_F3
40#define PCI_DEVICE_ID_AMD_17H_DF_F3 0x1463
41#endif
42
39/* CPUID function 0x80000001, ebx */ 43/* CPUID function 0x80000001, ebx */
40#define CPUID_PKGTYPE_MASK 0xf0000000 44#define CPUID_PKGTYPE_MASK 0xf0000000
41#define CPUID_PKGTYPE_F 0x00000000 45#define CPUID_PKGTYPE_F 0x00000000
@@ -61,31 +65,72 @@ static DEFINE_MUTEX(nb_smu_ind_mutex);
61 */ 65 */
62#define F15H_M60H_REPORTED_TEMP_CTRL_OFFSET 0xd8200ca4 66#define F15H_M60H_REPORTED_TEMP_CTRL_OFFSET 0xd8200ca4
63 67
64static void amd_nb_smu_index_read(struct pci_dev *pdev, unsigned int devfn, 68/* F17h M01h Access througn SMN */
65 int offset, u32 *val) 69#define F17H_M01H_REPORTED_TEMP_CTRL_OFFSET 0x00059800
70
71struct k10temp_data {
72 struct pci_dev *pdev;
73 void (*read_tempreg)(struct pci_dev *pdev, u32 *regval);
74 int temp_offset;
75};
76
77struct tctl_offset {
78 u8 model;
79 char const *id;
80 int offset;
81};
82
83static const struct tctl_offset tctl_offset_table[] = {
84 { 0x17, "AMD Ryzen 7 1600X", 20000 },
85 { 0x17, "AMD Ryzen 7 1700X", 20000 },
86 { 0x17, "AMD Ryzen 7 1800X", 20000 },
87 { 0x17, "AMD Ryzen Threadripper 1950X", 27000 },
88 { 0x17, "AMD Ryzen Threadripper 1920X", 27000 },
89 { 0x17, "AMD Ryzen Threadripper 1950", 10000 },
90 { 0x17, "AMD Ryzen Threadripper 1920", 10000 },
91 { 0x17, "AMD Ryzen Threadripper 1910", 10000 },
92};
93
94static void read_tempreg_pci(struct pci_dev *pdev, u32 *regval)
95{
96 pci_read_config_dword(pdev, REG_REPORTED_TEMPERATURE, regval);
97}
98
99static void amd_nb_index_read(struct pci_dev *pdev, unsigned int devfn,
100 unsigned int base, int offset, u32 *val)
66{ 101{
67 mutex_lock(&nb_smu_ind_mutex); 102 mutex_lock(&nb_smu_ind_mutex);
68 pci_bus_write_config_dword(pdev->bus, devfn, 103 pci_bus_write_config_dword(pdev->bus, devfn,
69 0xb8, offset); 104 base, offset);
70 pci_bus_read_config_dword(pdev->bus, devfn, 105 pci_bus_read_config_dword(pdev->bus, devfn,
71 0xbc, val); 106 base + 4, val);
72 mutex_unlock(&nb_smu_ind_mutex); 107 mutex_unlock(&nb_smu_ind_mutex);
73} 108}
74 109
110static void read_tempreg_nb_f15(struct pci_dev *pdev, u32 *regval)
111{
112 amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0xb8,
113 F15H_M60H_REPORTED_TEMP_CTRL_OFFSET, regval);
114}
115
116static void read_tempreg_nb_f17(struct pci_dev *pdev, u32 *regval)
117{
118 amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0x60,
119 F17H_M01H_REPORTED_TEMP_CTRL_OFFSET, regval);
120}
121
75static ssize_t temp1_input_show(struct device *dev, 122static ssize_t temp1_input_show(struct device *dev,
76 struct device_attribute *attr, char *buf) 123 struct device_attribute *attr, char *buf)
77{ 124{
125 struct k10temp_data *data = dev_get_drvdata(dev);
78 u32 regval; 126 u32 regval;
79 struct pci_dev *pdev = dev_get_drvdata(dev); 127 unsigned int temp;
80 128
81 if (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model == 0x60) { 129 data->read_tempreg(data->pdev, &regval);
82 amd_nb_smu_index_read(pdev, PCI_DEVFN(0, 0), 130 temp = (regval >> 21) * 125;
83 F15H_M60H_REPORTED_TEMP_CTRL_OFFSET, 131 temp -= data->temp_offset;
84 &regval); 132
85 } else { 133 return sprintf(buf, "%u\n", temp);
86 pci_read_config_dword(pdev, REG_REPORTED_TEMPERATURE, &regval);
87 }
88 return sprintf(buf, "%u\n", (regval >> 21) * 125);
89} 134}
90 135
91static ssize_t temp1_max_show(struct device *dev, 136static ssize_t temp1_max_show(struct device *dev,
@@ -98,11 +143,12 @@ static ssize_t show_temp_crit(struct device *dev,
98 struct device_attribute *devattr, char *buf) 143 struct device_attribute *devattr, char *buf)
99{ 144{
100 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 145 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
146 struct k10temp_data *data = dev_get_drvdata(dev);
101 int show_hyst = attr->index; 147 int show_hyst = attr->index;
102 u32 regval; 148 u32 regval;
103 int value; 149 int value;
104 150
105 pci_read_config_dword(dev_get_drvdata(dev), 151 pci_read_config_dword(data->pdev,
106 REG_HARDWARE_THERMAL_CONTROL, &regval); 152 REG_HARDWARE_THERMAL_CONTROL, &regval);
107 value = ((regval >> 16) & 0x7f) * 500 + 52000; 153 value = ((regval >> 16) & 0x7f) * 500 + 52000;
108 if (show_hyst) 154 if (show_hyst)
@@ -119,7 +165,8 @@ static umode_t k10temp_is_visible(struct kobject *kobj,
119 struct attribute *attr, int index) 165 struct attribute *attr, int index)
120{ 166{
121 struct device *dev = container_of(kobj, struct device, kobj); 167 struct device *dev = container_of(kobj, struct device, kobj);
122 struct pci_dev *pdev = dev_get_drvdata(dev); 168 struct k10temp_data *data = dev_get_drvdata(dev);
169 struct pci_dev *pdev = data->pdev;
123 170
124 if (index >= 2) { 171 if (index >= 2) {
125 u32 reg_caps, reg_htc; 172 u32 reg_caps, reg_htc;
@@ -187,7 +234,9 @@ static int k10temp_probe(struct pci_dev *pdev,
187{ 234{
188 int unreliable = has_erratum_319(pdev); 235 int unreliable = has_erratum_319(pdev);
189 struct device *dev = &pdev->dev; 236 struct device *dev = &pdev->dev;
237 struct k10temp_data *data;
190 struct device *hwmon_dev; 238 struct device *hwmon_dev;
239 int i;
191 240
192 if (unreliable) { 241 if (unreliable) {
193 if (!force) { 242 if (!force) {
@@ -199,7 +248,31 @@ static int k10temp_probe(struct pci_dev *pdev,
199 "unreliable CPU thermal sensor; check erratum 319\n"); 248 "unreliable CPU thermal sensor; check erratum 319\n");
200 } 249 }
201 250
202 hwmon_dev = devm_hwmon_device_register_with_groups(dev, "k10temp", pdev, 251 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
252 if (!data)
253 return -ENOMEM;
254
255 data->pdev = pdev;
256
257 if (boot_cpu_data.x86 == 0x15 && (boot_cpu_data.x86_model == 0x60 ||
258 boot_cpu_data.x86_model == 0x70))
259 data->read_tempreg = read_tempreg_nb_f15;
260 else if (boot_cpu_data.x86 == 0x17)
261 data->read_tempreg = read_tempreg_nb_f17;
262 else
263 data->read_tempreg = read_tempreg_pci;
264
265 for (i = 0; i < ARRAY_SIZE(tctl_offset_table); i++) {
266 const struct tctl_offset *entry = &tctl_offset_table[i];
267
268 if (boot_cpu_data.x86 == entry->model &&
269 strstr(boot_cpu_data.x86_model_id, entry->id)) {
270 data->temp_offset = entry->offset;
271 break;
272 }
273 }
274
275 hwmon_dev = devm_hwmon_device_register_with_groups(dev, "k10temp", data,
203 k10temp_groups); 276 k10temp_groups);
204 return PTR_ERR_OR_ZERO(hwmon_dev); 277 return PTR_ERR_OR_ZERO(hwmon_dev);
205} 278}
@@ -214,6 +287,7 @@ static const struct pci_device_id k10temp_id_table[] = {
214 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M60H_NB_F3) }, 287 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M60H_NB_F3) },
215 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) }, 288 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) },
216 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) }, 289 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) },
290 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_DF_F3) },
217 {} 291 {}
218}; 292};
219MODULE_DEVICE_TABLE(pci, k10temp_id_table); 293MODULE_DEVICE_TABLE(pci, k10temp_id_table);
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index a18278938494..76d966932941 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -303,10 +303,20 @@ static const struct i2c_device_id max1619_id[] = {
303}; 303};
304MODULE_DEVICE_TABLE(i2c, max1619_id); 304MODULE_DEVICE_TABLE(i2c, max1619_id);
305 305
306#ifdef CONFIG_OF
307static const struct of_device_id max1619_of_match[] = {
308 { .compatible = "maxim,max1619", },
309 {},
310};
311
312MODULE_DEVICE_TABLE(of, max1619_of_match);
313#endif
314
306static struct i2c_driver max1619_driver = { 315static struct i2c_driver max1619_driver = {
307 .class = I2C_CLASS_HWMON, 316 .class = I2C_CLASS_HWMON,
308 .driver = { 317 .driver = {
309 .name = "max1619", 318 .name = "max1619",
319 .of_match_table = of_match_ptr(max1619_of_match),
310 }, 320 },
311 .probe = max1619_probe, 321 .probe = max1619_probe,
312 .id_table = max1619_id, 322 .id_table = max1619_id,
diff --git a/drivers/hwmon/max6621.c b/drivers/hwmon/max6621.c
new file mode 100644
index 000000000000..35555f0eefb9
--- /dev/null
+++ b/drivers/hwmon/max6621.c
@@ -0,0 +1,593 @@
1/*
2 * Hardware monitoring driver for Maxim MAX6621
3 *
4 * Copyright (c) 2017 Mellanox Technologies. All rights reserved.
5 * Copyright (c) 2017 Vadim Pasternak <vadimp@mellanox.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <linux/bitops.h>
19#include <linux/hwmon.h>
20#include <linux/hwmon-sysfs.h>
21#include <linux/i2c.h>
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/of_device.h>
25#include <linux/regmap.h>
26
27#define MAX6621_DRV_NAME "max6621"
28#define MAX6621_TEMP_INPUT_REG_NUM 9
29#define MAX6621_TEMP_INPUT_MIN -127000
30#define MAX6621_TEMP_INPUT_MAX 128000
31#define MAX6621_TEMP_ALERT_CHAN_SHIFT 1
32
33#define MAX6621_TEMP_S0D0_REG 0x00
34#define MAX6621_TEMP_S0D1_REG 0x01
35#define MAX6621_TEMP_S1D0_REG 0x02
36#define MAX6621_TEMP_S1D1_REG 0x03
37#define MAX6621_TEMP_S2D0_REG 0x04
38#define MAX6621_TEMP_S2D1_REG 0x05
39#define MAX6621_TEMP_S3D0_REG 0x06
40#define MAX6621_TEMP_S3D1_REG 0x07
41#define MAX6621_TEMP_MAX_REG 0x08
42#define MAX6621_TEMP_MAX_ADDR_REG 0x0a
43#define MAX6621_TEMP_ALERT_CAUSE_REG 0x0b
44#define MAX6621_CONFIG0_REG 0x0c
45#define MAX6621_CONFIG1_REG 0x0d
46#define MAX6621_CONFIG2_REG 0x0e
47#define MAX6621_CONFIG3_REG 0x0f
48#define MAX6621_TEMP_S0_ALERT_REG 0x10
49#define MAX6621_TEMP_S1_ALERT_REG 0x11
50#define MAX6621_TEMP_S2_ALERT_REG 0x12
51#define MAX6621_TEMP_S3_ALERT_REG 0x13
52#define MAX6621_CLEAR_ALERT_REG 0x15
53#define MAX6621_REG_MAX (MAX6621_CLEAR_ALERT_REG + 1)
54#define MAX6621_REG_TEMP_SHIFT 0x06
55
56#define MAX6621_ENABLE_TEMP_ALERTS_BIT 4
57#define MAX6621_ENABLE_I2C_CRC_BIT 5
58#define MAX6621_ENABLE_ALTERNATE_DATA 6
59#define MAX6621_ENABLE_LOCKUP_TO 7
60#define MAX6621_ENABLE_S0D0_BIT 8
61#define MAX6621_ENABLE_S3D1_BIT 15
62#define MAX6621_ENABLE_TEMP_ALL GENMASK(MAX6621_ENABLE_S3D1_BIT, \
63 MAX6621_ENABLE_S0D0_BIT)
64#define MAX6621_POLL_DELAY_MASK 0x5
65#define MAX6621_CONFIG0_INIT (MAX6621_ENABLE_TEMP_ALL | \
66 BIT(MAX6621_ENABLE_LOCKUP_TO) | \
67 BIT(MAX6621_ENABLE_I2C_CRC_BIT) | \
68 MAX6621_POLL_DELAY_MASK)
69#define MAX6621_PECI_BIT_TIME 0x2
70#define MAX6621_PECI_RETRY_NUM 0x3
71#define MAX6621_CONFIG1_INIT ((MAX6621_PECI_BIT_TIME << 8) | \
72 MAX6621_PECI_RETRY_NUM)
73
74/* Error codes */
75#define MAX6621_TRAN_FAILED 0x8100 /*
76 * PECI transaction failed for more
77 * than the configured number of
78 * consecutive retries.
79 */
80#define MAX6621_POOL_DIS 0x8101 /*
81 * Polling disabled for requested
82 * socket/domain.
83 */
84#define MAX6621_POOL_UNCOMPLETE 0x8102 /*
85 * First poll not yet completed for
86 * requested socket/domain (on
87 * startup).
88 */
89#define MAX6621_SD_DIS 0x8103 /*
90 * Read maximum temperature requested,
91 * but no sockets/domains enabled or
92 * all enabled sockets/domains have
93 * errors; or read maximum temperature
94 * address requested, but read maximum
95 * temperature was not called.
96 */
97#define MAX6621_ALERT_DIS 0x8104 /*
98 * Get alert socket/domain requested,
99 * but no alert active.
100 */
101#define MAX6621_PECI_ERR_MIN 0x8000 /* Intel spec PECI error min value. */
102#define MAX6621_PECI_ERR_MAX 0x80ff /* Intel spec PECI error max value. */
103
104static const u32 max6621_temp_regs[] = {
105 MAX6621_TEMP_MAX_REG, MAX6621_TEMP_S0D0_REG, MAX6621_TEMP_S1D0_REG,
106 MAX6621_TEMP_S2D0_REG, MAX6621_TEMP_S3D0_REG, MAX6621_TEMP_S0D1_REG,
107 MAX6621_TEMP_S1D1_REG, MAX6621_TEMP_S2D1_REG, MAX6621_TEMP_S3D1_REG,
108};
109
110static const char *const max6621_temp_labels[] = {
111 "maximum",
112 "socket0_0",
113 "socket1_0",
114 "socket2_0",
115 "socket3_0",
116 "socket0_1",
117 "socket1_1",
118 "socket2_1",
119 "socket3_1",
120};
121
122static const int max6621_temp_alert_chan2reg[] = {
123 MAX6621_TEMP_S0_ALERT_REG,
124 MAX6621_TEMP_S1_ALERT_REG,
125 MAX6621_TEMP_S2_ALERT_REG,
126 MAX6621_TEMP_S3_ALERT_REG,
127};
128
129/**
130 * struct max6621_data - private data:
131 *
132 * @client: I2C client;
133 * @regmap: register map handle;
134 * @input_chan2reg: mapping from channel to register;
135 */
136struct max6621_data {
137 struct i2c_client *client;
138 struct regmap *regmap;
139 int input_chan2reg[MAX6621_TEMP_INPUT_REG_NUM + 1];
140};
141
142static long max6621_temp_mc2reg(long val)
143{
144 return (val / 1000L) << MAX6621_REG_TEMP_SHIFT;
145}
146
147static umode_t
148max6621_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr,
149 int channel)
150{
151 /* Skip channels which are not physically conncted. */
152 if (((struct max6621_data *)data)->input_chan2reg[channel] < 0)
153 return 0;
154
155 switch (type) {
156 case hwmon_temp:
157 switch (attr) {
158 case hwmon_temp_input:
159 case hwmon_temp_label:
160 case hwmon_temp_crit_alarm:
161 return 0444;
162 case hwmon_temp_offset:
163 case hwmon_temp_crit:
164 return 0644;
165 default:
166 break;
167 }
168
169 default:
170 break;
171 }
172
173 return 0;
174}
175
176static int max6621_verify_reg_data(struct device *dev, int regval)
177{
178 if (regval >= MAX6621_PECI_ERR_MIN &&
179 regval <= MAX6621_PECI_ERR_MAX) {
180 dev_dbg(dev, "PECI error code - err 0x%04x.\n",
181 regval);
182
183 return -EIO;
184 }
185
186 switch (regval) {
187 case MAX6621_TRAN_FAILED:
188 dev_dbg(dev, "PECI transaction failed - err 0x%04x.\n",
189 regval);
190 return -EIO;
191 case MAX6621_POOL_DIS:
192 dev_dbg(dev, "Polling disabled - err 0x%04x.\n", regval);
193 return -EOPNOTSUPP;
194 case MAX6621_POOL_UNCOMPLETE:
195 dev_dbg(dev, "First poll not completed on startup - err 0x%04x.\n",
196 regval);
197 return -EIO;
198 case MAX6621_SD_DIS:
199 dev_dbg(dev, "Resource is disabled - err 0x%04x.\n", regval);
200 return -EOPNOTSUPP;
201 case MAX6621_ALERT_DIS:
202 dev_dbg(dev, "No alert active - err 0x%04x.\n", regval);
203 return -EOPNOTSUPP;
204 default:
205 return 0;
206 }
207}
208
209static int
210max6621_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
211 int channel, long *val)
212{
213 struct max6621_data *data = dev_get_drvdata(dev);
214 u32 regval;
215 int reg;
216 s8 temp;
217 int ret;
218
219 switch (type) {
220 case hwmon_temp:
221 switch (attr) {
222 case hwmon_temp_input:
223 reg = data->input_chan2reg[channel];
224 ret = regmap_read(data->regmap, reg, &regval);
225 if (ret)
226 return ret;
227
228 ret = max6621_verify_reg_data(dev, regval);
229 if (ret)
230 return ret;
231
232 /*
233 * Bit MAX6621_REG_TEMP_SHIFT represents 1 degree step.
234 * The temperature is given in two's complement and 8
235 * bits is used for the register conversion.
236 */
237 temp = (regval >> MAX6621_REG_TEMP_SHIFT);
238 *val = temp * 1000L;
239
240 break;
241 case hwmon_temp_offset:
242 ret = regmap_read(data->regmap, MAX6621_CONFIG2_REG,
243 &regval);
244 if (ret)
245 return ret;
246
247 ret = max6621_verify_reg_data(dev, regval);
248 if (ret)
249 return ret;
250
251 *val = (regval >> MAX6621_REG_TEMP_SHIFT) *
252 1000L;
253
254 break;
255 case hwmon_temp_crit:
256 channel -= MAX6621_TEMP_ALERT_CHAN_SHIFT;
257 reg = max6621_temp_alert_chan2reg[channel];
258 ret = regmap_read(data->regmap, reg, &regval);
259 if (ret)
260 return ret;
261
262 ret = max6621_verify_reg_data(dev, regval);
263 if (ret)
264 return ret;
265
266 *val = regval * 1000L;
267
268 break;
269 case hwmon_temp_crit_alarm:
270 /*
271 * Set val to zero to recover the case, when reading
272 * MAX6621_TEMP_ALERT_CAUSE_REG results in for example
273 * MAX6621_ALERT_DIS. Reading will return with error,
274 * but in such case alarm should be returned as 0.
275 */
276 *val = 0;
277 ret = regmap_read(data->regmap,
278 MAX6621_TEMP_ALERT_CAUSE_REG,
279 &regval);
280 if (ret)
281 return ret;
282
283 ret = max6621_verify_reg_data(dev, regval);
284 if (ret) {
285 /* Do not report error if alert is disabled. */
286 if (regval == MAX6621_ALERT_DIS)
287 return 0;
288 else
289 return ret;
290 }
291
292 /*
293 * Clear the alert automatically, using send-byte
294 * smbus protocol for clearing alert.
295 */
296 if (regval) {
297 ret = i2c_smbus_write_byte(data->client,
298 MAX6621_CLEAR_ALERT_REG);
299 if (ret)
300 return ret;
301 }
302
303 *val = !!regval;
304
305 break;
306 default:
307 return -EOPNOTSUPP;
308 }
309 break;
310
311 default:
312 return -EOPNOTSUPP;
313 }
314
315 return 0;
316}
317
318static int
319max6621_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
320 int channel, long val)
321{
322 struct max6621_data *data = dev_get_drvdata(dev);
323 u32 reg;
324
325 switch (type) {
326 case hwmon_temp:
327 switch (attr) {
328 case hwmon_temp_offset:
329 /* Clamp to allowed range to prevent overflow. */
330 val = clamp_val(val, MAX6621_TEMP_INPUT_MIN,
331 MAX6621_TEMP_INPUT_MAX);
332 val = max6621_temp_mc2reg(val);
333
334 return regmap_write(data->regmap,
335 MAX6621_CONFIG2_REG, val);
336 case hwmon_temp_crit:
337 channel -= MAX6621_TEMP_ALERT_CHAN_SHIFT;
338 reg = max6621_temp_alert_chan2reg[channel];
339 /* Clamp to allowed range to prevent overflow. */
340 val = clamp_val(val, MAX6621_TEMP_INPUT_MIN,
341 MAX6621_TEMP_INPUT_MAX);
342 val = val / 1000L;
343
344 return regmap_write(data->regmap, reg, val);
345 default:
346 return -EOPNOTSUPP;
347 }
348 break;
349
350 default:
351 return -EOPNOTSUPP;
352 }
353
354 return -EOPNOTSUPP;
355}
356
357static int
358max6621_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
359 int channel, const char **str)
360{
361 switch (type) {
362 case hwmon_temp:
363 switch (attr) {
364 case hwmon_temp_label:
365 *str = max6621_temp_labels[channel];
366 return 0;
367 default:
368 return -EOPNOTSUPP;
369 }
370 break;
371 default:
372 return -EOPNOTSUPP;
373 }
374
375 return -EOPNOTSUPP;
376}
377
378static bool max6621_writeable_reg(struct device *dev, unsigned int reg)
379{
380 switch (reg) {
381 case MAX6621_CONFIG0_REG:
382 case MAX6621_CONFIG1_REG:
383 case MAX6621_CONFIG2_REG:
384 case MAX6621_CONFIG3_REG:
385 case MAX6621_TEMP_S0_ALERT_REG:
386 case MAX6621_TEMP_S1_ALERT_REG:
387 case MAX6621_TEMP_S2_ALERT_REG:
388 case MAX6621_TEMP_S3_ALERT_REG:
389 case MAX6621_TEMP_ALERT_CAUSE_REG:
390 return true;
391 }
392 return false;
393}
394
395static bool max6621_readable_reg(struct device *dev, unsigned int reg)
396{
397 switch (reg) {
398 case MAX6621_TEMP_S0D0_REG:
399 case MAX6621_TEMP_S0D1_REG:
400 case MAX6621_TEMP_S1D0_REG:
401 case MAX6621_TEMP_S1D1_REG:
402 case MAX6621_TEMP_S2D0_REG:
403 case MAX6621_TEMP_S2D1_REG:
404 case MAX6621_TEMP_S3D0_REG:
405 case MAX6621_TEMP_S3D1_REG:
406 case MAX6621_TEMP_MAX_REG:
407 case MAX6621_TEMP_MAX_ADDR_REG:
408 case MAX6621_CONFIG0_REG:
409 case MAX6621_CONFIG1_REG:
410 case MAX6621_CONFIG2_REG:
411 case MAX6621_CONFIG3_REG:
412 case MAX6621_TEMP_S0_ALERT_REG:
413 case MAX6621_TEMP_S1_ALERT_REG:
414 case MAX6621_TEMP_S2_ALERT_REG:
415 case MAX6621_TEMP_S3_ALERT_REG:
416 return true;
417 }
418 return false;
419}
420
421static bool max6621_volatile_reg(struct device *dev, unsigned int reg)
422{
423 switch (reg) {
424 case MAX6621_TEMP_S0D0_REG:
425 case MAX6621_TEMP_S0D1_REG:
426 case MAX6621_TEMP_S1D0_REG:
427 case MAX6621_TEMP_S1D1_REG:
428 case MAX6621_TEMP_S2D0_REG:
429 case MAX6621_TEMP_S2D1_REG:
430 case MAX6621_TEMP_S3D0_REG:
431 case MAX6621_TEMP_S3D1_REG:
432 case MAX6621_TEMP_MAX_REG:
433 case MAX6621_TEMP_S0_ALERT_REG:
434 case MAX6621_TEMP_S1_ALERT_REG:
435 case MAX6621_TEMP_S2_ALERT_REG:
436 case MAX6621_TEMP_S3_ALERT_REG:
437 case MAX6621_TEMP_ALERT_CAUSE_REG:
438 return true;
439 }
440 return false;
441}
442
443static const struct reg_default max6621_regmap_default[] = {
444 { MAX6621_CONFIG0_REG, MAX6621_CONFIG0_INIT },
445 { MAX6621_CONFIG1_REG, MAX6621_CONFIG1_INIT },
446};
447
448static const struct regmap_config max6621_regmap_config = {
449 .reg_bits = 8,
450 .val_bits = 16,
451 .max_register = MAX6621_REG_MAX,
452 .val_format_endian = REGMAP_ENDIAN_LITTLE,
453 .cache_type = REGCACHE_FLAT,
454 .writeable_reg = max6621_writeable_reg,
455 .readable_reg = max6621_readable_reg,
456 .volatile_reg = max6621_volatile_reg,
457 .reg_defaults = max6621_regmap_default,
458 .num_reg_defaults = ARRAY_SIZE(max6621_regmap_default),
459};
460
461static u32 max6621_chip_config[] = {
462 HWMON_C_REGISTER_TZ,
463 0
464};
465
466static const struct hwmon_channel_info max6621_chip = {
467 .type = hwmon_chip,
468 .config = max6621_chip_config,
469};
470
471static const u32 max6621_temp_config[] = {
472 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
473 HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_CRIT_ALARM | HWMON_T_LABEL,
474 HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_CRIT_ALARM | HWMON_T_LABEL,
475 HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_CRIT_ALARM | HWMON_T_LABEL,
476 HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_CRIT_ALARM | HWMON_T_LABEL,
477 HWMON_T_INPUT | HWMON_T_LABEL,
478 HWMON_T_INPUT | HWMON_T_LABEL,
479 HWMON_T_INPUT | HWMON_T_LABEL,
480 HWMON_T_INPUT | HWMON_T_LABEL,
481 0
482};
483
484static const struct hwmon_channel_info max6621_temp = {
485 .type = hwmon_temp,
486 .config = max6621_temp_config,
487};
488
489static const struct hwmon_channel_info *max6621_info[] = {
490 &max6621_chip,
491 &max6621_temp,
492 NULL
493};
494
495static const struct hwmon_ops max6621_hwmon_ops = {
496 .read = max6621_read,
497 .write = max6621_write,
498 .read_string = max6621_read_string,
499 .is_visible = max6621_is_visible,
500};
501
502static const struct hwmon_chip_info max6621_chip_info = {
503 .ops = &max6621_hwmon_ops,
504 .info = max6621_info,
505};
506
507static int max6621_probe(struct i2c_client *client,
508 const struct i2c_device_id *id)
509{
510 struct device *dev = &client->dev;
511 struct max6621_data *data;
512 struct device *hwmon_dev;
513 int i;
514 int ret;
515
516 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
517 if (!data)
518 return -ENOMEM;
519
520 data->regmap = devm_regmap_init_i2c(client, &max6621_regmap_config);
521 if (IS_ERR(data->regmap))
522 return PTR_ERR(data->regmap);
523
524 i2c_set_clientdata(client, data);
525 data->client = client;
526
527 /* Set CONFIG0 register masking temperature alerts and PEC. */
528 ret = regmap_write(data->regmap, MAX6621_CONFIG0_REG,
529 MAX6621_CONFIG0_INIT);
530 if (ret)
531 return ret;
532
533 /* Set CONFIG1 register for PEC access retry number. */
534 ret = regmap_write(data->regmap, MAX6621_CONFIG1_REG,
535 MAX6621_CONFIG1_INIT);
536 if (ret)
537 return ret;
538
539 /* Sync registers with hardware. */
540 regcache_mark_dirty(data->regmap);
541 ret = regcache_sync(data->regmap);
542 if (ret)
543 return ret;
544
545 /* Verify which temperature input registers are enabled. */
546 for (i = 0; i < MAX6621_TEMP_INPUT_REG_NUM; i++) {
547 ret = i2c_smbus_read_word_data(client, max6621_temp_regs[i]);
548 if (ret < 0)
549 return ret;
550 ret = max6621_verify_reg_data(dev, ret);
551 if (ret) {
552 data->input_chan2reg[i] = -1;
553 continue;
554 }
555
556 data->input_chan2reg[i] = max6621_temp_regs[i];
557 }
558
559 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
560 data,
561 &max6621_chip_info,
562 NULL);
563
564 return PTR_ERR_OR_ZERO(hwmon_dev);
565}
566
567static const struct i2c_device_id max6621_id[] = {
568 { MAX6621_DRV_NAME, 0 },
569 { }
570};
571MODULE_DEVICE_TABLE(i2c, max6621_id);
572
573static const struct of_device_id max6621_of_match[] = {
574 { .compatible = "maxim,max6621" },
575 { }
576};
577MODULE_DEVICE_TABLE(of, max6621_of_match);
578
579static struct i2c_driver max6621_driver = {
580 .class = I2C_CLASS_HWMON,
581 .driver = {
582 .name = MAX6621_DRV_NAME,
583 .of_match_table = of_match_ptr(max6621_of_match),
584 },
585 .probe = max6621_probe,
586 .id_table = max6621_id,
587};
588
589module_i2c_driver(max6621_driver);
590
591MODULE_AUTHOR("Vadim Pasternak <vadimp@mellanox.com>");
592MODULE_DESCRIPTION("Driver for Maxim MAX6621");
593MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index 40019325b517..08479006c7f9 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -114,6 +114,16 @@ config SENSORS_MAX20751
114 This driver can also be built as a module. If so, the module will 114 This driver can also be built as a module. If so, the module will
115 be called max20751. 115 be called max20751.
116 116
117config SENSORS_MAX31785
118 tristate "Maxim MAX31785 and compatibles"
119 default n
120 help
121 If you say yes here you get hardware monitoring support for Maxim
122 MAX31785.
123
124 This driver can also be built as a module. If so, the module will
125 be called max31785.
126
117config SENSORS_MAX34440 127config SENSORS_MAX34440
118 tristate "Maxim MAX34440 and compatibles" 128 tristate "Maxim MAX34440 and compatibles"
119 default n 129 default n
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
index e9364420a512..ea0e39518c21 100644
--- a/drivers/hwmon/pmbus/Makefile
+++ b/drivers/hwmon/pmbus/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_SENSORS_LTC2978) += ltc2978.o
13obj-$(CONFIG_SENSORS_LTC3815) += ltc3815.o 13obj-$(CONFIG_SENSORS_LTC3815) += ltc3815.o
14obj-$(CONFIG_SENSORS_MAX16064) += max16064.o 14obj-$(CONFIG_SENSORS_MAX16064) += max16064.o
15obj-$(CONFIG_SENSORS_MAX20751) += max20751.o 15obj-$(CONFIG_SENSORS_MAX20751) += max20751.o
16obj-$(CONFIG_SENSORS_MAX31785) += max31785.o
16obj-$(CONFIG_SENSORS_MAX34440) += max34440.o 17obj-$(CONFIG_SENSORS_MAX34440) += max34440.o
17obj-$(CONFIG_SENSORS_MAX8688) += max8688.o 18obj-$(CONFIG_SENSORS_MAX8688) += max8688.o
18obj-$(CONFIG_SENSORS_TPS40422) += tps40422.o 19obj-$(CONFIG_SENSORS_TPS40422) += tps40422.o
diff --git a/drivers/hwmon/pmbus/max31785.c b/drivers/hwmon/pmbus/max31785.c
new file mode 100644
index 000000000000..9313849d5160
--- /dev/null
+++ b/drivers/hwmon/pmbus/max31785.c
@@ -0,0 +1,116 @@
1/*
2 * Copyright (C) 2017 IBM Corp.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/err.h>
14#include <linux/i2c.h>
15#include "pmbus.h"
16
17enum max31785_regs {
18 MFR_REVISION = 0x9b,
19};
20
21#define MAX31785_NR_PAGES 23
22
23#define MAX31785_FAN_FUNCS \
24 (PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12)
25
26#define MAX31785_TEMP_FUNCS \
27 (PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP)
28
29#define MAX31785_VOUT_FUNCS \
30 (PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT)
31
32static const struct pmbus_driver_info max31785_info = {
33 .pages = MAX31785_NR_PAGES,
34
35 /* RPM */
36 .format[PSC_FAN] = direct,
37 .m[PSC_FAN] = 1,
38 .b[PSC_FAN] = 0,
39 .R[PSC_FAN] = 0,
40 .func[0] = MAX31785_FAN_FUNCS,
41 .func[1] = MAX31785_FAN_FUNCS,
42 .func[2] = MAX31785_FAN_FUNCS,
43 .func[3] = MAX31785_FAN_FUNCS,
44 .func[4] = MAX31785_FAN_FUNCS,
45 .func[5] = MAX31785_FAN_FUNCS,
46
47 .format[PSC_TEMPERATURE] = direct,
48 .m[PSC_TEMPERATURE] = 1,
49 .b[PSC_TEMPERATURE] = 0,
50 .R[PSC_TEMPERATURE] = 2,
51 .func[6] = MAX31785_TEMP_FUNCS,
52 .func[7] = MAX31785_TEMP_FUNCS,
53 .func[8] = MAX31785_TEMP_FUNCS,
54 .func[9] = MAX31785_TEMP_FUNCS,
55 .func[10] = MAX31785_TEMP_FUNCS,
56 .func[11] = MAX31785_TEMP_FUNCS,
57 .func[12] = MAX31785_TEMP_FUNCS,
58 .func[13] = MAX31785_TEMP_FUNCS,
59 .func[14] = MAX31785_TEMP_FUNCS,
60 .func[15] = MAX31785_TEMP_FUNCS,
61 .func[16] = MAX31785_TEMP_FUNCS,
62
63 .format[PSC_VOLTAGE_OUT] = direct,
64 .m[PSC_VOLTAGE_OUT] = 1,
65 .b[PSC_VOLTAGE_OUT] = 0,
66 .R[PSC_VOLTAGE_OUT] = 0,
67 .func[17] = MAX31785_VOUT_FUNCS,
68 .func[18] = MAX31785_VOUT_FUNCS,
69 .func[19] = MAX31785_VOUT_FUNCS,
70 .func[20] = MAX31785_VOUT_FUNCS,
71 .func[21] = MAX31785_VOUT_FUNCS,
72 .func[22] = MAX31785_VOUT_FUNCS,
73};
74
75static int max31785_probe(struct i2c_client *client,
76 const struct i2c_device_id *id)
77{
78 struct device *dev = &client->dev;
79 struct pmbus_driver_info *info;
80 s64 ret;
81
82 info = devm_kzalloc(dev, sizeof(struct pmbus_driver_info), GFP_KERNEL);
83 if (!info)
84 return -ENOMEM;
85
86 *info = max31785_info;
87
88 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 255);
89 if (ret < 0)
90 return ret;
91
92 return pmbus_do_probe(client, id, info);
93}
94
95static const struct i2c_device_id max31785_id[] = {
96 { "max31785", 0 },
97 { "max31785a", 0 },
98 { },
99};
100
101MODULE_DEVICE_TABLE(i2c, max31785_id);
102
103static struct i2c_driver max31785_driver = {
104 .driver = {
105 .name = "max31785",
106 },
107 .probe = max31785_probe,
108 .remove = pmbus_do_remove,
109 .id_table = max31785_id,
110};
111
112module_i2c_driver(max31785_driver);
113
114MODULE_AUTHOR("Andrew Jeffery <andrew@aj.id.au>");
115MODULE_DESCRIPTION("PMBus driver for the Maxim MAX31785");
116MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
index 4efa2bd4f6d8..fa613bd209e3 100644
--- a/drivers/hwmon/pmbus/pmbus.h
+++ b/drivers/hwmon/pmbus/pmbus.h
@@ -404,9 +404,9 @@ extern const struct regulator_ops pmbus_regulator_ops;
404/* Function declarations */ 404/* Function declarations */
405 405
406void pmbus_clear_cache(struct i2c_client *client); 406void pmbus_clear_cache(struct i2c_client *client);
407int pmbus_set_page(struct i2c_client *client, u8 page); 407int pmbus_set_page(struct i2c_client *client, int page);
408int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg); 408int pmbus_read_word_data(struct i2c_client *client, int page, u8 reg);
409int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word); 409int pmbus_write_word_data(struct i2c_client *client, int page, u8 reg, u16 word);
410int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg); 410int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg);
411int pmbus_write_byte(struct i2c_client *client, int page, u8 value); 411int pmbus_write_byte(struct i2c_client *client, int page, u8 value);
412int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg, 412int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg,
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 302f0aef59de..52a58b8b6e1b 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -136,13 +136,13 @@ void pmbus_clear_cache(struct i2c_client *client)
136} 136}
137EXPORT_SYMBOL_GPL(pmbus_clear_cache); 137EXPORT_SYMBOL_GPL(pmbus_clear_cache);
138 138
139int pmbus_set_page(struct i2c_client *client, u8 page) 139int pmbus_set_page(struct i2c_client *client, int page)
140{ 140{
141 struct pmbus_data *data = i2c_get_clientdata(client); 141 struct pmbus_data *data = i2c_get_clientdata(client);
142 int rv = 0; 142 int rv = 0;
143 int newpage; 143 int newpage;
144 144
145 if (page != data->currpage) { 145 if (page >= 0 && page != data->currpage) {
146 rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page); 146 rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page);
147 newpage = i2c_smbus_read_byte_data(client, PMBUS_PAGE); 147 newpage = i2c_smbus_read_byte_data(client, PMBUS_PAGE);
148 if (newpage != page) 148 if (newpage != page)
@@ -158,11 +158,9 @@ int pmbus_write_byte(struct i2c_client *client, int page, u8 value)
158{ 158{
159 int rv; 159 int rv;
160 160
161 if (page >= 0) { 161 rv = pmbus_set_page(client, page);
162 rv = pmbus_set_page(client, page); 162 if (rv < 0)
163 if (rv < 0) 163 return rv;
164 return rv;
165 }
166 164
167 return i2c_smbus_write_byte(client, value); 165 return i2c_smbus_write_byte(client, value);
168} 166}
@@ -186,7 +184,8 @@ static int _pmbus_write_byte(struct i2c_client *client, int page, u8 value)
186 return pmbus_write_byte(client, page, value); 184 return pmbus_write_byte(client, page, value);
187} 185}
188 186
189int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word) 187int pmbus_write_word_data(struct i2c_client *client, int page, u8 reg,
188 u16 word)
190{ 189{
191 int rv; 190 int rv;
192 191
@@ -219,7 +218,7 @@ static int _pmbus_write_word_data(struct i2c_client *client, int page, int reg,
219 return pmbus_write_word_data(client, page, reg, word); 218 return pmbus_write_word_data(client, page, reg, word);
220} 219}
221 220
222int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg) 221int pmbus_read_word_data(struct i2c_client *client, int page, u8 reg)
223{ 222{
224 int rv; 223 int rv;
225 224
@@ -255,11 +254,9 @@ int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg)
255{ 254{
256 int rv; 255 int rv;
257 256
258 if (page >= 0) { 257 rv = pmbus_set_page(client, page);
259 rv = pmbus_set_page(client, page); 258 if (rv < 0)
260 if (rv < 0) 259 return rv;
261 return rv;
262 }
263 260
264 return i2c_smbus_read_byte_data(client, reg); 261 return i2c_smbus_read_byte_data(client, reg);
265} 262}
diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
index e4d642b673c6..25d28343ba93 100644
--- a/drivers/hwmon/sht15.c
+++ b/drivers/hwmon/sht15.c
@@ -18,13 +18,11 @@
18 18
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/irq.h> 20#include <linux/irq.h>
21#include <linux/gpio.h>
22#include <linux/module.h> 21#include <linux/module.h>
23#include <linux/init.h> 22#include <linux/init.h>
24#include <linux/hwmon.h> 23#include <linux/hwmon.h>
25#include <linux/hwmon-sysfs.h> 24#include <linux/hwmon-sysfs.h>
26#include <linux/mutex.h> 25#include <linux/mutex.h>
27#include <linux/platform_data/sht15.h>
28#include <linux/platform_device.h> 26#include <linux/platform_device.h>
29#include <linux/sched.h> 27#include <linux/sched.h>
30#include <linux/delay.h> 28#include <linux/delay.h>
@@ -34,7 +32,8 @@
34#include <linux/slab.h> 32#include <linux/slab.h>
35#include <linux/atomic.h> 33#include <linux/atomic.h>
36#include <linux/bitrev.h> 34#include <linux/bitrev.h>
37#include <linux/of_gpio.h> 35#include <linux/gpio/consumer.h>
36#include <linux/of.h>
38 37
39/* Commands */ 38/* Commands */
40#define SHT15_MEASURE_TEMP 0x03 39#define SHT15_MEASURE_TEMP 0x03
@@ -122,7 +121,8 @@ static const u8 sht15_crc8_table[] = {
122 121
123/** 122/**
124 * struct sht15_data - device instance specific data 123 * struct sht15_data - device instance specific data
125 * @pdata: platform data (gpio's etc). 124 * @sck: clock GPIO line
125 * @data: data GPIO line
126 * @read_work: bh of interrupt handler. 126 * @read_work: bh of interrupt handler.
127 * @wait_queue: wait queue for getting values from device. 127 * @wait_queue: wait queue for getting values from device.
128 * @val_temp: last temperature value read from device. 128 * @val_temp: last temperature value read from device.
@@ -150,7 +150,8 @@ static const u8 sht15_crc8_table[] = {
150 * @interrupt_handled: flag used to indicate a handler has been scheduled. 150 * @interrupt_handled: flag used to indicate a handler has been scheduled.
151 */ 151 */
152struct sht15_data { 152struct sht15_data {
153 struct sht15_platform_data *pdata; 153 struct gpio_desc *sck;
154 struct gpio_desc *data;
154 struct work_struct read_work; 155 struct work_struct read_work;
155 wait_queue_head_t wait_queue; 156 wait_queue_head_t wait_queue;
156 uint16_t val_temp; 157 uint16_t val_temp;
@@ -205,16 +206,16 @@ static int sht15_connection_reset(struct sht15_data *data)
205{ 206{
206 int i, err; 207 int i, err;
207 208
208 err = gpio_direction_output(data->pdata->gpio_data, 1); 209 err = gpiod_direction_output(data->data, 1);
209 if (err) 210 if (err)
210 return err; 211 return err;
211 ndelay(SHT15_TSCKL); 212 ndelay(SHT15_TSCKL);
212 gpio_set_value(data->pdata->gpio_sck, 0); 213 gpiod_set_value(data->sck, 0);
213 ndelay(SHT15_TSCKL); 214 ndelay(SHT15_TSCKL);
214 for (i = 0; i < 9; ++i) { 215 for (i = 0; i < 9; ++i) {
215 gpio_set_value(data->pdata->gpio_sck, 1); 216 gpiod_set_value(data->sck, 1);
216 ndelay(SHT15_TSCKH); 217 ndelay(SHT15_TSCKH);
217 gpio_set_value(data->pdata->gpio_sck, 0); 218 gpiod_set_value(data->sck, 0);
218 ndelay(SHT15_TSCKL); 219 ndelay(SHT15_TSCKL);
219 } 220 }
220 return 0; 221 return 0;
@@ -227,11 +228,11 @@ static int sht15_connection_reset(struct sht15_data *data)
227 */ 228 */
228static inline void sht15_send_bit(struct sht15_data *data, int val) 229static inline void sht15_send_bit(struct sht15_data *data, int val)
229{ 230{
230 gpio_set_value(data->pdata->gpio_data, val); 231 gpiod_set_value(data->data, val);
231 ndelay(SHT15_TSU); 232 ndelay(SHT15_TSU);
232 gpio_set_value(data->pdata->gpio_sck, 1); 233 gpiod_set_value(data->sck, 1);
233 ndelay(SHT15_TSCKH); 234 ndelay(SHT15_TSCKH);
234 gpio_set_value(data->pdata->gpio_sck, 0); 235 gpiod_set_value(data->sck, 0);
235 ndelay(SHT15_TSCKL); /* clock low time */ 236 ndelay(SHT15_TSCKL); /* clock low time */
236} 237}
237 238
@@ -248,23 +249,23 @@ static int sht15_transmission_start(struct sht15_data *data)
248 int err; 249 int err;
249 250
250 /* ensure data is high and output */ 251 /* ensure data is high and output */
251 err = gpio_direction_output(data->pdata->gpio_data, 1); 252 err = gpiod_direction_output(data->data, 1);
252 if (err) 253 if (err)
253 return err; 254 return err;
254 ndelay(SHT15_TSU); 255 ndelay(SHT15_TSU);
255 gpio_set_value(data->pdata->gpio_sck, 0); 256 gpiod_set_value(data->sck, 0);
256 ndelay(SHT15_TSCKL); 257 ndelay(SHT15_TSCKL);
257 gpio_set_value(data->pdata->gpio_sck, 1); 258 gpiod_set_value(data->sck, 1);
258 ndelay(SHT15_TSCKH); 259 ndelay(SHT15_TSCKH);
259 gpio_set_value(data->pdata->gpio_data, 0); 260 gpiod_set_value(data->data, 0);
260 ndelay(SHT15_TSU); 261 ndelay(SHT15_TSU);
261 gpio_set_value(data->pdata->gpio_sck, 0); 262 gpiod_set_value(data->sck, 0);
262 ndelay(SHT15_TSCKL); 263 ndelay(SHT15_TSCKL);
263 gpio_set_value(data->pdata->gpio_sck, 1); 264 gpiod_set_value(data->sck, 1);
264 ndelay(SHT15_TSCKH); 265 ndelay(SHT15_TSCKH);
265 gpio_set_value(data->pdata->gpio_data, 1); 266 gpiod_set_value(data->data, 1);
266 ndelay(SHT15_TSU); 267 ndelay(SHT15_TSU);
267 gpio_set_value(data->pdata->gpio_sck, 0); 268 gpiod_set_value(data->sck, 0);
268 ndelay(SHT15_TSCKL); 269 ndelay(SHT15_TSCKL);
269 return 0; 270 return 0;
270} 271}
@@ -292,20 +293,20 @@ static int sht15_wait_for_response(struct sht15_data *data)
292{ 293{
293 int err; 294 int err;
294 295
295 err = gpio_direction_input(data->pdata->gpio_data); 296 err = gpiod_direction_input(data->data);
296 if (err) 297 if (err)
297 return err; 298 return err;
298 gpio_set_value(data->pdata->gpio_sck, 1); 299 gpiod_set_value(data->sck, 1);
299 ndelay(SHT15_TSCKH); 300 ndelay(SHT15_TSCKH);
300 if (gpio_get_value(data->pdata->gpio_data)) { 301 if (gpiod_get_value(data->data)) {
301 gpio_set_value(data->pdata->gpio_sck, 0); 302 gpiod_set_value(data->sck, 0);
302 dev_err(data->dev, "Command not acknowledged\n"); 303 dev_err(data->dev, "Command not acknowledged\n");
303 err = sht15_connection_reset(data); 304 err = sht15_connection_reset(data);
304 if (err) 305 if (err)
305 return err; 306 return err;
306 return -EIO; 307 return -EIO;
307 } 308 }
308 gpio_set_value(data->pdata->gpio_sck, 0); 309 gpiod_set_value(data->sck, 0);
309 ndelay(SHT15_TSCKL); 310 ndelay(SHT15_TSCKL);
310 return 0; 311 return 0;
311} 312}
@@ -360,17 +361,17 @@ static int sht15_ack(struct sht15_data *data)
360{ 361{
361 int err; 362 int err;
362 363
363 err = gpio_direction_output(data->pdata->gpio_data, 0); 364 err = gpiod_direction_output(data->data, 0);
364 if (err) 365 if (err)
365 return err; 366 return err;
366 ndelay(SHT15_TSU); 367 ndelay(SHT15_TSU);
367 gpio_set_value(data->pdata->gpio_sck, 1); 368 gpiod_set_value(data->sck, 1);
368 ndelay(SHT15_TSU); 369 ndelay(SHT15_TSU);
369 gpio_set_value(data->pdata->gpio_sck, 0); 370 gpiod_set_value(data->sck, 0);
370 ndelay(SHT15_TSU); 371 ndelay(SHT15_TSU);
371 gpio_set_value(data->pdata->gpio_data, 1); 372 gpiod_set_value(data->data, 1);
372 373
373 return gpio_direction_input(data->pdata->gpio_data); 374 return gpiod_direction_input(data->data);
374} 375}
375 376
376/** 377/**
@@ -383,13 +384,13 @@ static int sht15_end_transmission(struct sht15_data *data)
383{ 384{
384 int err; 385 int err;
385 386
386 err = gpio_direction_output(data->pdata->gpio_data, 1); 387 err = gpiod_direction_output(data->data, 1);
387 if (err) 388 if (err)
388 return err; 389 return err;
389 ndelay(SHT15_TSU); 390 ndelay(SHT15_TSU);
390 gpio_set_value(data->pdata->gpio_sck, 1); 391 gpiod_set_value(data->sck, 1);
391 ndelay(SHT15_TSCKH); 392 ndelay(SHT15_TSCKH);
392 gpio_set_value(data->pdata->gpio_sck, 0); 393 gpiod_set_value(data->sck, 0);
393 ndelay(SHT15_TSCKL); 394 ndelay(SHT15_TSCKL);
394 return 0; 395 return 0;
395} 396}
@@ -405,10 +406,10 @@ static u8 sht15_read_byte(struct sht15_data *data)
405 406
406 for (i = 0; i < 8; ++i) { 407 for (i = 0; i < 8; ++i) {
407 byte <<= 1; 408 byte <<= 1;
408 gpio_set_value(data->pdata->gpio_sck, 1); 409 gpiod_set_value(data->sck, 1);
409 ndelay(SHT15_TSCKH); 410 ndelay(SHT15_TSCKH);
410 byte |= !!gpio_get_value(data->pdata->gpio_data); 411 byte |= !!gpiod_get_value(data->data);
411 gpio_set_value(data->pdata->gpio_sck, 0); 412 gpiod_set_value(data->sck, 0);
412 ndelay(SHT15_TSCKL); 413 ndelay(SHT15_TSCKL);
413 } 414 }
414 return byte; 415 return byte;
@@ -428,7 +429,7 @@ static int sht15_send_status(struct sht15_data *data, u8 status)
428 err = sht15_send_cmd(data, SHT15_WRITE_STATUS); 429 err = sht15_send_cmd(data, SHT15_WRITE_STATUS);
429 if (err) 430 if (err)
430 return err; 431 return err;
431 err = gpio_direction_output(data->pdata->gpio_data, 1); 432 err = gpiod_direction_output(data->data, 1);
432 if (err) 433 if (err)
433 return err; 434 return err;
434 ndelay(SHT15_TSU); 435 ndelay(SHT15_TSU);
@@ -528,14 +529,14 @@ static int sht15_measurement(struct sht15_data *data,
528 if (ret) 529 if (ret)
529 return ret; 530 return ret;
530 531
531 ret = gpio_direction_input(data->pdata->gpio_data); 532 ret = gpiod_direction_input(data->data);
532 if (ret) 533 if (ret)
533 return ret; 534 return ret;
534 atomic_set(&data->interrupt_handled, 0); 535 atomic_set(&data->interrupt_handled, 0);
535 536
536 enable_irq(gpio_to_irq(data->pdata->gpio_data)); 537 enable_irq(gpiod_to_irq(data->data));
537 if (gpio_get_value(data->pdata->gpio_data) == 0) { 538 if (gpiod_get_value(data->data) == 0) {
538 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); 539 disable_irq_nosync(gpiod_to_irq(data->data));
539 /* Only relevant if the interrupt hasn't occurred. */ 540 /* Only relevant if the interrupt hasn't occurred. */
540 if (!atomic_read(&data->interrupt_handled)) 541 if (!atomic_read(&data->interrupt_handled))
541 schedule_work(&data->read_work); 542 schedule_work(&data->read_work);
@@ -547,7 +548,7 @@ static int sht15_measurement(struct sht15_data *data,
547 data->state = SHT15_READING_NOTHING; 548 data->state = SHT15_READING_NOTHING;
548 return -EIO; 549 return -EIO;
549 } else if (ret == 0) { /* timeout occurred */ 550 } else if (ret == 0) { /* timeout occurred */
550 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); 551 disable_irq_nosync(gpiod_to_irq(data->data));
551 ret = sht15_connection_reset(data); 552 ret = sht15_connection_reset(data);
552 if (ret) 553 if (ret)
553 return ret; 554 return ret;
@@ -826,15 +827,15 @@ static void sht15_bh_read_data(struct work_struct *work_s)
826 read_work); 827 read_work);
827 828
828 /* Firstly, verify the line is low */ 829 /* Firstly, verify the line is low */
829 if (gpio_get_value(data->pdata->gpio_data)) { 830 if (gpiod_get_value(data->data)) {
830 /* 831 /*
831 * If not, then start the interrupt again - care here as could 832 * If not, then start the interrupt again - care here as could
832 * have gone low in meantime so verify it hasn't! 833 * have gone low in meantime so verify it hasn't!
833 */ 834 */
834 atomic_set(&data->interrupt_handled, 0); 835 atomic_set(&data->interrupt_handled, 0);
835 enable_irq(gpio_to_irq(data->pdata->gpio_data)); 836 enable_irq(gpiod_to_irq(data->data));
836 /* If still not occurred or another handler was scheduled */ 837 /* If still not occurred or another handler was scheduled */
837 if (gpio_get_value(data->pdata->gpio_data) 838 if (gpiod_get_value(data->data)
838 || atomic_read(&data->interrupt_handled)) 839 || atomic_read(&data->interrupt_handled))
839 return; 840 return;
840 } 841 }
@@ -918,53 +919,12 @@ static const struct of_device_id sht15_dt_match[] = {
918 { }, 919 { },
919}; 920};
920MODULE_DEVICE_TABLE(of, sht15_dt_match); 921MODULE_DEVICE_TABLE(of, sht15_dt_match);
921
922/*
923 * This function returns NULL if pdev isn't a device instatiated by dt,
924 * a pointer to pdata if it could successfully get all information
925 * from dt or a negative ERR_PTR() on error.
926 */
927static struct sht15_platform_data *sht15_probe_dt(struct device *dev)
928{
929 struct device_node *np = dev->of_node;
930 struct sht15_platform_data *pdata;
931
932 /* no device tree device */
933 if (!np)
934 return NULL;
935
936 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
937 if (!pdata)
938 return ERR_PTR(-ENOMEM);
939
940 pdata->gpio_data = of_get_named_gpio(np, "data-gpios", 0);
941 if (pdata->gpio_data < 0) {
942 if (pdata->gpio_data != -EPROBE_DEFER)
943 dev_err(dev, "data-gpios not found\n");
944 return ERR_PTR(pdata->gpio_data);
945 }
946
947 pdata->gpio_sck = of_get_named_gpio(np, "clk-gpios", 0);
948 if (pdata->gpio_sck < 0) {
949 if (pdata->gpio_sck != -EPROBE_DEFER)
950 dev_err(dev, "clk-gpios not found\n");
951 return ERR_PTR(pdata->gpio_sck);
952 }
953
954 return pdata;
955}
956#else
957static inline struct sht15_platform_data *sht15_probe_dt(struct device *dev)
958{
959 return NULL;
960}
961#endif 922#endif
962 923
963static int sht15_probe(struct platform_device *pdev) 924static int sht15_probe(struct platform_device *pdev)
964{ 925{
965 int ret; 926 int ret;
966 struct sht15_data *data; 927 struct sht15_data *data;
967 u8 status = 0;
968 928
969 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 929 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
970 if (!data) 930 if (!data)
@@ -977,25 +937,6 @@ static int sht15_probe(struct platform_device *pdev)
977 data->dev = &pdev->dev; 937 data->dev = &pdev->dev;
978 init_waitqueue_head(&data->wait_queue); 938 init_waitqueue_head(&data->wait_queue);
979 939
980 data->pdata = sht15_probe_dt(&pdev->dev);
981 if (IS_ERR(data->pdata))
982 return PTR_ERR(data->pdata);
983 if (data->pdata == NULL) {
984 data->pdata = dev_get_platdata(&pdev->dev);
985 if (data->pdata == NULL) {
986 dev_err(&pdev->dev, "no platform data supplied\n");
987 return -EINVAL;
988 }
989 }
990
991 data->supply_uv = data->pdata->supply_mv * 1000;
992 if (data->pdata->checksum)
993 data->checksumming = true;
994 if (data->pdata->no_otp_reload)
995 status |= SHT15_STATUS_NO_OTP_RELOAD;
996 if (data->pdata->low_resolution)
997 status |= SHT15_STATUS_LOW_RESOLUTION;
998
999 /* 940 /*
1000 * If a regulator is available, 941 * If a regulator is available,
1001 * query what the supply voltage actually is! 942 * query what the supply voltage actually is!
@@ -1030,21 +971,20 @@ static int sht15_probe(struct platform_device *pdev)
1030 } 971 }
1031 972
1032 /* Try requesting the GPIOs */ 973 /* Try requesting the GPIOs */
1033 ret = devm_gpio_request_one(&pdev->dev, data->pdata->gpio_sck, 974 data->sck = devm_gpiod_get(&pdev->dev, "clk", GPIOD_OUT_LOW);
1034 GPIOF_OUT_INIT_LOW, "SHT15 sck"); 975 if (IS_ERR(data->sck)) {
1035 if (ret) { 976 ret = PTR_ERR(data->sck);
1036 dev_err(&pdev->dev, "clock line GPIO request failed\n"); 977 dev_err(&pdev->dev, "clock line GPIO request failed\n");
1037 goto err_release_reg; 978 goto err_release_reg;
1038 } 979 }
1039 980 data->data = devm_gpiod_get(&pdev->dev, "data", GPIOD_IN);
1040 ret = devm_gpio_request(&pdev->dev, data->pdata->gpio_data, 981 if (IS_ERR(data->data)) {
1041 "SHT15 data"); 982 ret = PTR_ERR(data->data);
1042 if (ret) {
1043 dev_err(&pdev->dev, "data line GPIO request failed\n"); 983 dev_err(&pdev->dev, "data line GPIO request failed\n");
1044 goto err_release_reg; 984 goto err_release_reg;
1045 } 985 }
1046 986
1047 ret = devm_request_irq(&pdev->dev, gpio_to_irq(data->pdata->gpio_data), 987 ret = devm_request_irq(&pdev->dev, gpiod_to_irq(data->data),
1048 sht15_interrupt_fired, 988 sht15_interrupt_fired,
1049 IRQF_TRIGGER_FALLING, 989 IRQF_TRIGGER_FALLING,
1050 "sht15 data", 990 "sht15 data",
@@ -1053,7 +993,7 @@ static int sht15_probe(struct platform_device *pdev)
1053 dev_err(&pdev->dev, "failed to get irq for data line\n"); 993 dev_err(&pdev->dev, "failed to get irq for data line\n");
1054 goto err_release_reg; 994 goto err_release_reg;
1055 } 995 }
1056 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); 996 disable_irq_nosync(gpiod_to_irq(data->data));
1057 ret = sht15_connection_reset(data); 997 ret = sht15_connection_reset(data);
1058 if (ret) 998 if (ret)
1059 goto err_release_reg; 999 goto err_release_reg;
@@ -1061,13 +1001,6 @@ static int sht15_probe(struct platform_device *pdev)
1061 if (ret) 1001 if (ret)
1062 goto err_release_reg; 1002 goto err_release_reg;
1063 1003
1064 /* write status with platform data options */
1065 if (status) {
1066 ret = sht15_send_status(data, status);
1067 if (ret)
1068 goto err_release_reg;
1069 }
1070
1071 ret = sysfs_create_group(&pdev->dev.kobj, &sht15_attr_group); 1004 ret = sysfs_create_group(&pdev->dev.kobj, &sht15_attr_group);
1072 if (ret) { 1005 if (ret) {
1073 dev_err(&pdev->dev, "sysfs create failed\n"); 1006 dev_err(&pdev->dev, "sysfs create failed\n");
diff --git a/drivers/hwmon/stts751.c b/drivers/hwmon/stts751.c
index 3f940fb67dc6..7fe152d92350 100644
--- a/drivers/hwmon/stts751.c
+++ b/drivers/hwmon/stts751.c
@@ -396,7 +396,7 @@ static ssize_t show_max_alarm(struct device *dev, struct device_attribute *attr,
396 if (ret < 0) 396 if (ret < 0)
397 return ret; 397 return ret;
398 398
399 return snprintf(buf, PAGE_SIZE - 1, "%d\n", priv->max_alert); 399 return snprintf(buf, PAGE_SIZE, "%d\n", priv->max_alert);
400} 400}
401 401
402static ssize_t show_min_alarm(struct device *dev, struct device_attribute *attr, 402static ssize_t show_min_alarm(struct device *dev, struct device_attribute *attr,
@@ -413,7 +413,7 @@ static ssize_t show_min_alarm(struct device *dev, struct device_attribute *attr,
413 if (ret < 0) 413 if (ret < 0)
414 return ret; 414 return ret;
415 415
416 return snprintf(buf, PAGE_SIZE - 1, "%d\n", priv->min_alert); 416 return snprintf(buf, PAGE_SIZE, "%d\n", priv->min_alert);
417} 417}
418 418
419static ssize_t show_input(struct device *dev, struct device_attribute *attr, 419static ssize_t show_input(struct device *dev, struct device_attribute *attr,
@@ -428,7 +428,7 @@ static ssize_t show_input(struct device *dev, struct device_attribute *attr,
428 if (ret < 0) 428 if (ret < 0)
429 return ret; 429 return ret;
430 430
431 return snprintf(buf, PAGE_SIZE - 1, "%d\n", priv->temp); 431 return snprintf(buf, PAGE_SIZE, "%d\n", priv->temp);
432} 432}
433 433
434static ssize_t show_therm(struct device *dev, struct device_attribute *attr, 434static ssize_t show_therm(struct device *dev, struct device_attribute *attr,
@@ -436,7 +436,7 @@ static ssize_t show_therm(struct device *dev, struct device_attribute *attr,
436{ 436{
437 struct stts751_priv *priv = dev_get_drvdata(dev); 437 struct stts751_priv *priv = dev_get_drvdata(dev);
438 438
439 return snprintf(buf, PAGE_SIZE - 1, "%d\n", priv->therm); 439 return snprintf(buf, PAGE_SIZE, "%d\n", priv->therm);
440} 440}
441 441
442static ssize_t set_therm(struct device *dev, struct device_attribute *attr, 442static ssize_t set_therm(struct device *dev, struct device_attribute *attr,
@@ -478,7 +478,7 @@ static ssize_t show_hyst(struct device *dev, struct device_attribute *attr,
478{ 478{
479 struct stts751_priv *priv = dev_get_drvdata(dev); 479 struct stts751_priv *priv = dev_get_drvdata(dev);
480 480
481 return snprintf(buf, PAGE_SIZE - 1, "%d\n", priv->hyst); 481 return snprintf(buf, PAGE_SIZE, "%d\n", priv->hyst);
482} 482}
483 483
484static ssize_t set_hyst(struct device *dev, struct device_attribute *attr, 484static ssize_t set_hyst(struct device *dev, struct device_attribute *attr,
@@ -518,7 +518,7 @@ static ssize_t show_therm_trip(struct device *dev,
518 if (ret < 0) 518 if (ret < 0)
519 return ret; 519 return ret;
520 520
521 return snprintf(buf, PAGE_SIZE - 1, "%d\n", priv->therm_trip); 521 return snprintf(buf, PAGE_SIZE, "%d\n", priv->therm_trip);
522} 522}
523 523
524static ssize_t show_max(struct device *dev, struct device_attribute *attr, 524static ssize_t show_max(struct device *dev, struct device_attribute *attr,
@@ -526,7 +526,7 @@ static ssize_t show_max(struct device *dev, struct device_attribute *attr,
526{ 526{
527 struct stts751_priv *priv = dev_get_drvdata(dev); 527 struct stts751_priv *priv = dev_get_drvdata(dev);
528 528
529 return snprintf(buf, PAGE_SIZE - 1, "%d\n", priv->event_max); 529 return snprintf(buf, PAGE_SIZE, "%d\n", priv->event_max);
530} 530}
531 531
532static ssize_t set_max(struct device *dev, struct device_attribute *attr, 532static ssize_t set_max(struct device *dev, struct device_attribute *attr,
@@ -560,7 +560,7 @@ static ssize_t show_min(struct device *dev, struct device_attribute *attr,
560{ 560{
561 struct stts751_priv *priv = dev_get_drvdata(dev); 561 struct stts751_priv *priv = dev_get_drvdata(dev);
562 562
563 return snprintf(buf, PAGE_SIZE - 1, "%d\n", priv->event_min); 563 return snprintf(buf, PAGE_SIZE, "%d\n", priv->event_min);
564} 564}
565 565
566static ssize_t set_min(struct device *dev, struct device_attribute *attr, 566static ssize_t set_min(struct device *dev, struct device_attribute *attr,
@@ -594,7 +594,7 @@ static ssize_t show_interval(struct device *dev, struct device_attribute *attr,
594{ 594{
595 struct stts751_priv *priv = dev_get_drvdata(dev); 595 struct stts751_priv *priv = dev_get_drvdata(dev);
596 596
597 return snprintf(buf, PAGE_SIZE - 1, "%d\n", 597 return snprintf(buf, PAGE_SIZE, "%d\n",
598 stts751_intervals[priv->interval]); 598 stts751_intervals[priv->interval]);
599} 599}
600 600
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index dab5c515d5a3..5ba9d9f1daa1 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -1676,7 +1676,9 @@ static int w83793_probe(struct i2c_client *client,
1676 const struct i2c_device_id *id) 1676 const struct i2c_device_id *id)
1677{ 1677{
1678 struct device *dev = &client->dev; 1678 struct device *dev = &client->dev;
1679 const int watchdog_minors[] = { WATCHDOG_MINOR, 212, 213, 214, 215 }; 1679 static const int watchdog_minors[] = {
1680 WATCHDOG_MINOR, 212, 213, 214, 215
1681 };
1680 struct w83793_data *data; 1682 struct w83793_data *data;
1681 int i, tmp, val, err; 1683 int i, tmp, val, err;
1682 int files_fan = ARRAY_SIZE(w83793_left_fan) / 7; 1684 int files_fan = ARRAY_SIZE(w83793_left_fan) / 7;
diff --git a/drivers/hwmon/xgene-hwmon.c b/drivers/hwmon/xgene-hwmon.c
index e1be61095532..a3cd91f23267 100644
--- a/drivers/hwmon/xgene-hwmon.c
+++ b/drivers/hwmon/xgene-hwmon.c
@@ -91,6 +91,11 @@
91#define to_xgene_hwmon_dev(cl) \ 91#define to_xgene_hwmon_dev(cl) \
92 container_of(cl, struct xgene_hwmon_dev, mbox_client) 92 container_of(cl, struct xgene_hwmon_dev, mbox_client)
93 93
94enum xgene_hwmon_version {
95 XGENE_HWMON_V1 = 0,
96 XGENE_HWMON_V2 = 1,
97};
98
94struct slimpro_resp_msg { 99struct slimpro_resp_msg {
95 u32 msg; 100 u32 msg;
96 u32 param1; 101 u32 param1;
@@ -609,6 +614,15 @@ static void xgene_hwmon_tx_done(struct mbox_client *cl, void *msg, int ret)
609 } 614 }
610} 615}
611 616
617#ifdef CONFIG_ACPI
618static const struct acpi_device_id xgene_hwmon_acpi_match[] = {
619 {"APMC0D29", XGENE_HWMON_V1},
620 {"APMC0D8A", XGENE_HWMON_V2},
621 {},
622};
623MODULE_DEVICE_TABLE(acpi, xgene_hwmon_acpi_match);
624#endif
625
612static int xgene_hwmon_probe(struct platform_device *pdev) 626static int xgene_hwmon_probe(struct platform_device *pdev)
613{ 627{
614 struct xgene_hwmon_dev *ctx; 628 struct xgene_hwmon_dev *ctx;
@@ -651,6 +665,15 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
651 } 665 }
652 } else { 666 } else {
653 struct acpi_pcct_hw_reduced *cppc_ss; 667 struct acpi_pcct_hw_reduced *cppc_ss;
668 const struct acpi_device_id *acpi_id;
669 int version;
670
671 acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
672 &pdev->dev);
673 if (!acpi_id)
674 return -EINVAL;
675
676 version = (int)acpi_id->driver_data;
654 677
655 if (device_property_read_u32(&pdev->dev, "pcc-channel", 678 if (device_property_read_u32(&pdev->dev, "pcc-channel",
656 &ctx->mbox_idx)) { 679 &ctx->mbox_idx)) {
@@ -693,7 +716,13 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
693 */ 716 */
694 ctx->comm_base_addr = cppc_ss->base_address; 717 ctx->comm_base_addr = cppc_ss->base_address;
695 if (ctx->comm_base_addr) { 718 if (ctx->comm_base_addr) {
696 ctx->pcc_comm_addr = memremap(ctx->comm_base_addr, 719 if (version == XGENE_HWMON_V2)
720 ctx->pcc_comm_addr = (void __force *)ioremap(
721 ctx->comm_base_addr,
722 cppc_ss->length);
723 else
724 ctx->pcc_comm_addr = memremap(
725 ctx->comm_base_addr,
697 cppc_ss->length, 726 cppc_ss->length,
698 MEMREMAP_WB); 727 MEMREMAP_WB);
699 } else { 728 } else {
@@ -761,14 +790,6 @@ static int xgene_hwmon_remove(struct platform_device *pdev)
761 return 0; 790 return 0;
762} 791}
763 792
764#ifdef CONFIG_ACPI
765static const struct acpi_device_id xgene_hwmon_acpi_match[] = {
766 {"APMC0D29", 0},
767 {},
768};
769MODULE_DEVICE_TABLE(acpi, xgene_hwmon_acpi_match);
770#endif
771
772static const struct of_device_id xgene_hwmon_of_match[] = { 793static const struct of_device_id xgene_hwmon_of_match[] = {
773 {.compatible = "apm,xgene-slimpro-hwmon"}, 794 {.compatible = "apm,xgene-slimpro-hwmon"},
774 {} 795 {}
diff --git a/include/linux/gpio-fan.h b/include/linux/gpio-fan.h
deleted file mode 100644
index 096659169215..000000000000
--- a/include/linux/gpio-fan.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 * include/linux/gpio-fan.h
3 *
4 * Platform data structure for GPIO fan driver
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
10
11#ifndef __LINUX_GPIO_FAN_H
12#define __LINUX_GPIO_FAN_H
13
14struct gpio_fan_alarm {
15 unsigned gpio;
16 unsigned active_low;
17};
18
19struct gpio_fan_speed {
20 int rpm;
21 int ctrl_val;
22};
23
24struct gpio_fan_platform_data {
25 int num_ctrl;
26 unsigned *ctrl; /* fan control GPIOs. */
27 struct gpio_fan_alarm *alarm; /* fan alarm GPIO. */
28 /*
29 * Speed conversion array: rpm from/to GPIO bit field.
30 * This array _must_ be sorted in ascending rpm order.
31 */
32 int num_speed;
33 struct gpio_fan_speed *speed;
34};
35
36#endif /* __LINUX_GPIO_FAN_H */
diff --git a/include/linux/platform_data/sht15.h b/include/linux/platform_data/sht15.h
deleted file mode 100644
index 12289c1e9413..000000000000
--- a/include/linux/platform_data/sht15.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/*
2 * sht15.h - support for the SHT15 Temperature and Humidity Sensor
3 *
4 * Copyright (c) 2009 Jonathan Cameron
5 *
6 * Copyright (c) 2007 Wouter Horre
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * For further information, see the Documentation/hwmon/sht15 file.
13 */
14
15#ifndef _PDATA_SHT15_H
16#define _PDATA_SHT15_H
17
18/**
19 * struct sht15_platform_data - sht15 connectivity info
20 * @gpio_data: no. of gpio to which bidirectional data line is
21 * connected.
22 * @gpio_sck: no. of gpio to which the data clock is connected.
23 * @supply_mv: supply voltage in mv. Overridden by regulator if
24 * available.
25 * @checksum: flag to indicate the checksum should be validated.
26 * @no_otp_reload: flag to indicate no reload from OTP.
27 * @low_resolution: flag to indicate the temp/humidity resolution to use.
28 */
29struct sht15_platform_data {
30 int gpio_data;
31 int gpio_sck;
32 int supply_mv;
33 bool checksum;
34 bool no_otp_reload;
35 bool low_resolution;
36};
37
38#endif /* _PDATA_SHT15_H */