/* SPDX-License-Identifier: GPL-2.0-only */ /* * HSI core header file. * * Copyright (C) 2010 Nokia Corporation. All rights reserved. * * Contact: Carlos Chinea <[email protected]> */ #ifndef __LINUX_HSI_H__ #define __LINUX_HSI_H__ #include <linux/device.h> #include <linux/mutex.h> #include <linux/scatterlist.h> #include <linux/list.h> #include <linux/module.h> #include <linux/notifier.h> /* HSI message ttype */ #define HSI_MSG_READ … #define HSI_MSG_WRITE … /* HSI configuration values */ enum { … }; enum { … }; enum { … }; #define HSI_MAX_CHANNELS … /* HSI message status codes */ enum { … }; /* HSI port event codes */ enum { … }; /** * struct hsi_channel - channel resource used by the hsi clients * @id: Channel number * @name: Channel name */ struct hsi_channel { … }; /** * struct hsi_config - Configuration for RX/TX HSI modules * @mode: Bit transmission mode (STREAM or FRAME) * @channels: Channel resources used by the client * @num_channels: Number of channel resources * @num_hw_channels: Number of channels the transceiver is configured for [1..16] * @speed: Max bit transmission speed (Kbit/s) * @flow: RX flow type (SYNCHRONIZED or PIPELINE) * @arb_mode: Arbitration mode for TX frame (Round robin, priority) */ struct hsi_config { … }; /** * struct hsi_board_info - HSI client board info * @name: Name for the HSI device * @hsi_id: HSI controller id where the client sits * @port: Port number in the controller where the client sits * @tx_cfg: HSI TX configuration * @rx_cfg: HSI RX configuration * @platform_data: Platform related data * @archdata: Architecture-dependent device data */ struct hsi_board_info { … }; #ifdef CONFIG_HSI_BOARDINFO extern int hsi_register_board_info(struct hsi_board_info const *info, unsigned int len); #else static inline int hsi_register_board_info(struct hsi_board_info const *info, unsigned int len) { return 0; } #endif /* CONFIG_HSI_BOARDINFO */ /** * struct hsi_client - HSI client attached to an HSI port * @device: Driver model representation of the device * @tx_cfg: HSI TX configuration * @rx_cfg: HSI RX configuration */ struct hsi_client { … }; #define to_hsi_client(dev) … static inline void hsi_client_set_drvdata(struct hsi_client *cl, void *data) { … } static inline void *hsi_client_drvdata(struct hsi_client *cl) { … } int hsi_register_port_event(struct hsi_client *cl, void (*handler)(struct hsi_client *, unsigned long)); int hsi_unregister_port_event(struct hsi_client *cl); /** * struct hsi_client_driver - Driver associated to an HSI client * @driver: Driver model representation of the driver */ struct hsi_client_driver { … }; #define to_hsi_client_driver(drv) … int hsi_register_client_driver(struct hsi_client_driver *drv); static inline void hsi_unregister_client_driver(struct hsi_client_driver *drv) { … } /** * struct hsi_msg - HSI message descriptor * @link: Free to use by the current descriptor owner * @cl: HSI device client that issues the transfer * @sgt: Head of the scatterlist array * @context: Client context data associated to the transfer * @complete: Transfer completion callback * @destructor: Destructor to free resources when flushing * @status: Status of the transfer when completed * @actual_len: Actual length of data transferred on completion * @channel: Channel were to TX/RX the message * @ttype: Transfer type (TX if set, RX otherwise) * @break_frame: if true HSI will send/receive a break frame. Data buffers are * ignored in the request. */ struct hsi_msg { … }; struct hsi_msg *hsi_alloc_msg(unsigned int n_frag, gfp_t flags); void hsi_free_msg(struct hsi_msg *msg); /** * struct hsi_port - HSI port device * @device: Driver model representation of the device * @tx_cfg: Current TX path configuration * @rx_cfg: Current RX path configuration * @num: Port number * @shared: Set when port can be shared by different clients * @claimed: Reference count of clients which claimed the port * @lock: Serialize port claim * @async: Asynchronous transfer callback * @setup: Callback to set the HSI client configuration * @flush: Callback to clean the HW state and destroy all pending transfers * @start_tx: Callback to inform that a client wants to TX data * @stop_tx: Callback to inform that a client no longer wishes to TX data * @release: Callback to inform that a client no longer uses the port * @n_head: Notifier chain for signaling port events to the clients. */ struct hsi_port { … }; #define to_hsi_port(dev) … #define hsi_get_port(cl) … int hsi_event(struct hsi_port *port, unsigned long event); int hsi_claim_port(struct hsi_client *cl, unsigned int share); void hsi_release_port(struct hsi_client *cl); static inline int hsi_port_claimed(struct hsi_client *cl) { … } static inline void hsi_port_set_drvdata(struct hsi_port *port, void *data) { … } static inline void *hsi_port_drvdata(struct hsi_port *port) { … } /** * struct hsi_controller - HSI controller device * @device: Driver model representation of the device * @owner: Pointer to the module owning the controller * @id: HSI controller ID * @num_ports: Number of ports in the HSI controller * @port: Array of HSI ports */ struct hsi_controller { … }; #define to_hsi_controller(dev) … struct hsi_controller *hsi_alloc_controller(unsigned int n_ports, gfp_t flags); void hsi_put_controller(struct hsi_controller *hsi); int hsi_register_controller(struct hsi_controller *hsi); void hsi_unregister_controller(struct hsi_controller *hsi); struct hsi_client *hsi_new_client(struct hsi_port *port, struct hsi_board_info *info); int hsi_remove_client(struct device *dev, void *data); void hsi_port_unregister_clients(struct hsi_port *port); #ifdef CONFIG_OF void hsi_add_clients_from_dt(struct hsi_port *port, struct device_node *clients); #else static inline void hsi_add_clients_from_dt(struct hsi_port *port, struct device_node *clients) { return; } #endif static inline void hsi_controller_set_drvdata(struct hsi_controller *hsi, void *data) { … } static inline void *hsi_controller_drvdata(struct hsi_controller *hsi) { … } static inline struct hsi_port *hsi_find_port_num(struct hsi_controller *hsi, unsigned int num) { … } /* * API for HSI clients */ int hsi_async(struct hsi_client *cl, struct hsi_msg *msg); int hsi_get_channel_id_by_name(struct hsi_client *cl, char *name); /** * hsi_id - Get HSI controller ID associated to a client * @cl: Pointer to a HSI client * * Return the controller id where the client is attached to */ static inline unsigned int hsi_id(struct hsi_client *cl) { … } /** * hsi_port_id - Gets the port number a client is attached to * @cl: Pointer to HSI client * * Return the port number associated to the client */ static inline unsigned int hsi_port_id(struct hsi_client *cl) { … } /** * hsi_setup - Configure the client's port * @cl: Pointer to the HSI client * * When sharing ports, clients should either relay on a single * client setup or have the same setup for all of them. * * Return -errno on failure, 0 on success */ static inline int hsi_setup(struct hsi_client *cl) { … } /** * hsi_flush - Flush all pending transactions on the client's port * @cl: Pointer to the HSI client * * This function will destroy all pending hsi_msg in the port and reset * the HW port so it is ready to receive and transmit from a clean state. * * Return -errno on failure, 0 on success */ static inline int hsi_flush(struct hsi_client *cl) { … } /** * hsi_async_read - Submit a read transfer * @cl: Pointer to the HSI client * @msg: HSI message descriptor of the transfer * * Return -errno on failure, 0 on success */ static inline int hsi_async_read(struct hsi_client *cl, struct hsi_msg *msg) { … } /** * hsi_async_write - Submit a write transfer * @cl: Pointer to the HSI client * @msg: HSI message descriptor of the transfer * * Return -errno on failure, 0 on success */ static inline int hsi_async_write(struct hsi_client *cl, struct hsi_msg *msg) { … } /** * hsi_start_tx - Signal the port that the client wants to start a TX * @cl: Pointer to the HSI client * * Return -errno on failure, 0 on success */ static inline int hsi_start_tx(struct hsi_client *cl) { … } /** * hsi_stop_tx - Signal the port that the client no longer wants to transmit * @cl: Pointer to the HSI client * * Return -errno on failure, 0 on success */ static inline int hsi_stop_tx(struct hsi_client *cl) { … } #endif /* __LINUX_HSI_H__ */