coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
gpio.c File Reference
#include <assert.h>
#include <console/console.h>
#include <device/mmio.h>
#include <delay.h>
#include <soc/cpu.h>
#include <soc/gpio.h>
Include dependency graph for gpio.c:

Go to the source code of this file.

Data Structures

struct  gpio_info
 

Macros

#define CON_MASK(x)   (0xf << ((x) << 2))
 
#define CON_SFR(x, v)   ((v) << ((x) << 2))
 
#define DAT_MASK(x)   (0x1 << (x))
 
#define DAT_SET(x)   (0x1 << (x))
 
#define PULL_MASK(x)   (0x3 << ((x) << 1))
 
#define PULL_MODE(x, v)   ((v) << ((x) << 1))
 
#define DRV_MASK(x)   (0x3 << ((x) << 1))
 
#define DRV_SET(x, m)   ((m) << ((x) << 1))
 
#define RATE_MASK(x)   (0x1 << (x + 16))
 
#define RATE_SET(x)   (0x1 << (x + 16))
 
#define GPIO_BIT(x)   ((x) & 0x7)
 
#define GPIO_DELAY_US   15
 

Functions

static struct gpio_bankgpio_get_bank (unsigned int gpio)
 
void gpio_cfg_pin (int gpio, int cfg)
 Set GPIO pin configuration. More...
 
static int gpio_get_cfg (int gpio)
 
void gpio_set_pull (int gpio, int mode)
 Set GPIO pull mode. More...
 
void gpio_set_drv (int gpio, int mode)
 Set GPIO drive strength level. More...
 
void gpio_set_rate (int gpio, int mode)
 Set GPIO drive rate. More...
 
int gpio_direction_input (unsigned int gpio)
 Make a GPIO an input. More...
 
int gpio_direction_output (unsigned int gpio, int value)
 Make a GPIO an output, and set its value. More...
 
int gpio_get_value (unsigned int gpio)
 Get a GPIO's value. More...
 
int gpio_set_value (unsigned int gpio, int value)
 Set an output GPIO's value. More...
 
int gpio_read_mvl3 (unsigned int gpio)
 
void gpio_info (void)
 

Variables

static const struct gpio_info gpio_data [EXYNOS_GPIO_NUM_PARTS]
 

Macro Definition Documentation

◆ CON_MASK

#define CON_MASK (   x)    (0xf << ((x) << 2))

Definition at line 10 of file gpio.c.

◆ CON_SFR

#define CON_SFR (   x,
 
)    ((v) << ((x) << 2))

Definition at line 11 of file gpio.c.

◆ DAT_MASK

#define DAT_MASK (   x)    (0x1 << (x))

Definition at line 13 of file gpio.c.

◆ DAT_SET

#define DAT_SET (   x)    (0x1 << (x))

Definition at line 14 of file gpio.c.

◆ DRV_MASK

#define DRV_MASK (   x)    (0x3 << ((x) << 1))

Definition at line 19 of file gpio.c.

◆ DRV_SET

#define DRV_SET (   x,
  m 
)    ((m) << ((x) << 1))

Definition at line 20 of file gpio.c.

◆ GPIO_BIT

#define GPIO_BIT (   x)    ((x) & 0x7)

Definition at line 39 of file gpio.c.

◆ GPIO_DELAY_US

#define GPIO_DELAY_US   15

Definition at line 195 of file gpio.c.

◆ PULL_MASK

#define PULL_MASK (   x)    (0x3 << ((x) << 1))

Definition at line 16 of file gpio.c.

◆ PULL_MODE

#define PULL_MODE (   x,
 
)    ((v) << ((x) << 1))

Definition at line 17 of file gpio.c.

◆ RATE_MASK

#define RATE_MASK (   x)    (0x1 << (x + 16))

Definition at line 21 of file gpio.c.

◆ RATE_SET

#define RATE_SET (   x)    (0x1 << (x + 16))

Definition at line 22 of file gpio.c.

Function Documentation

◆ gpio_cfg_pin()

void gpio_cfg_pin ( int  gpio,
int  cfg 
)

Set GPIO pin configuration.

Parameters
gpioGPIO pin
cfgEither GPIO_INPUT, GPIO_OUTPUT, or GPIO_IRQ

Definition at line 63 of file gpio.c.

References gpio_bank::con, CON_MASK, CON_SFR, GPIO_BIT, gpio_get_bank(), read32(), value, and write32().

Here is the call graph for this function:

◆ gpio_direction_input()

int gpio_direction_input ( unsigned int  gpio)

Make a GPIO an input.

Parameters
gpioGPIO number
Returns
0 if ok, -1 on error

Definition at line 144 of file gpio.c.

References gpio_cfg_pin(), and GPIO_INPUT.

Here is the call graph for this function:

◆ gpio_direction_output()

int gpio_direction_output ( unsigned int  gpio,
int  value 
)

Make a GPIO an output, and set its value.

Parameters
gpioGPIO number
valueGPIO value (0 for low or 1 for high)
Returns
0 if ok, -1 on error

Definition at line 151 of file gpio.c.

