blob: d6b4c5d7684bfb9427c90f148df1ef9dc21665a6 [file] [log] [blame]
Lars Povlsen585078f2018-12-20 09:56:03 +01001// 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 Glass4dcacfc2020-05-10 11:40:13 -06008#include <linux/bitops.h>
Lars Povlsen585078f2018-12-20 09:56:03 +01009
10void 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}