blob: fcda55517e1e74678145c9c234f7a09d5c04c531 [file] [log] [blame]
Benjamin Gaignarda550b542018-11-27 13:49:50 +01001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
4 */
5
Benjamin Gaignarda550b542018-11-27 13:49:50 +01006#include <dm.h>
7#include <hwspinlock.h>
8#include <asm/state.h>
9
10static int sandbox_lock(struct udevice *dev, int index)
11{
12 struct sandbox_state *state = state_get_current();
13
14 if (index != 0)
15 return -1;
16
17 if (state->hwspinlock)
18 return -1;
19
20 state->hwspinlock = true;
21
22 return 0;
23}
24
25static int sandbox_unlock(struct udevice *dev, int index)
26{
27 struct sandbox_state *state = state_get_current();
28
29 if (index != 0)
30 return -1;
31
32 if (!state->hwspinlock)
33 return -1;
34
35 state->hwspinlock = false;
36
37 return 0;
38}
39
40static const struct hwspinlock_ops sandbox_hwspinlock_ops = {
41 .lock = sandbox_lock,
42 .unlock = sandbox_unlock,
43};
44
45static const struct udevice_id sandbox_hwspinlock_ids[] = {
46 { .compatible = "sandbox,hwspinlock" },
47 {}
48};
49
50U_BOOT_DRIVER(hwspinlock_sandbox) = {
51 .name = "hwspinlock_sandbox",
52 .id = UCLASS_HWSPINLOCK,
53 .of_match = sandbox_hwspinlock_ids,
54 .ops = &sandbox_hwspinlock_ops,
55};