linux/include/linux/mfd/dln2.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2#ifndef __LINUX_USB_DLN2_H
   3#define __LINUX_USB_DLN2_H
   4
   5#define DLN2_CMD(cmd, id)               ((cmd) | ((id) << 8))
   6
   7struct dln2_platform_data {
   8        u16 handle;             /* sub-driver handle (internally used only) */
   9        u8 port;                /* I2C/SPI port */
  10};
  11
  12/**
  13 * dln2_event_cb_t - event callback function signature
  14 *
  15 * @pdev - the sub-device that registered this callback
  16 * @echo - the echo header field received in the message
  17 * @data - the data payload
  18 * @len  - the data payload length
  19 *
  20 * The callback function is called in interrupt context and the data payload is
  21 * only valid during the call. If the user needs later access of the data, it
  22 * must copy it.
  23 */
  24
  25typedef void (*dln2_event_cb_t)(struct platform_device *pdev, u16 echo,
  26                                const void *data, int len);
  27
  28/**
  29 * dl2n_register_event_cb - register a callback function for an event
  30 *
  31 * @pdev - the sub-device that registers the callback
  32 * @event - the event for which to register a callback
  33 * @event_cb - the callback function
  34 *
  35 * @return 0 in case of success, negative value in case of error
  36 */
  37int dln2_register_event_cb(struct platform_device *pdev, u16 event,
  38                           dln2_event_cb_t event_cb);
  39
  40/**
  41 * dln2_unregister_event_cb - unregister the callback function for an event
  42 *
  43 * @pdev - the sub-device that registered the callback
  44 * @event - the event for which to register a callback
  45 */
  46void dln2_unregister_event_cb(struct platform_device *pdev, u16 event);
  47
  48/**
  49 * dln2_transfer - issue a DLN2 command and wait for a response and the
  50 * associated data
  51 *
  52 * @pdev - the sub-device which is issuing this transfer
  53 * @cmd - the command to be sent to the device
  54 * @obuf - the buffer to be sent to the device; it can be NULL if the user
  55 *      doesn't need to transmit data with this command
  56 * @obuf_len - the size of the buffer to be sent to the device
  57 * @ibuf - any data associated with the response will be copied here; it can be
  58 *      NULL if the user doesn't need the response data
  59 * @ibuf_len - must be initialized to the input buffer size; it will be modified
  60 *      to indicate the actual data transferred;
  61 *
  62 * @return 0 for success, negative value for errors
  63 */
  64int dln2_transfer(struct platform_device *pdev, u16 cmd,
  65                  const void *obuf, unsigned obuf_len,
  66                  void *ibuf, unsigned *ibuf_len);
  67
  68/**
  69 * dln2_transfer_rx - variant of @dln2_transfer() where TX buffer is not needed
  70 *
  71 * @pdev - the sub-device which is issuing this transfer
  72 * @cmd - the command to be sent to the device
  73 * @ibuf - any data associated with the response will be copied here; it can be
  74 *      NULL if the user doesn't need the response data
  75 * @ibuf_len - must be initialized to the input buffer size; it will be modified
  76 *      to indicate the actual data transferred;
  77 *
  78 * @return 0 for success, negative value for errors
  79 */
  80
  81static inline int dln2_transfer_rx(struct platform_device *pdev, u16 cmd,
  82                                   void *ibuf, unsigned *ibuf_len)
  83{
  84        return dln2_transfer(pdev, cmd, NULL, 0, ibuf, ibuf_len);
  85}
  86
  87/**
  88 * dln2_transfer_tx - variant of @dln2_transfer() where RX buffer is not needed
  89 *
  90 * @pdev - the sub-device which is issuing this transfer
  91 * @cmd - the command to be sent to the device
  92 * @obuf - the buffer to be sent to the device; it can be NULL if the
  93 *      user doesn't need to transmit data with this command
  94 * @obuf_len - the size of the buffer to be sent to the device
  95 *
  96 * @return 0 for success, negative value for errors
  97 */
  98static inline int dln2_transfer_tx(struct platform_device *pdev, u16 cmd,
  99                                   const void *obuf, unsigned obuf_len)
 100{
 101        return dln2_transfer(pdev, cmd, obuf, obuf_len, NULL, NULL);
 102}
 103
 104#endif
 105