/*
 *  arch/arm/drivers/char/keyboard_psion.h
 *
 *  Psion keyboard definitions.
 *
 *  Copyright (C) 1998 Roger Gammans
 *  Copyright (C) 2000 Tony Lindgren <tony@atomide.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __ASM_ARCH_PSION_H
#define __ASM_ARCH_PSION_H

#include <asm/arch/hardware.h>

#define KBDSCAN         0x0000000f	/* Keyboard scan */
#define KBSC_HI         0x0             /* All driven high */
#define KBSC_LO         0x1             /* All driven low */
#define KBSC_X          0x2             /* All high impedance */
#define KBSC_COL0       0x8             /* Col 0 high, others high impedance */
#define KBSC_COL1       0x9             /* Col 1 high, others high impedance */
#define KBSC_COL2       0xa             /* Col 2 high, others high impedance */
#define KBSC_COL3       0xb             /* Col 3 high, others high impedance */
#define KBSC_COL4       0xc             /* Col 4 high, others high impedance */
#define KBSC_COL5       0xd             /* Col 5 high, others high impedance */
#define KBSC_COL6       0xe             /* Col 6 high, others high impedance */
#define KBSC_COL7       0xf             /* Col 7 high, others high impedance */

#define KB_JIFMASK	(127)

/*
 * Arm's keyboard is active high row select...
 *  (must try to remember)
 */
#define KB_ALLCOLS   KBSC_HI
#define KB_DISCHARGE KBSC_LO
#define KB_LASTROW   7

#define KBUP			(0x80)
#define KBDOWN			(0)

/*
 * Later on we'll try a struct of
 * two arrays then the existing keyboard.c can
 * test our array directly but until then....
 */
typedef struct {
	int in:1;		/* If the key down */
	int jif:7;		/* how long has key been down for (approx) */
} kbd_keyinfo;

static kbd_keyinfo kbdstate[NR_KEYCODES];

#ifdef KB_DELAY
extern unsigned int kbd_delay[];
#endif

/*
 *  Be sure to change the if you increase the
 *  number of kbd rows...
 */
#define KEYCODE(r,c)  ( ((c)<<3) + (r)+1)
#define KB_ROWMASK(r) (1 << (r))

/*
 * KB_DELAY is used to allow the matrix 
 * to stabilize.., value is determined via
 * experimentation. 
 */

#define KB_DELAY   {16 ,16 ,16 ,16 ,16 ,16 ,16 ,16 ,16}

/*
 * Not sure whether this trick works yet!
 * 
 */
#undef KBD_SUPPORTS_WIREOR

/*
 * treat debounce monostable as 30ms
 */

#define KB_DEB_JIFFY (30/HZ)

extern void psion_off(void);
void psion_toggle_backlight(void);
void psion_contrast(int increase);
void psion_debug_cf(void);

/*
 * Architecture-specific keys. Value 0 is invalid. 1 is SysRq.
 * Ctrl-Alt = Ctrl-Menu on Psion, For example: SysRq = Ctrl-Menu-,
 */
#define KBD_ARCHKEY_2	psion_off()			/* Fn-Off */
#define KBD_ARCHKEY_3	psion_toggle_backlight()	/* Fn-Space */
#define KBD_ARCHKEY_4	psion_contrast(0)		/* Fn-- */
#define KBD_ARCHKEY_5	psion_contrast(1)		/* Fn-+ */

/* KBD_ARCHKEY_6 to KBD_ARCHKEY_11 reserved for debugging */
#define KBD_ARCHKEY_6	0			/* Ctrl-Menu-z */

#ifdef CONFIG_PCMCIA_ETNA
extern void psion_debug_etna(void);
#define KBD_ARCHKEY_7	psion_debug_etna()	/* Ctrl-Menu-x */
#else
#define KBD_ARCHKEY_7	debug_gpio()		/* Ctrl-Menu-x */
#endif

#define KBD_ARCHKEY_8	0			/* Ctrl-Menu-c */
#define KBD_ARCHKEY_9	0			/* Ctrl-Menu-v */
#define KBD_ARCHKEY_8	0
#define KBD_ARCHKEY_9	0

#endif
