summaryrefslogtreecommitdiff
path: root/drivers/hwspinlock/sandbox_hwspinlock.c
blob: be920f5f99dfba4850bf3480cb9dc4433f8b04af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
/*
 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
 */

#include <common.h>
#include <dm.h>
#include <hwspinlock.h>
#include <asm/state.h>

static int sandbox_lock(struct udevice *dev, int index)
{
	struct sandbox_state *state = state_get_current();

	if (index != 0)
		return -1;

	if (state->hwspinlock)
		return -1;

	state->hwspinlock = true;

	return 0;
}

static int sandbox_unlock(struct udevice *dev, int index)
{
	struct sandbox_state *state = state_get_current();

	if (index != 0)
		return -1;

	if (!state->hwspinlock)
		return -1;

	state->hwspinlock = false;

	return 0;
}

static const struct hwspinlock_ops sandbox_hwspinlock_ops = {
	.lock = sandbox_lock,
	.unlock = sandbox_unlock,
};

static const struct udevice_id sandbox_hwspinlock_ids[] = {
	{ .compatible = "sandbox,hwspinlock" },
	{}
};

U_BOOT_DRIVER(hwspinlock_sandbox) = {
	.name = "hwspinlock_sandbox",
	.id = UCLASS_HWSPINLOCK,
	.of_match = sandbox_hwspinlock_ids,
	.ops = &sandbox_hwspinlock_ops,
};