kernel26 initrd

Matan Ziv-Av matan@svgalib.org
Wed Jun 30 21:54:23 CEST 2004


On Wed, 30 Jun 2004, Francois-Rene Rideau wrote:

> to merge sa1111ps2.c from 2.6 and j820_keyb.c from 2.4 into a sa1101ps2.c.
> Are you a taker?

Are the sa1101 interrupts supported yet in 2.6?
Attached is untested code - the two main files.
Still needed sa1101 setup - enabling the PS2 and the PS2 interrupts.


-- 
Matan Ziv-Av.                         matan@svgalib.org
-------------- next part --------------
/*
 *  linux/drivers/input/serio/sa1101ps2.c
 *
 *  Copyright (C) 2002 Russell King
 *
 * 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.
 */
#include <linux/module.h>
#include <linux/init.h>
#include <linux/input.h>
#include <linux/serio.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/spinlock.h>

#include <asm/io.h>
#include <asm/irq.h>
#include <asm/system.h>

#include <asm/hardware/sa1101.h>

struct ps2if {
	struct serio		io;
	unsigned long		base;
	unsigned int		open;
	spinlock_t		lock;
	unsigned int		head;
	unsigned int		tail;
	unsigned char		buf[4];
} *sps2if;

/*
 * Read all bytes waiting in the PS2 port.  There should be
 * at the most one, but we loop for safety.  If there was a
 * framing error, we have to manually clear the status.
 */
static irqreturn_t ps2_rxint(int irq, void *dev_id, struct pt_regs *regs)
{
	struct ps2if *ps2if = dev_id;
	unsigned int scancode, flag, status;
	int handled = IRQ_NONE;

	status = sa1101_readl(ps2if->base + SA1101_PS2STAT);
	while (status & PS2STAT_RXF) {
/* 1101 does not have this bit 
		if (status & PS2STAT_STP)
			sa1101_writel(PS2STAT_STP, ps2if->base + SA1101_PS2STAT);
*/
		flag = /* (status & PS2STAT_STP ? SERIO_FRAME : 0) | */
		       (status & PS2STAT_RXP ? 0 : SERIO_PARITY);

		scancode = sa1101_readl(ps2if->base + SA1101_PS2DATA) & 0xff;

		if (hweight8(scancode) & 1)
			flag ^= SERIO_PARITY;

		serio_interrupt(&ps2if->io, scancode, flag, regs);

		status = sa1101_readl(ps2if->base + SA1101_PS2STAT);

		handled = IRQ_HANDLED;
        }

        return handled;
}

/*
 * Completion of ps2 write
 */
static irqreturn_t ps2_txint(int irq, void *dev_id, struct pt_regs *regs)
{
	struct ps2if *ps2if = dev_id;
	unsigned int status;

	spin_lock(&ps2if->lock);
	status = sa1101_readl(ps2if->base + SA1101_PS2STAT);
	if (ps2if->head == ps2if->tail) {
		disable_irq(irq);
		/* done */
	} else if (status & PS2STAT_TXE) {
		sa1101_writel(ps2if->buf[ps2if->tail], ps2if->base + SA1101_PS2DATA);
		ps2if->tail = (ps2if->tail + 1) & (sizeof(ps2if->buf) - 1);
	}
	spin_unlock(&ps2if->lock);

	return IRQ_HANDLED;
}

/*
 * Write a byte to the PS2 port.  We have to wait for the
 * port to indicate that the transmitter is empty.
 */
static int ps2_write(struct serio *io, unsigned char val)
{
	struct ps2if *ps2if = io->driver;
	unsigned long flags;
	unsigned int head;

	spin_lock_irqsave(&ps2if->lock, flags);

	/*
	 * If the TX register is empty, we can go straight out.
	 */
	if (sa1101_readl(ps2if->base + SA1101_PS2STAT) & PS2STAT_TXE) {
		sa1101_writel(val, ps2if->base + SA1101_PS2DATA);
	} else {
		if (ps2if->head == ps2if->tail)
			enable_irq(IRQ_SA1101_TPTXINT);
		head = (ps2if->head + 1) & (sizeof(ps2if->buf) - 1);
		if (head != ps2if->tail) {
			ps2if->buf[ps2if->head] = val;
			ps2if->head = head;
		}
	}

	spin_unlock_irqrestore(&ps2if->lock, flags);
	return 0;
}