References gpio_bank::dat, DAT_MASK, DAT_SET, GPIO_BIT, gpio_cfg_pin(), gpio_get_bank(), GPIO_OUTPUT, read32(), val, value, and write32().

Here is the call graph for this function:

◆ gpio_get_bank()

static struct gpio_bank* gpio_get_bank ( unsigned int  gpio)
static

◆ gpio_get_cfg()

static int gpio_get_cfg ( int  gpio)
static

Definition at line 74 of file gpio.c.

References gpio_bank::con, CON_MASK, GPIO_BIT, gpio_get_bank(), and read32().

Referenced by gpio_info().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpio_get_value()

int gpio_get_value ( unsigned int  gpio)

Get a GPIO's value.

This will work whether the GPIO is an input or an output.

Parameters
gpioGPIO number
Returns
0 if low, 1 if high, -1 on error

Definition at line 167 of file gpio.c.

References gpio_bank::dat, DAT_MASK, GPIO_BIT, gpio_get_bank(), read32(), and value.

Here is the call graph for this function:

◆ gpio_info()

Definition at line 236 of file gpio.c.

References BIOS_INFO, gpio_get_cfg(), gpio_get_value(), GPIO_INPUT, GPIO_MAX_PORT, GPIO_OUTPUT, and printk.

Here is the call graph for this function:

◆ gpio_read_mvl3()

int gpio_read_mvl3 ( unsigned int  gpio)

Definition at line 197 of file gpio.c.

References GPIO_DELAY_US, gpio_direction_input(), gpio_get_value(), GPIO_MAX_PORT, GPIO_PULL_DOWN, GPIO_PULL_UP, gpio_set_pull(), LOGIC_0, LOGIC_1, LOGIC_Z, udelay(), and value.

Here is the call graph for this function:

◆ gpio_set_drv()

void gpio_set_drv ( int  gpio,
int  mode 
)

Set GPIO drive strength level.

Parameters
gpioGPIO pin
modeEither GPIO_DRV_1X, GPIO_DRV_2X, GPIO_DRV_3X, or GPIO_DRV_4X

Definition at line 102 of file gpio.c.

References gpio_bank::drv, DRV_MASK, DRV_SET, GPIO_BIT, GPIO_DRV_1X, GPIO_DRV_2X, GPIO_DRV_3X, GPIO_DRV_4X, gpio_get_bank(), read32(), value, and write32().

Here is the call graph for this function:

◆ gpio_set_pull()

void gpio_set_pull ( int  gpio,
int  mode 
)

Set GPIO pull mode.

Parameters
gpioGPIO pin
modeEither GPIO_PULL_DOWN or GPIO_PULL_UP

Definition at line 82 of file gpio.c.

References GPIO_BIT, gpio_get_bank(), GPIO_PULL_DOWN, GPIO_PULL_UP, gpio_bank::pull, PULL_MASK, PULL_MODE, read32(), value, and write32().

Here is the call graph for this function:

◆ gpio_set_rate()

void gpio_set_rate ( int  gpio,
int  mode 
)

Set GPIO drive rate.

Parameters
gpioGPIO pin
modeEither GPIO_DRV_FAST or GPIO_DRV_SLOW

Definition at line 124 of file gpio.c.

References gpio_bank::drv, GPIO_BIT, GPIO_DRV_FAST, GPIO_DRV_SLOW, gpio_get_bank(), RATE_MASK, RATE_SET, read32(), value, and write32().

Here is the call graph for this function:

◆ gpio_set_value()

int gpio_set_value ( unsigned int  gpio,
int  value 
)

Set an output GPIO's value.

The GPIO must already be an output or this function may have no effect.

Parameters
gpioGPIO number
valueGPIO value (0 for low or 1 for high)
Returns
0 if ok, -1 on error

Definition at line 176 of file gpio.c.

References gpio_bank::dat, DAT_MASK, DAT_SET, GPIO_BIT, gpio_get_bank(), read32(), val, value, and write32().

Here is the call graph for this function:

Variable Documentation

◆ gpio_data

const struct gpio_info gpio_data[EXYNOS_GPIO_NUM_PARTS]
static
Initial value:
= {
}
@ GPIO_MAX_PORT
Definition: gpio.h:430
@ GPIO_MAX_PORT_PART_4
Definition: gpio.h:411
@ GPIO_MAX_PORT_PART_2
Definition: gpio.h:301
@ GPIO_MAX_PORT_PART_3
Definition: gpio.h:376
@ GPIO_MAX_PORT_PART_5
Definition: gpio.h:422
@ GPIO_MAX_PORT_PART_1
Definition: gpio.h:266
#define EXYNOS5420_GPIO_PART6_BASE
Definition: cpu.h:12
#define EXYNOS5420_GPIO_PART5_BASE
Definition: cpu.h:54
#define EXYNOS5420_GPIO_PART1_BASE
Definition: cpu.h:50
#define EXYNOS5420_GPIO_PART3_BASE
Definition: cpu.h:52
#define EXYNOS5420_GPIO_PART4_BASE
Definition: cpu.h:53
#define EXYNOS5420_GPIO_PART2_BASE
Definition: cpu.h:51

Definition at line 1 of file gpio.c.

Referenced by gpio_get_bank().