iPXE
gpio.c File Reference

General purpose I/O. More...

#include <stdlib.h>
#include <errno.h>
#include <ipxe/gpio.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static LIST_HEAD (all_gpios)
 List of GPIO controllers.
struct gpiosalloc_gpios (unsigned int count, size_t priv_len)
 Allocate GPIO controller.
int gpios_register (struct gpios *gpios)
 Register GPIO controller.
void gpios_unregister (struct gpios *gpios)
 Unregister GPIO controller.
struct gpiosgpios_find (unsigned int bus_type, unsigned int location)
 Find GPIO controller.
static int null_gpio_in (struct gpios *gpios __unused, struct gpio *gpio __unused)
 Get null GPIO input value.
static void null_gpio_out (struct gpios *gpios __unused, struct gpio *gpio __unused, int active __unused)
 Set null GPIO output value.
static int null_gpio_config (struct gpios *gpios __unused, struct gpio *gpio __unused, unsigned int config __unused)
 Configure null GPIO pin.

Variables

struct gpio_operations null_gpio_operations
 Null GPIO operations.

Detailed Description

General purpose I/O.

Definition in file gpio.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ LIST_HEAD()

LIST_HEAD ( all_gpios )
static

List of GPIO controllers.

◆ alloc_gpios()

struct gpios * alloc_gpios ( unsigned int count,
size_t priv_len )

Allocate GPIO controller.

Parameters
countNumber of GPIO pins
priv_lenSize of driver-private data
Return values
gpiosGPIO controller, or NULL

Definition at line 46 of file gpio.c.

46 {
47 struct gpios *gpios;
48 struct gpio *gpio;
49 size_t len;
50 unsigned int i;
51
52 /* Allocate and initialise structure */
53 len = ( sizeof ( *gpios ) + ( count * sizeof ( *gpio ) ) + priv_len );
54 gpios = zalloc ( len );
55 if ( ! gpios )
56 return NULL;
57 gpios->count = count;
58 gpios->gpio = ( ( ( void * ) gpios ) + sizeof ( *gpios ) );
59 gpios->priv = ( ( ( void * ) gpios ) + sizeof ( *gpios ) +
60 ( count * sizeof ( *gpio ) ) );
61
62 /* Initialise GPIO pins */
63 for ( i = 0 ; i < count ; i++ ) {
64 gpio = &gpios->gpio[i];
65 gpio->gpios = gpios;
66 gpio->index = i;
67 }
68
69 return gpios;
70}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
ring len
Length.
Definition dwmac.h:226
static unsigned int count
Number of entries.
Definition dwmac.h:220
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
A GPIO pin.
Definition gpio.h:18
struct gpios * gpios
GPIO controller.
Definition gpio.h:20
unsigned int index
Pin index.
Definition gpio.h:22
A GPIO controller.
Definition gpio.h:37
void * priv
Driver-private data.
Definition gpio.h:53
unsigned int count
Number of GPIOs.
Definition gpio.h:45
struct gpio * gpio
Individual GPIOs.
Definition gpio.h:48

References count, gpios::count, gpios::gpio, gpio::gpios, gpio::index, len, NULL, gpios::priv, and zalloc().

Referenced by dwgpio_probe().

◆ gpios_register()

int gpios_register ( struct gpios * gpios)

Register GPIO controller.

Parameters
gpiosGPIO controller
Return values
rcReturn status code

Definition at line 78 of file gpio.c.

78 {
79
80 /* Add to list of GPIO controllers */
81 gpios_get ( gpios );
82 list_add_tail ( &gpios->list, &all_gpios );
83 DBGC ( gpios, "GPIO %s registered with %d GPIOs\n",
84 gpios->dev->name, gpios->count );
85
86 return 0;
87}
static struct gpios * gpios_get(struct gpios *gpios)
Get reference to GPIO controller.
Definition gpio.h:95
#define DBGC(...)
Definition compiler.h:505
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition list.h:94
char name[40]
Name.
Definition device.h:79
struct device * dev
Generic device.
Definition gpio.h:43
struct list_head list
List of GPIO controllers.
Definition gpio.h:41

