1*7433666eSthorpej /* $NetBSD: lubbock_pcic.c,v 1.8 2023/12/20 13:55:18 thorpej Exp $ */
2eab266e6Sbsh
3eab266e6Sbsh /*-
4eab266e6Sbsh * Copyright (c) 2001 The NetBSD Foundation, Inc.
5eab266e6Sbsh * All rights reserved.
6eab266e6Sbsh *
7eab266e6Sbsh * This code is derived from software contributed to The NetBSD Foundation
8eab266e6Sbsh * by IWAMOTO Toshihiro.
9eab266e6Sbsh *
10eab266e6Sbsh * Redistribution and use in source and binary forms, with or without
11eab266e6Sbsh * modification, are permitted provided that the following conditions
12eab266e6Sbsh * are met:
13eab266e6Sbsh * 1. Redistributions of source code must retain the above copyright
14eab266e6Sbsh * notice, this list of conditions and the following disclaimer.
15eab266e6Sbsh * 2. Redistributions in binary form must reproduce the above copyright
16eab266e6Sbsh * notice, this list of conditions and the following disclaimer in the
17eab266e6Sbsh * documentation and/or other materials provided with the distribution.
18eab266e6Sbsh *
19eab266e6Sbsh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20eab266e6Sbsh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21eab266e6Sbsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22eab266e6Sbsh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23eab266e6Sbsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24eab266e6Sbsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25eab266e6Sbsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26eab266e6Sbsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27eab266e6Sbsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28eab266e6Sbsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29eab266e6Sbsh * POSSIBILITY OF SUCH DAMAGE.
30eab266e6Sbsh */
31eab266e6Sbsh
32eab266e6Sbsh #include <sys/cdefs.h>
33*7433666eSthorpej __KERNEL_RCSID(0, "$NetBSD: lubbock_pcic.c,v 1.8 2023/12/20 13:55:18 thorpej Exp $");
34eab266e6Sbsh
35eab266e6Sbsh #include <sys/param.h>
36eab266e6Sbsh #include <sys/systm.h>
37eab266e6Sbsh #include <sys/types.h>
38eab266e6Sbsh #include <sys/conf.h>
39eab266e6Sbsh #include <sys/file.h>
40eab266e6Sbsh #include <sys/device.h>
41eab266e6Sbsh #include <sys/kernel.h>
42eab266e6Sbsh #include <sys/kthread.h>
43eab266e6Sbsh
44fea15f47Sdyoung #include <sys/bus.h>
45eab266e6Sbsh
46eab266e6Sbsh #include <dev/pcmcia/pcmciachip.h>
47eab266e6Sbsh #include <dev/pcmcia/pcmciavar.h>
48eab266e6Sbsh #include <arm/sa11x0/sa11x0_reg.h>
49eab266e6Sbsh #include <arm/sa11x0/sa11x0_var.h>
50eab266e6Sbsh #include <arm/sa11x0/sa1111_reg.h>
51eab266e6Sbsh #include <arm/sa11x0/sa1111_var.h>
52eab266e6Sbsh #include <arm/sa11x0/sa11x1_pcicreg.h>
53eab266e6Sbsh #include <arm/sa11x0/sa11xx_pcicvar.h>
54eab266e6Sbsh #include <arm/sa11x0/sa11x1_pcicvar.h>
55eab266e6Sbsh
56eab266e6Sbsh #include <evbarm/lubbock/lubbock_reg.h>
57eab266e6Sbsh #include <evbarm/lubbock/lubbock_var.h>
58eab266e6Sbsh
594c494f76Srjs static int sacpcic_match(device_t, cfdata_t, void *);
604c494f76Srjs static void sacpcic_attach(device_t, device_t, void *);
61eab266e6Sbsh static void lubbock_set_power(struct sapcic_socket *so, int arg);
62eab266e6Sbsh static void lubbock_socket_setup(struct sapcic_socket *sp);
63eab266e6Sbsh
64eab266e6Sbsh static struct sapcic_tag lubbock_sacpcic_functions = {
65eab266e6Sbsh sacpcic_read,
66eab266e6Sbsh sacpcic_write,
67eab266e6Sbsh lubbock_set_power,
68eab266e6Sbsh sacpcic_clear_intr,
69eab266e6Sbsh sacpcic_intr_establish,
70eab266e6Sbsh sacpcic_intr_disestablish
71eab266e6Sbsh };
72eab266e6Sbsh
734c494f76Srjs CFATTACH_DECL_NEW(sacpcic, sizeof(struct sacpcic_softc),
74eab266e6Sbsh sacpcic_match, sacpcic_attach, NULL, NULL);
75eab266e6Sbsh
76eab266e6Sbsh static int
sacpcic_match(device_t parent,cfdata_t cf,void * aux)774c494f76Srjs sacpcic_match(device_t parent, cfdata_t cf, void *aux)
78eab266e6Sbsh {
79eab266e6Sbsh return (1);
80eab266e6Sbsh }
81eab266e6Sbsh
82eab266e6Sbsh static void
lubbock_socket_setup(struct sapcic_socket * sp)83eab266e6Sbsh lubbock_socket_setup(struct sapcic_socket *sp)
84eab266e6Sbsh {
85eab266e6Sbsh sp->power_capability = SAPCIC_POWER_5V | SAPCIC_POWER_3V;
86eab266e6Sbsh sp->pcictag = &lubbock_sacpcic_functions;
87eab266e6Sbsh }
88eab266e6Sbsh
89eab266e6Sbsh static void
sacpcic_attach(device_t parent,device_t self,void * aux)904c494f76Srjs sacpcic_attach(device_t parent, device_t self, void *aux)
91eab266e6Sbsh {
92622048aaSbsh struct sacpcic_softc *sc = device_private(self);
93622048aaSbsh
94622048aaSbsh sc->sc_pc.sc_dev = self;
954c494f76Srjs sacpcic_attach_common(device_private(parent),
96622048aaSbsh sc, aux, lubbock_socket_setup);
97eab266e6Sbsh }
98eab266e6Sbsh
99eab266e6Sbsh
100eab266e6Sbsh static void
lubbock_set_power(struct sapcic_socket * so,int arg)101eab266e6Sbsh lubbock_set_power(struct sapcic_socket *so, int arg)
102eab266e6Sbsh {
103eab266e6Sbsh struct sacc_softc *sc = so->pcictag_cookie;
1044c494f76Srjs struct obio_softc *bsc = device_private(device_parent(sc->sc_dev));
105eab266e6Sbsh int s;
106eab266e6Sbsh uint16_t tmp;
107eab266e6Sbsh
108eab266e6Sbsh static const uint8_t vval_socket0[] = {
109eab266e6Sbsh /* for socket0 (pcmcia) */
110eab266e6Sbsh 0x00, /* OFF */
111eab266e6Sbsh 0x08, /* 3.3V */
112eab266e6Sbsh 0x05, /* 5V */
113eab266e6Sbsh };
114eab266e6Sbsh static const uint16_t vval_socket1[] = {
115eab266e6Sbsh /* for socket1 (CF) */
116eab266e6Sbsh 0x0000, /* OFF */
117eab266e6Sbsh 0x8000, /* 3.3V */
118eab266e6Sbsh 0x4000, /* 5V */
119eab266e6Sbsh };
120eab266e6Sbsh
121eab266e6Sbsh if( arg < 0 || SAPCIC_POWER_5V < arg )
122eab266e6Sbsh panic("sacpcic_set_power: bogus arg\n");
123eab266e6Sbsh
124eab266e6Sbsh switch( so->socket ){
125eab266e6Sbsh case 0:
126eab266e6Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR,
127eab266e6Sbsh vval_socket0[arg]);
128eab266e6Sbsh break;
129eab266e6Sbsh case 1:
130eab266e6Sbsh s = splhigh();
131eab266e6Sbsh tmp = bus_space_read_2(bsc->sc_iot, bsc->sc_obioreg_ioh,
132eab266e6Sbsh LUBBOCK_MISCWR);
133eab266e6Sbsh bus_space_write_2(bsc->sc_iot, bsc->sc_obioreg_ioh,
134eab266e6Sbsh LUBBOCK_MISCWR, (tmp & 0x3fff) | vval_socket1[arg] );
135eab266e6Sbsh splx(s);
136eab266e6Sbsh break;
137eab266e6Sbsh default:
1384c494f76Srjs aprint_normal("unknown socket number: %d\n", so->socket);
139eab266e6Sbsh }
140eab266e6Sbsh }
141