xref: /netbsd-src/sys/arch/evbarm/armadillo/armadillo9_pcic.c (revision cbab9cadce21ae72fac13910001079fff214cc29)
1 /*	$NetBSD: armadillo9_pcic.c,v 1.2 2012/10/27 17:17:46 chs Exp $	*/
2 
3 /*
4  * Copyright (c) 2005 HAMAJIMA Katsuomi. 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 AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: armadillo9_pcic.c,v 1.2 2012/10/27 17:17:46 chs Exp $");
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/device.h>
35 #include <arm/ep93xx/epsocvar.h>
36 #include <arm/ep93xx/epgpiovar.h>
37 #include <arm/ep93xx/eppcicvar.h>
38 
39 #ifdef A9PCIC_DEBUG
40 int armadillo9pcic_debug = A9PCIC_DEBUG;
41 #define DPRINTFN(n,x)	if (armadillo9pcic_debug>(n)) printf x;
42 #else
43 #define DPRINTFN(n,x)
44 #endif
45 
46 static int armadillo9pcic_match(device_t, cfdata_t, void *);
47 static void armadillo9pcic_attach(device_t, device_t, void *);
48 
49 CFATTACH_DECL_NEW(armadillo9pcic, 0,
50     armadillo9pcic_match, armadillo9pcic_attach, NULL, NULL);
51 
52 static int armadillo9pcic_card_mode(void *, int);
53 static int armadillo9pcic_power_capability(void *, int);
54 static int armadillo9pcic_power_ctl(void *, int, int);
55 
56 struct eppcic_chipset_tag armadillo9pcic_tag = {
57 	armadillo9pcic_card_mode,
58 	armadillo9pcic_power_capability,
59 	armadillo9pcic_power_ctl
60 };
61 
62 static int
armadillo9pcic_match(device_t parent,cfdata_t match,void * aux)63 armadillo9pcic_match(device_t parent, cfdata_t match, void *aux)
64 {
65 	return 1;
66 }
67 
68 static void
armadillo9pcic_attach(device_t parent,device_t self,void * aux)69 armadillo9pcic_attach(device_t parent, device_t self, void *aux)
70 {
71 	struct epsoc_attach_args *sa = aux;
72 
73 	epgpio_out(sa->sa_gpio, PORT_A, 3);
74 	eppcic_attach_common(parent, self, aux, &armadillo9pcic_tag);
75 }
76 
77 static int
armadillo9pcic_card_mode(void * self,int socket)78 armadillo9pcic_card_mode(void *self, int socket)
79 {
80 	if (socket == 0)
81 		return CF_MODE;
82 	else
83 		return SLOT_DISABLE;
84 }
85 
86 static int
armadillo9pcic_power_capability(void * self,int socket)87 armadillo9pcic_power_capability(void *self, int socket)
88 {
89 	int vcc = 0;
90 
91 	if (socket == 0)
92 		vcc |= VCC_3V;
93 	return vcc;
94 }
95 
96 static int
armadillo9pcic_power_ctl(void * self,int socket,int onoff)97 armadillo9pcic_power_ctl(void *self, int socket, int onoff)
98 {
99 	struct eppcic_softc *sc = device_private(self);
100 
101 	DPRINTFN(1, ("armadillo9pcic_power_ctl: %s\n",onoff?"on":"off"));
102 
103 	if (onoff)
104 		epgpio_clear(sc->sc_gpio, PORT_A, 3);
105 	else
106 		epgpio_set(sc->sc_gpio, PORT_A, 3);
107 	return (300 * 1000);
108 }
109