1/*- 2 * Copyright (c) 2010, Andrew Thompson <thompsa@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 25 unchanged lines hidden (view full) --- 34 * times out and not write our latch. To get around this we grab the iicbus and 35 * then do our own bit banging. This is a comprimise to changing all the iicbb 36 * device methods to allow a flag to be passed down and is similir to how Linux 37 * does it. 38 * 39 */ 40 41#include <sys/cdefs.h> |
42__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/cambria_gpio.c 277996 2015-01-31 19:32:14Z loos $"); |
43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/bus.h> 47 48#include <sys/kernel.h> 49#include <sys/module.h> 50#include <sys/rman.h> 51#include <sys/lock.h> 52#include <sys/mutex.h> 53#include <sys/gpio.h> 54 55#include <arm/xscale/ixp425/ixp425reg.h> 56#include <arm/xscale/ixp425/ixp425var.h> 57#include <arm/xscale/ixp425/ixdp425reg.h> 58 |
59#include <dev/gpio/gpiobusvar.h> |
60#include <dev/iicbus/iiconf.h> 61#include <dev/iicbus/iicbus.h> 62 63#include "iicbb_if.h" 64#include "gpio_if.h" 65 66#define IIC_M_WR 0 /* write operation */ 67#define PLD_ADDR 0xac /* slave address */ --- 7 unchanged lines hidden (view full) --- 75 76#define GPIO_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 77#define GPIO_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 78#define GPIO_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED) 79 80#define GPIO_PINS 5 81struct cambria_gpio_softc { 82 device_t sc_dev; |
83 device_t sc_busdev; |
84 bus_space_tag_t sc_iot; 85 bus_space_handle_t sc_gpio_ioh; 86 struct mtx sc_mtx; 87 struct gpio_pin sc_pins[GPIO_PINS]; 88 uint8_t sc_latch; 89 uint8_t sc_val; 90}; 91 --- 24 unchanged lines hidden (view full) --- 116 */ 117static int cambria_gpio_probe(device_t dev); 118static int cambria_gpio_attach(device_t dev); 119static int cambria_gpio_detach(device_t dev); 120 121/* 122 * GPIO interface 123 */ |
124static device_t cambria_gpio_get_bus(device_t); |
125static int cambria_gpio_pin_max(device_t dev, int *maxpin); 126static int cambria_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps); 127static int cambria_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t 128 *flags); 129static int cambria_gpio_pin_getname(device_t dev, uint32_t pin, char *name); 130static int cambria_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags); 131static int cambria_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value); 132static int cambria_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val); --- 126 unchanged lines hidden (view full) --- 259 i2c_sendbyte(sc, sc->sc_latch); 260 i2c_sendstop(sc); 261 262 iicbus_release_bus(device_get_parent(dev), dev); 263 264 return (0); 265} 266 |
267static device_t 268cambria_gpio_get_bus(device_t dev) 269{ 270 struct cambria_gpio_softc *sc; 271 272 sc = device_get_softc(dev); 273 274 return (sc->sc_busdev); 275} 276 |
277static int 278cambria_gpio_pin_max(device_t dev, int *maxpin) 279{ 280 281 *maxpin = GPIO_PINS - 1; 282 return (0); 283} 284 --- 161 unchanged lines hidden (view full) --- 446 447 strncpy(sc->sc_pins[pin].gp_name, p->name, GPIOMAXNAME); 448 sc->sc_pins[pin].gp_pin = pin; 449 sc->sc_pins[pin].gp_caps = GPIO_PIN_INPUT|GPIO_PIN_OUTPUT; 450 sc->sc_pins[pin].gp_flags = 0; 451 cambria_gpio_pin_setflags(dev, pin, p->flags); 452 } 453 |
454 sc->sc_busdev = gpiobus_attach_bus(dev); 455 if (sc->sc_busdev == NULL) { 456 mtx_destroy(&sc->sc_mtx); 457 return (ENXIO); 458 } |
459 |
460 return (0); |
461} 462 463static int 464cambria_gpio_detach(device_t dev) 465{ 466 struct cambria_gpio_softc *sc = device_get_softc(dev); 467 468 KASSERT(mtx_initialized(&sc->sc_mtx), ("gpio mutex not initialized")); 469 |
470 gpiobus_detach_bus(dev); |
471 mtx_destroy(&sc->sc_mtx); 472 473 return(0); 474} 475 476static device_method_t cambria_gpio_methods[] = { 477 DEVMETHOD(device_probe, cambria_gpio_probe), 478 DEVMETHOD(device_attach, cambria_gpio_attach), 479 DEVMETHOD(device_detach, cambria_gpio_detach), 480 481 /* GPIO protocol */ |
482 DEVMETHOD(gpio_get_bus, cambria_gpio_get_bus), |
483 DEVMETHOD(gpio_pin_max, cambria_gpio_pin_max), 484 DEVMETHOD(gpio_pin_getname, cambria_gpio_pin_getname), 485 DEVMETHOD(gpio_pin_getflags, cambria_gpio_pin_getflags), 486 DEVMETHOD(gpio_pin_getcaps, cambria_gpio_pin_getcaps), 487 DEVMETHOD(gpio_pin_setflags, cambria_gpio_pin_setflags), 488 DEVMETHOD(gpio_pin_get, cambria_gpio_pin_get), 489 DEVMETHOD(gpio_pin_set, cambria_gpio_pin_set), 490 DEVMETHOD(gpio_pin_toggle, cambria_gpio_pin_toggle), --- 13 unchanged lines hidden --- |