iPXE
Data Structures | Macros | Functions | Variables
gpio.h File Reference

General purpose I/O. More...

#include <stdint.h>
#include <ipxe/list.h>
#include <ipxe/refcnt.h>
#include <ipxe/device.h>

Go to the source code of this file.

Data Structures

struct  gpio
 A GPIO pin. More...
 
struct  gpios
 A GPIO controller. More...
 
struct  gpio_operations
 GPIO operations. More...
 

Macros

#define GPIO_CFG_ACTIVE_LOW   0x01
 GPIO is active low. More...
 
#define GPIO_CFG_OUTPUT   0x0100
 GPIO is an output. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static struct gpiosgpios_get (struct gpios *gpios)
 Get reference to GPIO controller. More...
 
static void gpios_put (struct gpios *gpios)
 Drop reference to GPIO controller. More...
 
static struct gpiogpio_get (struct gpio *gpio)
 Get reference to GPIO pin. More...
 
static void gpio_put (struct gpio *gpio)
 Drop reference to GPIO ping. More...
 
static void gpios_init (struct gpios *gpios, struct gpio_operations *op)
 Initialise a GPIO controller. More...
 
static void gpios_nullify (struct gpios *gpios)
 Stop using a GPIO controller. More...
 
static int gpio_in (struct gpio *gpio)
 Get current GPIO input value. More...
 
static void gpio_out (struct gpio *gpio, int active)
 Set current GPIO output value. More...
 
static int gpio_config (struct gpio *gpio, unsigned int config)
 Configure GPIO pin. 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...
 

Variables

struct gpio_operations null_gpio_operations
 Null GPIO operations. More...
 

Detailed Description

General purpose I/O.

Definition in file gpio.h.

Macro Definition Documentation

◆ GPIO_CFG_ACTIVE_LOW

#define GPIO_CFG_ACTIVE_LOW   0x01

GPIO is active low.

This bit is chosen to match the devicetree standard usage.

Definition at line 31 of file gpio.h.

◆ GPIO_CFG_OUTPUT

#define GPIO_CFG_OUTPUT   0x0100

GPIO is an output.

Definition at line 34 of file gpio.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ gpios_get()

static struct gpios* gpios_get ( struct gpios gpios)
inlinestatic

Get reference to GPIO controller.

Parameters
gpiosGPIO controller
Return values
gpiosGPIO controller

Definition at line 95 of file gpio.h.

95  {
96  ref_get ( &gpios->refcnt );
97  return gpios;
98 }
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
A GPIO controller.
Definition: gpio.h:37
struct refcnt refcnt
Reference count.
Definition: gpio.h:39

References ref_get, and gpios::refcnt.

Referenced by gpio_get(), and gpios_register().

◆ gpios_put()

static void gpios_put ( struct gpios gpios)
inlinestatic

Drop reference to GPIO controller.

Parameters
gpiosGPIO controller

Definition at line 106 of file gpio.h.

106  {
107  ref_put ( &gpios->refcnt );
108 }
A GPIO controller.
Definition: gpio.h:37
struct refcnt refcnt
Reference count.
Definition: gpio.h:39
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References ref_put, and gpios::refcnt.

Referenced by dwgpio_probe(), dwgpio_remove(), gpio_put(), and gpios_unregister().

◆ gpio_get()

static struct gpio* gpio_get ( struct gpio gpio)
inlinestatic

Get reference to GPIO pin.

Parameters
gpioGPIO pin
Return values
gpioGPIO pin

Definition at line 117 of file gpio.h.

117  {
118  gpios_get ( gpio->gpios );
119  return gpio;
120 }
struct gpios * gpios
GPIO controller.
Definition: gpio.h:20
pseudo_bit_t gpio[0x00001]
Definition: arbel.h:30
A GPIO pin.
Definition: gpio.h:18
static struct gpios * gpios_get(struct gpios *gpios)
Get reference to GPIO controller.
Definition: gpio.h:95

References gpio, gpio::gpios, and gpios_get().

◆ gpio_put()

static void gpio_put ( struct gpio gpio)
inlinestatic

Drop reference to GPIO ping.

Parameters
gpioGPIO pin

Definition at line 128 of file gpio.h.

