code:
/* $OpenBSD: zaurus_kbdmap.h,v 1.19 2005/05/10 08:26:12 espie Exp $ */

/*
 * Copyright (c) 2005 Dale Rahn <drahn@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#define KC(n) KS_KEYCODE(n)
#include <dev/wscons/wskbdraw.h>

static const keysym_t zkbd_keydesc_us[] = {
    KC(0),	KS_Control_L,
    KC(2),	KS_Tab,		KS_Tab,		KS_Caps_Lock,
    KC(3),	KS_Cmd_Screen1,	KS_f2,				/* Addr, */
    KC(4),	KS_Cmd_Screen0,	KS_f1,				/* Cal, */
    KC(5),	KS_Cmd_Screen2,	KS_f3,				/* Mail, */
    KC(6),	KS_Cmd_Screen3,	KS_f4,				/* Home, */
    KC(8),	KS_1,		KS_exclam,
    KC(9),	KS_2,		KS_quotedbl,
    KC(10),	KS_q,
    KC(11),	KS_w,		KS_W,		KS_asciicircum,
    KC(12),	KS_a,
    KC(13),	KS_z,
    KC(14),	KS_Cmd,		KS_Alt_L,
    KC(16),	KS_Cmd_BrightnessDown,	KS_3,	KS_numbersign,
    KC(17),	KS_Cmd_BrightnessUp,	KS_4,	KS_dollar,
    KC(18),	KS_e,		KS_E,		KS_equal,
    KC(19),	KS_s,
    KC(20),	KS_d,		KS_D,		KS_grave,
    KC(21),	KS_x,
    /* KC(22),	^/t (right japanese) */
    KC(24),	KS_5,		KS_percent,
    KC(25),	KS_r,		KS_R,		KS_plus,
    KC(26),	KS_t,		KS_T,		KS_bracketleft,
    KC(27),	KS_f,		KS_F,		KS_backslash,
    KC(28),	KS_c,
    KC(29),	KS_minus,	KS_minus,	KS_at,
    KC(30),	KS_Cmd_Debugger,KS_Escape,	/* Cancel */
    KC(32),	KS_6,		KS_ampersand,
    KC(33),	KS_y,		KS_Y,		KS_bracketright,
    KC(34),	KS_g,		KS_G,		KS_semicolon,
    KC(35),	KS_v,
    KC(36),	KS_b,		KS_B,		KS_underscore,
    KC(37),	KS_space,
    KC(38),	KS_KP_Enter,	/* ok */
    KC(40),	KS_7,		KS_apostrophe,
    KC(41),	KS_8,		KS_parenleft,
    KC(42),	KS_u,		KS_U,		KS_braceleft,
    KC(43),	KS_h,		KS_H,		KS_colon,
    KC(44),	KS_n,
    KC(45),	KS_comma,	KS_slash,	KS_less,
    KC(46),	KS_Cmd_Screen4,	KS_f5,				/* Menu, */
    KC(48),	KS_9,		KS_parenright,
    KC(49),	KS_i,		KS_I,		KS_braceright,
    KC(50),	KS_j,		KS_J,		KS_asterisk,
    KC(51),	KS_m,
    KC(52),	KS_period,	KS_question,	KS_greater,
    KC(54),	KS_KP_Left,	KS_KP_Left,	KS_Home, /* left, */
    KC(56),	KS_0,		KS_asciitilde,
    KC(57),	KS_o,
    KC(58),	KS_k,
    KC(59),	KS_l,		KS_L,		KS_bar,
    KC(61),	KS_KP_Up,	KS_KP_Up,	KS_Prior, /* up, */
    KC(62),	KS_KP_Down,	KS_KP_Down,	KS_Next, /* down, */
    KC(64),	KS_Delete,	KS_BackSpace,
    KC(65),	KS_p,
    KC(68),	KS_Return,
    KC(70),	KS_KP_Right,	KS_KP_Right,	KS_End, /* right, */
    KC(80),	KS_KP_Right, /* OK, (ext) */
    KC(81),	KS_KP_Down, /* tog left, */
    KC(83),	KS_Shift_R,
    KC(84),	KS_Shift_L,
    KC(88),	KS_KP_Left, /* cancel (ext), */
    KC(89),	KS_KP_Up, /* tog right, */
    KC(93),	KS_Mode_switch /* Fn */
};

#ifdef WSDISPLAY_COMPAT_RAWKBD
static const char xt_keymap[] = {
    /* KC(0), */	RAWKEY_Control_L,/* KS_Control_L, */
    /* KC(1), */	RAWKEY_Null, /* NC */
    /* KC(2), */	RAWKEY_Tab, /* KS_Tab,	KS_Tab,		KS_Caps_Lock, */
    /* KC(3), */	RAWKEY_f2, /* KS_Cmd_Screen1,	KS_f2,		Addr, */
    /* KC(4), */	RAWKEY_f1, /* KS_Cmd_Screen0,	KS_f1,		Cal, */
    /* KC(5), */	RAWKEY_f3, /* KS_Cmd_Screen2,	KS_f3,		Mail, */
    /* KC(6), */	RAWKEY_f4, /* KS_Cmd_Screen3,	KS_f4,		Home, */
    /* KC(7), */	RAWKEY_Null, /* NC */
    /* KC(8), */	RAWKEY_1, /* KS_1,		KS_exclam, */
    /* KC(9), */	RAWKEY_2, /* KS_2,		KS_quotedbl, */
    /* KC(10), */	RAWKEY_q, /* KS_q, */
    /* KC(11), */	RAWKEY_w, /* KS_w,	KS_W,	KS_asciicircum, */
    /* KC(12), */	RAWKEY_a, /* KS_a, */
    /* KC(13), */	RAWKEY_z, /* KS_z, */
    /* KC(14), */	RAWKEY_Alt_L, /* KS_Cmd,		KS_Alt_L, */
    /* KC(15), */	RAWKEY_Null, /* NC */
    /* KC(16), */	RAWKEY_3, /* KS_3,	KS_numbersign, */
    /* KC(17), */	RAWKEY_4, /* KS_4,	KS_dollar, */
    /* KC(18), */	RAWKEY_e, /* KS_e,	KS_E,		KS_equal, */
    /* KC(19), */	RAWKEY_s, /* KS_s, */
    /* KC(20), */	RAWKEY_d, /* KS_d,	KS_D,		KS_grave, */
    /* KC(21), */	RAWKEY_x, /* KS_x, */
    /* KC(22), */	RAWKEY_Null, /* ^/t (right japanese) */
    /* KC(23), */	RAWKEY_Null, /* NC */
    /* KC(24), */	RAWKEY_5, /* KS_5,	KS_percent, */
    /* KC(25), */	RAWKEY_r, /* KS_r,	KS_R,		KS_plus, */
    /* KC(26), */	RAWKEY_t, /* KS_t,	KS_T,		KS_bracketleft, */
    /* KC(27), */	RAWKEY_f, /* KS_f,		KS_F,		KS_backslash, */
    /* KC(28), */	RAWKEY_c, /* KS_c, */
    /* KC(29), */	RAWKEY_minus, /* KS_minus, KS_minus,	KS_at, */
    /* KC(30), */	RAWKEY_Escape, /* KS_Escape, Cancel */
    /* KC(31), */	RAWKEY_Null, /* NC */
    /* KC(32), */	RAWKEY_6, /* KS_6,		KS_ampersand, */
    /* KC(33), */	RAWKEY_y, /* KS_y,	KS_Y,	KS_bracketright, */
    /* KC(34), */	RAWKEY_g, /* KS_g,		KS_G,	KS_semicolon, */
    /* KC(35), */	RAWKEY_v, /* KS_v, */
    /* KC(36), */	RAWKEY_b, /* KS_b,	KS_B,	KS_underscore, */
    /* KC(37), */	RAWKEY_space, /* KS_space, */
    /* KC(38), */	RAWKEY_KP_Enter, /* KS_KP_Enter,	ok */
    /* KC(39), */	RAWKEY_Null, /* NC */
    /* KC(40), */	RAWKEY_7, /* KS_7,	KS_apostrophe, */
    /* KC(41), */	RAWKEY_8, /* KS_8,	KS_parenleft, */
    /* KC(42), */	RAWKEY_u, /* KS_u,	KS_U,		KS_braceleft,	 */
    /* KC(43), */	RAWKEY_h, /* KS_h,	KS_H,		KS_colon, */
    /* KC(44), */	RAWKEY_n, /* KS_n, */
    /* KC(45), */	RAWKEY_comma, /* KS_comma, KS_slash,	KS_less, */
    /* KC(46), */	RAWKEY_f5, /* KS_Cmd_Screen4,	KS_f5,		Menu, */
    /* KC(47), */	RAWKEY_Null, /* NC */
    /* KC(48), */	RAWKEY_9, /* KS_9,	KS_parenright, */
    /* KC(49), */	RAWKEY_i, /* KS_i,	KS_I,	KS_braceright, */
    /* KC(50), */	RAWKEY_j, /* KS_j,	KS_J,		KS_asterisk, */
    /* KC(51), */	RAWKEY_m, /* KS_m, */
    /* KC(52), */	RAWKEY_period, /* KS_period, KS_question, KS_greater, */
    /* KC(53), */	RAWKEY_Null, /* NC */
    /* KC(54), */	RAWKEY_Left, /* KS_KP_Left, left, */
    /* KC(55), */	RAWKEY_Null, /* NC */
    /* KC(56), */	RAWKEY_0, /* KS_0,	KS_asciitilde, */
    /* KC(57), */	RAWKEY_o, /* KS_o, */
    /* KC(58), */	RAWKEY_k, /* KS_k, */
    /* KC(59), */	RAWKEY_l, /* KS_l,	KS_L,		KS_bar, */
    /* KC(60), */	RAWKEY_Null, /* NC */
    /* KC(61), */	RAWKEY_Up, /* KS_KP_Up, up, */
    /* KC(62), */	RAWKEY_Down, /* KS_KP_Down, down, */
    /* KC(63), */	RAWKEY_Null, /* NC */
    /* KC(64), */	RAWKEY_BackSpace, /* KS_Delete,	KS_BackSpace, */
    /* KC(65), */	RAWKEY_p, /* KS_p, */
    /* KC(66), */	RAWKEY_Null, /* NC */
    /* KC(67), */	RAWKEY_Null, /* NC */
    /* KC(68), */	RAWKEY_Return, /* KS_Return, */
    /* KC(69), */	RAWKEY_Null, /* NC */
    /* KC(70), */	RAWKEY_Right, /* KS_KP_Right, right, */
    /* KC(71), */	RAWKEY_Null, /* NC */
    /* KC(72), */	RAWKEY_Null, /* NC */
    /* KC(73), */	RAWKEY_Null, /* NC */
    /* KC(74), */	RAWKEY_Null, /* NC */
    /* KC(75), */	RAWKEY_Null, /* NC */
    /* KC(76), */	RAWKEY_Null, /* NC */
    /* KC(77), */	RAWKEY_Null, /* NC */
    /* KC(78), */	RAWKEY_Null, /* NC */
    /* KC(79), */	RAWKEY_Null, /* NC */
    /* KC(80), */	RAWKEY_Right, /* KS_KP_Right, OK, (ext) */
    /* KC(81), */	RAWKEY_Down, /* KS_KP_Down, tog left, */
    /* KC(82), */	RAWKEY_Null, /* NC */
    /* KC(83), */	RAWKEY_Shift_R, /* KS_Shift_R, */
    /* KC(84), */	RAWKEY_Shift_L, /* KS_Shift_L, */
    /* KC(85), */	RAWKEY_Null, /* NC */
    /* KC(86), */	RAWKEY_Null, /* NC */
    /* KC(87), */	RAWKEY_Null, /* NC */
    /* KC(88), */	RAWKEY_Left, /* KS_KP_Left, cancel (ext), */
    /* KC(89), */	RAWKEY_Up, /* KS_KP_Up, tog right, */
    /* KC(90), */	RAWKEY_Null, /* NC */
    /* KC(91), */	RAWKEY_Null, /* NC */
    /* KC(92), */	RAWKEY_Null, /* NC */
    /* KC(93), */	RAWKEY_Alt_R, /* KS_Mode_switch Fn */
};
#endif

#define KBD_MAP(name, base, map) \
			{ name, base, sizeof(map)/sizeof(keysym_t), map }

static const struct wscons_keydesc zkbd_keydesctab[] = {
        KBD_MAP(KB_US,                  0,      zkbd_keydesc_us),
        {0, 0, 0, 0}
};

#undef KBD_MAP
#undef KC


code:
/*	$OpenBSD: zaurus_remote.c,v 1.2 2014/01/26 17:48:08 miod Exp $	*/

/*
 * Copyright (c) 2005 Uwe Stuehler <uwe@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/param.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/timeout.h>
#include <sys/systm.h>

#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wskbdraw.h>
#include <dev/wscons/wskbdvar.h>
#include <dev/wscons/wsksymdef.h>
#include <dev/wscons/wsksymvar.h>

#include <machine/intr.h>
#include <machine/zaurus_var.h>

#include <arm/xscale/pxa2x0reg.h>
#include <arm/xscale/pxa2x0_gpio.h>

#include <zaurus/dev/zaurus_scoopvar.h>
#include <zaurus/dev/zaurus_sspvar.h>

#define RESCAN_INTERVAL		(hz/100)

#define KEY_RELEASE		0	/* button release */
#define KEY_VOL_DOWN		1
#define KEY_MUTE		2
#define KEY_REWIND		3
#define KEY_VOL_UP		4
#define KEY_FORWARD		5
#define KEY_PLAY		6
#define KEY_STOP		7
#define KEY_EARPHONE		8

#ifdef DEBUG
static const char *zrc_keyname[] = {
	"(release)", "volume down", "mute", "rewind", "volume up",
	"forward", "play", "stop", "(earphone)"
};
#endif

