Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (c) 2011-2017, The Linux Foundation
0004  */
0005 
0006 #ifndef _LINUX_SLIMBUS_H
0007 #define _LINUX_SLIMBUS_H
0008 #include <linux/device.h>
0009 #include <linux/module.h>
0010 #include <linux/completion.h>
0011 #include <linux/mod_devicetable.h>
0012 
0013 extern struct bus_type slimbus_bus;
0014 
0015 /**
0016  * struct slim_eaddr - Enumeration address for a SLIMbus device
0017  * @instance: Instance value
0018  * @dev_index: Device index
0019  * @prod_code: Product code
0020  * @manf_id: Manufacturer Id for the device
0021  */
0022 struct slim_eaddr {
0023     u8 instance;
0024     u8 dev_index;
0025     u16 prod_code;
0026     u16 manf_id;
0027 } __packed;
0028 
0029 /**
0030  * enum slim_device_status - slim device status
0031  * @SLIM_DEVICE_STATUS_DOWN: Slim device is absent or not reported yet.
0032  * @SLIM_DEVICE_STATUS_UP: Slim device is announced on the bus.
0033  * @SLIM_DEVICE_STATUS_RESERVED: Reserved for future use.
0034  */
0035 enum slim_device_status {
0036     SLIM_DEVICE_STATUS_DOWN = 0,
0037     SLIM_DEVICE_STATUS_UP,
0038     SLIM_DEVICE_STATUS_RESERVED,
0039 };
0040 
0041 struct slim_controller;
0042 
0043 /**
0044  * struct slim_device - Slim device handle.
0045  * @dev: Driver model representation of the device.
0046  * @e_addr: Enumeration address of this device.
0047  * @status: slim device status
0048  * @ctrl: slim controller instance.
0049  * @laddr: 1-byte Logical address of this device.
0050  * @is_laddr_valid: indicates if the laddr is valid or not
0051  * @stream_list: List of streams on this device
0052  * @stream_list_lock: lock to protect the stream list
0053  *
0054  * This is the client/device handle returned when a SLIMbus
0055  * device is registered with a controller.
0056  * Pointer to this structure is used by client-driver as a handle.
0057  */
0058 struct slim_device {
0059     struct device       dev;
0060     struct slim_eaddr   e_addr;
0061     struct slim_controller  *ctrl;
0062     enum slim_device_status status;
0063     u8          laddr;
0064     bool            is_laddr_valid;
0065     struct list_head    stream_list;
0066     spinlock_t stream_list_lock;
0067 };
0068 
0069 #define to_slim_device(d) container_of(d, struct slim_device, dev)
0070 
0071 /**
0072  * struct slim_driver - SLIMbus 'generic device' (slave) device driver
0073  *              (similar to 'spi_device' on SPI)
0074  * @probe: Binds this driver to a SLIMbus device.
0075  * @remove: Unbinds this driver from the SLIMbus device.
0076  * @shutdown: Standard shutdown callback used during powerdown/halt.
0077  * @device_status: This callback is called when
0078  *  - The device reports present and gets a laddr assigned
0079  *  - The device reports absent, or the bus goes down.
0080  * @driver: SLIMbus device drivers should initialize name and owner field of
0081  *      this structure
0082  * @id_table: List of SLIMbus devices supported by this driver
0083  */
0084 
0085 struct slim_driver {
0086     int (*probe)(struct slim_device *sl);
0087     void    (*remove)(struct slim_device *sl);
0088     void    (*shutdown)(struct slim_device *sl);
0089     int (*device_status)(struct slim_device *sl,
0090                  enum slim_device_status s);
0091     struct device_driver        driver;
0092     const struct slim_device_id *id_table;
0093 };
0094 #define to_slim_driver(d) container_of(d, struct slim_driver, driver)
0095 
0096 /**
0097  * struct slim_val_inf - Slimbus value or information element
0098  * @start_offset: Specifies starting offset in information/value element map
0099  * @rbuf: buffer to read the values
0100  * @wbuf: buffer to write
0101  * @num_bytes: upto 16. This ensures that the message will fit the slicesize
0102  *      per SLIMbus spec
0103  * @comp: completion for asynchronous operations, valid only if TID is
0104  *    required for transaction, like REQUEST operations.
0105  *    Rest of the transactions are synchronous anyway.
0106  */
0107 struct slim_val_inf {
0108     u16         start_offset;
0109     u8          num_bytes;
0110     u8          *rbuf;
0111     const u8        *wbuf;
0112     struct  completion  *comp;
0113 };
0114 
0115 #define SLIM_DEVICE_MAX_CHANNELS    256
0116 /* A SLIMBus Device may have frmo 0 to 31 Ports (inclusive) */
0117 #define SLIM_DEVICE_MAX_PORTS       32
0118 
0119 /**
0120  * struct slim_stream_config - SLIMbus stream configuration
0121  *  Configuring a stream is done at hw_params or prepare call
0122  *  from audio drivers where they have all the required information
0123  *  regarding rate, number of channels and so on.
0124  *  There is a 1:1 mapping of channel and ports.
0125  *
0126  * @rate: data rate
0127  * @bps: bits per data sample
0128  * @ch_count: number of channels
0129  * @chs: pointer to list of channel numbers
0130  * @port_mask: port mask of ports to use for this stream
0131  * @direction: direction of the stream, SNDRV_PCM_STREAM_PLAYBACK
0132  *  or SNDRV_PCM_STREAM_CAPTURE.
0133  */
0134 struct slim_stream_config {
0135     unsigned int rate;
0136     unsigned int bps;
0137     /* MAX 256 channels */
0138     unsigned int ch_count;
0139     unsigned int *chs;
0140     /* Max 32 ports per device */
0141     unsigned long port_mask;
0142     int direction;
0143 };
0144 
0145 /*
0146  * use a macro to avoid include chaining to get THIS_MODULE
0147  */
0148 #define slim_driver_register(drv) \
0149     __slim_driver_register(drv, THIS_MODULE)
0150 int __slim_driver_register(struct slim_driver *drv, struct module *owner);
0151 void slim_driver_unregister(struct slim_driver *drv);
0152 
0153 /**
0154  * module_slim_driver() - Helper macro for registering a SLIMbus driver
0155  * @__slim_driver: slimbus_driver struct
0156  *
0157  * Helper macro for SLIMbus drivers which do not do anything special in module
0158  * init/exit. This eliminates a lot of boilerplate. Each module may only
0159  * use this macro once, and calling it replaces module_init() and module_exit()
0160  */
0161 #define module_slim_driver(__slim_driver) \
0162     module_driver(__slim_driver, slim_driver_register, \
0163             slim_driver_unregister)
0164 
0165 static inline void *slim_get_devicedata(const struct slim_device *dev)
0166 {
0167     return dev_get_drvdata(&dev->dev);
0168 }
0169 
0170 static inline void slim_set_devicedata(struct slim_device *dev, void *data)
0171 {
0172     dev_set_drvdata(&dev->dev, data);
0173 }
0174 
0175 struct slim_device *of_slim_get_device(struct slim_controller *ctrl,
0176                        struct device_node *np);
0177 struct slim_device *slim_get_device(struct slim_controller *ctrl,
0178                     struct slim_eaddr *e_addr);
0179 int slim_get_logical_addr(struct slim_device *sbdev);
0180 
0181 /* Information Element management messages */
0182 #define SLIM_MSG_MC_REQUEST_INFORMATION          0x20
0183 #define SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION    0x21
0184 #define SLIM_MSG_MC_REPLY_INFORMATION            0x24
0185 #define SLIM_MSG_MC_CLEAR_INFORMATION            0x28
0186 #define SLIM_MSG_MC_REPORT_INFORMATION           0x29
0187 
0188 /* Value Element management messages */
0189 #define SLIM_MSG_MC_REQUEST_VALUE                0x60
0190 #define SLIM_MSG_MC_REQUEST_CHANGE_VALUE         0x61
0191 #define SLIM_MSG_MC_REPLY_VALUE                  0x64
0192 #define SLIM_MSG_MC_CHANGE_VALUE                 0x68
0193 
0194 int slim_xfer_msg(struct slim_device *sbdev, struct slim_val_inf *msg,
0195           u8 mc);
0196 int slim_readb(struct slim_device *sdev, u32 addr);
0197 int slim_writeb(struct slim_device *sdev, u32 addr, u8 value);
0198 int slim_read(struct slim_device *sdev, u32 addr, size_t count, u8 *val);
0199 int slim_write(struct slim_device *sdev, u32 addr, size_t count, u8 *val);
0200 
0201 /* SLIMbus Stream apis */
0202 struct slim_stream_runtime;
0203 struct slim_stream_runtime *slim_stream_allocate(struct slim_device *dev,
0204                          const char *sname);
0205 int slim_stream_prepare(struct slim_stream_runtime *stream,
0206             struct slim_stream_config *c);
0207 int slim_stream_enable(struct slim_stream_runtime *stream);
0208 int slim_stream_disable(struct slim_stream_runtime *stream);
0209 int slim_stream_unprepare(struct slim_stream_runtime *stream);
0210 int slim_stream_free(struct slim_stream_runtime *stream);
0211 
0212 #endif /* _LINUX_SLIMBUS_H */