Lars Povlsen | e58031a | 2018-12-20 09:56:03 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0+ OR MIT) |
| 2 | /* |
| 3 | * Copyright (c) 2018 Microsemi Corporation |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <asm/io.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 8 | #include <linux/bitops.h> |
Lars Povlsen | e58031a | 2018-12-20 09:56:03 +0100 | [diff] [blame] | 9 | |
| 10 | void mscc_gpio_set_alternate(int gpio, int mode) |
| 11 | { |
| 12 | u32 mask = BIT(gpio); |
| 13 | u32 val0, val1; |
| 14 | |
| 15 | val0 = readl(BASE_DEVCPU_GCB + GPIO_ALT(0)); |
| 16 | val1 = readl(BASE_DEVCPU_GCB + GPIO_ALT(1)); |
| 17 | |
| 18 | if (mode == 1) { |
| 19 | val0 |= mask; |
| 20 | val1 &= ~mask; |
| 21 | } else if (mode == 2) { |
| 22 | val0 &= ~mask; |
| 23 | val1 |= mask; |
| 24 | } else if (mode == 3) { |
| 25 | val0 |= mask; |
| 26 | val1 |= mask; |
| 27 | } else { |
| 28 | val0 &= ~mask; |
| 29 | val1 &= ~mask; |
| 30 | } |
| 31 | |
| 32 | writel(val0, BASE_DEVCPU_GCB + GPIO_ALT(0)); |
| 33 | writel(val1, BASE_DEVCPU_GCB + GPIO_ALT(1)); |
| 34 | } |