summaryrefslogtreecommitdiff
path: root/sys/arch/hpcarm/dev/nbppcic.c
blob: 6d34183701c1c60e93b3fca0ab2a01b2ac30c73a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*	$NetBSD: nbppcic.c,v 1.1 2011/08/06 03:53:40 kiyohara Exp $ */
/*
 * Copyright (c) 2011 KIYOHARA Takashi
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/param.h>
#include <sys/bus.h>
#include <sys/device.h>
#include <sys/errno.h>

#include <machine/platid.h>
#include <machine/platid_mask.h>

#include <arm/xscale/pxa2x0var.h>
#include <arm/xscale/pxa2x0_gpio.h>
#include <arm/xscale/pxa2x0_pcic.h>

#include <dev/pcmcia/pcmciareg.h>
#include <dev/pcmcia/pcmciavar.h>
#include <dev/pcmcia/pcmciachip.h>


#define HAVE_CARD(r)	(!((r) & GPIO_SET))


static int nbppcic_match(device_t, cfdata_t, void *);
static void nbppcic_attach(device_t, device_t, void *);

static u_int nbppcic_read(struct pxapcic_socket *, int);
static void nbppcic_write(struct pxapcic_socket *, int, u_int);
static void nbppcic_set_power(struct pxapcic_socket *, int);
static void nbppcic_clear_intr(struct pxapcic_socket *);
static void *nbppcic_intr_establish(struct pxapcic_socket *, int,
				    int (*)(void *), void *);
static void nbppcic_intr_disestablish(struct pxapcic_socket *, void *);

static void nbppcic_socket_setup(struct pxapcic_socket *);

CFATTACH_DECL_NEW(nbppcic, sizeof(struct pxapcic_softc),
    nbppcic_match, nbppcic_attach, NULL, NULL);

static struct pxapcic_tag nbppcic_functions = {
	nbppcic_read,
	nbppcic_write,
	nbppcic_set_power,
	nbppcic_clear_intr,
	nbppcic_intr_establish,
	nbppcic_intr_disestablish,
};


static int
nbppcic_match(device_t parent, cfdata_t match, void *aux)
{
	struct pxaip_attach_args *pxa = aux;

	if (strcmp(pxa->pxa_name, match->cf_name) != 0 ||
	    !platid_match(&platid, &platid_mask_MACH_PSIONTEKLOGIX_NETBOOK_PRO))
		return 0;

	return	1;
}

static void
nbppcic_attach(device_t parent, device_t self, void *aux)
{
	struct pxapcic_softc *sc = device_private(self);
	struct pxaip_attach_args *pxa = aux;

	sc->sc_dev = self;
	sc->sc_iot = pxa->pxa_iot;

	sc->sc_nslots = 2;
	sc->sc_irqpin[0] = 71;		/* GPIO 71: PRDY1/~IRQ1 */
	sc->sc_irqcfpin[0] = 73;	/* GPIO 73: PCD1 */
	sc->sc_irqpin[1] = 77;		/* GPIO 77: PRDY2/~IRQ2 */
	sc->sc_irqcfpin[1] = 75;	/* GPIO 75: PCD2 */

	pxapcic_attach_common(sc, &nbppcic_socket_setup);
}

static u_int
nbppcic_read(struct pxapcic_socket *so, int which)
{
	struct pxapcic_softc *sc = so->sc;
	int reg;

	switch (which) {
	case PXAPCIC_CARD_STATUS:
		reg = pxa2x0_gpio_get_function(sc->sc_irqcfpin[so->socket]);
		return (HAVE_CARD(reg) ?
		    PXAPCIC_CARD_VALID : PXAPCIC_CARD_INVALID);

	case PXAPCIC_CARD_READY:
		reg = pxa2x0_gpio_get_function(sc->sc_irqpin[so->socket]);
		return (reg & GPIO_SET) ? 1 : 0;

	default:
		panic("%s: bogus register", __func__);
	}
	/* NOTREACHED */
}

static void
nbppcic_write(struct pxapcic_socket *so, int which, u_int arg)
{

	switch (which) {
	case PXAPCIC_CARD_POWER:
		/* To Be Done: ;-) */
		break;

	case PXAPCIC_CARD_RESET:
	{
		int reset_pin[2] = { 70, 74 };	/* GPIO 70, GPIO 74 */

		pxa2x0_gpio_set_function(reset_pin[so->socket],
		    GPIO_OUT | (arg ? GPIO_CLR : GPIO_SET));
		break;
	}

	default:
		panic("%s: bogus register", __func__);
	}
	/* NOTREACHED */
}

/* ARGSUSED */
static void
nbppcic_set_power(struct pxapcic_socket *so, int arg)
{

	if(arg != PXAPCIC_POWER_OFF && arg != PXAPCIC_POWER_3V)
		panic("%s: bogus arg\n", __func__);
}

/* ARGSUSED */
static void
nbppcic_clear_intr(struct pxapcic_socket *so)
{

	/* nothing to do */
}

static void *
nbppcic_intr_establish(struct pxapcic_socket *so, int level,
    int (* ih_fun)(void *), void *ih_arg)
{

	return pxa2x0_gpio_intr_establish(so->irqpin, IST_EDGE_FALLING,
	    level, ih_fun, ih_arg);
}

/* ARGSUSED */
static void
nbppcic_intr_disestablish(struct pxapcic_socket *so, void *ih)
{

	pxa2x0_gpio_intr_disestablish(ih);
}


static void
nbppcic_socket_setup(struct pxapcic_socket *so)
{

	so->power_capability = PXAPCIC_POWER_3V;
	so->pcictag_cookie = NULL;
	so->pcictag = &nbppcic_functions;
}