iPXE
Functions | Variables
dwgpio.c File Reference

Synopsys DesignWare GPIO driver. More...

#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ipxe/devtree.h>
#include <ipxe/fdt.h>
#include <ipxe/gpio.h>
#include "dwgpio.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int dwgpio_group_probe (struct dt_device *dt, unsigned int offset)
 Probe port group. More...
 
static void dwgpio_group_remove (struct dt_device *dt)
 Remove port group. More...
 
static void dwgpio_dump (struct dwgpio *dwgpio)
 Dump GPIO port status. More...
 
static int dwgpio_in (struct gpios *gpios, struct gpio *gpio)
 Get current GPIO input value. More...
 
static void dwgpio_out (struct gpios *gpios, struct gpio *gpio, int active)
 Set current GPIO output value. More...
 
static int dwgpio_config (struct gpios *gpios, struct gpio *gpio, unsigned int config)
 Configure GPIO pin. More...
 
static int dwgpio_probe (struct dt_device *dt, unsigned int offset)
 Probe port. More...
 
static void dwgpio_remove (struct dt_device *dt)
 Remove port. More...
 

Variables

static const char * dwgpio_group_ids []
 DesignWare GPIO port group compatible model identifiers. More...
 
struct dt_driver dwgpio_group_driver __dt_driver
 DesignWare GPIO port group devicetree driver. More...
 
static struct gpio_operations dwgpio_operations
 GPIO operations. More...
 
static const char * dwgpio_ids []
 DesignWare GPIO port compatible model identifiers. More...
 

Detailed Description

Synopsys DesignWare GPIO driver.

Definition in file dwgpio.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ dwgpio_group_probe()

static int dwgpio_group_probe ( struct dt_device dt,
unsigned int  offset 
)
static

Probe port group.

Parameters
dtDevicetree device
offsetStarting node offset
Return values
rcReturn status code

Definition at line 54 of file dwgpio.c.

