xref: /netbsd-src/sys/arch/hpcarm/dev/nbp_slhci.c (revision 4e8e66439e246961c4367c78584be80e23f52897)
1 /*	$NetBSD: nbp_slhci.c,v 1.2 2016/04/23 10:15:29 skrll Exp $ */
2 /*
3  * Copyright (c) 2011 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: nbp_slhci.c,v 1.2 2016/04/23 10:15:29 skrll Exp $");
29 
30 #include <sys/param.h>
31 #include <sys/bus.h>
32 #include <sys/device.h>
33 #include <sys/errno.h>
34 
35 #include <machine/platid.h>
36 #include <machine/platid_mask.h>
37 
38 #include <arm/xscale/pxa2x0var.h>
39 #include <arm/xscale/pxa2x0_gpio.h>
40 
41 #include <dev/usb/usb.h>
42 #include <dev/usb/usbdi.h>
43 #include <dev/usb/usbdivar.h>
44 #include <dev/ic/sl811hsvar.h>
45 
46 #define NETBOOKPRO_SLHCI_REG_ADDR	0x00000
47 #define NETBOOKPRO_SLHCI_REG_DATA	0x10000
48 #define NETBOOKPRO_SLHCI_REG_SIZE	0x20000
49 
50 static int nbp_slhci_match(device_t, cfdata_t, void *);
51 static void nbp_slhci_attach(device_t, device_t, void *);
52 
53 static void nbp_slhci_power(void *, enum power_change);
54 
55 CFATTACH_DECL_NEW(nbp_slhci, sizeof(struct slhci_softc),
56     nbp_slhci_match, nbp_slhci_attach, NULL, NULL);
57 
58 
59 /* ARGSUSED */
60 static int
nbp_slhci_match(device_t parent,cfdata_t match,void * aux)61 nbp_slhci_match(device_t parent, cfdata_t match, void *aux)
62 {
63 	struct pxaip_attach_args *pxa = aux;
64 
65 	if (strcmp(pxa->pxa_name, match->cf_name) != 0 ||
66 	    !platid_match(&platid, &platid_mask_MACH_PSIONTEKLOGIX_NETBOOK_PRO))
67 		return 0;
68 
69 	return 1;
70 }
71 
72 /* ARGSUSED */
73 static void
nbp_slhci_attach(device_t parent,device_t self,void * aux)74 nbp_slhci_attach(device_t parent, device_t self, void *aux)
75 {
76 	struct slhci_softc *sc = device_private(self);
77 	struct pxaip_attach_args *pxa = aux;
78 	bus_space_handle_t ioh;
79 
80 	aprint_naive("\n");
81 	aprint_normal("\n");
82 
83 	sc->sc_dev = self;
84 	sc->sc_bus.ub_hcpriv = sc;
85 
86 	if (bus_space_map(pxa->pxa_iot, pxa->pxa_addr,
87 				NETBOOKPRO_SLHCI_REG_SIZE, 0, &ioh) != 0) {
88 		aprint_error_dev(self, "can't map I/O space\n");
89 		return;
90 	}
91 
92 	slhci_preinit(sc, nbp_slhci_power, pxa->pxa_iot, ioh, 0,
93 	    NETBOOKPRO_SLHCI_REG_DATA - NETBOOKPRO_SLHCI_REG_ADDR);
94 
95 	/* GPIO 2 connects IRQ */
96 	pxa2x0_gpio_set_function(2, GPIO_IN);
97 	if (pxa2x0_gpio_intr_establish(2, IST_EDGE_RISING, IPL_USB,
98 						slhci_intr, sc) == NULL) {
99 		aprint_error_dev(self, "unable to establish interrupt\n");
100 		return;
101 	}
102 
103 	/* Reset Host Controller */
104 	pxa2x0_gpio_set_function(14, GPIO_OUT);
105 	pxa2x0_gpio_clear_bit(14);
106 	delay(1);			/* XXXX: nRST for 16+ clocks @ 48MHz */
107 	pxa2x0_gpio_set_bit(14);
108 
109 	if (slhci_attach(sc))
110 		aprint_error_dev(self, "slhci_attach failed\n");
111 	return;
112 }
113 
114 static void
nbp_slhci_power(void * arg,enum power_change onoff)115 nbp_slhci_power(void *arg, enum power_change onoff)
116 {
117 
118 //	nbp_pcon_command(I2C_SETUSBHOSTPOWER, onoff, PCON_FLAG_ASYNC, NULL);
119 }
120