struct zrc_akey {
	int	min;		/* minimum ADC value or INT_MIN */
	int	key;		/* remote control key number */
};

/* Values match the resistors in the CE-RH2 remote control. */
static const struct zrc_akey zrc_akeytab_c3000[] = {
	{ 238,		KEY_RELEASE  },
	{ 202,		KEY_VOL_DOWN },
	{ 168,		KEY_MUTE     },
	{ 135,		KEY_REWIND   },
	{ 105,		KEY_VOL_UP   },
	{ 74,		KEY_FORWARD  },
	{ 42,		KEY_PLAY     },
	{ 12,		KEY_STOP     },
	{ INT_MIN,	KEY_EARPHONE }
};

static const struct zrc_akey *zrc_akeytab = zrc_akeytab_c3000;

struct zrc_softc {
	struct device	 sc_dev;
	struct timeout	 sc_to;
	void		*sc_ih;
	int		 sc_key;	/* being scanned */
	int		 sc_scans;	/* rescan counter */
	int		 sc_noise;	/* discard if too noisy? */
	int		 sc_keydown;	/* currently pressed key */
	struct device   *sc_wskbddev;
#ifdef WSDISPLAY_COMPAT_RAWKBD
	int		 sc_rawkbd;
#endif
};

int	zrc_match(struct device *, void *, void *);
void	zrc_attach(struct device *, struct device *, void *);

int	zrc_intr(void *);
void	zrc_timeout(void *);
int	zrc_scan(void);
void	zrc_input(struct zrc_softc *, int, int);

struct cfattach zrc_ca = {
	sizeof(struct zrc_softc), zrc_match, zrc_attach
};

struct cfdriver zrc_cd = {
	NULL, "zrc", DV_DULL
};

int	zrc_enable(void *, int);
void	zrc_set_leds(void *, int);
int	zrc_ioctl(void *, u_long, caddr_t, int, struct proc *);

struct wskbd_accessops zrc_accessops = {
	zrc_enable,
	zrc_set_leds,
	zrc_ioctl,
};

#define KC(n) KS_KEYCODE(n)

/* XXX what keys should be generated in translated mode? */
static const keysym_t zrc_keydesc[] = {
	KC(KEY_VOL_DOWN),	KS_minus,
	KC(KEY_MUTE),		KS_m,
	KC(KEY_REWIND),		KS_b,
	KC(KEY_VOL_UP),		KS_plus,
	KC(KEY_FORWARD),	KS_f,
	KC(KEY_PLAY),		KS_p,
	KC(KEY_STOP),		KS_s,
};

#ifdef WSDISPLAY_COMPAT_RAWKBD
#define	RAWKEY_AudioRewind	0xa0
#define	RAWKEY_AudioForward	0xa1
#define	RAWKEY_AudioPlay	0xa2
#define	RAWKEY_AudioStop	0xa3
static const keysym_t zrc_xt_keymap[] = {
	/* KC(KEY_RELEASE), */	RAWKEY_Null,
	/* KC(KEY_VOL_DOWN), */	RAWKEY_AudioLower,
	/* KC(KEY_MUTE), */	RAWKEY_AudioMute,
	/* KC(KEY_REWIND), */	RAWKEY_AudioRewind,
	/* KC(KEY_VOL_UP), */	RAWKEY_AudioRaise,
	/* KC(KEY_FORWARD), */	RAWKEY_AudioForward,
	/* KC(KEY_PLAY), */	RAWKEY_AudioPlay,
	/* KC(KEY_STOP), */	RAWKEY_AudioStop,
};
#endif

static const struct wscons_keydesc zrc_keydesctab[] = {
        {KB_US, 0, sizeof(zrc_keydesc)/sizeof(keysym_t), zrc_keydesc},
        {0, 0, 0, 0}
};

struct wskbd_mapdata zrc_keymapdata = {
	zrc_keydesctab, KB_US | KB_DEFAULT
};

int
zrc_match(struct device *parent, void *match, void *aux)
{
	return (ZAURUS_ISC3000);
}

void
zrc_attach(struct device *parent, struct device *self, void *aux)
{
	struct zrc_softc *sc = (struct zrc_softc *)self;
	struct wskbddev_attach_args a;

	/* Configure remote control interrupt handling. */
	timeout_set(&sc->sc_to, zrc_timeout, sc);
	pxa2x0_gpio_set_function(C3000_RC_IRQ_PIN, GPIO_IN);
	sc->sc_ih = pxa2x0_gpio_intr_establish(C3000_RC_IRQ_PIN,
	    IST_EDGE_BOTH, IPL_BIO, zrc_intr, sc, "zrc");

	/* Enable the pullup while waiting for an interrupt. */
	scoop_akin_pullup(1);

	sc->sc_keydown = KEY_RELEASE;

	printf(": CE-RH2 remote control\n");

	a.console = 0;
	a.keymap = &zrc_keymapdata;
	a.accessops = &zrc_accessops;
	a.accesscookie = sc;

	sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
}

int
zrc_intr(void *v)
{
	struct zrc_softc *sc = v;

	/* just return if remote control isn't present */

	pxa2x0_gpio_intr_mask(sc->sc_ih);
	scoop_akin_pullup(0);
	sc->sc_key = zrc_scan();
	sc->sc_scans = 0;
	sc->sc_noise = 0;
	timeout_add(&sc->sc_to, RESCAN_INTERVAL);
	return (1);
}

void
zrc_timeout(void *v)
{
	struct zrc_softc *sc = v;
	int	key;

	key = zrc_scan();
	switch (sc->sc_scans) {
	case 0:
	case 1:
	case 2:
		/* wait for a stable read */
		if (sc->sc_key == key)
			sc->sc_scans++;
		else {
			sc->sc_key = key;
			sc->sc_scans = 0;
			sc->sc_noise++;
		}
		timeout_add(&sc->sc_to, RESCAN_INTERVAL);
		break;
	case 3:
		/* generate key press event */
		if (sc->sc_key != key) {
			key = sc->sc_key;
			sc->sc_noise++;
		}
		sc->sc_scans++;
		switch (key) {
		case KEY_EARPHONE:
		case KEY_RELEASE:
			sc->sc_scans = 6;
			break;
		default:
#ifdef DEBUG
			printf("%s pressed (%d noise)\n", zrc_keyname[key],
			    sc->sc_noise);
#endif
			sc->sc_keydown = key;
			sc->sc_noise = 0;
			zrc_input(sc, key, 1);
			break;
		}
		timeout_add(&sc->sc_to, RESCAN_INTERVAL);
		break;
	case 4:
	case 5:
		/* wait for key release, permit noise */
		if (sc->sc_key == key) {
			if (sc->sc_scans == 5)
				sc->sc_noise++;
			sc->sc_scans = 4;
		} else
			sc->sc_scans++;
		timeout_add(&sc->sc_to, RESCAN_INTERVAL);
		break;
	case 6:
		/* generate key release event */
		if (sc->sc_keydown != KEY_RELEASE) {
			zrc_input(sc, sc->sc_keydown, 0);
#ifdef DEBUG
			printf("%s released (%d noise)\n",
			    zrc_keyname[sc->sc_keydown], sc->sc_noise);
#endif
			sc->sc_keydown = KEY_RELEASE;
		}
		/* FALLTHROUGH */
	default:
		/* unmask interrupt again */
		timeout_del(&sc->sc_to);
		sc->sc_scans = 7;
		scoop_akin_pullup(1);
		pxa2x0_gpio_intr_unmask(sc->sc_ih);
	}
}

int
zrc_scan(void)
{
	int	val;
	int	i;

/* XXX MAX1111 command word - also appears in zaurus_apm.c */
#define MAXCTRL_PD0		(1<<0)
#define MAXCTRL_PD1		(1<<1)
#define MAXCTRL_SGL		(1<<2)
#define MAXCTRL_UNI		(1<<3)
#define MAXCTRL_SEL_SHIFT	4
#define MAXCTRL_STR		(1<<7)

#define C3000_ADCCH_ZRC 0
	val = zssp_read_max1111(MAXCTRL_PD0 | MAXCTRL_PD1 | MAXCTRL_SGL |
	    MAXCTRL_UNI | (C3000_ADCCH_ZRC << MAXCTRL_SEL_SHIFT) |
	    MAXCTRL_STR);
	for (i = 0; zrc_akeytab[i].min != INT_MIN; i++)
		if (val >= zrc_akeytab[i].min)
			break;
	return (zrc_akeytab[i].key);
}

void
zrc_input(struct zrc_softc *sc, int key, int down)
{
	u_int	type = down ? WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP;
	int	s;

	s = spltty();

#ifdef WSDISPLAY_COMPAT_RAWKBD
	if (sc->sc_rawkbd) {
		int	c;
		u_char	cbuf[2];
		int	ncbuf = 0;

		c = zrc_xt_keymap[key];
		if (c & 0x80)
			cbuf[ncbuf++] = 0xe0;
		cbuf[ncbuf] = c & 0x7f;

		if (!down)
			cbuf[ncbuf] |= 0x80;
		ncbuf++;

		wskbd_rawinput(sc->sc_wskbddev, cbuf, ncbuf);
	} else
#endif
		wskbd_input(sc->sc_wskbddev, type, key);

	splx(s);
}

int
zrc_enable(void *v, int on)
{
	return (0);
}

void
zrc_set_leds(void *v, int on)
{
}

int
zrc_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
{
#ifdef WSDISPLAY_COMPAT_RAWKBD
	struct zrc_softc *sc = v;
#endif

	switch (cmd) {
	case WSKBDIO_GTYPE:
		*(int *)data = WSKBD_TYPE_ZAURUS;
		return (0);
	case WSKBDIO_SETLEDS:
		return (0);
	case WSKBDIO_GETLEDS:
		*(int *)data = 0;
		return (0);
#ifdef WSDISPLAY_COMPAT_RAWKBD
	case WSKBDIO_SETMODE:
		sc->sc_rawkbd = *(int *)data == WSKBD_RAW;
		return (0);
#endif
	}
	return (-1);
}

license: unknown


code:
/*	$OpenBSD: zaurus_scoop.c,v 1.21 2010/09/07 16:21:41 deraadt Exp $	*/

/*
 * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/param.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/disk.h>
#include <sys/timeout.h>
#include <sys/gpio.h>

#include <machine/bus.h>

#include <arm/xscale/pxa2x0var.h>

#include <machine/machine_reg.h>
#include <machine/zaurus_var.h>

#include <zaurus/dev/zaurus_scoopreg.h>
#include <zaurus/dev/zaurus_scoopvar.h>

struct scoop_softc {
	struct device sc_dev;
	bus_space_tag_t sc_iot;
	bus_space_handle_t sc_ioh;
	u_int16_t sc_gpwr;	/* GPIO state before suspend */
	int sc_suspended;
};

int	scoopmatch(struct device *, void *, void *);
void	scoopattach(struct device *, struct device *, void *);
int	scoop_activate(struct device *, int);

struct cfattach scoop_ca = {
	sizeof (struct scoop_softc), scoopmatch, scoopattach, NULL,
	scoop_activate
};

struct cfdriver scoop_cd = {
	NULL, "scoop", DV_DULL
};

enum card {
	SD_CARD,
	CF_CARD			/* socket 0 (external) */
};

int	scoop_gpio_pin_read(struct scoop_softc *sc, int);
void	scoop_gpio_pin_write(struct scoop_softc *sc, int, int);
void	scoop_gpio_pin_ctl(struct scoop_softc *sc, int, int);
void	scoop0_set_card_power(enum card, int);

struct timeout	scoop_checkdisk;
void	scoop_timeout(void *);

int
scoopmatch(struct device *parent, void *match, void *aux)
{
	struct cfdata *cf = match;

	/*
	 * Only C3000-like models are known to have two SCOOPs.
	 */
        if (ZAURUS_ISC3000)
	    	return (cf->cf_unit < 2);

	return (cf->cf_unit == 0);
}

void
scoopattach(struct device *parent, struct device *self, void *aux)
{
	struct pxaip_attach_args *pxa = aux;
	struct scoop_softc *sc = (struct scoop_softc *)self;
	bus_addr_t addr;
	bus_size_t size;

	sc->sc_iot = pxa->pxa_iot;

	if (pxa->pxa_addr != -1)
		addr = pxa->pxa_addr;
	else if (sc->sc_dev.dv_unit == 0)
		addr = C3000_SCOOP0_BASE;
	else
		addr = C3000_SCOOP1_BASE;

	size = pxa->pxa_size < SCOOP_SIZE ? SCOOP_SIZE : pxa->pxa_size;

	if (bus_space_map(sc->sc_iot, addr, size, 0, &sc->sc_ioh) != 0) {
		printf(": failed to map %s\n", sc->sc_dev.dv_xname);
		return;
	}

	if (ZAURUS_ISC3000 && sc->sc_dev.dv_unit == 1) {
		scoop_gpio_pin_ctl(sc, SCOOP1_AKIN_PULLUP, GPIO_PIN_OUTPUT);
		scoop_gpio_pin_write(sc, SCOOP1_AKIN_PULLUP, GPIO_PIN_LOW);
	} else if (!ZAURUS_ISC3000) {
		scoop_gpio_pin_ctl(sc, SCOOP0_AKIN_PULLUP, GPIO_PIN_OUTPUT);
		scoop_gpio_pin_write(sc, SCOOP0_AKIN_PULLUP, GPIO_PIN_LOW);
	}

	if (sc->sc_dev.dv_unit == 0)
		timeout_set(&scoop_checkdisk, scoop_timeout, sc);

	printf(": PCMCIA/GPIO controller\n");
}

int
scoop_gpio_pin_read(struct scoop_softc *sc, int pin)
{
	u_int16_t rv;
	u_int16_t bit = (1 << pin);

	rv = bus_space_read_2(sc->sc_iot, sc->sc_ioh, SCOOP_GPWR);
	return (rv & bit) != 0 ? 1 : 0;
}

