]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/xscale/ixp425/cambria_fled.c
Merge ^/head r327169 through r327340.
[FreeBSD/FreeBSD.git] / sys / arm / xscale / ixp425 / cambria_fled.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2008 Sam Leffler.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 /*
30  * Cambria Front Panel LED sitting on the I2C bus.
31  */
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
36 #include <sys/bus.h>
37
38 #include <machine/bus.h>
39
40 #include <dev/iicbus/iiconf.h>
41 #include <dev/led/led.h>
42
43 #include "iicbus_if.h"
44
45 #define IIC_M_WR        0       /* write operation */
46 #define LED_ADDR        0xae    /* slave address */
47
48 struct fled_softc {
49         struct cdev     *sc_led;
50 };
51
52 static int
53 fled_probe(device_t dev)
54 {
55         device_set_desc(dev, "Gateworks Cambria Front Panel LED");
56         return 0;
57 }
58
59 static void
60 fled_cb(void *arg, int onoff)
61 {
62         uint8_t data[1];
63         struct iic_msg msgs[1] = {
64              { LED_ADDR, IIC_M_WR, 1, data },
65         };
66         device_t dev = arg;
67
68         data[0] = (onoff == 0);         /* NB: low true */
69         (void) iicbus_transfer(dev, msgs, 1);
70 }
71
72 static int
73 fled_attach(device_t dev)
74 {
75         struct fled_softc *sc = device_get_softc(dev);
76
77         sc->sc_led = led_create(fled_cb, dev, "front");
78
79         fled_cb(dev, 1);                /* Turn on LED */
80
81         return 0;
82 }
83
84 static int
85 fled_detach(device_t dev)
86 {
87         struct fled_softc *sc = device_get_softc(dev);
88
89         if (sc->sc_led != NULL)
90                 led_destroy(sc->sc_led);
91
92         return 0;
93 }
94
95 static device_method_t fled_methods[] = {
96         DEVMETHOD(device_probe,         fled_probe),
97         DEVMETHOD(device_attach,        fled_attach),
98         DEVMETHOD(device_detach,        fled_detach),
99
100         {0, 0},
101 };
102
103 static driver_t fled_driver = {
104         "fled",
105         fled_methods,
106         sizeof(struct fled_softc),
107 };
108 static devclass_t fled_devclass;
109
110 DRIVER_MODULE(fled, iicbus, fled_driver, fled_devclass, 0, 0);
111 MODULE_VERSION(fled, 1);
112 MODULE_DEPEND(fled, iicbus, 1, 1, 1);