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