cambria_fled.c revision 205705
1142581Ssimon/*- 2142581Ssimon * Copyright (c) 2008 Sam Leffler. All rights reserved. 3142581Ssimon * 4142581Ssimon * Redistribution and use in source and binary forms, with or without 5142581Ssimon * modification, are permitted provided that the following conditions 6142581Ssimon * are met: 7142581Ssimon * 1. Redistributions of source code must retain the above copyright 8142581Ssimon * notice, this list of conditions and the following disclaimer. 9142581Ssimon * 2. Redistributions in binary form must reproduce the above copyright 10142581Ssimon * notice, this list of conditions and the following disclaimer in the 11142581Ssimon * documentation and/or other materials provided with the distribution. 12142581Ssimon * 13142581Ssimon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14142581Ssimon * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15142581Ssimon * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16142581Ssimon * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17142581Ssimon * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18142581Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19142581Ssimon * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20142581Ssimon * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21142581Ssimon * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22142581Ssimon * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23142581Ssimon */ 24142581Ssimon 25142581Ssimon#include <sys/cdefs.h> 26142581Ssimon__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/cambria_fled.c 205705 2010-03-26 18:49:43Z rpaulo $"); 27152984Sjoel/* 28142581Ssimon * Cambria Front Panel LED sitting on the I2C bus. 29142581Ssimon */ 30142581Ssimon#include <sys/param.h> 31142581Ssimon#include <sys/systm.h> 32142581Ssimon#include <sys/kernel.h> 33142581Ssimon#include <sys/module.h> 34152984Sjoel#include <sys/bus.h> 35152984Sjoel 36152984Sjoel#include <machine/bus.h> 37142581Ssimon 38142581Ssimon#include <dev/iicbus/iiconf.h> 39152984Sjoel#include <dev/led/led.h> 40152984Sjoel 41152984Sjoel#include "iicbus_if.h" 42152984Sjoel 43152984Sjoel#define IIC_M_WR 0 /* write operation */ 44152984Sjoel#define LED_ADDR 0xae /* slave address */ 45152984Sjoel 46152984Sjoelstruct fled_softc { 47142581Ssimon struct cdev *sc_led; 48142581Ssimon}; 49142581Ssimon 50142597Ssimonstatic int 51142597Ssimonfled_probe(device_t dev) 52142597Ssimon{ 53142581Ssimon device_set_desc(dev, "Gateworks Cambria Front Panel LED"); 54142581Ssimon return 0; 55142581Ssimon} 56142581Ssimon 57142581Ssimonstatic void 58142581Ssimonfled_cb(void *arg, int onoff) 59142581Ssimon{ 60142581Ssimon uint8_t data[1]; 61142581Ssimon struct iic_msg msgs[1] = { 62142581Ssimon { LED_ADDR, IIC_M_WR, 1, data }, 63142581Ssimon }; 64142581Ssimon device_t dev = arg; 65142581Ssimon 66142581Ssimon data[0] = (onoff == 0); /* NB: low true */ 67142581Ssimon (void) iicbus_transfer(dev, msgs, 1); 68142581Ssimon} 69142581Ssimon 70142581Ssimonstatic int 71142581Ssimonfled_attach(device_t dev) 72152890Sjoel{ 73152890Sjoel struct fled_softc *sc = device_get_softc(dev); 74267938Sbapt 75 sc->sc_led = led_create(fled_cb, dev, "front"); 76 77 fled_cb(dev, 1); /* Turn on LED */ 78 79 return 0; 80} 81 82static int 83fled_detach(device_t dev) 84{ 85 struct fled_softc *sc = device_get_softc(dev); 86 87 if (sc->sc_led != NULL) 88 led_destroy(sc->sc_led); 89 90 return 0; 91} 92 93static device_method_t fled_methods[] = { 94 DEVMETHOD(device_probe, fled_probe), 95 DEVMETHOD(device_attach, fled_attach), 96 DEVMETHOD(device_detach, fled_detach), 97 98 {0, 0}, 99}; 100 101static driver_t fled_driver = { 102 "fled", 103 fled_methods, 104 sizeof(struct fled_softc), 105}; 106static devclass_t fled_devclass; 107 108DRIVER_MODULE(fled, iicbus, fled_driver, fled_devclass, 0, 0); 109MODULE_VERSION(fled, 1); 110MODULE_DEPEND(fled, iicbus, 1, 1, 1); 111