mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-25 04:23:46 +00:00
83d290c56f
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
140 lines
3.6 KiB
C
140 lines
3.6 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright 2013 Broadcom Corporation.
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <asm/io.h>
|
|
#include <asm/arch/sysmap.h>
|
|
|
|
#define GPIO_BASE (void *)GPIO2_BASE_ADDR
|
|
|
|
#define GPIO_PASSWD 0x00a5a501
|
|
#define GPIO_PER_BANK 32
|
|
#define GPIO_MAX_BANK_NUM 8
|
|
|
|
#define GPIO_BANK(gpio) ((gpio) >> 5)
|
|
#define GPIO_BITMASK(gpio) \
|
|
(1UL << ((gpio) & (GPIO_PER_BANK - 1)))
|
|
|
|
#define GPIO_OUT_STATUS(bank) (0x00000000 + ((bank) << 2))
|
|
#define GPIO_IN_STATUS(bank) (0x00000020 + ((bank) << 2))
|
|
#define GPIO_OUT_SET(bank) (0x00000040 + ((bank) << 2))
|
|
#define GPIO_OUT_CLEAR(bank) (0x00000060 + ((bank) << 2))
|
|
#define GPIO_INT_STATUS(bank) (0x00000080 + ((bank) << 2))
|
|
#define GPIO_INT_MASK(bank) (0x000000a0 + ((bank) << 2))
|
|
#define GPIO_INT_MSKCLR(bank) (0x000000c0 + ((bank) << 2))
|
|
#define GPIO_CONTROL(bank) (0x00000100 + ((bank) << 2))
|
|
#define GPIO_PWD_STATUS(bank) (0x00000500 + ((bank) << 2))
|
|
|
|
#define GPIO_GPPWR_OFFSET 0x00000520
|
|
|
|
#define GPIO_GPCTR0_DBR_SHIFT 5
|
|
#define GPIO_GPCTR0_DBR_MASK 0x000001e0
|
|
|
|
#define GPIO_GPCTR0_ITR_SHIFT 3
|
|
#define GPIO_GPCTR0_ITR_MASK 0x00000018
|
|
#define GPIO_GPCTR0_ITR_CMD_RISING_EDGE 0x00000001
|
|
#define GPIO_GPCTR0_ITR_CMD_FALLING_EDGE 0x00000002
|
|
#define GPIO_GPCTR0_ITR_CMD_BOTH_EDGE 0x00000003
|
|
|
|
#define GPIO_GPCTR0_IOTR_MASK 0x00000001
|
|
#define GPIO_GPCTR0_IOTR_CMD_0UTPUT 0x00000000
|
|
#define GPIO_GPCTR0_IOTR_CMD_INPUT 0x00000001
|
|
|
|
int gpio_request(unsigned gpio, const char *label)
|
|
{
|
|
unsigned int value, off;
|
|
|
|
writel(GPIO_PASSWD, GPIO_BASE + GPIO_GPPWR_OFFSET);
|
|
off = GPIO_PWD_STATUS(GPIO_BANK(gpio));
|
|
value = readl(GPIO_BASE + off) & ~GPIO_BITMASK(gpio);
|
|
writel(value, GPIO_BASE + off);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int gpio_free(unsigned gpio)
|
|
{
|
|
unsigned int value, off;
|
|
|
|
writel(GPIO_PASSWD, GPIO_BASE + GPIO_GPPWR_OFFSET);
|
|
off = GPIO_PWD_STATUS(GPIO_BANK(gpio));
|
|
value = readl(GPIO_BASE + off) | GPIO_BITMASK(gpio);
|
|
writel(value, GPIO_BASE + off);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int gpio_direction_input(unsigned gpio)
|
|
{
|
|
u32 val;
|
|
|
|
val = readl(GPIO_BASE + GPIO_CONTROL(gpio));
|
|
val &= ~GPIO_GPCTR0_IOTR_MASK;
|
|
val |= GPIO_GPCTR0_IOTR_CMD_INPUT;
|
|
writel(val, GPIO_BASE + GPIO_CONTROL(gpio));
|
|
|
|
return 0;
|
|
}
|
|
|
|
int gpio_direction_output(unsigned gpio, int value)
|
|
{
|
|
int bank_id = GPIO_BANK(gpio);
|
|
int bitmask = GPIO_BITMASK(gpio);
|
|
u32 val, off;
|
|
|
|
val = readl(GPIO_BASE + GPIO_CONTROL(gpio));
|
|
val &= ~GPIO_GPCTR0_IOTR_MASK;
|
|
val |= GPIO_GPCTR0_IOTR_CMD_0UTPUT;
|
|
writel(val, GPIO_BASE + GPIO_CONTROL(gpio));
|
|
off = value ? GPIO_OUT_SET(bank_id) : GPIO_OUT_CLEAR(bank_id);
|
|
|
|
val = readl(GPIO_BASE + off);
|
|
val |= bitmask;
|
|
writel(val, GPIO_BASE + off);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int gpio_get_value(unsigned gpio)
|
|
{
|
|
int bank_id = GPIO_BANK(gpio);
|
|
int bitmask = GPIO_BITMASK(gpio);
|
|
u32 val, off;
|
|
|
|
/* determine the GPIO pin direction */
|
|
val = readl(GPIO_BASE + GPIO_CONTROL(gpio));
|
|
val &= GPIO_GPCTR0_IOTR_MASK;
|
|
|
|
/* read the GPIO bank status */
|
|
off = (GPIO_GPCTR0_IOTR_CMD_INPUT == val) ?
|
|
GPIO_IN_STATUS(bank_id) : GPIO_OUT_STATUS(bank_id);
|
|
val = readl(GPIO_BASE + off);
|
|
|
|
/* return the specified bit status */
|
|
return !!(val & bitmask);
|
|
}
|
|
|
|
void gpio_set_value(unsigned gpio, int value)
|
|
{
|
|
int bank_id = GPIO_BANK(gpio);
|
|
int bitmask = GPIO_BITMASK(gpio);
|
|
u32 val, off;
|
|
|
|
/* determine the GPIO pin direction */
|
|
val = readl(GPIO_BASE + GPIO_CONTROL(gpio));
|
|
val &= GPIO_GPCTR0_IOTR_MASK;
|
|
|
|
/* this function only applies to output pin */
|
|
if (GPIO_GPCTR0_IOTR_CMD_INPUT == val) {
|
|
printf("%s: Cannot set an input pin %d\n", __func__, gpio);
|
|
return;
|
|
}
|
|
|
|
off = value ? GPIO_OUT_SET(bank_id) : GPIO_OUT_CLEAR(bank_id);
|
|
|
|
val = readl(GPIO_BASE + off);
|
|
val |= bitmask;
|
|
writel(val, GPIO_BASE + off);
|
|
}
|