summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2015-05-18 09:15:15 -0400
committerTom Rini <trini@konsulko.com>2015-05-18 09:15:15 -0400
commit0e6b7a28243175ae0874d53b6e6e4eff8548d71f (patch)
treee6c523fe67ddb72a72975d11cbec855a252bb537 /drivers
parent0744c2f1ad082a4d9ac38084b8f3ac84cc012d05 (diff)
parentcf85202770d95474ba341b8881f9b76589244bed (diff)
downloadtalos-obmc-uboot-0e6b7a28243175ae0874d53b6e6e4eff8548d71f.tar.gz
talos-obmc-uboot-0e6b7a28243175ae0874d53b6e6e4eff8548d71f.zip
Merge git://git.denx.de/u-boot-samsung
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpio/s3c2440_gpio.c75
-rw-r--r--drivers/i2c/s3c24x0_i2c.c10
2 files changed, 47 insertions, 38 deletions
diff --git a/drivers/gpio/s3c2440_gpio.c b/drivers/gpio/s3c2440_gpio.c
index e1e2d3f805..d6c7eeb693 100644
--- a/drivers/gpio/s3c2440_gpio.c
+++ b/drivers/gpio/s3c2440_gpio.c
@@ -8,53 +8,50 @@
#include <asm/arch/s3c2440.h>
#include <asm/gpio.h>
#include <asm/io.h>
+#include <errno.h>
#define GPIO_INPUT 0x0
#define GPIO_OUTPUT 0x1
-/* 0x4 means that we want DAT and not CON register */
-#define GPIO_PORT(x) ((((x) >> 5) & 0x3) + 0x4)
-#define GPIO_BIT(x) ((x) & 0x3f)
+#define S3C_GPIO_CON 0x0
+#define S3C_GPIO_DAT 0x4
-/*
- * It's how we calculate the full port address
- * We have to get the number of the port + 1 (Port A is at 0x56000001 ...)
- * We move it at the second digit, and finally we add 0x4 because we want
- * to modify GPIO DAT and not CON
- */
-#define GPIO_FULLPORT(x) (S3C24X0_GPIO_BASE | ((GPIO_PORT(gpio) + 1) << 1))
+static uint32_t s3c_gpio_get_bank_addr(unsigned gpio)
+{
+ /* There is up to 16 pins per bank, one bank is 0x10 big. */
+ uint32_t addr = gpio & ~0xf;
+
+ if (addr >= 0x80 && addr != 0xd0) { /* Wrong GPIO bank. */
+ printf("Invalid GPIO bank (bank %02x)\n", addr);
+ return 0xffffffff;
+ }
+
+ return addr | S3C24X0_GPIO_BASE;
+}
int gpio_set_value(unsigned gpio, int value)
{
- unsigned l = readl(GPIO_FULLPORT(gpio));
- unsigned bit;
- unsigned port = GPIO_FULLPORT(gpio);
-
- /*
- * All GPIO Port have a configuration on
- * 2 bits excepted the first GPIO (A) which
- * have only 1 bit of configuration.
- */
- if (!GPIO_PORT(gpio))
- bit = (0x1 << GPIO_BIT(gpio));
- else
- bit = (0x3 << GPIO_BIT(gpio));
+ uint32_t addr = s3c_gpio_get_bank_addr(gpio);
+
+ if (addr == 0xffffffff)
+ return -EINVAL;
if (value)
- l |= bit;
+ setbits_le32(addr | S3C_GPIO_DAT, 1 << (gpio & 0xf));
else
- l &= ~bit;
+ clrbits_le32(addr | S3C_GPIO_DAT, 1 << (gpio & 0xf));
- return writel(l, port);
+ return 0;
}
int gpio_get_value(unsigned gpio)
{
- unsigned l = readl(GPIO_FULLPORT(gpio));
+ uint32_t addr = s3c_gpio_get_bank_addr(gpio);
+
+ if (addr == 0xffffffff)
+ return -EINVAL;
- if (GPIO_PORT(gpio) == 0) /* PORT A */
- return (l >> GPIO_BIT(gpio)) & 0x1;
- return (l >> GPIO_BIT(gpio)) & 0x3;
+ return !!(readl(addr | S3C_GPIO_DAT) & (1 << (gpio & 0xf)));
}
int gpio_request(unsigned gpio, const char *label)
@@ -67,13 +64,25 @@ int gpio_free(unsigned gpio)
return 0;
}
+static int s3c_gpio_direction(unsigned gpio, uint8_t dir)
+{
+ uint32_t addr = s3c_gpio_get_bank_addr(gpio);
+ const uint32_t mask = 0x3 << ((gpio & 0xf) << 1);
+ const uint32_t dirm = dir << ((gpio & 0xf) << 1);
+
+ if (addr == 0xffffffff)
+ return -EINVAL;
+
+ clrsetbits_le32(addr | S3C_GPIO_CON, mask, dirm);
+ return 0;
+}
+
int gpio_direction_input(unsigned gpio)
{
- return writel(GPIO_INPUT << GPIO_BIT(gpio), GPIO_FULLPORT(gpio));
+ return s3c_gpio_direction(gpio, GPIO_INPUT);
}
int gpio_direction_output(unsigned gpio, int value)
{
- writel(GPIO_OUTPUT << GPIO_BIT(gpio), GPIO_FULLPORT(gpio));
- return gpio_set_value(gpio, value);
+ return s3c_gpio_direction(gpio, GPIO_OUTPUT);
}
diff --git a/drivers/i2c/s3c24x0_i2c.c b/drivers/i2c/s3c24x0_i2c.c
index 27ff587440..c053e84cdb 100644
--- a/drivers/i2c/s3c24x0_i2c.c
+++ b/drivers/i2c/s3c24x0_i2c.c
@@ -165,7 +165,7 @@ static int GetI2CSDA(void)
{
struct s3c24x0_gpio *gpio = s3c24x0_get_base_gpio();
-#ifdef CONFIG_S3C2410
+#if defined(CONFIG_S3C2410) || defined(CONFIG_S3C2440)
return (readl(&gpio->gpedat) & 0x8000) >> 15;
#endif
#ifdef CONFIG_S3C2400
@@ -177,7 +177,7 @@ static void SetI2CSCL(int x)
{
struct s3c24x0_gpio *gpio = s3c24x0_get_base_gpio();
-#ifdef CONFIG_S3C2410
+#if defined(CONFIG_S3C2410) || defined(CONFIG_S3C2440)
writel((readl(&gpio->gpedat) & ~0x4000) |
(x & 1) << 14, &gpio->gpedat);
#endif
@@ -443,7 +443,7 @@ static void s3c24x0_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd)
int i;
if ((readl(&i2c->iicstat) & I2CSTAT_BSY) || GetI2CSDA() == 0) {
-#ifdef CONFIG_S3C2410
+#if defined(CONFIG_S3C2410) || defined(CONFIG_S3C2440)
ulong old_gpecon = readl(&gpio->gpecon);
#endif
#ifdef CONFIG_S3C2400
@@ -452,7 +452,7 @@ static void s3c24x0_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd)
/* bus still busy probably by (most) previously interrupted
transfer */
-#ifdef CONFIG_S3C2410
+#if defined(CONFIG_S3C2410) || defined(CONFIG_S3C2440)
/* set I2CSDA and I2CSCL (GPE15, GPE14) to GPIO */
writel((readl(&gpio->gpecon) & ~0xF0000000) | 0x10000000,
&gpio->gpecon);
@@ -478,7 +478,7 @@ static void s3c24x0_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd)
udelay(1000);
/* restore pin functions */
-#ifdef CONFIG_S3C2410
+#if defined(CONFIG_S3C2410) || defined(CONFIG_S3C2440)
writel(old_gpecon, &gpio->gpecon);
#endif
#ifdef CONFIG_S3C2400
OpenPOWER on IntegriCloud