cambria_fled.c revision 203752
1139790Simp/*-
2131903Smarcel * Copyright (c) 2008 Sam Leffler.  All rights reserved.
3131903Smarcel *
4131903Smarcel * Redistribution and use in source and binary forms, with or without
5131903Smarcel * modification, are permitted provided that the following conditions
6131903Smarcel * are met:
7131903Smarcel * 1. Redistributions of source code must retain the above copyright
8131903Smarcel *    notice, this list of conditions and the following disclaimer.
9131903Smarcel * 2. Redistributions in binary form must reproduce the above copyright
10131903Smarcel *    notice, this list of conditions and the following disclaimer in the
11131903Smarcel *    documentation and/or other materials provided with the distribution.
12131903Smarcel *
13131903Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14131903Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15131903Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16131903Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17131903Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18131903Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19131903Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20131903Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21131903Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22131903Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23131903Smarcel */
24131903Smarcel
25131903Smarcel#include <sys/cdefs.h>
26131903Smarcel__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/cambria_fled.c 203752 2010-02-10 11:40:18Z rpaulo $");
27131903Smarcel/*
28131903Smarcel * Cambria Front Panel LED sitting on the I2C bus.
29131903Smarcel */
30131903Smarcel#include <sys/param.h>
31131903Smarcel#include <sys/systm.h>
32131903Smarcel#include <sys/kernel.h>
33131903Smarcel#include <sys/module.h>
34131903Smarcel#include <sys/bus.h>
35157448Smarcel
36157448Smarcel#include <machine/bus.h>
37131903Smarcel
38131903Smarcel#include <dev/iicbus/iiconf.h>
39131903Smarcel#include <dev/led/led.h>
40131903Smarcel
41131903Smarcel#include "iicbus_if.h"
42131903Smarcel
43131903Smarcel#define	IIC_M_WR	0	/* write operation */
44131903Smarcel#define	LED_ADDR	0xae	/* slave address */
45131903Smarcel
46131903Smarcelstruct fled_softc {
47131903Smarcel	struct cdev	*sc_led;
48131903Smarcel};
49131903Smarcel
50170473Smarcelstatic int
51170473Smarcelfled_probe(device_t dev)
52170473Smarcel{
53170473Smarcel	device_set_desc(dev, "Gateworks Cambria Front Panel LED");
54170473Smarcel	return 0;
55131903Smarcel}
56131903Smarcel
57131903Smarcelstatic void
58131903Smarcelfled_cb(void *arg, int onoff)
59131903Smarcel{
60	uint8_t data[1];
61	struct iic_msg msgs[1] = {
62	     { LED_ADDR, IIC_M_WR, 1, data },
63	};
64	device_t dev = arg;
65
66	data[0] = (onoff == 0);		/* NB: low true */
67	(void) iicbus_transfer(dev, msgs, 1);
68}
69
70static int
71fled_attach(device_t dev)
72{
73	struct fled_softc *sc = device_get_softc(dev);
74
75	sc->sc_led = led_create(fled_cb, dev, "front");
76
77	led_func(sc, 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