^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) * lm80.c - From lm_sensors, Linux kernel modules for hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * monitoring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * and Philip Edelbrock <phil@netroedge.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Ported to Linux 2.6 by Tiago Sousa <mirage@kaotik.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /* Addresses to scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 0x2e, 0x2f, I2C_CLIENT_END };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /* Many LM80 constants specified below */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* The LM80 registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define LM80_REG_IN_MAX(nr) (0x2a + (nr) * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define LM80_REG_IN_MIN(nr) (0x2b + (nr) * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define LM80_REG_IN(nr) (0x20 + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define LM80_REG_FAN1 0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define LM80_REG_FAN2 0x29
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define LM80_REG_FAN_MIN(nr) (0x3b + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define LM80_REG_TEMP 0x27
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define LM80_REG_TEMP_HOT_MAX 0x38
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define LM80_REG_TEMP_HOT_HYST 0x39
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define LM80_REG_TEMP_OS_MAX 0x3a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define LM80_REG_TEMP_OS_HYST 0x3b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define LM80_REG_CONFIG 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define LM80_REG_ALARM1 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define LM80_REG_ALARM2 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define LM80_REG_MASK1 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define LM80_REG_MASK2 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define LM80_REG_FANDIV 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define LM80_REG_RES 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define LM96080_REG_CONV_RATE 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define LM96080_REG_MAN_ID 0x3e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define LM96080_REG_DEV_ID 0x3f
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Conversions. Rounding and limit checking is only done on the TO_REG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * variants. Note that you should be a bit careful with which arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * these macros are called: arguments may be evaluated more than once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * Fixing this is just not worth it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define IN_TO_REG(val) (clamp_val(((val) + 5) / 10, 0, 255))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define IN_FROM_REG(val) ((val) * 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static inline unsigned char FAN_TO_REG(unsigned rpm, unsigned div)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (rpm == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) rpm = clamp_val(rpm, 1, 1000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
^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) #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) (val) == 255 ? 0 : 1350000/((div) * (val)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define TEMP_FROM_REG(reg) ((reg) * 125 / 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define TEMP_TO_REG(temp) (DIV_ROUND_CLOSEST(clamp_val((temp), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) -128000, 127000), 1000) << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define DIV_FROM_REG(val) (1 << (val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) enum temp_index {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) t_input = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) t_hot_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) t_hot_hyst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) t_os_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) t_os_hyst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) t_num_temp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static const u8 temp_regs[t_num_temp] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) [t_input] = LM80_REG_TEMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) [t_hot_max] = LM80_REG_TEMP_HOT_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) [t_hot_hyst] = LM80_REG_TEMP_HOT_HYST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) [t_os_max] = LM80_REG_TEMP_OS_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) [t_os_hyst] = LM80_REG_TEMP_OS_HYST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) enum in_index {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) i_input = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) i_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) i_min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) i_num_in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) enum fan_index {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) f_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) f_min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) f_num_fan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * Client data (each client gets its own)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct lm80_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) char error; /* !=0 if error occurred during last update */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) char valid; /* !=0 if following fields are valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) unsigned long last_updated; /* In jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u8 in[i_num_in][7]; /* Register value, 1st index is enum in_index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) u8 fan[f_num_fan][2]; /* Register value, 1st index enum fan_index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) u8 fan_div[2]; /* Register encoding, shifted right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) s16 temp[t_num_temp]; /* Register values, normalized to 16 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) u16 alarms; /* Register encoding, combined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int lm80_read_value(struct i2c_client *client, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return i2c_smbus_read_byte_data(client, reg);
^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 int lm80_write_value(struct i2c_client *client, u8 reg, u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return i2c_smbus_write_byte_data(client, reg, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* Called when we have found a new LM80 and after read errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static void lm80_init_client(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * Reset all except Watchdog values and last conversion values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * This sets fan-divs to 2, among others. This makes most other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * initializations unnecessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) lm80_write_value(client, LM80_REG_CONFIG, 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* Set 11-bit temperature resolution */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) lm80_write_value(client, LM80_REG_RES, 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /* Start monitoring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) lm80_write_value(client, LM80_REG_CONFIG, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static struct lm80_data *lm80_update_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct lm80_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) int prev_rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct lm80_data *ret = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (data->error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) lm80_init_client(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) dev_dbg(dev, "Starting lm80 update\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) for (i = 0; i <= 6; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) rv = lm80_read_value(client, LM80_REG_IN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) data->in[i_input][i] = rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) rv = lm80_read_value(client, LM80_REG_IN_MIN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) data->in[i_min][i] = rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) rv = lm80_read_value(client, LM80_REG_IN_MAX(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) data->in[i_max][i] = rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) rv = lm80_read_value(client, LM80_REG_FAN1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) data->fan[f_input][0] = rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) rv = lm80_read_value(client, LM80_REG_FAN_MIN(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) data->fan[f_min][0] = rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) rv = lm80_read_value(client, LM80_REG_FAN2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) data->fan[f_input][1] = rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) rv = lm80_read_value(client, LM80_REG_FAN_MIN(2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) data->fan[f_min][1] = rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) prev_rv = rv = lm80_read_value(client, LM80_REG_TEMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) rv = lm80_read_value(client, LM80_REG_RES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) data->temp[t_input] = (prev_rv << 8) | (rv & 0xf0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) for (i = t_input + 1; i < t_num_temp; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) rv = lm80_read_value(client, temp_regs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) data->temp[i] = rv << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) rv = lm80_read_value(client, LM80_REG_FANDIV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) data->fan_div[0] = (rv >> 2) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) data->fan_div[1] = (rv >> 4) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) prev_rv = rv = lm80_read_value(client, LM80_REG_ALARM1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) rv = lm80_read_value(client, LM80_REG_ALARM2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) data->alarms = prev_rv + (rv << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) data->last_updated = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) data->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) data->error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) abort:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ret = ERR_PTR(rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) data->valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) data->error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * Sysfs stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static ssize_t in_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct lm80_data *data = lm80_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) int index = to_sensor_dev_attr_2(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) int nr = to_sensor_dev_attr_2(attr)->nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr][index]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static ssize_t in_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct lm80_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) int index = to_sensor_dev_attr_2(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) int nr = to_sensor_dev_attr_2(attr)->nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) int err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) reg = nr == i_min ? LM80_REG_IN_MIN(index) : LM80_REG_IN_MAX(index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) data->in[nr][index] = IN_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) lm80_write_value(client, reg, data->in[nr][index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return count;
^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) static ssize_t fan_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int index = to_sensor_dev_attr_2(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int nr = to_sensor_dev_attr_2(attr)->nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct lm80_data *data = lm80_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr][index],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) DIV_FROM_REG(data->fan_div[index])));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct lm80_data *data = lm80_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static ssize_t fan_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int index = to_sensor_dev_attr_2(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) int nr = to_sensor_dev_attr_2(attr)->nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct lm80_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) int err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) data->fan[nr][index] = FAN_TO_REG(val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) DIV_FROM_REG(data->fan_div[index]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) lm80_write_value(client, LM80_REG_FAN_MIN(index + 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) data->fan[nr][index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * Note: we save and restore the fan minimum here, because its value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * determined in part by the fan divisor. This follows the principle of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * least surprise; the user doesn't expect the fan minimum to change just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * because the divisor changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static ssize_t fan_div_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct lm80_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) unsigned long min, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) rv = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) /* Save fan_min */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) min = FAN_FROM_REG(data->fan[f_min][nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) DIV_FROM_REG(data->fan_div[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) switch (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) data->fan_div[nr] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) data->fan_div[nr] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) data->fan_div[nr] = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) data->fan_div[nr] = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) rv = lm80_read_value(client, LM80_REG_FANDIV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) reg = (rv & ~(3 << (2 * (nr + 1))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) | (data->fan_div[nr] << (2 * (nr + 1)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) lm80_write_value(client, LM80_REG_FANDIV, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /* Restore fan_min */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) data->fan[f_min][nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) data->fan[f_min][nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static ssize_t temp_show(struct device *dev, struct device_attribute *devattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct lm80_data *data = lm80_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static ssize_t temp_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct device_attribute *devattr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct lm80_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) int err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) data->temp[nr] = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) lm80_write_value(client, temp_regs[nr], data->temp[nr] >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct lm80_data *data = lm80_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return sprintf(buf, "%u\n", data->alarms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) int bitnr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct lm80_data *data = lm80_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) static SENSOR_DEVICE_ATTR_2_RW(in0_min, in, i_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static SENSOR_DEVICE_ATTR_2_RW(in1_min, in, i_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static SENSOR_DEVICE_ATTR_2_RW(in2_min, in, i_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) static SENSOR_DEVICE_ATTR_2_RW(in3_min, in, i_min, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) static SENSOR_DEVICE_ATTR_2_RW(in4_min, in, i_min, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static SENSOR_DEVICE_ATTR_2_RW(in5_min, in, i_min, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static SENSOR_DEVICE_ATTR_2_RW(in6_min, in, i_min, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static SENSOR_DEVICE_ATTR_2_RW(in0_max, in, i_max, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static SENSOR_DEVICE_ATTR_2_RW(in1_max, in, i_max, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static SENSOR_DEVICE_ATTR_2_RW(in2_max, in, i_max, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static SENSOR_DEVICE_ATTR_2_RW(in3_max, in, i_max, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static SENSOR_DEVICE_ATTR_2_RW(in4_max, in, i_max, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static SENSOR_DEVICE_ATTR_2_RW(in5_max, in, i_max, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static SENSOR_DEVICE_ATTR_2_RW(in6_max, in, i_max, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static SENSOR_DEVICE_ATTR_2_RO(in0_input, in, i_input, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static SENSOR_DEVICE_ATTR_2_RO(in1_input, in, i_input, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) static SENSOR_DEVICE_ATTR_2_RO(in2_input, in, i_input, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static SENSOR_DEVICE_ATTR_2_RO(in3_input, in, i_input, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static SENSOR_DEVICE_ATTR_2_RO(in4_input, in, i_input, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static SENSOR_DEVICE_ATTR_2_RO(in5_input, in, i_input, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static SENSOR_DEVICE_ATTR_2_RO(in6_input, in, i_input, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static SENSOR_DEVICE_ATTR_2_RW(fan1_min, fan, f_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static SENSOR_DEVICE_ATTR_2_RW(fan2_min, fan, f_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static SENSOR_DEVICE_ATTR_2_RO(fan1_input, fan, f_input, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static SENSOR_DEVICE_ATTR_2_RO(fan2_input, fan, f_input, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, t_input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, t_hot_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, temp, t_hot_hyst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static SENSOR_DEVICE_ATTR_RW(temp1_crit, temp, t_os_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static SENSOR_DEVICE_ATTR_RW(temp1_crit_hyst, temp, t_os_hyst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) static DEVICE_ATTR_RO(alarms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, alarm, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * Real code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static struct attribute *lm80_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) &sensor_dev_attr_in0_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) &sensor_dev_attr_in1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) &sensor_dev_attr_in2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) &sensor_dev_attr_in3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) &sensor_dev_attr_in4_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) &sensor_dev_attr_in5_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) &sensor_dev_attr_in6_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) &sensor_dev_attr_in0_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) &sensor_dev_attr_in1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) &sensor_dev_attr_in2_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) &sensor_dev_attr_in3_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) &sensor_dev_attr_in4_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) &sensor_dev_attr_in5_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) &sensor_dev_attr_in6_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) &sensor_dev_attr_in0_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) &sensor_dev_attr_in1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) &sensor_dev_attr_in2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) &sensor_dev_attr_in3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) &sensor_dev_attr_in4_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) &sensor_dev_attr_in5_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) &sensor_dev_attr_in6_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) &sensor_dev_attr_fan1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) &sensor_dev_attr_fan2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) &sensor_dev_attr_fan1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) &sensor_dev_attr_fan2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) &sensor_dev_attr_fan1_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) &sensor_dev_attr_fan2_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) &sensor_dev_attr_temp1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) &sensor_dev_attr_temp1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) &sensor_dev_attr_temp1_crit.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) &dev_attr_alarms.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) &sensor_dev_attr_in0_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) &sensor_dev_attr_in1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) &sensor_dev_attr_in2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) &sensor_dev_attr_in3_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) &sensor_dev_attr_in4_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) &sensor_dev_attr_in5_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) &sensor_dev_attr_in6_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) &sensor_dev_attr_fan1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) &sensor_dev_attr_fan2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) ATTRIBUTE_GROUPS(lm80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) /* Return 0 if detection is successful, -ENODEV otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct i2c_adapter *adapter = client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) int i, cur, man_id, dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) const char *name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) /* First check for unused bits, common to both chip types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if ((lm80_read_value(client, LM80_REG_ALARM2) & 0xc0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) || (lm80_read_value(client, LM80_REG_CONFIG) & 0x80))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) * The LM96080 has manufacturer and stepping/die rev registers so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * can just check that. The LM80 does not have such registers so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * have to use a more expensive trick.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) man_id = lm80_read_value(client, LM96080_REG_MAN_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) dev_id = lm80_read_value(client, LM96080_REG_DEV_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (man_id == 0x01 && dev_id == 0x08) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) /* Check more unused bits for confirmation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (lm80_read_value(client, LM96080_REG_CONV_RATE) & 0xfe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) name = "lm96080";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) /* Check 6-bit addressing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) for (i = 0x2a; i <= 0x3d; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) cur = i2c_smbus_read_byte_data(client, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if ((i2c_smbus_read_byte_data(client, i + 0x40) != cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) || (i2c_smbus_read_byte_data(client, i + 0x80) != cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) || (i2c_smbus_read_byte_data(client, i + 0xc0) != cur))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) return -ENODEV;
^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) name = "lm80";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) strlcpy(info->type, name, I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) static int lm80_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) struct lm80_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) data = devm_kzalloc(dev, sizeof(struct lm80_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) /* Initialize the LM80 chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) lm80_init_client(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /* A few vars need to be filled upon startup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) data->fan[f_min][0] = lm80_read_value(client, LM80_REG_FAN_MIN(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) data->fan[f_min][1] = lm80_read_value(client, LM80_REG_FAN_MIN(2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) data, lm80_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) return PTR_ERR_OR_ZERO(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) * Driver data (common to all clients)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) static const struct i2c_device_id lm80_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) { "lm80", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) { "lm96080", 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) MODULE_DEVICE_TABLE(i2c, lm80_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) static struct i2c_driver lm80_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) .class = I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) .name = "lm80",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) .probe_new = lm80_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) .id_table = lm80_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) .detect = lm80_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) .address_list = normal_i2c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) module_i2c_driver(lm80_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) "Philip Edelbrock <phil@netroedge.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) MODULE_DESCRIPTION("LM80 driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) MODULE_LICENSE("GPL");