static int ps2_open(struct serio *io)
{
	struct ps2if *ps2if = io->driver;
	int ret;

	ret = request_irq(IRQ_SA1101_TPRXINT, ps2_rxint, 0,
			  "sa1101ps2rx", ps2if);
	if (ret) {
		printk(KERN_ERR "sa1101ps2: could not allocate IRQ%d: %d\n",
			IRQ_SA1101_TPRXINT, ret);
		return ret;
	}

	ret = request_irq(IRQ_SA1101_TPTXINT, ps2_txint, 0, "sa1101ps2tx", ps2if);
	if (ret) {
		printk(KERN_ERR "sa1101ps2: could not allocate IRQ%d: %d\n",
			IRQ_SA1101_TPTXINT, ret);
		free_irq(IRQ_SA1101_TPRXINT, ps2if);
		return ret;
	}

	ps2if->open = 1;

	enable_irq_wake(IRQ_SA1101_TPRXINT);

	sa1101_writel(PS2CR_ENA, ps2if->base + SA1101_PS2CR);
	return 0;
}

static void ps2_close(struct serio *io)
{
	struct ps2if *ps2if = io->driver;

	sa1101_writel(0, ps2if->base + SA1101_PS2CR);

	disable_irq_wake(IRQ_SA1101_TPRXINT);

	ps2if->open = 0;

	free_irq(IRQ_SA1101_TPTXINT, ps2if);
	free_irq(IRQ_SA1101_TPRXINT, ps2if);

}

/*
 * Clear the input buffer.
 */
static void __init ps2_clear_input(struct ps2if *ps2if)
{
	int maxread = 100;

	while (maxread--) {
		if ((sa1101_readl(ps2if->base + SA1101_PS2DATA) & 0xff) == 0xff)
			break;
	}
}

static inline unsigned int
ps2_test_one(struct ps2if *ps2if, unsigned int mask)
{
	unsigned int val;

	sa1101_writel(PS2CR_ENA | mask, ps2if->base + SA1101_PS2CR);

	udelay(2);

	val = sa1101_readl(ps2if->base + SA1101_PS2STAT);
	return val & (PS2STAT_KBC | PS2STAT_KBD);
}

/*
 * Test the keyboard interface.  We basically check to make sure that
 * we can drive each line to the keyboard independently of each other.
 */
static int __init ps2_test(struct ps2if *ps2if)
{
	unsigned int stat;
	int ret = 0;

	stat = ps2_test_one(ps2if, PS2CR_FKC);
	if (stat != PS2STAT_KBD) {
		printk("PS/2 interface test failed[1]: %02x\n", stat);
		ret = -ENODEV;
	}

	stat = ps2_test_one(ps2if, 0);
	if (stat != (PS2STAT_KBC | PS2STAT_KBD)) {
		printk("PS/2 interface test failed[2]: %02x\n", stat);
		ret = -ENODEV;
	}

	stat = ps2_test_one(ps2if, PS2CR_FKD);
	if (stat != PS2STAT_KBC) {
		printk("PS/2 interface test failed[3]: %02x\n", stat);
		ret = -ENODEV;
	}

	sa1101_writel(0, ps2if->base + SA1101_PS2CR);

	return ret;
}

/*
 * Add one device to this driver.
 */
static int __init ps2_probe(void)
{
	struct ps2if *ps2if;
	int ret;

	ps2if = kmalloc(sizeof(struct ps2if), GFP_KERNEL);
	if (!ps2if) {
		return -ENOMEM;
	}

	sps2if=ps2if;
	
	memset(ps2if, 0, sizeof(struct ps2if));

	ps2if->io.type		= SERIO_8042;
	ps2if->io.write		= ps2_write;
	ps2if->io.open		= ps2_open;
	ps2if->io.close		= ps2_close;
	ps2if->io.name		= "sa1101ps2";
	ps2if->io.phys		= ps2if->io.name;
	ps2if->io.driver	= ps2if;

	spin_lock_init(&ps2if->lock);

	/*
	 * Request the physical region for this PS2 port.
	 */
//	if (!request_mem_region(dev->res.start,
//				dev->res.end - dev->res.start + 1,
//				SA1101_DRIVER_NAME(dev))) {
//		ret = -EBUSY;
//		goto free;
//	}

	/*
	 * Our parent device has already mapped the region.
	 */
	ps2if->base = 0xf4000000 + SA1101_MSE;

//	sa1101_enable_device(ps2if->dev);

	/* Incoming clock is 8MHz */
	sa1101_writel(0, ps2if->base + SA1101_PS2CLKDIV);
	sa1101_writel(127, ps2if->base + SA1101_PS2PRECNT);

	/*
	 * Flush any pending input.
	 */
	ps2_clear_input(ps2if);

	/*
	 * Test the keyboard interface.
	 */
	ret = ps2_test(ps2if);
	if (ret)
		goto out;

	/*
	 * Flush any pending input.
	 */
	ps2_clear_input(ps2if);

//	sa1101_disable_device(ps2if->dev);
	serio_register_port(&ps2if->io);
	return 0;

 out:
//	sa1101_disable_device(ps2if->dev);
//	release_mem_region(dev->res.start,
//			   dev->res.end - dev->res.start + 1);
 free:
	kfree(ps2if);
	return ret;
}

