Ramesh Yadav Javadi | 43ff877 | 2018-04-06 13:13:53 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef BGCOM_H |
| 15 | #define BGCOM_H |
| 16 | |
| 17 | #define BGCOM_REG_TZ_TO_MASTER_STATUS 0x01 |
| 18 | #define BGCOM_REG_TZ_TO_MASTER_DATA 0x03 |
| 19 | #define BGCOM_REG_SLAVE_STATUS 0x05 |
| 20 | #define BGCOM_REG_TIMESTAMP 0x07 |
| 21 | #define BGCOM_REG_SLAVE_STATUS_AUTO_CLEAR 0x09 |
| 22 | #define BGCOM_REG_FIFO_FILL 0x0B |
| 23 | #define BGCOM_REG_FIFO_SIZE 0x0D |
| 24 | #define BGCOM_REG_TZ_TO_SLAVE_COMMAND 0x0E |
| 25 | #define BGCOM_REG_TZ_TO_SLAVE_DATA 0x10 |
| 26 | #define BGCOM_REG_MASTER_STATUS 0x12 |
| 27 | #define BGCOM_REG_MASTER_COMMAND 0x14 |
| 28 | #define BGCOM_REG_MSG_WR_REG_4 0x16 |
| 29 | #define BGCOM_REG_TO_SLAVE_FIFO 0x40 |
| 30 | #define BGCOM_REG_TO_MASTER_FIFO 0x41 |
| 31 | #define BGCOM_REG_TO_SLAVE_AHB 0x42 |
| 32 | #define BGCOM_REG_TO_MASTER_AHB 0x43 |
| 33 | |
| 34 | /* Enum to define the bgcom SPI state */ |
| 35 | enum bgcom_spi_state { |
| 36 | BGCOM_SPI_FREE = 0, |
| 37 | BGCOM_SPI_BUSY, |
| 38 | }; |
| 39 | |
| 40 | /* Enums to identify Blackghost events */ |
| 41 | enum bgcom_event_type { |
| 42 | BGCOM_EVENT_NONE = 0, |
| 43 | BGCOM_EVENT_APPLICATION_RUNNING, |
| 44 | BGCOM_EVENT_TO_SLAVE_FIFO_READY, |
| 45 | BGCOM_EVENT_TO_MASTER_FIFO_READY, |
| 46 | BGCOM_EVENT_AHB_READY, |
| 47 | BGCOM_EVENT_TO_MASTER_FIFO_USED, |
| 48 | BGCOM_EVENT_TO_SLAVE_FIFO_FREE, |
| 49 | BGCOM_EVENT_TIMESTAMP_UPDATE, |
| 50 | BGCOM_EVENT_RESET_OCCURRED, |
| 51 | |
| 52 | BGCOM_EVENT_ERROR_WRITE_FIFO_OVERRUN, |
| 53 | BGCOM_EVENT_ERROR_WRITE_FIFO_BUS_ERR, |
| 54 | BGCOM_EVENT_ERROR_WRITE_FIFO_ACCESS, |
| 55 | BGCOM_EVENT_ERROR_READ_FIFO_UNDERRUN, |
| 56 | BGCOM_EVENT_ERROR_READ_FIFO_BUS_ERR, |
| 57 | BGCOM_EVENT_ERROR_READ_FIFO_ACCESS, |
| 58 | BGCOM_EVENT_ERROR_TRUNCATED_READ, |
| 59 | BGCOM_EVENT_ERROR_TRUNCATED_WRITE, |
| 60 | BGCOM_EVENT_ERROR_AHB_ILLEGAL_ADDRESS, |
| 61 | BGCOM_EVENT_ERROR_AHB_BUS_ERR, |
| 62 | BGCOM_EVENT_ERROR_UNKNOWN, |
| 63 | }; |
| 64 | |
| 65 | /* Event specific data */ |
| 66 | union bgcom_event_data_type { |
| 67 | uint32_t unused; |
| 68 | bool application_running; /* BGCOM_EVENT_APPLICATION_RUNNING */ |
| 69 | bool to_slave_fifo_ready; /* BGCOM_EVENT_TO_SLAVE_FIFO_READY */ |
| 70 | bool to_master_fifo_ready; /* BGCOM_EVENT_TO_MASTER_FIFO_READY */ |
| 71 | bool ahb_ready; /* BGCOM_EVENT_AHB_READY */ |
| 72 | uint16_t to_slave_fifo_free; /* BGCOM_EVENT_TO_SLAVE_FIFO_FREE */ |
| 73 | struct fifo_event_data { |
| 74 | uint16_t to_master_fifo_used; |
| 75 | void *data; |
| 76 | } fifo_data; |
| 77 | }; |
| 78 | |
| 79 | /* Client specific data */ |
| 80 | struct bgcom_open_config_type { |
| 81 | /** Private data pointer for client to maintain context. |
| 82 | * This data is passed back to client in the notification callbacks. |
| 83 | */ |
| 84 | void *priv; |
| 85 | |
| 86 | /* Notification callbacks to notify the BG events */ |
| 87 | void (*bgcom_notification_cb)(void *handle, void *priv, |
| 88 | enum bgcom_event_type event, |
| 89 | union bgcom_event_data_type *event_data); |
| 90 | }; |
| 91 | |
| 92 | /** |
| 93 | * bgcom_open() - opens a channel to interact with Blackghost |
| 94 | * @open_config: pointer to the open configuration structure |
| 95 | * |
| 96 | * Open a new connection to blackghost |
| 97 | * |
| 98 | * Return a handle on success or NULL on error |
| 99 | */ |
| 100 | void *bgcom_open(struct bgcom_open_config_type *open_config); |
| 101 | |
| 102 | /** |
| 103 | * bgcom_close() - close the exsting with Blackghost |
| 104 | * @handle: pointer to the handle, provided by bgcom at |
| 105 | * bgcom_open |
| 106 | * |
| 107 | * Open a new connection to blackghost |
| 108 | * |
| 109 | * Return 0 on success or error on invalid handle |
| 110 | */ |
| 111 | int bgcom_close(void **handle); |
| 112 | |
| 113 | /** |
| 114 | * bgcom_reg_read() - Read from the one or more contiguous registers from BG |
| 115 | * @handle: BGCOM handle associated with the channel |
| 116 | * @reg_start_addr : 8 bit start address of the registers to read from |
| 117 | * @num_regs : Number of contiguous registers to read, starting |
| 118 | * from reg_start_addr. |
| 119 | * @read_buf : Buffer to read from the registers. |
| 120 | * Return 0 on success or -Ve on error |
| 121 | */ |
| 122 | int bgcom_reg_read(void *handle, uint8_t reg_start_addr, |
| 123 | uint32_t num_regs, void *read_buf); |
| 124 | |
| 125 | /** |
| 126 | * Write into the one or more contiguous registers. |
| 127 | * |
| 128 | * @param[in] handle BGCOM handle associated with the channel. |
| 129 | * @param[in] reg_start_addr 8bit start address of the registers to write into. |
| 130 | * @param[in] num_regs Number of contiguous registers to write, starting |
| 131 | * from reg_start_addr. |
| 132 | * @param[in] write_buf Buffer to write into the registers. |
| 133 | * |
| 134 | * @return |
| 135 | * 0 if function is successful, |
| 136 | * Otherwise returns error code. |
| 137 | * |
| 138 | * @sideeffects Causes the Blackghost SPI slave to wakeup. Depending up on |
| 139 | * the operation, it may also wakeup the complete Blackghost. |
| 140 | */ |
| 141 | |
| 142 | /** |
| 143 | * bgcom_reg_write() - Write to the one or more contiguous registers on BG |
| 144 | * @handle: BGCOM handle associated with the channel |
| 145 | * @reg_start_addr : 8 bit start address of the registers to read from |
| 146 | * @num_regs : Number of contiguous registers to write, starting |
| 147 | * from reg_start_addr. |
| 148 | * @write_buf : Buffer to be written to the registers. |
| 149 | * Return 0 on success or -Ve on error |
| 150 | */ |
| 151 | int bgcom_reg_write(void *handle, uint8_t reg_start_addr, |
| 152 | uint8_t num_regs, void *write_buf); |
| 153 | |
| 154 | /** |
| 155 | * bgcom_fifo_read() - Read data from the TO_MASTER_FIFO. |
| 156 | * @handle: BGCOM handle associated with the channel |
| 157 | * @num_words : number of words to read from FIFO |
| 158 | * @read_buf : Buffer read from FIFO. |
| 159 | * Return 0 on success or -Ve on error |
| 160 | */ |
| 161 | int bgcom_fifo_read(void *handle, uint32_t num_words, |
| 162 | void *read_buf); |
| 163 | |
| 164 | /** |
| 165 | * bgcom_fifo_write() - Write data to the TO_SLAVE_FIFO. |
| 166 | * @handle: BGCOM handle associated with the channel |
| 167 | * @num_words : number of words to write on FIFO |
| 168 | * @write_buf : Buffer written to FIFO. |
| 169 | * Return 0 on success or -Ve on error |
| 170 | */ |
| 171 | int bgcom_fifo_write(void *handle, uint32_t num_words, |
| 172 | void *write_buf); |
| 173 | |
| 174 | /** |
| 175 | * bgcom_ahb_read() - Read data from the AHB memory. |
| 176 | * @handle: BGCOM handle associated with the channel |
| 177 | * @ahb_start_addr : Memory start address from where to read |
| 178 | * @num_words : number of words to read from AHB |
| 179 | * @read_buf : Buffer read from FIFO. |
| 180 | * Return 0 on success or -Ve on error |
| 181 | */ |
| 182 | int bgcom_ahb_read(void *handle, uint32_t ahb_start_addr, |
| 183 | uint32_t num_words, void *read_buf); |
| 184 | |
| 185 | /** |
| 186 | * bgcom_ahb_write() - Write data to the AHB memory. |
| 187 | * @handle: BGCOM handle associated with the channel |
| 188 | * @ahb_start_addr : Memory start address from where to start write |
| 189 | * @num_words : number of words to read from AHB |
| 190 | * @write_buf : Buffer to write in AHB. |
| 191 | * Return 0 on success or -Ve on error |
| 192 | */ |
| 193 | int bgcom_ahb_write(void *handle, uint32_t ahb_start_addr, |
| 194 | uint32_t num_words, void *write_buf); |
| 195 | |
| 196 | /** |
| 197 | * bgcom_suspend() - Suspends the channel. |
| 198 | * @handle: BGCOM handle associated with the channel |
| 199 | * Return 0 on success or -Ve on error |
| 200 | */ |
| 201 | int bgcom_suspend(void *handle); |
| 202 | |
| 203 | /** |
| 204 | * bgcom_resume() - Resumes the channel. |
| 205 | * @handle: BGCOM handle associated with the channel |
| 206 | * Return 0 on success or -Ve on error |
| 207 | */ |
| 208 | int bgcom_resume(void *handle); |
| 209 | |
| 210 | int bgcom_set_spi_state(enum bgcom_spi_state state); |
| 211 | |
| 212 | void bgcom_bgdown_handler(void); |
| 213 | |
| 214 | #endif /* BGCOM_H */ |