gpioiic.c (256281) | gpioiic.c (266105) |
---|---|
1/*- 2 * Copyright (c) 2009 Oleksandr Tymoshenko <gonzo@freebsd.org> 3 * Copyright (c) 2010 Luiz Otavio O Souza 4 * 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: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009 Oleksandr Tymoshenko <gonzo@freebsd.org> 3 * Copyright (c) 2010 Luiz Otavio O Souza 4 * 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: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: stable/10/sys/dev/gpio/gpioiic.c 228729 2011-12-20 03:25:11Z adrian $"); | 29__FBSDID("$FreeBSD: stable/10/sys/dev/gpio/gpioiic.c 266105 2014-05-15 01:27:53Z loos $"); |
30 | 30 |
31#include "opt_platform.h" 32 |
|
31#include <sys/param.h> 32#include <sys/systm.h> | 33#include <sys/param.h> 34#include <sys/systm.h> |
33#include <sys/bio.h> | |
34#include <sys/bus.h> 35#include <sys/conf.h> 36#include <sys/kernel.h> | 35#include <sys/bus.h> 36#include <sys/conf.h> 37#include <sys/kernel.h> |
37#include <sys/kthread.h> 38#include <sys/lock.h> 39#include <sys/malloc.h> | |
40#include <sys/module.h> | 38#include <sys/module.h> |
41#include <sys/mutex.h> | |
42 43#include <sys/gpio.h> 44#include "gpiobus_if.h" 45 | 39 40#include <sys/gpio.h> 41#include "gpiobus_if.h" 42 |
43#ifdef FDT 44#include <dev/ofw/ofw_bus.h> 45#include <dev/ofw/ofw_bus_subr.h> 46#include <dev/fdt/fdt_common.h> 47#endif 48 |
|
46#include <dev/iicbus/iiconf.h> 47#include <dev/iicbus/iicbus.h> 48 49#include "iicbb_if.h" 50 51#define SCL_PIN_DEFAULT 0 /* default index of SCL pin on gpiobus */ 52#define SDA_PIN_DEFAULT 1 53 54struct gpioiic_softc 55{ 56 device_t sc_dev; 57 device_t sc_busdev; | 49#include <dev/iicbus/iiconf.h> 50#include <dev/iicbus/iicbus.h> 51 52#include "iicbb_if.h" 53 54#define SCL_PIN_DEFAULT 0 /* default index of SCL pin on gpiobus */ 55#define SDA_PIN_DEFAULT 1 56 57struct gpioiic_softc 58{ 59 device_t sc_dev; 60 device_t sc_busdev; |
58 struct cdev *sc_leddev; | |
59 int scl_pin; 60 int sda_pin; 61}; 62 63static int gpioiic_probe(device_t); 64static int gpioiic_attach(device_t); 65 66/* iicbb interface */ --- 5 unchanged lines hidden (view full) --- 72static int gpioiic_getscl(device_t); 73static int gpioiic_reset(device_t, u_char, u_char, u_char *); 74 75 76static int 77gpioiic_probe(device_t dev) 78{ 79 | 61 int scl_pin; 62 int sda_pin; 63}; 64 65static int gpioiic_probe(device_t); 66static int gpioiic_attach(device_t); 67 68/* iicbb interface */ --- 5 unchanged lines hidden (view full) --- 74static int gpioiic_getscl(device_t); 75static int gpioiic_reset(device_t, u_char, u_char, u_char *); 76 77 78static int 79gpioiic_probe(device_t dev) 80{ 81 |
82#ifdef FDT 83 if (!ofw_bus_is_compatible(dev, "gpioiic")) 84 return (ENXIO); 85#endif |
|
80 device_set_desc(dev, "GPIO I2C bit-banging driver"); | 86 device_set_desc(dev, "GPIO I2C bit-banging driver"); |
87 |
|
81 return (0); 82} 83 84static int 85gpioiic_attach(device_t dev) 86{ 87 struct gpioiic_softc *sc = device_get_softc(dev); 88 device_t bitbang; | 88 return (0); 89} 90 91static int 92gpioiic_attach(device_t dev) 93{ 94 struct gpioiic_softc *sc = device_get_softc(dev); 95 device_t bitbang; |
96#ifdef FDT 97 phandle_t node; 98 pcell_t pin; 99#endif |
|
89 90 sc->sc_dev = dev; 91 sc->sc_busdev = device_get_parent(dev); 92 if (resource_int_value(device_get_name(dev), 93 device_get_unit(dev), "scl", &sc->scl_pin)) 94 sc->scl_pin = SCL_PIN_DEFAULT; 95 if (resource_int_value(device_get_name(dev), 96 device_get_unit(dev), "sda", &sc->sda_pin)) 97 sc->sda_pin = SDA_PIN_DEFAULT; 98 | 100 101 sc->sc_dev = dev; 102 sc->sc_busdev = device_get_parent(dev); 103 if (resource_int_value(device_get_name(dev), 104 device_get_unit(dev), "scl", &sc->scl_pin)) 105 sc->scl_pin = SCL_PIN_DEFAULT; 106 if (resource_int_value(device_get_name(dev), 107 device_get_unit(dev), "sda", &sc->sda_pin)) 108 sc->sda_pin = SDA_PIN_DEFAULT; 109 |
110#ifdef FDT 111 if ((node = ofw_bus_get_node(dev)) == -1) 112 return (ENXIO); 113 if (OF_getencprop(node, "scl", &pin, sizeof(pin)) > 0) 114 sc->scl_pin = (int)pin; 115 if (OF_getencprop(node, "sda", &pin, sizeof(pin)) > 0) 116 sc->sda_pin = (int)pin; 117#endif 118 |
|
99 /* add generic bit-banging code */ 100 bitbang = device_add_child(dev, "iicbb", -1); 101 device_probe_and_attach(bitbang); 102 103 return (0); 104} 105 106/* --- 27 unchanged lines hidden (view full) --- 134 GPIOBUS_LOCK_BUS(sc->sc_busdev); 135 GPIOBUS_RELEASE_BUS(sc->sc_busdev, sc->sc_dev); 136 GPIOBUS_UNLOCK_BUS(sc->sc_busdev); 137 break; 138 default: 139 error = EINVAL; 140 } 141 | 119 /* add generic bit-banging code */ 120 bitbang = device_add_child(dev, "iicbb", -1); 121 device_probe_and_attach(bitbang); 122 123 return (0); 124} 125 126/* --- 27 unchanged lines hidden (view full) --- 154 GPIOBUS_LOCK_BUS(sc->sc_busdev); 155 GPIOBUS_RELEASE_BUS(sc->sc_busdev, sc->sc_dev); 156 GPIOBUS_UNLOCK_BUS(sc->sc_busdev); 157 break; 158 default: 159 error = EINVAL; 160 } 161 |
142 return(error); | 162 return (error); |
143} 144 145static void 146gpioiic_setsda(device_t dev, int val) 147{ 148 struct gpioiic_softc *sc = device_get_softc(dev); 149 150 if (val == 0) { --- 58 unchanged lines hidden (view full) --- 209 gpioiic_reset_bus(sc->sc_dev); 210 211 GPIOBUS_RELEASE_BUS(sc->sc_busdev, sc->sc_dev); 212 GPIOBUS_UNLOCK_BUS(sc->sc_busdev); 213 214 return (IIC_ENOADDR); 215} 216 | 163} 164 165static void 166gpioiic_setsda(device_t dev, int val) 167{ 168 struct gpioiic_softc *sc = device_get_softc(dev); 169 170 if (val == 0) { --- 58 unchanged lines hidden (view full) --- 229 gpioiic_reset_bus(sc->sc_dev); 230 231 GPIOBUS_RELEASE_BUS(sc->sc_busdev, sc->sc_dev); 232 GPIOBUS_UNLOCK_BUS(sc->sc_busdev); 233 234 return (IIC_ENOADDR); 235} 236 |
237#ifdef FDT 238static phandle_t 239gpioiic_get_node(device_t bus, device_t dev) 240{ 241 242 /* We only have one child, the iicbb, which needs our own node. */ 243 return (ofw_bus_get_node(bus)); 244} 245#endif 246 |
|
217static devclass_t gpioiic_devclass; 218 219static device_method_t gpioiic_methods[] = { 220 /* Device interface */ 221 DEVMETHOD(device_probe, gpioiic_probe), 222 DEVMETHOD(device_attach, gpioiic_attach), 223 DEVMETHOD(device_detach, bus_generic_detach), 224 225 /* iicbb interface */ 226 DEVMETHOD(iicbb_callback, gpioiic_callback), 227 DEVMETHOD(iicbb_setsda, gpioiic_setsda), 228 DEVMETHOD(iicbb_setscl, gpioiic_setscl), 229 DEVMETHOD(iicbb_getsda, gpioiic_getsda), 230 DEVMETHOD(iicbb_getscl, gpioiic_getscl), 231 DEVMETHOD(iicbb_reset, gpioiic_reset), 232 | 247static devclass_t gpioiic_devclass; 248 249static device_method_t gpioiic_methods[] = { 250 /* Device interface */ 251 DEVMETHOD(device_probe, gpioiic_probe), 252 DEVMETHOD(device_attach, gpioiic_attach), 253 DEVMETHOD(device_detach, bus_generic_detach), 254 255 /* iicbb interface */ 256 DEVMETHOD(iicbb_callback, gpioiic_callback), 257 DEVMETHOD(iicbb_setsda, gpioiic_setsda), 258 DEVMETHOD(iicbb_setscl, gpioiic_setscl), 259 DEVMETHOD(iicbb_getsda, gpioiic_getsda), 260 DEVMETHOD(iicbb_getscl, gpioiic_getscl), 261 DEVMETHOD(iicbb_reset, gpioiic_reset), 262 |
263#ifdef FDT 264 /* OFW bus interface */ 265 DEVMETHOD(ofw_bus_get_node, gpioiic_get_node), 266#endif 267 |
|
233 { 0, 0 } 234}; 235 236static driver_t gpioiic_driver = { 237 "gpioiic", 238 gpioiic_methods, 239 sizeof(struct gpioiic_softc), 240}; 241 242DRIVER_MODULE(gpioiic, gpiobus, gpioiic_driver, gpioiic_devclass, 0, 0); 243DRIVER_MODULE(iicbb, gpioiic, iicbb_driver, iicbb_devclass, 0, 0); 244MODULE_DEPEND(gpioiic, iicbb, IICBB_MINVER, IICBB_PREFVER, IICBB_MAXVER); 245MODULE_DEPEND(gpioiic, gpiobus, 1, 1, 1); | 268 { 0, 0 } 269}; 270 271static driver_t gpioiic_driver = { 272 "gpioiic", 273 gpioiic_methods, 274 sizeof(struct gpioiic_softc), 275}; 276 277DRIVER_MODULE(gpioiic, gpiobus, gpioiic_driver, gpioiic_devclass, 0, 0); 278DRIVER_MODULE(iicbb, gpioiic, iicbb_driver, iicbb_devclass, 0, 0); 279MODULE_DEPEND(gpioiic, iicbb, IICBB_MINVER, IICBB_PREFVER, IICBB_MAXVER); 280MODULE_DEPEND(gpioiic, gpiobus, 1, 1, 1); |