obsled.c revision 1.1.4.3 1 1.1.4.3 skrll /* $NetBSD: obsled.c,v 1.1.4.3 2005/04/01 14:27:26 skrll Exp $ */
2 1.1.4.2 skrll
3 1.1.4.2 skrll /*
4 1.1.4.2 skrll * Copyright (c) 2004 Shigeyuki Fukushima.
5 1.1.4.2 skrll * All rights reserved.
6 1.1.4.2 skrll *
7 1.1.4.2 skrll * Redistribution and use in source and binary forms, with or without
8 1.1.4.2 skrll * modification, are permitted provided that the following conditions
9 1.1.4.2 skrll * are met:
10 1.1.4.2 skrll * 1. Redistributions of source code must retain the above copyright
11 1.1.4.2 skrll * notice, this list of conditions and the following disclaimer.
12 1.1.4.2 skrll * 2. Redistributions in binary form must reproduce the above
13 1.1.4.2 skrll * copyright notice, this list of conditions and the following
14 1.1.4.2 skrll * disclaimer in the documentation and/or other materials provided
15 1.1.4.2 skrll * with the distribution.
16 1.1.4.2 skrll * 3. The name of the author may not be used to endorse or promote
17 1.1.4.2 skrll * products derived from this software without specific prior
18 1.1.4.2 skrll * written permission.
19 1.1.4.2 skrll *
20 1.1.4.2 skrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
21 1.1.4.2 skrll * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 1.1.4.2 skrll * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.1.4.2 skrll * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24 1.1.4.2 skrll * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.1.4.2 skrll * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
26 1.1.4.2 skrll * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1.4.2 skrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 1.1.4.2 skrll * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 1.1.4.2 skrll * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 1.1.4.2 skrll * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1.4.2 skrll */
32 1.1.4.2 skrll
33 1.1.4.2 skrll #include <sys/cdefs.h>
34 1.1.4.3 skrll __KERNEL_RCSID(0, "$NetBSD: obsled.c,v 1.1.4.3 2005/04/01 14:27:26 skrll Exp $");
35 1.1.4.2 skrll
36 1.1.4.2 skrll #include <sys/param.h>
37 1.1.4.2 skrll #include <sys/device.h>
38 1.1.4.2 skrll #include <sys/queue.h>
39 1.1.4.2 skrll #include <sys/systm.h>
40 1.1.4.2 skrll
41 1.1.4.3 skrll #include <machine/obs266.h>
42 1.1.4.2 skrll
43 1.1.4.2 skrll #include <powerpc/ibm4xx/dev/gpiovar.h>
44 1.1.4.2 skrll
45 1.1.4.2 skrll struct obsled_softc {
46 1.1.4.2 skrll struct device sc_dev;
47 1.1.4.2 skrll gpio_tag_t sc_tag;
48 1.1.4.2 skrll int sc_addr;
49 1.1.4.2 skrll };
50 1.1.4.2 skrll
51 1.1.4.2 skrll static void obsled_attach(struct device *, struct device *, void *);
52 1.1.4.2 skrll static int obsled_match(struct device *, struct cfdata *, void *);
53 1.1.4.2 skrll
54 1.1.4.2 skrll CFATTACH_DECL(obsled, sizeof(struct obsled_softc),
55 1.1.4.2 skrll obsled_match, obsled_attach, NULL, NULL);
56 1.1.4.2 skrll
57 1.1.4.2 skrll static int
58 1.1.4.2 skrll obsled_match(struct device *parent, struct cfdata *cf, void *aux)
59 1.1.4.2 skrll {
60 1.1.4.2 skrll struct gpio_attach_args *ga = aux;
61 1.1.4.2 skrll
62 1.1.4.2 skrll /* XXX: support only OpenBlockS266 LED */
63 1.1.4.3 skrll if (ga->ga_addr == OBS266_GPIO_LED1)
64 1.1.4.2 skrll return (1);
65 1.1.4.3 skrll else if (ga->ga_addr == OBS266_GPIO_LED2)
66 1.1.4.2 skrll return (1);
67 1.1.4.3 skrll else if (ga->ga_addr == OBS266_GPIO_LED4)
68 1.1.4.2 skrll return (1);
69 1.1.4.2 skrll
70 1.1.4.2 skrll return (0);
71 1.1.4.2 skrll }
72 1.1.4.2 skrll
73 1.1.4.2 skrll static void
74 1.1.4.2 skrll obsled_attach(struct device *parent, struct device *self, void *aux)
75 1.1.4.2 skrll {
76 1.1.4.2 skrll struct obsled_softc *sc = (struct obsled_softc *)self;
77 1.1.4.2 skrll struct gpio_attach_args *ga = aux;
78 1.1.4.2 skrll int led = (1 << sc->sc_dev.dv_unit);
79 1.1.4.2 skrll
80 1.1.4.2 skrll aprint_naive(": OpenBlockS LED%d\n", led);
81 1.1.4.2 skrll aprint_normal(": OpenBlockS LED%d\n", led);
82 1.1.4.2 skrll
83 1.1.4.2 skrll sc->sc_tag = ga->ga_tag;
84 1.1.4.2 skrll sc->sc_addr = ga->ga_addr;
85 1.1.4.2 skrll
86 1.1.4.3 skrll obs266_led_set(OBS266_LED_OFF);
87 1.1.4.2 skrll #if 0
88 1.1.4.2 skrll {
89 1.1.4.2 skrll gpio_tag_t tag = sc->sc_tag;
90 1.1.4.2 skrll (*(tag)->io_or_write)((tag)->cookie, sc->sc_addr, 0);
91 1.1.4.2 skrll }
92 1.1.4.2 skrll #endif
93 1.1.4.2 skrll }
94 1.1.4.2 skrll
95 1.1.4.2 skrll void
96 1.1.4.3 skrll obs266_led_set(int led)
97 1.1.4.2 skrll {
98 1.1.4.2 skrll struct device *dp = NULL;
99 1.1.4.2 skrll struct devicelist *dlp = &alldevs;
100 1.1.4.2 skrll
101 1.1.4.2 skrll for (dp = TAILQ_FIRST(dlp); dp != NULL; dp = TAILQ_NEXT(dp, dv_list)) {
102 1.1.4.2 skrll if (dp->dv_cfdata != NULL
103 1.1.4.2 skrll && strcmp(dp->dv_cfdata->cf_name, "obsled") == 0) {
104 1.1.4.2 skrll struct obsled_softc *sc = (struct obsled_softc *)dp;
105 1.1.4.2 skrll gpio_tag_t tag = sc->sc_tag;
106 1.1.4.2 skrll int bit = (led & (1 << dp->dv_unit)) >> dp->dv_unit;
107 1.1.4.2 skrll (*(tag)->io_or_write)((tag)->cookie,
108 1.1.4.2 skrll sc->sc_addr, (~bit & 1));
109 1.1.4.2 skrll }
110 1.1.4.2 skrll }
111 1.1.4.2 skrll }
112