Exemplo n.º 1
0
static void mac53c94_interrupt(int irq, void *dev_id)
{
	struct fsc_state *state = (struct fsc_state *) dev_id;
	struct mac53c94_regs __iomem *regs = state->regs;
	struct dbdma_regs __iomem *dma = state->dma;
	struct scsi_cmnd *cmd = state->current_req;
	int nb, stat, seq, intr;
	static int mac53c94_errors;

	/*
	 * Apparently, reading the interrupt register unlatches
	 * the status and sequence step registers.
	 */
	seq = readb(&regs->seqstep);
	stat = readb(&regs->status);
	intr = readb(&regs->interrupt);

#if 0
	printk(KERN_DEBUG "mac53c94_intr, intr=%x stat=%x seq=%x phase=%d\n",
	       intr, stat, seq, state->phase);
#endif

	if (intr & INTR_RESET) {
		/* SCSI bus was reset */
		printk(KERN_INFO "external SCSI bus reset detected\n");
		writeb(CMD_NOP, &regs->command);
		writel(RUN << 16, &dma->control);	/* stop dma */
		cmd_done(state, DID_RESET << 16);
		return;
	}
	if (intr & INTR_ILL_CMD) {
		printk(KERN_ERR "53c94: invalid cmd, intr=%x stat=%x seq=%x phase=%d\n",
		       intr, stat, seq, state->phase);
		cmd_done(state, DID_ERROR << 16);
		return;
	}
	if (stat & STAT_ERROR) {
#if 0
		/* XXX these seem to be harmless? */
		printk("53c94: bad error, intr=%x stat=%x seq=%x phase=%d\n",
		       intr, stat, seq, state->phase);
#endif
		++mac53c94_errors;
		writeb(CMD_NOP + CMD_DMA_MODE, &regs->command);
	}
	if (cmd == 0) {
		printk(KERN_DEBUG "53c94: interrupt with no command active?\n");
		return;
	}
	if (stat & STAT_PARITY) {
		printk(KERN_ERR "mac53c94: parity error\n");
		cmd_done(state, DID_PARITY << 16);
		return;
	}
	switch (state->phase) {
	case selecting:
		if (intr & INTR_DISCONNECT) {
			/* selection timed out */
			cmd_done(state, DID_BAD_TARGET << 16);
			return;
		}
		if (intr != INTR_BUS_SERV + INTR_DONE) {
			printk(KERN_DEBUG "got intr %x during selection\n", intr);
			cmd_done(state, DID_ERROR << 16);
			return;
		}
		if ((seq & SS_MASK) != SS_DONE) {
			printk(KERN_DEBUG "seq step %x after command\n", seq);
			cmd_done(state, DID_ERROR << 16);
			return;
		}
		writeb(CMD_NOP, &regs->command);
		/* set DMA controller going if any data to transfer */
		if ((stat & (STAT_MSG|STAT_CD)) == 0
		    && (scsi_sg_count(cmd) > 0 || scsi_bufflen(cmd))) {
			nb = cmd->SCp.this_residual;
			if (nb > 0xfff0)
				nb = 0xfff0;
			cmd->SCp.this_residual -= nb;
			writeb(nb, &regs->count_lo);
			writeb(nb >> 8, &regs->count_mid);
			writeb(CMD_DMA_MODE + CMD_NOP, &regs->command);
			writel(virt_to_phys(state->dma_cmds), &dma->cmdptr);
			writel((RUN << 16) | RUN, &dma->control);
			writeb(CMD_DMA_MODE + CMD_XFER_DATA, &regs->command);
			state->phase = dataing;
			break;
		} else if ((stat & STAT_PHASE) == STAT_CD + STAT_IO) {
Exemplo n.º 2
0
static ssize_t ac_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos)
{
    unsigned int NumCard;	/* Board number 1 -> 8           */
    unsigned int IndexCard;	/* Index board number 0 -> 7     */
    unsigned char TicCard;	/* Board TIC to send             */
    unsigned long flags;	/* Current priority              */
    struct st_ram_io st_loc;
    struct mailbox tmpmailbox;
#ifdef DEBUG
    int c;
#endif
    DECLARE_WAITQUEUE(wait, current);

    if (count != sizeof(struct st_ram_io) + sizeof(struct mailbox)) {
        static int warncount = 5;
        if (warncount) {
            printk(KERN_INFO "Hmmm. write() of Applicom card, length %zd != expected %zd\n",
                   count, sizeof(struct st_ram_io) + sizeof(struct mailbox));
            warncount--;
        }
        return -EINVAL;
    }

    if(copy_from_user(&st_loc, buf, sizeof(struct st_ram_io)))
        return -EFAULT;

    if(copy_from_user(&tmpmailbox, &buf[sizeof(struct st_ram_io)],
                      sizeof(struct mailbox)))
        return -EFAULT;

    NumCard = st_loc.num_card;	/* board number to send          */
    TicCard = st_loc.tic_des_from_pc;	/* tic number to send            */
    IndexCard = NumCard - 1;

    if((NumCard < 1) || (NumCard > MAX_BOARD) || !apbs[IndexCard].RamIO)
        return -EINVAL;

#ifdef DEBUG
    printk("Write to applicom card #%d. struct st_ram_io follows:",
           IndexCard+1);

    for (c = 0; c < sizeof(struct st_ram_io);) {

        printk("\n%5.5X: %2.2X", c, ((unsigned char *) &st_loc)[c]);

        for (c++; c % 8 && c < sizeof(struct st_ram_io); c++) {
            printk(" %2.2X", ((unsigned char *) &st_loc)[c]);
        }
    }

    printk("\nstruct mailbox follows:");

    for (c = 0; c < sizeof(struct mailbox);) {
        printk("\n%5.5X: %2.2X", c, ((unsigned char *) &tmpmailbox)[c]);

        for (c++; c % 8 && c < sizeof(struct mailbox); c++) {
            printk(" %2.2X", ((unsigned char *) &tmpmailbox)[c]);
        }
    }

    printk("\n");
#endif

    spin_lock_irqsave(&apbs[IndexCard].mutex, flags);

    /* Test octet ready correct */
    if(readb(apbs[IndexCard].RamIO + DATA_FROM_PC_READY) > 2) {
        Dummy = readb(apbs[IndexCard].RamIO + VERS);
        spin_unlock_irqrestore(&apbs[IndexCard].mutex, flags);
        printk(KERN_WARNING "APPLICOM driver write error board %d, DataFromPcReady = %d\n",
               IndexCard,(int)readb(apbs[IndexCard].RamIO + DATA_FROM_PC_READY));
        DeviceErrorCount++;
        return -EIO;
    }

    /* Place ourselves on the wait queue */
    set_current_state(TASK_INTERRUPTIBLE);
    add_wait_queue(&apbs[IndexCard].FlagSleepSend, &wait);

    /* Check whether the card is ready for us */
    while (readb(apbs[IndexCard].RamIO + DATA_FROM_PC_READY) != 0) {
        Dummy = readb(apbs[IndexCard].RamIO + VERS);
        /* It's busy. Sleep. */

        spin_unlock_irqrestore(&apbs[IndexCard].mutex, flags);
        schedule();
        if (signal_pending(current)) {
            remove_wait_queue(&apbs[IndexCard].FlagSleepSend,
                              &wait);
            return -EINTR;
        }
        spin_lock_irqsave(&apbs[IndexCard].mutex, flags);
        set_current_state(TASK_INTERRUPTIBLE);
    }

    /* We may not have actually slept */
    set_current_state(TASK_RUNNING);
    remove_wait_queue(&apbs[IndexCard].FlagSleepSend, &wait);

    writeb(1, apbs[IndexCard].RamIO + DATA_FROM_PC_READY);

    /* Which is best - lock down the pages with rawio and then
       copy directly, or use bounce buffers? For now we do the latter
       because it works with 2.2 still */
    {
        unsigned char *from = (unsigned char *) &tmpmailbox;
        void __iomem *to = apbs[IndexCard].RamIO + RAM_FROM_PC;
        int c;

        for (c = 0; c < sizeof(struct mailbox); c++)
            writeb(*(from++), to++);
    }

    writeb(0x20, apbs[IndexCard].RamIO + TIC_OWNER_FROM_PC);
    writeb(0xff, apbs[IndexCard].RamIO + NUMCARD_OWNER_FROM_PC);
    writeb(TicCard, apbs[IndexCard].RamIO + TIC_DES_FROM_PC);
    writeb(NumCard, apbs[IndexCard].RamIO + NUMCARD_DES_FROM_PC);
    writeb(2, apbs[IndexCard].RamIO + DATA_FROM_PC_READY);
    writeb(1, apbs[IndexCard].RamIO + RAM_IT_FROM_PC);
    Dummy = readb(apbs[IndexCard].RamIO + VERS);
    spin_unlock_irqrestore(&apbs[IndexCard].mutex, flags);
    return 0;
}
Exemplo n.º 3
0
static irqreturn_t ac_interrupt(int vec, void *dev_instance, struct pt_regs *regs)
{
    unsigned int i;
    unsigned int FlagInt;
    unsigned int LoopCount;
    int handled = 0;

    //    printk("Applicom interrupt on IRQ %d occurred\n", vec);

    LoopCount = 0;

    do {
        FlagInt = 0;
        for (i = 0; i < MAX_BOARD; i++) {

            /* Skip if this board doesn't exist */
            if (!apbs[i].RamIO)
                continue;

            spin_lock(&apbs[i].mutex);

            /* Skip if this board doesn't want attention */
            if(readb(apbs[i].RamIO + RAM_IT_TO_PC) == 0) {
                spin_unlock(&apbs[i].mutex);
                continue;
            }

            handled = 1;
            FlagInt = 1;
            writeb(0, apbs[i].RamIO + RAM_IT_TO_PC);

            if (readb(apbs[i].RamIO + DATA_TO_PC_READY) > 2) {
                printk(KERN_WARNING "APPLICOM driver interrupt err board %d, DataToPcReady = %d\n",
                       i+1,(int)readb(apbs[i].RamIO + DATA_TO_PC_READY));
                DeviceErrorCount++;
            }

            if((readb(apbs[i].RamIO + DATA_FROM_PC_READY) > 2) &&
                    (readb(apbs[i].RamIO + DATA_FROM_PC_READY) != 6)) {

                printk(KERN_WARNING "APPLICOM driver interrupt err board %d, DataFromPcReady = %d\n",
                       i+1,(int)readb(apbs[i].RamIO + DATA_FROM_PC_READY));
                DeviceErrorCount++;
            }

            if (readb(apbs[i].RamIO + DATA_TO_PC_READY) == 2) {	/* mailbox sent by the card ?   */
                if (waitqueue_active(&FlagSleepRec)) {
                    wake_up_interruptible(&FlagSleepRec);
                }
            }

            if (readb(apbs[i].RamIO + DATA_FROM_PC_READY) == 0) {	/* ram i/o free for write by pc ? */
                if (waitqueue_active(&apbs[i].FlagSleepSend)) {	/* process sleep during read ?    */
                    wake_up_interruptible(&apbs[i].FlagSleepSend);
                }
            }
            Dummy = readb(apbs[i].RamIO + VERS);

            if(readb(apbs[i].RamIO + RAM_IT_TO_PC)) {
                /* There's another int waiting on this card */
                spin_unlock(&apbs[i].mutex);
                i--;
            } else {
                spin_unlock(&apbs[i].mutex);
            }
        }
        if (FlagInt)
            LoopCount = 0;
        else
            LoopCount++;
    } while(LoopCount < 2);
    return IRQ_RETVAL(handled);
}
Exemplo n.º 4
0
static inline u_char
readisac(void __iomem *adr, u_char off)
{
	return readb(adr + ((off & 1) ? 0x2ff : 0x100) + off);
}
Exemplo n.º 5
0
static inline void riic_clear_set_bit(struct riic_dev *riic, u8 clear, u8 set, u8 reg)
{
	writeb((readb(riic->base + reg) & ~clear) | set, riic->base + reg);
}
Exemplo n.º 6
0
static int pcidev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
	int ret = 0;
	struct pcidev_struct *pcidev = (struct pcidev_struct *)file->private_data;
	if (!pcidev)
		return -EIO;
	switch(cmd) {
	case PCIDEV_IOCTL_FIND: {
		struct pcidev_find_struct *find;
		struct pci_dev *dev;
		unsigned long vendorID, deviceID;
		int idx;
		if (pcidev->dev)
			return -EIO; // only alloc once for now
		if (!access_ok(VERIFY_WRITE, (void *)arg, sizeof(struct pcidev_find_struct)))
			return -EFAULT;
		find = (struct pcidev_find_struct *)arg;
		__get_user(vendorID, &find->vendorID);
		__get_user(deviceID, &find->deviceID);
		__put_user(-1, &find->bus);
		__put_user(-1, &find->device);
		__put_user(-1, &find->func);
		dev = pci_find_device(vendorID, deviceID, NULL);
		if (!dev)
			return -ENOENT;
		if (pci_enable_device(dev)) {
			printk(KERN_WARNING "pcidev: Could not enable the PCI device.\n");
			return -EIO;
		}
		if (pci_set_dma_mask(dev, 0xffffffff))
			printk(KERN_WARNING "pcidev: only limited PCI busmaster DMA support.\n");
		pci_set_master(dev);
		printk(KERN_INFO "pcidev: device found at %x:%x.%d\n", 
				dev->bus->number, PCI_SLOT(dev->devfn), 
				PCI_FUNC(dev->devfn));
		ret = pci_request_regions(dev, pcidev_name);
		if (ret < 0)
			break;
		for (idx = 0; idx < PCIDEV_COUNT_RESOURCES; idx++) {
			if (pci_resource_flags(dev, idx) & IORESOURCE_MEM) {
				long len = pci_resource_len(dev, idx);
				unsigned long mapped_start = (unsigned long)ioremap(pci_resource_start(dev, idx), len);
				__put_user(mapped_start, &find->resources[idx].start);
				__put_user(mapped_start + len - 1, &find->resources[idx].end);
				pcidev->mapped_mem[idx] = (void *)mapped_start;
			}
			else {
				pcidev->mapped_mem[idx] = NULL;
				__put_user(pci_resource_start(dev, idx), &find->resources[idx].start);
				__put_user(pci_resource_end(dev, idx), &find->resources[idx].end);
			}
			__put_user(pci_resource_flags(dev, idx), &find->resources[idx].flags);
		}
		pcidev->dev = dev;
		__put_user(dev->bus->number, &find->bus);
		__put_user(PCI_SLOT(dev->devfn), &find->device);
		__put_user(PCI_FUNC(dev->devfn), &find->func);
		ret = 0;
		break;
	}
	case PCIDEV_IOCTL_READ_CONFIG_BYTE: 
	case PCIDEV_IOCTL_READ_CONFIG_WORD: 
	case PCIDEV_IOCTL_READ_CONFIG_DWORD: {
		struct pcidev_io_struct *io;
		unsigned long address, value;
		if (!pcidev->dev)
			return -EIO;
		if (!access_ok(VERIFY_WRITE, (void *)arg, sizeof(struct pcidev_io_struct)))
			return -EFAULT;
		io = (struct pcidev_io_struct *)arg;
		__get_user(address, &io->address);
		__put_user(-1, &io->value);
		printk(KERN_DEBUG "pcidev: reading config address %#x\n", (int)address);
		switch(cmd) {
		case PCIDEV_IOCTL_READ_CONFIG_BYTE:
			ret = pci_read_config_byte(pcidev->dev, address, (u8 *)&value);
			break;
		case PCIDEV_IOCTL_READ_CONFIG_WORD:
			ret = pci_read_config_word(pcidev->dev, address, (u16 *)&value);
			break;
		case PCIDEV_IOCTL_READ_CONFIG_DWORD:
			ret = pci_read_config_dword(pcidev->dev, address, (u32 *)&value);
			break;
		}
		if (ret < 0)
			return ret;
		__put_user(value, &io->value);
		break;
	}
	case PCIDEV_IOCTL_WRITE_CONFIG_BYTE: 
	case PCIDEV_IOCTL_WRITE_CONFIG_WORD: 
	case PCIDEV_IOCTL_WRITE_CONFIG_DWORD: {
		struct pcidev_io_struct *io;
		unsigned long address, value;
		if (!pcidev->dev)
			return -EIO;
		if (!access_ok(VERIFY_READ, (void *)arg, sizeof(struct pcidev_io_struct)))
			return -EFAULT;
		io = (struct pcidev_io_struct *)arg;
		__get_user(address, &io->address);
		__get_user(value, &io->value);
		/*
		 * Next tests prevent the pcidev user from remapping
		 * the PCI host device since this could cause great 
		 * trouble because we don't own those I/O resources.
		 * If the pcidev wants to remap a device he needs to
		 * emulate the mapping himself and not bother the host
		 * kernel about it.
		 */
		if (address == PCI_INTERRUPT_PIN) {
			printk(KERN_WARNING "pcidev: not allowed to set irq pin!\n");
			return -EIO;
		}
		if (address == PCI_INTERRUPT_LINE) {
			printk(KERN_WARNING "pcidev: not allowed to set irq line!\n");
			return -EIO;
		}
		if (PCI_BASE_ADDRESS_0 <= address && (address & ~3UL) <= PCI_BASE_ADDRESS_5) {
			printk(KERN_WARNING "pcidev: now allowed to change base address %d\n", 
					(int)((address & ~3UL) - PCI_BASE_ADDRESS_0) / 4);
			return -EIO;
		}
		printk(KERN_DEBUG "pcidev: writing config address %#x\n", (int)address);
		switch(cmd) {
		case PCIDEV_IOCTL_WRITE_CONFIG_BYTE:
			ret = pci_write_config_byte(pcidev->dev, address, (u8)value);
			break;
		case PCIDEV_IOCTL_WRITE_CONFIG_WORD:
			ret = pci_write_config_word(pcidev->dev, address, (u16)value);
			break;
		case PCIDEV_IOCTL_WRITE_CONFIG_DWORD:
			ret = pci_write_config_dword(pcidev->dev, address, (u32)value);
			break;
		}
		break;
	}
	case PCIDEV_IOCTL_INTERRUPT: {
		u8 irq;
		if (!pcidev->dev)
			return -EIO;
		ret = pci_read_config_byte(pcidev->dev, PCI_INTERRUPT_PIN, &irq);
		if (ret < 0)
			break;
		if (!irq)
			return -EIO;
		ret = pci_read_config_byte(pcidev->dev, PCI_INTERRUPT_LINE, &irq);
		if (ret < 0)
			break;
		if (arg & 1) {
			pcidev->pid = current->pid; // our dev_id
			printk(KERN_INFO "pcidev: enabling IRQ %d\n", irq);
			ret = request_irq(irq, pcidev_irqhandler, SA_SHIRQ,
					pcidev_name, (void *)current->pid);
		}
		else {
			if (!pcidev->pid)
				return -EIO;
			printk(KERN_INFO "pcidev: disabling IRQ %d\n", irq);
			free_irq(irq, (void *)pcidev->pid);
			pcidev->pid = 0;
			ret = 0;
		}
		break;
	}
	/*
	 * Next ioctl is only for testing purposes.
	 */
	case PCIDEV_IOCTL_INTERRUPT_TEST: {
		ret = -EIO;
		if (!pcidev->dev)
			break;
		if (!pcidev->pid)
			break;
		if (pcidev->irq_timer.function)
			del_timer_sync(&pcidev->irq_timer);
		pcidev->irq_timer.function = NULL;
		if (arg & 1) {
			init_timer(&pcidev->irq_timer);
			pcidev->irq_timer.function = irq_test_timer;
			pcidev->irq_timer.data = (unsigned long)pcidev;
			pcidev->irq_timer.expires = jiffies + HZ;
			add_timer(&pcidev->irq_timer);
		}
		ret = 0;
		break;
	}
	case PCIDEV_IOCTL_READ_IO_BYTE: 
	case PCIDEV_IOCTL_READ_IO_WORD: 
	case PCIDEV_IOCTL_READ_IO_DWORD: {
		/*
		 * We should probably check access rights against
		 * the PCI resource list... but who cares for a 
		 * security hole more or less :)
		 */
		struct pcidev_io_struct *io;
		unsigned long address, value = -1;
		if (!access_ok(VERIFY_WRITE, (void *)arg, sizeof(struct pcidev_io_struct)))
			return -EFAULT;
		io = (struct pcidev_io_struct *)arg;
		__get_user(address, &io->address);
		printk(KERN_DEBUG "pcidev: reading I/O port %#x\n", (int)address);
		switch(cmd) {
		case PCIDEV_IOCTL_READ_IO_BYTE:
			value = inb(address);
			break;
		case PCIDEV_IOCTL_READ_IO_WORD:
			value = inw(address);
			break;
		case PCIDEV_IOCTL_READ_IO_DWORD:
			value = inl(address);
			break;
		}
		__put_user(value, &io->value);
		ret = 0;
		break;
	}
	case PCIDEV_IOCTL_WRITE_IO_BYTE: 
	case PCIDEV_IOCTL_WRITE_IO_WORD: 
	case PCIDEV_IOCTL_WRITE_IO_DWORD: {
		struct pcidev_io_struct *io;
		unsigned long address, value;
		if (!access_ok(VERIFY_READ, (void *)arg, sizeof(struct pcidev_io_struct)))
			return -EFAULT;
		io = (struct pcidev_io_struct *)arg;
		__get_user(address, &io->address);
		__get_user(value, &io->value);
		printk(KERN_DEBUG "pcidev: writing I/O port %#x\n", (int)address);
		switch(cmd) {
		case PCIDEV_IOCTL_WRITE_IO_BYTE:
			outb(value, address);
			break;
		case PCIDEV_IOCTL_WRITE_IO_WORD:
			outw(value, address);
			break;
		case PCIDEV_IOCTL_WRITE_IO_DWORD:
			outl(value, address);
			break;
		}
		ret = 0;
		break;
	}
	case PCIDEV_IOCTL_READ_MEM_BYTE: 
	case PCIDEV_IOCTL_READ_MEM_WORD: 
	case PCIDEV_IOCTL_READ_MEM_DWORD: {
		struct pcidev_io_struct *io;
		unsigned long address, value = -1;
		if (!access_ok(VERIFY_WRITE, (void *)arg, sizeof(struct pcidev_io_struct)))
			return -EFAULT;
		io = (struct pcidev_io_struct *)arg;
		__get_user(address, &io->address);
		printk(KERN_DEBUG "pcidev: reading memory %#x\n", (int)address);
		switch(cmd) {
		case PCIDEV_IOCTL_READ_MEM_BYTE:
			value = readb((unsigned char *)address);
			break;
		case PCIDEV_IOCTL_READ_MEM_WORD:
			value = readw((unsigned short *)address);
			break;
		case PCIDEV_IOCTL_READ_MEM_DWORD:
			value = readl((unsigned int *)address);
			break;
		}
		__put_user(value, &io->value);
		ret = 0;
		break;
	}
	case PCIDEV_IOCTL_WRITE_MEM_BYTE: 
	case PCIDEV_IOCTL_WRITE_MEM_WORD:
	case PCIDEV_IOCTL_WRITE_MEM_DWORD: {
		struct pcidev_io_struct *io;
		unsigned long address, value;
		if (!access_ok(VERIFY_READ, (void *)arg, sizeof(struct pcidev_io_struct)))
			return -EFAULT;
		io = (struct pcidev_io_struct *)arg;
		__get_user(address, &io->address);
		__get_user(value, &io->value);
		printk(KERN_DEBUG "pcidev: writing memory %#x\n", (int)address);
		switch(cmd) {
		case PCIDEV_IOCTL_WRITE_MEM_BYTE:
			writeb(value, (unsigned char *)address);
			break;
		case PCIDEV_IOCTL_WRITE_MEM_WORD:
			writew(value, (unsigned short *)address);
			break;
		case PCIDEV_IOCTL_WRITE_MEM_DWORD:
			writel(value, (unsigned int *)address);
			break;
		}
		ret = 0;
		break;
	}
	case PCIDEV_IOCTL_PROBE_CONFIG_DWORD: {
		/*
		 * This ioctl allows for probing a config space value.
		 * This can be used for base address size probing
		 */
		struct pcidev_io_struct *io;
		unsigned long address, value, orig_value;
		if (!pcidev->dev)
			return -EIO;
		if (!access_ok(VERIFY_WRITE, (void *)arg, sizeof(struct pcidev_io_struct)))
			return -EFAULT;
		io = (struct pcidev_io_struct *)arg;
		__get_user(address, &io->address);
		__get_user(value, &io->value);
		__put_user(-1, &io->value);
		printk(KERN_INFO "pcidev: probing config space address: %#x\n", (int)address);
		ret = pci_read_config_dword(pcidev->dev, address, (u32 *)&orig_value);
		if (ret < 0)
			break;
		pci_write_config_dword(pcidev->dev, address, (u32)value);
		pci_read_config_dword(pcidev->dev, address, (u32 *)&value);
		ret = pci_write_config_dword(pcidev->dev, address, (u32)orig_value);
		if (ret < 0)
			break;
		__put_user(value, &io->value);
		break;
	}
	default:
		ret = -ENOTTY;
	}
	return ret;
}
Exemplo n.º 7
0
static u_char
ReadISAC(struct IsdnCardState *cs, u_char offset)
{
	return (readb(cs->hw.isurf.isac + offset));
}
Exemplo n.º 8
0
uint8
osl_readb(volatile uint8 *r)
{
	return (readb(r));
}
static void __init nas100d_init(void)
{
	uint8_t __iomem *f;
	int i;

	ixp4xx_sys_init();

	/* gpio 14 and 15 are _not_ clocks */
	*IXP4XX_GPIO_GPCLKR = 0;

	nas100d_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
	nas100d_flash_resource.end =
		IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;

	i2c_register_board_info(0, nas100d_i2c_board_info,
				ARRAY_SIZE(nas100d_i2c_board_info));

	/*
	 * This is only useful on a modified machine, but it is valuable
	 * to have it first in order to see debug messages, and so that
	 * it does *not* get removed if platform_add_devices fails!
	 */
	(void)platform_device_register(&nas100d_uart);

	platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));

	pm_power_off = nas100d_power_off;

	if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
		IRQF_DISABLED | IRQF_TRIGGER_LOW,
		"NAS100D reset button", NULL) < 0) {

		printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
			gpio_to_irq(NAS100D_RB_GPIO));
	}

	/* The power button on the Iomega NAS100d is on GPIO 14, but
	 * it cannot handle interrupts on that GPIO line.  So we'll
	 * have to poll it with a kernel timer.
	 */

	/* Make sure that the power button GPIO is set up as an input */
	gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);

	/* Set the initial value for the power button IRQ handler */
	power_button_countdown = PBUTTON_HOLDDOWN_COUNT;

	mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));

	/*
	 * Map in a portion of the flash and read the MAC address.
	 * Since it is stored in BE in the flash itself, we need to
	 * byteswap it if we're in LE mode.
	 */
	f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x1000000);
	if (f) {
		for (i = 0; i < 6; i++)
#ifdef __ARMEB__
			nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + i);
