From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heiko Schocher Date: Wed, 17 Aug 2016 09:13:27 +0200 Subject: [U-Boot] [PATCH 5/6] at91: add function to set IO drive In-Reply-To: <1471418009-12660-1-git-send-email-hs@denx.de> References: <1471418009-12660-1-git-send-email-hs@denx.de> Message-ID: <1471418009-12660-6-git-send-email-hs@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de add new function to set I/O drive. Signed-off-by: Heiko Schocher --- arch/arm/mach-at91/include/mach/at91_pio.h | 5 +++++ arch/arm/mach-at91/include/mach/gpio.h | 2 ++ drivers/gpio/at91_gpio.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/arch/arm/mach-at91/include/mach/at91_pio.h b/arch/arm/mach-at91/include/mach/at91_pio.h index 8e054e1..535208a 100644 --- a/arch/arm/mach-at91/include/mach/at91_pio.h +++ b/arch/arm/mach-at91/include/mach/at91_pio.h @@ -134,6 +134,7 @@ int at91_set_pio_debounce(unsigned port, unsigned pin, int is_on, int div); int at91_set_pio_pulldown(unsigned port, unsigned pin, int is_on); int at91_set_pio_disable_schmitt_trig(unsigned port, unsigned pin); #endif +int at91_set_pio_io_drive(unsigned port, unsigned pin, int value); int at91_set_pio_input(unsigned port, unsigned pin, int use_pullup); int at91_set_pio_multi_drive(unsigned port, unsigned pin, int is_on); int at91_set_pio_output(unsigned port, unsigned pin, int value); @@ -151,4 +152,8 @@ int at91_get_pio_value(unsigned port, unsigned pin); #define AT91_PIO_PORTD 0x3 #define AT91_PIO_PORTE 0x4 +/* allowed I/O driver values */ +#define AT91_PIO_HI_DRIVE 0 +#define AT91_PIO_MEDIUM_DRIVE 1 +#define AT91_PIO_LOW_DRIVE 2 #endif diff --git a/arch/arm/mach-at91/include/mach/gpio.h b/arch/arm/mach-at91/include/mach/gpio.h index 6d2a7b7..2b89309 100644 --- a/arch/arm/mach-at91/include/mach/gpio.h +++ b/arch/arm/mach-at91/include/mach/gpio.h @@ -227,6 +227,8 @@ static inline unsigned pin_to_mask(unsigned pin) at91_set_pio_value((x - PIN_BASE) / 32,(x % 32), y) #define at91_get_gpio_value(x) \ at91_get_pio_value((x - PIN_BASE) / 32,(x % 32)) +#define at91_set_gpio_io_drive(x, v) \ + at91_set_pio_io_drive((x - PIN_BASE) / 32,(x % 32), v) #else #define at91_set_gpio_value(x, y) at91_set_pio_value(x, y) #define at91_get_gpio_value(x) at91_get_pio_value(x) diff --git a/drivers/gpio/at91_gpio.c b/drivers/gpio/at91_gpio.c index 8e52e3d..1f624f8 100644 --- a/drivers/gpio/at91_gpio.c +++ b/drivers/gpio/at91_gpio.c @@ -358,6 +358,35 @@ int at91_set_pio_multi_drive(unsigned port, unsigned pin, int is_on) return 0; } +#if defined(CPU_HAS_PIO3) +/* + * set I/O driver value + */ +int at91_set_pio_io_drive(unsigned port, unsigned pin, int value) +{ + struct at91_port *at91_port = at91_pio_get_port(port); + u32 *reg; + u32 mask; + + if (pin > 15) { + reg = &at91_port->io_driver2; + pin -= 16; + } else { + reg = &at91_port->io_driver1; + } + + mask = 0x3 << (pin * 2); + clrsetbits_le32(reg, mask, value << (pin * 2)); + return 0; +} +#else +int at91_set_pio_io_drive(unsigned port, unsigned pin, int value) +{ + return -ENOENT; +} +#endif + + static void at91_set_port_value(struct at91_port *at91_port, int offset, int value) { -- 2.5.5