/*
 * Remove one device from this driver.
 */
static void __exit ps2_remove(void)
{

	serio_unregister_port(&sps2if->io);
//	release_mem_region(dev->res.start,
//			   dev->res.end - dev->res.start + 1);
//	sa1101_set_drvdata(dev, NULL);

	kfree(sps2if);
}

module_init(ps2_probe);
module_exit(ps2_remove);

MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
MODULE_DESCRIPTION("SA1101 PS2 controller driver");
MODULE_LICENSE("GPL");
-------------- next part --------------
/*
 * File created for Jornada 820... (?)
 * $Id: sa1101.h,v 1.2 2004/06/24 19:57:38 fare Exp $
 */
#ifndef _ASM_ARCH_SA1101
#define _ASM_ARCH_SA1101

#include <asm/arch/bitfield.h>

#define SA1101_IRQMASK_LO(x)	(1 << (x - IRQ_SA1101_START))
#define SA1101_IRQMASK_HI(x)	(1 << (x - IRQ_SA1101_START - 32))

extern int sa1101_probe(unsigned long phys_addr);

extern void sa1101_wake(void);
extern void sa1101_doze(void);

extern void sa1101_init_irq(int irq_nr);
extern void sa1101_IRQ_demux(int irq, void *dev_id, struct pt_regs *regs);

extern int sa1101_pcmcia_init(void *handler);
extern int sa1101_pcmcia_shutdown(void);

extern int sa1101_usb_init(void);
extern int sa1101_usb_shutdown(void);

extern int sa1101_vga_init(void);
extern int sa1101_vga_shutdown(void);

#define sa1101_writereg(val,addr)	({ *(volatile unsigned int *)(addr) = (val); })
#define sa1101_readreg(addr)	(*(volatile unsigned int *)(addr))

#define sa1101_writel(val,addr)	( *(volatile unsigned int *)(addr) = (val))
#define sa1101_readl(addr)	(*(volatile unsigned int *)(addr))



/*
 * PS/2 Trackpad and Mouse Interfaces
 *
 * Registers
 *    PS2CR     Control Register
 *    PS2STAT       Status Register
 *    PS2DATA       Transmit/Receive Data register
 *    PS2CLKDIV     Clock Division Register
 *    PS2PRECNT     Clock Precount Register
 *    PS2TEST1      Test register 1
 *    PS2TEST2      Test register 2
 *    PS2TEST3      Test register 3
 *    PS2TEST4      Test register 4
 */

#define SA1101_MSE      0x001b0000

/*
 *  * These are offsets from the above bases.
 *   */
#define SA1101_PS2CR        0x000000
#define SA1101_PS2STAT      0x000400
#define SA1101_PS2DATA      0x000800
#define SA1101_PS2CLKDIV    0x000c00
#define SA1101_PS2PRECNT    0x001000

#define PS2CR_ENA       0x08
#define PS2CR_FKD       0x02
#define PS2CR_FKC       0x01

#define PS2STAT_TXE     0x0080
#define PS2STAT_TXB     0x0040
#define PS2STAT_RXF     0x0020
#define PS2STAT_RXB     0x0010
#define PS2STAT_ENA     0x0008
#define PS2STAT_RXP     0x0004
#define PS2STAT_KBD     0x0002
#define PS2STAT_KBC     0x0001






#endif  /* _ASM_ARCH_SA1101 */


More information about the Jornada820 mailing list