128  {
129  gpios_put ( gpio->gpios );
130 }
struct gpios * gpios
GPIO controller.
Definition: gpio.h:20
static void gpios_put(struct gpios *gpios)
Drop reference to GPIO controller.
Definition: gpio.h:106
A GPIO pin.
Definition: gpio.h:18

References gpio::gpios, and gpios_put().

◆ gpios_init()

static void gpios_init ( struct gpios gpios,
struct gpio_operations op 
)
inlinestatic

Initialise a GPIO controller.

Parameters
gpiosGPIO controller
opGPIO operations

Definition at line 139 of file gpio.h.

139  {
140  gpios->op = op;
141 }
struct gpio_operations * op
GPIO operations.
Definition: gpio.h:50
A GPIO controller.
Definition: gpio.h:37
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327

References gpios::op, and op.

Referenced by dwgpio_probe().

◆ gpios_nullify()

static void gpios_nullify ( struct gpios gpios)
inlinestatic

Stop using a GPIO controller.

Parameters
gpiosGPIO controller

Drivers should call this method immediately before the final call to gpios_put().

Definition at line 152 of file gpio.h.

152  {
154 }
struct gpio_operations * op
GPIO operations.
Definition: gpio.h:50
A GPIO controller.
Definition: gpio.h:37
struct gpio_operations null_gpio_operations
Null GPIO operations.
Definition: gpio.c:161

References null_gpio_operations, and gpios::op.

Referenced by dwgpio_probe(), and dwgpio_remove().

◆ gpio_in()

static int gpio_in ( struct gpio gpio)
inlinestatic

Get current GPIO input value.

Parameters
gpioGPIO pin
Return values
activePin is in the active state

Definition at line 162 of file gpio.h.

162  {
163  struct gpios *gpios = gpio->gpios;
164 
165  return gpios->op->in ( gpios, gpio );
166 }
struct gpios * gpios
GPIO controller.
Definition: gpio.h:20
struct gpio_operations * op
GPIO operations.
Definition: gpio.h:50
int(* in)(struct gpios *gpios, struct gpio *gpio)
Get current GPIO input value.
Definition: gpio.h:65
A GPIO controller.
Definition: gpio.h:37
A GPIO pin.
Definition: gpio.h:18

References gpio::gpios, gpio_operations::in, and gpios::op.

◆ gpio_out()

static void gpio_out ( struct gpio gpio,
int  active 
)
inlinestatic

Set current GPIO output value.

Parameters
gpioGPIO pin
activeSet pin to active state

Definition at line 174 of file gpio.h.

174  {
175  struct gpios *gpios = gpio->gpios;
176 
177  gpios->op->out ( gpios, gpio, active );
178 }
struct gpios * gpios
GPIO controller.
Definition: gpio.h:20
struct gpio_operations * op
GPIO operations.
Definition: gpio.h:50
A GPIO controller.
Definition: gpio.h:37
A GPIO pin.
Definition: gpio.h:18
void(* out)(struct gpios *gpios, struct gpio *gpio, int active)
Set current GPIO output value.
Definition: gpio.h:73

References gpio::gpios, gpios::op, and gpio_operations::out.

◆ gpio_config()

static int gpio_config ( struct gpio gpio,
unsigned int  config 
)
inlinestatic

Configure GPIO pin.

Parameters
gpioGPIO pin
configConfiguration
Return values
rcReturn status code

Definition at line 187 of file gpio.h.

187  {
188  struct gpios *gpios = gpio->gpios;
189 
190  return gpios->op->config ( gpios, gpio, config );
191 }
struct gpios * gpios
GPIO controller.
Definition: gpio.h:20
struct gpio_operations * op
GPIO operations.
Definition: gpio.h:50
A GPIO controller.
Definition: gpio.h:37
A GPIO pin.
Definition: gpio.h:18
int(* config)(struct gpios *gpios, struct gpio *gpio, unsigned int config)
Configure GPIO pin.
Definition: gpio.h:82

References gpio_operations::config, gpio::gpios, and gpios::op.

◆ 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.

Variable Documentation

◆ null_gpio_operations

struct gpio_operations null_gpio_operations

Null GPIO operations.

Definition at line 161 of file gpio.c.

Referenced by gpios_nullify().