2019-05-20 15:19:02 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2012-01-20 03:02:25 +08:00
|
|
|
* smsc47b397.c - Part of lm_sensors, Linux kernel modules
|
|
|
|
* for hardware monitoring
|
|
|
|
*
|
|
|
|
* Supports the SMSC LPC47B397-NC Super-I/O chip.
|
|
|
|
*
|
|
|
|
* Author/Maintainer: Mark M. Hoffman <mhoffman@lightlink.com>
|
|
|
|
* Copyright (C) 2004 Utilitek Systems, Inc.
|
|
|
|
*
|
|
|
|
* derived in part from smsc47m1.c:
|
|
|
|
* Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
|
2014-01-30 03:40:08 +08:00
|
|
|
* Copyright (C) 2004 Jean Delvare <jdelvare@suse.de>
|
2012-01-20 03:02:25 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-20 14:51:48 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/jiffies.h>
|
2007-05-08 23:22:03 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-07-16 09:39:18 +08:00
|
|
|
#include <linux/hwmon.h>
|
2007-05-08 23:22:03 +08:00
|
|
|
#include <linux/hwmon-sysfs.h>
|
2005-07-16 09:39:18 +08:00
|
|
|
#include <linux/err.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
2006-01-19 06:19:26 +08:00
|
|
|
#include <linux/mutex.h>
|
2009-01-07 23:37:35 +08:00
|
|
|
#include <linux/acpi.h>
|
2009-09-15 23:18:13 +08:00
|
|
|
#include <linux/io.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-12-07 06:13:42 +08:00
|
|
|
static unsigned short force_id;
|
|
|
|
module_param(force_id, ushort, 0);
|
|
|
|
MODULE_PARM_DESC(force_id, "Override the detected device ID");
|
|
|
|
|
2007-05-08 23:22:03 +08:00
|
|
|
static struct platform_device *pdev;
|
|
|
|
|
|
|
|
#define DRVNAME "smsc47b397"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Super-I/0 registers and commands */
|
|
|
|
|
|
|
|
#define REG 0x2e /* The register to read/write */
|
|
|
|
#define VAL 0x2f /* The value to read/write */
|
|
|
|
|
|
|
|
static inline void superio_outb(int reg, int val)
|
|
|
|
{
|
|
|
|
outb(reg, REG);
|
|
|
|
outb(val, VAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int superio_inb(int reg)
|
|
|
|
{
|
|
|
|
outb(reg, REG);
|
|
|
|
return inb(VAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* select superio logical device */
|
|
|
|
static inline void superio_select(int ld)
|
|
|
|
{
|
|
|
|
superio_outb(0x07, ld);
|
|
|
|
}
|
|
|
|
|
2019-04-05 02:22:42 +08:00
|
|
|
static inline int superio_enter(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-04-05 02:22:42 +08:00
|
|
|
if (!request_muxed_region(REG, 2, DRVNAME))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
outb(0x55, REG);
|
2019-04-05 02:22:42 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void superio_exit(void)
|
|
|
|
{
|
|
|
|
outb(0xAA, REG);
|
2019-04-05 02:22:42 +08:00
|
|
|
release_region(REG, 2);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SUPERIO_REG_DEVID 0x20
|
|
|
|
#define SUPERIO_REG_DEVREV 0x21
|
|
|
|
#define SUPERIO_REG_BASE_MSB 0x60
|
|
|
|
#define SUPERIO_REG_BASE_LSB 0x61
|
|
|
|
#define SUPERIO_REG_LD8 0x08
|
|
|
|
|
|
|
|
#define SMSC_EXTENT 0x02
|
|
|
|
|
|
|
|
/* 0 <= nr <= 3 */
|
|
|
|
static u8 smsc47b397_reg_temp[] = {0x25, 0x26, 0x27, 0x80};
|
|
|
|
#define SMSC47B397_REG_TEMP(nr) (smsc47b397_reg_temp[(nr)])
|
|
|
|
|
|
|
|
/* 0 <= nr <= 3 */
|
|
|
|
#define SMSC47B397_REG_FAN_LSB(nr) (0x28 + 2 * (nr))
|
|
|
|
#define SMSC47B397_REG_FAN_MSB(nr) (0x29 + 2 * (nr))
|
|
|
|
|
|
|
|
struct smsc47b397_data {
|
2007-05-08 23:22:03 +08:00
|
|
|
unsigned short addr;
|
2006-01-19 06:19:26 +08:00
|
|
|
struct mutex lock;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-19 06:19:26 +08:00
|
|
|
struct mutex update_lock;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long last_updated; /* in jiffies */
|
2021-09-25 03:52:02 +08:00
|
|
|
bool valid;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* register values */
|
|
|
|
u16 fan[4];
|
|
|
|
u8 temp[4];
|
|
|
|
};
|
|
|
|
|
2011-11-04 19:00:47 +08:00
|
|
|
static int smsc47b397_read_value(struct smsc47b397_data *data, u8 reg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
2006-01-19 06:19:26 +08:00
|
|
|
mutex_lock(&data->lock);
|
2007-05-08 23:22:03 +08:00
|
|
|
outb(reg, data->addr);
|
|
|
|
res = inb_p(data->addr + 1);
|
2006-01-19 06:19:26 +08:00
|
|
|
mutex_unlock(&data->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct smsc47b397_data *smsc47b397_update_device(struct device *dev)
|
|
|
|
{
|
2007-05-08 23:22:03 +08:00
|
|
|
struct smsc47b397_data *data = dev_get_drvdata(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
2006-01-19 06:19:26 +08:00
|
|
|
mutex_lock(&data->update_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
|
2007-05-08 23:22:03 +08:00
|
|
|
dev_dbg(dev, "starting device update...\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* 4 temperature inputs, 4 fan inputs */
|
|
|
|
for (i = 0; i < 4; i++) {
|
2007-05-08 23:22:03 +08:00
|
|
|
data->temp[i] = smsc47b397_read_value(data,
|
2005-04-17 06:20:36 +08:00
|
|
|
SMSC47B397_REG_TEMP(i));
|
|
|
|
|
|
|
|
/* must read LSB first */
|
2007-05-08 23:22:03 +08:00
|
|
|
data->fan[i] = smsc47b397_read_value(data,
|
2005-04-17 06:20:36 +08:00
|
|
|
SMSC47B397_REG_FAN_LSB(i));
|
2007-05-08 23:22:03 +08:00
|
|
|
data->fan[i] |= smsc47b397_read_value(data,
|
2005-04-17 06:20:36 +08:00
|
|
|
SMSC47B397_REG_FAN_MSB(i)) << 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->last_updated = jiffies;
|
2021-09-25 03:52:02 +08:00
|
|
|
data->valid = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-05-08 23:22:03 +08:00
|
|
|
dev_dbg(dev, "... device update complete\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-01-19 06:19:26 +08:00
|
|
|
mutex_unlock(&data->update_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2012-01-20 03:02:25 +08:00
|
|
|
/*
|
|
|
|
* TEMP: 0.001C/bit (-128C to +127C)
|
|
|
|
* REG: 1C/bit, two's complement
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int temp_from_reg(u8 reg)
|
|
|
|
{
|
|
|
|
return (s8)reg * 1000;
|
|
|
|
}
|
|
|
|
|
2018-12-11 06:02:21 +08:00
|
|
|
static ssize_t temp_show(struct device *dev, struct device_attribute *devattr,
|
|
|
|
char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-05-08 23:22:03 +08:00
|
|
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct smsc47b397_data *data = smsc47b397_update_device(dev);
|
2007-05-08 23:22:03 +08:00
|
|
|
return sprintf(buf, "%d\n", temp_from_reg(data->temp[attr->index]));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-12-11 06:02:21 +08:00
|
|
|
static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
|
|
|
|
static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
|
|
|
|
static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
|
|
|
|
static SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 3);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-01-20 03:02:25 +08:00
|
|
|
/*
|
|
|
|
* FAN: 1 RPM/bit
|
|
|
|
* REG: count of 90kHz pulses / revolution
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int fan_from_reg(u16 reg)
|
|
|
|
{
|
2007-06-23 20:58:22 +08:00
|
|
|
if (reg == 0 || reg == 0xffff)
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 90000 * 60 / reg;
|
|
|
|
}
|
|
|
|
|
2018-12-11 06:02:21 +08:00
|
|
|
static ssize_t fan_show(struct device *dev, struct device_attribute *devattr,
|
|
|
|
char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-05-08 23:22:03 +08:00
|
|
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
|
|
|
struct smsc47b397_data *data = smsc47b397_update_device(dev);
|
|
|
|
return sprintf(buf, "%d\n", fan_from_reg(data->fan[attr->index]));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2018-12-11 06:02:21 +08:00
|
|
|
static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
|
|
|
|
static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
|
|
|
|
static SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 2);
|
|
|
|
static SENSOR_DEVICE_ATTR_RO(fan4_input, fan, 3);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-07-08 09:27:38 +08:00
|
|
|
static struct attribute *smsc47b397_attrs[] = {
|
2007-05-08 23:22:03 +08:00
|
|
|
&sensor_dev_attr_temp1_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp2_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp3_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_temp4_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan1_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan2_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan3_input.dev_attr.attr,
|
|
|
|
&sensor_dev_attr_fan4_input.dev_attr.attr,
|
2006-09-25 02:59:49 +08:00
|
|
|
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2014-07-08 09:27:38 +08:00
|
|
|
ATTRIBUTE_GROUPS(smsc47b397);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-05-08 23:22:03 +08:00
|
|
|
static int smsc47b397_probe(struct platform_device *pdev);
|
[PATCH] I2C: Separate non-i2c hwmon drivers from i2c-core (5/9)
Call the ISA chip drivers detection function directly instead of relying
on i2c_detect. The net effect is that address lists won't be handled
anymore, but they were mostly useless in the ISA case anyway (pc87360,
smsc47m1, smsc47b397 had already dropped them).
We don't need to handle multiple devices, all we may need is a way to
force a given address instead of the original one (some drivers already
do: sis5595, via686a, w83627hf), and, for drivers supporting multiple
chips, a way to force one given kind. All this may be added later on
demand, but I actually don't think there will be much demand.
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2005-07-20 05:56:35 +08:00
|
|
|
|
2007-05-08 23:22:03 +08:00
|
|
|
static struct platform_driver smsc47b397_driver = {
|
2005-11-27 03:37:41 +08:00
|
|
|
.driver = {
|
2007-05-08 23:22:03 +08:00
|
|
|
.name = DRVNAME,
|
2005-11-27 03:37:41 +08:00
|
|
|
},
|
2007-05-08 23:22:03 +08:00
|
|
|
.probe = smsc47b397_probe,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2012-11-20 02:22:35 +08:00
|
|
|
static int smsc47b397_probe(struct platform_device *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-05-08 23:22:03 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct smsc47b397_data *data;
|
2014-07-08 09:27:38 +08:00
|
|
|
struct device *hwmon_dev;
|
2007-05-08 23:22:03 +08:00
|
|
|
struct resource *res;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-05-08 23:22:03 +08:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_IO, 0);
|
2012-06-03 03:04:06 +08:00
|
|
|
if (!devm_request_region(dev, res->start, SMSC_EXTENT,
|
|
|
|
smsc47b397_driver.driver.name)) {
|
2007-05-08 23:22:03 +08:00
|
|
|
dev_err(dev, "Region 0x%lx-0x%lx already in use!\n",
|
|
|
|
(unsigned long)res->start,
|
|
|
|
(unsigned long)res->start + SMSC_EXTENT - 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2012-06-03 03:04:06 +08:00
|
|
|
data = devm_kzalloc(dev, sizeof(struct smsc47b397_data), GFP_KERNEL);
|
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-05-08 23:22:03 +08:00
|
|
|
data->addr = res->start;
|
2006-01-19 06:19:26 +08:00
|
|
|
mutex_init(&data->lock);
|
|
|
|
mutex_init(&data->update_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-07-08 09:27:38 +08:00
|
|
|
hwmon_dev = devm_hwmon_device_register_with_groups(dev, "smsc47b397",
|
|
|
|
data,
|
|
|
|
smsc47b397_groups);
|
|
|
|
return PTR_ERR_OR_ZERO(hwmon_dev);
|
2007-05-08 23:22:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init smsc47b397_device_add(unsigned short address)
|
|
|
|
{
|
|
|
|
struct resource res = {
|
|
|
|
.start = address,
|
|
|
|
.end = address + SMSC_EXTENT - 1,
|
|
|
|
.name = DRVNAME,
|
|
|
|
.flags = IORESOURCE_IO,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2009-01-07 23:37:35 +08:00
|
|
|
err = acpi_check_resource_conflict(&res);
|
|
|
|
if (err)
|
|
|
|
goto exit;
|
|
|
|
|
2007-05-08 23:22:03 +08:00
|
|
|
pdev = platform_device_alloc(DRVNAME, address);
|
|
|
|
if (!pdev) {
|
|
|
|
err = -ENOMEM;
|
2010-10-20 14:51:48 +08:00
|
|
|
pr_err("Device allocation failed\n");
|
2007-05-08 23:22:03 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = platform_device_add_resources(pdev, &res, 1);
|
|
|
|
if (err) {
|
2010-10-20 14:51:48 +08:00
|
|
|
pr_err("Device resource addition failed (%d)\n", err);
|
2007-05-08 23:22:03 +08:00
|
|
|
goto exit_device_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = platform_device_add(pdev);
|
|
|
|
if (err) {
|
2010-10-20 14:51:48 +08:00
|
|
|
pr_err("Device addition failed (%d)\n", err);
|
2007-05-08 23:22:03 +08:00
|
|
|
goto exit_device_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
exit_device_put:
|
|
|
|
platform_device_put(pdev);
|
|
|
|
exit:
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-03-28 23:35:26 +08:00
|
|
|
static int __init smsc47b397_find(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u8 id, rev;
|
2008-03-01 01:24:44 +08:00
|
|
|
char *name;
|
2012-03-28 23:35:26 +08:00
|
|
|
unsigned short addr;
|
2019-04-05 02:22:42 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = superio_enter();
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-12-07 06:13:42 +08:00
|
|
|
id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-11-04 19:00:47 +08:00
|
|
|
switch (id) {
|
2008-03-01 01:24:44 +08:00
|
|
|
case 0x81:
|
|
|
|
name = "SCH5307-NS";
|
|
|
|
break;
|
|
|
|
case 0x6f:
|
|
|
|
name = "LPC47B397-NC";
|
|
|
|
break;
|
|
|
|
case 0x85:
|
|
|
|
case 0x8c:
|
|
|
|
name = "SCH5317";
|
|
|
|
break;
|
|
|
|
default:
|
2005-04-17 06:20:36 +08:00
|
|
|
superio_exit();
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
rev = superio_inb(SUPERIO_REG_DEVREV);
|
|
|
|
|
|
|
|
superio_select(SUPERIO_REG_LD8);
|
2012-03-28 23:35:26 +08:00
|
|
|
addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8)
|
2005-04-17 06:20:36 +08:00
|
|
|
| superio_inb(SUPERIO_REG_BASE_LSB);
|
|
|
|
|
2010-10-20 14:51:48 +08:00
|
|
|
pr_info("found SMSC %s (base address 0x%04x, revision %u)\n",
|
2012-03-28 23:35:26 +08:00
|
|
|
name, addr, rev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
superio_exit();
|
2012-03-28 23:35:26 +08:00
|
|
|
return addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init smsc47b397_init(void)
|
|
|
|
{
|
2007-05-08 23:22:03 +08:00
|
|
|
unsigned short address;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret;
|
|
|
|
|
2012-03-28 23:35:26 +08:00
|
|
|
ret = smsc47b397_find();
|
|
|
|
if (ret < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
2012-03-28 23:35:26 +08:00
|
|
|
address = ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-05-08 23:22:03 +08:00
|
|
|
ret = platform_driver_register(&smsc47b397_driver);
|
|
|
|
if (ret)
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
/* Sets global pdev as a side effect */
|
|
|
|
ret = smsc47b397_device_add(address);
|
|
|
|
if (ret)
|
|
|
|
goto exit_driver;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
exit_driver:
|
|
|
|
platform_driver_unregister(&smsc47b397_driver);
|
|
|
|
exit:
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit smsc47b397_exit(void)
|
|
|
|
{
|
2007-05-08 23:22:03 +08:00
|
|
|
platform_device_unregister(pdev);
|
|
|
|
platform_driver_unregister(&smsc47b397_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>");
|
|
|
|
MODULE_DESCRIPTION("SMSC LPC47B397 driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_init(smsc47b397_init);
|
|
|
|
module_exit(smsc47b397_exit);
|