1 // SPDX-License-Identifier: GPL-2.0-only
3 * Board-level suspend/resume support.
5 * Copyright (C) 2014-2015 Marvell
7 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
10 #include <linux/delay.h>
11 #include <linux/gpio.h>
12 #include <linux/init.h>
15 #include <linux/of_address.h>
16 #include <linux/of_gpio.h>
17 #include <linux/slab.h>
20 #define ARMADA_PIC_NR_GPIOS 3
22 static void __iomem *gpio_ctrl;
23 static int pic_gpios[ARMADA_PIC_NR_GPIOS];
24 static int pic_raw_gpios[ARMADA_PIC_NR_GPIOS];
26 static void mvebu_armada_pm_enter(void __iomem *sdram_reg, u32 srcmd)
31 /* Put 001 as value on the GPIOs */
32 reg = readl(gpio_ctrl);
33 for (i = 0; i < ARMADA_PIC_NR_GPIOS; i++)
34 reg &= ~BIT(pic_raw_gpios[i]);
35 reg |= BIT(pic_raw_gpios[0]);
36 writel(reg, gpio_ctrl);
38 /* Prepare writing 111 to the GPIOs */
39 ackcmd = readl(gpio_ctrl);
40 for (i = 0; i < ARMADA_PIC_NR_GPIOS; i++)
41 ackcmd |= BIT(pic_raw_gpios[i]);
43 srcmd = cpu_to_le32(srcmd);
44 ackcmd = cpu_to_le32(ackcmd);
47 * Wait a while, the PIC needs quite a bit of time between the
53 /* Align to a cache line */
56 /* Enter self refresh */
57 "str %[srcmd], [%[sdram_reg]]\n\t"
60 * Wait 100 cycles for DDR to enter self refresh, by
61 * doing 50 times two instructions.
64 "1: subs r1, r1, #1\n\t"
67 /* Issue the command ACK */
68 "str %[ackcmd], [%[gpio_ctrl]]\n\t"
70 /* Trap the processor */
72 : : [srcmd] "r" (srcmd), [sdram_reg] "r" (sdram_reg),
73 [ackcmd] "r" (ackcmd), [gpio_ctrl] "r" (gpio_ctrl) : "r1");
76 static int __init mvebu_armada_pm_init(void)
78 struct device_node *np;
79 struct device_node *gpio_ctrl_np = NULL;
82 if (!of_machine_is_compatible("marvell,axp-gp"))
85 np = of_find_node_by_name(NULL, "pm_pic");
89 for (i = 0; i < ARMADA_PIC_NR_GPIOS; i++) {
91 struct of_phandle_args args;
93 pic_gpios[i] = of_get_named_gpio(np, "ctrl-gpios", i);
94 if (pic_gpios[i] < 0) {
99 name = kasprintf(GFP_KERNEL, "pic-pin%d", i);
105 ret = gpio_request(pic_gpios[i], name);
111 ret = gpio_direction_output(pic_gpios[i], 0);
113 gpio_free(pic_gpios[i]);
118 ret = of_parse_phandle_with_fixed_args(np, "ctrl-gpios", 2,
121 gpio_free(pic_gpios[i]);
127 of_node_put(gpio_ctrl_np);
128 gpio_ctrl_np = args.np;
129 pic_raw_gpios[i] = args.args[0];
132 gpio_ctrl = of_iomap(gpio_ctrl_np, 0);
138 mvebu_pm_suspend_init(mvebu_armada_pm_enter);
142 of_node_put(gpio_ctrl_np);
147 * Registering the mvebu_board_pm_enter callback must be done before
148 * the platform_suspend_ops will be registered. In the same time we
149 * also need to have the gpio devices registered. That's why we use a
150 * device_initcall_sync which is called after all the device_initcall
151 * (used by the gpio device) but before the late_initcall (used to
152 * register the platform_suspend_ops)
154 device_initcall_sync(mvebu_armada_pm_init);