Deleted Added
full compact
cambria_gpio.c (277882) cambria_gpio.c (277996)
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>
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 277882 2015-01-29 18:08:50Z loos $");
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
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>
59#include <dev/iicbus/iiconf.h>
60#include <dev/iicbus/iicbus.h>
61
62#include "iicbb_if.h"
63#include "gpio_if.h"
64
65#define IIC_M_WR 0 /* write operation */
66#define PLD_ADDR 0xac /* slave address */

--- 7 unchanged lines hidden (view full) ---

74
75#define GPIO_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
76#define GPIO_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
77#define GPIO_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
78
79#define GPIO_PINS 5
80struct cambria_gpio_softc {
81 device_t sc_dev;
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;
82 bus_space_tag_t sc_iot;
83 bus_space_handle_t sc_gpio_ioh;
84 struct mtx sc_mtx;
85 struct gpio_pin sc_pins[GPIO_PINS];
86 uint8_t sc_latch;
87 uint8_t sc_val;
88};
89

--- 24 unchanged lines hidden (view full) ---

114 */
115static int cambria_gpio_probe(device_t dev);
116static int cambria_gpio_attach(device_t dev);
117static int cambria_gpio_detach(device_t dev);
118
119/*
120 * GPIO interface
121 */
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);
122static int cambria_gpio_pin_max(device_t dev, int *maxpin);
123static int cambria_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps);
124static int cambria_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t
125 *flags);
126static int cambria_gpio_pin_getname(device_t dev, uint32_t pin, char *name);
127static int cambria_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags);
128static int cambria_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value);
129static int cambria_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val);

--- 126 unchanged lines hidden (view full) ---

256 i2c_sendbyte(sc, sc->sc_latch);
257 i2c_sendstop(sc);
258
259 iicbus_release_bus(device_get_parent(dev), dev);
260
261 return (0);
262}
263
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
264static int
265cambria_gpio_pin_max(device_t dev, int *maxpin)
266{
267
268 *maxpin = GPIO_PINS - 1;
269 return (0);
270}
271

--- 161 unchanged lines hidden (view full) ---

433
434 strncpy(sc->sc_pins[pin].gp_name, p->name, GPIOMAXNAME);
435 sc->sc_pins[pin].gp_pin = pin;
436 sc->sc_pins[pin].gp_caps = GPIO_PIN_INPUT|GPIO_PIN_OUTPUT;
437 sc->sc_pins[pin].gp_flags = 0;
438 cambria_gpio_pin_setflags(dev, pin, p->flags);
439 }
440
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
441 device_add_child(dev, "gpioc", -1);
442 device_add_child(dev, "gpiobus", -1);
454 sc->sc_busdev = gpiobus_attach_bus(dev);
455 if (sc->sc_busdev == NULL) {
456 mtx_destroy(&sc->sc_mtx);
457 return (ENXIO);
458 }
443
459
444 return (bus_generic_attach(dev));
460 return (0);
445}
446
447static int
448cambria_gpio_detach(device_t dev)
449{
450 struct cambria_gpio_softc *sc = device_get_softc(dev);
451
452 KASSERT(mtx_initialized(&sc->sc_mtx), ("gpio mutex not initialized"));
453
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
454 bus_generic_detach(dev);
455
470 gpiobus_detach_bus(dev);
456 mtx_destroy(&sc->sc_mtx);
457
458 return(0);
459}
460
461static device_method_t cambria_gpio_methods[] = {
462 DEVMETHOD(device_probe, cambria_gpio_probe),
463 DEVMETHOD(device_attach, cambria_gpio_attach),
464 DEVMETHOD(device_detach, cambria_gpio_detach),
465
466 /* GPIO protocol */
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),
467 DEVMETHOD(gpio_pin_max, cambria_gpio_pin_max),
468 DEVMETHOD(gpio_pin_getname, cambria_gpio_pin_getname),
469 DEVMETHOD(gpio_pin_getflags, cambria_gpio_pin_getflags),
470 DEVMETHOD(gpio_pin_getcaps, cambria_gpio_pin_getcaps),
471 DEVMETHOD(gpio_pin_setflags, cambria_gpio_pin_setflags),
472 DEVMETHOD(gpio_pin_get, cambria_gpio_pin_get),
473 DEVMETHOD(gpio_pin_set, cambria_gpio_pin_set),
474 DEVMETHOD(gpio_pin_toggle, cambria_gpio_pin_toggle),

--- 13 unchanged lines hidden ---
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 ---