xref: /netbsd-src/sys/arch/evbarm/lubbock/lubbock_pcic.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*      $NetBSD: lubbock_pcic.c,v 1.3 2006/02/23 05:37:47 thorpej 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: lubbock_pcic.c,v 1.3 2006/02/23 05:37:47 thorpej 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 
54 #include <dev/pcmcia/pcmciachip.h>
55 #include <dev/pcmcia/pcmciavar.h>
56 #include <arm/sa11x0/sa11x0_reg.h>
57 #include <arm/sa11x0/sa11x0_var.h>
58 #include <arm/sa11x0/sa1111_reg.h>
59 #include <arm/sa11x0/sa1111_var.h>
60 #include <arm/sa11x0/sa11x1_pcicreg.h>
61 #include <arm/sa11x0/sa11xx_pcicvar.h>
62 #include <arm/sa11x0/sa11x1_pcicvar.h>
63 
64 #include <evbarm/lubbock/lubbock_reg.h>
65 #include <evbarm/lubbock/lubbock_var.h>
66 
67 static	int	sacpcic_match(struct device *, struct cfdata *, void *);
68 static	void	sacpcic_attach(struct device *, struct device *, void *);
69 static	void	lubbock_set_power(struct sapcic_socket *so, int arg);
70 static	void	lubbock_socket_setup(struct sapcic_socket *sp);
71 
72 static struct sapcic_tag lubbock_sacpcic_functions = {
73 	sacpcic_read,
74 	sacpcic_write,
75 	lubbock_set_power,
76 	sacpcic_clear_intr,
77 	sacpcic_intr_establish,
78 	sacpcic_intr_disestablish
79 };
80 
81 CFATTACH_DECL(sacpcic, sizeof(struct sacpcic_softc),
82     sacpcic_match, sacpcic_attach, NULL, NULL);
83 
84 static int
85 sacpcic_match(struct device *parent, struct cfdata *cf, void *aux)
86 {
87 	return (1);
88 }
89 
90 static void
91 lubbock_socket_setup(struct sapcic_socket *sp)
92 {
93 	sp->power_capability = SAPCIC_POWER_5V | SAPCIC_POWER_3V;
94 	sp->pcictag = &lubbock_sacpcic_functions;
95 }
96 
97 static void
98 sacpcic_attach(struct device *parent, struct device *self, void *aux)
99 {
100 	sacpcic_attach_common((struct sacc_softc *)parent,
101 	    (struct sacpcic_softc *)self, aux, lubbock_socket_setup);
102 }
103 
104 
105 static void
106 lubbock_set_power(struct sapcic_socket *so, int arg)
107 {
108 	struct sacc_softc *sc = so->pcictag_cookie;
109 	struct obio_softc *bsc =
110 	    (struct obio_softc *)device_parent(&sc->sc_dev);
111 	int s;
112 	uint16_t tmp;
113 
114 	static const uint8_t vval_socket0[] = {
115 		/* for socket0 (pcmcia) */
116 		0x00,		/* OFF */
117 		0x08,		/* 3.3V */
118 		0x05,		/* 5V */
119 	};
120 	static const uint16_t vval_socket1[] = {
121 		/* for socket1 (CF) */
122 		0x0000,		/* OFF */
123 		0x8000,		/* 3.3V */
124 		0x4000,		/* 5V */
125 	};
126 
127 	if( arg < 0 || SAPCIC_POWER_5V < arg )
128 		panic("sacpcic_set_power: bogus arg\n");
129 
130 	switch( so->socket ){
131 	case 0:
132 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR,
133 				  vval_socket0[arg]);
134 		break;
135 	case 1:
136 		s = splhigh();
137 		tmp = bus_space_read_2(bsc->sc_iot, bsc->sc_obioreg_ioh,
138 		    LUBBOCK_MISCWR);
139 		bus_space_write_2(bsc->sc_iot, bsc->sc_obioreg_ioh,
140 		    LUBBOCK_MISCWR, (tmp & 0x3fff) | vval_socket1[arg] );
141 		splx(s);
142 		break;
143 	default:
144 		printf("unknown socket number: %d\n", so->socket);
145 	}
146 }
147