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