88
99#include <linux/delay.h>
1010#include <linux/err.h>
11- #include <linux/hwmon.h>
1211#include <linux/i2c.h>
1312#include <linux/init.h>
1413#include <linux/module.h>
1514#include <linux/mutex.h>
1615#include <linux/of.h>
1716#include "rmi-core.h"
1817
19- /* Do not allow setting negative power limit */
20- #define SBRMI_PWR_MIN 0
21-
2218static int sbrmi_enable_alert (struct i2c_client * client )
2319{
2420 int ctrl ;
@@ -40,100 +36,6 @@ static int sbrmi_enable_alert(struct i2c_client *client)
4036 return 0 ;
4137}
4238
43- static int sbrmi_read (struct device * dev , enum hwmon_sensor_types type ,
44- u32 attr , int channel , long * val )
45- {
46- struct sbrmi_data * data = dev_get_drvdata (dev );
47- struct sbrmi_mailbox_msg msg = { 0 };
48- int ret ;
49-
50- if (type != hwmon_power )
51- return - EINVAL ;
52-
53- msg .read = true;
54- switch (attr ) {
55- case hwmon_power_input :
56- msg .cmd = SBRMI_READ_PKG_PWR_CONSUMPTION ;
57- ret = rmi_mailbox_xfer (data , & msg );
58- break ;
59- case hwmon_power_cap :
60- msg .cmd = SBRMI_READ_PKG_PWR_LIMIT ;
61- ret = rmi_mailbox_xfer (data , & msg );
62- break ;
63- case hwmon_power_cap_max :
64- msg .data_out = data -> pwr_limit_max ;
65- ret = 0 ;
66- break ;
67- default :
68- return - EINVAL ;
69- }
70- if (ret < 0 )
71- return ret ;
72- /* hwmon power attributes are in microWatt */
73- * val = (long )msg .data_out * 1000 ;
74- return ret ;
75- }
76-
77- static int sbrmi_write (struct device * dev , enum hwmon_sensor_types type ,
78- u32 attr , int channel , long val )
79- {
80- struct sbrmi_data * data = dev_get_drvdata (dev );
81- struct sbrmi_mailbox_msg msg = { 0 };
82-
83- if (type != hwmon_power && attr != hwmon_power_cap )
84- return - EINVAL ;
85- /*
86- * hwmon power attributes are in microWatt
87- * mailbox read/write is in mWatt
88- */
89- val /= 1000 ;
90-
91- val = clamp_val (val , SBRMI_PWR_MIN , data -> pwr_limit_max );
92-
93- msg .cmd = SBRMI_WRITE_PKG_PWR_LIMIT ;
94- msg .data_in = val ;
95- msg .read = false;
96-
97- return rmi_mailbox_xfer (data , & msg );
98- }
99-
100- static umode_t sbrmi_is_visible (const void * data ,
101- enum hwmon_sensor_types type ,
102- u32 attr , int channel )
103- {
104- switch (type ) {
105- case hwmon_power :
106- switch (attr ) {
107- case hwmon_power_input :
108- case hwmon_power_cap_max :
109- return 0444 ;
110- case hwmon_power_cap :
111- return 0644 ;
112- }
113- break ;
114- default :
115- break ;
116- }
117- return 0 ;
118- }
119-
120- static const struct hwmon_channel_info * const sbrmi_info [] = {
121- HWMON_CHANNEL_INFO (power ,
122- HWMON_P_INPUT | HWMON_P_CAP | HWMON_P_CAP_MAX ),
123- NULL
124- };
125-
126- static const struct hwmon_ops sbrmi_hwmon_ops = {
127- .is_visible = sbrmi_is_visible ,
128- .read = sbrmi_read ,
129- .write = sbrmi_write ,
130- };
131-
132- static const struct hwmon_chip_info sbrmi_chip_info = {
133- .ops = & sbrmi_hwmon_ops ,
134- .info = sbrmi_info ,
135- };
136-
13739static int sbrmi_get_max_pwr_limit (struct sbrmi_data * data )
13840{
13941 struct sbrmi_mailbox_msg msg = { 0 };
@@ -152,7 +54,6 @@ static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data)
15254static int sbrmi_i2c_probe (struct i2c_client * client )
15355{
15456 struct device * dev = & client -> dev ;
155- struct device * hwmon_dev ;
15657 struct sbrmi_data * data ;
15758 int ret ;
15859
@@ -173,9 +74,8 @@ static int sbrmi_i2c_probe(struct i2c_client *client)
17374 if (ret < 0 )
17475 return ret ;
17576
176- hwmon_dev = devm_hwmon_device_register_with_info (dev , client -> name , data ,
177- & sbrmi_chip_info , NULL );
178- return PTR_ERR_OR_ZERO (hwmon_dev );
77+ dev_set_drvdata (dev , data );
78+ return create_hwmon_sensor_device (dev , data );
17979}
18080
18181static const struct i2c_device_id sbrmi_id [] = {
0 commit comments