j720pcic.c revision 1.3 1 /* $NetBSD: j720pcic.c,v 1.3 2006/03/04 13:56:17 peter Exp $ */
2
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by IWAMOTO Toshihiro.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: j720pcic.c,v 1.3 2006/03/04 13:56:17 peter Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/types.h>
45 #include <sys/conf.h>
46 #include <sys/file.h>
47 #include <sys/device.h>
48 #include <sys/kernel.h>
49 #include <sys/kthread.h>
50 #include <sys/malloc.h>
51
52 #include <machine/bus.h>
53 #include <machine/platid.h>
54 #include <machine/platid_mask.h>
55
56 #include <dev/pcmcia/pcmciachip.h>
57 #include <dev/pcmcia/pcmciavar.h>
58 #include <arm/sa11x0/sa11x0_reg.h>
59 #include <arm/sa11x0/sa11x0_var.h>
60 #include <arm/sa11x0/sa1111_reg.h>
61 #include <arm/sa11x0/sa1111_var.h>
62 #include <arm/sa11x0/sa11x1_pcicreg.h>
63 #include <arm/sa11x0/sa11xx_pcicvar.h>
64 #include <arm/sa11x0/sa11x1_pcicvar.h>
65
66 #include "sacpcic.h"
67
68 static int sacpcic_match(struct device *, struct cfdata *, void *);
69 static void sacpcic_attach(struct device *, struct device *, void *);
70 static void j720_set_power(struct sapcic_socket *so, int arg);
71
72 static struct sapcic_tag j720_sacpcic_functions = {
73 sacpcic_read,
74 sacpcic_write,
75 j720_set_power,
76 sacpcic_clear_intr,
77 sacpcic_intr_establish,
78 sacpcic_intr_disestablish
79 };
80
81 static int j720_power_capability[] = {
82 SAPCIC_POWER_5V | SAPCIC_POWER_3V, SAPCIC_POWER_3V
83 };
84
85 static struct platid_data sacpcic_platid_table[] = {
86 { &platid_mask_MACH_HP_JORNADA_7XX, j720_power_capability },
87 { NULL, NULL }
88 };
89
90 CFATTACH_DECL(sacpcic, sizeof(struct sacpcic_softc),
91 sacpcic_match, sacpcic_attach, NULL, NULL);
92
93 static int
94 sacpcic_match(struct device *parent, struct cfdata *cf, void *aux)
95 {
96 return (1);
97 }
98
99 static void
100 j720_socket_setup(struct sapcic_socket *sp)
101 {
102 int *ip;
103 struct platid_data *p;
104 int socket = sp->socket;
105
106 p = platid_search_data(&platid, sacpcic_platid_table);
107
108 if (p == NULL) {
109 sp->power_capability = SAPCIC_POWER_5V;
110 } else {
111 ip = (int *)p->data;
112 sp->power_capability = ip[socket];
113 }
114
115 sp->pcictag = &j720_sacpcic_functions;
116 }
117
118 static void
119 sacpcic_attach(struct device *parent, struct device *self, void *aux)
120 {
121 sacpcic_attach_common((struct sacc_softc *)parent,
122 (struct sacpcic_softc *)self, aux, j720_socket_setup);
123 }
124
125 static void
126 j720_set_power(so, arg)
127 struct sapcic_socket *so;
128 int arg;
129 {
130 int newval, oldval, s;
131 struct sacc_softc *sc = so->pcictag_cookie;
132
133 /* XXX this isn't well confirmed. DANGER DANGER */
134 switch (arg) {
135 case SAPCIC_POWER_OFF:
136 newval = 0;
137 break;
138 case SAPCIC_POWER_3V:
139 newval = 2;
140 break;
141 case SAPCIC_POWER_5V:
142 newval = 1;
143 break;
144 default:
145 panic("sacpcic_set_power: bogus arg");
146 }
147
148 s = splbio();
149 oldval = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
150 SACCGPIOA_DVR);
151 switch (so->socket) {
152 case 0:
153 newval = newval | (oldval & 0xc);
154 break;
155 case 1:
156 newval = (newval << 2) | (oldval & 3);
157 break;
158 default:
159 splx(s);
160 panic("sacpcic_set_power");
161 }
162 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR, newval);
163 splx(s);
164 }
165
166