armadillo9_pcic.c revision 1.1 1 /* $NetBSD: armadillo9_pcic.c,v 1.1 2005/11/13 06:33:05 hamajima 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.1 2005/11/13 06:33:05 hamajima 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 struct armadillo9pcic_softc {
47 struct eppcic_softc sc_dev;
48 };
49
50 static int armadillo9pcic_match(struct device *, struct cfdata *, void *);
51 static void armadillo9pcic_attach(struct device *, struct device *, void *);
52
53 CFATTACH_DECL(armadillo9pcic, sizeof(struct armadillo9pcic_softc),
54 armadillo9pcic_match, armadillo9pcic_attach, NULL, NULL);
55
56 static int armadillo9pcic_card_mode(void *, int);
57 static int armadillo9pcic_power_capability(void *, int);
58 static int armadillo9pcic_power_ctl(void *, int, int);
59
60 struct eppcic_chipset_tag armadillo9pcic_tag = {
61 armadillo9pcic_card_mode,
62 armadillo9pcic_power_capability,
63 armadillo9pcic_power_ctl
64 };
65
66 static int
67 armadillo9pcic_match(struct device *parent, struct cfdata *match, void *aux)
68 {
69 return 1;
70 }
71
72 static void
73 armadillo9pcic_attach(struct device *parent, struct device *self, void *aux)
74 {
75 struct epsoc_attach_args *sa = aux;
76
77 epgpio_out(sa->sa_gpio, PORT_A, 3);
78 eppcic_attach_common(parent, self, aux, &armadillo9pcic_tag);
79 }
80
81 static int
82 armadillo9pcic_card_mode(void *self, int socket)
83 {
84 if (socket == 0)
85 return CF_MODE;
86 else
87 return SLOT_DISABLE;
88 }
89
90 static int
91 armadillo9pcic_power_capability(void *self, int socket)
92 {
93 int vcc = 0;
94
95 if (socket == 0)
96 vcc |= VCC_3V;
97 return vcc;
98 }
99
100 static int
101 armadillo9pcic_power_ctl(void *self, int socket, int onoff)
102 {
103 struct eppcic_softc *sc = (struct eppcic_softc *)self;
104
105 DPRINTFN(1, ("armadillo9pcic_power_ctl: %s\n",onoff?"on":"off"));
106
107 if (onoff)
108 epgpio_clear(sc->sc_gpio, PORT_A, 3);
109 else
110 epgpio_set(sc->sc_gpio, PORT_A, 3);
111 return (300 * 1000);
112 }
113