Commit 6d588f51 authored by Linus Torvalds's avatar Linus Torvalds

Merge bk://kernel.bkbits.net/gregkh/linux/i2c-2.5

into home.osdl.org:/home/torvalds/v2.5/linux
parents e9c14cd9 68079c55
......@@ -51,10 +51,6 @@ MODULE_DESCRIPTION("nForce2 SMBus driver");
#ifndef PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS
#define PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS 0x0064
#endif
/* TODO: sync with lm-sensors */
#ifndef I2C_HW_SMBUS_NFORCE2
#define I2C_HW_SMBUS_NFORCE2 0x0c
#endif
struct nforce2_smbus {
......@@ -128,20 +124,10 @@ static struct i2c_adapter nforce2_adapter = {
.name = "unset",
};
#if 0
/* Internally used pause function */
static void nforce2_do_pause(unsigned int amount)
{
current->state = TASK_INTERRUPTIBLE;
schedule_timeout(amount);
}
#endif
/* Return -1 on error. See smbus.h for more information */
static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, unsigned short flags,
char read_write, u8 command, int size,
union i2c_smbus_data * data)
static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write,
u8 command, int size, union i2c_smbus_data * data)
{
struct nforce2_smbus *smbus = adap->algo_data;
unsigned char protocol, pec, temp;
......@@ -249,7 +235,7 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, unsigned short fl
#if 0
do {
nforce2_do_pause(1);
i2c_do_pause(1);
temp = inb_p(NVIDIA_SMB_STS);
} while (((temp & NVIDIA_SMB_STS_DONE) == 0) && (timeout++ < MAX_TIMEOUT));
#endif
......@@ -332,13 +318,8 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int reg,
smbus->base, smbus->base+smbus->size-1, name);
return -1;
}
/*
smbus->adapter.owner = THIS_MODULE;
smbus->adapter.id = I2C_ALGO_SMBUS | I2C_HW_SMBUS_NFORCE2;
smbus->adapter.algo = &smbus_algorithm;
smbus->adapter.algo_data = smbus;
*/
smbus->adapter = nforce2_adapter;
smbus->adapter.algo_data = smbus;
smbus->adapter.dev.parent = &dev->dev;
snprintf(smbus->adapter.name, DEVICE_NAME_SIZE,
"SMBus nForce2 adapter at %04x", smbus->base);
......
......@@ -160,6 +160,15 @@ static int piix4_setup(struct pci_dev *PIIX4_dev, const struct pci_device_id *id
}
pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp);
/* Some BIOS will set up the chipset incorrectly and leave a register
in an undefined state (causing I2C to act very strangely). */
if (temp & 0x02) {
dev_info(&PIIX4_dev->dev, "Worked around buggy BIOS (I2C)\n");
temp = temp & 0xfd;
pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp);
}
/* If force_addr is set, we program the new address here. Just to make
sure, we disable the PIIX4 first. */
if (force_addr) {
......
......@@ -2,10 +2,12 @@
# Makefile for the kernel hardware sensors chip drivers.
#
# w83781d goes first, as it can override other driver's addresses.
obj-$(CONFIG_SENSORS_W83781D) += w83781d.o
obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
obj-$(CONFIG_SENSORS_IT87) += it87.o
obj-$(CONFIG_SENSORS_LM75) += lm75.o
obj-$(CONFIG_SENSORS_LM78) += lm78.o
obj-$(CONFIG_SENSORS_LM85) += lm85.o
obj-$(CONFIG_SENSORS_VIA686A) += via686a.o
obj-$(CONFIG_SENSORS_W83781D) += w83781d.o
......@@ -79,12 +79,36 @@ static struct class i2c_adapter_class = {
.release = &i2c_adapter_class_dev_release,
};
static ssize_t show_adapter_name(struct device *dev, char *buf)
{
struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
return sprintf(buf, "%s\n", adap->name);
}
static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
static void i2c_client_release(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
complete(&client->released);
}
static ssize_t show_client_name(struct device *dev, char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
return sprintf(buf, "%s\n", client->name);
}
/*
* We can't use the DEVICE_ATTR() macro here as we want the same filename for a
* different type of a device. So beware if the DEVICE_ATTR() macro ever
* changes, this definition will also have to change.
*/
static struct device_attribute dev_attr_client_name = {
.attr = {.name = "name", .mode = S_IRUGO, .owner = THIS_MODULE },
.show = &show_client_name,
};
/* ---------------------------------------------------
* registering functions
......@@ -120,6 +144,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
adap->dev.driver = &i2c_adapter_driver;
adap->dev.release = &i2c_adapter_dev_release;
device_register(&adap->dev);
device_create_file(&adap->dev, &dev_attr_name);
/* Add this adapter to the i2c_adapter class */
memset(&adap->class_dev, 0x00, sizeof(struct class_device));
......@@ -184,6 +209,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
init_completion(&adap->dev_released);
init_completion(&adap->class_dev_released);
class_device_unregister(&adap->class_dev);
device_remove_file(&adap->dev, &dev_attr_name);
device_unregister(&adap->dev);
list_del(&adap->list);
......@@ -361,6 +387,7 @@ int i2c_attach_client(struct i2c_client *client)
"%d-%04x", i2c_adapter_id(adapter), client->addr);
printk("registering %s\n", client->dev.bus_id);
device_register(&client->dev);
device_create_file(&client->dev, &dev_attr_client_name);
return 0;
}
......@@ -387,6 +414,7 @@ int i2c_detach_client(struct i2c_client *client)
down(&adapter->clist_lock);
list_del(&client->list);
init_completion(&client->released);
device_remove_file(&client->dev, &dev_attr_client_name);
device_unregister(&client->dev);
up(&adapter->clist_lock);
wait_for_completion(&client->released);
......
......@@ -181,6 +181,7 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
struct i2c_smbus_ioctl_data data_arg;
union i2c_smbus_data temp;
struct i2c_msg *rdwr_pa;
u8 **data_ptrs;
int i,datasize,res;
unsigned long funcs;
......@@ -214,7 +215,7 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
return (copy_to_user((unsigned long __user *)arg, &funcs,
sizeof(unsigned long)))?-EFAULT:0;
case I2C_RDWR:
case I2C_RDWR:
if (copy_from_user(&rdwr_arg,
(struct i2c_rdwr_ioctl_data __user *)arg,
sizeof(rdwr_arg)))
......@@ -231,28 +232,37 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
if (rdwr_pa == NULL) return -ENOMEM;
if (copy_from_user(rdwr_pa, rdwr_arg.msgs,
rdwr_arg.nmsgs * sizeof(struct i2c_msg))) {
kfree(rdwr_pa);
return -EFAULT;
}
data_ptrs = (u8 **) kmalloc(rdwr_arg.nmsgs * sizeof(u8 *),
GFP_KERNEL);
if (data_ptrs == NULL) {
kfree(rdwr_pa);
return -ENOMEM;
}
res = 0;
for( i=0; i<rdwr_arg.nmsgs; i++ ) {
if(copy_from_user(&(rdwr_pa[i]),
&(rdwr_arg.msgs[i]),
sizeof(rdwr_pa[i]))) {
res = -EFAULT;
break;
}
/* Limit the size of the message to a sane amount */
if (rdwr_pa[i].len > 8192) {
res = -EINVAL;
break;
}
data_ptrs[i] = rdwr_pa[i].buf;
rdwr_pa[i].buf = kmalloc(rdwr_pa[i].len, GFP_KERNEL);
if(rdwr_pa[i].buf == NULL) {
res = -ENOMEM;
break;
}
if(copy_from_user(rdwr_pa[i].buf,
rdwr_arg.msgs[i].buf,
data_ptrs[i],
rdwr_pa[i].len)) {
res = -EFAULT;
++i; /* Needs to be kfreed too */
res = -EFAULT;
break;
}
}
......@@ -260,18 +270,18 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
int j;
for (j = 0; j < i; ++j)
kfree(rdwr_pa[j].buf);
kfree(data_ptrs);
kfree(rdwr_pa);
return res;
}
if (!res) {
res = i2c_transfer(client->adapter,
rdwr_pa,
rdwr_arg.nmsgs);
}
res = i2c_transfer(client->adapter,
rdwr_pa,
rdwr_arg.nmsgs);
while(i-- > 0) {
if( res>=0 && (rdwr_pa[i].flags & I2C_M_RD)) {
if(copy_to_user(
rdwr_arg.msgs[i].buf,
data_ptrs[i],
rdwr_pa[i].buf,
rdwr_pa[i].len)) {
res = -EFAULT;
......@@ -279,6 +289,7 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
}
kfree(rdwr_pa[i].buf);
}
kfree(data_ptrs);
kfree(rdwr_pa);
return res;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment