^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) * emc2103.c - Support for SMSC EMC2103
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2010 SMSC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /* Addresses scanned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) static const unsigned short normal_i2c[] = { 0x2E, I2C_CLIENT_END };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static const u8 REG_TEMP[4] = { 0x00, 0x02, 0x04, 0x06 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static const u8 REG_TEMP_MIN[4] = { 0x3c, 0x38, 0x39, 0x3a };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static const u8 REG_TEMP_MAX[4] = { 0x34, 0x30, 0x31, 0x32 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define REG_CONF1 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define REG_TEMP_MAX_ALARM 0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define REG_TEMP_MIN_ALARM 0x25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define REG_FAN_CONF1 0x42
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define REG_FAN_TARGET_LO 0x4c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define REG_FAN_TARGET_HI 0x4d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define REG_FAN_TACH_HI 0x4e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define REG_FAN_TACH_LO 0x4f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define REG_PRODUCT_ID 0xfd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define REG_MFG_ID 0xfe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* equation 4 from datasheet: rpm = (3932160 * multipler) / count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define FAN_RPM_FACTOR 3932160
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * 2103-2 and 2103-4's 3rd temperature sensor can be connected to two diodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * in anti-parallel mode, and in this configuration both can be read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * independently (so we have 4 temperature inputs). The device can't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * detect if it's connected in this mode, so we have to manually enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * it. Default is to leave the device in the state it's already in (-1).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * This parameter allows APD mode to be optionally forced on or off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static int apd = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) module_param(apd, bint, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) MODULE_PARM_DESC(apd, "Set to zero to disable anti-parallel diode mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct temperature {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) s8 degrees;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u8 fraction; /* 0-7 multiples of 0.125 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct emc2103_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) const struct attribute_group *groups[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) bool valid; /* registers are valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) bool fan_rpm_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int temp_count; /* num of temp sensors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) unsigned long last_updated; /* in jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct temperature temp[4]; /* internal + 3 external */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) s8 temp_min[4]; /* no fractional part */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) s8 temp_max[4]; /* no fractional part */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u8 temp_min_alarm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u8 temp_max_alarm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) u8 fan_multiplier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) u16 fan_tach;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) u16 fan_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static int read_u8_from_i2c(struct i2c_client *client, u8 i2c_reg, u8 *output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int status = i2c_smbus_read_byte_data(client, i2c_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) dev_warn(&client->dev, "reg 0x%02x, err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) i2c_reg, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *output = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static void read_temp_from_i2c(struct i2c_client *client, u8 i2c_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct temperature *temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u8 degrees, fractional;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (read_u8_from_i2c(client, i2c_reg, °rees) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (read_u8_from_i2c(client, i2c_reg + 1, &fractional) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) temp->degrees = degrees;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) temp->fraction = (fractional & 0xe0) >> 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static void read_fan_from_i2c(struct i2c_client *client, u16 *output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) u8 hi_addr, u8 lo_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) u8 high_byte, lo_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (read_u8_from_i2c(client, hi_addr, &high_byte) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (read_u8_from_i2c(client, lo_addr, &lo_byte) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) *output = ((u16)high_byte << 5) | (lo_byte >> 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void write_fan_target_to_i2c(struct i2c_client *client, u16 new_target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) u8 high_byte = (new_target & 0x1fe0) >> 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) u8 low_byte = (new_target & 0x001f) << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) i2c_smbus_write_byte_data(client, REG_FAN_TARGET_LO, low_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) i2c_smbus_write_byte_data(client, REG_FAN_TARGET_HI, high_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static void read_fan_config_from_i2c(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct emc2103_data *data = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u8 conf1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (read_u8_from_i2c(client, REG_FAN_CONF1, &conf1) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) data->fan_multiplier = 1 << ((conf1 & 0x60) >> 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) data->fan_rpm_control = (conf1 & 0x80) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static struct emc2103_data *emc2103_update_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct emc2103_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) || !data->valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) for (i = 0; i < data->temp_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) read_temp_from_i2c(client, REG_TEMP[i], &data->temp[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) read_u8_from_i2c(client, REG_TEMP_MIN[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) &data->temp_min[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) read_u8_from_i2c(client, REG_TEMP_MAX[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) &data->temp_max[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) read_u8_from_i2c(client, REG_TEMP_MIN_ALARM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) &data->temp_min_alarm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) read_u8_from_i2c(client, REG_TEMP_MAX_ALARM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) &data->temp_max_alarm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) read_fan_from_i2c(client, &data->fan_tach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) REG_FAN_TACH_HI, REG_FAN_TACH_LO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) read_fan_from_i2c(client, &data->fan_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) REG_FAN_TARGET_HI, REG_FAN_TARGET_LO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) read_fan_config_from_i2c(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) data->last_updated = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) data->valid = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) temp_show(struct device *dev, struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int nr = to_sensor_dev_attr(da)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int millidegrees = data->temp[nr].degrees * 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) + data->temp[nr].fraction * 125;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return sprintf(buf, "%d\n", millidegrees);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) temp_min_show(struct device *dev, struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int nr = to_sensor_dev_attr(da)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int millidegrees = data->temp_min[nr] * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return sprintf(buf, "%d\n", millidegrees);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) temp_max_show(struct device *dev, struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int nr = to_sensor_dev_attr(da)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int millidegrees = data->temp_max[nr] * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return sprintf(buf, "%d\n", millidegrees);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) temp_fault_show(struct device *dev, struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int nr = to_sensor_dev_attr(da)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) bool fault = (data->temp[nr].degrees == -128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return sprintf(buf, "%d\n", fault ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) temp_min_alarm_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) int nr = to_sensor_dev_attr(da)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) bool alarm = data->temp_min_alarm & (1 << nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return sprintf(buf, "%d\n", alarm ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) temp_max_alarm_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int nr = to_sensor_dev_attr(da)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) bool alarm = data->temp_max_alarm & (1 << nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return sprintf(buf, "%d\n", alarm ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static ssize_t temp_min_store(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) int nr = to_sensor_dev_attr(da)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct emc2103_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) int result = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) val = DIV_ROUND_CLOSEST(clamp_val(val, -63000, 127000), 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) data->temp_min[nr] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) i2c_smbus_write_byte_data(client, REG_TEMP_MIN[nr], val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static ssize_t temp_max_store(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int nr = to_sensor_dev_attr(da)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct emc2103_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int result = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) val = DIV_ROUND_CLOSEST(clamp_val(val, -63000, 127000), 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) data->temp_max[nr] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) i2c_smbus_write_byte_data(client, REG_TEMP_MAX[nr], val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) fan1_input_show(struct device *dev, struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) int rpm = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (data->fan_tach != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) rpm = (FAN_RPM_FACTOR * data->fan_multiplier) / data->fan_tach;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return sprintf(buf, "%d\n", rpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) fan1_div_show(struct device *dev, struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) int fan_div = 8 / data->fan_multiplier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return sprintf(buf, "%d\n", fan_div);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * Note: we also update the fan target here, because its value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * determined in part by the fan clock divider. This follows the principle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * of least surprise; the user doesn't expect the fan target to change just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * because the divider changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static ssize_t fan1_div_store(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int new_range_bits, old_div = 8 / data->fan_multiplier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) long new_div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int status = kstrtol(buf, 10, &new_div);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (new_div == old_div) /* No change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) switch (new_div) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) new_range_bits = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) new_range_bits = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) new_range_bits = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) new_range_bits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) status = i2c_smbus_read_byte_data(client, REG_FAN_CONF1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) dev_dbg(&client->dev, "reg 0x%02x, err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) REG_FAN_CONF1, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) status &= 0x9F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) status |= (new_range_bits << 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) i2c_smbus_write_byte_data(client, REG_FAN_CONF1, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) data->fan_multiplier = 8 / new_div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* update fan target if high byte is not disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if ((data->fan_target & 0x1fe0) != 0x1fe0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) u16 new_target = (data->fan_target * old_div) / new_div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) data->fan_target = min(new_target, (u16)0x1fff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) write_fan_target_to_i2c(client, data->fan_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /* invalidate data to force re-read from hardware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) data->valid = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) fan1_target_show(struct device *dev, struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int rpm = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /* high byte of 0xff indicates disabled so return 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if ((data->fan_target != 0) && ((data->fan_target & 0x1fe0) != 0x1fe0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) rpm = (FAN_RPM_FACTOR * data->fan_multiplier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) / data->fan_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return sprintf(buf, "%d\n", rpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static ssize_t fan1_target_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct device_attribute *da, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) unsigned long rpm_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) int result = kstrtoul(buf, 10, &rpm_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* Datasheet states 16384 as maximum RPM target (table 3.2) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) rpm_target = clamp_val(rpm_target, 0, 16384);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) if (rpm_target == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) data->fan_target = 0x1fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) data->fan_target = clamp_val(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) (FAN_RPM_FACTOR * data->fan_multiplier) / rpm_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 0, 0x1fff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) write_fan_target_to_i2c(client, data->fan_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) fan1_fault_show(struct device *dev, struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) bool fault = ((data->fan_tach & 0x1fe0) == 0x1fe0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return sprintf(buf, "%d\n", fault ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) pwm1_enable_show(struct device *dev, struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) struct emc2103_data *data = emc2103_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return sprintf(buf, "%d\n", data->fan_rpm_control ? 3 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static ssize_t pwm1_enable_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) struct device_attribute *da, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct emc2103_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) long new_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) u8 conf_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) int result = kstrtol(buf, 10, &new_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) switch (new_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) data->fan_rpm_control = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) data->fan_rpm_control = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) count = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) result = read_u8_from_i2c(client, REG_FAN_CONF1, &conf_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) count = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (data->fan_rpm_control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) conf_reg |= 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) conf_reg &= ~0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) i2c_smbus_write_byte_data(client, REG_FAN_CONF1, conf_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static SENSOR_DEVICE_ATTR_RO(temp1_fault, temp_fault, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) static SENSOR_DEVICE_ATTR_RO(temp1_min_alarm, temp_min_alarm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, temp_max_alarm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static SENSOR_DEVICE_ATTR_RO(temp2_fault, temp_fault, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static SENSOR_DEVICE_ATTR_RO(temp2_min_alarm, temp_min_alarm, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, temp_max_alarm, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static SENSOR_DEVICE_ATTR_RO(temp3_fault, temp_fault, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static SENSOR_DEVICE_ATTR_RO(temp3_min_alarm, temp_min_alarm, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static SENSOR_DEVICE_ATTR_RO(temp3_max_alarm, temp_max_alarm, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static SENSOR_DEVICE_ATTR_RW(temp4_min, temp_min, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) static SENSOR_DEVICE_ATTR_RW(temp4_max, temp_max, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) static SENSOR_DEVICE_ATTR_RO(temp4_fault, temp_fault, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static SENSOR_DEVICE_ATTR_RO(temp4_min_alarm, temp_min_alarm, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static SENSOR_DEVICE_ATTR_RO(temp4_max_alarm, temp_max_alarm, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static DEVICE_ATTR_RO(fan1_input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static DEVICE_ATTR_RW(fan1_div);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static DEVICE_ATTR_RW(fan1_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static DEVICE_ATTR_RO(fan1_fault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) static DEVICE_ATTR_RW(pwm1_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /* sensors present on all models */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) static struct attribute *emc2103_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) &sensor_dev_attr_temp1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) &sensor_dev_attr_temp1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) &sensor_dev_attr_temp1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) &sensor_dev_attr_temp1_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) &sensor_dev_attr_temp2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) &sensor_dev_attr_temp2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) &sensor_dev_attr_temp2_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) &sensor_dev_attr_temp2_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) &dev_attr_fan1_input.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) &dev_attr_fan1_div.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) &dev_attr_fan1_target.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) &dev_attr_fan1_fault.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) &dev_attr_pwm1_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /* extra temperature sensors only present on 2103-2 and 2103-4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) static struct attribute *emc2103_attributes_temp3[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) &sensor_dev_attr_temp3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) &sensor_dev_attr_temp3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) &sensor_dev_attr_temp3_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) &sensor_dev_attr_temp3_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) &sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /* extra temperature sensors only present on 2103-2 and 2103-4 in APD mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) static struct attribute *emc2103_attributes_temp4[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) &sensor_dev_attr_temp4_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) &sensor_dev_attr_temp4_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) &sensor_dev_attr_temp4_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) &sensor_dev_attr_temp4_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) &sensor_dev_attr_temp4_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) &sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) static const struct attribute_group emc2103_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) .attrs = emc2103_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) static const struct attribute_group emc2103_temp3_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) .attrs = emc2103_attributes_temp3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) static const struct attribute_group emc2103_temp4_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) .attrs = emc2103_attributes_temp4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) emc2103_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) struct emc2103_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) int status, idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) data = devm_kzalloc(&client->dev, sizeof(struct emc2103_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) i2c_set_clientdata(client, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) /* 2103-2 and 2103-4 have 3 external diodes, 2103-1 has 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) status = i2c_smbus_read_byte_data(client, REG_PRODUCT_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) if (status == 0x24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) /* 2103-1 only has 1 external diode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) data->temp_count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /* 2103-2 and 2103-4 have 3 or 4 external diodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) status = i2c_smbus_read_byte_data(client, REG_CONF1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) dev_dbg(&client->dev, "reg 0x%02x, err %d\n", REG_CONF1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) /* detect current state of hardware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) data->temp_count = (status & 0x01) ? 4 : 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) /* force APD state if module parameter is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) if (apd == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) /* force APD mode off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) data->temp_count = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) status &= ~(0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) i2c_smbus_write_byte_data(client, REG_CONF1, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) } else if (apd == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /* force APD mode on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) data->temp_count = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) status |= 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) i2c_smbus_write_byte_data(client, REG_CONF1, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) /* sysfs hooks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) data->groups[idx++] = &emc2103_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (data->temp_count >= 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) data->groups[idx++] = &emc2103_temp3_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (data->temp_count == 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) data->groups[idx++] = &emc2103_temp4_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) client->name, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) data->groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (IS_ERR(hwmon_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return PTR_ERR(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) dev_info(&client->dev, "%s: sensor '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) dev_name(hwmon_dev), client->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) static const struct i2c_device_id emc2103_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) { "emc2103", 0, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) { /* LIST END */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) MODULE_DEVICE_TABLE(i2c, emc2103_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) /* Return 0 if detection is successful, -ENODEV otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) emc2103_detect(struct i2c_client *new_client, struct i2c_board_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) struct i2c_adapter *adapter = new_client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) int manufacturer, product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) manufacturer = i2c_smbus_read_byte_data(new_client, REG_MFG_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) if (manufacturer != 0x5D)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) product = i2c_smbus_read_byte_data(new_client, REG_PRODUCT_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if ((product != 0x24) && (product != 0x26))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) strlcpy(info->type, "emc2103", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) static struct i2c_driver emc2103_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) .class = I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) .name = "emc2103",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) .probe_new = emc2103_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) .id_table = emc2103_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) .detect = emc2103_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) .address_list = normal_i2c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) module_i2c_driver(emc2103_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) MODULE_DESCRIPTION("SMSC EMC2103 hwmon driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) MODULE_LICENSE("GPL");