void
scoop_gpio_pin_write(struct scoop_softc *sc, int pin, int level)
{
	u_int16_t rv;
	u_int16_t bit = (1 << pin);
	int s;

	s = splhigh();
	rv = bus_space_read_2(sc->sc_iot, sc->sc_ioh, SCOOP_GPWR);
	bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCOOP_GPWR,
	    level == GPIO_PIN_LOW ? (rv & ~bit) : (rv | bit));
	splx(s);
}

void
scoop_gpio_pin_ctl(struct scoop_softc *sc, int pin, int flags)
{
	u_int16_t rv;
	u_int16_t bit = (1 << pin);

	rv = bus_space_read_2(sc->sc_iot, sc->sc_ioh, SCOOP_GPCR);
	switch (flags & (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT)) {
	case GPIO_PIN_INPUT:
		rv &= ~bit;
		break;
	case GPIO_PIN_OUTPUT:
		rv |= bit;
		break;
	}
	bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCOOP_GPCR, rv);
}

/*
 * Turn the LCD background light and contrast signal on or off.
 */
void
scoop_set_backlight(int on, int cont)
{

	if (scoop_cd.cd_ndevs > 1 && scoop_cd.cd_devs[1] != NULL) {
		/* C3000 */
		scoop_gpio_pin_write(scoop_cd.cd_devs[1],
		    SCOOP1_BACKLIGHT_CONT, !cont);
		scoop_gpio_pin_write(scoop_cd.cd_devs[1],
		    SCOOP1_BACKLIGHT_ON, on);
	}
#if 0
	else if (scoop_cd.cd_ndevs > 0 && scoop_cd.cd_devs[0] != NULL) {
		scoop_gpio_pin_write(scoop_cd.cd_devs[0],
		    SCOOP0_BACKLIGHT_CONT, cont);
	}
#endif
}

/*
 * Turn the infrared LED on or off (must be on while transmitting).
 */
void
scoop_set_irled(int on)
{
	if (scoop_cd.cd_ndevs > 1 && scoop_cd.cd_devs[1] != NULL)
		/* IR_ON is inverted */
		scoop_gpio_pin_write(scoop_cd.cd_devs[1],
		    SCOOP1_IR_ON, !on);
}

/*
 * Turn the green and orange LEDs on or off.  If the orange LED is on,
 * then it is wired to indicate if A/C is connected.  The green LED has
 * no such predefined function.
 */
void
scoop_led_set(int led, int on)
{

	if (scoop_cd.cd_ndevs > 0 && scoop_cd.cd_devs[0] != NULL) {
		if ((led & SCOOP_LED_GREEN) != 0)
			scoop_gpio_pin_write(scoop_cd.cd_devs[0],
			    SCOOP0_LED_GREEN, on);
		if (scoop_cd.cd_ndevs > 1 && (led & SCOOP_LED_ORANGE) != 0)
			scoop_gpio_pin_write(scoop_cd.cd_devs[0],
			    SCOOP0_LED_ORANGE_C3000, on);
	}
}

/*
 * Enable or disable the headphone output connection.
 */
void
scoop_set_headphone(int on)
{
	if (scoop_cd.cd_ndevs < 1 || scoop_cd.cd_devs[0] == NULL)
		return;

	scoop_gpio_pin_ctl(scoop_cd.cd_devs[0], SCOOP0_MUTE_L,
	    GPIO_PIN_OUTPUT);
	scoop_gpio_pin_ctl(scoop_cd.cd_devs[0], SCOOP0_MUTE_R,
	    GPIO_PIN_OUTPUT);

	if (on) {
		scoop_gpio_pin_write(scoop_cd.cd_devs[0], SCOOP0_MUTE_L,
		    GPIO_PIN_HIGH);
		scoop_gpio_pin_write(scoop_cd.cd_devs[0], SCOOP0_MUTE_R,
		    GPIO_PIN_HIGH);
	} else {
		scoop_gpio_pin_write(scoop_cd.cd_devs[0], SCOOP0_MUTE_L,
		    GPIO_PIN_LOW);
		scoop_gpio_pin_write(scoop_cd.cd_devs[0], SCOOP0_MUTE_R,
		    GPIO_PIN_LOW);
	}
}

/*
 * Enable or disable 3.3V power to the SD/MMC card slot.
 */
void
scoop_set_sdmmc_power(int on)
{
	scoop0_set_card_power(SD_CARD, on ? SCP_CPR_SD_3V : SCP_CPR_OFF);
}

/*
 * The Card Power Register of the first SCOOP unit controls the power
 * for the first CompactFlash slot and the SD/MMC card slot as well.
 */
void
scoop0_set_card_power(enum card slot, int new_cpr)
{
	struct scoop_softc *sc = scoop_cd.cd_devs[0];
	u_int16_t cpr;

	cpr = bus_space_read_2(sc->sc_iot, sc->sc_ioh, SCOOP_CPR);
	if (new_cpr & SCP_CPR_VOLTAGE_MSK) {
		if (slot == CF_CARD)
			cpr |= SCP_CPR_5V;
		else if (slot == SD_CARD)
			cpr |= SCP_CPR_SD_3V;

		scoop_gpio_pin_write(sc, SCOOP0_CF_POWER_C3000, 1);
		if (!ISSET(cpr, SCP_CPR_5V) && !ISSET(cpr, SCP_CPR_SD_3V))
			delay(5000);
		bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCOOP_CPR,
		    cpr | new_cpr);
	} else {
		if (slot == CF_CARD)
			cpr &= ~SCP_CPR_5V;
		else if (slot == SD_CARD)
			cpr &= ~SCP_CPR_SD_3V;

		if (!ISSET(cpr, SCP_CPR_5V) && !ISSET(cpr, SCP_CPR_SD_3V)) {
			bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCOOP_CPR,
			    SCP_CPR_OFF);
			delay(1000);
			scoop_gpio_pin_write(sc, SCOOP0_CF_POWER_C3000, 0);
		} else
			bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCOOP_CPR,
			    cpr | new_cpr);
	}
}

/*
 * Turn on pullup resistor while not reading the remote control.
 */
void
scoop_akin_pullup(int enable)
{
	if (scoop_cd.cd_ndevs > 1 && scoop_cd.cd_devs[1] != NULL)
		scoop_gpio_pin_write(scoop_cd.cd_devs[1],
		    SCOOP1_AKIN_PULLUP, enable);
	else
		scoop_gpio_pin_write(scoop_cd.cd_devs[0],
		    SCOOP0_AKIN_PULLUP, enable);
}

void
scoop_battery_temp_adc(int enable)
{

	if (scoop_cd.cd_ndevs > 0 && scoop_cd.cd_devs[0] != NULL)
		scoop_gpio_pin_write(scoop_cd.cd_devs[0],
		    SCOOP0_ADC_TEMP_ON_C3000, enable);
}

void
scoop_charge_battery(int enable, int voltage_high)
{

	if (scoop_cd.cd_ndevs > 0 && scoop_cd.cd_devs[0] != NULL) {
		scoop_gpio_pin_write(scoop_cd.cd_devs[0],
		    SCOOP0_JK_B_C3000, voltage_high);
		scoop_gpio_pin_write(scoop_cd.cd_devs[0],
		    SCOOP0_CHARGE_OFF_C3000, !enable);
	}
}

void
scoop_discharge_battery(int enable)
{

	if (scoop_cd.cd_ndevs > 0 && scoop_cd.cd_devs[0] != NULL)
		scoop_gpio_pin_write(scoop_cd.cd_devs[0],
		    SCOOP0_JK_A_C3000, enable);
}

/* XXX */
void scoop_check_mcr(void);
void
scoop_check_mcr(void)
{
	struct	scoop_softc *sc;

	/* C3000 */
	if (scoop_cd.cd_ndevs > 1 && scoop_cd.cd_devs[1] != NULL) {

		sc = scoop_cd.cd_devs[0];
		if ((bus_space_read_2(sc->sc_iot, sc->sc_ioh, SCOOP_MCR) &
		    0x100) == 0)
			bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCOOP_MCR,
			    0x0101);

		sc = scoop_cd.cd_devs[1];
		if ((bus_space_read_2(sc->sc_iot, sc->sc_ioh, SCOOP_MCR) &
		    0x100) == 0)
			bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCOOP_MCR,
			    0x0101);
	}
}

void
scoop_suspend(void)
{
	struct scoop_softc *sc;
	u_int32_t rv;

	scoop_check_mcr();

	if (scoop_cd.cd_ndevs > 0 && scoop_cd.cd_devs[0] != NULL) {
		sc = scoop_cd.cd_devs[0];
		sc->sc_gpwr = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
		    SCOOP_GPWR);
		/* C3000 */
		bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCOOP_GPWR,
		    sc->sc_gpwr & ~((1<<SCOOP0_MUTE_L) | (1<<SCOOP0_MUTE_R) |
		    (1<<SCOOP0_JK_A_C3000) | (1<<SCOOP0_ADC_TEMP_ON_C3000) |
		    (1<<SCOOP0_LED_GREEN)));
	}

	/* C3000 */
	if (scoop_cd.cd_ndevs > 1 && scoop_cd.cd_devs[1] != NULL) {
		sc = scoop_cd.cd_devs[1];
		sc->sc_gpwr = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
		    SCOOP_GPWR);
		bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCOOP_GPWR,
		    sc->sc_gpwr & ~((1<<SCOOP1_RESERVED_4) |
		    (1<<SCOOP1_RESERVED_5) | (1<<SCOOP1_RESERVED_6) |
		    (1<<SCOOP1_BACKLIGHT_CONT) | (1<<SCOOP1_BACKLIGHT_ON) |
		    (1<<SCOOP1_MIC_BIAS)));
		rv = bus_space_read_2(sc->sc_iot, sc->sc_ioh, SCOOP_GPWR);
		bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCOOP_GPWR,
		    rv | ((1<<SCOOP1_IR_ON) | (1<<SCOOP1_RESERVED_3)));
	}
}

void
scoop_resume(void)
{
	struct scoop_softc *sc;

	scoop_check_mcr();

	if (scoop_cd.cd_ndevs > 0 && scoop_cd.cd_devs[0] != NULL) {
		sc = scoop_cd.cd_devs[0];
		bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCOOP_GPWR,
		    sc->sc_gpwr);
	}

	if (scoop_cd.cd_ndevs > 1 && scoop_cd.cd_devs[1] != NULL) {
		sc = scoop_cd.cd_devs[1];
		bus_space_write_2(sc->sc_iot, sc->sc_ioh, SCOOP_GPWR,
		    sc->sc_gpwr);
	}
}

void
scoop_timeout(void *v)
{
	extern struct disklist_head disklist;
	struct scoop_softc *sc = v;
	static struct disk *dk;
	static int state = 0;

	if (dk == NULL) {
		TAILQ_FOREACH(dk, &disklist, dk_link) {
			if (dk->dk_name &&
			    strcmp(dk->dk_name, "wd0") == 0)
				break;
		}
	}

	if (sc->sc_suspended)
		state = -1;
	else if (dk) {
		int newstate = (dk->dk_busy ? 1 : 0);

		if (newstate != state) {
			state = newstate;
			scoop_led_set(SCOOP_LED_GREEN, newstate);
		}
	}
	timeout_add(&scoop_checkdisk, hz/25);
}

int
scoop_activate(struct device *self, int act)
{
	struct scoop_softc *sc = (struct scoop_softc *)self;

	switch (act) {
	case DVACT_SUSPEND:
		/*
		 * Nothing should use the scoop from this point on.
		 * No timeouts, no interrupts (even though interrupts
		 * are still enabled).  scoop_timeout() respects the
		 * sc_suspended flag.
		 */
		if (sc->sc_dev.dv_unit == 0) {
			sc->sc_suspended = 1;
			scoop_suspend();
		}
		break;
	case DVACT_RESUME:
		if (sc->sc_dev.dv_unit == 0) {
			scoop_resume();
			sc->sc_suspended = 0;
		}
		break;
	}
	return 0;
}


code:
/*	$OpenBSD: zaurus_scoopreg.h,v 1.8 2007/03/18 20:50:23 uwe Exp $	*/

/*
 * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#define SCOOP_SIZE		0x2c

/* registers and values */

#define SCOOP_MCR		0x00
#define  SCP_MCR_IOCARD		0x0010
#define SCOOP_CDR		0x04	/* card detect register */
#define  SCP_CDR_DETECT		0x0002
#define SCOOP_CSR		0x08	/* card status register */
#define  SCP_CSR_READY		0x0002
#define  SCP_CSR_MISSING	0x0004
#define  SCP_CSR_WPROT		0x0008
#define  SCP_CSR_BVD1		0x0010
#define  SCP_CSR_BVD2		0x0020
#define  SCP_CSR_3V		0x0040
#define  SCP_CSR_PWR		0x0080
#define SCOOP_CPR		0x0c	/* card power register */
#define  SCP_CPR_OFF		0x0000
#define  SCP_CPR_3V		0x0001	/* 3V for CF card */
#define  SCP_CPR_5V		0x0002	/* 5V for CF card */
#define  SCP_CPR_SD_3V		0x0004	/* 3.3V for SD/MMC card */
#define  SCP_CPR_VOLTAGE_MSK	0x0007
#define  SCP_CPR_PWR		0x0080
#define SCOOP_CCR		0x10	/* card control register */
#define  SCP_CCR_RESET		0x0080
#define SCOOP_IRR		0x14	/* XXX for pcic: bit 0x4 role is? */
#define SCOOP_IRM		0x14
#define SCOOP_IMR		0x18
#define  SCP_IMR_READY		0x0002
#define  SCP_IMR_DETECT		0x0004
#define  SCP_IMR_WRPROT		0x0008
#define  SCP_IMR_STSCHG		0x0010
#define  SCP_IMR_BATWARN	0x0020
#define  SCP_IMR_UNKN0		0x0040
#define  SCP_IMR_UNKN1		0x0080
#define SCOOP_ISR		0x1c
#define SCOOP_GPCR		0x20	/* GPIO pin direction (R/W) */
#define SCOOP_GPWR		0x24	/* GPIO pin output level (R/W) */
#define SCOOP_GPRR		0x28	/* GPIO pin input level (R) */

