Haavard Skinnemoen | fd077f2 | 2008-09-01 14:00:07 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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 | fd077f2 | 2008-09-01 14:00:07 +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 | fd077f2 | 2008-09-01 14:00:07 +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 | /* Both pull-up and pull-down set means buskeeper */ |
| 16 | if (flags & PORTMUX_PULL_DOWN) |
| 17 | gpio_writel(port, PDERS, pin_mask); |
| 18 | else |
| 19 | gpio_writel(port, PDERC, pin_mask); |
| 20 | if (flags & PORTMUX_PULL_UP) |
| 21 | gpio_writel(port, PUERS, pin_mask); |
| 22 | else |
| 23 | gpio_writel(port, PUERC, pin_mask); |
| 24 | |
| 25 | /* Select drive strength */ |
| 26 | if (flags & PORTMUX_DRIVE_LOW) |
| 27 | gpio_writel(port, ODCR0S, pin_mask); |
| 28 | else |
| 29 | gpio_writel(port, ODCR0C, pin_mask); |
| 30 | if (flags & PORTMUX_DRIVE_HIGH) |
| 31 | gpio_writel(port, ODCR1S, pin_mask); |
| 32 | else |
| 33 | gpio_writel(port, ODCR1C, pin_mask); |
| 34 | |
| 35 | /* Select function */ |
| 36 | if (func & PORTMUX_FUNC_B) |
| 37 | gpio_writel(port, PMR0S, pin_mask); |
| 38 | else |
| 39 | gpio_writel(port, PMR0C, pin_mask); |
| 40 | if (func & PORTMUX_FUNC_C) |
| 41 | gpio_writel(port, PMR1S, pin_mask); |
| 42 | else |
| 43 | gpio_writel(port, PMR1C, pin_mask); |
| 44 | |
| 45 | /* Disable GPIO (i.e. enable peripheral) */ |
| 46 | gpio_writel(port, GPERC, pin_mask); |
| 47 | } |
| 48 | |
| 49 | void portmux_select_gpio(void *port, unsigned long pin_mask, |
| 50 | unsigned long flags) |
| 51 | { |
| 52 | /* Both pull-up and pull-down set means buskeeper */ |
| 53 | if (flags & PORTMUX_PULL_DOWN) |
| 54 | gpio_writel(port, PDERS, pin_mask); |
| 55 | else |
| 56 | gpio_writel(port, PDERC, pin_mask); |
| 57 | if (flags & PORTMUX_PULL_UP) |
| 58 | gpio_writel(port, PUERS, pin_mask); |
| 59 | else |
| 60 | gpio_writel(port, PUERC, pin_mask); |
| 61 | |
| 62 | /* Enable open-drain mode if requested */ |
| 63 | if (flags & PORTMUX_OPEN_DRAIN) |
| 64 | gpio_writel(port, ODMERS, pin_mask); |
| 65 | else |
| 66 | gpio_writel(port, ODMERC, pin_mask); |
| 67 | |
| 68 | /* Select drive strength */ |
| 69 | if (flags & PORTMUX_DRIVE_LOW) |
| 70 | gpio_writel(port, ODCR0S, pin_mask); |
| 71 | else |
| 72 | gpio_writel(port, ODCR0C, pin_mask); |
| 73 | if (flags & PORTMUX_DRIVE_HIGH) |
| 74 | gpio_writel(port, ODCR1S, pin_mask); |
| 75 | else |
| 76 | gpio_writel(port, ODCR1C, pin_mask); |
| 77 | |
| 78 | /* Select direction and initial pin state */ |
| 79 | if (flags & PORTMUX_DIR_OUTPUT) { |
| 80 | if (flags & PORTMUX_INIT_HIGH) |
| 81 | gpio_writel(port, OVRS, pin_mask); |
| 82 | else |
| 83 | gpio_writel(port, OVRC, pin_mask); |
| 84 | gpio_writel(port, ODERS, pin_mask); |
| 85 | } else { |
| 86 | gpio_writel(port, ODERC, pin_mask); |
| 87 | } |
| 88 | |
| 89 | /* Enable GPIO */ |
| 90 | gpio_writel(port, GPERS, pin_mask); |
| 91 | } |