2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2008 Sam Leffler. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 * Cambria Front Panel LED sitting on the I2C bus.
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
38 #include <machine/bus.h>
40 #include <dev/iicbus/iiconf.h>
41 #include <dev/led/led.h>
43 #include "iicbus_if.h"
45 #define IIC_M_WR 0 /* write operation */
46 #define LED_ADDR 0xae /* slave address */
53 fled_probe(device_t dev)
55 device_set_desc(dev, "Gateworks Cambria Front Panel LED");
60 fled_cb(void *arg, int onoff)
63 struct iic_msg msgs[1] = {
64 { LED_ADDR, IIC_M_WR, 1, data },
68 data[0] = (onoff == 0); /* NB: low true */
69 (void) iicbus_transfer(dev, msgs, 1);
73 fled_attach(device_t dev)
75 struct fled_softc *sc = device_get_softc(dev);
77 sc->sc_led = led_create(fled_cb, dev, "front");
79 fled_cb(dev, 1); /* Turn on LED */
85 fled_detach(device_t dev)
87 struct fled_softc *sc = device_get_softc(dev);
89 if (sc->sc_led != NULL)
90 led_destroy(sc->sc_led);
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),
103 static driver_t fled_driver = {
106 sizeof(struct fled_softc),
108 static devclass_t fled_devclass;
110 DRIVER_MODULE(fled, iicbus, fled_driver, fled_devclass, 0, 0);
111 MODULE_VERSION(fled, 1);
112 MODULE_DEPEND(fled, iicbus, 1, 1, 1);