/* GPIO bits */

#define SCOOP0_LED_GREEN		1
#define SCOOP0_JK_B_C3000		2
#define SCOOP0_CHARGE_OFF_C3000		3
#define SCOOP0_MUTE_L			4
#define SCOOP0_MUTE_R			5
#define SCOOP0_AKIN_PULLUP		6
#define SCOOP0_CF_POWER_C3000		6
#define SCOOP0_APM_ON			7
#define SCOOP0_LED_ORANGE_C3000		7
#define SCOOP0_BACKLIGHT_CONT		8
#define SCOOP0_JK_A_C3000		8
#define SCOOP0_MIC_BIAS			9
#define SCOOP0_ADC_TEMP_ON_C3000	9

#define SCOOP1_IR_ON			1
#define SCOOP1_AKIN_PULLUP		2
#define SCOOP1_RESERVED_3		3
#define SCOOP1_RESERVED_4		4
#define SCOOP1_RESERVED_5		5
#define SCOOP1_RESERVED_6		6
#define SCOOP1_BACKLIGHT_CONT		7
#define SCOOP1_BACKLIGHT_ON		8
#define SCOOP1_MIC_BIAS			9


code:
/*	$OpenBSD: zaurus_scoopvar.h,v 1.11 2007/03/18 20:50:23 uwe Exp $	*/

/*
 * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#define	SCOOP_LED_GREEN		(1<<0)
#define	SCOOP_LED_ORANGE	(1<<1)

void	scoop_set_backlight(int, int);
void	scoop_set_irled(int);
void	scoop_led_set(int, int);
void	scoop_battery_temp_adc(int);
void	scoop_charge_battery(int, int);
void	scoop_discharge_battery(int);
void	scoop_check_mcr(void);
void	scoop_set_headphone(int);
void	scoop_set_sdmmc_power(int);
void	scoop_akin_pullup(int);
void	scoop_suspend(void);
void	scoop_resume(void);


code:
/*	$OpenBSD: zaurus_ssp.c,v 1.8 2010/09/07 16:21:41 deraadt Exp $	*/

/*
 * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>

#include <machine/bus.h>

#include <arm/xscale/pxa2x0reg.h>
#include <arm/xscale/pxa2x0var.h>
#include <arm/xscale/pxa2x0_gpio.h>

#include <zaurus/dev/zaurus_sspvar.h>

#define GPIO_ADS7846_CS_C3000	14	/* SSP SFRM */
#define GPIO_MAX1111_CS_C3000	20
#define GPIO_TG_CS_C3000	53

#define SSCR0_ADS7846_C3000	0x06ab
#define	SSCR0_LZ9JG18		0x01ab
#define SSCR0_MAX1111		0x0387

struct zssp_softc {
	struct device sc_dev;
	bus_space_tag_t sc_iot;
	bus_space_handle_t sc_ioh;
};

int	zssp_match(struct device *, void *, void *);
void	zssp_attach(struct device *, struct device *, void *);
void	zssp_init(void);
int	zssp_activate(struct device *, int);

int	zssp_read_max1111(u_int32_t);
u_int32_t zssp_read_ads7846(u_int32_t);
void	zssp_write_lz9jg18(u_int32_t);

struct cfattach zssp_ca = {
	sizeof (struct zssp_softc), zssp_match, zssp_attach, NULL,
	zssp_activate
};

struct cfdriver zssp_cd = {
	NULL, "zssp", DV_DULL
};

int
zssp_match(struct device *parent, void *match, void *aux)
{
	return 1;
}

void
zssp_attach(struct device *parent, struct device *self, void *aux)
{
	struct zssp_softc *sc = (struct zssp_softc *)self;

	sc->sc_iot = &pxa2x0_bs_tag;
	if (bus_space_map(sc->sc_iot, PXA2X0_SSP1_BASE, PXA2X0_SSP_SIZE,
	    0, &sc->sc_ioh)) {
		printf(": can't map bus space\n");
		return;
	}

	printf("\n");

	zssp_init();
}

/*
 * Initialize the dedicated SSP unit and disable all chip selects.
 * This function is called with interrupts disabled.
 */
void
zssp_init(void)
{
	struct zssp_softc *sc;

	KASSERT(zssp_cd.cd_ndevs > 0 && zssp_cd.cd_devs[0] != NULL);
	sc = (struct zssp_softc *)zssp_cd.cd_devs[0];

	pxa2x0_clkman_config(CKEN_SSP, 1);

	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, SSCR0_LZ9JG18);
	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR1, 0);

	pxa2x0_gpio_set_function(GPIO_ADS7846_CS_C3000, GPIO_OUT|GPIO_SET);
	pxa2x0_gpio_set_function(GPIO_MAX1111_CS_C3000, GPIO_OUT|GPIO_SET);
	pxa2x0_gpio_set_function(GPIO_TG_CS_C3000, GPIO_OUT|GPIO_SET);
}

int
zssp_activate(struct device *self, int act)
{
	switch (act) {
	case DVACT_SUSPEND:
		break;
	case DVACT_RESUME:
		zssp_init();
		break;
	}
	return 0;
}

/*
 * Transmit a single data word to one of the ICs, keep the chip selected
 * afterwards, and don't wait for data to be returned in SSDR.  Interrupts
 * must be held off until zssp_ic_stop() gets called.
 */
void
zssp_ic_start(int ic, u_int32_t data)
{
	struct zssp_softc *sc;

	KASSERT(zssp_cd.cd_ndevs > 0 && zssp_cd.cd_devs[0] != NULL);
	sc = (struct zssp_softc *)zssp_cd.cd_devs[0];

	/* disable other ICs */
	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, 0);
	if (ic != ZSSP_IC_ADS7846)
		pxa2x0_gpio_set_bit(GPIO_ADS7846_CS_C3000);
	if (ic != ZSSP_IC_LZ9JG18)
		pxa2x0_gpio_set_bit(GPIO_TG_CS_C3000);
	if (ic != ZSSP_IC_MAX1111)
		pxa2x0_gpio_set_bit(GPIO_MAX1111_CS_C3000);

	/* activate the chosen one */
	switch (ic) {
	case ZSSP_IC_ADS7846:
		bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0,
		    SSCR0_ADS7846_C3000);
		pxa2x0_gpio_clear_bit(GPIO_ADS7846_CS_C3000);
		bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR, data);
		while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
		    & SSSR_TNF) != SSSR_TNF)
			/* poll */;
		break;
	case ZSSP_IC_LZ9JG18:
		pxa2x0_gpio_clear_bit(GPIO_TG_CS_C3000);
		break;
	case ZSSP_IC_MAX1111:
		pxa2x0_gpio_clear_bit(GPIO_MAX1111_CS_C3000);
		break;
	}
}

/*
 * Read the last value from SSDR and deactivate all chip-selects.
 */
u_int32_t
zssp_ic_stop(int ic)
{
	struct zssp_softc *sc;
	u_int32_t rv;

	KASSERT(zssp_cd.cd_ndevs > 0 && zssp_cd.cd_devs[0] != NULL);
	sc = (struct zssp_softc *)zssp_cd.cd_devs[0];

	switch (ic) {
	case ZSSP_IC_ADS7846:
		/* read result of last command */
		while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
		    & SSSR_RNE) != SSSR_RNE)
			/* poll */;
		rv = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR);
		break;
	case ZSSP_IC_LZ9JG18:
	case ZSSP_IC_MAX1111:
		/* last value received is irrelevant or undefined */
	default:
		rv = 0;
		break;
	}

	pxa2x0_gpio_set_bit(GPIO_ADS7846_CS_C3000);
	pxa2x0_gpio_set_bit(GPIO_TG_CS_C3000);
	pxa2x0_gpio_set_bit(GPIO_MAX1111_CS_C3000);

	return (rv);
}

/*
 * Activate one of the chip-select lines, transmit one word value in
 * each direction, and deactivate the chip-select again.
 */
u_int32_t
zssp_ic_send(int ic, u_int32_t data)
{

	switch (ic) {
	case ZSSP_IC_MAX1111:
		return (zssp_read_max1111(data));
	case ZSSP_IC_ADS7846:
		return (zssp_read_ads7846(data));
	case ZSSP_IC_LZ9JG18:
		zssp_write_lz9jg18(data);
		return 0;
	default:
		printf("zssp_ic_send: invalid IC %d\n", ic);
		return 0;
	}
}

int
zssp_read_max1111(u_int32_t cmd)
{
	struct zssp_softc *sc;
	int	voltage[2];
	int	i;
	int	s;

	KASSERT(zssp_cd.cd_ndevs > 0 && zssp_cd.cd_devs[0] != NULL);
	sc = (struct zssp_softc *)zssp_cd.cd_devs[0];

	s = splhigh();

	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, 0);
	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, SSCR0_MAX1111);

	pxa2x0_gpio_set_bit(GPIO_TG_CS_C3000);
	pxa2x0_gpio_set_bit(GPIO_ADS7846_CS_C3000);
	pxa2x0_gpio_clear_bit(GPIO_MAX1111_CS_C3000);

	delay(1);

	/* Send the command word and read a dummy word back. */
	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR, cmd);
	while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
	    & SSSR_TNF) != SSSR_TNF)
		/* poll */;
	/* XXX is this delay necessary? */
	delay(1);
	while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
	    & SSSR_RNE) != SSSR_RNE)
		/* poll */;
	i = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR);

	for (i = 0; i < 2; i++) {
		bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR, 0);
		while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
		    & SSSR_TNF) != SSSR_TNF)
			/* poll */;
		/* XXX again, is this delay necessary? */
		delay(1);
		while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
		    & SSSR_RNE) != SSSR_RNE)
			/* poll */;
		voltage[i] = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
		    SSP_SSDR);
	}

	pxa2x0_gpio_set_bit(GPIO_TG_CS_C3000);
	pxa2x0_gpio_set_bit(GPIO_ADS7846_CS_C3000);
	pxa2x0_gpio_set_bit(GPIO_MAX1111_CS_C3000);

	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, 0);

	/* XXX no idea what this means, but it's what Linux would do. */
	if ((voltage[0] & 0xc0) != 0 || (voltage[1] & 0x3f) != 0)
		voltage[0] = -1;
	else
		voltage[0] = ((voltage[0] << 2) & 0xfc) |
		    ((voltage[1] >> 6) & 0x03);

	splx(s);
	return voltage[0];
}

/* XXX - only does CS_ADS7846 */
u_int32_t
zssp_read_ads7846(u_int32_t cmd)
{
	struct zssp_softc *sc;

	sc = (struct zssp_softc *)zssp_cd.cd_devs[0];
	unsigned int cr0;
	int s;
	u_int32_t val;

	if (zssp_cd.cd_ndevs < 1 || zssp_cd.cd_devs[0] == NULL) {
		printf("zssp_read_ads7846: not configured\n");
		return 0;
	}
	sc = (struct zssp_softc *)zssp_cd.cd_devs[0];

	s = splhigh();
	if (1) {
		cr0 =  SSCR0_ADS7846_C3000;
	} else {
		cr0 =  0x00ab;
	}
        bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, 0);
	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, cr0);

	pxa2x0_gpio_set_bit(GPIO_TG_CS_C3000);
	pxa2x0_gpio_set_bit(GPIO_MAX1111_CS_C3000);
	pxa2x0_gpio_clear_bit(GPIO_ADS7846_CS_C3000);

	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR, cmd);

	while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
	    & SSSR_TNF) != SSSR_TNF)
		/* poll */;

	delay(1);

	while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
	    & SSSR_RNE) != SSSR_RNE)
		/* poll */;

	val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR);

	pxa2x0_gpio_set_bit(GPIO_ADS7846_CS_C3000); /* deselect */

	splx(s);

	return val;
}

void
zssp_write_lz9jg18(u_int32_t data)
{
	int s;
	int sclk_pin, sclk_fn;
	int sfrm_pin, sfrm_fn;
	int txd_pin, txd_fn;
	int rxd_pin, rxd_fn;
	int i;

	/* XXX this creates a DAC command from a backlight duty value. */
	data = 0x40 | (data & 0x1f);

	if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X) {
		/* C3000 */
		sclk_pin = 19;
		sfrm_pin = 14;
		txd_pin = 87;
		rxd_pin = 86;
	} else {
		sclk_pin = 23;
		sfrm_pin = 24;
		txd_pin = 25;
		rxd_pin = 26;
	}

	s = splhigh();

	sclk_fn = pxa2x0_gpio_get_function(sclk_pin);
	sfrm_fn = pxa2x0_gpio_get_function(sfrm_pin);
	txd_fn = pxa2x0_gpio_get_function(txd_pin);
	rxd_fn = pxa2x0_gpio_get_function(rxd_pin);

	pxa2x0_gpio_set_function(sfrm_pin, GPIO_OUT | GPIO_SET);
	pxa2x0_gpio_set_function(sclk_pin, GPIO_OUT | GPIO_CLR);
	pxa2x0_gpio_set_function(txd_pin, GPIO_OUT | GPIO_CLR);
	pxa2x0_gpio_set_function(rxd_pin, GPIO_IN);

	pxa2x0_gpio_set_bit(GPIO_MAX1111_CS_C3000);
	pxa2x0_gpio_set_bit(GPIO_ADS7846_CS_C3000);
	pxa2x0_gpio_clear_bit(GPIO_TG_CS_C3000);

	delay(10);

	for (i = 0; i < 8; i++) {
		if (data & 0x80)
			pxa2x0_gpio_set_bit(txd_pin);
		else
			pxa2x0_gpio_clear_bit(txd_pin);
		delay(10);
		pxa2x0_gpio_set_bit(sclk_pin);
		delay(10);
		pxa2x0_gpio_clear_bit(sclk_pin);
		delay(10);
		data <<= 1;
	}

	pxa2x0_gpio_clear_bit(txd_pin);
	pxa2x0_gpio_set_bit(GPIO_TG_CS_C3000);

	pxa2x0_gpio_set_function(sclk_pin, sclk_fn);
	pxa2x0_gpio_set_function(sfrm_pin, sfrm_fn);
	pxa2x0_gpio_set_function(txd_pin, txd_fn);
	pxa2x0_gpio_set_function(rxd_pin, rxd_fn);

	splx(s);
}


