diff options
Diffstat (limited to 'drivers')
189 files changed, 4897 insertions, 2142 deletions
diff --git a/drivers/acorn/block/fd1772.c b/drivers/acorn/block/fd1772.c index 048542341204..674bf81c6e66 100644 --- a/drivers/acorn/block/fd1772.c +++ b/drivers/acorn/block/fd1772.c @@ -1549,12 +1549,12 @@ int fd1772_init(void) #ifdef TRACKBUFFER BufferDrive = BufferSide = BufferTrack = -1; /* Atari uses 512 - I want to eventually cope with 1K sectors */ - DMABuffer = (char *)kmalloc((FD1772_MAX_SECTORS+1)*512,GFP_KERNEL); + DMABuffer = kmalloc((FD1772_MAX_SECTORS+1)*512,GFP_KERNEL); TrackBuffer = DMABuffer + 512; #else /* Allocate memory for the DMAbuffer - on the Atari this takes it out of some special memory... */ - DMABuffer = (char *) kmalloc(2048); /* Copes with pretty large sectors */ + DMABuffer = kmalloc(2048); /* Copes with pretty large sectors */ #endif err = -ENOMEM; if (!DMAbuffer) diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c index 9021e34d2096..90786d7a20bb 100644 --- a/drivers/ata/pdc_adma.c +++ b/drivers/ata/pdc_adma.c @@ -551,7 +551,7 @@ static int adma_port_start(struct ata_port *ap) return rc; adma_enter_reg_mode(ap); rc = -ENOMEM; - pp = kcalloc(1, sizeof(*pp), GFP_KERNEL); + pp = kzalloc(sizeof(*pp), GFP_KERNEL); if (!pp) goto err_out; pp->pkt = dma_alloc_coherent(dev, ADMA_PKT_BYTES, &pp->pkt_dma, @@ -672,7 +672,7 @@ static int adma_ata_init_one(struct pci_dev *pdev, if (rc) goto err_out_iounmap; - probe_ent = kcalloc(1, sizeof(*probe_ent), GFP_KERNEL); + probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL); if (probe_ent == NULL) { rc = -ENOMEM; goto err_out_iounmap; diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c index bc1b13c8f5d7..5aab7bd473ac 100644 --- a/drivers/atm/eni.c +++ b/drivers/atm/eni.c @@ -1832,7 +1832,7 @@ static int __devinit eni_start(struct atm_dev *dev) /* initialize memory management */ buffer_mem = eni_dev->mem - (buf - eni_dev->ram); eni_dev->free_list_size = buffer_mem/MID_MIN_BUF_SIZE/2; - eni_dev->free_list = (struct eni_free *) kmalloc( + eni_dev->free_list = kmalloc( sizeof(struct eni_free)*(eni_dev->free_list_size+1),GFP_KERNEL); if (!eni_dev->free_list) { printk(KERN_ERR DEV_LABEL "(itf %d): couldn't get free page\n", @@ -2232,7 +2232,7 @@ static int __devinit eni_init_one(struct pci_dev *pci_dev, goto out0; } - eni_dev = (struct eni_dev *) kmalloc(sizeof(struct eni_dev),GFP_KERNEL); + eni_dev = kmalloc(sizeof(struct eni_dev),GFP_KERNEL); if (!eni_dev) goto out0; if (!cpu_zeroes) { cpu_zeroes = pci_alloc_consistent(pci_dev,ENI_ZEROES_SIZE, diff --git a/drivers/atm/he.c b/drivers/atm/he.c index 7d9b4e52f0bf..db33f6f4dd2a 100644 --- a/drivers/atm/he.c +++ b/drivers/atm/he.c @@ -2351,7 +2351,7 @@ he_open(struct atm_vcc *vcc) cid = he_mkcid(he_dev, vpi, vci); - he_vcc = (struct he_vcc *) kmalloc(sizeof(struct he_vcc), GFP_ATOMIC); + he_vcc = kmalloc(sizeof(struct he_vcc), GFP_ATOMIC); if (he_vcc == NULL) { hprintk("unable to allocate he_vcc during open\n"); return -ENOMEM; diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c index 267825501dfe..09f477d4237a 100644 --- a/drivers/atm/lanai.c +++ b/drivers/atm/lanai.c @@ -2602,7 +2602,7 @@ static int __devinit lanai_init_one(struct pci_dev *pci, struct atm_dev *atmdev; int result; - lanai = (struct lanai_dev *) kmalloc(sizeof(*lanai), GFP_KERNEL); + lanai = kmalloc(sizeof(*lanai), GFP_KERNEL); if (lanai == NULL) { printk(KERN_ERR DEV_LABEL ": couldn't allocate dev_data structure!\n"); diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c index bd0904594805..aab9b3733d52 100644 --- a/drivers/atm/nicstar.c +++ b/drivers/atm/nicstar.c @@ -997,7 +997,7 @@ static scq_info *get_scq(int size, u32 scd) if (size != VBR_SCQSIZE && size != CBR_SCQSIZE) return NULL; - scq = (scq_info *) kmalloc(sizeof(scq_info), GFP_KERNEL); + scq = kmalloc(sizeof(scq_info), GFP_KERNEL); if (scq == NULL) return NULL; scq->org = kmalloc(2 * size, GFP_KERNEL); @@ -1006,7 +1006,7 @@ static scq_info *get_scq(int size, u32 scd) kfree(scq); return NULL; } - scq->skb = (struct sk_buff **) kmalloc(sizeof(struct sk_buff *) * + scq->skb = kmalloc(sizeof(struct sk_buff *) * (size / NS_SCQE_SIZE), GFP_KERNEL); if (scq->skb == NULL) { diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c index 7df0f373188e..756d4f760da3 100644 --- a/drivers/atm/zatm.c +++ b/drivers/atm/zatm.c @@ -996,7 +996,7 @@ static int start_tx(struct atm_dev *dev) DPRINTK("start_tx\n"); zatm_dev = ZATM_DEV(dev); - zatm_dev->tx_map = (struct atm_vcc **) kmalloc(sizeof(struct atm_vcc *)* + zatm_dev->tx_map = kmalloc(sizeof(struct atm_vcc *)* zatm_dev->chans,GFP_KERNEL); if (!zatm_dev->tx_map) return -ENOMEM; zatm_dev->tx_bw = ATM_OC3_PCR; @@ -1591,7 +1591,7 @@ static int __devinit zatm_init_one(struct pci_dev *pci_dev, struct zatm_dev *zatm_dev; int ret = -ENOMEM; - zatm_dev = (struct zatm_dev *) kmalloc(sizeof(*zatm_dev), GFP_KERNEL); + zatm_dev = kmalloc(sizeof(*zatm_dev), GFP_KERNEL); if (!zatm_dev) { printk(KERN_EMERG "%s: memory shortage\n", DEV_LABEL); goto out; diff --git a/drivers/base/dmapool.c b/drivers/base/dmapool.c index dbe0735f8c9e..f95d50277274 100644 --- a/drivers/base/dmapool.c +++ b/drivers/base/dmapool.c @@ -173,7 +173,7 @@ pool_alloc_page (struct dma_pool *pool, gfp_t mem_flags) mapsize = (mapsize + BITS_PER_LONG - 1) / BITS_PER_LONG; mapsize *= sizeof (long); - page = (struct dma_page *) kmalloc (mapsize + sizeof *page, mem_flags); + page = kmalloc(mapsize + sizeof *page, mem_flags); if (!page) return NULL; page->vaddr = dma_alloc_coherent (pool->dev, diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig index ce9cfcb6071c..58c1debf86f1 100644 --- a/drivers/block/Kconfig +++ b/drivers/block/Kconfig @@ -28,13 +28,6 @@ config ATARI_FLOPPY tristate "Atari floppy support" depends on ATARI -config BLK_DEV_SWIM_IOP - bool "Macintosh IIfx/Quadra 900/Quadra 950 floppy support (EXPERIMENTAL)" - depends on MAC && EXPERIMENTAL && BROKEN - help - Say Y here to support the SWIM (Super Woz Integrated Machine) IOP - floppy controller on the Macintosh IIfx and Quadra 900/950. - config MAC_FLOPPY tristate "Support for PowerMac floppy" depends on PPC_PMAC && !PPC_PMAC64 diff --git a/drivers/block/Makefile b/drivers/block/Makefile index 410f259a8031..dd88e33c1eb1 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -9,7 +9,6 @@ obj-$(CONFIG_MAC_FLOPPY) += swim3.o obj-$(CONFIG_BLK_DEV_FD) += floppy.o obj-$(CONFIG_AMIGA_FLOPPY) += amiflop.o obj-$(CONFIG_ATARI_FLOPPY) += ataflop.o -obj-$(CONFIG_BLK_DEV_SWIM_IOP) += swim_iop.o obj-$(CONFIG_ATARI_ACSI) += acsi.o obj-$(CONFIG_ATARI_SLM) += acsi_slm.o obj-$(CONFIG_AMIGA_Z2RAM) += z2ram.o diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c index 2ee4a44423df..d719a5d8f435 100644 --- a/drivers/block/cciss.c +++ b/drivers/block/cciss.c @@ -1039,7 +1039,7 @@ static int cciss_ioctl(struct inode *inode, struct file *filep, status = -ENOMEM; goto cleanup1; } - buff_size = (int *)kmalloc(MAXSGENTRIES * sizeof(int), + buff_size = kmalloc(MAXSGENTRIES * sizeof(int), GFP_KERNEL); if (!buff_size) { status = -ENOMEM; @@ -3004,10 +3004,13 @@ static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev) } return 0; - err_out_free_res: +err_out_free_res: + /* + * Deliberately omit pci_disable_device(): it does something nasty to + * Smart Array controllers that pci_enable_device does not undo + */ pci_release_regions(pdev); return err; - } /* @@ -3380,6 +3383,10 @@ static int __devinit cciss_init_one(struct pci_dev *pdev, if (drv->queue) blk_cleanup_queue(drv->queue); } + /* + * Deliberately omit pci_disable_device(): it does something nasty to + * Smart Array controllers that pci_enable_device does not undo + */ pci_release_regions(pdev); pci_set_drvdata(pdev, NULL); free_hba(i); @@ -3449,6 +3456,10 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev) #ifdef CONFIG_CISS_SCSI_TAPE kfree(hba[i]->scsi_rejects.complete); #endif + /* + * Deliberately omit pci_disable_device(): it does something nasty to + * Smart Array controllers that pci_enable_device does not undo + */ pci_release_regions(pdev); pci_set_drvdata(pdev, NULL); free_hba(i); diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c index d5f519ebbc08..b94cd1c32131 100644 --- a/drivers/block/cpqarray.c +++ b/drivers/block/cpqarray.c @@ -1625,7 +1625,7 @@ static void start_fwbk(int ctlr) " processing\n"); /* Command does not return anything, but idasend command needs a buffer */ - id_ctlr_buf = (id_ctlr_t *)kmalloc(sizeof(id_ctlr_t), GFP_KERNEL); + id_ctlr_buf = kmalloc(sizeof(id_ctlr_t), GFP_KERNEL); if(id_ctlr_buf==NULL) { printk(KERN_WARNING "cpqarray: Out of memory. " @@ -1660,14 +1660,14 @@ static void getgeometry(int ctlr) info_p->log_drv_map = 0; - id_ldrive = (id_log_drv_t *)kmalloc(sizeof(id_log_drv_t), GFP_KERNEL); + id_ldrive = kmalloc(sizeof(id_log_drv_t), GFP_KERNEL); if(id_ldrive == NULL) { printk( KERN_ERR "cpqarray: out of memory.\n"); return; } - id_ctlr_buf = (id_ctlr_t *)kmalloc(sizeof(id_ctlr_t), GFP_KERNEL); + id_ctlr_buf = kmalloc(sizeof(id_ctlr_t), GFP_KERNEL); if(id_ctlr_buf == NULL) { kfree(id_ldrive); @@ -1675,7 +1675,7 @@ static void getgeometry(int ctlr) return; } - id_lstatus_buf = (sense_log_drv_stat_t *)kmalloc(sizeof(sense_log_drv_stat_t), GFP_KERNEL); + id_lstatus_buf = kmalloc(sizeof(sense_log_drv_stat_t), GFP_KERNEL); if(id_lstatus_buf == NULL) { kfree(id_ctlr_buf); @@ -1684,7 +1684,7 @@ static void getgeometry(int ctlr) return; } - sense_config_buf = (config_t *)kmalloc(sizeof(config_t), GFP_KERNEL); + sense_config_buf = kmalloc(sizeof(config_t), GFP_KERNEL); if(sense_config_buf == NULL) { kfree(id_lstatus_buf); diff --git a/drivers/block/swim_iop.c b/drivers/block/swim_iop.c deleted file mode 100644 index ed7b06cf3e68..000000000000 --- a/drivers/block/swim_iop.c +++ /dev/null @@ -1,578 +0,0 @@ -/* - * Driver for the SWIM (Super Woz Integrated Machine) IOP - * floppy controller on the Macintosh IIfx and Quadra 900/950 - * - * Written by Joshua M. Thompson (funaho@jurai.org) - * based on the SWIM3 driver (c) 1996 by Paul Mackerras. - * - * 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. - * - * 1999-06-12 (jmt) - Initial implementation. - */ - -/* - * ------------------- - * Theory of Operation - * ------------------- - * - * Since the SWIM IOP is message-driven we implement a simple request queue - * system. One outstanding request may be queued at any given time (this is - * an IOP limitation); only when that request has completed can a new request - * be sent. - */ - -#include <linux/stddef.h> -#include <linux/kernel.h> -#include <linux/sched.h> -#include <linux/timer.h> -#include <linux/delay.h> -#include <linux/fd.h> -#include <linux/ioctl.h> -#include <linux/blkdev.h> -#include <asm/io.h> -#include <asm/uaccess.h> -#include <asm/mac_iop.h> -#include <asm/swim_iop.h> - -#define DRIVER_VERSION "Version 0.1 (1999-06-12)" - -#define MAX_FLOPPIES 4 - -enum swim_state { - idle, - available, - revalidating, - transferring, - ejecting -}; - -struct floppy_state { - enum swim_state state; - int drive_num; /* device number */ - int secpercyl; /* disk geometry information */ - int secpertrack; - int total_secs; - int write_prot; /* 1 if write-protected, 0 if not, -1 dunno */ - int ref_count; - struct timer_list timeout; - int ejected; - struct wait_queue *wait; - int wanted; - int timeout_pending; -}; - -struct swim_iop_req { - int sent; - int complete; - __u8 command[32]; - struct floppy_state *fs; - void (*done)(struct swim_iop_req *); -}; - -static struct swim_iop_req *current_req; -static int floppy_count; - -static struct floppy_state floppy_states[MAX_FLOPPIES]; -static DEFINE_SPINLOCK(swim_iop_lock); - -#define CURRENT elv_next_request(swim_queue) - -static char *drive_names[7] = { - "not installed", /* DRV_NONE */ - "unknown (1)", /* DRV_UNKNOWN */ - "a 400K drive", /* DRV_400K */ - "an 800K drive" /* DRV_800K */ - "unknown (4)", /* ???? */ - "an FDHD", /* DRV_FDHD */ - "unknown (6)", /* ???? */ - "an Apple HD20" /* DRV_HD20 */ -}; - -int swimiop_init(void); -static void swimiop_init_request(struct swim_iop_req *); -static int swimiop_send_request(struct swim_iop_req *); -static void swimiop_receive(struct iop_msg *); -static void swimiop_status_update(int, struct swim_drvstatus *); -static int swimiop_eject(struct floppy_state *fs); - -static int floppy_ioctl(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long param); -static int floppy_open(struct inode *inode, struct file *filp); -static int floppy_release(struct inode *inode, struct file *filp); -static int floppy_check_change(struct gendisk *disk); -static int floppy_revalidate(struct gendisk *disk); -static int grab_drive(struct floppy_state *fs, enum swim_state state, - int interruptible); -static void release_drive(struct floppy_state *fs); -static void set_timeout(struct floppy_state *fs, int nticks, - void (*proc)(unsigned long)); -static void fd_request_timeout(unsigned long); -static void do_fd_request(request_queue_t * q); -static void start_request(struct floppy_state *fs); - -static struct block_device_operations floppy_fops = { - .open = floppy_open, - .release = floppy_release, - .ioctl = floppy_ioctl, - .media_changed = floppy_check_change, - .revalidate_disk= floppy_revalidate, -}; - -static struct request_queue *swim_queue; -/* - * SWIM IOP initialization - */ - -int swimiop_init(void) -{ - volatile struct swim_iop_req req; - struct swimcmd_status *cmd = (struct swimcmd_status *) &req.command[0]; - struct swim_drvstatus *ds = &cmd->status; - struct floppy_state *fs; - int i; - - current_req = NULL; - floppy_count = 0; - - if (!iop_ism_present) - return -ENODEV; - - if (register_blkdev(FLOPPY_MAJOR, "fd")) - return -EBUSY; - - swim_queue = blk_init_queue(do_fd_request, &swim_iop_lock); - if (!swim_queue) { - unregister_blkdev(FLOPPY_MAJOR, "fd"); - return -ENOMEM; - } - - printk("SWIM-IOP: %s by Joshua M. Thompson (funaho@jurai.org)\n", - DRIVER_VERSION); - - if (iop_listen(SWIM_IOP, SWIM_CHAN, swimiop_receive, "SWIM") != 0) { - printk(KERN_ERR "SWIM-IOP: IOP channel already in use; can't initialize.\n"); - unregister_blkdev(FLOPPY_MAJOR, "fd"); - blk_cleanup_queue(swim_queue); - return -EBUSY; - } - - printk(KERN_ERR "SWIM_IOP: probing for installed drives.\n"); - - for (i = 0 ; i < MAX_FLOPPIES ; i++) { - memset(&floppy_states[i], 0, sizeof(struct floppy_state)); - fs = &floppy_states[floppy_count]; - - swimiop_init_request(&req); - cmd->code = CMD_STATUS; - cmd->drive_num = i + 1; - if (swimiop_send_request(&req) != 0) continue; - while (!req.complete); - if (cmd->error != 0) { - printk(KERN_ERR "SWIM-IOP: probe on drive %d returned error %d\n", i, (uint) cmd->error); - continue; - } - if (ds->installed != 0x01) continue; - printk("SWIM-IOP: drive %d is %s (%s, %s, %s, %s)\n", i, - drive_names[ds->info.type], - ds->info.external? "ext" : "int", - ds->info.scsi? "scsi" : "floppy", - ds->info.fixed? "fixed" : "removable", - ds->info.secondary? "secondary" : "primary"); - swimiop_status_update(floppy_count, ds); - fs->state = idle; - - init_timer(&fs->timeout); - floppy_count++; - } - printk("SWIM-IOP: detected %d installed drives.\n", floppy_count); - - for (i = 0; i < floppy_count; i++) { - struct gendisk *disk = alloc_disk(1); - if (!disk) - continue; - disk->major = FLOPPY_MAJOR; - disk->first_minor = i; - disk->fops = &floppy_fops; - sprintf(disk->disk_name, "fd%d", i); - disk->private_data = &floppy_states[i]; - disk->queue = swim_queue; - set_capacity(disk, 2880 * 2); - add_disk(disk); - } - - return 0; -} - -static void swimiop_init_request(struct swim_iop_req *req) -{ - req->sent = 0; - req->complete = 0; - req->done = NULL; -} - -static int swimiop_send_request(struct swim_iop_req *req) -{ - unsigned long flags; - int err; - - /* It's doubtful an interrupt routine would try to send */ - /* a SWIM request, but I'd rather play it safe here. */ - - local_irq_save(flags); - - if (current_req != NULL) { - local_irq_restore(flags); - return -ENOMEM; - } - - current_req = req; - - /* Interrupts should be back on for iop_send_message() */ - - local_irq_restore(flags); - - err = iop_send_message(SWIM_IOP, SWIM_CHAN, (void *) req, - sizeof(req->command), (__u8 *) &req->command[0], - swimiop_receive); - - /* No race condition here; we own current_req at this point */ - - if (err) { - current_req = NULL; - } else { - req->sent = 1; - } - return err; -} - -/* - * Receive a SWIM message from the IOP. - * - * This will be called in two cases: - * - * 1. A message has been successfully sent to the IOP. - * 2. An unsolicited message was received from the IOP. - */ - -void swimiop_receive(struct iop_msg *msg) -{ - struct swim_iop_req *req; - struct swimmsg_status *sm; - struct swim_drvstatus *ds; - - req = current_req; - - switch(msg->status) { - case IOP_MSGSTATUS_COMPLETE: - memcpy(&req->command[0], &msg->reply[0], sizeof(req->command)); - req->complete = 1; - if (req->done) (*req->done)(req); - current_req = NULL; - break; - case IOP_MSGSTATUS_UNSOL: - sm = (struct swimmsg_status *) &msg->message[0]; - ds = &sm->status; - swimiop_status_update(sm->drive_num, ds); - iop_complete_message(msg); - break; - } -} - -static void swimiop_status_update(int drive_num, struct swim_drvstatus *ds) -{ - struct floppy_state *fs = &floppy_states[drive_num]; - - fs->write_prot = (ds->write_prot == 0x80); - if ((ds->disk_in_drive != 0x01) && (ds->disk_in_drive != 0x02)) { - fs->ejected = 1; - } else { - fs->ejected = 0; - } - switch(ds->info.type) { - case DRV_400K: - fs->secpercyl = 10; - fs->secpertrack = 10; - fs->total_secs = 800; - break; - case DRV_800K: - fs->secpercyl = 20; - fs->secpertrack = 10; - fs->total_secs = 1600; - break; - case DRV_FDHD: - fs->secpercyl = 36; - fs->secpertrack = 18; - fs->total_secs = 2880; - break; - default: - fs->secpercyl = 0; - fs->secpertrack = 0; - fs->total_secs = 0; - break; - } -} - -static int swimiop_eject(struct floppy_state *fs) -{ - int err, n; - struct swim_iop_req req; - struct swimcmd_eject *cmd = (struct swimcmd_eject *) &req.command[0]; - - err = grab_drive(fs, ejecting, 1); - if (err) return err; - - swimiop_init_request(&req); - cmd->code = CMD_EJECT; - cmd->drive_num = fs->drive_num; - err = swimiop_send_request(&req); - if (err) { - release_drive(fs); - return err; - } - for (n = 2*HZ; n > 0; --n) { - if (req.complete) break; - if (signal_pending(current)) { - err = -EINTR; - break; - } - schedule_timeout_interruptible(1); - } - release_drive(fs); - return cmd->error; -} - -static struct floppy_struct floppy_type = - { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,NULL }; /* 7 1.44MB 3.5" */ - -static int floppy_ioctl(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long param) -{ - struct floppy_state *fs = inode->i_bdev->bd_disk->private_data; - int err; - - if ((cmd & 0x80) && !capable(CAP_SYS_ADMIN)) - return -EPERM; - - switch (cmd) { - case FDEJECT: - if (fs->ref_count != 1) - return -EBUSY; - err = swimiop_eject(fs); - return err; - case FDGETPRM: - if (copy_to_user((void *) param, (void *) &floppy_type, - sizeof(struct floppy_struct))) - return -EFAULT; - return 0; - } - return -ENOTTY; -} - -static int floppy_open(struct inode *inode, struct file *filp) -{ - struct floppy_state *fs = inode->i_bdev->bd_disk->private_data; - - if (fs->ref_count == -1 || filp->f_flags & O_EXCL) - return -EBUSY; - - if ((filp->f_flags & O_NDELAY) == 0 && (filp->f_mode & 3)) { - check_disk_change(inode->i_bdev); - if (fs->ejected) - return -ENXIO; - } - - if ((filp->f_mode & 2) && fs->write_prot) - return -EROFS; - - if (filp->f_flags & O_EXCL) - fs->ref_count = -1; - else - ++fs->ref_count; - - return 0; -} - -static int floppy_release(struct inode *inode, struct file *filp) -{ - struct floppy_state *fs = inode->i_bdev->bd_disk->private_data; - if (fs->ref_count > 0) - fs->ref_count--; - return 0; -} - -static int floppy_check_change(struct gendisk *disk) -{ - struct floppy_state *fs = disk->private_data; - return fs->ejected; -} - -static int floppy_revalidate(struct gendisk *disk) -{ - struct floppy_state *fs = disk->private_data; - grab_drive(fs, revalidating, 0); - /* yadda, yadda */ - release_drive(fs); - return 0; -} - -static void floppy_off(unsigned int nr) -{ -} - -static int grab_drive(struct floppy_state *fs, enum swim_state state, - int interruptible) -{ - unsigned long flags; - - local_irq_save(flags); - if (fs->state != idle) { - ++fs->wanted; - while (fs->state != available) { - if (interruptible && signal_pending(current)) { - --fs->wanted; - local_irq_restore(flags); - return -EINTR; - } - interruptible_sleep_on(&fs->wait); - } - --fs->wanted; - } - fs->state = state; - local_irq_restore(flags); - return 0; -} - -static void release_drive(struct floppy_state *fs) -{ - unsigned long flags; - - local_irq_save(flags); - fs->state = idle; - start_request(fs); - local_irq_restore(flags); -} - -static void set_timeout(struct floppy_state *fs, int nticks, - void (*proc)(unsigned long)) -{ - unsigned long flags; - - local_irq_save(flags); - if (fs->timeout_pending) - del_timer(&fs->timeout); - init_timer(&fs->timeout); - fs->timeout.expires = jiffies + nticks; - fs->timeout.function = proc; - fs->timeout.data = (unsigned long) fs; - add_timer(&fs->timeout); - fs->timeout_pending = 1; - local_irq_restore(flags); -} - -static void do_fd_request(request_queue_t * q) -{ - int i; - - for (i = 0 ; i < floppy_count ; i++) { - start_request(&floppy_states[i]); - } -} - -static void fd_request_complete(struct swim_iop_req *req) -{ - struct floppy_state *fs = req->fs; - struct swimcmd_rw *cmd = (struct swimcmd_rw *) &req->command[0]; - - del_timer(&fs->timeout); - fs->timeout_pending = 0; - fs->state = idle; - if (cmd->error) { - printk(KERN_ERR "SWIM-IOP: error %d on read/write request.\n", cmd->error); - end_request(CURRENT, 0); - } else { - CURRENT->sector += cmd->num_blocks; - CURRENT->current_nr_sectors -= cmd->num_blocks; - if (CURRENT->current_nr_sectors <= 0) { - end_request(CURRENT, 1); - return; - } - } - start_request(fs); -} - -static void fd_request_timeout(unsigned long data) -{ - struct floppy_state *fs = (struct floppy_state *) data; - - fs->timeout_pending = 0; - end_request(CURRENT, 0); - fs->state = idle; -} - -static void start_request(struct floppy_state *fs) -{ - volatile struct swim_iop_req req; - struct swimcmd_rw *cmd = (struct swimcmd_rw *) &req.command[0]; - - if (fs->state == idle && fs->wanted) { - fs->state = available; - wake_up(&fs->wait); - return; - } - while (CURRENT && fs->state == idle) { - if (CURRENT->bh && !buffer_locked(CURRENT->bh)) - panic("floppy: block not locked"); -#if 0 - printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%ld buf=%p\n", - CURRENT->rq_disk->disk_name, CURRENT->cmd, - CURRENT->sector, CURRENT->nr_sectors, CURRENT->buffer); - printk(" errors=%d current_nr_sectors=%ld\n", - CURRENT->errors, CURRENT->current_nr_sectors); -#endif - - if (CURRENT->sector < 0 || CURRENT->sector >= fs->total_secs) { - end_request(CURRENT, 0); - continue; - } - if (CURRENT->current_nr_sectors == 0) { - end_request(CURRENT, 1); - continue; - } - if (fs->ejected) { - end_request(CURRENT, 0); - continue; - } - - swimiop_init_request(&req); - req.fs = fs; - req.done = fd_request_complete; - - if (CURRENT->cmd == WRITE) { - if (fs->write_prot) { - end_request(CURRENT, 0); - continue; - } - cmd->code = CMD_WRITE; - } else { - cmd->code = CMD_READ; - - } - cmd->drive_num = fs->drive_num; - cmd->buffer = CURRENT->buffer; - cmd->first_block = CURRENT->sector; - cmd->num_blocks = CURRENT->current_nr_sectors; - - if (swimiop_send_request(&req)) { - end_request(CURRENT, 0); - continue; - } - - set_timeout(fs, HZ*CURRENT->current_nr_sectors, - fd_request_timeout); - - fs->state = transferring; - } -} diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index 2df5cf4ec743..e4a2f8f3a1d7 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -1810,7 +1810,7 @@ static int dvd_read_disckey(struct cdrom_device_info *cdi, dvd_struct *s) size = sizeof(s->disckey.value) + 4; - if ((buf = (u_char *) kmalloc(size, GFP_KERNEL)) == NULL) + if ((buf = kmalloc(size, GFP_KERNEL)) == NULL) return -ENOMEM; init_cdrom_command(&cgc, buf, size, CGC_DATA_READ); @@ -1861,7 +1861,7 @@ static int dvd_read_manufact(struct cdrom_device_info *cdi, dvd_struct *s) size = sizeof(s->manufact.value) + 4; - if ((buf = (u_char *) kmalloc(size, GFP_KERNEL)) == NULL) + if ((buf = kmalloc(size, GFP_KERNEL)) == NULL) return -ENOMEM; init_cdrom_command(&cgc, buf, size, CGC_DATA_READ); @@ -2849,7 +2849,7 @@ static int mmc_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, /* FIXME: we need upper bound checking, too!! */ if (lba < 0) return -EINVAL; - cgc.buffer = (char *) kmalloc(blocksize, GFP_KERNEL); + cgc.buffer = kmalloc(blocksize, GFP_KERNEL); if (cgc.buffer == NULL) return -ENOMEM; memset(&sense, 0, sizeof(sense)); @@ -3031,7 +3031,7 @@ static int mmc_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, int size = sizeof(dvd_struct); if (!CDROM_CAN(CDC_DVD)) return -ENOSYS; - if ((s = (dvd_struct *) kmalloc(size, GFP_KERNEL)) == NULL) + if ((s = kmalloc(size, GFP_KERNEL)) == NULL) return -ENOMEM; cdinfo(CD_DO_IOCTL, "entering DVD_READ_STRUCT\n"); if (copy_from_user(s, (dvd_struct __user *)arg, size)) { diff --git a/drivers/cdrom/cm206.c b/drivers/cdrom/cm206.c index e6d8e9ededea..b6c61bbb20e1 100644 --- a/drivers/cdrom/cm206.c +++ b/drivers/cdrom/cm206.c @@ -1420,7 +1420,7 @@ int __init cm206_init(void) return -EIO; } printk(" adapter at 0x%x", cm206_base); - cd = (struct cm206_struct *) kmalloc(size, GFP_KERNEL); + cd = kmalloc(size, GFP_KERNEL); if (!cd) goto out_base; /* Now we have found the adaptor card, try to reset it. As we have diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 0a3aee29e067..9e43e39dc35c 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -97,7 +97,7 @@ config SERIAL_NONSTANDARD config COMPUTONE tristate "Computone IntelliPort Plus serial support" - depends on SERIAL_NONSTANDARD + depends on SERIAL_NONSTANDARD && (ISA || EISA || PCI) ---help--- This driver supports the entire family of Intelliport II/Plus controllers with the exception of the MicroChannel controllers and @@ -203,7 +203,7 @@ config MOXA_SMARTIO config MOXA_SMARTIO_NEW tristate "Moxa SmartIO support v. 2.0 (EXPERIMENTAL)" - depends on SERIAL_NONSTANDARD + depends on SERIAL_NONSTANDARD && (PCI || EISA || ISA) help Say Y here if you have a Moxa SmartIO multiport serial card and/or want to help develop a new version of this driver. @@ -218,7 +218,7 @@ config MOXA_SMARTIO_NEW config ISI tristate "Multi-Tech multiport card support (EXPERIMENTAL)" - depends on SERIAL_NONSTANDARD + depends on SERIAL_NONSTANDARD && PCI select FW_LOADER help This is a driver for the Multi-Tech cards which provide several @@ -312,7 +312,7 @@ config SPECIALIX_RTSCTS config SX tristate "Specialix SX (and SI) card support" - depends on SERIAL_NONSTANDARD + depends on SERIAL_NONSTANDARD && (PCI || EISA || ISA) help This is a driver for the SX and SI multiport serial cards. Please read the file <file:Documentation/sx.txt> for details. diff --git a/drivers/char/consolemap.c b/drivers/char/consolemap.c index 04a12027a740..b99b7561260d 100644 --- a/drivers/char/consolemap.c +++ b/drivers/char/consolemap.c @@ -443,7 +443,7 @@ int con_clear_unimap(struct vc_data *vc, struct unimapinit *ui) p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; if (p && p->readonly) return -EIO; if (!p || --p->refcount) { - q = (struct uni_pagedir *)kmalloc(sizeof(*p), GFP_KERNEL); + q = kmalloc(sizeof(*p), GFP_KERNEL); if (!q) { if (p) p->refcount++; return -ENOMEM; diff --git a/drivers/char/lcd.c b/drivers/char/lcd.c index da601fd6c07a..d649abbf0857 100644 --- a/drivers/char/lcd.c +++ b/drivers/char/lcd.c @@ -459,7 +459,7 @@ static int lcd_ioctl(struct inode *inode, struct file *file, (&display, (struct lcd_display *) arg, sizeof(struct lcd_display))) return -EFAULT; - rom = (unsigned char *) kmalloc((128), GFP_ATOMIC); + rom = kmalloc((128), GFP_ATOMIC); if (rom == NULL) { printk(KERN_ERR LCD "kmalloc() failed in %s\n", __FUNCTION__); diff --git a/drivers/char/lp.c b/drivers/char/lp.c index b70b5388b5a8..b51d08be0bcf 100644 --- a/drivers/char/lp.c +++ b/drivers/char/lp.c @@ -525,7 +525,7 @@ static int lp_open(struct inode * inode, struct file * file) return -EIO; } } - lp_table[minor].lp_buffer = (char *) kmalloc(LP_BUFFER_SIZE, GFP_KERNEL); + lp_table[minor].lp_buffer = kmalloc(LP_BUFFER_SIZE, GFP_KERNEL); if (!lp_table[minor].lp_buffer) { LP_F(minor) &= ~LP_BUSY; return -ENOMEM; diff --git a/drivers/char/mxser_new.c b/drivers/char/mxser_new.c index efa8076c33e0..cd989dce7c53 100644 --- a/drivers/char/mxser_new.c +++ b/drivers/char/mxser_new.c @@ -315,6 +315,7 @@ static struct mxser_mon_ext mon_data_ext; static int mxser_set_baud_method[MXSER_PORTS + 1]; static spinlock_t gm_lock; +#ifdef CONFIG_PCI static int CheckIsMoxaMust(int io) { u8 oldmcr, hwid; @@ -337,6 +338,7 @@ static int CheckIsMoxaMust(int io) } return MOXA_OTHER_UART; } +#endif static void process_txrx_fifo(struct mxser_port *info) { @@ -2380,9 +2382,11 @@ static void mxser_release_res(struct mxser_board *brd, struct pci_dev *pdev, if (irq) free_irq(brd->irq, brd); if (pdev != NULL) { /* PCI */ +#ifdef CONFIG_PCI pci_release_region(pdev, 2); pci_release_region(pdev, 3); pci_dev_put(pdev); +#endif } else { release_region(brd->ports[0].ioaddr, 8 * brd->info->nports); release_region(brd->vector, 1); @@ -2546,6 +2550,7 @@ static int __init mxser_get_ISA_conf(int cap, struct mxser_board *brd) static int __devinit mxser_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { +#ifdef CONFIG_PCI struct mxser_board *brd; unsigned int i, j; unsigned long ioaddress; @@ -2644,6 +2649,9 @@ err_relio: brd->info = NULL; err: return retval; +#else + return -ENODEV; +#endif } static void __devexit mxser_remove(struct pci_dev *pdev) diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c index 103d338f21e2..dc6d41841457 100644 --- a/drivers/char/n_r3964.c +++ b/drivers/char/n_r3964.c @@ -125,8 +125,8 @@ static void transmit_block(struct r3964_info *pInfo); static void receive_char(struct r3964_info *pInfo, const unsigned char c); static void receive_error(struct r3964_info *pInfo, const char flag); static void on_timeout(unsigned long priv); -static int enable_signals(struct r3964_info *pInfo, pid_t pid, int arg); -static int read_telegram(struct r3964_info *pInfo, pid_t pid, unsigned char __user *buf); +static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg); +static int read_telegram(struct r3964_info *pInfo, struct pid *pid, unsigned char __user *buf); static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg, int error_code, struct r3964_block_header *pBlock); static struct r3964_message* remove_msg(struct r3964_info *pInfo, @@ -829,7 +829,7 @@ static void on_timeout(unsigned long priv) } static struct r3964_client_info *findClient( - struct r3964_info *pInfo, pid_t pid) + struct r3964_info *pInfo, struct pid *pid) { struct r3964_client_info *pClient; @@ -843,7 +843,7 @@ static struct r3964_client_info *findClient( return NULL; } -static int enable_signals(struct r3964_info *pInfo, pid_t pid, int arg) +static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg) { struct r3964_client_info *pClient; struct r3964_client_info **ppClient; @@ -858,7 +858,7 @@ static int enable_signals(struct r3964_info *pInfo, pid_t pid, int arg) if(pClient->pid == pid) { - TRACE_PS("removing client %d from client list", pid); + TRACE_PS("removing client %d from client list", pid_nr(pid)); *ppClient = pClient->next; while(pClient->msg_count) { @@ -869,6 +869,7 @@ static int enable_signals(struct r3964_info *pInfo, pid_t pid, int arg) TRACE_M("enable_signals - msg kfree %p",pMsg); } } + put_pid(pClient->pid); kfree(pClient); TRACE_M("enable_signals - kfree %p",pClient); return 0; @@ -892,10 +893,10 @@ static int enable_signals(struct r3964_info *pInfo, pid_t pid, int arg) if(pClient==NULL) return -ENOMEM; - TRACE_PS("add client %d to client list", pid); + TRACE_PS("add client %d to client list", pid_nr(pid)); spin_lock_init(&pClient->lock); pClient->sig_flags=arg; - pClient->pid = pid; + pClient->pid = get_pid(pid); pClient->next=pInfo->firstClient; pClient->first_msg = NULL; pClient->last_msg = NULL; @@ -908,7 +909,7 @@ static int enable_signals(struct r3964_info *pInfo, pid_t pid, int arg) return 0; } -static int read_telegram(struct r3964_info *pInfo, pid_t pid, unsigned char __user *buf) +static int read_telegram(struct r3964_info *pInfo, struct pid *pid, unsigned char __user *buf) { struct r3964_client_info *pClient; struct r3964_block_header *block; @@ -1005,7 +1006,7 @@ queue_the_message: /* Send SIGIO signal to client process: */ if(pClient->sig_flags & R3964_USE_SIGIO) { - kill_proc(pClient->pid, SIGIO, 1); + kill_pid(pClient->pid, SIGIO, 1); } } @@ -1042,7 +1043,7 @@ static void remove_client_block(struct r3964_info *pInfo, { struct r3964_block_header *block; - TRACE_PS("remove_client_block PID %d", pClient->pid); + TRACE_PS("remove_client_block PID %d", pid_nr(pClient->pid)); block=pClient->next_block_to_read; if(block) @@ -1157,6 +1158,7 @@ static void r3964_close(struct tty_struct *tty) TRACE_M("r3964_close - msg kfree %p",pMsg); } } + put_pid(pClient->pid); kfree(pClient); TRACE_M("r3964_close - client kfree %p",pClient); pClient=pNext; @@ -1193,12 +1195,11 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file, struct r3964_client_message theMsg; DECLARE_WAITQUEUE (wait, current); - int pid = current->pid; int count; TRACE_L("read()"); - pClient=findClient(pInfo, pid); + pClient=findClient(pInfo, task_pid(current)); if(pClient) { pMsg = remove_msg(pInfo, pClient); @@ -1252,7 +1253,6 @@ static ssize_t r3964_write(struct tty_struct * tty, struct file * file, struct r3964_block_header *pHeader; struct r3964_client_info *pClient; unsigned char *new_data; - int pid; TRACE_L("write request, %d characters", count); /* @@ -1295,9 +1295,7 @@ static ssize_t r3964_write(struct tty_struct * tty, struct file * file, pHeader->locks = 0; pHeader->owner = NULL; - pid=current->pid; - - pClient=findClient(pInfo, pid); + pClient=findClient(pInfo, task_pid(current)); if(pClient) { pHeader->owner = pClient; @@ -1328,7 +1326,7 @@ static int r3964_ioctl(struct tty_struct * tty, struct file * file, switch(cmd) { case R3964_ENABLE_SIGNALS: - return enable_signals(pInfo, current->pid, arg); + return enable_signals(pInfo, task_pid(current), arg); case R3964_SETPRIORITY: if(arg<R3964_MASTER || arg>R3964_SLAVE) return -EINVAL; @@ -1341,7 +1339,7 @@ static int r3964_ioctl(struct tty_struct * tty, struct file * file, pInfo->flags &= ~R3964_BCC; return 0; case R3964_READ_TELEGRAM: - return read_telegram(pInfo, current->pid, (unsigned char __user *)arg); + return read_telegram(pInfo, task_pid(current), (unsigned char __user *)arg); default: return -ENOIOCTLCMD; } @@ -1357,7 +1355,6 @@ static unsigned int r3964_poll(struct tty_struct * tty, struct file * file, struct poll_table_struct *wait) { struct r3964_info *pInfo=(struct r3964_info*)tty->disc_data; - int pid=current->pid; struct r3964_client_info *pClient; struct r3964_message *pMsg=NULL; unsigned long flags; @@ -1365,7 +1362,7 @@ static unsigned int r3964_poll(struct tty_struct * tty, struct file * file, TRACE_L("POLL"); - pClient=findClient(pInfo,pid); + pClient=findClient(pInfo, task_pid(current)); if(pClient) { poll_wait(file, &pInfo->read_wait, wait); diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c index e96a00fe1389..2bdb0144a22e 100644 --- a/drivers/char/n_tty.c +++ b/drivers/char/n_tty.c @@ -1151,7 +1151,6 @@ static int copy_from_read_buf(struct tty_struct *tty, n = min(*nr, n); spin_unlock_irqrestore(&tty->read_lock, flags); if (n) { - mb(); retval = copy_to_user(*b, &tty->read_buf[tty->read_tail], n); n -= retval; spin_lock_irqsave(&tty->read_lock, flags); diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index 5152cedd8878..f108c136800a 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -541,7 +541,7 @@ static int mgslpc_probe(struct pcmcia_device *link) if (debug_level >= DEBUG_LEVEL_INFO) printk("mgslpc_attach\n"); - info = (MGSLPC_INFO *)kmalloc(sizeof(MGSLPC_INFO), GFP_KERNEL); + info = kmalloc(sizeof(MGSLPC_INFO), GFP_KERNEL); if (!info) { printk("Error can't allocate device instance data\n"); return -ENOMEM; diff --git a/drivers/char/rio/riocmd.c b/drivers/char/rio/riocmd.c index 167ebc84e8d7..245f03195b7c 100644 --- a/drivers/char/rio/riocmd.c +++ b/drivers/char/rio/riocmd.c @@ -556,7 +556,7 @@ struct CmdBlk *RIOGetCmdBlk(void) { struct CmdBlk *CmdBlkP; - CmdBlkP = (struct CmdBlk *)kmalloc(sizeof(struct CmdBlk), GFP_ATOMIC); + CmdBlkP = kmalloc(sizeof(struct CmdBlk), GFP_ATOMIC); if (CmdBlkP) memset(CmdBlkP, 0, sizeof(struct CmdBlk)); return CmdBlkP; diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c index 66a7385bc34a..e1d70e8b6268 100644 --- a/drivers/char/rtc.c +++ b/drivers/char/rtc.c @@ -113,7 +113,7 @@ static int rtc_has_irq = 1; #define hpet_set_rtc_irq_bit(arg) 0 #define hpet_rtc_timer_init() do { } while (0) #define hpet_rtc_dropped_irq() 0 -static inline irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id) {return 0;} +static irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id) {return 0;} #else extern irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id); #endif @@ -165,7 +165,9 @@ static void mask_rtc_irq_bit(unsigned char bit) } #endif +#ifdef CONFIG_PROC_FS static int rtc_proc_open(struct inode *inode, struct file *file); +#endif /* * Bits in rtc_status. (6 bits of room for future expansion) @@ -906,6 +908,7 @@ static struct miscdevice rtc_dev = { .fops = &rtc_fops, }; +#ifdef CONFIG_PROC_FS static const struct file_operations rtc_proc_fops = { .owner = THIS_MODULE, .open = rtc_proc_open, @@ -913,14 +916,13 @@ static const struct file_operations rtc_proc_fops = { .llseek = seq_lseek, .release = single_release, }; - -#if defined(RTC_IRQ) && !defined(__sparc__) -static irq_handler_t rtc_int_handler_ptr; #endif static int __init rtc_init(void) { +#ifdef CONFIG_PROC_FS struct proc_dir_entry *ent; +#endif #if defined(__alpha__) || defined(__mips__) unsigned int year, ctrl; char *guess = NULL; @@ -932,9 +934,11 @@ static int __init rtc_init(void) struct sparc_isa_bridge *isa_br; struct sparc_isa_device *isa_dev; #endif -#endif -#ifndef __sparc__ +#else void *r; +#ifdef RTC_IRQ + irq_handler_t rtc_int_handler_ptr; +#endif #endif #ifdef __sparc__ @@ -958,6 +962,7 @@ static int __init rtc_init(void) } } #endif + rtc_has_irq = 0; printk(KERN_ERR "rtc_init: no PC rtc found\n"); return -EIO; @@ -972,6 +977,7 @@ found: * PCI Slot 2 INTA# (and some INTx# in Slot 1). */ if (request_irq(rtc_irq, rtc_interrupt, IRQF_SHARED, "rtc", (void *)&rtc_port)) { + rtc_has_irq = 0; printk(KERN_ERR "rtc: cannot register IRQ %d\n", rtc_irq); return -EIO; } @@ -982,6 +988,9 @@ no_irq: else r = request_mem_region(RTC_PORT(0), RTC_IO_EXTENT, "rtc"); if (!r) { +#ifdef RTC_IRQ + rtc_has_irq = 0; +#endif printk(KERN_ERR "rtc: I/O resource %lx is not free.\n", (long)(RTC_PORT(0))); return -EIO; @@ -996,6 +1005,7 @@ no_irq: if(request_irq(RTC_IRQ, rtc_int_handler_ptr, IRQF_DISABLED, "rtc", NULL)) { /* Yeah right, seeing as irq 8 doesn't even hit the bus. */ + rtc_has_irq = 0; printk(KERN_ERR "rtc: IRQ %d is not free.\n", RTC_IRQ); if (RTC_IOMAPPED) release_region(RTC_PORT(0), RTC_IO_EXTENT); @@ -1012,21 +1022,19 @@ no_irq: if (misc_register(&rtc_dev)) { #ifdef RTC_IRQ free_irq(RTC_IRQ, NULL); + rtc_has_irq = 0; #endif release_region(RTC_PORT(0), RTC_IO_EXTENT); return -ENODEV; } +#ifdef CONFIG_PROC_FS ent = create_proc_entry("driver/rtc", 0, NULL); - if (!ent) { -#ifdef RTC_IRQ - free_irq(RTC_IRQ, NULL); + if (ent) + ent->proc_fops = &rtc_proc_fops; + else + printk(KERN_WARNING "rtc: Failed to register with procfs.\n"); #endif - release_region(RTC_PORT(0), RTC_IO_EXTENT); - misc_deregister(&rtc_dev); - return -ENOMEM; - } - ent->proc_fops = &rtc_proc_fops; #if defined(__alpha__) || defined(__mips__) rtc_freq = HZ; @@ -1159,6 +1167,7 @@ static void rtc_dropped_irq(unsigned long data) } #endif +#ifdef CONFIG_PROC_FS /* * Info exported via "/proc/driver/rtc". */ @@ -1243,6 +1252,7 @@ static int rtc_proc_open(struct inode *inode, struct file *file) { return single_open(file, rtc_proc_show, NULL); } +#endif void rtc_get_rtc_time(struct rtc_time *rtc_tm) { diff --git a/drivers/char/sx.c b/drivers/char/sx.c index a3008ce13015..1da92a689ae4 100644 --- a/drivers/char/sx.c +++ b/drivers/char/sx.c @@ -2498,8 +2498,10 @@ static void __devexit sx_remove_card(struct sx_board *board, /* It is safe/allowed to del_timer a non-active timer */ del_timer(&board->timer); if (pdev) { +#ifdef CONFIG_PCI pci_iounmap(pdev, board->base); pci_release_region(pdev, IS_CF_BOARD(board) ? 3 : 2); +#endif } else { iounmap(board->base); release_region(board->hw_base, board->hw_len); @@ -2601,6 +2603,7 @@ static struct eisa_driver sx_eisadriver = { #endif +#ifdef CONFIG_PCI /******************************************************** * Setting bit 17 in the CNTRL register of the PLX 9050 * * chip forces a retry on writes while a read is pending.* @@ -2632,10 +2635,12 @@ static void __devinit fix_sx_pci(struct pci_dev *pdev, struct sx_board *board) } iounmap(rebase); } +#endif static int __devinit sx_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { +#ifdef CONFIG_PCI struct sx_board *board; unsigned int i, reg; int retval = -EIO; @@ -2700,6 +2705,9 @@ err_flag: board->flags &= ~SX_BOARD_PRESENT; err: return retval; +#else + return -ENODEV; +#endif } static void __devexit sx_pci_remove(struct pci_dev *pdev) diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c index acc6fab601cc..3fa625db9e4b 100644 --- a/drivers/char/synclink.c +++ b/drivers/char/synclink.c @@ -4332,7 +4332,7 @@ static struct mgsl_struct* mgsl_allocate_device(void) { struct mgsl_struct *info; - info = (struct mgsl_struct *)kmalloc(sizeof(struct mgsl_struct), + info = kmalloc(sizeof(struct mgsl_struct), GFP_KERNEL); if (!info) { diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c index 53e8ccf94fe3..8f4d67afe5bf 100644 --- a/drivers/char/synclinkmp.c +++ b/drivers/char/synclinkmp.c @@ -2730,7 +2730,7 @@ static int startup(SLMP_INFO * info) return 0; if (!info->tx_buf) { - info->tx_buf = (unsigned char *)kmalloc(info->max_frame_size, GFP_KERNEL); + info->tx_buf = kmalloc(info->max_frame_size, GFP_KERNEL); if (!info->tx_buf) { printk(KERN_ERR"%s(%d):%s can't allocate transmit buffer\n", __FILE__,__LINE__,info->device_name); @@ -3798,7 +3798,7 @@ static SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev) { SLMP_INFO *info; - info = (SLMP_INFO *)kmalloc(sizeof(SLMP_INFO), + info = kmalloc(sizeof(SLMP_INFO), GFP_KERNEL); if (!info) { diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c index 05810c8d20bc..13935235e066 100644 --- a/drivers/char/sysrq.c +++ b/drivers/char/sysrq.c @@ -41,7 +41,34 @@ #include <asm/irq_regs.h> /* Whether we react on sysrq keys or just ignore them */ -int sysrq_enabled = 1; +int __read_mostly __sysrq_enabled = 1; + +static int __read_mostly sysrq_always_enabled; + +int sysrq_on(void) +{ + return __sysrq_enabled || sysrq_always_enabled; +} + +/* + * A value of 1 means 'all', other nonzero values are an op mask: + */ +static inline int sysrq_on_mask(int mask) +{ + return sysrq_always_enabled || __sysrq_enabled == 1 || + (__sysrq_enabled & mask); +} + +static int __init sysrq_always_enabled_setup(char *str) +{ + sysrq_always_enabled = 1; + printk(KERN_INFO "debug: sysrq always enabled.\n"); + + return 1; +} + +__setup("sysrq_always_enabled", sysrq_always_enabled_setup); + static void sysrq_handle_loglevel(int key, struct tty_struct *tty) { @@ -379,8 +406,7 @@ void __handle_sysrq(int key, struct tty_struct *tty, int check_mask) * Should we check for enabled operations (/proc/sysrq-trigger * should not) and is the invoked operation enabled? */ - if (!check_mask || sysrq_enabled == 1 || - (sysrq_enabled & op_p->enable_mask)) { + if (!check_mask || sysrq_on_mask(op_p->enable_mask)) { printk("%s\n", op_p->action_msg); console_loglevel = orig_log_level; op_p->handler(key, tty); @@ -414,9 +440,8 @@ void __handle_sysrq(int key, struct tty_struct *tty, int check_mask) */ void handle_sysrq(int key, struct tty_struct *tty) { - if (!sysrq_enabled) - return; - __handle_sysrq(key, tty, 1); + if (sysrq_on()) + __handle_sysrq(key, tty, 1); } EXPORT_SYMBOL(handle_sysrq); diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 4044c864fdd4..47a6eacb10bc 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -3335,18 +3335,13 @@ static void __do_SAK(struct work_struct *work) int session; int i; struct file *filp; - struct tty_ldisc *disc; struct fdtable *fdt; if (!tty) return; session = tty->session; - /* We don't want an ldisc switch during this */ - disc = tty_ldisc_ref(tty); - if (disc && disc->flush_buffer) - disc->flush_buffer(tty); - tty_ldisc_deref(disc); + tty_ldisc_flush(tty); if (tty->driver->flush_buffer) tty->driver->flush_buffer(tty); @@ -3821,6 +3816,7 @@ struct tty_struct *get_current_tty(void) barrier(); return tty; } +EXPORT_SYMBOL_GPL(get_current_tty); /* * Initialize the console device. This is called *early*, so diff --git a/drivers/char/viocons.c b/drivers/char/viocons.c index 6d2e314860df..0e0da443cbd5 100644 --- a/drivers/char/viocons.c +++ b/drivers/char/viocons.c @@ -61,10 +61,7 @@ static DEFINE_SPINLOCK(consolelock); static DEFINE_SPINLOCK(consoleloglock); -#ifdef CONFIG_MAGIC_SYSRQ static int vio_sysrq_pressed; -extern int sysrq_enabled; -#endif #define VIOCHAR_NUM_BUF 16 @@ -936,8 +933,10 @@ static void vioHandleData(struct HvLpEvent *event) */ num_pushed = 0; for (index = 0; index < cevent->len; index++) { -#ifdef CONFIG_MAGIC_SYSRQ - if (sysrq_enabled) { + /* + * Will be optimized away if !CONFIG_MAGIC_SYSRQ: + */ + if (sysrq_on()) { /* 0x0f is the ascii character for ^O */ if (cevent->data[index] == '\x0f') { vio_sysrq_pressed = 1; @@ -956,7 +955,6 @@ static void vioHandleData(struct HvLpEvent *event) continue; } } -#endif /* * The sysrq sequence isn't included in this check if * sysrq is enabled and compiled into the kernel because diff --git a/drivers/char/vt.c b/drivers/char/vt.c index a8239dac994f..06c32a3e3ca4 100644 --- a/drivers/char/vt.c +++ b/drivers/char/vt.c @@ -784,7 +784,7 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines) if (new_cols == vc->vc_cols && new_rows == vc->vc_rows) return 0; - newscreen = (unsigned short *) kmalloc(new_screen_size, GFP_USER); + newscreen = kmalloc(new_screen_size, GFP_USER); if (!newscreen) return -ENOMEM; diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c index ac5d60edbafa..dc8368ebb1ac 100644 --- a/drivers/char/vt_ioctl.c +++ b/drivers/char/vt_ioctl.c @@ -129,7 +129,7 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str !capable(CAP_SYS_RESOURCE)) return -EPERM; - key_map = (ushort *) kmalloc(sizeof(plain_map), + key_map = kmalloc(sizeof(plain_map), GFP_KERNEL); if (!key_map) return -ENOMEM; @@ -259,7 +259,7 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm) sz = 256; while (sz < funcbufsize - funcbufleft + delta) sz <<= 1; - fnw = (char *) kmalloc(sz, GFP_KERNEL); + fnw = kmalloc(sz, GFP_KERNEL); if(!fnw) { ret = -ENOMEM; goto reterr; @@ -1087,7 +1087,7 @@ static void complete_change_console(struct vc_data *vc) switch_screen(vc); /* - * This can't appear below a successful kill_proc(). If it did, + * This can't appear below a successful kill_pid(). If it did, * then the *blank_screen operation could occur while X, having * received acqsig, is waking up on another processor. This * condition can lead to overlapping accesses to the VGA range @@ -1110,7 +1110,7 @@ static void complete_change_console(struct vc_data *vc) */ if (vc->vt_mode.mode == VT_PROCESS) { /* - * Send the signal as privileged - kill_proc() will + * Send the signal as privileged - kill_pid() will * tell us if the process has gone or something else * is awry */ @@ -1170,7 +1170,7 @@ void change_console(struct vc_data *new_vc) vc = vc_cons[fg_console].d; if (vc->vt_mode.mode == VT_PROCESS) { /* - * Send the signal as privileged - kill_proc() will + * Send the signal as privileged - kill_pid() will * tell us if the process has gone or something else * is awry */ diff --git a/drivers/fc4/fc.c b/drivers/fc4/fc.c index ca4e67a022d0..22b62b3cd14e 100644 --- a/drivers/fc4/fc.c +++ b/drivers/fc4/fc.c @@ -266,7 +266,7 @@ static void fcp_report_map_done(fc_channel *fc, int i, int status) printk ("FC: Bad magic from REPORT_AL_MAP on %s - %08x\n", fc->name, p->magic); fc->state = FC_STATE_OFFLINE; } else { - fc->posmap = (fcp_posmap *)kzalloc(sizeof(fcp_posmap)+p->len, GFP_KERNEL); + fc->posmap = kzalloc(sizeof(fcp_posmap)+p->len, GFP_KERNEL); if (!fc->posmap) { printk("FC: Not enough memory, offlining channel\n"); fc->state = FC_STATE_OFFLINE; @@ -355,7 +355,7 @@ void fcp_register(fc_channel *fc, u8 type, int unregister) for (i = fc->can_queue; i < fc->scsi_bitmap_end; i++) set_bit (i, fc->scsi_bitmap); fc->scsi_free = fc->can_queue; - fc->cmd_slots = (fcp_cmnd **)kzalloc(slots * sizeof(fcp_cmnd*), GFP_KERNEL); + fc->cmd_slots = kzalloc(slots * sizeof(fcp_cmnd*), GFP_KERNEL); fc->abort_count = 0; } else { fc->scsi_name[0] = 0; @@ -933,7 +933,7 @@ int fcp_scsi_dev_reset(struct scsi_cmnd *SCpnt) DECLARE_MUTEX_LOCKED(sem); if (!fc->rst_pkt) { - fc->rst_pkt = (struct scsi_cmnd *) kmalloc(sizeof(SCpnt), GFP_KERNEL); + fc->rst_pkt = kmalloc(sizeof(SCpnt), GFP_KERNEL); if (!fc->rst_pkt) return FAILED; fcmd = FCP_CMND(fc->rst_pkt); @@ -1107,7 +1107,7 @@ int fc_do_plogi(fc_channel *fc, unsigned char alpa, fc_wwn *node, fc_wwn *nport) logi *l; int status; - l = (logi *)kzalloc(2 * sizeof(logi), GFP_KERNEL); + l = kzalloc(2 * sizeof(logi), GFP_KERNEL); if (!l) return -ENOMEM; l->code = LS_PLOGI; memcpy (&l->nport_wwn, &fc->wwn_nport, sizeof(fc_wwn)); @@ -1141,7 +1141,7 @@ int fc_do_prli(fc_channel *fc, unsigned char alpa) prli *p; int status; - p = (prli *)kzalloc(2 * sizeof(prli), GFP_KERNEL); + p = kzalloc(2 * sizeof(prli), GFP_KERNEL); if (!p) return -ENOMEM; p->code = LS_PRLI; p->params[0] = 0x08002000; diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index e76d91906c99..891ef6d0b1bf 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -106,6 +106,31 @@ config SENSORS_K8TEMP This driver can also be built as a module. If so, the module will be called k8temp. +config SENSORS_AMS + tristate "Apple Motion Sensor driver" + depends on HWMON && PPC_PMAC && !PPC64 && INPUT && ((ADB_PMU && I2C = y) || (ADB_PMU && !I2C) || I2C) && EXPERIMENTAL + help + Support for the motion sensor included in PowerBooks. Includes + implementations for PMU and I2C. + + This driver can also be built as a module. If so, the module + will be called ams. + +config SENSORS_AMS_PMU + bool "PMU variant" + depends on SENSORS_AMS && ADB_PMU + default y + help + PMU variant of motion sensor, found in late 2005 PowerBooks. + +config SENSORS_AMS_I2C + bool "I2C variant" + depends on SENSORS_AMS && I2C + default y + help + I2C variant of motion sensor, found in early 2005 PowerBooks and + iBooks. + config SENSORS_ASB100 tristate "Asus ASB100 Bach" depends on HWMON && I2C && EXPERIMENTAL @@ -142,11 +167,12 @@ config SENSORS_DS1621 will be called ds1621. config SENSORS_F71805F - tristate "Fintek F71805F/FG" + tristate "Fintek F71805F/FG and F71872F/FG" depends on HWMON && EXPERIMENTAL help If you say yes here you get support for hardware monitoring - features of the Fintek F71805F/FG chips. + features of the Fintek F71805F/FG and F71872F/FG Super-I/O + chips. This driver can also be built as a module. If so, the module will be called f71805f. @@ -353,6 +379,19 @@ config SENSORS_PC87360 This driver can also be built as a module. If so, the module will be called pc87360. +config SENSORS_PC87427 + tristate "National Semiconductor PC87427" + depends on HWMON && EXPERIMENTAL + help + If you say yes here you get access to the hardware monitoring + functions of the National Semiconductor PC87427 Super-I/O chip. + The chip has two distinct logical devices, one for fan speed + monitoring and control, and one for voltage and temperature + monitoring. Only fan speed monitoring is supported right now. + + This driver can also be built as a module. If so, the module + will be called pc87427. + config SENSORS_SIS5595 tristate "Silicon Integrated Systems Corp. SiS5595" depends on HWMON && I2C && PCI && EXPERIMENTAL @@ -474,6 +513,16 @@ config SENSORS_W83792D This driver can also be built as a module. If so, the module will be called w83792d. +config SENSORS_W83793 + tristate "Winbond W83793" + depends on HWMON && I2C && EXPERIMENTAL + help + If you say yes here you get support for the Winbond W83793 + hardware monitoring chip. + + This driver can also be built as a module. If so, the module + will be called w83793. + config SENSORS_W83L785TS tristate "Winbond W83L785TS-S" depends on HWMON && I2C && EXPERIMENTAL @@ -527,6 +576,9 @@ config SENSORS_HDAPS This driver also provides an absolute input class device, allowing the laptop to act as a pinball machine-esque joystick. + If your ThinkPad is not recognized by the driver, please update to latest + BIOS. This is especially the case for some R52 ThinkPads. + Say Y here if you have an applicable laptop and want to experience the awesome power of hdaps. diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index af01cc64f7d2..31661124271e 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -9,6 +9,7 @@ obj-$(CONFIG_HWMON_VID) += hwmon-vid.o obj-$(CONFIG_SENSORS_ASB100) += asb100.o obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o obj-$(CONFIG_SENSORS_W83792D) += w83792d.o +obj-$(CONFIG_SENSORS_W83793) += w83793.o obj-$(CONFIG_SENSORS_W83781D) += w83781d.o obj-$(CONFIG_SENSORS_W83791D) += w83791d.o @@ -18,6 +19,7 @@ obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o +obj-$(CONFIG_SENSORS_AMS) += ams/ obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o obj-$(CONFIG_SENSORS_DS1621) += ds1621.o obj-$(CONFIG_SENSORS_F71805F) += f71805f.o @@ -41,6 +43,7 @@ obj-$(CONFIG_SENSORS_LM90) += lm90.o obj-$(CONFIG_SENSORS_LM92) += lm92.o obj-$(CONFIG_SENSORS_MAX1619) += max1619.o obj-$(CONFIG_SENSORS_PC87360) += pc87360.o +obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o diff --git a/drivers/hwmon/ams/Makefile b/drivers/hwmon/ams/Makefile new file mode 100644 index 000000000000..41c95b2089dc --- /dev/null +++ b/drivers/hwmon/ams/Makefile @@ -0,0 +1,8 @@ +# +# Makefile for Apple Motion Sensor driver +# + +ams-y := ams-core.o ams-input.o +ams-$(CONFIG_SENSORS_AMS_PMU) += ams-pmu.o +ams-$(CONFIG_SENSORS_AMS_I2C) += ams-i2c.o +obj-$(CONFIG_SENSORS_AMS) += ams.o diff --git a/drivers/hwmon/ams/ams-core.c b/drivers/hwmon/ams/ams-core.c new file mode 100644 index 000000000000..f1f0f5d0442c --- /dev/null +++ b/drivers/hwmon/ams/ams-core.c @@ -0,0 +1,265 @@ +/* + * Apple Motion Sensor driver + * + * Copyright (C) 2005 Stelian Pop (stelian@popies.net) + * Copyright (C) 2006 Michael Hanselmann (linux-kernel@hansmi.ch) + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <linux/module.h> +#include <linux/types.h> +#include <linux/errno.h> +#include <linux/init.h> +#include <linux/module.h> +#include <asm/pmac_pfunc.h> +#include <asm/of_platform.h> + +#include "ams.h" + +/* There is only one motion sensor per machine */ +struct ams ams_info; + +static unsigned int verbose; +module_param(verbose, bool, 0644); +MODULE_PARM_DESC(verbose, "Show free falls and shocks in kernel output"); + +/* Call with ams_info.lock held! */ +void ams_sensors(s8 *x, s8 *y, s8 *z) +{ + u32 orient = ams_info.vflag? ams_info.orient1 : ams_info.orient2; + + if (orient & 0x80) + /* X and Y swapped */ + ams_info.get_xyz(y, x, z); + else + ams_info.get_xyz(x, y, z); + + if (orient & 0x04) + *z = ~(*z); + if (orient & 0x02) + *y = ~(*y); + if (orient & 0x01) + *x = ~(*x); +} + +static ssize_t ams_show_current(struct device *dev, + struct device_attribute *attr, char *buf) +{ + s8 x, y, z; + + mutex_lock(&ams_info.lock); + ams_sensors(&x, &y, &z); + mutex_unlock(&ams_info.lock); + + return snprintf(buf, PAGE_SIZE, "%d %d %d\n", x, y, z); +} + +static DEVICE_ATTR(current, S_IRUGO, ams_show_current, NULL); + +static void ams_handle_irq(void *data) +{ + enum ams_irq irq = *((enum ams_irq *)data); + + spin_lock(&ams_info.irq_lock); + + ams_info.worker_irqs |= irq; + schedule_work(&ams_info.worker); + + spin_unlock(&ams_info.irq_lock); +} + +static enum ams_irq ams_freefall_irq_data = AMS_IRQ_FREEFALL; +static struct pmf_irq_client ams_freefall_client = { + .owner = THIS_MODULE, + .handler = ams_handle_irq, + .data = &ams_freefall_irq_data, +}; + +static enum ams_irq ams_shock_irq_data = AMS_IRQ_SHOCK; +static struct pmf_irq_client ams_shock_client = { + .owner = THIS_MODULE, + .handler = ams_handle_irq, + .data = &ams_shock_irq_data, +}; + +/* Once hard disk parking is implemented in the kernel, this function can + * trigger it. + */ +static void ams_worker(struct work_struct *work) +{ + mutex_lock(&ams_info.lock); + + if (ams_info.has_device) { + unsigned long flags; + + spin_lock_irqsave(&ams_info.irq_lock, flags); + + if (ams_info.worker_irqs & AMS_IRQ_FREEFALL) { + if (verbose) + printk(KERN_INFO "ams: freefall detected!\n"); + + ams_info.worker_irqs &= ~AMS_IRQ_FREEFALL; + + /* we must call this with interrupts enabled */ + spin_unlock_irqrestore(&ams_info.irq_lock, flags); + ams_info.clear_irq(AMS_IRQ_FREEFALL); + spin_lock_irqsave(&ams_info.irq_lock, flags); + } + + if (ams_info.worker_irqs & AMS_IRQ_SHOCK) { + if (verbose) + printk(KERN_INFO "ams: shock detected!\n"); + + ams_info.worker_irqs &= ~AMS_IRQ_SHOCK; + + /* we must call this with interrupts enabled */ + spin_unlock_irqrestore(&ams_info.irq_lock, flags); + ams_info.clear_irq(AMS_IRQ_SHOCK); + spin_lock_irqsave(&ams_info.irq_lock, flags); + } + + spin_unlock_irqrestore(&ams_info.irq_lock, flags); + } + + mutex_unlock(&ams_info.lock); +} + +/* Call with ams_info.lock held! */ +int ams_sensor_attach(void) +{ + int result; + u32 *prop; + + /* Get orientation */ + prop = (u32*)get_property(ams_info.of_node, "orientation", NULL); + if (!prop) + return -ENODEV; + ams_info.orient1 = *prop; + ams_info.orient2 = *(prop + 1); + + /* Register freefall interrupt handler */ + result = pmf_register_irq_client(ams_info.of_node, + "accel-int-1", + &ams_freefall_client); + if (result < 0) + return -ENODEV; + + /* Reset saved irqs */ + ams_info.worker_irqs = 0; + + /* Register shock interrupt handler */ + result = pmf_register_irq_client(ams_info.of_node, + "accel-int-2", + &ams_shock_client); + if (result < 0) + goto release_freefall; + + /* Create device */ + ams_info.of_dev = of_platform_device_create(ams_info.of_node, "ams", NULL); + if (!ams_info.of_dev) { + result = -ENODEV; + goto release_shock; + } + + /* Create attributes */ + result = device_create_file(&ams_info.of_dev->dev, &dev_attr_current); + if (result) + goto release_of; + + ams_info.vflag = !!(ams_info.get_vendor() & 0x10); + + /* Init input device */ + result = ams_input_init(); + if (result) + goto release_device_file; + + return result; +release_device_file: + device_remove_file(&ams_info.of_dev->dev, &dev_attr_current); +release_of: + of_device_unregister(ams_info.of_dev); +release_shock: + pmf_unregister_irq_client(&ams_shock_client); +release_freefall: + pmf_unregister_irq_client(&ams_freefall_client); + return result; +} + +int __init ams_init(void) +{ + struct device_node *np; + + spin_lock_init(&ams_info.irq_lock); + mutex_init(&ams_info.lock); + INIT_WORK(&ams_info.worker, ams_worker); + +#ifdef CONFIG_SENSORS_AMS_I2C + np = of_find_node_by_name(NULL, "accelerometer"); + if (np && device_is_compatible(np, "AAPL,accelerometer_1")) + /* Found I2C motion sensor */ + return ams_i2c_init(np); +#endif + +#ifdef CONFIG_SENSORS_AMS_PMU + np = of_find_node_by_name(NULL, "sms"); + if (np && device_is_compatible(np, "sms")) + /* Found PMU motion sensor */ + return ams_pmu_init(np); +#endif + + printk(KERN_ERR "ams: No motion sensor found.\n"); + + return -ENODEV; +} + +void ams_exit(void) +{ + mutex_lock(&ams_info.lock); + + if (ams_info.has_device) { + /* Remove input device */ + ams_input_exit(); + + /* Shut down implementation */ + ams_info.exit(); + + /* Flush interrupt worker + * + * We do this after ams_info.exit(), because an interrupt might + * have arrived before disabling them. + */ + flush_scheduled_work(); + + /* Remove attributes */ + device_remove_file(&ams_info.of_dev->dev, &dev_attr_current); + + /* Remove device */ + of_device_unregister(ams_info.of_dev); + + /* Remove handler */ + pmf_unregister_irq_client(&ams_shock_client); + pmf_unregister_irq_client(&ams_freefall_client); + } + + mutex_unlock(&ams_info.lock); +} + +MODULE_AUTHOR("Stelian Pop, Michael Hanselmann"); +MODULE_DESCRIPTION("Apple Motion Sensor driver"); +MODULE_LICENSE("GPL"); + +module_init(ams_init); +module_exit(ams_exit); diff --git a/drivers/hwmon/ams/ams-i2c.c b/drivers/hwmon/ams/ams-i2c.c new file mode 100644 index 000000000000..0d24bdfea53e --- /dev/null +++ b/drivers/hwmon/ams/ams-i2c.c @@ -0,0 +1,299 @@ +/* + * Apple Motion Sensor driver (I2C variant) + * + * Copyright (C) 2005 Stelian Pop (stelian@popies.net) + * Copyright (C) 2006 Michael Hanselmann (linux-kernel@hansmi.ch) + * + * Clean room implementation based on the reverse engineered Mac OS X driver by + * Johannes Berg <johannes@sipsolutions.net>, documentation available at + * http://johannes.sipsolutions.net/PowerBook/Apple_Motion_Sensor_Specification + * + * 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/module.h> +#include <linux/types.h> +#include <linux/errno.h> +#include <linux/init.h> +#include <linux/delay.h> + +#include "ams.h" + +/* AMS registers */ +#define AMS_COMMAND 0x00 /* command register */ +#define AMS_STATUS 0x01 /* status register */ +#define AMS_CTRL1 0x02 /* read control 1 (number of values) */ +#define AMS_CTRL2 0x03 /* read control 2 (offset?) */ +#define AMS_CTRL3 0x04 /* read control 3 (size of each value?) */ +#define AMS_DATA1 0x05 /* read data 1 */ +#define AMS_DATA2 0x06 /* read data 2 */ +#define AMS_DATA3 0x07 /* read data 3 */ +#define AMS_DATA4 0x08 /* read data 4 */ +#define AMS_DATAX 0x20 /* data X */ +#define AMS_DATAY 0x21 /* data Y */ +#define AMS_DATAZ 0x22 /* data Z */ +#define AMS_FREEFALL 0x24 /* freefall int control */ +#define AMS_SHOCK 0x25 /* shock int control */ +#define AMS_SENSLOW 0x26 /* sensitivity low limit */ +#define AMS_SENSHIGH 0x27 /* sensitivity high limit */ +#define AMS_CTRLX 0x28 /* control X */ +#define AMS_CTRLY 0x29 /* control Y */ +#define AMS_CTRLZ 0x2A /* control Z */ +#define AMS_UNKNOWN1 0x2B /* unknown 1 */ +#define AMS_UNKNOWN2 0x2C /* unknown 2 */ +#define AMS_UNKNOWN3 0x2D /* unknown 3 */ +#define AMS_VENDOR 0x2E /* vendor */ + +/* AMS commands - use with the AMS_COMMAND register */ +enum ams_i2c_cmd { + AMS_CMD_NOOP = 0, + AMS_CMD_VERSION, + AMS_CMD_READMEM, + AMS_CMD_WRITEMEM, + AMS_CMD_ERASEMEM, + AMS_CMD_READEE, + AMS_CMD_WRITEEE, + AMS_CMD_RESET, + AMS_CMD_START, +}; + +static int ams_i2c_attach(struct i2c_adapter *adapter); +static int ams_i2c_detach(struct i2c_adapter *adapter); + +static struct i2c_driver ams_i2c_driver = { + .driver = { + .name = "ams", + .owner = THIS_MODULE, + }, + .attach_adapter = ams_i2c_attach, + .detach_adapter = ams_i2c_detach, +}; + +static s32 ams_i2c_read(u8 reg) +{ + return i2c_smbus_read_byte_data(&ams_info.i2c_client, reg); +} + +static int ams_i2c_write(u8 reg, u8 value) +{ + return i2c_smbus_write_byte_data(&ams_info.i2c_client, reg, value); +} + +static int ams_i2c_cmd(enum ams_i2c_cmd cmd) +{ + s32 result; + int remaining = HZ / 20; + + ams_i2c_write(AMS_COMMAND, cmd); + mdelay(5); + + while (remaining) { + result = ams_i2c_read(AMS_COMMAND); + if (result == 0 || result & 0x80) + return 0; + + remaining = schedule_timeout(remaining); + } + + return -1; +} + +static void ams_i2c_set_irq(enum ams_irq reg, char enable) +{ + if (reg & AMS_IRQ_FREEFALL) { + u8 val = ams_i2c_read(AMS_CTRLX); + if (enable) + val |= 0x80; + else + val &= ~0x80; + ams_i2c_write(AMS_CTRLX, val); + } + + if (reg & AMS_IRQ_SHOCK) { + u8 val = ams_i2c_read(AMS_CTRLY); + if (enable) + val |= 0x80; + else + val &= ~0x80; + ams_i2c_write(AMS_CTRLY, val); + } + + if (reg & AMS_IRQ_GLOBAL) { + u8 val = ams_i2c_read(AMS_CTRLZ); + if (enable) + val |= 0x80; + else + val &= ~0x80; + ams_i2c_write(AMS_CTRLZ, val); + } +} + +static void ams_i2c_clear_irq(enum ams_irq reg) +{ + if (reg & AMS_IRQ_FREEFALL) + ams_i2c_write(AMS_FREEFALL, 0); + + if (reg & AMS_IRQ_SHOCK) + ams_i2c_write(AMS_SHOCK, 0); +} + +static u8 ams_i2c_get_vendor(void) +{ + return ams_i2c_read(AMS_VENDOR); +} + +static void ams_i2c_get_xyz(s8 *x, s8 *y, s8 *z) +{ + *x = ams_i2c_read(AMS_DATAX); + *y = ams_i2c_read(AMS_DATAY); + *z = ams_i2c_read(AMS_DATAZ); +} + +static int ams_i2c_attach(struct i2c_adapter *adapter) +{ + unsigned long bus; + int vmaj, vmin; + int result; + + /* There can be only one */ + if (unlikely(ams_info.has_device)) + return -ENODEV; + + if (strncmp(adapter->name, "uni-n", 5)) + return -ENODEV; + + bus = simple_strtoul(adapter->name + 6, NULL, 10); + if (bus != ams_info.i2c_bus) + return -ENODEV; + + ams_info.i2c_client.addr = ams_info.i2c_address; + ams_info.i2c_client.adapter = adapter; + ams_info.i2c_client.driver = &ams_i2c_driver; + strcpy(ams_info.i2c_client.name, "Apple Motion Sensor"); + + if (ams_i2c_cmd(AMS_CMD_RESET)) { + printk(KERN_INFO "ams: Failed to reset the device\n"); + return -ENODEV; + } + + if (ams_i2c_cmd(AMS_CMD_START)) { + printk(KERN_INFO "ams: Failed to start the device\n"); + return -ENODEV; + } + + /* get version/vendor information */ + ams_i2c_write(AMS_CTRL1, 0x02); + ams_i2c_write(AMS_CTRL2, 0x85); + ams_i2c_write(AMS_CTRL3, 0x01); + + ams_i2c_cmd(AMS_CMD_READMEM); + + vmaj = ams_i2c_read(AMS_DATA1); + vmin = ams_i2c_read(AMS_DATA2); + if (vmaj != 1 || vmin != 52) { + printk(KERN_INFO "ams: Incorrect device version (%d.%d)\n", + vmaj, vmin); + return -ENODEV; + } + + ams_i2c_cmd(AMS_CMD_VERSION); + + vmaj = ams_i2c_read(AMS_DATA1); + vmin = ams_i2c_read(AMS_DATA2); + if (vmaj != 0 || vmin != 1) { + printk(KERN_INFO "ams: Incorrect firmware version (%d.%d)\n", + vmaj, vmin); + return -ENODEV; + } + + /* Disable interrupts */ + ams_i2c_set_irq(AMS_IRQ_ALL, 0); + + result = ams_sensor_attach(); + if (result < 0) + return result; + + /* Set default values */ + ams_i2c_write(AMS_SENSLOW, 0x15); + ams_i2c_write(AMS_SENSHIGH, 0x60); + ams_i2c_write(AMS_CTRLX, 0x08); + ams_i2c_write(AMS_CTRLY, 0x0F); + ams_i2c_write(AMS_CTRLZ, 0x4F); + ams_i2c_write(AMS_UNKNOWN1, 0x14); + + /* Clear interrupts */ + ams_i2c_clear_irq(AMS_IRQ_ALL); + + ams_info.has_device = 1; + + /* Enable interrupts */ + ams_i2c_set_irq(AMS_IRQ_ALL, 1); + + printk(KERN_INFO "ams: Found I2C based motion sensor\n"); + + return 0; +} + +static int ams_i2c_detach(struct i2c_adapter *adapter) +{ + if (ams_info.has_device) { + /* Disable interrupts */ + ams_i2c_set_irq(AMS_IRQ_ALL, 0); + + /* Clear interrupts */ + ams_i2c_clear_irq(AMS_IRQ_ALL); + + printk(KERN_INFO "ams: Unloading\n"); + + ams_info.has_device = 0; + } + + return 0; +} + +static void ams_i2c_exit(void) +{ + i2c_del_driver(&ams_i2c_driver); +} + +int __init ams_i2c_init(struct device_node *np) +{ + char *tmp_bus; + int result; + u32 *prop; + + mutex_lock(&ams_info.lock); + + /* Set implementation stuff */ + ams_info.of_node = np; + ams_info.exit = ams_i2c_exit; + ams_info.get_vendor = ams_i2c_get_vendor; + ams_info.get_xyz = ams_i2c_get_xyz; + ams_info.clear_irq = ams_i2c_clear_irq; + ams_info.bustype = BUS_I2C; + + /* look for bus either using "reg" or by path */ + prop = (u32*)get_property(ams_info.of_node, "reg", NULL); + if (!prop) { + result = -ENODEV; + + goto exit; + } + + tmp_bus = strstr(ams_info.of_node->full_name, "/i2c-bus@"); + if (tmp_bus) + ams_info.i2c_bus = *(tmp_bus + 9) - '0'; + else + ams_info.i2c_bus = ((*prop) >> 8) & 0x0f; + ams_info.i2c_address = ((*prop) & 0xff) >> 1; + + result = i2c_add_driver(&ams_i2c_driver); + +exit: + mutex_unlock(&ams_info.lock); + + return result; +} diff --git a/drivers/hwmon/ams/ams-input.c b/drivers/hwmon/ams/ams-input.c new file mode 100644 index 000000000000..f126aa485134 --- /dev/null +++ b/drivers/hwmon/ams/ams-input.c @@ -0,0 +1,160 @@ +/* + * Apple Motion Sensor driver (joystick emulation) + * + * Copyright (C) 2005 Stelian Pop (stelian@popies.net) + * Copyright (C) 2006 Michael Hanselmann (linux-kernel@hansmi.ch) + * + * 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/module.h> + +#include <linux/types.h> +#include <linux/errno.h> +#include <linux/init.h> +#include <linux/delay.h> + +#include "ams.h" + +static unsigned int joystick; +module_param(joystick, bool, 0644); +MODULE_PARM_DESC(joystick, "Enable the input class device on module load"); + +static unsigned int invert; +module_param(invert, bool, 0644); +MODULE_PARM_DESC(invert, "Invert input data on X and Y axis"); + +static int ams_input_kthread(void *data) +{ + s8 x, y, z; + + while (!kthread_should_stop()) { + mutex_lock(&ams_info.lock); + + ams_sensors(&x, &y, &z); + + x -= ams_info.xcalib; + y -= ams_info.ycalib; + z -= ams_info.zcalib; + + input_report_abs(ams_info.idev, ABS_X, invert ? -x : x); + input_report_abs(ams_info.idev, ABS_Y, invert ? -y : y); + input_report_abs(ams_info.idev, ABS_Z, z); + + input_sync(ams_info.idev); + + mutex_unlock(&ams_info.lock); + + msleep(25); + } + + return 0; +} + +static int ams_input_open(struct input_dev *dev) +{ + ams_info.kthread = kthread_run(ams_input_kthread, NULL, "kams"); + return IS_ERR(ams_info.kthread) ? PTR_ERR(ams_info.kthread) : 0; +} + +static void ams_input_close(struct input_dev *dev) +{ + kthread_stop(ams_info.kthread); +} + +/* Call with ams_info.lock held! */ +static void ams_input_enable(void) +{ + s8 x, y, z; + + if (ams_info.idev) + return; + + ams_sensors(&x, &y, &z); + ams_info.xcalib = x; + ams_info.ycalib = y; + ams_info.zcalib = z; + + ams_info.idev = input_allocate_device(); + if (!ams_info.idev) + return; + + ams_info.idev->name = "Apple Motion Sensor"; + ams_info.idev->id.bustype = ams_info.bustype; + ams_info.idev->id.vendor = 0; + ams_info.idev->open = ams_input_open; + ams_info.idev->close = ams_input_close; + ams_info.idev->cdev.dev = &ams_info.of_dev->dev; + + input_set_abs_params(ams_info.idev, ABS_X, -50, 50, 3, 0); + input_set_abs_params(ams_info.idev, ABS_Y, -50, 50, 3, 0); + input_set_abs_params(ams_info.idev, ABS_Z, -50, 50, 3, 0); + + set_bit(EV_ABS, ams_info.idev->evbit); + set_bit(EV_KEY, ams_info.idev->evbit); + set_bit(BTN_TOUCH, ams_info.idev->keybit); + + if (input_register_device(ams_info.idev)) { + input_free_device(ams_info.idev); + ams_info.idev = NULL; + return; + } +} + +/* Call with ams_info.lock held! */ +static void ams_input_disable(void) +{ + if (ams_info.idev) { + input_unregister_device(ams_info.idev); + ams_info.idev = NULL; + } +} + +static ssize_t ams_input_show_joystick(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", joystick); +} + +static ssize_t ams_input_store_joystick(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + if (sscanf(buf, "%d\n", &joystick) != 1) + return -EINVAL; + + mutex_lock(&ams_info.lock); + + if (joystick) + ams_input_enable(); + else + ams_input_disable(); + + mutex_unlock(&ams_info.lock); + + return count; +} + +static DEVICE_ATTR(joystick, S_IRUGO | S_IWUSR, + ams_input_show_joystick, ams_input_store_joystick); + +/* Call with ams_info.lock held! */ +int ams_input_init(void) +{ + int result; + + result = device_create_file(&ams_info.of_dev->dev, &dev_attr_joystick); + + if (!result && joystick) + ams_input_enable(); + return result; +} + +/* Call with ams_info.lock held! */ +void ams_input_exit() +{ + ams_input_disable(); + device_remove_file(&ams_info.of_dev->dev, &dev_attr_joystick); +} diff --git a/drivers/hwmon/ams/ams-pmu.c b/drivers/hwmon/ams/ams-pmu.c new file mode 100644 index 000000000000..4636ae031a53 --- /dev/null +++ b/drivers/hwmon/ams/ams-pmu.c @@ -0,0 +1,207 @@ +/* + * Apple Motion Sensor driver (PMU variant) + * + * Copyright (C) 2006 Michael Hanselmann (linux-kernel@hansmi.ch) + * + * 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/module.h> +#include <linux/types.h> +#include <linux/errno.h> +#include <linux/init.h> +#include <linux/adb.h> +#include <linux/pmu.h> + +#include "ams.h" + +/* Attitude */ +#define AMS_X 0x00 +#define AMS_Y 0x01 +#define AMS_Z 0x02 + +/* Not exactly known, maybe chip vendor */ +#define AMS_VENDOR 0x03 + +/* Freefall registers */ +#define AMS_FF_CLEAR 0x04 +#define AMS_FF_ENABLE 0x05 +#define AMS_FF_LOW_LIMIT 0x06 +#define AMS_FF_DEBOUNCE 0x07 + +/* Shock registers */ +#define AMS_SHOCK_CLEAR 0x08 +#define AMS_SHOCK_ENABLE 0x09 +#define AMS_SHOCK_HIGH_LIMIT 0x0a +#define AMS_SHOCK_DEBOUNCE 0x0b + +/* Global interrupt and power control register */ +#define AMS_CONTROL 0x0c + +static u8 ams_pmu_cmd; + +static void ams_pmu_req_complete(struct adb_request *req) +{ + complete((struct completion *)req->arg); +} + +/* Only call this function from task context */ +static void ams_pmu_set_register(u8 reg, u8 value) +{ + static struct adb_request req; + DECLARE_COMPLETION(req_complete); + + req.arg = &req_complete; + if (pmu_request(&req, ams_pmu_req_complete, 4, ams_pmu_cmd, 0x00, reg, value)) + return; + + wait_for_completion(&req_complete); +} + +/* Only call this function from task context */ +static u8 ams_pmu_get_register(u8 reg) +{ + static struct adb_request req; + DECLARE_COMPLETION(req_complete); + + req.arg = &req_complete; + if (pmu_request(&req, ams_pmu_req_complete, 3, ams_pmu_cmd, 0x01, reg)) + return 0; + + wait_for_completion(&req_complete); + + if (req.reply_len > 0) + return req.reply[0]; + else + return 0; +} + +/* Enables or disables the specified interrupts */ +static void ams_pmu_set_irq(enum ams_irq reg, char enable) +{ + if (reg & AMS_IRQ_FREEFALL) { + u8 val = ams_pmu_get_register(AMS_FF_ENABLE); + if (enable) + val |= 0x80; + else + val &= ~0x80; + ams_pmu_set_register(AMS_FF_ENABLE, val); + } + + if (reg & AMS_IRQ_SHOCK) { + u8 val = ams_pmu_get_register(AMS_SHOCK_ENABLE); + if (enable) + val |= 0x80; + else + val &= ~0x80; + ams_pmu_set_register(AMS_SHOCK_ENABLE, val); + } + + if (reg & AMS_IRQ_GLOBAL) { + u8 val = ams_pmu_get_register(AMS_CONTROL); + if (enable) + val |= 0x80; + else + val &= ~0x80; + ams_pmu_set_register(AMS_CONTROL, val); + } +} + +static void ams_pmu_clear_irq(enum ams_irq reg) +{ + if (reg & AMS_IRQ_FREEFALL) + ams_pmu_set_register(AMS_FF_CLEAR, 0x00); + + if (reg & AMS_IRQ_SHOCK) + ams_pmu_set_register(AMS_SHOCK_CLEAR, 0x00); +} + +static u8 ams_pmu_get_vendor(void) +{ + return ams_pmu_get_register(AMS_VENDOR); +} + +static void ams_pmu_get_xyz(s8 *x, s8 *y, s8 *z) +{ + *x = ams_pmu_get_register(AMS_X); + *y = ams_pmu_get_register(AMS_Y); + *z = ams_pmu_get_register(AMS_Z); +} + +static void ams_pmu_exit(void) +{ + /* Disable interrupts */ + ams_pmu_set_irq(AMS_IRQ_ALL, 0); + + /* Clear interrupts */ + ams_pmu_clear_irq(AMS_IRQ_ALL); + + ams_info.has_device = 0; + + printk(KERN_INFO "ams: Unloading\n"); +} + +int __init ams_pmu_init(struct device_node *np) +{ + u32 *prop; + int result; + + mutex_lock(&ams_info.lock); + + /* Set implementation stuff */ + ams_info.of_node = np; + ams_info.exit = ams_pmu_exit; + ams_info.get_vendor = ams_pmu_get_vendor; + ams_info.get_xyz = ams_pmu_get_xyz; + ams_info.clear_irq = ams_pmu_clear_irq; + ams_info.bustype = BUS_HOST; + + /* Get PMU command, should be 0x4e, but we can never know */ + prop = (u32*)get_property(ams_info.of_node, "reg", NULL); + if (!prop) { + result = -ENODEV; + goto exit; + } + ams_pmu_cmd = ((*prop) >> 8) & 0xff; + + /* Disable interrupts */ + ams_pmu_set_irq(AMS_IRQ_ALL, 0); + + /* Clear interrupts */ + ams_pmu_clear_irq(AMS_IRQ_ALL); + + result = ams_sensor_attach(); + if (result < 0) + goto exit; + + /* Set default values */ + ams_pmu_set_register(AMS_FF_LOW_LIMIT, 0x15); + ams_pmu_set_register(AMS_FF_ENABLE, 0x08); + ams_pmu_set_register(AMS_FF_DEBOUNCE, 0x14); + + ams_pmu_set_register(AMS_SHOCK_HIGH_LIMIT, 0x60); + ams_pmu_set_register(AMS_SHOCK_ENABLE, 0x0f); + ams_pmu_set_register(AMS_SHOCK_DEBOUNCE, 0x14); + + ams_pmu_set_register(AMS_CONTROL, 0x4f); + + /* Clear interrupts */ + ams_pmu_clear_irq(AMS_IRQ_ALL); + + ams_info.has_device = 1; + + /* Enable interrupts */ + ams_pmu_set_irq(AMS_IRQ_ALL, 1); + + printk(KERN_INFO "ams: Found PMU based motion sensor\n"); + + result = 0; + +exit: + mutex_unlock(&ams_info.lock); + + return result; +} diff --git a/drivers/hwmon/ams/ams.h b/drivers/hwmon/ams/ams.h new file mode 100644 index 000000000000..240730e6bcde --- /dev/null +++ b/drivers/hwmon/ams/ams.h @@ -0,0 +1,72 @@ +#include <linux/i2c.h> +#include <linux/input.h> +#include <linux/kthread.h> +#include <linux/mutex.h> +#include <linux/spinlock.h> +#include <linux/types.h> +#include <asm/of_device.h> + +enum ams_irq { + AMS_IRQ_FREEFALL = 0x01, + AMS_IRQ_SHOCK = 0x02, + AMS_IRQ_GLOBAL = 0x04, + AMS_IRQ_ALL = + AMS_IRQ_FREEFALL | + AMS_IRQ_SHOCK | + AMS_IRQ_GLOBAL, +}; + +struct ams { + /* Locks */ + spinlock_t irq_lock; + struct mutex lock; + + /* General properties */ + struct device_node *of_node; + struct of_device *of_dev; + char has_device; + char vflag; + u32 orient1; + u32 orient2; + + /* Interrupt worker */ + struct work_struct worker; + u8 worker_irqs; + + /* Implementation + * + * Only call these functions with the main lock held. + */ + void (*exit)(void); + + void (*get_xyz)(s8 *x, s8 *y, s8 *z); + u8 (*get_vendor)(void); + + void (*clear_irq)(enum ams_irq reg); + +#ifdef CONFIG_SENSORS_AMS_I2C + /* I2C properties */ + int i2c_bus; + int i2c_address; + struct i2c_client i2c_client; +#endif + + /* Joystick emulation */ + struct task_struct *kthread; + struct input_dev *idev; + __u16 bustype; + + /* calibrated null values */ + int xcalib, ycalib, zcalib; +}; + +extern struct ams ams_info; + +extern void ams_sensors(s8 *x, s8 *y, s8 *z); +extern int ams_sensor_attach(void); + +extern int ams_pmu_init(struct device_node *np); +extern int ams_i2c_init(struct device_node *np); + +extern int ams_input_init(void); +extern void ams_input_exit(void); diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c index de17a72149d9..a272cae8f60e 100644 --- a/drivers/hwmon/f71805f.c +++ b/drivers/hwmon/f71805f.c @@ -1,12 +1,15 @@ /* - * f71805f.c - driver for the Fintek F71805F/FG Super-I/O chip integrated - * hardware monitoring features + * f71805f.c - driver for the Fintek F71805F/FG and F71872F/FG Super-I/O + * chips integrated hardware monitoring features * Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org> * * The F71805F/FG is a LPC Super-I/O chip made by Fintek. It integrates * complete hardware monitoring features: voltage, fan and temperature * sensors, and manual and automatic fan speed control. * + * The F71872F/FG is almost the same, with two more voltages monitored, + * and 6 VID inputs. + * * 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,6 +40,7 @@ static struct platform_device *pdev; #define DRVNAME "f71805f" +enum kinds { f71805f, f71872f }; /* * Super-I/O constants and functions @@ -48,11 +52,13 @@ static struct platform_device *pdev; #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */ #define SIO_REG_DEVREV 0x22 /* Device revision */ #define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */ +#define SIO_REG_FNSEL1 0x29 /* Multi Function Select 1 (F71872F) */ #define SIO_REG_ENABLE 0x30 /* Logical device enable */ #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ #define SIO_FINTEK_ID 0x1934 #define SIO_F71805F_ID 0x0406 +#define SIO_F71872F_ID 0x0341 static inline int superio_inb(int base, int reg) @@ -96,22 +102,25 @@ superio_exit(int base) * ISA constants */ -#define REGION_LENGTH 2 -#define ADDR_REG_OFFSET 0 -#define DATA_REG_OFFSET 1 +#define REGION_LENGTH 8 +#define ADDR_REG_OFFSET 5 +#define DATA_REG_OFFSET 6 /* * Registers */ -/* in nr from 0 to 8 (8-bit values) */ +/* in nr from 0 to 10 (8-bit values) */ #define F71805F_REG_IN(nr) (0x10 + (nr)) -#define F71805F_REG_IN_HIGH(nr) (0x40 + 2 * (nr)) -#define F71805F_REG_IN_LOW(nr) (0x41 + 2 * (nr)) +#define F71805F_REG_IN_HIGH(nr) ((nr) < 10 ? 0x40 + 2 * (nr) : 0x2E) +#define F71805F_REG_IN_LOW(nr) ((nr) < 10 ? 0x41 + 2 * (nr) : 0x2F) /* fan nr from 0 to 2 (12-bit values, two registers) */ #define F71805F_REG_FAN(nr) (0x20 + 2 * (nr)) #define F71805F_REG_FAN_LOW(nr) (0x28 + 2 * (nr)) +#define F71805F_REG_FAN_TARGET(nr) (0x69 + 16 * (nr)) #define F71805F_REG_FAN_CTRL(nr) (0x60 + 16 * (nr)) +#define F71805F_REG_PWM_FREQ(nr) (0x63 + 16 * (nr)) +#define F71805F_REG_PWM_DUTY(nr) (0x6B + 16 * (nr)) /* temp nr from 0 to 2 (8-bit values) */ #define F71805F_REG_TEMP(nr) (0x1B + (nr)) #define F71805F_REG_TEMP_HIGH(nr) (0x54 + 2 * (nr)) @@ -122,6 +131,14 @@ superio_exit(int base) /* status nr from 0 to 2 */ #define F71805F_REG_STATUS(nr) (0x36 + (nr)) +/* individual register bits */ +#define FAN_CTRL_DC_MODE 0x10 +#define FAN_CTRL_LATCH_FULL 0x08 +#define FAN_CTRL_MODE_MASK 0x03 +#define FAN_CTRL_MODE_SPEED 0x00 +#define FAN_CTRL_MODE_TEMPERATURE 0x01 +#define FAN_CTRL_MODE_MANUAL 0x02 + /* * Data structures and manipulation thereof */ @@ -138,12 +155,16 @@ struct f71805f_data { unsigned long last_limits; /* In jiffies */ /* Register values */ - u8 in[9]; - u8 in_high[9]; - u8 in_low[9]; + u8 in[11]; + u8 in_high[11]; + u8 in_low[11]; + u16 has_in; u16 fan[3]; u16 fan_low[3]; - u8 fan_enabled; /* Read once at init time */ + u16 fan_target[3]; + u8 fan_ctrl[3]; + u8 pwm[3]; + u8 pwm_freq[3]; u8 temp[3]; u8 temp_high[3]; u8 temp_hyst[3]; @@ -151,6 +172,11 @@ struct f71805f_data { unsigned long alarms; }; +struct f71805f_sio_data { + enum kinds kind; + u8 fnsel1; +}; + static inline long in_from_reg(u8 reg) { return (reg * 8); @@ -200,6 +226,33 @@ static inline u16 fan_to_reg(long rpm) return (1500000 / rpm); } +static inline unsigned long pwm_freq_from_reg(u8 reg) +{ + unsigned long clock = (reg & 0x80) ? 48000000UL : 1000000UL; + + reg &= 0x7f; + if (reg == 0) + reg++; + return clock / (reg << 8); +} + +static inline u8 pwm_freq_to_reg(unsigned long val) +{ + if (val >= 187500) /* The highest we can do */ + return 0x80; + if (val >= 1475) /* Use 48 MHz clock */ + return 0x80 | (48000000UL / (val << 8)); + if (val < 31) /* The lowest we can do */ + return 0x7f; + else /* Use 1 MHz clock */ + return 1000000UL / (val << 8); +} + +static inline int pwm_mode_from_reg(u8 reg) +{ + return !(reg & FAN_CTRL_DC_MODE); +} + static inline long temp_from_reg(u8 reg) { return (reg * 1000); @@ -274,16 +327,21 @@ static struct f71805f_data *f71805f_update_device(struct device *dev) /* Limit registers cache is refreshed after 60 seconds */ if (time_after(jiffies, data->last_updated + 60 * HZ) || !data->valid) { - for (nr = 0; nr < 9; nr++) { + for (nr = 0; nr < 11; nr++) { + if (!(data->has_in & (1 << nr))) + continue; data->in_high[nr] = f71805f_read8(data, F71805F_REG_IN_HIGH(nr)); data->in_low[nr] = f71805f_read8(data, F71805F_REG_IN_LOW(nr)); } for (nr = 0; nr < 3; nr++) { - if (data->fan_enabled & (1 << nr)) - data->fan_low[nr] = f71805f_read16(data, - F71805F_REG_FAN_LOW(nr)); + data->fan_low[nr] = f71805f_read16(data, + F71805F_REG_FAN_LOW(nr)); + data->fan_target[nr] = f71805f_read16(data, + F71805F_REG_FAN_TARGET(nr)); + data->pwm_freq[nr] = f71805f_read8(data, + F71805F_REG_PWM_FREQ(nr)); } for (nr = 0; nr < 3; nr++) { data->temp_high[nr] = f71805f_read8(data, @@ -299,14 +357,19 @@ static struct f71805f_data *f71805f_update_device(struct device *dev) /* Measurement registers cache is refreshed after 1 second */ if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { - for (nr = 0; nr < 9; nr++) { + for (nr = 0; nr < 11; nr++) { + if (!(data->has_in & (1 << nr))) + continue; data->in[nr] = f71805f_read8(data, F71805F_REG_IN(nr)); } for (nr = 0; nr < 3; nr++) { - if (data->fan_enabled & (1 << nr)) - data->fan[nr] = f71805f_read16(data, - F71805F_REG_FAN(nr)); + data->fan[nr] = f71805f_read16(data, + F71805F_REG_FAN(nr)); + data->fan_ctrl[nr] = f71805f_read8(data, + F71805F_REG_FAN_CTRL(nr)); + data->pwm[nr] = f71805f_read8(data, + F71805F_REG_PWM_DUTY(nr)); } for (nr = 0; nr < 3; nr++) { data->temp[nr] = f71805f_read8(data, @@ -333,35 +396,43 @@ static ssize_t show_in0(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; - return sprintf(buf, "%ld\n", in0_from_reg(data->in[0])); + return sprintf(buf, "%ld\n", in0_from_reg(data->in[nr])); } static ssize_t show_in0_max(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; - return sprintf(buf, "%ld\n", in0_from_reg(data->in_high[0])); + return sprintf(buf, "%ld\n", in0_from_reg(data->in_high[nr])); } static ssize_t show_in0_min(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; - return sprintf(buf, "%ld\n", in0_from_reg(data->in_low[0])); + return sprintf(buf, "%ld\n", in0_from_reg(data->in_low[nr])); } static ssize_t set_in0_max(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); - data->in_high[0] = in0_to_reg(val); - f71805f_write8(data, F71805F_REG_IN_HIGH(0), data->in_high[0]); + data->in_high[nr] = in0_to_reg(val); + f71805f_write8(data, F71805F_REG_IN_HIGH(nr), data->in_high[nr]); mutex_unlock(&data->update_lock); return count; @@ -371,11 +442,13 @@ static ssize_t set_in0_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); - data->in_low[0] = in0_to_reg(val); - f71805f_write8(data, F71805F_REG_IN_LOW(0), data->in_low[0]); + data->in_low[nr] = in0_to_reg(val); + f71805f_write8(data, F71805F_REG_IN_LOW(nr), data->in_low[nr]); mutex_unlock(&data->update_lock); return count; @@ -463,6 +536,16 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute return sprintf(buf, "%ld\n", fan_from_reg(data->fan_low[nr])); } +static ssize_t show_fan_target(struct device *dev, struct device_attribute + *devattr, char *buf) +{ + struct f71805f_data *data = f71805f_update_device(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; + + return sprintf(buf, "%ld\n", fan_from_reg(data->fan_target[nr])); +} + static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { @@ -479,6 +562,157 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute return count; } +static ssize_t set_fan_target(struct device *dev, struct device_attribute + *devattr, const char *buf, size_t count) +{ + struct f71805f_data *data = dev_get_drvdata(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; + long val = simple_strtol(buf, NULL, 10); + + mutex_lock(&data->update_lock); + data->fan_target[nr] = fan_to_reg(val); + f71805f_write16(data, F71805F_REG_FAN_TARGET(nr), + data->fan_target[nr]); + mutex_unlock(&data->update_lock); + + return count; +} + +static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, + char *buf) +{ + struct f71805f_data *data = f71805f_update_device(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; + + return sprintf(buf, "%d\n", (int)data->pwm[nr]); +} + +static ssize_t show_pwm_enable(struct device *dev, struct device_attribute + *devattr, char *buf) +{ + struct f71805f_data *data = f71805f_update_device(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; + int mode; + + switch (data->fan_ctrl[nr] & FAN_CTRL_MODE_MASK) { + case FAN_CTRL_MODE_SPEED: + mode = 3; + break; + case FAN_CTRL_MODE_TEMPERATURE: + mode = 2; + break; + default: /* MANUAL */ + mode = 1; + } + + return sprintf(buf, "%d\n", mode); +} + +static ssize_t show_pwm_freq(struct device *dev, struct device_attribute + *devattr, char *buf) +{ + struct f71805f_data *data = f71805f_update_device(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; + + return sprintf(buf, "%lu\n", pwm_freq_from_reg(data->pwm_freq[nr])); +} + +static ssize_t show_pwm_mode(struct device *dev, struct device_attribute + *devattr, char *buf) +{ + struct f71805f_data *data = f71805f_update_device(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; + + return sprintf(buf, "%d\n", pwm_mode_from_reg(data->fan_ctrl[nr])); +} + +static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, + const char *buf, size_t count) +{ + struct f71805f_data *data = dev_get_drvdata(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; + unsigned long val = simple_strtoul(buf, NULL, 10); + + if (val > 255) + return -EINVAL; + + mutex_lock(&data->update_lock); + data->pwm[nr] = val; + f71805f_write8(data, F71805F_REG_PWM_DUTY(nr), data->pwm[nr]); + mutex_unlock(&data->update_lock); + + return count; +} + +static struct attribute *f71805f_attr_pwm[]; + +static ssize_t set_pwm_enable(struct device *dev, struct device_attribute + *devattr, const char *buf, size_t count) +{ + struct f71805f_data *data = dev_get_drvdata(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; + unsigned long val = simple_strtoul(buf, NULL, 10); + u8 reg; + + if (val < 1 || val > 3) + return -EINVAL; + + if (val > 1) { /* Automatic mode, user can't set PWM value */ + if (sysfs_chmod_file(&dev->kobj, f71805f_attr_pwm[nr], + S_IRUGO)) + dev_dbg(dev, "chmod -w pwm%d failed\n", nr + 1); + } + + mutex_lock(&data->update_lock); + reg = f71805f_read8(data, F71805F_REG_FAN_CTRL(nr)) + & ~FAN_CTRL_MODE_MASK; + switch (val) { + case 1: + reg |= FAN_CTRL_MODE_MANUAL; + break; + case 2: + reg |= FAN_CTRL_MODE_TEMPERATURE; + break; + case 3: + reg |= FAN_CTRL_MODE_SPEED; + break; + } + data->fan_ctrl[nr] = reg; + f71805f_write8(data, F71805F_REG_FAN_CTRL(nr), reg); + mutex_unlock(&data->update_lock); + + if (val == 1) { /* Manual mode, user can set PWM value */ + if (sysfs_chmod_file(&dev->kobj, f71805f_attr_pwm[nr], + S_IRUGO | S_IWUSR)) + dev_dbg(dev, "chmod +w pwm%d failed\n", nr + 1); + } + + return count; +} + +static ssize_t set_pwm_freq(struct device *dev, struct device_attribute + *devattr, const char *buf, size_t count) +{ + struct f71805f_data *data = dev_get_drvdata(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; + unsigned long val = simple_strtoul(buf, NULL, 10); + + mutex_lock(&data->update_lock); + data->pwm_freq[nr] = pwm_freq_to_reg(val); + f71805f_write8(data, F71805F_REG_PWM_FREQ(nr), data->pwm_freq[nr]); + mutex_unlock(&data->update_lock); + + return count; +} + static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, char *buf) { @@ -557,7 +791,7 @@ static ssize_t show_alarms_in(struct device *dev, struct device_attribute { struct f71805f_data *data = f71805f_update_device(dev); - return sprintf(buf, "%lu\n", data->alarms & 0x1ff); + return sprintf(buf, "%lu\n", data->alarms & 0x7ff); } static ssize_t show_alarms_fan(struct device *dev, struct device_attribute @@ -594,9 +828,11 @@ static ssize_t show_name(struct device *dev, struct device_attribute return sprintf(buf, "%s\n", data->name); } -static DEVICE_ATTR(in0_input, S_IRUGO, show_in0, NULL); -static DEVICE_ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max); -static DEVICE_ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min); +static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in0, NULL, 0); +static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO| S_IWUSR, + show_in0_max, set_in0_max, 0); +static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO| S_IWUSR, + show_in0_min, set_in0_min, 0); static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1); static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR, show_in_max, set_in_max, 1); @@ -637,16 +873,32 @@ static SENSOR_DEVICE_ATTR(in8_max, S_IRUGO | S_IWUSR, show_in_max, set_in_max, 8); static SENSOR_DEVICE_ATTR(in8_min, S_IRUGO | S_IWUSR, show_in_min, set_in_min, 8); +static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_in0, NULL, 9); +static SENSOR_DEVICE_ATTR(in9_max, S_IRUGO | S_IWUSR, + show_in0_max, set_in0_max, 9); +static SENSOR_DEVICE_ATTR(in9_min, S_IRUGO | S_IWUSR, + show_in0_min, set_in0_min, 9); +static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_in0, NULL, 10); +static SENSOR_DEVICE_ATTR(in10_max, S_IRUGO | S_IWUSR, + show_in0_max, set_in0_max, 10); +static SENSOR_DEVICE_ATTR(in10_min, S_IRUGO | S_IWUSR, + show_in0_min, set_in0_min, 10); static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR, show_fan_min, set_fan_min, 0); +static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, + show_fan_target, set_fan_target, 0); static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1); static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR, show_fan_min, set_fan_min, 1); +static SENSOR_DEVICE_ATTR(fan2_target, S_IRUGO | S_IWUSR, + show_fan_target, set_fan_target, 1); static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2); static SENSOR_DEVICE_ATTR(fan3_min, S_IRUGO | S_IWUSR, show_fan_min, set_fan_min, 2); +static SENSOR_DEVICE_ATTR(fan3_target, S_IRUGO | S_IWUSR, + show_fan_target, set_fan_target, 2); static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, @@ -667,6 +919,27 @@ static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_hyst, set_temp_hyst, 2); static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2); +/* pwm (value) files are created read-only, write permission is + then added or removed dynamically as needed */ +static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO, show_pwm, set_pwm, 0); +static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, + show_pwm_enable, set_pwm_enable, 0); +static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, + show_pwm_freq, set_pwm_freq, 0); +static SENSOR_DEVICE_ATTR(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0); +static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO, show_pwm, set_pwm, 1); +static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, + show_pwm_enable, set_pwm_enable, 1); +static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO | S_IWUSR, + show_pwm_freq, set_pwm_freq, 1); +static SENSOR_DEVICE_ATTR(pwm2_mode, S_IRUGO, show_pwm_mode, NULL, 1); +static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO, show_pwm, set_pwm, 2); +static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, + show_pwm_enable, set_pwm_enable, 2); +static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO | S_IWUSR, + show_pwm_freq, set_pwm_freq, 2); +static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2); + static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); @@ -676,6 +949,8 @@ static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5); static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6); static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7); static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 8); +static SENSOR_DEVICE_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 9); +static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 10); static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 11); static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 12); static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13); @@ -689,9 +964,9 @@ static DEVICE_ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL); static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); static struct attribute *f71805f_attributes[] = { - &dev_attr_in0_input.attr, - &dev_attr_in0_max.attr, - &dev_attr_in0_min.attr, + &sensor_dev_attr_in0_input.dev_attr.attr, + &sensor_dev_attr_in0_max.dev_attr.attr, + &sensor_dev_attr_in0_min.dev_attr.attr, &sensor_dev_attr_in1_input.dev_attr.attr, &sensor_dev_attr_in1_max.dev_attr.attr, &sensor_dev_attr_in1_min.dev_attr.attr, @@ -701,9 +976,6 @@ static struct attribute *f71805f_attributes[] = { &sensor_dev_attr_in3_input.dev_attr.attr, &sensor_dev_attr_in3_max.dev_attr.attr, &sensor_dev_attr_in3_min.dev_attr.attr, - &sensor_dev_attr_in4_input.dev_attr.attr, - &sensor_dev_attr_in4_max.dev_attr.attr, - &sensor_dev_attr_in4_min.dev_attr.attr, &sensor_dev_attr_in5_input.dev_attr.attr, &sensor_dev_attr_in5_max.dev_attr.attr, &sensor_dev_attr_in5_min.dev_attr.attr, @@ -713,9 +985,29 @@ static struct attribute *f71805f_attributes[] = { &sensor_dev_attr_in7_input.dev_attr.attr, &sensor_dev_attr_in7_max.dev_attr.attr, &sensor_dev_attr_in7_min.dev_attr.attr, - &sensor_dev_attr_in8_input.dev_attr.attr, - &sensor_dev_attr_in8_max.dev_attr.attr, - &sensor_dev_attr_in8_min.dev_attr.attr, + + &sensor_dev_attr_fan1_input.dev_attr.attr, + &sensor_dev_attr_fan1_min.dev_attr.attr, + &sensor_dev_attr_fan1_alarm.dev_attr.attr, + &sensor_dev_attr_fan1_target.dev_attr.attr, + &sensor_dev_attr_fan2_input.dev_attr.attr, + &sensor_dev_attr_fan2_min.dev_attr.attr, + &sensor_dev_attr_fan2_alarm.dev_attr.attr, + &sensor_dev_attr_fan2_target.dev_attr.attr, + &sensor_dev_attr_fan3_input.dev_attr.attr, + &sensor_dev_attr_fan3_min.dev_attr.attr, + &sensor_dev_attr_fan3_alarm.dev_attr.attr, + &sensor_dev_attr_fan3_target.dev_attr.attr, + + &sensor_dev_attr_pwm1.dev_attr.attr, + &sensor_dev_attr_pwm1_enable.dev_attr.attr, + &sensor_dev_attr_pwm1_mode.dev_attr.attr, + &sensor_dev_attr_pwm2.dev_attr.attr, + &sensor_dev_attr_pwm2_enable.dev_attr.attr, + &sensor_dev_attr_pwm2_mode.dev_attr.attr, + &sensor_dev_attr_pwm3.dev_attr.attr, + &sensor_dev_attr_pwm3_enable.dev_attr.attr, + &sensor_dev_attr_pwm3_mode.dev_attr.attr, &sensor_dev_attr_temp1_input.dev_attr.attr, &sensor_dev_attr_temp1_max.dev_attr.attr, @@ -734,11 +1026,9 @@ static struct attribute *f71805f_attributes[] = { &sensor_dev_attr_in1_alarm.dev_attr.attr, &sensor_dev_attr_in2_alarm.dev_attr.attr, &sensor_dev_attr_in3_alarm.dev_attr.attr, - &sensor_dev_attr_in4_alarm.dev_attr.attr, &sensor_dev_attr_in5_alarm.dev_attr.attr, &sensor_dev_attr_in6_alarm.dev_attr.attr, &sensor_dev_attr_in7_alarm.dev_attr.attr, - &sensor_dev_attr_in8_alarm.dev_attr.attr, &dev_attr_alarms_in.attr, &sensor_dev_attr_temp1_alarm.dev_attr.attr, &sensor_dev_attr_temp2_alarm.dev_attr.attr, @@ -754,29 +1044,59 @@ static const struct attribute_group f71805f_group = { .attrs = f71805f_attributes, }; -static struct attribute *f71805f_attributes_fan[3][4] = { +static struct attribute *f71805f_attributes_optin[4][5] = { { - &sensor_dev_attr_fan1_input.dev_attr.attr, - &sensor_dev_attr_fan1_min.dev_attr.attr, - &sensor_dev_attr_fan1_alarm.dev_attr.attr, + &sensor_dev_attr_in4_input.dev_attr.attr, + &sensor_dev_attr_in4_max.dev_attr.attr, + &sensor_dev_attr_in4_min.dev_attr.attr, + &sensor_dev_attr_in4_alarm.dev_attr.attr, + NULL + }, { + &sensor_dev_attr_in8_input.dev_attr.attr, + &sensor_dev_attr_in8_max.dev_attr.attr, + &sensor_dev_attr_in8_min.dev_attr.attr, + &sensor_dev_attr_in8_alarm.dev_attr.attr, NULL }, { - &sensor_dev_attr_fan2_input.dev_attr.attr, - &sensor_dev_attr_fan2_min.dev_attr.attr, - &sensor_dev_attr_fan2_alarm.dev_attr.attr, + &sensor_dev_attr_in9_input.dev_attr.attr, + &sensor_dev_attr_in9_max.dev_attr.attr, + &sensor_dev_attr_in9_min.dev_attr.attr, + &sensor_dev_attr_in9_alarm.dev_attr.attr, NULL }, { - &sensor_dev_attr_fan3_input.dev_attr.attr, - &sensor_dev_attr_fan3_min.dev_attr.attr, - &sensor_dev_attr_fan3_alarm.dev_attr.attr, + &sensor_dev_attr_in10_input.dev_attr.attr, + &sensor_dev_attr_in10_max.dev_attr.attr, + &sensor_dev_attr_in10_min.dev_attr.attr, + &sensor_dev_attr_in10_alarm.dev_attr.attr, NULL } }; -static const struct attribute_group f71805f_group_fan[3] = { - { .attrs = f71805f_attributes_fan[0] }, - { .attrs = f71805f_attributes_fan[1] }, - { .attrs = f71805f_attributes_fan[2] }, +static const struct attribute_group f71805f_group_optin[4] = { + { .attrs = f71805f_attributes_optin[0] }, + { .attrs = f71805f_attributes_optin[1] }, + { .attrs = f71805f_attributes_optin[2] }, + { .attrs = f71805f_attributes_optin[3] }, +}; + +/* We don't include pwm_freq files in the arrays above, because they must be + created conditionally (only if pwm_mode is 1 == PWM) */ +static struct attribute *f71805f_attributes_pwm_freq[] = { + &sensor_dev_attr_pwm1_freq.dev_attr.attr, + &sensor_dev_attr_pwm2_freq.dev_attr.attr, + &sensor_dev_attr_pwm3_freq.dev_attr.attr, + NULL +}; + +static const struct attribute_group f71805f_group_pwm_freq = { + .attrs = f71805f_attributes_pwm_freq, +}; + +/* We also need an indexed access to pwmN files to toggle writability */ +static struct attribute *f71805f_attr_pwm[] = { + &sensor_dev_attr_pwm1.dev_attr.attr, + &sensor_dev_attr_pwm2.dev_attr.attr, + &sensor_dev_attr_pwm3.dev_attr.attr, }; /* @@ -798,18 +1118,30 @@ static void __devinit f71805f_init_device(struct f71805f_data *data) /* Fan monitoring can be disabled. If it is, we won't be polling the register values, and won't create the related sysfs files. */ for (i = 0; i < 3; i++) { - reg = f71805f_read8(data, F71805F_REG_FAN_CTRL(i)); - if (!(reg & 0x80)) - data->fan_enabled |= (1 << i); + data->fan_ctrl[i] = f71805f_read8(data, + F71805F_REG_FAN_CTRL(i)); + /* Clear latch full bit, else "speed mode" fan speed control + doesn't work */ + if (data->fan_ctrl[i] & FAN_CTRL_LATCH_FULL) { + data->fan_ctrl[i] &= ~FAN_CTRL_LATCH_FULL; + f71805f_write8(data, F71805F_REG_FAN_CTRL(i), + data->fan_ctrl[i]); + } } } static int __devinit f71805f_probe(struct platform_device *pdev) { + struct f71805f_sio_data *sio_data = pdev->dev.platform_data; struct f71805f_data *data; struct resource *res; int i, err; + static const char *names[] = { + "f71805f", + "f71872f", + }; + if (!(data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL))) { err = -ENOMEM; printk(KERN_ERR DRVNAME ": Out of memory\n"); @@ -819,24 +1151,69 @@ static int __devinit f71805f_probe(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_IO, 0); data->addr = res->start; mutex_init(&data->lock); - data->name = "f71805f"; + data->name = names[sio_data->kind]; mutex_init(&data->update_lock); platform_set_drvdata(pdev, data); + /* Some voltage inputs depend on chip model and configuration */ + switch (sio_data->kind) { + case f71805f: + data->has_in = 0x1ff; + break; + case f71872f: + data->has_in = 0x6ef; + if (sio_data->fnsel1 & 0x01) + data->has_in |= (1 << 4); /* in4 */ + if (sio_data->fnsel1 & 0x02) + data->has_in |= (1 << 8); /* in8 */ + break; + } + /* Initialize the F71805F chip */ f71805f_init_device(data); /* Register sysfs interface files */ if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group))) goto exit_free; - for (i = 0; i < 3; i++) { - if (!(data->fan_enabled & (1 << i))) - continue; + if (data->has_in & (1 << 4)) { /* in4 */ + if ((err = sysfs_create_group(&pdev->dev.kobj, + &f71805f_group_optin[0]))) + goto exit_remove_files; + } + if (data->has_in & (1 << 8)) { /* in8 */ + if ((err = sysfs_create_group(&pdev->dev.kobj, + &f71805f_group_optin[1]))) + goto exit_remove_files; + } + if (data->has_in & (1 << 9)) { /* in9 (F71872F/FG only) */ if ((err = sysfs_create_group(&pdev->dev.kobj, - &f71805f_group_fan[i]))) + &f71805f_group_optin[2]))) goto exit_remove_files; } + if (data->has_in & (1 << 10)) { /* in9 (F71872F/FG only) */ + if ((err = sysfs_create_group(&pdev->dev.kobj, + &f71805f_group_optin[3]))) + goto exit_remove_files; + } + for (i = 0; i < 3; i++) { + /* If control mode is PWM, create pwm_freq file */ + if (!(data->fan_ctrl[i] & FAN_CTRL_DC_MODE)) { + if ((err = sysfs_create_file(&pdev->dev.kobj, + f71805f_attributes_pwm_freq[i]))) + goto exit_remove_files; + } + /* If PWM is in manual mode, add write permission */ + if (data->fan_ctrl[i] & FAN_CTRL_MODE_MANUAL) { + if ((err = sysfs_chmod_file(&pdev->dev.kobj, + f71805f_attr_pwm[i], + S_IRUGO | S_IWUSR))) { + dev_err(&pdev->dev, "chmod +w pwm%d failed\n", + i + 1); + goto exit_remove_files; + } + } + } data->class_dev = hwmon_device_register(&pdev->dev); if (IS_ERR(data->class_dev)) { @@ -849,8 +1226,9 @@ static int __devinit f71805f_probe(struct platform_device *pdev) exit_remove_files: sysfs_remove_group(&pdev->dev.kobj, &f71805f_group); - for (i = 0; i < 3; i++) - sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]); + for (i = 0; i < 4; i++) + sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_optin[i]); + sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq); exit_free: platform_set_drvdata(pdev, NULL); kfree(data); @@ -866,8 +1244,9 @@ static int __devexit f71805f_remove(struct platform_device *pdev) platform_set_drvdata(pdev, NULL); hwmon_device_unregister(data->class_dev); sysfs_remove_group(&pdev->dev.kobj, &f71805f_group); - for (i = 0; i < 3; i++) - sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]); + for (i = 0; i < 4; i++) + sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_optin[i]); + sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq); kfree(data); return 0; @@ -882,7 +1261,8 @@ static struct platform_driver f71805f_driver = { .remove = __devexit_p(f71805f_remove), }; -static int __init f71805f_device_add(unsigned short address) +static int __init f71805f_device_add(unsigned short address, + const struct f71805f_sio_data *sio_data) { struct resource res = { .start = address, @@ -906,26 +1286,45 @@ static int __init f71805f_device_add(unsigned short address) goto exit_device_put; } + pdev->dev.platform_data = kmalloc(sizeof(struct f71805f_sio_data), + GFP_KERNEL); + if (!pdev->dev.platform_data) { + err = -ENOMEM; + printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); + goto exit_device_put; + } + memcpy(pdev->dev.platform_data, sio_data, + sizeof(struct f71805f_sio_data)); + err = platform_device_add(pdev); if (err) { printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", err); - goto exit_device_put; + goto exit_kfree_data; } return 0; +exit_kfree_data: + kfree(pdev->dev.platform_data); + pdev->dev.platform_data = NULL; exit_device_put: platform_device_put(pdev); exit: return err; } -static int __init f71805f_find(int sioaddr, unsigned short *address) +static int __init f71805f_find(int sioaddr, unsigned short *address, + struct f71805f_sio_data *sio_data) { int err = -ENODEV; u16 devid; + static const char *names[] = { + "F71805F/FG", + "F71872F/FG", + }; + superio_enter(sioaddr); devid = superio_inw(sioaddr, SIO_REG_MANID); @@ -933,7 +1332,15 @@ static int __init f71805f_find(int sioaddr, unsigned short *address) goto exit; devid = superio_inw(sioaddr, SIO_REG_DEVID); - if (devid != SIO_F71805F_ID) { + switch (devid) { + case SIO_F71805F_ID: + sio_data->kind = f71805f; + break; + case SIO_F71872F_ID: + sio_data->kind = f71872f; + sio_data->fnsel1 = superio_inb(sioaddr, SIO_REG_FNSEL1); + break; + default: printk(KERN_INFO DRVNAME ": Unsupported Fintek device, " "skipping\n"); goto exit; @@ -952,10 +1359,12 @@ static int __init f71805f_find(int sioaddr, unsigned short *address) "skipping\n"); goto exit; } + *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */ err = 0; - printk(KERN_INFO DRVNAME ": Found F71805F chip at %#x, revision %u\n", - *address, superio_inb(sioaddr, SIO_REG_DEVREV)); + printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %u\n", + names[sio_data->kind], *address, + superio_inb(sioaddr, SIO_REG_DEVREV)); exit: superio_exit(sioaddr); @@ -966,9 +1375,10 @@ static int __init f71805f_init(void) { int err; unsigned short address; + struct f71805f_sio_data sio_data; - if (f71805f_find(0x2e, &address) - && f71805f_find(0x4e, &address)) + if (f71805f_find(0x2e, &address, &sio_data) + && f71805f_find(0x4e, &address, &sio_data)) return -ENODEV; err = platform_driver_register(&f71805f_driver); @@ -976,7 +1386,7 @@ static int __init f71805f_init(void) goto exit; /* Sets global pdev as a side effect */ - err = f71805f_device_add(address); + err = f71805f_device_add(address, &sio_data); if (err) goto exit_driver; @@ -990,13 +1400,16 @@ exit: static void __exit f71805f_exit(void) { + kfree(pdev->dev.platform_data); + pdev->dev.platform_data = NULL; platform_device_unregister(pdev); + platform_driver_unregister(&f71805f_driver); } MODULE_AUTHOR("Jean Delvare <khali@linux-fr>"); MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("F71805F hardware monitoring driver"); +MODULE_DESCRIPTION("F71805F/F71872F hardware monitoring driver"); module_init(f71805f_init); module_exit(f71805f_exit); diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c index e8ef62b83d6b..bf759ea545ac 100644 --- a/drivers/hwmon/hdaps.c +++ b/drivers/hwmon/hdaps.c @@ -478,74 +478,64 @@ static struct attribute_group hdaps_attribute_group = { /* Module stuff */ /* hdaps_dmi_match - found a match. return one, short-circuiting the hunt. */ -static int hdaps_dmi_match(struct dmi_system_id *id) +static int __init hdaps_dmi_match(struct dmi_system_id *id) { printk(KERN_INFO "hdaps: %s detected.\n", id->ident); return 1; } /* hdaps_dmi_match_invert - found an inverted match. */ -static int hdaps_dmi_match_invert(struct dmi_system_id *id) +static int __init hdaps_dmi_match_invert(struct dmi_system_id *id) { hdaps_invert = 1; printk(KERN_INFO "hdaps: inverting axis readings.\n"); return hdaps_dmi_match(id); } -#define HDAPS_DMI_MATCH_NORMAL(model) { \ - .ident = "IBM " model, \ +#define HDAPS_DMI_MATCH_NORMAL(vendor, model) { \ + .ident = vendor " " model, \ .callback = hdaps_dmi_match, \ .matches = { \ - DMI_MATCH(DMI_BOARD_VENDOR, "IBM"), \ + DMI_MATCH(DMI_BOARD_VENDOR, vendor), \ DMI_MATCH(DMI_PRODUCT_VERSION, model) \ } \ } -#define HDAPS_DMI_MATCH_INVERT(model) { \ - .ident = "IBM " model, \ +#define HDAPS_DMI_MATCH_INVERT(vendor, model) { \ + .ident = vendor " " model, \ .callback = hdaps_dmi_match_invert, \ .matches = { \ - DMI_MATCH(DMI_BOARD_VENDOR, "IBM"), \ + DMI_MATCH(DMI_BOARD_VENDOR, vendor), \ DMI_MATCH(DMI_PRODUCT_VERSION, model) \ } \ } -#define HDAPS_DMI_MATCH_LENOVO(model) { \ - .ident = "Lenovo " model, \ - .callback = hdaps_dmi_match_invert, \ - .matches = { \ - DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), \ - DMI_MATCH(DMI_PRODUCT_VERSION, model) \ - } \ -} +/* Note that HDAPS_DMI_MATCH_NORMAL("ThinkPad T42") would match + "ThinkPad T42p", so the order of the entries matters. + If your ThinkPad is not recognized, please update to latest + BIOS. This is especially the case for some R52 ThinkPads. */ +static struct dmi_system_id __initdata hdaps_whitelist[] = { + HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad R50p"), + HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R50"), + HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R51"), + HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R52"), + HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T41p"), + HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T41"), + HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T42p"), + HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T42"), + HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T43"), + HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T60"), + HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X40"), + HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X41"), + HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X60"), + HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad Z60m"), + { .ident = NULL } +}; static int __init hdaps_init(void) { int ret; - /* Note that HDAPS_DMI_MATCH_NORMAL("ThinkPad T42") would match - "ThinkPad T42p", so the order of the entries matters */ - struct dmi_system_id hdaps_whitelist[] = { - HDAPS_DMI_MATCH_NORMAL("ThinkPad H"), - HDAPS_DMI_MATCH_INVERT("ThinkPad R50p"), - HDAPS_DMI_MATCH_NORMAL("ThinkPad R50"), - HDAPS_DMI_MATCH_NORMAL("ThinkPad R51"), - HDAPS_DMI_MATCH_NORMAL("ThinkPad R52"), - HDAPS_DMI_MATCH_NORMAL("ThinkPad H"), /* R52 (1846AQG) */ - HDAPS_DMI_MATCH_INVERT("ThinkPad T41p"), - HDAPS_DMI_MATCH_NORMAL("ThinkPad T41"), - HDAPS_DMI_MATCH_INVERT("ThinkPad T42p"), - HDAPS_DMI_MATCH_NORMAL("ThinkPad T42"), - HDAPS_DMI_MATCH_NORMAL("ThinkPad T43"), - HDAPS_DMI_MATCH_LENOVO("ThinkPad T60p"), - HDAPS_DMI_MATCH_LENOVO("ThinkPad T60"), - HDAPS_DMI_MATCH_NORMAL("ThinkPad X40"), - HDAPS_DMI_MATCH_NORMAL("ThinkPad X41"), - HDAPS_DMI_MATCH_LENOVO("ThinkPad X60"), - HDAPS_DMI_MATCH_NORMAL("ThinkPad Z60m"), - { .ident = NULL } - }; - if (!dmi_check_system(hdaps_whitelist)) { printk(KERN_WARNING "hdaps: supported laptop not found!\n"); ret = -ENODEV; diff --git a/drivers/hwmon/hwmon-vid.c b/drivers/hwmon/hwmon-vid.c index 9d67320e6840..31c42002708f 100644 --- a/drivers/hwmon/hwmon-vid.c +++ b/drivers/hwmon/hwmon-vid.c @@ -1,7 +1,7 @@ /* hwmon-vid.c - VID/VRM/VRD voltage conversions - Copyright (c) 2004 Rudolf Marek <r.marek@sh.cvut.cz> + Copyright (c) 2004 Rudolf Marek <r.marek@assembler.cz> Partly imported from i2c-vid.h of the lm_sensors project Copyright (c) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> @@ -232,7 +232,7 @@ u8 vid_which_vrm(void) EXPORT_SYMBOL(vid_from_reg); EXPORT_SYMBOL(vid_which_vrm); -MODULE_AUTHOR("Rudolf Marek <r.marek@sh.cvut.cz>"); +MODULE_AUTHOR("Rudolf Marek <r.marek@assembler.cz>"); MODULE_DESCRIPTION("hwmon-vid driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index 323ef06719c1..1ed8b7e2c35d 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c @@ -3,7 +3,7 @@ monitoring. Supports: IT8705F Super I/O chip w/LPC interface - IT8712F Super I/O chip w/LPC interface & SMBus + IT8712F Super I/O chip w/LPC interface IT8716F Super I/O chip w/LPC interface IT8718F Super I/O chip w/LPC interface Sis950 A clone of the IT8705F @@ -41,12 +41,8 @@ #include <asm/io.h> -/* Addresses to scan */ -static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END }; static unsigned short isa_address; - -/* Insmod parameters */ -I2C_CLIENT_INSMOD_4(it87, it8712, it8716, it8718); +enum chips { it87, it8712, it8716, it8718 }; #define REG 0x2e /* The register to read/write */ #define DEV 0x07 /* Register: Logical device select */ @@ -162,8 +158,6 @@ static u8 vid_value; #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2) #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2) -#define IT87_REG_I2C_ADDR 0x48 - #define IT87_REG_VIN_ENABLE 0x50 #define IT87_REG_TEMP_ENABLE 0x51 @@ -242,33 +236,22 @@ struct it87_data { }; -static int it87_attach_adapter(struct i2c_adapter *adapter); -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_detect(struct i2c_adapter *adapter); static int it87_detach_client(struct i2c_client *client); static int it87_read_value(struct i2c_client *client, u8 reg); -static int it87_write_value(struct i2c_client *client, u8 reg, u8 value); +static void it87_write_value(struct i2c_client *client, u8 reg, u8 value); static struct it87_data *it87_update_device(struct device *dev); static int it87_check_pwm(struct i2c_client *client); static void it87_init_client(struct i2c_client *client, struct it87_data *data); -static struct i2c_driver it87_driver = { - .driver = { - .name = "it87", - }, - .id = I2C_DRIVERID_IT87, - .attach_adapter = it87_attach_adapter, - .detach_client = it87_detach_client, -}; - static struct i2c_driver it87_isa_driver = { .driver = { .owner = THIS_MODULE, .name = "it87-isa", }, - .attach_adapter = it87_isa_attach_adapter, + .attach_adapter = it87_detect, .detach_client = it87_detach_client, }; @@ -850,22 +833,6 @@ static const struct attribute_group it87_group_opt = { .attrs = it87_attributes_opt, }; -/* This function is called when: - * it87_driver is inserted (when this module is loaded), for each - available adapter - * when a new adapter is inserted (and it87_driver is still present) */ -static int it87_attach_adapter(struct i2c_adapter *adapter) -{ - if (!(adapter->class & I2C_CLASS_HWMON)) - return 0; - return i2c_probe(adapter, &addr_data, it87_detect); -} - -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(unsigned short *address) { @@ -916,29 +883,20 @@ exit: } /* This function is called by i2c_probe */ -static int it87_detect(struct i2c_adapter *adapter, int address, int kind) +static int it87_detect(struct i2c_adapter *adapter) { - int i; struct i2c_client *new_client; struct it87_data *data; int err = 0; - const char *name = ""; - int is_isa = i2c_is_isa_adapter(adapter); + const char *name; int enable_pwm_interface; - if (!is_isa && - !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) - goto ERROR0; - /* Reserve the ISA region */ - if (is_isa) - if (!request_region(address, IT87_EXTENT, - it87_isa_driver.driver.name)) - goto ERROR0; - - /* For now, we presume we have a valid client. We create the - client structure, even though we cannot fill it completely yet. - But it allows us to access it87_{read,write}_value. */ + if (!request_region(isa_address, IT87_EXTENT, + it87_isa_driver.driver.name)){ + err = -EBUSY; + goto ERROR0; + } if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) { err = -ENOMEM; @@ -946,80 +904,46 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind) } new_client = &data->client; - if (is_isa) - mutex_init(&data->lock); + mutex_init(&data->lock); i2c_set_clientdata(new_client, data); - new_client->addr = address; + new_client->addr = isa_address; new_client->adapter = adapter; - new_client->driver = is_isa ? &it87_isa_driver : &it87_driver; - new_client->flags = 0; + new_client->driver = &it87_isa_driver; /* Now, we do the remaining detection. */ - - if (kind < 0) { - if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80) - || (!is_isa - && it87_read_value(new_client, IT87_REG_I2C_ADDR) != address)) { - err = -ENODEV; - goto ERROR2; - } + if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80) + || it87_read_value(new_client, IT87_REG_CHIPID) != 0x90) { + err = -ENODEV; + goto ERROR2; } /* Determine the chip type. */ - if (kind <= 0) { - i = it87_read_value(new_client, IT87_REG_CHIPID); - if (i == 0x90) { - kind = it87; - if (is_isa) { - switch (chip_type) { - case IT8712F_DEVID: - kind = it8712; - break; - case IT8716F_DEVID: - kind = it8716; - break; - case IT8718F_DEVID: - kind = it8718; - break; - } - } - } - else { - if (kind == 0) - dev_info(&adapter->dev, - "Ignoring 'force' parameter for unknown chip at " - "adapter %d, address 0x%02x\n", - i2c_adapter_id(adapter), address); - err = -ENODEV; - goto ERROR2; - } - } - - if (kind == it87) { - name = "it87"; - } else if (kind == it8712) { + switch (chip_type) { + case IT8712F_DEVID: + data->type = it8712; name = "it8712"; - } else if (kind == it8716) { + break; + case IT8716F_DEVID: + data->type = it8716; name = "it8716"; - } else if (kind == it8718) { + break; + case IT8718F_DEVID: + data->type = it8718; name = "it8718"; + break; + default: + data->type = it87; + name = "it87"; } /* Fill in the remaining client fields and put it into the global list */ strlcpy(new_client->name, name, I2C_NAME_SIZE); - data->type = kind; - data->valid = 0; mutex_init(&data->update_lock); /* Tell the I2C layer a new client has arrived */ if ((err = i2c_attach_client(new_client))) goto ERROR2; - if (!is_isa) - dev_info(&new_client->dev, "The I2C interface to IT87xxF " - "hardware monitoring chips is deprecated. Please " - "report if you still rely on it.\n"); - /* Check PWM configuration */ enable_pwm_interface = it87_check_pwm(new_client); @@ -1129,8 +1053,7 @@ ERROR3: ERROR2: kfree(data); ERROR1: - if (is_isa) - release_region(address, IT87_EXTENT); + release_region(isa_address, IT87_EXTENT); ERROR0: return err; } @@ -1147,50 +1070,39 @@ static int it87_detach_client(struct i2c_client *client) if ((err = i2c_detach_client(client))) return err; - if(i2c_is_isa_client(client)) - release_region(client->addr, IT87_EXTENT); + release_region(client->addr, IT87_EXTENT); kfree(data); return 0; } -/* The SMBus locks itself, but ISA access must be locked explicitly! - We don't want to lock the whole ISA bus, so we lock each client - separately. +/* ISA access must be locked explicitly! We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, would slow down the IT87 access and should not be necessary. */ static int it87_read_value(struct i2c_client *client, u8 reg) { struct it87_data *data = i2c_get_clientdata(client); - int res; - if (i2c_is_isa_client(client)) { - mutex_lock(&data->lock); - outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); - res = inb_p(client->addr + IT87_DATA_REG_OFFSET); - mutex_unlock(&data->lock); - return res; - } else - return i2c_smbus_read_byte_data(client, reg); + + mutex_lock(&data->lock); + outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); + res = inb_p(client->addr + IT87_DATA_REG_OFFSET); + mutex_unlock(&data->lock); + + return res; } -/* The SMBus locks itself, but ISA access muse be locked explicitly! - We don't want to lock the whole ISA bus, so we lock each client - separately. +/* ISA access must be locked explicitly! We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, would slow down the IT87 access and should not be necessary. */ -static int it87_write_value(struct i2c_client *client, u8 reg, u8 value) +static void it87_write_value(struct i2c_client *client, u8 reg, u8 value) { struct it87_data *data = i2c_get_clientdata(client); - if (i2c_is_isa_client(client)) { - mutex_lock(&data->lock); - outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); - outb_p(value, client->addr + IT87_DATA_REG_OFFSET); - mutex_unlock(&data->lock); - return 0; - } else - return i2c_smbus_write_byte_data(client, reg, value); + mutex_lock(&data->lock); + outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); + outb_p(value, client->addr + IT87_DATA_REG_OFFSET); + mutex_unlock(&data->lock); } /* Return 1 if and only if the PWM interface is safe to use */ @@ -1426,26 +1338,14 @@ static int __init sm_it87_init(void) { int res; - res = i2c_add_driver(&it87_driver); - if (res) + if ((res = it87_find(&isa_address))) return res; - - if (!it87_find(&isa_address)) { - res = i2c_isa_add_driver(&it87_isa_driver); - if (res) { - i2c_del_driver(&it87_driver); - return res; - } - } - - return 0; + return i2c_isa_add_driver(&it87_isa_driver); } static void __exit sm_it87_exit(void) { - if (isa_address) - i2c_isa_del_driver(&it87_isa_driver); - i2c_del_driver(&it87_driver); + i2c_isa_del_driver(&it87_isa_driver); } diff --git a/drivers/hwmon/k8temp.c b/drivers/hwmon/k8temp.c index f58b64ed09e3..5d8d0ca08fa9 100644 --- a/drivers/hwmon/k8temp.c +++ b/drivers/hwmon/k8temp.c @@ -1,7 +1,7 @@ /* * k8temp.c - Linux kernel module for hardware monitoring * - * Copyright (C) 2006 Rudolf Marek <r.marek@sh.cvut.cz> + * Copyright (C) 2006 Rudolf Marek <r.marek@assembler.cz> * * Inspired from the w83785 and amd756 drivers. * @@ -286,7 +286,7 @@ static void __exit k8temp_exit(void) pci_unregister_driver(&k8temp_driver); } -MODULE_AUTHOR("Rudolf Marek <r.marek@sh.cvut.cz>"); +MODULE_AUTHOR("Rudolf Marek <r.marek@assembler.cz>"); MODULE_DESCRIPTION("AMD K8 core temperature monitor"); MODULE_LICENSE("GPL"); diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c index 3b8b81984ad4..c8a21be09d87 100644 --- a/drivers/hwmon/pc87360.c +++ b/drivers/hwmon/pc87360.c @@ -1000,7 +1000,7 @@ static int pc87360_detect(struct i2c_adapter *adapter) (i&0x02) ? "external" : "internal"); data->vid_conf = confreg[3]; - data->vrm = 90; + data->vrm = vid_which_vrm(); } /* Fan clock dividers may be needed before any data is read */ diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c new file mode 100644 index 000000000000..affa21a5ccfd --- /dev/null +++ b/drivers/hwmon/pc87427.c @@ -0,0 +1,627 @@ +/* + * pc87427.c - hardware monitoring driver for the + * National Semiconductor PC87427 Super-I/O chip + * Copyright (C) 2006 Jean Delvare <khali@linux-fr.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + * + * Supports the following chips: + * + * Chip #vin #fan #pwm #temp devid + * PC87427 - 8 - - 0xF2 + * + * This driver assumes that no more than one chip is present. + * Only fan inputs are supported so far, although the chip can do much more. + */ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/jiffies.h> +#include <linux/platform_device.h> +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> +#include <linux/err.h> +#include <linux/mutex.h> +#include <linux/sysfs.h> +#include <asm/io.h> + +static struct platform_device *pdev; + +#define DRVNAME "pc87427" + +/* The lock mutex protects both the I/O accesses (needed because the + device is using banked registers) and the register cache (needed to keep + the data in the registers and the cache in sync at any time). */ +struct pc87427_data { + struct class_device *class_dev; + struct mutex lock; + int address[2]; + const char *name; + + unsigned long last_updated; /* in jiffies */ + u8 fan_enabled; /* bit vector */ + u16 fan[8]; /* register values */ + u16 fan_min[8]; /* register values */ + u8 fan_status[8]; /* register values */ +}; + +/* + * Super-I/O registers and operations + */ + +#define SIOREG_LDSEL 0x07 /* Logical device select */ +#define SIOREG_DEVID 0x20 /* Device ID */ +#define SIOREG_ACT 0x30 /* Device activation */ +#define SIOREG_MAP 0x50 /* I/O or memory mapping */ +#define SIOREG_IOBASE 0x60 /* I/O base address */ + +static const u8 logdev[2] = { 0x09, 0x14 }; +static const char *logdev_str[2] = { DRVNAME " FMC", DRVNAME " HMC" }; +#define LD_FAN 0 +#define LD_IN 1 +#define LD_TEMP 1 + +static inline void superio_outb(int sioaddr, int reg, int val) +{ + outb(reg, sioaddr); + outb(val, sioaddr + 1); +} + +static inline int superio_inb(int sioaddr, int reg) +{ + outb(reg, sioaddr); + return inb(sioaddr + 1); +} + +static inline void superio_exit(int sioaddr) +{ + outb(0x02, sioaddr); + outb(0x02, sioaddr + 1); +} + +/* + * Logical devices + */ + +#define REGION_LENGTH 32 +#define PC87427_REG_BANK 0x0f +#define BANK_FM(nr) (nr) +#define BANK_FT(nr) (0x08 + (nr)) +#define BANK_FC(nr) (0x10 + (nr) * 2) + +/* + * I/O access functions + */ + +/* ldi is the logical device index */ +static inline int pc87427_read8(struct pc87427_data *data, u8 ldi, u8 reg) +{ + return inb(data->address[ldi] + reg); +} + +/* Must be called with data->lock held, except during init */ +static inline int pc87427_read8_bank(struct pc87427_data *data, u8 ldi, + u8 bank, u8 reg) +{ + outb(bank, data->address[ldi] + PC87427_REG_BANK); + return inb(data->address[ldi] + reg); +} + +/* Must be called with data->lock held, except during init */ +static inline void pc87427_write8_bank(struct pc87427_data *data, u8 ldi, + u8 bank, u8 reg, u8 value) +{ + outb(bank, data->address[ldi] + PC87427_REG_BANK); + outb(value, data->address[ldi] + reg); +} + +/* + * Fan registers and conversions + */ + +/* fan data registers are 16-bit wide */ +#define PC87427_REG_FAN 0x12 +#define PC87427_REG_FAN_MIN 0x14 +#define PC87427_REG_FAN_STATUS 0x10 + +#define FAN_STATUS_STALL (1 << 3) +#define FAN_STATUS_LOSPD (1 << 1) +#define FAN_STATUS_MONEN (1 << 0) + +/* Dedicated function to read all registers related to a given fan input. + This saves us quite a few locks and bank selections. + Must be called with data->lock held. + nr is from 0 to 7 */ +static void pc87427_readall_fan(struct pc87427_data *data, u8 nr) +{ + int iobase = data->address[LD_FAN]; + + outb(BANK_FM(nr), iobase + PC87427_REG_BANK); + data->fan[nr] = inw(iobase + PC87427_REG_FAN); + data->fan_min[nr] = inw(iobase + PC87427_REG_FAN_MIN); + data->fan_status[nr] = inb(iobase + PC87427_REG_FAN_STATUS); + /* Clear fan alarm bits */ + outb(data->fan_status[nr], iobase + PC87427_REG_FAN_STATUS); +} + +/* The 2 LSB of fan speed registers are used for something different. + The actual 2 LSB of the measurements are not available. */ +static inline unsigned long fan_from_reg(u16 reg) +{ + reg &= 0xfffc; + if (reg == 0x0000 || reg == 0xfffc) + return 0; + return 5400000UL / reg; +} + +/* The 2 LSB of the fan speed limit registers are not significant. */ +static inline u16 fan_to_reg(unsigned long val) +{ + if (val < 83UL) + return 0xffff; + if (val >= 1350000UL) + return 0x0004; + return ((1350000UL + val / 2) / val) << 2; +} + +/* + * Data interface + */ + +static struct pc87427_data *pc87427_update_device(struct device *dev) +{ + struct pc87427_data *data = dev_get_drvdata(dev); + int i; + + mutex_lock(&data->lock); + if (!time_after(jiffies, data->last_updated + HZ) + && data->last_updated) + goto done; + + /* Fans */ + for (i = 0; i < 8; i++) { + if (!(data->fan_enabled & (1 << i))) + continue; + pc87427_readall_fan(data, i); + } + data->last_updated = jiffies; + +done: + mutex_unlock(&data->lock); + return data; +} + +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 pc87427_data *data = pc87427_update_device(dev); + int nr = attr->index; + + return sprintf(buf, "%lu\n", fan_from_reg(data->fan[nr])); +} + +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 pc87427_data *data = pc87427_update_device(dev); + int nr = attr->index; + + return sprintf(buf, "%lu\n", fan_from_reg(data->fan_min[nr])); +} + +static ssize_t show_fan_alarm(struct device *dev, struct device_attribute + *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87427_data *data = pc87427_update_device(dev); + int nr = attr->index; + + return sprintf(buf, "%d\n", !!(data->fan_status[nr] + & FAN_STATUS_LOSPD)); +} + +static ssize_t show_fan_fault(struct device *dev, struct device_attribute + *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pc87427_data *data = pc87427_update_device(dev); + int nr = attr->index; + + return sprintf(buf, "%d\n", !!(data->fan_status[nr] + & FAN_STATUS_STALL)); +} + +static ssize_t set_fan_min(struct device *dev, struct device_attribute + *devattr, const char *buf, size_t count) +{ + struct pc87427_data *data = dev_get_drvdata(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + int nr = attr->index; + unsigned long val = simple_strtoul(buf, NULL, 10); + int iobase = data->address[LD_FAN]; + + mutex_lock(&data->lock); + outb(BANK_FM(nr), iobase + PC87427_REG_BANK); + /* The low speed limit registers are read-only while monitoring + is enabled, so we have to disable monitoring, then change the + limit, and finally enable monitoring again. */ + outb(0, iobase + PC87427_REG_FAN_STATUS); + data->fan_min[nr] = fan_to_reg(val); + outw(data->fan_min[nr], iobase + PC87427_REG_FAN_MIN); + outb(FAN_STATUS_MONEN, iobase + PC87427_REG_FAN_STATUS); + mutex_unlock(&data->lock); + + return count; +} + +static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0); +static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1); +static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan_input, NULL, 2); +static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan_input, NULL, 3); +static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan_input, NULL, 4); +static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan_input, NULL, 5); +static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan_input, NULL, 6); +static SENSOR_DEVICE_ATTR(fan8_input, S_IRUGO, show_fan_input, NULL, 7); + +static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, + show_fan_min, set_fan_min, 0); +static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, + show_fan_min, set_fan_min, 1); +static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, + show_fan_min, set_fan_min, 2); +static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, + show_fan_min, set_fan_min, 3); +static SENSOR_DEVICE_ATTR(fan5_min, S_IWUSR | S_IRUGO, + show_fan_min, set_fan_min, 4); +static SENSOR_DEVICE_ATTR(fan6_min, S_IWUSR | S_IRUGO, + show_fan_min, set_fan_min, 5); +static SENSOR_DEVICE_ATTR(fan7_min, S_IWUSR | S_IRUGO, + show_fan_min, set_fan_min, 6); +static SENSOR_DEVICE_ATTR(fan8_min, S_IWUSR | S_IRUGO, + show_fan_min, set_fan_min, 7); + +static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0); +static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 1); +static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 2); +static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 3); +static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_fan_alarm, NULL, 4); +static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_fan_alarm, NULL, 5); +static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO, show_fan_alarm, NULL, 6); +static SENSOR_DEVICE_ATTR(fan8_alarm, S_IRUGO, show_fan_alarm, NULL, 7); + +static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, show_fan_fault, NULL, 0); +static SENSOR_DEVICE_ATTR(fan2_fault, S_IRUGO, show_fan_fault, NULL, 1); +static SENSOR_DEVICE_ATTR(fan3_fault, S_IRUGO, show_fan_fault, NULL, 2); +static SENSOR_DEVICE_ATTR(fan4_fault, S_IRUGO, show_fan_fault, NULL, 3); +static SENSOR_DEVICE_ATTR(fan5_fault, S_IRUGO, show_fan_fault, NULL, 4); +static SENSOR_DEVICE_ATTR(fan6_fault, S_IRUGO, show_fan_fault, NULL, 5); +static SENSOR_DEVICE_ATTR(fan7_fault, S_IRUGO, show_fan_fault, NULL, 6); +static SENSOR_DEVICE_ATTR(fan8_fault, S_IRUGO, show_fan_fault, NULL, 7); + +static struct attribute *pc87427_attributes_fan[8][5] = { + { + &sensor_dev_attr_fan1_input.dev_attr.attr, + &sensor_dev_attr_fan1_min.dev_attr.attr, + &sensor_dev_attr_fan1_alarm.dev_attr.attr, + &sensor_dev_attr_fan1_fault.dev_attr.attr, + NULL + }, { + &sensor_dev_attr_fan2_input.dev_attr.attr, + &sensor_dev_attr_fan2_min.dev_attr.attr, + &sensor_dev_attr_fan2_alarm.dev_attr.attr, + &sensor_dev_attr_fan2_fault.dev_attr.attr, + NULL + }, { + &sensor_dev_attr_fan3_input.dev_attr.attr, + &sensor_dev_attr_fan3_min.dev_attr.attr, + &sensor_dev_attr_fan3_alarm.dev_attr.attr, + &sensor_dev_attr_fan3_fault.dev_attr.attr, + NULL + }, { + &sensor_dev_attr_fan4_input.dev_attr.attr, + &sensor_dev_attr_fan4_min.dev_attr.attr, + &sensor_dev_attr_fan4_alarm.dev_attr.attr, + &sensor_dev_attr_fan4_fault.dev_attr.attr, + NULL + }, { + &sensor_dev_attr_fan5_input.dev_attr.attr, + &sensor_dev_attr_fan5_min.dev_attr.attr, + &sensor_dev_attr_fan5_alarm.dev_attr.attr, + &sensor_dev_attr_fan5_fault.dev_attr.attr, + NULL + }, { + &sensor_dev_attr_fan6_input.dev_attr.attr, + &sensor_dev_attr_fan6_min.dev_attr.attr, + &sensor_dev_attr_fan6_alarm.dev_attr.attr, + &sensor_dev_attr_fan6_fault.dev_attr.attr, + NULL + }, { + &sensor_dev_attr_fan7_input.dev_attr.attr, + &sensor_dev_attr_fan7_min.dev_attr.attr, + &sensor_dev_attr_fan7_alarm.dev_attr.attr, + &sensor_dev_attr_fan7_fault.dev_attr.attr, + NULL + }, { + &sensor_dev_attr_fan8_input.dev_attr.attr, + &sensor_dev_attr_fan8_min.dev_attr.attr, + &sensor_dev_attr_fan8_alarm.dev_attr.attr, + &sensor_dev_attr_fan8_fault.dev_attr.attr, + NULL + } +}; + +static const struct attribute_group pc87427_group_fan[8] = { + { .attrs = pc87427_attributes_fan[0] }, + { .attrs = pc87427_attributes_fan[1] }, + { .attrs = pc87427_attributes_fan[2] }, + { .attrs = pc87427_attributes_fan[3] }, + { .attrs = pc87427_attributes_fan[4] }, + { .attrs = pc87427_attributes_fan[5] }, + { .attrs = pc87427_attributes_fan[6] }, + { .attrs = pc87427_attributes_fan[7] }, +}; + +static ssize_t show_name(struct device *dev, struct device_attribute + *devattr, char *buf) +{ + struct pc87427_data *data = dev_get_drvdata(dev); + + return sprintf(buf, "%s\n", data->name); +} +static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); + + +/* + * Device detection, attach and detach + */ + +static void __devinit pc87427_init_device(struct device *dev) +{ + struct pc87427_data *data = dev_get_drvdata(dev); + int i; + u8 reg; + + /* The FMC module should be ready */ + reg = pc87427_read8(data, LD_FAN, PC87427_REG_BANK); + if (!(reg & 0x80)) + dev_warn(dev, "FMC module not ready!\n"); + + /* Check which fans are enabled */ + for (i = 0; i < 8; i++) { + reg = pc87427_read8_bank(data, LD_FAN, BANK_FM(i), + PC87427_REG_FAN_STATUS); + if (reg & FAN_STATUS_MONEN) + data->fan_enabled |= (1 << i); + } + + if (!data->fan_enabled) { + dev_dbg(dev, "Enabling all fan inputs\n"); + for (i = 0; i < 8; i++) + pc87427_write8_bank(data, LD_FAN, BANK_FM(i), + PC87427_REG_FAN_STATUS, + FAN_STATUS_MONEN); + data->fan_enabled = 0xff; + } +} + +static int __devinit pc87427_probe(struct platform_device *pdev) +{ + struct pc87427_data *data; + struct resource *res; + int i, err; + + if (!(data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL))) { + err = -ENOMEM; + printk(KERN_ERR DRVNAME ": Out of memory\n"); + goto exit; + } + + /* This will need to be revisited when we add support for + temperature and voltage monitoring. */ + res = platform_get_resource(pdev, IORESOURCE_IO, 0); + data->address[0] = res->start; + + mutex_init(&data->lock); + data->name = "pc87427"; + platform_set_drvdata(pdev, data); + pc87427_init_device(&pdev->dev); + + /* Register sysfs hooks */ + if ((err = device_create_file(&pdev->dev, &dev_attr_name))) + goto exit_kfree; + for (i = 0; i < 8; i++) { + if (!(data->fan_enabled & (1 << i))) + continue; + if ((err = sysfs_create_group(&pdev->dev.kobj, + &pc87427_group_fan[i]))) + goto exit_remove_files; + } + + data->class_dev = hwmon_device_register(&pdev->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + dev_err(&pdev->dev, "Class registration failed (%d)\n", err); + goto exit_remove_files; + } + + return 0; + +exit_remove_files: + for (i = 0; i < 8; i++) { + if (!(data->fan_enabled & (1 << i))) + continue; + sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]); + } +exit_kfree: + platform_set_drvdata(pdev, NULL); + kfree(data); +exit: + return err; +} + +static int __devexit pc87427_remove(struct platform_device *pdev) +{ + struct pc87427_data *data = platform_get_drvdata(pdev); + int i; + + platform_set_drvdata(pdev, NULL); + hwmon_device_unregister(data->class_dev); + device_remove_file(&pdev->dev, &dev_attr_name); + for (i = 0; i < 8; i++) { + if (!(data->fan_enabled & (1 << i))) + continue; + sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]); + } + kfree(data); + + return 0; +} + + +static struct platform_driver pc87427_driver = { + .driver = { + .owner = THIS_MODULE, + .name = DRVNAME, + }, + .probe = pc87427_probe, + .remove = __devexit_p(pc87427_remove), +}; + +static int __init pc87427_device_add(unsigned short address) +{ + struct resource res = { + .start = address, + .end = address + REGION_LENGTH - 1, + .name = logdev_str[0], + .flags = IORESOURCE_IO, + }; + int err; + + pdev = platform_device_alloc(DRVNAME, address); + if (!pdev) { + err = -ENOMEM; + printk(KERN_ERR DRVNAME ": Device allocation failed\n"); + goto exit; + } + + err = platform_device_add_resources(pdev, &res, 1); + if (err) { + printk(KERN_ERR DRVNAME ": Device resource addition failed " + "(%d)\n", err); + goto exit_device_put; + } + + err = platform_device_add(pdev); + if (err) { + printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", + err); + goto exit_device_put; + } + + return 0; + +exit_device_put: + platform_device_put(pdev); +exit: + return err; +} + +static int __init pc87427_find(int sioaddr, unsigned short *address) +{ + u16 val; + int i, err = 0; + + /* Identify device */ + val = superio_inb(sioaddr, SIOREG_DEVID); + if (val != 0xf2) { /* PC87427 */ + err = -ENODEV; + goto exit; + } + + for (i = 0; i < 2; i++) { + address[i] = 0; + /* Select logical device */ + superio_outb(sioaddr, SIOREG_LDSEL, logdev[i]); + + val = superio_inb(sioaddr, SIOREG_ACT); + if (!(val & 0x01)) { + printk(KERN_INFO DRVNAME ": Logical device 0x%02x " + "not activated\n", logdev[i]); + continue; + } + + val = superio_inb(sioaddr, SIOREG_MAP); + if (val & 0x01) { + printk(KERN_WARNING DRVNAME ": Logical device 0x%02x " + "is memory-mapped, can't use\n", logdev[i]); + continue; + } + + val = (superio_inb(sioaddr, SIOREG_IOBASE) << 8) + | superio_inb(sioaddr, SIOREG_IOBASE + 1); + if (!val) { + printk(KERN_INFO DRVNAME ": I/O base address not set " + "for logical device 0x%02x\n", logdev[i]); + continue; + } + address[i] = val; + } + +exit: + superio_exit(sioaddr); + return err; +} + +static int __init pc87427_init(void) +{ + int err; + unsigned short address[2]; + + if (pc87427_find(0x2e, address) + && pc87427_find(0x4e, address)) + return -ENODEV; + + /* For now the driver only handles fans so we only care about the + first address. */ + if (!address[0]) + return -ENODEV; + + err = platform_driver_register(&pc87427_driver); + if (err) + goto exit; + + /* Sets global pdev as a side effect */ + err = pc87427_device_add(address[0]); + if (err) + goto exit_driver; + + return 0; + +exit_driver: + platform_driver_unregister(&pc87427_driver); +exit: + return err; +} + +static void __exit pc87427_exit(void) +{ + platform_device_unregister(pdev); + platform_driver_unregister(&pc87427_driver); +} + +MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); +MODULE_DESCRIPTION("PC87427 hardware monitoring driver"); +MODULE_LICENSE("GPL"); + +module_init(pc87427_init); +module_exit(pc87427_exit); diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c index 2257806d0102..212a1558c63b 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c @@ -3,7 +3,7 @@ the Winbond W83627EHF Super-I/O chip Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> Copyright (C) 2006 Yuan Mu (Winbond), - Rudolf Marek <r.marek@sh.cvut.cz> + Rudolf Marek <r.marek@assembler.cz> David Hubbard <david.c.hubbard@gmail.com> Shamelessly ripped from the w83627hf driver diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index 4e108262576f..b0fa296740d1 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c @@ -3,7 +3,7 @@ monitoring Copyright (C) 2004, 2005 Winbond Electronics Corp. Chunhao Huang <DZShen@Winbond.com.tw>, - Rudolf Marek <r.marek@sh.cvut.cz> + Rudolf Marek <r.marek@assembler.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 diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c new file mode 100644 index 000000000000..c12ac5abc2bb --- /dev/null +++ b/drivers/hwmon/w83793.c @@ -0,0 +1,1609 @@ +/* + w83793.c - Linux kernel driver for hardware monitoring + Copyright (C) 2006 Winbond Electronics Corp. + Yuan Mu + Rudolf Marek <r.marek@assembler.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 - version 2. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. +*/ + +/* + Supports following chips: + + Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA + w83793 10 12 8 6 0x7b 0x5ca3 yes no +*/ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/i2c.h> +#include <linux/hwmon.h> +#include <linux/hwmon-vid.h> +#include <linux/hwmon-sysfs.h> +#include <linux/err.h> +#include <linux/mutex.h> + +/* Addresses to scan */ +static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; + +/* Insmod parameters */ +I2C_CLIENT_INSMOD_1(w83793); +I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: " + "{bus, clientaddr, subclientaddr1, subclientaddr2}"); + +static int reset; +module_param(reset, bool, 0); +MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended"); + +/* + Address 0x00, 0x0d, 0x0e, 0x0f in all three banks are reserved + as ID, Bank Select registers +*/ +#define W83793_REG_BANKSEL 0x00 +#define W83793_REG_VENDORID 0x0d +#define W83793_REG_CHIPID 0x0e +#define W83793_REG_DEVICEID 0x0f + +#define W83793_REG_CONFIG 0x40 +#define W83793_REG_MFC 0x58 +#define W83793_REG_FANIN_CTRL 0x5c +#define W83793_REG_FANIN_SEL 0x5d +#define W83793_REG_I2C_ADDR 0x0b +#define W83793_REG_I2C_SUBADDR 0x0c +#define W83793_REG_VID_INA 0x05 +#define W83793_REG_VID_INB 0x06 +#define W83793_REG_VID_LATCHA 0x07 +#define W83793_REG_VID_LATCHB 0x08 +#define W83793_REG_VID_CTRL 0x59 + +static u16 W83793_REG_TEMP_MODE[2] = { 0x5e, 0x5f }; + +#define TEMP_READ 0 +#define TEMP_CRIT 1 +#define TEMP_CRIT_HYST 2 +#define TEMP_WARN 3 +#define TEMP_WARN_HYST 4 +/* only crit and crit_hyst affect real-time alarm status + current crit crit_hyst warn warn_hyst */ +static u16 W83793_REG_TEMP[][5] = { + {0x1c, 0x78, 0x79, 0x7a, 0x7b}, + {0x1d, 0x7c, 0x7d, 0x7e, 0x7f}, + {0x1e, 0x80, 0x81, 0x82, 0x83}, + {0x1f, 0x84, 0x85, 0x86, 0x87}, + {0x20, 0x88, 0x89, 0x8a, 0x8b}, + {0x21, 0x8c, 0x8d, 0x8e, 0x8f}, +}; + +#define W83793_REG_TEMP_LOW_BITS 0x22 + +#define W83793_REG_BEEP(index) (0x53 + (index)) +#define W83793_REG_ALARM(index) (0x4b + (index)) + +#define W83793_REG_CLR_CHASSIS 0x4a /* SMI MASK4 */ +#define W83793_REG_IRQ_CTRL 0x50 +#define W83793_REG_OVT_CTRL 0x51 +#define W83793_REG_OVT_BEEP 0x52 + +#define IN_READ 0 +#define IN_MAX 1 +#define IN_LOW 2 +static const u16 W83793_REG_IN[][3] = { + /* Current, High, Low */ + {0x10, 0x60, 0x61}, /* Vcore A */ + {0x11, 0x62, 0x63}, /* Vcore B */ + {0x12, 0x64, 0x65}, /* Vtt */ + {0x14, 0x6a, 0x6b}, /* VSEN1 */ + {0x15, 0x6c, 0x6d}, /* VSEN2 */ + {0x16, 0x6e, 0x6f}, /* +3VSEN */ + {0x17, 0x70, 0x71}, /* +12VSEN */ + {0x18, 0x72, 0x73}, /* 5VDD */ + {0x19, 0x74, 0x75}, /* 5VSB */ + {0x1a, 0x76, 0x77}, /* VBAT */ +}; + +/* Low Bits of Vcore A/B Vtt Read/High/Low */ +static const u16 W83793_REG_IN_LOW_BITS[] = { 0x1b, 0x68, 0x69 }; +static u8 scale_in[] = { 2, 2, 2, 16, 16, 16, 8, 24, 24, 16 }; + +#define W83793_REG_FAN(index) (0x23 + 2 * (index)) /* High byte */ +#define W83793_REG_FAN_MIN(index) (0x90 + 2 * (index)) /* High byte */ + +#define W83793_REG_PWM_DEFAULT 0xb2 +#define W83793_REG_PWM_ENABLE 0x207 +#define W83793_REG_PWM_UPTIME 0xc3 /* Unit in 0.1 second */ +#define W83793_REG_PWM_DOWNTIME 0xc4 /* Unit in 0.1 second */ +#define W83793_REG_TEMP_CRITICAL 0xc5 + +#define PWM_DUTY 0 +#define PWM_START 1 +#define PWM_NONSTOP 2 +#define W83793_REG_PWM(index, nr) (((nr) == 0 ? 0xb3 : \ + (nr) == 1 ? 0x220 : 0x218) + (index)) + +/* bit field, fan1 is bit0, fan2 is bit1 ... */ +#define W83793_REG_TEMP_FAN_MAP(index) (0x201 + (index)) +#define W83793_REG_TEMP_TOL(index) (0x208 + (index)) +#define W83793_REG_TEMP_CRUISE(index) (0x210 + (index)) +#define W83793_REG_PWM_STOP_TIME(index) (0x228 + (index)) +#define W83793_REG_SF2_TEMP(index, nr) (0x230 + ((index) << 4) + (nr)) +#define W83793_REG_SF2_PWM(index, nr) (0x238 + ((index) << 4) + (nr)) + +static inline unsigned long FAN_FROM_REG(u16 val) +{ + if ((val >= 0xfff) || (val == 0)) + return 0; + return (1350000UL / val); +} + +static inline u16 FAN_TO_REG(long rpm) +{ + if (rpm <= 0) + return 0x0fff; + return SENSORS_LIMIT((1350000 + (rpm >> 1)) / rpm, 1, 0xffe); +} + +static inline unsigned long TIME_FROM_REG(u8 reg) +{ + return (reg * 100); +} + +static inline u8 TIME_TO_REG(unsigned long val) +{ + return SENSORS_LIMIT((val + 50) / 100, 0, 0xff); +} + +static inline long TEMP_FROM_REG(s8 reg) +{ + return (reg * 1000); +} + +static inline s8 TEMP_TO_REG(long val, s8 min, s8 max) +{ + return SENSORS_LIMIT((val + (val < 0 ? -500 : 500)) / 1000, min, max); +} + +struct w83793_data { + struct i2c_client client; + struct i2c_client *lm75[2]; + struct class_device *class_dev; + struct mutex update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ + unsigned long last_nonvolatile; /* In jiffies, last time we update the + nonvolatile registers */ + + u8 bank; + u8 vrm; + u8 vid[2]; + u8 in[10][3]; /* Register value, read/high/low */ + u8 in_low_bits[3]; /* Additional resolution for VCore A/B Vtt */ + + u16 has_fan; /* Only fan1- fan5 has own pins */ + u16 fan[12]; /* Register value combine */ + u16 fan_min[12]; /* Register value combine */ + + s8 temp[6][5]; /* current, crit, crit_hyst,warn, warn_hyst */ + u8 temp_low_bits; /* Additional resolution TD1-TD4 */ + u8 temp_mode[2]; /* byte 0: Temp D1-D4 mode each has 2 bits + byte 1: Temp R1,R2 mode, each has 1 bit */ + u8 temp_critical; /* If reached all fan will be at full speed */ + u8 temp_fan_map[6]; /* Temp controls which pwm fan, bit field */ + + u8 has_pwm; + u8 pwm_enable; /* Register value, each Temp has 1 bit */ + u8 pwm_uptime; /* Register value */ + u8 pwm_downtime; /* Register value */ + u8 pwm_default; /* All fan default pwm, next poweron valid */ + u8 pwm[8][3]; /* Register value */ + u8 pwm_stop_time[8]; + u8 temp_cruise[6]; + + u8 alarms[5]; /* realtime status registers */ + u8 beeps[5]; + u8 beep_enable; + u8 tolerance[3]; /* Temp tolerance(Smart Fan I/II) */ + u8 sf2_pwm[6][7]; /* Smart FanII: Fan duty cycle */ + u8 sf2_temp[6][7]; /* Smart FanII: Temp level point */ +}; + +static u8 w83793_read_value(struct i2c_client *client, u16 reg); +static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value); +static int w83793_attach_adapter(struct i2c_adapter *adapter); +static int w83793_detect(struct i2c_adapter *adapter, int address, int kind); +static int w83793_detach_client(struct i2c_client *client); +static void w83793_init_client(struct i2c_client *client); +static void w83793_update_nonvolatile(struct device *dev); +static struct w83793_data *w83793_update_device(struct device *dev); + +static struct i2c_driver w83793_driver = { + .driver = { + .name = "w83793", + }, + .attach_adapter = w83793_attach_adapter, + .detach_client = w83793_detach_client, +}; + +static ssize_t +show_vrm(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83793_data *data = i2c_get_clientdata(client); + + return sprintf(buf, "%d\n", data->vrm); +} + +static ssize_t +show_vid(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83793_data *data = w83793_update_device(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int index = sensor_attr->index; + + return sprintf(buf, "%d\n", vid_from_reg(data->vid[index], data->vrm)); +} + +static ssize_t +store_vrm(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83793_data *data = i2c_get_clientdata(client); + + data->vrm = simple_strtoul(buf, NULL, 10); + return count; +} + +#define ALARM_STATUS 0 +#define BEEP_ENABLE 1 +static ssize_t +show_alarm_beep(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83793_data *data = w83793_update_device(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index >> 3; + int bit = sensor_attr->index & 0x07; + u8 val; + + if (ALARM_STATUS == nr) { + val = (data->alarms[index] >> (bit)) & 1; + } else { /* BEEP_ENABLE */ + val = (data->beeps[index] >> (bit)) & 1; + } + + return sprintf(buf, "%u\n", val); +} + +static ssize_t +store_beep(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83793_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int index = sensor_attr->index >> 3; + int shift = sensor_attr->index & 0x07; + u8 beep_bit = 1 << shift; + u8 val; + + val = simple_strtoul(buf, NULL, 10); + if (val != 0 && val != 1) + return -EINVAL; + + mutex_lock(&data->update_lock); + data->beeps[index] = w83793_read_value(client, W83793_REG_BEEP(index)); + data->beeps[index] &= ~beep_bit; + data->beeps[index] |= val << shift; + w83793_write_value(client, W83793_REG_BEEP(index), data->beeps[index]); + mutex_unlock(&data->update_lock); + + return count; +} + +static ssize_t +show_beep_enable(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83793_data *data = w83793_update_device(dev); + return sprintf(buf, "%u\n", (data->beep_enable >> 1) & 0x01); +} + +static ssize_t +store_beep_enable(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83793_data *data = i2c_get_clientdata(client); + u8 val = simple_strtoul(buf, NULL, 10); + + if (val != 0 && val != 1) + return -EINVAL; + + mutex_lock(&data->update_lock); + data->beep_enable = w83793_read_value(client, W83793_REG_OVT_BEEP) + & 0xfd; + data->beep_enable |= val << 1; + w83793_write_value(client, W83793_REG_OVT_BEEP, data->beep_enable); + mutex_unlock(&data->update_lock); + + return count; +} + +/* Write any value to clear chassis alarm */ +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 w83793_data *data = i2c_get_clientdata(client); + u8 val; + + mutex_lock(&data->update_lock); + val = w83793_read_value(client, W83793_REG_CLR_CHASSIS); + val |= 0x80; + w83793_write_value(client, W83793_REG_CLR_CHASSIS, val); + mutex_unlock(&data->update_lock); + return count; +} + +#define FAN_INPUT 0 +#define FAN_MIN 1 +static ssize_t +show_fan(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 w83793_data *data = w83793_update_device(dev); + u16 val; + + if (FAN_INPUT == nr) { + val = data->fan[index] & 0x0fff; + } else { + val = data->fan_min[index] & 0x0fff; + } + + return sprintf(buf, "%lu\n", FAN_FROM_REG(val)); +} + +static ssize_t +store_fan_min(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 index = sensor_attr->index; + struct i2c_client *client = to_i2c_client(dev); + struct w83793_data *data = i2c_get_clientdata(client); + u16 val = FAN_TO_REG(simple_strtoul(buf, NULL, 10)); + + mutex_lock(&data->update_lock); + data->fan_min[index] = val; + w83793_write_value(client, W83793_REG_FAN_MIN(index), + (val >> 8) & 0xff); + w83793_write_value(client, W83793_REG_FAN_MIN(index) + 1, val & 0xff); + mutex_unlock(&data->update_lock); + + return count; +} + +#define PWM_DUTY 0 +#define PWM_START 1 +#define PWM_NONSTOP 2 +#define PWM_STOP_TIME 3 +static ssize_t +show_pwm(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + struct w83793_data *data = w83793_update_device(dev); + u16 val; + int nr = sensor_attr->nr; + int index = sensor_attr->index; + + if (PWM_STOP_TIME == nr) + val = TIME_FROM_REG(data->pwm_stop_time[index]); + else + val = (data->pwm[index][nr] & 0x3f) << 2; + + return sprintf(buf, "%d\n", val); +} + +static ssize_t +store_pwm(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83793_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + u8 val; + + mutex_lock(&data->update_lock); + if (PWM_STOP_TIME == nr) { + val = TIME_TO_REG(simple_strtoul(buf, NULL, 10)); + data->pwm_stop_time[index] = val; + w83793_write_value(client, W83793_REG_PWM_STOP_TIME(index), + val); + } else { + val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 0xff) + >> 2; + data->pwm[index][nr] = + w83793_read_value(client, W83793_REG_PWM(index, nr)) & 0xc0; + data->pwm[index][nr] |= val; + w83793_write_value(client, W83793_REG_PWM(index, nr), + data->pwm[index][nr]); + } + + mutex_unlock(&data->update_lock); + return count; +} + +static ssize_t +show_temp(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 w83793_data *data = w83793_update_device(dev); + long temp = TEMP_FROM_REG(data->temp[index][nr]); + + if (TEMP_READ == nr && index < 4) { /* Only TD1-TD4 have low bits */ + int low = ((data->temp_low_bits >> (index * 2)) & 0x03) * 250; + temp += temp > 0 ? low : -low; + } + return sprintf(buf, "%ld\n", temp); +} + +static ssize_t +store_temp(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 w83793_data *data = i2c_get_clientdata(client); + long tmp = simple_strtol(buf, NULL, 10); + + mutex_lock(&data->update_lock); + data->temp[index][nr] = TEMP_TO_REG(tmp, -128, 127); + w83793_write_value(client, W83793_REG_TEMP[index][nr], + data->temp[index][nr]); + mutex_unlock(&data->update_lock); + return count; +} + +/* + TD1-TD4 + each has 4 mode:(2 bits) + 0: Stop monitor + 1: Use internal temp sensor(default) + 2: Use sensor in AMD CPU and get result by AMDSI + 3: Use sensor in Intel CPU and get result by PECI + + TR1-TR2 + each has 2 mode:(1 bit) + 0: Disable temp sensor monitor + 1: To enable temp sensors monitor +*/ + +/* 0 disable, 5 AMDSI, 6 PECI */ +static u8 TO_TEMP_MODE[] = { 0, 0, 5, 6 }; + +static ssize_t +show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83793_data *data = w83793_update_device(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int index = sensor_attr->index; + u8 mask = (index < 4) ? 0x03 : 0x01; + u8 shift = (index < 4) ? (2 * index) : (index - 4); + u8 tmp; + index = (index < 4) ? 0 : 1; + + tmp = (data->temp_mode[index] >> shift) & mask; + + /* for the internal sensor, found out if diode or thermistor */ + if (tmp == 1) { + tmp = index == 0 ? 3 : 4; + } else { + tmp = TO_TEMP_MODE[tmp]; + } + + return sprintf(buf, "%d\n", tmp); +} + +static ssize_t +store_temp_mode(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83793_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int index = sensor_attr->index; + u8 mask = (index < 4) ? 0x03 : 0x01; + u8 shift = (index < 4) ? (2 * index) : (index - 4); + u8 val = simple_strtoul(buf, NULL, 10); + + /* transform the sysfs interface values into table above */ + if ((val == 5 || val == 6) && (index < 4)) { + val -= 3; + } else if ((val == 3 && index < 4) + || (val == 4 && index >= 4) + || val == 0) { + /* transform diode or thermistor into internal enable */ + val = !!val; + } else { + return -EINVAL; + } + + index = (index < 4) ? 0 : 1; + mutex_lock(&data->update_lock); + data->temp_mode[index] = + w83793_read_value(client, W83793_REG_TEMP_MODE[index]); + data->temp_mode[index] &= ~(mask << shift); + data->temp_mode[index] |= val << shift; + w83793_write_value(client, W83793_REG_TEMP_MODE[index], + data->temp_mode[index]); + mutex_unlock(&data->update_lock); + + return count; +} + +#define SETUP_PWM_DEFAULT 0 +#define SETUP_PWM_UPTIME 1 /* Unit in 0.1s */ +#define SETUP_PWM_DOWNTIME 2 /* Unit in 0.1s */ +#define SETUP_TEMP_CRITICAL 3 +static ssize_t +show_sf_setup(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; + struct w83793_data *data = w83793_update_device(dev); + u32 val = 0; + + if (SETUP_PWM_DEFAULT == nr) { + val = (data->pwm_default & 0x3f) << 2; + } else if (SETUP_PWM_UPTIME == nr) { + val = TIME_FROM_REG(data->pwm_uptime); + } else if (SETUP_PWM_DOWNTIME == nr) { + val = TIME_FROM_REG(data->pwm_downtime); + } else if (SETUP_TEMP_CRITICAL == nr) { + val = TEMP_FROM_REG(data->temp_critical & 0x7f); + } + + return sprintf(buf, "%d\n", val); +} + +static ssize_t +store_sf_setup(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; + struct i2c_client *client = to_i2c_client(dev); + struct w83793_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + if (SETUP_PWM_DEFAULT == nr) { + data->pwm_default = + w83793_read_value(client, W83793_REG_PWM_DEFAULT) & 0xc0; + data->pwm_default |= SENSORS_LIMIT(simple_strtoul(buf, NULL, + 10), + 0, 0xff) >> 2; + w83793_write_value(client, W83793_REG_PWM_DEFAULT, + data->pwm_default); + } else if (SETUP_PWM_UPTIME == nr) { + data->pwm_uptime = TIME_TO_REG(simple_strtoul(buf, NULL, 10)); + data->pwm_uptime += data->pwm_uptime == 0 ? 1 : 0; + w83793_write_value(client, W83793_REG_PWM_UPTIME, + data->pwm_uptime); + } else if (SETUP_PWM_DOWNTIME == nr) { + data->pwm_downtime = TIME_TO_REG(simple_strtoul(buf, NULL, 10)); + data->pwm_downtime += data->pwm_downtime == 0 ? 1 : 0; + w83793_write_value(client, W83793_REG_PWM_DOWNTIME, + data->pwm_downtime); + } else { /* SETUP_TEMP_CRITICAL */ + data->temp_critical = + w83793_read_value(client, W83793_REG_TEMP_CRITICAL) & 0x80; + data->temp_critical |= TEMP_TO_REG(simple_strtol(buf, NULL, 10), + 0, 0x7f); + w83793_write_value(client, W83793_REG_TEMP_CRITICAL, + data->temp_critical); + } + + mutex_unlock(&data->update_lock); + return count; +} + +/* + Temp SmartFan control + TEMP_FAN_MAP + Temp channel control which pwm fan, bitfield, bit 0 indicate pwm1... + It's possible two or more temp channels control the same fan, w83793 + always prefers to pick the most critical request and applies it to + the related Fan. + It's possible one fan is not in any mapping of 6 temp channels, this + means the fan is manual mode + + TEMP_PWM_ENABLE + Each temp channel has its own SmartFan mode, and temp channel + control fans that are set by TEMP_FAN_MAP + 0: SmartFanII mode + 1: Thermal Cruise Mode + + TEMP_CRUISE + Target temperature in thermal cruise mode, w83793 will try to turn + fan speed to keep the temperature of target device around this + temperature. + + TEMP_TOLERANCE + If Temp higher or lower than target with this tolerance, w83793 + will take actions to speed up or slow down the fan to keep the + temperature within the tolerance range. +*/ + +#define TEMP_FAN_MAP 0 +#define TEMP_PWM_ENABLE 1 +#define TEMP_CRUISE 2 +#define TEMP_TOLERANCE 3 +static ssize_t +show_sf_ctrl(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 w83793_data *data = w83793_update_device(dev); + u32 val; + + if (TEMP_FAN_MAP == nr) { + val = data->temp_fan_map[index]; + } else if (TEMP_PWM_ENABLE == nr) { + /* +2 to transfrom into 2 and 3 to conform with sysfs intf */ + val = ((data->pwm_enable >> index) & 0x01) + 2; + } else if (TEMP_CRUISE == nr) { + val = TEMP_FROM_REG(data->temp_cruise[index] & 0x7f); + } else { /* TEMP_TOLERANCE */ + val = data->tolerance[index >> 1] >> ((index & 0x01) ? 4 : 0); + val = TEMP_FROM_REG(val & 0x0f); + } + return sprintf(buf, "%d\n", val); +} + +static ssize_t +store_sf_ctrl(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 w83793_data *data = i2c_get_clientdata(client); + u32 val; + + mutex_lock(&data->update_lock); + if (TEMP_FAN_MAP == nr) { + val = simple_strtoul(buf, NULL, 10) & 0xff; + w83793_write_value(client, W83793_REG_TEMP_FAN_MAP(index), val); + data->temp_fan_map[index] = val; + } else if (TEMP_PWM_ENABLE == nr) { + val = simple_strtoul(buf, NULL, 10); + if (2 == val || 3 == val) { + data->pwm_enable = + w83793_read_value(client, W83793_REG_PWM_ENABLE); + if (val - 2) + data->pwm_enable |= 1 << index; + else + data->pwm_enable &= ~(1 << index); + w83793_write_value(client, W83793_REG_PWM_ENABLE, + data->pwm_enable); + } else { + mutex_unlock(&data->update_lock); + return -EINVAL; + } + } else if (TEMP_CRUISE == nr) { + data->temp_cruise[index] = + w83793_read_value(client, W83793_REG_TEMP_CRUISE(index)); + val = TEMP_TO_REG(simple_strtol(buf, NULL, 10), 0, 0x7f); + data->temp_cruise[index] &= 0x80; + data->temp_cruise[index] |= val; + + w83793_write_value(client, W83793_REG_TEMP_CRUISE(index), + data->temp_cruise[index]); + } else { /* TEMP_TOLERANCE */ + int i = index >> 1; + u8 shift = (index & 0x01) ? 4 : 0; + data->tolerance[i] = + w83793_read_value(client, W83793_REG_TEMP_TOL(i)); + + val = TEMP_TO_REG(simple_strtol(buf, NULL, 10), 0, 0x0f); + data->tolerance[i] &= ~(0x0f << shift); + data->tolerance[i] |= val << shift; + w83793_write_value(client, W83793_REG_TEMP_TOL(i), + data->tolerance[i]); + } + + mutex_unlock(&data->update_lock); + return count; +} + +static ssize_t +show_sf2_pwm(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 w83793_data *data = w83793_update_device(dev); + + return sprintf(buf, "%d\n", (data->sf2_pwm[index][nr] & 0x3f) << 2); +} + +static ssize_t +store_sf2_pwm(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83793_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + u8 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 0xff) >> 2; + + mutex_lock(&data->update_lock); + data->sf2_pwm[index][nr] = + w83793_read_value(client, W83793_REG_SF2_PWM(index, nr)) & 0xc0; + data->sf2_pwm[index][nr] |= val; + w83793_write_value(client, W83793_REG_SF2_PWM(index, nr), + data->sf2_pwm[index][nr]); + mutex_unlock(&data->update_lock); + return count; +} + +static ssize_t +show_sf2_temp(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 w83793_data *data = w83793_update_device(dev); + + return sprintf(buf, "%ld\n", + TEMP_FROM_REG(data->sf2_temp[index][nr] & 0x7f)); +} + +static ssize_t +store_sf2_temp(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83793_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + u8 val = TEMP_TO_REG(simple_strtol(buf, NULL, 10), 0, 0x7f); + + mutex_lock(&data->update_lock); + data->sf2_temp[index][nr] = + w83793_read_value(client, W83793_REG_SF2_TEMP(index, nr)) & 0x80; + data->sf2_temp[index][nr] |= val; + w83793_write_value(client, W83793_REG_SF2_TEMP(index, nr), + data->sf2_temp[index][nr]); + mutex_unlock(&data->update_lock); + return count; +} + +/* only Vcore A/B and Vtt have additional 2 bits precision */ +static ssize_t +show_in(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 w83793_data *data = w83793_update_device(dev); + u16 val = data->in[index][nr]; + + if (index < 3) { + val <<= 2; + val += (data->in_low_bits[nr] >> (index * 2)) & 0x3; + } + return sprintf(buf, "%d\n", val * scale_in[index]); +} + +static ssize_t +store_in(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 w83793_data *data = i2c_get_clientdata(client); + u32 val; + + val = + (simple_strtoul(buf, NULL, 10) + + scale_in[index] / 2) / scale_in[index]; + mutex_lock(&data->update_lock); + if (index > 2) { + val = SENSORS_LIMIT(val, 0, 255); + } else { + val = SENSORS_LIMIT(val, 0, 0x3FF); + data->in_low_bits[nr] = + w83793_read_value(client, W83793_REG_IN_LOW_BITS[nr]); + data->in_low_bits[nr] &= ~(0x03 << (2 * index)); + data->in_low_bits[nr] |= (val & 0x03) << (2 * index); + w83793_write_value(client, W83793_REG_IN_LOW_BITS[nr], + data->in_low_bits[nr]); + val >>= 2; + } + data->in[index][nr] = val; + w83793_write_value(client, W83793_REG_IN[index][nr], + data->in[index][nr]); + mutex_unlock(&data->update_lock); + return count; +} + +#define NOT_USED -1 + +#define SENSOR_ATTR_IN(index) \ + SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \ + IN_READ, index), \ + SENSOR_ATTR_2(in##index##_max, S_IRUGO | S_IWUSR, show_in, \ + store_in, IN_MAX, index), \ + SENSOR_ATTR_2(in##index##_min, S_IRUGO | S_IWUSR, show_in, \ + store_in, IN_LOW, index), \ + SENSOR_ATTR_2(in##index##_alarm, S_IRUGO, show_alarm_beep, \ + NULL, ALARM_STATUS, index + ((index > 2) ? 1 : 0)), \ + SENSOR_ATTR_2(in##index##_beep, S_IWUSR | S_IRUGO, \ + show_alarm_beep, store_beep, BEEP_ENABLE, \ + index + ((index > 2) ? 1 : 0)) + +#define SENSOR_ATTR_FAN(index) \ + SENSOR_ATTR_2(fan##index##_alarm, S_IRUGO, show_alarm_beep, \ + NULL, ALARM_STATUS, index + 17), \ + SENSOR_ATTR_2(fan##index##_beep, S_IWUSR | S_IRUGO, \ + show_alarm_beep, store_beep, BEEP_ENABLE, index + 17), \ + SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \ + NULL, FAN_INPUT, index - 1), \ + SENSOR_ATTR_2(fan##index##_min, S_IWUSR | S_IRUGO, \ + show_fan, store_fan_min, FAN_MIN, index - 1) + +#define SENSOR_ATTR_PWM(index) \ + SENSOR_ATTR_2(pwm##index, S_IWUSR | S_IRUGO, show_pwm, \ + store_pwm, PWM_DUTY, index - 1), \ + SENSOR_ATTR_2(pwm##index##_nonstop, S_IWUSR | S_IRUGO, \ + show_pwm, store_pwm, PWM_NONSTOP, index - 1), \ + SENSOR_ATTR_2(pwm##index##_start, S_IWUSR | S_IRUGO, \ + show_pwm, store_pwm, PWM_START, index - 1), \ + SENSOR_ATTR_2(pwm##index##_stop_time, S_IWUSR | S_IRUGO, \ + show_pwm, store_pwm, PWM_STOP_TIME, index - 1) + +#define SENSOR_ATTR_TEMP(index) \ + SENSOR_ATTR_2(temp##index##_type, S_IRUGO | S_IWUSR, \ + show_temp_mode, store_temp_mode, NOT_USED, index - 1), \ + SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp, \ + NULL, TEMP_READ, index - 1), \ + SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_temp, \ + store_temp, TEMP_CRIT, index - 1), \ + SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \ + show_temp, store_temp, TEMP_CRIT_HYST, index - 1), \ + SENSOR_ATTR_2(temp##index##_warn, S_IRUGO | S_IWUSR, show_temp, \ + store_temp, TEMP_WARN, index - 1), \ + SENSOR_ATTR_2(temp##index##_warn_hyst, S_IRUGO | S_IWUSR, \ + show_temp, store_temp, TEMP_WARN_HYST, index - 1), \ + SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \ + show_alarm_beep, NULL, ALARM_STATUS, index + 11), \ + SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ + show_alarm_beep, store_beep, BEEP_ENABLE, index + 11), \ + SENSOR_ATTR_2(temp##index##_auto_channels_pwm, \ + S_IRUGO | S_IWUSR, show_sf_ctrl, store_sf_ctrl, \ + TEMP_FAN_MAP, index - 1), \ + SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \ + show_sf_ctrl, store_sf_ctrl, TEMP_PWM_ENABLE, \ + index - 1), \ + SENSOR_ATTR_2(thermal_cruise##index, S_IRUGO | S_IWUSR, \ + show_sf_ctrl, store_sf_ctrl, TEMP_CRUISE, index - 1), \ + SENSOR_ATTR_2(tolerance##index, S_IRUGO | S_IWUSR, show_sf_ctrl,\ + store_sf_ctrl, TEMP_TOLERANCE, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point1_pwm, S_IRUGO | S_IWUSR, \ + show_sf2_pwm, store_sf2_pwm, 0, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point2_pwm, S_IRUGO | S_IWUSR, \ + show_sf2_pwm, store_sf2_pwm, 1, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point3_pwm, S_IRUGO | S_IWUSR, \ + show_sf2_pwm, store_sf2_pwm, 2, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point4_pwm, S_IRUGO | S_IWUSR, \ + show_sf2_pwm, store_sf2_pwm, 3, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point5_pwm, S_IRUGO | S_IWUSR, \ + show_sf2_pwm, store_sf2_pwm, 4, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point6_pwm, S_IRUGO | S_IWUSR, \ + show_sf2_pwm, store_sf2_pwm, 5, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point7_pwm, S_IRUGO | S_IWUSR, \ + show_sf2_pwm, store_sf2_pwm, 6, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point1_temp, S_IRUGO | S_IWUSR,\ + show_sf2_temp, store_sf2_temp, 0, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point2_temp, S_IRUGO | S_IWUSR,\ + show_sf2_temp, store_sf2_temp, 1, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point3_temp, S_IRUGO | S_IWUSR,\ + show_sf2_temp, store_sf2_temp, 2, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point4_temp, S_IRUGO | S_IWUSR,\ + show_sf2_temp, store_sf2_temp, 3, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point5_temp, S_IRUGO | S_IWUSR,\ + show_sf2_temp, store_sf2_temp, 4, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point6_temp, S_IRUGO | S_IWUSR,\ + show_sf2_temp, store_sf2_temp, 5, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point7_temp, S_IRUGO | S_IWUSR,\ + show_sf2_temp, store_sf2_temp, 6, index - 1) + +static struct sensor_device_attribute_2 w83793_sensor_attr_2[] = { + SENSOR_ATTR_IN(0), + SENSOR_ATTR_IN(1), + SENSOR_ATTR_IN(2), + SENSOR_ATTR_IN(3), + SENSOR_ATTR_IN(4), + SENSOR_ATTR_IN(5), + SENSOR_ATTR_IN(6), + SENSOR_ATTR_IN(7), + SENSOR_ATTR_IN(8), + SENSOR_ATTR_IN(9), + SENSOR_ATTR_TEMP(1), + SENSOR_ATTR_TEMP(2), + SENSOR_ATTR_TEMP(3), + SENSOR_ATTR_TEMP(4), + SENSOR_ATTR_TEMP(5), + SENSOR_ATTR_TEMP(6), + SENSOR_ATTR_FAN(1), + SENSOR_ATTR_FAN(2), + SENSOR_ATTR_FAN(3), + SENSOR_ATTR_FAN(4), + SENSOR_ATTR_FAN(5), + SENSOR_ATTR_PWM(1), + SENSOR_ATTR_PWM(2), + SENSOR_ATTR_PWM(3), +}; + +/* Fan6-Fan12 */ +static struct sensor_device_attribute_2 w83793_left_fan[] = { + SENSOR_ATTR_FAN(6), + SENSOR_ATTR_FAN(7), + SENSOR_ATTR_FAN(8), + SENSOR_ATTR_FAN(9), + SENSOR_ATTR_FAN(10), + SENSOR_ATTR_FAN(11), + SENSOR_ATTR_FAN(12), +}; + +/* Pwm4-Pwm8 */ +static struct sensor_device_attribute_2 w83793_left_pwm[] = { + SENSOR_ATTR_PWM(4), + SENSOR_ATTR_PWM(5), + SENSOR_ATTR_PWM(6), + SENSOR_ATTR_PWM(7), + SENSOR_ATTR_PWM(8), +}; + +static struct sensor_device_attribute_2 sda_single_files[] = { + SENSOR_ATTR_2(cpu0_vid, S_IRUGO, show_vid, NULL, NOT_USED, 0), + SENSOR_ATTR_2(cpu1_vid, S_IRUGO, show_vid, NULL, NOT_USED, 1), + SENSOR_ATTR_2(vrm, S_IWUSR | S_IRUGO, show_vrm, store_vrm, + NOT_USED, NOT_USED), + SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep, + store_chassis_clear, ALARM_STATUS, 30), + SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_beep_enable, + store_beep_enable, NOT_USED, NOT_USED), + SENSOR_ATTR_2(pwm_default, S_IWUSR | S_IRUGO, show_sf_setup, + store_sf_setup, SETUP_PWM_DEFAULT, NOT_USED), + SENSOR_ATTR_2(pwm_uptime, S_IWUSR | S_IRUGO, show_sf_setup, + store_sf_setup, SETUP_PWM_UPTIME, NOT_USED), + SENSOR_ATTR_2(pwm_downtime, S_IWUSR | S_IRUGO, show_sf_setup, + store_sf_setup, SETUP_PWM_DOWNTIME, NOT_USED), + SENSOR_ATTR_2(temp_critical, S_IWUSR | S_IRUGO, show_sf_setup, + store_sf_setup, SETUP_TEMP_CRITICAL, NOT_USED), +}; + +static void w83793_init_client(struct i2c_client *client) +{ + if (reset) { + w83793_write_value(client, W83793_REG_CONFIG, 0x80); + } + + /* Start monitoring */ + w83793_write_value(client, W83793_REG_CONFIG, + w83793_read_value(client, W83793_REG_CONFIG) | 0x01); + +} + +static int w83793_attach_adapter(struct i2c_adapter *adapter) +{ + if (!(adapter->class & I2C_CLASS_HWMON)) + return 0; + return i2c_probe(adapter, &addr_data, w83793_detect); +} + +static int w83793_detach_client(struct i2c_client *client) +{ + struct w83793_data *data = i2c_get_clientdata(client); + struct device *dev = &client->dev; + int err, i; + + /* main client */ + if (data) { + hwmon_device_unregister(data->class_dev); + + for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) + device_remove_file(dev, + &w83793_sensor_attr_2[i].dev_attr); + + for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) + device_remove_file(dev, &sda_single_files[i].dev_attr); + + for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++) + device_remove_file(dev, &w83793_left_fan[i].dev_attr); + + for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++) + device_remove_file(dev, &w83793_left_pwm[i].dev_attr); + } + + if ((err = i2c_detach_client(client))) + return err; + + /* main client */ + if (data) + kfree(data); + /* subclient */ + else + kfree(client); + + return 0; +} + +static int +w83793_create_subclient(struct i2c_adapter *adapter, + struct i2c_client *client, int addr, + struct i2c_client **sub_cli) +{ + int err = 0; + struct i2c_client *sub_client; + + (*sub_cli) = sub_client = + kzalloc(sizeof(struct i2c_client), GFP_KERNEL); + if (!(sub_client)) { + return -ENOMEM; + } + sub_client->addr = 0x48 + addr; + i2c_set_clientdata(sub_client, NULL); + sub_client->adapter = adapter; + sub_client->driver = &w83793_driver; + strlcpy(sub_client->name, "w83793 subclient", I2C_NAME_SIZE); + if ((err = i2c_attach_client(sub_client))) { + dev_err(&client->dev, "subclient registration " + "at address 0x%x failed\n", sub_client->addr); + kfree(sub_client); + } + return err; +} + +static int +w83793_detect_subclients(struct i2c_adapter *adapter, int address, + int kind, struct i2c_client *client) +{ + int i, id, err; + u8 tmp; + struct w83793_data *data = i2c_get_clientdata(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(&client->dev, + "invalid subclient " + "address %d; must be 0x48-0x4f\n", + force_subclients[i]); + err = -EINVAL; + goto ERROR_SC_0; + } + } + w83793_write_value(client, W83793_REG_I2C_SUBADDR, + (force_subclients[2] & 0x07) | + ((force_subclients[3] & 0x07) << 4)); + } + + tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); + if (!(tmp & 0x08)) { + err = + w83793_create_subclient(adapter, client, tmp & 0x7, + &data->lm75[0]); + if (err < 0) + goto ERROR_SC_0; + } + if (!(tmp & 0x80)) { + if ((data->lm75[0] != NULL) + && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) { + dev_err(&client->dev, + "duplicate addresses 0x%x, " + "use force_subclients\n", data->lm75[0]->addr); + err = -ENODEV; + goto ERROR_SC_1; + } + err = w83793_create_subclient(adapter, client, + (tmp >> 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 w83793_detect(struct i2c_adapter *adapter, int address, int kind) +{ + int i; + u8 tmp, val; + struct i2c_client *client; + struct device *dev; + struct w83793_data *data; + int files_fan = ARRAY_SIZE(w83793_left_fan) / 7; + int files_pwm = ARRAY_SIZE(w83793_left_pwm) / 5; + int err = 0; + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_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 w83793_{read,write}_value. */ + + if (!(data = kzalloc(sizeof(struct w83793_data), GFP_KERNEL))) { + err = -ENOMEM; + goto exit; + } + + client = &data->client; + dev = &client->dev; + i2c_set_clientdata(client, data); + client->addr = address; + client->adapter = adapter; + client->driver = &w83793_driver; + + data->bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); + + /* Now, we do the remaining detection. */ + if (kind < 0) { + tmp = data->bank & 0x80 ? 0x5c : 0xa3; + /* Check Winbond vendor ID */ + if (tmp != i2c_smbus_read_byte_data(client, + W83793_REG_VENDORID)) { + pr_debug("w83793: Detection failed at check " + "vendor id\n"); + err = -ENODEV; + goto free_mem; + } + + /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR + should match */ + if ((data->bank & 0x07) == 0 + && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) != + (address << 1)) { + pr_debug("w83793: Detection failed at check " + "i2c addr\n"); + err = -ENODEV; + goto free_mem; + } + + } + + /* We have either had a force parameter, or we have already detected the + Winbond. Determine the chip type now */ + + if (kind <= 0) { + if (0x7b == w83793_read_value(client, W83793_REG_CHIPID)) { + kind = w83793; + } else { + if (kind == 0) + dev_warn(&adapter->dev, "w83793: Ignoring " + "'force' parameter for unknown chip " + "at address 0x%02x\n", address); + err = -ENODEV; + goto free_mem; + } + } + + /* Fill in the remaining client fields and put into the global list */ + strlcpy(client->name, "w83793", I2C_NAME_SIZE); + + mutex_init(&data->update_lock); + + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(client))) + goto free_mem; + + if ((err = w83793_detect_subclients(adapter, address, kind, client))) + goto detach_client; + + /* Initialize the chip */ + w83793_init_client(client); + + data->vrm = vid_which_vrm(); + /* + Only fan 1-5 has their own input pins, + Pwm 1-3 has their own pins + */ + data->has_fan = 0x1f; + data->has_pwm = 0x07; + tmp = w83793_read_value(client, W83793_REG_MFC); + val = w83793_read_value(client, W83793_REG_FANIN_CTRL); + + /* check the function of pins 49-56 */ + if (!(tmp & 0x80)) { + data->has_pwm |= 0x18; /* pwm 4,5 */ + if (val & 0x01) { /* fan 6 */ + data->has_fan |= 0x20; + data->has_pwm |= 0x20; + } + if (val & 0x02) { /* fan 7 */ + data->has_fan |= 0x40; + data->has_pwm |= 0x40; + } + if (!(tmp & 0x40) && (val & 0x04)) { /* fan 8 */ + data->has_fan |= 0x80; + data->has_pwm |= 0x80; + } + } + + if (0x08 == (tmp & 0x0c)) { + if (val & 0x08) /* fan 9 */ + data->has_fan |= 0x100; + if (val & 0x10) /* fan 10 */ + data->has_fan |= 0x200; + } + + if (0x20 == (tmp & 0x30)) { + if (val & 0x20) /* fan 11 */ + data->has_fan |= 0x400; + if (val & 0x40) /* fan 12 */ + data->has_fan |= 0x800; + } + + if ((tmp & 0x01) && (val & 0x04)) { /* fan 8, second location */ + data->has_fan |= 0x80; + data->has_pwm |= 0x80; + } + + /* Register sysfs hooks */ + for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) { + err = device_create_file(dev, + &w83793_sensor_attr_2[i].dev_attr); + if (err) + goto exit_remove; + } + + for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { + err = device_create_file(dev, &sda_single_files[i].dev_attr); + if (err) + goto exit_remove; + + } + + for (i = 5; i < 12; i++) { + int j; + if (!(data->has_fan & (1 << i))) + continue; + for (j = 0; j < files_fan; j++) { + err = device_create_file(dev, + &w83793_left_fan[(i - 5) * files_fan + + j].dev_attr); + if (err) + goto exit_remove; + } + } + + for (i = 3; i < 8; i++) { + int j; + if (!(data->has_pwm & (1 << i))) + continue; + for (j = 0; j < files_pwm; j++) { + err = device_create_file(dev, + &w83793_left_pwm[(i - 3) * files_pwm + + j].dev_attr); + if (err) + goto exit_remove; + } + } + + data->class_dev = hwmon_device_register(dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_remove; + } + + return 0; + + /* Unregister sysfs hooks */ + +exit_remove: + for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) + device_remove_file(dev, &w83793_sensor_attr_2[i].dev_attr); + + for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) + device_remove_file(dev, &sda_single_files[i].dev_attr); + + for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++) + device_remove_file(dev, &w83793_left_fan[i].dev_attr); + + for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++) + device_remove_file(dev, &w83793_left_pwm[i].dev_attr); + + 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]); + } +detach_client: + i2c_detach_client(client); +free_mem: + kfree(data); +exit: + return err; +} + +static void w83793_update_nonvolatile(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83793_data *data = i2c_get_clientdata(client); + int i, j; + /* + They are somewhat "stable" registers, and to update them everytime + takes so much time, it's just not worthy. Update them in a long + interval to avoid exception. + */ + if (!(time_after(jiffies, data->last_nonvolatile + HZ * 300) + || !data->valid)) + return; + /* update voltage limits */ + for (i = 1; i < 3; i++) { + for (j = 0; j < ARRAY_SIZE(data->in); j++) { + data->in[j][i] = + w83793_read_value(client, W83793_REG_IN[j][i]); + } + data->in_low_bits[i] = + w83793_read_value(client, W83793_REG_IN_LOW_BITS[i]); + } + + for (i = 0; i < ARRAY_SIZE(data->fan_min); i++) { + /* Update the Fan measured value and limits */ + if (!(data->has_fan & (1 << i))) { + continue; + } + data->fan_min[i] = + w83793_read_value(client, W83793_REG_FAN_MIN(i)) << 8; + data->fan_min[i] |= + w83793_read_value(client, W83793_REG_FAN_MIN(i) + 1); + } + + for (i = 0; i < ARRAY_SIZE(data->temp_fan_map); i++) { + data->temp_fan_map[i] = + w83793_read_value(client, W83793_REG_TEMP_FAN_MAP(i)); + for (j = 1; j < 5; j++) { + data->temp[i][j] = + w83793_read_value(client, W83793_REG_TEMP[i][j]); + } + data->temp_cruise[i] = + w83793_read_value(client, W83793_REG_TEMP_CRUISE(i)); + for (j = 0; j < 7; j++) { + data->sf2_pwm[i][j] = + w83793_read_value(client, W83793_REG_SF2_PWM(i, j)); + data->sf2_temp[i][j] = + w83793_read_value(client, + W83793_REG_SF2_TEMP(i, j)); + } + } + + for (i = 0; i < ARRAY_SIZE(data->temp_mode); i++) + data->temp_mode[i] = + w83793_read_value(client, W83793_REG_TEMP_MODE[i]); + + for (i = 0; i < ARRAY_SIZE(data->tolerance); i++) { + data->tolerance[i] = + w83793_read_value(client, W83793_REG_TEMP_TOL(i)); + } + + for (i = 0; i < ARRAY_SIZE(data->pwm); i++) { + if (!(data->has_pwm & (1 << i))) + continue; + data->pwm[i][PWM_NONSTOP] = + w83793_read_value(client, W83793_REG_PWM(i, PWM_NONSTOP)); + data->pwm[i][PWM_START] = + w83793_read_value(client, W83793_REG_PWM(i, PWM_START)); + data->pwm_stop_time[i] = + w83793_read_value(client, W83793_REG_PWM_STOP_TIME(i)); + } + + data->pwm_default = w83793_read_value(client, W83793_REG_PWM_DEFAULT); + data->pwm_enable = w83793_read_value(client, W83793_REG_PWM_ENABLE); + data->pwm_uptime = w83793_read_value(client, W83793_REG_PWM_UPTIME); + data->pwm_downtime = w83793_read_value(client, W83793_REG_PWM_DOWNTIME); + data->temp_critical = + w83793_read_value(client, W83793_REG_TEMP_CRITICAL); + data->beep_enable = w83793_read_value(client, W83793_REG_OVT_BEEP); + + for (i = 0; i < ARRAY_SIZE(data->beeps); i++) { + data->beeps[i] = w83793_read_value(client, W83793_REG_BEEP(i)); + } + + data->last_nonvolatile = jiffies; +} + +static struct w83793_data *w83793_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83793_data *data = i2c_get_clientdata(client); + int i; + + mutex_lock(&data->update_lock); + + if (!(time_after(jiffies, data->last_updated + HZ * 2) + || !data->valid)) + goto END; + + /* Update the voltages measured value and limits */ + for (i = 0; i < ARRAY_SIZE(data->in); i++) + data->in[i][IN_READ] = + w83793_read_value(client, W83793_REG_IN[i][IN_READ]); + + data->in_low_bits[IN_READ] = + w83793_read_value(client, W83793_REG_IN_LOW_BITS[IN_READ]); + + for (i = 0; i < ARRAY_SIZE(data->fan); i++) { + if (!(data->has_fan & (1 << i))) { + continue; + } + data->fan[i] = + w83793_read_value(client, W83793_REG_FAN(i)) << 8; + data->fan[i] |= + w83793_read_value(client, W83793_REG_FAN(i) + 1); + } + + for (i = 0; i < ARRAY_SIZE(data->temp); i++) + data->temp[i][TEMP_READ] = + w83793_read_value(client, W83793_REG_TEMP[i][TEMP_READ]); + + data->temp_low_bits = + w83793_read_value(client, W83793_REG_TEMP_LOW_BITS); + + for (i = 0; i < ARRAY_SIZE(data->pwm); i++) { + if (data->has_pwm & (1 << i)) + data->pwm[i][PWM_DUTY] = + w83793_read_value(client, + W83793_REG_PWM(i, PWM_DUTY)); + } + + for (i = 0; i < ARRAY_SIZE(data->alarms); i++) + data->alarms[i] = + w83793_read_value(client, W83793_REG_ALARM(i)); + data->vid[0] = w83793_read_value(client, W83793_REG_VID_INA); + data->vid[1] = w83793_read_value(client, W83793_REG_VID_INB); + w83793_update_nonvolatile(dev); + data->last_updated = jiffies; + data->valid = 1; + +END: + mutex_unlock(&data->update_lock); + return data; +} + +/* Ignore the possibility that somebody change bank outside the driver + Must be called with data->update_lock held, except during initialization */ +static u8 w83793_read_value(struct i2c_client *client, u16 reg) +{ + struct w83793_data *data = i2c_get_clientdata(client); + u8 res = 0xff; + u8 new_bank = reg >> 8; + + new_bank |= data->bank & 0xfc; + if (data->bank != new_bank) { + if (i2c_smbus_write_byte_data + (client, W83793_REG_BANKSEL, new_bank) >= 0) + data->bank = new_bank; + else { + dev_err(&client->dev, + "set bank to %d failed, fall back " + "to bank %d, read reg 0x%x error\n", + new_bank, data->bank, reg); + res = 0x0; /* read 0x0 from the chip */ + goto END; + } + } + res = i2c_smbus_read_byte_data(client, reg & 0xff); +END: + return res; +} + +/* Must be called with data->update_lock held, except during initialization */ +static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value) +{ + struct w83793_data *data = i2c_get_clientdata(client); + int res; + u8 new_bank = reg >> 8; + + new_bank |= data->bank & 0xfc; + if (data->bank != new_bank) { + if ((res = i2c_smbus_write_byte_data + (client, W83793_REG_BANKSEL, new_bank)) >= 0) + data->bank = new_bank; + else { + dev_err(&client->dev, + "set bank to %d failed, fall back " + "to bank %d, write reg 0x%x error\n", + new_bank, data->bank, reg); + goto END; + } + } + + res = i2c_smbus_write_byte_data(client, reg & 0xff, value); +END: + return res; +} + +static int __init sensors_w83793_init(void) +{ + return i2c_add_driver(&w83793_driver); +} + +static void __exit sensors_w83793_exit(void) +{ + i2c_del_driver(&w83793_driver); +} + +MODULE_AUTHOR("Yuan Mu"); +MODULE_DESCRIPTION("w83793 driver"); +MODULE_LICENSE("GPL"); + +module_init(sensors_w83793_init); +module_exit(sensors_w83793_exit); diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c index 33fbb47100a3..8e1e3f8e40a4 100644 --- a/drivers/i2c/busses/i2c-ali1563.c +++ b/drivers/i2c/busses/i2c-ali1563.c @@ -2,7 +2,7 @@ * i2c-ali1563.c - i2c driver for the ALi 1563 Southbridge * * Copyright (C) 2004 Patrick Mochel - * 2005 Rudolf Marek <r.marek@sh.cvut.cz> + * 2005 Rudolf Marek <r.marek@assembler.cz> * * The 1563 southbridge is deceptively similar to the 1533, with a * few notable exceptions. One of those happens to be the fact they diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c index 60bef94cd25f..4ee56def61f2 100644 --- a/drivers/i2c/chips/tps65010.c +++ b/drivers/i2c/chips/tps65010.c @@ -82,7 +82,7 @@ struct tps65010 { struct i2c_client client; struct mutex lock; int irq; - struct work_struct work; + struct delayed_work work; struct dentry *file; unsigned charging:1; unsigned por:1; @@ -328,7 +328,7 @@ static void tps65010_interrupt(struct tps65010 *tps) { u8 tmp = 0, mask, poll; - /* IRQs won't trigger irqs for certain events, but we can get + /* IRQs won't trigger for certain events, but we can get * others by polling (normally, with external power applied). */ poll = 0; @@ -411,10 +411,11 @@ static void tps65010_interrupt(struct tps65010 *tps) } /* handle IRQs and polling using keventd for now */ -static void tps65010_work(void *_tps) +static void tps65010_work(struct work_struct *work) { - struct tps65010 *tps = _tps; + struct tps65010 *tps; + tps = container_of(work, struct tps65010, work.work); mutex_lock(&tps->lock); tps65010_interrupt(tps); @@ -452,7 +453,7 @@ static irqreturn_t tps65010_irq(int irq, void *_tps) disable_irq_nosync(irq); set_bit(FLAG_IRQ_ENABLE, &tps->flags); - (void) schedule_work(&tps->work); + (void) schedule_work(&tps->work.work); return IRQ_HANDLED; } @@ -465,13 +466,15 @@ static int __exit tps65010_detach_client(struct i2c_client *client) struct tps65010 *tps; tps = container_of(client, struct tps65010, client); + free_irq(tps->irq, tps); #ifdef CONFIG_ARM if (machine_is_omap_h2()) omap_free_gpio(58); if (machine_is_omap_osk()) omap_free_gpio(OMAP_MPUIO(1)); #endif - free_irq(tps->irq, tps); + cancel_delayed_work(&tps->work); + flush_scheduled_work(); debugfs_remove(tps->file); if (i2c_detach_client(client) == 0) kfree(tps); @@ -505,7 +508,7 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind) return 0; mutex_init(&tps->lock); - INIT_WORK(&tps->work, tps65010_work, tps); + INIT_DELAYED_WORK(&tps->work, tps65010_work); tps->irq = -1; tps->client.addr = address; tps->client.adapter = bus; @@ -620,7 +623,7 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind) (void) i2c_smbus_write_byte_data(&tps->client, TPS_MASK3, 0x0f | i2c_smbus_read_byte_data(&tps->client, TPS_MASK3)); - tps65010_work(tps); + tps65010_work(&tps->work.work); tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL, tps, DEBUG_FOPS); @@ -672,7 +675,7 @@ int tps65010_set_vbus_draw(unsigned mA) && test_and_set_bit( FLAG_VBUS_CHANGED, &the_tps->flags)) { /* gadget drivers call this in_irq() */ - (void) schedule_work(&the_tps->work); + (void) schedule_work(&the_tps->work.work); } local_irq_restore(flags); diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c index e3a267622bb6..d33717c8afd4 100644 --- a/drivers/ide/ide-floppy.c +++ b/drivers/ide/ide-floppy.c @@ -2147,7 +2147,7 @@ static int ide_floppy_probe(ide_drive_t *drive) printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name); goto failed; } - if ((floppy = (idefloppy_floppy_t *) kzalloc (sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) { + if ((floppy = kzalloc(sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) { printk (KERN_ERR "ide-floppy: %s: Can't allocate a floppy structure\n", drive->name); goto failed; } diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c index e2f4bb549063..b3bcd1d7315e 100644 --- a/drivers/ide/ide-tape.c +++ b/drivers/ide/ide-tape.c @@ -2573,11 +2573,11 @@ static idetape_stage_t *__idetape_kmalloc_stage (idetape_tape_t *tape, int full, int pages = tape->pages_per_stage; char *b_data = NULL; - if ((stage = (idetape_stage_t *) kmalloc (sizeof (idetape_stage_t),GFP_KERNEL)) == NULL) + if ((stage = kmalloc(sizeof (idetape_stage_t),GFP_KERNEL)) == NULL) return NULL; stage->next = NULL; - bh = stage->bh = (struct idetape_bh *)kmalloc(sizeof(struct idetape_bh), GFP_KERNEL); + bh = stage->bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL); if (bh == NULL) goto abort; bh->b_reqnext = NULL; @@ -2607,7 +2607,7 @@ static idetape_stage_t *__idetape_kmalloc_stage (idetape_tape_t *tape, int full, continue; } prev_bh = bh; - if ((bh = (struct idetape_bh *)kmalloc(sizeof(struct idetape_bh), GFP_KERNEL)) == NULL) { + if ((bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL)) == NULL) { free_page((unsigned long) b_data); goto abort; } @@ -4860,7 +4860,7 @@ static int ide_tape_probe(ide_drive_t *drive) printk(KERN_WARNING "ide-tape: Use drive %s with ide-scsi emulation and osst.\n", drive->name); printk(KERN_WARNING "ide-tape: OnStream support will be removed soon from ide-tape!\n"); } - tape = (idetape_tape_t *) kzalloc (sizeof (idetape_tape_t), GFP_KERNEL); + tape = kzalloc(sizeof (idetape_tape_t), GFP_KERNEL); if (tape == NULL) { printk(KERN_ERR "ide-tape: %s: Can't allocate a tape structure\n", drive->name); goto failed; diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c index e993a51f250e..08119da06d54 100644 --- a/drivers/ide/pci/hpt366.c +++ b/drivers/ide/pci/hpt366.c @@ -4,6 +4,7 @@ * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org> * Portions Copyright (C) 2001 Sun Microsystems, Inc. * Portions Copyright (C) 2003 Red Hat Inc + * Portions Copyright (C) 2005-2006 MontaVista Software, Inc. * * Thanks to HighPoint Technologies for their assistance, and hardware. * Special Thanks to Jon Burchmore in SanDiego for the deep pockets, his @@ -11,9 +12,11 @@ * development and support. * * - * Highpoint have their own driver (source except for the raid part) - * available from http://www.highpoint-tech.com/hpt3xx-opensource-v131.tgz - * This may be useful to anyone wanting to work on the mainstream hpt IDE. + * HighPoint has its own drivers (open source except for the RAID part) + * available from http://www.highpoint-tech.com/BIOS%20+%20Driver/. + * This may be useful to anyone wanting to work on this driver, however do not + * trust them too much since the code tends to become less and less meaningful + * as the time passes... :-/ * * Note that final HPT370 support was done by force extraction of GPL. * @@ -52,6 +55,29 @@ * keeping me sane. * Alan Cox <alan@redhat.com> * + * - fix the clock turnaround code: it was writing to the wrong ports when + * called for the secondary channel, caching the current clock mode per- + * channel caused the cached register value to get out of sync with the + * actual one, the channels weren't serialized, the turnaround shouldn't + * be done on 66 MHz PCI bus + * - avoid calibrating PLL twice as the second time results in a wrong PCI + * frequency and thus in the wrong timings for the secondary channel + * - disable UltraATA/133 for HPT372 by default (50 MHz DPLL clock do not + * allow for this speed anyway) + * - add support for HPT302N and HPT371N clocking (the same as for HPT372N) + * - HPT371/N are single channel chips, so avoid touching the primary channel + * which exists only virtually (there's no pins for it) + * - fix/remove bad/unused timing tables and use one set of tables for the whole + * HPT37x chip family; save space by introducing the separate transfer mode + * table in which the mode lookup is done + * - use f_CNT value saved by the HighPoint BIOS as reading it directly gives + * the wrong PCI frequency since DPLL has already been calibrated by BIOS + * - fix the hotswap code: it caused RESET- to glitch when tristating the bus, + * and for HPT36x the obsolete HDIO_TRISTATE_HWIF handler was called instead + * - pass to init_chipset() handlers a copy of the IDE PCI device structure as + * they tamper with its fields + * <source@mvista.com> + * */ @@ -76,8 +102,8 @@ /* various tuning parameters */ #define HPT_RESET_STATE_ENGINE -#undef HPT_DELAY_INTERRUPT -#undef HPT_SERIALIZE_IO +#undef HPT_DELAY_INTERRUPT +#define HPT_SERIALIZE_IO 0 static const char *quirk_drives[] = { "QUANTUM FIREBALLlct08 08", @@ -141,305 +167,175 @@ static const char *bad_ata33[] = { NULL }; -struct chipset_bus_clock_list_entry { - u8 xfer_speed; - unsigned int chipset_settings; +static u8 xfer_speeds[] = { + XFER_UDMA_6, + XFER_UDMA_5, + XFER_UDMA_4, + XFER_UDMA_3, + XFER_UDMA_2, + XFER_UDMA_1, + XFER_UDMA_0, + + XFER_MW_DMA_2, + XFER_MW_DMA_1, + XFER_MW_DMA_0, + + XFER_PIO_4, + XFER_PIO_3, + XFER_PIO_2, + XFER_PIO_1, + XFER_PIO_0 }; -/* key for bus clock timings - * bit - * 0:3 data_high_time. inactive time of DIOW_/DIOR_ for PIO and MW - * DMA. cycles = value + 1 - * 4:8 data_low_time. active time of DIOW_/DIOR_ for PIO and MW - * DMA. cycles = value + 1 - * 9:12 cmd_high_time. inactive time of DIOW_/DIOR_ during task file - * register access. - * 13:17 cmd_low_time. active time of DIOW_/DIOR_ during task file - * register access. - * 18:21 udma_cycle_time. clock freq and clock cycles for UDMA xfer. - * during task file register access. - * 22:24 pre_high_time. time to initialize 1st cycle for PIO and MW DMA - * xfer. - * 25:27 cmd_pre_high_time. time to initialize 1st PIO cycle for task - * register access. - * 28 UDMA enable - * 29 DMA enable - * 30 PIO_MST enable. if set, the chip is in bus master mode during - * PIO. - * 31 FIFO enable. +/* Key for bus clock timings + * 36x 37x + * bits bits + * 0:3 0:3 data_high_time. Inactive time of DIOW_/DIOR_ for PIO and MW DMA. + * cycles = value + 1 + * 4:7 4:8 data_low_time. Active time of DIOW_/DIOR_ for PIO and MW DMA. + * cycles = value + 1 + * 8:11 9:12 cmd_high_time. Inactive time of DIOW_/DIOR_ during task file + * register access. + * 12:15 13:17 cmd_low_time. Active time of DIOW_/DIOR_ during task file + * register access. + * 16:18 18:20 udma_cycle_time. Clock cycles for UDMA xfer. + * - 21 CLK frequency: 0=ATA clock, 1=dual ATA clock. + * 19:21 22:24 pre_high_time. Time to initialize the 1st cycle for PIO and + * MW DMA xfer. + * 22:24 25:27 cmd_pre_high_time. Time to initialize the 1st PIO cycle for + * task file register access. + * 28 28 UDMA enable. + * 29 29 DMA enable. + * 30 30 PIO MST enable. If set, the chip is in bus master mode during + * PIO xfer. + * 31 31 FIFO enable. */ -static struct chipset_bus_clock_list_entry forty_base_hpt366[] = { - { XFER_UDMA_4, 0x900fd943 }, - { XFER_UDMA_3, 0x900ad943 }, - { XFER_UDMA_2, 0x900bd943 }, - { XFER_UDMA_1, 0x9008d943 }, - { XFER_UDMA_0, 0x9008d943 }, - - { XFER_MW_DMA_2, 0xa008d943 }, - { XFER_MW_DMA_1, 0xa010d955 }, - { XFER_MW_DMA_0, 0xa010d9fc }, - - { XFER_PIO_4, 0xc008d963 }, - { XFER_PIO_3, 0xc010d974 }, - { XFER_PIO_2, 0xc010d997 }, - { XFER_PIO_1, 0xc010d9c7 }, - { XFER_PIO_0, 0xc018d9d9 }, - { 0, 0x0120d9d9 } -}; - -static struct chipset_bus_clock_list_entry thirty_three_base_hpt366[] = { - { XFER_UDMA_4, 0x90c9a731 }, - { XFER_UDMA_3, 0x90cfa731 }, - { XFER_UDMA_2, 0x90caa731 }, - { XFER_UDMA_1, 0x90cba731 }, - { XFER_UDMA_0, 0x90c8a731 }, - - { XFER_MW_DMA_2, 0xa0c8a731 }, - { XFER_MW_DMA_1, 0xa0c8a732 }, /* 0xa0c8a733 */ - { XFER_MW_DMA_0, 0xa0c8a797 }, - - { XFER_PIO_4, 0xc0c8a731 }, - { XFER_PIO_3, 0xc0c8a742 }, - { XFER_PIO_2, 0xc0d0a753 }, - { XFER_PIO_1, 0xc0d0a7a3 }, /* 0xc0d0a793 */ - { XFER_PIO_0, 0xc0d0a7aa }, /* 0xc0d0a7a7 */ - { 0, 0x0120a7a7 } -}; - -static struct chipset_bus_clock_list_entry twenty_five_base_hpt366[] = { - { XFER_UDMA_4, 0x90c98521 }, - { XFER_UDMA_3, 0x90cf8521 }, - { XFER_UDMA_2, 0x90cf8521 }, - { XFER_UDMA_1, 0x90cb8521 }, - { XFER_UDMA_0, 0x90cb8521 }, - - { XFER_MW_DMA_2, 0xa0ca8521 }, - { XFER_MW_DMA_1, 0xa0ca8532 }, - { XFER_MW_DMA_0, 0xa0ca8575 }, - - { XFER_PIO_4, 0xc0ca8521 }, - { XFER_PIO_3, 0xc0ca8532 }, - { XFER_PIO_2, 0xc0ca8542 }, - { XFER_PIO_1, 0xc0d08572 }, - { XFER_PIO_0, 0xc0d08585 }, - { 0, 0x01208585 } -}; - -/* from highpoint documentation. these are old values */ -static struct chipset_bus_clock_list_entry thirty_three_base_hpt370[] = { -/* { XFER_UDMA_5, 0x1A85F442, 0x16454e31 }, */ - { XFER_UDMA_5, 0x16454e31 }, - { XFER_UDMA_4, 0x16454e31 }, - { XFER_UDMA_3, 0x166d4e31 }, - { XFER_UDMA_2, 0x16494e31 }, - { XFER_UDMA_1, 0x164d4e31 }, - { XFER_UDMA_0, 0x16514e31 }, - - { XFER_MW_DMA_2, 0x26514e21 }, - { XFER_MW_DMA_1, 0x26514e33 }, - { XFER_MW_DMA_0, 0x26514e97 }, - - { XFER_PIO_4, 0x06514e21 }, - { XFER_PIO_3, 0x06514e22 }, - { XFER_PIO_2, 0x06514e33 }, - { XFER_PIO_1, 0x06914e43 }, - { XFER_PIO_0, 0x06914e57 }, - { 0, 0x06514e57 } -}; - -static struct chipset_bus_clock_list_entry sixty_six_base_hpt370[] = { - { XFER_UDMA_5, 0x14846231 }, - { XFER_UDMA_4, 0x14886231 }, - { XFER_UDMA_3, 0x148c6231 }, - { XFER_UDMA_2, 0x148c6231 }, - { XFER_UDMA_1, 0x14906231 }, - { XFER_UDMA_0, 0x14986231 }, - - { XFER_MW_DMA_2, 0x26514e21 }, - { XFER_MW_DMA_1, 0x26514e33 }, - { XFER_MW_DMA_0, 0x26514e97 }, - - { XFER_PIO_4, 0x06514e21 }, - { XFER_PIO_3, 0x06514e22 }, - { XFER_PIO_2, 0x06514e33 }, - { XFER_PIO_1, 0x06914e43 }, - { XFER_PIO_0, 0x06914e57 }, - { 0, 0x06514e57 } -}; - -/* these are the current (4 sep 2001) timings from highpoint */ -static struct chipset_bus_clock_list_entry thirty_three_base_hpt370a[] = { - { XFER_UDMA_5, 0x12446231 }, - { XFER_UDMA_4, 0x12446231 }, - { XFER_UDMA_3, 0x126c6231 }, - { XFER_UDMA_2, 0x12486231 }, - { XFER_UDMA_1, 0x124c6233 }, - { XFER_UDMA_0, 0x12506297 }, - - { XFER_MW_DMA_2, 0x22406c31 }, - { XFER_MW_DMA_1, 0x22406c33 }, - { XFER_MW_DMA_0, 0x22406c97 }, - - { XFER_PIO_4, 0x06414e31 }, - { XFER_PIO_3, 0x06414e42 }, - { XFER_PIO_2, 0x06414e53 }, - { XFER_PIO_1, 0x06814e93 }, - { XFER_PIO_0, 0x06814ea7 }, - { 0, 0x06814ea7 } -}; - -/* 2x 33MHz timings */ -static struct chipset_bus_clock_list_entry sixty_six_base_hpt370a[] = { - { XFER_UDMA_5, 0x1488e673 }, - { XFER_UDMA_4, 0x1488e673 }, - { XFER_UDMA_3, 0x1498e673 }, - { XFER_UDMA_2, 0x1490e673 }, - { XFER_UDMA_1, 0x1498e677 }, - { XFER_UDMA_0, 0x14a0e73f }, - - { XFER_MW_DMA_2, 0x2480fa73 }, - { XFER_MW_DMA_1, 0x2480fa77 }, - { XFER_MW_DMA_0, 0x2480fb3f }, - - { XFER_PIO_4, 0x0c82be73 }, - { XFER_PIO_3, 0x0c82be95 }, - { XFER_PIO_2, 0x0c82beb7 }, - { XFER_PIO_1, 0x0d02bf37 }, - { XFER_PIO_0, 0x0d02bf5f }, - { 0, 0x0d02bf5f } -}; -static struct chipset_bus_clock_list_entry fifty_base_hpt370a[] = { - { XFER_UDMA_5, 0x12848242 }, - { XFER_UDMA_4, 0x12ac8242 }, - { XFER_UDMA_3, 0x128c8242 }, - { XFER_UDMA_2, 0x120c8242 }, - { XFER_UDMA_1, 0x12148254 }, - { XFER_UDMA_0, 0x121882ea }, - - { XFER_MW_DMA_2, 0x22808242 }, - { XFER_MW_DMA_1, 0x22808254 }, - { XFER_MW_DMA_0, 0x228082ea }, - - { XFER_PIO_4, 0x0a81f442 }, - { XFER_PIO_3, 0x0a81f443 }, - { XFER_PIO_2, 0x0a81f454 }, - { XFER_PIO_1, 0x0ac1f465 }, - { XFER_PIO_0, 0x0ac1f48a }, - { 0, 0x0ac1f48a } +static u32 forty_base_hpt36x[] = { + /* XFER_UDMA_6 */ 0x900fd943, + /* XFER_UDMA_5 */ 0x900fd943, + /* XFER_UDMA_4 */ 0x900fd943, + /* XFER_UDMA_3 */ 0x900ad943, + /* XFER_UDMA_2 */ 0x900bd943, + /* XFER_UDMA_1 */ 0x9008d943, + /* XFER_UDMA_0 */ 0x9008d943, + + /* XFER_MW_DMA_2 */ 0xa008d943, + /* XFER_MW_DMA_1 */ 0xa010d955, + /* XFER_MW_DMA_0 */ 0xa010d9fc, + + /* XFER_PIO_4 */ 0xc008d963, + /* XFER_PIO_3 */ 0xc010d974, + /* XFER_PIO_2 */ 0xc010d997, + /* XFER_PIO_1 */ 0xc010d9c7, + /* XFER_PIO_0 */ 0xc018d9d9 }; -static struct chipset_bus_clock_list_entry thirty_three_base_hpt372[] = { - { XFER_UDMA_6, 0x1c81dc62 }, - { XFER_UDMA_5, 0x1c6ddc62 }, - { XFER_UDMA_4, 0x1c8ddc62 }, - { XFER_UDMA_3, 0x1c8edc62 }, /* checkme */ - { XFER_UDMA_2, 0x1c91dc62 }, - { XFER_UDMA_1, 0x1c9adc62 }, /* checkme */ - { XFER_UDMA_0, 0x1c82dc62 }, /* checkme */ - - { XFER_MW_DMA_2, 0x2c829262 }, - { XFER_MW_DMA_1, 0x2c829266 }, /* checkme */ - { XFER_MW_DMA_0, 0x2c82922e }, /* checkme */ - - { XFER_PIO_4, 0x0c829c62 }, - { XFER_PIO_3, 0x0c829c84 }, - { XFER_PIO_2, 0x0c829ca6 }, - { XFER_PIO_1, 0x0d029d26 }, - { XFER_PIO_0, 0x0d029d5e }, - { 0, 0x0d029d5e } +static u32 thirty_three_base_hpt36x[] = { + /* XFER_UDMA_6 */ 0x90c9a731, + /* XFER_UDMA_5 */ 0x90c9a731, + /* XFER_UDMA_4 */ 0x90c9a731, + /* XFER_UDMA_3 */ 0x90cfa731, + /* XFER_UDMA_2 */ 0x90caa731, + /* XFER_UDMA_1 */ 0x90cba731, + /* XFER_UDMA_0 */ 0x90c8a731, + + /* XFER_MW_DMA_2 */ 0xa0c8a731, + /* XFER_MW_DMA_1 */ 0xa0c8a732, /* 0xa0c8a733 */ + /* XFER_MW_DMA_0 */ 0xa0c8a797, + + /* XFER_PIO_4 */ 0xc0c8a731, + /* XFER_PIO_3 */ 0xc0c8a742, + /* XFER_PIO_2 */ 0xc0d0a753, + /* XFER_PIO_1 */ 0xc0d0a7a3, /* 0xc0d0a793 */ + /* XFER_PIO_0 */ 0xc0d0a7aa /* 0xc0d0a7a7 */ }; -static struct chipset_bus_clock_list_entry fifty_base_hpt372[] = { - { XFER_UDMA_5, 0x12848242 }, - { XFER_UDMA_4, 0x12ac8242 }, - { XFER_UDMA_3, 0x128c8242 }, - { XFER_UDMA_2, 0x120c8242 }, - { XFER_UDMA_1, 0x12148254 }, - { XFER_UDMA_0, 0x121882ea }, - - { XFER_MW_DMA_2, 0x22808242 }, - { XFER_MW_DMA_1, 0x22808254 }, - { XFER_MW_DMA_0, 0x228082ea }, - - { XFER_PIO_4, 0x0a81f442 }, - { XFER_PIO_3, 0x0a81f443 }, - { XFER_PIO_2, 0x0a81f454 }, - { XFER_PIO_1, 0x0ac1f465 }, - { XFER_PIO_0, 0x0ac1f48a }, - { 0, 0x0a81f443 } +static u32 twenty_five_base_hpt36x[] = { + /* XFER_UDMA_6 */ 0x90c98521, + /* XFER_UDMA_5 */ 0x90c98521, + /* XFER_UDMA_4 */ 0x90c98521, + /* XFER_UDMA_3 */ 0x90cf8521, + /* XFER_UDMA_2 */ 0x90cf8521, + /* XFER_UDMA_1 */ 0x90cb8521, + /* XFER_UDMA_0 */ 0x90cb8521, + + /* XFER_MW_DMA_2 */ 0xa0ca8521, + /* XFER_MW_DMA_1 */ 0xa0ca8532, + /* XFER_MW_DMA_0 */ 0xa0ca8575, + + /* XFER_PIO_4 */ 0xc0ca8521, + /* XFER_PIO_3 */ 0xc0ca8532, + /* XFER_PIO_2 */ 0xc0ca8542, + /* XFER_PIO_1 */ 0xc0d08572, + /* XFER_PIO_0 */ 0xc0d08585 }; -static struct chipset_bus_clock_list_entry sixty_six_base_hpt372[] = { - { XFER_UDMA_6, 0x1c869c62 }, - { XFER_UDMA_5, 0x1cae9c62 }, - { XFER_UDMA_4, 0x1c8a9c62 }, - { XFER_UDMA_3, 0x1c8e9c62 }, - { XFER_UDMA_2, 0x1c929c62 }, - { XFER_UDMA_1, 0x1c9a9c62 }, - { XFER_UDMA_0, 0x1c829c62 }, - - { XFER_MW_DMA_2, 0x2c829c62 }, - { XFER_MW_DMA_1, 0x2c829c66 }, - { XFER_MW_DMA_0, 0x2c829d2e }, - - { XFER_PIO_4, 0x0c829c62 }, - { XFER_PIO_3, 0x0c829c84 }, - { XFER_PIO_2, 0x0c829ca6 }, - { XFER_PIO_1, 0x0d029d26 }, - { XFER_PIO_0, 0x0d029d5e }, - { 0, 0x0d029d26 } +static u32 thirty_three_base_hpt37x[] = { + /* XFER_UDMA_6 */ 0x12446231, /* 0x12646231 ?? */ + /* XFER_UDMA_5 */ 0x12446231, + /* XFER_UDMA_4 */ 0x12446231, + /* XFER_UDMA_3 */ 0x126c6231, + /* XFER_UDMA_2 */ 0x12486231, + /* XFER_UDMA_1 */ 0x124c6233, + /* XFER_UDMA_0 */ 0x12506297, + + /* XFER_MW_DMA_2 */ 0x22406c31, + /* XFER_MW_DMA_1 */ 0x22406c33, + /* XFER_MW_DMA_0 */ 0x22406c97, + + /* XFER_PIO_4 */ 0x06414e31, + /* XFER_PIO_3 */ 0x06414e42, + /* XFER_PIO_2 */ 0x06414e53, + /* XFER_PIO_1 */ 0x06814e93, + /* XFER_PIO_0 */ 0x06814ea7 }; -static struct chipset_bus_clock_list_entry thirty_three_base_hpt374[] = { - { XFER_UDMA_6, 0x12808242 }, - { XFER_UDMA_5, 0x12848242 }, - { XFER_UDMA_4, 0x12ac8242 }, - { XFER_UDMA_3, 0x128c8242 }, - { XFER_UDMA_2, 0x120c8242 }, - { XFER_UDMA_1, 0x12148254 }, - { XFER_UDMA_0, 0x121882ea }, - - { XFER_MW_DMA_2, 0x22808242 }, - { XFER_MW_DMA_1, 0x22808254 }, - { XFER_MW_DMA_0, 0x228082ea }, - - { XFER_PIO_4, 0x0a81f442 }, - { XFER_PIO_3, 0x0a81f443 }, - { XFER_PIO_2, 0x0a81f454 }, - { XFER_PIO_1, 0x0ac1f465 }, - { XFER_PIO_0, 0x0ac1f48a }, - { 0, 0x06814e93 } +static u32 fifty_base_hpt37x[] = { + /* XFER_UDMA_6 */ 0x12848242, + /* XFER_UDMA_5 */ 0x12848242, + /* XFER_UDMA_4 */ 0x12ac8242, + /* XFER_UDMA_3 */ 0x128c8242, + /* XFER_UDMA_2 */ 0x120c8242, + /* XFER_UDMA_1 */ 0x12148254, + /* XFER_UDMA_0 */ 0x121882ea, + + /* XFER_MW_DMA_2 */ 0x22808242, + /* XFER_MW_DMA_1 */ 0x22808254, + /* XFER_MW_DMA_0 */ 0x228082ea, + + /* XFER_PIO_4 */ 0x0a81f442, + /* XFER_PIO_3 */ 0x0a81f443, + /* XFER_PIO_2 */ 0x0a81f454, + /* XFER_PIO_1 */ 0x0ac1f465, + /* XFER_PIO_0 */ 0x0ac1f48a }; -/* FIXME: 50MHz timings for HPT374 */ - -#if 0 -static struct chipset_bus_clock_list_entry sixty_six_base_hpt374[] = { - { XFER_UDMA_6, 0x12406231 }, /* checkme */ - { XFER_UDMA_5, 0x12446231 }, /* 0x14846231 */ - { XFER_UDMA_4, 0x16814ea7 }, /* 0x14886231 */ - { XFER_UDMA_3, 0x16814ea7 }, /* 0x148c6231 */ - { XFER_UDMA_2, 0x16814ea7 }, /* 0x148c6231 */ - { XFER_UDMA_1, 0x16814ea7 }, /* 0x14906231 */ - { XFER_UDMA_0, 0x16814ea7 }, /* 0x14986231 */ - { XFER_MW_DMA_2, 0x16814ea7 }, /* 0x26514e21 */ - { XFER_MW_DMA_1, 0x16814ea7 }, /* 0x26514e97 */ - { XFER_MW_DMA_0, 0x16814ea7 }, /* 0x26514e97 */ - { XFER_PIO_4, 0x06814ea7 }, /* 0x06514e21 */ - { XFER_PIO_3, 0x06814ea7 }, /* 0x06514e22 */ - { XFER_PIO_2, 0x06814ea7 }, /* 0x06514e33 */ - { XFER_PIO_1, 0x06814ea7 }, /* 0x06914e43 */ - { XFER_PIO_0, 0x06814ea7 }, /* 0x06914e57 */ - { 0, 0x06814ea7 } +static u32 sixty_six_base_hpt37x[] = { + /* XFER_UDMA_6 */ 0x1c869c62, + /* XFER_UDMA_5 */ 0x1cae9c62, /* 0x1c8a9c62 */ + /* XFER_UDMA_4 */ 0x1c8a9c62, + /* XFER_UDMA_3 */ 0x1c8e9c62, + /* XFER_UDMA_2 */ 0x1c929c62, + /* XFER_UDMA_1 */ 0x1c9a9c62, + /* XFER_UDMA_0 */ 0x1c829c62, + + /* XFER_MW_DMA_2 */ 0x2c829c62, + /* XFER_MW_DMA_1 */ 0x2c829c66, + /* XFER_MW_DMA_0 */ 0x2c829d2e, + + /* XFER_PIO_4 */ 0x0c829c62, + /* XFER_PIO_3 */ 0x0c829c84, + /* XFER_PIO_2 */ 0x0c829ca6, + /* XFER_PIO_1 */ 0x0d029d26, + /* XFER_PIO_0 */ 0x0d029d5e }; -#endif #define HPT366_DEBUG_DRIVE_INFO 0 #define HPT374_ALLOW_ATA133_6 0 #define HPT371_ALLOW_ATA133_6 0 #define HPT302_ALLOW_ATA133_6 0 -#define HPT372_ALLOW_ATA133_6 1 +#define HPT372_ALLOW_ATA133_6 0 #define HPT370_ALLOW_ATA100_5 1 #define HPT366_ALLOW_ATA66_4 1 #define HPT366_ALLOW_ATA66_3 1 @@ -461,9 +357,10 @@ struct hpt_info int revision; /* Chipset revision */ int flags; /* Chipset properties */ #define PLL_MODE 1 -#define IS_372N 2 +#define IS_3xxN 2 +#define PCI_66MHZ 4 /* Speed table */ - struct chipset_bus_clock_list_entry *speed; + u32 *speed; }; /* @@ -600,12 +497,20 @@ static int check_in_drive_lists (ide_drive_t *drive, const char **list) return 0; } -static unsigned int pci_bus_clock_list (u8 speed, struct chipset_bus_clock_list_entry * chipset_table) +static u32 pci_bus_clock_list(u8 speed, u32 *chipset_table) { - for ( ; chipset_table->xfer_speed ; chipset_table++) - if (chipset_table->xfer_speed == speed) - return chipset_table->chipset_settings; - return chipset_table->chipset_settings; + int i; + + /* + * Lookup the transfer mode table to get the index into + * the timing table. + * + * NOTE: For XFER_PIO_SLOW, PIO mode 0 timings will be used. + */ + for (i = 0; i < ARRAY_SIZE(xfer_speeds) - 1; i++) + if (xfer_speeds[i] == speed) + break; + return chipset_table[i]; } static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed) @@ -956,156 +861,127 @@ static int hpt374_ide_dma_end (ide_drive_t *drive) } /** - * hpt372n_set_clock - perform clock switching dance - * @drive: Drive to switch - * @mode: Switching mode (0x21 for write, 0x23 otherwise) + * hpt3xxn_set_clock - perform clock switching dance + * @hwif: hwif to switch + * @mode: clocking mode (0x21 for write, 0x23 otherwise) * - * Switch the DPLL clock on the HPT372N devices. This is a - * right mess. + * Switch the DPLL clock on the HPT3xxN devices. This is a right mess. + * NOTE: avoid touching the disabled primary channel on HPT371N -- it + * doesn't physically exist anyway... */ - -static void hpt372n_set_clock(ide_drive_t *drive, int mode) + +static void hpt3xxn_set_clock(ide_hwif_t *hwif, u8 mode) { - ide_hwif_t *hwif = HWIF(drive); - - /* FIXME: should we check for DMA active and BUG() */ + u8 mcr1, scr2 = hwif->INB(hwif->dma_master + 0x7b); + + if ((scr2 & 0x7f) == mode) + return; + + /* MISC. control register 1 has the channel enable bit... */ + mcr1 = hwif->INB(hwif->dma_master + 0x70); + /* Tristate the bus */ - outb(0x80, hwif->dma_base+0x73); - outb(0x80, hwif->dma_base+0x77); - + if (mcr1 & 0x04) + hwif->OUTB(0x80, hwif->dma_master + 0x73); + hwif->OUTB(0x80, hwif->dma_master + 0x77); + /* Switch clock and reset channels */ - outb(mode, hwif->dma_base+0x7B); - outb(0xC0, hwif->dma_base+0x79); - + hwif->OUTB(mode, hwif->dma_master + 0x7b); + hwif->OUTB(0xc0, hwif->dma_master + 0x79); + /* Reset state machines */ - outb(0x37, hwif->dma_base+0x70); - outb(0x37, hwif->dma_base+0x74); - + if (mcr1 & 0x04) + hwif->OUTB(0x37, hwif->dma_master + 0x70); + hwif->OUTB(0x37, hwif->dma_master + 0x74); + /* Complete reset */ - outb(0x00, hwif->dma_base+0x79); - + hwif->OUTB(0x00, hwif->dma_master + 0x79); + /* Reconnect channels to bus */ - outb(0x00, hwif->dma_base+0x73); - outb(0x00, hwif->dma_base+0x77); + if (mcr1 & 0x04) + hwif->OUTB(0x00, hwif->dma_master + 0x73); + hwif->OUTB(0x00, hwif->dma_master + 0x77); } /** - * hpt372n_rw_disk - prepare for I/O + * hpt3xxn_rw_disk - prepare for I/O * @drive: drive for command * @rq: block request structure * - * This is called when a disk I/O is issued to the 372N. + * This is called when a disk I/O is issued to HPT3xxN. * We need it because of the clock switching. */ -static void hpt372n_rw_disk(ide_drive_t *drive, struct request *rq) -{ - ide_hwif_t *hwif = drive->hwif; - int wantclock; - - wantclock = rq_data_dir(rq) ? 0x23 : 0x21; - - if (hwif->config_data != wantclock) { - hpt372n_set_clock(drive, wantclock); - hwif->config_data = wantclock; - } -} - -/* - * Since SUN Cobalt is attempting to do this operation, I should disclose - * this has been a long time ago Thu Jul 27 16:40:57 2000 was the patch date - * HOTSWAP ATA Infrastructure. - */ - -static void hpt3xx_reset (ide_drive_t *drive) -{ -} - -static int hpt3xx_tristate (ide_drive_t * drive, int state) +static void hpt3xxn_rw_disk(ide_drive_t *drive, struct request *rq) { ide_hwif_t *hwif = HWIF(drive); - struct pci_dev *dev = hwif->pci_dev; - u8 reg59h = 0, reset = (hwif->channel) ? 0x80 : 0x40; - u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53; - - pci_read_config_byte(dev, 0x59, ®59h); - pci_read_config_byte(dev, state_reg, ®XXh); + u8 wantclock = rq_data_dir(rq) ? 0x23 : 0x21; - if (state) { - (void) ide_do_reset(drive); - pci_write_config_byte(dev, state_reg, regXXh|0x80); - pci_write_config_byte(dev, 0x59, reg59h|reset); - } else { - pci_write_config_byte(dev, 0x59, reg59h & ~(reset)); - pci_write_config_byte(dev, state_reg, regXXh & ~(0x80)); - (void) ide_do_reset(drive); - } - return 0; + hpt3xxn_set_clock(hwif, wantclock); } /* - * set/get power state for a drive. - * turning the power off does the following things: - * 1) soft-reset the drive - * 2) tri-states the ide bus + * Set/get power state for a drive. * - * when we turn things back on, we need to re-initialize things. + * When we turn the power back on, we need to re-initialize things. */ #define TRISTATE_BIT 0x8000 -static int hpt370_busproc(ide_drive_t * drive, int state) + +static int hpt3xx_busproc(ide_drive_t *drive, int state) { ide_hwif_t *hwif = drive->hwif; struct pci_dev *dev = hwif->pci_dev; - u8 tristate = 0, resetmask = 0, bus_reg = 0; - u16 tri_reg; + u8 tristate, resetmask, bus_reg = 0; + u16 tri_reg = 0; hwif->bus_state = state; if (hwif->channel) { /* secondary channel */ - tristate = 0x56; - resetmask = 0x80; + tristate = 0x56; + resetmask = 0x80; } else { /* primary channel */ - tristate = 0x52; + tristate = 0x52; resetmask = 0x40; } - /* grab status */ + /* Grab the status. */ pci_read_config_word(dev, tristate, &tri_reg); pci_read_config_byte(dev, 0x59, &bus_reg); - /* set the state. we don't set it if we don't need to do so. - * make sure that the drive knows that it has failed if it's off */ + /* + * Set the state. We don't set it if we don't need to do so. + * Make sure that the drive knows that it has failed if it's off. + */ switch (state) { case BUSSTATE_ON: - hwif->drives[0].failures = 0; - hwif->drives[1].failures = 0; - if ((bus_reg & resetmask) == 0) + if (!(bus_reg & resetmask)) return 0; - tri_reg &= ~TRISTATE_BIT; - bus_reg &= ~resetmask; - break; + hwif->drives[0].failures = hwif->drives[1].failures = 0; + + pci_write_config_byte(dev, 0x59, bus_reg & ~resetmask); + pci_write_config_word(dev, tristate, tri_reg & ~TRISTATE_BIT); + return 0; case BUSSTATE_OFF: - hwif->drives[0].failures = hwif->drives[0].max_failures + 1; - hwif->drives[1].failures = hwif->drives[1].max_failures + 1; - if ((tri_reg & TRISTATE_BIT) == 0 && (bus_reg & resetmask)) + if ((bus_reg & resetmask) && !(tri_reg & TRISTATE_BIT)) return 0; tri_reg &= ~TRISTATE_BIT; - bus_reg |= resetmask; break; case BUSSTATE_TRISTATE: - hwif->drives[0].failures = hwif->drives[0].max_failures + 1; - hwif->drives[1].failures = hwif->drives[1].max_failures + 1; - if ((tri_reg & TRISTATE_BIT) && (bus_reg & resetmask)) + if ((bus_reg & resetmask) && (tri_reg & TRISTATE_BIT)) return 0; tri_reg |= TRISTATE_BIT; - bus_reg |= resetmask; break; + default: + return -EINVAL; } - pci_write_config_byte(dev, 0x59, bus_reg); - pci_write_config_word(dev, tristate, tri_reg); + hwif->drives[0].failures = hwif->drives[0].max_failures + 1; + hwif->drives[1].failures = hwif->drives[1].max_failures + 1; + + pci_write_config_word(dev, tristate, tri_reg); + pci_write_config_byte(dev, 0x59, bus_reg | resetmask); return 0; } @@ -1119,14 +995,14 @@ static void __devinit hpt366_clocking(ide_hwif_t *hwif) /* detect bus speed by looking at control reg timing: */ switch((reg1 >> 8) & 7) { case 5: - info->speed = forty_base_hpt366; + info->speed = forty_base_hpt36x; break; case 9: - info->speed = twenty_five_base_hpt366; + info->speed = twenty_five_base_hpt36x; break; case 7: default: - info->speed = thirty_three_base_hpt366; + info->speed = thirty_three_base_hpt36x; break; } } @@ -1136,9 +1012,9 @@ static void __devinit hpt37x_clocking(ide_hwif_t *hwif) struct hpt_info *info = ide_get_hwifdata(hwif); struct pci_dev *dev = hwif->pci_dev; int adjust, i; - u16 freq; - u32 pll; - u8 reg5bh; + u16 freq = 0; + u32 pll, temp = 0; + u8 reg5bh = 0, mcr1 = 0; /* * default to pci clock. make sure MA15/16 are set to output @@ -1151,27 +1027,40 @@ static void __devinit hpt37x_clocking(ide_hwif_t *hwif) pci_write_config_byte(dev, 0x5b, 0x23); /* - * set up the PLL. we need to adjust it so that it's stable. - * freq = Tpll * 192 / Tpci + * We'll have to read f_CNT value in order to determine + * the PCI clock frequency according to the following ratio: + * + * f_CNT = Fpci * 192 / Fdpll + * + * First try reading the register in which the HighPoint BIOS + * saves f_CNT value before reprogramming the DPLL from its + * default setting (which differs for the various chips). + * NOTE: This register is only accessible via I/O space. * - * Todo. For non x86 should probably check the dword is - * set to 0xABCDExxx indicating the BIOS saved f_CNT + * In case the signature check fails, we'll have to resort to + * reading the f_CNT register itself in hopes that nobody has + * touched the DPLL yet... */ - pci_read_config_word(dev, 0x78, &freq); - freq &= 0x1FF; - + temp = inl(pci_resource_start(dev, 4) + 0x90); + if ((temp & 0xFFFFF000) != 0xABCDE000) { + printk(KERN_WARNING "HPT37X: no clock data saved by BIOS\n"); + + /* Calculate the average value of f_CNT */ + for (temp = i = 0; i < 128; i++) { + pci_read_config_word(dev, 0x78, &freq); + temp += freq & 0x1ff; + mdelay(1); + } + freq = temp / 128; + } else + freq = temp & 0x1ff; + /* - * The 372N uses different PCI clock information and has - * some other complications - * On PCI33 timing we must clock switch - * On PCI66 timing we must NOT use the PCI clock - * - * Currently we always set up the PLL for the 372N + * HPT3xxN chips use different PCI clock information. + * Currently we always set up the PLL for them. */ - - if(info->flags & IS_372N) - { - printk(KERN_INFO "hpt: HPT372N detected, using 372N timing.\n"); + + if (info->flags & IS_3xxN) { if(freq < 0x55) pll = F_LOW_PCI_33; else if(freq < 0x70) @@ -1180,10 +1069,8 @@ static void __devinit hpt37x_clocking(ide_hwif_t *hwif) pll = F_LOW_PCI_50; else pll = F_LOW_PCI_66; - - printk(KERN_INFO "FREQ: %d PLL: %d\n", freq, pll); - - /* We always use the pll not the PCI clock on 372N */ + + printk(KERN_INFO "HPT3xxN detected, FREQ: %d, PLL: %d\n", freq, pll); } else { @@ -1197,41 +1084,22 @@ static void __devinit hpt37x_clocking(ide_hwif_t *hwif) pll = F_LOW_PCI_66; if (pll == F_LOW_PCI_33) { - if (info->revision >= 8) - info->speed = thirty_three_base_hpt374; - else if (info->revision >= 5) - info->speed = thirty_three_base_hpt372; - else if (info->revision >= 4) - info->speed = thirty_three_base_hpt370a; - else - info->speed = thirty_three_base_hpt370; + info->speed = thirty_three_base_hpt37x; printk(KERN_DEBUG "HPT37X: using 33MHz PCI clock\n"); } else if (pll == F_LOW_PCI_40) { /* Unsupported */ } else if (pll == F_LOW_PCI_50) { - if (info->revision >= 8) - info->speed = fifty_base_hpt370a; - else if (info->revision >= 5) - info->speed = fifty_base_hpt372; - else if (info->revision >= 4) - info->speed = fifty_base_hpt370a; - else - info->speed = fifty_base_hpt370a; + info->speed = fifty_base_hpt37x; printk(KERN_DEBUG "HPT37X: using 50MHz PCI clock\n"); } else { - if (info->revision >= 8) { - printk(KERN_ERR "HPT37x: 66MHz timings are not supported.\n"); - } - else if (info->revision >= 5) - info->speed = sixty_six_base_hpt372; - else if (info->revision >= 4) - info->speed = sixty_six_base_hpt370a; - else - info->speed = sixty_six_base_hpt370; + info->speed = sixty_six_base_hpt37x; printk(KERN_DEBUG "HPT37X: using 66MHz PCI clock\n"); } } - + + if (pll == F_LOW_PCI_66) + info->flags |= PCI_66MHZ; + /* * only try the pll if we don't have a table for the clock * speed that we're running at. NOTE: the internal PLL will @@ -1248,11 +1116,8 @@ static void __devinit hpt37x_clocking(ide_hwif_t *hwif) info->flags |= PLL_MODE; /* - * FIXME: make this work correctly, esp with 372N as per - * reference driver code. - * - * adjust PLL based upon PCI clock, enable it, and wait for - * stabilization. + * Adjust the PLL based upon the PCI clock, enable it, and + * wait for stabilization... */ adjust = 0; freq = (pll < F_LOW_PCI_50) ? 2 : 4; @@ -1275,22 +1140,12 @@ static void __devinit hpt37x_clocking(ide_hwif_t *hwif) pci_write_config_dword(dev, 0x5c, pll & ~0x100); pci_write_config_byte(dev, 0x5b, 0x21); - if (info->revision >= 8) - info->speed = fifty_base_hpt370a; - else if (info->revision >= 5) - info->speed = fifty_base_hpt372; - else if (info->revision >= 4) - info->speed = fifty_base_hpt370a; - else - info->speed = fifty_base_hpt370a; + + info->speed = fifty_base_hpt37x; printk("HPT37X: using 50MHz internal PLL\n"); goto init_hpt37X_done; } } - if (!pci_get_drvdata(dev)) { - printk("No Clock Stabilization!!!\n"); - return; - } pll_recal: if (adjust & 1) pll -= (adjust >> 1); @@ -1300,11 +1155,16 @@ pll_recal: init_hpt37X_done: if (!info->speed) - printk(KERN_ERR "HPT37X%s: unknown bus timing [%d %d].\n", - (info->flags & IS_372N)?"N":"", pll, freq); - /* reset state engine */ - pci_write_config_byte(dev, 0x50, 0x37); - pci_write_config_byte(dev, 0x54, 0x37); + printk(KERN_ERR "HPT37x%s: unknown bus timing [%d %d].\n", + (info->flags & IS_3xxN) ? "N" : "", pll, freq); + /* + * Reset the state engines. + * NOTE: avoid accidentally enabling the primary channel on HPT371N. + */ + pci_read_config_byte(dev, 0x50, &mcr1); + if (mcr1 & 0x04) + pci_write_config_byte(dev, 0x50, 0x37); + pci_write_config_byte(dev, 0x54, 0x37); udelay(100); } @@ -1367,6 +1227,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) struct pci_dev *dev = hwif->pci_dev; struct hpt_info *info = ide_get_hwifdata(hwif); u8 ata66 = 0, regmask = (hwif->channel) ? 0x01 : 0x02; + int serialize = HPT_SERIALIZE_IO; hwif->tuneproc = &hpt3xx_tune_drive; hwif->speedproc = &hpt3xx_tune_chipset; @@ -1374,8 +1235,20 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) hwif->intrproc = &hpt3xx_intrproc; hwif->maskproc = &hpt3xx_maskproc; - if(info->flags & IS_372N) - hwif->rw_disk = &hpt372n_rw_disk; + /* + * HPT3xxN chips have some complications: + * + * - on 33 MHz PCI we must clock switch + * - on 66 MHz PCI we must NOT use the PCI clock + */ + if ((info->flags & (IS_3xxN | PCI_66MHZ)) == IS_3xxN) { + /* + * Clock is shared between the channels, + * so we'll have to serialize them... :-( + */ + serialize = 1; + hwif->rw_disk = &hpt3xxn_rw_disk; + } /* * The HPT37x uses the CBLID pins as outputs for MA15/MA16 @@ -1418,29 +1291,15 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) PCI_FUNC(hwif->pci_dev->devfn)); #endif /* DEBUG */ -#ifdef HPT_SERIALIZE_IO - /* serialize access to this device */ - if (hwif->mate) + /* Serialize access to this device */ + if (serialize && hwif->mate) hwif->serialized = hwif->mate->serialized = 1; -#endif - if (info->revision >= 3) { - u8 reg5ah = 0; - pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10); - /* - * set up ioctl for power status. - * note: power affects both - * drives on each channel - */ - hwif->resetproc = &hpt3xx_reset; - hwif->busproc = &hpt370_busproc; - } else if (info->revision >= 2) { - hwif->resetproc = &hpt3xx_reset; - hwif->busproc = &hpt3xx_tristate; - } else { - hwif->resetproc = &hpt3xx_reset; - hwif->busproc = &hpt3xx_tristate; - } + /* + * Set up ioctl for power status. + * NOTE: power affects both drives on each channel. + */ + hwif->busproc = &hpt3xx_busproc; if (!hwif->dma_base) { hwif->drives[0].autotune = 1; @@ -1490,7 +1349,7 @@ static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase) return; if(info->speed == NULL) { - printk(KERN_WARNING "hpt: no known IDE timings, disabling DMA.\n"); + printk(KERN_WARNING "hpt366: no known IDE timings, disabling DMA.\n"); return; } @@ -1519,9 +1378,10 @@ static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase) static void __devinit init_iops_hpt366(ide_hwif_t *hwif) { - struct hpt_info *info = kzalloc(sizeof(struct hpt_info), GFP_KERNEL); - unsigned long dmabase = pci_resource_start(hwif->pci_dev, 4); - u8 did, rid; + struct hpt_info *info = kzalloc(sizeof(struct hpt_info), GFP_KERNEL); + struct pci_dev *dev = hwif->pci_dev; + u16 did = dev->device; + u8 rid = 0; if(info == NULL) { printk(KERN_WARNING "hpt366: out of memory.\n"); @@ -1529,15 +1389,22 @@ static void __devinit init_iops_hpt366(ide_hwif_t *hwif) } ide_set_hwifdata(hwif, info); - if(dmabase) { - did = inb(dmabase + 0x22); - rid = inb(dmabase + 0x28); - - if((did == 4 && rid == 6) || (did == 5 && rid > 1)) - info->flags |= IS_372N; + /* Avoid doing the same thing twice. */ + if (hwif->channel && hwif->mate) { + memcpy(info, ide_get_hwifdata(hwif->mate), sizeof(struct hpt_info)); + return; } - info->revision = hpt_revision(hwif->pci_dev); + pci_read_config_byte(dev, PCI_CLASS_REVISION, &rid); + + if (( did == PCI_DEVICE_ID_TTI_HPT366 && rid == 6) || + ((did == PCI_DEVICE_ID_TTI_HPT372 || + did == PCI_DEVICE_ID_TTI_HPT302 || + did == PCI_DEVICE_ID_TTI_HPT371) && rid > 1) || + did == PCI_DEVICE_ID_TTI_HPT372N) + info->flags |= IS_3xxN; + + info->revision = hpt_revision(dev); if (info->revision >= 3) hpt37x_clocking(hwif); @@ -1574,6 +1441,23 @@ static int __devinit init_setup_hpt37x(struct pci_dev *dev, ide_pci_device_t *d) return ide_setup_pci_device(dev, d); } +static int __devinit init_setup_hpt371(struct pci_dev *dev, ide_pci_device_t *d) +{ + u8 mcr1 = 0; + + /* + * HPT371 chips physically have only one channel, the secondary one, + * but the primary channel registers do exist! Go figure... + * So, we manually disable the non-existing channel here + * (if the BIOS hasn't done this already). + */ + pci_read_config_byte(dev, 0x50, &mcr1); + if (mcr1 & 0x04) + pci_write_config_byte(dev, 0x50, (mcr1 & ~0x04)); + + return ide_setup_pci_device(dev, d); +} + static int __devinit init_setup_hpt366(struct pci_dev *dev, ide_pci_device_t *d) { struct pci_dev *findev = NULL; @@ -1661,13 +1545,14 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = { .bootable = OFF_BOARD, },{ /* 3 */ .name = "HPT371", - .init_setup = init_setup_hpt37x, + .init_setup = init_setup_hpt371, .init_chipset = init_chipset_hpt366, .init_iops = init_iops_hpt366, .init_hwif = init_hwif_hpt366, .init_dma = init_dma_hpt366, .channels = 2, .autodma = AUTODMA, + .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, .bootable = OFF_BOARD, },{ /* 4 */ .name = "HPT374", @@ -1699,13 +1584,16 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = { * * Called when the PCI registration layer (or the IDE initialization) * finds a device matching our IDE device tables. + * + * NOTE: since we'll have to modify some fields of the ide_pci_device_t + * structure depending on the chip's revision, we'd better pass a local + * copy down the call chain... */ - static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id) { - ide_pci_device_t *d = &hpt366_chipsets[id->driver_data]; + ide_pci_device_t d = hpt366_chipsets[id->driver_data]; - return d->init_setup(dev, d); + return d.init_setup(dev, &d); } static struct pci_device_id hpt366_pci_tbl[] = { diff --git a/drivers/input/keyboard/hilkbd.c b/drivers/input/keyboard/hilkbd.c index 54bc569db4b0..35461eab2faf 100644 --- a/drivers/input/keyboard/hilkbd.c +++ b/drivers/input/keyboard/hilkbd.c @@ -23,7 +23,12 @@ #include <linux/init.h> #include <linux/interrupt.h> #include <linux/hil.h> +#include <linux/io.h> #include <linux/spinlock.h> +#include <asm/irq.h> +#ifdef CONFIG_HP300 +#include <asm/hwtest.h> +#endif MODULE_AUTHOR("Philip Blundell, Matthew Wilcox, Helge Deller"); diff --git a/drivers/isdn/act2000/act2000_isa.c b/drivers/isdn/act2000/act2000_isa.c index 3cac23739344..09ea50dd3459 100644 --- a/drivers/isdn/act2000/act2000_isa.c +++ b/drivers/isdn/act2000/act2000_isa.c @@ -408,7 +408,7 @@ act2000_isa_download(act2000_card * card, act2000_ddef __user * cb) p = cblock.buffer; if (!access_ok(VERIFY_READ, p, length)) return -EFAULT; - buf = (u_char *) kmalloc(1024, GFP_KERNEL); + buf = kmalloc(1024, GFP_KERNEL); if (!buf) return -ENOMEM; timeout = 0; diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c index 097bfa7bc323..c4d438c17dab 100644 --- a/drivers/isdn/capi/capidrv.c +++ b/drivers/isdn/capi/capidrv.c @@ -2013,7 +2013,7 @@ static int capidrv_addcontr(u16 contr, struct capi_profile *profp) strcpy(card->name, id); card->contrnr = contr; card->nbchan = profp->nbchannel; - card->bchans = (capidrv_bchan *) kmalloc(sizeof(capidrv_bchan) * card->nbchan, GFP_ATOMIC); + card->bchans = kmalloc(sizeof(capidrv_bchan) * card->nbchan, GFP_ATOMIC); if (!card->bchans) { printk(KERN_WARNING "capidrv: (%s) Could not allocate bchan-structs.\n", id); diff --git a/drivers/isdn/divert/divert_procfs.c b/drivers/isdn/divert/divert_procfs.c index 399b316111f7..06967da7c4a8 100644 --- a/drivers/isdn/divert/divert_procfs.c +++ b/drivers/isdn/divert/divert_procfs.c @@ -45,7 +45,7 @@ put_info_buffer(char *cp) return; if (!*cp) return; - if (!(ib = (struct divert_info *) kmalloc(sizeof(struct divert_info) + strlen(cp), GFP_ATOMIC))) + if (!(ib = kmalloc(sizeof(struct divert_info) + strlen(cp), GFP_ATOMIC))) return; /* no memory */ strcpy(ib->info_start, cp); /* set output string */ ib->next = NULL; diff --git a/drivers/isdn/divert/isdn_divert.c b/drivers/isdn/divert/isdn_divert.c index 03319ea5aa0c..7d97d54588d9 100644 --- a/drivers/isdn/divert/isdn_divert.c +++ b/drivers/isdn/divert/isdn_divert.c @@ -153,7 +153,7 @@ int cf_command(int drvid, int mode, *ielenp = p - ielenp - 1; /* set total IE length */ /* allocate mem for information struct */ - if (!(cs = (struct call_struc *) kmalloc(sizeof(struct call_struc), GFP_ATOMIC))) + if (!(cs = kmalloc(sizeof(struct call_struc), GFP_ATOMIC))) return(-ENOMEM); /* no memory */ init_timer(&cs->timer); cs->info[0] = '\0'; @@ -276,7 +276,7 @@ int insertrule(int idx, divert_rule *newrule) { struct deflect_struc *ds,*ds1=NULL; unsigned long flags; - if (!(ds = (struct deflect_struc *) kmalloc(sizeof(struct deflect_struc), + if (!(ds = kmalloc(sizeof(struct deflect_struc), GFP_KERNEL))) return(-ENOMEM); /* no memory */ @@ -451,7 +451,7 @@ static int isdn_divert_icall(isdn_ctrl *ic) if (dv->rule.action == DEFLECT_PROCEED) if ((!if_used) || ((!extern_wait_max) && (!dv->rule.waittime))) return(0); /* no external deflection needed */ - if (!(cs = (struct call_struc *) kmalloc(sizeof(struct call_struc), GFP_ATOMIC))) + if (!(cs = kmalloc(sizeof(struct call_struc), GFP_ATOMIC))) return(0); /* no memory */ init_timer(&cs->timer); cs->info[0] = '\0'; diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c index 63b629b1cdb2..b5e7f9c7d74e 100644 --- a/drivers/isdn/gigaset/bas-gigaset.c +++ b/drivers/isdn/gigaset/bas-gigaset.c @@ -1853,20 +1853,24 @@ static int gigaset_write_cmd(struct cardstate *cs, { struct cmdbuf_t *cb; unsigned long flags; - int status; + int rc; gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ? DEBUG_TRANSCMD : DEBUG_LOCKCMD, "CMD Transmit", len, buf); - if (len <= 0) - return 0; /* nothing to do */ + if (len <= 0) { + /* nothing to do */ + rc = 0; + goto notqueued; + } if (len > IF_WRITEBUF) len = IF_WRITEBUF; if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) { dev_err(cs->dev, "%s: out of memory\n", __func__); - return -ENOMEM; + rc = -ENOMEM; + goto notqueued; } memcpy(cb->buf, buf, len); @@ -1891,11 +1895,21 @@ static int gigaset_write_cmd(struct cardstate *cs, if (unlikely(!cs->connected)) { spin_unlock_irqrestore(&cs->lock, flags); gig_dbg(DEBUG_USBREQ, "%s: not connected", __func__); + /* flush command queue */ + spin_lock_irqsave(&cs->cmdlock, flags); + while (cs->cmdbuf != NULL) + complete_cb(cs); + spin_unlock_irqrestore(&cs->cmdlock, flags); return -ENODEV; } - status = start_cbsend(cs); + rc = start_cbsend(cs); spin_unlock_irqrestore(&cs->lock, flags); - return status < 0 ? status : len; + return rc < 0 ? rc : len; + +notqueued: /* request handled without queuing */ + if (wake_tasklet) + tasklet_schedule(wake_tasklet); + return rc; } /* gigaset_write_room @@ -1964,20 +1978,15 @@ static int gigaset_freebcshw(struct bc_state *bcs) /* kill URBs and tasklets before freeing - better safe than sorry */ atomic_set(&ubc->running, 0); - for (i = 0; i < BAS_OUTURBS; ++i) - if (ubc->isoouturbs[i].urb) { - gig_dbg(DEBUG_INIT, "%s: killing iso out URB %d", - __func__, i); - usb_kill_urb(ubc->isoouturbs[i].urb); - usb_free_urb(ubc->isoouturbs[i].urb); - } - for (i = 0; i < BAS_INURBS; ++i) - if (ubc->isoinurbs[i]) { - gig_dbg(DEBUG_INIT, "%s: killing iso in URB %d", - __func__, i); - usb_kill_urb(ubc->isoinurbs[i]); - usb_free_urb(ubc->isoinurbs[i]); - } + gig_dbg(DEBUG_INIT, "%s: killing iso URBs", __func__); + for (i = 0; i < BAS_OUTURBS; ++i) { + usb_kill_urb(ubc->isoouturbs[i].urb); + usb_free_urb(ubc->isoouturbs[i].urb); + } + for (i = 0; i < BAS_INURBS; ++i) { + usb_kill_urb(ubc->isoinurbs[i]); + usb_free_urb(ubc->isoinurbs[i]); + } tasklet_kill(&ubc->sent_tasklet); tasklet_kill(&ubc->rcvd_tasklet); kfree(ubc->isooutbuf); @@ -2099,55 +2108,32 @@ static void freeurbs(struct cardstate *cs) struct bas_bc_state *ubc; int i, j; + gig_dbg(DEBUG_INIT, "%s: killing URBs", __func__); for (j = 0; j < 2; ++j) { ubc = cs->bcs[j].hw.bas; - for (i = 0; i < BAS_OUTURBS; ++i) - if (ubc->isoouturbs[i].urb) { - usb_kill_urb(ubc->isoouturbs[i].urb); - gig_dbg(DEBUG_INIT, - "%s: isoc output URB %d/%d unlinked", - __func__, j, i); - usb_free_urb(ubc->isoouturbs[i].urb); - ubc->isoouturbs[i].urb = NULL; - } - for (i = 0; i < BAS_INURBS; ++i) - if (ubc->isoinurbs[i]) { - usb_kill_urb(ubc->isoinurbs[i]); - gig_dbg(DEBUG_INIT, - "%s: isoc input URB %d/%d unlinked", - __func__, j, i); - usb_free_urb(ubc->isoinurbs[i]); - ubc->isoinurbs[i] = NULL; - } - } - if (ucs->urb_int_in) { - usb_kill_urb(ucs->urb_int_in); - gig_dbg(DEBUG_INIT, "%s: interrupt input URB unlinked", - __func__); - usb_free_urb(ucs->urb_int_in); - ucs->urb_int_in = NULL; - } - if (ucs->urb_cmd_out) { - usb_kill_urb(ucs->urb_cmd_out); - gig_dbg(DEBUG_INIT, "%s: command output URB unlinked", - __func__); - usb_free_urb(ucs->urb_cmd_out); - ucs->urb_cmd_out = NULL; - } - if (ucs->urb_cmd_in) { - usb_kill_urb(ucs->urb_cmd_in); - gig_dbg(DEBUG_INIT, "%s: command input URB unlinked", - __func__); - usb_free_urb(ucs->urb_cmd_in); - ucs->urb_cmd_in = NULL; - } - if (ucs->urb_ctrl) { - usb_kill_urb(ucs->urb_ctrl); - gig_dbg(DEBUG_INIT, "%s: control output URB unlinked", - __func__); - usb_free_urb(ucs->urb_ctrl); - ucs->urb_ctrl = NULL; + for (i = 0; i < BAS_OUTURBS; ++i) { + usb_kill_urb(ubc->isoouturbs[i].urb); + usb_free_urb(ubc->isoouturbs[i].urb); + ubc->isoouturbs[i].urb = NULL; + } + for (i = 0; i < BAS_INURBS; ++i) { + usb_kill_urb(ubc->isoinurbs[i]); + usb_free_urb(ubc->isoinurbs[i]); + ubc->isoinurbs[i] = NULL; + } } + usb_kill_urb(ucs->urb_int_in); + usb_free_urb(ucs->urb_int_in); + ucs->urb_int_in = NULL; + usb_kill_urb(ucs->urb_cmd_out); + usb_free_urb(ucs->urb_cmd_out); + ucs->urb_cmd_out = NULL; + usb_kill_urb(ucs->urb_cmd_in); + usb_free_urb(ucs->urb_cmd_in); + ucs->urb_cmd_in = NULL; + usb_kill_urb(ucs->urb_ctrl); + usb_free_urb(ucs->urb_ctrl); + ucs->urb_ctrl = NULL; } /* gigaset_probe diff --git a/drivers/isdn/hysdn/hysdn_procconf.c b/drivers/isdn/hysdn/hysdn_procconf.c index 8e2b03889f3c..94a935089119 100644 --- a/drivers/isdn/hysdn/hysdn_procconf.c +++ b/drivers/isdn/hysdn/hysdn_procconf.c @@ -275,7 +275,7 @@ hysdn_conf_open(struct inode *ino, struct file *filep) } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { /* read access -> output card info data */ - if (!(tmp = (char *) kmalloc(INFO_OUT_LEN * 2 + 2, GFP_KERNEL))) { + if (!(tmp = kmalloc(INFO_OUT_LEN * 2 + 2, GFP_KERNEL))) { unlock_kernel(); return (-EFAULT); /* out of memory */ } diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c index f241f5e551cb..375d956884d7 100644 --- a/drivers/isdn/hysdn/hysdn_proclog.c +++ b/drivers/isdn/hysdn/hysdn_proclog.c @@ -111,7 +111,7 @@ put_log_buffer(hysdn_card * card, char *cp) if (pd->if_used <= 0) return; /* no open file for read */ - if (!(ib = (struct log_data *) kmalloc(sizeof(struct log_data) + strlen(cp), GFP_ATOMIC))) + if (!(ib = kmalloc(sizeof(struct log_data) + strlen(cp), GFP_ATOMIC))) return; /* no memory */ strcpy(ib->log_start, cp); /* set output string */ ib->next = NULL; diff --git a/drivers/isdn/i4l/isdn_audio.c b/drivers/isdn/i4l/isdn_audio.c index 2cc56d6a9fae..fb350c567c6b 100644 --- a/drivers/isdn/i4l/isdn_audio.c +++ b/drivers/isdn/i4l/isdn_audio.c @@ -328,7 +328,7 @@ adpcm_state * isdn_audio_adpcm_init(adpcm_state * s, int nbits) { if (!s) - s = (adpcm_state *) kmalloc(sizeof(adpcm_state), GFP_ATOMIC); + s = kmalloc(sizeof(adpcm_state), GFP_ATOMIC); if (s) { s->a = 0; s->d = 5; @@ -343,7 +343,7 @@ dtmf_state * isdn_audio_dtmf_init(dtmf_state * s) { if (!s) - s = (dtmf_state *) kmalloc(sizeof(dtmf_state), GFP_ATOMIC); + s = kmalloc(sizeof(dtmf_state), GFP_ATOMIC); if (s) { s->idx = 0; s->last = ' '; @@ -621,7 +621,7 @@ silence_state * isdn_audio_silence_init(silence_state * s) { if (!s) - s = (silence_state *) kmalloc(sizeof(silence_state), GFP_ATOMIC); + s = kmalloc(sizeof(silence_state), GFP_ATOMIC); if (s) { s->idx = 0; s->state = 0; diff --git a/drivers/isdn/i4l/isdn_net.c b/drivers/isdn/i4l/isdn_net.c index c36c817578cb..838b3734e2b6 100644 --- a/drivers/isdn/i4l/isdn_net.c +++ b/drivers/isdn/i4l/isdn_net.c @@ -2948,7 +2948,7 @@ isdn_net_addphone(isdn_net_ioctl_phone * phone) isdn_net_phone *n; if (p) { - if (!(n = (isdn_net_phone *) kmalloc(sizeof(isdn_net_phone), GFP_KERNEL))) + if (!(n = kmalloc(sizeof(isdn_net_phone), GFP_KERNEL))) return -ENOMEM; strcpy(n->num, phone->phone); n->next = p->local->phone[phone->outgoing & 1]; diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c index 43811795b46b..1726131b20be 100644 --- a/drivers/isdn/i4l/isdn_ppp.c +++ b/drivers/isdn/i4l/isdn_ppp.c @@ -717,7 +717,7 @@ isdn_ppp_fill_rq(unsigned char *buf, int len, int proto, int slot) printk(KERN_DEBUG "ippp: device not activated.\n"); return 0; } - nbuf = (unsigned char *) kmalloc(len + 4, GFP_ATOMIC); + nbuf = kmalloc(len + 4, GFP_ATOMIC); if (!nbuf) { printk(KERN_WARNING "ippp: Can't alloc buf\n"); return 0; diff --git a/drivers/isdn/pcbit/layer2.c b/drivers/isdn/pcbit/layer2.c index 6ff85574e941..eafcce5e656a 100644 --- a/drivers/isdn/pcbit/layer2.c +++ b/drivers/isdn/pcbit/layer2.c @@ -100,7 +100,7 @@ pcbit_l2_write(struct pcbit_dev *dev, ulong msg, ushort refnum, dev_kfree_skb(skb); return -1; } - if ((frame = (struct frame_buf *) kmalloc(sizeof(struct frame_buf), + if ((frame = kmalloc(sizeof(struct frame_buf), GFP_ATOMIC)) == NULL) { printk(KERN_WARNING "pcbit_2_write: kmalloc failed\n"); dev_kfree_skb(skb); diff --git a/drivers/kvm/Kconfig b/drivers/kvm/Kconfig index 36412e90f09b..703cc88d1ef9 100644 --- a/drivers/kvm/Kconfig +++ b/drivers/kvm/Kconfig @@ -1,6 +1,8 @@ # # KVM configuration # +menu "Virtualization" + config KVM tristate "Kernel-based Virtual Machine (KVM) support" depends on X86 && EXPERIMENTAL @@ -31,3 +33,5 @@ config KVM_AMD ---help--- Provides support for KVM on AMD processors equipped with the AMD-V (SVM) extensions. + +endmenu diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h index 5785d0870ab6..930e04ce1af6 100644 --- a/drivers/kvm/kvm.h +++ b/drivers/kvm/kvm.h @@ -140,7 +140,7 @@ enum { VCPU_REGS_RBP = 5, VCPU_REGS_RSI = 6, VCPU_REGS_RDI = 7, -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 VCPU_REGS_R8 = 8, VCPU_REGS_R9 = 9, VCPU_REGS_R10 = 10, @@ -375,7 +375,7 @@ void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr0); void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr0); void lmsw(struct kvm_vcpu *vcpu, unsigned long msw); -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 void set_efer(struct kvm_vcpu *vcpu, u64 efer); #endif @@ -485,7 +485,7 @@ static inline unsigned long read_tr_base(void) return segment_base(tr); } -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 static inline unsigned long read_msr(unsigned long msr) { u64 value; @@ -533,7 +533,7 @@ static inline u32 get_rdx_init_val(void) #define TSS_REDIRECTION_SIZE (256 / 8) #define RMODE_TSS_SIZE (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1) -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 /* * When emulating 32-bit mode, cr3 is only 32 bits even on x86_64. Therefore diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c index b6b8a41b5ec8..fd1bb870545c 100644 --- a/drivers/kvm/kvm_main.c +++ b/drivers/kvm/kvm_main.c @@ -72,18 +72,7 @@ static struct dentry *debugfs_dir; #define CR8_RESEVED_BITS (~0x0fULL) #define EFER_RESERVED_BITS 0xfffffffffffff2fe -struct vmx_msr_entry *find_msr_entry(struct kvm_vcpu *vcpu, u32 msr) -{ - int i; - - for (i = 0; i < vcpu->nmsrs; ++i) - if (vcpu->guest_msrs[i].index == msr) - return &vcpu->guest_msrs[i]; - return 0; -} -EXPORT_SYMBOL_GPL(find_msr_entry); - -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 // LDT or TSS descriptor in the GDT. 16 bytes. struct segment_descriptor_64 { struct segment_descriptor s; @@ -115,7 +104,7 @@ unsigned long segment_base(u16 selector) } d = (struct segment_descriptor *)(table_base + (selector & ~7)); v = d->base_low | ((ul)d->base_mid << 16) | ((ul)d->base_high << 24); -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 if (d->system == 0 && (d->type == 2 || d->type == 9 || d->type == 11)) v |= ((ul)((struct segment_descriptor_64 *)d)->base_higher) << 32; @@ -216,7 +205,6 @@ static struct kvm_vcpu *vcpu_load(struct kvm *kvm, int vcpu_slot) static void vcpu_put(struct kvm_vcpu *vcpu) { kvm_arch_ops->vcpu_put(vcpu); - put_cpu(); mutex_unlock(&vcpu->mutex); } @@ -351,7 +339,7 @@ void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) } if (!is_paging(vcpu) && (cr0 & CR0_PG_MASK)) { -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 if ((vcpu->shadow_efer & EFER_LME)) { int cs_db, cs_l; @@ -1120,12 +1108,10 @@ static int get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata) return kvm_arch_ops->get_msr(vcpu, msr_index, pdata); } -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 void set_efer(struct kvm_vcpu *vcpu, u64 efer) { - struct vmx_msr_entry *msr; - if (efer & EFER_RESERVED_BITS) { printk(KERN_DEBUG "set_efer: 0x%llx #GP, reserved bits\n", efer); @@ -1140,16 +1126,12 @@ void set_efer(struct kvm_vcpu *vcpu, u64 efer) return; } + kvm_arch_ops->set_efer(vcpu, efer); + efer &= ~EFER_LMA; efer |= vcpu->shadow_efer & EFER_LMA; vcpu->shadow_efer = efer; - - msr = find_msr_entry(vcpu, MSR_EFER); - - if (!(efer & EFER_LMA)) - efer &= ~EFER_LME; - msr->data = efer; } EXPORT_SYMBOL_GPL(set_efer); @@ -1243,7 +1225,7 @@ static int kvm_dev_ioctl_get_regs(struct kvm *kvm, struct kvm_regs *regs) regs->rdi = vcpu->regs[VCPU_REGS_RDI]; regs->rsp = vcpu->regs[VCPU_REGS_RSP]; regs->rbp = vcpu->regs[VCPU_REGS_RBP]; -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 regs->r8 = vcpu->regs[VCPU_REGS_R8]; regs->r9 = vcpu->regs[VCPU_REGS_R9]; regs->r10 = vcpu->regs[VCPU_REGS_R10]; @@ -1287,7 +1269,7 @@ static int kvm_dev_ioctl_set_regs(struct kvm *kvm, struct kvm_regs *regs) vcpu->regs[VCPU_REGS_RDI] = regs->rdi; vcpu->regs[VCPU_REGS_RSP] = regs->rsp; vcpu->regs[VCPU_REGS_RBP] = regs->rbp; -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 vcpu->regs[VCPU_REGS_R8] = regs->r8; vcpu->regs[VCPU_REGS_R9] = regs->r9; vcpu->regs[VCPU_REGS_R10] = regs->r10; @@ -1401,7 +1383,7 @@ static int kvm_dev_ioctl_set_sregs(struct kvm *kvm, struct kvm_sregs *sregs) vcpu->cr8 = sregs->cr8; mmu_reset_needed |= vcpu->shadow_efer != sregs->efer; -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 kvm_arch_ops->set_efer(vcpu, sregs->efer); #endif vcpu->apic_base = sregs->apic_base; @@ -1434,7 +1416,7 @@ static int kvm_dev_ioctl_set_sregs(struct kvm *kvm, struct kvm_sregs *sregs) static u32 msrs_to_save[] = { MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP, MSR_K6_STAR, -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR, #endif MSR_IA32_TIME_STAMP_COUNTER, diff --git a/drivers/kvm/kvm_svm.h b/drivers/kvm/kvm_svm.h index 7d7f2aa10960..74cc862f4935 100644 --- a/drivers/kvm/kvm_svm.h +++ b/drivers/kvm/kvm_svm.h @@ -9,7 +9,7 @@ #include "kvm.h" static const u32 host_save_msrs[] = { -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 MSR_STAR, MSR_LSTAR, MSR_CSTAR, MSR_SYSCALL_MASK, MSR_KERNEL_GS_BASE, MSR_FS_BASE, MSR_GS_BASE, #endif diff --git a/drivers/kvm/kvm_vmx.h b/drivers/kvm/kvm_vmx.h index 87e12d2bfa16..d139f73fb6e1 100644 --- a/drivers/kvm/kvm_vmx.h +++ b/drivers/kvm/kvm_vmx.h @@ -1,7 +1,7 @@ #ifndef __KVM_VMX_H #define __KVM_VMX_H -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 /* * avoid save/load MSR_SYSCALL_MASK and MSR_LSTAR by std vt * mechanism (cpu bug AA24) diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c index 4e29d9b7211c..3d367cbfe1f9 100644 --- a/drivers/kvm/mmu.c +++ b/drivers/kvm/mmu.c @@ -61,22 +61,9 @@ #define PT32_PTE_COPY_MASK \ - (PT_PRESENT_MASK | PT_PWT_MASK | PT_PCD_MASK | \ - PT_ACCESSED_MASK | PT_DIRTY_MASK | PT_PAT_MASK | \ - PT_GLOBAL_MASK ) - -#define PT32_NON_PTE_COPY_MASK \ - (PT_PRESENT_MASK | PT_PWT_MASK | PT_PCD_MASK | \ - PT_ACCESSED_MASK | PT_DIRTY_MASK) - - -#define PT64_PTE_COPY_MASK \ - (PT64_NX_MASK | PT32_PTE_COPY_MASK) - -#define PT64_NON_PTE_COPY_MASK \ - (PT64_NX_MASK | PT32_NON_PTE_COPY_MASK) - + (PT_PRESENT_MASK | PT_ACCESSED_MASK | PT_DIRTY_MASK | PT_GLOBAL_MASK) +#define PT64_PTE_COPY_MASK (PT64_NX_MASK | PT32_PTE_COPY_MASK) #define PT_FIRST_AVAIL_BITS_SHIFT 9 #define PT64_SECOND_AVAIL_BITS_SHIFT 52 diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h index 765c2e1a048e..a9771b4c5bb8 100644 --- a/drivers/kvm/paging_tmpl.h +++ b/drivers/kvm/paging_tmpl.h @@ -32,7 +32,6 @@ #define SHADOW_PT_INDEX(addr, level) PT64_INDEX(addr, level) #define PT_LEVEL_MASK(level) PT64_LEVEL_MASK(level) #define PT_PTE_COPY_MASK PT64_PTE_COPY_MASK - #define PT_NON_PTE_COPY_MASK PT64_NON_PTE_COPY_MASK #elif PTTYPE == 32 #define pt_element_t u32 #define guest_walker guest_walker32 @@ -43,7 +42,6 @@ #define SHADOW_PT_INDEX(addr, level) PT64_INDEX(addr, level) #define PT_LEVEL_MASK(level) PT32_LEVEL_MASK(level) #define PT_PTE_COPY_MASK PT32_PTE_COPY_MASK - #define PT_NON_PTE_COPY_MASK PT32_NON_PTE_COPY_MASK #else #error Invalid PTTYPE value #endif @@ -105,9 +103,7 @@ static void FNAME(set_pde)(struct kvm_vcpu *vcpu, u64 guest_pde, if (PTTYPE == 32 && is_cpuid_PSE36()) gaddr |= (guest_pde & PT32_DIR_PSE36_MASK) << (32 - PT32_DIR_PSE36_SHIFT); - *shadow_pte = (guest_pde & (PT_NON_PTE_COPY_MASK | PT_GLOBAL_MASK)) | - ((guest_pde & PT_DIR_PAT_MASK) >> - (PT_DIR_PAT_SHIFT - PT_PAT_SHIFT)); + *shadow_pte = guest_pde & PT_PTE_COPY_MASK; set_pte_common(vcpu, shadow_pte, gaddr, guest_pde & PT_DIRTY_MASK, access_bits); } @@ -162,6 +158,7 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr, u32 index = SHADOW_PT_INDEX(addr, level); u64 *shadow_ent = ((u64 *)__va(shadow_addr)) + index; pt_element_t *guest_ent; + u64 shadow_pte; if (is_present_pte(*shadow_ent) || is_io_pte(*shadow_ent)) { if (level == PT_PAGE_TABLE_LEVEL) @@ -204,14 +201,11 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr, shadow_addr = kvm_mmu_alloc_page(vcpu, shadow_ent); if (!VALID_PAGE(shadow_addr)) return ERR_PTR(-ENOMEM); - if (!kvm_arch_ops->is_long_mode(vcpu) && level == 3) - *shadow_ent = shadow_addr | - (*guest_ent & (PT_PRESENT_MASK | PT_PWT_MASK | PT_PCD_MASK)); - else { - *shadow_ent = shadow_addr | - (*guest_ent & PT_NON_PTE_COPY_MASK); - *shadow_ent |= (PT_WRITABLE_MASK | PT_USER_MASK); - } + shadow_pte = shadow_addr | PT_PRESENT_MASK; + if (vcpu->mmu.root_level > 3 || level != 3) + shadow_pte |= PT_ACCESSED_MASK + | PT_WRITABLE_MASK | PT_USER_MASK; + *shadow_ent = shadow_pte; prev_shadow_ent = shadow_ent; } } diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c index a33a89c68138..0e6bc8c649ce 100644 --- a/drivers/kvm/svm.c +++ b/drivers/kvm/svm.c @@ -287,7 +287,7 @@ static void svm_hardware_enable(void *garbage) struct svm_cpu_data *svm_data; uint64_t efer; -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 struct desc_ptr gdt_descr; #else struct Xgt_desc_struct gdt_descr; @@ -377,6 +377,7 @@ static __init int svm_hardware_setup(void) void *msrpm_va; int r; + kvm_emulator_want_group7_invlpg(); iopm_pages = alloc_pages(GFP_KERNEL, IOPM_ALLOC_ORDER); @@ -397,7 +398,7 @@ static __init int svm_hardware_setup(void) memset(msrpm_va, 0xff, PAGE_SIZE * (1 << MSRPM_ALLOC_ORDER)); msrpm_base = page_to_pfn(msrpm_pages) << PAGE_SHIFT; -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 set_msr_interception(msrpm_va, MSR_GS_BASE, 1, 1); set_msr_interception(msrpm_va, MSR_FS_BASE, 1, 1); set_msr_interception(msrpm_va, MSR_KERNEL_GS_BASE, 1, 1); @@ -704,7 +705,7 @@ static void svm_set_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt) static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) { -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 if (vcpu->shadow_efer & KVM_EFER_LME) { if (!is_paging(vcpu) && (cr0 & CR0_PG_MASK)) { vcpu->shadow_efer |= KVM_EFER_LMA; @@ -1097,7 +1098,7 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data) case MSR_IA32_APICBASE: *data = vcpu->apic_base; break; -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 case MSR_STAR: *data = vcpu->svm->vmcb->save.star; break; @@ -1149,7 +1150,7 @@ static int rdmsr_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data) { switch (ecx) { -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 case MSR_EFER: set_efer(vcpu, data); break; @@ -1172,7 +1173,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data) case MSR_IA32_APICBASE: vcpu->apic_base = data; break; -#ifdef __x86_64___ +#ifdef CONFIG_X86_64_ case MSR_STAR: vcpu->svm->vmcb->save.star = data; break; @@ -1345,53 +1346,18 @@ static void kvm_reput_irq(struct kvm_vcpu *vcpu) static void save_db_regs(unsigned long *db_regs) { -#ifdef __x86_64__ - asm ("mov %%dr0, %%rax \n\t" - "mov %%rax, %[dr0] \n\t" - "mov %%dr1, %%rax \n\t" - "mov %%rax, %[dr1] \n\t" - "mov %%dr2, %%rax \n\t" - "mov %%rax, %[dr2] \n\t" - "mov %%dr3, %%rax \n\t" - "mov %%rax, %[dr3] \n\t" - : [dr0] "=m"(db_regs[0]), - [dr1] "=m"(db_regs[1]), - [dr2] "=m"(db_regs[2]), - [dr3] "=m"(db_regs[3]) - : : "rax"); -#else - asm ("mov %%dr0, %%eax \n\t" - "mov %%eax, %[dr0] \n\t" - "mov %%dr1, %%eax \n\t" - "mov %%eax, %[dr1] \n\t" - "mov %%dr2, %%eax \n\t" - "mov %%eax, %[dr2] \n\t" - "mov %%dr3, %%eax \n\t" - "mov %%eax, %[dr3] \n\t" - : [dr0] "=m"(db_regs[0]), - [dr1] "=m"(db_regs[1]), - [dr2] "=m"(db_regs[2]), - [dr3] "=m"(db_regs[3]) - : : "eax"); -#endif + asm volatile ("mov %%dr0, %0" : "=r"(db_regs[0])); + asm volatile ("mov %%dr1, %0" : "=r"(db_regs[1])); + asm volatile ("mov %%dr2, %0" : "=r"(db_regs[2])); + asm volatile ("mov %%dr3, %0" : "=r"(db_regs[3])); } static void load_db_regs(unsigned long *db_regs) { - asm volatile ("mov %[dr0], %%dr0 \n\t" - "mov %[dr1], %%dr1 \n\t" - "mov %[dr2], %%dr2 \n\t" - "mov %[dr3], %%dr3 \n\t" - : - : [dr0] "r"(db_regs[0]), - [dr1] "r"(db_regs[1]), - [dr2] "r"(db_regs[2]), - [dr3] "r"(db_regs[3]) -#ifdef __x86_64__ - : "rax"); -#else - : "eax"); -#endif + asm volatile ("mov %0, %%dr0" : : "r"(db_regs[0])); + asm volatile ("mov %0, %%dr1" : : "r"(db_regs[1])); + asm volatile ("mov %0, %%dr2" : : "r"(db_regs[2])); + asm volatile ("mov %0, %%dr3" : : "r"(db_regs[3])); } static int svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) @@ -1422,7 +1388,7 @@ again: load_db_regs(vcpu->svm->db_regs); } asm volatile ( -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 "push %%rbx; push %%rcx; push %%rdx;" "push %%rsi; push %%rdi; push %%rbp;" "push %%r8; push %%r9; push %%r10; push %%r11;" @@ -1432,7 +1398,7 @@ again: "push %%esi; push %%edi; push %%ebp;" #endif -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 "mov %c[rbx](%[vcpu]), %%rbx \n\t" "mov %c[rcx](%[vcpu]), %%rcx \n\t" "mov %c[rdx](%[vcpu]), %%rdx \n\t" @@ -1456,7 +1422,7 @@ again: "mov %c[rbp](%[vcpu]), %%ebp \n\t" #endif -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 /* Enter guest mode */ "push %%rax \n\t" "mov %c[svm](%[vcpu]), %%rax \n\t" @@ -1477,7 +1443,7 @@ again: #endif /* Save guest registers, load host registers */ -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 "mov %%rbx, %c[rbx](%[vcpu]) \n\t" "mov %%rcx, %c[rcx](%[vcpu]) \n\t" "mov %%rdx, %c[rdx](%[vcpu]) \n\t" @@ -1518,7 +1484,7 @@ again: [rsi]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RSI])), [rdi]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RDI])), [rbp]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RBP])) -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 ,[r8 ]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R8 ])), [r9 ]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R9 ])), [r10]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R10])), @@ -1663,9 +1629,7 @@ static struct kvm_arch_ops svm_arch_ops = { static int __init svm_init(void) { - kvm_emulator_want_group7_invlpg(); - kvm_init_arch(&svm_arch_ops, THIS_MODULE); - return 0; + return kvm_init_arch(&svm_arch_ops, THIS_MODULE); } static void __exit svm_exit(void) diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c index bda7a7ae2167..f0f0b1a781f8 100644 --- a/drivers/kvm/vmx.c +++ b/drivers/kvm/vmx.c @@ -22,6 +22,7 @@ #include <linux/mm.h> #include <linux/highmem.h> #include <asm/io.h> +#include <asm/desc.h> #include "segment_descriptor.h" @@ -33,7 +34,7 @@ MODULE_LICENSE("GPL"); static DEFINE_PER_CPU(struct vmcs *, vmxarea); static DEFINE_PER_CPU(struct vmcs *, current_vmcs); -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 #define HOST_IS_64 1 #else #define HOST_IS_64 0 @@ -70,15 +71,13 @@ static struct kvm_vmx_segment_field { }; static const u32 vmx_msr_index[] = { -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 MSR_SYSCALL_MASK, MSR_LSTAR, MSR_CSTAR, MSR_KERNEL_GS_BASE, #endif MSR_EFER, MSR_K6_STAR, }; #define NR_VMX_MSR (sizeof(vmx_msr_index) / sizeof(*vmx_msr_index)) -struct vmx_msr_entry *find_msr_entry(struct kvm_vcpu *vcpu, u32 msr); - static inline int is_page_fault(u32 intr_info) { return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK | @@ -92,6 +91,16 @@ static inline int is_external_interrupt(u32 intr_info) == (INTR_TYPE_EXT_INTR | INTR_INFO_VALID_MASK); } +static struct vmx_msr_entry *find_msr_entry(struct kvm_vcpu *vcpu, u32 msr) +{ + int i; + + for (i = 0; i < vcpu->nmsrs; ++i) + if (vcpu->guest_msrs[i].index == msr) + return &vcpu->guest_msrs[i]; + return 0; +} + static void vmcs_clear(struct vmcs *vmcs) { u64 phys_addr = __pa(vmcs); @@ -137,7 +146,7 @@ static u32 vmcs_read32(unsigned long field) static u64 vmcs_read64(unsigned long field) { -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 return vmcs_readl(field); #else return vmcs_readl(field) | ((u64)vmcs_readl(field+1) << 32); @@ -167,7 +176,7 @@ static void vmcs_write32(unsigned long field, u32 value) static void vmcs_write64(unsigned long field, u64 value) { -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 vmcs_writel(field, value); #else vmcs_writel(field, value); @@ -296,7 +305,7 @@ static void guest_write_tsc(u64 guest_tsc) static void reload_tss(void) { -#ifndef __x86_64__ +#ifndef CONFIG_X86_64 /* * VT restores TR but not its size. Useless. @@ -327,7 +336,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata) } switch (msr_index) { -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 case MSR_FS_BASE: data = vmcs_readl(GUEST_FS_BASE); break; @@ -390,7 +399,7 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data) { struct vmx_msr_entry *msr; switch (msr_index) { -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 case MSR_FS_BASE: vmcs_writel(GUEST_FS_BASE, data); break; @@ -525,7 +534,7 @@ static __init void hardware_enable(void *garbage) u64 old; rdmsrl(MSR_IA32_FEATURE_CONTROL, old); - if ((old & 5) == 0) + if ((old & 5) != 5) /* enable and lock */ wrmsrl(MSR_IA32_FEATURE_CONTROL, old | 5); write_cr4(read_cr4() | CR4_VMXE); /* FIXME: not cpu hotplug safe */ @@ -725,7 +734,7 @@ static void enter_rmode(struct kvm_vcpu *vcpu) fix_rmode_seg(VCPU_SREG_FS, &vcpu->rmode.fs); } -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 static void enter_lmode(struct kvm_vcpu *vcpu) { @@ -767,7 +776,7 @@ static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) if (!vcpu->rmode.active && !(cr0 & CR0_PE_MASK)) enter_rmode(vcpu); -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 if (vcpu->shadow_efer & EFER_LME) { if (!is_paging(vcpu) && (cr0 & CR0_PG_MASK)) enter_lmode(vcpu); @@ -808,7 +817,7 @@ static void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) vcpu->cr4 = cr4; } -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 static void vmx_set_efer(struct kvm_vcpu *vcpu, u64 efer) { @@ -883,6 +892,8 @@ static void vmx_set_segment(struct kvm_vcpu *vcpu, ar |= (var->db & 1) << 14; ar |= (var->g & 1) << 15; } + if (ar == 0) /* a 0 value means unusable */ + ar = AR_UNUSABLE_MASK; vmcs_write32(sf->ar_bytes, ar); } @@ -1095,7 +1106,7 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu) vmcs_write16(HOST_FS_SELECTOR, read_fs()); /* 22.2.4 */ vmcs_write16(HOST_GS_SELECTOR, read_gs()); /* 22.2.4 */ vmcs_write16(HOST_SS_SELECTOR, __KERNEL_DS); /* 22.2.4 */ -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 rdmsrl(MSR_FS_BASE, a); vmcs_writel(HOST_FS_BASE, a); /* 22.2.4 */ rdmsrl(MSR_GS_BASE, a); @@ -1164,8 +1175,10 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu) VM_ENTRY_CONTROLS, 0); vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); /* 22.2.1 */ +#ifdef CONFIG_X86_64 vmcs_writel(VIRTUAL_APIC_PAGE_ADDR, 0); vmcs_writel(TPR_THRESHOLD, 0); +#endif vmcs_writel(CR0_GUEST_HOST_MASK, KVM_GUEST_CR0_MASK); vmcs_writel(CR4_GUEST_HOST_MASK, KVM_GUEST_CR4_MASK); @@ -1173,7 +1186,7 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu) vcpu->cr0 = 0x60000010; vmx_set_cr0(vcpu, vcpu->cr0); // enter rmode vmx_set_cr4(vcpu, 0); -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 vmx_set_efer(vcpu, 0); #endif @@ -1689,7 +1702,7 @@ again: vmcs_write16(HOST_GS_SELECTOR, 0); } -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 vmcs_writel(HOST_FS_BASE, read_msr(MSR_FS_BASE)); vmcs_writel(HOST_GS_BASE, read_msr(MSR_GS_BASE)); #else @@ -1713,7 +1726,7 @@ again: asm ( /* Store host registers */ "pushf \n\t" -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 "push %%rax; push %%rbx; push %%rdx;" "push %%rsi; push %%rdi; push %%rbp;" "push %%r8; push %%r9; push %%r10; push %%r11;" @@ -1727,7 +1740,7 @@ again: /* Check if vmlaunch of vmresume is needed */ "cmp $0, %1 \n\t" /* Load guest registers. Don't clobber flags. */ -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 "mov %c[cr2](%3), %%rax \n\t" "mov %%rax, %%cr2 \n\t" "mov %c[rax](%3), %%rax \n\t" @@ -1764,7 +1777,7 @@ again: ".globl kvm_vmx_return \n\t" "kvm_vmx_return: " /* Save guest registers, load host registers, keep flags */ -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 "xchg %3, 0(%%rsp) \n\t" "mov %%rax, %c[rax](%3) \n\t" "mov %%rbx, %c[rbx](%3) \n\t" @@ -1816,7 +1829,7 @@ again: [rsi]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RSI])), [rdi]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RDI])), [rbp]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RBP])), -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 [r8 ]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R8 ])), [r9 ]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R9 ])), [r10]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R10])), @@ -1837,7 +1850,7 @@ again: fx_save(vcpu->guest_fx_image); fx_restore(vcpu->host_fx_image); -#ifndef __x86_64__ +#ifndef CONFIG_X86_64 asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS)); #endif @@ -1855,7 +1868,7 @@ again: */ local_irq_disable(); load_gs(gs_sel); -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 wrmsrl(MSR_GS_BASE, vmcs_readl(HOST_GS_BASE)); #endif local_irq_enable(); @@ -1965,7 +1978,7 @@ static struct kvm_arch_ops vmx_arch_ops = { .set_cr0_no_modeswitch = vmx_set_cr0_no_modeswitch, .set_cr3 = vmx_set_cr3, .set_cr4 = vmx_set_cr4, -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 .set_efer = vmx_set_efer, #endif .get_idt = vmx_get_idt, @@ -1989,8 +2002,7 @@ static struct kvm_arch_ops vmx_arch_ops = { static int __init vmx_init(void) { - kvm_init_arch(&vmx_arch_ops, THIS_MODULE); - return 0; + return kvm_init_arch(&vmx_arch_ops, THIS_MODULE); } static void __exit vmx_exit(void) diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c index 7e838bf0592d..1bff3e925fda 100644 --- a/drivers/kvm/x86_emulate.c +++ b/drivers/kvm/x86_emulate.c @@ -238,7 +238,7 @@ struct operand { * any modified flags. */ -#if defined(__x86_64__) +#if defined(CONFIG_X86_64) #define _LO32 "k" /* force 32-bit operand */ #define _STK "%%rsp" /* stack pointer */ #elif defined(__i386__) @@ -385,7 +385,7 @@ struct operand { } while (0) /* Emulate an instruction with quadword operands (x86/64 only). */ -#if defined(__x86_64__) +#if defined(CONFIG_X86_64) #define __emulate_2op_8byte(_op, _src, _dst, _eflags, _qx, _qy) \ do { \ __asm__ __volatile__ ( \ @@ -495,7 +495,7 @@ x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) case X86EMUL_MODE_PROT32: op_bytes = ad_bytes = 4; break; -#ifdef __x86_64__ +#ifdef CONFIG_X86_64 case X86EMUL_MODE_PROT64: op_bytes = 4; ad_bytes = 8; @@ -1341,7 +1341,7 @@ twobyte_special_insn: } break; } -#elif defined(__x86_64__) +#elif defined(CONFIG_X86_64) { unsigned long old, new; if ((rc = ops->read_emulated(cr2, &old, 8, ctxt)) != 0) diff --git a/drivers/kvm/x86_emulate.h b/drivers/kvm/x86_emulate.h index 658b58de30fc..5d41bd55125e 100644 --- a/drivers/kvm/x86_emulate.h +++ b/drivers/kvm/x86_emulate.h @@ -162,7 +162,7 @@ struct x86_emulate_ctxt { /* Host execution mode. */ #if defined(__i386__) #define X86EMUL_MODE_HOST X86EMUL_MODE_PROT32 -#elif defined(__x86_64__) +#elif defined(CONFIG_X86_64) #define X86EMUL_MODE_HOST X86EMUL_MODE_PROT64 #endif diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c index d43ea81d6df9..7cec6de5e2b0 100644 --- a/drivers/macintosh/adb.c +++ b/drivers/macintosh/adb.c @@ -828,7 +828,7 @@ static ssize_t adb_write(struct file *file, const char __user *buf, if (!access_ok(VERIFY_READ, buf, count)) return -EFAULT; - req = (struct adb_request *) kmalloc(sizeof(struct adb_request), + req = kmalloc(sizeof(struct adb_request), GFP_KERNEL); if (req == NULL) return -ENOMEM; diff --git a/drivers/macintosh/apm_emu.c b/drivers/macintosh/apm_emu.c index 8862a83b8d84..4300c628f8af 100644 --- a/drivers/macintosh/apm_emu.c +++ b/drivers/macintosh/apm_emu.c @@ -321,7 +321,7 @@ static int do_open(struct inode * inode, struct file * filp) { struct apm_user * as; - as = (struct apm_user *)kmalloc(sizeof(*as), GFP_KERNEL); + as = kmalloc(sizeof(*as), GFP_KERNEL); if (as == NULL) { printk(KERN_ERR "apm: cannot allocate struct of size %d bytes\n", sizeof(*as)); diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c index 6dde27ab79a8..6f30459b9385 100644 --- a/drivers/macintosh/smu.c +++ b/drivers/macintosh/smu.c @@ -945,7 +945,7 @@ static struct smu_sdbp_header *smu_create_sdb_partition(int id) */ tlen = sizeof(struct property) + len + 18; - prop = kcalloc(tlen, 1, GFP_KERNEL); + prop = kzalloc(tlen, GFP_KERNEL); if (prop == NULL) return NULL; hdr = (struct smu_sdbp_header *)(prop + 1); diff --git a/drivers/macintosh/via-pmu68k.c b/drivers/macintosh/via-pmu68k.c index d9986f3a3fbf..93e6ef9233f9 100644 --- a/drivers/macintosh/via-pmu68k.c +++ b/drivers/macintosh/via-pmu68k.c @@ -847,7 +847,7 @@ pbook_pci_save(void) n_pbook_pci_saves = npci; if (npci == 0) return; - ps = (struct pci_save *) kmalloc(npci * sizeof(*ps), GFP_KERNEL); + ps = kmalloc(npci * sizeof(*ps), GFP_KERNEL); pbook_pci_saves = ps; if (ps == NULL) return; diff --git a/drivers/md/faulty.c b/drivers/md/faulty.c index a7a5ab554338..4ebd0f2a75ec 100644 --- a/drivers/md/faulty.c +++ b/drivers/md/faulty.c @@ -173,7 +173,7 @@ static int make_request(request_queue_t *q, struct bio *bio) conf_t *conf = (conf_t*)mddev->private; int failit = 0; - if (bio->bi_rw & 1) { + if (bio_data_dir(bio) == WRITE) { /* write request */ if (atomic_read(&conf->counters[WriteAll])) { /* special case - don't decrement, don't generic_make_request, diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index b3c5e12f081d..b30f74be3982 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -1736,7 +1736,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i /* take from bio_init */ bio->bi_next = NULL; bio->bi_flags |= 1 << BIO_UPTODATE; - bio->bi_rw = 0; + bio->bi_rw = READ; bio->bi_vcnt = 0; bio->bi_idx = 0; bio->bi_phys_segments = 0; diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 7492d6033ac6..f0141910bb8d 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -1785,7 +1785,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i biolist = bio; bio->bi_private = r10_bio; bio->bi_end_io = end_sync_read; - bio->bi_rw = 0; + bio->bi_rw = READ; bio->bi_sector = r10_bio->devs[j].addr + conf->mirrors[d].rdev->data_offset; bio->bi_bdev = conf->mirrors[d].rdev->bdev; @@ -1801,7 +1801,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i biolist = bio; bio->bi_private = r10_bio; bio->bi_end_io = end_sync_write; - bio->bi_rw = 1; + bio->bi_rw = WRITE; bio->bi_sector = r10_bio->devs[k].addr + conf->mirrors[i].rdev->data_offset; bio->bi_bdev = conf->mirrors[i].rdev->bdev; @@ -1870,7 +1870,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i biolist = bio; bio->bi_private = r10_bio; bio->bi_end_io = end_sync_read; - bio->bi_rw = 0; + bio->bi_rw = READ; bio->bi_sector = r10_bio->devs[i].addr + conf->mirrors[d].rdev->data_offset; bio->bi_bdev = conf->mirrors[d].rdev->bdev; diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 377f8bc9b78b..be008f034ada 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -1827,16 +1827,16 @@ static void handle_stripe5(struct stripe_head *sh) struct bio *bi; mdk_rdev_t *rdev; if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) - rw = 1; + rw = WRITE; else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) - rw = 0; + rw = READ; else continue; bi = &sh->dev[i].req; bi->bi_rw = rw; - if (rw) + if (rw == WRITE) bi->bi_end_io = raid5_end_write_request; else bi->bi_end_io = raid5_end_read_request; @@ -1872,7 +1872,7 @@ static void handle_stripe5(struct stripe_head *sh) atomic_add(STRIPE_SECTORS, &rdev->corrected_errors); generic_make_request(bi); } else { - if (rw == 1) + if (rw == WRITE) set_bit(STRIPE_DEGRADED, &sh->state); PRINTK("skip op %ld on disc %d for sector %llu\n", bi->bi_rw, i, (unsigned long long)sh->sector); @@ -2370,16 +2370,16 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page) struct bio *bi; mdk_rdev_t *rdev; if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) - rw = 1; + rw = WRITE; else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) - rw = 0; + rw = READ; else continue; bi = &sh->dev[i].req; bi->bi_rw = rw; - if (rw) + if (rw == WRITE) bi->bi_end_io = raid5_end_write_request; else bi->bi_end_io = raid5_end_read_request; @@ -2415,7 +2415,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page) atomic_add(STRIPE_SECTORS, &rdev->corrected_errors); generic_make_request(bi); } else { - if (rw == 1) + if (rw == WRITE) set_bit(STRIPE_DEGRADED, &sh->state); PRINTK("skip op %ld on disc %d for sector %llu\n", bi->bi_rw, i, (unsigned long long)sh->sector); @@ -2567,7 +2567,7 @@ static int raid5_mergeable_bvec(request_queue_t *q, struct bio *bio, struct bio_ unsigned int chunk_sectors = mddev->chunk_size >> 9; unsigned int bio_sectors = bio->bi_size >> 9; - if (bio_data_dir(bio)) + if (bio_data_dir(bio) == WRITE) return biovec->bv_len; /* always allow writes to be mergeable */ max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9; @@ -2751,7 +2751,7 @@ static int make_request(request_queue_t *q, struct bio * bi) disk_stat_inc(mddev->gendisk, ios[rw]); disk_stat_add(mddev->gendisk, sectors[rw], bio_sectors(bi)); - if (bio_data_dir(bi) == READ && + if (rw == READ && mddev->reshape_position == MaxSector && chunk_aligned_read(q,bi)) return 0; diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c index 240ad084fa78..50bc32a8bd55 100644 --- a/drivers/media/dvb/bt8xx/dst_ca.c +++ b/drivers/media/dvb/bt8xx/dst_ca.c @@ -480,7 +480,7 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer; int result = 0; - if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { + if ((hw_buffer = kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure"); return -ENOMEM; } diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c index 80a85cb4975f..3e35931af35d 100644 --- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c +++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c @@ -657,7 +657,7 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type) case BTTV_BOARD_TWINHAN_DST: /* DST is not a frontend driver !!! */ - state = (struct dst_state *) kmalloc(sizeof (struct dst_state), GFP_KERNEL); + state = kmalloc(sizeof (struct dst_state), GFP_KERNEL); if (!state) { printk("dvb_bt8xx: No memory\n"); break; diff --git a/drivers/media/dvb/ttusb-dec/ttusbdecfe.c b/drivers/media/dvb/ttusb-dec/ttusbdecfe.c index 42f39a89bc4d..a6fb1d6a7b5d 100644 --- a/drivers/media/dvb/ttusb-dec/ttusbdecfe.c +++ b/drivers/media/dvb/ttusb-dec/ttusbdecfe.c @@ -195,7 +195,7 @@ struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* conf struct ttusbdecfe_state* state = NULL; /* allocate memory for the internal state */ - state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL); + state = kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL); if (state == NULL) return NULL; @@ -215,7 +215,7 @@ struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* conf struct ttusbdecfe_state* state = NULL; /* allocate memory for the internal state */ - state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL); + state = kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL); if (state == NULL) return NULL; diff --git a/drivers/media/video/dabusb.c b/drivers/media/video/dabusb.c index b1012e92ee04..917021fc2993 100644 --- a/drivers/media/video/dabusb.c +++ b/drivers/media/video/dabusb.c @@ -218,7 +218,7 @@ static int dabusb_alloc_buffers (pdabusb_t s) pipesize, packets, transfer_buffer_length); while (buffers < (s->total_buffer_size << 10)) { - b = (pbuff_t) kzalloc (sizeof (buff_t), GFP_KERNEL); + b = kzalloc(sizeof (buff_t), GFP_KERNEL); if (!b) { err("kzalloc(sizeof(buff_t))==NULL"); goto err; @@ -659,7 +659,7 @@ static int dabusb_ioctl (struct inode *inode, struct file *file, unsigned int cm switch (cmd) { case IOCTL_DAB_BULK: - pbulk = (pbulk_transfer_t) kmalloc (sizeof (bulk_transfer_t), GFP_KERNEL); + pbulk = kmalloc(sizeof (bulk_transfer_t), GFP_KERNEL); if (!pbulk) { ret = -ENOMEM; diff --git a/drivers/media/video/planb.c b/drivers/media/video/planb.c index 368d6e219fa4..86d2884e16c6 100644 --- a/drivers/media/video/planb.c +++ b/drivers/media/video/planb.c @@ -138,7 +138,7 @@ static int grabbuf_alloc(struct planb *pb) + MAX_LNUM #endif /* PLANB_GSCANLINE */ ); - if ((pb->rawbuf = (unsigned char**) kmalloc (npage + if ((pb->rawbuf = kmalloc(npage * sizeof(unsigned long), GFP_KERNEL)) == 0) return -ENOMEM; for (i = 0; i < npage; i++) { diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c index d8b88024bc2f..b560c9d7c516 100644 --- a/drivers/media/video/usbvideo/usbvideo.c +++ b/drivers/media/video/usbvideo/usbvideo.c @@ -690,7 +690,7 @@ int usbvideo_register( } base_size = num_cams * sizeof(struct uvd) + sizeof(struct usbvideo); - cams = (struct usbvideo *) kzalloc(base_size, GFP_KERNEL); + cams = kzalloc(base_size, GFP_KERNEL); if (cams == NULL) { err("Failed to allocate %d. bytes for usbvideo struct", base_size); return -ENOMEM; diff --git a/drivers/media/video/videocodec.c b/drivers/media/video/videocodec.c index 2ae3fb250630..290e64135650 100644 --- a/drivers/media/video/videocodec.c +++ b/drivers/media/video/videocodec.c @@ -346,7 +346,7 @@ videocodec_build_table (void) size); kfree(videocodec_buf); - videocodec_buf = (char *) kmalloc(size, GFP_KERNEL); + videocodec_buf = kmalloc(size, GFP_KERNEL); i = 0; i += scnprintf(videocodec_buf + i, size - 1, diff --git a/drivers/message/i2o/core.h b/drivers/message/i2o/core.h index dc388a3ff5e0..cbe384fb848c 100644 --- a/drivers/message/i2o/core.h +++ b/drivers/message/i2o/core.h @@ -18,7 +18,7 @@ extern struct i2o_driver i2o_exec_driver; extern int i2o_exec_lct_get(struct i2o_controller *); extern int __init i2o_exec_init(void); -extern void __exit i2o_exec_exit(void); +extern void i2o_exec_exit(void); /* driver */ extern struct bus_type i2o_bus_type; @@ -26,7 +26,7 @@ extern struct bus_type i2o_bus_type; extern int i2o_driver_dispatch(struct i2o_controller *, u32); extern int __init i2o_driver_init(void); -extern void __exit i2o_driver_exit(void); +extern void i2o_driver_exit(void); /* PCI */ extern int __init i2o_pci_init(void); diff --git a/drivers/message/i2o/driver.c b/drivers/message/i2o/driver.c index 9104b65ff70f..d3235f213c89 100644 --- a/drivers/message/i2o/driver.c +++ b/drivers/message/i2o/driver.c @@ -362,7 +362,7 @@ int __init i2o_driver_init(void) * * Unregisters the I2O bus and frees driver array. */ -void __exit i2o_driver_exit(void) +void i2o_driver_exit(void) { bus_unregister(&i2o_bus_type); kfree(i2o_drivers); diff --git a/drivers/message/i2o/exec-osm.c b/drivers/message/i2o/exec-osm.c index 902753b2c661..a539d3b61e76 100644 --- a/drivers/message/i2o/exec-osm.c +++ b/drivers/message/i2o/exec-osm.c @@ -595,7 +595,7 @@ int __init i2o_exec_init(void) * * Unregisters the Exec OSM from the I2O core. */ -void __exit i2o_exec_exit(void) +void i2o_exec_exit(void) { i2o_driver_unregister(&i2o_exec_driver); }; diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c index 1de30d711671..e33d446e7493 100644 --- a/drivers/message/i2o/i2o_config.c +++ b/drivers/message/i2o/i2o_config.c @@ -186,7 +186,7 @@ static int i2o_cfg_parms(unsigned long arg, unsigned int type) if (!dev) return -ENXIO; - ops = (u8 *) kmalloc(kcmd.oplen, GFP_KERNEL); + ops = kmalloc(kcmd.oplen, GFP_KERNEL); if (!ops) return -ENOMEM; @@ -199,7 +199,7 @@ static int i2o_cfg_parms(unsigned long arg, unsigned int type) * It's possible to have a _very_ large table * and that the user asks for all of it at once... */ - res = (u8 *) kmalloc(65536, GFP_KERNEL); + res = kmalloc(65536, GFP_KERNEL); if (!res) { kfree(ops); return -ENOMEM; diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c index 5db716045927..0a7e86859bf1 100644 --- a/drivers/mtd/devices/mtd_dataflash.c +++ b/drivers/mtd/devices/mtd_dataflash.c @@ -459,7 +459,7 @@ add_dataflash(struct spi_device *spi, char *name, struct mtd_info *device; struct flash_platform_data *pdata = spi->dev.platform_data; - priv = (struct dataflash *) kzalloc(sizeof *priv, GFP_KERNEL); + priv = kzalloc(sizeof *priv, GFP_KERNEL); if (!priv) return -ENOMEM; diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c index fa4362fb4dd8..0f3baa5d9c2a 100644 --- a/drivers/mtd/rfd_ftl.c +++ b/drivers/mtd/rfd_ftl.c @@ -768,7 +768,7 @@ static void rfd_ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) if (mtd->type != MTD_NORFLASH) return; - part = kcalloc(1, sizeof(struct partition), GFP_KERNEL); + part = kzalloc(sizeof(struct partition), GFP_KERNEL); if (!part) return; diff --git a/drivers/net/appletalk/ipddp.c b/drivers/net/appletalk/ipddp.c index b98592a8bac8..f22e46dfd770 100644 --- a/drivers/net/appletalk/ipddp.c +++ b/drivers/net/appletalk/ipddp.c @@ -186,7 +186,7 @@ static int ipddp_xmit(struct sk_buff *skb, struct net_device *dev) */ static int ipddp_create(struct ipddp_route *new_rt) { - struct ipddp_route *rt =(struct ipddp_route*) kmalloc(sizeof(*rt), GFP_KERNEL); + struct ipddp_route *rt = kmalloc(sizeof(*rt), GFP_KERNEL); if (rt == NULL) return -ENOMEM; diff --git a/drivers/net/bsd_comp.c b/drivers/net/bsd_comp.c index bae1de1e7802..7845eaf6f29f 100644 --- a/drivers/net/bsd_comp.c +++ b/drivers/net/bsd_comp.c @@ -395,7 +395,7 @@ static void *bsd_alloc (unsigned char *options, int opt_len, int decomp) * Allocate the main control structure for this instance. */ maxmaxcode = MAXCODE(bits); - db = (struct bsd_db *) kmalloc (sizeof (struct bsd_db), + db = kmalloc(sizeof (struct bsd_db), GFP_KERNEL); if (!db) { diff --git a/drivers/net/irda/donauboe.c b/drivers/net/irda/donauboe.c index 16620bd97fbf..11af0ae7510e 100644 --- a/drivers/net/irda/donauboe.c +++ b/drivers/net/irda/donauboe.c @@ -1603,7 +1603,7 @@ toshoboe_open (struct pci_dev *pci_dev, const struct pci_device_id *pdid) irda_qos_bits_to_value (&self->qos); /* Allocate twice the size to guarantee alignment */ - self->ringbuf = (void *) kmalloc (OBOE_RING_LEN << 1, GFP_KERNEL); + self->ringbuf = kmalloc(OBOE_RING_LEN << 1, GFP_KERNEL); if (!self->ringbuf) { printk (KERN_ERR DRIVER_NAME ": can't allocate DMA buffers\n"); diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c index 6e95645e7245..3ca1082ec776 100644 --- a/drivers/net/irda/irda-usb.c +++ b/drivers/net/irda/irda-usb.c @@ -1747,7 +1747,7 @@ static int irda_usb_probe(struct usb_interface *intf, /* Don't change this buffer size and allocation without doing * some heavy and complete testing. Don't ask why :-( * Jean II */ - self->speed_buff = (char *) kmalloc(IRDA_USB_SPEED_MTU, GFP_KERNEL); + self->speed_buff = kmalloc(IRDA_USB_SPEED_MTU, GFP_KERNEL); if (self->speed_buff == NULL) goto err_out_3; diff --git a/drivers/net/irda/irport.c b/drivers/net/irda/irport.c index 654a68b490ae..3098960dc2a1 100644 --- a/drivers/net/irda/irport.c +++ b/drivers/net/irda/irport.c @@ -164,7 +164,7 @@ irport_open(int i, unsigned int iobase, unsigned int irq) /* Allocate memory if needed */ if (self->tx_buff.truesize > 0) { - self->tx_buff.head = (__u8 *) kmalloc(self->tx_buff.truesize, + self->tx_buff.head = kmalloc(self->tx_buff.truesize, GFP_KERNEL); if (self->tx_buff.head == NULL) { IRDA_ERROR("%s(), can't allocate memory for " diff --git a/drivers/net/lp486e.c b/drivers/net/lp486e.c index b833016f1825..177c502f7385 100644 --- a/drivers/net/lp486e.c +++ b/drivers/net/lp486e.c @@ -884,7 +884,7 @@ static int i596_start_xmit (struct sk_buff *skb, struct net_device *dev) { dev->trans_start = jiffies; - tx_cmd = (struct tx_cmd *) kmalloc ((sizeof (struct tx_cmd) + sizeof (struct i596_tbd)), GFP_ATOMIC); + tx_cmd = kmalloc((sizeof (struct tx_cmd) + sizeof (struct i596_tbd)), GFP_ATOMIC); if (tx_cmd == NULL) { printk(KERN_WARNING "%s: i596_xmit Memory squeeze, dropping packet.\n", dev->name); lp->stats.tx_dropped++; @@ -1266,7 +1266,7 @@ static void set_multicast_list(struct net_device *dev) { if (dev->mc_count > 0) { struct dev_mc_list *dmi; char *cp; - cmd = (struct i596_cmd *)kmalloc(sizeof(struct i596_cmd)+2+dev->mc_count*6, GFP_ATOMIC); + cmd = kmalloc(sizeof(struct i596_cmd)+2+dev->mc_count*6, GFP_ATOMIC); if (cmd == NULL) { printk (KERN_ERR "%s: set_multicast Memory squeeze.\n", dev->name); return; diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index b01fc70a57db..a4d7529ef415 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -50,7 +50,7 @@ struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id) struct phy_device *dev; /* We allocate the device, and initialize the * default values */ - dev = kcalloc(1, sizeof(*dev), GFP_KERNEL); + dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (NULL == dev) return (struct phy_device*) PTR_ERR((void*)-ENOMEM); diff --git a/drivers/net/ppp_deflate.c b/drivers/net/ppp_deflate.c index f54c55242f4a..72c8d6628f58 100644 --- a/drivers/net/ppp_deflate.c +++ b/drivers/net/ppp_deflate.c @@ -121,7 +121,7 @@ static void *z_comp_alloc(unsigned char *options, int opt_len) if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE) return NULL; - state = (struct ppp_deflate_state *) kmalloc(sizeof(*state), + state = kmalloc(sizeof(*state), GFP_KERNEL); if (state == NULL) return NULL; @@ -341,7 +341,7 @@ static void *z_decomp_alloc(unsigned char *options, int opt_len) if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE) return NULL; - state = (struct ppp_deflate_state *) kmalloc(sizeof(*state), GFP_KERNEL); + state = kmalloc(sizeof(*state), GFP_KERNEL); if (state == NULL) return NULL; diff --git a/drivers/net/ppp_mppe.c b/drivers/net/ppp_mppe.c index f3655fd772f5..d5bdd2574659 100644 --- a/drivers/net/ppp_mppe.c +++ b/drivers/net/ppp_mppe.c @@ -200,7 +200,7 @@ static void *mppe_alloc(unsigned char *options, int optlen) || options[0] != CI_MPPE || options[1] != CILEN_MPPE) goto out; - state = (struct ppp_mppe_state *) kmalloc(sizeof(*state), GFP_KERNEL); + state = kmalloc(sizeof(*state), GFP_KERNEL); if (state == NULL) goto out; diff --git a/drivers/net/skge.c b/drivers/net/skge.c index b60f0451f6cd..8a39376f87dc 100644 --- a/drivers/net/skge.c +++ b/drivers/net/skge.c @@ -749,7 +749,7 @@ static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u32 base) struct skge_element *e; int i; - ring->start = kcalloc(sizeof(*e), ring->count, GFP_KERNEL); + ring->start = kcalloc(ring->count, sizeof(*e), GFP_KERNEL); if (!ring->start) return -ENOMEM; diff --git a/drivers/net/slip.c b/drivers/net/slip.c index 39c2152a07f4..a0806d262fc6 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -229,10 +229,10 @@ static int sl_realloc_bufs(struct slip *sl, int mtu) if (len < 576 * 2) len = 576 * 2; - xbuff = (unsigned char *) kmalloc (len + 4, GFP_ATOMIC); - rbuff = (unsigned char *) kmalloc (len + 4, GFP_ATOMIC); + xbuff = kmalloc(len + 4, GFP_ATOMIC); + rbuff = kmalloc(len + 4, GFP_ATOMIC); #ifdef SL_INCLUDE_CSLIP - cbuff = (unsigned char *) kmalloc (len + 4, GFP_ATOMIC); + cbuff = kmalloc(len + 4, GFP_ATOMIC); #endif diff --git a/drivers/net/wan/hostess_sv11.c b/drivers/net/wan/hostess_sv11.c index a4f735723c41..a02c5fb40567 100644 --- a/drivers/net/wan/hostess_sv11.c +++ b/drivers/net/wan/hostess_sv11.c @@ -231,7 +231,7 @@ static struct sv11_device *sv11_init(int iobase, int irq) return NULL; } - sv=(struct sv11_device *)kmalloc(sizeof(struct sv11_device), GFP_KERNEL); + sv = kmalloc(sizeof(struct sv11_device), GFP_KERNEL); if(!sv) goto fail3; diff --git a/drivers/net/wan/pc300_drv.c b/drivers/net/wan/pc300_drv.c index 36d1c3ff7078..62184dee377c 100644 --- a/drivers/net/wan/pc300_drv.c +++ b/drivers/net/wan/pc300_drv.c @@ -3455,7 +3455,7 @@ cpc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if ((err = pci_enable_device(pdev)) < 0) return err; - card = (pc300_t *) kmalloc(sizeof(pc300_t), GFP_KERNEL); + card = kmalloc(sizeof(pc300_t), GFP_KERNEL); if (card == NULL) { printk("PC300 found at RAM 0x%016llx, " "but could not allocate card structure.\n", diff --git a/drivers/net/wan/pc300_tty.c b/drivers/net/wan/pc300_tty.c index b2a23aed4428..5873c346e7e9 100644 --- a/drivers/net/wan/pc300_tty.c +++ b/drivers/net/wan/pc300_tty.c @@ -784,7 +784,7 @@ void cpc_tty_receive(pc300dev_t *pc300dev) continue; } - new = (st_cpc_rx_buf *)kmalloc(rx_len + sizeof(st_cpc_rx_buf), GFP_ATOMIC); + new = kmalloc(rx_len + sizeof(st_cpc_rx_buf), GFP_ATOMIC); if (new == 0) { cpc_tty_rx_disc_frame(pc300chan); continue; diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c index 9c3ccc669143..1c9edd97accd 100644 --- a/drivers/net/wan/x25_asy.c +++ b/drivers/net/wan/x25_asy.c @@ -123,8 +123,8 @@ static int x25_asy_change_mtu(struct net_device *dev, int newmtu) unsigned char *xbuff, *rbuff; int len = 2* newmtu; - xbuff = (unsigned char *) kmalloc (len + 4, GFP_ATOMIC); - rbuff = (unsigned char *) kmalloc (len + 4, GFP_ATOMIC); + xbuff = kmalloc(len + 4, GFP_ATOMIC); + rbuff = kmalloc(len + 4, GFP_ATOMIC); if (xbuff == NULL || rbuff == NULL) { @@ -465,11 +465,11 @@ static int x25_asy_open(struct net_device *dev) len = dev->mtu * 2; - sl->rbuff = (unsigned char *) kmalloc(len + 4, GFP_KERNEL); + sl->rbuff = kmalloc(len + 4, GFP_KERNEL); if (sl->rbuff == NULL) { goto norbuff; } - sl->xbuff = (unsigned char *) kmalloc(len + 4, GFP_KERNEL); + sl->xbuff = kmalloc(len + 4, GFP_KERNEL); if (sl->xbuff == NULL) { goto noxbuff; } diff --git a/drivers/net/wireless/hostap/hostap_ap.c b/drivers/net/wireless/hostap/hostap_ap.c index 974a8e5bec8b..efb8cf3bd8ad 100644 --- a/drivers/net/wireless/hostap/hostap_ap.c +++ b/drivers/net/wireless/hostap/hostap_ap.c @@ -1253,7 +1253,7 @@ static char * ap_auth_make_challenge(struct ap_data *ap) return NULL; } - tmpbuf = (char *) kmalloc(WLAN_AUTH_CHALLENGE_LEN, GFP_ATOMIC); + tmpbuf = kmalloc(WLAN_AUTH_CHALLENGE_LEN, GFP_ATOMIC); if (tmpbuf == NULL) { PDEBUG(DEBUG_AP, "AP: kmalloc failed for challenge\n"); return NULL; diff --git a/drivers/net/wireless/hostap/hostap_download.c b/drivers/net/wireless/hostap/hostap_download.c index 24fc387bba67..c7678e67697d 100644 --- a/drivers/net/wireless/hostap/hostap_download.c +++ b/drivers/net/wireless/hostap/hostap_download.c @@ -201,7 +201,7 @@ static u8 * prism2_read_pda(struct net_device *dev) 0x7f0002 /* Intel PRO/Wireless 2011B (PCI) */, }; - buf = (u8 *) kmalloc(PRISM2_PDA_SIZE, GFP_KERNEL); + buf = kmalloc(PRISM2_PDA_SIZE, GFP_KERNEL); if (buf == NULL) return NULL; diff --git a/drivers/net/wireless/hostap/hostap_hw.c b/drivers/net/wireless/hostap/hostap_hw.c index a394a23b9a20..3079378fb8cd 100644 --- a/drivers/net/wireless/hostap/hostap_hw.c +++ b/drivers/net/wireless/hostap/hostap_hw.c @@ -2252,7 +2252,7 @@ static int hostap_tx_compl_read(local_info_t *local, int error, if (txdesc->sw_support) { len = le16_to_cpu(txdesc->data_len); if (len < PRISM2_DATA_MAXLEN) { - *payload = (char *) kmalloc(len, GFP_ATOMIC); + *payload = kmalloc(len, GFP_ATOMIC); if (*payload == NULL || hfa384x_from_bap(dev, BAP0, *payload, len)) { PDEBUG(DEBUG_EXTRA, "%s: could not read TX " diff --git a/drivers/net/wireless/hostap/hostap_ioctl.c b/drivers/net/wireless/hostap/hostap_ioctl.c index 3b7b8063ff1c..cb08bc5db2bd 100644 --- a/drivers/net/wireless/hostap/hostap_ioctl.c +++ b/drivers/net/wireless/hostap/hostap_ioctl.c @@ -3829,7 +3829,7 @@ static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p) p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer) return -EINVAL; - param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL); + param = kmalloc(p->length, GFP_KERNEL); if (param == NULL) return -ENOMEM; diff --git a/drivers/net/wireless/hostap/hostap_main.c b/drivers/net/wireless/hostap/hostap_main.c index 0796be9d9e77..04c19cefa1da 100644 --- a/drivers/net/wireless/hostap/hostap_main.c +++ b/drivers/net/wireless/hostap/hostap_main.c @@ -250,7 +250,7 @@ u16 hostap_tx_callback_register(local_info_t *local, unsigned long flags; struct hostap_tx_callback_info *entry; - entry = (struct hostap_tx_callback_info *) kmalloc(sizeof(*entry), + entry = kmalloc(sizeof(*entry), GFP_ATOMIC); if (entry == NULL) return 0; diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c index dd9ba4aad7bb..0e94fbbf7a94 100644 --- a/drivers/net/wireless/ipw2100.c +++ b/drivers/net/wireless/ipw2100.c @@ -2246,7 +2246,7 @@ static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv) if (priv->snapshot[0]) return 1; for (i = 0; i < 0x30; i++) { - priv->snapshot[i] = (u8 *) kmalloc(0x1000, GFP_ATOMIC); + priv->snapshot[i] = kmalloc(0x1000, GFP_ATOMIC); if (!priv->snapshot[i]) { IPW_DEBUG_INFO("%s: Error allocating snapshot " "buffer %d\n", priv->net_dev->name, i); diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c index 96606ed10076..838d510213c6 100644 --- a/drivers/net/wireless/prism54/isl_ioctl.c +++ b/drivers/net/wireless/prism54/isl_ioctl.c @@ -2775,7 +2775,7 @@ prism54_hostapd(struct net_device *ndev, struct iw_point *p) p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer) return -EINVAL; - param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL); + param = kmalloc(p->length, GFP_KERNEL); if (param == NULL) return -ENOMEM; diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c index 233d906c08f0..5eb81638e846 100644 --- a/drivers/net/wireless/wavelan_cs.c +++ b/drivers/net/wireless/wavelan_cs.c @@ -603,7 +603,7 @@ static wavepoint_history *wl_new_wavepoint(unsigned short nwid, unsigned char se if(lp->wavepoint_table.num_wavepoints==MAX_WAVEPOINTS) return NULL; - new_wavepoint=(wavepoint_history *) kmalloc(sizeof(wavepoint_history),GFP_ATOMIC); + new_wavepoint = kmalloc(sizeof(wavepoint_history),GFP_ATOMIC); if(new_wavepoint==NULL) return NULL; diff --git a/drivers/net/wireless/zd1211rw/zd_chip.c b/drivers/net/wireless/zd1211rw/zd_chip.c index 77e11ddad836..78ea72fb8f0c 100644 --- a/drivers/net/wireless/zd1211rw/zd_chip.c +++ b/drivers/net/wireless/zd1211rw/zd_chip.c @@ -101,7 +101,7 @@ int zd_ioread32v_locked(struct zd_chip *chip, u32 *values, const zd_addr_t *addr /* Allocate a single memory block for values and addresses. */ count16 = 2*count; - a16 = (zd_addr_t *)kmalloc(count16 * (sizeof(zd_addr_t) + sizeof(u16)), + a16 = kmalloc(count16 * (sizeof(zd_addr_t) + sizeof(u16)), GFP_NOFS); if (!a16) { dev_dbg_f(zd_chip_dev(chip), diff --git a/drivers/parisc/iosapic.c b/drivers/parisc/iosapic.c index 12bab64a62a1..6fb3f7979f21 100644 --- a/drivers/parisc/iosapic.c +++ b/drivers/parisc/iosapic.c @@ -874,7 +874,7 @@ void *iosapic_register(unsigned long hpa) return NULL; } - isi = (struct iosapic_info *)kzalloc(sizeof(struct iosapic_info), GFP_KERNEL); + isi = kzalloc(sizeof(struct iosapic_info), GFP_KERNEL); if (!isi) { BUG(); return NULL; diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c index 298a6cfd8406..ae5e974c45a7 100644 --- a/drivers/pci/hotplug/cpqphp_nvram.c +++ b/drivers/pci/hotplug/cpqphp_nvram.c @@ -520,7 +520,7 @@ int compaq_nvram_load (void __iomem *rom_start, struct controller *ctrl) return 2; while (nummem--) { - mem_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); + mem_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL); if (!mem_node) break; @@ -548,7 +548,7 @@ int compaq_nvram_load (void __iomem *rom_start, struct controller *ctrl) } while (numpmem--) { - p_mem_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); + p_mem_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL); if (!p_mem_node) break; @@ -576,7 +576,7 @@ int compaq_nvram_load (void __iomem *rom_start, struct controller *ctrl) } while (numio--) { - io_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); + io_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL); if (!io_node) break; @@ -604,7 +604,7 @@ int compaq_nvram_load (void __iomem *rom_start, struct controller *ctrl) } while (numbus--) { - bus_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); + bus_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL); if (!bus_node) break; diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 6d3f580f2666..25d3aadfddbf 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -1320,7 +1320,7 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev) DBG_ENTER_ROUTINE spin_lock_init(&list_lock); - php_ctlr = (struct php_ctlr_state_s *) kmalloc(sizeof(struct php_ctlr_state_s), GFP_KERNEL); + php_ctlr = kmalloc(sizeof(struct php_ctlr_state_s), GFP_KERNEL); if (!php_ctlr) { /* allocate controller state data */ err("%s: HPC controller memory allocation error!\n", __FUNCTION__); diff --git a/drivers/pci/pcie/aer/aerdrv.c b/drivers/pci/pcie/aer/aerdrv.c index 55866b6b26fa..6f5fabbd14e5 100644 --- a/drivers/pci/pcie/aer/aerdrv.c +++ b/drivers/pci/pcie/aer/aerdrv.c @@ -148,7 +148,7 @@ static struct aer_rpc* aer_alloc_rpc(struct pcie_device *dev) { struct aer_rpc *rpc; - if (!(rpc = (struct aer_rpc *)kmalloc(sizeof(struct aer_rpc), + if (!(rpc = kmalloc(sizeof(struct aer_rpc), GFP_KERNEL))) return NULL; diff --git a/drivers/pcmcia/at91_cf.c b/drivers/pcmcia/at91_cf.c index 52d4a38b3667..3334f22a86c0 100644 --- a/drivers/pcmcia/at91_cf.c +++ b/drivers/pcmcia/at91_cf.c @@ -230,7 +230,7 @@ static int __init at91_cf_probe(struct platform_device *pdev) if (!io) return -ENODEV; - cf = kcalloc(1, sizeof *cf, GFP_KERNEL); + cf = kzalloc(sizeof *cf, GFP_KERNEL); if (!cf) return -ENOMEM; diff --git a/drivers/pcmcia/omap_cf.c b/drivers/pcmcia/omap_cf.c index 06bf7f48836e..e65a6b8188f6 100644 --- a/drivers/pcmcia/omap_cf.c +++ b/drivers/pcmcia/omap_cf.c @@ -220,7 +220,7 @@ static int __devinit omap_cf_probe(struct device *dev) if (irq < 0) return -EINVAL; - cf = kcalloc(1, sizeof *cf, GFP_KERNEL); + cf = kzalloc(sizeof *cf, GFP_KERNEL); if (!cf) return -ENOMEM; init_timer(&cf->timer); diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c index 3ac5b123215a..a0b158704ca1 100644 --- a/drivers/pnp/isapnp/core.c +++ b/drivers/pnp/isapnp/core.c @@ -395,7 +395,7 @@ static void isapnp_parse_id(struct pnp_dev * dev, unsigned short vendor, unsigne struct pnp_id * id; if (!dev) return; - id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL); + id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); if (!id) return; sprintf(id->id, "%c%c%c%x%x%x%x", @@ -419,7 +419,7 @@ static struct pnp_dev * __init isapnp_parse_device(struct pnp_card *card, int si struct pnp_dev *dev; isapnp_peek(tmp, size); - dev = kcalloc(1, sizeof(struct pnp_dev), GFP_KERNEL); + dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); if (!dev) return NULL; dev->number = number; @@ -450,7 +450,7 @@ static void __init isapnp_parse_irq_resource(struct pnp_option *option, unsigned long bits; isapnp_peek(tmp, size); - irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL); + irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL); if (!irq) return; bits = (tmp[1] << 8) | tmp[0]; @@ -474,7 +474,7 @@ static void __init isapnp_parse_dma_resource(struct pnp_option *option, struct pnp_dma *dma; isapnp_peek(tmp, size); - dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL); + dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL); if (!dma) return; dma->map = tmp[0]; @@ -494,7 +494,7 @@ static void __init isapnp_parse_port_resource(struct pnp_option *option, struct pnp_port *port; isapnp_peek(tmp, size); - port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); + port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); if (!port) return; port->min = (tmp[2] << 8) | tmp[1]; @@ -517,7 +517,7 @@ static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option, struct pnp_port *port; isapnp_peek(tmp, size); - port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); + port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); if (!port) return; port->min = port->max = (tmp[1] << 8) | tmp[0]; @@ -539,7 +539,7 @@ static void __init isapnp_parse_mem_resource(struct pnp_option *option, struct pnp_mem *mem; isapnp_peek(tmp, size); - mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); + mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); if (!mem) return; mem->min = ((tmp[2] << 8) | tmp[1]) << 8; @@ -562,7 +562,7 @@ static void __init isapnp_parse_mem32_resource(struct pnp_option *option, struct pnp_mem *mem; isapnp_peek(tmp, size); - mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); + mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); if (!mem) return; mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; @@ -584,7 +584,7 @@ static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option, struct pnp_mem *mem; isapnp_peek(tmp, size); - mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); + mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); if (!mem) return; mem->min = mem->max = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; @@ -829,7 +829,7 @@ static unsigned char __init isapnp_checksum(unsigned char *data) static void isapnp_parse_card_id(struct pnp_card * card, unsigned short vendor, unsigned short device) { - struct pnp_id * id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL); + struct pnp_id * id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); if (!id) return; sprintf(id->id, "%c%c%c%x%x%x%x", @@ -865,7 +865,7 @@ static int __init isapnp_build_device_list(void) header[4], header[5], header[6], header[7], header[8]); printk(KERN_DEBUG "checksum = 0x%x\n", checksum); #endif - if ((card = kcalloc(1, sizeof(struct pnp_card), GFP_KERNEL)) == NULL) + if ((card = kzalloc(sizeof(struct pnp_card), GFP_KERNEL)) == NULL) continue; card->number = csn; diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c index 6cf34a63c790..62eda5d59024 100644 --- a/drivers/pnp/pnpacpi/core.c +++ b/drivers/pnp/pnpacpi/core.c @@ -139,7 +139,7 @@ static int __init pnpacpi_add_device(struct acpi_device *device) return 0; pnp_dbg("ACPI device : hid %s", acpi_device_hid(device)); - dev = kcalloc(1, sizeof(struct pnp_dev), GFP_KERNEL); + dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); if (!dev) { pnp_err("Out of memory"); return -ENOMEM; @@ -169,7 +169,7 @@ static int __init pnpacpi_add_device(struct acpi_device *device) dev->number = num; /* set the initial values for the PnP device */ - dev_id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL); + dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); if (!dev_id) goto err; pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id); @@ -201,7 +201,7 @@ static int __init pnpacpi_add_device(struct acpi_device *device) for (i = 0; i < cid_list->count; i++) { if (!ispnpidacpi(cid_list->id[i].value)) continue; - dev_id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL); + dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); if (!dev_id) continue; diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c index 379048fdf05d..7a535542fe92 100644 --- a/drivers/pnp/pnpacpi/rsparser.c +++ b/drivers/pnp/pnpacpi/rsparser.c @@ -298,7 +298,7 @@ static void pnpacpi_parse_dma_option(struct pnp_option *option, struct acpi_reso if (p->channel_count == 0) return; - dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL); + dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL); if (!dma) return; @@ -354,7 +354,7 @@ static void pnpacpi_parse_irq_option(struct pnp_option *option, if (p->interrupt_count == 0) return; - irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL); + irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL); if (!irq) return; @@ -375,7 +375,7 @@ static void pnpacpi_parse_ext_irq_option(struct pnp_option *option, if (p->interrupt_count == 0) return; - irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL); + irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL); if (!irq) return; @@ -396,7 +396,7 @@ pnpacpi_parse_port_option(struct pnp_option *option, if (io->address_length == 0) return; - port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); + port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); if (!port) return; port->min = io->minimum; @@ -417,7 +417,7 @@ pnpacpi_parse_fixed_port_option(struct pnp_option *option, if (io->address_length == 0) return; - port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); + port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); if (!port) return; port->min = port->max = io->address; @@ -436,7 +436,7 @@ pnpacpi_parse_mem24_option(struct pnp_option *option, if (p->address_length == 0) return; - mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); + mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); if (!mem) return; mem->min = p->minimum; @@ -459,7 +459,7 @@ pnpacpi_parse_mem32_option(struct pnp_option *option, if (p->address_length == 0) return; - mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); + mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); if (!mem) return; mem->min = p->minimum; @@ -482,7 +482,7 @@ pnpacpi_parse_fixed_mem32_option(struct pnp_option *option, if (p->address_length == 0) return; - mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); + mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); if (!mem) return; mem->min = mem->max = p->address; @@ -514,7 +514,7 @@ pnpacpi_parse_address_option(struct pnp_option *option, struct acpi_resource *r) return; if (p->resource_type == ACPI_MEMORY_RANGE) { - mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); + mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); if (!mem) return; mem->min = mem->max = p->minimum; @@ -524,7 +524,7 @@ pnpacpi_parse_address_option(struct pnp_option *option, struct acpi_resource *r) ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE : 0; pnp_register_mem_resource(option, mem); } else if (p->resource_type == ACPI_IO_RANGE) { - port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); + port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); if (!port) return; port->min = port->max = p->minimum; @@ -721,7 +721,7 @@ int pnpacpi_build_resource_template(acpi_handle handle, if (!res_cnt) return -EINVAL; buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1; - buffer->pointer = kcalloc(1, buffer->length - 1, GFP_KERNEL); + buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL); if (!buffer->pointer) return -ENOMEM; pnp_dbg("Res cnt %d", res_cnt); diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c index 33adeba1a31f..95738dbd5d45 100644 --- a/drivers/pnp/pnpbios/core.c +++ b/drivers/pnp/pnpbios/core.c @@ -109,10 +109,10 @@ static int pnp_dock_event(int dock, struct pnp_docking_station_info *info) if (!current->fs->root) { return -EAGAIN; } - if (!(envp = (char **) kcalloc (20, sizeof (char *), GFP_KERNEL))) { + if (!(envp = kcalloc(20, sizeof (char *), GFP_KERNEL))) { return -ENOMEM; } - if (!(buf = kcalloc (1, 256, GFP_KERNEL))) { + if (!(buf = kzalloc(256, GFP_KERNEL))) { kfree (envp); return -ENOMEM; } @@ -220,7 +220,7 @@ static int pnpbios_get_resources(struct pnp_dev * dev, struct pnp_resource_table if(!pnpbios_is_dynamic(dev)) return -EPERM; - node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); + node = kzalloc(node_info.max_node_size, GFP_KERNEL); if (!node) return -1; if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) { @@ -243,7 +243,7 @@ static int pnpbios_set_resources(struct pnp_dev * dev, struct pnp_resource_table if (!pnpbios_is_dynamic(dev)) return -EPERM; - node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); + node = kzalloc(node_info.max_node_size, GFP_KERNEL); if (!node) return -1; if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) { @@ -294,7 +294,7 @@ static int pnpbios_disable_resources(struct pnp_dev *dev) if(dev->flags & PNPBIOS_NO_DISABLE || !pnpbios_is_dynamic(dev)) return -EPERM; - node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); + node = kzalloc(node_info.max_node_size, GFP_KERNEL); if (!node) return -ENOMEM; @@ -336,7 +336,7 @@ static int insert_device(struct pnp_dev *dev, struct pnp_bios_node * node) } /* set the initial values for the PnP device */ - dev_id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL); + dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); if (!dev_id) return -1; pnpid32_to_pnpid(node->eisa_id,id); @@ -374,7 +374,7 @@ static void __init build_devlist(void) struct pnp_bios_node *node; struct pnp_dev *dev; - node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); + node = kzalloc(node_info.max_node_size, GFP_KERNEL); if (!node) return; @@ -391,7 +391,7 @@ static void __init build_devlist(void) break; } nodes_got++; - dev = kcalloc(1, sizeof (struct pnp_dev), GFP_KERNEL); + dev = kzalloc(sizeof (struct pnp_dev), GFP_KERNEL); if (!dev) break; if(insert_device(dev,node)<0) diff --git a/drivers/pnp/pnpbios/proc.c b/drivers/pnp/pnpbios/proc.c index 5a3dfc97f5e9..8027073f7919 100644 --- a/drivers/pnp/pnpbios/proc.c +++ b/drivers/pnp/pnpbios/proc.c @@ -87,7 +87,7 @@ static int proc_read_escd(char *buf, char **start, off_t pos, return -EFBIG; } - tmpbuf = kcalloc(1, escd.escd_size, GFP_KERNEL); + tmpbuf = kzalloc(escd.escd_size, GFP_KERNEL); if (!tmpbuf) return -ENOMEM; if (pnp_bios_read_escd(tmpbuf, escd.nv_storage_base)) { @@ -133,7 +133,7 @@ static int proc_read_devices(char *buf, char **start, off_t pos, if (pos >= 0xff) return 0; - node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); + node = kzalloc(node_info.max_node_size, GFP_KERNEL); if (!node) return -ENOMEM; for (nodenum=pos; nodenum<0xff; ) { @@ -168,7 +168,7 @@ static int proc_read_node(char *buf, char **start, off_t pos, u8 nodenum = (long)data; int len; - node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); + node = kzalloc(node_info.max_node_size, GFP_KERNEL); if (!node) return -ENOMEM; if (pnp_bios_get_dev_node(&nodenum, boot, node)) { kfree(node); @@ -188,7 +188,7 @@ static int proc_write_node(struct file *file, const char __user *buf, u8 nodenum = (long)data; int ret = count; - node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); + node = kzalloc(node_info.max_node_size, GFP_KERNEL); if (!node) return -ENOMEM; if (pnp_bios_get_dev_node(&nodenum, boot, node)) { diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c index ef508a4de557..95b79685a9d1 100644 --- a/drivers/pnp/pnpbios/rsparser.c +++ b/drivers/pnp/pnpbios/rsparser.c @@ -248,7 +248,7 @@ static void pnpbios_parse_mem_option(unsigned char *p, int size, struct pnp_option *option) { struct pnp_mem * mem; - mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); + mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); if (!mem) return; mem->min = ((p[5] << 8) | p[4]) << 8; @@ -264,7 +264,7 @@ static void pnpbios_parse_mem32_option(unsigned char *p, int size, struct pnp_option *option) { struct pnp_mem * mem; - mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); + mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); if (!mem) return; mem->min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; @@ -280,7 +280,7 @@ static void pnpbios_parse_fixed_mem32_option(unsigned char *p, int size, struct pnp_option *option) { struct pnp_mem * mem; - mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); + mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); if (!mem) return; mem->min = mem->max = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; @@ -297,7 +297,7 @@ pnpbios_parse_irq_option(unsigned char *p, int size, struct pnp_option *option) struct pnp_irq * irq; unsigned long bits; - irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL); + irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL); if (!irq) return; bits = (p[2] << 8) | p[1]; @@ -314,7 +314,7 @@ static void pnpbios_parse_dma_option(unsigned char *p, int size, struct pnp_option *option) { struct pnp_dma * dma; - dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL); + dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL); if (!dma) return; dma->map = p[1]; @@ -327,7 +327,7 @@ static void pnpbios_parse_port_option(unsigned char *p, int size, struct pnp_option *option) { struct pnp_port * port; - port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); + port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); if (!port) return; port->min = (p[3] << 8) | p[2]; @@ -343,7 +343,7 @@ static void pnpbios_parse_fixed_port_option(unsigned char *p, int size, struct pnp_option *option) { struct pnp_port * port; - port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); + port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); if (!port) return; port->min = port->max = (p[2] << 8) | p[1]; @@ -527,7 +527,7 @@ pnpbios_parse_compatible_ids(unsigned char *p, unsigned char *end, struct pnp_de case SMALL_TAG_COMPATDEVID: /* compatible ID */ if (len != 4) goto len_err; - dev_id = kcalloc(1, sizeof (struct pnp_id), GFP_KERNEL); + dev_id = kzalloc(sizeof (struct pnp_id), GFP_KERNEL); if (!dev_id) return NULL; memset(dev_id, 0, sizeof(struct pnp_id)); diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c index 5c8addcaf1fb..4f654c901c64 100644 --- a/drivers/rtc/rtc-at91rm9200.c +++ b/drivers/rtc/rtc-at91rm9200.c @@ -137,6 +137,9 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); tm->tm_year = at91_alarm_year - 1900; + alrm->enabled = (at91_sys_read(AT91_RTC_IMR) & AT91_RTC_ALARM) + ? 1 : 0; + pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__, 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); @@ -223,8 +226,6 @@ static int at91_rtc_proc(struct device *dev, struct seq_file *seq) { unsigned long imr = at91_sys_read(AT91_RTC_IMR); - seq_printf(seq, "alarm_IRQ\t: %s\n", - (imr & AT91_RTC_ALARM) ? "yes" : "no"); seq_printf(seq, "update_IRQ\t: %s\n", (imr & AT91_RTC_ACKUPD) ? "yes" : "no"); seq_printf(seq, "periodic_IRQ\t: %s\n", diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c index 828b329e08e0..94d3df62a5fa 100644 --- a/drivers/rtc/rtc-dev.c +++ b/drivers/rtc/rtc-dev.c @@ -435,7 +435,7 @@ static int rtc_dev_add_device(struct class_device *class_dev, goto err_cdev_del; } - dev_info(class_dev->dev, "rtc intf: dev (%d:%d)\n", + dev_dbg(class_dev->dev, "rtc intf: dev (%d:%d)\n", MAJOR(rtc->rtc_dev->devt), MINOR(rtc->rtc_dev->devt)); diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c index eac5fb1fc02f..d59880d44fba 100644 --- a/drivers/rtc/rtc-omap.c +++ b/drivers/rtc/rtc-omap.c @@ -279,9 +279,8 @@ static int omap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) local_irq_enable(); bcd2tm(&alm->time); - alm->pending = !!(rtc_read(OMAP_RTC_INTERRUPTS_REG) + alm->enabled = !!(rtc_read(OMAP_RTC_INTERRUPTS_REG) & OMAP_RTC_INTERRUPTS_IT_ALARM); - alm->enabled = alm->pending && device_may_wakeup(dev); return 0; } diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/rtc-proc.c index d51d8f20e634..c272afd62173 100644 --- a/drivers/rtc/rtc-proc.c +++ b/drivers/rtc/rtc-proc.c @@ -65,7 +65,7 @@ static int rtc_proc_show(struct seq_file *seq, void *offset) seq_printf(seq, "%02d\n", alrm.time.tm_mday); else seq_printf(seq, "**\n"); - seq_printf(seq, "alrm_wakeup\t: %s\n", + seq_printf(seq, "alarm_IRQ\t: %s\n", alrm.enabled ? "yes" : "no"); seq_printf(seq, "alrm_pending\t: %s\n", alrm.pending ? "yes" : "no"); @@ -120,7 +120,7 @@ static int rtc_proc_add_device(struct class_device *class_dev, ent->owner = rtc->owner; ent->data = class_dev; - dev_info(class_dev->dev, "rtc intf: proc\n"); + dev_dbg(class_dev->dev, "rtc intf: proc\n"); } else rtc_dev = NULL; diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c index e301dea57bb3..f406a2b55aea 100644 --- a/drivers/rtc/rtc-s3c.c +++ b/drivers/rtc/rtc-s3c.c @@ -191,6 +191,8 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) alm_en = readb(base + S3C2410_RTCALM); + alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; + pr_debug("read alarm %02x %02x.%02x.%02x %02x/%02x/%02x\n", alm_en, alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, @@ -331,12 +333,8 @@ static int s3c_rtc_ioctl(struct device *dev, static int s3c_rtc_proc(struct device *dev, struct seq_file *seq) { - unsigned int rtcalm = readb(s3c_rtc_base + S3C2410_RTCALM); unsigned int ticnt = readb(s3c_rtc_base + S3C2410_TICNT); - seq_printf(seq, "alarm_IRQ\t: %s\n", - (rtcalm & S3C2410_RTCALM_ALMEN) ? "yes" : "no" ); - seq_printf(seq, "periodic_IRQ\t: %s\n", (ticnt & S3C2410_TICNT_ENABLE) ? "yes" : "no" ); diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c index bd4d7d174ef4..9c8ead43a59c 100644 --- a/drivers/rtc/rtc-sa1100.c +++ b/drivers/rtc/rtc-sa1100.c @@ -289,9 +289,7 @@ static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq) { - seq_printf(seq, "trim/divider\t: 0x%08lx\n", RTTR); - seq_printf(seq, "alarm_IRQ\t: %s\n", - (RTSR & RTSR_ALE) ? "yes" : "no" ); + seq_printf(seq, "trim/divider\t: 0x%08x\n", (u32) RTTR); seq_printf(seq, "update_IRQ\t: %s\n", (RTSR & RTSR_HZE) ? "yes" : "no"); seq_printf(seq, "periodic_IRQ\t: %s\n", diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c index 625637b84d33..9418a59fb368 100644 --- a/drivers/rtc/rtc-sysfs.c +++ b/drivers/rtc/rtc-sysfs.c @@ -83,7 +83,7 @@ static int __devinit rtc_sysfs_add_device(struct class_device *class_dev, { int err; - dev_info(class_dev->dev, "rtc intf: sysfs\n"); + dev_dbg(class_dev->dev, "rtc intf: sysfs\n"); err = sysfs_create_group(&class_dev->kobj, &rtc_attr_group); if (err) diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c index c9321b920e90..25b5d7a66417 100644 --- a/drivers/s390/char/con3215.c +++ b/drivers/s390/char/con3215.c @@ -688,7 +688,7 @@ raw3215_probe (struct ccw_device *cdev) raw->cdev = cdev; raw->inbuf = (char *) raw + sizeof(struct raw3215_info); memset(raw, 0, sizeof(struct raw3215_info)); - raw->buffer = (char *) kmalloc(RAW3215_BUFFER_SIZE, + raw->buffer = kmalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL|GFP_DMA); if (raw->buffer == NULL) { spin_lock(&raw3215_device_lock); diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c index e3491a5f5219..3e86fd1756e5 100644 --- a/drivers/s390/char/keyboard.c +++ b/drivers/s390/char/keyboard.c @@ -377,7 +377,7 @@ do_kdsk_ioctl(struct kbd_data *kbd, struct kbentry __user *user_kbe, if (!(key_map = kbd->key_maps[tmp.kb_table])) { int j; - key_map = (ushort *) kmalloc(sizeof(plain_map), + key_map = kmalloc(sizeof(plain_map), GFP_KERNEL); if (!key_map) return -ENOMEM; diff --git a/drivers/s390/char/sclp_cpi.c b/drivers/s390/char/sclp_cpi.c index 732dfbdb85c4..f7c10d954ec6 100644 --- a/drivers/s390/char/sclp_cpi.c +++ b/drivers/s390/char/sclp_cpi.c @@ -127,7 +127,7 @@ cpi_prepare_req(void) struct cpi_sccb *sccb; struct cpi_evbuf *evb; - req = (struct sclp_req *) kmalloc(sizeof(struct sclp_req), GFP_KERNEL); + req = kmalloc(sizeof(struct sclp_req), GFP_KERNEL); if (req == NULL) return ERR_PTR(-ENOMEM); sccb = (struct cpi_sccb *) __get_free_page(GFP_KERNEL | GFP_DMA); diff --git a/drivers/s390/crypto/zcrypt_cex2a.c b/drivers/s390/crypto/zcrypt_cex2a.c index a62b00083d0c..5bb13a9d0898 100644 --- a/drivers/s390/crypto/zcrypt_cex2a.c +++ b/drivers/s390/crypto/zcrypt_cex2a.c @@ -295,7 +295,7 @@ static long zcrypt_cex2a_modexpo(struct zcrypt_device *zdev, struct completion work; int rc; - ap_msg.message = (void *) kmalloc(CEX2A_MAX_MESSAGE_SIZE, GFP_KERNEL); + ap_msg.message = kmalloc(CEX2A_MAX_MESSAGE_SIZE, GFP_KERNEL); if (!ap_msg.message) return -ENOMEM; ap_msg.psmid = (((unsigned long long) current->pid) << 32) + @@ -337,7 +337,7 @@ static long zcrypt_cex2a_modexpo_crt(struct zcrypt_device *zdev, struct completion work; int rc; - ap_msg.message = (void *) kmalloc(CEX2A_MAX_MESSAGE_SIZE, GFP_KERNEL); + ap_msg.message = kmalloc(CEX2A_MAX_MESSAGE_SIZE, GFP_KERNEL); if (!ap_msg.message) return -ENOMEM; ap_msg.psmid = (((unsigned long long) current->pid) << 32) + diff --git a/drivers/s390/crypto/zcrypt_pcica.c b/drivers/s390/crypto/zcrypt_pcica.c index b6a4ecdc8025..32e37014345c 100644 --- a/drivers/s390/crypto/zcrypt_pcica.c +++ b/drivers/s390/crypto/zcrypt_pcica.c @@ -279,7 +279,7 @@ static long zcrypt_pcica_modexpo(struct zcrypt_device *zdev, struct completion work; int rc; - ap_msg.message = (void *) kmalloc(PCICA_MAX_MESSAGE_SIZE, GFP_KERNEL); + ap_msg.message = kmalloc(PCICA_MAX_MESSAGE_SIZE, GFP_KERNEL); if (!ap_msg.message) return -ENOMEM; ap_msg.psmid = (((unsigned long long) current->pid) << 32) + @@ -321,7 +321,7 @@ static long zcrypt_pcica_modexpo_crt(struct zcrypt_device *zdev, struct completion work; int rc; - ap_msg.message = (void *) kmalloc(PCICA_MAX_MESSAGE_SIZE, GFP_KERNEL); + ap_msg.message = kmalloc(PCICA_MAX_MESSAGE_SIZE, GFP_KERNEL); if (!ap_msg.message) return -ENOMEM; ap_msg.psmid = (((unsigned long long) current->pid) << 32) + diff --git a/drivers/s390/crypto/zcrypt_pcixcc.c b/drivers/s390/crypto/zcrypt_pcixcc.c index 2da8b9381407..b7153c1e15cd 100644 --- a/drivers/s390/crypto/zcrypt_pcixcc.c +++ b/drivers/s390/crypto/zcrypt_pcixcc.c @@ -717,7 +717,7 @@ long zcrypt_pcixcc_send_cprb(struct zcrypt_device *zdev, struct ica_xcRB *xcRB) }; int rc; - ap_msg.message = (void *) kmalloc(PCIXCC_MAX_XCRB_MESSAGE_SIZE, GFP_KERNEL); + ap_msg.message = kmalloc(PCIXCC_MAX_XCRB_MESSAGE_SIZE, GFP_KERNEL); if (!ap_msg.message) return -ENOMEM; ap_msg.psmid = (((unsigned long long) current->pid) << 32) + diff --git a/drivers/s390/net/ctcmain.c b/drivers/s390/net/ctcmain.c index 3257c22dd79c..03cc263fe0da 100644 --- a/drivers/s390/net/ctcmain.c +++ b/drivers/s390/net/ctcmain.c @@ -1646,7 +1646,7 @@ add_channel(struct ccw_device *cdev, enum channel_types type) return -1; } memset(ch, 0, sizeof (struct channel)); - if ((ch->ccw = (struct ccw1 *) kmalloc(8*sizeof(struct ccw1), + if ((ch->ccw = kmalloc(8*sizeof(struct ccw1), GFP_KERNEL | GFP_DMA)) == NULL) { kfree(ch); ctc_pr_warn("ctc: Out of memory in add_channel\n"); @@ -1693,7 +1693,7 @@ add_channel(struct ccw_device *cdev, enum channel_types type) return -1; } fsm_newstate(ch->fsm, CH_STATE_IDLE); - if ((ch->irb = (struct irb *) kmalloc(sizeof (struct irb), + if ((ch->irb = kmalloc(sizeof (struct irb), GFP_KERNEL)) == NULL) { ctc_pr_warn("ctc: Out of memory in add_channel\n"); kfree_fsm(ch->fsm); @@ -2535,7 +2535,7 @@ ctc_print_statistics(struct ctc_priv *priv) DBF_TEXT(trace, 4, __FUNCTION__); if (!priv) return; - sbuf = (char *)kmalloc(2048, GFP_KERNEL); + sbuf = kmalloc(2048, GFP_KERNEL); if (sbuf == NULL) return; p = sbuf; diff --git a/drivers/s390/net/iucv.c b/drivers/s390/net/iucv.c index 1476ce2b437c..229aeb5fc399 100644 --- a/drivers/s390/net/iucv.c +++ b/drivers/s390/net/iucv.c @@ -772,7 +772,7 @@ iucv_register_program (__u8 pgmname[16], } /* Allocate handler entry */ - new_handler = (handler *)kmalloc(sizeof(handler), GFP_ATOMIC); + new_handler = kmalloc(sizeof(handler), GFP_ATOMIC); if (new_handler == NULL) { printk(KERN_WARNING "%s: storage allocation for new handler " "failed.\n", __FUNCTION__); diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c index 5d39b2df0cc4..85093b71f9fa 100644 --- a/drivers/s390/scsi/zfcp_aux.c +++ b/drivers/s390/scsi/zfcp_aux.c @@ -237,7 +237,7 @@ zfcp_device_setup(char *devstr) return 0; len = strlen(devstr) + 1; - str = (char *) kmalloc(len, GFP_KERNEL); + str = kmalloc(len, GFP_KERNEL); if (!str) goto err_out; memcpy(str, devstr, len); diff --git a/drivers/sbus/char/vfc_dev.c b/drivers/sbus/char/vfc_dev.c index 2722af5d3404..386e7de0b7e3 100644 --- a/drivers/sbus/char/vfc_dev.c +++ b/drivers/sbus/char/vfc_dev.c @@ -659,7 +659,7 @@ static int vfc_probe(void) if (!cards) return -ENODEV; - vfc_dev_lst = (struct vfc_dev **)kmalloc(sizeof(struct vfc_dev *) * + vfc_dev_lst = kmalloc(sizeof(struct vfc_dev *) * (cards+1), GFP_KERNEL); if (vfc_dev_lst == NULL) diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c index ac108f9e2674..426cd6f49f5d 100644 --- a/drivers/scsi/aacraid/aachba.c +++ b/drivers/scsi/aacraid/aachba.c @@ -288,7 +288,7 @@ int aac_get_containers(struct aac_dev *dev) if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS) maximum_num_containers = MAXIMUM_NUM_CONTAINERS; - fsa_dev_ptr = (struct fsa_dev_info *) kmalloc( + fsa_dev_ptr = kmalloc( sizeof(*fsa_dev_ptr) * maximum_num_containers, GFP_KERNEL); if (!fsa_dev_ptr) { aac_fib_free(fibptr); diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c index d5cf8b91a0e7..6d305b2f854e 100644 --- a/drivers/scsi/aacraid/comminit.c +++ b/drivers/scsi/aacraid/comminit.c @@ -386,7 +386,7 @@ struct aac_dev *aac_init_adapter(struct aac_dev *dev) * Ok now init the communication subsystem */ - dev->queues = (struct aac_queue_block *) kmalloc(sizeof(struct aac_queue_block), GFP_KERNEL); + dev->queues = kmalloc(sizeof(struct aac_queue_block), GFP_KERNEL); if (dev->queues == NULL) { printk(KERN_ERR "Error could not allocate comm region.\n"); return NULL; diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c index d7a61a6bdaae..1d239f6c0103 100644 --- a/drivers/scsi/aha1542.c +++ b/drivers/scsi/aha1542.c @@ -699,7 +699,7 @@ static int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *)) #endif int i; ccb[mbo].op = 2; /* SCSI Initiator Command w/scatter-gather */ - SCpnt->host_scribble = (unsigned char *) kmalloc(512, GFP_KERNEL | GFP_DMA); + SCpnt->host_scribble = kmalloc(512, GFP_KERNEL | GFP_DMA); sgpnt = (struct scatterlist *) SCpnt->request_buffer; cptr = (struct chain *) SCpnt->host_scribble; if (cptr == NULL) { diff --git a/drivers/scsi/aic7xxx_old.c b/drivers/scsi/aic7xxx_old.c index 46eed10b25d9..7d1fec620948 100644 --- a/drivers/scsi/aic7xxx_old.c +++ b/drivers/scsi/aic7xxx_old.c @@ -2565,7 +2565,7 @@ aic7xxx_allocate_scb(struct aic7xxx_host *p) } } scb_count = min( (i-1), p->scb_data->maxscbs - p->scb_data->numscbs); - scb_ap = (struct aic7xxx_scb *)kmalloc(sizeof (struct aic7xxx_scb) * scb_count + scb_ap = kmalloc(sizeof (struct aic7xxx_scb) * scb_count + sizeof(struct aic7xxx_scb_dma), GFP_ATOMIC); if (scb_ap == NULL) return(0); diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c index e95b367d09ed..a965ed3548d5 100644 --- a/drivers/scsi/dc395x.c +++ b/drivers/scsi/dc395x.c @@ -4319,7 +4319,7 @@ static int __devinit adapter_sg_tables_alloc(struct AdapterCtlBlk *acb) dprintkdbg(DBG_1, "Allocate %i pages for SG tables\n", pages); while (pages--) { - ptr = (struct SGentry *)kmalloc(PAGE_SIZE, GFP_KERNEL); + ptr = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!ptr) { adapter_sg_tables_free(acb); return 1; diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c index 60b1b434eba7..365db537a28d 100644 --- a/drivers/scsi/dpt_i2o.c +++ b/drivers/scsi/dpt_i2o.c @@ -297,7 +297,7 @@ static void adpt_inquiry(adpt_hba* pHba) s32 rcode; memset(msg, 0, sizeof(msg)); - buf = (u8*)kmalloc(80,GFP_KERNEL|ADDR32); + buf = kmalloc(80,GFP_KERNEL|ADDR32); if(!buf){ printk(KERN_ERR"%s: Could not allocate buffer\n",pHba->name); return; @@ -1311,7 +1311,7 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba) schedule_timeout_uninterruptible(1); } while (m == EMPTY_QUEUE); - status = (u8*)kmalloc(4, GFP_KERNEL|ADDR32); + status = kmalloc(4, GFP_KERNEL|ADDR32); if(status == NULL) { adpt_send_nop(pHba, m); printk(KERN_ERR"IOP reset failed - no free memory.\n"); @@ -1444,7 +1444,7 @@ static int adpt_i2o_parse_lct(adpt_hba* pHba) } continue; } - d = (struct i2o_device *)kmalloc(sizeof(struct i2o_device), GFP_KERNEL); + d = kmalloc(sizeof(struct i2o_device), GFP_KERNEL); if(d==NULL) { printk(KERN_CRIT"%s: Out of memory for I2O device data.\n",pHba->name); @@ -2425,7 +2425,7 @@ static s32 adpt_i2o_reparse_lct(adpt_hba* pHba) pDev = pDev->next_lun; } if(!pDev ) { // Something new add it - d = (struct i2o_device *)kmalloc(sizeof(struct i2o_device), GFP_KERNEL); + d = kmalloc(sizeof(struct i2o_device), GFP_KERNEL); if(d==NULL) { printk(KERN_CRIT "Out of memory for I2O device data.\n"); @@ -2728,7 +2728,7 @@ static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba) kfree(pHba->reply_pool); - pHba->reply_pool = (u32*)kmalloc(pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4, GFP_KERNEL|ADDR32); + pHba->reply_pool = kmalloc(pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4, GFP_KERNEL|ADDR32); if(!pHba->reply_pool){ printk(KERN_ERR"%s: Could not allocate reply pool\n",pHba->name); return -1; diff --git a/drivers/scsi/initio.c b/drivers/scsi/initio.c index f160357e37a6..d561663fb4e4 100644 --- a/drivers/scsi/initio.c +++ b/drivers/scsi/initio.c @@ -2828,7 +2828,7 @@ static int i91u_detect(struct scsi_host_template * tpnt) for (; tul_num_scb >= MAX_TARGETS + 3; tul_num_scb--) { i = tul_num_ch * tul_num_scb * sizeof(SCB); - if ((tul_scb = (SCB *) kmalloc(i, GFP_ATOMIC | GFP_DMA)) != NULL) + if ((tul_scb = kmalloc(i, GFP_ATOMIC | GFP_DMA)) != NULL) break; } if (tul_scb == NULL) { diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c index 824fe080d1dc..7d2311067903 100644 --- a/drivers/scsi/osst.c +++ b/drivers/scsi/osst.c @@ -5777,7 +5777,7 @@ static int osst_probe(struct device *dev) dev_num = i; /* allocate a struct osst_tape for this device */ - tpnt = (struct osst_tape *)kmalloc(sizeof(struct osst_tape), GFP_ATOMIC); + tpnt = kmalloc(sizeof(struct osst_tape), GFP_ATOMIC); if (tpnt == NULL) { write_unlock(&os_scsi_tapes_lock); printk(KERN_ERR "osst :E: Can't allocate device descriptor, device not attached.\n"); diff --git a/drivers/scsi/pluto.c b/drivers/scsi/pluto.c index aa60a5f1fbc3..3b2e1a53e6e2 100644 --- a/drivers/scsi/pluto.c +++ b/drivers/scsi/pluto.c @@ -117,7 +117,7 @@ int __init pluto_detect(struct scsi_host_template *tpnt) #endif return 0; } - fcs = (struct ctrl_inquiry *) kmalloc (sizeof (struct ctrl_inquiry) * fcscount, GFP_DMA); + fcs = kmalloc(sizeof (struct ctrl_inquiry) * fcscount, GFP_DMA); if (!fcs) { printk ("PLUTO: Not enough memory to probe\n"); return 0; diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c index d1268cb46837..0578ba42718b 100644 --- a/drivers/scsi/sr_ioctl.c +++ b/drivers/scsi/sr_ioctl.c @@ -546,7 +546,7 @@ int sr_is_xa(Scsi_CD *cd) if (!xa_test) return 0; - raw_sector = (unsigned char *) kmalloc(2048, GFP_KERNEL | SR_GFP_DMA(cd)); + raw_sector = kmalloc(2048, GFP_KERNEL | SR_GFP_DMA(cd)); if (!raw_sector) return -ENOMEM; if (0 == sr_read_sector(cd, cd->ms_offset + 16, diff --git a/drivers/scsi/sr_vendor.c b/drivers/scsi/sr_vendor.c index a3e9d0f2eb5b..4eb3da996b36 100644 --- a/drivers/scsi/sr_vendor.c +++ b/drivers/scsi/sr_vendor.c @@ -117,7 +117,7 @@ int sr_set_blocklength(Scsi_CD *cd, int blocklength) density = (blocklength > 2048) ? 0x81 : 0x83; #endif - buffer = (unsigned char *) kmalloc(512, GFP_KERNEL | GFP_DMA); + buffer = kmalloc(512, GFP_KERNEL | GFP_DMA); if (!buffer) return -ENOMEM; @@ -164,7 +164,7 @@ int sr_cd_check(struct cdrom_device_info *cdi) if (cd->cdi.mask & CDC_MULTI_SESSION) return 0; - buffer = (unsigned char *) kmalloc(512, GFP_KERNEL | GFP_DMA); + buffer = kmalloc(512, GFP_KERNEL | GFP_DMA); if (!buffer) return -ENOMEM; diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.c b/drivers/scsi/sym53c8xx_2/sym_hipd.c index 940fa1e6f994..21cd4c7f5289 100644 --- a/drivers/scsi/sym53c8xx_2/sym_hipd.c +++ b/drivers/scsi/sym53c8xx_2/sym_hipd.c @@ -5545,7 +5545,7 @@ int sym_hcb_attach(struct Scsi_Host *shost, struct sym_fw *fw, struct sym_nvram /* * Allocate the array of lists of CCBs hashed by DSA. */ - np->ccbh = kcalloc(sizeof(struct sym_ccb **), CCB_HASH_SIZE, GFP_KERNEL); + np->ccbh = kcalloc(CCB_HASH_SIZE, sizeof(struct sym_ccb **), GFP_KERNEL); if (!np->ccbh) goto attach_failed; diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 72f3db99ff94..3e0abbb49fe1 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c @@ -598,7 +598,7 @@ at91_ep_alloc_request(struct usb_ep *_ep, unsigned int gfp_flags) { struct at91_request *req; - req = kcalloc(1, sizeof (struct at91_request), gfp_flags); + req = kzalloc(sizeof (struct at91_request), gfp_flags); if (!req) return NULL; diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index 5516c59ed5ec..2d12bf9f19d6 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c @@ -2195,7 +2195,7 @@ static struct gs_buf *gs_buf_alloc(unsigned int size, gfp_t kmalloc_flags) if (size == 0) return NULL; - gb = (struct gs_buf *)kmalloc(sizeof(struct gs_buf), kmalloc_flags); + gb = kmalloc(sizeof(struct gs_buf), kmalloc_flags); if (gb == NULL) return NULL; diff --git a/drivers/usb/host/hc_crisv10.c b/drivers/usb/host/hc_crisv10.c index 9325e46a68c0..282d82efc0b0 100644 --- a/drivers/usb/host/hc_crisv10.c +++ b/drivers/usb/host/hc_crisv10.c @@ -365,7 +365,7 @@ static inline struct urb *urb_list_first(int epid) /* Adds an urb_entry last in the list for this epid. */ static inline void urb_list_add(struct urb *urb, int epid) { - urb_entry_t *urb_entry = (urb_entry_t *)kmalloc(sizeof(urb_entry_t), KMALLOC_FLAG); + urb_entry_t *urb_entry = kmalloc(sizeof(urb_entry_t), KMALLOC_FLAG); assert(urb_entry); urb_entry->urb = urb; diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c index c703f73e1655..6c7f3efb1d40 100644 --- a/drivers/usb/misc/auerswald.c +++ b/drivers/usb/misc/auerswald.c @@ -766,7 +766,7 @@ static int auerbuf_setup (pauerbufctl_t bcp, unsigned int numElements, unsigned bep->bufp = kmalloc (bufsize, GFP_KERNEL); if (!bep->bufp) goto bl_fail; - bep->dr = (struct usb_ctrlrequest *) kmalloc (sizeof (struct usb_ctrlrequest), GFP_KERNEL); + bep->dr = kmalloc(sizeof (struct usb_ctrlrequest), GFP_KERNEL); if (!bep->dr) goto bl_fail; bep->urbp = usb_alloc_urb (0, GFP_KERNEL); @@ -1969,7 +1969,7 @@ static int auerswald_probe (struct usb_interface *intf, info("device is a %s", cp->dev_desc); /* get the maximum allowed control transfer length */ - pbuf = (__le16 *) kmalloc (2, GFP_KERNEL); /* use an allocated buffer because of urb target */ + pbuf = kmalloc(2, GFP_KERNEL); /* use an allocated buffer because of urb target */ if (!pbuf) { err( "out of memory"); goto pfail; diff --git a/drivers/usb/misc/uss720.c b/drivers/usb/misc/uss720.c index 7e8a0acd52ee..70250252ae2a 100644 --- a/drivers/usb/misc/uss720.c +++ b/drivers/usb/misc/uss720.c @@ -705,7 +705,7 @@ static int uss720_probe(struct usb_interface *intf, /* * Allocate parport interface */ - if (!(priv = kcalloc(sizeof(struct parport_uss720_private), 1, GFP_KERNEL))) { + if (!(priv = kzalloc(sizeof(struct parport_uss720_private), GFP_KERNEL))) { usb_put_dev(usbdev); return -ENOMEM; } diff --git a/drivers/usb/net/rndis_host.c b/drivers/usb/net/rndis_host.c index 99f26b3e502f..ea5f44de3de2 100644 --- a/drivers/usb/net/rndis_host.c +++ b/drivers/usb/net/rndis_host.c @@ -469,7 +469,7 @@ static void rndis_unbind(struct usbnet *dev, struct usb_interface *intf) struct rndis_halt *halt; /* try to clear any rndis state/activity (no i/o from stack!) */ - halt = kcalloc(1, sizeof *halt, GFP_KERNEL); + halt = kzalloc(sizeof *halt, GFP_KERNEL); if (halt) { halt->msg_type = RNDIS_MSG_HALT; halt->msg_len = ccpu2(sizeof *halt); diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c index a1fdb85b8c0a..45cdf9bc43b2 100644 --- a/drivers/usb/serial/cypress_m8.c +++ b/drivers/usb/serial/cypress_m8.c @@ -1493,7 +1493,7 @@ static struct cypress_buf *cypress_buf_alloc(unsigned int size) if (size == 0) return NULL; - cb = (struct cypress_buf *)kmalloc(sizeof(struct cypress_buf), GFP_KERNEL); + cb = kmalloc(sizeof(struct cypress_buf), GFP_KERNEL); if (cb == NULL) return NULL; diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index 9d9ea874639c..efd9ce3f931f 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c @@ -1681,7 +1681,7 @@ dbg( "digi_startup: TOP" ); for( i=0; i<serial->type->num_ports+1; i++ ) { /* allocate port private structure */ - priv = (struct digi_port *)kmalloc( sizeof(struct digi_port), + priv = kmalloc( sizeof(struct digi_port), GFP_KERNEL ); if( priv == (struct digi_port *)0 ) { while( --i >= 0 ) @@ -1714,7 +1714,7 @@ dbg( "digi_startup: TOP" ); } /* allocate serial private structure */ - serial_priv = (struct digi_serial *)kmalloc( sizeof(struct digi_serial), + serial_priv = kmalloc( sizeof(struct digi_serial), GFP_KERNEL ); if( serial_priv == (struct digi_serial *)0 ) { for( i=0; i<serial->type->num_ports+1; i++ ) diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index 2da2684e0809..980285c0233a 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c @@ -2811,7 +2811,7 @@ static struct edge_buf *edge_buf_alloc(unsigned int size) if (size == 0) return NULL; - eb = (struct edge_buf *)kmalloc(sizeof(struct edge_buf), GFP_KERNEL); + eb = kmalloc(sizeof(struct edge_buf), GFP_KERNEL); if (eb == NULL) return NULL; diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c index d72cf8bc7f76..42f757a5b876 100644 --- a/drivers/usb/serial/ipaq.c +++ b/drivers/usb/serial/ipaq.c @@ -595,7 +595,7 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp) bytes_in = 0; bytes_out = 0; - priv = (struct ipaq_private *)kmalloc(sizeof(struct ipaq_private), GFP_KERNEL); + priv = kmalloc(sizeof(struct ipaq_private), GFP_KERNEL); if (priv == NULL) { err("%s - Out of memory", __FUNCTION__); return -ENOMEM; diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c index e284d6c0fd35..62bea0c923bd 100644 --- a/drivers/usb/serial/kobil_sct.c +++ b/drivers/usb/serial/kobil_sct.c @@ -269,7 +269,7 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp) } // allocate memory for write_urb transfer buffer - port->write_urb->transfer_buffer = (unsigned char *) kmalloc(write_urb_transfer_buffer_length, GFP_KERNEL); + port->write_urb->transfer_buffer = kmalloc(write_urb_transfer_buffer_length, GFP_KERNEL); if (! port->write_urb->transfer_buffer) { kfree(transfer_buffer); usb_free_urb(port->write_urb); @@ -696,7 +696,7 @@ static int kobil_ioctl(struct usb_serial_port *port, struct file *file, return 0; case TCFLSH: // 0x540B - transfer_buffer = (unsigned char *) kmalloc(transfer_buffer_length, GFP_KERNEL); + transfer_buffer = kmalloc(transfer_buffer_length, GFP_KERNEL); if (! transfer_buffer) { return -ENOBUFS; } diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index d124d780e42e..5dc2ac9afa90 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -159,7 +159,7 @@ static struct pl2303_buf *pl2303_buf_alloc(unsigned int size) if (size == 0) return NULL; - pb = (struct pl2303_buf *)kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL); + pb = kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL); if (pb == NULL) return NULL; diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index f42eb9ea6405..83189005c6fb 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c @@ -1710,7 +1710,7 @@ static struct circ_buf *ti_buf_alloc(void) { struct circ_buf *cb; - cb = (struct circ_buf *)kmalloc(sizeof(struct circ_buf), GFP_KERNEL); + cb = kmalloc(sizeof(struct circ_buf), GFP_KERNEL); if (cb == NULL) return NULL; diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c index dc45e58e2b8c..5483d8564c1b 100644 --- a/drivers/usb/serial/whiteheat.c +++ b/drivers/usb/serial/whiteheat.c @@ -416,7 +416,7 @@ static int whiteheat_attach (struct usb_serial *serial) for (i = 0; i < serial->num_ports; i++) { port = serial->port[i]; - info = (struct whiteheat_private *)kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL); + info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL); if (info == NULL) { err("%s: Out of memory for port structures\n", serial->type->description); goto no_private; @@ -487,7 +487,7 @@ static int whiteheat_attach (struct usb_serial *serial) usb_set_serial_port_data(port, info); } - command_info = (struct whiteheat_command_private *)kmalloc(sizeof(struct whiteheat_command_private), GFP_KERNEL); + command_info = kmalloc(sizeof(struct whiteheat_command_private), GFP_KERNEL); if (command_info == NULL) { err("%s: Out of memory for port structures\n", serial->type->description); goto no_command_private; diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c index fb8bacaae27c..e3528eca29a5 100644 --- a/drivers/usb/storage/sddr09.c +++ b/drivers/usb/storage/sddr09.c @@ -646,7 +646,7 @@ sddr09_read_sg_test_only(struct us_data *us) { return result; } - buf = (unsigned char *) kmalloc(bulklen, GFP_NOIO); + buf = kmalloc(bulklen, GFP_NOIO); if (!buf) return -ENOMEM; diff --git a/drivers/video/amba-clcd.c b/drivers/video/amba-clcd.c index 6761b68c35e9..6c9dc2e69c82 100644 --- a/drivers/video/amba-clcd.c +++ b/drivers/video/amba-clcd.c @@ -447,7 +447,7 @@ static int clcdfb_probe(struct amba_device *dev, void *id) goto out; } - fb = (struct clcd_fb *) kmalloc(sizeof(struct clcd_fb), GFP_KERNEL); + fb = kmalloc(sizeof(struct clcd_fb), GFP_KERNEL); if (!fb) { printk(KERN_INFO "CLCD: could not allocate new clcd_fb struct\n"); ret = -ENOMEM; diff --git a/drivers/video/amifb.c b/drivers/video/amifb.c index 88a47845c4f7..1a849b870bcc 100644 --- a/drivers/video/amifb.c +++ b/drivers/video/amifb.c @@ -2906,14 +2906,6 @@ static int ami_decode_var(struct fb_var_screeninfo *var, par->crsr.spot_x = par->crsr.spot_y = 0; par->crsr.height = par->crsr.width = 0; -#if 0 /* fbmon not done. uncomment for 2.5.x -brad */ - if (!fbmon_valid_timings(pixclock[clk_shift], htotal, vtotal, - &fb_info)) { - DPRINTK("mode doesn't fit for monitor\n"); - return -EINVAL; - } -#endif - return 0; } diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c index 176f9b85cdbe..09684d7a7ce9 100644 --- a/drivers/video/aty/atyfb_base.c +++ b/drivers/video/aty/atyfb_base.c @@ -1488,10 +1488,6 @@ static int atyfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) else info->var.accel_flags = 0; -#if 0 /* fbmon is not done. uncomment for 2.5.x -brad */ - if (!fbmon_valid_timings(pixclock, htotal, vtotal, info)) - return -EINVAL; -#endif aty_crtc_to_var(&crtc, var); var->pixclock = par->pll_ops->pll_to_var(info, &pll); return 0; diff --git a/drivers/video/matrox/i2c-matroxfb.c b/drivers/video/matrox/i2c-matroxfb.c index 797b42305b0f..fe28848e7b52 100644 --- a/drivers/video/matrox/i2c-matroxfb.c +++ b/drivers/video/matrox/i2c-matroxfb.c @@ -146,7 +146,7 @@ static void* i2c_matroxfb_probe(struct matrox_fb_info* minfo) { unsigned long flags; struct matroxfb_dh_maven_info* m2info; - m2info = (struct matroxfb_dh_maven_info*)kmalloc(sizeof(*m2info), GFP_KERNEL); + m2info = kmalloc(sizeof(*m2info), GFP_KERNEL); if (!m2info) return NULL; diff --git a/drivers/video/matrox/matroxfb_base.c b/drivers/video/matrox/matroxfb_base.c index e9b4115fcad0..cb2aa402ddfd 100644 --- a/drivers/video/matrox/matroxfb_base.c +++ b/drivers/video/matrox/matroxfb_base.c @@ -2028,7 +2028,7 @@ static int matroxfb_probe(struct pci_dev* pdev, const struct pci_device_id* dumm } #ifdef CONFIG_FB_MATROX_MULTIHEAD - minfo = (struct matrox_fb_info*)kmalloc(sizeof(*minfo), GFP_KERNEL); + minfo = kmalloc(sizeof(*minfo), GFP_KERNEL); if (!minfo) return -1; #else diff --git a/drivers/video/matrox/matroxfb_crtc2.c b/drivers/video/matrox/matroxfb_crtc2.c index 27eb4bb4f89f..2c9801090fae 100644 --- a/drivers/video/matrox/matroxfb_crtc2.c +++ b/drivers/video/matrox/matroxfb_crtc2.c @@ -694,7 +694,7 @@ static void* matroxfb_crtc2_probe(struct matrox_fb_info* minfo) { /* hardware is CRTC2 incapable... */ if (!ACCESS_FBINFO(devflags.crtc2)) return NULL; - m2info = (struct matroxfb_dh_fb_info*)kmalloc(sizeof(*m2info), GFP_KERNEL); + m2info = kmalloc(sizeof(*m2info), GFP_KERNEL); if (!m2info) { printk(KERN_ERR "matroxfb_crtc2: Not enough memory for CRTC2 control structs\n"); return NULL; diff --git a/drivers/video/sstfb.c b/drivers/video/sstfb.c index 711cb11d6eb3..59cd1e750f30 100644 --- a/drivers/video/sstfb.c +++ b/drivers/video/sstfb.c @@ -21,6 +21,11 @@ * Remove never finished and bogus 24/32bit support * Clean up macro abuse * Minor tidying for format. + * 12/2006 Helge Deller <deller@gmx.de> + * add /sys/class/graphics/fbX/vgapass sysfs-interface + * add module option "mode_option" to set initial screen mode + * use fbdev default videomode database + * remove debug functions from ioctl */ /* @@ -65,19 +70,10 @@ * * sstfb specific ioctls: * toggle vga (0x46db) : toggle vga_pass_through - * fill fb (0x46dc) : fills fb - * test disp (0x46de) : draws a test image */ #undef SST_DEBUG -/* - Default video mode . - 0 800x600@60 took from glide - 1 640x480@75 took from glide - 2 1024x768@76 std fb.mode - 3 640x480@60 glide default */ -#define DEFAULT_MODE 3 /* * Includes @@ -92,20 +88,24 @@ #include <linux/init.h> #include <linux/slab.h> #include <asm/io.h> -#include <asm/ioctl.h> #include <asm/uaccess.h> #include <video/sstfb.h> /* initialized by setup */ -static int vgapass; /* enable Vga passthrough cable */ +static int vgapass; /* enable VGA passthrough cable */ static int mem; /* mem size in MB, 0 = autodetect */ static int clipping = 1; /* use clipping (slower, safer) */ static int gfxclk; /* force FBI freq in Mhz . Dangerous */ static int slowpci; /* slow PCI settings */ -static char *mode_option __devinitdata; +/* + Possible default video modes: 800x600@60, 640x480@75, 1024x768@76, 640x480@60 +*/ +#define DEFAULT_VIDEO_MODE "640x480@60" + +static char *mode_option __devinitdata = DEFAULT_VIDEO_MODE; enum { ID_VOODOO1 = 0, @@ -119,48 +119,11 @@ static struct sst_spec voodoo_spec[] __devinitdata = { { .name = "Voodoo2", .default_gfx_clock = 75000, .max_gfxclk = 85 }, }; -static struct fb_var_screeninfo sstfb_default = -#if ( DEFAULT_MODE == 0 ) - { /* 800x600@60, 16 bpp .borowed from glide/sst1/include/sst1init.h */ - 800, 600, 800, 600, 0, 0, 16, 0, - {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, - 0, 0, -1, -1, 0, - 25000, 86, 41, 23, 1, 127, 4, - 0, FB_VMODE_NONINTERLACED }; -#elif ( DEFAULT_MODE == 1 ) - {/* 640x480@75, 16 bpp .borowed from glide/sst1/include/sst1init.h */ - 640, 480, 640, 480, 0, 0, 16, 0, - {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, - 0, 0, -1, -1, 0, - 31746, 118, 17, 16, 1, 63, 3, - 0, FB_VMODE_NONINTERLACED }; -#elif ( DEFAULT_MODE == 2 ) - { /* 1024x768@76 took from my /etc/fb.modes */ - 1024, 768, 1024, 768,0, 0, 16,0, - {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, - 0, 0, -1, -1, 0, - 11764, 208, 8, 36, 16, 120, 3 , - 0, FB_VMODE_NONINTERLACED }; -#elif ( DEFAULT_MODE == 3 ) - { /* 640x480@60 , 16bpp glide default ?*/ - 640, 480, 640, 480, 0, 0, 16, 0, - {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, - 0, 0, -1, -1, 0, - 39721 , 38, 26 , 25 ,18 , 96 ,2, - 0, FB_VMODE_NONINTERLACED }; -#elif - #error "Invalid DEFAULT_MODE value !" -#endif - /* * debug functions */ -static void sstfb_drawdebugimage(struct fb_info *info); -static int sstfb_dump_regs(struct fb_info *info); - - #if (SST_DEBUG_REG > 0) static void sst_dbg_print_read_reg(u32 reg, u32 val) { const char *regname; @@ -726,51 +689,77 @@ static int sstfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, return 0; } -static int sstfb_ioctl(struct fb_info *info, u_int cmd, u_long arg) +static void sstfb_setvgapass( struct fb_info *info, int enable ) { struct sstfb_par *par = info->par; struct pci_dev *sst_dev = par->dev; - u32 fbiinit0, tmp, val; - u_long p; + u32 fbiinit0, tmp; + + enable = enable ? 1:0; + if (par->vgapass == enable) + return; + par->vgapass = enable; + + pci_read_config_dword(sst_dev, PCI_INIT_ENABLE, &tmp); + pci_write_config_dword(sst_dev, PCI_INIT_ENABLE, + tmp | PCI_EN_INIT_WR ); + fbiinit0 = sst_read (FBIINIT0); + if (par->vgapass) { + sst_write(FBIINIT0, fbiinit0 & ~DIS_VGA_PASSTHROUGH); + printk(KERN_INFO "fb%d: Enabling VGA pass-through\n", info->node ); + } else { + sst_write(FBIINIT0, fbiinit0 | DIS_VGA_PASSTHROUGH); + printk(KERN_INFO "fb%d: Disabling VGA pass-through\n", info->node ); + } + pci_write_config_dword(sst_dev, PCI_INIT_ENABLE, tmp); +} + +static ssize_t store_vgapass(struct device *device, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct fb_info *info = dev_get_drvdata(device); + char ** last = NULL; + int val; + + val = simple_strtoul(buf, last, 0); + sstfb_setvgapass(info, val); + + return count; +} + +static ssize_t show_vgapass(struct device *device, struct device_attribute *attr, + char *buf) +{ + struct fb_info *info = dev_get_drvdata(device); + struct sstfb_par *par = info->par; + return snprintf(buf, PAGE_SIZE, "%d\n", par->vgapass); +} + +static struct device_attribute device_attrs[] = { + __ATTR(vgapass, S_IRUGO|S_IWUSR, show_vgapass, store_vgapass) + }; + +static int sstfb_ioctl(struct fb_info *info, unsigned int cmd, + unsigned long arg) +{ + struct sstfb_par *par; + u32 val; switch (cmd) { - - /* dump current FBIINIT values to system log */ - case _IO('F', 0xdb): /* 0x46db */ - return sstfb_dump_regs(info); - - /* fills lfb with #arg pixels */ - case _IOW('F', 0xdc, u32): /* 0x46dc */ + /* set/get VGA pass_through mode */ + case SSTFB_SET_VGAPASS: if (copy_from_user(&val, (void __user *)arg, sizeof(val))) return -EFAULT; - if (val > info->fix.smem_len) - val = info->fix.smem_len; - for (p = 0 ; p < val; p += 2) - writew(p >> 6, info->screen_base + p); + sstfb_setvgapass(info, val); return 0; - - /* change VGA pass_through mode */ - case _IOW('F', 0xdd, u32): /* 0x46dd */ - if (copy_from_user(&val, (void __user *)arg, sizeof(val))) + case SSTFB_GET_VGAPASS: + par = info->par; + val = par->vgapass; + if (copy_to_user((void __user *)arg, &val, sizeof(val))) return -EFAULT; - pci_read_config_dword(sst_dev, PCI_INIT_ENABLE, &tmp); - pci_write_config_dword(sst_dev, PCI_INIT_ENABLE, - tmp | PCI_EN_INIT_WR ); - fbiinit0 = sst_read (FBIINIT0); - if (val) - sst_write(FBIINIT0, fbiinit0 & ~EN_VGA_PASSTHROUGH); - else - sst_write(FBIINIT0, fbiinit0 | EN_VGA_PASSTHROUGH); - pci_write_config_dword(sst_dev, PCI_INIT_ENABLE, tmp); - return 0; - - /* draw test image */ - case _IO('F', 0xde): /* 0x46de */ - f_dprintk("test color display at %d bpp\n", - info->var.bits_per_pixel); - sstfb_drawdebugimage(info); return 0; } + return -EINVAL; } @@ -804,6 +793,7 @@ static void sstfb_copyarea(struct fb_info *info, const struct fb_copyarea *area) /* * FillRect 2D command (solidfill or invert (via ROP_XOR)) - Voodoo2 only */ +#if 0 static void sstfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) { struct sstfb_par *par = info->par; @@ -825,6 +815,7 @@ static void sstfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) | (BLT_16BPP_FMT << 3) /* | BIT(14) */ | BIT(15) | BIT(16) ); sst_wait_idle(); } +#endif @@ -1156,6 +1147,7 @@ static int __devinit sst_init(struct fb_info *info, struct sstfb_par *par) struct pll_timing gfx_timings; struct sst_spec *spec; int Fout; + int gfx_clock; spec = &voodoo_spec[par->type]; f_ddprintk(" fbiinit0 fbiinit1 fbiinit2 fbiinit3 fbiinit4 " @@ -1196,15 +1188,15 @@ static int __devinit sst_init(struct fb_info *info, struct sstfb_par *par) } /* set graphic clock */ - par->gfx_clock = spec->default_gfx_clock; + gfx_clock = spec->default_gfx_clock; if ((gfxclk >10 ) && (gfxclk < spec->max_gfxclk)) { printk(KERN_INFO "sstfb: Using supplied graphic freq : %dMHz\n", gfxclk); - par->gfx_clock = gfxclk *1000; + gfx_clock = gfxclk *1000; } else if (gfxclk) { printk(KERN_WARNING "sstfb: %dMhz is way out of spec! Using default\n", gfxclk); } - sst_calc_pll(par->gfx_clock, &Fout, &gfx_timings); + sst_calc_pll(gfx_clock, &Fout, &gfx_timings); par->dac_sw.set_pll(info, &gfx_timings, GFX_CLOCK); /* disable fbiinit remap */ @@ -1215,10 +1207,11 @@ static int __devinit sst_init(struct fb_info *info, struct sstfb_par *par) fbiinit0 = FBIINIT0_DEFAULT; fbiinit1 = FBIINIT1_DEFAULT; fbiinit4 = FBIINIT4_DEFAULT; - if (vgapass) - fbiinit0 &= ~EN_VGA_PASSTHROUGH; + par->vgapass = vgapass; + if (par->vgapass) + fbiinit0 &= ~DIS_VGA_PASSTHROUGH; else - fbiinit0 |= EN_VGA_PASSTHROUGH; + fbiinit0 |= DIS_VGA_PASSTHROUGH; if (slowpci) { fbiinit1 |= SLOW_PCI_WRITES; fbiinit4 |= SLOW_PCI_READS; @@ -1267,7 +1260,7 @@ static void __devexit sst_shutdown(struct fb_info *info) /* TODO maybe shutdown the dac, vrefresh and so on... */ pci_write_config_dword(dev, PCI_INIT_ENABLE, PCI_EN_INIT_WR); - sst_unset_bits(FBIINIT0, FBI_RESET | FIFO_RESET | EN_VGA_PASSTHROUGH); + sst_unset_bits(FBIINIT0, FBI_RESET | FIFO_RESET | DIS_VGA_PASSTHROUGH); pci_write_config_dword(dev, PCI_VCLK_DISABLE,0); /* maybe keep fbiinit* and PCI_INIT_enable in the fb_info struct * from start ? */ @@ -1278,8 +1271,7 @@ static void __devexit sst_shutdown(struct fb_info *info) /* * Interface to the world */ -#ifndef MODULE -static int __init sstfb_setup(char *options) +static int __devinit sstfb_setup(char *options) { char *this_opt; @@ -1312,7 +1304,7 @@ static int __init sstfb_setup(char *options) } return 0; } -#endif + static struct fb_ops sstfb_ops = { .owner = THIS_MODULE, @@ -1416,15 +1408,10 @@ static int __devinit sstfb_probe(struct pci_dev *pdev, */ fix->line_length = 2048; /* default value, for 24 or 32bit: 4096 */ - if ( mode_option && - fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 16)) { - printk(KERN_ERR "sstfb: can't set supplied video mode. Using default\n"); - info->var = sstfb_default; - } else - info->var = sstfb_default; + fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 16); if (sstfb_check_var(&info->var, info)) { - printk(KERN_ERR "sstfb: invalid default video mode.\n"); + printk(KERN_ERR "sstfb: invalid video mode.\n"); goto fail; } @@ -1442,10 +1429,11 @@ static int __devinit sstfb_probe(struct pci_dev *pdev, goto fail; } - if (1) /* set to 0 to see an initial bitmap instead */ - sstfb_clear_screen(info); - else - sstfb_drawdebugimage(info); + sstfb_clear_screen(info); + + if (device_create_file(info->dev, &device_attrs[0])) + printk(KERN_WARNING "sstfb: can't create sysfs entry.\n"); + printk(KERN_INFO "fb%d: %s frame buffer device at 0x%p\n", info->node, fix->id, info->screen_base); @@ -1453,6 +1441,7 @@ static int __devinit sstfb_probe(struct pci_dev *pdev, return 0; fail: + fb_dealloc_cmap(&info->cmap); iounmap(info->screen_base); fail_fb_remap: iounmap(par->mmio_vbase); @@ -1473,21 +1462,23 @@ static void __devexit sstfb_remove(struct pci_dev *pdev) info = pci_get_drvdata(pdev); par = info->par; + device_remove_file(info->dev, &device_attrs[0]); sst_shutdown(info); - unregister_framebuffer(info); iounmap(info->screen_base); iounmap(par->mmio_vbase); release_mem_region(info->fix.smem_start, 0x400000); release_mem_region(info->fix.mmio_start, info->fix.mmio_len); + fb_dealloc_cmap(&info->cmap); + unregister_framebuffer(info); framebuffer_release(info); } -static struct pci_device_id sstfb_id_tbl[] = { - { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO, - PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_VOODOO1 }, - { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO2, - PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_VOODOO2 }, +static const struct pci_device_id sstfb_id_tbl[] = { + { PCI_DEVICE(PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO ), + .driver_data = ID_VOODOO1, }, + { PCI_DEVICE(PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO2), + .driver_data = ID_VOODOO2, }, { 0 }, }; @@ -1501,142 +1492,23 @@ static struct pci_driver sstfb_driver = { static int __devinit sstfb_init(void) { -#ifndef MODULE char *option = NULL; if (fb_get_options("sstfb", &option)) return -ENODEV; sstfb_setup(option); -#endif + return pci_register_driver(&sstfb_driver); } -#ifdef MODULE static void __devexit sstfb_exit(void) { pci_unregister_driver(&sstfb_driver); } -#endif -/* - * testing and debugging functions - */ - -static int sstfb_dump_regs(struct fb_info *info) -{ -#ifdef SST_DEBUG - static struct { u32 reg ; const char *reg_name;} pci_regs[] = { - { PCI_INIT_ENABLE, "initenable"}, - { PCI_VCLK_ENABLE, "enable vclk"}, - { PCI_VCLK_DISABLE, "disable vclk"}, - }; - - static struct { u32 reg ; const char *reg_name;} sst_regs[] = { - {FBIINIT0,"fbiinit0"}, - {FBIINIT1,"fbiinit1"}, - {FBIINIT2,"fbiinit2"}, - {FBIINIT3,"fbiinit3"}, - {FBIINIT4,"fbiinit4"}, - {FBIINIT5,"fbiinit5"}, - {FBIINIT6,"fbiinit6"}, - {FBIINIT7,"fbiinit7"}, - {LFBMODE,"lfbmode"}, - {FBZMODE,"fbzmode"}, - }; - - const int pci_s = ARRAY_SIZE(pci_regs); - const int sst_s = ARRAY_SIZE(sst_regs); - struct sstfb_par *par = info->par; - struct pci_dev *dev = par->dev; - u32 pci_res[pci_s]; - u32 sst_res[sst_s]; - int i; - - for (i=0; i<pci_s; i++) { - pci_read_config_dword(dev, pci_regs[i].reg, &pci_res[i]); - } - for (i=0; i<sst_s; i++) { - sst_res[i] = sst_read(sst_regs[i].reg); - } - - dprintk("hardware register dump:\n"); - for (i=0; i<pci_s; i++) { - dprintk("%s %0#10x\n", pci_regs[i].reg_name, pci_res[i]); - } - for (i=0; i<sst_s; i++) { - dprintk("%s %0#10x\n", sst_regs[i].reg_name, sst_res[i]); - } - return 0; -#else - return -EINVAL; -#endif -} - -static void sstfb_fillrect_softw( struct fb_info *info, const struct fb_fillrect *rect) -{ - u8 __iomem *fbbase_virt = info->screen_base; - int x, y, w = info->var.bits_per_pixel == 16 ? 2 : 4; - u32 color = rect->color, height = rect->height; - u8 __iomem *p; - - if (w==2) color |= color<<16; - for (y=rect->dy; height; y++, height--) { - p = fbbase_virt + y*info->fix.line_length + rect->dx*w; - x = rect->width; - if (w==2) x>>=1; - while (x) { - writel(color, p); - p += 4; - x--; - } - } -} - -static void sstfb_drawrect_XY( struct fb_info *info, int x, int y, - int w, int h, int color, int hwfunc) -{ - struct fb_fillrect rect; - rect.dx = x; - rect.dy = y; - rect.height = h; - rect.width = w; - rect.color = color; - rect.rop = ROP_COPY; - if (hwfunc) - sstfb_fillrect(info, &rect); - else - sstfb_fillrect_softw(info, &rect); -} - -/* print some squares on the fb */ -static void sstfb_drawdebugimage(struct fb_info *info) -{ - static int idx; - - /* clear screen */ - sstfb_clear_screen(info); - - idx = (idx+1) & 1; - - /* white rect */ - sstfb_drawrect_XY(info, 0, 0, 50, 50, 0xffff, idx); - - /* blue rect */ - sstfb_drawrect_XY(info, 50, 50, 50, 50, 0x001f, idx); - - /* green rect */ - sstfb_drawrect_XY(info, 100, 100, 80, 80, 0x07e0, idx); - - /* red rect */ - sstfb_drawrect_XY(info, 250, 250, 120, 100, 0xf800, idx); -} - module_init(sstfb_init); - -#ifdef MODULE module_exit(sstfb_exit); -#endif MODULE_AUTHOR("(c) 2000,2002 Ghozlane Toumi <gtoumi@laposte.net>"); MODULE_DESCRIPTION("FBDev driver for 3dfx Voodoo Graphics and Voodoo2 based video boards"); @@ -1652,3 +1524,6 @@ module_param(gfxclk, int, 0); MODULE_PARM_DESC(gfxclk, "Force graphic chip frequency in MHz. DANGEROUS. (default=auto)"); module_param(slowpci, bool, 0); MODULE_PARM_DESC(slowpci, "Uses slow PCI settings (0 or 1) (default=0)"); +module_param(mode_option, charp, 0); +MODULE_PARM_DESC(mode_option, "Initial video mode (default=" DEFAULT_VIDEO_MODE ")"); + diff --git a/drivers/w1/slaves/Kconfig b/drivers/w1/slaves/Kconfig index d18d6424cd21..904e5aeb696c 100644 --- a/drivers/w1/slaves/Kconfig +++ b/drivers/w1/slaves/Kconfig @@ -9,7 +9,7 @@ config W1_SLAVE_THERM tristate "Thermal family implementation" depends on W1 help - Say Y here if you want to connect 1-wire thermal sensors to you + Say Y here if you want to connect 1-wire thermal sensors to your wire. config W1_SLAVE_SMEM @@ -17,7 +17,7 @@ config W1_SLAVE_SMEM depends on W1 help Say Y here if you want to connect 1-wire - simple 64bit memory rom(ds2401/ds2411/ds1990*) to you wire. + simple 64bit memory rom(ds2401/ds2411/ds1990*) to your wire. config W1_SLAVE_DS2433 tristate "4kb EEPROM family support (DS2433)" |