Deleted Added
sdiff udiff text old ( 277968 ) new ( 277996 )
full compact
1/*-
2 * Copyright (c) 2013 Ruslan Bukin <br@bsdpad.com>
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

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

25 */
26
27/*
28 * Vybrid Family General-Purpose Input/Output (GPIO)
29 * Chapter 7, Vybrid Reference Manual, Rev. 5, 07/2013
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/arm/freescale/vybrid/vf_gpio.c 277968 2015-01-31 12:17:07Z loos $");
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/bus.h>
38#include <sys/kernel.h>
39#include <sys/module.h>
40#include <sys/malloc.h>
41#include <sys/rman.h>
42#include <sys/timeet.h>
43#include <sys/timetc.h>
44#include <sys/watchdog.h>
45#include <sys/mutex.h>
46#include <sys/gpio.h>
47
48#include <dev/fdt/fdt_common.h>
49#include <dev/ofw/openfirm.h>
50#include <dev/ofw/ofw_bus.h>
51#include <dev/ofw/ofw_bus_subr.h>
52
53#include <machine/bus.h>
54#include <machine/fdt.h>
55#include <machine/cpu.h>
56#include <machine/intr.h>

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

69#define GPIO_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
70#define GPIO_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
71
72#define DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)
73
74/*
75 * GPIO interface
76 */
77static int vf_gpio_pin_max(device_t, int *);
78static int vf_gpio_pin_getcaps(device_t, uint32_t, uint32_t *);
79static int vf_gpio_pin_getname(device_t, uint32_t, char *);
80static int vf_gpio_pin_getflags(device_t, uint32_t, uint32_t *);
81static int vf_gpio_pin_setflags(device_t, uint32_t, uint32_t);
82static int vf_gpio_pin_set(device_t, uint32_t, unsigned int);
83static int vf_gpio_pin_get(device_t, uint32_t, unsigned int *);
84static int vf_gpio_pin_toggle(device_t, uint32_t pin);
85
86struct vf_gpio_softc {
87 struct resource *res[1];
88 bus_space_tag_t bst;
89 bus_space_handle_t bsh;
90
91 struct mtx sc_mtx;
92 int gpio_npins;
93 struct gpio_pin gpio_pins[NGPIO];
94};
95
96struct vf_gpio_softc *gpio_sc;
97
98static struct resource_spec vf_gpio_spec[] = {

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

142 sc->gpio_pins[i].gp_caps = DEFAULT_CAPS;
143 sc->gpio_pins[i].gp_flags =
144 (READ4(sc, GPIO_PDOR(i)) & (1 << (i % 32))) ?
145 GPIO_PIN_OUTPUT: GPIO_PIN_INPUT;
146 snprintf(sc->gpio_pins[i].gp_name, GPIOMAXNAME,
147 "vf_gpio%d.%d", device_get_unit(dev), i);
148 }
149
150 device_add_child(dev, "gpioc", -1);
151 device_add_child(dev, "gpiobus", -1);
152
153 return (bus_generic_attach(dev));
154}
155
156static int
157vf_gpio_pin_max(device_t dev, int *maxpin)
158{
159
160 *maxpin = NGPIO - 1;
161 return (0);
162}
163

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

343 return (0);
344}
345
346static device_method_t vf_gpio_methods[] = {
347 DEVMETHOD(device_probe, vf_gpio_probe),
348 DEVMETHOD(device_attach, vf_gpio_attach),
349
350 /* GPIO protocol */
351 DEVMETHOD(gpio_pin_max, vf_gpio_pin_max),
352 DEVMETHOD(gpio_pin_getname, vf_gpio_pin_getname),
353 DEVMETHOD(gpio_pin_getcaps, vf_gpio_pin_getcaps),
354 DEVMETHOD(gpio_pin_getflags, vf_gpio_pin_getflags),
355 DEVMETHOD(gpio_pin_get, vf_gpio_pin_get),
356 DEVMETHOD(gpio_pin_toggle, vf_gpio_pin_toggle),
357 DEVMETHOD(gpio_pin_setflags, vf_gpio_pin_setflags),
358 DEVMETHOD(gpio_pin_set, vf_gpio_pin_set),

--- 12 unchanged lines hidden ---