Skip to content

Commit

Permalink
mips: mscc: Add generic GPIO control utility function
Browse files Browse the repository at this point in the history
The GPIO control function can be used for controlling alternate
functions associated with a GPIO.

Signed-off-by: Lars Povlsen <[email protected]>
  • Loading branch information
lpovlsen authored and danielschwierzeck committed Jan 16, 2019
1 parent 3098ade commit e58031a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion arch/mips/mach-mscc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

CFLAGS_cpu.o += -finline-limit=64000

obj-y += cpu.o dram.o reset.o phy.o lowlevel_init.o
obj-y += cpu.o dram.o reset.o phy.o gpio.o lowlevel_init.o
obj-$(CONFIG_SOC_LUTON) += lowlevel_init_luton.o
33 changes: 33 additions & 0 deletions arch/mips/mach-mscc/gpio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
* Copyright (c) 2018 Microsemi Corporation
*/

#include <common.h>
#include <asm/io.h>

void mscc_gpio_set_alternate(int gpio, int mode)
{
u32 mask = BIT(gpio);
u32 val0, val1;

val0 = readl(BASE_DEVCPU_GCB + GPIO_ALT(0));
val1 = readl(BASE_DEVCPU_GCB + GPIO_ALT(1));

if (mode == 1) {
val0 |= mask;
val1 &= ~mask;
} else if (mode == 2) {
val0 &= ~mask;
val1 |= mask;
} else if (mode == 3) {
val0 |= mask;
val1 |= mask;
} else {
val0 &= ~mask;
val1 &= ~mask;
}

writel(val0, BASE_DEVCPU_GCB + GPIO_ALT(0));
writel(val1, BASE_DEVCPU_GCB + GPIO_ALT(1));
}
2 changes: 2 additions & 0 deletions arch/mips/mach-mscc/include/mach/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ int mscc_phy_wr(u32 miim_controller,
u8 addr,
u16 value);

void mscc_gpio_set_alternate(int gpio, int mode);

#endif /* __ASM_MACH_COMMON_H */
2 changes: 2 additions & 0 deletions arch/mips/mach-mscc/include/mach/luton/luton_devcpu_gcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
#define PERF_SOFT_RST_SOFT_SWC_RST BIT(1)
#define PERF_SOFT_RST_SOFT_CHIP_RST BIT(0)

#define GPIO_ALT(x) (0x88 + 4 * (x))

#endif
2 changes: 2 additions & 0 deletions arch/mips/mach-mscc/include/mach/ocelot/ocelot_devcpu_gcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@

#define PERF_GPIO_OE 0x44

#define GPIO_ALT(x) (0x54 + 4 * (x))

#endif

0 comments on commit e58031a

Please sign in to comment.