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 | |
Benjamin Gaignard | a550b54 | 2018-11-27 13:49:50 +0100 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <hwspinlock.h> |
| 8 | #include <asm/state.h> |
| 9 | |
| 10 | static 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 | |
| 25 | static 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 | |
| 40 | static const struct hwspinlock_ops sandbox_hwspinlock_ops = { |
| 41 | .lock = sandbox_lock, |
| 42 | .unlock = sandbox_unlock, |
| 43 | }; |
| 44 | |
| 45 | static const struct udevice_id sandbox_hwspinlock_ids[] = { |
| 46 | { .compatible = "sandbox,hwspinlock" }, |
| 47 | {} |
| 48 | }; |
| 49 | |
| 50 | U_BOOT_DRIVER(hwspinlock_sandbox) = { |
| 51 | .name = "hwspinlock_sandbox", |
| 52 | .id = UCLASS_HWSPINLOCK, |
| 53 | .of_match = sandbox_hwspinlock_ids, |
| 54 | .ops = &sandbox_hwspinlock_ops, |
| 55 | }; |