code:
/*	$OpenBSD: zaurus_sspvar.h,v 1.3 2005/04/08 21:58:49 uwe Exp $	*/

/*
 * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#define ZSSP_IC_MAX1111		1	/* temperature/voltage ADC */
#define ZSSP_IC_LZ9JG18		2	/* LCD backlight controller */
#define ZSSP_IC_ADS7846		3	/* touch screen controller */

void	  zssp_ic_start(int, u_int32_t);
u_int32_t zssp_ic_send(int, u_int32_t);
u_int32_t zssp_ic_stop(int);

int	  zssp_read_max1111(u_int32_t);
void	  zssp_write_lz9jg18(u_int32_t);


code:
/*	$OpenBSD: zaurus_udc.c,v 1.3 2013/10/24 22:40:10 aalm Exp $	*/
/*
 * Copyright (c) 2009 Marek Vasut <marex@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/* Attachment driver for pxaudc(4) on Zaurus */

#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>
#include <sys/timeout.h>

#include <dev/sdmmc/sdmmcreg.h>
#include <machine/machine_reg.h>
#include <machine/zaurus_var.h>

#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdivar.h>
#include <dev/usb/usbf.h>
#include <dev/usb/usbfvar.h>

#include <arch/arm/xscale/pxa2x0_gpio.h>
#include <arch/arm/xscale/pxa27x_udc.h>

int	zaurus_udc_match(struct device *, void *, void *);
void	zaurus_udc_attach(struct device *, struct device *, void *);
int	zaurus_udc_detach(struct device *, int);
int	zaurus_udc_activate(struct device *, int);
int	zaurus_udc_is_host(void);

struct cfattach pxaudc_zaurus_ca = {
	sizeof(struct pxaudc_softc),
	zaurus_udc_match,
	zaurus_udc_attach,
	zaurus_udc_detach,
	zaurus_udc_activate
};

int
zaurus_udc_match(struct device *parent, void *match, void *aux)
{
	return pxaudc_match();
}

int
zaurus_udc_is_host(void)
{
	return !(pxa2x0_gpio_get_bit(GPIO_USB_DETECT) ||
		pxa2x0_gpio_get_bit(GPIO_USB_DEVICE));
}

void
zaurus_udc_attach(struct device *parent, struct device *self, void *aux)
{
	struct pxaudc_softc *sc = (struct pxaudc_softc *)self;

	sc->sc_gpio_detect	= GPIO_USB_DETECT;
	sc->sc_gpio_pullup	= GPIO_USB_PULLUP;
	sc->sc_gpio_pullup_inv	= 0;
	sc->sc_is_host		= zaurus_udc_is_host;

	/* Platform specific GPIO configuration */
	pxa2x0_gpio_set_function(GPIO_USB_DETECT, GPIO_IN);
	pxa2x0_gpio_set_function(GPIO_USB_DEVICE, GPIO_IN);
	pxa2x0_gpio_set_function(GPIO_USB_PULLUP, GPIO_OUT);

	pxa2x0_gpio_set_function(45, GPIO_OUT);
	pxa2x0_gpio_set_function(40, GPIO_OUT);
	pxa2x0_gpio_set_function(39, GPIO_IN);
	pxa2x0_gpio_set_function(38, GPIO_IN);
	pxa2x0_gpio_set_function(37, GPIO_OUT);
	pxa2x0_gpio_set_function(36, GPIO_IN);
	pxa2x0_gpio_set_function(34, GPIO_IN);
	pxa2x0_gpio_set_function(89, GPIO_OUT);
	pxa2x0_gpio_set_function(120, GPIO_OUT);

	pxaudc_attach(sc, aux);
}

int
zaurus_udc_detach(struct device *self, int flags)
{
	struct pxaudc_softc *sc = (struct pxaudc_softc *)self;

	return pxaudc_detach(sc, flags);
}

int
zaurus_udc_activate(struct device *self, int act)
{
	struct pxaudc_softc *sc = (struct pxaudc_softc *)self;

	return pxaudc_activate(sc, act);
}


code:
/* $OpenBSD: zts.c,v 1.16 2014/03/29 18:09:30 guenther Exp $ */
/*
 * Copyright (c) 2005 Dale Rahn <drahn@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/timeout.h>
#include <sys/kernel.h>

#include <arm/xscale/pxa2x0reg.h>
#include <arm/xscale/pxa2x0_gpio.h>

#include <zaurus/dev/zaurus_sspvar.h>

#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsmousevar.h>

#include <dev/wscons/wsdisplayvar.h>
#include <arm/xscale/pxa2x0var.h>
#include <arm/xscale/pxa2x0_lcd.h>

#ifdef ZTS_DEBUG
#define DPRINTF(x)	do { printf x; } while (0)
#else
#define DPRINTF(x)
#endif

/*
 * ADS784x touch screen controller
 */
#define ADSCTRL_PD0_SH          0       /* PD0 bit */
#define ADSCTRL_PD1_SH          1       /* PD1 bit */
#define ADSCTRL_DFR_SH          2       /* SER/DFR bit */
#define ADSCTRL_MOD_SH          3       /* Mode bit */
#define ADSCTRL_ADR_SH          4       /* Address setting */
#define ADSCTRL_STS_SH          7       /* Start bit */

#define GPIO_TP_INT_C3K		11
#define GPIO_HSYNC_C3K		22

#define POLL_TIMEOUT_RATE0	((hz * 150)/1000)
#define POLL_TIMEOUT_RATE1	(hz / 100) /* XXX every tick */

#define CCNT_HS_400_VGA_C3K 6250	/* 15.024us */

struct tsscale {
	int minx, maxx;
	int miny, maxy;
	int swapxy;
	int resx, resy;
} zts_scale = {
	/* C3000 */
	209, 3620, 312, 3780, 0, 640, 480
};

int	zts_match(struct device *, void *, void *);
void	zts_attach(struct device *, struct device *, void *);
int	zts_activate(struct device *, int);
int	zts_enable(void *);
void	zts_disable(void *);
void	zts_poll(void *);
int	zts_irq(void *);
int	zts_ioctl(void *, u_long, caddr_t, int, struct proc *);

struct zts_softc {
	struct device sc_dev;
	struct timeout sc_ts_poll;
	void *sc_gh;
	int sc_enabled;
	int sc_running;
	int sc_buttons; /* button emulation ? */
	struct device *sc_wsmousedev;
	int sc_oldx;
	int sc_oldy;
	int sc_rawmode;

	struct tsscale sc_tsscale;
};

struct cfattach zts_ca = {
	sizeof(struct zts_softc), zts_match, zts_attach, NULL,
	zts_activate
};

struct cfdriver zts_cd = {
	NULL, "zts", DV_DULL
};

int
zts_match(struct device *parent, void *cf, void *aux)
{
	return 1;
}

const struct wsmouse_accessops zts_accessops = {
        zts_enable,
	zts_ioctl,
	zts_disable
};

void
zts_attach(struct device *parent, struct device *self, void *aux)
{
	struct zts_softc *sc = (struct zts_softc *)self;
	struct wsmousedev_attach_args a;

	timeout_set(&sc->sc_ts_poll, zts_poll, sc);

	/* Initialize ADS7846 Difference Reference mode */
	(void)zssp_ic_send(ZSSP_IC_ADS7846,
	    (1<<ADSCTRL_ADR_SH) | (1<<ADSCTRL_STS_SH));
	delay(5000);
	(void)zssp_ic_send(ZSSP_IC_ADS7846,
	    (3<<ADSCTRL_ADR_SH) | (1<<ADSCTRL_STS_SH));
	delay(5000);
	(void)zssp_ic_send(ZSSP_IC_ADS7846,
	    (4<<ADSCTRL_ADR_SH) | (1<<ADSCTRL_STS_SH));
	delay(5000);
	(void)zssp_ic_send(ZSSP_IC_ADS7846,
	    (5<<ADSCTRL_ADR_SH) | (1<<ADSCTRL_STS_SH));
	delay(5000);

	a.accessops = &zts_accessops;
	a.accesscookie = sc;
	printf("\n");

	/* Copy the default scalue values to each softc */
	bcopy(&zts_scale, &sc->sc_tsscale, sizeof(sc->sc_tsscale));

	sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
}

int
zts_enable(void *v)
{
	struct zts_softc *sc = v;

	if (sc->sc_enabled)
		return EBUSY;

	timeout_del(&sc->sc_ts_poll);

	pxa2x0_gpio_set_function(GPIO_TP_INT_C3K, GPIO_IN);

	/* XXX */
	if (sc->sc_gh == NULL)
		sc->sc_gh = pxa2x0_gpio_intr_establish(GPIO_TP_INT_C3K,
		    IST_EDGE_FALLING, IPL_TTY, zts_irq, sc,
		    sc->sc_dev.dv_xname);
	else
		pxa2x0_gpio_intr_unmask(sc->sc_gh);

	/* enable interrupts */
	sc->sc_enabled = 1;
	sc->sc_running = 1;
	sc->sc_buttons = 0;

	return 0;
}

void
zts_disable(void *v)
{
	struct zts_softc *sc = v;

	timeout_del(&sc->sc_ts_poll);

	if (sc->sc_gh != NULL) {
#if 0
		pxa2x0_gpio_intr_disestablish(sc->sc_gh);
		sc->sc_gh = NULL;
#endif
	}

	/* disable interrupts */
	sc->sc_enabled = 0;
	sc->sc_running = 0;
}

int
zts_activate(struct device *self, int act)
{
	struct zts_softc *sc = (struct zts_softc *)self;

	switch (act) {
	case DVACT_SUSPEND:
		if (sc->sc_enabled == 0)
			break;
		sc->sc_running = 0;
#if 0
		pxa2x0_gpio_intr_disestablish(sc->sc_gh);
#endif
		timeout_del(&sc->sc_ts_poll);

		pxa2x0_gpio_intr_mask(sc->sc_gh);

		/* Turn off reference voltage but leave ADC on. */
		(void)zssp_ic_send(ZSSP_IC_ADS7846, (1 << ADSCTRL_PD1_SH) |
		    (1 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH));

		pxa2x0_gpio_set_function(GPIO_TP_INT_C3K,
		    GPIO_OUT | GPIO_SET);
		break;

	case DVACT_RESUME:
		if (sc->sc_enabled == 0)
			break;
		pxa2x0_gpio_set_function(GPIO_TP_INT_C3K, GPIO_IN);
		pxa2x0_gpio_intr_mask(sc->sc_gh);

		/* Enable automatic low power mode. */
		(void)zssp_ic_send(ZSSP_IC_ADS7846,
		    (4 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH));

#if 0
		sc->sc_gh = pxa2x0_gpio_intr_establish(GPIO_TP_INT_C3K,
		    IST_EDGE_FALLING, IPL_TTY, zts_irq, sc,
		    sc->sc_dev.dv_xname);
#else
		pxa2x0_gpio_intr_unmask(sc->sc_gh);
#endif
		sc->sc_running = 1;
		break;
	}
	return 0;
}

struct zts_pos {
	int x;
	int y;
	int z;			/* touch pressure */
};

#define NSAMPLES 3
struct zts_pos zts_samples[NSAMPLES];
int	ztsavgloaded = 0;

int	zts_readpos(struct zts_pos *);
void	zts_avgpos(struct zts_pos *);

#define HSYNC()							\
	do {								\
		while (pxa2x0_gpio_get_bit(GPIO_HSYNC_C3K) == 0);	\
		while (pxa2x0_gpio_get_bit(GPIO_HSYNC_C3K) != 0);	\
	} while (0)

int	  pxa2x0_ccnt_enable(int);
u_int32_t pxa2x0_read_ccnt(void);
u_int32_t zts_sync_ads784x(int, int, u_int32_t);
void	  zts_sync_send(u_int32_t);

int
pxa2x0_ccnt_enable(int on)
{
	u_int32_t rv;

	on = on ? 0x1 : 0x0;
	__asm volatile("mrc p14, 0, %0, c0, c1, 0" : "=r" (rv));
	__asm volatile("mcr p14, 0, %0, c0, c1, 0" : : "r" (on));
	return ((int)(rv & 0x1));
}

u_int32_t
pxa2x0_read_ccnt(void)
{
	u_int32_t rv;

	__asm volatile("mrc p14, 0, %0, c1, c1, 0" : "=r" (rv));
	return (rv);
}

/*
 * Communicate synchronously with the ADS784x touch screen controller.
 */
u_int32_t
zts_sync_ads784x(int dorecv/* XXX */, int dosend/* XXX */, u_int32_t cmd)
{
	int	ccen;
	u_int32_t rv;

	/* XXX poll hsync only if LCD is enabled */

	/* start clock counter */
	ccen = pxa2x0_ccnt_enable(1);

	HSYNC();

	if (dorecv)
		/* read SSDR and disable ADS784x */
		rv = zssp_ic_stop(ZSSP_IC_ADS7846);
	else
		rv = 0;

	if (dosend)
		zts_sync_send(cmd);

	/* stop clock counter */
	pxa2x0_ccnt_enable(ccen);

	return (rv);
}

