nbp_slhci.c revision 1.2 1 1.2 skrll /* $NetBSD: nbp_slhci.c,v 1.2 2016/04/23 10:15:29 skrll Exp $ */
2 1.1 kiyohara /*
3 1.1 kiyohara * Copyright (c) 2011 KIYOHARA Takashi
4 1.1 kiyohara * All rights reserved.
5 1.1 kiyohara *
6 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
7 1.1 kiyohara * modification, are permitted provided that the following conditions
8 1.1 kiyohara * are met:
9 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
10 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
11 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
13 1.1 kiyohara * documentation and/or other materials provided with the distribution.
14 1.1 kiyohara *
15 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 kiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 1.1 kiyohara * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 1.1 kiyohara * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 1.1 kiyohara * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 1.1 kiyohara * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 1.1 kiyohara * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 kiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 1.1 kiyohara * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 1.1 kiyohara * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 kiyohara * POSSIBILITY OF SUCH DAMAGE.
26 1.1 kiyohara */
27 1.1 kiyohara #include <sys/cdefs.h>
28 1.2 skrll __KERNEL_RCSID(0, "$NetBSD: nbp_slhci.c,v 1.2 2016/04/23 10:15:29 skrll Exp $");
29 1.1 kiyohara
30 1.1 kiyohara #include <sys/param.h>
31 1.1 kiyohara #include <sys/bus.h>
32 1.1 kiyohara #include <sys/device.h>
33 1.1 kiyohara #include <sys/errno.h>
34 1.1 kiyohara
35 1.1 kiyohara #include <machine/platid.h>
36 1.1 kiyohara #include <machine/platid_mask.h>
37 1.1 kiyohara
38 1.1 kiyohara #include <arm/xscale/pxa2x0var.h>
39 1.1 kiyohara #include <arm/xscale/pxa2x0_gpio.h>
40 1.1 kiyohara
41 1.1 kiyohara #include <dev/usb/usb.h>
42 1.1 kiyohara #include <dev/usb/usbdi.h>
43 1.1 kiyohara #include <dev/usb/usbdivar.h>
44 1.1 kiyohara #include <dev/ic/sl811hsvar.h>
45 1.1 kiyohara
46 1.1 kiyohara #define NETBOOKPRO_SLHCI_REG_ADDR 0x00000
47 1.1 kiyohara #define NETBOOKPRO_SLHCI_REG_DATA 0x10000
48 1.1 kiyohara #define NETBOOKPRO_SLHCI_REG_SIZE 0x20000
49 1.1 kiyohara
50 1.1 kiyohara static int nbp_slhci_match(device_t, cfdata_t, void *);
51 1.1 kiyohara static void nbp_slhci_attach(device_t, device_t, void *);
52 1.1 kiyohara
53 1.1 kiyohara static void nbp_slhci_power(void *, enum power_change);
54 1.1 kiyohara
55 1.1 kiyohara CFATTACH_DECL_NEW(nbp_slhci, sizeof(struct slhci_softc),
56 1.1 kiyohara nbp_slhci_match, nbp_slhci_attach, NULL, NULL);
57 1.1 kiyohara
58 1.1 kiyohara
59 1.1 kiyohara /* ARGSUSED */
60 1.1 kiyohara static int
61 1.1 kiyohara nbp_slhci_match(device_t parent, cfdata_t match, void *aux)
62 1.1 kiyohara {
63 1.1 kiyohara struct pxaip_attach_args *pxa = aux;
64 1.1 kiyohara
65 1.1 kiyohara if (strcmp(pxa->pxa_name, match->cf_name) != 0 ||
66 1.1 kiyohara !platid_match(&platid, &platid_mask_MACH_PSIONTEKLOGIX_NETBOOK_PRO))
67 1.1 kiyohara return 0;
68 1.1 kiyohara
69 1.1 kiyohara return 1;
70 1.1 kiyohara }
71 1.1 kiyohara
72 1.1 kiyohara /* ARGSUSED */
73 1.1 kiyohara static void
74 1.1 kiyohara nbp_slhci_attach(device_t parent, device_t self, void *aux)
75 1.1 kiyohara {
76 1.1 kiyohara struct slhci_softc *sc = device_private(self);
77 1.1 kiyohara struct pxaip_attach_args *pxa = aux;
78 1.1 kiyohara bus_space_handle_t ioh;
79 1.1 kiyohara
80 1.1 kiyohara aprint_naive("\n");
81 1.1 kiyohara aprint_normal("\n");
82 1.1 kiyohara
83 1.1 kiyohara sc->sc_dev = self;
84 1.2 skrll sc->sc_bus.ub_hcpriv = sc;
85 1.1 kiyohara
86 1.1 kiyohara if (bus_space_map(pxa->pxa_iot, pxa->pxa_addr,
87 1.1 kiyohara NETBOOKPRO_SLHCI_REG_SIZE, 0, &ioh) != 0) {
88 1.1 kiyohara aprint_error_dev(self, "can't map I/O space\n");
89 1.1 kiyohara return;
90 1.1 kiyohara }
91 1.1 kiyohara
92 1.1 kiyohara slhci_preinit(sc, nbp_slhci_power, pxa->pxa_iot, ioh, 0,
93 1.1 kiyohara NETBOOKPRO_SLHCI_REG_DATA - NETBOOKPRO_SLHCI_REG_ADDR);
94 1.1 kiyohara
95 1.1 kiyohara /* GPIO 2 connects IRQ */
96 1.1 kiyohara pxa2x0_gpio_set_function(2, GPIO_IN);
97 1.1 kiyohara if (pxa2x0_gpio_intr_establish(2, IST_EDGE_RISING, IPL_USB,
98 1.1 kiyohara slhci_intr, sc) == NULL) {
99 1.1 kiyohara aprint_error_dev(self, "unable to establish interrupt\n");
100 1.1 kiyohara return;
101 1.1 kiyohara }
102 1.1 kiyohara
103 1.1 kiyohara /* Reset Host Controller */
104 1.1 kiyohara pxa2x0_gpio_set_function(14, GPIO_OUT);
105 1.1 kiyohara pxa2x0_gpio_clear_bit(14);
106 1.1 kiyohara delay(1); /* XXXX: nRST for 16+ clocks @ 48MHz */
107 1.1 kiyohara pxa2x0_gpio_set_bit(14);
108 1.1 kiyohara
109 1.1 kiyohara if (slhci_attach(sc))
110 1.1 kiyohara aprint_error_dev(self, "slhci_attach failed\n");
111 1.1 kiyohara return;
112 1.1 kiyohara }
113 1.1 kiyohara
114 1.1 kiyohara static void
115 1.1 kiyohara nbp_slhci_power(void *arg, enum power_change onoff)
116 1.1 kiyohara {
117 1.1 kiyohara
118 1.1 kiyohara // nbp_pcon_command(I2C_SETUSBHOSTPOWER, onoff, PCON_FLAG_ASYNC, NULL);
119 1.1 kiyohara }
120