Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  ds620.c - Support for temperature sensor and thermostat DS620
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/platform_data/ds620.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * Many DS620 constants specified below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *  15   14   13   12   11   10   09    08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *  07   06   05   04   03   02   01    00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * |PO2 |PO1 |A2  |A1  |A0  |    |     |     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define DS620_REG_CONFIG_DONE		0x8000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define DS620_REG_CONFIG_NVB		0x4000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define DS620_REG_CONFIG_THF		0x2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define DS620_REG_CONFIG_TLF		0x1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define DS620_REG_CONFIG_R1		0x0800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define DS620_REG_CONFIG_R0		0x0400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define DS620_REG_CONFIG_AUTOC		0x0200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define DS620_REG_CONFIG_1SHOT		0x0100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define DS620_REG_CONFIG_PO2		0x0080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define DS620_REG_CONFIG_PO1		0x0040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define DS620_REG_CONFIG_A2		0x0020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define DS620_REG_CONFIG_A1		0x0010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define DS620_REG_CONFIG_A0		0x0008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) /* The DS620 registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static const u8 DS620_REG_TEMP[3] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	0xAA,			/* input, word, RO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	0xA2,			/* min, word, RW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	0xA0,			/* max, word, RW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define DS620_REG_CONF		0xAC	/* word, RW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define DS620_COM_START		0x51	/* no data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define DS620_COM_STOP		0x22	/* no data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) /* Each client has this additional data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) struct ds620_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	char valid;		/* !=0 if following fields are valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	unsigned long last_updated;	/* In jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	s16 temp[3];		/* Register values, word */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static void ds620_init_client(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct ds620_platform_data *ds620_info = dev_get_platdata(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	u16 conf, new_conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	new_conf = conf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	    i2c_smbus_read_word_swapped(client, DS620_REG_CONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	/* switch to continuous conversion mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	new_conf &= ~DS620_REG_CONFIG_1SHOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/* already high at power-on, but don't trust the BIOS! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	new_conf |= DS620_REG_CONFIG_PO2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	/* thermostat mode according to platform data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (ds620_info && ds620_info->pomode == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		new_conf &= ~DS620_REG_CONFIG_PO1; /* PO_LOW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	else if (ds620_info && ds620_info->pomode == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		new_conf |= DS620_REG_CONFIG_PO1; /* PO_HIGH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		new_conf &= ~DS620_REG_CONFIG_PO2; /* always low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	/* with highest precision */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (conf != new_conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		i2c_smbus_write_word_swapped(client, DS620_REG_CONF, new_conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	/* start conversion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	i2c_smbus_write_byte(client, DS620_COM_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static struct ds620_data *ds620_update_client(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct ds620_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct ds620_data *ret = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	    || !data->valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		dev_dbg(&client->dev, "Starting ds620 update\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			res = i2c_smbus_read_word_swapped(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 							  DS620_REG_TEMP[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 				ret = ERR_PTR(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			data->temp[i] = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		data->last_updated = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		data->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) abort:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static ssize_t temp_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct ds620_data *data = ds620_update_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static ssize_t temp_store(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			  const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct ds620_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	res = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	val = (clamp_val(val, -128000, 128000) * 10 / 625) * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	data->temp[attr->index] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	i2c_smbus_write_word_swapped(client, DS620_REG_TEMP[attr->index],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				     data->temp[attr->index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static ssize_t alarm_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct ds620_data *data = ds620_update_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	u16 conf, new_conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	/* reset alarms if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	res = i2c_smbus_read_word_swapped(client, DS620_REG_CONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	new_conf = conf = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	new_conf &= ~attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (conf != new_conf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		res = i2c_smbus_write_word_swapped(client, DS620_REG_CONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 						   new_conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	return sprintf(buf, "%d\n", !!(conf & attr->index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static SENSOR_DEVICE_ATTR_RW(temp1_min, temp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static SENSOR_DEVICE_ATTR_RO(temp1_min_alarm, alarm, DS620_REG_CONFIG_TLF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, DS620_REG_CONFIG_THF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static struct attribute *ds620_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	&sensor_dev_attr_temp1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	&sensor_dev_attr_temp1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	&sensor_dev_attr_temp1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ATTRIBUTE_GROUPS(ds620);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static int ds620_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct ds620_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	data = devm_kzalloc(dev, sizeof(struct ds620_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	/* Initialize the DS620 chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	ds620_init_client(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 							   data, ds620_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	return PTR_ERR_OR_ZERO(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static const struct i2c_device_id ds620_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	{"ds620", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) MODULE_DEVICE_TABLE(i2c, ds620_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /* This is the driver that will be inserted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static struct i2c_driver ds620_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	.class = I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		   .name = "ds620",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	.probe_new = ds620_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	.id_table = ds620_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) module_i2c_driver(ds620_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) MODULE_DESCRIPTION("DS620 driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) MODULE_LICENSE("GPL");