1*4e8e6643Sskrll /* $NetBSD: nbp_slhci.c,v 1.2 2016/04/23 10:15:29 skrll Exp $ */
2587ef940Skiyohara /*
3587ef940Skiyohara * Copyright (c) 2011 KIYOHARA Takashi
4587ef940Skiyohara * All rights reserved.
5587ef940Skiyohara *
6587ef940Skiyohara * Redistribution and use in source and binary forms, with or without
7587ef940Skiyohara * modification, are permitted provided that the following conditions
8587ef940Skiyohara * are met:
9587ef940Skiyohara * 1. Redistributions of source code must retain the above copyright
10587ef940Skiyohara * notice, this list of conditions and the following disclaimer.
11587ef940Skiyohara * 2. Redistributions in binary form must reproduce the above copyright
12587ef940Skiyohara * notice, this list of conditions and the following disclaimer in the
13587ef940Skiyohara * documentation and/or other materials provided with the distribution.
14587ef940Skiyohara *
15587ef940Skiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16587ef940Skiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17587ef940Skiyohara * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18587ef940Skiyohara * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19587ef940Skiyohara * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20587ef940Skiyohara * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21587ef940Skiyohara * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22587ef940Skiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23587ef940Skiyohara * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24587ef940Skiyohara * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25587ef940Skiyohara * POSSIBILITY OF SUCH DAMAGE.
26587ef940Skiyohara */
27587ef940Skiyohara #include <sys/cdefs.h>
28*4e8e6643Sskrll __KERNEL_RCSID(0, "$NetBSD: nbp_slhci.c,v 1.2 2016/04/23 10:15:29 skrll Exp $");
29587ef940Skiyohara
30587ef940Skiyohara #include <sys/param.h>
31587ef940Skiyohara #include <sys/bus.h>
32587ef940Skiyohara #include <sys/device.h>
33587ef940Skiyohara #include <sys/errno.h>
34587ef940Skiyohara
35587ef940Skiyohara #include <machine/platid.h>
36587ef940Skiyohara #include <machine/platid_mask.h>
37587ef940Skiyohara
38587ef940Skiyohara #include <arm/xscale/pxa2x0var.h>
39587ef940Skiyohara #include <arm/xscale/pxa2x0_gpio.h>
40587ef940Skiyohara
41587ef940Skiyohara #include <dev/usb/usb.h>
42587ef940Skiyohara #include <dev/usb/usbdi.h>
43587ef940Skiyohara #include <dev/usb/usbdivar.h>
44587ef940Skiyohara #include <dev/ic/sl811hsvar.h>
45587ef940Skiyohara
46587ef940Skiyohara #define NETBOOKPRO_SLHCI_REG_ADDR 0x00000
47587ef940Skiyohara #define NETBOOKPRO_SLHCI_REG_DATA 0x10000
48587ef940Skiyohara #define NETBOOKPRO_SLHCI_REG_SIZE 0x20000
49587ef940Skiyohara
50587ef940Skiyohara static int nbp_slhci_match(device_t, cfdata_t, void *);
51587ef940Skiyohara static void nbp_slhci_attach(device_t, device_t, void *);
52587ef940Skiyohara
53587ef940Skiyohara static void nbp_slhci_power(void *, enum power_change);
54587ef940Skiyohara
55587ef940Skiyohara CFATTACH_DECL_NEW(nbp_slhci, sizeof(struct slhci_softc),
56587ef940Skiyohara nbp_slhci_match, nbp_slhci_attach, NULL, NULL);
57587ef940Skiyohara
58587ef940Skiyohara
59587ef940Skiyohara /* ARGSUSED */
60587ef940Skiyohara static int
nbp_slhci_match(device_t parent,cfdata_t match,void * aux)61587ef940Skiyohara nbp_slhci_match(device_t parent, cfdata_t match, void *aux)
62587ef940Skiyohara {
63587ef940Skiyohara struct pxaip_attach_args *pxa = aux;
64587ef940Skiyohara
65587ef940Skiyohara if (strcmp(pxa->pxa_name, match->cf_name) != 0 ||
66587ef940Skiyohara !platid_match(&platid, &platid_mask_MACH_PSIONTEKLOGIX_NETBOOK_PRO))
67587ef940Skiyohara return 0;
68587ef940Skiyohara
69587ef940Skiyohara return 1;
70587ef940Skiyohara }
71587ef940Skiyohara
72587ef940Skiyohara /* ARGSUSED */
73587ef940Skiyohara static void
nbp_slhci_attach(device_t parent,device_t self,void * aux)74587ef940Skiyohara nbp_slhci_attach(device_t parent, device_t self, void *aux)
75587ef940Skiyohara {
76587ef940Skiyohara struct slhci_softc *sc = device_private(self);
77587ef940Skiyohara struct pxaip_attach_args *pxa = aux;
78587ef940Skiyohara bus_space_handle_t ioh;
79587ef940Skiyohara
80587ef940Skiyohara aprint_naive("\n");
81587ef940Skiyohara aprint_normal("\n");
82587ef940Skiyohara
83587ef940Skiyohara sc->sc_dev = self;
84*4e8e6643Sskrll sc->sc_bus.ub_hcpriv = sc;
85587ef940Skiyohara
86587ef940Skiyohara if (bus_space_map(pxa->pxa_iot, pxa->pxa_addr,
87587ef940Skiyohara NETBOOKPRO_SLHCI_REG_SIZE, 0, &ioh) != 0) {
88587ef940Skiyohara aprint_error_dev(self, "can't map I/O space\n");
89587ef940Skiyohara return;
90587ef940Skiyohara }
91587ef940Skiyohara
92587ef940Skiyohara slhci_preinit(sc, nbp_slhci_power, pxa->pxa_iot, ioh, 0,
93587ef940Skiyohara NETBOOKPRO_SLHCI_REG_DATA - NETBOOKPRO_SLHCI_REG_ADDR);
94587ef940Skiyohara
95587ef940Skiyohara /* GPIO 2 connects IRQ */
96587ef940Skiyohara pxa2x0_gpio_set_function(2, GPIO_IN);
97587ef940Skiyohara if (pxa2x0_gpio_intr_establish(2, IST_EDGE_RISING, IPL_USB,
98587ef940Skiyohara slhci_intr, sc) == NULL) {
99587ef940Skiyohara aprint_error_dev(self, "unable to establish interrupt\n");
100587ef940Skiyohara return;
101587ef940Skiyohara }
102587ef940Skiyohara
103587ef940Skiyohara /* Reset Host Controller */
104587ef940Skiyohara pxa2x0_gpio_set_function(14, GPIO_OUT);
105587ef940Skiyohara pxa2x0_gpio_clear_bit(14);
106587ef940Skiyohara delay(1); /* XXXX: nRST for 16+ clocks @ 48MHz */
107587ef940Skiyohara pxa2x0_gpio_set_bit(14);
108587ef940Skiyohara
109587ef940Skiyohara if (slhci_attach(sc))
110587ef940Skiyohara aprint_error_dev(self, "slhci_attach failed\n");
111587ef940Skiyohara return;
112587ef940Skiyohara }
113587ef940Skiyohara
114587ef940Skiyohara static void
nbp_slhci_power(void * arg,enum power_change onoff)115587ef940Skiyohara nbp_slhci_power(void *arg, enum power_change onoff)
116587ef940Skiyohara {
117587ef940Skiyohara
118587ef940Skiyohara // nbp_pcon_command(I2C_SETUSBHOSTPOWER, onoff, PCON_FLAG_ASYNC, NULL);
119587ef940Skiyohara }
120