Haavard Skinnemoen | 610b362 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006, 2008 Atmel Corporation |
| 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Haavard Skinnemoen | 610b362 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 5 | */ |
| 6 | #include <common.h> |
| 7 | |
| 8 | #include <asm/io.h> |
Andreas Bießmann | 94156fa | 2010-11-04 23:15:30 +0000 | [diff] [blame] | 9 | #include <asm/arch/hardware.h> |
Haavard Skinnemoen | 610b362 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 10 | #include <asm/arch/gpio.h> |
| 11 | |
| 12 | void portmux_select_peripheral(void *port, unsigned long pin_mask, |
| 13 | enum portmux_function func, unsigned long flags) |
| 14 | { |
| 15 | if (flags & PORTMUX_PULL_UP) |
| 16 | pio_writel(port, PUER, pin_mask); |
| 17 | else |
| 18 | pio_writel(port, PUDR, pin_mask); |
| 19 | |
| 20 | switch (func) { |
| 21 | case PORTMUX_FUNC_A: |
| 22 | pio_writel(port, ASR, pin_mask); |
| 23 | break; |
| 24 | case PORTMUX_FUNC_B: |
| 25 | pio_writel(port, BSR, pin_mask); |
| 26 | break; |
| 27 | } |
| 28 | |
| 29 | pio_writel(port, PDR, pin_mask); |
| 30 | } |
| 31 | |
| 32 | void portmux_select_gpio(void *port, unsigned long pin_mask, |
| 33 | unsigned long flags) |
| 34 | { |
| 35 | if (flags & PORTMUX_PULL_UP) |
| 36 | pio_writel(port, PUER, pin_mask); |
| 37 | else |
| 38 | pio_writel(port, PUDR, pin_mask); |
| 39 | |
| 40 | if (flags & PORTMUX_OPEN_DRAIN) |
| 41 | pio_writel(port, MDER, pin_mask); |
| 42 | else |
| 43 | pio_writel(port, MDDR, pin_mask); |
| 44 | |
| 45 | if (flags & PORTMUX_DIR_OUTPUT) { |
| 46 | if (flags & PORTMUX_INIT_HIGH) |
| 47 | pio_writel(port, SODR, pin_mask); |
| 48 | else |
| 49 | pio_writel(port, CODR, pin_mask); |
| 50 | pio_writel(port, OER, pin_mask); |
| 51 | } else { |
| 52 | pio_writel(port, ODR, pin_mask); |
| 53 | } |
| 54 | |
| 55 | pio_writel(port, PER, pin_mask); |
| 56 | } |
| 57 | |
| 58 | void pio_set_output_value(unsigned int pin, int value) |
| 59 | { |
| 60 | void *port = pio_pin_to_port(pin); |
| 61 | |
| 62 | if (!port) |
| 63 | panic("Invalid GPIO pin %u\n", pin); |
| 64 | |
| 65 | __pio_set_output_value(port, pin & 0x1f, value); |
| 66 | } |
| 67 | |
| 68 | int pio_get_input_value(unsigned int pin) |
| 69 | { |
| 70 | void *port = pio_pin_to_port(pin); |
| 71 | |
| 72 | if (!port) |
| 73 | panic("Invalid GPIO pin %u\n", pin); |
| 74 | |
| 75 | return __pio_get_input_value(port, pin & 0x1f); |
| 76 | } |