xref: /netbsd-src/sys/arch/hpcarm/dev/j720pcic.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*      $NetBSD: j720pcic.c,v 1.5 2008/04/28 20:23:21 martin 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  *
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.
30  */
31 
32 /* Jornada 720 PCMCIA support. */
33 
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: j720pcic.c,v 1.5 2008/04/28 20:23:21 martin Exp $");
36 
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>
46 
47 #include <machine/bus.h>
48 #include <machine/platid.h>
49 #include <machine/platid_mask.h>
50 
51 #include <dev/pcmcia/pcmciachip.h>
52 #include <dev/pcmcia/pcmciavar.h>
53 
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>
61 
62 #include "sacpcic.h"
63 
64 static int	sacpcic_match(struct device *, struct cfdata *, void *);
65 static void	sacpcic_attach(struct device *, struct device *, void *);
66 
67 static void	j720_socket_setup(struct sapcic_socket *);
68 static void	j720_set_power(struct sapcic_socket *, int);
69 
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
77 };
78 
79 static int j720_power_capability[] = {
80 	SAPCIC_POWER_5V | SAPCIC_POWER_3V, SAPCIC_POWER_3V
81 };
82 
83 static struct platid_data sacpcic_platid_table[] = {
84 	{ &platid_mask_MACH_HP_JORNADA_7XX, j720_power_capability },
85 	{ NULL, NULL }
86 };
87 
88 CFATTACH_DECL(sacpcic, sizeof(struct sacpcic_softc),
89     sacpcic_match, sacpcic_attach, NULL, NULL);
90 
91 
92 static int
93 sacpcic_match(struct device *parent, struct cfdata *cf, void *aux)
94 {
95 
96 	return 1;
97 }
98 
99 static void
100 sacpcic_attach(struct device *parent, struct device *self, void *aux)
101 {
102 
103 	sacpcic_attach_common((struct sacc_softc *)parent,
104 	    (struct sacpcic_softc *)self, aux, j720_socket_setup);
105 }
106 
107 static void
108 j720_socket_setup(struct sapcic_socket *sp)
109 {
110 	int *ip;
111 	struct platid_data *p;
112 	int socket = sp->socket;
113 
114 	p = platid_search_data(&platid, sacpcic_platid_table);
115 
116 	if (p == NULL) {
117 		sp->power_capability = SAPCIC_POWER_5V;
118 	} else {
119 		ip = (int *)p->data;
120 		sp->power_capability = ip[socket];
121 	}
122 
123 	sp->pcictag = &j720_sacpcic_functions;
124 }
125 
126 static void
127 j720_set_power(struct sapcic_socket *so, int arg)
128 {
129 	int newval, oldval, s;
130 	struct sacc_softc *sc = so->pcictag_cookie;
131 
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);
145 	}
146 
147 	s = splbio();
148 	oldval = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR);
149 
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);
160 	}
161 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR, newval);
162 	splx(s);
163 }
164