]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/arm/mach-mvebu/pm-board.c
2 * Board-level suspend/resume support.
4 * Copyright (C) 2014-2015 Marvell
6 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
13 #include <linux/delay.h>
14 #include <linux/gpio.h>
15 #include <linux/init.h>
18 #include <linux/of_address.h>
19 #include <linux/of_gpio.h>
20 #include <linux/slab.h>
23 #define ARMADA_PIC_NR_GPIOS 3
25 static void __iomem
*gpio_ctrl
;
26 static int pic_gpios
[ARMADA_PIC_NR_GPIOS
];
27 static int pic_raw_gpios
[ARMADA_PIC_NR_GPIOS
];
29 static void mvebu_armada_pm_enter(void __iomem
*sdram_reg
, u32 srcmd
)
34 /* Put 001 as value on the GPIOs */
35 reg
= readl(gpio_ctrl
);
36 for (i
= 0; i
< ARMADA_PIC_NR_GPIOS
; i
++)
37 reg
&= ~BIT(pic_raw_gpios
[i
]);
38 reg
|= BIT(pic_raw_gpios
[0]);
39 writel(reg
, gpio_ctrl
);
41 /* Prepare writing 111 to the GPIOs */
42 ackcmd
= readl(gpio_ctrl
);
43 for (i
= 0; i
< ARMADA_PIC_NR_GPIOS
; i
++)
44 ackcmd
|= BIT(pic_raw_gpios
[i
]);
46 srcmd
= cpu_to_le32(srcmd
);
47 ackcmd
= cpu_to_le32(ackcmd
);
50 * Wait a while, the PIC needs quite a bit of time between the
56 /* Align to a cache line */
59 /* Enter self refresh */
60 "str %[srcmd], [%[sdram_reg]]\n\t"
63 * Wait 100 cycles for DDR to enter self refresh, by
64 * doing 50 times two instructions.
67 "1: subs r1, r1, #1\n\t"
70 /* Issue the command ACK */
71 "str %[ackcmd], [%[gpio_ctrl]]\n\t"
73 /* Trap the processor */
75 : : [srcmd
] "r" (srcmd
), [sdram_reg
] "r" (sdram_reg
),
76 [ackcmd
] "r" (ackcmd
), [gpio_ctrl
] "r" (gpio_ctrl
) : "r1");
79 static int __init
mvebu_armada_pm_init(void)
81 struct device_node
*np
;
82 struct device_node
*gpio_ctrl_np
;
85 if (!of_machine_is_compatible("marvell,axp-gp"))
88 np
= of_find_node_by_name(NULL
, "pm_pic");
92 for (i
= 0; i
< ARMADA_PIC_NR_GPIOS
; i
++) {
94 struct of_phandle_args args
;
96 pic_gpios
[i
] = of_get_named_gpio(np
, "ctrl-gpios", i
);
97 if (pic_gpios
[i
] < 0) {
102 name
= kasprintf(GFP_KERNEL
, "pic-pin%d", i
);
108 ret
= gpio_request(pic_gpios
[i
], name
);
114 ret
= gpio_direction_output(pic_gpios
[i
], 0);
116 gpio_free(pic_gpios
[i
]);
121 ret
= of_parse_phandle_with_fixed_args(np
, "ctrl-gpios", 2,
124 gpio_free(pic_gpios
[i
]);
129 gpio_ctrl_np
= args
.np
;
130 pic_raw_gpios
[i
] = args
.args
[0];
133 gpio_ctrl
= of_iomap(gpio_ctrl_np
, 0);
137 mvebu_pm_suspend_init(mvebu_armada_pm_enter
);
145 * Registering the mvebu_board_pm_enter callback must be done before
146 * the platform_suspend_ops will be registered. In the same time we
147 * also need to have the gpio devices registered. That's why we use a
148 * device_initcall_sync which is called after all the device_initcall
149 * (used by the gpio device) but before the late_initcall (used to
150 * register the platform_suspend_ops)
152 device_initcall_sync(mvebu_armada_pm_init
);