1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2011-2017, The Linux Foundation
6 #ifndef _LINUX_SLIMBUS_H
7 #define _LINUX_SLIMBUS_H
8 #include <linux/device.h>
9 #include <linux/module.h>
10 #include <linux/completion.h>
11 #include <linux/mod_devicetable.h>
13 extern struct bus_type slimbus_bus
;
16 * struct slim_eaddr - Enumeration address for a SLIMbus device
17 * @manf_id: Manufacturer Id for the device
18 * @prod_code: Product code
19 * @dev_index: Device index
20 * @instance: Instance value
30 * enum slim_device_status - slim device status
31 * @SLIM_DEVICE_STATUS_DOWN: Slim device is absent or not reported yet.
32 * @SLIM_DEVICE_STATUS_UP: Slim device is announced on the bus.
33 * @SLIM_DEVICE_STATUS_RESERVED: Reserved for future use.
35 enum slim_device_status
{
36 SLIM_DEVICE_STATUS_DOWN
= 0,
37 SLIM_DEVICE_STATUS_UP
,
38 SLIM_DEVICE_STATUS_RESERVED
,
41 struct slim_controller
;
44 * struct slim_device - Slim device handle.
45 * @dev: Driver model representation of the device.
46 * @e_addr: Enumeration address of this device.
47 * @status: slim device status
48 * @ctrl: slim controller instance.
49 * @laddr: 1-byte Logical address of this device.
50 * @is_laddr_valid: indicates if the laddr is valid or not
52 * This is the client/device handle returned when a SLIMbus
53 * device is registered with a controller.
54 * Pointer to this structure is used by client-driver as a handle.
58 struct slim_eaddr e_addr
;
59 struct slim_controller
*ctrl
;
60 enum slim_device_status status
;
65 #define to_slim_device(d) container_of(d, struct slim_device, dev)
68 * struct slim_driver - SLIMbus 'generic device' (slave) device driver
69 * (similar to 'spi_device' on SPI)
70 * @probe: Binds this driver to a SLIMbus device.
71 * @remove: Unbinds this driver from the SLIMbus device.
72 * @shutdown: Standard shutdown callback used during powerdown/halt.
73 * @device_status: This callback is called when
74 * - The device reports present and gets a laddr assigned
75 * - The device reports absent, or the bus goes down.
76 * @driver: SLIMbus device drivers should initialize name and owner field of
78 * @id_table: List of SLIMbus devices supported by this driver
82 int (*probe
)(struct slim_device
*sl
);
83 void (*remove
)(struct slim_device
*sl
);
84 void (*shutdown
)(struct slim_device
*sl
);
85 int (*device_status
)(struct slim_device
*sl
,
86 enum slim_device_status s
);
87 struct device_driver driver
;
88 const struct slim_device_id
*id_table
;
90 #define to_slim_driver(d) container_of(d, struct slim_driver, driver)
93 * struct slim_val_inf - Slimbus value or information element
94 * @start_offset: Specifies starting offset in information/value element map
95 * @rbuf: buffer to read the values
96 * @wbuf: buffer to write
97 * @num_bytes: upto 16. This ensures that the message will fit the slicesize
99 * @comp: completion for asynchronous operations, valid only if TID is
100 * required for transaction, like REQUEST operations.
101 * Rest of the transactions are synchronous anyway.
103 struct slim_val_inf
{
108 struct completion
*comp
;
112 * use a macro to avoid include chaining to get THIS_MODULE
114 #define slim_driver_register(drv) \
115 __slim_driver_register(drv, THIS_MODULE)
116 int __slim_driver_register(struct slim_driver
*drv
, struct module
*owner
);
117 void slim_driver_unregister(struct slim_driver
*drv
);
120 * module_slim_driver() - Helper macro for registering a SLIMbus driver
121 * @__slim_driver: slimbus_driver struct
123 * Helper macro for SLIMbus drivers which do not do anything special in module
124 * init/exit. This eliminates a lot of boilerplate. Each module may only
125 * use this macro once, and calling it replaces module_init() and module_exit()
127 #define module_slim_driver(__slim_driver) \
128 module_driver(__slim_driver, slim_driver_register, \
129 slim_driver_unregister)
131 static inline void *slim_get_devicedata(const struct slim_device
*dev
)
133 return dev_get_drvdata(&dev
->dev
);
136 static inline void slim_set_devicedata(struct slim_device
*dev
, void *data
)
138 dev_set_drvdata(&dev
->dev
, data
);
141 struct slim_device
*slim_get_device(struct slim_controller
*ctrl
,
142 struct slim_eaddr
*e_addr
);
143 int slim_get_logical_addr(struct slim_device
*sbdev
);
145 /* Information Element management messages */
146 #define SLIM_MSG_MC_REQUEST_INFORMATION 0x20
147 #define SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION 0x21
148 #define SLIM_MSG_MC_REPLY_INFORMATION 0x24
149 #define SLIM_MSG_MC_CLEAR_INFORMATION 0x28
150 #define SLIM_MSG_MC_REPORT_INFORMATION 0x29
152 /* Value Element management messages */
153 #define SLIM_MSG_MC_REQUEST_VALUE 0x60
154 #define SLIM_MSG_MC_REQUEST_CHANGE_VALUE 0x61
155 #define SLIM_MSG_MC_REPLY_VALUE 0x64
156 #define SLIM_MSG_MC_CHANGE_VALUE 0x68
158 int slim_xfer_msg(struct slim_device
*sbdev
, struct slim_val_inf
*msg
,
160 int slim_readb(struct slim_device
*sdev
, u32 addr
);
161 int slim_writeb(struct slim_device
*sdev
, u32 addr
, u8 value
);
162 int slim_read(struct slim_device
*sdev
, u32 addr
, size_t count
, u8
*val
);
163 int slim_write(struct slim_device
*sdev
, u32 addr
, size_t count
, u8
*val
);
164 #endif /* _LINUX_SLIMBUS_H */