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