2019-05-20 10:19:02 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
2012-01-15 01:20:00 +04:00
|
|
|
* asb100.c - Part of lm_sensors, Linux kernel modules for hardware
|
|
|
|
* monitoring
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Mark M. Hoffman <mhoffman@lightlink.com>
|
|
|
|
*
|
|
|
|
* (derived from w83781d.c)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 - 2003 Frodo Looijaard <frodol@dds.nl>,
|
|
|
|
* Philip Edelbrock <phil@netroedge.com>, and
|
|
|
|
* Mark Studebaker <mdsxyz123@yahoo.com>
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
2012-01-15 01:20:00 +04:00
|
|
|
* This driver supports the hardware sensor chips: Asus ASB100 and
|
|
|
|
* ASB100-A "BACH".
|
|
|
|
*
|
|
|
|
* ASB100-A supports pwm1, while plain ASB100 does not. There is no known
|
|
|
|
* way for the driver to tell which one is there.
|
|
|
|
*
|
2012-11-06 00:54:40 +04:00
|
|
|
* Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
|
2012-01-15 01:20:00 +04:00
|
|
|
* asb100 7 3 1 4 0x31 0x0694 yes no
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-10-20 10:51:29 +04:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/i2c.h>
|
2005-07-16 05:39:18 +04:00
|
|
|
#include <linux/hwmon.h>
|
2008-01-04 01:21:07 +03:00
|
|
|
#include <linux/hwmon-sysfs.h>
|
2005-07-31 23:52:01 +04:00
|
|
|
#include <linux/hwmon-vid.h>
|
2005-07-16 05:39:18 +04:00
|
|
|
#include <linux/err.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/init.h>
|
2005-05-16 20:12:18 +04:00
|
|
|
#include <linux/jiffies.h>
|
2006-01-19 01:19:26 +03:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include "lm75.h"
|
|
|
|
|
|
|
|
/* I2C addresses to scan */
|
2008-02-18 06:28:03 +03:00
|
|
|
static const unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-01-07 18:37:32 +03:00
|
|
|
static unsigned short force_subclients[4];
|
|
|
|
module_param_array(force_subclients, short, NULL, 0);
|
2013-01-10 22:01:24 +04:00
|
|
|
MODULE_PARM_DESC(force_subclients,
|
|
|
|
"List of subclient addresses: {bus, clientaddr, subclientaddr1, subclientaddr2}");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Voltage IN registers 0-6 */
|
|
|
|
#define ASB100_REG_IN(nr) (0x20 + (nr))
|
|
|
|
#define ASB100_REG_IN_MAX(nr) (0x2b + (nr * 2))
|
|
|
|
#define ASB100_REG_IN_MIN(nr) (0x2c + (nr * 2))
|
|
|
|
|
|
|
|
/* FAN IN registers 1-3 */
|
|
|
|
#define ASB100_REG_FAN(nr) (0x28 + (nr))
|
|
|
|
#define ASB100_REG_FAN_MIN(nr) (0x3b + (nr))
|
|
|
|
|
|
|
|
/* TEMPERATURE registers 1-4 */
|
|
|
|
static const u16 asb100_reg_temp[] = {0, 0x27, 0x150, 0x250, 0x17};
|
|
|
|
static const u16 asb100_reg_temp_max[] = {0, 0x39, 0x155, 0x255, 0x18};
|
|
|
|
static const u16 asb100_reg_temp_hyst[] = {0, 0x3a, 0x153, 0x253, 0x19};
|
|
|
|
|
|
|
|
#define ASB100_REG_TEMP(nr) (asb100_reg_temp[nr])
|
|
|
|
#define ASB100_REG_TEMP_MAX(nr) (asb100_reg_temp_max[nr])
|
|
|
|
#define ASB100_REG_TEMP_HYST(nr) (asb100_reg_temp_hyst[nr])
|
|
|
|
|
|
|
|
#define ASB100_REG_TEMP2_CONFIG 0x0152
|
|
|
|
#define ASB100_REG_TEMP3_CONFIG 0x0252
|
|
|
|
|
|
|
|
|
|
|
|
#define ASB100_REG_CONFIG 0x40
|
|
|
|
#define ASB100_REG_ALARM1 0x41
|
|
|
|
#define ASB100_REG_ALARM2 0x42
|
|
|
|
#define ASB100_REG_SMIM1 0x43
|
|
|
|
#define ASB100_REG_SMIM2 0x44
|
|
|
|
#define ASB100_REG_VID_FANDIV 0x47
|
|
|
|
#define ASB100_REG_I2C_ADDR 0x48
|
|
|
|
#define ASB100_REG_CHIPID 0x49
|
|
|
|
#define ASB100_REG_I2C_SUBADDR 0x4a
|
|
|
|
#define ASB100_REG_PIN 0x4b
|
|
|
|
#define ASB100_REG_IRQ 0x4c
|
|
|
|
#define ASB100_REG_BANK 0x4e
|
|
|
|
#define ASB100_REG_CHIPMAN 0x4f
|
|
|
|
|
|
|
|
#define ASB100_REG_WCHIPID 0x58
|
|
|
|
|
|
|
|
/* bit 7 -> enable, bits 0-3 -> duty cycle */
|
|
|
|
#define ASB100_REG_PWM1 0x59
|
|
|
|
|
2012-01-15 01:20:00 +04:00
|
|
|
/*
|
|
|
|
* CONVERSIONS
|
|
|
|
* Rounding and limit checking is only done on the TO_REG variants.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* These constants are a guess, consistent w/ w83781d */
|
2012-01-15 01:20:00 +04:00
|
|
|
#define ASB100_IN_MIN 0
|
|
|
|
#define ASB100_IN_MAX 4080
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-01-15 01:20:00 +04:00
|
|
|
/*
|
|
|
|
* IN: 1/1000 V (0V to 4.08V)
|
|
|
|
* REG: 16mV/bit
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
static u8 IN_TO_REG(unsigned val)
|
|
|
|
{
|
2013-01-09 20:09:34 +04:00
|
|
|
unsigned nval = clamp_val(val, ASB100_IN_MIN, ASB100_IN_MAX);
|
2005-04-17 02:20:36 +04:00
|
|
|
return (nval + 8) / 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned IN_FROM_REG(u8 reg)
|
|
|
|
{
|
|
|
|
return reg * 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 FAN_TO_REG(long rpm, int div)
|
|
|
|
{
|
|
|
|
if (rpm == -1)
|
|
|
|
return 0;
|
|
|
|
if (rpm == 0)
|
|
|
|
return 255;
|
2013-01-09 20:09:34 +04:00
|
|
|
rpm = clamp_val(rpm, 1, 1000000);
|
|
|
|
return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int FAN_FROM_REG(u8 val, int div)
|
|
|
|
{
|
2012-01-15 01:20:00 +04:00
|
|
|
return val == 0 ? -1 : val == 255 ? 0 : 1350000 / (val * div);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* These constants are a guess, consistent w/ w83781d */
|
2012-01-15 01:20:00 +04:00
|
|
|
#define ASB100_TEMP_MIN -128000
|
|
|
|
#define ASB100_TEMP_MAX 127000
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-01-15 01:20:00 +04:00
|
|
|
/*
|
|
|
|
* TEMP: 0.001C/bit (-128C to +127C)
|
|
|
|
* REG: 1C/bit, two's complement
|
|
|
|
*/
|
2007-08-16 13:40:10 +04:00
|
|
|
static u8 TEMP_TO_REG(long temp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2013-01-09 20:09:34 +04:00
|
|
|
int ntemp = clamp_val(temp, ASB100_TEMP_MIN, ASB100_TEMP_MAX);
|
2012-01-15 01:20:00 +04:00
|
|
|
ntemp += (ntemp < 0 ? -500 : 500);
|
2005-04-17 02:20:36 +04:00
|
|
|
return (u8)(ntemp / 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int TEMP_FROM_REG(u8 reg)
|
|
|
|
{
|
|
|
|
return (s8)reg * 1000;
|
|
|
|
}
|
|
|
|
|
2012-01-15 01:20:00 +04:00
|
|
|
/*
|
|
|
|
* PWM: 0 - 255 per sensors documentation
|
|
|
|
* REG: (6.25% duty cycle per bit)
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
static u8 ASB100_PWM_TO_REG(int pwm)
|
|
|
|
{
|
2013-01-09 20:09:34 +04:00
|
|
|
pwm = clamp_val(pwm, 0, 255);
|
2005-04-17 02:20:36 +04:00
|
|
|
return (u8)(pwm / 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ASB100_PWM_FROM_REG(u8 reg)
|
|
|
|
{
|
|
|
|
return reg * 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DIV_FROM_REG(val) (1 << (val))
|
|
|
|
|
2012-01-15 01:20:00 +04:00
|
|
|
/*
|
|
|
|
* FAN DIV: 1, 2, 4, or 8 (defaults to 2)
|
|
|
|
* REG: 0, 1, 2, or 3 (respectively) (defaults to 1)
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
static u8 DIV_TO_REG(long val)
|
|
|
|
{
|
2012-01-15 01:20:00 +04:00
|
|
|
return val == 8 ? 3 : val == 4 ? 2 : val == 1 ? 0 : 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2012-01-15 01:20:00 +04:00
|
|
|
/*
|
|
|
|
* For each registered client, we need to keep some data in memory. That
|
|
|
|
* data is pointed to by client->data. The structure itself is
|
|
|
|
* dynamically allocated, at the same time the client itself is allocated.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
struct asb100_data {
|
2007-08-21 00:46:20 +04:00
|
|
|
struct device *hwmon_dev;
|
2006-01-19 01:19:26 +03:00
|
|
|
struct mutex lock;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-01-19 01:19:26 +03:00
|
|
|
struct mutex update_lock;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned long last_updated; /* In jiffies */
|
|
|
|
|
|
|
|
/* array of 2 pointers to subclients */
|
|
|
|
struct i2c_client *lm75[2];
|
|
|
|
|
|
|
|
char valid; /* !=0 if following fields are valid */
|
|
|
|
u8 in[7]; /* Register value */
|
|
|
|
u8 in_max[7]; /* Register value */
|
|
|
|
u8 in_min[7]; /* Register value */
|
|
|
|
u8 fan[3]; /* Register value */
|
|
|
|
u8 fan_min[3]; /* Register value */
|
|
|
|
u16 temp[4]; /* Register value (0 and 3 are u8 only) */
|
|
|
|
u16 temp_max[4]; /* Register value (0 and 3 are u8 only) */
|
|
|
|
u16 temp_hyst[4]; /* Register value (0 and 3 are u8 only) */
|
|
|
|
u8 fan_div[3]; /* Register encoding, right justified */
|
|
|
|
u8 pwm; /* Register encoding */
|
|
|
|
u8 vid; /* Register encoding, combined */
|
|
|
|
u32 alarms; /* Register encoding, combined */
|
|
|
|
u8 vrm;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int asb100_read_value(struct i2c_client *client, u16 reg);
|
|
|
|
static void asb100_write_value(struct i2c_client *client, u16 reg, u16 val);
|
|
|
|
|
2020-08-13 19:02:22 +03:00
|
|
|
static int asb100_probe(struct i2c_client *client);
|
2009-12-14 23:17:23 +03:00
|
|
|
static int asb100_detect(struct i2c_client *client,
|
2008-07-16 21:30:11 +04:00
|
|
|
struct i2c_board_info *info);
|
|
|
|
static int asb100_remove(struct i2c_client *client);
|
2005-04-17 02:20:36 +04:00
|
|
|
static struct asb100_data *asb100_update_device(struct device *dev);
|
|
|
|
static void asb100_init_client(struct i2c_client *client);
|
|
|
|
|
2008-07-16 21:30:11 +04:00
|
|
|
static const struct i2c_device_id asb100_id[] = {
|
2009-12-14 23:17:26 +03:00
|
|
|
{ "asb100", 0 },
|
2008-07-16 21:30:11 +04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, asb100_id);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static struct i2c_driver asb100_driver = {
|
2008-07-16 21:30:11 +04:00
|
|
|
.class = I2C_CLASS_HWMON,
|
2005-11-26 22:37:41 +03:00
|
|
|
.driver = {
|
|
|
|
.name = "asb100",
|
|
|
|
},
|
2020-08-13 19:02:22 +03:00
|
|
|
.probe_new = asb100_probe,
|
2008-07-16 21:30:11 +04:00
|
|
|
.remove = asb100_remove,
|
|
|
|
.id_table = asb100_id,
|
|
|
|
.detect = asb100_detect,
|
2009-12-14 23:17:25 +03:00
|
|
|
.address_list = normal_i2c,
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 7 Voltages */
|
|
|
|
#define show_in_reg(reg) \
|
2008-01-04 01:21:07 +03:00
|
|
|
static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
|
|
|
|
char *buf) \
|
2005-04-17 02:20:36 +04:00
|
|
|
{ \
|
2008-01-04 01:21:07 +03:00
|
|
|
int nr = to_sensor_dev_attr(attr)->index; \
|
2005-04-17 02:20:36 +04:00
|
|
|
struct asb100_data *data = asb100_update_device(dev); \
|
|
|
|
return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
|
|
|
|
}
|
|
|
|
|
|
|
|
show_in_reg(in)
|
|
|
|
show_in_reg(in_min)
|
|
|
|
show_in_reg(in_max)
|
|
|
|
|
|
|
|
#define set_in_reg(REG, reg) \
|
2008-01-04 01:21:07 +03:00
|
|
|
static ssize_t set_in_##reg(struct device *dev, struct device_attribute *attr, \
|
|
|
|
const char *buf, size_t count) \
|
2005-04-17 02:20:36 +04:00
|
|
|
{ \
|
2008-01-04 01:21:07 +03:00
|
|
|
int nr = to_sensor_dev_attr(attr)->index; \
|
2005-04-17 02:20:36 +04:00
|
|
|
struct i2c_client *client = to_i2c_client(dev); \
|
|
|
|
struct asb100_data *data = i2c_get_clientdata(client); \
|
2012-01-15 01:20:00 +04:00
|
|
|
unsigned long val; \
|
|
|
|
int err = kstrtoul(buf, 10, &val); \
|
|
|
|
if (err) \
|
|
|
|
return err; \
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_lock(&data->update_lock); \
|
2005-04-17 02:20:36 +04:00
|
|
|
data->in_##reg[nr] = IN_TO_REG(val); \
|
|
|
|
asb100_write_value(client, ASB100_REG_IN_##REG(nr), \
|
|
|
|
data->in_##reg[nr]); \
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_unlock(&data->update_lock); \
|
2005-04-17 02:20:36 +04:00
|
|
|
return count; \
|
|
|
|
}
|
|
|
|
|
|
|
|
set_in_reg(MIN, min)
|
|
|
|
set_in_reg(MAX, max)
|
|
|
|
|
|
|
|
#define sysfs_in(offset) \
|
2008-01-04 01:21:07 +03:00
|
|
|
static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
|
|
|
|
show_in, NULL, offset); \
|
|
|
|
static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
|
|
|
|
show_in_min, set_in_min, offset); \
|
|
|
|
static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
|
|
|
|
show_in_max, set_in_max, offset)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
sysfs_in(0);
|
|
|
|
sysfs_in(1);
|
|
|
|
sysfs_in(2);
|
|
|
|
sysfs_in(3);
|
|
|
|
sysfs_in(4);
|
|
|
|
sysfs_in(5);
|
|
|
|
sysfs_in(6);
|
|
|
|
|
|
|
|
/* 3 Fans */
|
2008-01-04 01:21:07 +03:00
|
|
|
static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-01-04 01:21:07 +03:00
|
|
|
int nr = to_sensor_dev_attr(attr)->index;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct asb100_data *data = asb100_update_device(dev);
|
|
|
|
return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
|
|
|
|
DIV_FROM_REG(data->fan_div[nr])));
|
|
|
|
}
|
|
|
|
|
2008-01-04 01:21:07 +03:00
|
|
|
static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-01-04 01:21:07 +03:00
|
|
|
int nr = to_sensor_dev_attr(attr)->index;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct asb100_data *data = asb100_update_device(dev);
|
|
|
|
return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
|
|
|
|
DIV_FROM_REG(data->fan_div[nr])));
|
|
|
|
}
|
|
|
|
|
2008-01-04 01:21:07 +03:00
|
|
|
static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-01-04 01:21:07 +03:00
|
|
|
int nr = to_sensor_dev_attr(attr)->index;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct asb100_data *data = asb100_update_device(dev);
|
|
|
|
return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
|
|
|
|
}
|
|
|
|
|
2008-01-04 01:21:07 +03:00
|
|
|
static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-01-04 01:21:07 +03:00
|
|
|
int nr = to_sensor_dev_attr(attr)->index;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
|
|
struct asb100_data *data = i2c_get_clientdata(client);
|
2012-01-15 01:20:00 +04:00
|
|
|
unsigned long val;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = kstrtoul(buf, 10, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_lock(&data->update_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
|
|
|
|
asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]);
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_unlock(&data->update_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2012-01-15 01:20:00 +04:00
|
|
|
/*
|
|
|
|
* Note: we save and restore the fan minimum here, because its value is
|
|
|
|
* determined in part by the fan divisor. This follows the principle of
|
|
|
|
* least surprise; the user doesn't expect the fan minimum to change just
|
|
|
|
* because the divisor changed.
|
|
|
|
*/
|
2008-01-04 01:21:07 +03:00
|
|
|
static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-01-04 01:21:07 +03:00
|
|
|
int nr = to_sensor_dev_attr(attr)->index;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
|
|
struct asb100_data *data = i2c_get_clientdata(client);
|
|
|
|
unsigned long min;
|
|
|
|
int reg;
|
2012-01-15 01:20:00 +04:00
|
|
|
unsigned long val;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = kstrtoul(buf, 10, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2008-01-04 01:15:49 +03:00
|
|
|
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_lock(&data->update_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
min = FAN_FROM_REG(data->fan_min[nr],
|
|
|
|
DIV_FROM_REG(data->fan_div[nr]));
|
|
|
|
data->fan_div[nr] = DIV_TO_REG(val);
|
|
|
|
|
2008-01-04 01:15:49 +03:00
|
|
|
switch (nr) {
|
2005-04-17 02:20:36 +04:00
|
|
|
case 0: /* fan 1 */
|
|
|
|
reg = asb100_read_value(client, ASB100_REG_VID_FANDIV);
|
|
|
|
reg = (reg & 0xcf) | (data->fan_div[0] << 4);
|
|
|
|
asb100_write_value(client, ASB100_REG_VID_FANDIV, reg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* fan 2 */
|
|
|
|
reg = asb100_read_value(client, ASB100_REG_VID_FANDIV);
|
|
|
|
reg = (reg & 0x3f) | (data->fan_div[1] << 6);
|
|
|
|
asb100_write_value(client, ASB100_REG_VID_FANDIV, reg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* fan 3 */
|
|
|
|
reg = asb100_read_value(client, ASB100_REG_PIN);
|
|
|
|
reg = (reg & 0x3f) | (data->fan_div[2] << 6);
|
|
|
|
asb100_write_value(client, ASB100_REG_PIN, reg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->fan_min[nr] =
|
|
|
|
FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
|
|
|
|
asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]);
|
|
|
|
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_unlock(&data->update_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define sysfs_fan(offset) \
|
2008-01-04 01:21:07 +03:00
|
|
|
static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
|
|
|
|
show_fan, NULL, offset - 1); \
|
|
|
|
static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
|
|
|
|
show_fan_min, set_fan_min, offset - 1); \
|
|
|
|
static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
|
|
|
|
show_fan_div, set_fan_div, offset - 1)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
sysfs_fan(1);
|
|
|
|
sysfs_fan(2);
|
|
|
|
sysfs_fan(3);
|
|
|
|
|
|
|
|
/* 4 Temp. Sensors */
|
|
|
|
static int sprintf_temp_from_reg(u16 reg, char *buf, int nr)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (nr) {
|
|
|
|
case 1: case 2:
|
|
|
|
ret = sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(reg));
|
|
|
|
break;
|
|
|
|
case 0: case 3: default:
|
|
|
|
ret = sprintf(buf, "%d\n", TEMP_FROM_REG(reg));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2008-01-04 01:15:49 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#define show_temp_reg(reg) \
|
2008-01-04 01:21:07 +03:00
|
|
|
static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
|
|
|
|
char *buf) \
|
2005-04-17 02:20:36 +04:00
|
|
|
{ \
|
2008-01-04 01:21:07 +03:00
|
|
|
int nr = to_sensor_dev_attr(attr)->index; \
|
2005-04-17 02:20:36 +04:00
|
|
|
struct asb100_data *data = asb100_update_device(dev); \
|
|
|
|
return sprintf_temp_from_reg(data->reg[nr], buf, nr); \
|
|
|
|
}
|
|
|
|
|
|
|
|
show_temp_reg(temp);
|
|
|
|
show_temp_reg(temp_max);
|
|
|
|
show_temp_reg(temp_hyst);
|
|
|
|
|
|
|
|
#define set_temp_reg(REG, reg) \
|
2008-01-04 01:21:07 +03:00
|
|
|
static ssize_t set_##reg(struct device *dev, struct device_attribute *attr, \
|
|
|
|
const char *buf, size_t count) \
|
2005-04-17 02:20:36 +04:00
|
|
|
{ \
|
2008-01-04 01:21:07 +03:00
|
|
|
int nr = to_sensor_dev_attr(attr)->index; \
|
2005-04-17 02:20:36 +04:00
|
|
|
struct i2c_client *client = to_i2c_client(dev); \
|
|
|
|
struct asb100_data *data = i2c_get_clientdata(client); \
|
2012-01-15 01:20:00 +04:00
|
|
|
long val; \
|
|
|
|
int err = kstrtol(buf, 10, &val); \
|
|
|
|
if (err) \
|
|
|
|
return err; \
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_lock(&data->update_lock); \
|
2005-04-17 02:20:36 +04:00
|
|
|
switch (nr) { \
|
|
|
|
case 1: case 2: \
|
|
|
|
data->reg[nr] = LM75_TEMP_TO_REG(val); \
|
|
|
|
break; \
|
|
|
|
case 0: case 3: default: \
|
|
|
|
data->reg[nr] = TEMP_TO_REG(val); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
asb100_write_value(client, ASB100_REG_TEMP_##REG(nr+1), \
|
|
|
|
data->reg[nr]); \
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_unlock(&data->update_lock); \
|
2005-04-17 02:20:36 +04:00
|
|
|
return count; \
|
|
|
|
}
|
|
|
|
|
|
|
|
set_temp_reg(MAX, temp_max);
|
|
|
|
set_temp_reg(HYST, temp_hyst);
|
|
|
|
|
|
|
|
#define sysfs_temp(num) \
|
2008-01-04 01:21:07 +03:00
|
|
|
static SENSOR_DEVICE_ATTR(temp##num##_input, S_IRUGO, \
|
|
|
|
show_temp, NULL, num - 1); \
|
|
|
|
static SENSOR_DEVICE_ATTR(temp##num##_max, S_IRUGO | S_IWUSR, \
|
|
|
|
show_temp_max, set_temp_max, num - 1); \
|
|
|
|
static SENSOR_DEVICE_ATTR(temp##num##_max_hyst, S_IRUGO | S_IWUSR, \
|
|
|
|
show_temp_hyst, set_temp_hyst, num - 1)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
sysfs_temp(1);
|
|
|
|
sysfs_temp(2);
|
|
|
|
sysfs_temp(3);
|
|
|
|
sysfs_temp(4);
|
|
|
|
|
|
|
|
/* VID */
|
2016-12-22 15:04:36 +03:00
|
|
|
static ssize_t cpu0_vid_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct asb100_data *data = asb100_update_device(dev);
|
|
|
|
return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
|
|
|
|
}
|
|
|
|
|
2016-12-22 15:04:36 +03:00
|
|
|
static DEVICE_ATTR_RO(cpu0_vid);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* VRM */
|
2016-12-22 15:04:36 +03:00
|
|
|
static ssize_t vrm_show(struct device *dev, struct device_attribute *attr,
|
2008-01-04 01:15:49 +03:00
|
|
|
char *buf)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2007-10-08 20:24:35 +04:00
|
|
|
struct asb100_data *data = dev_get_drvdata(dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
return sprintf(buf, "%d\n", data->vrm);
|
|
|
|
}
|
|
|
|
|
2016-12-22 15:04:36 +03:00
|
|
|
static ssize_t vrm_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2007-12-01 13:25:33 +03:00
|
|
|
struct asb100_data *data = dev_get_drvdata(dev);
|
2012-01-15 01:20:00 +04:00
|
|
|
unsigned long val;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = kstrtoul(buf, 10, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2014-08-06 04:21:49 +04:00
|
|
|
|
|
|
|
if (val > 255)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-01-15 01:20:00 +04:00
|
|
|
data->vrm = val;
|
2005-04-17 02:20:36 +04:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Alarms */
|
2016-12-22 15:04:36 +03:00
|
|
|
static DEVICE_ATTR_RW(vrm);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2016-12-22 15:04:36 +03:00
|
|
|
static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
|
2008-01-04 01:15:49 +03:00
|
|
|
char *buf)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct asb100_data *data = asb100_update_device(dev);
|
2005-05-16 20:52:38 +04:00
|
|
|
return sprintf(buf, "%u\n", data->alarms);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2016-12-22 15:04:36 +03:00
|
|
|
static DEVICE_ATTR_RO(alarms);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-01-04 01:24:24 +03:00
|
|
|
static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
int bitnr = to_sensor_dev_attr(attr)->index;
|
|
|
|
struct asb100_data *data = asb100_update_device(dev);
|
|
|
|
return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
|
|
|
|
}
|
|
|
|
static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
|
|
|
|
static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
|
|
|
|
static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
|
|
|
|
static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
|
|
|
|
static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
|
|
|
|
static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
|
|
|
|
static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
|
|
|
|
static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11);
|
|
|
|
static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
|
|
|
|
static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
|
|
|
|
static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* 1 PWM */
|
2016-12-22 15:04:36 +03:00
|
|
|
static ssize_t pwm1_show(struct device *dev, struct device_attribute *attr,
|
2008-01-04 01:15:49 +03:00
|
|
|
char *buf)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct asb100_data *data = asb100_update_device(dev);
|
|
|
|
return sprintf(buf, "%d\n", ASB100_PWM_FROM_REG(data->pwm & 0x0f));
|
|
|
|
}
|
|
|
|
|
2016-12-22 15:04:36 +03:00
|
|
|
static ssize_t pwm1_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
|
|
struct asb100_data *data = i2c_get_clientdata(client);
|
2012-01-15 01:20:00 +04:00
|
|
|
unsigned long val;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = kstrtoul(buf, 10, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_lock(&data->update_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
data->pwm &= 0x80; /* keep the enable bit */
|
|
|
|
data->pwm |= (0x0f & ASB100_PWM_TO_REG(val));
|
|
|
|
asb100_write_value(client, ASB100_REG_PWM1, data->pwm);
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_unlock(&data->update_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2016-12-22 15:04:36 +03:00
|
|
|
static ssize_t pwm1_enable_show(struct device *dev,
|
2008-01-04 01:15:49 +03:00
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct asb100_data *data = asb100_update_device(dev);
|
|
|
|
return sprintf(buf, "%d\n", (data->pwm & 0x80) ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2016-12-22 15:04:36 +03:00
|
|
|
static ssize_t pwm1_enable_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
|
|
struct asb100_data *data = i2c_get_clientdata(client);
|
2012-01-15 01:20:00 +04:00
|
|
|
unsigned long val;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = kstrtoul(buf, 10, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_lock(&data->update_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
data->pwm &= 0x0f; /* keep the duty cycle bits */
|
|
|
|
data->pwm |= (val ? 0x80 : 0x00);
|
|
|
|
asb100_write_value(client, ASB100_REG_PWM1, data->pwm);
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_unlock(&data->update_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2016-12-22 15:04:36 +03:00
|
|
|
static DEVICE_ATTR_RW(pwm1);
|
|
|
|
static DEVICE_ATTR_RW(pwm1_enable);
|
2006-09-24 22:59:49 +04:00
|
|
|
|
|
|
|
static struct attribute *asb100_attributes[] = {
|
2008-01-04 01:21:07 +03:00
|
|
|
&sensor_dev_attr_in0_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in0_min.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in0_max.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in1_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in1_min.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in1_max.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in2_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in2_min.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in2_max.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in3_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in3_min.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in3_max.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in4_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in4_min.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in4_max.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in5_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in5_min.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in5_max.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in6_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in6_min.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in6_max.dev_attr.attr,
|
|
|
|
|
|
|
|
&sensor_dev_attr_fan1_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan1_min.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan1_div.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan2_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan2_min.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan2_div.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan3_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan3_min.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan3_div.dev_attr.attr,
|
|
|
|
|
|
|
|
&sensor_dev_attr_temp1_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp1_max.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp2_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp2_max.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp3_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp3_max.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp4_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp4_max.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
|
2006-09-24 22:59:49 +04:00
|
|
|
|
2008-01-04 01:24:24 +03:00
|
|
|
&sensor_dev_attr_in0_alarm.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in1_alarm.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in2_alarm.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in3_alarm.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_in4_alarm.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan1_alarm.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan2_alarm.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan3_alarm.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp1_alarm.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp2_alarm.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp3_alarm.dev_attr.attr,
|
|
|
|
|
2006-09-24 22:59:49 +04:00
|
|
|
&dev_attr_cpu0_vid.attr,
|
|
|
|
&dev_attr_vrm.attr,
|
|
|
|
&dev_attr_alarms.attr,
|
|
|
|
&dev_attr_pwm1.attr,
|
|
|
|
&dev_attr_pwm1_enable.attr,
|
|
|
|
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group asb100_group = {
|
|
|
|
.attrs = asb100_attributes,
|
|
|
|
};
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-07-16 21:30:11 +04:00
|
|
|
static int asb100_detect_subclients(struct i2c_client *client)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int i, id, err;
|
2008-07-16 21:30:11 +04:00
|
|
|
int address = client->addr;
|
|
|
|
unsigned short sc_addr[2];
|
2008-01-04 01:15:49 +03:00
|
|
|
struct asb100_data *data = i2c_get_clientdata(client);
|
2008-07-16 21:30:11 +04:00
|
|
|
struct i2c_adapter *adapter = client->adapter;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
id = i2c_adapter_id(adapter);
|
|
|
|
|
|
|
|
if (force_subclients[0] == id && force_subclients[1] == address) {
|
|
|
|
for (i = 2; i <= 3; i++) {
|
|
|
|
if (force_subclients[i] < 0x48 ||
|
|
|
|
force_subclients[i] > 0x4f) {
|
2013-01-10 22:01:24 +04:00
|
|
|
dev_err(&client->dev,
|
|
|
|
"invalid subclient address %d; must be 0x48-0x4f\n",
|
2005-04-17 02:20:36 +04:00
|
|
|
force_subclients[i]);
|
|
|
|
err = -ENODEV;
|
|
|
|
goto ERROR_SC_2;
|
|
|
|
}
|
|
|
|
}
|
2008-01-04 01:15:49 +03:00
|
|
|
asb100_write_value(client, ASB100_REG_I2C_SUBADDR,
|
2005-04-17 02:20:36 +04:00
|
|
|
(force_subclients[2] & 0x07) |
|
2008-01-04 01:15:49 +03:00
|
|
|
((force_subclients[3] & 0x07) << 4));
|
2008-07-16 21:30:11 +04:00
|
|
|
sc_addr[0] = force_subclients[2];
|
|
|
|
sc_addr[1] = force_subclients[3];
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
2008-01-04 01:15:49 +03:00
|
|
|
int val = asb100_read_value(client, ASB100_REG_I2C_SUBADDR);
|
2008-07-16 21:30:11 +04:00
|
|
|
sc_addr[0] = 0x48 + (val & 0x07);
|
|
|
|
sc_addr[1] = 0x48 + ((val >> 4) & 0x07);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2008-07-16 21:30:11 +04:00
|
|
|
if (sc_addr[0] == sc_addr[1]) {
|
2013-01-10 22:01:24 +04:00
|
|
|
dev_err(&client->dev,
|
|
|
|
"duplicate addresses 0x%x for subclients\n",
|
|
|
|
sc_addr[0]);
|
2005-04-17 02:20:36 +04:00
|
|
|
err = -ENODEV;
|
|
|
|
goto ERROR_SC_2;
|
|
|
|
}
|
|
|
|
|
2019-07-22 20:26:08 +03:00
|
|
|
data->lm75[0] = i2c_new_dummy_device(adapter, sc_addr[0]);
|
|
|
|
if (IS_ERR(data->lm75[0])) {
|
2013-01-10 22:01:24 +04:00
|
|
|
dev_err(&client->dev,
|
|
|
|
"subclient %d registration at address 0x%x failed.\n",
|
|
|
|
1, sc_addr[0]);
|
2019-07-22 20:26:08 +03:00
|
|
|
err = PTR_ERR(data->lm75[0]);
|
2005-04-17 02:20:36 +04:00
|
|
|
goto ERROR_SC_2;
|
|
|
|
}
|
|
|
|
|
2019-07-22 20:26:08 +03:00
|
|
|
data->lm75[1] = i2c_new_dummy_device(adapter, sc_addr[1]);
|
|
|
|
if (IS_ERR(data->lm75[1])) {
|
2013-01-10 22:01:24 +04:00
|
|
|
dev_err(&client->dev,
|
|
|
|
"subclient %d registration at address 0x%x failed.\n",
|
|
|
|
2, sc_addr[1]);
|
2019-07-22 20:26:08 +03:00
|
|
|
err = PTR_ERR(data->lm75[1]);
|
2005-04-17 02:20:36 +04:00
|
|
|
goto ERROR_SC_3;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Undo inits in case of errors */
|
|
|
|
ERROR_SC_3:
|
2008-07-16 21:30:11 +04:00
|
|
|
i2c_unregister_device(data->lm75[0]);
|
2005-04-17 02:20:36 +04:00
|
|
|
ERROR_SC_2:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-07-16 21:30:11 +04:00
|
|
|
/* Return 0 if detection is successful, -ENODEV otherwise */
|
2009-12-14 23:17:23 +03:00
|
|
|
static int asb100_detect(struct i2c_client *client,
|
2008-07-16 21:30:11 +04:00
|
|
|
struct i2c_board_info *info)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-07-16 21:30:11 +04:00
|
|
|
struct i2c_adapter *adapter = client->adapter;
|
2009-12-09 22:35:57 +03:00
|
|
|
int val1, val2;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
|
2010-10-20 10:51:29 +04:00
|
|
|
pr_debug("detect failed, smbus byte data not supported!\n");
|
2008-07-16 21:30:11 +04:00
|
|
|
return -ENODEV;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2009-12-09 22:35:57 +03:00
|
|
|
val1 = i2c_smbus_read_byte_data(client, ASB100_REG_BANK);
|
|
|
|
val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-12-09 22:35:57 +03:00
|
|
|
/* If we're in bank 0 */
|
|
|
|
if ((!(val1 & 0x07)) &&
|
|
|
|
/* Check for ASB100 ID (low byte) */
|
|
|
|
(((!(val1 & 0x80)) && (val2 != 0x94)) ||
|
|
|
|
/* Check for ASB100 ID (high byte ) */
|
|
|
|
((val1 & 0x80) && (val2 != 0x06)))) {
|
2010-10-20 10:51:29 +04:00
|
|
|
pr_debug("detect failed, bad chip id 0x%02x!\n", val2);
|
2009-12-09 22:35:57 +03:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-12-09 22:35:57 +03:00
|
|
|
/* Put it now into bank 0 and Vendor ID High Byte */
|
2008-07-16 21:30:11 +04:00
|
|
|
i2c_smbus_write_byte_data(client, ASB100_REG_BANK,
|
|
|
|
(i2c_smbus_read_byte_data(client, ASB100_REG_BANK) & 0x78)
|
|
|
|
| 0x80);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Determine the chip type. */
|
2009-12-09 22:35:57 +03:00
|
|
|
val1 = i2c_smbus_read_byte_data(client, ASB100_REG_WCHIPID);
|
|
|
|
val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN);
|
|
|
|
|
|
|
|
if (val1 != 0x31 || val2 != 0x06)
|
|
|
|
return -ENODEV;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-07-16 21:30:11 +04:00
|
|
|
strlcpy(info->type, "asb100", I2C_NAME_SIZE);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-07-16 21:30:11 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-13 19:02:22 +03:00
|
|
|
static int asb100_probe(struct i2c_client *client)
|
2008-07-16 21:30:11 +04:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct asb100_data *data;
|
|
|
|
|
2012-06-02 20:58:02 +04:00
|
|
|
data = devm_kzalloc(&client->dev, sizeof(struct asb100_data),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
2008-07-16 21:30:11 +04:00
|
|
|
|
|
|
|
i2c_set_clientdata(client, data);
|
|
|
|
mutex_init(&data->lock);
|
|
|
|
mutex_init(&data->update_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Attach secondary lm75 clients */
|
2008-07-16 21:30:11 +04:00
|
|
|
err = asb100_detect_subclients(client);
|
|
|
|
if (err)
|
2012-06-02 20:58:02 +04:00
|
|
|
return err;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Initialize the chip */
|
2008-01-04 01:15:49 +03:00
|
|
|
asb100_init_client(client);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* A few vars need to be filled upon startup */
|
2008-01-04 01:15:49 +03:00
|
|
|
data->fan_min[0] = asb100_read_value(client, ASB100_REG_FAN_MIN(0));
|
|
|
|
data->fan_min[1] = asb100_read_value(client, ASB100_REG_FAN_MIN(1));
|
|
|
|
data->fan_min[2] = asb100_read_value(client, ASB100_REG_FAN_MIN(2));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Register sysfs hooks */
|
2012-01-15 01:20:00 +04:00
|
|
|
err = sysfs_create_group(&client->dev.kobj, &asb100_group);
|
|
|
|
if (err)
|
2006-09-24 22:59:49 +04:00
|
|
|
goto ERROR3;
|
|
|
|
|
2008-01-04 01:15:49 +03:00
|
|
|
data->hwmon_dev = hwmon_device_register(&client->dev);
|
2007-08-21 00:46:20 +04:00
|
|
|
if (IS_ERR(data->hwmon_dev)) {
|
|
|
|
err = PTR_ERR(data->hwmon_dev);
|
2006-09-24 22:59:49 +04:00
|
|
|
goto ERROR4;
|
2005-07-16 05:39:18 +04:00
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
|
2006-09-24 22:59:49 +04:00
|
|
|
ERROR4:
|
2008-01-04 01:15:49 +03:00
|
|
|
sysfs_remove_group(&client->dev.kobj, &asb100_group);
|
2005-07-16 05:39:18 +04:00
|
|
|
ERROR3:
|
2008-07-16 21:30:11 +04:00
|
|
|
i2c_unregister_device(data->lm75[1]);
|
|
|
|
i2c_unregister_device(data->lm75[0]);
|
2005-04-17 02:20:36 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-07-16 21:30:11 +04:00
|
|
|
static int asb100_remove(struct i2c_client *client)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-16 05:39:18 +04:00
|
|
|
struct asb100_data *data = i2c_get_clientdata(client);
|
|
|
|
|
2008-07-16 21:30:11 +04:00
|
|
|
hwmon_device_unregister(data->hwmon_dev);
|
|
|
|
sysfs_remove_group(&client->dev.kobj, &asb100_group);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-07-16 21:30:11 +04:00
|
|
|
i2c_unregister_device(data->lm75[1]);
|
|
|
|
i2c_unregister_device(data->lm75[0]);
|
2005-07-16 05:39:18 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-15 01:20:00 +04:00
|
|
|
/*
|
|
|
|
* The SMBus locks itself, usually, but nothing may access the chip between
|
|
|
|
* bank switches.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
static int asb100_read_value(struct i2c_client *client, u16 reg)
|
|
|
|
{
|
|
|
|
struct asb100_data *data = i2c_get_clientdata(client);
|
|
|
|
struct i2c_client *cl;
|
|
|
|
int res, bank;
|
|
|
|
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_lock(&data->lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
bank = (reg >> 8) & 0x0f;
|
|
|
|
if (bank > 2)
|
|
|
|
/* switch banks */
|
|
|
|
i2c_smbus_write_byte_data(client, ASB100_REG_BANK, bank);
|
|
|
|
|
|
|
|
if (bank == 0 || bank > 2) {
|
|
|
|
res = i2c_smbus_read_byte_data(client, reg & 0xff);
|
|
|
|
} else {
|
|
|
|
/* switch to subclient */
|
|
|
|
cl = data->lm75[bank - 1];
|
|
|
|
|
|
|
|
/* convert from ISA to LM75 I2C addresses */
|
|
|
|
switch (reg & 0xff) {
|
|
|
|
case 0x50: /* TEMP */
|
2011-11-04 15:00:47 +04:00
|
|
|
res = i2c_smbus_read_word_swapped(cl, 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
case 0x52: /* CONFIG */
|
|
|
|
res = i2c_smbus_read_byte_data(cl, 1);
|
|
|
|
break;
|
|
|
|
case 0x53: /* HYST */
|
2011-11-04 15:00:47 +04:00
|
|
|
res = i2c_smbus_read_word_swapped(cl, 2);
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
case 0x55: /* MAX */
|
|
|
|
default:
|
2011-11-04 15:00:47 +04:00
|
|
|
res = i2c_smbus_read_word_swapped(cl, 3);
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bank > 2)
|
|
|
|
i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0);
|
|
|
|
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_unlock(&data->lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value)
|
|
|
|
{
|
|
|
|
struct asb100_data *data = i2c_get_clientdata(client);
|
|
|
|
struct i2c_client *cl;
|
|
|
|
int bank;
|
|
|
|
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_lock(&data->lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
bank = (reg >> 8) & 0x0f;
|
|
|
|
if (bank > 2)
|
|
|
|
/* switch banks */
|
|
|
|
i2c_smbus_write_byte_data(client, ASB100_REG_BANK, bank);
|
|
|
|
|
|
|
|
if (bank == 0 || bank > 2) {
|
|
|
|
i2c_smbus_write_byte_data(client, reg & 0xff, value & 0xff);
|
|
|
|
} else {
|
|
|
|
/* switch to subclient */
|
|
|
|
cl = data->lm75[bank - 1];
|
|
|
|
|
|
|
|
/* convert from ISA to LM75 I2C addresses */
|
|
|
|
switch (reg & 0xff) {
|
|
|
|
case 0x52: /* CONFIG */
|
|
|
|
i2c_smbus_write_byte_data(cl, 1, value & 0xff);
|
|
|
|
break;
|
|
|
|
case 0x53: /* HYST */
|
2011-11-04 15:00:47 +04:00
|
|
|
i2c_smbus_write_word_swapped(cl, 2, value);
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
case 0x55: /* MAX */
|
2011-11-04 15:00:47 +04:00
|
|
|
i2c_smbus_write_word_swapped(cl, 3, value);
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bank > 2)
|
|
|
|
i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0);
|
|
|
|
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_unlock(&data->lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void asb100_init_client(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct asb100_data *data = i2c_get_clientdata(client);
|
|
|
|
|
2005-07-31 23:52:01 +04:00
|
|
|
data->vrm = vid_which_vrm();
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Start monitoring */
|
2008-01-04 01:15:49 +03:00
|
|
|
asb100_write_value(client, ASB100_REG_CONFIG,
|
2005-04-17 02:20:36 +04:00
|
|
|
(asb100_read_value(client, ASB100_REG_CONFIG) & 0xf7) | 0x01);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct asb100_data *asb100_update_device(struct device *dev)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
|
|
struct asb100_data *data = i2c_get_clientdata(client);
|
|
|
|
int i;
|
|
|
|
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_lock(&data->update_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|
|
|
|
|| !data->valid) {
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "starting device update...\n");
|
|
|
|
|
|
|
|
/* 7 voltage inputs */
|
|
|
|
for (i = 0; i < 7; i++) {
|
|
|
|
data->in[i] = asb100_read_value(client,
|
|
|
|
ASB100_REG_IN(i));
|
|
|
|
data->in_min[i] = asb100_read_value(client,
|
|
|
|
ASB100_REG_IN_MIN(i));
|
|
|
|
data->in_max[i] = asb100_read_value(client,
|
|
|
|
ASB100_REG_IN_MAX(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 3 fan inputs */
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
data->fan[i] = asb100_read_value(client,
|
|
|
|
ASB100_REG_FAN(i));
|
|
|
|
data->fan_min[i] = asb100_read_value(client,
|
|
|
|
ASB100_REG_FAN_MIN(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 4 temperature inputs */
|
|
|
|
for (i = 1; i <= 4; i++) {
|
|
|
|
data->temp[i-1] = asb100_read_value(client,
|
|
|
|
ASB100_REG_TEMP(i));
|
|
|
|
data->temp_max[i-1] = asb100_read_value(client,
|
|
|
|
ASB100_REG_TEMP_MAX(i));
|
|
|
|
data->temp_hyst[i-1] = asb100_read_value(client,
|
|
|
|
ASB100_REG_TEMP_HYST(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* VID and fan divisors */
|
|
|
|
i = asb100_read_value(client, ASB100_REG_VID_FANDIV);
|
|
|
|
data->vid = i & 0x0f;
|
|
|
|
data->vid |= (asb100_read_value(client,
|
|
|
|
ASB100_REG_CHIPID) & 0x01) << 4;
|
|
|
|
data->fan_div[0] = (i >> 4) & 0x03;
|
|
|
|
data->fan_div[1] = (i >> 6) & 0x03;
|
|
|
|
data->fan_div[2] = (asb100_read_value(client,
|
|
|
|
ASB100_REG_PIN) >> 6) & 0x03;
|
|
|
|
|
|
|
|
/* PWM */
|
|
|
|
data->pwm = asb100_read_value(client, ASB100_REG_PWM1);
|
|
|
|
|
|
|
|
/* alarms */
|
|
|
|
data->alarms = asb100_read_value(client, ASB100_REG_ALARM1) +
|
|
|
|
(asb100_read_value(client, ASB100_REG_ALARM2) << 8);
|
|
|
|
|
|
|
|
data->last_updated = jiffies;
|
|
|
|
data->valid = 1;
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "... device update complete\n");
|
|
|
|
}
|
|
|
|
|
2006-01-19 01:19:26 +03:00
|
|
|
mutex_unlock(&data->update_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2012-01-20 11:38:18 +04:00
|
|
|
module_i2c_driver(asb100_driver);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>");
|
|
|
|
MODULE_DESCRIPTION("ASB100 Bach driver");
|
|
|
|
MODULE_LICENSE("GPL");
|