#else
			nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + (i^3));
#endif
		iounmap(f);
	}
	printk(KERN_INFO "NAS100D: Using MAC address %pM for port 0\n",
	       nas100d_plat_eth[0].hwaddr);

}
int
eicon_isa_load(eicon_isa_card *card, eicon_isa_codebuf *cb) {
	eicon_isa_boot    *boot;
	int               tmp;
	int               timeout;
	int 		  j;
	eicon_isa_codebuf cbuf;
	unsigned char     *code;
	unsigned char     *p;

	if (copy_from_user(&cbuf, cb, sizeof(eicon_isa_codebuf)))
		return -EFAULT;

	if (!(code = kmalloc(cbuf.firmware_len, GFP_KERNEL))) {
		printk(KERN_WARNING "eicon_isa_load: Couldn't allocate code buffer\n");
		return -ENOMEM;
	}

	if (copy_from_user(code, &cb->code, cbuf.firmware_len)) {
		kfree(code);
		return -EFAULT;
	}

	boot = &card->shmem->boot;

	if ((!card->ivalid) && card->master) {
		card->irqprobe = 1;
		/* Check for valid IRQ */
		if ((card->irq < 0) || (card->irq > 15) || 
		    (!((1 << card->irq) & eicon_isa_valid_irq[card->type & 0x0f]))) {
			printk(KERN_WARNING "eicon_isa_load: illegal irq: %d\n", card->irq);
			eicon_isa_release_shmem(card);
			kfree(code);
			return -EINVAL;
		}
		/* Register irq */
		if (!request_irq(card->irq, &eicon_irq, 0, "Eicon ISA ISDN", card))
			card->ivalid = 1;
		else {
			printk(KERN_WARNING "eicon_isa_load: irq %d already in use.\n",
			       card->irq);
			eicon_isa_release_shmem(card);
			kfree(code);
			return -EBUSY;
		}
	}

        tmp = readb(&boot->msize);
        if (tmp != 8 && tmp != 16 && tmp != 24 &&
            tmp != 32 && tmp != 48 && tmp != 60) {
                printk(KERN_WARNING "eicon_isa_load: invalid memsize\n");
		eicon_isa_release_shmem(card);
                return -EIO;
        }

	eicon_isa_printpar(card);

	/* Download firmware */
	printk(KERN_INFO "%s %dkB, loading firmware ...\n", 
	       eicon_ctype_name[card->type],
	       tmp * 16);
	tmp = cbuf.firmware_len >> 8;
	p = code;
	while (tmp--) {
		memcpy_toio(&boot->b, p, 256);
		writeb(1, &boot->ctrl);
		timeout = jiffies + HZ / 10;
		while (time_before(jiffies, timeout)) {
			if (readb(&boot->ctrl) == 0)
				break;
			SLEEP(2);
		}
		if (readb(&boot->ctrl)) {
			printk(KERN_WARNING "eicon_isa_load: download timeout at 0x%x\n", p-code);
			eicon_isa_release(card);
			kfree(code);
			return -EIO;
		}
		p += 256;
	}
	kfree(code);

	/* Initialize firmware parameters */
	memcpy_toio(&card->shmem->c[8], &cbuf.tei, 14);
	memcpy_toio(&card->shmem->c[32], &cbuf.oad, 96);
	memcpy_toio(&card->shmem->c[128], &cbuf.oad, 96);
	
	/* Start firmware, wait for signature */
	writeb(2, &boot->ctrl);
	timeout = jiffies + (5*HZ);
	while (time_before(jiffies, timeout)) {
		if (readw(&boot->signature) == 0x4447)
			break;
		SLEEP(2);
	}
	if (readw(&boot->signature) != 0x4447) {
		printk(KERN_WARNING "eicon_isa_load: firmware selftest failed %04x\n",
		       readw(&boot->signature));
		eicon_isa_release(card);
		return -EIO;
	}

	card->channels = readb(&card->shmem->c[0x3f6]);

	/* clear irq-requests, reset irq-count */
	readb(card->intack);
	writeb(0, card->intack);

	if (card->master) {
		card->irqprobe = 1;
		/* Trigger an interrupt and check if it is delivered */
		tmp = readb(&card->shmem->com.ReadyInt);
		tmp ++;
		writeb(tmp, &card->shmem->com.ReadyInt);
		timeout = jiffies + HZ / 5;
		while (time_before(jiffies, timeout)) {
			if (card->irqprobe > 1)
				break;
			SLEEP(2);
		}
		if (card->irqprobe == 1) {
			printk(KERN_WARNING "eicon_isa_load: IRQ # %d test failed\n", card->irq);
			eicon_isa_release(card);
			return -EIO;
		}
	}
#ifdef EICON_MCA_DEBUG
	printk(KERN_INFO "eicon_isa_load: IRQ # %d test succeeded.\n", card->irq);
#endif

	writeb(card->irq, &card->shmem->com.Int);

	/* initializing some variables */
	((eicon_card *)card->card)->ReadyInt = 0;
	((eicon_card *)card->card)->ref_in  = 1;
	((eicon_card *)card->card)->ref_out = 1;
	for(j=0; j<256; j++) ((eicon_card *)card->card)->IdTable[j] = NULL;
	for(j=0; j< (card->channels + 1); j++) {
		((eicon_card *)card->card)->bch[j].e.busy = 0;
		((eicon_card *)card->card)->bch[j].e.D3Id = 0;
		((eicon_card *)card->card)->bch[j].e.B2Id = 0;
		((eicon_card *)card->card)->bch[j].e.ref = 0;
		((eicon_card *)card->card)->bch[j].e.Req = 0;
		((eicon_card *)card->card)->bch[j].e.complete = 1;
		((eicon_card *)card->card)->bch[j].fsm_state = EICON_STATE_NULL;
	}

	printk(KERN_INFO "Eicon: Supported channels: %d\n", card->channels); 
	printk(KERN_INFO "%s successfully started\n", eicon_ctype_name[card->type]);

	/* Enable normal IRQ processing */
	card->irqprobe = 0;
	return 0;
}
Exemplo n.º 11
0
static void __init rbtx4939_update_ioc_pen(void)
{
	__u64 pcfg = ____raw_readq(&tx4939_ccfgptr->pcfg);
	__u64 ccfg = ____raw_readq(&tx4939_ccfgptr->ccfg);
	__u8 pe1 = readb(rbtx4939_pe1_addr);
	__u8 pe2 = readb(rbtx4939_pe2_addr);
	__u8 pe3 = readb(rbtx4939_pe3_addr);
	if (pcfg & TX4939_PCFG_ATA0MODE)
		pe1 |= RBTX4939_PE1_ATA(0);
	else
		pe1 &= ~RBTX4939_PE1_ATA(0);
	if (pcfg & TX4939_PCFG_ATA1MODE) {
		pe1 |= RBTX4939_PE1_ATA(1);
		pe1 &= ~(RBTX4939_PE1_RMII(0) | RBTX4939_PE1_RMII(1));
	} else {
		pe1 &= ~RBTX4939_PE1_ATA(1);
		if (pcfg & TX4939_PCFG_ET0MODE)
			pe1 |= RBTX4939_PE1_RMII(0);
		else
			pe1 &= ~RBTX4939_PE1_RMII(0);
		if (pcfg & TX4939_PCFG_ET1MODE)
			pe1 |= RBTX4939_PE1_RMII(1);
		else
			pe1 &= ~RBTX4939_PE1_RMII(1);
	}
	if (ccfg & TX4939_CCFG_PTSEL)
		pe3 &= ~(RBTX4939_PE3_VP | RBTX4939_PE3_VP_P |
			 RBTX4939_PE3_VP_S);
	else {
		__u64 vmode = pcfg &
			(TX4939_PCFG_VSSMODE | TX4939_PCFG_VPSMODE);
		if (vmode == 0)
			pe3 &= ~(RBTX4939_PE3_VP | RBTX4939_PE3_VP_P |
				 RBTX4939_PE3_VP_S);
		else if (vmode == TX4939_PCFG_VPSMODE) {
			pe3 |= RBTX4939_PE3_VP_P;
			pe3 &= ~(RBTX4939_PE3_VP | RBTX4939_PE3_VP_S);
		} else if (vmode == TX4939_PCFG_VSSMODE) {
			pe3 |= RBTX4939_PE3_VP | RBTX4939_PE3_VP_S;
			pe3 &= ~RBTX4939_PE3_VP_P;
		} else {
			pe3 |= RBTX4939_PE3_VP | RBTX4939_PE3_VP_P;
			pe3 &= ~RBTX4939_PE3_VP_S;
		}
	}
	if (pcfg & TX4939_PCFG_SPIMODE) {
		if (pcfg & TX4939_PCFG_SIO2MODE_GPIO)
			pe2 &= ~(RBTX4939_PE2_SIO2 | RBTX4939_PE2_SIO0);
		else {
			if (pcfg & TX4939_PCFG_SIO2MODE_SIO2) {
				pe2 |= RBTX4939_PE2_SIO2;
				pe2 &= ~RBTX4939_PE2_SIO0;
			} else {
				pe2 |= RBTX4939_PE2_SIO0;
				pe2 &= ~RBTX4939_PE2_SIO2;
			}
		}
		if (pcfg & TX4939_PCFG_SIO3MODE)
			pe2 |= RBTX4939_PE2_SIO3;
		else
			pe2 &= ~RBTX4939_PE2_SIO3;
		pe2 &= ~RBTX4939_PE2_SPI;
	} else {
		pe2 |= RBTX4939_PE2_SPI;
		pe2 &= ~(RBTX4939_PE2_SIO3 | RBTX4939_PE2_SIO2 |
			 RBTX4939_PE2_SIO0);
	}
	if ((pcfg & TX4939_PCFG_I2SMODE_MASK) == TX4939_PCFG_I2SMODE_GPIO)
		pe2 |= RBTX4939_PE2_GPIO;
	else
		pe2 &= ~RBTX4939_PE2_GPIO;
	writeb(pe1, rbtx4939_pe1_addr);
	writeb(pe2, rbtx4939_pe2_addr);
	writeb(pe3, rbtx4939_pe3_addr);
}
int
eicon_isa_bootload(eicon_isa_card *card, eicon_isa_codebuf *cb) {
	int	tmp;
	int               timeout;
	eicon_isa_codebuf cbuf;
	unsigned char     *code;
	eicon_isa_boot    *boot;

	if (copy_from_user(&cbuf, cb, sizeof(eicon_isa_codebuf)))
		return -EFAULT;

	/* Allocate code-buffer and copy code from userspace */
	if (cbuf.bootstrap_len > 1024) {
		printk(KERN_WARNING "eicon_isa_boot: Invalid startup-code size %ld\n",
		       cbuf.bootstrap_len);
		return -EINVAL;
	}
	if (!(code = kmalloc(cbuf.bootstrap_len, GFP_KERNEL))) {
		printk(KERN_WARNING "eicon_isa_boot: Couldn't allocate code buffer\n");
		return -ENOMEM;
	}
	if (copy_from_user(code, &cb->code, cbuf.bootstrap_len)) {
		kfree(code);
		return -EFAULT;
	}

	if (card->type == EICON_CTYPE_ISAPRI)
		card->ramsize  = RAMSIZE_P;
	else
		card->ramsize  = RAMSIZE;

	if (check_mem_region(card->physmem, card->ramsize)) {
		printk(KERN_WARNING "eicon_isa_boot: memory at 0x%lx already in use.\n",
			card->physmem);
		kfree(code);
		return -EBUSY;
	}
	request_mem_region(card->physmem, card->ramsize, "Eicon ISA ISDN");
	card->shmem = (eicon_isa_shmem *) ioremap(card->physmem, card->ramsize);
#ifdef EICON_MCA_DEBUG
	printk(KERN_INFO "eicon_isa_boot: card->ramsize = %d.\n", card->ramsize);
#endif
	card->mvalid = 1;

	switch(card->type) {
		case EICON_CTYPE_S:
		case EICON_CTYPE_SX:
		case EICON_CTYPE_SCOM:
		case EICON_CTYPE_QUADRO:
		case EICON_CTYPE_ISABRI:
			card->intack   = (__u8 *)card->shmem + INTACK;
			card->startcpu = (__u8 *)card->shmem + STARTCPU;
			card->stopcpu  = (__u8 *)card->shmem + STOPCPU;
			break;
		case EICON_CTYPE_S2M:
		case EICON_CTYPE_ISAPRI:
			card->intack   = (__u8 *)card->shmem + INTACK_P;
			card->startcpu = (__u8 *)card->shmem + STARTCPU_P;
			card->stopcpu  = (__u8 *)card->shmem + STOPCPU_P;
			break;
		default:
			printk(KERN_WARNING "eicon_isa_boot: Invalid card type %d\n", card->type);
			eicon_isa_release_shmem(card);
			kfree(code);
			return -EINVAL;
	}

	/* clear any pending irq's */
	readb(card->intack);
#ifdef CONFIG_MCA
	if (MCA_bus) {
		if (card->type == EICON_CTYPE_SCOM) {
			outb_p(0,card->io+1);
		}
		else {
			printk(KERN_WARNING "eicon_isa_boot: Card type not supported yet.\n");
			eicon_isa_release_shmem(card);
			return -EINVAL;
		};

#ifdef EICON_MCA_DEBUG
	printk(KERN_INFO "eicon_isa_boot: card->io      = %x.\n", card->io);
	printk(KERN_INFO "eicon_isa_boot: card->irq     = %d.\n", (int)card->irq);
#endif
	}
#else
	/* set reset-line active */
	writeb(0, card->stopcpu); 
#endif  /* CONFIG_MCA */
	/* clear irq-requests */
	writeb(0, card->intack);
	readb(card->intack);

	/* Copy code into card */
	memcpy_toio(&card->shmem->c, code, cbuf.bootstrap_len);

	/* Check for properly loaded code */
	if (!check_signature((unsigned long)&card->shmem->c, code, 1020)) {
		printk(KERN_WARNING "eicon_isa_boot: Could not load startup-code\n");
		eicon_isa_release_shmem(card);
		kfree(code);
		return -EIO;
	}
	/* if 16k-ramsize, duplicate the reset-jump-code */
	if (card->ramsize == RAMSIZE_P)
		memcpy_toio((__u8 *)card->shmem + 0x3ff0, &code[0x3f0], 12);

	kfree(code);
	boot = &card->shmem->boot;

	/* Delay 0.2 sec. */
	SLEEP(HZ / 5);

	/* Start CPU */
	writeb(cbuf.boot_opt, &boot->ctrl);
#ifdef CONFIG_MCA
	if (MCA_bus) {
		outb_p(0, card->io);
	}
#else 
	writeb(0, card->startcpu); 
#endif /* CONFIG_MCA */

	/* Delay 0.2 sec. */
	SLEEP(HZ / 5);

	timeout = jiffies + (HZ * 22);
	while (time_before(jiffies, timeout)) {
		if (readb(&boot->ctrl) == 0)
			break;
		SLEEP(10);
	}
	if (readb(&boot->ctrl) != 0) {
		printk(KERN_WARNING "eicon_isa_boot: CPU test failed.\n");
#ifdef EICON_MCA_DEBUG
		printk(KERN_INFO "eicon_isa_boot: &boot->ctrl = %d.\n",
			readb(&boot->ctrl));
#endif
		eicon_isa_release_shmem(card);
		return -EIO;
	}

	/* Check for memory-test errors */
	if (readw(&boot->ebit)) {
		printk(KERN_WARNING "eicon_isa_boot: memory test failed (bit 0x%04x at 0x%08x)\n",
		       readw(&boot->ebit), readl(&boot->eloc));
		eicon_isa_release_shmem(card);
		return -EIO;
	}

        /* Check card type and memory size */
        tmp = readb(&boot->card);
	if ((tmp < 0) || (tmp > 4)) {
		printk(KERN_WARNING "eicon_isa_boot: Type detect failed\n");
		eicon_isa_release_shmem(card);
		return -EIO;
	}
	card->type = tmp;
	((eicon_card *)card->card)->type = tmp;

        tmp = readb(&boot->msize);
        if (tmp != 8 && tmp != 16 && tmp != 24 &&
            tmp != 32 && tmp != 48 && tmp != 60) {
                printk(KERN_WARNING "eicon_isa_boot: invalid memsize\n");
		eicon_isa_release_shmem(card);
                return -EIO;
        }
	printk(KERN_INFO "%s: startup-code loaded\n", eicon_ctype_name[card->type]); 
	if ((card->type == EICON_CTYPE_QUADRO) && (card->master)) {
		tmp = eicon_addcard(card->type, card->physmem, card->irq, 
				((eicon_card *)card->card)->regname, 0);
		printk(KERN_INFO "Eicon: %d adapters added\n", tmp);
	}
	return 0;
}
Exemplo n.º 13
0
static u8 ide_itdm320_inb (unsigned long port)
{
	return (u8) readb(port);
}
Exemplo n.º 14
0
static int __devinit s3c_rtc_probe(struct platform_device *pdev)
{
	struct rtc_device *rtc;
	struct resource *res;
	int ret;

	pr_debug("%s: probe=%p\n", __func__, pdev);

	/* find the IRQs */

	s3c_rtc_tickno = platform_get_irq(pdev, 1);
	if (s3c_rtc_tickno < 0) {
		dev_err(&pdev->dev, "no irq for rtc tick\n");
		return -ENOENT;
	}

	s3c_rtc_alarmno = platform_get_irq(pdev, 0);
	if (s3c_rtc_alarmno < 0) {
		dev_err(&pdev->dev, "no irq for alarm\n");
		return -ENOENT;
	}

	pr_debug("s3c2410_rtc: tick irq %d, alarm irq %d\n",
		 s3c_rtc_tickno, s3c_rtc_alarmno);

	/* get the memory region */

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (res == NULL) {
		dev_err(&pdev->dev, "failed to get memory region resource\n");
		return -ENOENT;
	}

	s3c_rtc_mem = request_mem_region(res->start,
					 res->end-res->start+1,
					 pdev->name);

	if (s3c_rtc_mem == NULL) {
		dev_err(&pdev->dev, "failed to reserve memory region\n");
		ret = -ENOENT;
		goto err_nores;
	}

	s3c_rtc_base = ioremap(res->start, res->end - res->start + 1);
	if (s3c_rtc_base == NULL) {
		dev_err(&pdev->dev, "failed ioremap()\n");
		ret = -EINVAL;
		goto err_nomap;
	}

	device_init_wakeup(&pdev->dev, 1);

	/* register RTC and exit */

	rtc = rtc_device_register("s3c", &pdev->dev, &s3c_rtcops,
				  THIS_MODULE);

	if (IS_ERR(rtc)) {
		dev_err(&pdev->dev, "cannot attach rtc\n");
		ret = PTR_ERR(rtc);
		goto err_nortc;
	}

	s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;

	if (s3c_rtc_cpu_type == TYPE_S3C64XX)
		rtc->max_user_freq = 32768;
	else
		rtc->max_user_freq = 128;

	platform_set_drvdata(pdev, rtc);

	s3c_rtc_enable(pdev, 1);

	pr_debug("s3c2410_rtc: RTCCON=%02x\n",
		 readb(s3c_rtc_base + S3C2410_RTCCON));

	s3c_rtc_setfreq(&pdev->dev, 1);

	return 0;

 err_nortc:
	iounmap(s3c_rtc_base);

 err_nomap:
	release_resource(s3c_rtc_mem);

 err_nores:
	return ret;
}
Exemplo n.º 15
0
			if (!(status & STATUS_DRQ))
				continue;

			word = *addr | *(addr + 1) << 8;
			writew(word, info->base + CUMANASCSI2_PSEUDODMA);
			addr += 2;
			length -= 2;
		}
