1/*	$NetBSD$	*/
2/*
3 * Copyright (c) 2013 KIYOHARA Takashi
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD$");
29
30#include <sys/param.h>
31#include <sys/bus.h>
32#include <sys/device.h>
33#include <sys/errno.h>
34
35#include <epoc32/windermere/windermerereg.h>
36#include <epoc32/windermere/windermerevar.h>
37#include <epoc32/dev/epockbdvar.h>
38
39#include "locators.h"
40
41static int epockbd_windermere_match(device_t, cfdata_t, void *);
42static void epockbd_windermere_attach(device_t, device_t, void *);
43
44CFATTACH_DECL_NEW(epockbd_windermere, sizeof(struct epockbd_softc),
45    epockbd_windermere_match, epockbd_windermere_attach, NULL, NULL);
46
47static int
48epockbd_windermere_match(device_t parent, cfdata_t match, void *aux)
49{
50	struct windermere_attach_args *aa = aux;
51
52        /* Wildcard not accept */
53	if (aa->aa_offset == WINDERMERECF_OFFSET_DEFAULT)
54		return 0;
55
56	return 1;
57}
58
59static void
60epockbd_windermere_attach(device_t parent, device_t self, void *aux)
61{
62	struct epockbd_softc *sc = device_private(self);
63	struct windermere_attach_args *aa = aux;
64	bus_space_tag_t iot = aa->aa_iot;
65	bus_space_handle_t ioh = *aa->aa_ioh;
66	bus_addr_t gpio_addr;
67
68	sc->sc_dev = self;
69	sc->sc_kbd_ncolumn = 8;
70	sc->sc_kbd_nrow = 7;
71	if (windermere_bus_space_subregion(iot, ioh, aa->aa_offset,
72					sizeof(uint32_t), &sc->sc_scanh) != 0) {
73		aprint_error_dev(self, "can't map scan registers\n");
74		return;
75	}
76	gpio_addr = aa->aa_offset & ~0xff;	/* XXXX */
77	if (windermere_bus_space_subregion(iot, ioh, gpio_addr,
78					sizeof(uint32_t), &sc->sc_datah) != 0) {
79		aprint_error_dev(self, "can't map data registers\n");
80		return;
81	}
82	sc->sc_scant = iot;
83	sc->sc_datat = iot;
84
85	epockbd_attach(sc);
86}
87