Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * powr1220.c - Driver for the Lattice POWR1220 programmable power supply
  4 * and monitor. Users can read all ADC inputs along with their labels
  5 * using the sysfs nodes.
  6 *
  7 * Copyright (c) 2014 Echo360 https://www.echo360.com
  8 * Scott Kanowitz <skanowitz@echo360.com> <scott.kanowitz@gmail.com>
  9 */
 10
 11#include <linux/module.h>
 12#include <linux/init.h>
 13#include <linux/slab.h>
 14#include <linux/jiffies.h>
 15#include <linux/i2c.h>
 16#include <linux/hwmon.h>
 17#include <linux/hwmon-sysfs.h>
 18#include <linux/err.h>
 19#include <linux/mutex.h>
 20#include <linux/delay.h>
 21
 22#define ADC_STEP_MV			2
 23#define ADC_MAX_LOW_MEASUREMENT_MV	2000
 24
 
 
 25enum powr1220_regs {
 26	VMON_STATUS0,
 27	VMON_STATUS1,
 28	VMON_STATUS2,
 29	OUTPUT_STATUS0,
 30	OUTPUT_STATUS1,
 31	OUTPUT_STATUS2,
 32	INPUT_STATUS,
 33	ADC_VALUE_LOW,
 34	ADC_VALUE_HIGH,
 35	ADC_MUX,
 36	UES_BYTE0,
 37	UES_BYTE1,
 38	UES_BYTE2,
 39	UES_BYTE3,
 40	GP_OUTPUT1,
 41	GP_OUTPUT2,
 42	GP_OUTPUT3,
 43	INPUT_VALUE,
 44	RESET,
 45	TRIM1_TRIM,
 46	TRIM2_TRIM,
 47	TRIM3_TRIM,
 48	TRIM4_TRIM,
 49	TRIM5_TRIM,
 50	TRIM6_TRIM,
 51	TRIM7_TRIM,
 52	TRIM8_TRIM,
 53	MAX_POWR1220_REGS
 54};
 55
 56enum powr1220_adc_values {
 57	VMON1,
 58	VMON2,
 59	VMON3,
 60	VMON4,
 61	VMON5,
 62	VMON6,
 63	VMON7,
 64	VMON8,
 65	VMON9,
 66	VMON10,
 67	VMON11,
 68	VMON12,
 69	VCCA,
 70	VCCINP,
 71	MAX_POWR1220_ADC_VALUES
 72};
 73
 74struct powr1220_data {
 75	struct i2c_client *client;
 76	struct mutex update_lock;
 
 77	bool adc_valid[MAX_POWR1220_ADC_VALUES];
 78	 /* the next value is in jiffies */
 79	unsigned long adc_last_updated[MAX_POWR1220_ADC_VALUES];
 80
 81	/* values */
 82	int adc_maxes[MAX_POWR1220_ADC_VALUES];
 83	int adc_values[MAX_POWR1220_ADC_VALUES];
 84};
 85
 86static const char * const input_names[] = {
 87	[VMON1]    = "vmon1",
 88	[VMON2]    = "vmon2",
 89	[VMON3]    = "vmon3",
 90	[VMON4]    = "vmon4",
 91	[VMON5]    = "vmon5",
 92	[VMON6]    = "vmon6",
 93	[VMON7]    = "vmon7",
 94	[VMON8]    = "vmon8",
 95	[VMON9]    = "vmon9",
 96	[VMON10]   = "vmon10",
 97	[VMON11]   = "vmon11",
 98	[VMON12]   = "vmon12",
 99	[VCCA]     = "vcca",
100	[VCCINP]   = "vccinp",
101};
102
103/* Reads the specified ADC channel */
104static int powr1220_read_adc(struct device *dev, int ch_num)
105{
106	struct powr1220_data *data = dev_get_drvdata(dev);
107	int reading;
108	int result;
109	int adc_range = 0;
110
111	mutex_lock(&data->update_lock);
112
113	if (time_after(jiffies, data->adc_last_updated[ch_num] + HZ) ||
114			!data->adc_valid[ch_num]) {
115		/*
116		 * figure out if we need to use the attenuator for
117		 * high inputs or inputs that we don't yet have a measurement
118		 * for. We dynamically set the attenuator depending on the
119		 * max reading.
120		 */
121		if (data->adc_maxes[ch_num] > ADC_MAX_LOW_MEASUREMENT_MV ||
122				data->adc_maxes[ch_num] == 0)
123			adc_range = 1 << 4;
124
125		/* set the attenuator and mux */
126		result = i2c_smbus_write_byte_data(data->client, ADC_MUX,
127				adc_range | ch_num);
128		if (result)
129			goto exit;
130
131		/*
132		 * wait at least Tconvert time (200 us) for the
133		 * conversion to complete
134		 */
135		udelay(200);
136
137		/* get the ADC reading */
138		result = i2c_smbus_read_byte_data(data->client, ADC_VALUE_LOW);
139		if (result < 0)
140			goto exit;
141
142		reading = result >> 4;
143
144		/* get the upper half of the reading */
145		result = i2c_smbus_read_byte_data(data->client, ADC_VALUE_HIGH);
146		if (result < 0)
147			goto exit;
148
149		reading |= result << 4;
150
151		/* now convert the reading to a voltage */
152		reading *= ADC_STEP_MV;
153		data->adc_values[ch_num] = reading;
154		data->adc_valid[ch_num] = true;
155		data->adc_last_updated[ch_num] = jiffies;
156		result = reading;
157
158		if (reading > data->adc_maxes[ch_num])
159			data->adc_maxes[ch_num] = reading;
160	} else {
161		result = data->adc_values[ch_num];
162	}
163
164exit:
165	mutex_unlock(&data->update_lock);
166
167	return result;
168}
169
170/* Shows the voltage associated with the specified ADC channel */
171static ssize_t powr1220_voltage_show(struct device *dev,
172				     struct device_attribute *dev_attr,
173				     char *buf)
174{
175	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
176	int adc_val = powr1220_read_adc(dev, attr->index);
 
 
177
178	if (adc_val < 0)
179		return adc_val;
 
 
 
 
 
 
 
 
 
 
 
 
180
181	return sprintf(buf, "%d\n", adc_val);
182}
183
184/* Shows the maximum setting associated with the specified ADC channel */
185static ssize_t powr1220_max_show(struct device *dev,
186				 struct device_attribute *dev_attr, char *buf)
187{
188	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
189	struct powr1220_data *data = dev_get_drvdata(dev);
 
 
 
 
 
 
 
 
 
 
 
190
191	return sprintf(buf, "%d\n", data->adc_maxes[attr->index]);
192}
193
194/* Shows the label associated with the specified ADC channel */
195static ssize_t powr1220_label_show(struct device *dev,
196				   struct device_attribute *dev_attr,
197				   char *buf)
198{
199	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
201	return sprintf(buf, "%s\n", input_names[attr->index]);
202}
203
204static SENSOR_DEVICE_ATTR_RO(in0_input, powr1220_voltage, VMON1);
205static SENSOR_DEVICE_ATTR_RO(in1_input, powr1220_voltage, VMON2);
206static SENSOR_DEVICE_ATTR_RO(in2_input, powr1220_voltage, VMON3);
207static SENSOR_DEVICE_ATTR_RO(in3_input, powr1220_voltage, VMON4);
208static SENSOR_DEVICE_ATTR_RO(in4_input, powr1220_voltage, VMON5);
209static SENSOR_DEVICE_ATTR_RO(in5_input, powr1220_voltage, VMON6);
210static SENSOR_DEVICE_ATTR_RO(in6_input, powr1220_voltage, VMON7);
211static SENSOR_DEVICE_ATTR_RO(in7_input, powr1220_voltage, VMON8);
212static SENSOR_DEVICE_ATTR_RO(in8_input, powr1220_voltage, VMON9);
213static SENSOR_DEVICE_ATTR_RO(in9_input, powr1220_voltage, VMON10);
214static SENSOR_DEVICE_ATTR_RO(in10_input, powr1220_voltage, VMON11);
215static SENSOR_DEVICE_ATTR_RO(in11_input, powr1220_voltage, VMON12);
216static SENSOR_DEVICE_ATTR_RO(in12_input, powr1220_voltage, VCCA);
217static SENSOR_DEVICE_ATTR_RO(in13_input, powr1220_voltage, VCCINP);
218
219static SENSOR_DEVICE_ATTR_RO(in0_highest, powr1220_max, VMON1);
220static SENSOR_DEVICE_ATTR_RO(in1_highest, powr1220_max, VMON2);
221static SENSOR_DEVICE_ATTR_RO(in2_highest, powr1220_max, VMON3);
222static SENSOR_DEVICE_ATTR_RO(in3_highest, powr1220_max, VMON4);
223static SENSOR_DEVICE_ATTR_RO(in4_highest, powr1220_max, VMON5);
224static SENSOR_DEVICE_ATTR_RO(in5_highest, powr1220_max, VMON6);
225static SENSOR_DEVICE_ATTR_RO(in6_highest, powr1220_max, VMON7);
226static SENSOR_DEVICE_ATTR_RO(in7_highest, powr1220_max, VMON8);
227static SENSOR_DEVICE_ATTR_RO(in8_highest, powr1220_max, VMON9);
228static SENSOR_DEVICE_ATTR_RO(in9_highest, powr1220_max, VMON10);
229static SENSOR_DEVICE_ATTR_RO(in10_highest, powr1220_max, VMON11);
230static SENSOR_DEVICE_ATTR_RO(in11_highest, powr1220_max, VMON12);
231static SENSOR_DEVICE_ATTR_RO(in12_highest, powr1220_max, VCCA);
232static SENSOR_DEVICE_ATTR_RO(in13_highest, powr1220_max, VCCINP);
233
234static SENSOR_DEVICE_ATTR_RO(in0_label, powr1220_label, VMON1);
235static SENSOR_DEVICE_ATTR_RO(in1_label, powr1220_label, VMON2);
236static SENSOR_DEVICE_ATTR_RO(in2_label, powr1220_label, VMON3);
237static SENSOR_DEVICE_ATTR_RO(in3_label, powr1220_label, VMON4);
238static SENSOR_DEVICE_ATTR_RO(in4_label, powr1220_label, VMON5);
239static SENSOR_DEVICE_ATTR_RO(in5_label, powr1220_label, VMON6);
240static SENSOR_DEVICE_ATTR_RO(in6_label, powr1220_label, VMON7);
241static SENSOR_DEVICE_ATTR_RO(in7_label, powr1220_label, VMON8);
242static SENSOR_DEVICE_ATTR_RO(in8_label, powr1220_label, VMON9);
243static SENSOR_DEVICE_ATTR_RO(in9_label, powr1220_label, VMON10);
244static SENSOR_DEVICE_ATTR_RO(in10_label, powr1220_label, VMON11);
245static SENSOR_DEVICE_ATTR_RO(in11_label, powr1220_label, VMON12);
246static SENSOR_DEVICE_ATTR_RO(in12_label, powr1220_label, VCCA);
247static SENSOR_DEVICE_ATTR_RO(in13_label, powr1220_label, VCCINP);
248
249static struct attribute *powr1220_attrs[] = {
250	&sensor_dev_attr_in0_input.dev_attr.attr,
251	&sensor_dev_attr_in1_input.dev_attr.attr,
252	&sensor_dev_attr_in2_input.dev_attr.attr,
253	&sensor_dev_attr_in3_input.dev_attr.attr,
254	&sensor_dev_attr_in4_input.dev_attr.attr,
255	&sensor_dev_attr_in5_input.dev_attr.attr,
256	&sensor_dev_attr_in6_input.dev_attr.attr,
257	&sensor_dev_attr_in7_input.dev_attr.attr,
258	&sensor_dev_attr_in8_input.dev_attr.attr,
259	&sensor_dev_attr_in9_input.dev_attr.attr,
260	&sensor_dev_attr_in10_input.dev_attr.attr,
261	&sensor_dev_attr_in11_input.dev_attr.attr,
262	&sensor_dev_attr_in12_input.dev_attr.attr,
263	&sensor_dev_attr_in13_input.dev_attr.attr,
264
265	&sensor_dev_attr_in0_highest.dev_attr.attr,
266	&sensor_dev_attr_in1_highest.dev_attr.attr,
267	&sensor_dev_attr_in2_highest.dev_attr.attr,
268	&sensor_dev_attr_in3_highest.dev_attr.attr,
269	&sensor_dev_attr_in4_highest.dev_attr.attr,
270	&sensor_dev_attr_in5_highest.dev_attr.attr,
271	&sensor_dev_attr_in6_highest.dev_attr.attr,
272	&sensor_dev_attr_in7_highest.dev_attr.attr,
273	&sensor_dev_attr_in8_highest.dev_attr.attr,
274	&sensor_dev_attr_in9_highest.dev_attr.attr,
275	&sensor_dev_attr_in10_highest.dev_attr.attr,
276	&sensor_dev_attr_in11_highest.dev_attr.attr,
277	&sensor_dev_attr_in12_highest.dev_attr.attr,
278	&sensor_dev_attr_in13_highest.dev_attr.attr,
279
280	&sensor_dev_attr_in0_label.dev_attr.attr,
281	&sensor_dev_attr_in1_label.dev_attr.attr,
282	&sensor_dev_attr_in2_label.dev_attr.attr,
283	&sensor_dev_attr_in3_label.dev_attr.attr,
284	&sensor_dev_attr_in4_label.dev_attr.attr,
285	&sensor_dev_attr_in5_label.dev_attr.attr,
286	&sensor_dev_attr_in6_label.dev_attr.attr,
287	&sensor_dev_attr_in7_label.dev_attr.attr,
288	&sensor_dev_attr_in8_label.dev_attr.attr,
289	&sensor_dev_attr_in9_label.dev_attr.attr,
290	&sensor_dev_attr_in10_label.dev_attr.attr,
291	&sensor_dev_attr_in11_label.dev_attr.attr,
292	&sensor_dev_attr_in12_label.dev_attr.attr,
293	&sensor_dev_attr_in13_label.dev_attr.attr,
294
295	NULL
296};
297
298ATTRIBUTE_GROUPS(powr1220);
 
 
 
 
 
 
 
 
 
