diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gpio/Makefile | 1 | ||||
-rw-r--r-- | drivers/gpio/mx31_gpio.c | 15 | ||||
-rw-r--r-- | drivers/gpio/s5p_gpio.c | 143 | ||||
-rw-r--r-- | drivers/serial/Makefile | 2 | ||||
-rw-r--r-- | drivers/serial/serial_s5p.c (renamed from drivers/serial/serial_s5pc1xx.c) | 30 |
5 files changed, 175 insertions, 16 deletions
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index d9660820bd..528ca2e99a 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -29,6 +29,7 @@ COBJS-$(CONFIG_AT91_GPIO) += at91_gpio.o COBJS-$(CONFIG_KIRKWOOD_GPIO) += kw_gpio.o COBJS-$(CONFIG_MX31_GPIO) += mx31_gpio.o COBJS-$(CONFIG_PCA953X) += pca953x.o +COBJS-$(CONFIG_S5PC1XX) += s5p_gpio.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c) diff --git a/drivers/gpio/mx31_gpio.c b/drivers/gpio/mx31_gpio.c index 737aafa822..b07f038156 100644 --- a/drivers/gpio/mx31_gpio.c +++ b/drivers/gpio/mx31_gpio.c @@ -71,3 +71,18 @@ void mx31_gpio_set(unsigned int gpio, unsigned int value) l &= ~(1 << gpio); __REG(gpio_ports[port] + GPIO_DR) = l; } + +int mx31_gpio_get(unsigned int gpio) +{ + unsigned int port = gpio >> 5; + u32 l; + + if (port >= ARRAY_SIZE(gpio_ports)) + return -1; + + gpio &= 0x1f; + + l = (__REG(gpio_ports[port] + GPIO_DR) >> gpio) & 0x01; + + return l; +} diff --git a/drivers/gpio/s5p_gpio.c b/drivers/gpio/s5p_gpio.c new file mode 100644 index 0000000000..0439477e46 --- /dev/null +++ b/drivers/gpio/s5p_gpio.c @@ -0,0 +1,143 @@ +/* + * (C) Copyright 2009 Samsung Electronics + * Minkyu Kang <mk7.kang@samsung.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <common.h> +#include <asm/io.h> +#include <asm/arch/gpio.h> + +#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)) + +void gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg) +{ + unsigned int value; + + value = readl(&bank->con); + value &= ~CON_MASK(gpio); + value |= CON_SFR(gpio, cfg); + writel(value, &bank->con); +} + +void gpio_direction_output(struct s5p_gpio_bank *bank, int gpio, int en) +{ + unsigned int value; + + gpio_cfg_pin(bank, gpio, GPIO_OUTPUT); + + value = readl(&bank->dat); + value &= ~DAT_MASK(gpio); + if (en) + value |= DAT_SET(gpio); + writel(value, &bank->dat); +} + +void gpio_direction_input(struct s5p_gpio_bank *bank, int gpio) +{ + gpio_cfg_pin(bank, gpio, GPIO_INPUT); +} + +void gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en) +{ + unsigned int value; + + value = readl(&bank->dat); + value &= ~DAT_MASK(gpio); + if (en) + value |= DAT_SET(gpio); + writel(value, &bank->dat); +} + +unsigned int gpio_get_value(struct s5p_gpio_bank *bank, int gpio) +{ + unsigned int value; + + value = readl(&bank->dat); + return !!(value & DAT_MASK(gpio)); +} + +void gpio_set_pull(struct s5p_gpio_bank *bank, int gpio, int mode) +{ + unsigned int value; + + value = readl(&bank->pull); + value &= ~PULL_MASK(gpio); + + switch (mode) { + case GPIO_PULL_DOWN: + case GPIO_PULL_UP: + value |= PULL_MODE(gpio, mode); + break; + default: + return; + } + + writel(value, &bank->pull); +} + +void gpio_set_drv(struct s5p_gpio_bank *bank, int gpio, int mode) +{ + unsigned int value; + + value = readl(&bank->drv); + value &= ~DRV_MASK(gpio); + + switch (mode) { + case GPIO_DRV_1X: + case GPIO_DRV_2X: + case GPIO_DRV_3X: + case GPIO_DRV_4X: + value |= DRV_SET(gpio, mode); + break; + default: + return; + } + + writel(value, &bank->drv); +} + +void gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode) +{ + unsigned int value; + + value = readl(&bank->drv); + value &= ~RATE_MASK(gpio); + + switch (mode) { + case GPIO_DRV_FAST: + case GPIO_DRV_SLOW: + value |= RATE_SET(gpio); + break; + default: + return; + } + + writel(value, &bank->drv); +} diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index d2b4820b6f..c731bfb594 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile @@ -36,7 +36,7 @@ COBJS-$(CONFIG_OPENCORES_YANU) += opencores_yanu.o COBJS-$(CONFIG_SYS_NS16550) += ns16550.o COBJS-$(CONFIG_DRIVER_S3C4510_UART) += s3c4510b_uart.o COBJS-$(CONFIG_S3C64XX) += s3c64xx.o -COBJS-$(CONFIG_S5PC1XX) += serial_s5pc1xx.o +COBJS-$(CONFIG_S5PC1XX) += serial_s5p.o COBJS-$(CONFIG_SYS_NS16550_SERIAL) += serial.o COBJS-$(CONFIG_CLPS7111_SERIAL) += serial_clps7111.o COBJS-$(CONFIG_IMX_SERIAL) += serial_imx.o diff --git a/drivers/serial/serial_s5pc1xx.c b/drivers/serial/serial_s5p.c index 8da0c8606d..9747db3721 100644 --- a/drivers/serial/serial_s5pc1xx.c +++ b/drivers/serial/serial_s5p.c @@ -27,18 +27,18 @@ #include <asm/arch/clk.h> #include <serial.h> -static inline struct s5pc1xx_uart *s5pc1xx_get_base_uart(int dev_index) +static inline struct s5p_uart *s5p_get_base_uart(int dev_index) { - u32 offset = dev_index * sizeof(struct s5pc1xx_uart); + u32 offset = dev_index * sizeof(struct s5p_uart); if (cpu_is_s5pc100()) - return (struct s5pc1xx_uart *)(S5PC100_UART_BASE + offset); + return (struct s5p_uart *)(S5PC100_UART_BASE + offset); else - return (struct s5pc1xx_uart *)(S5PC110_UART_BASE + offset); + return (struct s5p_uart *)(S5PC110_UART_BASE + offset); } /* - * The coefficient, used to calculate the baudrate on S5PC1XX UARTs is + * The coefficient, used to calculate the baudrate on S5P UARTs is * calculated as * C = UBRDIV * 16 + number_of_set_bits_in_UDIVSLOT * however, section 31.6.11 of the datasheet doesn't recomment using 1 for 1, @@ -66,7 +66,7 @@ static const int udivslot[] = { void serial_setbrg_dev(const int dev_index) { DECLARE_GLOBAL_DATA_PTR; - struct s5pc1xx_uart *const uart = s5pc1xx_get_base_uart(dev_index); + struct s5p_uart *const uart = s5p_get_base_uart(dev_index); u32 pclk = get_pclk(); u32 baudrate = gd->baudrate; u32 val; @@ -83,7 +83,7 @@ void serial_setbrg_dev(const int dev_index) */ int serial_init_dev(const int dev_index) { - struct s5pc1xx_uart *const uart = s5pc1xx_get_base_uart(dev_index); + struct s5p_uart *const uart = s5p_get_base_uart(dev_index); /* reset and enable FIFOs, set triggers to the maximum */ writel(0, &uart->ufcon); @@ -100,7 +100,7 @@ int serial_init_dev(const int dev_index) static int serial_err_check(const int dev_index, int op) { - struct s5pc1xx_uart *const uart = s5pc1xx_get_base_uart(dev_index); + struct s5p_uart *const uart = s5p_get_base_uart(dev_index); unsigned int mask; /* @@ -125,7 +125,7 @@ static int serial_err_check(const int dev_index, int op) */ int serial_getc_dev(const int dev_index) { - struct s5pc1xx_uart *const uart = s5pc1xx_get_base_uart(dev_index); + struct s5p_uart *const uart = s5p_get_base_uart(dev_index); /* wait for character to arrive */ while (!(readl(&uart->utrstat) & 0x1)) { @@ -141,7 +141,7 @@ int serial_getc_dev(const int dev_index) */ void serial_putc_dev(const char c, const int dev_index) { - struct s5pc1xx_uart *const uart = s5pc1xx_get_base_uart(dev_index); + struct s5p_uart *const uart = s5p_get_base_uart(dev_index); /* wait for room in the tx FIFO */ while (!(readl(&uart->utrstat) & 0x2)) { @@ -161,7 +161,7 @@ void serial_putc_dev(const char c, const int dev_index) */ int serial_tstc_dev(const int dev_index) { - struct s5pc1xx_uart *const uart = s5pc1xx_get_base_uart(dev_index); + struct s5p_uart *const uart = s5p_get_base_uart(dev_index); return (int)(readl(&uart->utrstat) & 0x1); } @@ -193,14 +193,14 @@ void s5p_serial##port##_puts(const char *s) { serial_puts_dev(s, port); } s5p_serial##port##_puts, } DECLARE_S5P_SERIAL_FUNCTIONS(0); -struct serial_device s5pc1xx_serial0_device = +struct serial_device s5p_serial0_device = INIT_S5P_SERIAL_STRUCTURE(0, "s5pser0", "S5PUART0"); DECLARE_S5P_SERIAL_FUNCTIONS(1); -struct serial_device s5pc1xx_serial1_device = +struct serial_device s5p_serial1_device = INIT_S5P_SERIAL_STRUCTURE(1, "s5pser1", "S5PUART1"); DECLARE_S5P_SERIAL_FUNCTIONS(2); -struct serial_device s5pc1xx_serial2_device = +struct serial_device s5p_serial2_device = INIT_S5P_SERIAL_STRUCTURE(2, "s5pser2", "S5PUART2"); DECLARE_S5P_SERIAL_FUNCTIONS(3); -struct serial_device s5pc1xx_serial3_device = +struct serial_device s5p_serial3_device = INIT_S5P_SERIAL_STRUCTURE(3, "s5pser3", "S5PUART3"); |