Files
system76-coreboot/src/cpu/allwinner/a10/gpio.c
Julius Werner d21a329866 arm(64): Replace write32() and friends with writel()
This patch is a raw application of the following spatch to the
directories src/arch/arm(64)?, src/mainboard/<arm(64)-board>,
src/soc/<arm(64)-soc> and src/drivers/gic:

@@
expression A, V;
@@
- write32(V, A)
+ writel(V, A)
@@
expression A, V;
@@
- write16(V, A)
+ writew(V, A)
@@
expression A, V;
@@
- write8(V, A)
+ writeb(V, A)

This replaces all uses of write{32,16,8}() with write{l,w,b}()
which is currently equivalent and much more common. This is a
preparatory step that will allow us to easier flip them all at once to
the new write32(a,v) model.

BRANCH=none
BUG=chromium:451388
TEST=Compiled Cosmos, Daisy, Blaze, Pit, Ryu, Storm and Pinky.

Change-Id: I16016cd77780e7cadbabe7d8aa7ab465b95b8f09
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 93f0ada19b429b4e30d67335b4e61d0f43597b24
Original-Change-Id: I1ac01c67efef4656607663253ed298ff4d0ef89d
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254862
Reviewed-on: http://review.coreboot.org/9834
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-04-21 08:21:15 +02:00

99 lines
2.1 KiB
C

/*
* Basic GPIO helpers for Allwinner CPUs
*
* Copyright (C) 2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
* Subject to the GNU GPL v2, or (at your option) any later version.
*/
#include "gpio.h"
#include <arch/io.h>
static struct a10_gpio *const gpio = (void *)GPIO_BASE;
/**
* \brief Set a single output pin
*
* @param[in] port GPIO port of the pin (GPA -> GPS)
* @param[in] pin the pin number in the given port (1 -> 31)
*/
void gpio_set(u8 port, u8 pin)
{
u32 reg32;
if ((port > GPS))
return;
reg32 = gpio_read(port);
reg32 |= (1 << pin);
gpio_write(port, reg32);
}
/**
* \brief Clear a single output pin
*
* @param[in] port GPIO port of the pin (GPA -> GPS)
* @param[in] pin the pin number in the given port (1 -> 31)
*/
void gpio_clear(u8 port, u8 pin)
{
u32 reg32;
if ((port > GPS))
return;
reg32 = gpio_read(port);
reg32 &= ~(1 << pin);
gpio_write(port, reg32);
}
/**
* \brief Get the status of a single input pin
*
* @param[in] port GPIO port of the pin (GPA -> GPS)
* @param[in] pin the pin number in the given port (1 -> 31)
* @return 1 if the pin is high, or 0 if the pin is low
*/
int gpio_get(u8 port, u8 pin)
{
if ((port > GPS))
return 0;
return (gpio_read(port) & (1 << pin)) ? 1 : 0;
}
/**
* \brief Write to a GPIO port
*
* Write the state of all output pins in the GPIO port. This only affects pins
* configured as output pins.
*
* @param[in] port GPIO port of the pin (GPA -> GPS)
* @param[in] val 32-bit mask indicating which pins to set. For a set bit, the
* corresponding pin will be set. Otherwise, it will be cleared
*/
void gpio_write(u8 port, u32 val)
{
if ((port > GPS))
return;
writel(val, &gpio->port[port].dat);
}
/**
* \brief Write to a GPIO port
*
* Read the state of all input pins in the GPIO port.
*
* @param[in] port GPIO port of the pin (GPA -> GPS)
* @return 32-bit mask indicating which pins are high. For each set bit, the
* corresponding pin is high. The value of bits corresponding to pins
* which are not configured as inputs is undefined.
*/
u32 gpio_read(u8 port)
{
if ((port > GPS))
return 0;
return read32(&gpio->port[port].dat);
}