Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d8672c5 authored by Jean Delvare's avatar Jean Delvare Committed by Greg Kroah-Hartman
Browse files

[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: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 5042c7d7
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -48,7 +48,8 @@
/* Addresses to scan */
static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
					0x2e, 0x2f, I2C_CLIENT_END };
static unsigned int normal_isa[] = { 0x0290, I2C_CLIENT_ISA_END };
static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
static unsigned short isa_address = 0x290;

/* Insmod parameters */
SENSORS_INSMOD_2(it87, it8712);
@@ -222,7 +223,7 @@ struct it87_data {


static int it87_attach_adapter(struct i2c_adapter *adapter);
static int it87_find(int *address);
static int it87_isa_attach_adapter(struct i2c_adapter *adapter);
static int it87_detect(struct i2c_adapter *adapter, int address, int kind);
static int it87_detach_client(struct i2c_client *client);

@@ -246,7 +247,7 @@ static struct i2c_driver it87_driver = {
static struct i2c_driver it87_isa_driver = {
	.owner		= THIS_MODULE,
	.name		= "it87-isa",
	.attach_adapter	= it87_attach_adapter,
	.attach_adapter	= it87_isa_attach_adapter,
	.detach_client	= it87_detach_client,
};

@@ -701,7 +702,12 @@ static int it87_attach_adapter(struct i2c_adapter *adapter)
	return i2c_detect(adapter, &addr_data, it87_detect);
}

/* SuperIO detection - will change normal_isa[0] if a chip is found */
static int it87_isa_attach_adapter(struct i2c_adapter *adapter)
{
	return it87_detect(adapter, isa_address, -1);
}

/* SuperIO detection - will change isa_address if a chip is found */
static int it87_find(int *address)
{
	int err = -ENODEV;
@@ -1184,7 +1190,7 @@ static int __init sm_it87_init(void)
	int addr, res;

	if (!it87_find(&addr)) {
		normal_isa[0] = addr;
		isa_address = addr;
	}

	res = i2c_add_driver(&it87_driver);
+9 −2
Original line number Diff line number Diff line
@@ -34,7 +34,8 @@ static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24,
					0x25, 0x26, 0x27, 0x28, 0x29,
					0x2a, 0x2b, 0x2c, 0x2d, 0x2e,
					0x2f, I2C_CLIENT_END };
static unsigned int normal_isa[] = { 0x0290, I2C_CLIENT_ISA_END };
static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
static unsigned short isa_address = 0x290;

/* Insmod parameters */
SENSORS_INSMOD_2(lm78, lm79);
@@ -160,6 +161,7 @@ struct lm78_data {


static int lm78_attach_adapter(struct i2c_adapter *adapter);
static int lm78_isa_attach_adapter(struct i2c_adapter *adapter);
static int lm78_detect(struct i2c_adapter *adapter, int address, int kind);
static int lm78_detach_client(struct i2c_client *client);

@@ -181,7 +183,7 @@ static struct i2c_driver lm78_driver = {
static struct i2c_driver lm78_isa_driver = {
	.owner		= THIS_MODULE,
	.name		= "lm78-isa",
	.attach_adapter	= lm78_attach_adapter,
	.attach_adapter	= lm78_isa_attach_adapter,
	.detach_client	= lm78_detach_client,
};

@@ -480,6 +482,11 @@ static int lm78_attach_adapter(struct i2c_adapter *adapter)
	return i2c_detect(adapter, &addr_data, lm78_detect);
}

static int lm78_isa_attach_adapter(struct i2c_adapter *adapter)
{
	return lm78_detect(adapter, isa_address, -1);
}

/* This function is called by i2c_detect */
int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
{
+9 −29
Original line number Diff line number Diff line
@@ -39,25 +39,17 @@
#include <linux/jiffies.h>
#include <linux/i2c.h>
#include <linux/i2c-isa.h>
#include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h>
#include <linux/hwmon.h>
#include <linux/err.h>
#include <asm/io.h>

static unsigned short normal_i2c[] = { I2C_CLIENT_END };
static unsigned int normal_isa[] = { 0, I2C_CLIENT_ISA_END };
static struct i2c_force_data forces[] = {{ NULL }};
static u8 devid;
static unsigned int extra_isa[3];
static unsigned short address;
static unsigned short extra_isa[3];
static u8 confreg[4];

enum chips { any_chip, pc87360, pc87363, pc87364, pc87365, pc87366 };
static struct i2c_address_data addr_data = {
	.normal_i2c		= normal_i2c,
	.normal_isa		= normal_isa,
	.forces			= forces,
};

static int init = 1;
module_param(init, int, 0);
@@ -228,8 +220,7 @@ struct pc87360_data {
 * Functions declaration
 */

static int pc87360_attach_adapter(struct i2c_adapter *adapter);
static int pc87360_detect(struct i2c_adapter *adapter, int address, int kind);
static int pc87360_detect(struct i2c_adapter *adapter);
static int pc87360_detach_client(struct i2c_client *client);

static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
@@ -246,8 +237,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev);
static struct i2c_driver pc87360_driver = {
	.owner		= THIS_MODULE,
	.name		= "pc87360",
	.flags		= I2C_DF_NOTIFY,
	.attach_adapter	= pc87360_attach_adapter,
	.attach_adapter	= pc87360_detect,
	.detach_client	= pc87360_detach_client,
};

@@ -636,12 +626,7 @@ static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL);
 * Device detection, registration and update
 */

static int pc87360_attach_adapter(struct i2c_adapter *adapter)
{
	return i2c_detect(adapter, &addr_data, pc87360_detect);
}

static int pc87360_find(int sioaddr, u8 *devid, int *address)
static int pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses)
{
	u16 val;
	int i;
@@ -687,7 +672,7 @@ static int pc87360_find(int sioaddr, u8 *devid, int *address)
			continue;
		}

		address[i] = val;
		addresses[i] = val;

		if (i==0) { /* Fans */
			confreg[0] = superio_inb(sioaddr, 0xF0);
@@ -731,9 +716,7 @@ static int pc87360_find(int sioaddr, u8 *devid, int *address)
	return 0;
}

/* We don't really care about the address.
   Read from extra_isa instead. */
int pc87360_detect(struct i2c_adapter *adapter, int address, int kind)
static int pc87360_detect(struct i2c_adapter *adapter)
{
	int i;
	struct i2c_client *new_client;
@@ -742,9 +725,6 @@ int pc87360_detect(struct i2c_adapter *adapter, int address, int kind)
	const char *name = "pc87360";
	int use_thermistors = 0;

	if (!i2c_is_isa_adapter(adapter))
		return -ENODEV;

	if (!(data = kmalloc(sizeof(struct pc87360_data), GFP_KERNEL)))
		return -ENOMEM;
	memset(data, 0x00, sizeof(struct pc87360_data));
@@ -1334,12 +1314,12 @@ static int __init pc87360_init(void)
	/* Arbitrarily pick one of the addresses */
	for (i = 0; i < 3; i++) {
		if (extra_isa[i] != 0x0000) {
			normal_isa[0] = extra_isa[i];
			address = extra_isa[i];
			break;
		}
	}

	if (normal_isa[0] == 0x0000) {
	if (address == 0x0000) {
		printk(KERN_WARNING "pc87360: No active logical device, "
		       "module not inserted.\n");
		return -ENODEV;
+9 −32
Original line number Diff line number Diff line
@@ -71,14 +71,10 @@ module_param(force_addr, ushort, 0);
MODULE_PARM_DESC(force_addr,
		 "Initialize the base address of the sensors");

/* Addresses to scan.
/* Device address
   Note that we can't determine the ISA address until we have initialized
   our module */
static unsigned short normal_i2c[] = { I2C_CLIENT_END };
static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END };

/* Insmod parameters */
SENSORS_INSMOD_1(sis5595);
static unsigned short address;

/* Many SIS5595 constants specified below */

@@ -194,8 +190,7 @@ struct sis5595_data {

static struct pci_dev *s_bridge;	/* pointer to the (only) sis5595 */

static int sis5595_attach_adapter(struct i2c_adapter *adapter);
static int sis5595_detect(struct i2c_adapter *adapter, int address, int kind);
static int sis5595_detect(struct i2c_adapter *adapter);
static int sis5595_detach_client(struct i2c_client *client);

static int sis5595_read_value(struct i2c_client *client, u8 register);
@@ -206,9 +201,7 @@ static void sis5595_init_client(struct i2c_client *client);
static struct i2c_driver sis5595_driver = {
	.owner		= THIS_MODULE,
	.name		= "sis5595",
	.id		= I2C_DRIVERID_SIS5595,
	.flags		= I2C_DF_NOTIFY,
	.attach_adapter	= sis5595_attach_adapter,
	.attach_adapter	= sis5595_detect,
	.detach_client	= sis5595_detach_client,
};

@@ -480,14 +473,7 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
 
/* This is called when the module is loaded */
static int sis5595_attach_adapter(struct i2c_adapter *adapter)
{
	if (!(adapter->class & I2C_CLASS_HWMON))
		return 0;
	return i2c_detect(adapter, &addr_data, sis5595_detect);
}

int sis5595_detect(struct i2c_adapter *adapter, int address, int kind)
static int sis5595_detect(struct i2c_adapter *adapter)
{
	int err = 0;
	int i;
@@ -496,10 +482,6 @@ int sis5595_detect(struct i2c_adapter *adapter, int address, int kind)
	char val;
	u16 a;

	/* Make sure we are probing the ISA bus!!  */
	if (!i2c_is_isa_adapter(adapter))
		goto exit;

	if (force_addr)
		address = force_addr & ~(SIS5595_EXTENT - 1);
	/* Reserve the ISA region */
@@ -642,7 +624,6 @@ static int sis5595_detach_client(struct i2c_client *client)
		return err;
	}

	if (i2c_is_isa_client(client))
	release_region(client->addr, SIS5595_EXTENT);

	kfree(data);
@@ -760,7 +741,6 @@ static int __devinit sis5595_pci_probe(struct pci_dev *dev,
{
	u16 val;
	int *i;
	int addr = 0;

	for (i = blacklist; *i != 0; i++) {
		struct pci_dev *dev;
@@ -776,19 +756,16 @@ static int __devinit sis5595_pci_probe(struct pci_dev *dev,
	    pci_read_config_word(dev, SIS5595_BASE_REG, &val))
		return -ENODEV;
	
	addr = val & ~(SIS5595_EXTENT - 1);
	if (addr == 0 && force_addr == 0) {
	address = val & ~(SIS5595_EXTENT - 1);
	if (address == 0 && force_addr == 0) {
		dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n");
		return -ENODEV;
	}
	if (force_addr)
		addr = force_addr;	/* so detect will get called */

	if (!addr) {
	if (!address) {
		dev_err(&dev->dev,"No SiS 5595 sensors found.\n");
		return -ENODEV;
	}
	normal_isa[0] = addr;

	s_bridge = pci_dev_get(dev);
	if (i2c_isa_add_driver(&sis5595_driver)) {
+12 −36
Original line number Diff line number Diff line
@@ -32,25 +32,13 @@
#include <linux/jiffies.h>
#include <linux/i2c.h>
#include <linux/i2c-isa.h>
#include <linux/i2c-sensor.h>
#include <linux/hwmon.h>
#include <linux/err.h>
#include <linux/init.h>
#include <asm/io.h>

static unsigned short normal_i2c[] = { I2C_CLIENT_END };
/* Address is autodetected, there is no default value */
static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END };
static struct i2c_force_data forces[] = {{NULL}};

enum chips { any_chip, smsc47b397 };
static struct i2c_address_data addr_data = {
	.normal_i2c		= normal_i2c,
	.normal_isa		= normal_isa,
	.probe			= normal_i2c,		/* cheat */
	.ignore			= normal_i2c,		/* cheat */
	.forces			= forces,
};
static unsigned short address;

/* Super-I/0 registers and commands */

@@ -219,15 +207,6 @@ sysfs_fan(4);
#define device_create_file_fan(client, num) \
	device_create_file(&client->dev, &dev_attr_fan##num##_input)

static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind);

static int smsc47b397_attach_adapter(struct i2c_adapter *adapter)
{
	if (!(adapter->class & I2C_CLASS_HWMON))
		return 0;
	return i2c_detect(adapter, &addr_data, smsc47b397_detect);
}

static int smsc47b397_detach_client(struct i2c_client *client)
{
	struct smsc47b397_data *data = i2c_get_clientdata(client);
@@ -247,27 +226,24 @@ static int smsc47b397_detach_client(struct i2c_client *client)
	return 0;
}

static int smsc47b397_detect(struct i2c_adapter *adapter);

static struct i2c_driver smsc47b397_driver = {
	.owner		= THIS_MODULE,
	.name		= "smsc47b397",
	.id		= I2C_DRIVERID_SMSC47B397,
	.flags		= I2C_DF_NOTIFY,
	.attach_adapter	= smsc47b397_attach_adapter,
	.attach_adapter	= smsc47b397_detect,
	.detach_client	= smsc47b397_detach_client,
};

static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind)
static int smsc47b397_detect(struct i2c_adapter *adapter)
{
	struct i2c_client *new_client;
	struct smsc47b397_data *data;
	int err = 0;

	if (!i2c_is_isa_adapter(adapter)) {
		return 0;
	}

	if (!request_region(addr, SMSC_EXTENT, smsc47b397_driver.name)) {
		dev_err(&adapter->dev, "Region 0x%x already in use!\n", addr);
	if (!request_region(address, SMSC_EXTENT, smsc47b397_driver.name)) {
		dev_err(&adapter->dev, "Region 0x%x already in use!\n",
			address);
		return -EBUSY;
	}

@@ -279,7 +255,7 @@ static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind)

	new_client = &data->client;
	i2c_set_clientdata(new_client, data);
	new_client->addr = addr;
	new_client->addr = address;
	init_MUTEX(&data->lock);
	new_client->adapter = adapter;
	new_client->driver = &smsc47b397_driver;
@@ -315,11 +291,11 @@ static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind)
error_free:
	kfree(data);
error_release:
	release_region(addr, SMSC_EXTENT);
	release_region(address, SMSC_EXTENT);
	return err;
}

static int __init smsc47b397_find(unsigned int *addr)
static int __init smsc47b397_find(unsigned short *addr)
{
	u8 id, rev;

@@ -348,7 +324,7 @@ static int __init smsc47b397_init(void)
{
	int ret;

	if ((ret = smsc47b397_find(normal_isa)))
	if ((ret = smsc47b397_find(&address)))
		return ret;

	return i2c_isa_add_driver(&smsc47b397_driver);
Loading