54  {
55  struct dwgpio_group *group;
56  int rc;
57 
58  /* Allocate and initialise structure */
59  group = zalloc ( sizeof ( *group ) );
60  if ( ! group ) {
61  rc = -ENOMEM;
62  goto err_alloc;
63  }
64  dt_set_drvdata ( dt, group );
65 
66  /* Map registers */
67  group->regs = dt_ioremap ( dt, offset, 0, 0 );
68  if ( ! group->regs ) {
69  rc = -ENODEV;
70  goto err_ioremap;
71  }
72 
73  /* Probe child ports */
74  if ( ( rc = dt_probe_children ( dt, offset ) ) != 0 )
75  goto err_children;
76 
77  return 0;
78 
79  dt_remove_children ( dt );
80  err_children:
81  iounmap ( group->regs );
82  err_ioremap:
83  free ( group );
84  err_alloc:
85  return rc;
86 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void dt_remove_children(struct dt_device *parent)
Remove devicetree children.
Definition: devtree.c:310
#define ENOMEM
Not enough space.
Definition: errno.h:534
uint16_t group
Type of event.
Definition: ena.h:12
A DesignWare GPIO port group.
Definition: dwgpio.h:55
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static void dt_set_drvdata(struct dt_device *dt, void *priv)
Set devicetree driver-private data.
Definition: devtree.h:66
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
#define ENODEV
No such device.
Definition: errno.h:509
int dt_probe_children(struct dt_device *parent, unsigned int offset)
Probe devicetree children.
Definition: devtree.c:264
void * dt_ioremap(struct dt_device *dt, unsigned int offset, unsigned int index, size_t len)
Map devicetree range.
Definition: devtree.c:52
void iounmap(volatile const void *io_addr)
Unmap I/O address.
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

References dt_ioremap(), dt_probe_children(), dt_remove_children(), dt_set_drvdata(), ENODEV, ENOMEM, free, group, iounmap(), offset, rc, and zalloc().

◆ dwgpio_group_remove()

static void dwgpio_group_remove ( struct dt_device dt)
static

Remove port group.

Parameters
dtDevicetree device

Definition at line 93 of file dwgpio.c.

93  {
94  struct dwgpio_group *group = dt_get_drvdata ( dt );
95 
96  /* Remove child ports */
97  dt_remove_children ( dt );
98 
99  /* Unmap registers */
100  iounmap ( group->regs );
101 
102  /* Free device */
103  free ( group );
104 }
void dt_remove_children(struct dt_device *parent)
Remove devicetree children.
Definition: devtree.c:310
uint16_t group
Type of event.
Definition: ena.h:12
A DesignWare GPIO port group.
Definition: dwgpio.h:55
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void iounmap(volatile const void *io_addr)
Unmap I/O address.
static void * dt_get_drvdata(struct dt_device *dt)
Get devicetree driver-private data.
Definition: devtree.h:76

References dt_get_drvdata(), dt_remove_children(), free, group, and iounmap().

◆ dwgpio_dump()

static void dwgpio_dump ( struct dwgpio dwgpio)
inlinestatic

Dump GPIO port status.

Parameters
dwgpioDesignWare GPIO port

Definition at line 133 of file dwgpio.c.

133  {
134 
135  DBGC2 ( dwgpio, "DWGPIO %s dr %#08x ddr %#08x ctl %#08x\n",
139 }
const char * name
Device name.
Definition: dwgpio.h:63
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DWGPIO_SWPORT_CTL
Control register.
Definition: dwgpio.h:45
void * swport
Software port registers.
Definition: dwgpio.h:67
A DesignWare GPIO port.
Definition: dwgpio.h:61
#define DWGPIO_SWPORT_DR
Data register.
Definition: dwgpio.h:30
#define DBGC2(...)
Definition: compiler.h:522
#define DWGPIO_SWPORT_DDR
Data direction register.
Definition: dwgpio.h:37

References DBGC2, DWGPIO_SWPORT_CTL, DWGPIO_SWPORT_DDR, DWGPIO_SWPORT_DR, dwgpio::name, readl(), and dwgpio::swport.

Referenced by dwgpio_config(), dwgpio_out(), and dwgpio_probe().

◆ dwgpio_in()

static int dwgpio_in ( struct gpios gpios,
struct gpio gpio 
)
static

Get current GPIO input value.

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

Definition at line 148 of file dwgpio.c.

148  {
149  struct dwgpio *dwgpio = gpios->priv;
150  uint32_t ext;
151 
152  /* Read external port status */
153  ext = readl ( dwgpio->ext );
154  return ( ( ( ext >> gpio->index ) ^ gpio->config ) & 1 );
155 }
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
unsigned int index
Pin index.
Definition: gpio.h:22
A DesignWare GPIO port.
Definition: dwgpio.h:61
unsigned int config
Configuration.
Definition: gpio.h:24
A GPIO controller.
Definition: gpio.h:37
unsigned int uint32_t
Definition: stdint.h:12
uint16_t ext
Extended status.
Definition: ena.h:20
void * ext
External port register.
Definition: dwgpio.h:69
A GPIO pin.
Definition: gpio.h:18
void * priv
Driver-private data.
Definition: gpio.h:53

References gpio::config, ext, dwgpio::ext, gpio::index, gpios::priv, and readl().

◆ dwgpio_out()

static void dwgpio_out ( struct gpios gpios,
struct gpio gpio,
int  active 
)
static

Set current GPIO output value.

Parameters
gpiosGPIO controller
gpioGPIO pin
activeSet pin to active state

Definition at line 164 of file dwgpio.c.

164  {
165  struct dwgpio *dwgpio = gpios->priv;
166  uint32_t mask = ( 1UL << gpio->index );
167  uint32_t dr;
168 
169  /* Update data register */
171  dr &= ~mask;
172  if ( ( ( !! active ) ^ gpio->config ) & 1 )
173  dr |= mask;
174  writel ( dr, ( dwgpio->swport + DWGPIO_SWPORT_DR ) );
175  dwgpio_dump ( dwgpio );
176 }
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
unsigned int index
Pin index.
Definition: gpio.h:22
void * swport
Software port registers.
Definition: dwgpio.h:67
A DesignWare GPIO port.
Definition: dwgpio.h:61
#define DWGPIO_SWPORT_DR
Data register.
Definition: dwgpio.h:30
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static void dwgpio_dump(struct dwgpio *dwgpio)
Dump GPIO port status.
Definition: dwgpio.c:133
unsigned int config
Configuration.
Definition: gpio.h:24
A GPIO controller.
Definition: gpio.h:37
static unsigned long dr[NUM_HWBP]
Hardware breakpoint addresses (debug registers 0-3)
Definition: gdbmach.c:72
unsigned int uint32_t
Definition: stdint.h:12
A GPIO pin.
Definition: gpio.h:18
void * priv
Driver-private data.
Definition: gpio.h:53

References gpio::config, dr, dwgpio_dump(), DWGPIO_SWPORT_DR, gpio::index, gpios::priv, readl(), dwgpio::swport, and writel().

◆ dwgpio_config()

static int dwgpio_config ( struct gpios gpios,
struct gpio gpio,
unsigned int  config 
)
static

Configure GPIO pin.

Parameters
gpiosGPIO controller
gpioGPIO pin
configConfiguration
Return values
rcReturn status code

Definition at line 186 of file dwgpio.c.

187  {
188  struct dwgpio *dwgpio = gpios->priv;
189  uint32_t mask = ( 1UL << gpio->index );
190  uint32_t ddr;
191  uint32_t ctl;
192 
193  /* Update data direction and control registers */
196  ctl &= ~mask;
197  ddr &= ~mask;
198  if ( config & GPIO_CFG_OUTPUT )
199  ddr |= mask;
202  dwgpio_dump ( dwgpio );
203 
204  return 0;
205 }
uint32_t ctl
Original control register value.
Definition: dwgpio.h:76
uint32_t ddr
Original data direction register value.
Definition: dwgpio.h:74
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
unsigned int index
Pin index.
Definition: gpio.h:22
#define DWGPIO_SWPORT_CTL
Control register.
Definition: dwgpio.h:45
void * swport
Software port registers.
Definition: dwgpio.h:67
A DesignWare GPIO port.
Definition: dwgpio.h:61
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static void dwgpio_dump(struct dwgpio *dwgpio)
Dump GPIO port status.
Definition: dwgpio.c:133
A GPIO controller.
Definition: gpio.h:37
#define GPIO_CFG_OUTPUT
GPIO is an output.
Definition: gpio.h:34
unsigned int uint32_t
Definition: stdint.h:12
#define DWGPIO_SWPORT_DDR
Data direction register.
Definition: dwgpio.h:37
A GPIO pin.
Definition: gpio.h:18
void * priv
Driver-private data.
Definition: gpio.h:53

References dwgpio::ctl, dwgpio::ddr, dwgpio_dump(), DWGPIO_SWPORT_CTL, DWGPIO_SWPORT_DDR, GPIO_CFG_OUTPUT, gpio::index, gpios::priv, readl(), dwgpio::swport, and writel().

◆ dwgpio_probe()

static int dwgpio_probe ( struct dt_device dt,
unsigned int  offset 
)
static

Probe port.

Parameters
dtDevicetree device
offsetStarting node offset
Return values
rcReturn status code

Definition at line 221 of file dwgpio.c.

221  {
222  struct dt_device *parent;
223  struct dwgpio_group *group;
224  struct dwgpio *dwgpio;
225  struct gpios *gpios;
226  uint32_t count;
227  uint64_t port;
228  int rc;
229 
230  /* Get number of GPIOs */
231  if ( ( rc = fdt_u32 ( &sysfdt, offset, "nr-gpios-snps",
232  &count ) ) != 0 ) {
233  goto err_count;
234  }
236 
237  /* Allocate and initialise device */
238  gpios = alloc_gpios ( count, sizeof ( *dwgpio ) );
239  if ( ! gpios ) {
240  rc = -ENOMEM;
241  goto err_alloc;
242  }
243  dt_set_drvdata ( dt, gpios );
244  gpios->dev = &dt->dev;
246  dwgpio = gpios->priv;
247  dwgpio->name = dt->name;
248 
249  /* Identify group */
250  parent = dt_parent ( dt );
251  if ( parent->driver != &dwgpio_group_driver ) {
252  DBGC ( dwgpio, "DWGPIO %s has invalid parent %s\n",
253  dwgpio->name, parent->name );
254  rc = -EINVAL;
255  goto err_parent;
256  }
257  group = dt_get_drvdata ( parent );
258 
259  /* Identify port */
260  if ( ( rc = fdt_reg ( &sysfdt, offset, &port ) ) != 0 ) {
261  DBGC ( dwgpio, "DWGPIO %s could not get port number: %s\n",
262  dwgpio->name, strerror ( rc ) );
263  goto err_port;
264  }
265  dwgpio->port = port;
266  DBGC ( dwgpio, "DWGPIO %s is %s port %d (%d GPIOs)\n",
267  dwgpio->name, parent->name, dwgpio->port, gpios->count );
268 
269  /* Map registers */
270  dwgpio->swport = ( group->regs + DWGPIO_SWPORT ( port ) );
271  dwgpio->ext = ( group->regs + DWGPIO_EXT_PORT ( port ) );
272  dwgpio_dump ( dwgpio );
273 
274  /* Record original register values */
278 
279  /* Register GPIO controller */
280  if ( ( rc = gpios_register ( gpios ) ) != 0 ) {
281  DBGC ( dwgpio, "DWGPIO %s could not register: %s\n",
282  dwgpio->name, strerror ( rc ) );
283  goto err_register;
284  }
285 
286  return 0;
287 
289  err_register:
290  err_port:
291  err_parent:
292  gpios_nullify ( gpios );
293  gpios_put ( gpios );
294  err_alloc:
295  err_count:
296  return rc;
297 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t ctl
Original control register value.
Definition: dwgpio.h:76
const char * name
Device name.
Definition: dwgpio.h:63
uint32_t ddr
Original data direction register value.
Definition: dwgpio.h:74
static void gpios_put(struct gpios *gpios)
Drop reference to GPIO controller.
Definition: gpio.h:106
#define DWGPIO_EXT_PORT(x)
External port.
Definition: dwgpio.h:52
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
unsigned long long uint64_t
Definition: stdint.h:13
struct device * dev
Generic device.
Definition: gpio.h:43
#define DWGPIO_SWPORT_CTL
Control register.
Definition: dwgpio.h:45
struct device dev
Generic device.
Definition: devtree.h:21
struct gpios * alloc_gpios(unsigned int count, size_t priv_len)
Allocate GPIO controller.
Definition: gpio.c:46
void * swport
Software port registers.
Definition: dwgpio.h:67
#define ENOMEM
Not enough space.
Definition: errno.h:534
u8 port
Port number.
Definition: CIB_PRM.h:31
static struct dt_device * dt_parent(struct dt_device *dt)
Get devicetree parent device.
Definition: devtree.h:86
#define DWGPIO_MAX_COUNT
Maximum number of GPIOs per port.
Definition: dwgpio.h:13
uint16_t group
Type of event.
Definition: ena.h:12
A DesignWare GPIO port.
Definition: dwgpio.h:61
#define DWGPIO_SWPORT_DR
Data register.
Definition: dwgpio.h:30
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int fdt_u32(struct fdt *fdt, unsigned int offset, const char *name, uint32_t *value)
Get 32-bit integer property.
Definition: fdt.c:663
struct dt_driver * driver
Driver for this device.
Definition: devtree.h:25
void gpios_unregister(struct gpios *gpios)
Unregister GPIO controller.
Definition: gpio.c:94
A devicetree device.
Definition: devtree.h:17
#define DWGPIO_SWPORT(x)
Software port.
Definition: dwgpio.h:19
static unsigned int count
Number of entries.
Definition: dwmac.h:225
static void dwgpio_dump(struct dwgpio *dwgpio)
Dump GPIO port status.
Definition: dwgpio.c:133
A DesignWare GPIO port group.
Definition: dwgpio.h:55
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void dt_set_drvdata(struct dt_device *dt, void *priv)
Set devicetree driver-private data.
Definition: devtree.h:66
uint32_t dr
Original data register value.
Definition: dwgpio.h:72
A GPIO controller.
Definition: gpio.h:37
unsigned int uint32_t
Definition: stdint.h:12
int fdt_reg(struct fdt *fdt, unsigned int offset, uint64_t *region)
Get unsized single-entry region address.
Definition: fdt.c:843
const char * name
Device name.
Definition: devtree.h:19
int gpios_register(struct gpios *gpios)
Register GPIO controller.
Definition: gpio.c:78
static void gpios_init(struct gpios *gpios, struct gpio_operations *op)
Initialise a GPIO controller.
Definition: gpio.h:139
void * ext
External port register.
Definition: dwgpio.h:69
static void gpios_nullify(struct gpios *gpios)
Stop using a GPIO controller.
Definition: gpio.h:152
#define DWGPIO_SWPORT_DDR
Data direction register.
Definition: dwgpio.h:37
static struct gpio_operations dwgpio_operations
GPIO operations.
Definition: dwgpio.c:208
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
unsigned int count
Number of GPIOs.
Definition: gpio.h:45
unsigned int port
Port index.
Definition: dwgpio.h:65
static void * dt_get_drvdata(struct dt_device *dt)
Get devicetree driver-private data.
Definition: devtree.h:76
void * priv
Driver-private data.
Definition: gpio.h:53
struct fdt sysfdt
The system flattened device tree (if present)
Definition: fdt.c:44

References alloc_gpios(), assert(), gpios::count, count, dwgpio::ctl, DBGC, dwgpio::ddr, dt_device::dev, gpios::dev, dwgpio::dr, dt_device::driver, dt_get_drvdata(), dt_parent(), dt_set_drvdata(), dwgpio_dump(), DWGPIO_EXT_PORT, DWGPIO_MAX_COUNT, dwgpio_operations, DWGPIO_SWPORT, DWGPIO_SWPORT_CTL, DWGPIO_SWPORT_DDR, DWGPIO_SWPORT_DR, EINVAL, ENOMEM, dwgpio::ext, fdt_reg(), fdt_u32(), gpios_init(), gpios_nullify(), gpios_put(), gpios_register(), gpios_unregister(), group, dt_device::name, dwgpio::name, offset, port, dwgpio::port, gpios::priv, rc, readl(), strerror(), dwgpio::swport, and sysfdt.

◆ dwgpio_remove()

static void dwgpio_remove ( struct dt_device dt)
static

Remove port.

Parameters
dtDevicetree device

Definition at line 304 of file dwgpio.c.

304  {
305  struct gpios *gpios = dt_get_drvdata ( dt );
306  struct dwgpio *dwgpio = gpios->priv;
307 
308  /* Unregister GPIO controller */
310 
311  /* Restore original register values */
315 
316  /* Free GPIO device */
317  gpios_nullify ( gpios );
318  gpios_put ( gpios );
319 }
uint32_t ctl
Original control register value.
Definition: dwgpio.h:76
uint32_t ddr
Original data direction register value.
Definition: dwgpio.h:74
static void gpios_put(struct gpios *gpios)
Drop reference to GPIO controller.
Definition: gpio.h:106
#define DWGPIO_SWPORT_CTL
Control register.
Definition: dwgpio.h:45
void * swport
Software port registers.
Definition: dwgpio.h:67
A DesignWare GPIO port.
Definition: dwgpio.h:61
#define DWGPIO_SWPORT_DR
Data register.
Definition: dwgpio.h:30
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
void gpios_unregister(struct gpios *gpios)
Unregister GPIO controller.
Definition: gpio.c:94
uint32_t dr
Original data register value.
Definition: dwgpio.h:72
A GPIO controller.
Definition: gpio.h:37
static void gpios_nullify(struct gpios *gpios)
Stop using a GPIO controller.
Definition: gpio.h:152
#define DWGPIO_SWPORT_DDR
Data direction register.
Definition: dwgpio.h:37
static void * dt_get_drvdata(struct dt_device *dt)
Get devicetree driver-private data.
Definition: devtree.h:76
void * priv
Driver-private data.
Definition: gpio.h:53

References dwgpio::ctl, dwgpio::ddr, dwgpio::dr, dt_get_drvdata(), DWGPIO_SWPORT_CTL, DWGPIO_SWPORT_DDR, DWGPIO_SWPORT_DR, gpios_nullify(), gpios_put(), gpios_unregister(), gpios::priv, dwgpio::swport, and writel().

Variable Documentation

◆ dwgpio_group_ids

const char* dwgpio_group_ids[]
static
Initial value:
= {
"snps,dw-apb-gpio",
}

DesignWare GPIO port group compatible model identifiers.

Definition at line 107 of file dwgpio.c.

◆ __dt_driver

struct dt_driver dwgpio_driver __dt_driver
Initial value:
= {
.name = "dwgpio-group",
.id_count = ( sizeof ( dwgpio_group_ids ) /
sizeof ( dwgpio_group_ids[0] ) ),
}
static int dwgpio_group_probe(struct dt_device *dt, unsigned int offset)
Probe port group.
Definition: dwgpio.c:54
static const char * dwgpio_group_ids[]
DesignWare GPIO port group compatible model identifiers.
Definition: dwgpio.c:107
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
static void dwgpio_group_remove(struct dt_device *dt)
Remove port group.
Definition: dwgpio.c:93

DesignWare GPIO port group devicetree driver.

DesignWare GPIO port devicetree driver.

Definition at line 112 of file dwgpio.c.

◆ dwgpio_operations

struct gpio_operations dwgpio_operations
static
Initial value:
= {
.in = dwgpio_in,
.out = dwgpio_out,
.config = dwgpio_config,
}
static int dwgpio_config(struct gpios *gpios, struct gpio *gpio, unsigned int config)
Configure GPIO pin.
Definition: dwgpio.c:186
static void dwgpio_out(struct gpios *gpios, struct gpio *gpio, int active)
Set current GPIO output value.
Definition: dwgpio.c:164
static int dwgpio_in(struct gpios *gpios, struct gpio *gpio)
Get current GPIO input value.
Definition: dwgpio.c:148

GPIO operations.

Definition at line 208 of file dwgpio.c.

Referenced by dwgpio_probe().

◆ dwgpio_ids

const char* dwgpio_ids[]
static
Initial value:
= {
"snps,dw-apb-gpio-port",
}

DesignWare GPIO port compatible model identifiers.

Definition at line 322 of file dwgpio.c.