diff options
Diffstat (limited to 'drivers')
244 files changed, 5835 insertions, 3334 deletions
diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c index c4b75ecf946..55959e4d1cb 100644 --- a/drivers/atm/zatm.c +++ b/drivers/atm/zatm.c @@ -417,9 +417,9 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]); chan = (here[3] & uPD98401_AAL5_CHAN) >> uPD98401_AAL5_CHAN_SHIFT; if (chan < zatm_dev->chans && zatm_dev->rx_map[chan]) { - int pos = ZATM_VCC(vcc)->pool; - + int pos; vcc = zatm_dev->rx_map[chan]; + pos = ZATM_VCC(vcc)->pool; if (skb == zatm_dev->last_free[pos]) zatm_dev->last_free[pos] = NULL; skb_unlink(skb, zatm_dev->pool + pos); diff --git a/drivers/base/bus.c b/drivers/base/bus.c index ab53832d57e..17e96698410 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -156,7 +156,9 @@ static ssize_t driver_unbind(struct device_driver *drv, device_release_driver(dev); err = count; } - return err; + if (err) + return err; + return count; } static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); @@ -358,7 +360,7 @@ int bus_add_device(struct device * dev) if (bus) { pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); device_attach(dev); - klist_add_tail(&bus->klist_devices, &dev->knode_bus); + klist_add_tail(&dev->knode_bus, &bus->klist_devices); error = device_add_attrs(bus, dev); if (!error) { sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); @@ -446,7 +448,7 @@ int bus_add_driver(struct device_driver * drv) } driver_attach(drv); - klist_add_tail(&bus->klist_drivers, &drv->knode_bus); + klist_add_tail(&drv->knode_bus, &bus->klist_drivers); module_add_driver(drv->owner, drv); driver_add_attrs(bus, drv); diff --git a/drivers/base/class.c b/drivers/base/class.c index 0154a1623b2..d164c32a97a 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -299,10 +299,8 @@ static void class_dev_release(struct kobject * kobj) pr_debug("device class '%s': release.\n", cd->class_id); - if (cd->devt_attr) { - kfree(cd->devt_attr); - cd->devt_attr = NULL; - } + kfree(cd->devt_attr); + cd->devt_attr = NULL; if (cls->release) cls->release(cd); @@ -452,10 +450,29 @@ void class_device_initialize(struct class_device *class_dev) INIT_LIST_HEAD(&class_dev->node); } +static char *make_class_name(struct class_device *class_dev) +{ + char *name; + int size; + + size = strlen(class_dev->class->name) + + strlen(kobject_name(&class_dev->kobj)) + 2; + + name = kmalloc(size, GFP_KERNEL); + if (!name) + return ERR_PTR(-ENOMEM); + + strcpy(name, class_dev->class->name); + strcat(name, ":"); + strcat(name, kobject_name(&class_dev->kobj)); + return name; +} + int class_device_add(struct class_device *class_dev) { struct class * parent = NULL; struct class_interface * class_intf; + char *class_name = NULL; int error; class_dev = class_device_get(class_dev); @@ -500,9 +517,13 @@ int class_device_add(struct class_device *class_dev) } class_device_add_attrs(class_dev); - if (class_dev->dev) + if (class_dev->dev) { + class_name = make_class_name(class_dev); sysfs_create_link(&class_dev->kobj, &class_dev->dev->kobj, "device"); + sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj, + class_name); + } /* notify any interfaces this device is now here */ if (parent) { @@ -519,6 +540,7 @@ int class_device_add(struct class_device *class_dev) if (error && parent) class_put(parent); class_device_put(class_dev); + kfree(class_name); return error; } @@ -584,6 +606,7 @@ void class_device_del(struct class_device *class_dev) { struct class * parent = class_dev->class; struct class_interface * class_intf; + char *class_name = NULL; if (parent) { down(&parent->sem); @@ -594,8 +617,11 @@ void class_device_del(struct class_device *class_dev) up(&parent->sem); } - if (class_dev->dev) + if (class_dev->dev) { + class_name = make_class_name(class_dev); sysfs_remove_link(&class_dev->kobj, "device"); + sysfs_remove_link(&class_dev->dev->kobj, class_name); + } if (class_dev->devt_attr) class_device_remove_file(class_dev, class_dev->devt_attr); class_device_remove_attrs(class_dev); @@ -605,6 +631,7 @@ void class_device_del(struct class_device *class_dev) if (parent) class_put(parent); + kfree(class_name); } void class_device_unregister(struct class_device *class_dev) diff --git a/drivers/base/core.c b/drivers/base/core.c index efe03a024a5..c8a33df0076 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -249,7 +249,7 @@ int device_add(struct device *dev) if ((error = bus_add_device(dev))) goto BusError; if (parent) - klist_add_tail(&parent->klist_children, &dev->knode_parent); + klist_add_tail(&dev->knode_parent, &parent->klist_children); /* notify platform of device entry */ if (platform_notify) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 16323f9cbff..d5bbce38282 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -42,7 +42,7 @@ void device_bind_driver(struct device * dev) { pr_debug("bound device '%s' to driver '%s'\n", dev->bus_id, dev->driver->name); - klist_add_tail(&dev->driver->klist_devices, &dev->knode_driver); + klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); sysfs_create_link(&dev->driver->kobj, &dev->kobj, kobject_name(&dev->kobj)); sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver"); diff --git a/drivers/base/node.c b/drivers/base/node.c index 904b27caf69..16c513aa4d4 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -39,13 +39,25 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) int n; int nid = dev->id; struct sysinfo i; + struct page_state ps; unsigned long inactive; unsigned long active; unsigned long free; si_meminfo_node(&i, nid); + get_page_state_node(&ps, nid); __get_zone_counts(&active, &inactive, &free, NODE_DATA(nid)); + /* Check for negative values in these approximate counters */ + if ((long)ps.nr_dirty < 0) + ps.nr_dirty = 0; + if ((long)ps.nr_writeback < 0) + ps.nr_writeback = 0; + if ((long)ps.nr_mapped < 0) + ps.nr_mapped = 0; + if ((long)ps.nr_slab < 0) + ps.nr_slab = 0; + n = sprintf(buf, "\n" "Node %d MemTotal: %8lu kB\n" "Node %d MemFree: %8lu kB\n" @@ -55,7 +67,11 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) "Node %d HighTotal: %8lu kB\n" "Node %d HighFree: %8lu kB\n" "Node %d LowTotal: %8lu kB\n" - "Node %d LowFree: %8lu kB\n", + "Node %d LowFree: %8lu kB\n" + "Node %d Dirty: %8lu kB\n" + "Node %d Writeback: %8lu kB\n" + "Node %d Mapped: %8lu kB\n" + "Node %d Slab: %8lu kB\n", nid, K(i.totalram), nid, K(i.freeram), nid, K(i.totalram - i.freeram), @@ -64,7 +80,11 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) nid, K(i.totalhigh), nid, K(i.freehigh), nid, K(i.totalram - i.totalhigh), - nid, K(i.freeram - i.freehigh)); + nid, K(i.freeram - i.freehigh), + nid, K(ps.nr_dirty), + nid, K(ps.nr_writeback), + nid, K(ps.nr_mapped), + nid, K(ps.nr_slab)); n += hugetlb_report_node_meminfo(nid, buf + n); return n; } diff --git a/drivers/base/power/resume.c b/drivers/base/power/resume.c index bdd96b03b88..0a7aa07b9a2 100644 --- a/drivers/base/power/resume.c +++ b/drivers/base/power/resume.c @@ -26,11 +26,11 @@ int resume_device(struct device * dev) down(&dev->sem); if (dev->power.pm_parent - && dev->power.pm_parent->power.power_state) { + && dev->power.pm_parent->power.power_state.event) { dev_err(dev, "PM: resume from %d, parent %s still %d\n", - dev->power.power_state, + dev->power.power_state.event, dev->power.pm_parent->bus_id, - dev->power.pm_parent->power.power_state); + dev->power.pm_parent->power.power_state.event); } if (dev->bus && dev->bus->resume) { dev_dbg(dev,"resuming\n"); @@ -54,7 +54,7 @@ void dpm_resume(void) list_add_tail(entry, &dpm_active); up(&dpm_list_sem); - if (!dev->power.prev_state) + if (!dev->power.prev_state.event) resume_device(dev); down(&dpm_list_sem); put_device(dev); diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 325962d8019..e8f0519f5df 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -13,10 +13,10 @@ static void runtime_resume(struct device * dev) { dev_dbg(dev, "resuming\n"); - if (!dev->power.power_state) + if (!dev->power.power_state.event) return; if (!resume_device(dev)) - dev->power.power_state = 0; + dev->power.power_state = PMSG_ON; } @@ -49,10 +49,10 @@ int dpm_runtime_suspend(struct device * dev, pm_message_t state) int error = 0; down(&dpm_sem); - if (dev->power.power_state == state) + if (dev->power.power_state.event == state.event) goto Done; - if (dev->power.power_state) + if (dev->power.power_state.event) runtime_resume(dev); if (!(error = suspend_device(dev, state))) diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c index 2ccee3763ac..50501764d05 100644 --- a/drivers/base/power/suspend.c +++ b/drivers/base/power/suspend.c @@ -40,22 +40,22 @@ int suspend_device(struct device * dev, pm_message_t state) int error = 0; down(&dev->sem); - if (dev->power.power_state) { + if (dev->power.power_state.event) { dev_dbg(dev, "PM: suspend %d-->%d\n", - dev->power.power_state, state); + dev->power.power_state.event, state.event); } if (dev->power.pm_parent - && dev->power.pm_parent->power.power_state) { + && dev->power.pm_parent->power.power_state.event) { dev_err(dev, "PM: suspend %d->%d, parent %s already %d\n", - dev->power.power_state, state, + dev->power.power_state.event, state.event, dev->power.pm_parent->bus_id, - dev->power.pm_parent->power.power_state); + dev->power.pm_parent->power.power_state.event); } dev->power.prev_state = dev->power.power_state; - if (dev->bus && dev->bus->suspend && !dev->power.power_state) { + if (dev->bus && dev->bus->suspend && !dev->power.power_state.event) { dev_dbg(dev, "suspending\n"); error = dev->bus->suspend(dev, state); } diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index f82b3df9545..8d04fb435c1 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c @@ -26,19 +26,19 @@ static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf) { - return sprintf(buf, "%u\n", dev->power.power_state); + return sprintf(buf, "%u\n", dev->power.power_state.event); } static ssize_t state_store(struct device * dev, struct device_attribute *attr, const char * buf, size_t n) { - u32 state; + pm_message_t state; char * rest; int error = 0; - state = simple_strtoul(buf, &rest, 10); + state.event = simple_strtoul(buf, &rest, 10); if (*rest) return -EINVAL; - if (state) + if (state.event) error = dpm_runtime_suspend(dev, state); else dpm_runtime_resume(dev); diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 214b9643540..3431eb6004c 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c @@ -288,6 +288,27 @@ void sysdev_shutdown(void) up(&sysdev_drivers_lock); } +static void __sysdev_resume(struct sys_device *dev) +{ + struct sysdev_class *cls = dev->cls; + struct sysdev_driver *drv; + + /* First, call the class-specific one */ + if (cls->resume) + cls->resume(dev); + + /* Call auxillary drivers next. */ + list_for_each_entry(drv, &cls->drivers, entry) { + if (drv->resume) + drv->resume(dev); + } + + /* Call global drivers. */ + list_for_each_entry(drv, &sysdev_drivers, entry) { + if (drv->resume) + drv->resume(dev); + } +} /** * sysdev_suspend - Suspend all system devices. @@ -305,38 +326,93 @@ void sysdev_shutdown(void) int sysdev_suspend(pm_message_t state) { struct sysdev_class * cls; + struct sys_device *sysdev, *err_dev; + struct sysdev_driver *drv, *err_drv; + int ret; pr_debug("Suspending System Devices\n"); list_for_each_entry_reverse(cls, &system_subsys.kset.list, kset.kobj.entry) { - struct sys_device * sysdev; pr_debug("Suspending type '%s':\n", kobject_name(&cls->kset.kobj)); list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) { - struct sysdev_driver * drv; pr_debug(" %s\n", kobject_name(&sysdev->kobj)); /* Call global drivers first. */ list_for_each_entry(drv, &sysdev_drivers, entry) { - if (drv->suspend) - drv->suspend(sysdev, state); + if (drv->suspend) { + ret = drv->suspend(sysdev, state); + if (ret) + goto gbl_driver; + } } /* Call auxillary drivers next. */ list_for_each_entry(drv, &cls->drivers, entry) { - if (drv->suspend) - drv->suspend(sysdev, state); + if (drv->suspend) { + ret = drv->suspend(sysdev, state); + if (ret) + goto aux_driver; + } } /* Now call the generic one */ - if (cls->suspend) - cls->suspend(sysdev, state); + if (cls->suspend) { + ret = cls->suspend(sysdev, state); + if (ret) + goto cls_driver; + } } } return 0; + /* resume current sysdev */ +cls_driver: + drv = NULL; + printk(KERN_ERR "Class suspend failed for %s\n", + kobject_name(&sysdev->kobj)); + +aux_driver: + if (drv) + printk(KERN_ERR "Class driver suspend failed for %s\n", + kobject_name(&sysdev->kobj)); + list_for_each_entry(err_drv, &cls->drivers, entry) { + if (err_drv == drv) + break; + if (err_drv->resume) + err_drv->resume(sysdev); + } + drv = NULL; + +gbl_driver: + if (drv) + printk(KERN_ERR "sysdev driver suspend failed for %s\n", + kobject_name(&sysdev->kobj)); + list_for_each_entry(err_drv, &sysdev_drivers, entry) { + if (err_drv == drv) + break; + if (err_drv->resume) + err_drv->resume(sysdev); + } + /* resume other sysdevs in current class */ + list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) { + if (err_dev == sysdev) + break; + pr_debug(" %s\n", kobject_name(&err_dev->kobj)); + __sysdev_resume(err_dev); + } + + /* resume other classes */ + list_for_each_entry_continue(cls, &system_subsys.kset.list, + kset.kobj.entry) { + list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) { + pr_debug(" %s\n", kobject_name(&err_dev->kobj)); + __sysdev_resume(err_dev); + } + } + return ret; } @@ -362,25 +438,9 @@ int sysdev_resume(void) kobject_name(&cls->kset.kobj)); list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) { - struct sysdev_driver * drv; pr_debug(" %s\n", kobject_name(&sysdev->kobj)); - /* First, call the class-specific one */ - if (cls->resume) - cls->resume(sysdev); - - /* Call auxillary drivers next. */ - list_for_each_entry(drv, &cls->drivers, entry) { - if (drv->resume) - drv->resume(sysdev); - } - - /* Call global drivers. */ - list_for_each_entry(drv, &sysdev_drivers, entry) { - if (drv->resume) - drv->resume(sysdev); - } - + __sysdev_resume(sysdev); } } return 0; diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig index b594768b024..6b736364cc5 100644 --- a/drivers/block/Kconfig +++ b/drivers/block/Kconfig @@ -408,54 +408,12 @@ config BLK_DEV_INITRD "real" root file system, etc. See <file:Documentation/initrd.txt> for details. -config INITRAMFS_SOURCE - string "Initramfs source file(s)" - default "" - help - This can be either a single cpio archive with a .cpio suffix or a - space-separated list of directories and files for building the - initramfs image. A cpio archive should contain a filesystem archive - to be used as an initramfs image. Directories should contain a - filesystem layout to be included in the initramfs image. Files - should contain entries according to the format described by the - "usr/gen_init_cpio" program in the kernel tree. - - When multiple directories and files are specified then the - initramfs image will be the aggregate of all of them. - - See <file:Documentation/early-userspace/README for more details. - - If you are not sure, leave it blank. - -config INITRAMFS_ROOT_UID - int "User ID to map to 0 (user root)" - depends on INITRAMFS_SOURCE!="" - default "0" - help - This setting is only meaningful if the INITRAMFS_SOURCE is - contains a directory. Setting this user ID (UID) to something - other than "0" will cause all files owned by that UID to be - owned by user root in the initial ramdisk image. - - If you are not sure, leave it set to "0". - -config INITRAMFS_ROOT_GID - int "Group ID to map to 0 (group root)" - depends on INITRAMFS_SOURCE!="" - default "0" - help - This setting is only meaningful if the INITRAMFS_SOURCE is - contains a directory. Setting this group ID (GID) to something - other than "0" will cause all files owned by that GID to be - owned by group root in the initial ramdisk image. - - If you are not sure, leave it set to "0". #XXX - it makes sense to enable this only for 32-bit subarch's, not for x86_64 #for instance. config LBD bool "Support for Large Block Devices" - depends on X86 || MIPS32 || PPC32 || ARCH_S390_31 || SUPERH || UML + depends on X86 || (MIPS && 32BIT) || PPC32 || ARCH_S390_31 || SUPERH || UML help Say Y here if you want to attach large (bigger than 2TB) discs to your machine, or if you want to have a raid or loopback device diff --git a/drivers/block/cryptoloop.c b/drivers/block/cryptoloop.c index 5be6f998d8c..3d4261c39f1 100644 --- a/drivers/block/cryptoloop.c +++ b/drivers/block/cryptoloop.c @@ -57,9 +57,11 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info) mode = strsep(&cmsp, "-"); if (mode == NULL || strcmp(mode, "cbc") == 0) - tfm = crypto_alloc_tfm(cipher, CRYPTO_TFM_MODE_CBC); + tfm = crypto_alloc_tfm(cipher, CRYPTO_TFM_MODE_CBC | + CRYPTO_TFM_REQ_MAY_SLEEP); else if (strcmp(mode, "ecb") == 0) - tfm = crypto_alloc_tfm(cipher, CRYPTO_TFM_MODE_ECB); + tfm = crypto_alloc_tfm(cipher, CRYPTO_TFM_MODE_ECB | + CRYPTO_TFM_REQ_MAY_SLEEP); if (tfm == NULL) return -EINVAL; diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index f0c1084b840..888dad5eef3 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -493,6 +493,8 @@ static struct floppy_struct user_params[N_DRIVE]; static sector_t floppy_sizes[256]; +static char floppy_device_name[] = "floppy"; + /* * The driver is trying to determine the correct media format * while probing is set. rw_interrupt() clears it after a @@ -4191,18 +4193,24 @@ static int __init floppy_setup(char *str) static int have_no_fdc = -ENODEV; +static ssize_t floppy_cmos_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct platform_device *p; + int drive; + + p = container_of(dev, struct platform_device,dev); + drive = p->id; + return sprintf(buf, "%X\n", UDP->cmos); +} +DEVICE_ATTR(cmos,S_IRUGO,floppy_cmos_show,NULL); + static void floppy_device_release(struct device *dev) { complete(&device_release); } -static struct platform_device floppy_device = { - .name = "floppy", - .id = 0, - .dev = { - .release = floppy_device_release, - } -}; +static struct platform_device floppy_device[N_DRIVE]; static struct kobject *floppy_find(dev_t dev, int *part, void *data) { @@ -4370,20 +4378,26 @@ static int __init floppy_init(void) goto out_flush_work; } - err = platform_device_register(&floppy_device); - if (err) - goto out_flush_work; - for (drive = 0; drive < N_DRIVE; drive++) { if (!(allowed_drive_mask & (1 << drive))) continue; if (fdc_state[FDC(drive)].version == FDC_NONE) continue; + + floppy_device[drive].name = floppy_device_name; + floppy_device[drive].id = drive; + floppy_device[drive].dev.release = floppy_device_release; + + err = platform_device_register(&floppy_device[drive]); + if (err) + goto out_flush_work; + + device_create_file(&floppy_device[drive].dev,&dev_attr_cmos); /* to be cleaned up... */ disks[drive]->private_data = (void *)(long)drive; disks[drive]->queue = floppy_queue; disks[drive]->flags |= GENHD_FL_REMOVABLE; - disks[drive]->driverfs_dev = &floppy_device.dev; + disks[drive]->driverfs_dev = &floppy_device[drive].dev; add_disk(disks[drive]); } @@ -4603,10 +4617,11 @@ void cleanup_module(void) fdc_state[FDC(drive)].version != FDC_NONE) { del_gendisk(disks[drive]); unregister_devfs_entries(drive); + device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); + platform_device_unregister(&floppy_device[drive]); } put_disk(disks[drive]); } - platform_device_unregister(&floppy_device); devfs_remove("floppy"); del_timer_sync(&fd_timeout); diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 7333b41d422..a1de06d76de 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -735,7 +735,7 @@ config SGI_IP27_RTC config GEN_RTC tristate "Generic /dev/rtc emulation" - depends on RTC!=y && !IA64 && !ARM && !PPC64 && !M32R && !SPARC32 + depends on RTC!=y && !IA64 && !ARM && !PPC64 && !M32R && !SPARC32 && !SPARC64 ---help--- If you say Y here and create a character special file /dev/rtc with major number 10 and minor number 135 using mknod ("man mknod"), you @@ -842,8 +842,7 @@ config SONYPI config TANBAC_TB0219 tristate "TANBAC TB0219 base board support" - depends TANBAC_TB0229 - + depends TANBAC_TB022X menu "Ftape, the floppy tape device driver" diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c index 95f7046ff05..79e490ef2cf 100644 --- a/drivers/char/moxa.c +++ b/drivers/char/moxa.c @@ -339,7 +339,7 @@ static int __init moxa_init(void) init_MUTEX(&moxaBuffSem); moxaDriver->owner = THIS_MODULE; - moxaDriver->name = "ttya"; + moxaDriver->name = "ttyMX"; moxaDriver->devfs_name = "tts/a"; moxaDriver->major = ttymajor; moxaDriver->minor_start = 0; diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c index f022f094443..d0ef1ae4129 100644 --- a/drivers/char/mxser.c +++ b/drivers/char/mxser.c @@ -63,7 +63,6 @@ #include <asm/system.h> #include <asm/io.h> #include <asm/irq.h> -#include <asm/segment.h> #include <asm/bitops.h> #include <asm/uaccess.h> diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c index cd4fe8b1709..63fff7c1244 100644 --- a/drivers/char/rtc.c +++ b/drivers/char/rtc.c @@ -938,10 +938,9 @@ found: /* * XXX Interrupt pin #7 in Espresso is shared between RTC and - * PCI Slot 2 INTA# (and some INTx# in Slot 1). SA_INTERRUPT here - * is asking for trouble with add-on boards. Change to SA_SHIRQ. + * PCI Slot 2 INTA# (and some INTx# in Slot 1). */ - if (request_irq(rtc_irq, rtc_interrupt, SA_INTERRUPT, "rtc", (void *)&rtc_port)) { + if (request_irq(rtc_irq, rtc_interrupt, SA_SHIRQ, "rtc", (void *)&rtc_port)) { /* * Standard way for sparc to print irq's is to use * __irq_itoa(). I think for EBus it's ok to use %d. diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c index dc8c540391f..939e51e119e 100644 --- a/drivers/char/tpm/tpm_infineon.c +++ b/drivers/char/tpm/tpm_infineon.c @@ -14,7 +14,6 @@ * License. */ -#include <acpi/acpi_bus.h> #include <linux/pnp.h> #include "tpm.h" @@ -29,9 +28,10 @@ #define TPM_MAX_TRIES 5000 #define TPM_INFINEON_DEV_VEN_VALUE 0x15D1 -/* These values will be filled after ACPI-call */ +/* These values will be filled after PnP-call */ static int TPM_INF_DATA = 0; static int TPM_INF_ADDR = 0; +static int pnp_registered = 0; /* TPM header definitions */ enum infineon_tpm_header { @@ -356,24 +356,26 @@ static const struct pnp_device_id tpm_pnp_tbl[] = { {"IFX0102", 0}, {"", 0} }; +MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl); -static int __devinit tpm_inf_acpi_probe(struct pnp_dev *dev, +static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id) { - TPM_INF_ADDR = (pnp_port_start(dev, 0) & 0xff); - TPM_INF_DATA = ((TPM_INF_ADDR + 1) & 0xff); - tpm_inf.base = pnp_port_start(dev, 1); - dev_info(&dev->dev, "Found %s with ID %s\n", - dev->name, dev_id->id); - if (!((tpm_inf.base >> 8) & 0xff)) - tpm_inf.base = 0; - return 0; + if (pnp_port_valid(dev, 0)) { + TPM_INF_ADDR = (pnp_port_start(dev, 0) & 0xff); + TPM_INF_DATA = ((TPM_INF_ADDR + 1) & 0xff); + tpm_inf.base = pnp_port_start(dev, 1); + dev_info(&dev->dev, "Found %s with ID %s\n", + dev->name, dev_id->id); + return 0; + } + return -ENODEV; } static struct pnp_driver tpm_inf_pnp = { .name = "tpm_inf_pnp", .id_table = tpm_pnp_tbl, - .probe = tpm_inf_acpi_probe, + .probe = tpm_inf_pnp_probe, }; static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, @@ -386,19 +388,30 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, int productid[2]; char chipname[20]; - if (pci_enable_device(pci_dev)) - return -EIO; + rc = pci_enable_device(pci_dev); + if (rc) + return rc; dev_info(&pci_dev->dev, "LPC-bus found at 0x%x\n", pci_id->device); - /* read IO-ports from ACPI */ - pnp_register_driver(&tpm_inf_pnp); - pnp_unregister_driver(&tpm_inf_pnp); + /* read IO-ports from PnP */ + rc = pnp_register_driver(&tpm_inf_pnp); + if (rc < 0) { + dev_err(&pci_dev->dev, + "Error %x from pnp_register_driver!\n",rc); + goto error2; + } + if (!rc) { + dev_info(&pci_dev->dev, "No Infineon TPM found!\n"); + goto error; + } else { + pnp_registered = 1; + } /* Make sure, we have received valid config ports */ if (!TPM_INF_ADDR) { - pci_disable_device(pci_dev); - return -EIO; + dev_err(&pci_dev->dev, "No valid IO-ports received!\n"); + goto error; } /* query chip for its vendor, its version number a.s.o. */ @@ -418,23 +431,21 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, switch ((productid[0] << 8) | productid[1]) { case 6: - sprintf(chipname, " (SLD 9630 TT 1.1)"); + snprintf(chipname, sizeof(chipname), " (SLD 9630 TT 1.1)"); break; case 11: - sprintf(chipname, " (SLB 9635 TT 1.2)"); + snprintf(chipname, sizeof(chipname), " (SLB 9635 TT 1.2)"); break; default: - sprintf(chipname, " (unknown chip)"); + snprintf(chipname, sizeof(chipname), " (unknown chip)"); break; } - chipname[19] = 0; if ((vendorid[0] << 8 | vendorid[1]) == (TPM_INFINEON_DEV_VEN_VALUE)) { if (tpm_inf.base == 0) { dev_err(&pci_dev->dev, "No IO-ports found!\n"); - pci_disable_device(pci_dev); - return -EIO; + goto error; } /* configure TPM with IO-ports */ outb(IOLIMH, TPM_INF_ADDR); @@ -452,8 +463,7 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, dev_err(&pci_dev->dev, "Could not set IO-ports to %04x\n", tpm_inf.base); - pci_disable_device(pci_dev); - return -EIO; + goto error; } /* activate register */ @@ -479,14 +489,16 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, productid[0], productid[1], chipname); rc = tpm_register_hardware(pci_dev, &tpm_inf); - if (rc < 0) { - pci_disable_device(pci_dev); - return -ENODEV; - } + if (rc < 0) + goto error; return 0; } else { dev_info(&pci_dev->dev, "No Infineon TPM found!\n"); +error: + pnp_unregister_driver(&tpm_inf_pnp); +error2: pci_disable_device(pci_dev); + pnp_registered = 0; return -ENODEV; } } @@ -521,6 +533,8 @@ static int __init init_inf(void) static void __exit cleanup_inf(void) { + if (pnp_registered) + pnp_unregister_driver(&tpm_inf_pnp); pci_unregister_driver(&inf_pci_driver); } diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig index b53e2e2b5ae..c3898afce3a 100644 --- a/drivers/char/watchdog/Kconfig +++ b/drivers/char/watchdog/Kconfig @@ -346,6 +346,13 @@ config 8xx_WDT tristate "MPC8xx Watchdog Timer" depends on WATCHDOG && 8xx +config BOOKE_WDT + tristate "PowerPC Book-E Watchdog Timer" + depends on WATCHDOG && (BOOKE || 4xx) + ---help--- + Please see Documentation/watchdog/watchdog-api.txt for + more information. + # MIPS Architecture config INDYDOG diff --git a/drivers/char/watchdog/Makefile b/drivers/char/watchdog/Makefile index c1838834ea7..cfeac6f1013 100644 --- a/drivers/char/watchdog/Makefile +++ b/drivers/char/watchdog/Makefile @@ -2,42 +2,68 @@ # Makefile for the WatchDog device drivers. # +# Only one watchdog can succeed. We probe the ISA/PCI/USB based +# watchdog-cards first, then the architecture specific watchdog +# drivers and then the architecture independant "softdog" driver. +# This means that if your ISA/PCI/USB card isn't detected that +# you can fall back to an architecture specific driver and if +# that also fails then you can fall back to the software watchdog +# to give you some cover. + +# ISA-based Watchdog Cards obj-$(CONFIG_PCWATCHDOG) += pcwd.o -obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o -obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o -obj-$(CONFIG_IB700_WDT) += ib700wdt.o obj-$(CONFIG_MIXCOMWD) += mixcomwd.o -obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o -obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o obj-$(CONFIG_WDT) += wdt.o + +# PCI-based Watchdog Cards +obj-$(CONFIG_PCIPCWATCHDOG) += pcwd_pci.o obj-$(CONFIG_WDTPCI) += wdt_pci.o + +# USB-based Watchdog Cards +obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o + +# ARM Architecture obj-$(CONFIG_21285_WATCHDOG) += wdt285.o obj-$(CONFIG_977_WATCHDOG) += wdt977.o -obj-$(CONFIG_I8XX_TCO) += i8xx_tco.o -obj-$(CONFIG_MACHZ_WDT) += machzwd.o -obj-$(CONFIG_SH_WDT) += shwdt.o +obj-$(CONFIG_IXP2000_WATCHDOG) += ixp2000_wdt.o +obj-$(CONFIG_IXP4XX_WATCHDOG) += ixp4xx_wdt.o obj-$(CONFIG_S3C2410_WATCHDOG) += s3c2410_wdt.o obj-$(CONFIG_SA1100_WATCHDOG) += sa1100_wdt.o -obj-$(CONFIG_EUROTECH_WDT) += eurotechwdt.o -obj-$(CONFIG_W83877F_WDT) += w83877f_wdt.o -obj-$(CONFIG_W83627HF_WDT) += w83627hf_wdt.o -obj-$(CONFIG_SC520_WDT) += sc520_wdt.o -obj-$(CONFIG_ALIM7101_WDT) += alim7101_wdt.o + +# X86 (i386 + ia64 + x86_64) Architecture +obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o +obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o obj-$(CONFIG_ALIM1535_WDT) += alim1535_wdt.o -obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o +obj-$(CONFIG_ALIM7101_WDT) += alim7101_wdt.o +obj-$(CONFIG_SC520_WDT) += sc520_wdt.o +obj-$(CONFIG_EUROTECH_WDT) += eurotechwdt.o +obj-$(CONFIG_IB700_WDT) += ib700wdt.o obj-$(CONFIG_WAFER_WDT) += wafer5823wdt.o +obj-$(CONFIG_I8XX_TCO) += i8xx_tco.o +obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o +obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o +obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o obj-$(CONFIG_CPU5_WDT) += cpu5wdt.o -obj-$(CONFIG_INDYDOG) += indydog.o -obj-$(CONFIG_PCIPCWATCHDOG) += pcwd_pci.o -obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o -obj-$(CONFIG_IXP4XX_WATCHDOG) += ixp4xx_wdt.o -obj-$(CONFIG_IXP2000_WATCHDOG) += ixp2000_wdt.o +obj-$(CONFIG_W83627HF_WDT) += w83627hf_wdt.o +obj-$(CONFIG_W83877F_WDT) += w83877f_wdt.o +obj-$(CONFIG_MACHZ_WDT) += machzwd.o + +# PowerPC Architecture obj-$(CONFIG_8xx_WDT) += mpc8xx_wdt.o + +# PPC64 Architecture obj-$(CONFIG_WATCHDOG_RTAS) += wdrtas.o +obj-$(CONFIG_BOOKE_WDT) += booke_wdt.o + +# MIPS Architecture +obj-$(CONFIG_INDYDOG) += indydog.o + +# S390 Architecture + +# SUPERH Architecture +obj-$(CONFIG_SH_WDT) += shwdt.o -# Only one watchdog can succeed. We probe the hardware watchdog -# drivers first, then the softdog driver. This means if your hardware -# watchdog dies or is 'borrowed' for some reason the software watchdog -# still gives you some cover. +# SPARC64 Architecture +# Architecture Independant obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o diff --git a/drivers/char/watchdog/booke_wdt.c b/drivers/char/watchdog/booke_wdt.c new file mode 100644 index 00000000000..abc30cca664 --- /dev/null +++ b/drivers/char/watchdog/booke_wdt.c @@ -0,0 +1,192 @@ +/* + * drivers/char/watchdog/booke_wdt.c + * + * Watchdog timer for PowerPC Book-E systems + * + * Author: Matthew McClintock + * Maintainer: Kumar Gala <kumar.gala@freescale.com> + * + * Copyright 2005 Freescale Semiconductor Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#include <linux/config.h> +#include <linux/module.h> +#include <linux/fs.h> +#include <linux/miscdevice.h> +#include <linux/notifier.h> +#include <linux/watchdog.h> + +#include <asm/reg_booke.h> +#include <asm/uaccess.h> +#include <asm/system.h> + +/* If the kernel parameter wdt_enable=1, the watchdog will be enabled at boot. + * Also, the wdt_period sets the watchdog timer period timeout. + * For E500 cpus the wdt_period sets which bit changing from 0->1 will + * trigger a watchog timeout. This watchdog timeout will occur 3 times, the + * first time nothing will happen, the second time a watchdog exception will + * occur, and the final time the board will reset. + */ + +#ifdef CONFIG_FSL_BOOKE +#define WDT_PERIOD_DEFAULT 63 /* Ex. wdt_period=28 bus=333Mhz , reset=~40sec */ +#else +#define WDT_PERIOD_DEFAULT 4 /* Refer to the PPC40x and PPC4xx manuals */ +#endif /* for timing information */ + +u32 booke_wdt_enabled = 0; +u32 booke_wdt_period = WDT_PERIOD_DEFAULT; + +#ifdef CONFIG_FSL_BOOKE +#define WDTP(x) ((((63-x)&0x3)<<30)|(((63-x)&0x3c)<<15)) +#else +#define WDTP(x) (TCR_WP(x)) +#endif + +/* + * booke_wdt_enable: + */ +static __inline__ void booke_wdt_enable(void) +{ + u32 val; + + val = mfspr(SPRN_TCR); + val |= (TCR_WIE|TCR_WRC(WRC_CHIP)|WDTP(booke_wdt_period)); + + mtspr(SPRN_TCR, val); +} + +/* + * booke_wdt_ping: + */ +static __inline__ void booke_wdt_ping(void) +{ + mtspr(SPRN_TSR, TSR_ENW|TSR_WIS); +} + +/* + * booke_wdt_write: + */ +static ssize_t booke_wdt_write (struct file *file, const char *buf, + size_t count, loff_t *ppos) +{ + booke_wdt_ping(); + return count; +} + +static struct watchdog_info ident = { + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING, + .firmware_version = 0, + .identity = "PowerPC Book-E Watchdog", +}; + +/* + * booke_wdt_ioctl: + */ +static int booke_wdt_ioctl (struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) +{ + u32 tmp = 0; + + switch (cmd) { + case WDIOC_GETSUPPORT: + if (copy_to_user ((struct watchdog_info *) arg, &ident, + sizeof(struct watchdog_info))) + return -EFAULT; + case WDIOC_GETSTATUS: + return put_user(ident.options, (u32 *) arg); + case WDIOC_GETBOOTSTATUS: + /* XXX: something is clearing TSR */ + tmp = mfspr(SPRN_TSR) & TSR_WRS(3); + /* returns 1 if last reset was caused by the WDT */ + return (tmp ? 1 : 0); + case WDIOC_KEEPALIVE: + booke_wdt_ping(); + return 0; + case WDIOC_SETTIMEOUT: + if (get_user(booke_wdt_period, (u32 *) arg)) + return -EFAULT; + mtspr(SPRN_TCR, (mfspr(SPRN_TCR)&~WDTP(0))|WDTP(booke_wdt_period)); + return 0; + case WDIOC_GETTIMEOUT: + return put_user(booke_wdt_period, (u32 *) arg); + case WDIOC_SETOPTIONS: + if (get_user(tmp, (u32 *) arg)) + return -EINVAL; + if (tmp == WDIOS_ENABLECARD) { + booke_wdt_ping(); + break; + } else + return -EINVAL; + return 0; + default: + return -ENOIOCTLCMD; + } + + return 0; +} +/* + * booke_wdt_open: + */ +static int booke_wdt_open (struct inode *inode, struct file *file) +{ + if (booke_wdt_enabled == 0) { + booke_wdt_enabled = 1; + booke_wdt_enable(); + printk (KERN_INFO "PowerPC Book-E Watchdog Timer Enabled (wdt_period=%d)\n", + booke_wdt_period); + } + + return 0; +} + +static struct file_operations booke_wdt_fops = { + .owner = THIS_MODULE, + .llseek = no_llseek, + .write = booke_wdt_write, + .ioctl = booke_wdt_ioctl, + .open = booke_wdt_open, +}; + +static struct miscdevice booke_wdt_miscdev = { + .minor = WATCHDOG_MINOR, + .name = "watchdog", + .fops = &booke_wdt_fops, +}; + +static void __exit booke_wdt_exit(void) +{ + misc_deregister(&booke_wdt_miscdev); +} + +/* + * booke_wdt_init: + */ +static int __init booke_wdt_init(void) +{ + int ret = 0; + + printk (KERN_INFO "PowerPC Book-E Watchdog Timer Loaded\n"); + ident.firmware_version = cpu_specs[0].pvr_value; + + ret = misc_register(&booke_wdt_miscdev); + if (ret) { + printk (KERN_CRIT "Cannot register miscdev on minor=%d (err=%d)\n", + WATCHDOG_MINOR, ret); + return ret; + } + + if (booke_wdt_enabled == 1) { + printk (KERN_INFO "PowerPC Book-E Watchdog Timer Enabled (wdt_period=%d)\n", + booke_wdt_period); + booke_wdt_enable(); + } + + return ret; +} +device_initcall(booke_wdt_init); diff --git a/drivers/char/watchdog/ixp2000_wdt.c b/drivers/char/watchdog/ixp2000_wdt.c index e7640bc4904..0cfb9b9c4a4 100644 --- a/drivers/char/watchdog/ixp2000_wdt.c +++ b/drivers/char/watchdog/ixp2000_wdt.c @@ -182,7 +182,7 @@ static struct file_operations ixp2000_wdt_fops = static struct miscdevice ixp2000_wdt_miscdev = { .minor = WATCHDOG_MINOR, - .name = "IXP2000 Watchdog", + .name = "watchdog", .fops = &ixp2000_wdt_fops, }; diff --git a/drivers/char/watchdog/ixp4xx_wdt.c b/drivers/char/watchdog/ixp4xx_wdt.c index 8d916afbf4f..b5be8b11104 100644 --- a/drivers/char/watchdog/ixp4xx_wdt.c +++ b/drivers/char/watchdog/ixp4xx_wdt.c @@ -176,7 +176,7 @@ static struct file_operations ixp4xx_wdt_fops = static struct miscdevice ixp4xx_wdt_miscdev = { .minor = WATCHDOG_MINOR, - .name = "IXP4xx Watchdog", + .name = "watchdog", .fops = &ixp4xx_wdt_fops, }; diff --git a/drivers/char/watchdog/s3c2410_wdt.c b/drivers/char/watchdog/s3c2410_wdt.c index f85ac898a49..8b292bf343c 100644 --- a/drivers/char/watchdog/s3c2410_wdt.c +++ b/drivers/char/watchdog/s3c2410_wdt.c @@ -27,7 +27,10 @@ * Fixed tmr_count / wdt_count confusion * Added configurable debug * - * 11-Jan-2004 BJD Fixed divide-by-2 in timeout code + * 11-Jan-2005 BJD Fixed divide-by-2 in timeout code + * + * 25-Jan-2005 DA Added suspend/resume support + * Replaced reboot notifier with .shutdown method * * 10-Mar-2005 LCVR Changed S3C2410_VA to S3C24XX_VA */ @@ -40,8 +43,6 @@ #include <linux/miscdevice.h> #include <linux/watchdog.h> #include <linux/fs.h> -#include <linux/notifier.h> -#include <linux/reboot.h> #include <linux/init.h> #include <linux/device.h> #include <linux/interrupt.h> @@ -317,20 +318,6 @@ static int s3c2410wdt_ioctl(struct inode *inode, struct file *file, } } -/* - * Notifier for system down - */ - -static int s3c2410wdt_notify_sys(struct notifier_block *this, unsigned long code, - void *unused) -{ - if(code==SYS_DOWN || code==SYS_HALT) { - /* Turn the WDT off */ - s3c2410wdt_stop(); - } - return NOTIFY_DONE; -} - /* kernel interface */ static struct file_operations s3c2410wdt_fops = { @@ -348,10 +335,6 @@ static struct miscdevice s3c2410wdt_miscdev = { .fops = &s3c2410wdt_fops, }; -static struct notifier_block s3c2410wdt_notifier = { - .notifier_call = s3c2410wdt_notify_sys, -}; - /* interrupt handler code */ static irqreturn_t s3c2410wdt_irq(int irqno, void *param, @@ -432,18 +415,10 @@ static int s3c2410wdt_probe(struct device *dev) } } - ret = register_reboot_notifier(&s3c2410wdt_notifier); - if (ret) { - printk (KERN_ERR PFX "cannot register reboot notifier (%d)\n", - ret); - return ret; - } - ret = misc_register(&s3c2410wdt_miscdev); if (ret) { printk (KERN_ERR PFX "cannot register miscdev on minor=%d (%d)\n", WATCHDOG_MINOR, ret); - unregister_reboot_notifier(&s3c2410wdt_notifier); return ret; } @@ -479,15 +454,63 @@ static int s3c2410wdt_remove(struct device *dev) return 0; } +static void s3c2410wdt_shutdown(struct device *dev) +{ + s3c2410wdt_stop(); +} + +#ifdef CONFIG_PM + +static unsigned long wtcon_save; +static unsigned long wtdat_save; + +static int s3c2410wdt_suspend(struct device *dev, u32 state, u32 level) +{ + if (level == SUSPEND_POWER_DOWN) { + /* Save watchdog state, and turn it off. */ + wtcon_save = readl(wdt_base + S3C2410_WTCON); + wtdat_save = readl(wdt_base + S3C2410_WTDAT); + + /* Note that WTCNT doesn't need to be saved. */ + s3c2410wdt_stop(); + } + + return 0; +} + +static int s3c2410wdt_resume(struct device *dev, u32 level) +{ + if (level == RESUME_POWER_ON) { + /* Restore watchdog state. */ + + writel(wtdat_save, wdt_base + S3C2410_WTDAT); + writel(wtdat_save, wdt_base + S3C2410_WTCNT); /* Reset count */ + writel(wtcon_save, wdt_base + S3C2410_WTCON); + + printk(KERN_INFO PFX "watchdog %sabled\n", + (wtcon_save & S3C2410_WTCON_ENABLE) ? "en" : "dis"); + } + + return 0; +} + +#else +#define s3c2410wdt_suspend NULL +#define s3c2410wdt_resume NULL +#endif /* CONFIG_PM */ + + static struct device_driver s3c2410wdt_driver = { .name = "s3c2410-wdt", .bus = &platform_bus_type, .probe = s3c2410wdt_probe, .remove = s3c2410wdt_remove, + .shutdown = s3c2410wdt_shutdown, + .suspend = s3c2410wdt_suspend, + .resume = s3c2410wdt_resume, }; - static char banner[] __initdata = KERN_INFO "S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics\n"; static int __init watchdog_init(void) @@ -499,13 +522,13 @@ static int __init watchdog_init(void) static void __exit watchdog_exit(void) { driver_unregister(&s3c2410wdt_driver); - unregister_reboot_notifier(&s3c2410wdt_notifier); } module_init(watchdog_init); module_exit(watchdog_exit); -MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); +MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, " + "Dimitry Andric <dimitry.andric@tomtom.com>"); MODULE_DESCRIPTION("S3C2410 Watchdog Device Driver"); MODULE_LICENSE("GPL"); MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); diff --git a/drivers/char/watchdog/scx200_wdt.c b/drivers/char/watchdog/scx200_wdt.c index c4568569f3a..b4a102a2d7e 100644 --- a/drivers/char/watchdog/scx200_wdt.c +++ b/drivers/char/watchdog/scx200_wdt.c @@ -206,7 +206,7 @@ static struct file_operations scx200_wdt_fops = { static struct miscdevice scx200_wdt_miscdev = { .minor = WATCHDOG_MINOR, - .name = NAME, + .name = "watchdog", .fops = &scx200_wdt_fops, }; diff --git a/drivers/char/watchdog/softdog.c b/drivers/char/watchdog/softdog.c index 4d7ed931f5c..20e5eb8667f 100644 --- a/drivers/char/watchdog/softdog.c +++ b/drivers/char/watchdog/softdog.c @@ -77,7 +77,7 @@ static void watchdog_fire(unsigned long); static struct timer_list watchdog_ticktock = TIMER_INITIALIZER(watchdog_fire, 0, 0); -static unsigned long timer_alive; +static unsigned long driver_open, orphan_timer; static char expect_close; @@ -87,6 +87,9 @@ static char expect_close; static void watchdog_fire(unsigned long data) { + if (test_and_clear_bit(0, &orphan_timer)) + module_put(THIS_MODULE); + if (soft_noboot) printk(KERN_CRIT PFX "Triggered - Reboot ignored.\n"); else @@ -128,9 +131,9 @@ static int softdog_set_heartbeat(int t) static int softdog_open(struct inode *inode, struct file *file) { - if(test_and_set_bit(0, &timer_alive)) + if (test_and_set_bit(0, &driver_open)) return -EBUSY; - if (nowayout) + if (!test_and_clear_bit(0, &orphan_timer)) __module_get(THIS_MODULE); /* * Activate timer @@ -147,11 +150,13 @@ static int softdog_release(struct inode *inode, struct file *file) */ if (expect_close == 42) { softdog_stop(); + module_put(THIS_MODULE); } else { printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); + set_bit(0, &orphan_timer); softdog_keepalive(); } - clear_bit(0, &timer_alive); + clear_bit(0, &driver_open); expect_close = 0; return 0; } diff --git a/drivers/char/watchdog/w83627hf_wdt.c b/drivers/char/watchdog/w83627hf_wdt.c index 465e0fd0423..b5d82101542 100644 --- a/drivers/char/watchdog/w83627hf_wdt.c +++ b/drivers/char/watchdog/w83627hf_wdt.c @@ -93,6 +93,12 @@ w83627hf_init(void) w83627hf_select_wd_register(); + outb_p(0xF6, WDT_EFER); /* Select CRF6 */ + t=inb_p(WDT_EFDR); /* read CRF6 */ + if (t != 0) { + printk (KERN_INFO PFX "Watchdog already running. Resetting timeout to %d sec\n", timeout); + outb_p(timeout, WDT_EFDR); /* Write back to CRF6 */ + } outb_p(0xF5, WDT_EFER); /* Select CRF5 */ t=inb_p(WDT_EFDR); /* read CRF5 */ t&=~0x0C; /* set second mode & disable keyboard turning off watchdog */ diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 140d5f851a5..138dc50270e 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -12,12 +12,20 @@ config HWMON of a system. Most modern motherboards include such a device. It can include temperature sensors, voltage sensors, fan speed sensors and various additional features such as the ability to - control the speed of the fans. + control the speed of the fans. If you want this support you + should say Y here and also to the specific driver(s) for your + sensors chip(s) below. + + This support can also be built as a module. If so, the module + will be called hwmon. + +config HWMON_VID + tristate + default n config SENSORS_ADM1021 tristate "Analog Devices ADM1021 and compatibles" depends on HWMON && I2C - select I2C_SENSOR help If you say yes here you get support for Analog Devices ADM1021 and ADM1023 sensor chips and clones: Maxim MAX1617 and MAX1617A, @@ -30,7 +38,7 @@ config SENSORS_ADM1021 config SENSORS_ADM1025 tristate "Analog Devices ADM1025 and compatibles" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR + select HWMON_VID help If you say yes here you get support for Analog Devices ADM1025 and Philips NE1619 sensor chips. @@ -41,7 +49,7 @@ config SENSORS_ADM1025 config SENSORS_ADM1026 tristate "Analog Devices ADM1026 and compatibles" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR + select HWMON_VID help If you say yes here you get support for Analog Devices ADM1026 sensor chip. @@ -52,7 +60,6 @@ config SENSORS_ADM1026 config SENSORS_ADM1031 tristate "Analog Devices ADM1031 and compatibles" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for Analog Devices ADM1031 and ADM1030 sensor chips. @@ -63,7 +70,7 @@ config SENSORS_ADM1031 config SENSORS_ADM9240 tristate "Analog Devices ADM9240 and compatibles" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR + select HWMON_VID help If you say yes here you get support for Analog Devices ADM9240, Dallas DS1780, National Semiconductor LM81 sensor chips. @@ -74,7 +81,7 @@ config SENSORS_ADM9240 config SENSORS_ASB100 tristate "Asus ASB100 Bach" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR + select HWMON_VID help If you say yes here you get support for the ASB100 Bach sensor chip found on some Asus mainboards. @@ -85,7 +92,7 @@ config SENSORS_ASB100 config SENSORS_ATXP1 tristate "Attansic ATXP1 VID controller" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR + select HWMON_VID help If you say yes here you get support for the Attansic ATXP1 VID controller. @@ -99,7 +106,6 @@ config SENSORS_ATXP1 config SENSORS_DS1621 tristate "Dallas Semiconductor DS1621 and DS1625" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for Dallas Semiconductor DS1621 and DS1625 sensor chips. @@ -110,7 +116,6 @@ config SENSORS_DS1621 config SENSORS_FSCHER tristate "FSC Hermes" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for Fujitsu Siemens Computers Hermes sensor chips. @@ -121,7 +126,6 @@ config SENSORS_FSCHER config SENSORS_FSCPOS tristate "FSC Poseidon" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for Fujitsu Siemens Computers Poseidon sensor chips. @@ -132,7 +136,6 @@ config SENSORS_FSCPOS config SENSORS_GL518SM tristate "Genesys Logic GL518SM" depends on HWMON && I2C - select I2C_SENSOR help If you say yes here you get support for Genesys Logic GL518SM sensor chips. @@ -143,7 +146,7 @@ config SENSORS_GL518SM config SENSORS_GL520SM tristate "Genesys Logic GL520SM" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR + select HWMON_VID help If you say yes here you get support for Genesys Logic GL520SM sensor chips. @@ -154,7 +157,8 @@ config SENSORS_GL520SM config SENSORS_IT87 tristate "ITE IT87xx and compatibles" depends on HWMON && I2C - select I2C_SENSOR + select I2C_ISA + select HWMON_VID help If you say yes here you get support for ITE IT87xx sensor chips and clones: SiS960. @@ -165,7 +169,6 @@ config SENSORS_IT87 config SENSORS_LM63 tristate "National Semiconductor LM63" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for the National Semiconductor LM63 remote diode digital temperature sensor with integrated fan @@ -178,7 +181,6 @@ config SENSORS_LM63 config SENSORS_LM75 tristate "National Semiconductor LM75 and compatibles" depends on HWMON && I2C - select I2C_SENSOR help If you say yes here you get support for National Semiconductor LM75 sensor chips and clones: Dallas Semiconductor DS75 and DS1775 (in @@ -194,7 +196,6 @@ config SENSORS_LM75 config SENSORS_LM77 tristate "National Semiconductor LM77" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for National Semiconductor LM77 sensor chips. @@ -205,7 +206,8 @@ config SENSORS_LM77 config SENSORS_LM78 tristate "National Semiconductor LM78 and compatibles" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR + select I2C_ISA + select HWMON_VID help If you say yes here you get support for National Semiconductor LM78, LM78-J and LM79. @@ -216,7 +218,6 @@ config SENSORS_LM78 config SENSORS_LM80 tristate "National Semiconductor LM80" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for National Semiconductor LM80 sensor chips. @@ -227,7 +228,6 @@ config SENSORS_LM80 config SENSORS_LM83 tristate "National Semiconductor LM83" depends on HWMON && I2C - select I2C_SENSOR help If you say yes here you get support for National Semiconductor LM83 sensor chips. @@ -238,7 +238,7 @@ config SENSORS_LM83 config SENSORS_LM85 tristate "National Semiconductor LM85 and compatibles" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR + select HWMON_VID help If you say yes here you get support for National Semiconductor LM85 sensor chips and clones: ADT7463, EMC6D100, EMC6D102 and ADM1027. @@ -249,7 +249,7 @@ config SENSORS_LM85 config SENSORS_LM87 tristate "National Semiconductor LM87" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR + select HWMON_VID help If you say yes here you get support for National Semiconductor LM87 sensor chips. @@ -260,7 +260,6 @@ config SENSORS_LM87 config SENSORS_LM90 tristate "National Semiconductor LM90 and compatibles" depends on HWMON && I2C - select I2C_SENSOR help If you say yes here you get support for National Semiconductor LM90, LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657 and @@ -275,7 +274,6 @@ config SENSORS_LM90 config SENSORS_LM92 tristate "National Semiconductor LM92 and compatibles" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for National Semiconductor LM92 and Maxim MAX6635 sensor chips. @@ -286,7 +284,6 @@ config SENSORS_LM92 config SENSORS_MAX1619 tristate "Maxim MAX1619 sensor chip" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for MAX1619 sensor chip. @@ -296,8 +293,8 @@ config SENSORS_MAX1619 config SENSORS_PC87360 tristate "National Semiconductor PC87360 family" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR select I2C_ISA + select HWMON_VID help If you say yes here you get access to the hardware monitoring functions of the National Semiconductor PC8736x Super-I/O chips. @@ -311,7 +308,6 @@ config SENSORS_PC87360 config SENSORS_SIS5595 tristate "Silicon Integrated Systems Corp. SiS5595" depends on HWMON && I2C && PCI && EXPERIMENTAL - select I2C_SENSOR select I2C_ISA help If you say yes here you get support for the integrated sensors in @@ -323,7 +319,6 @@ config SENSORS_SIS5595 config SENSORS_SMSC47M1 tristate "SMSC LPC47M10x and compatibles" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR select I2C_ISA help If you say yes here you get support for the integrated fan @@ -336,7 +331,6 @@ config SENSORS_SMSC47M1 config SENSORS_SMSC47B397 tristate "SMSC LPC47B397-NC" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR select I2C_ISA help If you say yes here you get support for the SMSC LPC47B397-NC @@ -348,7 +342,6 @@ config SENSORS_SMSC47B397 config SENSORS_VIA686A tristate "VIA686A" depends on HWMON && I2C && PCI - select I2C_SENSOR select I2C_ISA help If you say yes here you get support for the integrated sensors in @@ -360,7 +353,8 @@ config SENSORS_VIA686A config SENSORS_W83781D tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F" depends on HWMON && I2C - select I2C_SENSOR + select I2C_ISA + select HWMON_VID help If you say yes here you get support for the Winbond W8378x series of sensor chips: the W83781D, W83782D, W83783S and W83627HF, @@ -369,10 +363,18 @@ config SENSORS_W83781D This driver can also be built as a module. If so, the module will be called w83781d. +config SENSORS_W83792D + tristate "Winbond W83792D" + depends on HWMON && I2C && EXPERIMENTAL + help + If you say yes here you get support for the Winbond W83792D chip. + + This driver can also be built as a module. If so, the module + will be called w83792d. + config SENSORS_W83L785TS tristate "Winbond W83L785TS-S" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for the Winbond W83L785TS-S sensor chip, which is used on the Asus A7N8X, among other @@ -384,8 +386,8 @@ config SENSORS_W83L785TS config SENSORS_W83627HF tristate "Winbond W83627HF, W83627THF, W83637HF, W83697HF" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR select I2C_ISA + select HWMON_VID help If you say yes here you get support for the Winbond W836X7 series of sensor chips: the W83627HF, W83627THF, W83637HF, and the W83697HF @@ -396,7 +398,6 @@ config SENSORS_W83627HF config SENSORS_W83627EHF tristate "Winbond W83627EHF" depends on HWMON && I2C && EXPERIMENTAL - select I2C_SENSOR select I2C_ISA help If you say yes here you get preliminary support for the hardware @@ -404,6 +405,9 @@ config SENSORS_W83627EHF Only fan and temperature inputs are supported at the moment, while the chip does much more than that. + This driver also supports the W83627EHG, which is the lead-free + version of the W83627EHF. + This driver can also be built as a module. If so, the module will be called w83627ehf. diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 2781403a023..381f1bf04cc 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -2,9 +2,13 @@ # Makefile for sensor chip drivers. # +obj-$(CONFIG_HWMON) += hwmon.o +obj-$(CONFIG_HWMON_VID) += hwmon-vid.o + # asb100, then w83781d go first, as they can override other drivers' addresses. obj-$(CONFIG_SENSORS_ASB100) += asb100.o obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o +obj-$(CONFIG_SENSORS_W83792D) += w83792d.o obj-$(CONFIG_SENSORS_W83781D) += w83781d.o obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c index d2c774c32f4..e928cdb041c 100644 --- a/drivers/hwmon/adm1021.c +++ b/drivers/hwmon/adm1021.c @@ -24,7 +24,8 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/hwmon.h> +#include <linux/err.h> /* Addresses to scan */ @@ -32,10 +33,9 @@ static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_8(adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, mc1066); +I2C_CLIENT_INSMOD_8(adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, mc1066); /* adm1021 constants specified below */ @@ -89,6 +89,7 @@ clearing it. Weird, ey? --Phil */ /* Each client has this additional data */ struct adm1021_data { struct i2c_client client; + struct class_device *class_dev; enum chips type; struct semaphore update_lock; @@ -185,7 +186,7 @@ static int adm1021_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, adm1021_detect); + return i2c_probe(adapter, &addr_data, adm1021_detect); } static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) @@ -196,15 +197,6 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) int err = 0; const char *type_name = ""; - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; i2c_detect really won't call us. */ -#ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - dev_dbg(&adapter->dev, "adm1021_detect called for an ISA bus adapter?!?\n"); - return 0; - } -#endif - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) goto error0; @@ -295,6 +287,12 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) adm1021_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto error2; + } + device_create_file(&new_client->dev, &dev_attr_temp1_max); device_create_file(&new_client->dev, &dev_attr_temp1_min); device_create_file(&new_client->dev, &dev_attr_temp1_input); @@ -305,6 +303,8 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +error2: + i2c_detach_client(new_client); error1: kfree(data); error0: @@ -322,14 +322,15 @@ static void adm1021_init_client(struct i2c_client *client) static int adm1021_detach_client(struct i2c_client *client) { + struct adm1021_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c index e452d0daf90..526b7ff179e 100644 --- a/drivers/hwmon/adm1025.c +++ b/drivers/hwmon/adm1025.c @@ -50,8 +50,9 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> -#include <linux/i2c-vid.h> +#include <linux/hwmon.h> +#include <linux/hwmon-vid.h> +#include <linux/err.h> /* * Addresses to scan @@ -60,13 +61,12 @@ */ static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* * Insmod parameters */ -SENSORS_INSMOD_2(adm1025, ne1619); +I2C_CLIENT_INSMOD_2(adm1025, ne1619); /* * The ADM1025 registers @@ -132,6 +132,7 @@ static struct i2c_driver adm1025_driver = { struct adm1025_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* zero until following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -312,7 +313,7 @@ static int adm1025_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, adm1025_detect); + return i2c_probe(adapter, &addr_data, adm1025_detect); } /* @@ -416,6 +417,12 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) adm1025_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_in0_input); device_create_file(&new_client->dev, &dev_attr_in1_input); device_create_file(&new_client->dev, &dev_attr_in2_input); @@ -452,6 +459,8 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -464,7 +473,7 @@ static void adm1025_init_client(struct i2c_client *client) struct adm1025_data *data = i2c_get_clientdata(client); int i; - data->vrm = i2c_which_vrm(); + data->vrm = vid_which_vrm(); /* * Set high limits @@ -502,15 +511,15 @@ static void adm1025_init_client(struct i2c_client *client) static int adm1025_detach_client(struct i2c_client *client) { + struct adm1025_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c index c8a7f47911f..625158110fd 100644 --- a/drivers/hwmon/adm1026.c +++ b/drivers/hwmon/adm1026.c @@ -28,16 +28,16 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> -#include <linux/i2c-vid.h> +#include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> +#include <linux/hwmon-vid.h> +#include <linux/err.h> /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_1(adm1026); +I2C_CLIENT_INSMOD_1(adm1026); static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; @@ -259,6 +259,7 @@ struct pwm_data { struct adm1026_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; enum chips type; @@ -319,13 +320,15 @@ int adm1026_attach_adapter(struct i2c_adapter *adapter) if (!(adapter->class & I2C_CLASS_HWMON)) { return 0; } - return i2c_detect(adapter, &addr_data, adm1026_detect); + return i2c_probe(adapter, &addr_data, adm1026_detect); } int adm1026_detach_client(struct i2c_client *client) { + struct adm1026_data *data = i2c_get_clientdata(client); + hwmon_device_unregister(data->class_dev); i2c_detach_client(client); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } @@ -1549,12 +1552,18 @@ int adm1026_detect(struct i2c_adapter *adapter, int address, goto exitfree; /* Set the VRM version */ - data->vrm = i2c_which_vrm(); + data->vrm = vid_which_vrm(); /* Initialize the ADM1026 chip */ adm1026_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exitdetach; + } + device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr); device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr); @@ -1690,6 +1699,8 @@ int adm1026_detect(struct i2c_adapter *adapter, int address, return 0; /* Error out and cleanup code */ +exitdetach: + i2c_detach_client(new_client); exitfree: kfree(data); exit: diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c index 93625095727..58338ed7c8a 100644 --- a/drivers/hwmon/adm1031.c +++ b/drivers/hwmon/adm1031.c @@ -26,7 +26,8 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/hwmon.h> +#include <linux/err.h> /* Following macros takes channel parameter starting from 0 to 2 */ #define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) @@ -59,16 +60,16 @@ /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_2(adm1030, adm1031); +I2C_CLIENT_INSMOD_2(adm1030, adm1031); typedef u8 auto_chan_table_t[8][2]; /* Each client has this additional data */ struct adm1031_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; int chip_type; char valid; /* !=0 if following fields are valid */ @@ -725,10 +726,10 @@ static int adm1031_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, adm1031_detect); + return i2c_probe(adapter, &addr_data, adm1031_detect); } -/* This function is called by i2c_detect */ +/* This function is called by i2c_probe */ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) { struct i2c_client *new_client; @@ -788,6 +789,12 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) adm1031_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_fan1_input); device_create_file(&new_client->dev, &dev_attr_fan1_div); device_create_file(&new_client->dev, &dev_attr_fan1_min); @@ -833,6 +840,8 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -841,11 +850,14 @@ exit: static int adm1031_detach_client(struct i2c_client *client) { + struct adm1031_data *data = i2c_get_clientdata(client); int ret; + + hwmon_device_unregister(data->class_dev); if ((ret = i2c_detach_client(client)) != 0) { return ret; } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c index ce2a6eb93f6..bc7faef162f 100644 --- a/drivers/hwmon/adm9240.c +++ b/drivers/hwmon/adm9240.c @@ -45,17 +45,16 @@ #include <linux/module.h> #include <linux/slab.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> -#include <linux/i2c-vid.h> +#include <linux/hwmon.h> +#include <linux/hwmon-vid.h> +#include <linux/err.h> /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; - /* Insmod parameters */ -SENSORS_INSMOD_3(adm9240, ds1780, lm81); +I2C_CLIENT_INSMOD_3(adm9240, ds1780, lm81); /* ADM9240 registers */ #define ADM9240_REG_MAN_ID 0x3e @@ -150,6 +149,7 @@ static struct i2c_driver adm9240_driver = { struct adm9240_data { enum chips type; struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; unsigned long last_updated_measure; @@ -582,6 +582,12 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) adm9240_init_client(new_client); /* populate sysfs filesystem */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_in0_input); device_create_file(&new_client->dev, &dev_attr_in0_min); device_create_file(&new_client->dev, &dev_attr_in0_max); @@ -615,6 +621,9 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) device_create_file(&new_client->dev, &dev_attr_cpu0_vid); return 0; + +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -625,20 +634,20 @@ static int adm9240_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, adm9240_detect); + return i2c_probe(adapter, &addr_data, adm9240_detect); } static int adm9240_detach_client(struct i2c_client *client) { + struct adm9240_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } @@ -648,7 +657,7 @@ static void adm9240_init_client(struct i2c_client *client) u8 conf = adm9240_read_value(client, ADM9240_REG_CONFIG); u8 mode = adm9240_read_value(client, ADM9240_REG_TEMP_CONF) & 3; - data->vrm = i2c_which_vrm(); /* need this to report vid as mV */ + data->vrm = vid_which_vrm(); /* need this to report vid as mV */ dev_info(&client->dev, "Using VRM: %d.%d\n", data->vrm / 10, data->vrm % 10); diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c index 70d996d6fe0..8e34855a627 100644 --- a/drivers/hwmon/asb100.c +++ b/drivers/hwmon/asb100.c @@ -39,8 +39,9 @@ #include <linux/module.h> #include <linux/slab.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> -#include <linux/i2c-vid.h> +#include <linux/hwmon.h> +#include <linux/hwmon-vid.h> +#include <linux/err.h> #include <linux/init.h> #include <linux/jiffies.h> #include "lm75.h" @@ -54,11 +55,8 @@ /* I2C addresses to scan */ static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END }; -/* ISA addresses to scan (none) */ -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; - /* Insmod parameters */ -SENSORS_INSMOD_1(asb100); +I2C_CLIENT_INSMOD_1(asb100); I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: " "{bus, clientaddr, subclientaddr1, subclientaddr2}"); @@ -183,6 +181,7 @@ static u8 DIV_TO_REG(long val) dynamically allocated, at the same time the client itself is allocated. */ struct asb100_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; enum chips type; @@ -621,7 +620,7 @@ static int asb100_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, asb100_detect); + return i2c_probe(adapter, &addr_data, asb100_detect); } static int asb100_detect_subclients(struct i2c_adapter *adapter, int address, @@ -714,14 +713,6 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) struct i2c_client *new_client; struct asb100_data *data; - /* asb100 is SMBus only */ - if (i2c_is_isa_adapter(adapter)) { - pr_debug("asb100.o: detect failed, " - "cannot attach to legacy adapter!\n"); - err = -ENODEV; - goto ERROR0; - } - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { pr_debug("asb100.o: detect failed, " "smbus byte data not supported!\n"); @@ -821,6 +812,12 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2)); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto ERROR3; + } + device_create_file_in(new_client, 0); device_create_file_in(new_client, 1); device_create_file_in(new_client, 2); @@ -847,6 +844,11 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +ERROR3: + i2c_detach_client(data->lm75[1]); + i2c_detach_client(data->lm75[0]); + kfree(data->lm75[1]); + kfree(data->lm75[0]); ERROR2: i2c_detach_client(new_client); ERROR1: @@ -857,21 +859,23 @@ ERROR0: static int asb100_detach_client(struct i2c_client *client) { + struct asb100_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "client deregistration failed; " - "client not detached.\n"); + /* main client */ + if (data) + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - if (i2c_get_clientdata(client)==NULL) { - /* subclients */ + /* main client */ + if (data) + kfree(data); + + /* subclient */ + else kfree(client); - } else { - /* main client */ - kfree(i2c_get_clientdata(client)); - } return 0; } @@ -969,7 +973,7 @@ static void asb100_init_client(struct i2c_client *client) vid = asb100_read_value(client, ASB100_REG_VID_FANDIV) & 0x0f; vid |= (asb100_read_value(client, ASB100_REG_CHIPID) & 0x01) << 4; - data->vrm = i2c_which_vrm(); + data->vrm = vid_which_vrm(); vid = vid_from_reg(vid, data->vrm); /* Start monitoring */ diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c index fca3fc1cef7..deb4d34c953 100644 --- a/drivers/hwmon/atxp1.c +++ b/drivers/hwmon/atxp1.c @@ -23,8 +23,9 @@ #include <linux/module.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> -#include <linux/i2c-vid.h> +#include <linux/hwmon.h> +#include <linux/hwmon-vid.h> +#include <linux/err.h> MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("System voltages control via Attansic ATXP1"); @@ -40,9 +41,8 @@ MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>"); #define ATXP1_GPIO1MASK 0x0f static unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; -SENSORS_INSMOD_1(atxp1); +I2C_CLIENT_INSMOD_1(atxp1); static int atxp1_attach_adapter(struct i2c_adapter * adapter); static int atxp1_detach_client(struct i2c_client * client); @@ -59,6 +59,7 @@ static struct i2c_driver atxp1_driver = { struct atxp1_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; unsigned long last_updated; u8 valid; @@ -252,7 +253,7 @@ static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2); static int atxp1_attach_adapter(struct i2c_adapter *adapter) { - return i2c_detect(adapter, &addr_data, &atxp1_detect); + return i2c_probe(adapter, &addr_data, &atxp1_detect); }; static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) @@ -295,7 +296,7 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) } /* Get VRM */ - data->vrm = i2c_which_vrm(); + data->vrm = vid_which_vrm(); if ((data->vrm != 90) && (data->vrm != 91)) { dev_err(&new_client->dev, "Not supporting VRM %d.%d\n", @@ -317,6 +318,12 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) goto exit_free; } + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_gpio1); device_create_file(&new_client->dev, &dev_attr_gpio2); device_create_file(&new_client->dev, &dev_attr_cpu0_vid); @@ -326,6 +333,8 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -334,14 +343,17 @@ exit: static int atxp1_detach_client(struct i2c_client * client) { + struct atxp1_data * data = i2c_get_clientdata(client); int err; + hwmon_device_unregister(data->class_dev); + err = i2c_detach_client(client); if (err) dev_err(&client->dev, "Failed to detach client.\n"); else - kfree(i2c_get_clientdata(client)); + kfree(data); return err; }; diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c index 5360d58804f..b0199e063d0 100644 --- a/drivers/hwmon/ds1621.c +++ b/drivers/hwmon/ds1621.c @@ -26,16 +26,16 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/hwmon.h> +#include <linux/err.h> #include "lm75.h" /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_1(ds1621); +I2C_CLIENT_INSMOD_1(ds1621); static int polarity = -1; module_param(polarity, int, 0); MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low"); @@ -71,6 +71,7 @@ MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low") /* Each client has this additional data */ struct ds1621_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* !=0 if following fields are valid */ unsigned long last_updated; /* In jiffies */ @@ -179,10 +180,10 @@ static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max); static int ds1621_attach_adapter(struct i2c_adapter *adapter) { - return i2c_detect(adapter, &addr_data, ds1621_detect); + return i2c_probe(adapter, &addr_data, ds1621_detect); } -/* This function is called by i2c_detect */ +/* This function is called by i2c_probe */ int ds1621_detect(struct i2c_adapter *adapter, int address, int kind) { @@ -250,6 +251,12 @@ int ds1621_detect(struct i2c_adapter *adapter, int address, ds1621_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_alarms); device_create_file(&new_client->dev, &dev_attr_temp1_input); device_create_file(&new_client->dev, &dev_attr_temp1_min); @@ -259,6 +266,8 @@ int ds1621_detect(struct i2c_adapter *adapter, int address, /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ + exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -267,15 +276,15 @@ int ds1621_detect(struct i2c_adapter *adapter, int address, static int ds1621_detach_client(struct i2c_client *client) { + struct ds1621_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/fscher.c b/drivers/hwmon/fscher.c index da411741c2c..eef6061d786 100644 --- a/drivers/hwmon/fscher.c +++ b/drivers/hwmon/fscher.c @@ -31,20 +31,20 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/hwmon.h> +#include <linux/err.h> /* * Addresses to scan */ static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* * Insmod parameters */ -SENSORS_INSMOD_1(fscher); +I2C_CLIENT_INSMOD_1(fscher); /* * The FSCHER registers @@ -132,6 +132,7 @@ static struct i2c_driver fscher_driver = { struct fscher_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* zero until following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -287,7 +288,7 @@ static int fscher_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, fscher_detect); + return i2c_probe(adapter, &addr_data, fscher_detect); } static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) @@ -341,6 +342,12 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) fscher_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file_revision(new_client); device_create_file_alarms(new_client); device_create_file_control(new_client); @@ -360,6 +367,8 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -368,15 +377,15 @@ exit: static int fscher_detach_client(struct i2c_client *client) { + struct fscher_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c index 301ae98bd0a..5fc77a5fed0 100644 --- a/drivers/hwmon/fscpos.c +++ b/drivers/hwmon/fscpos.c @@ -34,19 +34,19 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> #include <linux/init.h> +#include <linux/hwmon.h> +#include <linux/err.h> /* * Addresses to scan */ static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* * Insmod parameters */ -SENSORS_INSMOD_1(fscpos); +I2C_CLIENT_INSMOD_1(fscpos); /* * The FSCPOS registers @@ -113,6 +113,7 @@ static struct i2c_driver fscpos_driver = { */ struct fscpos_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* 0 until following fields are valid */ unsigned long last_updated; /* In jiffies */ @@ -434,7 +435,7 @@ static int fscpos_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, fscpos_detect); + return i2c_probe(adapter, &addr_data, fscpos_detect); } int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) @@ -496,6 +497,12 @@ int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_event); device_create_file(&new_client->dev, &dev_attr_in0_input); device_create_file(&new_client->dev, &dev_attr_in1_input); @@ -526,6 +533,8 @@ int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -534,14 +543,14 @@ exit: static int fscpos_detach_client(struct i2c_client *client) { + struct fscpos_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, client" - " not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index 6bedf729dcf..256b9323c84 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c @@ -41,14 +41,14 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/hwmon.h> +#include <linux/err.h> /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_2(gl518sm_r00, gl518sm_r80); +I2C_CLIENT_INSMOD_2(gl518sm_r00, gl518sm_r80); /* Many GL518 constants specified below */ @@ -117,6 +117,7 @@ static inline u8 FAN_TO_REG(long rpm, int div) /* Each client has this additional data */ struct gl518_data { struct i2c_client client; + struct class_device *class_dev; enum chips type; struct semaphore update_lock; @@ -346,7 +347,7 @@ static int gl518_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, gl518_detect); + return i2c_probe(adapter, &addr_data, gl518_detect); } static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) @@ -419,6 +420,12 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) gl518_init_client((struct i2c_client *) new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_in0_input); device_create_file(&new_client->dev, &dev_attr_in1_input); device_create_file(&new_client->dev, &dev_attr_in2_input); @@ -450,6 +457,8 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -477,16 +486,15 @@ static void gl518_init_client(struct i2c_client *client) static int gl518_detach_client(struct i2c_client *client) { + struct gl518_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); - return err; - } + hwmon_device_unregister(data->class_dev); - kfree(i2c_get_clientdata(client)); + if ((err = i2c_detach_client(client))) + return err; + kfree(data); return 0; } diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c index 80ae8d30c2a..12fd757066f 100644 --- a/drivers/hwmon/gl520sm.c +++ b/drivers/hwmon/gl520sm.c @@ -26,8 +26,9 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> -#include <linux/i2c-vid.h> +#include <linux/hwmon.h> +#include <linux/hwmon-vid.h> +#include <linux/err.h> /* Type of the extra sensor */ static unsigned short extra_sensor_type; @@ -36,10 +37,9 @@ MODULE_PARM_DESC(extra_sensor_type, "Type of extra sensor (0=autodetect, 1=tempe /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_1(gl520sm); +I2C_CLIENT_INSMOD_1(gl520sm); /* Many GL520 constants specified below One of the inputs can be configured as either temp or voltage. @@ -120,6 +120,7 @@ static struct i2c_driver gl520_driver = { /* Client data */ struct gl520_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* zero until the following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -518,7 +519,7 @@ static int gl520_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, gl520_detect); + return i2c_probe(adapter, &addr_data, gl520_detect); } static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) @@ -571,6 +572,12 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) gl520_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file_vid(new_client, 0); device_create_file_in(new_client, 0); @@ -592,6 +599,8 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -608,7 +617,7 @@ static void gl520_init_client(struct i2c_client *client) conf = oldconf = gl520_read_value(client, GL520_REG_CONF); data->alarm_mask = 0xff; - data->vrm = i2c_which_vrm(); + data->vrm = vid_which_vrm(); if (extra_sensor_type == 1) conf &= ~0x10; @@ -639,15 +648,15 @@ static void gl520_init_client(struct i2c_client *client) static int gl520_detach_client(struct i2c_client *client) { + struct gl520_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/hwmon-vid.c b/drivers/hwmon/hwmon-vid.c new file mode 100644 index 00000000000..312769ad4da --- /dev/null +++ b/drivers/hwmon/hwmon-vid.c @@ -0,0 +1,189 @@ +/* + hwmon-vid.c - VID/VRM/VRD voltage conversions + + Copyright (c) 2004 Rudolf Marek <r.marek@sh.cvut.cz> + + Partly imported from i2c-vid.h of the lm_sensors project + Copyright (c) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> + With assistance from Trent Piepho <xyzzy@speakeasy.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include <linux/config.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/hwmon-vid.h> + +/* + Common code for decoding VID pins. + + References: + + For VRM 8.4 to 9.1, "VRM x.y DC-DC Converter Design Guidelines", + available at http://developer.intel.com/. + + For VRD 10.0 and up, "VRD x.y Design Guide", + available at http://developer.intel.com/. + + AMD Opteron processors don't follow the Intel specifications. + I'm going to "make up" 2.4 as the spec number for the Opterons. + No good reason just a mnemonic for the 24x Opteron processor + series. + + Opteron VID encoding is: + 00000 = 1.550 V + 00001 = 1.525 V + . . . . + 11110 = 0.800 V + 11111 = 0.000 V (off) +*/ + +/* vrm is the VRM/VRD document version multiplied by 10. + val is the 4-, 5- or 6-bit VID code. + Returned value is in mV to avoid floating point in the kernel. */ +int vid_from_reg(int val, int vrm) +{ + int vid; + + switch(vrm) { + + case 0: + return 0; + + case 100: /* VRD 10.0 */ + if((val & 0x1f) == 0x1f) + return 0; + if((val & 0x1f) <= 0x09 || val == 0x0a) + vid = 10875 - (val & 0x1f) * 250; + else + vid = 18625 - (val & 0x1f) * 250; + if(val & 0x20) + vid -= 125; + vid /= 10; /* only return 3 dec. places for now */ + return vid; + + case 24: /* Opteron processor */ + return(val == 0x1f ? 0 : 1550 - val * 25); + + case 91: /* VRM 9.1 */ + case 90: /* VRM 9.0 */ + return(val == 0x1f ? 0 : + 1850 - val * 25); + + case 85: /* VRM 8.5 */ + return((val & 0x10 ? 25 : 0) + + ((val & 0x0f) > 0x04 ? 2050 : 1250) - + ((val & 0x0f) * 50)); + + case 84: /* VRM 8.4 */ + val &= 0x0f; + /* fall through */ + default: /* VRM 8.2 */ + return(val == 0x1f ? 0 : + val & 0x10 ? 5100 - (val) * 100 : + 2050 - (val) * 50); + } +} + + +/* + After this point is the code to automatically determine which + VRM/VRD specification should be used depending on the CPU. +*/ + +struct vrm_model { + u8 vendor; + u8 eff_family; + u8 eff_model; + int vrm_type; +}; + +#define ANY 0xFF + +#ifdef CONFIG_X86 + +static struct vrm_model vrm_models[] = { + {X86_VENDOR_AMD, 0x6, ANY, 90}, /* Athlon Duron etc */ + {X86_VENDOR_AMD, 0xF, ANY, 24}, /* Athlon 64, Opteron */ + {X86_VENDOR_INTEL, 0x6, 0x9, 85}, /* 0.13um too */ + {X86_VENDOR_INTEL, 0x6, 0xB, 85}, /* Tualatin */ + {X86_VENDOR_INTEL, 0x6, ANY, 82}, /* any P6 */ + {X86_VENDOR_INTEL, 0x7, ANY, 0}, /* Itanium */ + {X86_VENDOR_INTEL, 0xF, 0x0, 90}, /* P4 */ + {X86_VENDOR_INTEL, 0xF, 0x1, 90}, /* P4 Willamette */ + {X86_VENDOR_INTEL, 0xF, 0x2, 90}, /* P4 Northwood */ + {X86_VENDOR_INTEL, 0xF, 0x3, 100}, /* P4 Prescott */ + {X86_VENDOR_INTEL, 0xF, 0x4, 100}, /* P4 Prescott */ + {X86_VENDOR_INTEL, 0x10,ANY, 0}, /* Itanium 2 */ + {X86_VENDOR_UNKNOWN, ANY, ANY, 0} /* stop here */ +}; + +static int find_vrm(u8 eff_family, u8 eff_model, u8 vendor) +{ + int i = 0; + + while (vrm_models[i].vendor!=X86_VENDOR_UNKNOWN) { + if (vrm_models[i].vendor==vendor) + if ((vrm_models[i].eff_family==eff_family) + && ((vrm_models[i].eff_model==eff_model) || + (vrm_models[i].eff_model==ANY))) + return vrm_models[i].vrm_type; + i++; + } + + return 0; +} + +int vid_which_vrm(void) +{ + struct cpuinfo_x86 *c = cpu_data; + u32 eax; + u8 eff_family, eff_model; + int vrm_ret; + + if (c->x86 < 6) /* Any CPU with family lower than 6 */ + return 0; /* doesn't have VID and/or CPUID */ + + eax = cpuid_eax(1); + eff_family = ((eax & 0x00000F00)>>8); + eff_model = ((eax & 0x000000F0)>>4); + if (eff_family == 0xF) { /* use extended model & family */ + eff_family += ((eax & 0x00F00000)>>20); + eff_model += ((eax & 0x000F0000)>>16)<<4; + } + vrm_ret = find_vrm(eff_family,eff_model,c->x86_vendor); + if (vrm_ret == 0) + printk(KERN_INFO "hwmon-vid: Unknown VRM version of your " + "x86 CPU\n"); + return vrm_ret; +} + +/* and now something completely different for the non-x86 world */ +#else +int vid_which_vrm(void) +{ + printk(KERN_INFO "hwmon-vid: Unknown VRM version of your CPU\n"); + return 0; +} +#endif + +EXPORT_SYMBOL(vid_from_reg); +EXPORT_SYMBOL(vid_which_vrm); + +MODULE_AUTHOR("Rudolf Marek <r.marek@sh.cvut.cz>"); + +MODULE_DESCRIPTION("hwmon-vid driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c new file mode 100644 index 00000000000..9b41c9bd805 --- /dev/null +++ b/drivers/hwmon/hwmon.c @@ -0,0 +1,98 @@ +/* + hwmon.c - part of lm_sensors, Linux kernel modules for hardware monitoring + + This file defines the sysfs class "hwmon", for use by sensors drivers. + + Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. +*/ + +#include <linux/module.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/kdev_t.h> +#include <linux/idr.h> +#include <linux/hwmon.h> + +#define HWMON_ID_PREFIX "hwmon" +#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" + +static struct class *hwmon_class; + +static DEFINE_IDR(hwmon_idr); + +/** + * hwmon_device_register - register w/ hwmon sysfs class + * @dev: the device to register + * + * hwmon_device_unregister() must be called when the class device is no + * longer needed. + * + * Returns the pointer to the new struct class device. + */ +struct class_device *hwmon_device_register(struct device *dev) +{ + struct class_device *cdev; + int id; + + if (idr_pre_get(&hwmon_idr, GFP_KERNEL) == 0) + return ERR_PTR(-ENOMEM); + + if (idr_get_new(&hwmon_idr, NULL, &id) < 0) + return ERR_PTR(-ENOMEM); + + id = id & MAX_ID_MASK; + cdev = class_device_create(hwmon_class, MKDEV(0,0), dev, + HWMON_ID_FORMAT, id); + + if (IS_ERR(cdev)) + idr_remove(&hwmon_idr, id); + + return cdev; +} + +/** + * hwmon_device_unregister - removes the previously registered class device + * + * @cdev: the class device to destroy + */ +void hwmon_device_unregister(struct class_device *cdev) +{ + int id; + + if (sscanf(cdev->class_id, HWMON_ID_FORMAT, &id) == 1) { + class_device_unregister(cdev); + idr_remove(&hwmon_idr, id); + } else + dev_dbg(cdev->dev, + "hwmon_device_unregister() failed: bad class ID!\n"); +} + +static int __init hwmon_init(void) +{ + hwmon_class = class_create(THIS_MODULE, "hwmon"); + if (IS_ERR(hwmon_class)) { + printk(KERN_ERR "hwmon.c: couldn't create sysfs class\n"); + return PTR_ERR(hwmon_class); + } + return 0; +} + +static void __exit hwmon_exit(void) +{ + class_destroy(hwmon_class); +} + +module_init(hwmon_init); +module_exit(hwmon_exit); + +EXPORT_SYMBOL_GPL(hwmon_device_register); +EXPORT_SYMBOL_GPL(hwmon_device_unregister); + +MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); +MODULE_DESCRIPTION("hardware monitoring sysfs/class support"); +MODULE_LICENSE("GPL"); + diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index db20c9e4739..53cc2b6d638 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c @@ -36,19 +36,21 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> -#include <linux/i2c-vid.h> +#include <linux/i2c-isa.h> +#include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> +#include <linux/hwmon-vid.h> +#include <linux/err.h> #include <asm/io.h> /* 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 short isa_address = 0x290; /* Insmod parameters */ -SENSORS_INSMOD_2(it87, it8712); +I2C_CLIENT_INSMOD_2(it87, it8712); #define REG 0x2e /* The register to read/write */ #define DEV 0x07 /* Register: Logical device select */ @@ -192,6 +194,7 @@ static int DIV_TO_REG(int val) allocated. */ struct it87_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; enum chips type; @@ -218,7 +221,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); @@ -239,6 +242,14 @@ static struct i2c_driver it87_driver = { .detach_client = it87_detach_client, }; +static struct i2c_driver it87_isa_driver = { + .owner = THIS_MODULE, + .name = "it87-isa", + .attach_adapter = it87_isa_attach_adapter, + .detach_client = it87_detach_client, +}; + + static ssize_t show_in(struct device *dev, struct device_attribute *attr, char *buf) { @@ -686,11 +697,16 @@ static int it87_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, it87_detect); + return i2c_probe(adapter, &addr_data, it87_detect); } -/* SuperIO detection - will change normal_isa[0] if a chip is found */ -static int it87_find(int *address) +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 __init it87_find(int *address) { int err = -ENODEV; @@ -721,7 +737,7 @@ exit: return err; } -/* This function is called by i2c_detect */ +/* This function is called by i2c_probe */ int it87_detect(struct i2c_adapter *adapter, int address, int kind) { int i; @@ -738,7 +754,7 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind) /* Reserve the ISA region */ if (is_isa) - if (!request_region(address, IT87_EXTENT, it87_driver.name)) + if (!request_region(address, IT87_EXTENT, it87_isa_driver.name)) goto ERROR0; /* Probe whether there is anything available on this address. Already @@ -784,7 +800,7 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind) i2c_set_clientdata(new_client, data); new_client->addr = address; new_client->adapter = adapter; - new_client->driver = &it87_driver; + new_client->driver = is_isa ? &it87_isa_driver : &it87_driver; new_client->flags = 0; /* Now, we do the remaining detection. */ @@ -840,6 +856,12 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind) it87_init_client(new_client, data); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto ERROR3; + } + device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr); device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr); @@ -897,13 +919,15 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind) } if (data->type == it8712) { - data->vrm = i2c_which_vrm(); + data->vrm = vid_which_vrm(); device_create_file_vrm(new_client); device_create_file_vid(new_client); } return 0; +ERROR3: + i2c_detach_client(new_client); ERROR2: kfree(data); ERROR1: @@ -915,17 +939,17 @@ ERROR0: static int it87_detach_client(struct i2c_client *client) { + struct it87_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, - "Client deregistration failed, client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } if(i2c_is_isa_client(client)) release_region(client->addr, IT87_EXTENT); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } @@ -1158,16 +1182,28 @@ static struct it87_data *it87_update_device(struct device *dev) static int __init sm_it87_init(void) { - int addr; + int addr, res; if (!it87_find(&addr)) { - normal_isa[0] = addr; + isa_address = addr; + } + + res = i2c_add_driver(&it87_driver); + if (res) + return res; + + res = i2c_isa_add_driver(&it87_isa_driver); + if (res) { + i2c_del_driver(&it87_driver); + return res; } - return i2c_add_driver(&it87_driver); + + return 0; } static void __exit sm_it87_exit(void) { + i2c_isa_del_driver(&it87_isa_driver); i2c_del_driver(&it87_driver); } diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c index 7c6f9ea5a25..be5c7095ecb 100644 --- a/drivers/hwmon/lm63.c +++ b/drivers/hwmon/lm63.c @@ -42,8 +42,9 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> #include <linux/hwmon-sysfs.h> +#include <linux/hwmon.h> +#include <linux/err.h> /* * Addresses to scan @@ -51,13 +52,12 @@ */ static unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* * Insmod parameters */ -SENSORS_INSMOD_1(lm63); +I2C_CLIENT_INSMOD_1(lm63); /* * The LM63 registers @@ -152,6 +152,7 @@ static struct i2c_driver lm63_driver = { struct lm63_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* zero until following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -358,7 +359,7 @@ static int lm63_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, lm63_detect); + return i2c_probe(adapter, &addr_data, lm63_detect); } /* @@ -437,6 +438,12 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind) lm63_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + if (data->config & 0x04) { /* tachometer enabled */ device_create_file(&new_client->dev, &sensor_dev_attr_fan1_input.dev_attr); @@ -462,6 +469,8 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -505,15 +514,15 @@ static void lm63_init_client(struct i2c_client *client) static int lm63_detach_client(struct i2c_client *client) { + struct lm63_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 5be164ed278..9a3ebdf583f 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -23,17 +23,17 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/hwmon.h> +#include <linux/err.h> #include "lm75.h" /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_1(lm75); +I2C_CLIENT_INSMOD_1(lm75); /* Many LM75 constants specified below */ @@ -46,6 +46,7 @@ SENSORS_INSMOD_1(lm75); /* Each client has this additional data */ struct lm75_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* !=0 if following fields are valid */ unsigned long last_updated; /* In jiffies */ @@ -107,10 +108,10 @@ static int lm75_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, lm75_detect); + return i2c_probe(adapter, &addr_data, lm75_detect); } -/* This function is called by i2c_detect */ +/* This function is called by i2c_probe */ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) { int i; @@ -119,16 +120,6 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) int err = 0; const char *name = ""; - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; i2c_detect really won't call us. */ -#ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - dev_dbg(&adapter->dev, - "lm75_detect called for an ISA bus adapter?!?\n"); - goto exit; - } -#endif - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) goto exit; @@ -208,12 +199,20 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) lm75_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_temp1_max); device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst); device_create_file(&new_client->dev, &dev_attr_temp1_input); return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -222,8 +221,10 @@ exit: static int lm75_detach_client(struct i2c_client *client) { + struct lm75_data *data = i2c_get_clientdata(client); + hwmon_device_unregister(data->class_dev); i2c_detach_client(client); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } @@ -251,8 +252,12 @@ static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) static void lm75_init_client(struct i2c_client *client) { - /* Initialize the LM75 chip */ - lm75_write_value(client, LM75_REG_CONF, 0); + int reg; + + /* Enable if in shutdown mode */ + reg = lm75_read_value(client, LM75_REG_CONF); + if (reg >= 0 && (reg & 0x01)) + lm75_write_value(client, LM75_REG_CONF, reg & 0xfe); } static struct lm75_data *lm75_update_device(struct device *dev) diff --git a/drivers/hwmon/lm75.h b/drivers/hwmon/lm75.h index 63e3f2fb4c2..af7dc650ee1 100644 --- a/drivers/hwmon/lm75.h +++ b/drivers/hwmon/lm75.h @@ -25,7 +25,7 @@ which contains this code, we don't worry about the wasted space. */ -#include <linux/i2c-sensor.h> +#include <linux/hwmon.h> /* straight from the datasheet */ #define LM75_TEMP_MIN (-55000) diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c index b98f4495299..866eab96a6f 100644 --- a/drivers/hwmon/lm77.c +++ b/drivers/hwmon/lm77.c @@ -30,15 +30,14 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> - +#include <linux/hwmon.h> +#include <linux/err.h> /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_1(lm77); +I2C_CLIENT_INSMOD_1(lm77); /* The LM77 registers */ #define LM77_REG_TEMP 0x00 @@ -51,6 +50,7 @@ SENSORS_INSMOD_1(lm77); /* Each client has this additional data */ struct lm77_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; unsigned long last_updated; /* In jiffies */ @@ -208,10 +208,10 @@ static int lm77_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, lm77_detect); + return i2c_probe(adapter, &addr_data, lm77_detect); } -/* This function is called by i2c_detect */ +/* This function is called by i2c_probe */ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) { struct i2c_client *new_client; @@ -317,6 +317,12 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) lm77_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_temp1_input); device_create_file(&new_client->dev, &dev_attr_temp1_crit); device_create_file(&new_client->dev, &dev_attr_temp1_min); @@ -327,6 +333,8 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) device_create_file(&new_client->dev, &dev_attr_alarms); return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -335,8 +343,10 @@ exit: static int lm77_detach_client(struct i2c_client *client) { + struct lm77_data *data = i2c_get_clientdata(client); + hwmon_device_unregister(data->class_dev); i2c_detach_client(client); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c index 29241469dcb..f6730dc3573 100644 --- a/drivers/hwmon/lm78.c +++ b/drivers/hwmon/lm78.c @@ -23,7 +23,10 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/i2c-isa.h> +#include <linux/hwmon.h> +#include <linux/hwmon-vid.h> +#include <linux/err.h> #include <asm/io.h> /* Addresses to scan */ @@ -31,10 +34,10 @@ 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 short isa_address = 0x290; /* Insmod parameters */ -SENSORS_INSMOD_3(lm78, lm78j, lm79); +I2C_CLIENT_INSMOD_2(lm78, lm79); /* Many LM78 constants specified below */ @@ -104,13 +107,6 @@ static inline int TEMP_FROM_REG(s8 val) return val * 1000; } -/* VID: mV - REG: (see doc/vid) */ -static inline int VID_FROM_REG(u8 val) -{ - return val==0x1f ? 0 : val>=0x10 ? 5100-val*100 : 2050-val*50; -} - #define DIV_FROM_REG(val) (1 << (val)) /* There are some complications in a module like this. First off, LM78 chips @@ -134,6 +130,7 @@ static inline int VID_FROM_REG(u8 val) allocated. */ struct lm78_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; enum chips type; @@ -156,6 +153,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); @@ -174,6 +172,14 @@ static struct i2c_driver lm78_driver = { .detach_client = lm78_detach_client, }; +static struct i2c_driver lm78_isa_driver = { + .owner = THIS_MODULE, + .name = "lm78-isa", + .attach_adapter = lm78_isa_attach_adapter, + .detach_client = lm78_detach_client, +}; + + /* 7 Voltages */ static ssize_t show_in(struct device *dev, char *buf, int nr) { @@ -445,7 +451,7 @@ static DEVICE_ATTR(fan3_div, S_IRUGO, show_fan_3_div, NULL); static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) { struct lm78_data *data = lm78_update_device(dev); - return sprintf(buf, "%d\n", VID_FROM_REG(data->vid)); + return sprintf(buf, "%d\n", vid_from_reg(82, data->vid)); } static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); @@ -465,10 +471,15 @@ static int lm78_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, lm78_detect); + return i2c_probe(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 */ +/* This function is called by i2c_probe */ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) { int i, err; @@ -485,7 +496,8 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) /* Reserve the ISA region */ if (is_isa) - if (!request_region(address, LM78_EXTENT, lm78_driver.name)) { + if (!request_region(address, LM78_EXTENT, + lm78_isa_driver.name)) { err = -EBUSY; goto ERROR0; } @@ -540,7 +552,7 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) i2c_set_clientdata(new_client, data); new_client->addr = address; new_client->adapter = adapter; - new_client->driver = &lm78_driver; + new_client->driver = is_isa ? &lm78_isa_driver : &lm78_driver; new_client->flags = 0; /* Now, we do the remaining detection. */ @@ -559,10 +571,9 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) /* Determine the chip type. */ if (kind <= 0) { i = lm78_read_value(new_client, LM78_REG_CHIPID); - if (i == 0x00 || i == 0x20) + if (i == 0x00 || i == 0x20 /* LM78 */ + || i == 0x40) /* LM78-J */ kind = lm78; - else if (i == 0x40) - kind = lm78j; else if ((i & 0xfe) == 0xc0) kind = lm79; else { @@ -578,8 +589,6 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) if (kind == lm78) { client_name = "lm78"; - } else if (kind == lm78j) { - client_name = "lm78-j"; } else if (kind == lm79) { client_name = "lm79"; } @@ -605,6 +614,12 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) } /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto ERROR3; + } + device_create_file(&new_client->dev, &dev_attr_in0_input); device_create_file(&new_client->dev, &dev_attr_in0_min); device_create_file(&new_client->dev, &dev_attr_in0_max); @@ -643,6 +658,8 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +ERROR3: + i2c_detach_client(new_client); ERROR2: kfree(data); ERROR1: @@ -654,18 +671,18 @@ ERROR0: static int lm78_detach_client(struct i2c_client *client) { + struct lm78_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, - "Client deregistration failed, client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } if(i2c_is_isa_client(client)) release_region(client->addr, LM78_EXTENT); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } @@ -777,18 +794,31 @@ static struct lm78_data *lm78_update_device(struct device *dev) static int __init sm_lm78_init(void) { - return i2c_add_driver(&lm78_driver); + int res; + + res = i2c_add_driver(&lm78_driver); + if (res) + return res; + + res = i2c_isa_add_driver(&lm78_isa_driver); + if (res) { + i2c_del_driver(&lm78_driver); + return res; + } + + return 0; } static void __exit sm_lm78_exit(void) { + i2c_isa_del_driver(&lm78_isa_driver); i2c_del_driver(&lm78_driver); } MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"); -MODULE_DESCRIPTION("LM78, LM78-J and LM79 driver"); +MODULE_DESCRIPTION("LM78/LM79 driver"); MODULE_LICENSE("GPL"); module_init(sm_lm78_init); diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c index 8100595feb4..83af8b3a0ca 100644 --- a/drivers/hwmon/lm80.c +++ b/drivers/hwmon/lm80.c @@ -26,15 +26,15 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/hwmon.h> +#include <linux/err.h> /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_1(lm80); +I2C_CLIENT_INSMOD_1(lm80); /* Many LM80 constants specified below */ @@ -107,6 +107,7 @@ static inline long TEMP_FROM_REG(u16 temp) struct lm80_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* !=0 if following fields are valid */ unsigned long last_updated; /* In jiffies */ @@ -389,7 +390,7 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, lm80_detect); + return i2c_probe(adapter, &addr_data, lm80_detect); } int lm80_detect(struct i2c_adapter *adapter, int address, int kind) @@ -451,6 +452,12 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind) data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2)); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto error_detach; + } + device_create_file(&new_client->dev, &dev_attr_in0_min); device_create_file(&new_client->dev, &dev_attr_in1_min); device_create_file(&new_client->dev, &dev_attr_in2_min); @@ -487,6 +494,8 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +error_detach: + i2c_detach_client(new_client); error_free: kfree(data); exit: @@ -495,15 +504,15 @@ exit: static int lm80_detach_client(struct i2c_client *client) { + struct lm80_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c index a49008b444c..d74b2c20c71 100644 --- a/drivers/hwmon/lm83.c +++ b/drivers/hwmon/lm83.c @@ -32,8 +32,9 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> #include <linux/hwmon-sysfs.h> +#include <linux/hwmon.h> +#include <linux/err.h> /* * Addresses to scan @@ -45,13 +46,12 @@ static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* * Insmod parameters */ -SENSORS_INSMOD_1(lm83); +I2C_CLIENT_INSMOD_1(lm83); /* * The LM83 registers @@ -138,6 +138,7 @@ static struct i2c_driver lm83_driver = { struct lm83_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* zero until following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -212,7 +213,7 @@ static int lm83_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, lm83_detect); + return i2c_probe(adapter, &addr_data, lm83_detect); } /* @@ -312,6 +313,12 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) */ /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr); device_create_file(&new_client->dev, @@ -340,6 +347,8 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -348,15 +357,15 @@ exit: static int lm83_detach_client(struct i2c_client *client) { + struct lm83_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, - "Client deregistration failed, client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index b4d7fd41826..ab214df9624 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c @@ -28,15 +28,15 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> -#include <linux/i2c-vid.h> +#include <linux/hwmon.h> +#include <linux/hwmon-vid.h> +#include <linux/err.h> /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102); +I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102); /* The LM85 registers */ @@ -281,15 +281,6 @@ static int ZONE_TO_REG( int zone ) #define PPR_TO_REG(val,fan) (SENSORS_LIMIT((val)-1,0,3)<<(fan *2)) #define PPR_FROM_REG(val,fan) ((((val)>>(fan * 2))&0x03)+1) -/* i2c-vid.h defines vid_from_reg() */ -#define VID_FROM_REG(val,vrm) (vid_from_reg((val),(vrm))) - -/* Unlike some other drivers we DO NOT set initial limits. Use - * the config file to set limits. Some users have reported - * motherboards shutting down when we set limits in a previous - * version of the driver. - */ - /* Chip sampling rates * * Some sensors are not updated more frequently than once per second @@ -339,6 +330,7 @@ struct lm85_autofan { struct lm85_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; enum chips type; @@ -1019,7 +1011,7 @@ int lm85_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, lm85_detect); + return i2c_probe(adapter, &addr_data, lm85_detect); } int lm85_detect(struct i2c_adapter *adapter, int address, @@ -1031,11 +1023,6 @@ int lm85_detect(struct i2c_adapter *adapter, int address, int err = 0; const char *type_name = ""; - if (i2c_is_isa_adapter(adapter)) { - /* This chip has no ISA interface */ - goto ERROR0 ; - }; - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { /* We need to be able to do byte I/O */ @@ -1160,12 +1147,18 @@ int lm85_detect(struct i2c_adapter *adapter, int address, goto ERROR1; /* Set the VRM version */ - data->vrm = i2c_which_vrm(); + data->vrm = vid_which_vrm(); /* Initialize the LM85 chip */ lm85_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto ERROR2; + } + device_create_file(&new_client->dev, &dev_attr_fan1_input); device_create_file(&new_client->dev, &dev_attr_fan2_input); device_create_file(&new_client->dev, &dev_attr_fan3_input); @@ -1235,6 +1228,8 @@ int lm85_detect(struct i2c_adapter *adapter, int address, return 0; /* Error out and cleanup code */ + ERROR2: + i2c_detach_client(new_client); ERROR1: kfree(data); ERROR0: @@ -1243,8 +1238,10 @@ int lm85_detect(struct i2c_adapter *adapter, int address, int lm85_detach_client(struct i2c_client *client) { + struct lm85_data *data = i2c_get_clientdata(client); + hwmon_device_unregister(data->class_dev); i2c_detach_client(client); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c index 1921ed1af18..dca996de4c3 100644 --- a/drivers/hwmon/lm87.c +++ b/drivers/hwmon/lm87.c @@ -57,8 +57,9 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> -#include <linux/i2c-vid.h> +#include <linux/hwmon.h> +#include <linux/hwmon-vid.h> +#include <linux/err.h> /* * Addresses to scan @@ -66,13 +67,12 @@ */ static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* * Insmod parameters */ -SENSORS_INSMOD_1(lm87); +I2C_CLIENT_INSMOD_1(lm87); /* * The LM87 registers @@ -175,6 +175,7 @@ static struct i2c_driver lm87_driver = { struct lm87_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* zero until following fields are valid */ unsigned long last_updated; /* In jiffies */ @@ -537,7 +538,7 @@ static int lm87_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, lm87_detect); + return i2c_probe(adapter, &addr_data, lm87_detect); } /* @@ -608,6 +609,12 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) data->in_scale[7] = 1875; /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_in1_input); device_create_file(&new_client->dev, &dev_attr_in1_min); device_create_file(&new_client->dev, &dev_attr_in1_max); @@ -673,6 +680,8 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -685,7 +694,7 @@ static void lm87_init_client(struct i2c_client *client) u8 config; data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE); - data->vrm = i2c_which_vrm(); + data->vrm = vid_which_vrm(); config = lm87_read_value(client, LM87_REG_CONFIG); if (!(config & 0x01)) { @@ -719,15 +728,15 @@ static void lm87_init_client(struct i2c_client *client) static int lm87_detach_client(struct i2c_client *client) { + struct lm87_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index a67dcadf7cb..14de05fcd43 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -75,8 +75,9 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> #include <linux/hwmon-sysfs.h> +#include <linux/hwmon.h> +#include <linux/err.h> /* * Addresses to scan @@ -89,13 +90,12 @@ */ static unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* * Insmod parameters */ -SENSORS_INSMOD_6(lm90, adm1032, lm99, lm86, max6657, adt7461); +I2C_CLIENT_INSMOD_6(lm90, adm1032, lm99, lm86, max6657, adt7461); /* * The LM90 registers @@ -200,6 +200,7 @@ static struct i2c_driver lm90_driver = { struct lm90_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* zero until following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -352,7 +353,7 @@ static int lm90_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, lm90_detect); + return i2c_probe(adapter, &addr_data, lm90_detect); } /* @@ -500,6 +501,12 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) lm90_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr); device_create_file(&new_client->dev, @@ -524,6 +531,8 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -547,15 +556,15 @@ static void lm90_init_client(struct i2c_client *client) static int lm90_detach_client(struct i2c_client *client) { + struct lm90_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c index 215c8e40ffd..647b7c7cd57 100644 --- a/drivers/hwmon/lm92.c +++ b/drivers/hwmon/lm92.c @@ -44,17 +44,16 @@ #include <linux/init.h> #include <linux/slab.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> - +#include <linux/hwmon.h> +#include <linux/err.h> /* The LM92 and MAX6635 have 2 two-state pins for address selection, resulting in 4 possible addresses. */ static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_1(lm92); +I2C_CLIENT_INSMOD_1(lm92); /* The LM92 registers */ #define LM92_REG_CONFIG 0x01 /* 8-bit, RW */ @@ -96,6 +95,7 @@ static struct i2c_driver lm92_driver; /* Client data (each client gets its own) */ struct lm92_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* zero until following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -359,6 +359,12 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) lm92_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_temp1_input); device_create_file(&new_client->dev, &dev_attr_temp1_crit); device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst); @@ -370,6 +376,8 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -380,20 +388,20 @@ static int lm92_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, lm92_detect); + return i2c_probe(adapter, &addr_data, lm92_detect); } static int lm92_detach_client(struct i2c_client *client) { + struct lm92_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index 3c159f1d49e..16bf71f3a04 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c @@ -31,20 +31,19 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> - +#include <linux/hwmon.h> +#include <linux/err.h> static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* * Insmod parameters */ -SENSORS_INSMOD_1(max1619); +I2C_CLIENT_INSMOD_1(max1619); /* * The MAX1619 registers @@ -104,6 +103,7 @@ static struct i2c_driver max1619_driver = { struct max1619_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* zero until following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -179,7 +179,7 @@ static int max1619_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, max1619_detect); + return i2c_probe(adapter, &addr_data, max1619_detect); } /* @@ -275,6 +275,12 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) max1619_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_temp1_input); device_create_file(&new_client->dev, &dev_attr_temp2_input); device_create_file(&new_client->dev, &dev_attr_temp2_min); @@ -285,6 +291,8 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -308,15 +316,15 @@ static void max1619_init_client(struct i2c_client *client) static int max1619_detach_client(struct i2c_client *client) { + struct max1619_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c index fa4032d53b7..cf2a35799c7 100644 --- a/drivers/hwmon/pc87360.c +++ b/drivers/hwmon/pc87360.c @@ -38,23 +38,19 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> -#include <linux/i2c-vid.h> +#include <linux/i2c-isa.h> +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> +#include <linux/hwmon-vid.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); @@ -186,6 +182,7 @@ static inline u8 PWM_TO_REG(int val, int inv) struct pc87360_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; struct semaphore update_lock; char valid; /* !=0 if following fields are valid */ @@ -224,8 +221,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, @@ -242,8 +238,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, }; @@ -251,168 +246,178 @@ static struct i2c_driver pc87360_driver = { * Sysfs stuff */ -static ssize_t set_fan_min(struct device *dev, const char *buf, - size_t count, int nr) +static ssize_t show_fan_input(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[attr->index], + FAN_DIV_FROM_REG(data->fan_status[attr->index]))); +} +static ssize_t show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[attr->index], + FAN_DIV_FROM_REG(data->fan_status[attr->index]))); +} +static ssize_t show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", + FAN_DIV_FROM_REG(data->fan_status[attr->index])); +} +static ssize_t show_fan_status(struct device *dev, struct device_attribute *devattr, char *buf) { + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", + FAN_STATUS_FROM_REG(data->fan_status[attr->index])); +} +static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf, + size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct pc87360_data *data = i2c_get_clientdata(client); long fan_min = simple_strtol(buf, NULL, 10); down(&data->update_lock); - fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[nr])); + fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[attr->index])); /* If it wouldn't fit, change clock divisor */ while (fan_min > 255 - && (data->fan_status[nr] & 0x60) != 0x60) { + && (data->fan_status[attr->index] & 0x60) != 0x60) { fan_min >>= 1; - data->fan[nr] >>= 1; - data->fan_status[nr] += 0x20; + data->fan[attr->index] >>= 1; + data->fan_status[attr->index] += 0x20; } - data->fan_min[nr] = fan_min > 255 ? 255 : fan_min; - pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(nr), - data->fan_min[nr]); + data->fan_min[attr->index] = fan_min > 255 ? 255 : fan_min; + pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(attr->index), + data->fan_min[attr->index]); /* Write new divider, preserve alarm bits */ - pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(nr), - data->fan_status[nr] & 0xF9); + pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(attr->index), + data->fan_status[attr->index] & 0xF9); up(&data->update_lock); return count; } #define show_and_set_fan(offset) \ -static ssize_t show_fan##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[offset-1], \ - FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \ -} \ -static ssize_t show_fan##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[offset-1], \ - FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \ -} \ -static ssize_t show_fan##offset##_div(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", \ - FAN_DIV_FROM_REG(data->fan_status[offset-1])); \ -} \ -static ssize_t show_fan##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", \ - FAN_STATUS_FROM_REG(data->fan_status[offset-1])); \ -} \ -static ssize_t set_fan##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ - size_t count) \ -{ \ - return set_fan_min(dev, buf, count, offset-1); \ -} \ -static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ - show_fan##offset##_input, NULL); \ -static DEVICE_ATTR(fan##offset##_min, S_IWUSR | S_IRUGO, \ - show_fan##offset##_min, set_fan##offset##_min); \ -static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \ - show_fan##offset##_div, NULL); \ -static DEVICE_ATTR(fan##offset##_status, S_IRUGO, \ - show_fan##offset##_status, NULL); +static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ + show_fan_input, NULL, offset-1); \ +static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IWUSR | S_IRUGO, \ + show_fan_min, set_fan_min, offset-1); \ +static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO, \ + show_fan_div, NULL, offset-1); \ +static SENSOR_DEVICE_ATTR(fan##offset##_status, S_IRUGO, \ + show_fan_status, NULL, offset-1); show_and_set_fan(1) show_and_set_fan(2) show_and_set_fan(3) +static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", + PWM_FROM_REG(data->pwm[attr->index], + FAN_CONFIG_INVERT(data->fan_conf, + attr->index))); +} +static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, const char *buf, + size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct pc87360_data *data = i2c_get_clientdata(client); + long val = simple_strtol(buf, NULL, 10); + + down(&data->update_lock); + data->pwm[attr->index] = PWM_TO_REG(val, + FAN_CONFIG_INVERT(data->fan_conf, attr->index)); + pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(attr->index), + data->pwm[attr->index]); + up(&data->update_lock); + return count; +} + #define show_and_set_pwm(offset) \ -static ssize_t show_pwm##offset(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", \ - PWM_FROM_REG(data->pwm[offset-1], \ - FAN_CONFIG_INVERT(data->fan_conf, \ - offset-1))); \ -} \ -static ssize_t set_pwm##offset(struct device *dev, struct device_attribute *attr, const char *buf, \ - size_t count) \ -{ \ - struct i2c_client *client = to_i2c_client(dev); \ - struct pc87360_data *data = i2c_get_clientdata(client); \ - long val = simple_strtol(buf, NULL, 10); \ - \ - down(&data->update_lock); \ - data->pwm[offset-1] = PWM_TO_REG(val, \ - FAN_CONFIG_INVERT(data->fan_conf, offset-1)); \ - pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(offset-1), \ - data->pwm[offset-1]); \ - up(&data->update_lock); \ - return count; \ -} \ -static DEVICE_ATTR(pwm##offset, S_IWUSR | S_IRUGO, \ - show_pwm##offset, set_pwm##offset); +static SENSOR_DEVICE_ATTR(pwm##offset, S_IWUSR | S_IRUGO, \ + show_pwm, set_pwm, offset-1); show_and_set_pwm(1) show_and_set_pwm(2) show_and_set_pwm(3) +static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], + data->in_vref)); +} +static ssize_t show_in_min(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], + data->in_vref)); +} +static ssize_t show_in_max(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], + data->in_vref)); +} +static ssize_t show_in_status(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", data->in_status[attr->index]); +} +static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, const char *buf, + size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct pc87360_data *data = i2c_get_clientdata(client); + long val = simple_strtol(buf, NULL, 10); + + down(&data->update_lock); + data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); + pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MIN, + data->in_min[attr->index]); + up(&data->update_lock); + return count; +} +static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf, + size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct pc87360_data *data = i2c_get_clientdata(client); + long val = simple_strtol(buf, NULL, 10); + + down(&data->update_lock); + data->in_max[attr->index] = IN_TO_REG(val, + data->in_vref); + pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MAX, + data->in_max[attr->index]); + up(&data->update_lock); + return count; +} + #define show_and_set_in(offset) \ -static ssize_t show_in##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \ - data->in_vref)); \ -} \ -static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \ - data->in_vref)); \ -} \ -static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \ - data->in_vref)); \ -} \ -static ssize_t show_in##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", data->in_status[offset]); \ -} \ -static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ - size_t count) \ -{ \ - struct i2c_client *client = to_i2c_client(dev); \ - struct pc87360_data *data = i2c_get_clientdata(client); \ - long val = simple_strtol(buf, NULL, 10); \ - \ - down(&data->update_lock); \ - data->in_min[offset] = IN_TO_REG(val, data->in_vref); \ - pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MIN, \ - data->in_min[offset]); \ - up(&data->update_lock); \ - return count; \ -} \ -static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ - size_t count) \ -{ \ - struct i2c_client *client = to_i2c_client(dev); \ - struct pc87360_data *data = i2c_get_clientdata(client); \ - long val = simple_strtol(buf, NULL, 10); \ - \ - down(&data->update_lock); \ - data->in_max[offset] = IN_TO_REG(val, \ - data->in_vref); \ - pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MAX, \ - data->in_max[offset]); \ - up(&data->update_lock); \ - return count; \ -} \ -static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ - show_in##offset##_input, NULL); \ -static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \ - show_in##offset##_min, set_in##offset##_min); \ -static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \ - show_in##offset##_max, set_in##offset##_max); \ -static DEVICE_ATTR(in##offset##_status, S_IRUGO, \ - show_in##offset##_status, NULL); +static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ + show_in_input, NULL, offset); \ +static SENSOR_DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \ + show_in_min, set_in_min, offset); \ +static SENSOR_DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \ + show_in_max, set_in_max, offset); \ +static SENSOR_DEVICE_ATTR(in##offset##_status, S_IRUGO, \ + show_in_status, NULL, offset); show_and_set_in(0) show_and_set_in(1) show_and_set_in(2) @@ -425,88 +430,97 @@ show_and_set_in(8) show_and_set_in(9) show_and_set_in(10) +static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], + data->in_vref)); +} +static ssize_t show_therm_min(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], + data->in_vref)); +} +static ssize_t show_therm_max(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], + data->in_vref)); +} +static ssize_t show_therm_crit(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11], + data->in_vref)); +} +static ssize_t show_therm_status(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%u\n", data->in_status[attr->index]); +} +static ssize_t set_therm_min(struct device *dev, struct device_attribute *devattr, const char *buf, + size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct pc87360_data *data = i2c_get_clientdata(client); + long val = simple_strtol(buf, NULL, 10); + + down(&data->update_lock); + data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); + pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MIN, + data->in_min[attr->index]); + up(&data->update_lock); + return count; +} +static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf, + size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct pc87360_data *data = i2c_get_clientdata(client); + long val = simple_strtol(buf, NULL, 10); + + down(&data->update_lock); + data->in_max[attr->index] = IN_TO_REG(val, data->in_vref); + pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MAX, + data->in_max[attr->index]); + up(&data->update_lock); + return count; +} +static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf, + size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct pc87360_data *data = i2c_get_clientdata(client); + long val = simple_strtol(buf, NULL, 10); + + down(&data->update_lock); + data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref); + pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_CRIT, + data->in_crit[attr->index-11]); + up(&data->update_lock); + return count; +} + #define show_and_set_therm(offset) \ -static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset+7], \ - data->in_vref)); \ -} \ -static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset+7], \ - data->in_vref)); \ -} \ -static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset+7], \ - data->in_vref)); \ -} \ -static ssize_t show_temp##offset##_crit(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[offset-4], \ - data->in_vref)); \ -} \ -static ssize_t show_temp##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%u\n", data->in_status[offset+7]); \ -} \ -static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ - size_t count) \ -{ \ - struct i2c_client *client = to_i2c_client(dev); \ - struct pc87360_data *data = i2c_get_clientdata(client); \ - long val = simple_strtol(buf, NULL, 10); \ - \ - down(&data->update_lock); \ - data->in_min[offset+7] = IN_TO_REG(val, data->in_vref); \ - pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MIN, \ - data->in_min[offset+7]); \ - up(&data->update_lock); \ - return count; \ -} \ -static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ - size_t count) \ -{ \ - struct i2c_client *client = to_i2c_client(dev); \ - struct pc87360_data *data = i2c_get_clientdata(client); \ - long val = simple_strtol(buf, NULL, 10); \ - \ - down(&data->update_lock); \ - data->in_max[offset+7] = IN_TO_REG(val, data->in_vref); \ - pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MAX, \ - data->in_max[offset+7]); \ - up(&data->update_lock); \ - return count; \ -} \ -static ssize_t set_temp##offset##_crit(struct device *dev, struct device_attribute *attr, const char *buf, \ - size_t count) \ -{ \ - struct i2c_client *client = to_i2c_client(dev); \ - struct pc87360_data *data = i2c_get_clientdata(client); \ - long val = simple_strtol(buf, NULL, 10); \ - \ - down(&data->update_lock); \ - data->in_crit[offset-4] = IN_TO_REG(val, data->in_vref); \ - pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_CRIT, \ - data->in_crit[offset-4]); \ - up(&data->update_lock); \ - return count; \ -} \ -static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ - show_temp##offset##_input, NULL); \ -static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \ - show_temp##offset##_min, set_temp##offset##_min); \ -static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \ - show_temp##offset##_max, set_temp##offset##_max); \ -static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \ - show_temp##offset##_crit, set_temp##offset##_crit); \ -static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \ - show_temp##offset##_status, NULL); +static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ + show_therm_input, NULL, 11+offset-4); \ +static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \ + show_therm_min, set_therm_min, 11+offset-4); \ +static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \ + show_therm_max, set_therm_max, 11+offset-4); \ +static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \ + show_therm_crit, set_therm_crit, 11+offset-4); \ +static SENSOR_DEVICE_ATTR(temp##offset##_status, S_IRUGO, \ + show_therm_status, NULL, 11+offset-4); show_and_set_therm(4) show_and_set_therm(5) show_and_set_therm(6) @@ -539,84 +553,93 @@ static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR(alarms_in, S_IRUGO, show_in_alarms, NULL); +static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index])); +} +static ssize_t show_temp_min(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index])); +} +static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index])); +} +static ssize_t show_temp_crit(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[attr->index])); +} +static ssize_t show_temp_status(struct device *dev, struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87360_data *data = pc87360_update_device(dev); + return sprintf(buf, "%d\n", data->temp_status[attr->index]); +} +static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr, const char *buf, + size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct pc87360_data *data = i2c_get_clientdata(client); + long val = simple_strtol(buf, NULL, 10); + + down(&data->update_lock); + data->temp_min[attr->index] = TEMP_TO_REG(val); + pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MIN, + data->temp_min[attr->index]); + up(&data->update_lock); + return count; +} +static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf, + size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct pc87360_data *data = i2c_get_clientdata(client); + long val = simple_strtol(buf, NULL, 10); + + down(&data->update_lock); + data->temp_max[attr->index] = TEMP_TO_REG(val); + pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MAX, + data->temp_max[attr->index]); + up(&data->update_lock); + return count; +} +static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf, + size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct pc87360_data *data = i2c_get_clientdata(client); + long val = simple_strtol(buf, NULL, 10); + + down(&data->update_lock); + data->temp_crit[attr->index] = TEMP_TO_REG(val); + pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_CRIT, + data->temp_crit[attr->index]); + up(&data->update_lock); + return count; +} + #define show_and_set_temp(offset) \ -static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \ -} \ -static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \ -} \ -static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \ -}\ -static ssize_t show_temp##offset##_crit(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[offset-1])); \ -}\ -static ssize_t show_temp##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \ -{ \ - struct pc87360_data *data = pc87360_update_device(dev); \ - return sprintf(buf, "%d\n", data->temp_status[offset-1]); \ -}\ -static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ - size_t count) \ -{ \ - struct i2c_client *client = to_i2c_client(dev); \ - struct pc87360_data *data = i2c_get_clientdata(client); \ - long val = simple_strtol(buf, NULL, 10); \ - \ - down(&data->update_lock); \ - data->temp_min[offset-1] = TEMP_TO_REG(val); \ - pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MIN, \ - data->temp_min[offset-1]); \ - up(&data->update_lock); \ - return count; \ -} \ -static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ - size_t count) \ -{ \ - struct i2c_client *client = to_i2c_client(dev); \ - struct pc87360_data *data = i2c_get_clientdata(client); \ - long val = simple_strtol(buf, NULL, 10); \ - \ - down(&data->update_lock); \ - data->temp_max[offset-1] = TEMP_TO_REG(val); \ - pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MAX, \ - data->temp_max[offset-1]); \ - up(&data->update_lock); \ - return count; \ -} \ -static ssize_t set_temp##offset##_crit(struct device *dev, struct device_attribute *attr, const char *buf, \ - size_t count) \ -{ \ - struct i2c_client *client = to_i2c_client(dev); \ - struct pc87360_data *data = i2c_get_clientdata(client); \ - long val = simple_strtol(buf, NULL, 10); \ - \ - down(&data->update_lock); \ - data->temp_crit[offset-1] = TEMP_TO_REG(val); \ - pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_CRIT, \ - data->temp_crit[offset-1]); \ - up(&data->update_lock); \ - return count; \ -} \ -static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ - show_temp##offset##_input, NULL); \ -static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \ - show_temp##offset##_min, set_temp##offset##_min); \ -static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \ - show_temp##offset##_max, set_temp##offset##_max); \ -static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \ - show_temp##offset##_crit, set_temp##offset##_crit); \ -static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \ - show_temp##offset##_status, NULL); +static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ + show_temp_input, NULL, offset-1); \ +static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \ + show_temp_min, set_temp_min, offset-1); \ +static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \ + show_temp_max, set_temp_max, offset-1); \ +static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \ + show_temp_crit, set_temp_crit, offset-1); \ +static SENSOR_DEVICE_ATTR(temp##offset##_status, S_IRUGO, \ + show_temp_status, NULL, offset-1); show_and_set_temp(1) show_and_set_temp(2) show_and_set_temp(3) @@ -632,12 +655,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 __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses) { u16 val; int i; @@ -683,7 +701,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); @@ -727,9 +745,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; @@ -738,9 +754,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)); @@ -838,51 +851,57 @@ int pc87360_detect(struct i2c_adapter *adapter, int address, int kind) } /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto ERROR3; + } + if (data->innr) { - device_create_file(&new_client->dev, &dev_attr_in0_input); - device_create_file(&new_client->dev, &dev_attr_in1_input); - device_create_file(&new_client->dev, &dev_attr_in2_input); - device_create_file(&new_client->dev, &dev_attr_in3_input); - device_create_file(&new_client->dev, &dev_attr_in4_input); - device_create_file(&new_client->dev, &dev_attr_in5_input); - device_create_file(&new_client->dev, &dev_attr_in6_input); - device_create_file(&new_client->dev, &dev_attr_in7_input); - device_create_file(&new_client->dev, &dev_attr_in8_input); - device_create_file(&new_client->dev, &dev_attr_in9_input); - device_create_file(&new_client->dev, &dev_attr_in10_input); - device_create_file(&new_client->dev, &dev_attr_in0_min); - device_create_file(&new_client->dev, &dev_attr_in1_min); - device_create_file(&new_client->dev, &dev_attr_in2_min); - device_create_file(&new_client->dev, &dev_attr_in3_min); - device_create_file(&new_client->dev, &dev_attr_in4_min); - device_create_file(&new_client->dev, &dev_attr_in5_min); - device_create_file(&new_client->dev, &dev_attr_in6_min); - device_create_file(&new_client->dev, &dev_attr_in7_min); - device_create_file(&new_client->dev, &dev_attr_in8_min); - device_create_file(&new_client->dev, &dev_attr_in9_min); - device_create_file(&new_client->dev, &dev_attr_in10_min); - device_create_file(&new_client->dev, &dev_attr_in0_max); - device_create_file(&new_client->dev, &dev_attr_in1_max); - device_create_file(&new_client->dev, &dev_attr_in2_max); - device_create_file(&new_client->dev, &dev_attr_in3_max); - device_create_file(&new_client->dev, &dev_attr_in4_max); - device_create_file(&new_client->dev, &dev_attr_in5_max); - device_create_file(&new_client->dev, &dev_attr_in6_max); - device_create_file(&new_client->dev, &dev_attr_in7_max); - device_create_file(&new_client->dev, &dev_attr_in8_max); - device_create_file(&new_client->dev, &dev_attr_in9_max); - device_create_file(&new_client->dev, &dev_attr_in10_max); - device_create_file(&new_client->dev, &dev_attr_in0_status); - device_create_file(&new_client->dev, &dev_attr_in1_status); - device_create_file(&new_client->dev, &dev_attr_in2_status); - device_create_file(&new_client->dev, &dev_attr_in3_status); - device_create_file(&new_client->dev, &dev_attr_in4_status); - device_create_file(&new_client->dev, &dev_attr_in5_status); - device_create_file(&new_client->dev, &dev_attr_in6_status); - device_create_file(&new_client->dev, &dev_attr_in7_status); - device_create_file(&new_client->dev, &dev_attr_in8_status); - device_create_file(&new_client->dev, &dev_attr_in9_status); - device_create_file(&new_client->dev, &dev_attr_in10_status); + device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in9_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in10_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in8_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in9_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in10_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in8_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in9_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in10_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in0_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in1_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in2_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in3_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in4_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in5_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in6_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in7_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in8_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in9_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_in10_status.dev_attr); device_create_file(&new_client->dev, &dev_attr_cpu0_vid); device_create_file(&new_client->dev, &dev_attr_vrm); @@ -890,90 +909,92 @@ int pc87360_detect(struct i2c_adapter *adapter, int address, int kind) } if (data->tempnr) { - device_create_file(&new_client->dev, &dev_attr_temp1_input); - device_create_file(&new_client->dev, &dev_attr_temp2_input); - device_create_file(&new_client->dev, &dev_attr_temp1_min); - device_create_file(&new_client->dev, &dev_attr_temp2_min); - device_create_file(&new_client->dev, &dev_attr_temp1_max); - device_create_file(&new_client->dev, &dev_attr_temp2_max); - device_create_file(&new_client->dev, &dev_attr_temp1_crit); - device_create_file(&new_client->dev, &dev_attr_temp2_crit); - device_create_file(&new_client->dev, &dev_attr_temp1_status); - device_create_file(&new_client->dev, &dev_attr_temp2_status); + device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp1_crit.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp2_crit.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp1_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp2_status.dev_attr); device_create_file(&new_client->dev, &dev_attr_alarms_temp); } if (data->tempnr == 3) { - device_create_file(&new_client->dev, &dev_attr_temp3_input); - device_create_file(&new_client->dev, &dev_attr_temp3_min); - device_create_file(&new_client->dev, &dev_attr_temp3_max); - device_create_file(&new_client->dev, &dev_attr_temp3_crit); - device_create_file(&new_client->dev, &dev_attr_temp3_status); + device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp3_crit.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp3_status.dev_attr); } if (data->innr == 14) { - device_create_file(&new_client->dev, &dev_attr_temp4_input); - device_create_file(&new_client->dev, &dev_attr_temp5_input); - device_create_file(&new_client->dev, &dev_attr_temp6_input); - device_create_file(&new_client->dev, &dev_attr_temp4_min); - device_create_file(&new_client->dev, &dev_attr_temp5_min); - device_create_file(&new_client->dev, &dev_attr_temp6_min); - device_create_file(&new_client->dev, &dev_attr_temp4_max); - device_create_file(&new_client->dev, &dev_attr_temp5_max); - device_create_file(&new_client->dev, &dev_attr_temp6_max); - device_create_file(&new_client->dev, &dev_attr_temp4_crit); - device_create_file(&new_client->dev, &dev_attr_temp5_crit); - device_create_file(&new_client->dev, &dev_attr_temp6_crit); - device_create_file(&new_client->dev, &dev_attr_temp4_status); - device_create_file(&new_client->dev, &dev_attr_temp5_status); - device_create_file(&new_client->dev, &dev_attr_temp6_status); + device_create_file(&new_client->dev, &sensor_dev_attr_temp4_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp5_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp6_input.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp4_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp5_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp6_min.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp4_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp5_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp6_max.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp4_crit.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp5_crit.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp6_crit.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp4_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp5_status.dev_attr); + device_create_file(&new_client->dev, &sensor_dev_attr_temp6_status.dev_attr); } if (data->fannr) { if (FAN_CONFIG_MONITOR(data->fan_conf, 0)) { device_create_file(&new_client->dev, - &dev_attr_fan1_input); + &sensor_dev_attr_fan1_input.dev_attr); device_create_file(&new_client->dev, - &dev_attr_fan1_min); + &sensor_dev_attr_fan1_min.dev_attr); device_create_file(&new_client->dev, - &dev_attr_fan1_div); + &sensor_dev_attr_fan1_div.dev_attr); device_create_file(&new_client->dev, - &dev_attr_fan1_status); + &sensor_dev_attr_fan1_status.dev_attr); } if (FAN_CONFIG_MONITOR(data->fan_conf, 1)) { device_create_file(&new_client->dev, - &dev_attr_fan2_input); + &sensor_dev_attr_fan2_input.dev_attr); device_create_file(&new_client->dev, - &dev_attr_fan2_min); + &sensor_dev_attr_fan2_min.dev_attr); device_create_file(&new_client->dev, - &dev_attr_fan2_div); + &sensor_dev_attr_fan2_div.dev_attr); device_create_file(&new_client->dev, - &dev_attr_fan2_status); + &sensor_dev_attr_fan2_status.dev_attr); } if (FAN_CONFIG_CONTROL(data->fan_conf, 0)) - device_create_file(&new_client->dev, &dev_attr_pwm1); + device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr); if (FAN_CONFIG_CONTROL(data->fan_conf, 1)) - device_create_file(&new_client->dev, &dev_attr_pwm2); + device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr); } if (data->fannr == 3) { if (FAN_CONFIG_MONITOR(data->fan_conf, 2)) { device_create_file(&new_client->dev, - &dev_attr_fan3_input); + &sensor_dev_attr_fan3_input.dev_attr); device_create_file(&new_client->dev, - &dev_attr_fan3_min); + &sensor_dev_attr_fan3_min.dev_attr); device_create_file(&new_client->dev, - &dev_attr_fan3_div); + &sensor_dev_attr_fan3_div.dev_attr); device_create_file(&new_client->dev, - &dev_attr_fan3_status); + &sensor_dev_attr_fan3_status.dev_attr); } if (FAN_CONFIG_CONTROL(data->fan_conf, 2)) - device_create_file(&new_client->dev, &dev_attr_pwm3); + device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr); } return 0; +ERROR3: + i2c_detach_client(new_client); ERROR2: for (i = 0; i < 3; i++) { if (data->address[i]) { @@ -990,11 +1011,10 @@ static int pc87360_detach_client(struct i2c_client *client) struct pc87360_data *data = i2c_get_clientdata(client); int i; - if ((i = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((i = i2c_detach_client(client))) return i; - } for (i = 0; i < 3; i++) { if (data->address[i]) { @@ -1320,23 +1340,23 @@ 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; } - return i2c_add_driver(&pc87360_driver); + return i2c_isa_add_driver(&pc87360_driver); } static void __exit pc87360_exit(void) { - i2c_del_driver(&pc87360_driver); + i2c_isa_del_driver(&pc87360_driver); } diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c index 6bbfc8fb4f1..8610bce0824 100644 --- a/drivers/hwmon/sis5595.c +++ b/drivers/hwmon/sis5595.c @@ -55,7 +55,9 @@ #include <linux/ioport.h> #include <linux/pci.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/i2c-isa.h> +#include <linux/hwmon.h> +#include <linux/err.h> #include <linux/init.h> #include <linux/jiffies.h> #include <asm/io.h> @@ -68,14 +70,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 */ @@ -168,6 +166,7 @@ static inline u8 DIV_TO_REG(int val) allocated. */ struct sis5595_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; struct semaphore update_lock; @@ -190,8 +189,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); @@ -202,9 +200,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, }; @@ -476,14 +472,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; @@ -492,10 +481,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 */ @@ -578,6 +563,12 @@ int sis5595_detect(struct i2c_adapter *adapter, int address, int kind) } /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_in0_input); device_create_file(&new_client->dev, &dev_attr_in0_min); device_create_file(&new_client->dev, &dev_attr_in0_max); @@ -608,7 +599,9 @@ int sis5595_detect(struct i2c_adapter *adapter, int address, int kind) device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst); } return 0; - + +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit_release: @@ -619,18 +612,17 @@ exit: static int sis5595_detach_client(struct i2c_client *client) { + struct sis5595_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, - "Client deregistration failed, client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - if (i2c_is_isa_client(client)) - release_region(client->addr, SIS5595_EXTENT); + release_region(client->addr, SIS5595_EXTENT); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } @@ -745,7 +737,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; @@ -761,22 +752,19 @@ 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_add_driver(&sis5595_driver)) { + if (i2c_isa_add_driver(&sis5595_driver)) { pci_dev_put(s_bridge); s_bridge = NULL; } @@ -803,7 +791,7 @@ static void __exit sm_sis5595_exit(void) { pci_unregister_driver(&sis5595_pci_driver); if (s_bridge != NULL) { - i2c_del_driver(&sis5595_driver); + i2c_isa_del_driver(&sis5595_driver); pci_dev_put(s_bridge); s_bridge = NULL; } diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c index fdeeb3ab6f2..7fe71576dea 100644 --- a/drivers/hwmon/smsc47b397.c +++ b/drivers/hwmon/smsc47b397.c @@ -31,23 +31,14 @@ #include <linux/ioport.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/i2c-isa.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 */ @@ -100,6 +91,7 @@ static u8 smsc47b397_reg_temp[] = {0x25, 0x26, 0x27, 0x80}; struct smsc47b397_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; struct semaphore update_lock; @@ -215,52 +207,40 @@ 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); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } release_region(client->addr, SMSC_EXTENT); - kfree(i2c_get_clientdata(client)); + kfree(data); 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; } @@ -272,7 +252,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; @@ -285,6 +265,12 @@ static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind) if ((err = i2c_attach_client(new_client))) goto error_free; + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto error_detach; + } + device_create_file_temp(new_client, 1); device_create_file_temp(new_client, 2); device_create_file_temp(new_client, 3); @@ -297,14 +283,16 @@ static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind) return 0; +error_detach: + i2c_detach_client(new_client); 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; @@ -333,15 +321,15 @@ static int __init smsc47b397_init(void) { int ret; - if ((ret = smsc47b397_find(normal_isa))) + if ((ret = smsc47b397_find(&address))) return ret; - return i2c_add_driver(&smsc47b397_driver); + return i2c_isa_add_driver(&smsc47b397_driver); } static void __exit smsc47b397_exit(void) { - i2c_del_driver(&smsc47b397_driver); + i2c_isa_del_driver(&smsc47b397_driver); } MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index 7166ad0b2fd..7e699a8ede2 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c @@ -30,21 +30,14 @@ #include <linux/ioport.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/i2c-isa.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, smsc47m1 }; -static struct i2c_address_data addr_data = { - .normal_i2c = normal_i2c, - .normal_isa = normal_isa, - .forces = forces, -}; +static unsigned short address; /* Super-I/0 registers and commands */ @@ -108,6 +101,7 @@ superio_exit(void) struct smsc47m1_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; struct semaphore update_lock; @@ -121,9 +115,7 @@ struct smsc47m1_data { }; -static int smsc47m1_attach_adapter(struct i2c_adapter *adapter); -static int smsc47m1_find(int *address); -static int smsc47m1_detect(struct i2c_adapter *adapter, int address, int kind); +static int smsc47m1_detect(struct i2c_adapter *adapter); static int smsc47m1_detach_client(struct i2c_client *client); static int smsc47m1_read_value(struct i2c_client *client, u8 reg); @@ -136,9 +128,7 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev, static struct i2c_driver smsc47m1_driver = { .owner = THIS_MODULE, .name = "smsc47m1", - .id = I2C_DRIVERID_SMSC47M1, - .flags = I2C_DF_NOTIFY, - .attach_adapter = smsc47m1_attach_adapter, + .attach_adapter = smsc47m1_detect, .detach_client = smsc47m1_detach_client, }; @@ -354,14 +344,7 @@ fan_present(2); static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL); -static int smsc47m1_attach_adapter(struct i2c_adapter *adapter) -{ - if (!(adapter->class & I2C_CLASS_HWMON)) - return 0; - return i2c_detect(adapter, &addr_data, smsc47m1_detect); -} - -static int smsc47m1_find(int *address) +static int __init smsc47m1_find(unsigned short *addr) { u8 val; @@ -388,10 +371,10 @@ static int smsc47m1_find(int *address) } superio_select(); - *address = (superio_inb(SUPERIO_REG_BASE) << 8) - | superio_inb(SUPERIO_REG_BASE + 1); + *addr = (superio_inb(SUPERIO_REG_BASE) << 8) + | superio_inb(SUPERIO_REG_BASE + 1); val = superio_inb(SUPERIO_REG_ACT); - if (*address == 0 || (val & 0x01) == 0) { + if (*addr == 0 || (val & 0x01) == 0) { printk(KERN_INFO "smsc47m1: Device is disabled, will not use\n"); superio_exit(); return -ENODEV; @@ -401,17 +384,13 @@ static int smsc47m1_find(int *address) return 0; } -static int smsc47m1_detect(struct i2c_adapter *adapter, int address, int kind) +static int smsc47m1_detect(struct i2c_adapter *adapter) { struct i2c_client *new_client; struct smsc47m1_data *data; int err = 0; int fan1, fan2, pwm1, pwm2; - if (!i2c_is_isa_adapter(adapter)) { - return 0; - } - if (!request_region(address, SMSC_EXTENT, smsc47m1_driver.name)) { dev_err(&adapter->dev, "Region 0x%x already in use!\n", address); return -EBUSY; @@ -461,6 +440,13 @@ static int smsc47m1_detect(struct i2c_adapter *adapter, int address, int kind) function. */ smsc47m1_update_device(&new_client->dev, 1); + /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto error_detach; + } + if (fan1) { device_create_file(&new_client->dev, &dev_attr_fan1_input); device_create_file(&new_client->dev, &dev_attr_fan1_min); @@ -494,6 +480,8 @@ static int smsc47m1_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +error_detach: + i2c_detach_client(new_client); error_free: kfree(data); error_release: @@ -503,16 +491,16 @@ error_release: static int smsc47m1_detach_client(struct i2c_client *client) { + struct smsc47m1_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } release_region(client->addr, SMSC_EXTENT); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } @@ -573,16 +561,16 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev, static int __init sm_smsc47m1_init(void) { - if (smsc47m1_find(normal_isa)) { + if (smsc47m1_find(&address)) { return -ENODEV; } - return i2c_add_driver(&smsc47m1_driver); + return i2c_isa_add_driver(&smsc47m1_driver); } static void __exit sm_smsc47m1_exit(void) { - i2c_del_driver(&smsc47m1_driver); + i2c_isa_del_driver(&smsc47m1_driver); } MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>"); diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c index 164d4794839..eb84997627c 100644 --- a/drivers/hwmon/via686a.c +++ b/drivers/hwmon/via686a.c @@ -35,7 +35,9 @@ #include <linux/pci.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/i2c-isa.h> +#include <linux/hwmon.h> +#include <linux/err.h> #include <linux/init.h> #include <asm/io.h> @@ -47,14 +49,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(via686a); +static unsigned short address; /* The Via 686a southbridge has a LM78-like chip integrated on the same IC. @@ -297,6 +295,7 @@ static inline long TEMP_FROM_REG10(u16 val) via686a client is allocated. */ struct via686a_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* !=0 if following fields are valid */ unsigned long last_updated; /* In jiffies */ @@ -315,8 +314,7 @@ struct via686a_data { static struct pci_dev *s_bridge; /* pointer to the (only) via686a */ -static int via686a_attach_adapter(struct i2c_adapter *adapter); -static int via686a_detect(struct i2c_adapter *adapter, int address, int kind); +static int via686a_detect(struct i2c_adapter *adapter); static int via686a_detach_client(struct i2c_client *client); static inline int via686a_read_value(struct i2c_client *client, u8 reg) @@ -576,22 +574,13 @@ static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); static struct i2c_driver via686a_driver = { .owner = THIS_MODULE, .name = "via686a", - .id = I2C_DRIVERID_VIA686A, - .flags = I2C_DF_NOTIFY, - .attach_adapter = via686a_attach_adapter, + .attach_adapter = via686a_detect, .detach_client = via686a_detach_client, }; /* This is called when the module is loaded */ -static int via686a_attach_adapter(struct i2c_adapter *adapter) -{ - if (!(adapter->class & I2C_CLASS_HWMON)) - return 0; - return i2c_detect(adapter, &addr_data, via686a_detect); -} - -static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) +static int via686a_detect(struct i2c_adapter *adapter) { struct i2c_client *new_client; struct via686a_data *data; @@ -599,13 +588,6 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) const char client_name[] = "via686a"; u16 val; - /* Make sure we are probing the ISA bus!! */ - if (!i2c_is_isa_adapter(adapter)) { - dev_err(&adapter->dev, - "via686a_detect called for an I2C bus adapter?!?\n"); - return 0; - } - /* 8231 requires multiple of 256, we enforce that on 686 as well */ if (force_addr) address = force_addr & 0xFF00; @@ -637,7 +619,7 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) { err = -ENOMEM; - goto ERROR0; + goto exit_release; } memset(data, 0, sizeof(struct via686a_data)); @@ -655,12 +637,18 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) init_MUTEX(&data->update_lock); /* Tell the I2C layer a new client has arrived */ if ((err = i2c_attach_client(new_client))) - goto ERROR3; + goto exit_free; /* Initialize the VIA686A chip */ via686a_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_in0_input); device_create_file(&new_client->dev, &dev_attr_in1_input); device_create_file(&new_client->dev, &dev_attr_in2_input); @@ -695,25 +683,27 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) return 0; -ERROR3: +exit_detach: + i2c_detach_client(new_client); +exit_free: kfree(data); -ERROR0: +exit_release: release_region(address, VIA686A_EXTENT); return err; } static int via686a_detach_client(struct i2c_client *client) { + struct via686a_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, - "Client deregistration failed, client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } release_region(client->addr, VIA686A_EXTENT); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } @@ -810,29 +800,25 @@ static int __devinit via686a_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { u16 val; - int addr = 0; if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VIA686A_BASE_REG, &val)) return -ENODEV; - addr = val & ~(VIA686A_EXTENT - 1); - if (addr == 0 && force_addr == 0) { + address = val & ~(VIA686A_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 Via 686A sensors found.\n"); return -ENODEV; } - normal_isa[0] = addr; s_bridge = pci_dev_get(dev); - if (i2c_add_driver(&via686a_driver)) { + if (i2c_isa_add_driver(&via686a_driver)) { pci_dev_put(s_bridge); s_bridge = NULL; } @@ -859,7 +845,7 @@ static void __exit sm_via686a_exit(void) { pci_unregister_driver(&via686a_pci_driver); if (s_bridge != NULL) { - i2c_del_driver(&via686a_driver); + i2c_isa_del_driver(&via686a_driver); pci_dev_put(s_bridge); s_bridge = NULL; } diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c index 8a40b6976e1..b60efe8f8b2 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c @@ -9,6 +9,9 @@ Thanks to Leon Moonen, Steve Cliffe and Grant Coady for their help in testing and debugging this driver. + This driver also supports the W83627EHG, which is the lead-free + version of the W83627EHF. + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -37,17 +40,14 @@ #include <linux/init.h> #include <linux/slab.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/i2c-isa.h> +#include <linux/hwmon.h> +#include <linux/err.h> #include <asm/io.h> #include "lm75.h" -/* Addresses to scan - The actual ISA address is read from Super-I/O configuration space */ -static unsigned short normal_i2c[] = { I2C_CLIENT_END }; -static unsigned int normal_isa[] = { 0, I2C_CLIENT_ISA_END }; - -/* Insmod parameters */ -SENSORS_INSMOD_1(w83627ehf); +/* The actual ISA address is read from Super-I/O configuration space */ +static unsigned short address; /* * Super-I/O constants and functions @@ -174,6 +174,7 @@ temp1_to_reg(int temp) struct w83627ehf_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; struct semaphore update_lock; @@ -666,15 +667,12 @@ static void w83627ehf_init_client(struct i2c_client *client) } } -static int w83627ehf_detect(struct i2c_adapter *adapter, int address, int kind) +static int w83627ehf_detect(struct i2c_adapter *adapter) { struct i2c_client *client; struct w83627ehf_data *data; int i, err = 0; - if (!i2c_is_isa_adapter(adapter)) - return 0; - if (!request_region(address, REGION_LENGTH, w83627ehf_driver.name)) { err = -EBUSY; goto exit; @@ -720,6 +718,12 @@ static int w83627ehf_detect(struct i2c_adapter *adapter, int address, int kind) data->has_fan |= (1 << 4); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&client->dev, &dev_attr_fan1_input); device_create_file(&client->dev, &dev_attr_fan1_min); device_create_file(&client->dev, &dev_attr_fan1_div); @@ -753,6 +757,8 @@ static int w83627ehf_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(client); exit_free: kfree(data); exit_release: @@ -761,24 +767,17 @@ exit: return err; } -static int w83627ehf_attach_adapter(struct i2c_adapter *adapter) -{ - if (!(adapter->class & I2C_CLASS_HWMON)) - return 0; - return i2c_detect(adapter, &addr_data, w83627ehf_detect); -} - static int w83627ehf_detach_client(struct i2c_client *client) { + struct w83627ehf_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } release_region(client->addr, REGION_LENGTH); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } @@ -786,12 +785,11 @@ static int w83627ehf_detach_client(struct i2c_client *client) static struct i2c_driver w83627ehf_driver = { .owner = THIS_MODULE, .name = "w83627ehf", - .flags = I2C_DF_NOTIFY, - .attach_adapter = w83627ehf_attach_adapter, + .attach_adapter = w83627ehf_detect, .detach_client = w83627ehf_detach_client, }; -static int __init w83627ehf_find(int sioaddr, int *address) +static int __init w83627ehf_find(int sioaddr, unsigned short *addr) { u16 val; @@ -809,8 +807,8 @@ static int __init w83627ehf_find(int sioaddr, int *address) superio_select(W83627EHF_LD_HWM); val = (superio_inb(SIO_REG_ADDR) << 8) | superio_inb(SIO_REG_ADDR + 1); - *address = val & ~(REGION_LENGTH - 1); - if (*address == 0) { + *addr = val & ~(REGION_LENGTH - 1); + if (*addr == 0) { superio_exit(); return -ENODEV; } @@ -826,16 +824,16 @@ static int __init w83627ehf_find(int sioaddr, int *address) static int __init sensors_w83627ehf_init(void) { - if (w83627ehf_find(0x2e, &normal_isa[0]) - && w83627ehf_find(0x4e, &normal_isa[0])) + if (w83627ehf_find(0x2e, &address) + && w83627ehf_find(0x4e, &address)) return -ENODEV; - return i2c_add_driver(&w83627ehf_driver); + return i2c_isa_add_driver(&w83627ehf_driver); } static void __exit sensors_w83627ehf_exit(void) { - i2c_del_driver(&w83627ehf_driver); + i2c_isa_del_driver(&w83627ehf_driver); } MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c index bd87a42e068..02bd5c0239a 100644 --- a/drivers/hwmon/w83627hf.c +++ b/drivers/hwmon/w83627hf.c @@ -42,8 +42,10 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> -#include <linux/i2c-vid.h> +#include <linux/i2c-isa.h> +#include <linux/hwmon.h> +#include <linux/hwmon-vid.h> +#include <linux/err.h> #include <asm/io.h> #include "lm75.h" @@ -56,12 +58,11 @@ module_param(force_i2c, byte, 0); MODULE_PARM_DESC(force_i2c, "Initialize the i2c address of the sensors"); -/* Addresses to scan */ -static unsigned short normal_i2c[] = { I2C_CLIENT_END }; -static unsigned int normal_isa[] = { 0, I2C_CLIENT_ISA_END }; +/* The actual ISA address is read from Super-I/O configuration space */ +static unsigned short address; /* Insmod parameters */ -SENSORS_INSMOD_4(w83627hf, w83627thf, w83697hf, w83637hf); +enum chips { any_chip, w83627hf, w83627thf, w83697hf, w83637hf }; static int init = 1; module_param(init, bool, 0); @@ -277,6 +278,7 @@ static inline u8 DIV_TO_REG(long val) dynamically allocated, at the same time when a new client is allocated. */ struct w83627hf_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; enum chips type; @@ -314,9 +316,7 @@ struct w83627hf_data { }; -static int w83627hf_attach_adapter(struct i2c_adapter *adapter); -static int w83627hf_detect(struct i2c_adapter *adapter, int address, - int kind); +static int w83627hf_detect(struct i2c_adapter *adapter); static int w83627hf_detach_client(struct i2c_client *client); static int w83627hf_read_value(struct i2c_client *client, u16 register); @@ -328,9 +328,7 @@ static void w83627hf_init_client(struct i2c_client *client); static struct i2c_driver w83627hf_driver = { .owner = THIS_MODULE, .name = "w83627hf", - .id = I2C_DRIVERID_W83627HF, - .flags = I2C_DF_NOTIFY, - .attach_adapter = w83627hf_attach_adapter, + .attach_adapter = w83627hf_detect, .detach_client = w83627hf_detach_client, }; @@ -959,16 +957,7 @@ device_create_file(&client->dev, &dev_attr_temp##offset##_type); \ } while (0) -/* This function is called when: - * w83627hf_driver is inserted (when this module is loaded), for each - available adapter - * when a new adapter is inserted (and w83627hf_driver is still present) */ -static int w83627hf_attach_adapter(struct i2c_adapter *adapter) -{ - return i2c_detect(adapter, &addr_data, w83627hf_detect); -} - -static int w83627hf_find(int sioaddr, int *address) +static int __init w83627hf_find(int sioaddr, unsigned short *addr) { u16 val; @@ -988,32 +977,24 @@ static int w83627hf_find(int sioaddr, int *address) superio_select(W83627HF_LD_HWM); val = (superio_inb(WINB_BASE_REG) << 8) | superio_inb(WINB_BASE_REG + 1); - *address = val & ~(WINB_EXTENT - 1); - if (*address == 0 && force_addr == 0) { + *addr = val & ~(WINB_EXTENT - 1); + if (*addr == 0 && force_addr == 0) { superio_exit(); return -ENODEV; } - if (force_addr) - *address = force_addr; /* so detect will get called */ superio_exit(); return 0; } -int w83627hf_detect(struct i2c_adapter *adapter, int address, - int kind) +static int w83627hf_detect(struct i2c_adapter *adapter) { - int val; + int val, kind; struct i2c_client *new_client; struct w83627hf_data *data; int err = 0; const char *client_name = ""; - if (!i2c_is_isa_adapter(adapter)) { - err = -ENODEV; - goto ERROR0; - } - if(force_addr) address = force_addr & ~(WINB_EXTENT - 1); @@ -1102,6 +1083,12 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address, data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3)); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto ERROR3; + } + device_create_file_in(new_client, 0); if (kind != w83697hf) device_create_file_in(new_client, 1); @@ -1152,6 +1139,8 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address, return 0; + ERROR3: + i2c_detach_client(new_client); ERROR2: kfree(data); ERROR1: @@ -1162,16 +1151,16 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address, static int w83627hf_detach_client(struct i2c_client *client) { + struct w83627hf_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, - "Client deregistration failed, client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } release_region(client->addr, WINB_EXTENT); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } @@ -1327,7 +1316,7 @@ static void w83627hf_init_client(struct i2c_client *client) data->vrm = (data->vrm_ovt & 0x01) ? 90 : 82; } else { /* Convert VID to voltage based on default VRM */ - data->vrm = i2c_which_vrm(); + data->vrm = vid_which_vrm(); } tmp = w83627hf_read_value(client, W83781D_REG_SCFG1); @@ -1485,20 +1474,17 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev) static int __init sensors_w83627hf_init(void) { - int addr; - - if (w83627hf_find(0x2e, &addr) - && w83627hf_find(0x4e, &addr)) { + if (w83627hf_find(0x2e, &address) + && w83627hf_find(0x4e, &address)) { return -ENODEV; } - normal_isa[0] = addr; - return i2c_add_driver(&w83627hf_driver); + return i2c_isa_add_driver(&w83627hf_driver); } static void __exit sensors_w83627hf_exit(void) { - i2c_del_driver(&w83627hf_driver); + i2c_isa_del_driver(&w83627hf_driver); } MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c index 0bb131ce09e..4c43337ca78 100644 --- a/drivers/hwmon/w83781d.c +++ b/drivers/hwmon/w83781d.c @@ -38,8 +38,10 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> -#include <linux/i2c-vid.h> +#include <linux/i2c-isa.h> +#include <linux/hwmon.h> +#include <linux/hwmon-vid.h> +#include <linux/err.h> #include <asm/io.h> #include "lm75.h" @@ -47,10 +49,10 @@ 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 short isa_address = 0x290; /* Insmod parameters */ -SENSORS_INSMOD_5(w83781d, w83782d, w83783s, w83627hf, as99127f); +I2C_CLIENT_INSMOD_5(w83781d, w83782d, w83783s, w83627hf, as99127f); I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: " "{bus, clientaddr, subclientaddr1, subclientaddr2}"); @@ -218,6 +220,7 @@ DIV_TO_REG(long val, enum chips type) allocated. */ struct w83781d_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; enum chips type; @@ -255,6 +258,7 @@ struct w83781d_data { }; static int w83781d_attach_adapter(struct i2c_adapter *adapter); +static int w83781d_isa_attach_adapter(struct i2c_adapter *adapter); static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind); static int w83781d_detach_client(struct i2c_client *client); @@ -273,6 +277,14 @@ static struct i2c_driver w83781d_driver = { .detach_client = w83781d_detach_client, }; +static struct i2c_driver w83781d_isa_driver = { + .owner = THIS_MODULE, + .name = "w83781d-isa", + .attach_adapter = w83781d_isa_attach_adapter, + .detach_client = w83781d_detach_client, +}; + + /* following are the sysfs callback functions */ #define show_in_reg(reg) \ static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ @@ -856,7 +868,13 @@ w83781d_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, w83781d_detect); + return i2c_probe(adapter, &addr_data, w83781d_detect); +} + +static int +w83781d_isa_attach_adapter(struct i2c_adapter *adapter) +{ + return w83781d_detect(adapter, isa_address, -1); } /* Assumes that adapter is of I2C, not ISA variety. @@ -961,10 +979,10 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, ERROR_SC_3: i2c_detach_client(data->lm75[0]); ERROR_SC_2: - if (NULL != data->lm75[1]) + if (data->lm75[1]) kfree(data->lm75[1]); ERROR_SC_1: - if (NULL != data->lm75[0]) + if (data->lm75[0]) kfree(data->lm75[0]); ERROR_SC_0: return err; @@ -999,7 +1017,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) if (is_isa) if (!request_region(address, W83781D_EXTENT, - w83781d_driver.name)) { + w83781d_isa_driver.name)) { dev_dbg(&adapter->dev, "Request of region " "0x%x-0x%x for w83781d failed\n", address, address + W83781D_EXTENT - 1); @@ -1057,7 +1075,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) new_client->addr = address; init_MUTEX(&data->lock); new_client->adapter = adapter; - new_client->driver = &w83781d_driver; + new_client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver; new_client->flags = 0; /* Now, we do the remaining detection. */ @@ -1189,6 +1207,12 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) data->pwmenable[i] = 1; /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto ERROR4; + } + device_create_file_in(new_client, 0); if (kind != w83783s) device_create_file_in(new_client, 1); @@ -1241,6 +1265,15 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +ERROR4: + if (data->lm75[1]) { + i2c_detach_client(data->lm75[1]); + kfree(data->lm75[1]); + } + if (data->lm75[0]) { + i2c_detach_client(data->lm75[0]); + kfree(data->lm75[0]); + } ERROR3: i2c_detach_client(new_client); ERROR2: @@ -1255,24 +1288,26 @@ ERROR0: static int w83781d_detach_client(struct i2c_client *client) { + struct w83781d_data *data = i2c_get_clientdata(client); int err; + /* main client */ + if (data) + hwmon_device_unregister(data->class_dev); + if (i2c_is_isa_client(client)) release_region(client->addr, W83781D_EXTENT); - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, - "Client deregistration failed, client not detached.\n"); + if ((err = i2c_detach_client(client))) return err; - } - if (i2c_get_clientdata(client)==NULL) { - /* subclients */ + /* main client */ + if (data) + kfree(data); + + /* subclient */ + else kfree(client); - } else { - /* main client */ - kfree(i2c_get_clientdata(client)); - } return 0; } @@ -1443,7 +1478,7 @@ w83781d_init_client(struct i2c_client *client) w83781d_write_value(client, W83781D_REG_BEEP_INTS2, 0); } - data->vrm = i2c_which_vrm(); + data->vrm = vid_which_vrm(); if ((type != w83781d) && (type != as99127f)) { tmp = w83781d_read_value(client, W83781D_REG_SCFG1); @@ -1613,12 +1648,25 @@ static struct w83781d_data *w83781d_update_device(struct device *dev) static int __init sensors_w83781d_init(void) { - return i2c_add_driver(&w83781d_driver); + int res; + + res = i2c_add_driver(&w83781d_driver); + if (res) + return res; + + res = i2c_isa_add_driver(&w83781d_isa_driver); + if (res) { + i2c_del_driver(&w83781d_driver); + return res; + } + + return 0; } static void __exit sensors_w83781d_exit(void) { + i2c_isa_del_driver(&w83781d_isa_driver); i2c_del_driver(&w83781d_driver); } diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c new file mode 100644 index 00000000000..ba0c28015f6 --- /dev/null +++ b/drivers/hwmon/w83792d.c @@ -0,0 +1,1649 @@ +/* + w83792d.c - Part of lm_sensors, Linux kernel modules for hardware + monitoring + Copyright (C) 2004, 2005 Winbond Electronics Corp. + Chunhao Huang <DZShen@Winbond.com.tw>, + Rudolf Marek <r.marek@sh.cvut.cz> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + Note: + 1. This driver is only for 2.6 kernel, 2.4 kernel need a different driver. + 2. This driver is only for Winbond W83792D C version device, there + are also some motherboards with B version W83792D device. The + calculation method to in6-in7(measured value, limits) is a little + different between C and B version. C or B version can be identified + by CR[0x49h]. +*/ + +/* + Supports following chips: + + Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA + w83792d 9 7 7 3 0x7a 0x5ca3 yes no +*/ + +#include <linux/config.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/i2c.h> +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> +#include <linux/err.h> + +/* Addresses to scan */ +static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; + +/* Insmod parameters */ +I2C_CLIENT_INSMOD_1(w83792d); +I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: " + "{bus, clientaddr, subclientaddr1, subclientaddr2}"); + +static int init; +module_param(init, bool, 0); +MODULE_PARM_DESC(init, "Set to one to force chip initialization"); + +/* The W83792D registers */ +static const u8 W83792D_REG_IN[9] = { + 0x20, /* Vcore A in DataSheet */ + 0x21, /* Vcore B in DataSheet */ + 0x22, /* VIN0 in DataSheet */ + 0x23, /* VIN1 in DataSheet */ + 0x24, /* VIN2 in DataSheet */ + 0x25, /* VIN3 in DataSheet */ + 0x26, /* 5VCC in DataSheet */ + 0xB0, /* 5VSB in DataSheet */ + 0xB1 /* VBAT in DataSheet */ +}; +#define W83792D_REG_LOW_BITS1 0x3E /* Low Bits I in DataSheet */ +#define W83792D_REG_LOW_BITS2 0x3F /* Low Bits II in DataSheet */ +static const u8 W83792D_REG_IN_MAX[9] = { + 0x2B, /* Vcore A High Limit in DataSheet */ + 0x2D, /* Vcore B High Limit in DataSheet */ + 0x2F, /* VIN0 High Limit in DataSheet */ + 0x31, /* VIN1 High Limit in DataSheet */ + 0x33, /* VIN2 High Limit in DataSheet */ + 0x35, /* VIN3 High Limit in DataSheet */ + 0x37, /* 5VCC High Limit in DataSheet */ + 0xB4, /* 5VSB High Limit in DataSheet */ + 0xB6 /* VBAT High Limit in DataSheet */ +}; +static const u8 W83792D_REG_IN_MIN[9] = { + 0x2C, /* Vcore A Low Limit in DataSheet */ + 0x2E, /* Vcore B Low Limit in DataSheet */ + 0x30, /* VIN0 Low Limit in DataSheet */ + 0x32, /* VIN1 Low Limit in DataSheet */ + 0x34, /* VIN2 Low Limit in DataSheet */ + 0x36, /* VIN3 Low Limit in DataSheet */ + 0x38, /* 5VCC Low Limit in DataSheet */ + 0xB5, /* 5VSB Low Limit in DataSheet */ + 0xB7 /* VBAT Low Limit in DataSheet */ +}; +static const u8 W83792D_REG_FAN[7] = { + 0x28, /* FAN 1 Count in DataSheet */ + 0x29, /* FAN 2 Count in DataSheet */ + 0x2A, /* FAN 3 Count in DataSheet */ + 0xB8, /* FAN 4 Count in DataSheet */ + 0xB9, /* FAN 5 Count in DataSheet */ + 0xBA, /* FAN 6 Count in DataSheet */ + 0xBE /* FAN 7 Count in DataSheet */ +}; +static const u8 W83792D_REG_FAN_MIN[7] = { + 0x3B, /* FAN 1 Count Low Limit in DataSheet */ + 0x3C, /* FAN 2 Count Low Limit in DataSheet */ + 0x3D, /* FAN 3 Count Low Limit in DataSheet */ + 0xBB, /* FAN 4 Count Low Limit in DataSheet */ + 0xBC, /* FAN 5 Count Low Limit in DataSheet */ + 0xBD, /* FAN 6 Count Low Limit in DataSheet */ + 0xBF /* FAN 7 Count Low Limit in DataSheet */ +}; +#define W83792D_REG_FAN_CFG 0x84 /* FAN Configuration in DataSheet */ +static const u8 W83792D_REG_FAN_DIV[4] = { + 0x47, /* contains FAN2 and FAN1 Divisor */ + 0x5B, /* contains FAN4 and FAN3 Divisor */ + 0x5C, /* contains FAN6 and FAN5 Divisor */ + 0x9E /* contains FAN7 Divisor. */ +}; +static const u8 W83792D_REG_PWM[7] = { + 0x81, /* FAN 1 Duty Cycle, be used to control */ + 0x83, /* FAN 2 Duty Cycle, be used to control */ + 0x94, /* FAN 3 Duty Cycle, be used to control */ + 0xA3, /* FAN 4 Duty Cycle, be used to control */ + 0xA4, /* FAN 5 Duty Cycle, be used to control */ + 0xA5, /* FAN 6 Duty Cycle, be used to control */ + 0xA6 /* FAN 7 Duty Cycle, be used to control */ +}; +#define W83792D_REG_BANK 0x4E +#define W83792D_REG_TEMP2_CONFIG 0xC2 +#define W83792D_REG_TEMP3_CONFIG 0xCA + +static const u8 W83792D_REG_TEMP1[3] = { + 0x27, /* TEMP 1 in DataSheet */ + 0x39, /* TEMP 1 Over in DataSheet */ + 0x3A, /* TEMP 1 Hyst in DataSheet */ +}; + +static const u8 W83792D_REG_TEMP_ADD[2][6] = { + { 0xC0, /* TEMP 2 in DataSheet */ + 0xC1, /* TEMP 2(0.5 deg) in DataSheet */ + 0xC5, /* TEMP 2 Over High part in DataSheet */ + 0xC6, /* TEMP 2 Over Low part in DataSheet */ + 0xC3, /* TEMP 2 Thyst High part in DataSheet */ + 0xC4 }, /* TEMP 2 Thyst Low part in DataSheet */ + { 0xC8, /* TEMP 3 in DataSheet */ + 0xC9, /* TEMP 3(0.5 deg) in DataSheet */ + 0xCD, /* TEMP 3 Over High part in DataSheet */ + 0xCE, /* TEMP 3 Over Low part in DataSheet */ + 0xCB, /* TEMP 3 Thyst High part in DataSheet */ + 0xCC } /* TEMP 3 Thyst Low part in DataSheet */ +}; + +static const u8 W83792D_REG_THERMAL[3] = { + 0x85, /* SmartFanI: Fan1 target value */ + 0x86, /* SmartFanI: Fan2 target value */ + 0x96 /* SmartFanI: Fan3 target value */ +}; + +static const u8 W83792D_REG_TOLERANCE[3] = { + 0x87, /* (bit3-0)SmartFan Fan1 tolerance */ + 0x87, /* (bit7-4)SmartFan Fan2 tolerance */ + 0x97 /* (bit3-0)SmartFan Fan3 tolerance */ +}; + +static const u8 W83792D_REG_POINTS[3][4] = { + { 0x85, /* SmartFanII: Fan1 temp point 1 */ + 0xE3, /* SmartFanII: Fan1 temp point 2 */ + 0xE4, /* SmartFanII: Fan1 temp point 3 */ + 0xE5 }, /* SmartFanII: Fan1 temp point 4 */ + { 0x86, /* SmartFanII: Fan2 temp point 1 */ + 0xE6, /* SmartFanII: Fan2 temp point 2 */ + 0xE7, /* SmartFanII: Fan2 temp point 3 */ + 0xE8 }, /* SmartFanII: Fan2 temp point 4 */ + { 0x96, /* SmartFanII: Fan3 temp point 1 */ + 0xE9, /* SmartFanII: Fan3 temp point 2 */ + 0xEA, /* SmartFanII: Fan3 temp point 3 */ + 0xEB } /* SmartFanII: Fan3 temp point 4 */ +}; + +static const u8 W83792D_REG_LEVELS[3][4] = { + { 0x88, /* (bit3-0) SmartFanII: Fan1 Non-Stop */ + 0x88, /* (bit7-4) SmartFanII: Fan1 Level 1 */ + 0xE0, /* (bit7-4) SmartFanII: Fan1 Level 2 */ + 0xE0 }, /* (bit3-0) SmartFanII: Fan1 Level 3 */ + { 0x89, /* (bit3-0) SmartFanII: Fan2 Non-Stop */ + 0x89, /* (bit7-4) SmartFanII: Fan2 Level 1 */ + 0xE1, /* (bit7-4) SmartFanII: Fan2 Level 2 */ + 0xE1 }, /* (bit3-0) SmartFanII: Fan2 Level 3 */ + { 0x98, /* (bit3-0) SmartFanII: Fan3 Non-Stop */ + 0x98, /* (bit7-4) SmartFanII: Fan3 Level 1 */ + 0xE2, /* (bit7-4) SmartFanII: Fan3 Level 2 */ + 0xE2 } /* (bit3-0) SmartFanII: Fan3 Level 3 */ +}; + +#define W83792D_REG_CONFIG 0x40 +#define W83792D_REG_VID_FANDIV 0x47 +#define W83792D_REG_CHIPID 0x49 +#define W83792D_REG_WCHIPID 0x58 +#define W83792D_REG_CHIPMAN 0x4F +#define W83792D_REG_PIN 0x4B +#define W83792D_REG_I2C_SUBADDR 0x4A + +#define W83792D_REG_ALARM1 0xA9 /* realtime status register1 */ +#define W83792D_REG_ALARM2 0xAA /* realtime status register2 */ +#define W83792D_REG_ALARM3 0xAB /* realtime status register3 */ +#define W83792D_REG_CHASSIS 0x42 /* Bit 5: Case Open status bit */ +#define W83792D_REG_CHASSIS_CLR 0x44 /* Bit 7: Case Open CLR_CHS/Reset bit */ + +/* control in0/in1 's limit modifiability */ +#define W83792D_REG_VID_IN_B 0x17 + +#define W83792D_REG_VBAT 0x5D +#define W83792D_REG_I2C_ADDR 0x48 + +/* Conversions. Rounding and limit checking is only done on the TO_REG + variants. Note that you should be a bit careful with which arguments + these macros are called: arguments may be evaluated more than once. + Fixing this is just not worth it. */ +#define IN_FROM_REG(nr,val) (((nr)<=1)?(val*2): \ + ((((nr)==6)||((nr)==7))?(val*6):(val*4))) +#define IN_TO_REG(nr,val) (((nr)<=1)?(val/2): \ + ((((nr)==6)||((nr)==7))?(val/6):(val/4))) + +static inline u8 +FAN_TO_REG(long rpm, int div) +{ + if (rpm == 0) + return 255; + rpm = SENSORS_LIMIT(rpm, 1, 1000000); + return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); +} + +#define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \ + ((val) == 255 ? 0 : \ + 1350000 / ((val) * (div)))) + +/* for temp1 */ +#define TEMP1_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \ + : (val)) / 1000, 0, 0xff)) +#define TEMP1_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000) +/* for temp2 and temp3, because they need addtional resolution */ +#define TEMP_ADD_FROM_REG(val1, val2) \ + ((((val1) & 0x80 ? (val1)-0x100 \ + : (val1)) * 1000) + ((val2 & 0x80) ? 500 : 0)) +#define TEMP_ADD_TO_REG_HIGH(val) \ + (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \ + : (val)) / 1000, 0, 0xff)) +#define TEMP_ADD_TO_REG_LOW(val) ((val%1000) ? 0x80 : 0x00) + +#define PWM_FROM_REG(val) (val) +#define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255)) +#define DIV_FROM_REG(val) (1 << (val)) + +static inline u8 +DIV_TO_REG(long val) +{ + int i; + val = SENSORS_LIMIT(val, 1, 128) >> 1; + for (i = 0; i < 6; i++) { + if (val == 0) + break; + val >>= 1; + } + return ((u8) i); +} + +struct w83792d_data { + struct i2c_client client; + struct class_device *class_dev; + struct semaphore lock; + enum chips type; + + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ + + /* array of 2 pointers to subclients */ + struct i2c_client *lm75[2]; + + u8 in[9]; /* Register value */ + u8 in_max[9]; /* Register value */ + u8 in_min[9]; /* Register value */ + u8 low_bits[2]; /* Additional resolution to voltage in0-6 */ + u8 fan[7]; /* Register value */ + u8 fan_min[7]; /* Register value */ + u8 temp1[3]; /* current, over, thyst */ + u8 temp_add[2][6]; /* Register value */ + u8 fan_div[7]; /* Register encoding, shifted right */ + u8 pwm[7]; /* We only consider the first 3 set of pwm, + although 792 chip has 7 set of pwm. */ + u8 pwmenable[3]; + u8 pwm_mode[7]; /* indicates PWM or DC mode: 1->PWM; 0->DC */ + u32 alarms; /* realtime status register encoding,combined */ + u8 chassis; /* Chassis status */ + u8 chassis_clear; /* CLR_CHS, clear chassis intrusion detection */ + u8 thermal_cruise[3]; /* Smart FanI: Fan1,2,3 target value */ + u8 tolerance[3]; /* Fan1,2,3 tolerance(Smart Fan I/II) */ + u8 sf2_points[3][4]; /* Smart FanII: Fan1,2,3 temperature points */ + u8 sf2_levels[3][4]; /* Smart FanII: Fan1,2,3 duty cycle levels */ +}; + +static int w83792d_attach_adapter(struct i2c_adapter *adapter); +static int w83792d_detect(struct i2c_adapter *adapter, int address, int kind); +static int w83792d_detach_client(struct i2c_client *client); + +static int w83792d_read_value(struct i2c_client *client, u8 register); +static int w83792d_write_value(struct i2c_client *client, u8 register, + u8 value); +static struct w83792d_data *w83792d_update_device(struct device *dev); + +#ifdef DEBUG +static void w83792d_print_debug(struct w83792d_data *data, struct device *dev); +#endif + +static void w83792d_init_client(struct i2c_client *client); + +static struct i2c_driver w83792d_driver = { + .owner = THIS_MODULE, + .name = "w83792d", + .flags = I2C_DF_NOTIFY, + .attach_adapter = w83792d_attach_adapter, + .detach_client = w83792d_detach_client, +}; + +static long in_count_from_reg(int nr, struct w83792d_data *data) +{ + u16 vol_count = data->in[nr]; + u16 low_bits = 0; + vol_count = (vol_count << 2); + switch (nr) + { + case 0: /* vin0 */ + low_bits = (data->low_bits[0]) & 0x03; + break; + case 1: /* vin1 */ + low_bits = ((data->low_bits[0]) & 0x0c) >> 2; + break; + case 2: /* vin2 */ + low_bits = ((data->low_bits[0]) & 0x30) >> 4; + break; + case 3: /* vin3 */ + low_bits = ((data->low_bits[0]) & 0xc0) >> 6; + break; + case 4: /* vin4 */ + low_bits = (data->low_bits[1]) & 0x03; + break; + case 5: /* vin5 */ + low_bits = ((data->low_bits[1]) & 0x0c) >> 2; + break; + case 6: /* vin6 */ + low_bits = ((data->low_bits[1]) & 0x30) >> 4; + default: + break; + } + vol_count = vol_count | low_bits; + return vol_count; +} + +/* following are the sysfs callback functions */ +static ssize_t show_in(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index; + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf,"%ld\n", IN_FROM_REG(nr,(in_count_from_reg(nr, data)))); +} + +#define show_in_reg(reg) \ +static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ + char *buf) \ +{ \ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ + int nr = sensor_attr->index; \ + struct w83792d_data *data = w83792d_update_device(dev); \ + return sprintf(buf,"%ld\n", (long)(IN_FROM_REG(nr, (data->reg[nr])*4))); \ +} + +show_in_reg(in_min); +show_in_reg(in_max); + +#define store_in_reg(REG, reg) \ +static ssize_t store_in_##reg (struct device *dev, \ + struct device_attribute *attr, \ + const char *buf, size_t count) \ +{ \ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ + int nr = sensor_attr->index; \ + struct i2c_client *client = to_i2c_client(dev); \ + struct w83792d_data *data = i2c_get_clientdata(client); \ + u32 val; \ + \ + val = simple_strtoul(buf, NULL, 10); \ + data->in_##reg[nr] = SENSORS_LIMIT(IN_TO_REG(nr, val)/4, 0, 255); \ + w83792d_write_value(client, W83792D_REG_IN_##REG[nr], data->in_##reg[nr]); \ + \ + return count; \ +} +store_in_reg(MIN, min); +store_in_reg(MAX, max); + +#define sysfs_in_reg(offset) \ +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, store_in_min, offset); \ +static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ + show_in_max, store_in_max, offset); + +sysfs_in_reg(0); +sysfs_in_reg(1); +sysfs_in_reg(2); +sysfs_in_reg(3); +sysfs_in_reg(4); +sysfs_in_reg(5); +sysfs_in_reg(6); +sysfs_in_reg(7); +sysfs_in_reg(8); + +#define device_create_file_in(client, offset) \ +do { \ +device_create_file(&client->dev, &sensor_dev_attr_in##offset##_input.dev_attr); \ +device_create_file(&client->dev, &sensor_dev_attr_in##offset##_max.dev_attr); \ +device_create_file(&client->dev, &sensor_dev_attr_in##offset##_min.dev_attr); \ +} while (0) + +#define show_fan_reg(reg) \ +static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \ + char *buf) \ +{ \ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ + int nr = sensor_attr->index - 1; \ + struct w83792d_data *data = w83792d_update_device(dev); \ + return sprintf(buf,"%d\n", \ + FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \ +} + +show_fan_reg(fan); +show_fan_reg(fan_min); + +static ssize_t +store_fan_min(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index - 1; + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + u32 val; + + val = simple_strtoul(buf, NULL, 10); + data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); + w83792d_write_value(client, W83792D_REG_FAN_MIN[nr], + data->fan_min[nr]); + + return count; +} + +static ssize_t +show_fan_div(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index; + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr - 1])); +} + +/* 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 suprise; the user doesn't expect the fan minimum to change just + because the divisor changed. */ +static ssize_t +store_fan_div(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index - 1; + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + unsigned long min; + /*u8 reg;*/ + u8 fan_div_reg = 0; + u8 tmp_fan_div; + + /* Save fan_min */ + min = FAN_FROM_REG(data->fan_min[nr], + DIV_FROM_REG(data->fan_div[nr])); + + data->fan_div[nr] = DIV_TO_REG(simple_strtoul(buf, NULL, 10)); + + fan_div_reg = w83792d_read_value(client, W83792D_REG_FAN_DIV[nr >> 1]); + fan_div_reg &= (nr & 0x01) ? 0x8f : 0xf8; + tmp_fan_div = (nr & 0x01) ? (((data->fan_div[nr]) << 4) & 0x70) + : ((data->fan_div[nr]) & 0x07); + w83792d_write_value(client, W83792D_REG_FAN_DIV[nr >> 1], + fan_div_reg | tmp_fan_div); + + /* Restore fan_min */ + data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); + w83792d_write_value(client, W83792D_REG_FAN_MIN[nr], data->fan_min[nr]); + + return count; +} + +#define sysfs_fan(offset) \ +static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan, NULL, \ + offset); \ +static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ + show_fan_div, store_fan_div, offset); \ +static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ + show_fan_min, store_fan_min, offset); + +sysfs_fan(1); +sysfs_fan(2); +sysfs_fan(3); +sysfs_fan(4); +sysfs_fan(5); +sysfs_fan(6); +sysfs_fan(7); + +#define device_create_file_fan(client, offset) \ +do { \ +device_create_file(&client->dev, &sensor_dev_attr_fan##offset##_input.dev_attr); \ +device_create_file(&client->dev, &sensor_dev_attr_fan##offset##_div.dev_attr); \ +device_create_file(&client->dev, &sensor_dev_attr_fan##offset##_min.dev_attr); \ +} while (0) + + +/* read/write the temperature1, includes measured value and limits */ + +static ssize_t show_temp1(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index; + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp1[nr])); +} + +static ssize_t store_temp1(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index; + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + s32 val; + + val = simple_strtol(buf, NULL, 10); + + data->temp1[nr] = TEMP1_TO_REG(val); + w83792d_write_value(client, W83792D_REG_TEMP1[nr], + data->temp1[nr]); + + return count; +} + + +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1, NULL, 0); +static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp1, + store_temp1, 1); +static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp1, + store_temp1, 2); + +#define device_create_file_temp1(client) \ +do { \ +device_create_file(&client->dev, &sensor_dev_attr_temp1_input.dev_attr); \ +device_create_file(&client->dev, &sensor_dev_attr_temp1_max.dev_attr); \ +device_create_file(&client->dev, &sensor_dev_attr_temp1_max_hyst.dev_attr); \ +} while (0) + + +/* read/write the temperature2-3, includes measured value and limits */ + +static ssize_t show_temp23(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf,"%ld\n", + (long)TEMP_ADD_FROM_REG(data->temp_add[nr][index], + data->temp_add[nr][index+1])); +} + +static ssize_t store_temp23(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + s32 val; + + val = simple_strtol(buf, NULL, 10); + + data->temp_add[nr][index] = TEMP_ADD_TO_REG_HIGH(val); + data->temp_add[nr][index+1] = TEMP_ADD_TO_REG_LOW(val); + w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index], + data->temp_add[nr][index]); + w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index+1], + data->temp_add[nr][index+1]); + + return count; +} + +#define sysfs_temp23(name,idx) \ +static SENSOR_DEVICE_ATTR_2(name##_input, S_IRUGO, show_temp23, NULL, \ + idx, 0); \ +static SENSOR_DEVICE_ATTR_2(name##_max, S_IRUGO | S_IWUSR, \ + show_temp23, store_temp23, idx, 2); \ +static SENSOR_DEVICE_ATTR_2(name##_max_hyst, S_IRUGO | S_IWUSR, \ + show_temp23, store_temp23, idx, 4); + +sysfs_temp23(temp2,0) +sysfs_temp23(temp3,1) + +#define device_create_file_temp_add(client, offset) \ +do { \ +device_create_file(&client->dev, &sensor_dev_attr_temp##offset##_input.dev_attr); \ +device_create_file(&client->dev, &sensor_dev_attr_temp##offset##_max.dev_attr); \ +device_create_file(&client->dev, \ +&sensor_dev_attr_temp##offset##_max_hyst.dev_attr); \ +} while (0) + + +/* get reatime status of all sensors items: voltage, temp, fan */ +static ssize_t +show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf, "%d\n", data->alarms); +} + +static +DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); +#define device_create_file_alarms(client) \ +device_create_file(&client->dev, &dev_attr_alarms); + + + +static ssize_t +show_pwm(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index; + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf, "%ld\n", (long) PWM_FROM_REG(data->pwm[nr-1])); +} + +static ssize_t +show_pwmenable(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index - 1; + struct w83792d_data *data = w83792d_update_device(dev); + long pwm_enable_tmp = 1; + + switch (data->pwmenable[nr]) { + case 0: + pwm_enable_tmp = 1; /* manual mode */ + break; + case 1: + pwm_enable_tmp = 3; /*thermal cruise/Smart Fan I */ + break; + case 2: + pwm_enable_tmp = 2; /* Smart Fan II */ + break; + } + + return sprintf(buf, "%ld\n", pwm_enable_tmp); +} + +static ssize_t +store_pwm(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index - 1; + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + u32 val; + + val = simple_strtoul(buf, NULL, 10); + data->pwm[nr] = PWM_TO_REG(val); + w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]); + + return count; +} + +static ssize_t +store_pwmenable(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index - 1; + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + u32 val; + u8 fan_cfg_tmp, cfg1_tmp, cfg2_tmp, cfg3_tmp, cfg4_tmp; + + val = simple_strtoul(buf, NULL, 10); + switch (val) { + case 1: + data->pwmenable[nr] = 0; /* manual mode */ + break; + case 2: + data->pwmenable[nr] = 2; /* Smart Fan II */ + break; + case 3: + data->pwmenable[nr] = 1; /* thermal cruise/Smart Fan I */ + break; + default: + return -EINVAL; + } + cfg1_tmp = data->pwmenable[0]; + cfg2_tmp = (data->pwmenable[1]) << 2; + cfg3_tmp = (data->pwmenable[2]) << 4; + cfg4_tmp = w83792d_read_value(client,W83792D_REG_FAN_CFG) & 0xc0; + fan_cfg_tmp = ((cfg4_tmp | cfg3_tmp) | cfg2_tmp) | cfg1_tmp; + w83792d_write_value(client, W83792D_REG_FAN_CFG, fan_cfg_tmp); + + return count; +} + +#define sysfs_pwm(offset) \ +static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ + show_pwm, store_pwm, offset); \ +static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ + show_pwmenable, store_pwmenable, offset); \ + +sysfs_pwm(1); +sysfs_pwm(2); +sysfs_pwm(3); + + +#define device_create_file_pwm(client, offset) \ +do { \ +device_create_file(&client->dev, &sensor_dev_attr_pwm##offset.dev_attr); \ +} while (0) + +#define device_create_file_pwmenable(client, offset) \ +do { \ +device_create_file(&client->dev, &sensor_dev_attr_pwm##offset##_enable.dev_attr); \ +} while (0) + + +static ssize_t +show_pwm_mode(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index; + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf, "%d\n", data->pwm_mode[nr-1]); +} + +static ssize_t +store_pwm_mode(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index - 1; + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + u32 val; + u8 pwm_mode_mask = 0; + + val = simple_strtoul(buf, NULL, 10); + data->pwm_mode[nr] = SENSORS_LIMIT(val, 0, 1); + pwm_mode_mask = w83792d_read_value(client, + W83792D_REG_PWM[nr]) & 0x7f; + w83792d_write_value(client, W83792D_REG_PWM[nr], + ((data->pwm_mode[nr]) << 7) | pwm_mode_mask); + + return count; +} + +#define sysfs_pwm_mode(offset) \ +static SENSOR_DEVICE_ATTR(pwm##offset##_mode, S_IRUGO | S_IWUSR, \ + show_pwm_mode, store_pwm_mode, offset); + +sysfs_pwm_mode(1); +sysfs_pwm_mode(2); +sysfs_pwm_mode(3); + +#define device_create_file_pwm_mode(client, offset) \ +do { \ +device_create_file(&client->dev, &sensor_dev_attr_pwm##offset##_mode.dev_attr); \ +} while (0) + + +static ssize_t +show_regs_chassis(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf, "%d\n", data->chassis); +} + +static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL); + +#define device_create_file_chassis(client) \ +do { \ +device_create_file(&client->dev, &dev_attr_chassis); \ +} while (0) + + +static ssize_t +show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf, "%d\n", data->chassis_clear); +} + +static ssize_t +store_chassis_clear(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + u32 val; + u8 temp1 = 0, temp2 = 0; + + val = simple_strtoul(buf, NULL, 10); + + data->chassis_clear = SENSORS_LIMIT(val, 0 ,1); + temp1 = ((data->chassis_clear) << 7) & 0x80; + temp2 = w83792d_read_value(client, + W83792D_REG_CHASSIS_CLR) & 0x7f; + w83792d_write_value(client, W83792D_REG_CHASSIS_CLR, temp1 | temp2); + + return count; +} + +static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR, + show_chassis_clear, store_chassis_clear); + +#define device_create_file_chassis_clear(client) \ +do { \ +device_create_file(&client->dev, &dev_attr_chassis_clear); \ +} while (0) + + + +/* For Smart Fan I / Thermal Cruise */ +static ssize_t +show_thermal_cruise(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index; + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf, "%ld\n", (long)data->thermal_cruise[nr-1]); +} + +static ssize_t +store_thermal_cruise(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index - 1; + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + u32 val; + u8 target_tmp=0, target_mask=0; + + val = simple_strtoul(buf, NULL, 10); + target_tmp = val; + target_tmp = target_tmp & 0x7f; + target_mask = w83792d_read_value(client, W83792D_REG_THERMAL[nr]) & 0x80; + data->thermal_cruise[nr] = SENSORS_LIMIT(target_tmp, 0, 255); + w83792d_write_value(client, W83792D_REG_THERMAL[nr], + (data->thermal_cruise[nr]) | target_mask); + + return count; +} + +#define sysfs_thermal_cruise(offset) \ +static SENSOR_DEVICE_ATTR(thermal_cruise##offset, S_IRUGO | S_IWUSR, \ + show_thermal_cruise, store_thermal_cruise, offset); + +sysfs_thermal_cruise(1); +sysfs_thermal_cruise(2); +sysfs_thermal_cruise(3); + +#define device_create_file_thermal_cruise(client, offset) \ +do { \ +device_create_file(&client->dev, \ +&sensor_dev_attr_thermal_cruise##offset.dev_attr); \ +} while (0) + + +/* For Smart Fan I/Thermal Cruise and Smart Fan II */ +static ssize_t +show_tolerance(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index; + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf, "%ld\n", (long)data->tolerance[nr-1]); +} + +static ssize_t +store_tolerance(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + int nr = sensor_attr->index - 1; + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + u32 val; + u8 tol_tmp, tol_mask; + + val = simple_strtoul(buf, NULL, 10); + tol_mask = w83792d_read_value(client, + W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0); + tol_tmp = SENSORS_LIMIT(val, 0, 15); + tol_tmp &= 0x0f; + data->tolerance[nr] = tol_tmp; + if (nr == 1) { + tol_tmp <<= 4; + } + w83792d_write_value(client, W83792D_REG_TOLERANCE[nr], + tol_mask | tol_tmp); + + return count; +} + +#define sysfs_tolerance(offset) \ +static SENSOR_DEVICE_ATTR(tolerance##offset, S_IRUGO | S_IWUSR, \ + show_tolerance, store_tolerance, offset); + +sysfs_tolerance(1); +sysfs_tolerance(2); +sysfs_tolerance(3); + +#define device_create_file_tolerance(client, offset) \ +do { \ +device_create_file(&client->dev, &sensor_dev_attr_tolerance##offset.dev_attr); \ +} while (0) + + +/* For Smart Fan II */ +static ssize_t +show_sf2_point(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf, "%ld\n", (long)data->sf2_points[index-1][nr-1]); +} + +static ssize_t +store_sf2_point(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr - 1; + int index = sensor_attr->index - 1; + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + u32 val; + u8 mask_tmp = 0; + + val = simple_strtoul(buf, NULL, 10); + data->sf2_points[index][nr] = SENSORS_LIMIT(val, 0, 127); + mask_tmp = w83792d_read_value(client, + W83792D_REG_POINTS[index][nr]) & 0x80; + w83792d_write_value(client, W83792D_REG_POINTS[index][nr], + mask_tmp|data->sf2_points[index][nr]); + + return count; +} + +#define sysfs_sf2_point(offset, index) \ +static SENSOR_DEVICE_ATTR_2(sf2_point##offset##_fan##index, S_IRUGO | S_IWUSR, \ + show_sf2_point, store_sf2_point, offset, index); + +sysfs_sf2_point(1, 1); /* Fan1 */ +sysfs_sf2_point(2, 1); /* Fan1 */ +sysfs_sf2_point(3, 1); /* Fan1 */ +sysfs_sf2_point(4, 1); /* Fan1 */ +sysfs_sf2_point(1, 2); /* Fan2 */ +sysfs_sf2_point(2, 2); /* Fan2 */ +sysfs_sf2_point(3, 2); /* Fan2 */ +sysfs_sf2_point(4, 2); /* Fan2 */ +sysfs_sf2_point(1, 3); /* Fan3 */ +sysfs_sf2_point(2, 3); /* Fan3 */ +sysfs_sf2_point(3, 3); /* Fan3 */ +sysfs_sf2_point(4, 3); /* Fan3 */ + +#define device_create_file_sf2_point(client, offset, index) \ +do { \ +device_create_file(&client->dev, \ +&sensor_dev_attr_sf2_point##offset##_fan##index.dev_attr); \ +} while (0) + + +static ssize_t +show_sf2_level(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + struct w83792d_data *data = w83792d_update_device(dev); + return sprintf(buf, "%d\n", + (((data->sf2_levels[index-1][nr]) * 100) / 15)); +} + +static ssize_t +store_sf2_level(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index - 1; + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + u32 val; + u8 mask_tmp=0, level_tmp=0; + + val = simple_strtoul(buf, NULL, 10); + data->sf2_levels[index][nr] = SENSORS_LIMIT((val * 15) / 100, 0, 15); + mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr]) + & ((nr==3) ? 0xf0 : 0x0f); + if (nr==3) { + level_tmp = data->sf2_levels[index][nr]; + } else { + level_tmp = data->sf2_levels[index][nr] << 4; + } + w83792d_write_value(client, W83792D_REG_LEVELS[index][nr], level_tmp | mask_tmp); + + return count; +} + +#define sysfs_sf2_level(offset, index) \ +static SENSOR_DEVICE_ATTR_2(sf2_level##offset##_fan##index, S_IRUGO | S_IWUSR, \ + show_sf2_level, store_sf2_level, offset, index); + +sysfs_sf2_level(1, 1); /* Fan1 */ +sysfs_sf2_level(2, 1); /* Fan1 */ +sysfs_sf2_level(3, 1); /* Fan1 */ +sysfs_sf2_level(1, 2); /* Fan2 */ +sysfs_sf2_level(2, 2); /* Fan2 */ +sysfs_sf2_level(3, 2); /* Fan2 */ +sysfs_sf2_level(1, 3); /* Fan3 */ +sysfs_sf2_level(2, 3); /* Fan3 */ +sysfs_sf2_level(3, 3); /* Fan3 */ + +#define device_create_file_sf2_level(client, offset, index) \ +do { \ +device_create_file(&client->dev, \ +&sensor_dev_attr_sf2_level##offset##_fan##index.dev_attr); \ +} while (0) + + +/* This function is called when: + * w83792d_driver is inserted (when this module is loaded), for each + available adapter + * when a new adapter is inserted (and w83792d_driver is still present) */ +static int +w83792d_attach_adapter(struct i2c_adapter *adapter) +{ + if (!(adapter->class & I2C_CLASS_HWMON)) + return 0; + return i2c_probe(adapter, &addr_data, w83792d_detect); +} + + +static int +w83792d_create_subclient(struct i2c_adapter *adapter, + struct i2c_client *new_client, int addr, + struct i2c_client **sub_cli) +{ + int err; + struct i2c_client *sub_client; + + (*sub_cli) = sub_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); + if (!(sub_client)) { + return -ENOMEM; + } + memset(sub_client, 0x00, sizeof(struct i2c_client)); + sub_client->addr = 0x48 + addr; + i2c_set_clientdata(sub_client, NULL); + sub_client->adapter = adapter; + sub_client->driver = &w83792d_driver; + sub_client->flags = 0; + strlcpy(sub_client->name, "w83792d subclient", I2C_NAME_SIZE); + if ((err = i2c_attach_client(sub_client))) { + dev_err(&new_client->dev, "subclient registration " + "at address 0x%x failed\n", sub_client->addr); + kfree(sub_client); + return err; + } + return 0; +} + + +static int +w83792d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, + struct i2c_client *new_client) +{ + int i, id, err; + u8 val; + struct w83792d_data *data = i2c_get_clientdata(new_client); + + 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) { + dev_err(&new_client->dev, "invalid subclient " + "address %d; must be 0x48-0x4f\n", + force_subclients[i]); + err = -ENODEV; + goto ERROR_SC_0; + } + } + w83792d_write_value(new_client, W83792D_REG_I2C_SUBADDR, + (force_subclients[2] & 0x07) | + ((force_subclients[3] & 0x07) << 4)); + } + + val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR); + if (!(val & 0x08)) { + err = w83792d_create_subclient(adapter, new_client, val & 0x7, + &data->lm75[0]); + if (err < 0) + goto ERROR_SC_0; + } + if (!(val & 0x80)) { + if ((data->lm75[0] != NULL) && + ((val & 0x7) == ((val >> 4) & 0x7))) { + dev_err(&new_client->dev, "duplicate addresses 0x%x, " + "use force_subclient\n", data->lm75[0]->addr); + err = -ENODEV; + goto ERROR_SC_1; + } + err = w83792d_create_subclient(adapter, new_client, + (val >> 4) & 0x7, &data->lm75[1]); + if (err < 0) + goto ERROR_SC_1; + } + + return 0; + +/* Undo inits in case of errors */ + +ERROR_SC_1: + if (data->lm75[0] != NULL) { + i2c_detach_client(data->lm75[0]); + kfree(data->lm75[0]); + } +ERROR_SC_0: + return err; +} + + +static int +w83792d_detect(struct i2c_adapter *adapter, int address, int kind) +{ + int i = 0, val1 = 0, val2; + struct i2c_client *new_client; + struct w83792d_data *data; + int err = 0; + const char *client_name = ""; + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { + goto ERROR0; + } + + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access w83792d_{read,write}_value. */ + + if (!(data = kmalloc(sizeof(struct w83792d_data), GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } + memset(data, 0, sizeof(struct w83792d_data)); + + new_client = &data->client; + i2c_set_clientdata(new_client, data); + new_client->addr = address; + init_MUTEX(&data->lock); + new_client->adapter = adapter; + new_client->driver = &w83792d_driver; + new_client->flags = 0; + + /* Now, we do the remaining detection. */ + + /* The w83792d may be stuck in some other bank than bank 0. This may + make reading other information impossible. Specify a force=... or + force_*=... parameter, and the Winbond will be reset to the right + bank. */ + if (kind < 0) { + if (w83792d_read_value(new_client, W83792D_REG_CONFIG) & 0x80) { + dev_warn(&new_client->dev, "Detection failed at step " + "3\n"); + goto ERROR1; + } + val1 = w83792d_read_value(new_client, W83792D_REG_BANK); + val2 = w83792d_read_value(new_client, W83792D_REG_CHIPMAN); + /* Check for Winbond ID if in bank 0 */ + if (!(val1 & 0x07)) { /* is Bank0 */ + if (((!(val1 & 0x80)) && (val2 != 0xa3)) || + ((val1 & 0x80) && (val2 != 0x5c))) { + goto ERROR1; + } + } + /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR + should match */ + if (w83792d_read_value(new_client, + W83792D_REG_I2C_ADDR) != address) { + dev_warn(&new_client->dev, "Detection failed " + "at step 5\n"); + goto ERROR1; + } + } + + /* We have either had a force parameter, or we have already detected the + Winbond. Put it now into bank 0 and Vendor ID High Byte */ + w83792d_write_value(new_client, + W83792D_REG_BANK, + (w83792d_read_value(new_client, + W83792D_REG_BANK) & 0x78) | 0x80); + + /* Determine the chip type. */ + if (kind <= 0) { + /* get vendor ID */ + val2 = w83792d_read_value(new_client, W83792D_REG_CHIPMAN); + if (val2 != 0x5c) { /* the vendor is NOT Winbond */ + goto ERROR1; + } + val1 = w83792d_read_value(new_client, W83792D_REG_WCHIPID); + if (val1 == 0x7a && address >= 0x2c) { + kind = w83792d; + } else { + if (kind == 0) + dev_warn(&new_client->dev, + "w83792d: Ignoring 'force' parameter for" + " unknown chip at adapter %d, address" + " 0x%02x\n", i2c_adapter_id(adapter), + address); + goto ERROR1; + } + } + + if (kind == w83792d) { + client_name = "w83792d"; + } else { + dev_err(&new_client->dev, "w83792d: Internal error: unknown" + " kind (%d)?!?", kind); + goto ERROR1; + } + + /* Fill in the remaining client fields and put into the global list */ + strlcpy(new_client->name, client_name, I2C_NAME_SIZE); + data->type = kind; + + data->valid = 0; + init_MUTEX(&data->update_lock); + + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR1; + + if ((err = w83792d_detect_subclients(adapter, address, + kind, new_client))) + goto ERROR2; + + /* Initialize the chip */ + w83792d_init_client(new_client); + + /* A few vars need to be filled upon startup */ + for (i = 1; i <= 7; i++) { + data->fan_min[i - 1] = w83792d_read_value(new_client, + W83792D_REG_FAN_MIN[i]); + } + + /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto ERROR3; + } + device_create_file_in(new_client, 0); + device_create_file_in(new_client, 1); + device_create_file_in(new_client, 2); + device_create_file_in(new_client, 3); + device_create_file_in(new_client, 4); + device_create_file_in(new_client, 5); + device_create_file_in(new_client, 6); + device_create_file_in(new_client, 7); + device_create_file_in(new_client, 8); + + device_create_file_fan(new_client, 1); + device_create_file_fan(new_client, 2); + device_create_file_fan(new_client, 3); + device_create_file_fan(new_client, 4); + device_create_file_fan(new_client, 5); + device_create_file_fan(new_client, 6); + device_create_file_fan(new_client, 7); + + device_create_file_temp1(new_client); /* Temp1 */ + device_create_file_temp_add(new_client, 2); /* Temp2 */ + device_create_file_temp_add(new_client, 3); /* Temp3 */ + + device_create_file_alarms(new_client); + + device_create_file_pwm(new_client, 1); + device_create_file_pwm(new_client, 2); + device_create_file_pwm(new_client, 3); + + device_create_file_pwmenable(new_client, 1); + device_create_file_pwmenable(new_client, 2); + device_create_file_pwmenable(new_client, 3); + + device_create_file_pwm_mode(new_client, 1); + device_create_file_pwm_mode(new_client, 2); + device_create_file_pwm_mode(new_client, 3); + + device_create_file_chassis(new_client); + device_create_file_chassis_clear(new_client); + + device_create_file_thermal_cruise(new_client, 1); + device_create_file_thermal_cruise(new_client, 2); + device_create_file_thermal_cruise(new_client, 3); + + device_create_file_tolerance(new_client, 1); + device_create_file_tolerance(new_client, 2); + device_create_file_tolerance(new_client, 3); + + device_create_file_sf2_point(new_client, 1, 1); /* Fan1 */ + device_create_file_sf2_point(new_client, 2, 1); /* Fan1 */ + device_create_file_sf2_point(new_client, 3, 1); /* Fan1 */ + device_create_file_sf2_point(new_client, 4, 1); /* Fan1 */ + device_create_file_sf2_point(new_client, 1, 2); /* Fan2 */ + device_create_file_sf2_point(new_client, 2, 2); /* Fan2 */ + device_create_file_sf2_point(new_client, 3, 2); /* Fan2 */ + device_create_file_sf2_point(new_client, 4, 2); /* Fan2 */ + device_create_file_sf2_point(new_client, 1, 3); /* Fan3 */ + device_create_file_sf2_point(new_client, 2, 3); /* Fan3 */ + device_create_file_sf2_point(new_client, 3, 3); /* Fan3 */ + device_create_file_sf2_point(new_client, 4, 3); /* Fan3 */ + + device_create_file_sf2_level(new_client, 1, 1); /* Fan1 */ + device_create_file_sf2_level(new_client, 2, 1); /* Fan1 */ + device_create_file_sf2_level(new_client, 3, 1); /* Fan1 */ + device_create_file_sf2_level(new_client, 1, 2); /* Fan2 */ + device_create_file_sf2_level(new_client, 2, 2); /* Fan2 */ + device_create_file_sf2_level(new_client, 3, 2); /* Fan2 */ + device_create_file_sf2_level(new_client, 1, 3); /* Fan3 */ + device_create_file_sf2_level(new_client, 2, 3); /* Fan3 */ + device_create_file_sf2_level(new_client, 3, 3); /* Fan3 */ + + return 0; + +ERROR3: + if (data->lm75[0] != NULL) { + i2c_detach_client(data->lm75[0]); + kfree(data->lm75[0]); + } + if (data->lm75[1] != NULL) { + i2c_detach_client(data->lm75[1]); + kfree(data->lm75[1]); + } +ERROR2: + i2c_detach_client(new_client); +ERROR1: + kfree(data); +ERROR0: + return err; +} + +static int +w83792d_detach_client(struct i2c_client *client) +{ + struct w83792d_data *data = i2c_get_clientdata(client); + int err; + + /* main client */ + if (data) + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) + return err; + + /* main client */ + if (data) + kfree(data); + /* subclient */ + else + kfree(client); + + return 0; +} + +/* The SMBus locks itself, usually, but nothing may access the Winbond between + bank switches. ISA access must always be locked explicitly! + We ignore the W83792D BUSY flag at this moment - it could lead to deadlocks, + would slow down the W83792D access and should not be necessary. + There are some ugly typecasts here, but the good news is - they should + nowhere else be necessary! */ +static int +w83792d_read_value(struct i2c_client *client, u8 reg) +{ + int res=0; + res = i2c_smbus_read_byte_data(client, reg); + + return res; +} + +static int +w83792d_write_value(struct i2c_client *client, u8 reg, u8 value) +{ + i2c_smbus_write_byte_data(client, reg, value); + return 0; +} + +/* Called when we have found a new W83792D. It should set limits, etc. */ +static void +w83792d_init_client(struct i2c_client *client) +{ + u8 temp2_cfg, temp3_cfg, vid_in_b; + + if (init) { + w83792d_write_value(client, W83792D_REG_CONFIG, 0x80); + } + /* Clear the bit6 of W83792D_REG_VID_IN_B(set it into 0): + W83792D_REG_VID_IN_B bit6 = 0: the high/low limit of + vin0/vin1 can be modified by user; + W83792D_REG_VID_IN_B bit6 = 1: the high/low limit of + vin0/vin1 auto-updated, can NOT be modified by user. */ + vid_in_b = w83792d_read_value(client, W83792D_REG_VID_IN_B); + w83792d_write_value(client, W83792D_REG_VID_IN_B, + vid_in_b & 0xbf); + + temp2_cfg = w83792d_read_value(client, W83792D_REG_TEMP2_CONFIG); + temp3_cfg = w83792d_read_value(client, W83792D_REG_TEMP3_CONFIG); + w83792d_write_value(client, W83792D_REG_TEMP2_CONFIG, + temp2_cfg & 0xe6); + w83792d_write_value(client, W83792D_REG_TEMP3_CONFIG, + temp3_cfg & 0xe6); + + /* Start monitoring */ + w83792d_write_value(client, W83792D_REG_CONFIG, + (w83792d_read_value(client, + W83792D_REG_CONFIG) & 0xf7) + | 0x01); +} + +static struct w83792d_data *w83792d_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83792d_data *data = i2c_get_clientdata(client); + int i, j; + u8 reg_array_tmp[4], pwm_array_tmp[7], reg_tmp; + + down(&data->update_lock); + + if (time_after + (jiffies - data->last_updated, (unsigned long) (HZ * 3)) + || time_before(jiffies, data->last_updated) || !data->valid) { + dev_dbg(dev, "Starting device update\n"); + + /* Update the voltages measured value and limits */ + for (i = 0; i < 9; i++) { + data->in[i] = w83792d_read_value(client, + W83792D_REG_IN[i]); + data->in_max[i] = w83792d_read_value(client, + W83792D_REG_IN_MAX[i]); + data->in_min[i] = w83792d_read_value(client, + W83792D_REG_IN_MIN[i]); + } + data->low_bits[0] = w83792d_read_value(client, + W83792D_REG_LOW_BITS1); + data->low_bits[1] = w83792d_read_value(client, + W83792D_REG_LOW_BITS2); + for (i = 0; i < 7; i++) { + /* Update the Fan measured value and limits */ + data->fan[i] = w83792d_read_value(client, + W83792D_REG_FAN[i]); + data->fan_min[i] = w83792d_read_value(client, + W83792D_REG_FAN_MIN[i]); + /* Update the PWM/DC Value and PWM/DC flag */ + pwm_array_tmp[i] = w83792d_read_value(client, + W83792D_REG_PWM[i]); + data->pwm[i] = pwm_array_tmp[i] & 0x0f; + data->pwm_mode[i] = (pwm_array_tmp[i] >> 7) & 0x01; + } + + reg_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG); + data->pwmenable[0] = reg_tmp & 0x03; + data->pwmenable[1] = (reg_tmp>>2) & 0x03; + data->pwmenable[2] = (reg_tmp>>4) & 0x03; + + for (i = 0; i < 3; i++) { + data->temp1[i] = w83792d_read_value(client, + W83792D_REG_TEMP1[i]); + } + for (i = 0; i < 2; i++) { + for (j = 0; j < 6; j++) { + data->temp_add[i][j] = w83792d_read_value( + client,W83792D_REG_TEMP_ADD[i][j]); + } + } + + /* Update the Fan Divisor */ + for (i = 0; i < 4; i++) { + reg_array_tmp[i] = w83792d_read_value(client, + W83792D_REG_FAN_DIV[i]); + } + data->fan_div[0] = reg_array_tmp[0] & 0x07; + data->fan_div[1] = (reg_array_tmp[0] >> 4) & 0x07; + data->fan_div[2] = reg_array_tmp[1] & 0x07; + data->fan_div[3] = (reg_array_tmp[1] >> 4) & 0x07; + data->fan_div[4] = reg_array_tmp[2] & 0x07; + data->fan_div[5] = (reg_array_tmp[2] >> 4) & 0x07; + data->fan_div[6] = reg_array_tmp[3] & 0x07; + + /* Update the realtime status */ + data->alarms = w83792d_read_value(client, W83792D_REG_ALARM1) + + (w83792d_read_value(client, W83792D_REG_ALARM2) << 8) + + (w83792d_read_value(client, W83792D_REG_ALARM3) << 16); + + /* Update CaseOpen status and it's CLR_CHS. */ + data->chassis = (w83792d_read_value(client, + W83792D_REG_CHASSIS) >> 5) & 0x01; + data->chassis_clear = (w83792d_read_value(client, + W83792D_REG_CHASSIS_CLR) >> 7) & 0x01; + + /* Update Thermal Cruise/Smart Fan I target value */ + for (i = 0; i < 3; i++) { + data->thermal_cruise[i] = + w83792d_read_value(client, + W83792D_REG_THERMAL[i]) & 0x7f; + } + + /* Update Smart Fan I/II tolerance */ + reg_tmp = w83792d_read_value(client, W83792D_REG_TOLERANCE[0]); + data->tolerance[0] = reg_tmp & 0x0f; + data->tolerance[1] = (reg_tmp >> 4) & 0x0f; + data->tolerance[2] = w83792d_read_value(client, + W83792D_REG_TOLERANCE[2]) & 0x0f; + + /* Update Smart Fan II temperature points */ + for (i = 0; i < 3; i++) { + for (j = 0; j < 4; j++) { + data->sf2_points[i][j] = w83792d_read_value( + client,W83792D_REG_POINTS[i][j]) & 0x7f; + } + } + + /* Update Smart Fan II duty cycle levels */ + for (i = 0; i < 3; i++) { + reg_tmp = w83792d_read_value(client, + W83792D_REG_LEVELS[i][0]); + data->sf2_levels[i][0] = reg_tmp & 0x0f; + data->sf2_levels[i][1] = (reg_tmp >> 4) & 0x0f; + reg_tmp = w83792d_read_value(client, + W83792D_REG_LEVELS[i][2]); + data->sf2_levels[i][2] = (reg_tmp >> 4) & 0x0f; + data->sf2_levels[i][3] = reg_tmp & 0x0f; + } + + data->last_updated = jiffies; + data->valid = 1; + } + + up(&data->update_lock); + +#ifdef DEBUG + w83792d_print_debug(data, dev); +#endif + + return data; +} + +#ifdef DEBUG +static void w83792d_print_debug(struct w83792d_data *data, struct device *dev) +{ + int i=0, j=0; + dev_dbg(dev, "==========The following is the debug message...========\n"); + dev_dbg(dev, "9 set of Voltages: =====>\n"); + for (i=0; i<9; i++) { + dev_dbg(dev, "vin[%d] is: 0x%x\n", i, data->in[i]); + dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]); + dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]); + } + dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits[0]); + dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits[1]); + dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n"); + for (i=0; i<7; i++) { + dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]); + dev_dbg(dev, "fan[%d] min is: 0x%x\n", i, data->fan_min[i]); + dev_dbg(dev, "pwm[%d] is: 0x%x\n", i, data->pwm[i]); + dev_dbg(dev, "pwm_mode[%d] is: 0x%x\n", i, data->pwm_mode[i]); + } + dev_dbg(dev, "3 set of Temperatures: =====>\n"); + for (i=0; i<3; i++) { + dev_dbg(dev, "temp1[%d] is: 0x%x\n", i, data->temp1[i]); + } + + for (i=0; i<2; i++) { + for (j=0; j<6; j++) { + dev_dbg(dev, "temp_add[%d][%d] is: 0x%x\n", i, j, + data->temp_add[i][j]); + } + } + + for (i=0; i<7; i++) { + dev_dbg(dev, "fan_div[%d] is: 0x%x\n", i, data->fan_div[i]); + } + dev_dbg(dev, "==========End of the debug message...==================\n"); + dev_dbg(dev, "\n"); +} +#endif + +static int __init +sensors_w83792d_init(void) +{ + return i2c_add_driver(&w83792d_driver); +} + +static void __exit +sensors_w83792d_exit(void) +{ + i2c_del_driver(&w83792d_driver); +} + +MODULE_AUTHOR("Chunhao Huang @ Winbond <DZShen@Winbond.com.tw>"); +MODULE_DESCRIPTION("W83792AD/D driver for linux-2.6"); +MODULE_LICENSE("GPL"); + +module_init(sensors_w83792d_init); +module_exit(sensors_w83792d_exit); + diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c index 4469d52aba4..133e34ab1d0 100644 --- a/drivers/hwmon/w83l785ts.c +++ b/drivers/hwmon/w83l785ts.c @@ -36,7 +36,8 @@ #include <linux/slab.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/hwmon.h> +#include <linux/err.h> /* How many retries on register read error */ #define MAX_RETRIES 5 @@ -47,13 +48,12 @@ */ static unsigned short normal_i2c[] = { 0x2e, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* * Insmod parameters */ -SENSORS_INSMOD_1(w83l785ts); +I2C_CLIENT_INSMOD_1(w83l785ts); /* * The W83L785TS-S registers @@ -105,6 +105,7 @@ static struct i2c_driver w83l785ts_driver = { struct w83l785ts_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* zero until following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -140,7 +141,7 @@ static int w83l785ts_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, w83l785ts_detect); + return i2c_probe(adapter, &addr_data, w83l785ts_detect); } /* @@ -239,11 +240,19 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) */ /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_temp1_input); device_create_file(&new_client->dev, &dev_attr_temp1_max); return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -252,15 +261,15 @@ exit: static int w83l785ts_detach_client(struct i2c_client *client) { + struct w83l785ts_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index cd170395a8c..71c5a854ac5 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -4,12 +4,8 @@ obj-$(CONFIG_I2C) += i2c-core.o obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o -obj-$(CONFIG_I2C_SENSOR) += i2c-sensor.o obj-y += busses/ chips/ algos/ -i2c-sensor-objs := i2c-sensor-detect.o i2c-sensor-vid.o - - ifeq ($(CONFIG_I2C_DEBUG_CORE),y) EXTRA_CFLAGS += -DDEBUG endif diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index fb5b732238e..df05df1a0ef 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c @@ -519,8 +519,6 @@ static u32 bit_func(struct i2c_adapter *adap) /* -----exported algorithm data: ------------------------------------- */ static struct i2c_algorithm i2c_bit_algo = { - .name = "Bit-shift algorithm", - .id = I2C_ALGO_BIT, .master_xfer = bit_xfer, .functionality = bit_func, }; @@ -541,8 +539,6 @@ int i2c_bit_add_bus(struct i2c_adapter *adap) DEB2(dev_dbg(&adap->dev, "hw routines registered.\n")); /* register new adapter to i2c module... */ - - adap->id |= i2c_bit_algo.id; adap->algo = &i2c_bit_algo; adap->timeout = 100; /* default values, should */ diff --git a/drivers/i2c/algos/i2c-algo-ite.c b/drivers/i2c/algos/i2c-algo-ite.c index e6cae39f47a..2db7bfc8522 100644 --- a/drivers/i2c/algos/i2c-algo-ite.c +++ b/drivers/i2c/algos/i2c-algo-ite.c @@ -713,8 +713,6 @@ static u32 iic_func(struct i2c_adapter *adap) /* -----exported algorithm data: ------------------------------------- */ static struct i2c_algorithm iic_algo = { - .name = "ITE IIC algorithm", - .id = I2C_ALGO_IIC, .master_xfer = iic_xfer, .algo_control = algo_control, /* ioctl */ .functionality = iic_func, @@ -738,8 +736,6 @@ int i2c_iic_add_bus(struct i2c_adapter *adap) adap->name)); /* register new adapter to i2c module... */ - - adap->id |= iic_algo.id; adap->algo = &iic_algo; adap->timeout = 100; /* default values, should */ diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c index cc3a952401f..beb10edfe9c 100644 --- a/drivers/i2c/algos/i2c-algo-pca.c +++ b/drivers/i2c/algos/i2c-algo-pca.c @@ -187,12 +187,14 @@ static int pca_xfer(struct i2c_adapter *i2c_adap, int numbytes = 0; int state; int ret; + int timeout = 100; - state = pca_status(adap); - if ( state != 0xF8 ) { - dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state ); - /* FIXME: what to do. Force stop ? */ - return -EREMOTEIO; + while ((state = pca_status(adap)) != 0xf8 && timeout--) { + msleep(10); + } + if (state != 0xf8) { + dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state); + return -EIO; } DEB1("{{{ XFER %d messages\n", num); @@ -354,8 +356,6 @@ static int pca_init(struct i2c_algo_pca_data *adap) } static struct i2c_algorithm pca_algo = { - .name = "PCA9564 algorithm", - .id = I2C_ALGO_PCA, .master_xfer = pca_xfer, .functionality = pca_func, }; @@ -369,8 +369,6 @@ int i2c_pca_add_bus(struct i2c_adapter *adap) int rval; /* register new adapter to i2c module... */ - - adap->id |= pca_algo.id; adap->algo = &pca_algo; adap->timeout = 100; /* default values, should */ diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c index 8d087dac32a..6e498df1f71 100644 --- a/drivers/i2c/algos/i2c-algo-pcf.c +++ b/drivers/i2c/algos/i2c-algo-pcf.c @@ -459,8 +459,6 @@ static u32 pcf_func(struct i2c_adapter *adap) /* -----exported algorithm data: ------------------------------------- */ static struct i2c_algorithm pcf_algo = { - .name = "PCF8584 algorithm", - .id = I2C_ALGO_PCF, .master_xfer = pcf_xfer, .functionality = pcf_func, }; @@ -476,8 +474,6 @@ int i2c_pcf_add_bus(struct i2c_adapter *adap) DEB2(dev_dbg(&adap->dev, "hw routines registered.\n")); /* register new adapter to i2c module... */ - - adap->id |= pcf_algo.id; adap->algo = &pcf_algo; adap->timeout = 100; /* default values, should */ diff --git a/drivers/i2c/algos/i2c-algo-sgi.c b/drivers/i2c/algos/i2c-algo-sgi.c index 422721b241e..932c4fa86c7 100644 --- a/drivers/i2c/algos/i2c-algo-sgi.c +++ b/drivers/i2c/algos/i2c-algo-sgi.c @@ -149,7 +149,7 @@ static int sgi_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, err = i2c_write(adap, p->buf, p->len); } - return err; + return (err < 0) ? err : i; } static u32 sgi_func(struct i2c_adapter *adap) @@ -158,8 +158,6 @@ static u32 sgi_func(struct i2c_adapter *adap) } static struct i2c_algorithm sgi_algo = { - .name = "SGI algorithm", - .id = I2C_ALGO_SGI, .master_xfer = sgi_xfer, .functionality = sgi_func, }; @@ -169,7 +167,6 @@ static struct i2c_algorithm sgi_algo = { */ int i2c_sgi_add_bus(struct i2c_adapter *adap) { - adap->id |= sgi_algo.id; adap->algo = &sgi_algo; return i2c_add_adapter(adap); diff --git a/drivers/i2c/algos/i2c-algo-sibyte.c b/drivers/i2c/algos/i2c-algo-sibyte.c index f2785499237..8ed5ad12552 100644 --- a/drivers/i2c/algos/i2c-algo-sibyte.c +++ b/drivers/i2c/algos/i2c-algo-sibyte.c @@ -135,8 +135,6 @@ static u32 bit_func(struct i2c_adapter *adap) /* -----exported algorithm data: ------------------------------------- */ static struct i2c_algorithm i2c_sibyte_algo = { - .name = "SiByte algorithm", - .id = I2C_ALGO_SIBYTE, .smbus_xfer = smbus_xfer, .algo_control = algo_control, /* ioctl */ .functionality = bit_func, @@ -151,8 +149,6 @@ int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed) struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data; /* register new adapter to i2c module... */ - - i2c_adap->id |= i2c_sibyte_algo.id; i2c_adap->algo = &i2c_sibyte_algo; /* Set the frequency to 100 kHz */ diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 916ba5e40a9..6e9da137222 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -182,14 +182,8 @@ config I2C_IOP3XX will be called i2c-iop3xx. config I2C_ISA - tristate "ISA Bus support" + tristate depends on I2C - help - If you say yes to this option, support will be included for i2c - interfaces that are on the ISA bus. - - This driver can also be built as a module. If so, the module - will be called i2c-isa. config I2C_ITE tristate "ITE I2C Adapter" diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c index f634a0780cf..f021acd2674 100644 --- a/drivers/i2c/busses/i2c-ali1535.c +++ b/drivers/i2c/busses/i2c-ali1535.c @@ -472,8 +472,6 @@ static u32 ali1535_func(struct i2c_adapter *adapter) } static struct i2c_algorithm smbus_algorithm = { - .name = "Non-i2c SMBus adapter", - .id = I2C_ALGO_SMBUS, .smbus_xfer = ali1535_access, .functionality = ali1535_func, }; diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c index fdd881aee61..86947504aea 100644 --- a/drivers/i2c/busses/i2c-ali1563.c +++ b/drivers/i2c/busses/i2c-ali1563.c @@ -366,8 +366,6 @@ static void ali1563_shutdown(struct pci_dev *dev) } static struct i2c_algorithm ali1563_algorithm = { - .name = "Non-i2c SMBus adapter", - .id = I2C_ALGO_SMBUS, .smbus_xfer = ali1563_access, .functionality = ali1563_func, }; diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c index 0f781a1a332..b3f50bff39a 100644 --- a/drivers/i2c/busses/i2c-ali15x3.c +++ b/drivers/i2c/busses/i2c-ali15x3.c @@ -462,8 +462,6 @@ static u32 ali15x3_func(struct i2c_adapter *adapter) } static struct i2c_algorithm smbus_algorithm = { - .name = "Non-I2C SMBus adapter", - .id = I2C_ALGO_SMBUS, .smbus_xfer = ali15x3_access, .functionality = ali15x3_func, }; diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c index 6347ebc6fb5..6ad0603384b 100644 --- a/drivers/i2c/busses/i2c-amd756.c +++ b/drivers/i2c/busses/i2c-amd756.c @@ -295,8 +295,6 @@ static u32 amd756_func(struct i2c_adapter *adapter) } static struct i2c_algorithm smbus_algorithm = { - .name = "Non-I2C SMBus adapter", - .id = I2C_ALGO_SMBUS, .smbus_xfer = amd756_access, .functionality = amd756_func, }; diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c index d6644481d2a..45ea24ba14d 100644 --- a/drivers/i2c/busses/i2c-amd8111.c +++ b/drivers/i2c/busses/i2c-amd8111.c @@ -323,8 +323,6 @@ static u32 amd8111_func(struct i2c_adapter *adapter) } static struct i2c_algorithm smbus_algorithm = { - .name = "Non-I2C SMBus 2.0 adapter", - .id = I2C_ALGO_SMBUS, .smbus_xfer = amd8111_access, .functionality = amd8111_func, }; diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c index a7ff112e49b..d06edce03bf 100644 --- a/drivers/i2c/busses/i2c-au1550.c +++ b/drivers/i2c/busses/i2c-au1550.c @@ -283,8 +283,6 @@ au1550_func(struct i2c_adapter *adap) } static struct i2c_algorithm au1550_algo = { - .name = "Au1550 algorithm", - .id = I2C_ALGO_AU1550, .master_xfer = au1550_xfer, .functionality = au1550_func, }; diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 1ab41313ce5..709beab7660 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -535,8 +535,6 @@ static u32 i801_func(struct i2c_adapter *adapter) } static struct i2c_algorithm smbus_algorithm = { - .name = "Non-I2C SMBus adapter", - .id = I2C_ALGO_SMBUS, .smbus_xfer = i801_access, .functionality = i801_func, }; diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c index 93ca36dc777..a3ed9590f02 100644 --- a/drivers/i2c/busses/i2c-ibm_iic.c +++ b/drivers/i2c/busses/i2c-ibm_iic.c @@ -627,8 +627,6 @@ static u32 iic_func(struct i2c_adapter *adap) } static struct i2c_algorithm iic_algo = { - .name = "IBM IIC algorithm", - .id = I2C_ALGO_OCP, .master_xfer = iic_xfer, .functionality = iic_func }; @@ -727,7 +725,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){ adap = &dev->adap; strcpy(adap->name, "IBM IIC"); i2c_set_adapdata(adap, dev); - adap->id = I2C_HW_OCP | iic_algo.id; + adap->id = I2C_HW_OCP; adap->algo = &iic_algo; adap->client_register = NULL; adap->client_unregister = NULL; diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c index 6b682e903f0..7bd9102db70 100644 --- a/drivers/i2c/busses/i2c-iop3xx.c +++ b/drivers/i2c/busses/i2c-iop3xx.c @@ -399,8 +399,6 @@ iop3xx_i2c_func(struct i2c_adapter *adap) } static struct i2c_algorithm iop3xx_i2c_algo = { - .name = "IOP3xx I2C algorithm", - .id = I2C_ALGO_IOP3XX, .master_xfer = iop3xx_i2c_master_xfer, .algo_control = iop3xx_i2c_algo_control, .functionality = iop3xx_i2c_func, diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c index 00e7f7157b7..bdc6806dafa 100644 --- a/drivers/i2c/busses/i2c-isa.c +++ b/drivers/i2c/busses/i2c-isa.c @@ -1,6 +1,8 @@ /* - i2c-isa.c - Part of lm_sensors, Linux kernel modules for hardware - monitoring + i2c-isa.c - an i2c-core-like thing for ISA hardware monitoring chips + Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> + + Based on the i2c-isa pseudo-adapter from the lm_sensors project Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> This program is free software; you can redistribute it and/or modify @@ -18,30 +20,36 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* This implements an i2c algorithm/adapter for ISA bus. Not that this is - on first sight very useful; almost no functionality is preserved. - Except that it makes writing drivers for chips which can be on both - the SMBus and the ISA bus very much easier. See lm78.c for an example - of this. */ +/* This implements an i2c-core-like thing for ISA hardware monitoring + chips. Such chips are linked to the i2c subsystem for historical + reasons (because the early ISA hardware monitoring chips such as the + LM78 had both an I2C and an ISA interface). They used to be + registered with the main i2c-core, but as a first step in the + direction of a clean separation between I2C and ISA chip drivers, + we now have this separate core for ISA ones. It is significantly + more simple than the real one, of course, because we don't have to + handle multiple busses: there is only one (fake) ISA adapter. + It is worth noting that we still rely on i2c-core for some things + at the moment - but hopefully this won't last. */ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/i2c.h> +#include <linux/i2c-isa.h> static u32 isa_func(struct i2c_adapter *adapter); /* This is the actual algorithm we define */ static struct i2c_algorithm isa_algorithm = { - .name = "ISA bus algorithm", - .id = I2C_ALGO_ISA, .functionality = isa_func, }; /* There can only be one... */ static struct i2c_adapter isa_adapter = { .owner = THIS_MODULE, + .id = I2C_HW_ISA, .class = I2C_CLASS_HWMON, .algo = &isa_algorithm, .name = "ISA main adapter", @@ -53,17 +61,146 @@ static u32 isa_func(struct i2c_adapter *adapter) return 0; } + +/* Copied from i2c-core */ +static ssize_t show_adapter_name(struct device *dev, + struct device_attribute *attr, 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 int i2c_isa_device_probe(struct device *dev) +{ + return -ENODEV; +} + +static int i2c_isa_device_remove(struct device *dev) +{ + return 0; +} + + +/* We implement an interface which resembles i2c_{add,del}_driver, + but for i2c-isa drivers. We don't have to remember and handle lists + of drivers and adapters so this is much more simple, of course. */ + +int i2c_isa_add_driver(struct i2c_driver *driver) +{ + int res; + + /* Add the driver to the list of i2c drivers in the driver core */ + driver->driver.name = driver->name; + driver->driver.bus = &i2c_bus_type; + driver->driver.probe = i2c_isa_device_probe; + driver->driver.remove = i2c_isa_device_remove; + res = driver_register(&driver->driver); + if (res) + return res; + dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->name); + + /* Now look for clients */ + driver->attach_adapter(&isa_adapter); + + return 0; +} + +int i2c_isa_del_driver(struct i2c_driver *driver) +{ + struct list_head *item, *_n; + struct i2c_client *client; + int res; + + /* Detach all clients belonging to this one driver */ + list_for_each_safe(item, _n, &isa_adapter.clients) { + client = list_entry(item, struct i2c_client, list); + if (client->driver != driver) + continue; + dev_dbg(&isa_adapter.dev, "Detaching client %s at 0x%x\n", + client->name, client->addr); + if ((res = driver->detach_client(client))) { + dev_err(&isa_adapter.dev, "Failed, driver " + "%s not unregistered!\n", + driver->name); + return res; + } + } + + /* Get the driver off the core list */ + driver_unregister(&driver->driver); + dev_dbg(&isa_adapter.dev, "Driver %s unregistered\n", driver->name); + + return 0; +} + + static int __init i2c_isa_init(void) { - return i2c_add_adapter(&isa_adapter); + init_MUTEX(&isa_adapter.clist_lock); + INIT_LIST_HEAD(&isa_adapter.clients); + + isa_adapter.nr = ANY_I2C_ISA_BUS; + isa_adapter.dev.parent = &platform_bus; + sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); + isa_adapter.dev.driver = &i2c_adapter_driver; + isa_adapter.dev.release = &i2c_adapter_dev_release; + device_register(&isa_adapter.dev); + device_create_file(&isa_adapter.dev, &dev_attr_name); + + /* Add this adapter to the i2c_adapter class */ + memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device)); + isa_adapter.class_dev.dev = &isa_adapter.dev; + isa_adapter.class_dev.class = &i2c_adapter_class; + strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id, + BUS_ID_SIZE); + class_device_register(&isa_adapter.class_dev); + + dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); + + return 0; } static void __exit i2c_isa_exit(void) { - i2c_del_adapter(&isa_adapter); +#ifdef DEBUG + struct list_head *item, *_n; + struct i2c_client *client = NULL; +#endif + + /* There should be no more active client */ +#ifdef DEBUG + dev_dbg(&isa_adapter.dev, "Looking for clients\n"); + list_for_each_safe(item, _n, &isa_adapter.clients) { + client = list_entry(item, struct i2c_client, list); + dev_err(&isa_adapter.dev, "Driver %s still has an active " + "ISA client at 0x%x\n", client->driver->name, + client->addr); + } + if (client != NULL) + return; +#endif + + /* Clean up the sysfs representation */ + dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); + init_completion(&isa_adapter.dev_released); + init_completion(&isa_adapter.class_dev_released); + class_device_unregister(&isa_adapter.class_dev); + device_remove_file(&isa_adapter.dev, &dev_attr_name); + device_unregister(&isa_adapter.dev); + + /* Wait for sysfs to drop all references */ + dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n"); + wait_for_completion(&isa_adapter.dev_released); + wait_for_completion(&isa_adapter.class_dev_released); + + dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name); } -MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"); +EXPORT_SYMBOL(i2c_isa_add_driver); +EXPORT_SYMBOL(i2c_isa_del_driver); + +MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); MODULE_DESCRIPTION("ISA bus access through i2c"); MODULE_LICENSE("GPL"); diff --git a/drivers/i2c/busses/i2c-keywest.c b/drivers/i2c/busses/i2c-keywest.c index 94ae808314f..37b49c2daf5 100644 --- a/drivers/i2c/busses/i2c-keywest.c +++ b/drivers/i2c/busses/i2c-keywest.c @@ -87,12 +87,9 @@ static const char *__kw_state_names[] = { }; #endif /* DEBUG */ -static int probe; - MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>"); MODULE_DESCRIPTION("I2C driver for Apple's Keywest"); MODULE_LICENSE("GPL"); -module_param(probe, bool, 0); #ifdef POLLED_MODE /* Don't schedule, the g5 fan controller is too @@ -498,8 +495,6 @@ keywest_func(struct i2c_adapter * adapter) /* For now, we only handle combined mode (smbus) */ static struct i2c_algorithm keywest_algorithm = { - .name = "Keywest i2c", - .id = I2C_ALGO_SMBUS, .smbus_xfer = keywest_smbus_xfer, .master_xfer = keywest_xfer, .functionality = keywest_func, @@ -621,7 +616,6 @@ create_iface(struct device_node *np, struct device *dev) sprintf(chan->adapter.name, "%s %d", np->parent->name, i); chan->iface = iface; chan->chan_no = i; - chan->adapter.id = I2C_ALGO_SMBUS; chan->adapter.algo = &keywest_algorithm; chan->adapter.algo_data = NULL; chan->adapter.client_register = NULL; @@ -635,15 +629,6 @@ create_iface(struct device_node *np, struct device *dev) chan->adapter.name); i2c_set_adapdata(&chan->adapter, NULL); } - if (probe) { - printk("Probe: "); - for (addr = 0x00; addr <= 0x7f; addr++) { - if (i2c_smbus_xfer(&chan->adapter,addr, - 0,0,0,I2C_SMBUS_QUICK,NULL) >= 0) - printk("%02x ", addr); - } - printk("\n"); - } } printk(KERN_INFO "Found KeyWest i2c on \"%s\", %d channel%s, stepping: %d bits\n", diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index 9ad3e9262e8..f065583ddcf 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c @@ -272,8 +272,6 @@ static u32 mpc_functionality(struct i2c_adapter *adap) } static struct i2c_algorithm mpc_algo = { - .name = "MPC algorithm", - .id = I2C_ALGO_MPC107, .master_xfer = mpc_xfer, .functionality = mpc_functionality, }; @@ -281,7 +279,7 @@ static struct i2c_algorithm mpc_algo = { static struct i2c_adapter mpc_ops = { .owner = THIS_MODULE, .name = "MPC adapter", - .id = I2C_ALGO_MPC107 | I2C_HW_MPC107, + .id = I2C_HW_MPC107, .algo = &mpc_algo, .class = I2C_CLASS_HWMON, .timeout = 1, diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c index 5b852782d2f..99abca45fec 100644 --- a/drivers/i2c/busses/i2c-mv64xxx.c +++ b/drivers/i2c/busses/i2c-mv64xxx.c @@ -423,18 +423,16 @@ static int mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) { struct mv64xxx_i2c_data *drv_data = i2c_get_adapdata(adap); - int i, rc = 0; + int i, rc; for (i=0; i<num; i++) - if ((rc = mv64xxx_i2c_execute_msg(drv_data, &msgs[i])) != 0) - break; + if ((rc = mv64xxx_i2c_execute_msg(drv_data, &msgs[i])) < 0) + return rc; - return rc; + return num; } static struct i2c_algorithm mv64xxx_i2c_algo = { - .name = MV64XXX_I2C_CTLR_NAME " algorithm", - .id = I2C_ALGO_MV64XXX, .master_xfer = mv64xxx_i2c_xfer, .functionality = mv64xxx_i2c_functionality, }; @@ -523,7 +521,7 @@ mv64xxx_i2c_probe(struct device *dev) drv_data->freq_m = pdata->freq_m; drv_data->freq_n = pdata->freq_n; drv_data->irq = platform_get_irq(pd, 0); - drv_data->adapter.id = I2C_ALGO_MV64XXX | I2C_HW_MV64XXX; + drv_data->adapter.id = I2C_HW_MV64XXX; drv_data->adapter.algo = &mv64xxx_i2c_algo; drv_data->adapter.owner = THIS_MODULE; drv_data->adapter.class = I2C_CLASS_HWMON; diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c index 74eb89aa935..e0b7a913431 100644 --- a/drivers/i2c/busses/i2c-nforce2.c +++ b/drivers/i2c/busses/i2c-nforce2.c @@ -110,8 +110,6 @@ static u32 nforce2_func(struct i2c_adapter *adapter); static struct i2c_algorithm smbus_algorithm = { - .name = "Non-I2C SMBus adapter", - .id = I2C_ALGO_SMBUS, .smbus_xfer = nforce2_access, .functionality = nforce2_func, }; @@ -131,7 +129,6 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, struct nforce2_smbus *smbus = adap->algo_data; unsigned char protocol, pec, temp; unsigned char len = 0; /* to keep the compiler quiet */ - int timeout = 0; int i; protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ : @@ -191,29 +188,10 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, case I2C_SMBUS_PROC_CALL: dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); return -1; - /* - outb_p(command, NVIDIA_SMB_CMD); - outb_p(data->word, NVIDIA_SMB_DATA); - outb_p(data->word >> 8, NVIDIA_SMB_DATA + 1); - protocol = NVIDIA_SMB_PRTCL_PROC_CALL | pec; - read_write = I2C_SMBUS_READ; - break; - */ case I2C_SMBUS_BLOCK_PROC_CALL: dev_err(&adap->dev, "I2C_SMBUS_BLOCK_PROC_CALL not supported!\n"); return -1; - /* - protocol |= pec; - len = min_t(u8, data->block[0], 31); - outb_p(command, NVIDIA_SMB_CMD); - outb_p(len, NVIDIA_SMB_BCNT); - for (i = 0; i < len; i++) - outb_p(data->block[i + 1], NVIDIA_SMB_DATA + i); - protocol = NVIDIA_SMB_PRTCL_BLOCK_PROC_CALL | pec; - read_write = I2C_SMBUS_READ; - break; - */ case I2C_SMBUS_WORD_DATA_PEC: case I2C_SMBUS_BLOCK_DATA_PEC: @@ -232,12 +210,6 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, temp = inb_p(NVIDIA_SMB_STS); -#if 0 - do { - i2c_do_pause(1); - temp = inb_p(NVIDIA_SMB_STS); - } while (((temp & NVIDIA_SMB_STS_DONE) == 0) && (timeout++ < MAX_TIMEOUT)); -#endif if (~temp & NVIDIA_SMB_STS_DONE) { udelay(500); temp = inb_p(NVIDIA_SMB_STS); @@ -247,9 +219,10 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, temp = inb_p(NVIDIA_SMB_STS); } - if ((timeout >= MAX_TIMEOUT) || (~temp & NVIDIA_SMB_STS_DONE) - || (temp & NVIDIA_SMB_STS_STATUS)) + if ((~temp & NVIDIA_SMB_STS_DONE) || (temp & NVIDIA_SMB_STS_STATUS)) { + dev_dbg(&adap->dev, "SMBus Timeout! (0x%02x)\n", temp); return -1; + } if (read_write == I2C_SMBUS_WRITE) return 0; diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c index 6d34ee381ce..6d48a4da7be 100644 --- a/drivers/i2c/busses/i2c-piix4.c +++ b/drivers/i2c/busses/i2c-piix4.c @@ -399,8 +399,6 @@ static u32 piix4_func(struct i2c_adapter *adapter) } static struct i2c_algorithm smbus_algorithm = { - .name = "Non-I2C SMBus adapter", - .id = I2C_ALGO_SMBUS, .smbus_xfer = piix4_access, .functionality = piix4_func, }; diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index a3b38257cc3..73a092fb0e7 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -568,7 +568,6 @@ static u32 s3c24xx_i2c_func(struct i2c_adapter *adap) /* i2c bus registration info */ static struct i2c_algorithm s3c24xx_i2c_algorithm = { - .name = "S3C2410-I2C-Algorithm", .master_xfer = s3c24xx_i2c_xfer, .functionality = s3c24xx_i2c_func, }; diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c index bbd5e4e52f0..080318d6f54 100644 --- a/drivers/i2c/busses/i2c-sis5595.c +++ b/drivers/i2c/busses/i2c-sis5595.c @@ -357,8 +357,6 @@ static u32 sis5595_func(struct i2c_adapter *adapter) } static struct i2c_algorithm smbus_algorithm = { - .name = "Non-I2C SMBus adapter", - .id = I2C_ALGO_SMBUS, .smbus_xfer = sis5595_access, .functionality = sis5595_func, }; diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c index f58455e7689..86f0f448fa0 100644 --- a/drivers/i2c/busses/i2c-sis630.c +++ b/drivers/i2c/busses/i2c-sis630.c @@ -448,8 +448,6 @@ exit: static struct i2c_algorithm smbus_algorithm = { - .name = "Non-I2C SMBus adapter", - .id = I2C_ALGO_SMBUS, .smbus_xfer = sis630_access, .functionality = sis630_func, }; diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c index 6484792e23a..ead2ff3cf60 100644 --- a/drivers/i2c/busses/i2c-sis96x.c +++ b/drivers/i2c/busses/i2c-sis96x.c @@ -249,8 +249,6 @@ static u32 sis96x_func(struct i2c_adapter *adapter) } static struct i2c_algorithm smbus_algorithm = { - .name = "Non-I2C SMBus adapter", - .id = I2C_ALGO_SMBUS, .smbus_xfer = sis96x_access, .functionality = sis96x_func, }; diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c index 00d94e88695..73f481e93a3 100644 --- a/drivers/i2c/busses/i2c-stub.c +++ b/drivers/i2c/busses/i2c-stub.c @@ -109,8 +109,6 @@ static u32 stub_func(struct i2c_adapter *adapter) } static struct i2c_algorithm smbus_algorithm = { - .name = "Non-I2C SMBus adapter", - .id = I2C_ALGO_SMBUS, .functionality = stub_func, .smbus_xfer = stub_xfer, }; diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c index 6b5008005c6..99d209e0485 100644 --- a/drivers/i2c/busses/i2c-viapro.c +++ b/drivers/i2c/busses/i2c-viapro.c @@ -286,8 +286,6 @@ static u32 vt596_func(struct i2c_adapter *adapter) } static struct i2c_algorithm smbus_algorithm = { - .name = "Non-I2C SMBus adapter", - .id = I2C_ALGO_SMBUS, .smbus_xfer = vt596_access, .functionality = vt596_func, }; diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c index a18bdd9aa7b..a1d580e0536 100644 --- a/drivers/i2c/busses/scx200_acb.c +++ b/drivers/i2c/busses/scx200_acb.c @@ -395,8 +395,6 @@ static u32 scx200_acb_func(struct i2c_adapter *adapter) /* For now, we only handle combined mode (smbus) */ static struct i2c_algorithm scx200_acb_algorithm = { - .name = "NatSemi SCx200 ACCESS.bus", - .id = I2C_ALGO_SMBUS, .smbus_xfer = scx200_acb_smbus_xfer, .functionality = scx200_acb_func, }; @@ -456,7 +454,7 @@ static int __init scx200_acb_create(int base, int index) i2c_set_adapdata(adapter, iface); snprintf(adapter->name, I2C_NAME_SIZE, "SCx200 ACB%d", index); adapter->owner = THIS_MODULE; - adapter->id = I2C_ALGO_SMBUS; + adapter->id = I2C_HW_SMBUS_SCX200; adapter->algo = &scx200_acb_algorithm; adapter->class = I2C_CLASS_HWMON; diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig index 43f70dbfc03..6bd44a44cd2 100644 --- a/drivers/i2c/chips/Kconfig +++ b/drivers/i2c/chips/Kconfig @@ -2,17 +2,12 @@ # Miscellaneous I2C chip drivers configuration # -config I2C_SENSOR - tristate - default n - menu "Miscellaneous I2C Chip support" depends on I2C config SENSORS_DS1337 tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock" depends on I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for Dallas Semiconductor DS1337 and DS1339 real-time clock chips. @@ -23,7 +18,6 @@ config SENSORS_DS1337 config SENSORS_DS1374 tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock" depends on I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for Dallas Semiconductor DS1374 real-time clock chips. @@ -34,7 +28,6 @@ config SENSORS_DS1374 config SENSORS_EEPROM tristate "EEPROM reader" depends on I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get read-only access to the EEPROM data available on modern memory DIMMs and Sony Vaio laptops. Such @@ -46,7 +39,6 @@ config SENSORS_EEPROM config SENSORS_PCF8574 tristate "Philips PCF8574 and PCF8574A" depends on I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for Philips PCF8574 and PCF8574A chips. @@ -67,7 +59,6 @@ config SENSORS_PCA9539 config SENSORS_PCF8591 tristate "Philips PCF8591" depends on I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for Philips PCF8591 chips. @@ -77,7 +68,6 @@ config SENSORS_PCF8591 config SENSORS_RTC8564 tristate "Epson 8564 RTC chip" depends on I2C && EXPERIMENTAL - select I2C_SENSOR help If you say yes here you get support for the Epson 8564 RTC chip. diff --git a/drivers/i2c/chips/ds1337.c b/drivers/i2c/chips/ds1337.c index 82cf959989f..9d3175c0339 100644 --- a/drivers/i2c/chips/ds1337.c +++ b/drivers/i2c/chips/ds1337.c @@ -17,7 +17,6 @@ #include <linux/init.h> #include <linux/slab.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> #include <linux/string.h> #include <linux/rtc.h> /* get the user-level API */ #include <linux/bcd.h> @@ -39,9 +38,8 @@ * Functions declaration */ static unsigned short normal_i2c[] = { 0x68, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; -SENSORS_INSMOD_1(ds1337); +I2C_CLIENT_INSMOD_1(ds1337); static int ds1337_attach_adapter(struct i2c_adapter *adapter); static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind); @@ -227,7 +225,7 @@ int ds1337_do_command(int bus, int cmd, void *arg) static int ds1337_attach_adapter(struct i2c_adapter *adapter) { - return i2c_detect(adapter, &addr_data, ds1337_detect); + return i2c_probe(adapter, &addr_data, ds1337_detect); } /* @@ -354,11 +352,8 @@ static int ds1337_detach_client(struct i2c_client *client) int err; struct ds1337_data *data = i2c_get_clientdata(client); - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + if ((err = i2c_detach_client(client))) return err; - } list_del(&data->list); kfree(data); diff --git a/drivers/i2c/chips/ds1374.c b/drivers/i2c/chips/ds1374.c index a445736d883..0936327a946 100644 --- a/drivers/i2c/chips/ds1374.c +++ b/drivers/i2c/chips/ds1374.c @@ -53,7 +53,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_addr, .probe = ignore, .ignore = ignore, - .force = ignore, }; static ulong ds1374_read_rtc(void) @@ -166,7 +165,7 @@ static void ds1374_set_tlet(ulong arg) "can't confirm time set from rtc chip\n"); } -ulong new_time; +static ulong new_time; DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet, (ulong) & new_time); diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c index a2da31b0dd7..d58403a4790 100644 --- a/drivers/i2c/chips/eeprom.c +++ b/drivers/i2c/chips/eeprom.c @@ -33,15 +33,13 @@ #include <linux/sched.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_1(eeprom); +I2C_CLIENT_INSMOD_1(eeprom); /* Size of EEPROM in bytes */ @@ -153,21 +151,16 @@ static struct bin_attribute eeprom_attr = { static int eeprom_attach_adapter(struct i2c_adapter *adapter) { - return i2c_detect(adapter, &addr_data, eeprom_detect); + return i2c_probe(adapter, &addr_data, eeprom_detect); } -/* This function is called by i2c_detect */ +/* This function is called by i2c_probe */ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) { struct i2c_client *new_client; struct eeprom_data *data; int err = 0; - /* prevent 24RF08 corruption */ - if (kind < 0) - i2c_smbus_xfer(adapter, address, 0, 0, 0, - I2C_SMBUS_QUICK, NULL); - /* There are three ways we can read the EEPROM data: (1) I2C block reads (faster, but unsupported by most adapters) (2) Consecutive byte reads (100% overhead) @@ -231,10 +224,8 @@ static int eeprom_detach_client(struct i2c_client *client) int err; err = i2c_detach_client(client); - if (err) { - dev_err(&client->dev, "Client deregistration failed, client not detached.\n"); + if (err) return err; - } kfree(i2c_get_clientdata(client)); diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c index 778d7e12859..3f14528a52a 100644 --- a/drivers/i2c/chips/m41t00.c +++ b/drivers/i2c/chips/m41t00.c @@ -42,7 +42,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_addr, .probe = ignore, .ignore = ignore, - .force = ignore, }; ulong @@ -145,7 +144,7 @@ m41t00_set_tlet(ulong arg) return; } -ulong new_time; +static ulong new_time; DECLARE_TASKLET_DISABLED(m41t00_tasklet, m41t00_set_tlet, (ulong)&new_time); diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c index 0230375f72e..9e1aeb69abf 100644 --- a/drivers/i2c/chips/max6875.c +++ b/drivers/i2c/chips/max6875.c @@ -5,97 +5,60 @@ Based on i2c/chips/eeprom.c - The MAX6875 has two EEPROM sections: config and user. - At reset, the config EEPROM is read into the registers. + The MAX6875 has a bank of registers and two banks of EEPROM. + Address ranges are defined as follows: + * 0x0000 - 0x0046 = configuration registers + * 0x8000 - 0x8046 = configuration EEPROM + * 0x8100 - 0x82FF = user EEPROM - This driver make 3 binary files available in sysfs: - reg_config - direct access to the registers - eeprom_config - acesses configuration eeprom space - eeprom_user - free for application use + This driver makes the user EEPROM available for read. - In our application, we put device serial & model numbers in user eeprom. + The registers & config EEPROM should be accessed via i2c-dev. - Notes: - 1) The datasheet says that register 0x44 / EEPROM 0x8044 should NOT - be overwritten, so the driver explicitly prevents that. - 2) It's a good idea to keep the config (0x45) locked in config EEPROM. - You can temporarily enable config writes by changing register 0x45. + The MAX6875 ignores the lowest address bit, so each chip responds to + two addresses - 0x50/0x51 and 0x52/0x53. + + Note that the MAX6875 uses i2c_smbus_write_byte_data() to set the read + address, so this driver is destructive if loaded for the wrong EEPROM chip. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. */ -#include <linux/config.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/module.h> #include <linux/slab.h> -#include <linux/sched.h> -#include <linux/delay.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <asm/semaphore.h> -/* Addresses to scan */ -/* No address scanned by default, as this could corrupt standard EEPROMS. */ +/* Do not scan - the MAX6875 access method will write to some EEPROM chips */ static unsigned short normal_i2c[] = {I2C_CLIENT_END}; -static unsigned int normal_isa[] = {I2C_CLIENT_ISA_END}; /* Insmod parameters */ -SENSORS_INSMOD_1(max6875); - -/* this param will prevent 'accidental' writes to the eeprom */ -static int allow_write = 0; -module_param(allow_write, int, 0); -MODULE_PARM_DESC(allow_write, - "Enable write access:\n" - "*0: Read only\n" - " 1: Read/Write access"); +I2C_CLIENT_INSMOD_1(max6875); /* The MAX6875 can only read/write 16 bytes at a time */ #define SLICE_SIZE 16 #define SLICE_BITS 4 -/* CONFIG EEPROM is at addresses 0x8000 - 0x8045, registers are at 0 - 0x45 */ -#define CONFIG_EEPROM_BASE 0x8000 -#define CONFIG_EEPROM_SIZE 0x0046 -#define CONFIG_EEPROM_SLICES 5 - /* USER EEPROM is at addresses 0x8100 - 0x82FF */ #define USER_EEPROM_BASE 0x8100 #define USER_EEPROM_SIZE 0x0200 #define USER_EEPROM_SLICES 32 /* MAX6875 commands */ -#define MAX6875_CMD_BLOCK_WRITE 0x83 -#define MAX6875_CMD_BLOCK_READ 0x84 -#define MAX6875_CMD_REBOOT 0x88 - -enum max6875_area_type { - max6875_register_config=0, - max6875_eeprom_config, - max6875_eeprom_user, - max6857_max -}; - -struct eeprom_block { - enum max6875_area_type type; - u8 slices; - u32 size; - u32 valid; - u32 base; - unsigned long *updated; - u8 *data; -}; +#define MAX6875_CMD_BLK_READ 0x84 /* Each client has this additional data */ struct max6875_data { struct i2c_client client; struct semaphore update_lock; - struct eeprom_block blocks[max6857_max]; - /* the above structs point into the arrays below */ - u8 data[USER_EEPROM_SIZE + (CONFIG_EEPROM_SIZE*2)]; - unsigned long last_updated[USER_EEPROM_SLICES + (CONFIG_EEPROM_SLICES*2)]; + + u32 valid; + u8 data[USER_EEPROM_SIZE]; + unsigned long last_updated[USER_EEPROM_SLICES]; }; static int max6875_attach_adapter(struct i2c_adapter *adapter); @@ -111,337 +74,160 @@ static struct i2c_driver max6875_driver = { .detach_client = max6875_detach_client, }; -static int max6875_update_slice(struct i2c_client *client, - struct eeprom_block *blk, - int slice) +static void max6875_update_slice(struct i2c_client *client, int slice) { struct max6875_data *data = i2c_get_clientdata(client); - int i, j, addr, count; - u8 rdbuf[SLICE_SIZE]; - int retval = 0; + int i, j, addr; + u8 *buf; - if (slice >= blk->slices) - return -1; + if (slice >= USER_EEPROM_SLICES) + return; down(&data->update_lock); - if (!(blk->valid & (1 << slice)) || - (jiffies - blk->updated[slice] > 300 * HZ) || - (jiffies < blk->updated[slice])) { - dev_dbg(&client->dev, "Starting eeprom update, slice %u, base %u\n", - slice, blk->base); + buf = &data->data[slice << SLICE_BITS]; - addr = blk->base + (slice << SLICE_BITS); - count = blk->size - (slice << SLICE_BITS); - if (count > SLICE_SIZE) { - count = SLICE_SIZE; - } + if (!(data->valid & (1 << slice)) || + time_after(jiffies, data->last_updated[slice])) { - /* Preset the read address */ - if (addr < 0x100) { - /* select the register */ - if (i2c_smbus_write_byte(client, addr & 0xFF)) { - dev_dbg(&client->dev, "max6875 register select has failed!\n"); - retval = -1; - goto exit; - } - } else { - /* select the eeprom */ - if (i2c_smbus_write_byte_data(client, addr >> 8, addr & 0xFF)) { - dev_dbg(&client->dev, "max6875 address set has failed!\n"); - retval = -1; - goto exit; - } + dev_dbg(&client->dev, "Starting update of slice %u\n", slice); + + data->valid &= ~(1 << slice); + + addr = USER_EEPROM_BASE + (slice << SLICE_BITS); + + /* select the eeprom address */ + if (i2c_smbus_write_byte_data(client, addr >> 8, addr & 0xFF)) { + dev_err(&client->dev, "address set failed\n"); + goto exit_up; } - if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { - if (i2c_smbus_read_i2c_block_data(client, MAX6875_CMD_BLOCK_READ, - rdbuf) != SLICE_SIZE) - { - retval = -1; - goto exit; + if (i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { + if (i2c_smbus_read_i2c_block_data(client, + MAX6875_CMD_BLK_READ, + buf) != SLICE_SIZE) { + goto exit_up; } - - memcpy(&blk->data[slice << SLICE_BITS], rdbuf, count); } else { - for (i = 0; i < count; i++) { + for (i = 0; i < SLICE_SIZE; i++) { j = i2c_smbus_read_byte(client); - if (j < 0) - { - retval = -1; - goto exit; + if (j < 0) { + goto exit_up; } - blk->data[(slice << SLICE_BITS) + i] = (u8) j; + buf[i] = j; } } - blk->updated[slice] = jiffies; - blk->valid |= (1 << slice); + data->last_updated[slice] = jiffies; + data->valid |= (1 << slice); } - exit: +exit_up: up(&data->update_lock); - return retval; } -static ssize_t max6875_read(struct kobject *kobj, char *buf, loff_t off, size_t count, - enum max6875_area_type area_type) +static ssize_t max6875_read(struct kobject *kobj, char *buf, loff_t off, + size_t count) { - struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); + struct i2c_client *client = kobj_to_i2c_client(kobj); struct max6875_data *data = i2c_get_clientdata(client); - struct eeprom_block *blk; - int slice; - - blk = &data->blocks[area_type]; + int slice, max_slice; - if (off > blk->size) + if (off > USER_EEPROM_SIZE) return 0; - if (off + count > blk->size) - count = blk->size - off; - /* Only refresh slices which contain requested bytes */ - for (slice = (off >> SLICE_BITS); slice <= ((off + count - 1) >> SLICE_BITS); slice++) - max6875_update_slice(client, blk, slice); + if (off + count > USER_EEPROM_SIZE) + count = USER_EEPROM_SIZE - off; - memcpy(buf, &blk->data[off], count); + /* refresh slices which contain requested bytes */ + max_slice = (off + count - 1) >> SLICE_BITS; + for (slice = (off >> SLICE_BITS); slice <= max_slice; slice++) + max6875_update_slice(client, slice); - return count; -} - -static ssize_t max6875_user_read(struct kobject *kobj, char *buf, loff_t off, size_t count) -{ - return max6875_read(kobj, buf, off, count, max6875_eeprom_user); -} - -static ssize_t max6875_config_read(struct kobject *kobj, char *buf, loff_t off, size_t count) -{ - return max6875_read(kobj, buf, off, count, max6875_eeprom_config); -} - -static ssize_t max6875_cfgreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count) -{ - return max6875_read(kobj, buf, off, count, max6875_register_config); -} - - -static ssize_t max6875_write(struct kobject *kobj, char *buf, loff_t off, size_t count, - enum max6875_area_type area_type) -{ - struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); - struct max6875_data *data = i2c_get_clientdata(client); - struct eeprom_block *blk; - int slice, addr, retval; - ssize_t sent = 0; - - blk = &data->blocks[area_type]; - - if (off > blk->size) - return 0; - if ((off + count) > blk->size) - count = blk->size - off; - - if (down_interruptible(&data->update_lock)) - return -EAGAIN; - - /* writing to a register is done with i2c_smbus_write_byte_data() */ - if (blk->type == max6875_register_config) { - for (sent = 0; sent < count; sent++) { - addr = off + sent; - if (addr == 0x44) - continue; - - retval = i2c_smbus_write_byte_data(client, addr, buf[sent]); - } - } else { - int cmd, val; - - /* We are writing to EEPROM */ - for (sent = 0; sent < count; sent++) { - addr = blk->base + off + sent; - cmd = addr >> 8; - val = (addr & 0xff) | (buf[sent] << 8); // reversed - - if (addr == 0x8044) - continue; - - retval = i2c_smbus_write_word_data(client, cmd, val); - - if (retval) { - goto error_exit; - } + memcpy(buf, &data->data[off], count); - /* A write takes up to 11 ms */ - msleep(11); - } - } - - /* Invalidate the scratch buffer */ - for (slice = (off >> SLICE_BITS); slice <= ((off + count - 1) >> SLICE_BITS); slice++) - blk->valid &= ~(1 << slice); - - error_exit: - up(&data->update_lock); - - return sent; -} - -static ssize_t max6875_user_write(struct kobject *kobj, char *buf, loff_t off, size_t count) -{ - return max6875_write(kobj, buf, off, count, max6875_eeprom_user); -} - -static ssize_t max6875_config_write(struct kobject *kobj, char *buf, loff_t off, size_t count) -{ - return max6875_write(kobj, buf, off, count, max6875_eeprom_config); -} - -static ssize_t max6875_cfgreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count) -{ - return max6875_write(kobj, buf, off, count, max6875_register_config); + return count; } static struct bin_attribute user_eeprom_attr = { .attr = { - .name = "eeprom_user", - .mode = S_IRUGO | S_IWUSR | S_IWGRP, - .owner = THIS_MODULE, - }, - .size = USER_EEPROM_SIZE, - .read = max6875_user_read, - .write = max6875_user_write, -}; - -static struct bin_attribute config_eeprom_attr = { - .attr = { - .name = "eeprom_config", - .mode = S_IRUGO | S_IWUSR, - .owner = THIS_MODULE, - }, - .size = CONFIG_EEPROM_SIZE, - .read = max6875_config_read, - .write = max6875_config_write, -}; - -static struct bin_attribute config_register_attr = { - .attr = { - .name = "reg_config", - .mode = S_IRUGO | S_IWUSR, + .name = "eeprom", + .mode = S_IRUGO, .owner = THIS_MODULE, }, - .size = CONFIG_EEPROM_SIZE, - .read = max6875_cfgreg_read, - .write = max6875_cfgreg_write, + .size = USER_EEPROM_SIZE, + .read = max6875_read, }; static int max6875_attach_adapter(struct i2c_adapter *adapter) { - return i2c_detect(adapter, &addr_data, max6875_detect); + return i2c_probe(adapter, &addr_data, max6875_detect); } -/* This function is called by i2c_detect */ +/* This function is called by i2c_probe */ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind) { - struct i2c_client *new_client; + struct i2c_client *real_client; + struct i2c_client *fake_client; struct max6875_data *data; int err = 0; - /* Prevent 24RF08 corruption (in case of user error) */ - if (kind < 0) - i2c_smbus_xfer(adapter, address, 0, 0, 0, - I2C_SMBUS_QUICK, NULL); - - /* There are three ways we can read the EEPROM data: - (1) I2C block reads (faster, but unsupported by most adapters) - (2) Consecutive byte reads (100% overhead) - (3) Regular byte data reads (200% overhead) - The third method is not implemented by this driver because all - known adapters support at least the second. */ - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA | - I2C_FUNC_SMBUS_BYTE | - I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) - goto exit; - - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access eeprom_{read,write}_value. */ - if (!(data = kmalloc(sizeof(struct max6875_data), GFP_KERNEL))) { - err = -ENOMEM; - goto exit; - } + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA + | I2C_FUNC_SMBUS_READ_BYTE)) + return 0; + + /* Only check even addresses */ + if (address & 1) + return 0; + + if (!(data = kmalloc(sizeof(struct max6875_data), GFP_KERNEL))) + return -ENOMEM; memset(data, 0, sizeof(struct max6875_data)); - new_client = &data->client; - i2c_set_clientdata(new_client, data); - new_client->addr = address; - new_client->adapter = adapter; - new_client->driver = &max6875_driver; - new_client->flags = 0; - - /* Setup the user section */ - data->blocks[max6875_eeprom_user].type = max6875_eeprom_user; - data->blocks[max6875_eeprom_user].slices = USER_EEPROM_SLICES; - data->blocks[max6875_eeprom_user].size = USER_EEPROM_SIZE; - data->blocks[max6875_eeprom_user].base = USER_EEPROM_BASE; - data->blocks[max6875_eeprom_user].data = data->data; - data->blocks[max6875_eeprom_user].updated = data->last_updated; - - /* Setup the config section */ - data->blocks[max6875_eeprom_config].type = max6875_eeprom_config; - data->blocks[max6875_eeprom_config].slices = CONFIG_EEPROM_SLICES; - data->blocks[max6875_eeprom_config].size = CONFIG_EEPROM_SIZE; - data->blocks[max6875_eeprom_config].base = CONFIG_EEPROM_BASE; - data->blocks[max6875_eeprom_config].data = &data->data[USER_EEPROM_SIZE]; - data->blocks[max6875_eeprom_config].updated = &data->last_updated[USER_EEPROM_SLICES]; - - /* Setup the register section */ - data->blocks[max6875_register_config].type = max6875_register_config; - data->blocks[max6875_register_config].slices = CONFIG_EEPROM_SLICES; - data->blocks[max6875_register_config].size = CONFIG_EEPROM_SIZE; - data->blocks[max6875_register_config].base = 0; - data->blocks[max6875_register_config].data = &data->data[USER_EEPROM_SIZE+CONFIG_EEPROM_SIZE]; - data->blocks[max6875_register_config].updated = &data->last_updated[USER_EEPROM_SLICES+CONFIG_EEPROM_SLICES]; - - /* Init the data */ - memset(data->data, 0xff, sizeof(data->data)); - - /* Fill in the remaining client fields */ - strlcpy(new_client->name, "max6875", I2C_NAME_SIZE); + /* A fake client is created on the odd address */ + if (!(fake_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) { + err = -ENOMEM; + goto exit_kfree1; + } + memset(fake_client, 0, sizeof(struct i2c_client)); + + /* Init real i2c_client */ + real_client = &data->client; + i2c_set_clientdata(real_client, data); + real_client->addr = address; + real_client->adapter = adapter; + real_client->driver = &max6875_driver; + real_client->flags = 0; + strlcpy(real_client->name, "max6875", I2C_NAME_SIZE); init_MUTEX(&data->update_lock); - /* Verify that the chip is really what we think it is */ - if ((max6875_update_slice(new_client, &data->blocks[max6875_eeprom_config], 4) < 0) || - (max6875_update_slice(new_client, &data->blocks[max6875_register_config], 4) < 0)) - goto exit_kfree; - - /* 0x41,0x42 must be zero and 0x40 must match in eeprom and registers */ - if ((data->blocks[max6875_eeprom_config].data[0x41] != 0) || - (data->blocks[max6875_eeprom_config].data[0x42] != 0) || - (data->blocks[max6875_register_config].data[0x41] != 0) || - (data->blocks[max6875_register_config].data[0x42] != 0) || - (data->blocks[max6875_eeprom_config].data[0x40] != - data->blocks[max6875_register_config].data[0x40])) - goto exit_kfree; - - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto exit_kfree; - - /* create the sysfs eeprom files with the correct permissions */ - if (allow_write == 0) { - user_eeprom_attr.attr.mode &= ~S_IWUGO; - user_eeprom_attr.write = NULL; - config_eeprom_attr.attr.mode &= ~S_IWUGO; - config_eeprom_attr.write = NULL; - config_register_attr.attr.mode &= ~S_IWUGO; - config_register_attr.write = NULL; - } - sysfs_create_bin_file(&new_client->dev.kobj, &user_eeprom_attr); - sysfs_create_bin_file(&new_client->dev.kobj, &config_eeprom_attr); - sysfs_create_bin_file(&new_client->dev.kobj, &config_register_attr); + /* Init fake client data */ + /* set the client data to the i2c_client so that it will get freed */ + i2c_set_clientdata(fake_client, fake_client); + fake_client->addr = address | 1; + fake_client->adapter = adapter; + fake_client->driver = &max6875_driver; + fake_client->flags = 0; + strlcpy(fake_client->name, "max6875 subclient", I2C_NAME_SIZE); + + /* Prevent 24RF08 corruption (in case of user error) */ + i2c_smbus_write_quick(real_client, 0); + + if ((err = i2c_attach_client(real_client)) != 0) + goto exit_kfree2; + + if ((err = i2c_attach_client(fake_client)) != 0) + goto exit_detach; + + sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr); return 0; -exit_kfree: +exit_detach: + i2c_detach_client(real_client); +exit_kfree2: + kfree(fake_client); +exit_kfree1: kfree(data); -exit: return err; } @@ -450,13 +236,9 @@ static int max6875_detach_client(struct i2c_client *client) int err; err = i2c_detach_client(client); - if (err) { - dev_err(&client->dev, "Client deregistration failed, client not detached.\n"); + if (err) return err; - } - kfree(i2c_get_clientdata(client)); - return 0; } diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c index 9f3ad45daae..225577fdda4 100644 --- a/drivers/i2c/chips/pca9539.c +++ b/drivers/i2c/chips/pca9539.c @@ -13,14 +13,12 @@ #include <linux/slab.h> #include <linux/i2c.h> #include <linux/hwmon-sysfs.h> -#include <linux/i2c-sensor.h> /* Addresses to scan */ static unsigned short normal_i2c[] = {0x74, 0x75, 0x76, 0x77, I2C_CLIENT_END}; -static unsigned int normal_isa[] = {I2C_CLIENT_ISA_END}; /* Insmod parameters */ -SENSORS_INSMOD_1(pca9539); +I2C_CLIENT_INSMOD_1(pca9539); enum pca9539_cmd { @@ -109,10 +107,10 @@ static struct attribute_group pca9539_defattr_group = { static int pca9539_attach_adapter(struct i2c_adapter *adapter) { - return i2c_detect(adapter, &addr_data, pca9539_detect); + return i2c_probe(adapter, &addr_data, pca9539_detect); } -/* This function is called by i2c_detect */ +/* This function is called by i2c_probe */ static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind) { struct i2c_client *new_client; @@ -164,10 +162,8 @@ static int pca9539_detach_client(struct i2c_client *client) { int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed.\n"); + if ((err = i2c_detach_client(client))) return err; - } kfree(i2c_get_clientdata(client)); return 0; diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c index cfcf6465408..6525743ff9f 100644 --- a/drivers/i2c/chips/pcf8574.c +++ b/drivers/i2c/chips/pcf8574.c @@ -39,16 +39,14 @@ #include <linux/init.h> #include <linux/slab.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_2(pcf8574, pcf8574a); +I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a); /* Initial values */ #define PCF8574_INIT 255 /* All outputs on (input mode) */ @@ -113,10 +111,10 @@ static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write); static int pcf8574_attach_adapter(struct i2c_adapter *adapter) { - return i2c_detect(adapter, &addr_data, pcf8574_detect); + return i2c_probe(adapter, &addr_data, pcf8574_detect); } -/* This function is called by i2c_detect */ +/* This function is called by i2c_probe */ int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) { struct i2c_client *new_client; @@ -186,11 +184,8 @@ static int pcf8574_detach_client(struct i2c_client *client) { int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, - "Client deregistration failed, client not detached.\n"); + if ((err = i2c_detach_client(client))) return err; - } kfree(i2c_get_clientdata(client)); return 0; diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c index db812ade856..80f1df9a450 100644 --- a/drivers/i2c/chips/pcf8591.c +++ b/drivers/i2c/chips/pcf8591.c @@ -24,15 +24,13 @@ #include <linux/init.h> #include <linux/slab.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_1(pcf8591); +I2C_CLIENT_INSMOD_1(pcf8591); static int input_mode; module_param(input_mode, int, 0); @@ -164,10 +162,10 @@ static DEVICE_ATTR(out0_enable, S_IWUSR | S_IRUGO, */ static int pcf8591_attach_adapter(struct i2c_adapter *adapter) { - return i2c_detect(adapter, &addr_data, pcf8591_detect); + return i2c_probe(adapter, &addr_data, pcf8591_detect); } -/* This function is called by i2c_detect */ +/* This function is called by i2c_probe */ int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) { struct i2c_client *new_client; @@ -241,11 +239,8 @@ static int pcf8591_detach_client(struct i2c_client *client) { int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, - "Client deregistration failed, client not detached.\n"); + if ((err = i2c_detach_client(client))) return err; - } kfree(i2c_get_clientdata(client)); return 0; diff --git a/drivers/i2c/chips/rtc8564.c b/drivers/i2c/chips/rtc8564.c index 588fc2261a9..0b5385c892b 100644 --- a/drivers/i2c/chips/rtc8564.c +++ b/drivers/i2c/chips/rtc8564.c @@ -67,7 +67,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_addr, .probe = ignore, .ignore = ignore, - .force = ignore, }; static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem); diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 4a9ead27759..dda472e5e8b 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -61,7 +61,7 @@ static int i2c_bus_resume(struct device * dev) return rc; } -static struct bus_type i2c_bus_type = { +struct bus_type i2c_bus_type = { .name = "i2c", .match = i2c_device_match, .suspend = i2c_bus_suspend, @@ -78,13 +78,13 @@ static int i2c_device_remove(struct device *dev) return 0; } -static void i2c_adapter_dev_release(struct device *dev) +void i2c_adapter_dev_release(struct device *dev) { struct i2c_adapter *adap = dev_to_i2c_adapter(dev); complete(&adap->dev_released); } -static struct device_driver i2c_adapter_driver = { +struct device_driver i2c_adapter_driver = { .name = "i2c_adapter", .bus = &i2c_bus_type, .probe = i2c_device_probe, @@ -97,7 +97,7 @@ static void i2c_adapter_class_dev_release(struct class_device *dev) complete(&adap->class_dev_released); } -static struct class i2c_adapter_class = { +struct class i2c_adapter_class = { .name = "i2c-adapter", .release = &i2c_adapter_class_dev_release, }; @@ -188,6 +188,8 @@ int i2c_add_adapter(struct i2c_adapter *adap) strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE); class_device_register(&adap->class_dev); + dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); + /* inform drivers of new adapters */ list_for_each(item,&drivers) { driver = list_entry(item, struct i2c_driver, list); @@ -196,8 +198,6 @@ int i2c_add_adapter(struct i2c_adapter *adap) driver->attach_adapter(adap); } - dev_dbg(&adap->dev, "registered as adapter #%d\n", adap->nr); - out_unlock: up(&core_lists); return res; @@ -220,8 +220,8 @@ int i2c_del_adapter(struct i2c_adapter *adap) break; } if (adap_from_list != adap) { - pr_debug("I2C: Attempting to delete an unregistered " - "adapter\n"); + pr_debug("i2c-core: attempting to delete unregistered " + "adapter [%s]\n", adap->name); res = -EINVAL; goto out_unlock; } @@ -230,9 +230,8 @@ int i2c_del_adapter(struct i2c_adapter *adap) driver = list_entry(item, struct i2c_driver, list); if (driver->detach_adapter) if ((res = driver->detach_adapter(adap))) { - dev_warn(&adap->dev, "can't detach adapter " - "while detaching driver %s: driver " - "not detached!\n", driver->name); + dev_err(&adap->dev, "detach_adapter failed " + "for driver [%s]\n", driver->name); goto out_unlock; } } @@ -247,9 +246,8 @@ int i2c_del_adapter(struct i2c_adapter *adap) * must be deleted, as this would cause invalid states. */ if ((res=client->driver->detach_client(client))) { - dev_err(&adap->dev, "adapter not " - "unregistered, because client at " - "address %02x can't be detached. ", + dev_err(&adap->dev, "detach_client failed for client " + "[%s] at address 0x%02x\n", client->name, client->addr); goto out_unlock; } @@ -270,7 +268,7 @@ int i2c_del_adapter(struct i2c_adapter *adap) /* free dynamically allocated bus id */ idr_remove(&i2c_adapter_idr, adap->nr); - dev_dbg(&adap->dev, "adapter unregistered\n"); + dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); out_unlock: up(&core_lists); @@ -303,7 +301,7 @@ int i2c_add_driver(struct i2c_driver *driver) goto out_unlock; list_add_tail(&driver->list,&drivers); - pr_debug("i2c-core: driver %s registered.\n", driver->name); + pr_debug("i2c-core: driver [%s] registered\n", driver->name); /* now look for instances of driver on our adapters */ if (driver->flags & I2C_DF_NOTIFY) { @@ -331,21 +329,17 @@ int i2c_del_driver(struct i2c_driver *driver) /* Have a look at each adapter, if clients of this driver are still * attached. If so, detach them to be able to kill the driver * afterwards. - */ - pr_debug("i2c-core: unregister_driver - looking for clients.\n"); - /* removing clients does not depend on the notify flag, else + * + * Removing clients does not depend on the notify flag, else * invalid operation might (will!) result, when using stale client * pointers. */ list_for_each(item1,&adapters) { adap = list_entry(item1, struct i2c_adapter, list); - dev_dbg(&adap->dev, "examining adapter\n"); if (driver->detach_adapter) { if ((res = driver->detach_adapter(adap))) { - dev_warn(&adap->dev, "while unregistering " - "dummy driver %s, adapter could " - "not be detached properly; driver " - "not unloaded!",driver->name); + dev_err(&adap->dev, "detach_adapter failed " + "for driver [%s]\n", driver->name); goto out_unlock; } } else { @@ -353,16 +347,13 @@ int i2c_del_driver(struct i2c_driver *driver) client = list_entry(item2, struct i2c_client, list); if (client->driver != driver) continue; - pr_debug("i2c-core.o: detaching client %s:\n", client->name); + dev_dbg(&adap->dev, "detaching client [%s] " + "at 0x%02x\n", client->name, + client->addr); if ((res = driver->detach_client(client))) { - dev_err(&adap->dev, "while " - "unregistering driver " - "`%s', the client at " - "address %02x of " - "adapter could not " - "be detached; driver " - "not unloaded!", - driver->name, + dev_err(&adap->dev, "detach_client " + "failed for client [%s] at " + "0x%02x\n", client->name, client->addr); goto out_unlock; } @@ -372,7 +363,7 @@ int i2c_del_driver(struct i2c_driver *driver) driver_unregister(&driver->driver); list_del(&driver->list); - pr_debug("i2c-core: driver unregistered: %s\n", driver->name); + pr_debug("i2c-core: driver [%s] unregistered\n", driver->name); out_unlock: up(&core_lists); @@ -417,15 +408,12 @@ int i2c_attach_client(struct i2c_client *client) if (adapter->client_register) { if (adapter->client_register(client)) { - dev_warn(&adapter->dev, "warning: client_register " - "seems to have failed for client %02x\n", - client->addr); + dev_dbg(&adapter->dev, "client_register " + "failed for client [%s] at 0x%02x\n", + client->name, client->addr); } } - dev_dbg(&adapter->dev, "client [%s] registered to adapter\n", - client->name); - if (client->flags & I2C_CLIENT_ALLOW_USE) client->usage_count = 0; @@ -436,7 +424,8 @@ int i2c_attach_client(struct i2c_client *client) snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), "%d-%04x", i2c_adapter_id(adapter), client->addr); - pr_debug("registering %s\n", client->dev.bus_id); + dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", + client->name, client->dev.bus_id); device_register(&client->dev); device_create_file(&client->dev, &dev_attr_client_name); @@ -449,8 +438,12 @@ int i2c_detach_client(struct i2c_client *client) struct i2c_adapter *adapter = client->adapter; int res = 0; - if ((client->flags & I2C_CLIENT_ALLOW_USE) && (client->usage_count > 0)) + if ((client->flags & I2C_CLIENT_ALLOW_USE) + && (client->usage_count > 0)) { + dev_warn(&client->dev, "Client [%s] still busy, " + "can't detach\n", client->name); return -EBUSY; + } if (adapter->client_unregister) { res = adapter->client_unregister(client); @@ -669,98 +662,128 @@ int i2c_control(struct i2c_client *client, * Will not work for 10-bit addresses! * ---------------------------------------------------- */ +static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind, + int (*found_proc) (struct i2c_adapter *, int, int)) +{ + int err; + + /* Make sure the address is valid */ + if (addr < 0x03 || addr > 0x77) { + dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n", + addr); + return -EINVAL; + } + + /* Skip if already in use */ + if (i2c_check_addr(adapter, addr)) + return 0; + + /* Make sure there is something at this address, unless forced */ + if (kind < 0) { + if (i2c_smbus_xfer(adapter, addr, 0, 0, 0, + I2C_SMBUS_QUICK, NULL) < 0) + return 0; + + /* prevent 24RF08 corruption */ + if ((addr & ~0x0f) == 0x50) + i2c_smbus_xfer(adapter, addr, 0, 0, 0, + I2C_SMBUS_QUICK, NULL); + } + + /* Finally call the custom detection function */ + err = found_proc(adapter, addr, kind); + + /* -ENODEV can be returned if there is a chip at the given address + but it isn't supported by this chip driver. We catch it here as + this isn't an error. */ + return (err == -ENODEV) ? 0 : err; +} + int i2c_probe(struct i2c_adapter *adapter, struct i2c_client_address_data *address_data, int (*found_proc) (struct i2c_adapter *, int, int)) { - int addr,i,found,err; + int i, err; int adap_id = i2c_adapter_id(adapter); /* Forget it if we can't probe using SMBUS_QUICK */ if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK)) return -1; - for (addr = 0x00; addr <= 0x7f; addr++) { - - /* Skip if already in use */ - if (i2c_check_addr(adapter,addr)) - continue; - - /* If it is in one of the force entries, we don't do any detection - at all */ - found = 0; - - for (i = 0; !found && (address_data->force[i] != I2C_CLIENT_END); i += 2) { - if (((adap_id == address_data->force[i]) || - (address_data->force[i] == ANY_I2C_BUS)) && - (addr == address_data->force[i+1])) { - dev_dbg(&adapter->dev, "found force parameter for adapter %d, addr %04x\n", - adap_id, addr); - if ((err = found_proc(adapter,addr,0))) - return err; - found = 1; - } - } - if (found) - continue; - - /* If this address is in one of the ignores, we can forget about - it right now */ - for (i = 0; - !found && (address_data->ignore[i] != I2C_CLIENT_END); - i += 2) { - if (((adap_id == address_data->ignore[i]) || - ((address_data->ignore[i] == ANY_I2C_BUS))) && - (addr == address_data->ignore[i+1])) { - dev_dbg(&adapter->dev, "found ignore parameter for adapter %d, " - "addr %04x\n", adap_id ,addr); - found = 1; + /* Force entries are done first, and are not affected by ignore + entries */ + if (address_data->forces) { + unsigned short **forces = address_data->forces; + int kind; + + for (kind = 0; forces[kind]; kind++) { + for (i = 0; forces[kind][i] != I2C_CLIENT_END; + i += 2) { + if (forces[kind][i] == adap_id + || forces[kind][i] == ANY_I2C_BUS) { + dev_dbg(&adapter->dev, "found force " + "parameter for adapter %d, " + "addr 0x%02x, kind %d\n", + adap_id, forces[kind][i + 1], + kind); + err = i2c_probe_address(adapter, + forces[kind][i + 1], + kind, found_proc); + if (err) + return err; + } } } - if (found) - continue; + } - /* Now, we will do a detection, but only if it is in the normal or - probe entries */ - for (i = 0; - !found && (address_data->normal_i2c[i] != I2C_CLIENT_END); - i += 1) { - if (addr == address_data->normal_i2c[i]) { - found = 1; - dev_dbg(&adapter->dev, "found normal i2c entry for adapter %d, " - "addr %02x\n", adap_id, addr); - } + /* Probe entries are done second, and are not affected by ignore + entries either */ + for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) { + if (address_data->probe[i] == adap_id + || address_data->probe[i] == ANY_I2C_BUS) { + dev_dbg(&adapter->dev, "found probe parameter for " + "adapter %d, addr 0x%02x\n", adap_id, + address_data->probe[i + 1]); + err = i2c_probe_address(adapter, + address_data->probe[i + 1], + -1, found_proc); + if (err) + return err; } + } - for (i = 0; - !found && (address_data->probe[i] != I2C_CLIENT_END); - i += 2) { - if (((adap_id == address_data->probe[i]) || - ((address_data->probe[i] == ANY_I2C_BUS))) && - (addr == address_data->probe[i+1])) { - found = 1; - dev_dbg(&adapter->dev, "found probe parameter for adapter %d, " - "addr %04x\n", adap_id,addr); + /* Normal entries are done last, unless shadowed by an ignore entry */ + for (i = 0; address_data->normal_i2c[i] != I2C_CLIENT_END; i += 1) { + int j, ignore; + + ignore = 0; + for (j = 0; address_data->ignore[j] != I2C_CLIENT_END; + j += 2) { + if ((address_data->ignore[j] == adap_id || + address_data->ignore[j] == ANY_I2C_BUS) + && address_data->ignore[j + 1] + == address_data->normal_i2c[i]) { + dev_dbg(&adapter->dev, "found ignore " + "parameter for adapter %d, " + "addr 0x%02x\n", adap_id, + address_data->ignore[j + 1]); } + ignore = 1; + break; } - if (!found) + if (ignore) continue; - /* OK, so we really should examine this address. First check - whether there is some client here at all! */ - if (i2c_smbus_xfer(adapter,addr,0,0,0,I2C_SMBUS_QUICK,NULL) >= 0) - if ((err = found_proc(adapter,addr,-1))) - return err; + dev_dbg(&adapter->dev, "found normal entry for adapter %d, " + "addr 0x%02x\n", adap_id, + address_data->normal_i2c[i]); + err = i2c_probe_address(adapter, address_data->normal_i2c[i], + -1, found_proc); + if (err) + return err; } - return 0; -} -/* - * return id number for a specific adapter - */ -int i2c_adapter_id(struct i2c_adapter *adap) -{ - return adap->nr; + return 0; } struct i2c_adapter* i2c_get_adapter(int id) @@ -1171,6 +1194,12 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, } +/* Next four are needed by i2c-isa */ +EXPORT_SYMBOL_GPL(i2c_adapter_dev_release); +EXPORT_SYMBOL_GPL(i2c_adapter_driver); +EXPORT_SYMBOL_GPL(i2c_adapter_class); +EXPORT_SYMBOL_GPL(i2c_bus_type); + EXPORT_SYMBOL(i2c_add_adapter); EXPORT_SYMBOL(i2c_del_adapter); EXPORT_SYMBOL(i2c_add_driver); @@ -1186,7 +1215,6 @@ EXPORT_SYMBOL(i2c_master_send); EXPORT_SYMBOL(i2c_master_recv); EXPORT_SYMBOL(i2c_control); EXPORT_SYMBOL(i2c_transfer); -EXPORT_SYMBOL(i2c_adapter_id); EXPORT_SYMBOL(i2c_get_adapter); EXPORT_SYMBOL(i2c_put_adapter); EXPORT_SYMBOL(i2c_probe); diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index bc5d557e5dd..aa7a4fadef6 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -434,7 +434,8 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap) devfs_mk_cdev(MKDEV(I2C_MAJOR, i2c_dev->minor), S_IFCHR|S_IRUSR|S_IWUSR, "i2c/%d", i2c_dev->minor); - dev_dbg(&adap->dev, "Registered as minor %d\n", i2c_dev->minor); + pr_debug("i2c-dev: adapter [%s] registered as minor %d\n", + adap->name, i2c_dev->minor); /* register this i2c device with the driver core */ i2c_dev->adap = adap; @@ -471,7 +472,7 @@ static int i2cdev_detach_adapter(struct i2c_adapter *adap) wait_for_completion(&i2c_dev->released); kfree(i2c_dev); - dev_dbg(&adap->dev, "Adapter unregistered\n"); + pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name); return 0; } diff --git a/drivers/i2c/i2c-sensor-detect.c b/drivers/i2c/i2c-sensor-detect.c deleted file mode 100644 index f99a8161a9f..00000000000 --- a/drivers/i2c/i2c-sensor-detect.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - i2c-sensor-detect.c - Part of lm_sensors, Linux kernel modules for hardware - monitoring - Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl> and - Mark D. Studebaker <mdsxyz123@yahoo.com> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/i2c.h> -#include <linux/i2c-sensor.h> - -static unsigned short empty[] = {I2C_CLIENT_END}; -static unsigned int empty_isa[] = {I2C_CLIENT_ISA_END}; - -/* Very inefficient for ISA detects, and won't work for 10-bit addresses! */ -int i2c_detect(struct i2c_adapter *adapter, - struct i2c_address_data *address_data, - int (*found_proc) (struct i2c_adapter *, int, int)) -{ - int addr, i, found, j, err; - struct i2c_force_data *this_force; - int is_isa = i2c_is_isa_adapter(adapter); - int adapter_id = - is_isa ? ANY_I2C_ISA_BUS : i2c_adapter_id(adapter); - unsigned short *normal_i2c; - unsigned int *normal_isa; - unsigned short *probe; - unsigned short *ignore; - - /* Forget it if we can't probe using SMBUS_QUICK */ - if ((!is_isa) && - !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) - return -1; - - /* Use default "empty" list if the adapter doesn't specify any */ - normal_i2c = probe = ignore = empty; - normal_isa = empty_isa; - if (address_data->normal_i2c) - normal_i2c = address_data->normal_i2c; - if (address_data->normal_isa) - normal_isa = address_data->normal_isa; - if (address_data->probe) - probe = address_data->probe; - if (address_data->ignore) - ignore = address_data->ignore; - - for (addr = 0x00; addr <= (is_isa ? 0xffff : 0x7f); addr++) { - if (!is_isa && i2c_check_addr(adapter, addr)) - continue; - - /* If it is in one of the force entries, we don't do any - detection at all */ - found = 0; - for (i = 0; !found && (this_force = address_data->forces + i, this_force->force); i++) { - for (j = 0; !found && (this_force->force[j] != I2C_CLIENT_END); j += 2) { - if ( ((adapter_id == this_force->force[j]) || - ((this_force->force[j] == ANY_I2C_BUS) && !is_isa)) && - (addr == this_force->force[j + 1]) ) { - dev_dbg(&adapter->dev, "found force parameter for adapter %d, addr %04x\n", adapter_id, addr); - if ((err = found_proc(adapter, addr, this_force->kind))) - return err; - found = 1; - } - } - } - if (found) - continue; - - /* If this address is in one of the ignores, we can forget about it - right now */ - for (i = 0; !found && (ignore[i] != I2C_CLIENT_END); i += 2) { - if ( ((adapter_id == ignore[i]) || - ((ignore[i] == ANY_I2C_BUS) && - !is_isa)) && - (addr == ignore[i + 1])) { - dev_dbg(&adapter->dev, "found ignore parameter for adapter %d, addr %04x\n", adapter_id, addr); - found = 1; - } - } - if (found) - continue; - - /* Now, we will do a detection, but only if it is in the normal or - probe entries */ - if (is_isa) { - for (i = 0; !found && (normal_isa[i] != I2C_CLIENT_ISA_END); i += 1) { - if (addr == normal_isa[i]) { - dev_dbg(&adapter->dev, "found normal isa entry for adapter %d, addr %04x\n", adapter_id, addr); - found = 1; - } - } - } else { - for (i = 0; !found && (normal_i2c[i] != I2C_CLIENT_END); i += 1) { - if (addr == normal_i2c[i]) { - found = 1; - dev_dbg(&adapter->dev, "found normal i2c entry for adapter %d, addr %02x\n", adapter_id, addr); - } - } - } - - for (i = 0; - !found && (probe[i] != I2C_CLIENT_END); - i += 2) { - if (((adapter_id == probe[i]) || - ((probe[i] == ANY_I2C_BUS) && !is_isa)) - && (addr == probe[i + 1])) { - dev_dbg(&adapter->dev, "found probe parameter for adapter %d, addr %04x\n", adapter_id, addr); - found = 1; - } - } - if (!found) - continue; - - /* OK, so we really should examine this address. First check - whether there is some client here at all! */ - if (is_isa || - (i2c_smbus_xfer (adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) >= 0)) - if ((err = found_proc(adapter, addr, -1))) - return err; - } - return 0; -} - -EXPORT_SYMBOL(i2c_detect); - -MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " - "Rudolf Marek <r.marek@sh.cvut.cz>"); - -MODULE_DESCRIPTION("i2c-sensor driver"); -MODULE_LICENSE("GPL"); diff --git a/drivers/i2c/i2c-sensor-vid.c b/drivers/i2c/i2c-sensor-vid.c deleted file mode 100644 index 922e22f054b..00000000000 --- a/drivers/i2c/i2c-sensor-vid.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - i2c-sensor-vid.c - Part of lm_sensors, Linux kernel modules for hardware - monitoring - - Copyright (c) 2004 Rudolf Marek <r.marek@sh.cvut.cz> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include <linux/config.h> -#include <linux/module.h> -#include <linux/kernel.h> - -struct vrm_model { - u8 vendor; - u8 eff_family; - u8 eff_model; - int vrm_type; -}; - -#define ANY 0xFF - -#ifdef CONFIG_X86 - -static struct vrm_model vrm_models[] = { - {X86_VENDOR_AMD, 0x6, ANY, 90}, /* Athlon Duron etc */ - {X86_VENDOR_AMD, 0xF, ANY, 24}, /* Athlon 64, Opteron */ - {X86_VENDOR_INTEL, 0x6, 0x9, 85}, /* 0.13um too */ - {X86_VENDOR_INTEL, 0x6, 0xB, 85}, /* 0xB Tualatin */ - {X86_VENDOR_INTEL, 0x6, ANY, 82}, /* any P6 */ - {X86_VENDOR_INTEL, 0x7, ANY, 0}, /* Itanium */ - {X86_VENDOR_INTEL, 0xF, 0x3, 100}, /* P4 Prescott */ - {X86_VENDOR_INTEL, 0xF, ANY, 90}, /* P4 before Prescott */ - {X86_VENDOR_INTEL, 0x10,ANY, 0}, /* Itanium 2 */ - {X86_VENDOR_UNKNOWN, ANY, ANY, 0} /* stop here */ - }; - -static int find_vrm(u8 eff_family, u8 eff_model, u8 vendor) -{ - int i = 0; - - while (vrm_models[i].vendor!=X86_VENDOR_UNKNOWN) { - if (vrm_models[i].vendor==vendor) - if ((vrm_models[i].eff_family==eff_family)&& \ - ((vrm_models[i].eff_model==eff_model)|| \ - (vrm_models[i].eff_model==ANY))) - return vrm_models[i].vrm_type; - i++; - } - - return 0; -} - -int i2c_which_vrm(void) -{ - struct cpuinfo_x86 *c = cpu_data; - u32 eax; - u8 eff_family, eff_model; - int vrm_ret; - - if (c->x86 < 6) return 0; /* any CPU with familly lower than 6 - dont have VID and/or CPUID */ - eax = cpuid_eax(1); - eff_family = ((eax & 0x00000F00)>>8); - eff_model = ((eax & 0x000000F0)>>4); - if (eff_family == 0xF) { /* use extended model & family */ - eff_family += ((eax & 0x00F00000)>>20); - eff_model += ((eax & 0x000F0000)>>16)<<4; - } - vrm_ret = find_vrm(eff_family,eff_model,c->x86_vendor); - if (vrm_ret == 0) - printk(KERN_INFO "i2c-sensor.o: Unknown VRM version of your" - " x86 CPU\n"); - return vrm_ret; -} - -/* and now for something completely different for Non-x86 world*/ -#else -int i2c_which_vrm(void) -{ - printk(KERN_INFO "i2c-sensor.o: Unknown VRM version of your CPU\n"); - return 0; -} -#endif - -EXPORT_SYMBOL(i2c_which_vrm); diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c index 248e3cc8b35..f174aee659e 100644 --- a/drivers/ide/ide-io.c +++ b/drivers/ide/ide-io.c @@ -150,7 +150,7 @@ static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 s switch (rq->pm->pm_step) { case ide_pm_flush_cache: /* Suspend step 1 (flush cache) complete */ - if (rq->pm->pm_state == 4) + if (rq->pm->pm_state == PM_EVENT_FREEZE) rq->pm->pm_step = ide_pm_state_completed; else rq->pm->pm_step = idedisk_pm_standby; diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c index dae1bd5b8c3..73ca8f73917 100644 --- a/drivers/ide/ide.c +++ b/drivers/ide/ide.c @@ -1229,7 +1229,7 @@ static int generic_ide_suspend(struct device *dev, pm_message_t state) rq.special = &args; rq.pm = &rqpm; rqpm.pm_step = ide_pm_state_start_suspend; - rqpm.pm_state = state; + rqpm.pm_state = state.event; return ide_do_drive_cmd(drive, &rq, ide_wait); } @@ -1248,7 +1248,7 @@ static int generic_ide_resume(struct device *dev) rq.special = &args; rq.pm = &rqpm; rqpm.pm_step = ide_pm_state_start_resume; - rqpm.pm_state = 0; + rqpm.pm_state = PM_EVENT_ON; return ide_do_drive_cmd(drive, &rq, ide_head_wait); } diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c index 10592cec6c4..24e21b2838c 100644 --- a/drivers/ide/pci/sc1200.c +++ b/drivers/ide/pci/sc1200.c @@ -350,9 +350,9 @@ static int sc1200_suspend (struct pci_dev *dev, pm_message_t state) { ide_hwif_t *hwif = NULL; - printk("SC1200: suspend(%u)\n", state); + printk("SC1200: suspend(%u)\n", state.event); - if (state == 0) { + if (state.event == PM_EVENT_ON) { // we only save state when going from full power to less // @@ -386,8 +386,8 @@ static int sc1200_suspend (struct pci_dev *dev, pm_message_t state) /* You don't need to iterate over disks -- sysfs should have done that for you already */ pci_disable_device(dev); - pci_set_power_state(dev,state); - dev->current_state = state; + pci_set_power_state(dev, pci_choose_state(dev, state)); + dev->current_state = state.event; return 0; } @@ -396,8 +396,8 @@ static int sc1200_resume (struct pci_dev *dev) ide_hwif_t *hwif = NULL; printk("SC1200: resume\n"); - pci_set_power_state(dev,0); // bring chip back from sleep state - dev->current_state = 0; + pci_set_power_state(dev, PCI_D0); // bring chip back from sleep state + dev->current_state = PM_EVENT_ON; pci_enable_device(dev); // // loop over all interfaces that are part of this pci device: diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c index ea65b070a36..87d1f8a1f41 100644 --- a/drivers/ide/ppc/pmac.c +++ b/drivers/ide/ppc/pmac.c @@ -1504,12 +1504,12 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match) } static int -pmac_ide_macio_suspend(struct macio_dev *mdev, u32 state) +pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t state) { ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev); int rc = 0; - if (state != mdev->ofdev.dev.power.power_state && state >= 2) { + if (state.event != mdev->ofdev.dev.power.power_state.event && state.event >= PM_EVENT_SUSPEND) { rc = pmac_ide_do_suspend(hwif); if (rc == 0) mdev->ofdev.dev.power.power_state = state; @@ -1524,10 +1524,10 @@ pmac_ide_macio_resume(struct macio_dev *mdev) ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev); int rc = 0; - if (mdev->ofdev.dev.power.power_state != 0) { + if (mdev->ofdev.dev.power.power_state.event != PM_EVENT_ON) { rc = pmac_ide_do_resume(hwif); if (rc == 0) - mdev->ofdev.dev.power.power_state = 0; + mdev->ofdev.dev.power.power_state = PMSG_ON; } return rc; @@ -1608,12 +1608,12 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id) } static int -pmac_ide_pci_suspend(struct pci_dev *pdev, u32 state) +pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t state) { ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev); int rc = 0; - if (state != pdev->dev.power.power_state && state >= 2) { + if (state.event != pdev->dev.power.power_state.event && state.event >= 2) { rc = pmac_ide_do_suspend(hwif); if (rc == 0) pdev->dev.power.power_state = state; @@ -1628,10 +1628,10 @@ pmac_ide_pci_resume(struct pci_dev *pdev) ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev); int rc = 0; - if (pdev->dev.power.power_state != 0) { + if (pdev->dev.power.power_state.event != PM_EVENT_ON) { rc = pmac_ide_do_resume(hwif); if (rc == 0) - pdev->dev.power.power_state = 0; + pdev->dev.power.power_state = PMSG_ON; } return rc; diff --git a/drivers/ieee1394/pcilynx.c b/drivers/ieee1394/pcilynx.c index 36074e6eeeb..6b1ab875333 100644 --- a/drivers/ieee1394/pcilynx.c +++ b/drivers/ieee1394/pcilynx.c @@ -1464,26 +1464,6 @@ static int __devinit add_card(struct pci_dev *dev, { 0x50, I2C_M_RD, 20, (unsigned char*) lynx->bus_info_block } }; - -#ifdef CONFIG_IEEE1394_VERBOSEDEBUG - union i2c_smbus_data data; - - if (i2c_smbus_xfer(i2c_ad, 80, 0, I2C_SMBUS_WRITE, 0, I2C_SMBUS_BYTE,NULL)) - PRINT(KERN_ERR, lynx->id,"eeprom read start has failed"); - else - { - u16 addr; - for (addr=0x00; addr < 0x100; addr++) { - if (i2c_smbus_xfer(i2c_ad, 80, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE,& data)) { - PRINT(KERN_ERR, lynx->id, "unable to read i2c %x", addr); - break; - } - else - PRINT(KERN_DEBUG, lynx->id,"got serial eeprom data at %x: %x",addr, data.byte); - } - } -#endif - /* we use i2c_transfer, because i2c_smbus_read_block_data does not work properly and we do it more efficiently in one transaction rather then using several reads */ if (i2c_transfer(i2c_ad, msg, 2) < 0) { diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index 20e3a165989..f8b278d3559 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -160,6 +160,8 @@ struct input_event_compat { # define COMPAT_TEST IS_IA32_PROCESS(ia64_task_regs(current)) #elif defined(CONFIG_ARCH_S390) # define COMPAT_TEST test_thread_flag(TIF_31BIT) +#elif defined(CONFIG_MIPS) +# define COMPAT_TEST (current->thread.mflags & MF_32BIT_ADDR) #else # define COMPAT_TEST test_thread_flag(TIF_32BIT) #endif diff --git a/drivers/macintosh/mediabay.c b/drivers/macintosh/mediabay.c index 7c16c25fc5d..c0712a1ea5a 100644 --- a/drivers/macintosh/mediabay.c +++ b/drivers/macintosh/mediabay.c @@ -708,7 +708,7 @@ static int __pmac media_bay_suspend(struct macio_dev *mdev, pm_message_t state) { struct media_bay_info *bay = macio_get_drvdata(mdev); - if (state != mdev->ofdev.dev.power.power_state && state == PM_SUSPEND_MEM) { + if (state.event != mdev->ofdev.dev.power.power_state.event && state.event == PM_EVENT_SUSPEND) { down(&bay->lock); bay->sleeping = 1; set_mb_power(bay, 0); @@ -723,8 +723,8 @@ static int __pmac media_bay_resume(struct macio_dev *mdev) { struct media_bay_info *bay = macio_get_drvdata(mdev); - if (mdev->ofdev.dev.power.power_state != 0) { - mdev->ofdev.dev.power.power_state = 0; + if (mdev->ofdev.dev.power.power_state.event != PM_EVENT_ON) { + mdev->ofdev.dev.power.power_state = PMSG_ON; /* We re-enable the bay using it's previous content only if it did not change. Note those bozo timings, diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c index 4a0a0ad2d03..645a2e5c70a 100644 --- a/drivers/macintosh/via-pmu.c +++ b/drivers/macintosh/via-pmu.c @@ -3065,7 +3065,7 @@ static int pmu_sys_suspended = 0; static int pmu_sys_suspend(struct sys_device *sysdev, pm_message_t state) { - if (state != PM_SUSPEND_DISK || pmu_sys_suspended) + if (state.event != PM_EVENT_SUSPEND || pmu_sys_suspended) return 0; /* Suspend PMU event interrupts */ diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index d0a4bab220e..b82bc315047 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -144,7 +144,7 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti, } /* Hash the cipher key with the given hash algorithm */ - hash_tfm = crypto_alloc_tfm(opts, 0); + hash_tfm = crypto_alloc_tfm(opts, CRYPTO_TFM_REQ_MAY_SLEEP); if (hash_tfm == NULL) { ti->error = PFX "Error initializing ESSIV hash"; return -EINVAL; @@ -172,7 +172,8 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti, /* Setup the essiv_tfm with the given salt */ essiv_tfm = crypto_alloc_tfm(crypto_tfm_alg_name(cc->tfm), - CRYPTO_TFM_MODE_ECB); + CRYPTO_TFM_MODE_ECB | + CRYPTO_TFM_REQ_MAY_SLEEP); if (essiv_tfm == NULL) { ti->error = PFX "Error allocating crypto tfm for ESSIV"; kfree(salt); @@ -587,7 +588,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) goto bad1; } - tfm = crypto_alloc_tfm(cipher, crypto_flags); + tfm = crypto_alloc_tfm(cipher, crypto_flags | CRYPTO_TFM_REQ_MAY_SLEEP); if (!tfm) { ti->error = PFX "Error allocating crypto tfm"; goto bad1; diff --git a/drivers/media/common/saa7146_i2c.c b/drivers/media/common/saa7146_i2c.c index 781f23f0cbc..6284894505c 100644 --- a/drivers/media/common/saa7146_i2c.c +++ b/drivers/media/common/saa7146_i2c.c @@ -387,8 +387,6 @@ static int saa7146_i2c_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, in /* exported algorithm data */ static struct i2c_algorithm saa7146_algo = { - .name = "saa7146 i2c algorithm", - .id = I2C_ALGO_SAA7146, .master_xfer = saa7146_i2c_xfer, .functionality = saa7146_i2c_func, }; @@ -412,7 +410,7 @@ int saa7146_i2c_adapter_prepare(struct saa7146_dev *dev, struct i2c_adapter *i2c #endif i2c_adapter->algo = &saa7146_algo; i2c_adapter->algo_data = NULL; - i2c_adapter->id = I2C_ALGO_SAA7146; + i2c_adapter->id = I2C_HW_SAA7146; i2c_adapter->timeout = SAA7146_I2C_TIMEOUT; i2c_adapter->retries = SAA7146_I2C_RETRIES; } diff --git a/drivers/media/dvb/b2c2/flexcop-i2c.c b/drivers/media/dvb/b2c2/flexcop-i2c.c index be4266d4ae9..56495cb6cd0 100644 --- a/drivers/media/dvb/b2c2/flexcop-i2c.c +++ b/drivers/media/dvb/b2c2/flexcop-i2c.c @@ -172,8 +172,6 @@ static u32 flexcop_i2c_func(struct i2c_adapter *adapter) } static struct i2c_algorithm flexcop_algo = { - .name = "FlexCop I2C algorithm", - .id = I2C_ALGO_BIT, .master_xfer = flexcop_master_xfer, .functionality = flexcop_i2c_func, }; @@ -192,7 +190,6 @@ int flexcop_i2c_init(struct flexcop_device *fc) fc->i2c_adap.class = I2C_CLASS_TV_DIGITAL; fc->i2c_adap.algo = &flexcop_algo; fc->i2c_adap.algo_data = NULL; - fc->i2c_adap.id = I2C_ALGO_BIT; if ((ret = i2c_add_adapter(&fc->i2c_adap)) < 0) return ret; diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c index 7d8b3cad350..9ea5747b121 100644 --- a/drivers/media/dvb/cinergyT2/cinergyT2.c +++ b/drivers/media/dvb/cinergyT2/cinergyT2.c @@ -888,7 +888,7 @@ static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state) if (down_interruptible(&cinergyt2->sem)) return -ERESTARTSYS; - if (state > 0) { /* state 0 seems to mean DEVICE_PM_ON */ + if (state.event > PM_EVENT_ON) { struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf); #ifdef ENABLE_RC cancel_delayed_work(&cinergyt2->rc_query_work); diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c index c3e1b661aae..9e96a188f1e 100644 --- a/drivers/media/dvb/dvb-usb/cxusb.c +++ b/drivers/media/dvb/dvb-usb/cxusb.c @@ -141,8 +141,6 @@ static u32 cxusb_i2c_func(struct i2c_adapter *adapter) } static struct i2c_algorithm cxusb_i2c_algo = { - .name = "Conexant USB I2C algorithm", - .id = I2C_ALGO_BIT, .master_xfer = cxusb_i2c_xfer, .functionality = cxusb_i2c_func, }; diff --git a/drivers/media/dvb/dvb-usb/dibusb-common.c b/drivers/media/dvb/dvb-usb/dibusb-common.c index 9b9d6f8ee74..00b946419b4 100644 --- a/drivers/media/dvb/dvb-usb/dibusb-common.c +++ b/drivers/media/dvb/dvb-usb/dibusb-common.c @@ -156,8 +156,6 @@ static u32 dibusb_i2c_func(struct i2c_adapter *adapter) } struct i2c_algorithm dibusb_i2c_algo = { - .name = "DiBcom USB I2C algorithm", - .id = I2C_ALGO_BIT, .master_xfer = dibusb_i2c_xfer, .functionality = dibusb_i2c_func, }; diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c index 9a676afc1d6..f70e0be0920 100644 --- a/drivers/media/dvb/dvb-usb/digitv.c +++ b/drivers/media/dvb/dvb-usb/digitv.c @@ -77,8 +77,6 @@ static u32 digitv_i2c_func(struct i2c_adapter *adapter) } static struct i2c_algorithm digitv_i2c_algo = { - .name = "Nebula DigiTV USB I2C algorithm", - .id = I2C_ALGO_BIT, .master_xfer = digitv_i2c_xfer, .functionality = digitv_i2c_func, }; diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c b/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c index 9f0a8d90d14..da970947dfc 100644 --- a/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c +++ b/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c @@ -27,7 +27,6 @@ int dvb_usb_i2c_init(struct dvb_usb_device *d) #endif d->i2c_adap.algo = d->props.i2c_algo; d->i2c_adap.algo_data = NULL; - d->i2c_adap.id = I2C_ALGO_BIT; i2c_set_adapdata(&d->i2c_adap, d); diff --git a/drivers/media/dvb/pluto2/pluto2.c b/drivers/media/dvb/pluto2/pluto2.c index 706e0bcb5ed..85b437bbddc 100644 --- a/drivers/media/dvb/pluto2/pluto2.c +++ b/drivers/media/dvb/pluto2/pluto2.c @@ -633,7 +633,6 @@ static int __devinit pluto2_probe(struct pci_dev *pdev, i2c_set_adapdata(&pluto->i2c_adap, pluto); strcpy(pluto->i2c_adap.name, DRIVER_NAME); pluto->i2c_adap.owner = THIS_MODULE; - pluto->i2c_adap.id = I2C_ALGO_BIT; pluto->i2c_adap.class = I2C_CLASS_TV_DIGITAL; pluto->i2c_adap.dev.parent = &pdev->dev; pluto->i2c_adap.algo_data = &pluto->i2c_bit; diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c index aa43b5fcb8e..7daf7b1598a 100644 --- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c +++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c @@ -1472,8 +1472,6 @@ static void frontend_init(struct ttusb* ttusb) static struct i2c_algorithm ttusb_dec_algo = { - .name = "ttusb dec i2c algorithm", - .id = I2C_ALGO_BIT, .master_xfer = master_xfer, .functionality = functionality, }; @@ -1525,7 +1523,6 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i #endif ttusb->i2c_adap.algo = &ttusb_dec_algo; ttusb->i2c_adap.algo_data = NULL; - ttusb->i2c_adap.id = I2C_ALGO_BIT; result = i2c_add_adapter(&ttusb->i2c_adap); if (result) { diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index 3f574239609..16c85c081e6 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig @@ -254,6 +254,7 @@ config VIDEO_SAA7134_DVB select VIDEO_BUF_DVB select DVB_MT352 select DVB_CX22702 + select DVB_TDA1004X ---help--- This adds support for DVB cards based on the Philips saa7134 chip. diff --git a/drivers/media/video/adv7170.c b/drivers/media/video/adv7170.c index 48989eda240..52e32f05d62 100644 --- a/drivers/media/video/adv7170.c +++ b/drivers/media/video/adv7170.c @@ -391,7 +391,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_i2c, .probe = &ignore, .ignore = &ignore, - .force = &ignore, }; static struct i2c_driver i2c_driver_adv7170; diff --git a/drivers/media/video/adv7175.c b/drivers/media/video/adv7175.c index f898b658637..b5ed9544bde 100644 --- a/drivers/media/video/adv7175.c +++ b/drivers/media/video/adv7175.c @@ -441,7 +441,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_i2c, .probe = &ignore, .ignore = &ignore, - .force = &ignore, }; static struct i2c_driver i2c_driver_adv7175; diff --git a/drivers/media/video/bt819.c b/drivers/media/video/bt819.c index 8733588f6db..c6cfa7c48b0 100644 --- a/drivers/media/video/bt819.c +++ b/drivers/media/video/bt819.c @@ -507,7 +507,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_i2c, .probe = &ignore, .ignore = &ignore, - .force = &ignore, }; static struct i2c_driver i2c_driver_bt819; diff --git a/drivers/media/video/bt832.c b/drivers/media/video/bt832.c index a070417e65e..76c1b63ebdf 100644 --- a/drivers/media/video/bt832.c +++ b/drivers/media/video/bt832.c @@ -188,7 +188,7 @@ static int bt832_probe(struct i2c_adapter *adap) if (adap->class & I2C_CLASS_TV_ANALOG) return i2c_probe(adap, &addr_data, bt832_attach); #else - if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848)) + if (adap->id == I2C_HW_B_BT848) return i2c_probe(adap, &addr_data, bt832_attach); #endif return 0; @@ -241,7 +241,7 @@ static struct i2c_driver driver = { }; static struct i2c_client client_template = { - I2C_DEVNAME("bt832"), + .name = "bt832", .flags = I2C_CLIENT_ALLOW_USE, .driver = &driver, }; diff --git a/drivers/media/video/bt856.c b/drivers/media/video/bt856.c index a5d529ccf3a..c13d2865886 100644 --- a/drivers/media/video/bt856.c +++ b/drivers/media/video/bt856.c @@ -295,7 +295,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_i2c, .probe = &ignore, .ignore = &ignore, - .force = &ignore, }; static struct i2c_driver i2c_driver_bt856; diff --git a/drivers/media/video/bttv-driver.c b/drivers/media/video/bttv-driver.c index eee9322ce21..087efb4dea0 100644 --- a/drivers/media/video/bttv-driver.c +++ b/drivers/media/video/bttv-driver.c @@ -4047,7 +4047,6 @@ static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state) struct bttv_buffer_set idle; unsigned long flags; - dprintk("bttv%d: suspend %d\n", btv->c.nr, state); /* stop dma + irqs */ spin_lock_irqsave(&btv->s_lock,flags); diff --git a/drivers/media/video/bttv-i2c.c b/drivers/media/video/bttv-i2c.c index 234a8556376..706dc48df96 100644 --- a/drivers/media/video/bttv-i2c.c +++ b/drivers/media/video/bttv-i2c.c @@ -109,7 +109,7 @@ static struct i2c_adapter bttv_i2c_adap_sw_template = { #ifdef I2C_CLASS_TV_ANALOG .class = I2C_CLASS_TV_ANALOG, #endif - I2C_DEVNAME("bt848"), + .name = "bt848", .id = I2C_HW_B_BT848, .client_register = attach_inform, }; @@ -270,8 +270,6 @@ static int bttv_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int } static struct i2c_algorithm bttv_algo = { - .name = "bt878", - .id = I2C_ALGO_BIT | I2C_HW_B_BT848 /* FIXME */, .master_xfer = bttv_i2c_xfer, .algo_control = algo_control, .functionality = functionality, @@ -282,8 +280,8 @@ static struct i2c_adapter bttv_i2c_adap_hw_template = { #ifdef I2C_CLASS_TV_ANALOG .class = I2C_CLASS_TV_ANALOG, #endif - I2C_DEVNAME("bt878"), - .id = I2C_ALGO_BIT | I2C_HW_B_BT848 /* FIXME */, + .name = "bt878", + .id = I2C_HW_B_BT848 /* FIXME */, .algo = &bttv_algo, .client_register = attach_inform, }; @@ -298,7 +296,7 @@ static int attach_inform(struct i2c_client *client) if (bttv_debug) printk(KERN_DEBUG "bttv%d: %s i2c attach [addr=0x%x,client=%s]\n", btv->c.nr,client->driver->name,client->addr, - i2c_clientname(client)); + client->name); if (!client->driver->command) return 0; @@ -326,7 +324,7 @@ void bttv_call_i2c_clients(struct bttv *btv, unsigned int cmd, void *arg) } static struct i2c_client bttv_i2c_client_template = { - I2C_DEVNAME("bttv internal"), + .name = "bttv internal", }; diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c index a628a55299c..7f598039e02 100644 --- a/drivers/media/video/cx88/cx88-i2c.c +++ b/drivers/media/video/cx88/cx88-i2c.c @@ -95,7 +95,7 @@ static int attach_inform(struct i2c_client *client) struct cx88_core *core = i2c_get_adapdata(client->adapter); dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n", - client->driver->name,client->addr,i2c_clientname(client)); + client->driver->name, client->addr, client->name); if (!client->driver->command) return 0; @@ -128,7 +128,7 @@ static int detach_inform(struct i2c_client *client) { struct cx88_core *core = i2c_get_adapdata(client->adapter); - dprintk(1, "i2c detach [client=%s]\n", i2c_clientname(client)); + dprintk(1, "i2c detach [client=%s]\n", client->name); return 0; } @@ -152,7 +152,7 @@ static struct i2c_algo_bit_data cx8800_i2c_algo_template = { /* ----------------------------------------------------------------------- */ static struct i2c_adapter cx8800_i2c_adap_template = { - I2C_DEVNAME("cx2388x"), + .name = "cx2388x", .owner = THIS_MODULE, .id = I2C_HW_B_CX2388x, .client_register = attach_inform, @@ -160,7 +160,7 @@ static struct i2c_adapter cx8800_i2c_adap_template = { }; static struct i2c_client cx8800_i2c_client_template = { - I2C_DEVNAME("cx88xx internal"), + .name = "cx88xx internal", }; static char *i2c_devs[128] = { diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c index 9fc5055e001..1e273ff3f95 100644 --- a/drivers/media/video/ir-kbd-i2c.c +++ b/drivers/media/video/ir-kbd-i2c.c @@ -308,7 +308,7 @@ static struct i2c_driver driver = { static struct i2c_client client_template = { - I2C_DEVNAME("unset"), + .name = "unset", .driver = &driver }; @@ -429,10 +429,10 @@ static int ir_probe(struct i2c_adapter *adap) struct i2c_client c; char buf; int i,rc; switch (adap->id) { - case I2C_ALGO_BIT | I2C_HW_B_BT848: + case I2C_HW_B_BT848: probe = probe_bttv; break; - case I2C_ALGO_SAA7134: + case I2C_HW_SAA7134: probe = probe_saa7134; break; } diff --git a/drivers/media/video/msp3400.c b/drivers/media/video/msp3400.c index 62f1b8ddb98..ca02f6f14b0 100644 --- a/drivers/media/video/msp3400.c +++ b/drivers/media/video/msp3400.c @@ -1416,7 +1416,7 @@ static int msp_detach(struct i2c_client *client); static int msp_probe(struct i2c_adapter *adap); static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg); -static int msp_suspend(struct device * dev, u32 state, u32 level); +static int msp_suspend(struct device * dev, pm_message_t state, u32 level); static int msp_resume(struct device * dev, u32 level); static void msp_wake_thread(struct i2c_client *client); @@ -1437,7 +1437,7 @@ static struct i2c_driver driver = { static struct i2c_client client_template = { - I2C_DEVNAME("(unset)"), + .name = "(unset)", .flags = I2C_CLIENT_ALLOW_USE, .driver = &driver, }; @@ -1509,7 +1509,7 @@ static int msp_attach(struct i2c_adapter *adap, int addr, int kind) } /* hello world :-) */ - printk(KERN_INFO "msp34xx: init: chip=%s",i2c_clientname(c)); + printk(KERN_INFO "msp34xx: init: chip=%s", c->name); if (HAVE_NICAM(msp)) printk(" +nicam"); if (HAVE_SIMPLE(msp)) @@ -1817,7 +1817,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) return 0; } -static int msp_suspend(struct device * dev, u32 state, u32 level) +static int msp_suspend(struct device * dev, pm_message_t state, u32 level) { struct i2c_client *c = container_of(dev, struct i2c_client, dev); diff --git a/drivers/media/video/ovcamchip/ov6x20.c b/drivers/media/video/ovcamchip/ov6x20.c index 3433619ad93..b3f4d266ced 100644 --- a/drivers/media/video/ovcamchip/ov6x20.c +++ b/drivers/media/video/ovcamchip/ov6x20.c @@ -164,10 +164,10 @@ static int ov6x20_init(struct i2c_client *c) DDEBUG(4, &c->dev, "entered"); switch (c->adapter->id) { - case I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV511: + case I2C_HW_SMBUS_OV511: rc = ov_write_regvals(c, regvals_init_6x20_511); break; - case I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV518: + case I2C_HW_SMBUS_OV518: rc = ov_write_regvals(c, regvals_init_6x20_518); break; default: @@ -338,7 +338,7 @@ static int ov6x20_mode_init(struct i2c_client *c, struct ovcamchip_window *win) /******** Palette-specific regs ********/ /* OV518 needs 8 bit multiplexed in color mode, and 16 bit in B&W */ - if (c->adapter->id == (I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV518)) { + if (c->adapter->id == I2C_HW_SMBUS_OV518) { if (win->format == VIDEO_PALETTE_GREY) ov_write_mask(c, 0x13, 0x00, 0x20); else diff --git a/drivers/media/video/ovcamchip/ov6x30.c b/drivers/media/video/ovcamchip/ov6x30.c index 44a842379b4..6eab458ab79 100644 --- a/drivers/media/video/ovcamchip/ov6x30.c +++ b/drivers/media/video/ovcamchip/ov6x30.c @@ -301,7 +301,7 @@ static int ov6x30_mode_init(struct i2c_client *c, struct ovcamchip_window *win) /******** Palette-specific regs ********/ if (win->format == VIDEO_PALETTE_GREY) { - if (c->adapter->id == (I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV518)) { + if (c->adapter->id == I2C_HW_SMBUS_OV518) { /* Do nothing - we're already in 8-bit mode */ } else { ov_write_mask(c, 0x13, 0x20, 0x20); @@ -313,7 +313,7 @@ static int ov6x30_mode_init(struct i2c_client *c, struct ovcamchip_window *win) * Therefore, the OV6630 needs to be in 8-bit multiplexed * output mode */ - if (c->adapter->id == (I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV518)) { + if (c->adapter->id == I2C_HW_SMBUS_OV518) { /* Do nothing - we want to stay in 8-bit mode */ /* Warning: Messing with reg 0x13 breaks OV518 color */ } else { diff --git a/drivers/media/video/ovcamchip/ovcamchip_core.c b/drivers/media/video/ovcamchip/ovcamchip_core.c index 54dd5612d3b..2de34ebf067 100644 --- a/drivers/media/video/ovcamchip/ovcamchip_core.c +++ b/drivers/media/video/ovcamchip/ovcamchip_core.c @@ -296,10 +296,10 @@ static int ovcamchip_attach(struct i2c_adapter *adap) * attach to adapters that are known to contain OV camera chips. */ switch (adap->id) { - case (I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV511): - case (I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV518): - case (I2C_ALGO_SMBUS | I2C_HW_SMBUS_OVFX2): - case (I2C_ALGO_SMBUS | I2C_HW_SMBUS_W9968CF): + case I2C_HW_SMBUS_OV511: + case I2C_HW_SMBUS_OV518: + case I2C_HW_SMBUS_OVFX2: + case I2C_HW_SMBUS_W9968CF: PDEBUG(1, "Adapter ID 0x%06x accepted", adap->id); break; default: @@ -314,7 +314,7 @@ static int ovcamchip_attach(struct i2c_adapter *adap) } memcpy(c, &client_template, sizeof *c); c->adapter = adap; - strcpy(i2c_clientname(c), "OV????"); + strcpy(c->name, "OV????"); ov = kmalloc(sizeof *ov, GFP_KERNEL); if (!ov) { @@ -328,7 +328,7 @@ static int ovcamchip_attach(struct i2c_adapter *adap) if (rc < 0) goto error; - strcpy(i2c_clientname(c), chip_names[ov->subtype]); + strcpy(c->name, chip_names[ov->subtype]); PDEBUG(1, "Camera chip detection complete"); @@ -421,7 +421,7 @@ static struct i2c_driver driver = { }; static struct i2c_client client_template = { - I2C_DEVNAME("(unset)"), + .name = "(unset)", .driver = &driver, }; diff --git a/drivers/media/video/saa7110.c b/drivers/media/video/saa7110.c index 22d055d8a69..e116bdbed31 100644 --- a/drivers/media/video/saa7110.c +++ b/drivers/media/video/saa7110.c @@ -470,7 +470,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_i2c, .probe = &ignore, .ignore = &ignore, - .force = &ignore, }; static struct i2c_driver i2c_driver_saa7110; diff --git a/drivers/media/video/saa7111.c b/drivers/media/video/saa7111.c index fcd897382fc..f18df53d98f 100644 --- a/drivers/media/video/saa7111.c +++ b/drivers/media/video/saa7111.c @@ -489,7 +489,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_i2c, .probe = &ignore, .ignore = &ignore, - .force = &ignore, }; static struct i2c_driver i2c_driver_saa7111; diff --git a/drivers/media/video/saa7114.c b/drivers/media/video/saa7114.c index 2ba997f5ef1..e0c70f54f07 100644 --- a/drivers/media/video/saa7114.c +++ b/drivers/media/video/saa7114.c @@ -827,7 +827,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_i2c, .probe = &ignore, .ignore = &ignore, - .force = &ignore, }; static struct i2c_driver i2c_driver_saa7114; diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c index 79d05ea1b69..382911c6ef2 100644 --- a/drivers/media/video/saa7134/saa6752hs.c +++ b/drivers/media/video/saa7134/saa6752hs.c @@ -598,7 +598,7 @@ static struct i2c_driver driver = { static struct i2c_client client_template = { - I2C_DEVNAME("saa6752hs"), + .name = "saa6752hs", .flags = I2C_CLIENT_ALLOW_USE, .driver = &driver, }; diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c index 1203b93a572..eae6b529713 100644 --- a/drivers/media/video/saa7134/saa7134-i2c.c +++ b/drivers/media/video/saa7134/saa7134-i2c.c @@ -334,7 +334,7 @@ static int attach_inform(struct i2c_client *client) struct tuner_setup tun_setup; d1printk( "%s i2c attach [addr=0x%x,client=%s]\n", - client->driver->name,client->addr,i2c_clientname(client)); + client->driver->name, client->addr, client->name); if (!client->driver->command) return 0; @@ -370,8 +370,6 @@ static int attach_inform(struct i2c_client *client) } static struct i2c_algorithm saa7134_algo = { - .name = "saa7134", - .id = I2C_ALGO_SAA7134, .master_xfer = saa7134_i2c_xfer, .algo_control = algo_control, .functionality = functionality, @@ -382,14 +380,14 @@ static struct i2c_adapter saa7134_adap_template = { #ifdef I2C_CLASS_TV_ANALOG .class = I2C_CLASS_TV_ANALOG, #endif - I2C_DEVNAME("saa7134"), - .id = I2C_ALGO_SAA7134, + .name = "saa7134", + .id = I2C_HW_SAA7134, .algo = &saa7134_algo, .client_register = attach_inform, }; static struct i2c_client saa7134_client_template = { - I2C_DEVNAME("saa7134 internal"), + .name = "saa7134 internal", }; /* ----------------------------------------------------------- */ diff --git a/drivers/media/video/saa7185.c b/drivers/media/video/saa7185.c index 108e7a4a027..e93412f4407 100644 --- a/drivers/media/video/saa7185.c +++ b/drivers/media/video/saa7185.c @@ -387,7 +387,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_i2c, .probe = &ignore, .ignore = &ignore, - .force = &ignore, }; static struct i2c_driver i2c_driver_saa7185; diff --git a/drivers/media/video/tda7432.c b/drivers/media/video/tda7432.c index 7cb1fb3e66f..255b6088ebf 100644 --- a/drivers/media/video/tda7432.c +++ b/drivers/media/video/tda7432.c @@ -328,7 +328,7 @@ static int tda7432_probe(struct i2c_adapter *adap) if (adap->class & I2C_CLASS_TV_ANALOG) return i2c_probe(adap, &addr_data, tda7432_attach); #else - if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848)) + if (adap->id == I2C_HW_B_BT848) return i2c_probe(adap, &addr_data, tda7432_attach); #endif return 0; @@ -513,7 +513,7 @@ static struct i2c_driver driver = { static struct i2c_client client_template = { - I2C_DEVNAME("tda7432"), + .name = "tda7432", .driver = &driver, }; diff --git a/drivers/media/video/tda9840.c b/drivers/media/video/tda9840.c index c29bdfc3244..1794686612c 100644 --- a/drivers/media/video/tda9840.c +++ b/drivers/media/video/tda9840.c @@ -205,7 +205,7 @@ static int detect(struct i2c_adapter *adapter, int address, int kind) static int attach(struct i2c_adapter *adapter) { /* let's see whether this is a know adapter we can attach to */ - if (adapter->id != I2C_ALGO_SAA7146) { + if (adapter->id != I2C_HW_SAA7146) { dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id); return -ENODEV; } @@ -231,7 +231,7 @@ static struct i2c_driver driver = { }; static struct i2c_client client_template = { - I2C_DEVNAME("tda9840"), + .name = "tda9840", .driver = &driver, }; diff --git a/drivers/media/video/tda9875.c b/drivers/media/video/tda9875.c index 566e1a5ca13..7e3dcdb262b 100644 --- a/drivers/media/video/tda9875.c +++ b/drivers/media/video/tda9875.c @@ -262,7 +262,7 @@ static int tda9875_probe(struct i2c_adapter *adap) if (adap->class & I2C_CLASS_TV_ANALOG) return i2c_probe(adap, &addr_data, tda9875_attach); #else - if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848)) + if (adap->id == I2C_HW_B_BT848) return i2c_probe(adap, &addr_data, tda9875_attach); #endif return 0; @@ -384,7 +384,7 @@ static struct i2c_driver driver = { static struct i2c_client client_template = { - I2C_DEVNAME("tda9875"), + .name = "tda9875", .driver = &driver, }; diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c index 108c3ad7d62..d60fc562aec 100644 --- a/drivers/media/video/tda9887.c +++ b/drivers/media/video/tda9887.c @@ -618,9 +618,9 @@ static int tda9887_probe(struct i2c_adapter *adap) return i2c_probe(adap, &addr_data, tda9887_attach); #else switch (adap->id) { - case I2C_ALGO_BIT | I2C_HW_B_BT848: - case I2C_ALGO_BIT | I2C_HW_B_RIVA: - case I2C_ALGO_SAA7134: + case I2C_HW_B_BT848: + case I2C_HW_B_RIVA: + case I2C_HW_SAA7134: return i2c_probe(adap, &addr_data, tda9887_attach); break; } @@ -760,7 +760,7 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg) return 0; } -static int tda9887_suspend(struct device * dev, u32 state, u32 level) +static int tda9887_suspend(struct device * dev, pm_message_t state, u32 level) { dprintk("tda9887: suspend\n"); return 0; @@ -793,7 +793,7 @@ static struct i2c_driver driver = { }; static struct i2c_client client_template = { - I2C_DEVNAME("tda9887"), + .name = "tda9887", .flags = I2C_CLIENT_ALLOW_USE, .driver = &driver, }; diff --git a/drivers/media/video/tea6415c.c b/drivers/media/video/tea6415c.c index b44db8a7b94..ee3688348b6 100644 --- a/drivers/media/video/tea6415c.c +++ b/drivers/media/video/tea6415c.c @@ -86,7 +86,7 @@ static int detect(struct i2c_adapter *adapter, int address, int kind) static int attach(struct i2c_adapter *adapter) { /* let's see whether this is a know adapter we can attach to */ - if (adapter->id != I2C_ALGO_SAA7146) { + if (adapter->id != I2C_HW_SAA7146) { dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id); return -ENODEV; } @@ -200,7 +200,7 @@ static struct i2c_driver driver = { }; static struct i2c_client client_template = { - I2C_DEVNAME("tea6415c"), + .name = "tea6415c", .driver = &driver, }; diff --git a/drivers/media/video/tea6420.c b/drivers/media/video/tea6420.c index 48d4db7d507..17975c19da5 100644 --- a/drivers/media/video/tea6420.c +++ b/drivers/media/video/tea6420.c @@ -135,7 +135,7 @@ static int tea6420_detect(struct i2c_adapter *adapter, int address, int kind) static int attach(struct i2c_adapter *adapter) { /* let's see whether this is a know adapter we can attach to */ - if (adapter->id != I2C_ALGO_SAA7146) { + if (adapter->id != I2C_HW_SAA7146) { dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id); return -ENODEV; } @@ -177,7 +177,7 @@ static struct i2c_driver driver = { }; static struct i2c_client client_template = { - I2C_DEVNAME("tea6420"), + .name = "tea6420", .driver = &driver, }; diff --git a/drivers/media/video/tuner-3036.c b/drivers/media/video/tuner-3036.c index 7d825e510ff..79203595b9c 100644 --- a/drivers/media/video/tuner-3036.c +++ b/drivers/media/video/tuner-3036.c @@ -41,7 +41,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_i2c, .probe = &ignore, .ignore = &ignore, - .force = &ignore, }; /* ---------------------------------------------------------------------- */ @@ -166,7 +165,7 @@ static int tuner_probe(struct i2c_adapter *adap) { this_adap = 0; - if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_LP)) + if (adap->id == I2C_HW_B_LP) return i2c_probe(adap, &addr_data, tuner_attach); return 0; } diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c index f0a579827a2..3b1893c2ae3 100644 --- a/drivers/media/video/tuner-core.c +++ b/drivers/media/video/tuner-core.c @@ -672,7 +672,7 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) return 0; } -static int tuner_suspend(struct device *dev, u32 state, u32 level) +static int tuner_suspend(struct device *dev, pm_message_t state, u32 level) { struct i2c_client *c = container_of (dev, struct i2c_client, dev); struct tuner *t = i2c_get_clientdata (c); @@ -709,7 +709,7 @@ static struct i2c_driver driver = { }, }; static struct i2c_client client_template = { - I2C_DEVNAME("(tuner unset)"), + .name = "(tuner unset)", .flags = I2C_CLIENT_ALLOW_USE, .driver = &driver, }; diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c index f42a1efa8fc..258724b2d6d 100644 --- a/drivers/media/video/tvaudio.c +++ b/drivers/media/video/tvaudio.c @@ -162,24 +162,23 @@ static int chip_write(struct CHIPSTATE *chip, int subaddr, int val) unsigned char buffer[2]; if (-1 == subaddr) { - dprintk("%s: chip_write: 0x%x\n", - i2c_clientname(&chip->c), val); + dprintk("%s: chip_write: 0x%x\n", chip->c.name, val); chip->shadow.bytes[1] = val; buffer[0] = val; if (1 != i2c_master_send(&chip->c,buffer,1)) { printk(KERN_WARNING "%s: I/O error (write 0x%x)\n", - i2c_clientname(&chip->c), val); + chip->c.name, val); return -1; } } else { dprintk("%s: chip_write: reg%d=0x%x\n", - i2c_clientname(&chip->c), subaddr, val); + chip->c.name, subaddr, val); chip->shadow.bytes[subaddr+1] = val; buffer[0] = subaddr; buffer[1] = val; if (2 != i2c_master_send(&chip->c,buffer,2)) { printk(KERN_WARNING "%s: I/O error (write reg%d=0x%x)\n", - i2c_clientname(&chip->c), subaddr, val); + chip->c.name, subaddr, val); return -1; } } @@ -203,11 +202,10 @@ static int chip_read(struct CHIPSTATE *chip) unsigned char buffer; if (1 != i2c_master_recv(&chip->c,&buffer,1)) { - printk(KERN_WARNING "%s: I/O error (read)\n", - i2c_clientname(&chip->c)); + printk(KERN_WARNING "%s: I/O error (read)\n", chip->c.name); return -1; } - dprintk("%s: chip_read: 0x%x\n",i2c_clientname(&chip->c),buffer); + dprintk("%s: chip_read: 0x%x\n", chip->c.name, buffer); return buffer; } @@ -222,12 +220,11 @@ static int chip_read2(struct CHIPSTATE *chip, int subaddr) write[0] = subaddr; if (2 != i2c_transfer(chip->c.adapter,msgs,2)) { - printk(KERN_WARNING "%s: I/O error (read2)\n", - i2c_clientname(&chip->c)); + printk(KERN_WARNING "%s: I/O error (read2)\n", chip->c.name); return -1; } dprintk("%s: chip_read2: reg%d=0x%x\n", - i2c_clientname(&chip->c),subaddr,read[0]); + chip->c.name, subaddr, read[0]); return read[0]; } @@ -240,7 +237,7 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd) /* update our shadow register set; print bytes if (debug > 0) */ dprintk("%s: chip_cmd(%s): reg=%d, data:", - i2c_clientname(&chip->c),name,cmd->bytes[0]); + chip->c.name, name, cmd->bytes[0]); for (i = 1; i < cmd->count; i++) { dprintk(" 0x%x",cmd->bytes[i]); chip->shadow.bytes[i+cmd->bytes[0]] = cmd->bytes[i]; @@ -249,7 +246,7 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd) /* send data to the chip */ if (cmd->count != i2c_master_send(&chip->c,cmd->bytes,cmd->count)) { - printk(KERN_WARNING "%s: I/O error (%s)\n", i2c_clientname(&chip->c), name); + printk(KERN_WARNING "%s: I/O error (%s)\n", chip->c.name, name); return -1; } return 0; @@ -274,9 +271,9 @@ static int chip_thread(void *data) struct CHIPSTATE *chip = data; struct CHIPDESC *desc = chiplist + chip->type; - daemonize("%s",i2c_clientname(&chip->c)); + daemonize("%s", chip->c.name); allow_signal(SIGTERM); - dprintk("%s: thread started\n", i2c_clientname(&chip->c)); + dprintk("%s: thread started\n", chip->c.name); for (;;) { add_wait_queue(&chip->wq, &wait); @@ -288,7 +285,7 @@ static int chip_thread(void *data) try_to_freeze(); if (chip->done || signal_pending(current)) break; - dprintk("%s: thread wakeup\n", i2c_clientname(&chip->c)); + dprintk("%s: thread wakeup\n", chip->c.name); /* don't do anything for radio or if mode != auto */ if (chip->norm == VIDEO_MODE_RADIO || chip->mode != 0) @@ -301,7 +298,7 @@ static int chip_thread(void *data) mod_timer(&chip->wt, jiffies+2*HZ); } - dprintk("%s: thread exiting\n", i2c_clientname(&chip->c)); + dprintk("%s: thread exiting\n", chip->c.name); complete_and_exit(&chip->texit, 0); return 0; } @@ -314,7 +311,7 @@ static void generic_checkmode(struct CHIPSTATE *chip) if (mode == chip->prevmode) return; - dprintk("%s: thread checkmode\n", i2c_clientname(&chip->c)); + dprintk("%s: thread checkmode\n", chip->c.name); chip->prevmode = mode; if (mode & VIDEO_SOUND_STEREO) @@ -1098,7 +1095,7 @@ static int tda8425_initialize(struct CHIPSTATE *chip) /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF, /* off */ TDA8425_S1_OFF, /* on */ TDA8425_S1_CH2}; - if (chip->c.adapter->id == (I2C_ALGO_BIT | I2C_HW_B_RIVA)) { + if (chip->c.adapter->id == I2C_HW_B_RIVA) { memcpy (desc->inputmap, inputmap, sizeof (inputmap)); } return 0; @@ -1501,7 +1498,7 @@ static int chip_attach(struct i2c_adapter *adap, int addr, int kind) (desc->flags & CHIP_HAS_INPUTSEL) ? " audiomux" : ""); /* fill required data structures */ - strcpy(i2c_clientname(&chip->c),desc->name); + strcpy(chip->c.name, desc->name); chip->type = desc-chiplist; chip->shadow.count = desc->registers+1; chip->prevmode = -1; @@ -1538,7 +1535,7 @@ static int chip_attach(struct i2c_adapter *adap, int addr, int kind) chip->tpid = kernel_thread(chip_thread,(void *)chip,0); if (chip->tpid < 0) printk(KERN_WARNING "%s: kernel_thread() failed\n", - i2c_clientname(&chip->c)); + chip->c.name); wake_up_interruptible(&chip->wq); } return 0; @@ -1548,16 +1545,16 @@ static int chip_probe(struct i2c_adapter *adap) { /* don't attach on saa7146 based cards, because dedicated drivers are used */ - if ((adap->id & I2C_ALGO_SAA7146)) + if (adap->id == I2C_HW_SAA7146) return 0; #ifdef I2C_CLASS_TV_ANALOG if (adap->class & I2C_CLASS_TV_ANALOG) return i2c_probe(adap, &addr_data, chip_attach); #else switch (adap->id) { - case I2C_ALGO_BIT | I2C_HW_B_BT848: - case I2C_ALGO_BIT | I2C_HW_B_RIVA: - case I2C_ALGO_SAA7134: + case I2C_HW_B_BT848: + case I2C_HW_B_RIVA: + case I2C_HW_SAA7134: return i2c_probe(adap, &addr_data, chip_attach); } #endif @@ -1591,7 +1588,7 @@ static int chip_command(struct i2c_client *client, struct CHIPSTATE *chip = i2c_get_clientdata(client); struct CHIPDESC *desc = chiplist + chip->type; - dprintk("%s: chip_command 0x%x\n",i2c_clientname(&chip->c),cmd); + dprintk("%s: chip_command 0x%x\n", chip->c.name, cmd); switch (cmd) { case AUDC_SET_INPUT: @@ -1702,7 +1699,7 @@ static struct i2c_driver driver = { static struct i2c_client client_template = { - I2C_DEVNAME("(unset)"), + .name = "(unset)", .flags = I2C_CLIENT_ALLOW_USE, .driver = &driver, }; diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c index 127ec38ebd6..3c3356a01cc 100644 --- a/drivers/media/video/tveeprom.c +++ b/drivers/media/video/tveeprom.c @@ -534,7 +534,7 @@ static int tveeprom_attach_adapter (struct i2c_adapter *adapter) { dprintk(1,"%s: id 0x%x\n",__FUNCTION__,adapter->id); - if (adapter->id != (I2C_ALGO_BIT | I2C_HW_B_BT848)) + if (adapter->id != I2C_HW_B_BT848) return 0; return i2c_probe(adapter, &addr_data, tveeprom_detect_client); } diff --git a/drivers/media/video/tvmixer.c b/drivers/media/video/tvmixer.c index 51b99cdbf29..a43301a154a 100644 --- a/drivers/media/video/tvmixer.c +++ b/drivers/media/video/tvmixer.c @@ -91,7 +91,7 @@ static int tvmixer_ioctl(struct inode *inode, struct file *file, unsigned int cm if (cmd == SOUND_MIXER_INFO) { mixer_info info; strlcpy(info.id, "tv card", sizeof(info.id)); - strlcpy(info.name, i2c_clientname(client), sizeof(info.name)); + strlcpy(info.name, client->name, sizeof(info.name)); info.modify_counter = 42 /* FIXME */; if (copy_to_user(argp, &info, sizeof(info))) return -EFAULT; @@ -100,7 +100,7 @@ static int tvmixer_ioctl(struct inode *inode, struct file *file, unsigned int cm if (cmd == SOUND_OLD_MIXER_INFO) { _old_mixer_info info; strlcpy(info.id, "tv card", sizeof(info.id)); - strlcpy(info.name, i2c_clientname(client), sizeof(info.name)); + strlcpy(info.name, client->name, sizeof(info.name)); if (copy_to_user(argp, &info, sizeof(info))) return -EFAULT; return 0; @@ -276,9 +276,9 @@ static int tvmixer_clients(struct i2c_client *client) #else /* TV card ??? */ switch (client->adapter->id) { - case I2C_ALGO_BIT | I2C_HW_SMBUS_VOODOO3: - case I2C_ALGO_BIT | I2C_HW_B_BT848: - case I2C_ALGO_BIT | I2C_HW_B_RIVA: + case I2C_HW_SMBUS_VOODOO3: + case I2C_HW_B_BT848: + case I2C_HW_B_RIVA: /* ok, have a look ... */ break; default: @@ -295,7 +295,7 @@ static int tvmixer_clients(struct i2c_client *client) devices[i].dev = NULL; devices[i].minor = -1; printk("tvmixer: %s unregistered (#1)\n", - i2c_clientname(client)); + client->name); return 0; } } @@ -354,7 +354,7 @@ static void __exit tvmixer_cleanup_module(void) if (devices[i].minor != -1) { unregister_sound_mixer(devices[i].minor); printk("tvmixer: %s unregistered (#2)\n", - i2c_clientname(devices[i].dev)); + devices[i].dev->name); } } } diff --git a/drivers/media/video/vpx3220.c b/drivers/media/video/vpx3220.c index 5dbd9f6bf35..4437bdebe24 100644 --- a/drivers/media/video/vpx3220.c +++ b/drivers/media/video/vpx3220.c @@ -576,7 +576,6 @@ static struct i2c_client_address_data addr_data = { .normal_i2c = normal_i2c, .probe = &ignore, .ignore = &ignore, - .force = &ignore, }; static struct i2c_driver vpx3220_i2c_driver; diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c index 25743085b2d..eed2acea177 100644 --- a/drivers/media/video/zoran_card.c +++ b/drivers/media/video/zoran_card.c @@ -737,7 +737,7 @@ static struct i2c_algo_bit_data zoran_i2c_bit_data_template = { }; static struct i2c_adapter zoran_i2c_adapter_template = { - I2C_DEVNAME("zr36057"), + .name = "zr36057", .id = I2C_HW_B_ZR36067, .algo = NULL, .client_register = zoran_i2c_client_register, diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 3c5904834fe..0a8165974ba 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -457,6 +457,11 @@ static void mmc_idle_cards(struct mmc_host *host) { struct mmc_command cmd; + host->ios.chip_select = MMC_CS_HIGH; + host->ops->set_ios(host, &host->ios); + + mmc_delay(1); + cmd.opcode = MMC_GO_IDLE_STATE; cmd.arg = 0; cmd.flags = MMC_RSP_NONE; @@ -464,6 +469,11 @@ static void mmc_idle_cards(struct mmc_host *host) mmc_wait_for_cmd(host, &cmd, 0); mmc_delay(1); + + host->ios.chip_select = MMC_CS_DONTCARE; + host->ops->set_ios(host, &host->ios); + + mmc_delay(1); } /* @@ -475,6 +485,7 @@ static void mmc_power_up(struct mmc_host *host) host->ios.vdd = bit; host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; + host->ios.chip_select = MMC_CS_DONTCARE; host->ios.power_mode = MMC_POWER_UP; host->ops->set_ios(host, &host->ios); @@ -492,6 +503,7 @@ static void mmc_power_off(struct mmc_host *host) host->ios.clock = 0; host->ios.vdd = 0; host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; + host->ios.chip_select = MMC_CS_DONTCARE; host->ios.power_mode = MMC_POWER_OFF; host->ops->set_ios(host, &host->ios); } diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c index 402c2d661fb..08ae22aed9e 100644 --- a/drivers/mmc/wbsd.c +++ b/drivers/mmc/wbsd.c @@ -42,7 +42,7 @@ #include "wbsd.h" #define DRIVER_NAME "wbsd" -#define DRIVER_VERSION "1.3" +#define DRIVER_VERSION "1.4" #ifdef CONFIG_MMC_DEBUG #define DBG(x...) \ @@ -960,8 +960,9 @@ static void wbsd_set_ios(struct mmc_host* mmc, struct mmc_ios* ios) struct wbsd_host* host = mmc_priv(mmc); u8 clk, setup, pwr; - DBGF("clock %uHz busmode %u powermode %u Vdd %u\n", - ios->clock, ios->bus_mode, ios->power_mode, ios->vdd); + DBGF("clock %uHz busmode %u powermode %u cs %u Vdd %u\n", + ios->clock, ios->bus_mode, ios->power_mode, ios->chip_select, + ios->vdd); spin_lock_bh(&host->lock); @@ -1003,13 +1004,11 @@ static void wbsd_set_ios(struct mmc_host* mmc, struct mmc_ios* ios) /* * MMC cards need to have pin 1 high during init. - * Init time corresponds rather nicely with the bus mode. * It wreaks havoc with the card detection though so - * that needs to be disabed. + * that needs to be disabled. */ setup = wbsd_read_index(host, WBSD_IDX_SETUP); - if ((ios->power_mode == MMC_POWER_ON) && - (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)) + if (ios->chip_select == MMC_CS_HIGH) { setup |= WBSD_DAT3_H; host->flags |= WBSD_FIGNORE_DETECT; @@ -1017,7 +1016,12 @@ static void wbsd_set_ios(struct mmc_host* mmc, struct mmc_ios* ios) else { setup &= ~WBSD_DAT3_H; - host->flags &= ~WBSD_FIGNORE_DETECT; + + /* + * We cannot resume card detection immediatly + * because of capacitance and delays in the chip. + */ + mod_timer(&host->ignore_timer, jiffies + HZ/100); } wbsd_write_index(host, WBSD_IDX_SETUP, setup); @@ -1036,6 +1040,31 @@ static struct mmc_host_ops wbsd_ops = { \*****************************************************************************/ /* + * Helper function to reset detection ignore + */ + +static void wbsd_reset_ignore(unsigned long data) +{ + struct wbsd_host *host = (struct wbsd_host*)data; + + BUG_ON(host == NULL); + + DBG("Resetting card detection ignore\n"); + + spin_lock_bh(&host->lock); + + host->flags &= ~WBSD_FIGNORE_DETECT; + + /* + * Card status might have changed during the + * blackout. + */ + tasklet_schedule(&host->card_tasklet); + + spin_unlock_bh(&host->lock); +} + +/* * Helper function for card detection */ static void wbsd_detect_card(unsigned long data) @@ -1097,7 +1126,7 @@ static void wbsd_tasklet_card(unsigned long param) * Delay card detection to allow electrical connections * to stabilise. */ - mod_timer(&host->timer, jiffies + HZ/2); + mod_timer(&host->detect_timer, jiffies + HZ/2); } spin_unlock(&host->lock); @@ -1124,6 +1153,8 @@ static void wbsd_tasklet_card(unsigned long param) mmc_detect_change(host->mmc); } + else + spin_unlock(&host->lock); } static void wbsd_tasklet_fifo(unsigned long param) @@ -1328,11 +1359,15 @@ static int __devinit wbsd_alloc_mmc(struct device* dev) spin_lock_init(&host->lock); /* - * Set up detection timer + * Set up timers */ - init_timer(&host->timer); - host->timer.data = (unsigned long)host; - host->timer.function = wbsd_detect_card; + init_timer(&host->detect_timer); + host->detect_timer.data = (unsigned long)host; + host->detect_timer.function = wbsd_detect_card; + + init_timer(&host->ignore_timer); + host->ignore_timer.data = (unsigned long)host; + host->ignore_timer.function = wbsd_reset_ignore; /* * Maximum number of segments. Worst case is one sector per segment @@ -1370,7 +1405,8 @@ static void __devexit wbsd_free_mmc(struct device* dev) host = mmc_priv(mmc); BUG_ON(host == NULL); - del_timer_sync(&host->timer); + del_timer_sync(&host->ignore_timer); + del_timer_sync(&host->detect_timer); mmc_free_host(mmc); diff --git a/drivers/mmc/wbsd.h b/drivers/mmc/wbsd.h index 661a9f6a6e6..8af43549f5d 100644 --- a/drivers/mmc/wbsd.h +++ b/drivers/mmc/wbsd.h @@ -181,5 +181,6 @@ struct wbsd_host struct tasklet_struct finish_tasklet; struct tasklet_struct block_tasklet; - struct timer_list timer; /* Card detection timer */ + struct timer_list detect_timer; /* Card detection timer */ + struct timer_list ignore_timer; /* Ignore detection timer */ }; diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c index 7babf6af4e2..55a72c7ad00 100644 --- a/drivers/net/bnx2.c +++ b/drivers/net/bnx2.c @@ -2004,14 +2004,14 @@ bnx2_init_cpus(struct bnx2 *bp) } static int -bnx2_set_power_state(struct bnx2 *bp, int state) +bnx2_set_power_state(struct bnx2 *bp, pci_power_t state) { u16 pmcsr; pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr); switch (state) { - case 0: { + case PCI_D0: { u32 val; pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, @@ -2032,7 +2032,7 @@ bnx2_set_power_state(struct bnx2 *bp, int state) REG_WR(bp, BNX2_RPM_CONFIG, val); break; } - case 3: { + case PCI_D3hot: { int i; u32 val, wol_msg; @@ -3886,7 +3886,7 @@ bnx2_open(struct net_device *dev) struct bnx2 *bp = dev->priv; int rc; - bnx2_set_power_state(bp, 0); + bnx2_set_power_state(bp, PCI_D0); bnx2_disable_int(bp); rc = bnx2_alloc_mem(bp); @@ -4197,7 +4197,7 @@ bnx2_close(struct net_device *dev) bnx2_free_mem(bp); bp->link_up = 0; netif_carrier_off(bp->dev); - bnx2_set_power_state(bp, 3); + bnx2_set_power_state(bp, PCI_D3hot); return 0; } @@ -5203,7 +5203,7 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev) BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA | BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP); - bnx2_set_power_state(bp, 0); + bnx2_set_power_state(bp, PCI_D0); bp->chip_id = REG_RD(bp, BNX2_MISC_ID); @@ -5495,7 +5495,7 @@ bnx2_remove_one(struct pci_dev *pdev) } static int -bnx2_suspend(struct pci_dev *pdev, u32 state) +bnx2_suspend(struct pci_dev *pdev, pm_message_t state) { struct net_device *dev = pci_get_drvdata(pdev); struct bnx2 *bp = dev->priv; @@ -5513,7 +5513,7 @@ bnx2_suspend(struct pci_dev *pdev, u32 state) reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL; bnx2_reset_chip(bp, reset_code); bnx2_free_skbs(bp); - bnx2_set_power_state(bp, state); + bnx2_set_power_state(bp, pci_choose_state(pdev, state)); return 0; } @@ -5526,7 +5526,7 @@ bnx2_resume(struct pci_dev *pdev) if (!netif_running(dev)) return 0; - bnx2_set_power_state(bp, 0); + bnx2_set_power_state(bp, PCI_D0); netif_device_attach(dev); bnx2_init_nic(bp); bnx2_netif_start(bp); diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c index 9b596e0bbf9..7c8a0a22dcd 100644 --- a/drivers/net/e1000/e1000_main.c +++ b/drivers/net/e1000/e1000_main.c @@ -162,7 +162,7 @@ static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid); static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); static void e1000_restore_vlan(struct e1000_adapter *adapter); -static int e1000_suspend(struct pci_dev *pdev, uint32_t state); +static int e1000_suspend(struct pci_dev *pdev, pm_message_t state); #ifdef CONFIG_PM static int e1000_resume(struct pci_dev *pdev); #endif @@ -3642,7 +3642,7 @@ e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx) } static int -e1000_suspend(struct pci_dev *pdev, uint32_t state) +e1000_suspend(struct pci_dev *pdev, pm_message_t state) { struct net_device *netdev = pci_get_drvdata(pdev); struct e1000_adapter *adapter = netdev_priv(netdev); @@ -3726,9 +3726,7 @@ e1000_suspend(struct pci_dev *pdev, uint32_t state) } pci_disable_device(pdev); - - state = (state > 0) ? 3 : 0; - pci_set_power_state(pdev, state); + pci_set_power_state(pdev, pci_choose_state(pdev, state)); return 0; } @@ -3741,13 +3739,13 @@ e1000_resume(struct pci_dev *pdev) struct e1000_adapter *adapter = netdev_priv(netdev); uint32_t manc, ret_val, swsm; - pci_set_power_state(pdev, 0); + pci_set_power_state(pdev, PCI_D0); pci_restore_state(pdev); ret_val = pci_enable_device(pdev); pci_set_master(pdev); - pci_enable_wake(pdev, 3, 0); - pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */ + pci_enable_wake(pdev, PCI_D3hot, 0); + pci_enable_wake(pdev, PCI_D3cold, 0); e1000_reset(adapter); E1000_WRITE_REG(&adapter->hw, WUS, ~0); diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c index 006e4f57560..6d9de626c96 100644 --- a/drivers/net/irda/vlsi_ir.c +++ b/drivers/net/irda/vlsi_ir.c @@ -1749,11 +1749,6 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state) struct net_device *ndev = pci_get_drvdata(pdev); vlsi_irda_dev_t *idev; - if (state < 1 || state > 3 ) { - IRDA_ERROR("%s - %s: invalid pm state request: %u\n", - __FUNCTION__, PCIDEV_NAME(pdev), state); - return 0; - } if (!ndev) { IRDA_ERROR("%s - %s: no netdevice \n", __FUNCTION__, PCIDEV_NAME(pdev)); @@ -1762,12 +1757,12 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state) idev = ndev->priv; down(&idev->sem); if (pdev->current_state != 0) { /* already suspended */ - if (state > pdev->current_state) { /* simply go deeper */ - pci_set_power_state(pdev,state); - pdev->current_state = state; + if (state.event > pdev->current_state) { /* simply go deeper */ + pci_set_power_state(pdev, pci_choose_state(pdev, state)); + pdev->current_state = state.event; } else - IRDA_ERROR("%s - %s: invalid suspend request %u -> %u\n", __FUNCTION__, PCIDEV_NAME(pdev), pdev->current_state, state); + IRDA_ERROR("%s - %s: invalid suspend request %u -> %u\n", __FUNCTION__, PCIDEV_NAME(pdev), pdev->current_state, state.event); up(&idev->sem); return 0; } @@ -1781,8 +1776,8 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state) idev->new_baud = idev->baud; } - pci_set_power_state(pdev,state); - pdev->current_state = state; + pci_set_power_state(pdev, pci_choose_state(pdev, state)); + pdev->current_state = state.event; idev->resume_ok = 1; up(&idev->sem); return 0; @@ -1807,8 +1802,8 @@ static int vlsi_irda_resume(struct pci_dev *pdev) return 0; } - pci_set_power_state(pdev, 0); - pdev->current_state = 0; + pci_set_power_state(pdev, PCI_D0); + pdev->current_state = PM_EVENT_ON; if (!idev->resume_ok) { /* should be obsolete now - but used to happen due to: diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 41f62c0c5fc..5e81494e9a9 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -128,7 +128,7 @@ static int mdio_bus_match(struct device *dev, struct device_driver *drv) /* Suspend and resume. Copied from platform_suspend and * platform_resume */ -static int mdio_bus_suspend(struct device * dev, u32 state) +static int mdio_bus_suspend(struct device * dev, pm_message_t state) { int ret = 0; struct device_driver *drv = dev->driver; diff --git a/drivers/net/sungem.c b/drivers/net/sungem.c index 2608e7a3d21..3f67a42e850 100644 --- a/drivers/net/sungem.c +++ b/drivers/net/sungem.c @@ -948,6 +948,7 @@ static irqreturn_t gem_interrupt(int irq, void *dev_id, struct pt_regs *regs) u32 gem_status = readl(gp->regs + GREG_STAT); if (gem_status == 0) { + netif_poll_enable(dev); spin_unlock_irqrestore(&gp->lock, flags); return IRQ_NONE; } diff --git a/drivers/net/sungem.h b/drivers/net/sungem.h index 7143fd7cf3f..ff8ae5f7997 100644 --- a/drivers/net/sungem.h +++ b/drivers/net/sungem.h @@ -1020,7 +1020,7 @@ struct gem { struct gem_init_block *init_block; struct sk_buff *rx_skbs[RX_RING_SIZE]; - struct sk_buff *tx_skbs[RX_RING_SIZE]; + struct sk_buff *tx_skbs[TX_RING_SIZE]; dma_addr_t gblock_dvma; struct pci_dev *pdev; diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c index af8263a1580..dc57352e5a9 100644 --- a/drivers/net/tg3.c +++ b/drivers/net/tg3.c @@ -36,6 +36,7 @@ #include <linux/ip.h> #include <linux/tcp.h> #include <linux/workqueue.h> +#include <linux/prefetch.h> #include <net/checksum.h> @@ -66,8 +67,8 @@ #define DRV_MODULE_NAME "tg3" #define PFX DRV_MODULE_NAME ": " -#define DRV_MODULE_VERSION "3.37" -#define DRV_MODULE_RELDATE "August 25, 2005" +#define DRV_MODULE_VERSION "3.39" +#define DRV_MODULE_RELDATE "September 5, 2005" #define TG3_DEF_MAC_MODE 0 #define TG3_DEF_RX_MODE 0 @@ -121,12 +122,9 @@ TG3_RX_RCB_RING_SIZE(tp)) #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ TG3_TX_RING_SIZE) -#define TX_RING_GAP(TP) \ - (TG3_TX_RING_SIZE - (TP)->tx_pending) #define TX_BUFFS_AVAIL(TP) \ - (((TP)->tx_cons <= (TP)->tx_prod) ? \ - (TP)->tx_cons + (TP)->tx_pending - (TP)->tx_prod : \ - (TP)->tx_cons - (TP)->tx_prod - TX_RING_GAP(TP)) + ((TP)->tx_pending - \ + (((TP)->tx_prod - (TP)->tx_cons) & (TG3_TX_RING_SIZE - 1))) #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) #define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64) @@ -490,7 +488,8 @@ static void tg3_disable_ints(struct tg3 *tp) static inline void tg3_cond_int(struct tg3 *tp) { - if (tp->hw_status->status & SD_STATUS_UPDATED) + if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) && + (tp->hw_status->status & SD_STATUS_UPDATED)) tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); } @@ -2880,9 +2879,13 @@ static void tg3_tx(struct tg3 *tp) tp->tx_cons = sw_idx; - if (netif_queue_stopped(tp->dev) && - (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH)) - netif_wake_queue(tp->dev); + if (unlikely(netif_queue_stopped(tp->dev))) { + spin_lock(&tp->tx_lock); + if (netif_queue_stopped(tp->dev) && + (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH)) + netif_wake_queue(tp->dev); + spin_unlock(&tp->tx_lock); + } } /* Returns size of skb allocated or < 0 on error. @@ -3198,9 +3201,7 @@ static int tg3_poll(struct net_device *netdev, int *budget) /* run TX completion thread */ if (sblk->idx[0].tx_consumer != tp->tx_cons) { - spin_lock(&tp->tx_lock); tg3_tx(tp); - spin_unlock(&tp->tx_lock); } /* run RX thread, within the bounds set by NAPI. @@ -3220,18 +3221,17 @@ static int tg3_poll(struct net_device *netdev, int *budget) netdev->quota -= work_done; } - if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) + if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) { tp->last_tag = sblk->status_tag; - rmb(); - sblk->status &= ~SD_STATUS_UPDATED; + rmb(); + } else + sblk->status &= ~SD_STATUS_UPDATED; /* if no more work, tell net stack and NIC we're done */ done = !tg3_has_work(tp); if (done) { - spin_lock(&tp->lock); netif_rx_complete(netdev); tg3_restart_ints(tp); - spin_unlock(&tp->lock); } return (done ? 0 : 1); @@ -3279,8 +3279,9 @@ static irqreturn_t tg3_msi(int irq, void *dev_id, struct pt_regs *regs) { struct net_device *dev = dev_id; struct tg3 *tp = netdev_priv(dev); - struct tg3_hw_status *sblk = tp->hw_status; + prefetch(tp->hw_status); + prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]); /* * Writing any value to intr-mbox-0 clears PCI INTA# and * chip-internal interrupt pending events. @@ -3289,19 +3290,9 @@ static irqreturn_t tg3_msi(int irq, void *dev_id, struct pt_regs *regs) * event coalescing. */ tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); - tp->last_tag = sblk->status_tag; - rmb(); - if (tg3_irq_sync(tp)) - goto out; - sblk->status &= ~SD_STATUS_UPDATED; - if (likely(tg3_has_work(tp))) + if (likely(!tg3_irq_sync(tp))) netif_rx_schedule(dev); /* schedule NAPI poll */ - else { - /* No work, re-enable interrupts. */ - tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, - tp->last_tag << 24); - } -out: + return IRQ_RETVAL(1); } @@ -3331,9 +3322,10 @@ static irqreturn_t tg3_interrupt(int irq, void *dev_id, struct pt_regs *regs) if (tg3_irq_sync(tp)) goto out; sblk->status &= ~SD_STATUS_UPDATED; - if (likely(tg3_has_work(tp))) + if (likely(tg3_has_work(tp))) { + prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]); netif_rx_schedule(dev); /* schedule NAPI poll */ - else { + } else { /* No work, shared interrupt perhaps? re-enable * interrupts, and flush that PCI write */ @@ -3359,7 +3351,7 @@ static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id, struct pt_regs *r * Reading the PCI State register will confirm whether the * interrupt is ours and will flush the status block. */ - if ((sblk->status & SD_STATUS_UPDATED) || + if ((sblk->status_tag != tp->last_tag) || !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { /* * writing any value to intr-mbox-0 clears PCI INTA# and @@ -3370,19 +3362,17 @@ static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id, struct pt_regs *r */ tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); - tp->last_tag = sblk->status_tag; - rmb(); if (tg3_irq_sync(tp)) goto out; - sblk->status &= ~SD_STATUS_UPDATED; - if (likely(tg3_has_work(tp))) - netif_rx_schedule(dev); /* schedule NAPI poll */ - else { - /* no work, shared interrupt perhaps? re-enable - * interrupts, and flush that PCI write + if (netif_rx_schedule_prep(dev)) { + prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]); + /* Update last_tag to mark that this status has been + * seen. Because interrupt may be shared, we may be + * racing with tg3_poll(), so only update last_tag + * if tg3_poll() is not scheduled. */ - tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, - tp->last_tag << 24); + tp->last_tag = sblk->status_tag; + __netif_rx_schedule(dev); } } else { /* shared interrupt */ handled = 0; @@ -3716,8 +3706,11 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev) tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry); tp->tx_prod = entry; - if (TX_BUFFS_AVAIL(tp) <= (MAX_SKB_FRAGS + 1)) + if (TX_BUFFS_AVAIL(tp) <= (MAX_SKB_FRAGS + 1)) { netif_stop_queue(dev); + if (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH) + netif_wake_queue(tp->dev); + } out_unlock: mmiowb(); @@ -5960,7 +5953,7 @@ static int tg3_reset_hw(struct tg3 *tp) tw32(MAC_LED_CTRL, tp->led_ctrl); tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); - if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) { + if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) { tw32_f(MAC_RX_MODE, RX_MODE_RESET); udelay(10); } @@ -6242,6 +6235,7 @@ static int tg3_test_interrupt(struct tg3 *tp) if (err) return err; + tp->hw_status->status &= ~SD_STATUS_UPDATED; tg3_enable_ints(tp); tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | @@ -7557,6 +7551,38 @@ static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf) } } +static int tg3_phys_id(struct net_device *dev, u32 data) +{ + struct tg3 *tp = netdev_priv(dev); + int i; + + if (!netif_running(tp->dev)) + return -EAGAIN; + + if (data == 0) + data = 2; + + for (i = 0; i < (data * 2); i++) { + if ((i % 2) == 0) + tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | + LED_CTRL_1000MBPS_ON | + LED_CTRL_100MBPS_ON | + LED_CTRL_10MBPS_ON | + LED_CTRL_TRAFFIC_OVERRIDE | + LED_CTRL_TRAFFIC_BLINK | + LED_CTRL_TRAFFIC_LED); + + else + tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | + LED_CTRL_TRAFFIC_OVERRIDE); + + if (msleep_interruptible(500)) + break; + } + tw32(MAC_LED_CTRL, tp->led_ctrl); + return 0; +} + static void tg3_get_ethtool_stats (struct net_device *dev, struct ethtool_stats *estats, u64 *tmp_stats) { @@ -7616,7 +7642,7 @@ static int tg3_test_link(struct tg3 *tp) if (!netif_running(tp->dev)) return -ENODEV; - if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) + if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) max = TG3_SERDES_TIMEOUT_SEC; else max = TG3_COPPER_TIMEOUT_SEC; @@ -7901,9 +7927,12 @@ static int tg3_test_memory(struct tg3 *tp) return err; } -static int tg3_test_loopback(struct tg3 *tp) +#define TG3_MAC_LOOPBACK 0 +#define TG3_PHY_LOOPBACK 1 + +static int tg3_run_loopback(struct tg3 *tp, int loopback_mode) { - u32 mac_mode, send_idx, rx_start_idx, rx_idx, tx_idx, opaque_key; + u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key; u32 desc_idx; struct sk_buff *skb, *rx_skb; u8 *tx_data; @@ -7911,18 +7940,26 @@ static int tg3_test_loopback(struct tg3 *tp) int num_pkts, tx_len, rx_len, i, err; struct tg3_rx_buffer_desc *desc; - if (!netif_running(tp->dev)) - return -ENODEV; + if (loopback_mode == TG3_MAC_LOOPBACK) { + mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | + MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY | + MAC_MODE_PORT_MODE_GMII; + tw32(MAC_MODE, mac_mode); + } else if (loopback_mode == TG3_PHY_LOOPBACK) { + mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | + MAC_MODE_LINK_POLARITY | MAC_MODE_PORT_MODE_GMII; + if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) + mac_mode &= ~MAC_MODE_LINK_POLARITY; + tw32(MAC_MODE, mac_mode); + + tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK | BMCR_FULLDPLX | + BMCR_SPEED1000); + } + else + return -EINVAL; err = -EIO; - tg3_reset_hw(tp); - - mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | - MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY | - MAC_MODE_PORT_MODE_GMII; - tw32(MAC_MODE, mac_mode); - tx_len = 1514; skb = dev_alloc_skb(tx_len); tx_data = skb_put(skb, tx_len); @@ -7943,15 +7980,15 @@ static int tg3_test_loopback(struct tg3 *tp) rx_start_idx = tp->hw_status->idx[0].rx_producer; - send_idx = 0; num_pkts = 0; - tg3_set_txd(tp, send_idx, map, tx_len, 0, 1); + tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1); - send_idx++; + tp->tx_prod++; num_pkts++; - tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, send_idx); + tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, + tp->tx_prod); tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW); udelay(10); @@ -7964,7 +8001,7 @@ static int tg3_test_loopback(struct tg3 *tp) tx_idx = tp->hw_status->idx[0].tx_consumer; rx_idx = tp->hw_status->idx[0].rx_producer; - if ((tx_idx == send_idx) && + if ((tx_idx == tp->tx_prod) && (rx_idx == (rx_start_idx + num_pkts))) break; } @@ -7972,7 +8009,7 @@ static int tg3_test_loopback(struct tg3 *tp) pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE); dev_kfree_skb(skb); - if (tx_idx != send_idx) + if (tx_idx != tp->tx_prod) goto out; if (rx_idx != rx_start_idx + num_pkts) @@ -8008,6 +8045,30 @@ out: return err; } +#define TG3_MAC_LOOPBACK_FAILED 1 +#define TG3_PHY_LOOPBACK_FAILED 2 +#define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \ + TG3_PHY_LOOPBACK_FAILED) + +static int tg3_test_loopback(struct tg3 *tp) +{ + int err = 0; + + if (!netif_running(tp->dev)) + return TG3_LOOPBACK_FAILED; + + tg3_reset_hw(tp); + + if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK)) + err |= TG3_MAC_LOOPBACK_FAILED; + if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) { + if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK)) + err |= TG3_PHY_LOOPBACK_FAILED; + } + + return err; +} + static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, u64 *data) { @@ -8048,10 +8109,8 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, etest->flags |= ETH_TEST_FL_FAILED; data[3] = 1; } - if (tg3_test_loopback(tp) != 0) { + if ((data[4] = tg3_test_loopback(tp)) != 0) etest->flags |= ETH_TEST_FL_FAILED; - data[4] = 1; - } tg3_full_unlock(tp); @@ -8239,6 +8298,7 @@ static struct ethtool_ops tg3_ethtool_ops = { .self_test_count = tg3_get_test_count, .self_test = tg3_self_test, .get_strings = tg3_get_strings, + .phys_id = tg3_phys_id, .get_stats_count = tg3_get_stats_count, .get_ethtool_stats = tg3_get_ethtool_stats, .get_coalesce = tg3_get_coalesce, @@ -8303,7 +8363,8 @@ static void __devinit tg3_get_nvram_info(struct tg3 *tp) tw32(NVRAM_CFG1, nvcfg1); } - if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) { + if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) || + (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)) { switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: tp->nvram_jedecnum = JEDEC_ATMEL; @@ -8717,8 +8778,9 @@ static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, if (i == (len - 4)) nvram_cmd |= NVRAM_CMD_LAST; - if ((tp->nvram_jedecnum == JEDEC_ST) && - (nvram_cmd & NVRAM_CMD_FIRST)) { + if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) && + (tp->nvram_jedecnum == JEDEC_ST) && + (nvram_cmd & NVRAM_CMD_FIRST)) { if ((ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_WREN | NVRAM_CMD_GO | diff --git a/drivers/net/tun.c b/drivers/net/tun.c index effab0b9adc..50b8c6754b1 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -18,6 +18,9 @@ /* * Changes: * + * Mike Kershaw <dragorn@kismetwireless.net> 2005/08/14 + * Add TUNSETLINK ioctl to set the link encapsulation + * * Mark Smith <markzzzsmith@yahoo.com.au> * Use random_ether_addr() for tap MAC address. * @@ -612,6 +615,18 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file, DBG(KERN_INFO "%s: owner set to %d\n", tun->dev->name, tun->owner); break; + case TUNSETLINK: + /* Only allow setting the type when the interface is down */ + if (tun->dev->flags & IFF_UP) { + DBG(KERN_INFO "%s: Linktype set failed because interface is up\n", + tun->dev->name); + return -EBUSY; + } else { + tun->dev->type = (int) arg; + DBG(KERN_INFO "%s: linktype set to %d\n", tun->dev->name, tun->dev->type); + } + break; + #ifdef TUN_DEBUG case TUNSETDEBUG: tun->debug = arg; diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c index 6db1fb6461d..dbcb5a8a219 100644 --- a/drivers/net/wireless/airo.c +++ b/drivers/net/wireless/airo.c @@ -1308,7 +1308,7 @@ static int micsetup(struct airo_info *ai) { int i; if (ai->tfm == NULL) - ai->tfm = crypto_alloc_tfm("aes", 0); + ai->tfm = crypto_alloc_tfm("aes", CRYPTO_TFM_REQ_MAY_SLEEP); if (ai->tfm == NULL) { printk(KERN_ERR "airo: failed to load transform for AES\n"); @@ -2239,7 +2239,7 @@ static void airo_read_stats(struct airo_info *ai) { u32 *vals = stats_rid.vals; clear_bit(JOB_STATS, &ai->flags); - if (ai->power) { + if (ai->power.event) { up(&ai->sem); return; } @@ -2410,8 +2410,7 @@ void stop_airo_card( struct net_device *dev, int freeres ) } } #ifdef MICSUPPORT - if (ai->tfm) - crypto_free_tfm(ai->tfm); + crypto_free_tfm(ai->tfm); #endif del_airo_dev( dev ); free_netdev( dev ); @@ -2969,7 +2968,7 @@ static int airo_thread(void *data) { break; } - if (ai->power || test_bit(FLAG_FLASHING, &ai->flags)) { + if (ai->power.event || test_bit(FLAG_FLASHING, &ai->flags)) { up(&ai->sem); continue; } @@ -5521,7 +5520,7 @@ static int airo_pci_resume(struct pci_dev *pdev) pci_restore_state(pdev); pci_enable_wake(pdev, pci_choose_state(pdev, ai->power), 0); - if (ai->power > 1) { + if (ai->power.event > 1) { reset_card(dev, 0); mpi_init_descriptors(ai); setup_card(ai, dev->dev_addr, 0); @@ -7123,7 +7122,7 @@ static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) int rc = 0; struct airo_info *ai = (struct airo_info *)dev->priv; - if (ai->power) + if (ai->power.event) return 0; switch (cmd) { @@ -7202,7 +7201,7 @@ static void airo_read_wireless_stats(struct airo_info *local) /* Get stats out of the card */ clear_bit(JOB_WSTATS, &local->flags); - if (local->power) { + if (local->power.event) { up(&local->sem); return; } diff --git a/drivers/net/wireless/hostap/hostap_pci.c b/drivers/net/wireless/hostap/hostap_pci.c index 4f567ef6178..025f8cdb556 100644 --- a/drivers/net/wireless/hostap/hostap_pci.c +++ b/drivers/net/wireless/hostap/hostap_pci.c @@ -416,7 +416,7 @@ static int prism2_pci_suspend(struct pci_dev *pdev, pm_message_t state) prism2_suspend(dev); pci_save_state(pdev); pci_disable_device(pdev); - pci_set_power_state(pdev, 3); + pci_set_power_state(pdev, PCI_D3hot); return 0; } diff --git a/drivers/net/wireless/ipw2200.c b/drivers/net/wireless/ipw2200.c index 6d0b6b1df4c..2a3bd607a5c 100644 --- a/drivers/net/wireless/ipw2200.c +++ b/drivers/net/wireless/ipw2200.c @@ -7225,7 +7225,7 @@ static void ipw_pci_remove(struct pci_dev *pdev) #ifdef CONFIG_PM -static int ipw_pci_suspend(struct pci_dev *pdev, u32 state) +static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state) { struct ipw_priv *priv = pci_get_drvdata(pdev); struct net_device *dev = priv->net_dev; @@ -7240,7 +7240,7 @@ static int ipw_pci_suspend(struct pci_dev *pdev, u32 state) pci_save_state(pdev); pci_disable_device(pdev); - pci_set_power_state(pdev, state); + pci_set_power_state(pdev, pci_choose_state(pdev, state)); return 0; } diff --git a/drivers/net/wireless/ipw2200.h b/drivers/net/wireless/ipw2200.h index 3bff09d9315..dc3e7bc805f 100644 --- a/drivers/net/wireless/ipw2200.h +++ b/drivers/net/wireless/ipw2200.h @@ -45,6 +45,7 @@ #include <linux/firmware.h> #include <linux/wireless.h> +#include <linux/dma-mapping.h> #include <asm/io.h> #include <net/ieee80211.h> diff --git a/drivers/net/wireless/orinoco_pci.c b/drivers/net/wireless/orinoco_pci.c index 7a6f52ea7fa..42e03438291 100644 --- a/drivers/net/wireless/orinoco_pci.c +++ b/drivers/net/wireless/orinoco_pci.c @@ -301,8 +301,6 @@ static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state) unsigned long flags; int err; - printk(KERN_DEBUG "%s: Orinoco-PCI entering sleep mode (state=%d)\n", - dev->name, state); err = orinoco_lock(priv, &flags); if (err) { diff --git a/drivers/net/wireless/prism54/islpci_hotplug.c b/drivers/net/wireless/prism54/islpci_hotplug.c index c17391d947f..dc040caab7d 100644 --- a/drivers/net/wireless/prism54/islpci_hotplug.c +++ b/drivers/net/wireless/prism54/islpci_hotplug.c @@ -267,8 +267,6 @@ prism54_suspend(struct pci_dev *pdev, pm_message_t state) islpci_private *priv = ndev ? netdev_priv(ndev) : NULL; BUG_ON(!priv); - printk(KERN_NOTICE "%s: got suspend request (state %d)\n", - ndev->name, state); pci_save_state(pdev); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 1b34fc56067..c62d2f04339 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -333,13 +333,17 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state) if (platform_pci_choose_state) { ret = platform_pci_choose_state(dev, state); if (ret >= 0) - state = ret; + state.event = ret; } - switch (state) { - case 0: return PCI_D0; - case 3: return PCI_D3hot; + + switch (state.event) { + case PM_EVENT_ON: + return PCI_D0; + case PM_EVENT_FREEZE: + case PM_EVENT_SUSPEND: + return PCI_D3hot; default: - printk("They asked me for state %d\n", state); + printk("They asked me for state %d\n", state.event); BUG(); } return PCI_D0; diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index bb36bb69803..140354a2aa7 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -422,6 +422,25 @@ static void __devinit quirk_via_ioapic(struct pci_dev *dev) DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic ); /* + * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit. + * This leads to doubled level interrupt rates. + * Set this bit to get rid of cycle wastage. + * Otherwise uncritical. + */ +static void __devinit quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev) +{ + u8 misc_control2; +#define BYPASS_APIC_DEASSERT 8 + + pci_read_config_byte(dev, 0x5B, &misc_control2); + if (!(misc_control2 & BYPASS_APIC_DEASSERT)) { + printk(KERN_INFO "PCI: Bypassing VIA 8237 APIC De-Assert Message\n"); + pci_write_config_byte(dev, 0x5B, misc_control2|BYPASS_APIC_DEASSERT); + } +} +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert); + +/* * The AMD io apic can hang the box when an apic irq is masked. * We check all revs >= B0 (yet not in the pre production!) as the bug * is currently marked NoFix diff --git a/drivers/s390/block/Kconfig b/drivers/s390/block/Kconfig index dc1c89dbdb8..6e7d7b06421 100644 --- a/drivers/s390/block/Kconfig +++ b/drivers/s390/block/Kconfig @@ -49,7 +49,7 @@ config DASD_FBA config DASD_DIAG tristate "Support for DIAG access to Disks" - depends on DASD && ARCH_S390X = 'n' + depends on DASD && ( ARCH_S390X = 'n' || EXPERIMENTAL) help Select this option if you want to use Diagnose250 command to access Disks under VM. If you are not running under VM or unsure what it is, diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c index d5f53980749..8fc891a9d47 100644 --- a/drivers/s390/block/dasd.c +++ b/drivers/s390/block/dasd.c @@ -7,7 +7,7 @@ * Bugreports.to..: <Linux390@de.ibm.com> * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001 * - * $Revision: 1.165 $ + * $Revision: 1.167 $ */ #include <linux/config.h> @@ -1131,17 +1131,13 @@ __dasd_process_blk_queue(struct dasd_device * device) request_queue_t *queue; struct request *req; struct dasd_ccw_req *cqr; - int nr_queued, feature_ro; + int nr_queued; queue = device->request_queue; /* No queue ? Then there is nothing to do. */ if (queue == NULL) return; - feature_ro = dasd_get_feature(device->cdev, DASD_FEATURE_READONLY); - if (feature_ro < 0) /* no devmap */ - return; - /* * We requeue request from the block device queue to the ccw * queue only in two states. In state DASD_STATE_READY the @@ -1162,7 +1158,8 @@ __dasd_process_blk_queue(struct dasd_device * device) nr_queued < DASD_CHANQ_MAX_SIZE) { req = elv_next_request(queue); - if (feature_ro && rq_data_dir(req) == WRITE) { + if (device->features & DASD_FEATURE_READONLY && + rq_data_dir(req) == WRITE) { DBF_DEV_EVENT(DBF_ERR, device, "Rejecting write request %p", req); @@ -1814,17 +1811,13 @@ dasd_generic_set_online (struct ccw_device *cdev, { struct dasd_device *device; - int feature_diag, rc; + int rc; device = dasd_create_device(cdev); if (IS_ERR(device)) return PTR_ERR(device); - feature_diag = dasd_get_feature(cdev, DASD_FEATURE_USEDIAG); - if (feature_diag < 0) - return feature_diag; - - if (feature_diag) { + if (device->features & DASD_FEATURE_USEDIAG) { if (!dasd_diag_discipline_pointer) { printk (KERN_WARNING "dasd_generic couldn't online device %s " diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c index d948566bb24..bda896d9d78 100644 --- a/drivers/s390/block/dasd_devmap.c +++ b/drivers/s390/block/dasd_devmap.c @@ -11,7 +11,7 @@ * functions may not be called from interrupt context. In particular * dasd_get_device is a no-no from interrupt context. * - * $Revision: 1.40 $ + * $Revision: 1.43 $ */ #include <linux/config.h> @@ -513,6 +513,7 @@ dasd_create_device(struct ccw_device *cdev) if (!devmap->device) { devmap->device = device; device->devindex = devmap->devindex; + device->features = devmap->features; get_device(&cdev->dev); device->cdev = cdev; rc = 0; @@ -643,6 +644,8 @@ dasd_ro_store(struct device *dev, struct device_attribute *attr, const char *buf devmap->features |= DASD_FEATURE_READONLY; else devmap->features &= ~DASD_FEATURE_READONLY; + if (devmap->device) + devmap->device->features = devmap->features; if (devmap->device && devmap->device->gdp) set_disk_ro(devmap->device->gdp, ro_flag); spin_unlock(&dasd_devmap_lock); @@ -758,7 +761,8 @@ dasd_set_feature(struct ccw_device *cdev, int feature, int flag) devmap->features |= feature; else devmap->features &= ~feature; - + if (devmap->device) + devmap->device->features = devmap->features; spin_unlock(&dasd_devmap_lock); return 0; } diff --git a/drivers/s390/block/dasd_diag.c b/drivers/s390/block/dasd_diag.c index 127699830fa..7478423b53b 100644 --- a/drivers/s390/block/dasd_diag.c +++ b/drivers/s390/block/dasd_diag.c @@ -6,17 +6,18 @@ * Bugreports.to..: <Linux390@de.ibm.com> * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000 * - * $Revision: 1.42 $ + * $Revision: 1.49 $ */ #include <linux/config.h> #include <linux/stddef.h> #include <linux/kernel.h> #include <linux/slab.h> -#include <linux/hdreg.h> /* HDIO_GETGEO */ +#include <linux/hdreg.h> #include <linux/bio.h> #include <linux/module.h> #include <linux/init.h> +#include <linux/jiffies.h> #include <asm/dasd.h> #include <asm/debug.h> @@ -28,58 +29,89 @@ #include "dasd_int.h" #include "dasd_diag.h" -#ifdef PRINTK_HEADER -#undef PRINTK_HEADER -#endif /* PRINTK_HEADER */ #define PRINTK_HEADER "dasd(diag):" MODULE_LICENSE("GPL"); +/* The maximum number of blocks per request (max_blocks) is dependent on the + * amount of storage that is available in the static I/O buffer for each + * device. Currently each device gets 2 pages. We want to fit two requests + * into the available memory so that we can immediately start the next if one + * finishes. */ +#define DIAG_MAX_BLOCKS (((2 * PAGE_SIZE - sizeof(struct dasd_ccw_req) - \ + sizeof(struct dasd_diag_req)) / \ + sizeof(struct dasd_diag_bio)) / 2) +#define DIAG_MAX_RETRIES 32 +#define DIAG_TIMEOUT 50 * HZ + struct dasd_discipline dasd_diag_discipline; struct dasd_diag_private { struct dasd_diag_characteristics rdc_data; struct dasd_diag_rw_io iob; struct dasd_diag_init_io iib; - unsigned int pt_block; + blocknum_t pt_block; }; struct dasd_diag_req { - int block_count; + unsigned int block_count; struct dasd_diag_bio bio[0]; }; +static const u8 DASD_DIAG_CMS1[] = { 0xc3, 0xd4, 0xe2, 0xf1 };/* EBCDIC CMS1 */ + +/* Perform DIAG250 call with block I/O parameter list iob (input and output) + * and function code cmd. + * In case of an exception return 3. Otherwise return result of bitwise OR of + * resulting condition code and DIAG return code. */ static __inline__ int dia250(void *iob, int cmd) { + typedef struct { + char _[max(sizeof (struct dasd_diag_init_io), + sizeof (struct dasd_diag_rw_io))]; + } addr_type; int rc; - __asm__ __volatile__(" lhi %0,3\n" - " lr 0,%2\n" - " diag 0,%1,0x250\n" - "0: ipm %0\n" - " srl %0,28\n" - " or %0,1\n" - "1:\n" -#ifndef CONFIG_ARCH_S390X - ".section __ex_table,\"a\"\n" - " .align 4\n" - " .long 0b,1b\n" - ".previous\n" + __asm__ __volatile__( +#ifdef CONFIG_ARCH_S390X + " lghi %0,3\n" + " lgr 0,%3\n" + " diag 0,%2,0x250\n" + "0: ipm %0\n" + " srl %0,28\n" + " or %0,1\n" + "1:\n" + ".section __ex_table,\"a\"\n" + " .align 8\n" + " .quad 0b,1b\n" + ".previous\n" #else - ".section __ex_table,\"a\"\n" - " .align 8\n" - " .quad 0b,1b\n" - ".previous\n" + " lhi %0,3\n" + " lr 0,%3\n" + " diag 0,%2,0x250\n" + "0: ipm %0\n" + " srl %0,28\n" + " or %0,1\n" + "1:\n" + ".section __ex_table,\"a\"\n" + " .align 4\n" + " .long 0b,1b\n" + ".previous\n" #endif - : "=&d" (rc) - : "d" (cmd), "d" ((void *) __pa(iob)) - : "0", "1", "cc"); + : "=&d" (rc), "=m" (*(addr_type *) iob) + : "d" (cmd), "d" (iob), "m" (*(addr_type *) iob) + : "0", "1", "cc"); return rc; } +/* Initialize block I/O to DIAG device using the specified blocksize and + * block offset. On success, return zero and set end_block to contain the + * number of blocks on the device minus the specified offset. Return non-zero + * otherwise. */ static __inline__ int -mdsk_init_io(struct dasd_device * device, int blocksize, int offset, int size) +mdsk_init_io(struct dasd_device *device, unsigned int blocksize, + blocknum_t offset, blocknum_t *end_block) { struct dasd_diag_private *private; struct dasd_diag_init_io *iib; @@ -92,14 +124,18 @@ mdsk_init_io(struct dasd_device * device, int blocksize, int offset, int size) iib->dev_nr = _ccw_device_get_device_number(device->cdev); iib->block_size = blocksize; iib->offset = offset; - iib->start_block = 0; - iib->end_block = size; + iib->flaga = DASD_DIAG_FLAGA_DEFAULT; rc = dia250(iib, INIT_BIO); - return rc & 3; + if ((rc & 3) == 0 && end_block) + *end_block = iib->end_block; + + return rc; } +/* Remove block I/O environment for device. Return zero on success, non-zero + * otherwise. */ static __inline__ int mdsk_term_io(struct dasd_device * device) { @@ -112,9 +148,25 @@ mdsk_term_io(struct dasd_device * device) memset(iib, 0, sizeof (struct dasd_diag_init_io)); iib->dev_nr = _ccw_device_get_device_number(device->cdev); rc = dia250(iib, TERM_BIO); - return rc & 3; + return rc; +} + +/* Error recovery for failed DIAG requests - try to reestablish the DIAG + * environment. */ +static void +dasd_diag_erp(struct dasd_device *device) +{ + int rc; + + mdsk_term_io(device); + rc = mdsk_init_io(device, device->bp_block, 0, NULL); + if (rc) + DEV_MESSAGE(KERN_WARNING, device, "DIAG ERP unsuccessful, " + "rc=%d", rc); } +/* Start a given request at the device. Return zero on success, non-zero + * otherwise. */ static int dasd_start_diag(struct dasd_ccw_req * cqr) { @@ -124,32 +176,66 @@ dasd_start_diag(struct dasd_ccw_req * cqr) int rc; device = cqr->device; + if (cqr->retries < 0) { + DEV_MESSAGE(KERN_WARNING, device, "DIAG start_IO: request %p " + "- no retry left)", cqr); + cqr->status = DASD_CQR_FAILED; + return -EIO; + } private = (struct dasd_diag_private *) device->private; dreq = (struct dasd_diag_req *) cqr->data; private->iob.dev_nr = _ccw_device_get_device_number(device->cdev); private->iob.key = 0; - private->iob.flags = 2; /* do asynchronous io */ + private->iob.flags = DASD_DIAG_RWFLAG_ASYNC; private->iob.block_count = dreq->block_count; - private->iob.interrupt_params = (u32)(addr_t) cqr; + private->iob.interrupt_params = (addr_t) cqr; private->iob.bio_list = __pa(dreq->bio); + private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT; cqr->startclk = get_clock(); + cqr->starttime = jiffies; + cqr->retries--; rc = dia250(&private->iob, RW_BIO); - if (rc > 8) { - DEV_MESSAGE(KERN_WARNING, device, "dia250 returned CC %d", rc); - cqr->status = DASD_CQR_ERROR; - } else if (rc == 0) { + switch (rc) { + case 0: /* Synchronous I/O finished successfully */ + cqr->stopclk = get_clock(); cqr->status = DASD_CQR_DONE; - dasd_schedule_bh(device); - } else { + /* Indicate to calling function that only a dasd_schedule_bh() + and no timer is needed */ + rc = -EACCES; + break; + case 8: /* Asynchronous I/O was started */ cqr->status = DASD_CQR_IN_IO; rc = 0; + break; + default: /* Error condition */ + cqr->status = DASD_CQR_QUEUED; + DEV_MESSAGE(KERN_WARNING, device, "dia250 returned rc=%d", rc); + dasd_diag_erp(device); + rc = -EIO; + break; } return rc; } +/* Terminate given request at the device. */ +static int +dasd_diag_term_IO(struct dasd_ccw_req * cqr) +{ + struct dasd_device *device; + + device = cqr->device; + mdsk_term_io(device); + mdsk_init_io(device, device->bp_block, 0, NULL); + cqr->status = DASD_CQR_CLEAR; + cqr->stopclk = get_clock(); + dasd_schedule_bh(device); + return 0; +} + +/* Handle external interruption. */ static void dasd_ext_handler(struct pt_regs *regs, __u16 code) { @@ -157,25 +243,27 @@ dasd_ext_handler(struct pt_regs *regs, __u16 code) struct dasd_device *device; unsigned long long expires; unsigned long flags; - char status; - int ip; - - /* - * Get the external interruption subcode. VM stores - * this in the 'cpu address' field associated with - * the external interrupt. For diag 250 the subcode - * needs to be 3. - */ - if ((S390_lowcore.cpu_addr & 0xff00) != 0x0300) - return; - status = *((char *) &S390_lowcore.ext_params + 5); - ip = S390_lowcore.ext_params; + u8 int_code, status; + addr_t ip; + int rc; + int_code = *((u8 *) DASD_DIAG_LC_INT_CODE); + status = *((u8 *) DASD_DIAG_LC_INT_STATUS); + switch (int_code) { + case DASD_DIAG_CODE_31BIT: + ip = (addr_t) *((u32 *) DASD_DIAG_LC_INT_PARM_31BIT); + break; + case DASD_DIAG_CODE_64BIT: + ip = (addr_t) *((u64 *) DASD_DIAG_LC_INT_PARM_64BIT); + break; + default: + return; + } if (!ip) { /* no intparm: unsolicited interrupt */ MESSAGE(KERN_DEBUG, "%s", "caught unsolicited interrupt"); return; } - cqr = (struct dasd_ccw_req *)(addr_t) ip; + cqr = (struct dasd_ccw_req *) ip; device = (struct dasd_device *) cqr->device; if (strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) { DEV_MESSAGE(KERN_WARNING, device, @@ -188,6 +276,15 @@ dasd_ext_handler(struct pt_regs *regs, __u16 code) /* get irq lock to modify request queue */ spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); + /* Check for a pending clear operation */ + if (cqr->status == DASD_CQR_CLEAR) { + cqr->status = DASD_CQR_QUEUED; + dasd_clear_timer(device); + dasd_schedule_bh(device); + spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); + return; + } + cqr->stopclk = get_clock(); expires = 0; @@ -198,16 +295,22 @@ dasd_ext_handler(struct pt_regs *regs, __u16 code) next = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list); if (next->status == DASD_CQR_QUEUED) { - if (dasd_start_diag(next) == 0) + rc = dasd_start_diag(next); + if (rc == 0) expires = next->expires; - else + else if (rc != -EACCES) DEV_MESSAGE(KERN_WARNING, device, "%s", "Interrupt fastpath " "failed!"); } } - } else - cqr->status = DASD_CQR_FAILED; + } else { + cqr->status = DASD_CQR_QUEUED; + DEV_MESSAGE(KERN_WARNING, device, "interrupt status for " + "request %p was %d (%d retries left)", cqr, status, + cqr->retries); + dasd_diag_erp(device); + } if (expires != 0) dasd_set_timer(device, expires); @@ -218,14 +321,17 @@ dasd_ext_handler(struct pt_regs *regs, __u16 code) spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); } +/* Check whether device can be controlled by DIAG discipline. Return zero on + * success, non-zero otherwise. */ static int dasd_diag_check_device(struct dasd_device *device) { struct dasd_diag_private *private; struct dasd_diag_characteristics *rdc_data; struct dasd_diag_bio bio; - long *label; - int sb, bsize; + struct dasd_diag_cms_label *label; + blocknum_t end_block; + unsigned int sb, bsize; int rc; private = (struct dasd_diag_private *) device->private; @@ -244,8 +350,11 @@ dasd_diag_check_device(struct dasd_device *device) rdc_data->rdc_len = sizeof (struct dasd_diag_characteristics); rc = diag210((struct diag210 *) rdc_data); - if (rc) + if (rc) { + DEV_MESSAGE(KERN_WARNING, device, "failed to retrieve device " + "information (rc=%d)", rc); return -ENOTSUPP; + } /* Figure out position of label block */ switch (private->rdc_data.vdev_class) { @@ -256,6 +365,8 @@ dasd_diag_check_device(struct dasd_device *device) private->pt_block = 2; break; default: + DEV_MESSAGE(KERN_WARNING, device, "unsupported device class " + "(class=%d)", private->rdc_data.vdev_class); return -ENOTSUPP; } @@ -269,15 +380,17 @@ dasd_diag_check_device(struct dasd_device *device) mdsk_term_io(device); /* figure out blocksize of device */ - label = (long *) get_zeroed_page(GFP_KERNEL); + label = (struct dasd_diag_cms_label *) get_zeroed_page(GFP_KERNEL); if (label == NULL) { DEV_MESSAGE(KERN_WARNING, device, "%s", "No memory to allocate initialization request"); return -ENOMEM; } + rc = 0; + end_block = 0; /* try all sizes - needed for ECKD devices */ for (bsize = 512; bsize <= PAGE_SIZE; bsize <<= 1) { - mdsk_init_io(device, bsize, 0, 64); + mdsk_init_io(device, bsize, 0, &end_block); memset(&bio, 0, sizeof (struct dasd_diag_bio)); bio.type = MDSK_READ_REQ; bio.block_number = private->pt_block + 1; @@ -289,37 +402,45 @@ dasd_diag_check_device(struct dasd_device *device) private->iob.block_count = 1; private->iob.interrupt_params = 0; private->iob.bio_list = __pa(&bio); - if (dia250(&private->iob, RW_BIO) == 0) + private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT; + rc = dia250(&private->iob, RW_BIO); + if (rc == 0 || rc == 3) break; mdsk_term_io(device); } - if (bsize <= PAGE_SIZE && label[0] == 0xc3d4e2f1) { - /* get formatted blocksize from label block */ - bsize = (int) label[3]; - device->blocks = label[7]; + if (rc == 3) { + DEV_MESSAGE(KERN_WARNING, device, "%s", "DIAG call failed"); + rc = -EOPNOTSUPP; + } else if (rc != 0) { + DEV_MESSAGE(KERN_WARNING, device, "device access failed " + "(rc=%d)", rc); + rc = -EIO; + } else { + if (memcmp(label->label_id, DASD_DIAG_CMS1, + sizeof(DASD_DIAG_CMS1)) == 0) { + /* get formatted blocksize from label block */ + bsize = (unsigned int) label->block_size; + device->blocks = (unsigned long) label->block_count; + } else + device->blocks = end_block; device->bp_block = bsize; device->s2b_shift = 0; /* bits to shift 512 to get a block */ for (sb = 512; sb < bsize; sb = sb << 1) device->s2b_shift++; DEV_MESSAGE(KERN_INFO, device, - "capacity (%dkB blks): %ldkB", - (device->bp_block >> 10), - (device->blocks << device->s2b_shift) >> 1); + "(%ld B/blk): %ldkB", + (unsigned long) device->bp_block, + (unsigned long) (device->blocks << + device->s2b_shift) >> 1); rc = 0; - } else { - if (bsize > PAGE_SIZE) - DEV_MESSAGE(KERN_WARNING, device, "%s", - "DIAG access failed"); - else - DEV_MESSAGE(KERN_WARNING, device, "%s", - "volume is not CMS formatted"); - rc = -EMEDIUMTYPE; } free_page((long) label); return rc; } +/* Fill in virtual disk geometry for device. Return zero on success, non-zero + * otherwise. */ static int dasd_diag_fill_geometry(struct dasd_device *device, struct hd_geometry *geo) { @@ -349,6 +470,8 @@ dasd_diag_erp_postaction(struct dasd_ccw_req * cqr) return dasd_default_erp_postaction; } +/* Create DASD request from block device request. Return pointer to new + * request on success, ERR_PTR otherwise. */ static struct dasd_ccw_req * dasd_diag_build_cp(struct dasd_device * device, struct request *req) { @@ -358,9 +481,9 @@ dasd_diag_build_cp(struct dasd_device * device, struct request *req) struct bio *bio; struct bio_vec *bv; char *dst; - int count, datasize; + unsigned int count, datasize; sector_t recid, first_rec, last_rec; - unsigned blksize, off; + unsigned int blksize, off; unsigned char rw_cmd; int i; @@ -413,13 +536,16 @@ dasd_diag_build_cp(struct dasd_device * device, struct request *req) } } } + cqr->retries = DIAG_MAX_RETRIES; cqr->buildclk = get_clock(); cqr->device = device; - cqr->expires = 50 * HZ; /* 50 seconds */ + cqr->expires = DIAG_TIMEOUT; cqr->status = DASD_CQR_FILLED; return cqr; } +/* Release DASD request. Return non-zero if request was successful, zero + * otherwise. */ static int dasd_diag_free_cp(struct dasd_ccw_req *cqr, struct request *req) { @@ -430,6 +556,7 @@ dasd_diag_free_cp(struct dasd_ccw_req *cqr, struct request *req) return status; } +/* Fill in IOCTL data for device. */ static int dasd_diag_fill_info(struct dasd_device * device, struct dasd_information2_t * info) @@ -437,7 +564,7 @@ dasd_diag_fill_info(struct dasd_device * device, struct dasd_diag_private *private; private = (struct dasd_diag_private *) device->private; - info->label_block = private->pt_block; + info->label_block = (unsigned int) private->pt_block; info->FBA_layout = 1; info->format = DASD_FORMAT_LDL; info->characteristics_size = sizeof (struct dasd_diag_characteristics); @@ -456,26 +583,15 @@ dasd_diag_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req, "dump sense not available for DIAG data"); } -/* - * max_blocks is dependent on the amount of storage that is available - * in the static io buffer for each device. Currently each device has - * 8192 bytes (=2 pages). dasd diag is only relevant for 31 bit. - * The struct dasd_ccw_req has 96 bytes, the struct dasd_diag_req has - * 8 bytes and the struct dasd_diag_bio for each block has 16 bytes. - * That makes: - * (8192 - 96 - 8) / 16 = 505.5 blocks at maximum. - * We want to fit two into the available memory so that we can immediately - * start the next request if one finishes off. That makes 252.75 blocks - * for one request. Give a little safety and the result is 240. - */ struct dasd_discipline dasd_diag_discipline = { .owner = THIS_MODULE, .name = "DIAG", .ebcname = "DIAG", - .max_blocks = 240, + .max_blocks = DIAG_MAX_BLOCKS, .check_device = dasd_diag_check_device, .fill_geometry = dasd_diag_fill_geometry, .start_IO = dasd_start_diag, + .term_IO = dasd_diag_term_IO, .examine_error = dasd_diag_examine_error, .erp_action = dasd_diag_erp_action, .erp_postaction = dasd_diag_erp_postaction, @@ -493,7 +609,7 @@ dasd_diag_init(void) "Machine is not VM: %s " "discipline not initializing", dasd_diag_discipline.name); - return -EINVAL; + return -ENODEV; } ASCEBC(dasd_diag_discipline.ebcname, 4); @@ -506,13 +622,6 @@ dasd_diag_init(void) static void __exit dasd_diag_cleanup(void) { - if (!MACHINE_IS_VM) { - MESSAGE_LOG(KERN_INFO, - "Machine is not VM: %s " - "discipline not cleaned", - dasd_diag_discipline.name); - return; - } unregister_external_interrupt(0x2603, dasd_ext_handler); ctl_clear_bit(0, 9); dasd_diag_discipline_pointer = NULL; @@ -520,22 +629,3 @@ dasd_diag_cleanup(void) module_init(dasd_diag_init); module_exit(dasd_diag_cleanup); - -/* - * Overrides for Emacs so that we follow Linus's tabbing style. - * Emacs will notice this stuff at the end of the file and automatically - * adjust the settings for this buffer only. This must remain at the end - * of the file. - * --------------------------------------------------------------------------- - * Local variables: - * c-indent-level: 4 - * c-brace-imaginary-offset: 0 - * c-brace-offset: -4 - * c-argdecl-indent: 4 - * c-label-offset: -4 - * c-continued-statement-offset: 4 - * c-continued-brace-offset: 0 - * indent-tabs-mode: 1 - * tab-width: 8 - * End: - */ diff --git a/drivers/s390/block/dasd_diag.h b/drivers/s390/block/dasd_diag.h index a0c38e30397..b26eb28df4b 100644 --- a/drivers/s390/block/dasd_diag.h +++ b/drivers/s390/block/dasd_diag.h @@ -6,7 +6,7 @@ * Bugreports.to..: <Linux390@de.ibm.com> * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000 * - * $Revision: 1.6 $ + * $Revision: 1.7 $ */ #define MDSK_WRITE_REQ 0x01 @@ -19,6 +19,18 @@ #define DEV_CLASS_FBA 0x01 #define DEV_CLASS_ECKD 0x04 +#define DASD_DIAG_LC_INT_CODE 132 +#define DASD_DIAG_LC_INT_STATUS 133 +#define DASD_DIAG_LC_INT_PARM_31BIT 128 +#define DASD_DIAG_LC_INT_PARM_64BIT 4536 +#define DASD_DIAG_CODE_31BIT 0x03 +#define DASD_DIAG_CODE_64BIT 0x07 + +#define DASD_DIAG_RWFLAG_ASYNC 0x02 +#define DASD_DIAG_RWFLAG_NOCACHE 0x01 + +#define DASD_DIAG_FLAGA_FORMAT_64BIT 0x80 + struct dasd_diag_characteristics { u16 dev_nr; u16 rdc_len; @@ -32,35 +44,106 @@ struct dasd_diag_characteristics { u8 rdev_features; } __attribute__ ((packed, aligned(4))); +struct dasd_diag_cms_label { + u8 label_id[4]; + u8 vol_id[6]; + u16 version_id; + u32 block_size; + u32 origin_ptr; + u32 usable_count; + u32 formatted_count; + u32 block_count; + u32 used_count; + u32 fst_size; + u32 fst_count; + u8 format_date[6]; + u8 reserved1[2]; + u32 disk_offset; + u32 map_block; + u32 hblk_disp; + u32 user_disp; + u8 reserved2[4]; + u8 segment_name[8]; +} __attribute__ ((packed)); + +#ifdef CONFIG_ARCH_S390X +#define DASD_DIAG_FLAGA_DEFAULT DASD_DIAG_FLAGA_FORMAT_64BIT + +typedef u64 blocknum_t; +typedef s64 sblocknum_t; + +struct dasd_diag_bio { + u8 type; + u8 status; + u8 spare1[2]; + u32 alet; + blocknum_t block_number; + u64 buffer; +} __attribute__ ((packed, aligned(8))); + +struct dasd_diag_init_io { + u16 dev_nr; + u8 flaga; + u8 spare1[21]; + u32 block_size; + u8 spare2[4]; + blocknum_t offset; + sblocknum_t start_block; + blocknum_t end_block; + u8 spare3[8]; +} __attribute__ ((packed, aligned(8))); + +struct dasd_diag_rw_io { + u16 dev_nr; + u8 flaga; + u8 spare1[21]; + u8 key; + u8 flags; + u8 spare2[2]; + u32 block_count; + u32 alet; + u8 spare3[4]; + u64 interrupt_params; + u64 bio_list; + u8 spare4[8]; +} __attribute__ ((packed, aligned(8))); +#else /* CONFIG_ARCH_S390X */ +#define DASD_DIAG_FLAGA_DEFAULT 0x0 + +typedef u32 blocknum_t; +typedef s32 sblocknum_t; + struct dasd_diag_bio { u8 type; u8 status; u16 spare1; - u32 block_number; + blocknum_t block_number; u32 alet; u32 buffer; } __attribute__ ((packed, aligned(8))); struct dasd_diag_init_io { u16 dev_nr; - u16 spare1[11]; + u8 flaga; + u8 spare1[21]; u32 block_size; - u32 offset; - u32 start_block; - u32 end_block; - u32 spare2[6]; + blocknum_t offset; + sblocknum_t start_block; + blocknum_t end_block; + u8 spare2[24]; } __attribute__ ((packed, aligned(8))); struct dasd_diag_rw_io { u16 dev_nr; - u16 spare1[11]; + u8 flaga; + u8 spare1[21]; u8 key; u8 flags; - u16 spare2; + u8 spare2[2]; u32 block_count; u32 alet; u32 bio_list; u32 interrupt_params; - u32 spare3[5]; + u8 spare3[20]; } __attribute__ ((packed, aligned(8))); - +#endif /* CONFIG_ARCH_S390X */ diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c index 96c49349701..a601c9a3354 100644 --- a/drivers/s390/block/dasd_genhd.c +++ b/drivers/s390/block/dasd_genhd.c @@ -9,7 +9,7 @@ * * gendisk related functions for the dasd driver. * - * $Revision: 1.50 $ + * $Revision: 1.51 $ */ #include <linux/config.h> @@ -31,16 +31,12 @@ int dasd_gendisk_alloc(struct dasd_device *device) { struct gendisk *gdp; - int len, feature_ro; + int len; /* Make sure the minor for this device exists. */ if (device->devindex >= DASD_PER_MAJOR) return -EBUSY; - feature_ro = dasd_get_feature(device->cdev, DASD_FEATURE_READONLY); - if (feature_ro < 0) - return feature_ro; - gdp = alloc_disk(1 << DASD_PARTN_BITS); if (!gdp) return -ENOMEM; @@ -75,7 +71,7 @@ dasd_gendisk_alloc(struct dasd_device *device) sprintf(gdp->devfs_name, "dasd/%s", device->cdev->dev.bus_id); - if (feature_ro) + if (device->features & DASD_FEATURE_READONLY) set_disk_ro(gdp, 1); gdp->private_data = device; gdp->queue = device->request_queue; diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h index a9f38b23598..9fab04f3056 100644 --- a/drivers/s390/block/dasd_int.h +++ b/drivers/s390/block/dasd_int.h @@ -6,7 +6,7 @@ * Bugreports.to..: <Linux390@de.ibm.com> * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000 * - * $Revision: 1.64 $ + * $Revision: 1.65 $ */ #ifndef DASD_INT_H @@ -286,6 +286,7 @@ struct dasd_device { unsigned int bp_block; /* bytes per block */ unsigned int s2b_shift; /* log2 (bp_block/512) */ unsigned long flags; /* per device flags */ + unsigned short features; /* copy of devmap-features (read-only!) */ /* Device discipline stuff. */ struct dasd_discipline *discipline; diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c index 980c555aa53..789595b3fa0 100644 --- a/drivers/s390/block/dasd_ioctl.c +++ b/drivers/s390/block/dasd_ioctl.c @@ -7,7 +7,7 @@ * Bugreports.to..: <Linux390@de.ibm.com> * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001 * - * $Revision: 1.45 $ + * $Revision: 1.47 $ * * i/o controls for the dasd driver. */ @@ -296,7 +296,6 @@ dasd_ioctl_format(struct block_device *bdev, int no, long args) { struct dasd_device *device; struct format_data_t fdata; - int feature_ro; if (!capable(CAP_SYS_ADMIN)) return -EACCES; @@ -308,10 +307,7 @@ dasd_ioctl_format(struct block_device *bdev, int no, long args) if (device == NULL) return -ENODEV; - feature_ro = dasd_get_feature(device->cdev, DASD_FEATURE_READONLY); - if (feature_ro < 0) - return feature_ro; - if (feature_ro) + if (device->features & DASD_FEATURE_READONLY) return -EROFS; if (copy_from_user(&fdata, (void __user *) args, sizeof (struct format_data_t))) @@ -384,7 +380,7 @@ dasd_ioctl_information(struct block_device *bdev, int no, long args) struct dasd_device *device; struct dasd_information2_t *dasd_info; unsigned long flags; - int rc, feature_ro; + int rc; struct ccw_device *cdev; device = bdev->bd_disk->private_data; @@ -394,10 +390,6 @@ dasd_ioctl_information(struct block_device *bdev, int no, long args) if (!device->discipline->fill_info) return -EINVAL; - feature_ro = dasd_get_feature(device->cdev, DASD_FEATURE_READONLY); - if (feature_ro < 0) - return feature_ro; - dasd_info = kmalloc(sizeof(struct dasd_information2_t), GFP_KERNEL); if (dasd_info == NULL) return -ENOMEM; @@ -427,7 +419,8 @@ dasd_ioctl_information(struct block_device *bdev, int no, long args) (dasd_check_blocksize(device->bp_block))) dasd_info->format = DASD_FORMAT_NONE; - dasd_info->features |= feature_ro; + dasd_info->features |= + ((device->features & DASD_FEATURE_READONLY) != 0); if (device->discipline) memcpy(dasd_info->type, device->discipline->name, 4); diff --git a/drivers/s390/block/dasd_proc.c b/drivers/s390/block/dasd_proc.c index 43c34f8c5e6..fff9020d488 100644 --- a/drivers/s390/block/dasd_proc.c +++ b/drivers/s390/block/dasd_proc.c @@ -9,7 +9,7 @@ * * /proc interface for the dasd driver. * - * $Revision: 1.32 $ + * $Revision: 1.33 $ */ #include <linux/config.h> @@ -55,7 +55,6 @@ dasd_devices_show(struct seq_file *m, void *v) { struct dasd_device *device; char *substr; - int feature; device = dasd_device_from_devindex((unsigned long) v - 1); if (IS_ERR(device)) @@ -79,10 +78,7 @@ dasd_devices_show(struct seq_file *m, void *v) else seq_printf(m, " is ????????"); /* Print devices features. */ - feature = dasd_get_feature(device->cdev, DASD_FEATURE_READONLY); - if (feature < 0) - return 0; - substr = feature ? "(ro)" : " "; + substr = (device->features & DASD_FEATURE_READONLY) ? "(ro)" : " "; seq_printf(m, "%4s: ", substr); /* Print device status information. */ switch ((device != NULL) ? device->state : -1) { diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c index d5eefeaba50..328d9cbc56a 100644 --- a/drivers/s390/char/raw3270.c +++ b/drivers/s390/char/raw3270.c @@ -632,12 +632,9 @@ __raw3270_size_device(struct raw3270 *rp) raw3270_init_request.ccw.cda = (__u32) __pa(raw3270_init_data); rc = raw3270_start_init(rp, &raw3270_init_view, &raw3270_init_request); - if (rc) { + if (rc) /* Check error cases: -ERESTARTSYS, -EIO and -EOPNOTSUPP */ - if (rc == -EOPNOTSUPP && MACHINE_IS_VM) - return __raw3270_size_device_vm(rp); return rc; - } /* Wait for attention interrupt. */ #ifdef CONFIG_TN3270_CONSOLE @@ -695,7 +692,10 @@ raw3270_size_device(struct raw3270 *rp) down(&raw3270_init_sem); rp->view = &raw3270_init_view; raw3270_init_view.dev = rp; - rc = __raw3270_size_device(rp); + if (MACHINE_IS_VM) + rc = __raw3270_size_device_vm(rp); + else + rc = __raw3270_size_device(rp); raw3270_init_view.dev = 0; rp->view = 0; up(&raw3270_init_sem); @@ -710,6 +710,12 @@ raw3270_size_device(struct raw3270 *rp) rp->model = 4; if (rp->rows == 27 && rp->cols == 132) rp->model = 5; + } else { + /* Couldn't detect size. Use default model 2. */ + rp->model = 2; + rp->rows = 24; + rp->cols = 80; + return 0; } return rc; } diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c index ea813bdce1d..185bc73c3ec 100644 --- a/drivers/s390/cio/cio.c +++ b/drivers/s390/cio/cio.c @@ -1,7 +1,7 @@ /* * drivers/s390/cio/cio.c * S/390 common I/O routines -- low level i/o calls - * $Revision: 1.134 $ + * $Revision: 1.135 $ * * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH, * IBM Corporation @@ -815,8 +815,9 @@ __clear_subchannel_easy(unsigned int schid) struct tpi_info ti; if (tpi(&ti)) { - tsch(schid, (struct irb *)__LC_IRB); - return 0; + tsch(ti.irq, (struct irb *)__LC_IRB); + if (ti.irq == schid) + return 0; } udelay(100); } diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c index ee7a05e0c3b..fbe4202a3f6 100644 --- a/drivers/s390/cio/device_fsm.c +++ b/drivers/s390/cio/device_fsm.c @@ -13,7 +13,7 @@ #include <linux/init.h> #include <asm/ccwdev.h> -#include <asm/qdio.h> +#include <asm/cio.h> #include "cio.h" #include "cio_debug.h" @@ -21,7 +21,6 @@ #include "device.h" #include "chsc.h" #include "ioasm.h" -#include "qdio.h" int device_is_online(struct subchannel *sch) diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c index 02d01a0de16..ad3fe5aeb66 100644 --- a/drivers/s390/cio/device_ops.c +++ b/drivers/s390/cio/device_ops.c @@ -1,7 +1,7 @@ /* * drivers/s390/cio/device_ops.c * - * $Revision: 1.56 $ + * $Revision: 1.57 $ * * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, * IBM Corporation @@ -19,14 +19,12 @@ #include <asm/ccwdev.h> #include <asm/idals.h> -#include <asm/qdio.h> #include "cio.h" #include "cio_debug.h" #include "css.h" #include "chsc.h" #include "device.h" -#include "qdio.h" int ccw_device_set_options(struct ccw_device *cdev, unsigned long flags) diff --git a/drivers/s390/cio/ioasm.h b/drivers/s390/cio/ioasm.h index c874607d9a8..45480a2bc4c 100644 --- a/drivers/s390/cio/ioasm.h +++ b/drivers/s390/cio/ioasm.h @@ -21,7 +21,7 @@ struct tpi_info { * Some S390 specific IO instructions as inline */ -extern __inline__ int stsch(int irq, volatile struct schib *addr) +static inline int stsch(int irq, volatile struct schib *addr) { int ccode; @@ -36,7 +36,7 @@ extern __inline__ int stsch(int irq, volatile struct schib *addr) return ccode; } -extern __inline__ int msch(int irq, volatile struct schib *addr) +static inline int msch(int irq, volatile struct schib *addr) { int ccode; @@ -51,7 +51,7 @@ extern __inline__ int msch(int irq, volatile struct schib *addr) return ccode; } -extern __inline__ int msch_err(int irq, volatile struct schib *addr) +static inline int msch_err(int irq, volatile struct schib *addr) { int ccode; @@ -79,7 +79,7 @@ extern __inline__ int msch_err(int irq, volatile struct schib *addr) return ccode; } -extern __inline__ int tsch(int irq, volatile struct irb *addr) +static inline int tsch(int irq, volatile struct irb *addr) { int ccode; @@ -94,7 +94,7 @@ extern __inline__ int tsch(int irq, volatile struct irb *addr) return ccode; } -extern __inline__ int tpi( volatile struct tpi_info *addr) +static inline int tpi( volatile struct tpi_info *addr) { int ccode; @@ -108,7 +108,7 @@ extern __inline__ int tpi( volatile struct tpi_info *addr) return ccode; } -extern __inline__ int ssch(int irq, volatile struct orb *addr) +static inline int ssch(int irq, volatile struct orb *addr) { int ccode; @@ -123,7 +123,7 @@ extern __inline__ int ssch(int irq, volatile struct orb *addr) return ccode; } -extern __inline__ int rsch(int irq) +static inline int rsch(int irq) { int ccode; @@ -138,7 +138,7 @@ extern __inline__ int rsch(int irq) return ccode; } -extern __inline__ int csch(int irq) +static inline int csch(int irq) { int ccode; @@ -153,7 +153,7 @@ extern __inline__ int csch(int irq) return ccode; } -extern __inline__ int hsch(int irq) +static inline int hsch(int irq) { int ccode; @@ -168,7 +168,7 @@ extern __inline__ int hsch(int irq) return ccode; } -extern __inline__ int xsch(int irq) +static inline int xsch(int irq) { int ccode; @@ -183,7 +183,7 @@ extern __inline__ int xsch(int irq) return ccode; } -extern __inline__ int chsc(void *chsc_area) +static inline int chsc(void *chsc_area) { int cc; @@ -198,7 +198,7 @@ extern __inline__ int chsc(void *chsc_area) return cc; } -extern __inline__ int iac( void) +static inline int iac( void) { int ccode; @@ -210,7 +210,7 @@ extern __inline__ int iac( void) return ccode; } -extern __inline__ int rchp(int chpid) +static inline int rchp(int chpid) { int ccode; diff --git a/drivers/s390/crypto/z90common.h b/drivers/s390/crypto/z90common.h index bcabac7a7c4..e319e78b5ea 100644 --- a/drivers/s390/crypto/z90common.h +++ b/drivers/s390/crypto/z90common.h @@ -27,7 +27,7 @@ #ifndef _Z90COMMON_H_ #define _Z90COMMON_H_ -#define VERSION_Z90COMMON_H "$Revision: 1.16 $" +#define VERSION_Z90COMMON_H "$Revision: 1.17 $" #define RESPBUFFSIZE 256 @@ -164,5 +164,4 @@ struct CPRBX { #define UMIN(a,b) ((a) < (b) ? (a) : (b)) #define IS_EVEN(x) ((x) == (2 * ((x) / 2))) - #endif diff --git a/drivers/s390/crypto/z90hardware.c b/drivers/s390/crypto/z90hardware.c index beb6a5e0da2..c215e088973 100644 --- a/drivers/s390/crypto/z90hardware.c +++ b/drivers/s390/crypto/z90hardware.c @@ -32,7 +32,7 @@ #include "z90crypt.h" #include "z90common.h" -#define VERSION_Z90HARDWARE_C "$Revision: 1.33 $" +#define VERSION_Z90HARDWARE_C "$Revision: 1.34 $" char z90hardware_version[] __initdata = "z90hardware.o (" VERSION_Z90HARDWARE_C "/" @@ -283,48 +283,6 @@ struct type6_msg { struct CPRB CPRB; }; -union request_msg { - union type4_msg t4msg; - struct type6_msg t6msg; -}; - -struct request_msg_ext { - int q_nr; - unsigned char *psmid; - union request_msg reqMsg; -}; - -struct type82_hdr { - unsigned char reserved1; - unsigned char type; - unsigned char reserved2[2]; - unsigned char reply_code; - unsigned char reserved3[3]; -}; - -#define TYPE82_RSP_CODE 0x82 - -#define REPLY_ERROR_MACHINE_FAILURE 0x10 -#define REPLY_ERROR_PREEMPT_FAILURE 0x12 -#define REPLY_ERROR_CHECKPT_FAILURE 0x14 -#define REPLY_ERROR_MESSAGE_TYPE 0x20 -#define REPLY_ERROR_INVALID_COMM_CD 0x21 -#define REPLY_ERROR_INVALID_MSG_LEN 0x23 -#define REPLY_ERROR_RESERVD_FIELD 0x24 -#define REPLY_ERROR_FORMAT_FIELD 0x29 -#define REPLY_ERROR_INVALID_COMMAND 0x30 -#define REPLY_ERROR_MALFORMED_MSG 0x40 -#define REPLY_ERROR_RESERVED_FIELDO 0x50 -#define REPLY_ERROR_WORD_ALIGNMENT 0x60 -#define REPLY_ERROR_MESSAGE_LENGTH 0x80 -#define REPLY_ERROR_OPERAND_INVALID 0x82 -#define REPLY_ERROR_OPERAND_SIZE 0x84 -#define REPLY_ERROR_EVEN_MOD_IN_OPND 0x85 -#define REPLY_ERROR_RESERVED_FIELD 0x88 -#define REPLY_ERROR_TRANSPORT_FAIL 0x90 -#define REPLY_ERROR_PACKET_TRUNCATED 0xA0 -#define REPLY_ERROR_ZERO_BUFFER_LEN 0xB0 - struct type86_hdr { unsigned char reserved1; unsigned char type; @@ -338,7 +296,7 @@ struct type86_hdr { #define TYPE86_FMT2 0x02 struct type86_fmt2_msg { - struct type86_hdr hdr; + struct type86_hdr header; unsigned char reserved[4]; unsigned char apfs[4]; unsigned int count1; @@ -538,6 +496,8 @@ static struct function_and_rules_block static_pke_function_and_rulesX = { {'M','R','P',' ',' ',' ',' ',' '} }; +static unsigned char static_PKE_function_code[2] = {0x50, 0x4B}; + struct T6_keyBlock_hdrX { unsigned short blen; unsigned short ulen; @@ -688,9 +648,38 @@ static struct cca_public_sec static_cca_pub_sec = { #define RESPONSE_CPRB_SIZE 0x000006B8 #define RESPONSE_CPRBX_SIZE 0x00000724 -#define CALLER_HEADER 12 +struct error_hdr { + unsigned char reserved1; + unsigned char type; + unsigned char reserved2[2]; + unsigned char reply_code; + unsigned char reserved3[3]; +}; -static unsigned char static_PKE_function_code[2] = {0x50, 0x4B}; +#define TYPE82_RSP_CODE 0x82 + +#define REP82_ERROR_MACHINE_FAILURE 0x10 +#define REP82_ERROR_PREEMPT_FAILURE 0x12 +#define REP82_ERROR_CHECKPT_FAILURE 0x14 +#define REP82_ERROR_MESSAGE_TYPE 0x20 +#define REP82_ERROR_INVALID_COMM_CD 0x21 +#define REP82_ERROR_INVALID_MSG_LEN 0x23 +#define REP82_ERROR_RESERVD_FIELD 0x24 +#define REP82_ERROR_FORMAT_FIELD 0x29 +#define REP82_ERROR_INVALID_COMMAND 0x30 +#define REP82_ERROR_MALFORMED_MSG 0x40 +#define REP82_ERROR_RESERVED_FIELDO 0x50 +#define REP82_ERROR_WORD_ALIGNMENT 0x60 +#define REP82_ERROR_MESSAGE_LENGTH 0x80 +#define REP82_ERROR_OPERAND_INVALID 0x82 +#define REP82_ERROR_OPERAND_SIZE 0x84 +#define REP82_ERROR_EVEN_MOD_IN_OPND 0x85 +#define REP82_ERROR_RESERVED_FIELD 0x88 +#define REP82_ERROR_TRANSPORT_FAIL 0x90 +#define REP82_ERROR_PACKET_TRUNCATED 0xA0 +#define REP82_ERROR_ZERO_BUFFER_LEN 0xB0 + +#define CALLER_HEADER 12 static inline int testq(int q_nr, int *q_depth, int *dev_type, struct ap_status_word *stat) @@ -1212,9 +1201,9 @@ send_to_AP(int dev_nr, int cdx, int msg_len, unsigned char *msg_ext) struct ap_status_word stat_word; enum devstat stat; int ccode; + u32 *q_nr_p = (u32 *)msg_ext; - ((struct request_msg_ext *) msg_ext)->q_nr = - (dev_nr << SKIP_BITL) + cdx; + *q_nr_p = (dev_nr << SKIP_BITL) + cdx; PDEBUG("msg_len passed to sen: %d\n", msg_len); PDEBUG("q number passed to sen: %02x%02x%02x%02x\n", msg_ext[0], msg_ext[1], msg_ext[2], msg_ext[3]); @@ -2104,7 +2093,7 @@ convert_response(unsigned char *response, unsigned char *buffer, int *respbufflen_p, unsigned char *resp_buff) { struct ica_rsa_modexpo *icaMsg_p = (struct ica_rsa_modexpo *) buffer; - struct type82_hdr *t82h_p = (struct type82_hdr *) response; + struct error_hdr *errh_p = (struct error_hdr *) response; struct type84_hdr *t84h_p = (struct type84_hdr *) response; struct type86_fmt2_msg *t86m_p = (struct type86_fmt2_msg *) response; int reply_code, service_rc, service_rs, src_l; @@ -2117,12 +2106,13 @@ convert_response(unsigned char *response, unsigned char *buffer, service_rc = 0; service_rs = 0; src_l = 0; - switch (t82h_p->type) { + switch (errh_p->type) { case TYPE82_RSP_CODE: - reply_code = t82h_p->reply_code; - src_p = (unsigned char *)t82h_p; - PRINTK("Hardware error: Type 82 Message Header: " + reply_code = errh_p->reply_code; + src_p = (unsigned char *)errh_p; + PRINTK("Hardware error: Type %02X Message Header: " "%02x%02x%02x%02x%02x%02x%02x%02x\n", + errh_p->type, src_p[0], src_p[1], src_p[2], src_p[3], src_p[4], src_p[5], src_p[6], src_p[7]); break; @@ -2131,7 +2121,7 @@ convert_response(unsigned char *response, unsigned char *buffer, src_p = response + (int)t84h_p->len - src_l; break; case TYPE86_RSP_CODE: - reply_code = t86m_p->hdr.reply_code; + reply_code = t86m_p->header.reply_code; if (reply_code != 0) break; cprb_p = (struct CPRB *) @@ -2143,6 +2133,9 @@ convert_response(unsigned char *response, unsigned char *buffer, le2toI(cprb_p->ccp_rscode, &service_rs); if ((service_rc == 8) && (service_rs == 66)) PDEBUG("Bad block format on PCICC\n"); + else if ((service_rc == 8) && (service_rs == 65)) + PDEBUG("Probably an even modulus on " + "PCICC\n"); else if ((service_rc == 8) && (service_rs == 770)) { PDEBUG("Invalid key length on PCICC\n"); unset_ext_bitlens(); @@ -2155,7 +2148,7 @@ convert_response(unsigned char *response, unsigned char *buffer, return REC_USE_PCICA; } else - PRINTK("service rc/rs: %d/%d\n", + PRINTK("service rc/rs (PCICC): %d/%d\n", service_rc, service_rs); return REC_OPERAND_INV; } @@ -2169,7 +2162,10 @@ convert_response(unsigned char *response, unsigned char *buffer, if (service_rc != 0) { service_rs = (int) cprbx_p->ccp_rscode; if ((service_rc == 8) && (service_rs == 66)) - PDEBUG("Bad block format on PCXICC\n"); + PDEBUG("Bad block format on PCIXCC\n"); + else if ((service_rc == 8) && (service_rs == 65)) + PDEBUG("Probably an even modulus on " + "PCIXCC\n"); else if ((service_rc == 8) && (service_rs == 770)) { PDEBUG("Invalid key length on PCIXCC\n"); unset_ext_bitlens(); @@ -2182,7 +2178,7 @@ convert_response(unsigned char *response, unsigned char *buffer, return REC_USE_PCICA; } else - PRINTK("service rc/rs: %d/%d\n", + PRINTK("service rc/rs (PCIXCC): %d/%d\n", service_rc, service_rs); return REC_OPERAND_INV; } @@ -2195,20 +2191,25 @@ convert_response(unsigned char *response, unsigned char *buffer, } break; default: + src_p = (unsigned char *)errh_p; + PRINTK("Unrecognized Message Header: " + "%02x%02x%02x%02x%02x%02x%02x%02x\n", + src_p[0], src_p[1], src_p[2], src_p[3], + src_p[4], src_p[5], src_p[6], src_p[7]); return REC_BAD_MESSAGE; } if (reply_code) switch (reply_code) { - case REPLY_ERROR_OPERAND_INVALID: + case REP82_ERROR_OPERAND_INVALID: return REC_OPERAND_INV; - case REPLY_ERROR_OPERAND_SIZE: + case REP82_ERROR_OPERAND_SIZE: return REC_OPERAND_SIZE; - case REPLY_ERROR_EVEN_MOD_IN_OPND: + case REP82_ERROR_EVEN_MOD_IN_OPND: return REC_EVEN_MOD; - case REPLY_ERROR_MESSAGE_TYPE: + case REP82_ERROR_MESSAGE_TYPE: return WRONG_DEVICE_TYPE; - case REPLY_ERROR_TRANSPORT_FAIL: + case REP82_ERROR_TRANSPORT_FAIL: PRINTKW("Transport failed (APFS = %02X%02X%02X%02X)\n", t86m_p->apfs[0], t86m_p->apfs[1], t86m_p->apfs[2], t86m_p->apfs[3]); @@ -2229,7 +2230,7 @@ convert_response(unsigned char *response, unsigned char *buffer, PDEBUG("Length returned = %d\n", src_l); tgt_p = resp_buff + icaMsg_p->outputdatalength - src_l; memcpy(tgt_p, src_p, src_l); - if ((t82h_p->type == TYPE86_RSP_CODE) && (resp_buff < tgt_p)) { + if ((errh_p->type == TYPE86_RSP_CODE) && (resp_buff < tgt_p)) { memset(resp_buff, 0, icaMsg_p->outputdatalength - src_l); if (pad_msg(resp_buff, icaMsg_p->outputdatalength, src_l)) return REC_INVALID_PAD; diff --git a/drivers/s390/crypto/z90main.c b/drivers/s390/crypto/z90main.c index 9ec29bb41b2..6aeef3bacc3 100644 --- a/drivers/s390/crypto/z90main.c +++ b/drivers/s390/crypto/z90main.c @@ -31,6 +31,7 @@ #include <linux/init.h> #include <linux/interrupt.h> // for tasklets #include <linux/ioctl32.h> +#include <linux/miscdevice.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kobject_uevent.h> @@ -39,19 +40,8 @@ #include <linux/version.h> #include "z90crypt.h" #include "z90common.h" -#ifndef Z90CRYPT_USE_HOTPLUG -#include <linux/miscdevice.h> -#endif - -#define VERSION_CODE(vers, rel, seq) (((vers)<<16) | ((rel)<<8) | (seq)) -#if LINUX_VERSION_CODE < VERSION_CODE(2,4,0) /* version < 2.4 */ -# error "This kernel is too old: not supported" -#endif -#if LINUX_VERSION_CODE > VERSION_CODE(2,7,0) /* version > 2.6 */ -# error "This kernel is too recent: not supported by this file" -#endif -#define VERSION_Z90MAIN_C "$Revision: 1.57 $" +#define VERSION_Z90MAIN_C "$Revision: 1.62 $" static char z90main_version[] __initdata = "z90main.o (" VERSION_Z90MAIN_C "/" @@ -63,21 +53,12 @@ extern char z90hardware_version[]; * Defaults that may be modified. */ -#ifndef Z90CRYPT_USE_HOTPLUG /** * You can specify a different minor at compile time. */ #ifndef Z90CRYPT_MINOR #define Z90CRYPT_MINOR MISC_DYNAMIC_MINOR #endif -#else -/** - * You can specify a different major at compile time. - */ -#ifndef Z90CRYPT_MAJOR -#define Z90CRYPT_MAJOR 0 -#endif -#endif /** * You can specify a different domain at compile time or on the insmod @@ -97,7 +78,7 @@ extern char z90hardware_version[]; * older than CLEANUPTIME seconds in the past. */ #ifndef CLEANUPTIME -#define CLEANUPTIME 20 +#define CLEANUPTIME 15 #endif /** @@ -298,6 +279,10 @@ struct z90crypt { * it contains the request; at READ, the response. The function * send_to_crypto_device converts the request to device-dependent * form and use the caller's OPEN-allocated buffer for the response. + * + * For the contents of caller_dev_dep_req and caller_dev_dep_req_p + * because that points to it, see the discussion in z90hardware.c. + * Search for "extended request message block". */ struct caller { int caller_buf_l; // length of original request @@ -398,24 +383,9 @@ static int z90crypt_status_write(struct file *, const char __user *, unsigned long, void *); /** - * Hotplug support - */ - -#ifdef Z90CRYPT_USE_HOTPLUG -#define Z90CRYPT_HOTPLUG_ADD 1 -#define Z90CRYPT_HOTPLUG_REMOVE 2 - -static void z90crypt_hotplug_event(int, int, int); -#endif - -/** * Storage allocated at initialization and used throughout the life of * this insmod */ -#ifdef Z90CRYPT_USE_HOTPLUG -static int z90crypt_major = Z90CRYPT_MAJOR; -#endif - static int domain = DOMAIN_INDEX; static struct z90crypt z90crypt; static int quiesce_z90crypt; @@ -444,14 +414,12 @@ static struct file_operations z90crypt_fops = { .release = z90crypt_release }; -#ifndef Z90CRYPT_USE_HOTPLUG static struct miscdevice z90crypt_misc_device = { .minor = Z90CRYPT_MINOR, .name = DEV_NAME, .fops = &z90crypt_fops, .devfs_name = DEV_NAME }; -#endif /** * Documentation values. @@ -603,7 +571,6 @@ z90crypt_init_module(void) return -EINVAL; } -#ifndef Z90CRYPT_USE_HOTPLUG /* Register as misc device with given minor (or get a dynamic one). */ result = misc_register(&z90crypt_misc_device); if (result < 0) { @@ -611,18 +578,6 @@ z90crypt_init_module(void) z90crypt_misc_device.minor, result); return result; } -#else - /* Register the major (or get a dynamic one). */ - result = register_chrdev(z90crypt_major, REG_NAME, &z90crypt_fops); - if (result < 0) { - PRINTKW("register_chrdev (major %d) failed with %d.\n", - z90crypt_major, result); - return result; - } - - if (z90crypt_major == 0) - z90crypt_major = result; -#endif PDEBUG("Registered " DEV_NAME " with result %d\n", result); @@ -645,11 +600,6 @@ z90crypt_init_module(void) } else PRINTK("No devices at startup\n"); -#ifdef Z90CRYPT_USE_HOTPLUG - /* generate hotplug event for device node generation */ - z90crypt_hotplug_event(z90crypt_major, 0, Z90CRYPT_HOTPLUG_ADD); -#endif - /* Initialize globals. */ spin_lock_init(&queuespinlock); @@ -701,17 +651,10 @@ z90crypt_init_module(void) return 0; // success init_module_cleanup: -#ifndef Z90CRYPT_USE_HOTPLUG if ((nresult = misc_deregister(&z90crypt_misc_device))) PRINTK("misc_deregister failed with %d.\n", nresult); else PDEBUG("misc_deregister successful.\n"); -#else - if ((nresult = unregister_chrdev(z90crypt_major, REG_NAME))) - PRINTK("unregister_chrdev failed with %d.\n", nresult); - else - PDEBUG("unregister_chrdev successful.\n"); -#endif return result; // failure } @@ -728,19 +671,10 @@ z90crypt_cleanup_module(void) remove_proc_entry("driver/z90crypt", 0); -#ifndef Z90CRYPT_USE_HOTPLUG if ((nresult = misc_deregister(&z90crypt_misc_device))) PRINTK("misc_deregister failed with %d.\n", nresult); else PDEBUG("misc_deregister successful.\n"); -#else - z90crypt_hotplug_event(z90crypt_major, 0, Z90CRYPT_HOTPLUG_REMOVE); - - if ((nresult = unregister_chrdev(z90crypt_major, REG_NAME))) - PRINTK("unregister_chrdev failed with %d.\n", nresult); - else - PDEBUG("unregister_chrdev successful.\n"); -#endif /* Remove the tasks */ tasklet_kill(&reader_tasklet); @@ -748,6 +682,9 @@ z90crypt_cleanup_module(void) del_timer(&config_timer); del_timer(&cleanup_timer); + if (z90_device_work) + destroy_workqueue(z90_device_work); + destroy_z90crypt(); PRINTKN("Unloaded.\n"); @@ -766,8 +703,6 @@ z90crypt_cleanup_module(void) * z90crypt_status_write * disable_card * enable_card - * scan_char - * scan_string * * Helper functions: * z90crypt_rsa @@ -1057,9 +992,10 @@ remove_device(struct device *device_p) * The MCL must be applied and the newer bitlengths enabled for these to work. * * Card Type Old limit New limit + * PCICA ??-2048 same (the lower limit is less than 128 bit...) * PCICC 512-1024 512-2048 - * PCIXCC_MCL2 512-2048 no change (applying this MCL == card is MCL3+) - * PCIXCC_MCL3 512-2048 128-2048 + * PCIXCC_MCL2 512-2048 ----- (applying any GA LIC will make an MCL3 card) + * PCIXCC_MCL3 ----- 128-2048 * CEX2C 512-2048 128-2048 * * ext_bitlens (extended bitlengths) is a global, since you should not apply an @@ -1104,7 +1040,7 @@ select_device_type(int *dev_type_p, int bytelength) if (PCICA_avail || PCIXCC_MCL3_avail || CEX2C_avail) { /** * bitlength is a factor, PCICA is the most capable, even with - * the new MCL. + * the new MCL for PCIXCC. */ if ((bytelength < PCIXCC_MIN_MOD_SIZE) || (!ext_bitlens && (bytelength < OLD_PCIXCC_MIN_MOD_SIZE))) { @@ -2144,73 +2080,15 @@ enable_card(int card_index) z90crypt.hdware_info->type_mask[devp->dev_type].user_disabled_count--; } -static inline int -scan_char(unsigned char *bf, unsigned int len, - unsigned int *offs, unsigned int *p_eof, unsigned char c) -{ - unsigned int i, found; - - found = 0; - for (i = 0; i < len; i++) { - if (bf[i] == c) { - found = 1; - break; - } - if (bf[i] == '\0') { - *p_eof = 1; - break; - } - if (bf[i] == '\n') { - break; - } - } - *offs = i+1; - return found; -} - -static inline int -scan_string(unsigned char *bf, unsigned int len, - unsigned int *offs, unsigned int *p_eof, unsigned char *s) -{ - unsigned int temp_len, temp_offs, found, eof; - - temp_len = temp_offs = found = eof = 0; - while (!eof && !found) { - found = scan_char(bf+temp_len, len-temp_len, - &temp_offs, &eof, *s); - - temp_len += temp_offs; - if (eof) { - found = 0; - break; - } - - if (found) { - if (len >= temp_offs+strlen(s)) { - found = !strncmp(bf+temp_len-1, s, strlen(s)); - if (found) { - *offs = temp_len+strlen(s)-1; - break; - } - } else { - found = 0; - *p_eof = 1; - break; - } - } - } - return found; -} - static int z90crypt_status_write(struct file *file, const char __user *buffer, unsigned long count, void *data) { - int i, j, len, offs, found, eof; - unsigned char *lbuf; + int j, eol; + unsigned char *lbuf, *ptr; unsigned int local_count; -#define LBUFSIZE 600 +#define LBUFSIZE 1200 lbuf = kmalloc(LBUFSIZE, GFP_KERNEL); if (!lbuf) { PRINTK("kmalloc failed!\n"); @@ -2227,49 +2105,46 @@ z90crypt_status_write(struct file *file, const char __user *buffer, return -EFAULT; } - lbuf[local_count-1] = '\0'; + lbuf[local_count] = '\0'; - len = 0; - eof = 0; - found = 0; - while (!eof) { - found = scan_string(lbuf+len, local_count-len, &offs, &eof, - "Online devices"); - len += offs; - if (found == 1) - break; + ptr = strstr(lbuf, "Online devices"); + if (ptr == 0) { + PRINTK("Unable to parse data (missing \"Online devices\")\n"); + kfree(lbuf); + return count; } - if (eof) { + ptr = strstr(ptr, "\n"); + if (ptr == 0) { + PRINTK("Unable to parse data (missing newline after \"Online devices\")\n"); kfree(lbuf); return count; } + ptr++; - if (found) - found = scan_char(lbuf+len, local_count-len, &offs, &eof, '\n'); - - if (!found || eof) { + if (strstr(ptr, "Waiting work element counts") == NULL) { + PRINTK("Unable to parse data (missing \"Waiting work element counts\")\n"); kfree(lbuf); return count; } - len += offs; j = 0; - for (i = 0; i < 80; i++) { - switch (*(lbuf+len+i)) { + eol = 0; + while ((j < 64) && (*ptr != '\0')) { + switch (*ptr) { case '\t': case ' ': break; case '\n': default: - eof = 1; + eol = 1; break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': + case '0': // no device + case '1': // PCICA + case '2': // PCICC + case '3': // PCIXCC_MCL2 + case '4': // PCIXCC_MCL3 + case '5': // CEX2C j++; break; case 'd': @@ -2283,8 +2158,9 @@ z90crypt_status_write(struct file *file, const char __user *buffer, j++; break; } - if (eof) + if (eol) break; + ptr++; } kfree(lbuf); @@ -3479,45 +3355,5 @@ probe_PCIXCC_type(struct device *devPtr) return rv; } -#ifdef Z90CRYPT_USE_HOTPLUG -static void -z90crypt_hotplug_event(int dev_major, int dev_minor, int action) -{ -#ifdef CONFIG_HOTPLUG - char *argv[3]; - char *envp[6]; - char major[20]; - char minor[20]; - - sprintf(major, "MAJOR=%d", dev_major); - sprintf(minor, "MINOR=%d", dev_minor); - - argv[0] = hotplug_path; - argv[1] = "z90crypt"; - argv[2] = 0; - - envp[0] = "HOME=/"; - envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; - - switch (action) { - case Z90CRYPT_HOTPLUG_ADD: - envp[2] = "ACTION=add"; - break; - case Z90CRYPT_HOTPLUG_REMOVE: - envp[2] = "ACTION=remove"; - break; - default: - BUG(); - break; - } - envp[3] = major; - envp[4] = minor; - envp[5] = 0; - - call_usermodehelper(argv[0], argv, envp, 0); -#endif -} -#endif - module_init(z90crypt_init_module); module_exit(z90crypt_cleanup_module); diff --git a/drivers/s390/s390mach.c b/drivers/s390/s390mach.c index 5bb255e02ac..4191fd9d4d1 100644 --- a/drivers/s390/s390mach.c +++ b/drivers/s390/s390mach.c @@ -240,7 +240,7 @@ s390_revalidate_registers(struct mci *mci) * Floating point control register can't be restored. * Task will be terminated. */ - asm volatile ("lfpc 0(%0)" : : "a" (&zero)); + asm volatile ("lfpc 0(%0)" : : "a" (&zero), "m" (zero)); kill_task = 1; } diff --git a/drivers/sbus/char/Kconfig b/drivers/sbus/char/Kconfig index a41778a490d..3a8152906bf 100644 --- a/drivers/sbus/char/Kconfig +++ b/drivers/sbus/char/Kconfig @@ -69,11 +69,40 @@ config SUN_JSFLASH If you say Y here, you will be able to boot from your JavaStation's Flash memory. -# XXX Why don't we do "source drivers/char/Config.in" somewhere? -# no shit -config RTC - tristate "PC-style Real Time Clock Support" - depends on PCI && EXPERIMENTAL && SPARC32 +config BBC_I2C + tristate "UltraSPARC-III bootbus i2c controller driver" + depends on PCI && SPARC64 + help + The BBC devices on the UltraSPARC III have two I2C controllers. The + first I2C controller connects mainly to configuration PROMs (NVRAM, + CPU configuration, DIMM types, etc.). The second I2C controller + connects to environmental control devices such as fans and + temperature sensors. The second controller also connects to the + smartcard reader, if present. Say Y to enable support for these. + +config ENVCTRL + tristate "SUNW, envctrl support" + depends on PCI && SPARC64 + help + Kernel support for temperature and fan monitoring on Sun SME + machines. + + To compile this driver as a module, choose M here: the + module will be called envctrl. + +config DISPLAY7SEG + tristate "7-Segment Display support" + depends on PCI && SPARC64 + ---help--- + This is the driver for the 7-segment display and LED present on + Sun Microsystems CompactPCI models CP1400 and CP1500. + + To compile this driver as a module, choose M here: the + module will be called display7seg. + + If you do not have a CompactPCI model CP1400 or CP1500, or + another UltraSPARC-IIi-cEngine boardset with a 7-segment display, + you should say N to this option. endmenu diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index 12c208fb18c..787ad00a2b7 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig @@ -250,7 +250,7 @@ config SCSI_DECNCR config SCSI_DECSII tristate "DEC SII Scsi Driver" - depends on MACH_DECSTATION && SCSI && MIPS32 + depends on MACH_DECSTATION && SCSI && 32BIT config BLK_DEV_3W_XXXX_RAID tristate "3ware 5/6/7/8xxx ATA-RAID support" diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c index 179c95c878a..31065261de8 100644 --- a/drivers/scsi/ahci.c +++ b/drivers/scsi/ahci.c @@ -189,7 +189,6 @@ static void ahci_irq_clear(struct ata_port *ap); static void ahci_eng_timeout(struct ata_port *ap); static int ahci_port_start(struct ata_port *ap); static void ahci_port_stop(struct ata_port *ap); -static void ahci_host_stop(struct ata_host_set *host_set); static void ahci_tf_read(struct ata_port *ap, struct ata_taskfile *tf); static void ahci_qc_prep(struct ata_queued_cmd *qc); static u8 ahci_check_status(struct ata_port *ap); @@ -242,7 +241,6 @@ static struct ata_port_operations ahci_ops = { .port_start = ahci_port_start, .port_stop = ahci_port_stop, - .host_stop = ahci_host_stop, }; static struct ata_port_info ahci_port_info[] = { @@ -296,17 +294,9 @@ static inline unsigned long ahci_port_base_ul (unsigned long base, unsigned int return base + 0x100 + (port * 0x80); } -static inline void *ahci_port_base (void *base, unsigned int port) +static inline void __iomem *ahci_port_base (void __iomem *base, unsigned int port) { - return (void *) ahci_port_base_ul((unsigned long)base, port); -} - -static void ahci_host_stop(struct ata_host_set *host_set) -{ - struct ahci_host_priv *hpriv = host_set->private_data; - kfree(hpriv); - - ata_host_stop(host_set); + return (void __iomem *) ahci_port_base_ul((unsigned long)base, port); } static int ahci_port_start(struct ata_port *ap) @@ -314,8 +304,9 @@ static int ahci_port_start(struct ata_port *ap) struct device *dev = ap->host_set->dev; struct ahci_host_priv *hpriv = ap->host_set->private_data; struct ahci_port_priv *pp; - void *mem, *mmio = ap->host_set->mmio_base; - void *port_mmio = ahci_port_base(mmio, ap->port_no); + void __iomem *mmio = ap->host_set->mmio_base; + void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); + void *mem; dma_addr_t mem_dma; pp = kmalloc(sizeof(*pp), GFP_KERNEL); @@ -383,8 +374,8 @@ static void ahci_port_stop(struct ata_port *ap) { struct device *dev = ap->host_set->dev; struct ahci_port_priv *pp = ap->private_data; - void *mmio = ap->host_set->mmio_base; - void *port_mmio = ahci_port_base(mmio, ap->port_no); + void __iomem *mmio = ap->host_set->mmio_base; + void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); u32 tmp; tmp = readl(port_mmio + PORT_CMD); @@ -546,8 +537,8 @@ static void ahci_qc_prep(struct ata_queued_cmd *qc) static void ahci_intr_error(struct ata_port *ap, u32 irq_stat) { - void *mmio = ap->host_set->mmio_base; - void *port_mmio = ahci_port_base(mmio, ap->port_no); + void __iomem *mmio = ap->host_set->mmio_base; + void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); u32 tmp; int work; @@ -595,8 +586,8 @@ static void ahci_intr_error(struct ata_port *ap, u32 irq_stat) static void ahci_eng_timeout(struct ata_port *ap) { struct ata_host_set *host_set = ap->host_set; - void *mmio = host_set->mmio_base; - void *port_mmio = ahci_port_base(mmio, ap->port_no); + void __iomem *mmio = host_set->mmio_base; + void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); struct ata_queued_cmd *qc; unsigned long flags; @@ -626,8 +617,8 @@ static void ahci_eng_timeout(struct ata_port *ap) static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc) { - void *mmio = ap->host_set->mmio_base; - void *port_mmio = ahci_port_base(mmio, ap->port_no); + void __iomem *mmio = ap->host_set->mmio_base; + void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); u32 status, serr, ci; serr = readl(port_mmio + PORT_SCR_ERR); @@ -663,7 +654,7 @@ static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs * struct ata_host_set *host_set = dev_instance; struct ahci_host_priv *hpriv; unsigned int i, handled = 0; - void *mmio; + void __iomem *mmio; u32 irq_stat, irq_ack = 0; VPRINTK("ENTER\n"); @@ -709,7 +700,7 @@ static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs * static int ahci_qc_issue(struct ata_queued_cmd *qc) { struct ata_port *ap = qc->ap; - void *port_mmio = (void *) ap->ioaddr.cmd_addr; + void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; writel(1, port_mmio + PORT_CMD_ISSUE); readl(port_mmio + PORT_CMD_ISSUE); /* flush */ @@ -894,7 +885,7 @@ static void ahci_print_info(struct ata_probe_ent *probe_ent) { struct ahci_host_priv *hpriv = probe_ent->private_data; struct pci_dev *pdev = to_pci_dev(probe_ent->dev); - void *mmio = probe_ent->mmio_base; + void __iomem *mmio = probe_ent->mmio_base; u32 vers, cap, impl, speed; const char *speed_s; u16 cc; @@ -967,7 +958,7 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) struct ata_probe_ent *probe_ent = NULL; struct ahci_host_priv *hpriv; unsigned long base; - void *mmio_base; + void __iomem *mmio_base; unsigned int board_idx = (unsigned int) ent->driver_data; int have_msi, pci_dev_busy = 0; int rc; @@ -1004,8 +995,7 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) probe_ent->dev = pci_dev_to_dev(pdev); INIT_LIST_HEAD(&probe_ent->node); - mmio_base = ioremap(pci_resource_start(pdev, AHCI_PCI_BAR), - pci_resource_len(pdev, AHCI_PCI_BAR)); + mmio_base = pci_iomap(pdev, AHCI_PCI_BAR, 0); if (mmio_base == NULL) { rc = -ENOMEM; goto err_out_free_ent; @@ -1049,7 +1039,7 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) err_out_hpriv: kfree(hpriv); err_out_iounmap: - iounmap(mmio_base); + pci_iounmap(pdev, mmio_base); err_out_free_ent: kfree(probe_ent); err_out_msi: @@ -1089,7 +1079,8 @@ static void ahci_remove_one (struct pci_dev *pdev) scsi_host_put(ap->host); } - host_set->ops->host_stop(host_set); + kfree(hpriv); + pci_iounmap(pdev, host_set->mmio_base); kfree(host_set); if (have_msi) @@ -1106,7 +1097,6 @@ static int __init ahci_init(void) return pci_module_init(&ahci_pci_driver); } - static void __exit ahci_exit(void) { pci_unregister_driver(&ahci_pci_driver); diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c index fb28c126184..deec0cef88d 100644 --- a/drivers/scsi/ata_piix.c +++ b/drivers/scsi/ata_piix.c @@ -583,8 +583,7 @@ static void pci_enable_intx(struct pci_dev *pdev) #define AHCI_ENABLE (1 << 31) static int piix_disable_ahci(struct pci_dev *pdev) { - void *mmio; - unsigned long addr; + void __iomem *mmio; u32 tmp; int rc = 0; @@ -592,11 +591,11 @@ static int piix_disable_ahci(struct pci_dev *pdev) * works because this device is usually set up by BIOS. */ - addr = pci_resource_start(pdev, AHCI_PCI_BAR); - if (!addr || !pci_resource_len(pdev, AHCI_PCI_BAR)) + if (!pci_resource_start(pdev, AHCI_PCI_BAR) || + !pci_resource_len(pdev, AHCI_PCI_BAR)) return 0; - mmio = ioremap(addr, 64); + mmio = pci_iomap(pdev, AHCI_PCI_BAR, 64); if (!mmio) return -ENOMEM; @@ -610,7 +609,7 @@ static int piix_disable_ahci(struct pci_dev *pdev) rc = -EIO; } - iounmap(mmio); + pci_iounmap(pdev, mmio); return rc; } diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index dee4b12b034..9fb9814525a 100644 --- a/drivers/scsi/libata-core.c +++ b/drivers/scsi/libata-core.c @@ -75,6 +75,10 @@ static void __ata_qc_complete(struct ata_queued_cmd *qc); static unsigned int ata_unique_id = 1; static struct workqueue_struct *ata_wq; +int atapi_enabled = 0; +module_param(atapi_enabled, int, 0444); +MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)"); + MODULE_AUTHOR("Jeff Garzik"); MODULE_DESCRIPTION("Library module for ATA devices"); MODULE_LICENSE("GPL"); @@ -4200,6 +4204,15 @@ ata_probe_ent_alloc(struct device *dev, struct ata_port_info *port) +#ifdef CONFIG_PCI + +void ata_pci_host_stop (struct ata_host_set *host_set) +{ + struct pci_dev *pdev = to_pci_dev(host_set->dev); + + pci_iounmap(pdev, host_set->mmio_base); +} + /** * ata_pci_init_native_mode - Initialize native-mode driver * @pdev: pci device to be initialized @@ -4212,7 +4225,6 @@ ata_probe_ent_alloc(struct device *dev, struct ata_port_info *port) * ata_probe_ent structure should then be freed with kfree(). */ -#ifdef CONFIG_PCI struct ata_probe_ent * ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port) { @@ -4595,6 +4607,7 @@ EXPORT_SYMBOL_GPL(ata_scsi_simulate); #ifdef CONFIG_PCI EXPORT_SYMBOL_GPL(pci_test_config_bits); +EXPORT_SYMBOL_GPL(ata_pci_host_stop); EXPORT_SYMBOL_GPL(ata_pci_init_native_mode); EXPORT_SYMBOL_GPL(ata_pci_init_one); EXPORT_SYMBOL_GPL(ata_pci_remove_one); diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c index 346eb36b1e3..104fd9a63e7 100644 --- a/drivers/scsi/libata-scsi.c +++ b/drivers/scsi/libata-scsi.c @@ -1470,10 +1470,10 @@ ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev) if (unlikely(!ata_dev_present(dev))) return NULL; -#ifndef ATA_ENABLE_ATAPI - if (unlikely(dev->class == ATA_DEV_ATAPI)) - return NULL; -#endif + if (!atapi_enabled) { + if (unlikely(dev->class == ATA_DEV_ATAPI)) + return NULL; + } return dev; } diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h index 809c634afbc..d608b3a0f6f 100644 --- a/drivers/scsi/libata.h +++ b/drivers/scsi/libata.h @@ -38,6 +38,7 @@ struct ata_scsi_args { }; /* libata-core.c */ +extern int atapi_enabled; extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, struct ata_device *dev); extern void ata_qc_free(struct ata_queued_cmd *qc); diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c index ff1933298da..a4857db4f9b 100644 --- a/drivers/scsi/mesh.c +++ b/drivers/scsi/mesh.c @@ -1766,7 +1766,7 @@ static int mesh_suspend(struct macio_dev *mdev, pm_message_t state) struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); unsigned long flags; - if (state == mdev->ofdev.dev.power.power_state || state < 2) + if (state.event == mdev->ofdev.dev.power.power_state.event || state.event < 2) return 0; scsi_block_requests(ms->host); @@ -1791,7 +1791,7 @@ static int mesh_resume(struct macio_dev *mdev) struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); unsigned long flags; - if (mdev->ofdev.dev.power.power_state == 0) + if (mdev->ofdev.dev.power.power_state.event == PM_EVENT_ON) return 0; set_mesh_power(ms, 1); @@ -1802,7 +1802,7 @@ static int mesh_resume(struct macio_dev *mdev) enable_irq(ms->meshintr); scsi_unblock_requests(ms->host); - mdev->ofdev.dev.power.power_state = 0; + mdev->ofdev.dev.power.power_state.event = PM_EVENT_ON; return 0; } diff --git a/drivers/scsi/sata_nv.c b/drivers/scsi/sata_nv.c index 03d9bc6e69d..a1d62dee3be 100644 --- a/drivers/scsi/sata_nv.c +++ b/drivers/scsi/sata_nv.c @@ -351,6 +351,7 @@ static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) static void nv_host_stop (struct ata_host_set *host_set) { struct nv_host *host = host_set->private_data; + struct pci_dev *pdev = to_pci_dev(host_set->dev); // Disable hotplug event interrupts. if (host->host_desc->disable_hotplug) @@ -358,7 +359,8 @@ static void nv_host_stop (struct ata_host_set *host_set) kfree(host); - ata_host_stop(host_set); + if (host_set->mmio_base) + pci_iounmap(pdev, host_set->mmio_base); } static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) @@ -420,8 +422,7 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO) { unsigned long base; - probe_ent->mmio_base = ioremap(pci_resource_start(pdev, 5), - pci_resource_len(pdev, 5)); + probe_ent->mmio_base = pci_iomap(pdev, 5, 0); if (probe_ent->mmio_base == NULL) { rc = -EIO; goto err_out_free_host; @@ -457,7 +458,7 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) err_out_iounmap: if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO) - iounmap(probe_ent->mmio_base); + pci_iounmap(pdev, probe_ent->mmio_base); err_out_free_host: kfree(host); err_out_free_ent: diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c index 7c4f6ecc1cc..538ad727bd2 100644 --- a/drivers/scsi/sata_promise.c +++ b/drivers/scsi/sata_promise.c @@ -92,6 +92,7 @@ static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf); static void pdc_irq_clear(struct ata_port *ap); static int pdc_qc_issue_prot(struct ata_queued_cmd *qc); + static Scsi_Host_Template pdc_ata_sht = { .module = THIS_MODULE, .name = DRV_NAME, @@ -132,7 +133,7 @@ static struct ata_port_operations pdc_sata_ops = { .scr_write = pdc_sata_scr_write, .port_start = pdc_port_start, .port_stop = pdc_port_stop, - .host_stop = ata_host_stop, + .host_stop = ata_pci_host_stop, }; static struct ata_port_operations pdc_pata_ops = { @@ -153,7 +154,7 @@ static struct ata_port_operations pdc_pata_ops = { .port_start = pdc_port_start, .port_stop = pdc_port_stop, - .host_stop = ata_host_stop, + .host_stop = ata_pci_host_stop, }; static struct ata_port_info pdc_port_info[] = { @@ -282,7 +283,7 @@ static void pdc_port_stop(struct ata_port *ap) static void pdc_reset_port(struct ata_port *ap) { - void *mmio = (void *) ap->ioaddr.cmd_addr + PDC_CTLSTAT; + void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT; unsigned int i; u32 tmp; @@ -418,7 +419,7 @@ static inline unsigned int pdc_host_intr( struct ata_port *ap, u8 status; unsigned int handled = 0, have_err = 0; u32 tmp; - void *mmio = (void *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL; + void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL; tmp = readl(mmio); if (tmp & PDC_ERR_MASK) { @@ -447,7 +448,7 @@ static inline unsigned int pdc_host_intr( struct ata_port *ap, static void pdc_irq_clear(struct ata_port *ap) { struct ata_host_set *host_set = ap->host_set; - void *mmio = host_set->mmio_base; + void __iomem *mmio = host_set->mmio_base; readl(mmio + PDC_INT_SEQMASK); } @@ -459,7 +460,7 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *r u32 mask = 0; unsigned int i, tmp; unsigned int handled = 0; - void *mmio_base; + void __iomem *mmio_base; VPRINTK("ENTER\n"); @@ -581,7 +582,7 @@ static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base) static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe) { - void *mmio = pe->mmio_base; + void __iomem *mmio = pe->mmio_base; u32 tmp; /* @@ -624,7 +625,7 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e static int printed_version; struct ata_probe_ent *probe_ent = NULL; unsigned long base; - void *mmio_base; + void __iomem *mmio_base; unsigned int board_idx = (unsigned int) ent->driver_data; int pci_dev_busy = 0; int rc; @@ -663,8 +664,7 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e probe_ent->dev = pci_dev_to_dev(pdev); INIT_LIST_HEAD(&probe_ent->node); - mmio_base = ioremap(pci_resource_start(pdev, 3), - pci_resource_len(pdev, 3)); + mmio_base = pci_iomap(pdev, 3, 0); if (mmio_base == NULL) { rc = -ENOMEM; goto err_out_free_ent; diff --git a/drivers/scsi/sata_qstor.c b/drivers/scsi/sata_qstor.c index 9c99ab433bd..029c2482e12 100644 --- a/drivers/scsi/sata_qstor.c +++ b/drivers/scsi/sata_qstor.c @@ -538,11 +538,12 @@ static void qs_port_stop(struct ata_port *ap) static void qs_host_stop(struct ata_host_set *host_set) { void __iomem *mmio_base = host_set->mmio_base; + struct pci_dev *pdev = to_pci_dev(host_set->dev); writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */ writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */ - ata_host_stop(host_set); + pci_iounmap(pdev, mmio_base); } static void qs_host_init(unsigned int chip_id, struct ata_probe_ent *pe) @@ -646,8 +647,7 @@ static int qs_ata_init_one(struct pci_dev *pdev, goto err_out_regions; } - mmio_base = ioremap(pci_resource_start(pdev, 4), - pci_resource_len(pdev, 4)); + mmio_base = pci_iomap(pdev, 4, 0); if (mmio_base == NULL) { rc = -ENOMEM; goto err_out_regions; @@ -697,7 +697,7 @@ static int qs_ata_init_one(struct pci_dev *pdev, return 0; err_out_iounmap: - iounmap(mmio_base); + pci_iounmap(pdev, mmio_base); err_out_regions: pci_release_regions(pdev); err_out: diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c index 71d49548f0a..ba98a175ee3 100644 --- a/drivers/scsi/sata_sil.c +++ b/drivers/scsi/sata_sil.c @@ -86,6 +86,7 @@ static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg); static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); static void sil_post_set_mode (struct ata_port *ap); + static struct pci_device_id sil_pci_tbl[] = { { 0x1095, 0x3112, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112_m15w }, { 0x1095, 0x0240, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112_m15w }, @@ -172,7 +173,7 @@ static struct ata_port_operations sil_ops = { .scr_write = sil_scr_write, .port_start = ata_port_start, .port_stop = ata_port_stop, - .host_stop = ata_host_stop, + .host_stop = ata_pci_host_stop, }; static struct ata_port_info sil_port_info[] = { @@ -231,6 +232,7 @@ MODULE_LICENSE("GPL"); MODULE_DEVICE_TABLE(pci, sil_pci_tbl); MODULE_VERSION(DRV_VERSION); + static unsigned char sil_get_device_cache_line(struct pci_dev *pdev) { u8 cache_line = 0; @@ -242,7 +244,8 @@ static void sil_post_set_mode (struct ata_port *ap) { struct ata_host_set *host_set = ap->host_set; struct ata_device *dev; - void *addr = host_set->mmio_base + sil_port[ap->port_no].xfer_mode; + void __iomem *addr = + host_set->mmio_base + sil_port[ap->port_no].xfer_mode; u32 tmp, dev_mode[2]; unsigned int i; @@ -375,7 +378,7 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) static int printed_version; struct ata_probe_ent *probe_ent = NULL; unsigned long base; - void *mmio_base; + void __iomem *mmio_base; int rc; unsigned int i; int pci_dev_busy = 0; @@ -425,8 +428,7 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) probe_ent->irq_flags = SA_SHIRQ; probe_ent->host_flags = sil_port_info[ent->driver_data].host_flags; - mmio_base = ioremap(pci_resource_start(pdev, 5), - pci_resource_len(pdev, 5)); + mmio_base = pci_iomap(pdev, 5, 0); if (mmio_base == NULL) { rc = -ENOMEM; goto err_out_free_ent; diff --git a/drivers/scsi/sata_svw.c b/drivers/scsi/sata_svw.c index 19d3bb3b0fb..d89d968beda 100644 --- a/drivers/scsi/sata_svw.c +++ b/drivers/scsi/sata_svw.c @@ -318,7 +318,7 @@ static struct ata_port_operations k2_sata_ops = { .scr_write = k2_sata_scr_write, .port_start = ata_port_start, .port_stop = ata_port_stop, - .host_stop = ata_host_stop, + .host_stop = ata_pci_host_stop, }; static void k2_sata_setup_port(struct ata_ioports *port, unsigned long base) @@ -346,7 +346,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e static int printed_version; struct ata_probe_ent *probe_ent = NULL; unsigned long base; - void *mmio_base; + void __iomem *mmio_base; int pci_dev_busy = 0; int rc; int i; @@ -392,8 +392,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e probe_ent->dev = pci_dev_to_dev(pdev); INIT_LIST_HEAD(&probe_ent->node); - mmio_base = ioremap(pci_resource_start(pdev, 5), - pci_resource_len(pdev, 5)); + mmio_base = pci_iomap(pdev, 5, 0); if (mmio_base == NULL) { rc = -ENOMEM; goto err_out_free_ent; diff --git a/drivers/scsi/sata_sx4.c b/drivers/scsi/sata_sx4.c index c72fcc46f0f..540a8519117 100644 --- a/drivers/scsi/sata_sx4.c +++ b/drivers/scsi/sata_sx4.c @@ -245,13 +245,14 @@ static struct pci_driver pdc_sata_pci_driver = { static void pdc20621_host_stop(struct ata_host_set *host_set) { + struct pci_dev *pdev = to_pci_dev(host_set->dev); struct pdc_host_priv *hpriv = host_set->private_data; void *dimm_mmio = hpriv->dimm_mmio; - iounmap(dimm_mmio); + pci_iounmap(pdev, dimm_mmio); kfree(hpriv); - ata_host_stop(host_set); + pci_iounmap(pdev, host_set->mmio_base); } static int pdc_port_start(struct ata_port *ap) @@ -451,9 +452,9 @@ static void pdc20621_dma_prep(struct ata_queued_cmd *qc) struct scatterlist *sg = qc->sg; struct ata_port *ap = qc->ap; struct pdc_port_priv *pp = ap->private_data; - void *mmio = ap->host_set->mmio_base; + void __iomem *mmio = ap->host_set->mmio_base; struct pdc_host_priv *hpriv = ap->host_set->private_data; - void *dimm_mmio = hpriv->dimm_mmio; + void __iomem *dimm_mmio = hpriv->dimm_mmio; unsigned int portno = ap->port_no; unsigned int i, last, idx, total_len = 0, sgt_len; u32 *buf = (u32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ]; @@ -513,9 +514,9 @@ static void pdc20621_nodata_prep(struct ata_queued_cmd *qc) { struct ata_port *ap = qc->ap; struct pdc_port_priv *pp = ap->private_data; - void *mmio = ap->host_set->mmio_base; + void __iomem *mmio = ap->host_set->mmio_base; struct pdc_host_priv *hpriv = ap->host_set->private_data; - void *dimm_mmio = hpriv->dimm_mmio; + void __iomem *dimm_mmio = hpriv->dimm_mmio; unsigned int portno = ap->port_no; unsigned int i; @@ -565,7 +566,7 @@ static void __pdc20621_push_hdma(struct ata_queued_cmd *qc, { struct ata_port *ap = qc->ap; struct ata_host_set *host_set = ap->host_set; - void *mmio = host_set->mmio_base; + void __iomem *mmio = host_set->mmio_base; /* hard-code chip #0 */ mmio += PDC_CHIP0_OFS; @@ -639,7 +640,7 @@ static void pdc20621_packet_start(struct ata_queued_cmd *qc) struct ata_port *ap = qc->ap; struct ata_host_set *host_set = ap->host_set; unsigned int port_no = ap->port_no; - void *mmio = host_set->mmio_base; + void __iomem *mmio = host_set->mmio_base; unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); u8 seq = (u8) (port_no + 1); unsigned int port_ofs; @@ -699,7 +700,7 @@ static int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc) static inline unsigned int pdc20621_host_intr( struct ata_port *ap, struct ata_queued_cmd *qc, unsigned int doing_hdma, - void *mmio) + void __iomem *mmio) { unsigned int port_no = ap->port_no; unsigned int port_ofs = @@ -778,7 +779,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap, static void pdc20621_irq_clear(struct ata_port *ap) { struct ata_host_set *host_set = ap->host_set; - void *mmio = host_set->mmio_base; + void __iomem *mmio = host_set->mmio_base; mmio += PDC_CHIP0_OFS; @@ -792,7 +793,7 @@ static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance, struct pt_re u32 mask = 0; unsigned int i, tmp, port_no; unsigned int handled = 0; - void *mmio_base; + void __iomem *mmio_base; VPRINTK("ENTER\n"); @@ -940,9 +941,9 @@ static void pdc20621_get_from_dimm(struct ata_probe_ent *pe, void *psource, u16 idx; u8 page_mask; long dist; - void *mmio = pe->mmio_base; + void __iomem *mmio = pe->mmio_base; struct pdc_host_priv *hpriv = pe->private_data; - void *dimm_mmio = hpriv->dimm_mmio; + void __iomem *dimm_mmio = hpriv->dimm_mmio; /* hard-code chip #0 */ mmio += PDC_CHIP0_OFS; @@ -996,9 +997,9 @@ static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, void *psource, u16 idx; u8 page_mask; long dist; - void *mmio = pe->mmio_base; + void __iomem *mmio = pe->mmio_base; struct pdc_host_priv *hpriv = pe->private_data; - void *dimm_mmio = hpriv->dimm_mmio; + void __iomem *dimm_mmio = hpriv->dimm_mmio; /* hard-code chip #0 */ mmio += PDC_CHIP0_OFS; @@ -1044,7 +1045,7 @@ static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, void *psource, static unsigned int pdc20621_i2c_read(struct ata_probe_ent *pe, u32 device, u32 subaddr, u32 *pdata) { - void *mmio = pe->mmio_base; + void __iomem *mmio = pe->mmio_base; u32 i2creg = 0; u32 status; u32 count =0; @@ -1103,7 +1104,7 @@ static int pdc20621_prog_dimm0(struct ata_probe_ent *pe) u32 data = 0; int size, i; u8 bdimmsize; - void *mmio = pe->mmio_base; + void __iomem *mmio = pe->mmio_base; static const struct { unsigned int reg; unsigned int ofs; @@ -1166,7 +1167,7 @@ static unsigned int pdc20621_prog_dimm_global(struct ata_probe_ent *pe) { u32 data, spd0; int error, i; - void *mmio = pe->mmio_base; + void __iomem *mmio = pe->mmio_base; /* hard-code chip #0 */ mmio += PDC_CHIP0_OFS; @@ -1220,7 +1221,7 @@ static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe) u32 ticks=0; u32 clock=0; u32 fparam=0; - void *mmio = pe->mmio_base; + void __iomem *mmio = pe->mmio_base; /* hard-code chip #0 */ mmio += PDC_CHIP0_OFS; @@ -1344,7 +1345,7 @@ static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe) static void pdc_20621_init(struct ata_probe_ent *pe) { u32 tmp; - void *mmio = pe->mmio_base; + void __iomem *mmio = pe->mmio_base; /* hard-code chip #0 */ mmio += PDC_CHIP0_OFS; @@ -1377,7 +1378,8 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id * static int printed_version; struct ata_probe_ent *probe_ent = NULL; unsigned long base; - void *mmio_base, *dimm_mmio = NULL; + void __iomem *mmio_base; + void __iomem *dimm_mmio = NULL; struct pdc_host_priv *hpriv = NULL; unsigned int board_idx = (unsigned int) ent->driver_data; int pci_dev_busy = 0; @@ -1417,8 +1419,7 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id * probe_ent->dev = pci_dev_to_dev(pdev); INIT_LIST_HEAD(&probe_ent->node); - mmio_base = ioremap(pci_resource_start(pdev, 3), - pci_resource_len(pdev, 3)); + mmio_base = pci_iomap(pdev, 3, 0); if (mmio_base == NULL) { rc = -ENOMEM; goto err_out_free_ent; @@ -1432,8 +1433,7 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id * } memset(hpriv, 0, sizeof(*hpriv)); - dimm_mmio = ioremap(pci_resource_start(pdev, 4), - pci_resource_len(pdev, 4)); + dimm_mmio = pci_iomap(pdev, 4, 0); if (!dimm_mmio) { kfree(hpriv); rc = -ENOMEM; @@ -1480,9 +1480,9 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id * err_out_iounmap_dimm: /* only get to this label if 20621 */ kfree(hpriv); - iounmap(dimm_mmio); + pci_iounmap(pdev, dimm_mmio); err_out_iounmap: - iounmap(mmio_base); + pci_iounmap(pdev, mmio_base); err_out_free_ent: kfree(probe_ent); err_out_regions: diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c index 3985f344da4..cf94e0158a8 100644 --- a/drivers/scsi/sata_vsc.c +++ b/drivers/scsi/sata_vsc.c @@ -252,7 +252,7 @@ static struct ata_port_operations vsc_sata_ops = { .scr_write = vsc_sata_scr_write, .port_start = ata_port_start, .port_stop = ata_port_stop, - .host_stop = ata_host_stop, + .host_stop = ata_pci_host_stop, }; static void __devinit vsc_sata_setup_port(struct ata_ioports *port, unsigned long base) @@ -326,8 +326,7 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d probe_ent->dev = pci_dev_to_dev(pdev); INIT_LIST_HEAD(&probe_ent->node); - mmio_base = ioremap(pci_resource_start(pdev, 0), - pci_resource_len(pdev, 0)); + mmio_base = pci_iomap(pdev, 0, 0); if (mmio_base == NULL) { rc = -ENOMEM; goto err_out_free_ent; diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 74b80f7c062..e39818a34a0 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -308,7 +308,7 @@ config SERIAL_S3C2410_CONSOLE config SERIAL_DZ bool "DECstation DZ serial driver" - depends on MACH_DECSTATION && MIPS32 + depends on MACH_DECSTATION && 32BIT select SERIAL_CORE help DZ11-family serial controllers for VAXstations, including the diff --git a/drivers/serial/cpm_uart/cpm_uart_core.c b/drivers/serial/cpm_uart/cpm_uart_core.c index 282b32351d8..25825f2aba2 100644 --- a/drivers/serial/cpm_uart/cpm_uart_core.c +++ b/drivers/serial/cpm_uart/cpm_uart_core.c @@ -403,10 +403,8 @@ static int cpm_uart_startup(struct uart_port *port) inline void cpm_uart_wait_until_send(struct uart_cpm_port *pinfo) { - unsigned long target_jiffies = jiffies + pinfo->wait_closing; - - while (!time_after(jiffies, target_jiffies)) - schedule(); + set_current_state(TASK_UNINTERRUPTIBLE); + schedule_timeout(pinfo->wait_closing); } /* @@ -425,9 +423,12 @@ static void cpm_uart_shutdown(struct uart_port *port) /* If the port is not the console, disable Rx and Tx. */ if (!(pinfo->flags & FLAG_CONSOLE)) { /* Wait for all the BDs marked sent */ - while(!cpm_uart_tx_empty(port)) + while(!cpm_uart_tx_empty(port)) { + set_current_state(TASK_UNINTERRUPTIBLE); schedule_timeout(2); - if(pinfo->wait_closing) + } + + if (pinfo->wait_closing) cpm_uart_wait_until_send(pinfo); /* Stop uarts */ diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm2.c b/drivers/serial/cpm_uart/cpm_uart_cpm2.c index c4c8f4b44f5..15ad58d9488 100644 --- a/drivers/serial/cpm_uart/cpm_uart_cpm2.c +++ b/drivers/serial/cpm_uart/cpm_uart_cpm2.c @@ -142,6 +142,14 @@ void scc2_lineif(struct uart_cpm_port *pinfo) * be supported in a sane fashion. */ #ifndef CONFIG_STX_GP3 +#ifdef CONFIG_MPC8560_ADS + volatile iop_cpm2_t *io = &cpm2_immr->im_ioport; + io->iop_ppard |= 0x00000018; + io->iop_psord &= ~0x00000008; /* Rx */ + io->iop_psord &= ~0x00000010; /* Tx */ + io->iop_pdird &= ~0x00000008; /* Rx */ + io->iop_pdird |= 0x00000010; /* Tx */ +#else volatile iop_cpm2_t *io = &cpm2_immr->im_ioport; io->iop_pparb |= 0x008b0000; io->iop_pdirb |= 0x00880000; @@ -149,6 +157,7 @@ void scc2_lineif(struct uart_cpm_port *pinfo) io->iop_pdirb &= ~0x00030000; io->iop_psorb &= ~0x00030000; #endif +#endif cpm2_immr->im_cpmux.cmx_scr &= 0xff00ffff; cpm2_immr->im_cpmux.cmx_scr |= 0x00090000; pinfo->brg = 2; @@ -257,6 +266,7 @@ int cpm_uart_init_portdesc(void) cpm_uart_ports[UART_SMC1].smcp = (smc_t *) & cpm2_immr->im_smc[0]; cpm_uart_ports[UART_SMC1].smcup = (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC1]; + *(u16 *)(&cpm2_immr->im_dprambase[PROFF_SMC1_BASE]) = PROFF_SMC1; cpm_uart_ports[UART_SMC1].port.mapbase = (unsigned long)&cpm2_immr->im_smc[0]; cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX); @@ -269,6 +279,7 @@ int cpm_uart_init_portdesc(void) cpm_uart_ports[UART_SMC2].smcp = (smc_t *) & cpm2_immr->im_smc[1]; cpm_uart_ports[UART_SMC2].smcup = (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC2]; + *(u16 *)(&cpm2_immr->im_dprambase[PROFF_SMC2_BASE]) = PROFF_SMC2; cpm_uart_ports[UART_SMC2].port.mapbase = (unsigned long)&cpm2_immr->im_smc[1]; cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX); diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c index 23b8871e74c..5690594b257 100644 --- a/drivers/serial/crisv10.c +++ b/drivers/serial/crisv10.c @@ -5041,17 +5041,3 @@ rs_init(void) /* this makes sure that rs_init is called during kernel boot */ module_init(rs_init); - -/* - * register_serial and unregister_serial allows for serial ports to be - * configured at run-time, to support PCMCIA modems. - */ -int -register_serial(struct serial_struct *req) -{ - return -1; -} - -void unregister_serial(int line) -{ -} diff --git a/drivers/serial/pmac_zilog.c b/drivers/serial/pmac_zilog.c index 5bfde99e245..5ddd8ab1f10 100644 --- a/drivers/serial/pmac_zilog.c +++ b/drivers/serial/pmac_zilog.c @@ -1600,7 +1600,7 @@ static int pmz_suspend(struct macio_dev *mdev, pm_message_t pm_state) return 0; } - if (pm_state == mdev->ofdev.dev.power.power_state || pm_state < 2) + if (pm_state.event == mdev->ofdev.dev.power.power_state.event) return 0; pmz_debug("suspend, switching to state %d\n", pm_state); @@ -1660,7 +1660,7 @@ static int pmz_resume(struct macio_dev *mdev) if (uap == NULL) return 0; - if (mdev->ofdev.dev.power.power_state == 0) + if (mdev->ofdev.dev.power.power_state.event == PM_EVENT_ON) return 0; pmz_debug("resume, switching to state 0\n"); @@ -1713,7 +1713,7 @@ static int pmz_resume(struct macio_dev *mdev) pmz_debug("resume, switching complete\n"); - mdev->ofdev.dev.power.power_state = 0; + mdev->ofdev.dev.power.power_state.event = PM_EVENT_ON; return 0; } diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c index dea156a62d0..2d8622eef70 100644 --- a/drivers/serial/serial_core.c +++ b/drivers/serial/serial_core.c @@ -1947,21 +1947,29 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port) static inline void uart_report_port(struct uart_driver *drv, struct uart_port *port) { - printk("%s%d", drv->dev_name, port->line); - printk(" at "); + char address[64]; + switch (port->iotype) { case UPIO_PORT: - printk("I/O 0x%x", port->iobase); + snprintf(address, sizeof(address), + "I/O 0x%x", port->iobase); break; case UPIO_HUB6: - printk("I/O 0x%x offset 0x%x", port->iobase, port->hub6); + snprintf(address, sizeof(address), + "I/O 0x%x offset 0x%x", port->iobase, port->hub6); break; case UPIO_MEM: case UPIO_MEM32: - printk("MMIO 0x%lx", port->mapbase); + snprintf(address, sizeof(address), + "MMIO 0x%lx", port->mapbase); + break; + default: + strlcpy(address, "*unknown*", sizeof(address)); break; } - printk(" (irq = %d) is a %s\n", port->irq, uart_type(port)); + + printk(KERN_INFO "%s%d at %s (irq = %d) is a %s\n", + drv->dev_name, port->line, address, port->irq, uart_type(port)); } static void diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c index 0cc879eb1c0..5959e6755a8 100644 --- a/drivers/serial/sunsu.c +++ b/drivers/serial/sunsu.c @@ -269,7 +269,10 @@ static void sunsu_stop_tx(struct uart_port *port) __stop_tx(up); - if (up->port.type == PORT_16C950 && tty_stop /*FIXME*/) { + /* + * We really want to stop the transmitter from sending. + */ + if (up->port.type == PORT_16C950) { up->acr |= UART_ACR_TXDIS; serial_icr_write(up, UART_ACR, up->acr); } @@ -283,10 +286,11 @@ static void sunsu_start_tx(struct uart_port *port) up->ier |= UART_IER_THRI; serial_out(up, UART_IER, up->ier); } + /* - * We only do this from uart_start + * Re-enable the transmitter if we disabled it. */ - if (tty_start && up->port.type == PORT_16C950 /*FIXME*/) { + if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) { up->acr &= ~UART_ACR_TXDIS; serial_icr_write(up, UART_ACR, up->acr); } diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 79422a3b07b..9f44e83c6a6 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -782,7 +782,7 @@ static int usb_register_bus(struct usb_bus *bus) return -E2BIG; } - bus->class_dev = class_device_create(usb_host_class, MKDEV(0,0), bus->controller, "usb%d", busnum); + bus->class_dev = class_device_create(usb_host_class, MKDEV(0,0), bus->controller, "usb_host%d", busnum); if (IS_ERR(bus->class_dev)) { clear_bit(busnum, busmap.busmap); up(&usb_bus_list_lock); diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index c3e46d24a37..c9412daff68 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -1570,7 +1570,7 @@ static int __usb_suspend_device (struct usb_device *udev, int port1, struct usb_driver *driver; intf = udev->actconfig->interface[i]; - if (state <= intf->dev.power.power_state) + if (state.event <= intf->dev.power.power_state.event) continue; if (!intf->dev.driver) continue; @@ -1578,11 +1578,11 @@ static int __usb_suspend_device (struct usb_device *udev, int port1, if (driver->suspend) { status = driver->suspend(intf, state); - if (intf->dev.power.power_state != state + if (intf->dev.power.power_state.event != state.event || status) dev_err(&intf->dev, "suspend %d fail, code %d\n", - state, status); + state.event, status); } /* only drivers with suspend() can ever resume(); @@ -1595,7 +1595,7 @@ static int __usb_suspend_device (struct usb_device *udev, int port1, * since we know every driver's probe/disconnect works * even for drivers that can't suspend. */ - if (!driver->suspend || state > PM_SUSPEND_MEM) { + if (!driver->suspend || state.event > PM_EVENT_FREEZE) { #if 1 dev_warn(&intf->dev, "resume is unsafe!\n"); #else @@ -1616,7 +1616,7 @@ static int __usb_suspend_device (struct usb_device *udev, int port1, * policies (when HNP doesn't apply) once we have mechanisms to * turn power back on! (Likely not before 2.7...) */ - if (state > PM_SUSPEND_MEM) { + if (state.event > PM_EVENT_FREEZE) { dev_warn(&udev->dev, "no poweroff yet, suspending instead\n"); } @@ -1733,7 +1733,7 @@ static int finish_port_resume(struct usb_device *udev) struct usb_driver *driver; intf = udev->actconfig->interface[i]; - if (intf->dev.power.power_state == PMSG_ON) + if (intf->dev.power.power_state.event == PM_EVENT_ON) continue; if (!intf->dev.driver) { /* FIXME maybe force to alt 0 */ @@ -1747,11 +1747,11 @@ static int finish_port_resume(struct usb_device *udev) /* can we do better than just logging errors? */ status = driver->resume(intf); - if (intf->dev.power.power_state != PMSG_ON + if (intf->dev.power.power_state.event != PM_EVENT_ON || status) dev_dbg(&intf->dev, "resume fail, state %d code %d\n", - intf->dev.power.power_state, status); + intf->dev.power.power_state.event, status); } status = 0; @@ -1934,7 +1934,7 @@ static int hub_resume(struct usb_interface *intf) unsigned port1; int status; - if (intf->dev.power.power_state == PM_SUSPEND_ON) + if (intf->dev.power.power_state.event == PM_EVENT_ON) return 0; for (port1 = 1; port1 <= hdev->maxchild; port1++) { diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 99c85d2f92d..2cddd8a0043 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -1400,7 +1400,7 @@ static int usb_generic_suspend(struct device *dev, pm_message_t message) driver = to_usb_driver(dev->driver); /* there's only one USB suspend state */ - if (intf->dev.power.power_state) + if (intf->dev.power.power_state.event) return 0; if (driver->suspend) diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index b01efb6b36f..65ac9fef3a7 100644 --- a/drivers/usb/host/ehci-dbg.c +++ b/drivers/usb/host/ehci-dbg.c @@ -641,7 +641,7 @@ show_registers (struct class_device *class_dev, char *buf) spin_lock_irqsave (&ehci->lock, flags); - if (bus->controller->power.power_state) { + if (bus->controller->power.power_state.event) { size = scnprintf (next, size, "bus %s, device %s (driver " DRIVER_VERSION ")\n" "%s\n" diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c index c58408c95c3..447f488f5d9 100644 --- a/drivers/usb/host/ohci-dbg.c +++ b/drivers/usb/host/ohci-dbg.c @@ -631,7 +631,7 @@ show_registers (struct class_device *class_dev, char *buf) hcd->product_desc, hcd_name); - if (bus->controller->power.power_state) { + if (bus->controller->power.power_state.event) { size -= scnprintf (next, size, "SUSPENDED (no register access)\n"); goto done; diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index 7a890a65f55..80eaf659c19 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c @@ -1781,9 +1781,9 @@ sl811h_suspend(struct device *dev, pm_message_t state, u32 phase) if (phase != SUSPEND_POWER_DOWN) return retval; - if (state <= PM_SUSPEND_MEM) + if (state.event == PM_EVENT_FREEZE) retval = sl811h_hub_suspend(hcd); - else + else if (state.event == PM_EVENT_SUSPEND) port_power(sl811, 0); if (retval == 0) dev->power.power_state = state; @@ -1802,7 +1802,7 @@ sl811h_resume(struct device *dev, u32 phase) /* with no "check to see if VBUS is still powered" board hook, * let's assume it'd only be powered to enable remote wakeup. */ - if (dev->power.power_state > PM_SUSPEND_MEM + if (dev->power.power_state.event == PM_EVENT_SUSPEND || !hcd->can_wakeup) { sl811->port1 = 0; port_power(sl811, 1); diff --git a/drivers/usb/media/w9968cf.c b/drivers/usb/media/w9968cf.c index ca9f3a30634..f36c0b6c6e3 100644 --- a/drivers/usb/media/w9968cf.c +++ b/drivers/usb/media/w9968cf.c @@ -1523,7 +1523,6 @@ static u32 w9968cf_i2c_func(struct i2c_adapter* adap) static int w9968cf_i2c_attach_inform(struct i2c_client* client) { struct w9968cf_device* cam = i2c_get_adapdata(client->adapter); - const char* clientname = i2c_clientname(client); int id = client->driver->id, err = 0; if (id == I2C_DRIVERID_OVCAMCHIP) { @@ -1535,12 +1534,12 @@ static int w9968cf_i2c_attach_inform(struct i2c_client* client) } } else { DBG(4, "Rejected client [%s] with driver [%s]", - clientname, client->driver->name) + client->name, client->driver->name) return -EINVAL; } DBG(5, "I2C attach client [%s] with driver [%s]", - clientname, client->driver->name) + client->name, client->driver->name) return 0; } @@ -1549,12 +1548,11 @@ static int w9968cf_i2c_attach_inform(struct i2c_client* client) static int w9968cf_i2c_detach_inform(struct i2c_client* client) { struct w9968cf_device* cam = i2c_get_adapdata(client->adapter); - const char* clientname = i2c_clientname(client); if (cam->sensor_client == client) cam->sensor_client = NULL; - DBG(5, "I2C detach client [%s]", clientname) + DBG(5, "I2C detach client [%s]", client->name) return 0; } @@ -1573,15 +1571,13 @@ static int w9968cf_i2c_init(struct w9968cf_device* cam) int err = 0; static struct i2c_algorithm algo = { - .name = "W996[87]CF algorithm", - .id = I2C_ALGO_SMBUS, .smbus_xfer = w9968cf_i2c_smbus_xfer, .algo_control = w9968cf_i2c_control, .functionality = w9968cf_i2c_func, }; static struct i2c_adapter adap = { - .id = I2C_ALGO_SMBUS | I2C_HW_SMBUS_W9968CF, + .id = I2C_HW_SMBUS_W9968CF, .class = I2C_CLASS_CAM_DIGITAL, .owner = THIS_MODULE, .client_register = w9968cf_i2c_attach_inform, diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index cda7249a90b..fd7fb98e4b2 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c @@ -1533,7 +1533,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf) if (down_interruptible (&dev->sem)) return -ERESTARTSYS; - if (intf->dev.power.power_state != PMSG_ON) { + if (intf->dev.power.power_state.event != PM_EVENT_ON) { up (&dev->sem); return -EHOSTUNREACH; } diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c index 7bc1d44d881..b0eba3ac642 100644 --- a/drivers/video/aty/aty128fb.c +++ b/drivers/video/aty/aty128fb.c @@ -2323,17 +2323,16 @@ static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state) * can properly take care of D3 ? Also, with swsusp, we * know we'll be rebooted, ... */ -#ifdef CONFIG_PPC_PMAC +#ifndef CONFIG_PPC_PMAC /* HACK ALERT ! Once I find a proper way to say to each driver * individually what will happen with it's PCI slot, I'll change * that. On laptops, the AGP slot is just unclocked, so D2 is * expected, while on desktops, the card is powered off */ - if (state >= 3) - state = 2; + return 0; #endif /* CONFIG_PPC_PMAC */ - if (state != 2 || state == pdev->dev.power.power_state) + if (state.event == pdev->dev.power.power_state.event) return 0; printk(KERN_DEBUG "aty128fb: suspending...\n"); @@ -2367,7 +2366,7 @@ static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state) * used dummy fb ops, 2.5 need proper support for this at the * fbdev level */ - if (state == 2) + if (state.event != PM_EVENT_ON) aty128_set_suspend(par, 1); release_console_sem(); @@ -2382,12 +2381,11 @@ static int aty128_do_resume(struct pci_dev *pdev) struct fb_info *info = pci_get_drvdata(pdev); struct aty128fb_par *par = info->par; - if (pdev->dev.power.power_state == 0) + if (pdev->dev.power.power_state.event == PM_EVENT_ON) return 0; /* Wakeup chip */ - if (pdev->dev.power.power_state == 2) - aty128_set_suspend(par, 0); + aty128_set_suspend(par, 0); par->asleep = 0; /* Restore display & engine */ diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c index 8c42538dc8c..3e10bd837d9 100644 --- a/drivers/video/aty/atyfb_base.c +++ b/drivers/video/aty/atyfb_base.c @@ -2022,17 +2022,16 @@ static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state) struct fb_info *info = pci_get_drvdata(pdev); struct atyfb_par *par = (struct atyfb_par *) info->par; -#ifdef CONFIG_PPC_PMAC +#ifndef CONFIG_PPC_PMAC /* HACK ALERT ! Once I find a proper way to say to each driver * individually what will happen with it's PCI slot, I'll change * that. On laptops, the AGP slot is just unclocked, so D2 is * expected, while on desktops, the card is powered off */ - if (state >= 3) - state = 2; + return 0; #endif /* CONFIG_PPC_PMAC */ - if (state != 2 || state == pdev->dev.power.power_state) + if (state.event == pdev->dev.power.power_state.event) return 0; acquire_console_sem(); @@ -2071,12 +2070,12 @@ static int atyfb_pci_resume(struct pci_dev *pdev) struct fb_info *info = pci_get_drvdata(pdev); struct atyfb_par *par = (struct atyfb_par *) info->par; - if (pdev->dev.power.power_state == 0) + if (pdev->dev.power.power_state.event == PM_EVENT_ON) return 0; acquire_console_sem(); - if (pdev->dev.power.power_state == 2) + if (pdev->dev.power.power_state.event == 2) aty_power_mgmt(0, par); par->asleep = 0; diff --git a/drivers/video/aty/radeon_i2c.c b/drivers/video/aty/radeon_i2c.c index 762244164c8..a9d0414e465 100644 --- a/drivers/video/aty/radeon_i2c.c +++ b/drivers/video/aty/radeon_i2c.c @@ -75,7 +75,7 @@ static int radeon_setup_i2c_bus(struct radeon_i2c_chan *chan, const char *name) strcpy(chan->adapter.name, name); chan->adapter.owner = THIS_MODULE; - chan->adapter.id = I2C_ALGO_ATI; + chan->adapter.id = I2C_HW_B_RADEON; chan->adapter.algo_data = &chan->algo; chan->adapter.dev.parent = &chan->rinfo->pdev->dev; chan->algo.setsda = radeon_gpio_setsda; diff --git a/drivers/video/aty/radeon_pm.c b/drivers/video/aty/radeon_pm.c index 98352af3932..59a1b6f8506 100644 --- a/drivers/video/aty/radeon_pm.c +++ b/drivers/video/aty/radeon_pm.c @@ -2526,18 +2526,18 @@ int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state) struct radeonfb_info *rinfo = info->par; int i; - if (state == pdev->dev.power.power_state) + if (state.event == pdev->dev.power.power_state.event) return 0; printk(KERN_DEBUG "radeonfb (%s): suspending to state: %d...\n", - pci_name(pdev), state); + pci_name(pdev), state.event); /* For suspend-to-disk, we cheat here. We don't suspend anything and * let fbcon continue drawing until we are all set. That shouldn't * really cause any problem at this point, provided that the wakeup * code knows that any state in memory may not match the HW */ - if (state != PM_SUSPEND_MEM) + if (state.event == PM_EVENT_FREEZE) goto done; acquire_console_sem(); @@ -2616,7 +2616,7 @@ int radeonfb_pci_resume(struct pci_dev *pdev) struct radeonfb_info *rinfo = info->par; int rc = 0; - if (pdev->dev.power.power_state == 0) + if (pdev->dev.power.power_state.event == PM_EVENT_ON) return 0; if (rinfo->no_schedule) { @@ -2626,7 +2626,7 @@ int radeonfb_pci_resume(struct pci_dev *pdev) acquire_console_sem(); printk(KERN_DEBUG "radeonfb (%s): resuming from state: %d...\n", - pci_name(pdev), pdev->dev.power.power_state); + pci_name(pdev), pdev->dev.power.power_state.event); if (pci_enable_device(pdev)) { @@ -2637,7 +2637,7 @@ int radeonfb_pci_resume(struct pci_dev *pdev) } pci_set_master(pdev); - if (pdev->dev.power.power_state == PM_SUSPEND_MEM) { + if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) { /* Wakeup chip. Check from config space if we were powered off * (todo: additionally, check CLK_PIN_CNTL too) */ diff --git a/drivers/video/chipsfb.c b/drivers/video/chipsfb.c index e75a965ec76..4131243cfdf 100644 --- a/drivers/video/chipsfb.c +++ b/drivers/video/chipsfb.c @@ -462,9 +462,9 @@ static int chipsfb_pci_suspend(struct pci_dev *pdev, pm_message_t state) { struct fb_info *p = pci_get_drvdata(pdev); - if (state == pdev->dev.power.power_state) + if (state.event == pdev->dev.power.power_state.event) return 0; - if (state != PM_SUSPEND_MEM) + if (state.event != PM_SUSPEND_MEM) goto done; acquire_console_sem(); diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c index 7513fb9b19c..6db183462b9 100644 --- a/drivers/video/i810/i810_main.c +++ b/drivers/video/i810/i810_main.c @@ -1506,12 +1506,12 @@ static int i810fb_suspend(struct pci_dev *dev, pm_message_t state) struct i810fb_par *par = (struct i810fb_par *) info->par; int blank = 0, prev_state = par->cur_state; - if (state == prev_state) + if (state.event == prev_state) return 0; - par->cur_state = state; + par->cur_state = state.event; - switch (state) { + switch (state.event) { case 1: blank = VESA_VSYNC_SUSPEND; break; diff --git a/drivers/video/matrox/matroxfb_maven.c b/drivers/video/matrox/matroxfb_maven.c index 67f85344f0c..ad60bbb16cd 100644 --- a/drivers/video/matrox/matroxfb_maven.c +++ b/drivers/video/matrox/matroxfb_maven.c @@ -1271,7 +1271,7 @@ ERROR0:; } static int maven_attach_adapter(struct i2c_adapter* adapter) { - if (adapter->id == (I2C_ALGO_BIT | I2C_HW_B_G400)) + if (adapter->id == I2C_HW_B_G400) return i2c_probe(adapter, &addr_data, &maven_detect_client); return 0; } diff --git a/drivers/video/nvidia/nv_i2c.c b/drivers/video/nvidia/nv_i2c.c index 3757c1407c1..1a91bffdda2 100644 --- a/drivers/video/nvidia/nv_i2c.c +++ b/drivers/video/nvidia/nv_i2c.c @@ -90,14 +90,13 @@ static int nvidia_gpio_getsda(void *data) return val; } -#define I2C_ALGO_NVIDIA 0x0e0000 static int nvidia_setup_i2c_bus(struct nvidia_i2c_chan *chan, const char *name) { int rc; strcpy(chan->adapter.name, name); chan->adapter.owner = THIS_MODULE; - chan->adapter.id = I2C_ALGO_NVIDIA; + chan->adapter.id = I2C_HW_B_NVIDIA; chan->adapter.algo_data = &chan->algo; chan->adapter.dev.parent = &chan->par->pci_dev->dev; chan->algo.setsda = nvidia_gpio_setsda; diff --git a/drivers/video/pmag-aa-fb.c b/drivers/video/pmag-aa-fb.c index 3e00ad7f2e3..28d1fe5fe34 100644 --- a/drivers/video/pmag-aa-fb.c +++ b/drivers/video/pmag-aa-fb.c @@ -413,7 +413,7 @@ static struct fb_ops aafb_ops = { static int __init init_one(int slot) { - unsigned long base_addr = get_tc_base_addr(slot); + unsigned long base_addr = CKSEG1ADDR(get_tc_base_addr(slot)); struct aafb_info *ip = &my_fb_info[slot]; memset(ip, 0, sizeof(struct aafb_info)); diff --git a/drivers/video/pmag-ba-fb.c b/drivers/video/pmag-ba-fb.c index f8095588e99..c98f1c8d7dc 100644 --- a/drivers/video/pmag-ba-fb.c +++ b/drivers/video/pmag-ba-fb.c @@ -1,57 +1,55 @@ /* - * linux/drivers/video/pmag-ba-fb.c + * linux/drivers/video/pmag-ba-fb.c * - * PMAG-BA TurboChannel framebuffer card support ... derived from: + * PMAG-BA TURBOchannel Color Frame Buffer (CFB) card support, + * derived from: * "HP300 Topcat framebuffer support (derived from macfb of all things) * Phil Blundell <philb@gnu.org> 1998", the original code can be - * found in the file hpfb.c in the same directory. + * found in the file hpfb.c in the same directory. * * Based on digital document: * "PMAG-BA TURBOchannel Color Frame Buffer * Functional Specification", Revision 1.2, August 27, 1990 * - * DECstation related code Copyright (C) 1999, 2000, 2001 by - * Michael Engel <engel@unix-ag.org>, - * Karsten Merker <merker@linuxtag.org> and + * DECstation related code Copyright (C) 1999, 2000, 2001 by + * Michael Engel <engel@unix-ag.org>, + * Karsten Merker <merker@linuxtag.org> and * Harald Koerfgen. - * This file is subject to the terms and conditions of the GNU General - * Public License. See the file COPYING in the main directory of this - * archive for more details. + * Copyright (c) 2005 Maciej W. Rozycki * + * This file is subject to the terms and conditions of the GNU General + * Public License. See the file COPYING in the main directory of this + * archive for more details. */ -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/sched.h> + +#include <linux/compiler.h> #include <linux/errno.h> -#include <linux/string.h> -#include <linux/timer.h> -#include <linux/mm.h> -#include <linux/tty.h> -#include <linux/slab.h> -#include <linux/delay.h> -#include <linux/init.h> #include <linux/fb.h> -#include <asm/bootinfo.h> -#include <asm/dec/machtype.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/types.h> + +#include <asm/bug.h> +#include <asm/io.h> +#include <asm/system.h> + #include <asm/dec/tc.h> + #include <video/pmag-ba-fb.h> -struct pmag_ba_ramdac_regs { - unsigned char addr_low; - unsigned char pad0[3]; - unsigned char addr_hi; - unsigned char pad1[3]; - unsigned char data; - unsigned char pad2[3]; - unsigned char cmap; + +struct pmagbafb_par { + struct fb_info *next; + volatile void __iomem *mmio; + volatile u32 __iomem *dac; + int slot; }; -/* - * Max 3 TURBOchannel slots -> max 3 PMAG-BA :) - */ -static struct fb_info pmagba_fb_info[3]; -static struct fb_var_screeninfo pmagbafb_defined = { +static struct fb_info *root_pmagbafb_dev; + +static struct fb_var_screeninfo pmagbafb_defined __initdata = { .xres = 1024, .yres = 864, .xres_virtual = 1024, @@ -61,58 +59,71 @@ static struct fb_var_screeninfo pmagbafb_defined = { .green.length = 8, .blue.length = 8, .activate = FB_ACTIVATE_NOW, - .height = 274, - .width = 195, - .accel = FB_ACCEL_NONE, + .height = -1, + .width = -1, + .accel_flags = FB_ACCEL_NONE, + .pixclock = 14452, + .left_margin = 116, + .right_margin = 12, + .upper_margin = 34, + .lower_margin = 12, + .hsync_len = 128, + .vsync_len = 3, + .sync = FB_SYNC_ON_GREEN, .vmode = FB_VMODE_NONINTERLACED, }; -static struct fb_fix_screeninfo pmagbafb_fix = { +static struct fb_fix_screeninfo pmagbafb_fix __initdata = { .id = "PMAG-BA", - .smem_len = (1024 * 864), + .smem_len = (1024 * 1024), .type = FB_TYPE_PACKED_PIXELS, .visual = FB_VISUAL_PSEUDOCOLOR, .line_length = 1024, + .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459, }; -/* - * Turn hardware cursor off - */ -void pmagbafb_erase_cursor(struct pmag_ba_ramdac_regs *bt459_regs) + +static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v) { - bt459_regs->addr_low = 0; - bt459_regs->addr_hi = 3; - bt459_regs->data = 0; + writeb(v, par->dac + reg / 4); } +static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg) +{ + return readb(par->dac + reg / 4); +} + + /* - * Set the palette. + * Set the palette. */ -static int pmagbafb_setcolreg(unsigned regno, unsigned red, unsigned green, - unsigned blue, unsigned transp, - struct fb_info *info) +static int pmagbafb_setcolreg(unsigned int regno, unsigned int red, + unsigned int green, unsigned int blue, + unsigned int transp, struct fb_info *info) { - struct pmag_ba_ramdac_regs *bt459_regs = (struct pmag_ba_ramdac_regs *) info->par; + struct pmagbafb_par *par = info->par; - if (regno >= info->cmap.len) - return 1; + BUG_ON(regno >= info->cmap.len); red >>= 8; /* The cmap fields are 16 bits */ - green >>= 8; /* wide, but the harware colormap */ + green >>= 8; /* wide, but the hardware colormap */ blue >>= 8; /* registers are only 8 bits wide */ - bt459_regs->addr_low = (__u8) regno; - bt459_regs->addr_hi = 0; - bt459_regs->cmap = red; - bt459_regs->cmap = green; - bt459_regs->cmap = blue; + mb(); + dac_write(par, BT459_ADDR_LO, regno); + dac_write(par, BT459_ADDR_HI, 0x00); + wmb(); + dac_write(par, BT459_CMAP, red); + wmb(); + dac_write(par, BT459_CMAP, green); + wmb(); + dac_write(par, BT459_CMAP, blue); + return 0; } static struct fb_ops pmagbafb_ops = { .owner = THIS_MODULE, - .fb_get_fix = gen_get_fix, - .fb_get_var = gen_get_var, .fb_setcolreg = pmagbafb_setcolreg, .fb_fillrect = cfb_fillrect, .fb_copyarea = cfb_copyarea, @@ -120,63 +131,133 @@ static struct fb_ops pmagbafb_ops = { .fb_cursor = soft_cursor, }; -int __init pmagbafb_init_one(int slot) + +/* + * Turn the hardware cursor off. + */ +static void __init pmagbafb_erase_cursor(struct fb_info *info) +{ + struct pmagbafb_par *par = info->par; + + mb(); + dac_write(par, BT459_ADDR_LO, 0x00); + dac_write(par, BT459_ADDR_HI, 0x03); + wmb(); + dac_write(par, BT459_DATA, 0x00); +} + + +static int __init pmagbafb_init_one(int slot) { - unsigned long base_addr = get_tc_base_addr(slot); - struct fb_info *info = &pmagba_fb_info[slot]; - struct display *disp = &pmagba_disp[slot]; - - printk("PMAG-BA framebuffer in slot %d\n", slot); - /* - * Framebuffer display memory base address and friends - */ - pmagbafb_fix.smem_start = base_addr + PMAG_BA_ONBOARD_FBMEM_OFFSET; - info->par = (base_addr + PMAG_BA_BT459_OFFSET); - - /* - * Configure the Bt459 RAM DAC - */ - pmagbafb_erase_cursor((struct pmag_ba_ramdac_regs *) info->par); - - /* - * Let there be consoles.. - */ + struct fb_info *info; + struct pmagbafb_par *par; + unsigned long base_addr; + + info = framebuffer_alloc(sizeof(struct pmagbafb_par), NULL); + if (!info) + return -ENOMEM; + + par = info->par; + par->slot = slot; + claim_tc_card(par->slot); + + base_addr = get_tc_base_addr(par->slot); + + par->next = root_pmagbafb_dev; + root_pmagbafb_dev = info; + + if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) + goto err_alloc; + info->fbops = &pmagbafb_ops; + info->fix = pmagbafb_fix; info->var = pmagbafb_defined; - info->fix = pmagbafb_fix; - info->screen_base = pmagbafb_fix.smem_start; info->flags = FBINFO_DEFAULT; - fb_alloc_cmap(&fb_info.cmap, 256, 0); + /* MMIO mapping setup. */ + info->fix.mmio_start = base_addr; + par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len); + if (!par->mmio) + goto err_cmap; + par->dac = par->mmio + PMAG_BA_BT459; + + /* Frame buffer mapping setup. */ + info->fix.smem_start = base_addr + PMAG_BA_FBMEM; + info->screen_base = ioremap_nocache(info->fix.smem_start, + info->fix.smem_len); + if (!info->screen_base) + goto err_mmio_map; + info->screen_size = info->fix.smem_len; + + pmagbafb_erase_cursor(info); if (register_framebuffer(info) < 0) - return 1; + goto err_smem_map; + + pr_info("fb%d: %s frame buffer device in slot %d\n", + info->node, info->fix.id, par->slot); + return 0; + + +err_smem_map: + iounmap(info->screen_base); + +err_mmio_map: + iounmap(par->mmio); + +err_cmap: + fb_dealloc_cmap(&info->cmap); + +err_alloc: + root_pmagbafb_dev = par->next; + release_tc_card(par->slot); + framebuffer_release(info); + return -ENXIO; } -/* - * Initialise the framebuffer - */ +static void __exit pmagbafb_exit_one(void) +{ + struct fb_info *info = root_pmagbafb_dev; + struct pmagbafb_par *par = info->par; -int __init pmagbafb_init(void) + unregister_framebuffer(info); + iounmap(info->screen_base); + iounmap(par->mmio); + fb_dealloc_cmap(&info->cmap); + root_pmagbafb_dev = par->next; + release_tc_card(par->slot); + framebuffer_release(info); +} + + +/* + * Initialise the framebuffer. + */ +static int __init pmagbafb_init(void) { - int sid; - int found = 0; + int count = 0; + int slot; if (fb_get_options("pmagbafb", NULL)) - return -ENODEV; - - if (TURBOCHANNEL) { - while ((sid = search_tc_card("PMAG-BA")) >= 0) { - found = 1; - claim_tc_card(sid); - pmagbafb_init_one(sid); - } - return found ? 0 : -ENODEV; - } else { - return -ENODEV; + return -ENXIO; + + while ((slot = search_tc_card("PMAG-BA")) >= 0) { + if (pmagbafb_init_one(slot) < 0) + break; + count++; } + return (count > 0) ? 0 : -ENXIO; } +static void __exit pmagbafb_exit(void) +{ + while (root_pmagbafb_dev) + pmagbafb_exit_one(); +} + + module_init(pmagbafb_init); +module_exit(pmagbafb_exit); + MODULE_LICENSE("GPL"); diff --git a/drivers/video/pmagb-b-fb.c b/drivers/video/pmagb-b-fb.c index d14eaee91cf..a483b13e117 100644 --- a/drivers/video/pmagb-b-fb.c +++ b/drivers/video/pmagb-b-fb.c @@ -1,114 +1,128 @@ /* - * linux/drivers/video/pmagb-b-fb.c + * linux/drivers/video/pmagb-b-fb.c * - * PMAGB-B TurboChannel framebuffer card support ... derived from: + * PMAGB-B TURBOchannel Smart Frame Buffer (SFB) card support, + * derived from: * "HP300 Topcat framebuffer support (derived from macfb of all things) * Phil Blundell <philb@gnu.org> 1998", the original code can be - * found in the file hpfb.c in the same directory. + * found in the file hpfb.c in the same directory. * - * DECstation related code Copyright (C) 1999, 2000, 2001 by - * Michael Engel <engel@unix-ag.org>, - * Karsten Merker <merker@linuxtag.org> and + * DECstation related code Copyright (C) 1999, 2000, 2001 by + * Michael Engel <engel@unix-ag.org>, + * Karsten Merker <merker@linuxtag.org> and * Harald Koerfgen. - * This file is subject to the terms and conditions of the GNU General - * Public License. See the file COPYING in the main directory of this - * archive for more details. + * Copyright (c) 2005 Maciej W. Rozycki * + * This file is subject to the terms and conditions of the GNU General + * Public License. See the file COPYING in the main directory of this + * archive for more details. */ -/* - * We currently only support the PMAGB-B in high resolution mode - * as I know of no way to detect low resolution mode set via jumper. - * KM, 2001/01/07 - */ - -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/sched.h> -#include <linux/errno.h> -#include <linux/string.h> -#include <linux/timer.h> -#include <linux/mm.h> -#include <linux/tty.h> -#include <linux/slab.h> +#include <linux/compiler.h> #include <linux/delay.h> -#include <linux/init.h> +#include <linux/errno.h> #include <linux/fb.h> -#include <asm/bootinfo.h> -#include <asm/dec/machtype.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/types.h> + +#include <asm/bug.h> +#include <asm/io.h> +#include <asm/system.h> + #include <asm/dec/tc.h> + #include <video/pmagb-b-fb.h> -struct pmagb_b_ramdac_regs { - unsigned char addr_low; - unsigned char pad0[3]; - unsigned char addr_hi; - unsigned char pad1[3]; - unsigned char data; - unsigned char pad2[3]; - unsigned char cmap; + +struct pmagbbfb_par { + struct fb_info *next; + volatile void __iomem *mmio; + volatile void __iomem *smem; + volatile u32 __iomem *sfb; + volatile u32 __iomem *dac; + unsigned int osc0; + unsigned int osc1; + int slot; }; -/* - * Max 3 TURBOchannel slots -> max 3 PMAGB-B :) - */ -static struct fb_info pmagbb_fb_info[3]; -static struct fb_var_screeninfo pmagbbfb_defined = { - .xres = 1280, - .yres = 1024, - .xres_virtual = 1280, - .yres_virtual = 1024, +static struct fb_info *root_pmagbbfb_dev; + +static struct fb_var_screeninfo pmagbbfb_defined __initdata = { .bits_per_pixel = 8, .red.length = 8, .green.length = 8, .blue.length = 8, .activate = FB_ACTIVATE_NOW, - .height = 274, - .width = 195, + .height = -1, + .width = -1, .accel_flags = FB_ACCEL_NONE, + .sync = FB_SYNC_ON_GREEN, .vmode = FB_VMODE_NONINTERLACED, }; -static struct fb_fix_screeninfo pmagbafb_fix = { +static struct fb_fix_screeninfo pmagbbfb_fix __initdata = { .id = "PMAGB-BA", - .smem_len = (1280 * 1024), + .smem_len = (2048 * 1024), .type = FB_TYPE_PACKED_PIXELS, .visual = FB_VISUAL_PSEUDOCOLOR, - .line_length = 1280, + .mmio_len = PMAGB_B_FBMEM, +}; + + +static inline void sfb_write(struct pmagbbfb_par *par, unsigned int reg, u32 v) +{ + writel(v, par->sfb + reg / 4); } -/* - * Turn hardware cursor off - */ -void pmagbbfb_erase_cursor(struct pmagb_b_ramdac_regs *bt459_regs) +static inline u32 sfb_read(struct pmagbbfb_par *par, unsigned int reg) +{ + return readl(par->sfb + reg / 4); +} + +static inline void dac_write(struct pmagbbfb_par *par, unsigned int reg, u8 v) { - bt459_regs->addr_low = 0; - bt459_regs->addr_hi = 3; - bt459_regs->data = 0; + writeb(v, par->dac + reg / 4); } +static inline u8 dac_read(struct pmagbbfb_par *par, unsigned int reg) +{ + return readb(par->dac + reg / 4); +} + +static inline void gp0_write(struct pmagbbfb_par *par, u32 v) +{ + writel(v, par->mmio + PMAGB_B_GP0); +} + + /* - * Set the palette. + * Set the palette. */ -static int pmagbbfb_setcolreg(unsigned regno, unsigned red, unsigned green, - unsigned blue, unsigned transp, - struct fb_info *info) +static int pmagbbfb_setcolreg(unsigned int regno, unsigned int red, + unsigned int green, unsigned int blue, + unsigned int transp, struct fb_info *info) { - struct pmagb_b_ramdac_regs *bt459_regs = (struct pmagb_b_ramdac_regs *) info->par; - - if (regno >= info->cmap.len) - return 1; + struct pmagbbfb_par *par = info->par; + + BUG_ON(regno >= info->cmap.len); red >>= 8; /* The cmap fields are 16 bits */ - green >>= 8; /* wide, but the harware colormap */ + green >>= 8; /* wide, but the hardware colormap */ blue >>= 8; /* registers are only 8 bits wide */ - bt459_regs->addr_low = (__u8) regno; - bt459_regs->addr_hi = 0; - bt459_regs->cmap = red; - bt459_regs->cmap = green; - bt459_regs->cmap = blue; + mb(); + dac_write(par, BT459_ADDR_LO, regno); + dac_write(par, BT459_ADDR_HI, 0x00); + wmb(); + dac_write(par, BT459_CMAP, red); + wmb(); + dac_write(par, BT459_CMAP, green); + wmb(); + dac_write(par, BT459_CMAP, blue); + return 0; } @@ -121,62 +135,247 @@ static struct fb_ops pmagbbfb_ops = { .fb_cursor = soft_cursor, }; -int __init pmagbbfb_init_one(int slot) + +/* + * Turn the hardware cursor off. + */ +static void __init pmagbbfb_erase_cursor(struct fb_info *info) +{ + struct pmagbbfb_par *par = info->par; + + mb(); + dac_write(par, BT459_ADDR_LO, 0x00); + dac_write(par, BT459_ADDR_HI, 0x03); + wmb(); + dac_write(par, BT459_DATA, 0x00); +} + +/* + * Set up screen parameters. + */ +static void __init pmagbbfb_screen_setup(struct fb_info *info) +{ + struct pmagbbfb_par *par = info->par; + + info->var.xres = ((sfb_read(par, SFB_REG_VID_HOR) >> + SFB_VID_HOR_PIX_SHIFT) & SFB_VID_HOR_PIX_MASK) * 4; + info->var.xres_virtual = info->var.xres; + info->var.yres = (sfb_read(par, SFB_REG_VID_VER) >> + SFB_VID_VER_SL_SHIFT) & SFB_VID_VER_SL_MASK; + info->var.yres_virtual = info->var.yres; + info->var.left_margin = ((sfb_read(par, SFB_REG_VID_HOR) >> + SFB_VID_HOR_BP_SHIFT) & + SFB_VID_HOR_BP_MASK) * 4; + info->var.right_margin = ((sfb_read(par, SFB_REG_VID_HOR) >> + SFB_VID_HOR_FP_SHIFT) & + SFB_VID_HOR_FP_MASK) * 4; + info->var.upper_margin = (sfb_read(par, SFB_REG_VID_VER) >> + SFB_VID_VER_BP_SHIFT) & SFB_VID_VER_BP_MASK; + info->var.lower_margin = (sfb_read(par, SFB_REG_VID_VER) >> + SFB_VID_VER_FP_SHIFT) & SFB_VID_VER_FP_MASK; + info->var.hsync_len = ((sfb_read(par, SFB_REG_VID_HOR) >> + SFB_VID_HOR_SYN_SHIFT) & + SFB_VID_HOR_SYN_MASK) * 4; + info->var.vsync_len = (sfb_read(par, SFB_REG_VID_VER) >> + SFB_VID_VER_SYN_SHIFT) & SFB_VID_VER_SYN_MASK; + + info->fix.line_length = info->var.xres; +}; + +/* + * Determine oscillator configuration. + */ +static void __init pmagbbfb_osc_setup(struct fb_info *info) { - unsigned long base_addr = get_tc_base_addr(slot); - struct fb_info *info = &pmagbb_fb_info[slot]; - - printk("PMAGB-BA framebuffer in slot %d\n", slot); - /* - * Framebuffer display memory base address and friends - */ - pmagbbfb_fix.smem_start = base_addr + PMAGB_B_ONBOARD_FBMEM_OFFSET; - info->par = (base_addr + PMAGB_B_BT459_OFFSET); - - /* - * Configure the Bt459 RAM DAC - */ - pmagbbfb_erase_cursor((struct pmagb_b_ramdac_regs *) info->par); - - /* - * Let there be consoles.. - */ + static unsigned int pmagbbfb_freqs[] __initdata = { + 130808, 119843, 104000, 92980, 74367, 72800, + 69197, 66000, 65000, 50350, 36000, 32000, 25175 + }; + struct pmagbbfb_par *par = info->par; + u32 count0 = 8, count1 = 8, counttc = 16 * 256 + 8; + u32 freq0, freq1, freqtc = get_tc_speed() / 250; + int i, j; + + gp0_write(par, 0); /* select Osc0 */ + for (j = 0; j < 16; j++) { + mb(); + sfb_write(par, SFB_REG_TCCLK_COUNT, 0); + mb(); + for (i = 0; i < 100; i++) { /* nominally max. 20.5us */ + if (sfb_read(par, SFB_REG_TCCLK_COUNT) == 0) + break; + udelay(1); + } + count0 += sfb_read(par, SFB_REG_VIDCLK_COUNT); + } + + gp0_write(par, 1); /* select Osc1 */ + for (j = 0; j < 16; j++) { + mb(); + sfb_write(par, SFB_REG_TCCLK_COUNT, 0); + + for (i = 0; i < 100; i++) { /* nominally max. 20.5us */ + if (sfb_read(par, SFB_REG_TCCLK_COUNT) == 0) + break; + udelay(1); + } + count1 += sfb_read(par, SFB_REG_VIDCLK_COUNT); + } + + freq0 = (freqtc * count0 + counttc / 2) / counttc; + par->osc0 = freq0; + if (freq0 >= pmagbbfb_freqs[0] - (pmagbbfb_freqs[0] + 32) / 64 && + freq0 <= pmagbbfb_freqs[0] + (pmagbbfb_freqs[0] + 32) / 64) + par->osc0 = pmagbbfb_freqs[0]; + + freq1 = (par->osc0 * count1 + count0 / 2) / count0; + par->osc1 = freq1; + for (i = 0; i < sizeof(pmagbbfb_freqs) / sizeof(*pmagbbfb_freqs); i++) + if (freq1 >= pmagbbfb_freqs[i] - + (pmagbbfb_freqs[i] + 128) / 256 && + freq1 <= pmagbbfb_freqs[i] + + (pmagbbfb_freqs[i] + 128) / 256) { + par->osc1 = pmagbbfb_freqs[i]; + break; + } + + if (par->osc0 - par->osc1 <= (par->osc0 + par->osc1 + 256) / 512 || + par->osc1 - par->osc0 <= (par->osc0 + par->osc1 + 256) / 512) + par->osc1 = 0; + + gp0_write(par, par->osc1 != 0); /* reselect OscX */ + + info->var.pixclock = par->osc1 ? + (1000000000 + par->osc1 / 2) / par->osc1 : + (1000000000 + par->osc0 / 2) / par->osc0; +}; + + +static int __init pmagbbfb_init_one(int slot) +{ + char freq0[12], freq1[12]; + struct fb_info *info; + struct pmagbbfb_par *par; + unsigned long base_addr; + u32 vid_base; + + info = framebuffer_alloc(sizeof(struct pmagbbfb_par), NULL); + if (!info) + return -ENOMEM; + + par = info->par; + par->slot = slot; + claim_tc_card(par->slot); + + base_addr = get_tc_base_addr(par->slot); + + par->next = root_pmagbbfb_dev; + root_pmagbbfb_dev = info; + + if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) + goto err_alloc; + info->fbops = &pmagbbfb_ops; - info->var = pmagbbfb_defined; info->fix = pmagbbfb_fix; - info->screen_base = pmagbbfb_fix.smem_start; + info->var = pmagbbfb_defined; info->flags = FBINFO_DEFAULT; - fb_alloc_cmap(&fb_info.cmap, 256, 0); + /* MMIO mapping setup. */ + info->fix.mmio_start = base_addr; + par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len); + if (!par->mmio) + goto err_cmap; + par->sfb = par->mmio + PMAGB_B_SFB; + par->dac = par->mmio + PMAGB_B_BT459; + + /* Frame buffer mapping setup. */ + info->fix.smem_start = base_addr + PMAGB_B_FBMEM; + par->smem = ioremap_nocache(info->fix.smem_start, info->fix.smem_len); + if (!par->smem) + goto err_mmio_map; + vid_base = sfb_read(par, SFB_REG_VID_BASE); + info->screen_base = (void __iomem *)par->smem + vid_base * 0x1000; + info->screen_size = info->fix.smem_len - 2 * vid_base * 0x1000; + + pmagbbfb_erase_cursor(info); + pmagbbfb_screen_setup(info); + pmagbbfb_osc_setup(info); if (register_framebuffer(info) < 0) - return 1; + goto err_smem_map; + + snprintf(freq0, sizeof(freq0), "%u.%03uMHz", + par->osc0 / 1000, par->osc0 % 1000); + snprintf(freq1, sizeof(freq1), "%u.%03uMHz", + par->osc1 / 1000, par->osc1 % 1000); + + pr_info("fb%d: %s frame buffer device in slot %d\n", + info->node, info->fix.id, par->slot); + pr_info("fb%d: Osc0: %s, Osc1: %s, Osc%u selected\n", + info->node, freq0, par->osc1 ? freq1 : "disabled", + par->osc1 != 0); + return 0; + + +err_smem_map: + iounmap(par->smem); + +err_mmio_map: + iounmap(par->mmio); + +err_cmap: + fb_dealloc_cmap(&info->cmap); + +err_alloc: + root_pmagbbfb_dev = par->next; + release_tc_card(par->slot); + framebuffer_release(info); + return -ENXIO; } -/* - * Initialise the framebuffer - */ +static void __exit pmagbbfb_exit_one(void) +{ + struct fb_info *info = root_pmagbbfb_dev; + struct pmagbbfb_par *par = info->par; + + unregister_framebuffer(info); + iounmap(par->smem); + iounmap(par->mmio); + fb_dealloc_cmap(&info->cmap); + root_pmagbbfb_dev = par->next; + release_tc_card(par->slot); + framebuffer_release(info); +} -int __init pmagbbfb_init(void) + +/* + * Initialise the framebuffer. + */ +static int __init pmagbbfb_init(void) { - int sid; - int found = 0; + int count = 0; + int slot; if (fb_get_options("pmagbbfb", NULL)) - return -ENODEV; + return -ENXIO; - if (TURBOCHANNEL) { - while ((sid = search_tc_card("PMAGB-BA")) >= 0) { - found = 1; - claim_tc_card(sid); - pmagbbfb_init_one(sid); - } - return found ? 0 : -ENODEV; - } else { - return -ENODEV; + while ((slot = search_tc_card("PMAGB-BA")) >= 0) { + if (pmagbbfb_init_one(slot) < 0) + break; + count++; } + return (count > 0) ? 0 : -ENXIO; +} + +static void __exit pmagbbfb_exit(void) +{ + while (root_pmagbbfb_dev) + pmagbbfb_exit_one(); } + module_init(pmagbbfb_init); +module_exit(pmagbbfb_exit); + MODULE_LICENSE("GPL"); diff --git a/drivers/video/riva/rivafb-i2c.c b/drivers/video/riva/rivafb-i2c.c index da1334dfd51..77151d8e076 100644 --- a/drivers/video/riva/rivafb-i2c.c +++ b/drivers/video/riva/rivafb-i2c.c @@ -92,14 +92,13 @@ static int riva_gpio_getsda(void* data) return val; } -#define I2C_ALGO_RIVA 0x0e0000 static int riva_setup_i2c_bus(struct riva_i2c_chan *chan, const char *name) { int rc; strcpy(chan->adapter.name, name); chan->adapter.owner = THIS_MODULE; - chan->adapter.id = I2C_ALGO_RIVA; + chan->adapter.id = I2C_HW_B_RIVA; chan->adapter.algo_data = &chan->algo; chan->adapter.dev.parent = &chan->par->pdev->dev; chan->algo.setsda = riva_gpio_setsda; diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c index 3848be2b9d2..fa98d91c42e 100644 --- a/drivers/video/s1d13xxxfb.c +++ b/drivers/video/s1d13xxxfb.c @@ -655,7 +655,7 @@ bail: } #ifdef CONFIG_PM -static int s1d13xxxfb_suspend(struct device *dev, u32 state, u32 level) +static int s1d13xxxfb_suspend(struct device *dev, pm_message_t state, u32 level) { struct fb_info *info = dev_get_drvdata(dev); struct s1d13xxxfb_par *s1dfb = info->par; diff --git a/drivers/video/savage/savagefb-i2c.c b/drivers/video/savage/savagefb-i2c.c index 024a0cecff1..847698b5cfe 100644 --- a/drivers/video/savage/savagefb-i2c.c +++ b/drivers/video/savage/savagefb-i2c.c @@ -137,7 +137,6 @@ static int prosavage_gpio_getsda(void* data) return (0 != (GET_CR_DATA(chan->ioaddr) & PROSAVAGE_I2C_SDA_IN)); } -#define I2C_ALGO_SAVAGE 0x0f0000 static int savage_setup_i2c_bus(struct savagefb_i2c_chan *chan, const char *name) { @@ -147,7 +146,7 @@ static int savage_setup_i2c_bus(struct savagefb_i2c_chan *chan, if (add_bus && chan->par) { strcpy(chan->adapter.name, name); chan->adapter.owner = THIS_MODULE; - chan->adapter.id = I2C_ALGO_SAVAGE; + chan->adapter.id = I2C_HW_B_SAVAGE; chan->adapter.algo_data = &chan->algo; chan->adapter.dev.parent = &chan->par->pcidev->dev; chan->algo.udelay = 40; diff --git a/drivers/video/savage/savagefb_driver.c b/drivers/video/savage/savagefb_driver.c index f4633d1891f..117ad42f120 100644 --- a/drivers/video/savage/savagefb_driver.c +++ b/drivers/video/savage/savagefb_driver.c @@ -2110,7 +2110,6 @@ static int savagefb_suspend (struct pci_dev* dev, pm_message_t state) struct savagefb_par *par = (struct savagefb_par *)info->par; DBG("savagefb_suspend"); - printk(KERN_DEBUG "state: %u\n", state); acquire_console_sem(); fb_set_suspend(info, pci_choose_state(dev, state)); |