void
zts_sync_send(u_int32_t cmd)
{
	u_int32_t tck;
	u_int32_t a, b;

	/* XXX */
	tck = CCNT_HS_400_VGA_C3K - 151;

	/* send dummy command; discard SSDR */
	(void)zssp_ic_send(ZSSP_IC_ADS7846, cmd);

	/* wait for refresh */
	HSYNC();

	/* wait after refresh */
	a = pxa2x0_read_ccnt();
	b = pxa2x0_read_ccnt();
	while ((b - a) < tck)
		b = pxa2x0_read_ccnt();

	/* send the actual command; keep ADS784x enabled */
	zssp_ic_start(ZSSP_IC_ADS7846, cmd);
}

int
zts_readpos(struct zts_pos *pos)
{
	int cmd;
	int t0, t1;
	int down;

	/* XXX */
	pxa2x0_gpio_set_function(GPIO_HSYNC_C3K, GPIO_IN);

	/* check that pen is down */
	cmd = (1 << ADSCTRL_PD0_SH) | (1 << ADSCTRL_PD1_SH) |
	    (3 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);

	t0 = zssp_ic_send(ZSSP_IC_ADS7846, cmd);
	down = !(t0 < 10);
	if (down == 0)
		goto out;

	/* Y */
	cmd = (1 << ADSCTRL_PD0_SH) | (1 << ADSCTRL_PD1_SH) |
	    (1 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);

	(void)zts_sync_ads784x(0, 1, cmd);

	/* Y */
	cmd = (1 << ADSCTRL_PD0_SH) | (1 << ADSCTRL_PD1_SH) |
	    (1 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);

	(void)zts_sync_ads784x(1, 1, cmd);

	/* X */
	cmd = (1 << ADSCTRL_PD0_SH) | (1 << ADSCTRL_PD1_SH) |
	    (5 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);

	pos->y = zts_sync_ads784x(1, 1, cmd);

	/* T0 */
	cmd = (1 << ADSCTRL_PD0_SH) | (1 << ADSCTRL_PD1_SH) |
	    (3 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);

	pos->x = zts_sync_ads784x(1, 1, cmd);

	/* T1 */
	cmd = (1 << ADSCTRL_PD0_SH) | (1 << ADSCTRL_PD1_SH) |
	    (4 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);

	t0 = zts_sync_ads784x(1, 1, cmd);
	t1 = zts_sync_ads784x(1, 0, cmd);

	/* check that pen is still down */
	/* XXX pressure sensitivity varies with X or what? */
	if (t0 == 0 || (pos->x * (t1 - t0) / t0) >= 15000)
		down = 0;
	pos->z = down;

out:
	/* Enable automatic low power mode. */
        cmd = (4 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);
	(void)zssp_ic_send(ZSSP_IC_ADS7846, cmd);

	return (down);
}

#define NAVGSAMPLES (NSAMPLES < 3 ? NSAMPLES : 3)
void
zts_avgpos(struct zts_pos *pos)
{
	struct zts_pos *tpp = zts_samples;
	int diff[NAVGSAMPLES];
	int mindiff, mindiffv;
	int n;
	int i;
	static int tail;

	if (ztsavgloaded < NAVGSAMPLES) {
		tpp[(tail + ztsavgloaded) % NSAMPLES] = *pos;
		ztsavgloaded++;
		return;
	}

	tpp[tail] = *pos;
	tail = (tail+1) % NSAMPLES;

	/* X */
	i = tail;
	for (n = 0 ; n < NAVGSAMPLES; n++) {
		int alt;
		alt = (i+1) % NSAMPLES;
		diff[n] = tpp[i].x - tpp[alt].x;
		if (diff[n] < 0)
			diff[n] = - diff[n]; /* ABS */
		i = alt;
	}
	mindiffv = diff[0];
	mindiff = 0;
	for (n = 1; n < NAVGSAMPLES; n++) {
		if (diff[n] < mindiffv) {
			mindiffv = diff[n];
			mindiff = n;
		}
	}
	pos->x = (tpp[(tail + mindiff) % NSAMPLES].x +
	    tpp[(tail + mindiff + 1) % NSAMPLES].x) / 2;

	/* Y */
	i = tail;
	for (n = 0 ; n < NAVGSAMPLES; n++) {
		int alt;
		alt = (i+1) % NSAMPLES;
		diff[n] = tpp[i].y - tpp[alt].y;
		if (diff[n] < 0)
			diff[n] = - diff[n]; /* ABS */
		i = alt;
	}
	mindiffv = diff[0];
	mindiff = 0;
	for (n = 1; n < NAVGSAMPLES; n++) {
		if (diff[n] < mindiffv) {
			mindiffv = diff[n];
			mindiff = n;
		}
	}
	pos->y = (tpp[(tail + mindiff) % NSAMPLES].y +
	    tpp[(tail + mindiff + 1) % NSAMPLES].y) / 2;
}

void
zts_poll(void *v)
{
	int s;

	s = spltty();
	(void)zts_irq(v);
	splx(s);
}

#define TS_STABLE 8
int
zts_irq(void *v)
{
	struct zts_softc *sc = v;
	struct zts_pos tp;
	int s;
	int pindown;
	int down;
	extern int zkbd_modstate;

	if (!sc->sc_running)
		return 0;

	s = splhigh();
	pindown = pxa2x0_gpio_get_bit(GPIO_TP_INT_C3K) ? 0 : 1;
	if (pindown) {
		pxa2x0_gpio_intr_mask(sc->sc_gh);
		timeout_add(&sc->sc_ts_poll, POLL_TIMEOUT_RATE1);
	}

	down = zts_readpos(&tp);

	if (!pindown) {
		pxa2x0_gpio_intr_unmask(sc->sc_gh);
		timeout_add(&sc->sc_ts_poll, POLL_TIMEOUT_RATE0);
		ztsavgloaded = 0;
	}
	pxa2x0_gpio_clear_intr(GPIO_TP_INT_C3K);
	splx(s);

	if (down) {
		zts_avgpos(&tp);
		if (!sc->sc_rawmode &&
		    (sc->sc_tsscale.maxx - sc->sc_tsscale.minx) != 0 &&
		    (sc->sc_tsscale.maxy - sc->sc_tsscale.miny) != 0) {
			/* Scale down to the screen resolution. */
			tp.x = ((tp.x - sc->sc_tsscale.minx) *
			    sc->sc_tsscale.resx) /
			    (sc->sc_tsscale.maxx - sc->sc_tsscale.minx);
			tp.y = ((tp.y - sc->sc_tsscale.miny) *
			    sc->sc_tsscale.resy) /
			    (sc->sc_tsscale.maxy - sc->sc_tsscale.miny);
		}
	}

	if (zkbd_modstate != 0 && down) {
		if(zkbd_modstate & (1 << 1)) {
			/* Fn */
			down = 2;
		}
		if(zkbd_modstate & (1 << 2)) {
			/* 'Alt' */
			down = 4;
		}
	}
	if (!down) {
		/* x/y values are not reliable when pen is up */
		tp.x = sc->sc_oldx;
		tp.y = sc->sc_oldy;
	}

	if (down || sc->sc_buttons != down) {
		DPRINTF(("%s: tp.z = %d, tp.x = %d, tp.y = %d\n",
		    sc->sc_dev.dv_xname, tp.z, tp.x, tp.y));

		wsmouse_input(sc->sc_wsmousedev, down, tp.x, tp.y,
		    0 /* z */, 0 /* w */,
		    WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y |
		    WSMOUSE_INPUT_ABSOLUTE_Z);
		sc->sc_buttons = down;
		sc->sc_oldx = tp.x;
		sc->sc_oldy = tp.y;
	}

	return 1;
}

int
zts_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
{
	int error = 0;
	struct zts_softc *sc = v;
	struct wsmouse_calibcoords *wsmc = (struct wsmouse_calibcoords *)data;

	DPRINTF(("zts_ioctl(%d, '%c', %d)\n",
	    IOCPARM_LEN(cmd), IOCGROUP(cmd), cmd & 0xff));

	switch (cmd) {
	case WSMOUSEIO_SCALIBCOORDS:
		if (!(wsmc->minx >= 0 && wsmc->maxx >= 0 &&
		    wsmc->miny >= 0 && wsmc->maxy >= 0 &&
		    wsmc->resx >= 0 && wsmc->resy >= 0 &&
		    wsmc->minx < 32768 && wsmc->maxx < 32768 &&
		    wsmc->miny < 32768 && wsmc->maxy < 32768 &&
		    (wsmc->maxx - wsmc->minx) != 0 &&
		    (wsmc->maxy - wsmc->miny) != 0 &&
		    wsmc->resx < 32768 && wsmc->resy < 32768 &&
		    wsmc->swapxy >= 0 && wsmc->swapxy <= 1 &&
		    wsmc->samplelen >= 0 && wsmc->samplelen <= 1))
			return (EINVAL);

		sc->sc_tsscale.minx = wsmc->minx;
		sc->sc_tsscale.maxx = wsmc->maxx;
		sc->sc_tsscale.miny = wsmc->miny;
		sc->sc_tsscale.maxy = wsmc->maxy;
		sc->sc_tsscale.swapxy = wsmc->swapxy;
		sc->sc_tsscale.resx = wsmc->resx;
		sc->sc_tsscale.resy = wsmc->resy;
		sc->sc_rawmode = wsmc->samplelen;
		break;
	case WSMOUSEIO_GCALIBCOORDS:
		wsmc->minx = sc->sc_tsscale.minx;
		wsmc->maxx = sc->sc_tsscale.maxx;
		wsmc->miny = sc->sc_tsscale.miny;
		wsmc->maxy = sc->sc_tsscale.maxy;
		wsmc->swapxy = sc->sc_tsscale.swapxy;
		wsmc->resx = sc->sc_tsscale.resx;
		wsmc->resy = sc->sc_tsscale.resy;
		wsmc->samplelen = sc->sc_rawmode;
		break;
	case WSMOUSEIO_GTYPE:
		*(u_int *)data = WSMOUSE_TYPE_TPANEL;
		break;
	default:
		error = ENOTTY;
		break;
	}

	return (error);
}


path: sys/arch/zaurus/include/CVS/Entries


code: src/sys/arch/zaurus/include

path: sys/arch/zaurus/include/CVS/Repository


code:
/*	$OpenBSD: _float.h,v 1.1 2012/06/26 16:12:45 deraadt Exp $	*/

#include <arm/_float.h>


code:
/* 	$OpenBSD: _types.h,v 1.7 2012/11/05 19:39:34 miod Exp $	*/

#ifndef _MACHINE__TYPES_H_
#define	_MACHINE__TYPES_H_

#include <arm/_types.h>

#endif


code:
/*	$OpenBSD: apmvar.h,v 1.2 2010/02/02 06:19:28 kevlo Exp $	*/
#include <arm/apmvar.h>


code:
/*	$OpenBSD: atomic.h,v 1.5 2011/03/23 16:54:37 pirofti Exp $	*/

/* Public Domain */

#ifndef _MACHINE_ATOMIC_H_
#define _MACHINE_ATOMIC_H_

#include <arm/atomic.h>

#endif /* _MACHINE_ATOMIC_H_ */


code:
/*	$OpenBSD: bootconfig.h,v 1.2 2011/09/20 22:02:13 miod Exp $	*/
/*	$NetBSD: bootconfig.h,v 1.2 2001/06/21 22:08:28 chris Exp $	*/

/*
 * Copyright (c) 1994 Mark Brinicombe.
 * Copyright (c) 1994 Brini.
 * All rights reserved.
 *
 * This code is derived from software written for Brini by Mark Brinicombe
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Mark Brinicombe
 *	for the NetBSD Project.
 * 4. The name of the company nor the name of the author may be used to
 *    endorse or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * boot configuration structures
 *
 * Created      : 12/09/94
 *
 * Based on kate/boot/bootconfig.h
 */

#if defined(_KERNEL)

typedef struct _PhysMem {
	u_int address;
	u_int pages;
} PhysMem;

#define	DRAM_BLOCKS	1

typedef struct _BootConfig {
	PhysMem dram[DRAM_BLOCKS];
	u_int dramblocks;
} BootConfig;

extern BootConfig bootconfig;
#define MAX_BOOT_STRING 255

extern char *boot_args;
extern char *boot_file;
#endif	/* _KERNEL */

/* End of bootconfig.h */


code:
/*	$OpenBSD: cdefs.h,v 1.2 2005/11/24 20:46:49 deraadt Exp $	*/

#include <arm/cdefs.h>


code:
/*	$OpenBSD: conf.h,v 1.8 2011/03/23 16:54:37 pirofti Exp $	*/
/*	$NetBSD: conf.h,v 1.8 2002/02/10 12:26:03 chris Exp $	*/

#ifndef _MACHINE_CONF_H_
#define	_MACHINE_CONF_H_

#include <sys/conf.h>

/*
 * ZAURUS specific device includes go in here
 */

#define CONF_HAVE_APM

#include <arm/conf.h>

#endif	/* _MACHINE_CONF_H_ */


code:
/*	$OpenBSD: db_machdep.h,v 1.1 2004/12/31 00:04:35 drahn Exp $	*/
/*	$NetBSD: db_machdep.h,v 1.3 2001/11/25 15:55:55 thorpej Exp $	*/

#include <arm/db_machdep.h>


code:
/*	$OpenBSD: disklabel.h,v 1.2 2007/06/17 00:27:28 deraadt Exp $	*/

#include <arm/disklabel.h>


code:
/*	$OpenBSD: exec.h,v 1.2 2006/10/02 17:45:33 miod Exp $	*/
/* public domain */
#include <arm/exec.h>


code:
/*	$OpenBSD: fenv.h,v 1.2 2013/06/01 21:20:54 jasper Exp $	*/
/* public domain */
#include <arm/fenv.h>