References gpios::count, DBGC, gpios::dev, gpios_get(), gpios::list, list_add_tail, and device::name.

Referenced by dwgpio_probe().

◆ gpios_unregister()

void gpios_unregister ( struct gpios * gpios)

Unregister GPIO controller.

Parameters
gpiosGPIO controller

Definition at line 94 of file gpio.c.

94 {
95
96 /* Remove from list of GPIO controllers */
97 DBGC ( gpios, "GPIO %s unregistered\n", gpios->dev->name );
98 list_del ( &gpios->list );
99 gpios_put ( gpios );
100}
static void gpios_put(struct gpios *gpios)
Drop reference to GPIO controller.
Definition gpio.h:106
#define list_del(list)
Delete an entry from a list.
Definition list.h:120

References DBGC, gpios::dev, gpios_put(), gpios::list, list_del, and device::name.

Referenced by dwgpio_probe(), and dwgpio_remove().

◆ gpios_find()

struct gpios * gpios_find ( unsigned int bus_type,
unsigned int location )

Find GPIO controller.

Parameters
bus_typeBus type
locationBus location
Return values
gpiosGPIO controller, or NULL

Definition at line 109 of file gpio.c.

109 {
110 struct gpios *gpios;
111
112 /* Scan through list of registered GPIO controllers */
113 list_for_each_entry ( gpios, &all_gpios, list ) {
114 if ( ( gpios->dev->desc.bus_type == bus_type ) &&
115 ( gpios->dev->desc.location == location ) )
116 return gpios;
117 }
118
119 return NULL;
120}
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition list.h:432
unsigned int bus_type
Bus type.
Definition device.h:25
unsigned int location
Location.
Definition device.h:30
struct device_description desc
Device description.
Definition device.h:83

References device_description::bus_type, device::desc, gpios::dev, gpios::list, list_for_each_entry, device_description::location, and NULL.

◆ null_gpio_in()

int null_gpio_in ( struct gpios *gpios __unused,
struct gpio *gpio __unused )
static

Get null GPIO input value.

Parameters
gpiosGPIO controller
gpioGPIO pin
Return values
activePin is in the active state

Definition at line 129 of file gpio.c.

130 {
131 return 0;
132}

References __unused.

◆ null_gpio_out()

void null_gpio_out ( struct gpios *gpios __unused,
struct gpio *gpio __unused,
int active __unused )
static

Set null GPIO output value.

Parameters
gpiosGPIO controller
gpioGPIO pin
activeSet pin to active state

Definition at line 141 of file gpio.c.

142 {
143 /* Nothing to do */
144}

References __unused.

◆ null_gpio_config()

int null_gpio_config ( struct gpios *gpios __unused,
struct gpio *gpio __unused,
unsigned int config __unused )
static

Configure null GPIO pin.

Parameters
gpiosGPIO controller
gpioGPIO pin
configConfiguration
Return values
rcReturn status code

Definition at line 154 of file gpio.c.

156 {
157 return -ENODEV;
158}
#define ENODEV
No such device.
Definition errno.h:510

References __unused, and ENODEV.

Variable Documentation

◆ null_gpio_operations

struct gpio_operations null_gpio_operations
Initial value:
= {
.in = null_gpio_in,
.out = null_gpio_out,
.config = null_gpio_config,
}
static int null_gpio_config(struct gpios *gpios __unused, struct gpio *gpio __unused, unsigned int config __unused)
Configure null GPIO pin.
Definition gpio.c:154
static int null_gpio_in(struct gpios *gpios __unused, struct gpio *gpio __unused)
Get null GPIO input value.
Definition gpio.c:129
static void null_gpio_out(struct gpios *gpios __unused, struct gpio *gpio __unused, int active __unused)
Set null GPIO output value.
Definition gpio.c:141

Null GPIO operations.

Definition at line 161 of file gpio.c.

161 {
162 .in = null_gpio_in,
163 .out = null_gpio_out,
164 .config = null_gpio_config,
165};

Referenced by gpios_nullify().