sandbox_hwspinlock.c 1.0 KB

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