code:
/*	$OpenBSD: intr.h,v 1.11 2013/05/17 19:38:52 kettenis Exp $	*/
/*	$NetBSD: intr.h,v 1.12 2003/06/16 20:00:59 thorpej Exp $	*/

/*
 * Copyright (c) 2001, 2003 Wasabi Systems, Inc.
 * All rights reserved.
 *
 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed for the NetBSD Project by
 *	Wasabi Systems, Inc.
 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
 *    or promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef	_MACHINE_INTR_H_
#define	_MACHINE_INTR_H_

#ifdef _KERNEL

/* Interrupt priority "levels". */
#define	IPL_NONE	0	/* nothing */
#define	IPL_SOFT	1	/* generic software interrupts */
#define	IPL_SOFTCLOCK	2	/* software clock interrupt */
#define	IPL_SOFTNET	3	/* software network interrupt */
#define	IPL_BIO		4	/* block I/O */
#define	IPL_NET		5	/* network */
#define	IPL_SOFTTTY	6	/* software serial interrupt */
#define	IPL_TTY		7	/* terminals */
#define	IPL_VM		8	/* memory allocation */
#define	IPL_AUDIO	9	/* audio device */
#define	IPL_CLOCK	10	/* clock interrupt */
#define	IPL_STATCLOCK	11	/* statistics clock interrupt */
#define	IPL_SCHED	12	/* everything */
#define	IPL_HIGH	12	/* everything */

#define	NIPL		13

/* Interrupt priority "flags". */
#define	IPL_MPSAFE	0	/* no "mpsafe" interrupts */

/* Interrupt sharing types. */
#define	IST_NONE	0	/* none */
#define	IST_PULSE	1	/* pulsed */
#define	IST_EDGE	2	/* edge-triggered */
#define	IST_LEVEL	3	/* level-triggered */

#define IST_LEVEL_LOW	 IST_LEVEL
#define IST_LEVEL_HIGH   4
#define IST_EDGE_FALLING IST_EDGE
#define IST_EDGE_RISING  5
#define IST_EDGE_BOTH    6

#ifndef _LOCORE

#include <sys/device.h>
#include <sys/queue.h>

#define	splhigh()	_splraise(IPL_HIGH)
#define	splsoft()	_splraise(IPL_SOFT)
#define	splsoftclock()	_splraise(IPL_SOFTCLOCK)
#define	splsoftnet()	_splraise(IPL_SOFTNET)
#define	splbio()	_splraise(IPL_BIO)
#define	splnet()	_splraise(IPL_NET)
#define	spltty()	_splraise(IPL_TTY)
#define	splvm()		_splraise(IPL_VM)
#define	splaudio()	_splraise(IPL_AUDIO)
#define	splclock()	_splraise(IPL_CLOCK)
#define	splstatclock()	_splraise(IPL_STATCLOCK)
#define	splserial()	_splraise(IPL_SERIAL)

#define	spl0()		_spllower(IPL_NONE)

#define	splsched()	splhigh()
#define	spllock()	splhigh()

#endif /* ! _LOCORE */

#include <arm/xscale/pxa2x0_intr.h>

#endif /* _KERNEL */

#endif	/* _MACHINE_INTR_H_ */


code:
/*	$OpenBSD: loadfile_machdep.h,v 1.4 2015/07/17 20:44:39 miod Exp $	*/
/*	$NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $	*/

/*-
 * Copyright (c) 1999 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Christos Zoulas.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#define BOOT_ELF
#define ELFSIZE 32

#define LOAD_KERNEL		LOAD_ALL
#define COUNT_KERNEL		COUNT_ALL

#define LOADADDR(a)		((((u_long)(a)) + offset)&0xfffffff)
#define ALIGNENTRY(a)		((u_long)(a))
#define READ(f, b, c)		read((f), (void *)LOADADDR(b), (c))
#define BCOPY(s, d, c)		memcpy((void *)LOADADDR(d), (void *)(s), (c))
#define BZERO(d, c)		memset((void *)LOADADDR(d), 0, (c))
#define	WARN(a)			(void)(printf a, \
				    printf((errno ? ": %s\n" : "\n"), \
				    strerror(errno)))
#define PROGRESS(a)		(void) printf a
#define ALLOC(a)		alloc(a)
#define FREE(a, b)		free(a, b)

void run_loadfile(u_long *, int);


code:
/*	$OpenBSD: machine_reg.h,v 1.3 2010/06/07 16:34:20 drahn Exp $	*/
/*	$NetBSD: lubbock_reg.h,v 1.1 2003/06/18 10:51:15 bsh Exp $ */

/*
 * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
 * Written by Hiroyuki Bessho for Genetec Corporation.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of Genetec Corporation may not be used to endorse or
 *    promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _ZAURUS_REG_H
#define _ZAURUS_REG_H

#include <arm/xscale/pxa2x0reg.h>

/*
 * Logical mapping for onboard/integrated peripherals
 */
#define	ZAURUS_IO_AREA_VBASE	0xfd000000
#define ZAURUS_GPIO_VBASE	0xfd000000
#define ZAURUS_CLKMAN_VBASE 	0xfd100000
#define ZAURUS_INTCTL_VBASE 	0xfd200000
#define ZAURUS_SCOOP0_VBASE	0xfd300000
#define ZAURUS_SCOOP1_VBASE	0xfd400000
#define ZAURUS_VBASE_FREE	0xfd500000
/* FFUART, BTUART and/or STUART are mapped to this area when
   used for console or kgdb port */

#define ioreg_read(a)  (*(volatile unsigned *)(a))
#define ioreg_write(a,v)  (*(volatile unsigned *)(a)=(v))

#define ioreg16_read(a)  (*(volatile uint16_t *)(a))
#define ioreg16_write(a,v)  (*(volatile uint16_t *)(a)=(v))

#define ioreg8_read(a)  (*(volatile uint8_t *)(a))
#define ioreg8_write(a,v)  (*(volatile uint8_t *)(a)=(v))

/*
 * Magic numbers for the C860 (PXA255) and C3000 (PXA27x).
 */

/* physical adresses of companion chips */
#define C3000_SCOOP0_BASE	0x10800000 /* XXX same as C860 */
#define C3000_SCOOP1_BASE	0x08800040

/* processor IRQ numbers */
#define C860_CF0_IRQ		17
#define C3000_CF0_IRQ		105
#define C3000_CF1_IRQ		106

/* processor GPIO pins */
#define C860_CF0_IRQ_PIN	14
#define C3000_RC_IRQ_PIN	13	/* remote control */
#define C3000_CF0_IRQ_PIN	94
#define C3000_CF1_IRQ_PIN	93
#define GPIO_USB_DEVICE		35	/* indicate connection type */
#define GPIO_USB_DETECT		41	/* connection interrupt */
#define GPIO_USB_PULLUP		45	/* show/hide device presence */
#define GPIO_HP_IN_C3000	116	/* headphone jack */
#define GPIO_MMC_DETECT	9	/* card detect */

#endif /* _ZAURUS_REG_H */


code:
/*	$OpenBSD: mutex.h,v 1.2 2007/12/05 16:08:06 deraadt Exp $	*/
/* public domain */
#include <arm/mutex.h>


code:
/*	$OpenBSD: param.h,v 1.6 2013/03/23 16:12:28 deraadt Exp $	*/

/*
 * Copyright (c) 1994,1995 Mark Brinicombe.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the RiscBSD team.
 * 4. The name "RiscBSD" nor the name of the author may be used to
 *    endorse or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY RISCBSD ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL RISCBSD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef	_MACHINE_PARAM_H_
#define	_MACHINE_PARAM_H_

#include <arm/param.h>

#define	_MACHINE	zaurus
#define	MACHINE		"zaurus"

#ifndef	MSGBUFSIZE
#define	MSGBUFSIZE	(1 * PAGE_SIZE)
#endif

#endif /* _MACHINE_PARAM_H_ */


code:
/*	$OpenBSD: profile.h,v 1.1 2004/12/31 00:04:35 drahn Exp $	*/
/*	$NetBSD: profile.h,v 1.3 2001/11/25 15:55:57 thorpej Exp $	*/

#include <arm/profile.h>


code:
/*	$OpenBSD: reloc.h,v 1.1 2004/12/31 00:04:35 drahn Exp $	*/
#include <arm/reloc.h>


code:
/*	$OpenBSD: spinlock.h,v 1.4 2011/03/23 16:54:37 pirofti Exp $	*/
#ifndef _MACHINE_SPINLOCK_H_
#define _MACHINE_SPINLOCK_H_
#include <arm/spinlock.h>
#endif /* _MACHINE_SPINLOCK_H_ */


code:
/*	$OpenBSD: sysarch.h,v 1.1 2004/12/31 00:04:35 drahn Exp $	*/
/*	$NetBSD: sysarch.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $	*/

#include <arm/sysarch.h>


code:
/*	$OpenBSD: tcb.h,v 1.2 2013/06/01 21:20:54 jasper Exp $	*/
/* public domain */
#include <arm/tcb.h>


code:
/* 	$OpenBSD: vmparam.h,v 1.8 2015/06/24 21:35:01 miod Exp $	*/
/*	$NetBSD: vmparam.h,v 1.23 2003/05/22 05:47:07 thorpej Exp $	*/

/*
 * Copyright (c) 1988 The Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef	_MACHINE_VMPARAM_H_
#define	_MACHINE_VMPARAM_H_

#define	ARM_KERNEL_BASE		0xc0000000U

#include <arm/vmparam.h>

#ifdef _KERNEL
/*
 * Address space constants
 */

/*
 * The line between user space and kernel space
 * Mappings >= KERNEL_BASE are constant across all processes
 */
#define	KERNEL_BASE		ARM_KERNEL_BASE

#define VM_KERNEL_SPACE_SIZE	0x10000000

/*
 * Override the default pager_map size, there's not enough KVA.
 */
#define PAGER_MAP_SIZE		(4 * 1024 * 1024)

/*
 * Size of User Raw I/O map
 */

#define USRIOSIZE       300

/* virtual sizes (bytes) for various kernel submaps */

#define VM_PHYS_SIZE		(USRIOSIZE*PAGE_SIZE)

/*
 * max number of non-contig chunks of physical RAM you can have
 */

#define	VM_PHYSSEG_MAX		1
#define	VM_PHYSSEG_STRAT	VM_PSTRAT_RANDOM

/*
 * this indicates that we can't add RAM to the VM system after the
 * vm system is init'd.
 */

#define	VM_PHYSSEG_NOADD

#endif /* _KERNEL */

#endif	/* _MACHINE_VMPARAM_H_ */


code:
/*	$OpenBSD: zaurus_var.h,v 1.5 2008/11/25 14:55:44 drahn Exp $	*/
/*	$NetBSD: lubbock_var.h,v 1.1 2003/06/18 10:51:15 bsh Exp $ */

/*
 * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
 * Written by Hiroyuki Bessho for Genetec Corporation.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of Genetec Corporation may not be used to endorse or
 *    promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _EVBARM_ZAURUS_VAR_H
#define _EVBARM_ZAURUS_VAR_H

#include <sys/conf.h>
#include <sys/device.h>

#include <machine/bus.h>
#include <machine/machine_reg.h>

#ifdef _KERNEL

#define ZAURUS_C860		0xC0860
#define ZAURUS_C3000		0xC3000

extern int zaurusmod;

#define ZAURUS_ISC860		(zaurusmod == ZAURUS_C860)
#define ZAURUS_ISC3000		(zaurusmod == ZAURUS_C3000)

#endif

#endif /* _EVBARM_ZAURUS_VAR_H */


code:
/Makefile/1.6/Fri Nov  4 01:02:31 2005//TOPENBSD_5_8_BASE
/Makefile.inc/1.2/Fri Nov  4 01:02:31 2005//TOPENBSD_5_8_BASE
D/zboot////
D/zbsdmod////

path: sys/arch/zaurus/stand/CVS/Entries


code: src/sys/arch/zaurus/stand

path: sys/arch/zaurus/stand/CVS/Repository


code:
#	$OpenBSD: Makefile,v 1.6 2005/11/04 01:02:31 uwe Exp $

SUBDIR= zboot

.if ${MACHINE} == "zaurus"
SUBDIR+= zbsdmod
.endif

.include <bsd.subdir.mk>

path: sys/arch/zaurus/stand/Makefile


code:
#	$OpenBSD: Makefile.inc,v 1.2 2005/11/04 01:02:31 uwe Exp $

BINDIR=	/usr/mdec


path: sys/arch/zaurus/stand/zboot/CVS/Entries


path: sys/arch/zaurus/stand/zboot/CVS/Tag


code:
#	$OpenBSD: Makefile,v 1.16 2014/07/20 19:33:54 tobias Exp $

MAN=	boot.8
MANSUBDIR=zaurus
MLINKS=	boot.8 boot.conf.5

.if ${MACHINE} == "zaurus"
PROG=	zboot
LDFLAGS+=-nostdlib -Bstatic -nopie
INSTALL_STRIP=

SRCS=	crt0.c

S=	${.CURDIR}/../../../..

CLEANFILES+= arm machine
.if !make(libdep) && !make(sadep) && !make(salibdir) && !make(obj)
.BEGIN:
	@([ X$(S) = X -o -h arm ] || ln -s $(S)/arch/arm/include arm)
	@([ X$(S) = X -o -h machine ] || ln -s $(S)/arch/zaurus/include machine)
.endif

# stand/boot
SRCS+=	boot.c cmd.c vars.c bootarg.c conf.c

# libsa
SRCS+=	close.c closeall.c cons.c ctime.c disklabel.c dkcksum.c fstat.c \
	lseek.c memcmp.c memcpy.c memset.c open.c printf.c read.c \
	readdir.c snprintf.c stat.c strerror.c strtol.c ufs.c