#else
		printk ("PSEUDO_OUT???\n");
#endif
	else {
		if (transfer && (transfer & 255)) {
			while (length >= 256) {
				unsigned int status = readb(info->base + CUMANASCSI2_STATUS);

				if (status & STATUS_INT)
					return;
	    
				if (!(status & STATUS_DRQ))
					continue;

				readsw(info->base + CUMANASCSI2_PSEUDODMA,
				       addr, 256 >> 1);
				addr += 256;
				length -= 256;
			}
		}

		while (length > 0) {
Exemplo n.º 16
0
static int __init samsung_init(void)
{
        struct device *parent=NULL;	

	if (use_sabi && !dmi_check_system(samsung_sabi_dmi_table) && !force){
	    printk(KERN_ERR "Samsung-backlight is intended to work only with Samsung laptops.\n");
	    return -ENODEV;
	}
        if (!use_sabi && !dmi_check_system(samsung_dmi_table) && !force){
	    printk(KERN_ERR "Sorry, your laptop is not supported. Try use_sabi=1\n");
	    return -ENODEV;
        }

        if(use_sabi){
	    const char *test_str = "SwSmi@";
	    int pos;
	    int index = 0;
	    void __iomem *base;
	    unsigned int ifaceP;
	
	    mutex_init(&sabi_mutex);
	
	    f0000_segment = ioremap(0xf0000, 0xffff);
	    if (!f0000_segment) {
	        printk(KERN_ERR "Samsung-backlight: Can't map the segment at 0xf0000\n");
	        return -EINVAL;
	    }
	
	    printk(KERN_INFO "Samsung-backlight: checking for SABI support.\n");
	
	    /* Try to find the signature "SwSmi@" in memory to find the header */
	    base = f0000_segment;
	    for (pos = 0; pos < 0xffff; ++pos) {
	        char temp = readb(base + pos);
	        if (temp == test_str[index]) {
	            if (5 == index++)
	                break;
	        }
	        else {
	            index = 0;
	        }
	    }
	    if (pos == 0xffff) {
	        printk(KERN_INFO "Samsung-backlight: SABI is not supported\n");
	        iounmap(f0000_segment);
	        return -EINVAL;
	    }
	
	    sabi = (struct sabi_header __iomem *)(base + pos + 1);
	
	    printk(KERN_INFO "Samsung-backlight: SABI is supported (%x)\n", pos + 0xf0000 - 6);
	    if (debug) {
	        printk(KERN_DEBUG "SABI header:\n");
	        printk(KERN_DEBUG " SMI Port Number = 0x%04x\n", readw(&sabi->port));
	        printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n", readb(&sabi->iface_func));
	        printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n", readb(&sabi->en_mem));
	        printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n", readb(&sabi->re_mem));
	        printk(KERN_DEBUG " SABI data offset = 0x%04x\n", readw(&sabi->data_offset));
	        printk(KERN_DEBUG " SABI data segment = 0x%04x\n", readw(&sabi->data_segment));
	        printk(KERN_DEBUG " BIOS interface version = 0x%02x\n", readb(&sabi->bios_ifver));
	        printk(KERN_DEBUG " KBD Launcher string = 0x%02x\n", readb(&sabi->launcher_string));
	    }
	
	    /* Get a pointer to the SABI Interface */
	    ifaceP = (readw(&sabi->data_segment) & 0x0ffff) << 4;
	    ifaceP += readw(&sabi->data_offset) & 0x0ffff;
	    sabi_iface = (struct sabi_interface __iomem *)ioremap(ifaceP, 16);
	    if (!sabi_iface) {
	        printk(KERN_ERR "Samsung-backlight: Can't remap %x\n", ifaceP);
	        iounmap(f0000_segment);
	        return -EINVAL;
	    }
	
	    if (debug) {
	        printk(KERN_DEBUG "Samsung-backlight: SABI Interface = %p\n", sabi_iface);
	    }
        }else{
          /*
	   * The Samsung N120, N130, and NC10 use pci device id 0x27ae, while the
	   * NP-Q45 uses 0x2a02.  Odds are we might need to add more to the
	   * list over time...
	   */
          int pcidevids[]={0x27ae,0x2a02,0x2a42,0xa011,0};
	  int i;
          for(i=0, pci_device=NULL;pcidevids[i]>0 && pci_device==NULL;++i)
	    pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, pcidevids[i], NULL);
          if (!pci_device)
            return -ENODEV;
          parent=&pci_device->dev;
        }
 
        /* create a backlight device to talk to this one */
#if LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,34)
	backlight_device = backlight_device_register("samsung",
						     parent,
						     NULL, &backlight_ops,NULL);
#else
	backlight_device = backlight_device_register("samsung",
						     parent,
						     NULL, &backlight_ops);
#endif
	if (IS_ERR(backlight_device)) {
                if(pci_device)
		  pci_dev_put(pci_device);
		return PTR_ERR(backlight_device);
	}

	backlight_device->props.max_brightness = use_sabi ? SABI_MAX_BRIGHT : MAX_BRIGHT;
	backlight_device->props.brightness = read_brightness();
	backlight_device->props.power = FB_BLANK_UNBLANK;
	backlight_update_status(backlight_device);

	return 0;
}
Exemplo n.º 17
0
static int __init c101_run(unsigned long irq, unsigned long winbase)
{
	struct net_device *dev;
	hdlc_device *hdlc;
	card_t *card;
	int result;

	if (irq<3 || irq>15 || irq == 6) /* FIXME */ {
		pr_err("invalid IRQ value\n");
		return -ENODEV;
	}

	if (winbase < 0xC0000 || winbase > 0xDFFFF || (winbase & 0x3FFF) !=0) {
		pr_err("invalid RAM value\n");
		return -ENODEV;
	}

	card = kzalloc(sizeof(card_t), GFP_KERNEL);
	if (card == NULL) {
		pr_err("unable to allocate memory\n");
		return -ENOBUFS;
	}

	card->dev = alloc_hdlcdev(card);
	if (!card->dev) {
		pr_err("unable to allocate memory\n");
		kfree(card);
		return -ENOBUFS;
	}

	if (request_irq(irq, sca_intr, 0, devname, card)) {
		pr_err("could not allocate IRQ\n");
		c101_destroy_card(card);
		return -EBUSY;
	}
	card->irq = irq;

	if (!request_mem_region(winbase, C101_MAPPED_RAM_SIZE, devname)) {
		pr_err("could not request RAM window\n");
		c101_destroy_card(card);
		return -EBUSY;
	}
	card->phy_winbase = winbase;
	card->win0base = ioremap(winbase, C101_MAPPED_RAM_SIZE);
	if (!card->win0base) {
		pr_err("could not map I/O address\n");
		c101_destroy_card(card);
		return -EFAULT;
	}

	card->tx_ring_buffers = TX_RING_BUFFERS;
	card->rx_ring_buffers = RX_RING_BUFFERS;
	card->buff_offset = C101_WINDOW_SIZE; /* Bytes 1D00-1FFF reserved */

	readb(card->win0base + C101_PAGE); /* Resets SCA? */
	udelay(100);
	writeb(0, card->win0base + C101_PAGE);
	writeb(0, card->win0base + C101_DTR); /* Power-up for RAM? */

	sca_init(card, 0);

	dev = port_to_dev(card);
	hdlc = dev_to_hdlc(dev);

	spin_lock_init(&card->lock);
	dev->irq = irq;
	dev->mem_start = winbase;
	dev->mem_end = winbase + C101_MAPPED_RAM_SIZE - 1;
	dev->tx_queue_len = 50;
	dev->netdev_ops = &c101_ops;
	hdlc->attach = sca_attach;
	hdlc->xmit = sca_xmit;
	card->settings.clock_type = CLOCK_EXT;

	result = register_hdlc_device(dev);
	if (result) {
		pr_warn("unable to register hdlc device\n");
		c101_destroy_card(card);
		return result;
	}

	sca_init_port(card); /* Set up C101 memory */
	set_carrier(card);

	netdev_info(dev, "Moxa C101 on IRQ%u, using %u TX + %u RX packets rings\n",
		    card->irq, card->tx_ring_buffers, card->rx_ring_buffers);

	*new_card = card;
	new_card = &card->next_card;
	return 0;
}
Exemplo n.º 18
0
int sabi_exec_command(u8 command, u8 data, struct sabi_retval *sretval)
{
    int retval = 0;
    
    mutex_lock(&sabi_mutex);

    /* enable memory to be able to write to it */
    outb(readb(&sabi->en_mem), readw(&sabi->port));

    /* write out the command */
    writew(0x5843, &sabi_iface->mainfunc);
    writew(command, &sabi_iface->subfunc);
    writeb(0, &sabi_iface->complete);
    writeb(data, &sabi_iface->retval[0]);
    outb(readb(&sabi->iface_func), readw(&sabi->port));

    /* sleep for a bit to let the command complete */
    msleep(10);

    /* write protect memory to make it safe */
    outb(readb(&sabi->re_mem), readw(&sabi->port));

    /* see if the command actually succeeded */
    if (readb(&sabi_iface->complete) == 0xaa &&
        readb(&sabi_iface->retval[0]) != 0xff) {
        if (sretval) {
            sretval->retval[0] = readb(&sabi_iface->retval[0]);
            sretval->retval[1] = readb(&sabi_iface->retval[1]);
            sretval->retval[2] = readb(&sabi_iface->retval[2]);
            sretval->retval[3] = readb(&sabi_iface->retval[3]);
        }
    }
    else {
        /* Something bad happened, so report it and error out */
        printk(KERN_WARNING "SABI command 0x%02x failed with completion flag 0x%02x and output 0x%02x\n",
            command, readb(&sabi_iface->complete),
        readb(&sabi_iface->retval[0]));
        retval = -EINVAL;
    }
    mutex_unlock(&sabi_mutex);
    return retval;
}
Exemplo n.º 19
0
static unsigned long bgpio_read8(void __iomem *reg)
{
	return readb(reg);
}
Exemplo n.º 20
0
HPT_U8   os_readb  (void *addr) { return readb(addr); }
Exemplo n.º 21
0
static u_char
ReadISAR(struct IsdnCardState *cs, int mode, u_char offset)
{	
	return(readb(cs->hw.isurf.isar + offset));
}
Exemplo n.º 22
0
static noinline uint8_t
rtc_read(enum ds1511reg reg)
{
	return readb(ds1511_base + (reg * reg_spacing));
}
Exemplo n.º 23
0
static inline u_char
readhscx(void __iomem *adr, int hscx, u_char off)
{
	return readb(adr + (hscx ? 0x1c0 : 0x180) +
		     ((off & 1) ? 0x1ff : 0) + off);
}
Exemplo n.º 24
0
static void tmu_timer_stop (unsigned int timer)
{
	if (timer > 2)
		return;
	writeb(readb(TSTR) & ~(1 << timer), TSTR);
}
Exemplo n.º 25
0
int __init applicom_init(void)
{
    int i, numisa = 0;
    struct pci_dev *dev = NULL;
    void __iomem *RamIO;
    int boardno, ret;

    printk(KERN_INFO "Applicom driver: $Id: ac.c,v 1.30 2000/03/22 16:03:57 dwmw2 Exp $\n");

    /* No mem and irq given - check for a PCI card */

    while ( (dev = pci_get_class(PCI_CLASS_OTHERS << 16, dev))) {

        if (dev->vendor != PCI_VENDOR_ID_APPLICOM)
            continue;

        if (dev->device  > MAX_PCI_DEVICE_NUM || dev->device == 0)
            continue;

        if (pci_enable_device(dev))
            return -EIO;

        RamIO = ioremap(dev->resource[0].start, LEN_RAM_IO);

        if (!RamIO) {
            printk(KERN_INFO "ac.o: Failed to ioremap PCI memory space at 0x%lx\n", dev->resource[0].start);
            pci_disable_device(dev);
            return -EIO;
        }

        printk(KERN_INFO "Applicom %s found at mem 0x%lx, irq %d\n",
               applicom_pci_devnames[dev->device-1], dev->resource[0].start,
               dev->irq);

        boardno = ac_register_board(dev->resource[0].start, RamIO,0);
        if (!boardno) {
            printk(KERN_INFO "ac.o: PCI Applicom device doesn't have correct signature.\n");
            iounmap(RamIO);
            pci_disable_device(dev);
            continue;
        }

        if (request_irq(dev->irq, &ac_interrupt, SA_SHIRQ, "Applicom PCI", &dummy)) {
            printk(KERN_INFO "Could not allocate IRQ %d for PCI Applicom device.\n", dev->irq);
            iounmap(RamIO);
            pci_disable_device(dev);
            apbs[boardno - 1].RamIO = NULL;
            continue;
        }

        /* Enable interrupts. */

        writeb(0x40, apbs[boardno - 1].RamIO + RAM_IT_FROM_PC);

        apbs[boardno - 1].irq = dev->irq;
    }

    /* Finished with PCI cards. If none registered,
     * and there was no mem/irq specified, exit */

    if (!mem || !irq) {
        if (numboards)
            goto fin;
        else {
            printk(KERN_INFO "ac.o: No PCI boards found.\n");
            printk(KERN_INFO "ac.o: For an ISA board you must supply memory and irq parameters.\n");
            return -ENXIO;
        }
    }

    /* Now try the specified ISA cards */

    for (i = 0; i < MAX_ISA_BOARD; i++) {
        RamIO = ioremap(mem + (LEN_RAM_IO * i), LEN_RAM_IO);

        if (!RamIO) {
            printk(KERN_INFO "ac.o: Failed to ioremap the ISA card's memory space (slot #%d)\n", i + 1);
            continue;
        }

        if (!(boardno = ac_register_board((unsigned long)mem+ (LEN_RAM_IO*i),
                                          RamIO,i+1))) {
            iounmap(RamIO);
            continue;
        }

        printk(KERN_NOTICE "Applicom ISA card found at mem 0x%lx, irq %d\n", mem + (LEN_RAM_IO*i), irq);

        if (!numisa) {
            if (request_irq(irq, &ac_interrupt, SA_SHIRQ, "Applicom ISA", &dummy)) {
                printk(KERN_WARNING "Could not allocate IRQ %d for ISA Applicom device.\n", irq);
                iounmap(RamIO);
                apbs[boardno - 1].RamIO = NULL;
            }
            else
                apbs[boardno - 1].irq = irq;
        }
        else
            apbs[boardno - 1].irq = 0;

        numisa++;
    }

    if (!numisa)
        printk(KERN_WARNING "ac.o: No valid ISA Applicom boards found "
               "at mem 0x%lx\n", mem);

fin:
    init_waitqueue_head(&FlagSleepRec);

    WriteErrorCount = 0;
    ReadErrorCount = 0;
    DeviceErrorCount = 0;

    if (numboards) {
        ret = misc_register(&ac_miscdev);
        if (ret) {
            printk(KERN_WARNING "ac.o: Unable to register misc device\n");
            goto out;
        }
        for (i = 0; i < MAX_BOARD; i++) {
            int serial;
            char boardname[(SERIAL_NUMBER - TYPE_CARD) + 1];

            if (!apbs[i].RamIO)
                continue;

            for (serial = 0; serial < SERIAL_NUMBER - TYPE_CARD; serial++)
                boardname[serial] = readb(apbs[i].RamIO + TYPE_CARD + serial);

            boardname[serial] = 0;


            printk(KERN_INFO "Applicom board %d: %s, PROM V%d.%d",
                   i+1, boardname,
                   (int)(readb(apbs[i].RamIO + VERS) >> 4),
                   (int)(readb(apbs[i].RamIO + VERS) & 0xF));

            serial = (readb(apbs[i].RamIO + SERIAL_NUMBER) << 16) +
                     (readb(apbs[i].RamIO + SERIAL_NUMBER + 1) << 8) +
                     (readb(apbs[i].RamIO + SERIAL_NUMBER + 2) );

            if (serial != 0)
                printk(" S/N %d\n", serial);
            else
                printk("\n");
        }
        return 0;
    }

    else
        return -ENXIO;
Exemplo n.º 26
0
static unsigned char ts78xx_ts_rtc_readbyte(unsigned long addr)
{
	writeb(addr, TS_RTC_CTRL);
	return readb(TS_RTC_DATA);
}
Exemplo n.º 27
0
static ssize_t ac_read (struct file *filp, char __user *buf, size_t count, loff_t *ptr)
{
    unsigned long flags;
    unsigned int i;
    unsigned char tmp;
    int ret = 0;
    DECLARE_WAITQUEUE(wait, current);
#ifdef DEBUG
    int loopcount=0;
#endif
    /* No need to ratelimit this. Only root can trigger it anyway */
    if (count != sizeof(struct st_ram_io) + sizeof(struct mailbox)) {
        printk( KERN_WARNING "Hmmm. read() of Applicom card, length %zd != expected %zd\n",
                count,sizeof(struct st_ram_io) + sizeof(struct mailbox));
        return -EINVAL;
    }

    while(1) {
        /* Stick ourself on the wait queue */
        set_current_state(TASK_INTERRUPTIBLE);
        add_wait_queue(&FlagSleepRec, &wait);

        /* Scan each board, looking for one which has a packet for us */
        for (i=0; i < MAX_BOARD; i++) {
            if (!apbs[i].RamIO)
                continue;
            spin_lock_irqsave(&apbs[i].mutex, flags);

            tmp = readb(apbs[i].RamIO + DATA_TO_PC_READY);

            if (tmp == 2) {
                struct st_ram_io st_loc;
                struct mailbox mailbox;

                /* Got a packet for us */
                ret = do_ac_read(i, buf, &st_loc, &mailbox);
                spin_unlock_irqrestore(&apbs[i].mutex, flags);
                set_current_state(TASK_RUNNING);
                remove_wait_queue(&FlagSleepRec, &wait);

                if (copy_to_user(buf, &st_loc, sizeof(st_loc)))
                    return -EFAULT;
                if (copy_to_user(buf + sizeof(st_loc), &mailbox, sizeof(mailbox)))
                    return -EFAULT;
                return tmp;
            }

            if (tmp > 2) {
                /* Got an error */
                Dummy = readb(apbs[i].RamIO + VERS);

                spin_unlock_irqrestore(&apbs[i].mutex, flags);
                set_current_state(TASK_RUNNING);
                remove_wait_queue(&FlagSleepRec, &wait);

                printk(KERN_WARNING "APPLICOM driver read error board %d, DataToPcReady = %d\n",
                       i,(int)readb(apbs[i].RamIO + DATA_TO_PC_READY));
                DeviceErrorCount++;
                return -EIO;
            }

            /* Nothing for us. Try the next board */
            Dummy = readb(apbs[i].RamIO + VERS);
            spin_unlock_irqrestore(&apbs[i].mutex, flags);

        } /* per board */

        /* OK - No boards had data for us. Sleep now */

        schedule();
        remove_wait_queue(&FlagSleepRec, &wait);

        if (signal_pending(current))
            return -EINTR;

#ifdef DEBUG
        if (loopcount++ > 2) {
            printk(KERN_DEBUG "Looping in ac_read. loopcount %d\n", loopcount);
        }
#endif
    }
}
Exemplo n.º 28
0
/* Function Description: Read 1 byte of data from addr 
 *			 set by envctrl_i2c_read_addr() 
 * Return : Data from address set by envctrl_i2c_read_addr().
 */
static unsigned char envctrl_i2c_read_data(void)
{
	envtrl_i2c_test_pin();
	writeb(CONTROL_ES0, i2c + PCF8584_CSR);  /* Send neg ack. */
	return readb(i2c + PCF8584_DATA);
}
Exemplo n.º 29
0
static int ac_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)

{   /* @ ADG ou ATO selon le cas */
    int i;
    unsigned char IndexCard;
    void __iomem *pmem;
    int ret = 0;
    volatile unsigned char byte_reset_it;
    struct st_ram_io *adgl;
    void __user *argp = (void __user *)arg;

    /* In general, the device is only openable by root anyway, so we're not
       particularly concerned that bogus ioctls can flood the console. */

    adgl = kmalloc(sizeof(struct st_ram_io), GFP_KERNEL);
    if (!adgl)
        return -ENOMEM;

    if (copy_from_user(adgl, argp, sizeof(struct st_ram_io))) {
        kfree(adgl);
        return -EFAULT;
    }

    IndexCard = adgl->num_card-1;

    if(cmd != 0 && cmd != 6 &&
            ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) {
        static int warncount = 10;
        if (warncount) {
            printk( KERN_WARNING "APPLICOM driver IOCTL, bad board number %d\n",(int)IndexCard+1);
            warncount--;
        }
        kfree(adgl);
        return -EINVAL;
    }

    switch (cmd) {

    case 0:
        pmem = apbs[IndexCard].RamIO;
        for (i = 0; i < sizeof(struct st_ram_io); i++)
            ((unsigned char *)adgl)[i]=readb(pmem++);
        if (copy_to_user(argp, adgl, sizeof(struct st_ram_io)))
            ret = -EFAULT;
        break;
    case 1:
        pmem = apbs[IndexCard].RamIO + CONF_END_TEST;
        for (i = 0; i < 4; i++)
            adgl->conf_end_test[i] = readb(pmem++);
        for (i = 0; i < 2; i++)
            adgl->error_code[i] = readb(pmem++);
        for (i = 0; i < 4; i++)
            adgl->parameter_error[i] = readb(pmem++);
        pmem = apbs[IndexCard].RamIO + VERS;
        adgl->vers = readb(pmem);
        pmem = apbs[IndexCard].RamIO + TYPE_CARD;
        for (i = 0; i < 20; i++)
            adgl->reserv1[i] = readb(pmem++);
        *(int *)&adgl->reserv1[20] =
            (readb(apbs[IndexCard].RamIO + SERIAL_NUMBER) << 16) +
            (readb(apbs[IndexCard].RamIO + SERIAL_NUMBER + 1) << 8) +
            (readb(apbs[IndexCard].RamIO + SERIAL_NUMBER + 2) );

        if (copy_to_user(argp, adgl, sizeof(struct st_ram_io)))
            ret = -EFAULT;
        break;
    case 2:
        pmem = apbs[IndexCard].RamIO + CONF_END_TEST;
        for (i = 0; i < 10; i++)
            writeb(0xff, pmem++);
        writeb(adgl->data_from_pc_ready,
               apbs[IndexCard].RamIO + DATA_FROM_PC_READY);

        writeb(1, apbs[IndexCard].RamIO + RAM_IT_FROM_PC);

        for (i = 0; i < MAX_BOARD; i++) {
            if (apbs[i].RamIO) {
                byte_reset_it = readb(apbs[i].RamIO + RAM_IT_TO_PC);
            }
        }
        break;
    case 3:
        pmem = apbs[IndexCard].RamIO + TIC_DES_FROM_PC;
        writeb(adgl->tic_des_from_pc, pmem);
        break;
    case 4:
        pmem = apbs[IndexCard].RamIO + TIC_OWNER_TO_PC;
        adgl->tic_owner_to_pc     = readb(pmem++);
        adgl->numcard_owner_to_pc = readb(pmem);
        if (copy_to_user(argp, adgl,sizeof(struct st_ram_io)))
            ret = -EFAULT;
        break;
    case 5:
        writeb(adgl->num_card, apbs[IndexCard].RamIO + NUMCARD_OWNER_TO_PC);
        writeb(adgl->num_card, apbs[IndexCard].RamIO + NUMCARD_DES_FROM_PC);
        writeb(adgl->num_card, apbs[IndexCard].RamIO + NUMCARD_ACK_FROM_PC);
        writeb(4, apbs[IndexCard].RamIO + DATA_FROM_PC_READY);
        writeb(1, apbs[IndexCard].RamIO + RAM_IT_FROM_PC);
        break;
    case 6:
        printk(KERN_INFO "APPLICOM driver release .... V2.8.0 ($Revision: 1.30 $)\n");
        printk(KERN_INFO "Number of installed boards . %d\n", (int) numboards);
        printk(KERN_INFO "Segment of board ........... %X\n", (int) mem);
        printk(KERN_INFO "Interrupt IRQ number ....... %d\n", (int) irq);
        for (i = 0; i < MAX_BOARD; i++) {
            int serial;
            char boardname[(SERIAL_NUMBER - TYPE_CARD) + 1];

            if (!apbs[i].RamIO)
                continue;

            for (serial = 0; serial < SERIAL_NUMBER - TYPE_CARD; serial++)
                boardname[serial] = readb(apbs[i].RamIO + TYPE_CARD + serial);
            boardname[serial] = 0;

            printk(KERN_INFO "Prom version board %d ....... V%d.%d %s",
                   i+1,
                   (int)(readb(apbs[IndexCard].RamIO + VERS) >> 4),
                   (int)(readb(apbs[IndexCard].RamIO + VERS) & 0xF),
                   boardname);


            serial = (readb(apbs[i].RamIO + SERIAL_NUMBER) << 16) +
                     (readb(apbs[i].RamIO + SERIAL_NUMBER + 1) << 8) +
                     (readb(apbs[i].RamIO + SERIAL_NUMBER + 2) );

            if (serial != 0)
                printk(" S/N %d\n", serial);
            else
                printk("\n");
        }
        if (DeviceErrorCount != 0)
            printk(KERN_INFO "DeviceErrorCount ........... %d\n", DeviceErrorCount);
        if (ReadErrorCount != 0)
            printk(KERN_INFO "ReadErrorCount ............. %d\n", ReadErrorCount);
        if (WriteErrorCount != 0)
            printk(KERN_INFO "WriteErrorCount ............ %d\n", WriteErrorCount);
        if (waitqueue_active(&FlagSleepRec))
            printk(KERN_INFO "Process in read pending\n");
        for (i = 0; i < MAX_BOARD; i++) {
            if (apbs[i].RamIO && waitqueue_active(&apbs[i].FlagSleepSend))
                printk(KERN_INFO "Process in write pending board %d\n",i+1);
        }
        break;
    default:
        printk(KERN_INFO "APPLICOM driver ioctl, unknown function code %d\n",cmd) ;
        ret = -EINVAL;
        break;
    }
    Dummy = readb(apbs[IndexCard].RamIO + VERS);
    kfree(adgl);
    return 0;
}
Exemplo n.º 30
0
/*
 *   Read a byte from I/O port
 */
static u8
ior(struct board_info *db, int reg)
{
	writeb(reg, db->io_addr);
	return readb(db->io_data);
}