299
300static int powr1220_probe(struct i2c_client *client,
301		const struct i2c_device_id *id)
 
302{
303	struct powr1220_data *data;
304	struct device *hwmon_dev;
305
306	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
307		return -ENODEV;
308
309	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
310	if (!data)
311		return -ENOMEM;
312
 
 
 
 
 
 
 
 
 
313	mutex_init(&data->update_lock);
314	data->client = client;
315
316	hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
317			client->name, data, powr1220_groups);
 
 
 
318
319	return PTR_ERR_OR_ZERO(hwmon_dev);
320}
321
322static const struct i2c_device_id powr1220_ids[] = {
323	{ "powr1220", 0, },
 
324	{ }
325};
326
327MODULE_DEVICE_TABLE(i2c, powr1220_ids);
328
329static struct i2c_driver powr1220_driver = {
330	.class		= I2C_CLASS_HWMON,
331	.driver = {
332		.name	= "powr1220",
333	},
334	.probe		= powr1220_probe,
335	.id_table	= powr1220_ids,
336};
337
338module_i2c_driver(powr1220_driver);
339
340MODULE_AUTHOR("Scott Kanowitz");
341MODULE_DESCRIPTION("POWR1220 driver");
342MODULE_LICENSE("GPL");
v6.8
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * powr1220.c - Driver for the Lattice POWR1220 programmable power supply
  4 * and monitor. Users can read all ADC inputs along with their labels
  5 * using the sysfs nodes.
  6 *
  7 * Copyright (c) 2014 Echo360 https://www.echo360.com
  8 * Scott Kanowitz <skanowitz@echo360.com> <scott.kanowitz@gmail.com>
  9 */
 10
 11#include <linux/module.h>
 12#include <linux/init.h>
 13#include <linux/slab.h>
 14#include <linux/jiffies.h>
 15#include <linux/i2c.h>
 16#include <linux/hwmon.h>
 17#include <linux/hwmon-sysfs.h>
 18#include <linux/err.h>
 19#include <linux/mutex.h>
 20#include <linux/delay.h>
 21
 22#define ADC_STEP_MV			2
 23#define ADC_MAX_LOW_MEASUREMENT_MV	2000
 24
 25enum powr1xxx_chips { powr1014, powr1220 };
 26
 27enum powr1220_regs {
 28	VMON_STATUS0,
 29	VMON_STATUS1,
 30	VMON_STATUS2,
 31	OUTPUT_STATUS0,
 32	OUTPUT_STATUS1,
 33	OUTPUT_STATUS2,
 34	INPUT_STATUS,
 35	ADC_VALUE_LOW,
 36	ADC_VALUE_HIGH,
 37	ADC_MUX,
 38	UES_BYTE0,
 39	UES_BYTE1,
 40	UES_BYTE2,
 41	UES_BYTE3,
 42	GP_OUTPUT1,
 43	GP_OUTPUT2,
 44	GP_OUTPUT3,
 45	INPUT_VALUE,
 46	RESET,
 47	TRIM1_TRIM,
 48	TRIM2_TRIM,
 49	TRIM3_TRIM,
 50	TRIM4_TRIM,
 51	TRIM5_TRIM,
 52	TRIM6_TRIM,
 53	TRIM7_TRIM,
 54	TRIM8_TRIM,
 55	MAX_POWR1220_REGS
 56};
 57
 58enum powr1220_adc_values {
 59	VMON1,
 60	VMON2,
 61	VMON3,
 62	VMON4,
 63	VMON5,
 64	VMON6,
 65	VMON7,
 66	VMON8,
 67	VMON9,
 68	VMON10,
 69	VMON11,
 70	VMON12,
 71	VCCA,
 72	VCCINP,
 73	MAX_POWR1220_ADC_VALUES
 74};
 75
 76struct powr1220_data {
 77	struct i2c_client *client;
 78	struct mutex update_lock;
 79	u8 max_channels;
 80	bool adc_valid[MAX_POWR1220_ADC_VALUES];
 81	 /* the next value is in jiffies */
 82	unsigned long adc_last_updated[MAX_POWR1220_ADC_VALUES];
 83
 84	/* values */
 85	int adc_maxes[MAX_POWR1220_ADC_VALUES];
 86	int adc_values[MAX_POWR1220_ADC_VALUES];
 87};
 88
 89static const char * const input_names[] = {
 90	[VMON1]    = "vmon1",
 91	[VMON2]    = "vmon2",
 92	[VMON3]    = "vmon3",
 93	[VMON4]    = "vmon4",
 94	[VMON5]    = "vmon5",
 95	[VMON6]    = "vmon6",
 96	[VMON7]    = "vmon7",
 97	[VMON8]    = "vmon8",
 98	[VMON9]    = "vmon9",
 99	[VMON10]   = "vmon10",
100	[VMON11]   = "vmon11",
101	[VMON12]   = "vmon12",
102	[VCCA]     = "vcca",
103	[VCCINP]   = "vccinp",
104};
105
106/* Reads the specified ADC channel */
107static int powr1220_read_adc(struct device *dev, int ch_num)
108{
109	struct powr1220_data *data = dev_get_drvdata(dev);
110	int reading;
111	int result;
112	int adc_range = 0;
113
114	mutex_lock(&data->update_lock);
115
116	if (time_after(jiffies, data->adc_last_updated[ch_num] + HZ) ||
117	    !data->adc_valid[ch_num]) {
118		/*
119		 * figure out if we need to use the attenuator for
120		 * high inputs or inputs that we don't yet have a measurement
121		 * for. We dynamically set the attenuator depending on the
122		 * max reading.
123		 */
124		if (data->adc_maxes[ch_num] > ADC_MAX_LOW_MEASUREMENT_MV ||
125		    data->adc_maxes[ch_num] == 0)
126			adc_range = 1 << 4;
127
128		/* set the attenuator and mux */
129		result = i2c_smbus_write_byte_data(data->client, ADC_MUX,
130						   adc_range | ch_num);
131		if (result)
132			goto exit;
133
134		/*
135		 * wait at least Tconvert time (200 us) for the
136		 * conversion to complete
137		 */
138		udelay(200);
139
140		/* get the ADC reading */
141		result = i2c_smbus_read_byte_data(data->client, ADC_VALUE_LOW);
142		if (result < 0)
143			goto exit;
144
145		reading = result >> 4;
146
147		/* get the upper half of the reading */
148		result = i2c_smbus_read_byte_data(data->client, ADC_VALUE_HIGH);
149		if (result < 0)
150			goto exit;
151
152		reading |= result << 4;
153
154		/* now convert the reading to a voltage */
155		reading *= ADC_STEP_MV;
156		data->adc_values[ch_num] = reading;
157		data->adc_valid[ch_num] = true;
158		data->adc_last_updated[ch_num] = jiffies;
159		result = reading;
160
161		if (reading > data->adc_maxes[ch_num])
162			data->adc_maxes[ch_num] = reading;
163	} else {
164		result = data->adc_values[ch_num];
165	}
166
167exit:
168	mutex_unlock(&data->update_lock);
169
170	return result;
171}
172
173static umode_t
174powr1220_is_visible(const void *data, enum hwmon_sensor_types type, u32
175		    attr, int channel)
 
