No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hpcarm / dev / j720pcic.c
blob7175f1291734db96bdfeb482eb3591643f844f5d
1 /* $NetBSD: j720pcic.c,v 1.5 2008/04/28 20:23:21 martin Exp $ */
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by IWAMOTO Toshihiro.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 /* Jornada 720 PCMCIA support. */
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: j720pcic.c,v 1.5 2008/04/28 20:23:21 martin Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/types.h>
40 #include <sys/conf.h>
41 #include <sys/file.h>
42 #include <sys/device.h>
43 #include <sys/kernel.h>
44 #include <sys/kthread.h>
45 #include <sys/malloc.h>
47 #include <machine/bus.h>
48 #include <machine/platid.h>
49 #include <machine/platid_mask.h>
51 #include <dev/pcmcia/pcmciachip.h>
52 #include <dev/pcmcia/pcmciavar.h>
54 #include <arm/sa11x0/sa11x0_reg.h>
55 #include <arm/sa11x0/sa11x0_var.h>
56 #include <arm/sa11x0/sa1111_reg.h>
57 #include <arm/sa11x0/sa1111_var.h>
58 #include <arm/sa11x0/sa11x1_pcicreg.h>
59 #include <arm/sa11x0/sa11xx_pcicvar.h>
60 #include <arm/sa11x0/sa11x1_pcicvar.h>
62 #include "sacpcic.h"
64 static int sacpcic_match(device_t, cfdata_t, void *);
65 static void sacpcic_attach(device_t, device_t, void *);
67 static void j720_socket_setup(struct sapcic_socket *);
68 static void j720_set_power(struct sapcic_socket *, int);
70 static struct sapcic_tag j720_sacpcic_functions = {
71 sacpcic_read,
72 sacpcic_write,
73 j720_set_power,
74 sacpcic_clear_intr,
75 sacpcic_intr_establish,
76 sacpcic_intr_disestablish
79 static int j720_power_capability[] = {
80 SAPCIC_POWER_5V | SAPCIC_POWER_3V, SAPCIC_POWER_3V
83 static struct platid_data sacpcic_platid_table[] = {
84 { &platid_mask_MACH_HP_JORNADA_7XX, j720_power_capability },
85 { NULL, NULL }
88 CFATTACH_DECL_NEW(sacpcic, sizeof(struct sacpcic_softc),
89 sacpcic_match, sacpcic_attach, NULL, NULL);
92 static int
93 sacpcic_match(device_t parent, cfdata_t cf, void *aux)
96 return 1;
99 static void
100 sacpcic_attach(device_t parent, device_t self, void *aux)
103 sacpcic_attach_common(device_private(parent),
104 device_private(self), aux, j720_socket_setup);
107 static void
108 j720_socket_setup(struct sapcic_socket *sp)
110 int *ip;
111 struct platid_data *p;
112 int socket = sp->socket;
114 p = platid_search_data(&platid, sacpcic_platid_table);
116 if (p == NULL) {
117 sp->power_capability = SAPCIC_POWER_5V;
118 } else {
119 ip = (int *)p->data;
120 sp->power_capability = ip[socket];
123 sp->pcictag = &j720_sacpcic_functions;
126 static void
127 j720_set_power(struct sapcic_socket *so, int arg)
129 int newval, oldval, s;
130 struct sacc_softc *sc = so->pcictag_cookie;
132 /* XXX this isn't well confirmed. DANGER DANGER */
133 switch (arg) {
134 case SAPCIC_POWER_OFF:
135 newval = 0;
136 break;
137 case SAPCIC_POWER_3V:
138 newval = 2;
139 break;
140 case SAPCIC_POWER_5V:
141 newval = 1;
142 break;
143 default:
144 panic("j720_set_power: bogus arg (%d)", arg);
147 s = splbio();
148 oldval = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR);
150 switch (so->socket) {
151 case 0:
152 newval = newval | (oldval & 0xc);
153 break;
154 case 1:
155 newval = (newval << 2) | (oldval & 3);
156 break;
157 default:
158 splx(s);
159 panic("j720_set_power: bogus socket (%d)", so->socket);
161 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR, newval);
162 splx(s);