1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 2 /* 3 * HSI core header file. 4 * 5 * Copyright (C) 2010 Nokia Corporation. All r 6 * 7 * Contact: Carlos Chinea <carlos.chinea@nokia 8 */ 9 10 #ifndef __LINUX_HSI_H__ 11 #define __LINUX_HSI_H__ 12 13 #include <linux/device.h> 14 #include <linux/mutex.h> 15 #include <linux/scatterlist.h> 16 #include <linux/list.h> 17 #include <linux/module.h> 18 #include <linux/notifier.h> 19 20 /* HSI message ttype */ 21 #define HSI_MSG_READ 0 22 #define HSI_MSG_WRITE 1 23 24 /* HSI configuration values */ 25 enum { 26 HSI_MODE_STREAM = 1, 27 HSI_MODE_FRAME, 28 }; 29 30 enum { 31 HSI_FLOW_SYNC, /* Synchronized flow * 32 HSI_FLOW_PIPE, /* Pipelined flow */ 33 }; 34 35 enum { 36 HSI_ARB_RR, /* Round-robin arbitra 37 HSI_ARB_PRIO, /* Channel priority ar 38 }; 39 40 #define HSI_MAX_CHANNELS 16 41 42 /* HSI message status codes */ 43 enum { 44 HSI_STATUS_COMPLETED, /* Message tra 45 HSI_STATUS_PENDING, /* Message pen 46 HSI_STATUS_PROCEEDING, /* Message tra 47 HSI_STATUS_QUEUED, /* Message wai 48 HSI_STATUS_ERROR, /* Error when 49 }; 50 51 /* HSI port event codes */ 52 enum { 53 HSI_EVENT_START_RX, 54 HSI_EVENT_STOP_RX, 55 }; 56 57 /** 58 * struct hsi_channel - channel resource used 59 * @id: Channel number 60 * @name: Channel name 61 */ 62 struct hsi_channel { 63 unsigned int id; 64 const char *name; 65 }; 66 67 /** 68 * struct hsi_config - Configuration for RX/TX 69 * @mode: Bit transmission mode (STREAM or FRA 70 * @channels: Channel resources used by the cl 71 * @num_channels: Number of channel resources 72 * @num_hw_channels: Number of channels the tr 73 * @speed: Max bit transmission speed (Kbit/s) 74 * @flow: RX flow type (SYNCHRONIZED or PIPELI 75 * @arb_mode: Arbitration mode for TX frame (R 76 */ 77 struct hsi_config { 78 unsigned int mode; 79 struct hsi_channel *channels; 80 unsigned int num_channels; 81 unsigned int num_hw_channel 82 unsigned int speed; 83 union { 84 unsigned int flow; 85 unsigned int arb_mode; 86 }; 87 }; 88 89 /** 90 * struct hsi_board_info - HSI client board in 91 * @name: Name for the HSI device 92 * @hsi_id: HSI controller id where the client 93 * @port: Port number in the controller where 94 * @tx_cfg: HSI TX configuration 95 * @rx_cfg: HSI RX configuration 96 * @platform_data: Platform related data 97 * @archdata: Architecture-dependent device da 98 */ 99 struct hsi_board_info { 100 const char *name; 101 unsigned int hsi_id; 102 unsigned int port; 103 struct hsi_config tx_cfg; 104 struct hsi_config rx_cfg; 105 void *platform_data 106 struct dev_archdata *archdata; 107 }; 108 109 #ifdef CONFIG_HSI_BOARDINFO 110 extern int hsi_register_board_info(struct hsi_ 111 112 #else 113 static inline int hsi_register_board_info(stru 114 115 { 116 return 0; 117 } 118 #endif /* CONFIG_HSI_BOARDINFO */ 119 120 /** 121 * struct hsi_client - HSI client attached to 122 * @device: Driver model representation of the 123 * @tx_cfg: HSI TX configuration 124 * @rx_cfg: HSI RX configuration 125 */ 126 struct hsi_client { 127 struct device device; 128 struct hsi_config tx_cfg; 129 struct hsi_config rx_cfg; 130 /* private: */ 131 void (*ehandler)(st 132 unsigned int pclaimed:1; 133 struct notifier_block nb; 134 }; 135 136 #define to_hsi_client(dev) container_of(dev, s 137 138 static inline void hsi_client_set_drvdata(stru 139 { 140 dev_set_drvdata(&cl->device, data); 141 } 142 143 static inline void *hsi_client_drvdata(struct 144 { 145 return dev_get_drvdata(&cl->device); 146 } 147 148 int hsi_register_port_event(struct hsi_client 149 void (*handler)(struct 150 int hsi_unregister_port_event(struct hsi_clien 151 152 /** 153 * struct hsi_client_driver - Driver associate 154 * @driver: Driver model representation of the 155 */ 156 struct hsi_client_driver { 157 struct device_driver driver; 158 }; 159 160 #define to_hsi_client_driver(drv) container_of 161 162 163 int hsi_register_client_driver(struct hsi_clie 164 165 static inline void hsi_unregister_client_drive 166 { 167 driver_unregister(&drv->driver); 168 } 169 170 /** 171 * struct hsi_msg - HSI message descriptor 172 * @link: Free to use by the current descripto 173 * @cl: HSI device client that issues the tran 174 * @sgt: Head of the scatterlist array 175 * @context: Client context data associated to 176 * @complete: Transfer completion callback 177 * @destructor: Destructor to free resources w 178 * @status: Status of the transfer when comple 179 * @actual_len: Actual length of data transfer 180 * @channel: Channel were to TX/RX the message 181 * @ttype: Transfer type (TX if set, RX otherw 182 * @break_frame: if true HSI will send/receive 183 * ignored in the request. 184 */ 185 struct hsi_msg { 186 struct list_head link; 187 struct hsi_client *cl; 188 struct sg_table sgt; 189 void *context; 190 191 void (*complete)(st 192 void (*destructor)( 193 194 int status; 195 unsigned int actual_len; 196 unsigned int channel; 197 unsigned int ttype:1; 198 unsigned int break_frame:1; 199 }; 200 201 struct hsi_msg *hsi_alloc_msg(unsigned int n_f 202 void hsi_free_msg(struct hsi_msg *msg); 203 204 /** 205 * struct hsi_port - HSI port device 206 * @device: Driver model representation of the 207 * @tx_cfg: Current TX path configuration 208 * @rx_cfg: Current RX path configuration 209 * @num: Port number 210 * @shared: Set when port can be shared by dif 211 * @claimed: Reference count of clients which 212 * @lock: Serialize port claim 213 * @async: Asynchronous transfer callback 214 * @setup: Callback to set the HSI client conf 215 * @flush: Callback to clean the HW state and 216 * @start_tx: Callback to inform that a client 217 * @stop_tx: Callback to inform that a client 218 * @release: Callback to inform that a client 219 * @n_head: Notifier chain for signaling port 220 */ 221 struct hsi_port { 222 struct device device 223 struct hsi_config tx_cfg 224 struct hsi_config rx_cfg 225 unsigned int num; 226 unsigned int shared 227 int claime 228 struct mutex lock; 229 int (*asyn 230 int (*setu 231 int (*flus 232 int (*star 233 int (*stop 234 int (*rele 235 /* private */ 236 struct blocking_notifier_head n_head 237 }; 238 239 #define to_hsi_port(dev) container_of(dev, str 240 #define hsi_get_port(cl) to_hsi_port((cl)->dev 241 242 int hsi_event(struct hsi_port *port, unsigned 243 int hsi_claim_port(struct hsi_client *cl, unsi 244 void hsi_release_port(struct hsi_client *cl); 245 246 static inline int hsi_port_claimed(struct hsi_ 247 { 248 return cl->pclaimed; 249 } 250 251 static inline void hsi_port_set_drvdata(struct 252 { 253 dev_set_drvdata(&port->device, data); 254 } 255 256 static inline void *hsi_port_drvdata(struct hs 257 { 258 return dev_get_drvdata(&port->device); 259 } 260 261 /** 262 * struct hsi_controller - HSI controller devi 263 * @device: Driver model representation of the 264 * @owner: Pointer to the module owning the co 265 * @id: HSI controller ID 266 * @num_ports: Number of ports in the HSI cont 267 * @port: Array of HSI ports 268 */ 269 struct hsi_controller { 270 struct device device; 271 struct module *owner; 272 unsigned int id; 273 unsigned int num_ports; 274 struct hsi_port **port; 275 }; 276 277 #define to_hsi_controller(dev) container_of(de 278 279 struct hsi_controller *hsi_alloc_controller(un 280 void hsi_put_controller(struct hsi_controller 281 int hsi_register_controller(struct hsi_control 282 void hsi_unregister_controller(struct hsi_cont 283 struct hsi_client *hsi_new_client(struct hsi_p 284 285 int hsi_remove_client(struct device *dev, void 286 void hsi_port_unregister_clients(struct hsi_po 287 288 #ifdef CONFIG_OF 289 void hsi_add_clients_from_dt(struct hsi_port * 290 struct device_nod 291 #else 292 static inline void hsi_add_clients_from_dt(str 293 str 294 { 295 return; 296 } 297 #endif 298 299 static inline void hsi_controller_set_drvdata( 300 301 { 302 dev_set_drvdata(&hsi->device, data); 303 } 304 305 static inline void *hsi_controller_drvdata(str 306 { 307 return dev_get_drvdata(&hsi->device); 308 } 309 310 static inline struct hsi_port *hsi_find_port_n 311 312 { 313 return (num < hsi->num_ports) ? hsi->p 314 } 315 316 /* 317 * API for HSI clients 318 */ 319 int hsi_async(struct hsi_client *cl, struct hs 320 321 int hsi_get_channel_id_by_name(struct hsi_clie 322 323 /** 324 * hsi_id - Get HSI controller ID associated t 325 * @cl: Pointer to a HSI client 326 * 327 * Return the controller id where the client i 328 */ 329 static inline unsigned int hsi_id(struct hsi_c 330 { 331 return to_hsi_controller(cl->device.p 332 } 333 334 /** 335 * hsi_port_id - Gets the port number a client 336 * @cl: Pointer to HSI client 337 * 338 * Return the port number associated to the cl 339 */ 340 static inline unsigned int hsi_port_id(struct 341 { 342 return to_hsi_port(cl->device.parent) 343 } 344 345 /** 346 * hsi_setup - Configure the client's port 347 * @cl: Pointer to the HSI client 348 * 349 * When sharing ports, clients should either r 350 * client setup or have the same setup for all 351 * 352 * Return -errno on failure, 0 on success 353 */ 354 static inline int hsi_setup(struct hsi_client 355 { 356 if (!hsi_port_claimed(cl)) 357 return -EACCES; 358 return hsi_get_port(cl)->setup(cl); 359 } 360 361 /** 362 * hsi_flush - Flush all pending transactions 363 * @cl: Pointer to the HSI client 364 * 365 * This function will destroy all pending hsi_ 366 * the HW port so it is ready to receive and t 367 * 368 * Return -errno on failure, 0 on success 369 */ 370 static inline int hsi_flush(struct hsi_client 371 { 372 if (!hsi_port_claimed(cl)) 373 return -EACCES; 374 return hsi_get_port(cl)->flush(cl); 375 } 376 377 /** 378 * hsi_async_read - Submit a read transfer 379 * @cl: Pointer to the HSI client 380 * @msg: HSI message descriptor of the transfe 381 * 382 * Return -errno on failure, 0 on success 383 */ 384 static inline int hsi_async_read(struct hsi_cl 385 { 386 msg->ttype = HSI_MSG_READ; 387 return hsi_async(cl, msg); 388 } 389 390 /** 391 * hsi_async_write - Submit a write transfer 392 * @cl: Pointer to the HSI client 393 * @msg: HSI message descriptor of the transfe 394 * 395 * Return -errno on failure, 0 on success 396 */ 397 static inline int hsi_async_write(struct hsi_c 398 { 399 msg->ttype = HSI_MSG_WRITE; 400 return hsi_async(cl, msg); 401 } 402 403 /** 404 * hsi_start_tx - Signal the port that the cli 405 * @cl: Pointer to the HSI client 406 * 407 * Return -errno on failure, 0 on success 408 */ 409 static inline int hsi_start_tx(struct hsi_clie 410 { 411 if (!hsi_port_claimed(cl)) 412 return -EACCES; 413 return hsi_get_port(cl)->start_tx(cl); 414 } 415 416 /** 417 * hsi_stop_tx - Signal the port that the clie 418 * @cl: Pointer to the HSI client 419 * 420 * Return -errno on failure, 0 on success 421 */ 422 static inline int hsi_stop_tx(struct hsi_clien 423 { 424 if (!hsi_port_claimed(cl)) 425 return -EACCES; 426 return hsi_get_port(cl)->stop_tx(cl); 427 } 428 #endif /* __LINUX_HSI_H__ */ 429
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.