.PATH:	${S}/lib/libkern/arch/arm ${S}/lib/libkern
SRCS+=	getchar.c putchar.c strcmp.c strlcpy.c strlen.c strncmp.c strncpy.c \
	write.c ashrdi3.c divsi3.S divdi3.c moddi3.c qdivrem.c

# local overrides and additions
SRCS+=	alloc.c devopen.c diskprobe.c exec.c exit.c loadfile.c \
	machdep.c termios.c unixcons.c unixdev.c unixsys.S

.PATH:	${S}/stand/boot
.PATH:	${S}/lib/libsa

${PROG}: ${OBJS} ${LIBSA}
	${LD} ${LDFLAGS} -o ${PROG} ${OBJS} ${LIBSA}

.else
NOPROG=
.endif

.include <bsd.prog.mk>

AFLAGS+=-D_LOCORE
CPPFLAGS+=-D_STANDALONE
CPPFLAGS+=-I${S}/stand/boot -I${S}/lib/libsa -I. -I${.CURDIR} -I${S}
CFLAGS+=-fno-stack-protector -fno-builtin -fpack-struct -fno-pie
AFLAGS+= -fno-pie

path: sys/arch/zaurus/stand/zboot/Makefile


code:
/*	$OpenBSD: alloc.c,v 1.1 2005/01/10 00:25:03 deraadt Exp $	*/
/*	$NetBSD: alloc.c,v 1.6 1997/02/04 18:36:33 thorpej Exp $	*/

/*
 * Copyright (c) 1997 Christopher G. Demetriou.  All rights reserved.
 * Copyright (c) 1996
 *	Matthias Drochner.  All rights reserved.
 * Copyright (c) 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * The Mach Operating System project at Carnegie-Mellon University.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)alloc.c	8.1 (Berkeley) 6/11/93
 *
 *
 * Copyright (c) 1989, 1990, 1991 Carnegie Mellon University
 * All Rights Reserved.
 *
 * Author: Alessandro Forin
 *
 * Permission to use, copy, modify and distribute this software and its
 * documentation is hereby granted, provided that both the copyright
 * notice and this permission notice appear in all copies of the
 * software, derivative works or modified versions, and any portions
 * thereof, and that both notices appear in supporting documentation.
 *
 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
 *
 * Carnegie Mellon requests users of this software to return to
 *
 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
 *  School of Computer Science
 *  Carnegie Mellon University
 *  Pittsburgh PA 15213-3890
 *
 * any improvements or extensions that they make and grant Carnegie the
 * rights to redistribute these changes.
 */

/*
 * Dynamic memory allocator.
 *
 * Compile options:
 *
 *	ALLOC_TRACE	enable tracing of allocations/deallocations
 *
 *	ALLOC_FIRST_FIT	use a first-fit allocation algorithm, rather than
 *			the default best-fit algorithm.
 *
 *	HEAP_LIMIT	heap limit address (defaults to "no limit").
 *
 *	HEAP_START	start address of heap (defaults to '&end').
 *
 *	DEBUG		enable debugging sanity checks.
 */

#include <sys/param.h>

/*
 * Each block actually has ALIGN(unsigned) + ALIGN(size) bytes allocated
 * to it, as follows:
 *
 * 0 ... (sizeof(unsigned) - 1)
 *	allocated or unallocated: holds size of user-data part of block.
 *
 * sizeof(unsigned) ... (ALIGN(sizeof(unsigned)) - 1)
 *	allocated: unused
 *	unallocated: depends on packing of struct fl
 *
 * ALIGN(sizeof(unsigned)) ... (ALIGN(sizeof(unsigned)) + ALIGN(data size) - 1)
 *	allocated: user data
 *	unallocated: depends on packing of struct fl
 *
 * 'next' is only used when the block is unallocated (i.e. on the free list).
 * However, note that ALIGN(sizeof(unsigned)) + ALIGN(data size) must
 * be at least 'sizeof(struct fl)', so that blocks can be used as structures
 * when on the free list.
 */

#include <lib/libsa/stand.h>

struct fl {
	unsigned	size;
	struct fl	*next;
} *freelist = (struct fl *)0;

static char heap[4 * 1024 * 1024];
#define HEAP_START (heap)
#define HEAP_LIMIT (&heap[sizeof(heap)])

#ifdef HEAP_START
static char *top = (char *)HEAP_START;
#else
extern char end[];
static char *top = end;
#endif

void *
alloc(unsigned int size)
{
	struct fl **f = &freelist, **bestf = NULL;
#ifndef ALLOC_FIRST_FIT
	unsigned bestsize = 0xffffffff;	/* greater than any real size */
#endif
	char *help;
	int failed;

#ifdef ALLOC_TRACE
	printf("alloc(%u)", size);
#endif

#ifdef ALLOC_FIRST_FIT
	while (*f != (struct fl *)0 && (*f)->size < size)
		f = &((*f)->next);
	bestf = f;
	failed = (*bestf == (struct fl *)0);
#else
	/* scan freelist */
	while (*f) {
		if ((*f)->size >= size) {
			if ((*f)->size == size) /* exact match */
				goto found;

			if ((*f)->size < bestsize) {
				/* keep best fit */
				bestf = f;
				bestsize = (*f)->size;
			}
		}
		f = &((*f)->next);
	}

	/* no match in freelist if bestsize unchanged */
	failed = (bestsize == 0xffffffff);
#endif

	if (failed) { /* nothing found */
		/*
		 * allocate from heap, keep chunk len in
		 * first word
		 */
		help = top;

		/* make _sure_ the region can hold a struct fl. */
		if (size < ALIGN(sizeof (struct fl *)))
			size = ALIGN(sizeof (struct fl *));
		top += ALIGN(sizeof(unsigned)) + ALIGN(size);
#ifdef HEAP_LIMIT
		if (top > (char *)HEAP_LIMIT)
			panic("heap full (0x%lx+%u)", help, size);
#endif
		*(unsigned *)help = ALIGN(size);
#ifdef ALLOC_TRACE
		printf("=%p\n", help + ALIGN(sizeof(unsigned)));
#endif
		return(help + ALIGN(sizeof(unsigned)));
	}

	/* we take the best fit */
	f = bestf;

#ifndef ALLOC_FIRST_FIT
found:
#endif
	/* remove from freelist */
	help = (char *)*f;
	*f = (*f)->next;
#ifdef ALLOC_TRACE
	printf("=%p (origsize %u)\n", help + ALIGN(sizeof(unsigned)),
	    *(unsigned *)help);
#endif
	return(help + ALIGN(sizeof(unsigned)));
}

void
free(void *ptr, unsigned int size)
{
	struct fl *f = (struct fl *)((char *)ptr -
	    ALIGN(sizeof(unsigned)));

#ifdef ALLOC_TRACE
	printf("free(%p, %u) (origsize %u)\n", ptr, size, f->size);
#endif
#ifdef DEBUG
	if (size > f->size)
		printf("free %u bytes @%p, should be <=%u\n",
		    size, ptr, f->size);
#ifdef HEAP_START
	if (ptr < (void *)HEAP_START)
#else
	if (ptr < (void *)end)
#endif
		printf("free: %lx before start of heap.\n", (u_long)ptr);

#ifdef HEAP_LIMIT
	if (ptr > (void *)HEAP_LIMIT)
		printf("free: %lx beyond end of heap.\n", (u_long)ptr);
#endif
#endif /* DEBUG */
	/* put into freelist */
	f->next = freelist;
	freelist = f;
}


code:
/*	$OpenBSD: compat_linux.h,v 1.8 2007/06/16 00:26:33 deraadt Exp $	*/

/*
 * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/* This file must be included late, for redefinitions to take effect. */

#ifndef _LOCORE

#include <compat/linux/linux_types.h>
#include <compat/linux/linux_fcntl.h>
#include <compat/linux/linux_termios.h>
struct proc;
#include <compat/linux/linux_ioctl.h>

#define	INT_LIMIT(x)		(~((x)1 << (sizeof(x)*8 - 1)))
#define	OFFSET_MAX		INT_LIMIT(long long)
#define	OFFT_OFFSET_MAX		INT_LIMIT(long)

#undef	O_RDONLY
#undef	O_WRONLY
#undef	O_RDWR
#undef	SEEK_SET
#undef	SEEK_CUR

#define O_RDONLY		LINUX_O_RDONLY
#define O_WRONLY		LINUX_O_WRONLY
#define O_RDWR			LINUX_O_RDWR
#define SEEK_SET		0
#define SEEK_CUR		1

#define	LINUX_EOVERFLOW		75

#define termios			linux_termios

#define IMAXBEL			LINUX_IMAXBEL
#define IGNBRK			LINUX_IGNBRK
#define BRKINT			LINUX_BRKINT
#define PARMRK			LINUX_PARMRK
#define ISTRIP			LINUX_ISTRIP
#define INLCR			LINUX_INLCR
#define IGNCR			LINUX_IGNCR
#define ICRNL			LINUX_ICRNL
#define IXON			LINUX_IXON
#define OPOST			LINUX_OPOST
#define ECHO			LINUX_ECHO
#define ECHONL			LINUX_ECHONL
#define ICANON			LINUX_ICANON
#define ISIG			LINUX_ISIG
#define IEXTEN			LINUX_IEXTEN
#define CSIZE			LINUX_CSIZE
#define PARENB			LINUX_PARENB
#define CS8			LINUX_CS8

#define TIOCGETA		LINUX_TCGETS
#define TIOCSETA		LINUX_TCGETS
#define TIOCSETAW		LINUX_TCSETSW
#define TIOCSETAF		LINUX_TCSETSF

#define TCSANOW			LINUX_TCSANOW
#define TCSADRAIN		LINUX_TCSADRAIN
#define TCSAFLUSH		LINUX_TCSAFLUSH

typedef unsigned int speed_t;

void	cfmakeraw(struct termios *);
int	cfsetspeed(struct termios *, speed_t);
int	tcgetattr(int, struct termios *);
int	tcsetattr(int, int, struct termios *);

#endif /* !_LOCORE */

#include <compat/linux/linux_syscall.h>

/* linux/asm/unistd.h */
#define __NR_SYSCALL_BASE	0x900000
#define __NR_exit		(__NR_SYSCALL_BASE+LINUX_SYS_exit)
#define __NR_read		(__NR_SYSCALL_BASE+LINUX_SYS_read)
#define __NR_write		(__NR_SYSCALL_BASE+LINUX_SYS_write)
#define __NR_open		(__NR_SYSCALL_BASE+LINUX_SYS_open)
#define __NR_close		(__NR_SYSCALL_BASE+LINUX_SYS_close)
#define __NR_time		(__NR_SYSCALL_BASE+LINUX_SYS_time)
#define __NR_lseek32		(__NR_SYSCALL_BASE+LINUX_SYS_lseek)
#define __NR_ioctl		(__NR_SYSCALL_BASE+LINUX_SYS_ioctl)
#define __NR_select		(__NR_SYSCALL_BASE+LINUX_SYS_select)
#define __NR_stat		(__NR_SYSCALL_BASE+LINUX_SYS_stat)
#define __NR_syscall		(__NR_SYSCALL_BASE+113)

#undef	SYS_select
#define SYS_select		__NR_select


code:
/*	$OpenBSD: conf.c,v 1.9 2014/07/20 19:33:54 tobias Exp $	*/

/*
 * Copyright (c) 1996 Michael Shalayeff
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#include <sys/param.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <libsa.h>
#include <lib/libsa/ufs.h>
#ifdef notdef
#include <lib/libsa/cd9660.h>
#include <lib/libsa/fat.h>
#include <lib/libsa/nfs.h>
#include <lib/libsa/tftp.h>
#include <lib/libsa/netif.h>
#endif
#include "unixdev.h"
#include <dev/cons.h>

const char version[] = "2.10";
int	debug = 1;

void (*zaurus_probe1[])(void) = {
	cninit
};
void (*zaurus_probe2[])(void) = {
	diskprobe
};

struct zaurus_boot_probes probe_list[] = {
	{ "probing", zaurus_probe1, nitems(zaurus_probe1) },
	{ "disk",    zaurus_probe2, nitems(zaurus_probe2) }
};
int nibprobes = nitems(probe_list);

void (*sa_cleanup)(void) = NULL;

struct fs_ops file_system[] = {
	{ ufs_open,    ufs_close,    ufs_read,    ufs_write,    ufs_seek,
	  ufs_stat,    ufs_readdir    },
#ifdef notdef
	{ fat_open,    fat_close,    fat_read,    fat_write,    fat_seek,
	  fat_stat,    fat_readdir    },
	{ nfs_open,    nfs_close,    nfs_read,    nfs_write,    nfs_seek,
	  nfs_stat,    nfs_readdir    },
	{ cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek,
	  cd9660_stat, cd9660_readdir },
#endif
#ifdef _TEST
	{ null_open,   null_close,   null_read,   null_write,   null_seek,
	  null_stat,   null_readdir   }
#endif
};
int nfsys = nitems(file_system);

struct devsw	devsw[] = {
	{ "UNIX", unixstrategy, unixopen, unixclose, unixioctl },
#if 0
	{ "TFTP", tftpstrategy, tftpopen, tftpclose, tftpioctl },
#endif
};
int ndevs = nitems(devsw);

#ifdef notdef
struct netif_driver	*netif_drivers[] = {
	NULL
};
int n_netif_drivers = nitems(netif_drivers);
#endif

struct consdev constab[] = {
	{ cn_probe, cn_init, cn_getc, cn_putc },
	{ com_probe, com_init, com_getc, com_putc },
	{ NULL }
};
struct consdev *cn_tab = constab;


code:
/*	$OpenBSD: crt0.c,v 1.1 2005/04/16 17:22:44 uwe Exp $	*/

/*
 * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

void _start(void) asm("_start");

void
_start(void)
{
	boot(0);
}