brcm_scpi.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2019-2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef BRCM_SCPI_H
  7. #define BRCM_SCPI_H
  8. #include <stddef.h>
  9. #include <stdint.h>
  10. /*
  11. * An SCPI command consists of a header and a payload.
  12. * The following structure describes the header. It is 64-bit long.
  13. */
  14. typedef struct {
  15. /* Command ID */
  16. uint32_t id : 7;
  17. /* Set ID. Identifies whether this is a standard or extended command. */
  18. uint32_t set : 1;
  19. /* Sender ID to match a reply. The value is sender specific. */
  20. uint32_t sender : 8;
  21. /* Size of the payload in bytes (0 - 511) */
  22. uint32_t size : 9;
  23. uint32_t reserved : 7;
  24. /*
  25. * Status indicating the success of a command.
  26. * See the enum below.
  27. */
  28. uint32_t status;
  29. } scpi_cmd_t;
  30. typedef enum {
  31. SCPI_SET_NORMAL = 0, /* Normal SCPI commands */
  32. SCPI_SET_EXTENDED /* Extended SCPI commands */
  33. } scpi_set_t;
  34. enum {
  35. SCP_OK = 0, /* Success */
  36. SCP_E_PARAM, /* Invalid parameter(s) */
  37. SCP_E_ALIGN, /* Invalid alignment */
  38. SCP_E_SIZE, /* Invalid size */
  39. SCP_E_HANDLER, /* Invalid handler or callback */
  40. SCP_E_ACCESS, /* Invalid access or permission denied */
  41. SCP_E_RANGE, /* Value out of range */
  42. SCP_E_TIMEOUT, /* Time out has ocurred */
  43. SCP_E_NOMEM, /* Invalid memory area or pointer */
  44. SCP_E_PWRSTATE, /* Invalid power state */
  45. SCP_E_SUPPORT, /* Feature not supported or disabled */
  46. SCPI_E_DEVICE, /* Device error */
  47. SCPI_E_BUSY, /* Device is busy */
  48. };
  49. typedef uint32_t scpi_status_t;
  50. typedef enum {
  51. SCPI_CMD_SCP_READY = 0x01,
  52. SCPI_CMD_SET_POWER_STATE = 0x03,
  53. SCPI_CMD_GET_POWER_STATE = 0x04,
  54. SCPI_CMD_SYS_POWER_STATE = 0x05
  55. } scpi_command_t;
  56. /*
  57. * Macros to parse SCP response to GET_POWER_STATE command
  58. *
  59. * [3:0] : cluster ID
  60. * [7:4] : cluster state: 0 = on; 3 = off; rest are reserved
  61. * [15:8]: on/off state for individual CPUs in the cluster
  62. *
  63. * Payload is in little-endian
  64. */
  65. #define CLUSTER_ID(_resp) ((_resp) & 0xf)
  66. #define CLUSTER_POWER_STATE(_resp) (((_resp) >> 4) & 0xf)
  67. /* Result is a bit mask of CPU on/off states in the cluster */
  68. #define CPU_POWER_STATE(_resp) (((_resp) >> 8) & 0xff)
  69. /*
  70. * For GET_POWER_STATE, SCP returns the power states of every cluster. The
  71. * size of response depends on the number of clusters in the system. The
  72. * SCP-to-AP payload contains 2 bytes per cluster. Make sure the response is
  73. * large enough to contain power states of a given cluster
  74. */
  75. #define CHECK_RESPONSE(_resp, _clus) (_resp.size >= (((_clus) + 1) * 2))
  76. typedef enum {
  77. scpi_power_on = 0,
  78. scpi_power_retention = 1,
  79. scpi_power_off = 3,
  80. } scpi_power_state_t;
  81. typedef enum {
  82. scpi_system_shutdown = 0,
  83. scpi_system_reboot = 1,
  84. scpi_system_reset = 2
  85. } scpi_system_state_t;
  86. extern int scpi_wait_ready(void);
  87. extern void scpi_set_brcm_power_state(unsigned int mpidr,
  88. scpi_power_state_t cpu_state,
  89. scpi_power_state_t cluster_state,
  90. scpi_power_state_t css_state);
  91. int scpi_get_brcm_power_state(unsigned int mpidr, unsigned int *cpu_state_p,
  92. unsigned int *cluster_state_p);
  93. uint32_t scpi_sys_power_state(scpi_system_state_t system_state);
  94. #endif /* BRCM_SCPI_H */