176{
177	struct powr1220_data *chip_data = (struct powr1220_data *)data;
178
179	if (channel >= chip_data->max_channels)
180		return 0;
181
182	switch (type) {
183	case hwmon_in:
184		switch (attr) {
185		case hwmon_in_input:
186		case hwmon_in_highest:
187		case hwmon_in_label:
188			return 0444;
189		default:
190			break;
191		}
192		break;
193	default:
194		break;
195	}
196
197	return 0;
198}
199
200static int
201powr1220_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
202		     int channel, const char **str)
203{
204	switch (type) {
205	case hwmon_in:
206		switch (attr) {
207		case hwmon_in_label:
208			*str = input_names[channel];
209			return 0;
210		default:
211			return -EOPNOTSUPP;
212		}
213		break;
214	default:
215		return -EOPNOTSUPP;
216	}
217
218	return -EOPNOTSUPP;
219}
220
221static int
222powr1220_read(struct device *dev, enum hwmon_sensor_types type, u32
223	      attr, int channel, long *val)
 
224{
225	struct powr1220_data *data = dev_get_drvdata(dev);
226	int ret;
227
228	switch (type) {
229	case hwmon_in:
230		switch (attr) {
231		case hwmon_in_input:
232			ret = powr1220_read_adc(dev, channel);
233			if (ret < 0)
234				return ret;
235			*val = ret;
236			break;
237		case hwmon_in_highest:
238			*val = data->adc_maxes[channel];
239			break;
240		default:
241			return -EOPNOTSUPP;
242		}
243		break;
244	default:
245		return -EOPNOTSUPP;
246}
247
248	return 0;
249}
250
251static const struct hwmon_channel_info * const powr1220_info[] = {
252	HWMON_CHANNEL_INFO(in,
253			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
254			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
255			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
256			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
257			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
258			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
259			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
260			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
261			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
262			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
263			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
264			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
265			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL,
266			   HWMON_I_INPUT | HWMON_I_HIGHEST | HWMON_I_LABEL),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
268	NULL
269};
270
271static const struct hwmon_ops powr1220_hwmon_ops = {
272	.read = powr1220_read,
273	.read_string = powr1220_read_string,
274	.is_visible = powr1220_is_visible,
275};
276
277static const struct hwmon_chip_info powr1220_chip_info = {
278	.ops = &powr1220_hwmon_ops,
279	.info = powr1220_info,
280};
281
282static const struct i2c_device_id powr1220_ids[];
283
284static int powr1220_probe(struct i2c_client *client)
285{
286	struct powr1220_data *data;
287	struct device *hwmon_dev;
288
289	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
290		return -ENODEV;
291
292	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
293	if (!data)
294		return -ENOMEM;
295
296	switch (i2c_match_id(powr1220_ids, client)->driver_data) {
297	case powr1014:
298		data->max_channels = 10;
299		break;
300	default:
301		data->max_channels = 12;
302		break;
303	}
304
305	mutex_init(&data->update_lock);
306	data->client = client;
307
308	hwmon_dev = devm_hwmon_device_register_with_info(&client->dev,
309							 client->name,
310							 data,
311							 &powr1220_chip_info,
312							 NULL);
313
314	return PTR_ERR_OR_ZERO(hwmon_dev);
315}
316
317static const struct i2c_device_id powr1220_ids[] = {
318	{ "powr1014", powr1014, },
319	{ "powr1220", powr1220, },
320	{ }
321};
322
323MODULE_DEVICE_TABLE(i2c, powr1220_ids);
324
325static struct i2c_driver powr1220_driver = {
326	.class		= I2C_CLASS_HWMON,
327	.driver = {
328		.name	= "powr1220",
329	},
330	.probe		= powr1220_probe,
331	.id_table	= powr1220_ids,
332};
333
334module_i2c_driver(powr1220_driver);
335
336MODULE_AUTHOR("Scott Kanowitz");
337MODULE_DESCRIPTION("POWR1220 driver");
338MODULE_LICENSE("GPL");