iPXE
Functions | Variables
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. More...
 
struct gpiosalloc_gpios (unsigned int count, size_t priv_len)
 Allocate GPIO controller. More...
 
int gpios_register (struct gpios *gpios)
 Register GPIO controller. More...
 
void gpios_unregister (struct gpios *gpios)
 Unregister GPIO controller. More...
 
struct gpiosgpios_find (unsigned int bus_type, unsigned int location)
 Find GPIO controller. More...
 
static int null_gpio_in (struct gpios *gpios __unused, struct gpio *gpio __unused)
 Get null GPIO input value. More...
 
static void null_gpio_out (struct gpios *gpios __unused, struct gpio *gpio __unused, int active __unused)
 Set null GPIO output value. More...
 
static int null_gpio_config (struct gpios *gpios __unused, struct gpio *gpio __unused, unsigned int config __unused)
 Configure null GPIO pin. More...
 

Variables

struct gpio_operations null_gpio_operations
 Null GPIO operations. More...
 

Detailed Description

General purpose I/O.

Definition in file gpio.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ LIST_HEAD()

static 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 }
struct gpios * gpios
GPIO controller.
Definition: gpio.h:20
unsigned int index
Pin index.
Definition: gpio.h:22
pseudo_bit_t gpio[0x00001]
Definition: arbel.h:30
ring len
Length.
Definition: dwmac.h:231
static unsigned int count
Number of entries.
Definition: dwmac.h:225
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
A GPIO controller.
Definition: gpio.h:37
A GPIO pin.
Definition: gpio.h:18
unsigned int count
Number of GPIOs.
Definition: gpio.h:45
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct gpio * gpio
Individual GPIOs.
Definition: gpio.h:48
void * priv
Driver-private data.
Definition: gpio.h:53

References gpios::count, count, gpio, 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 }
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:78
struct device * dev
Generic device.
Definition: gpio.h:43
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
struct list_head list
List of GPIO controllers.
Definition: gpio.h:41
A GPIO controller.
Definition: gpio.h:37
unsigned int count
Number of GPIOs.
Definition: gpio.h:45
static struct gpios * gpios_get(struct gpios *gpios)
Get reference to GPIO controller.
Definition: gpio.h:95

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 DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:78
struct device * dev
Generic device.
Definition: gpio.h:43
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
struct list_head list
List of GPIO controllers.
Definition: gpio.h:41
A GPIO controller.
Definition: gpio.h:37

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 }
struct device * dev
Generic device.
Definition: gpio.h:43
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
unsigned int location
Location.
Definition: device.h:29
struct list_head list
List of GPIO controllers.
Definition: gpio.h:41
A GPIO controller.
Definition: gpio.h:37
unsigned int bus_type
Bus type.
Definition: device.h:24
struct device_description desc
Device description.
Definition: device.h:82
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

◆ null_gpio_in()

static 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 }

◆ null_gpio_out()

static 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 }

◆ null_gpio_config()

static 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:509

References 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_in(struct gpios *gpios __unused, struct gpio *gpio __unused)
Get null GPIO input value.
Definition: gpio.c:129
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 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.

Referenced by gpios_nullify().