diff options
Diffstat (limited to 'include/linux/slimbus.h')
-rw-r--r-- | include/linux/slimbus.h | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/include/linux/slimbus.h b/include/linux/slimbus.h new file mode 100644 index 000000000000..c36cf121d2cd --- /dev/null +++ b/include/linux/slimbus.h | |||
@@ -0,0 +1,164 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | /* | ||
3 | * Copyright (c) 2011-2017, The Linux Foundation | ||
4 | */ | ||
5 | |||
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> | ||
12 | |||
13 | extern struct bus_type slimbus_bus; | ||
14 | |||
15 | /** | ||
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 | ||
21 | */ | ||
22 | struct slim_eaddr { | ||
23 | u16 manf_id; | ||
24 | u16 prod_code; | ||
25 | u8 dev_index; | ||
26 | u8 instance; | ||
27 | } __packed; | ||
28 | |||
29 | /** | ||
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. | ||
34 | */ | ||
35 | enum slim_device_status { | ||
36 | SLIM_DEVICE_STATUS_DOWN = 0, | ||
37 | SLIM_DEVICE_STATUS_UP, | ||
38 | SLIM_DEVICE_STATUS_RESERVED, | ||
39 | }; | ||
40 | |||
41 | struct slim_controller; | ||
42 | |||
43 | /** | ||
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 | ||
51 | * | ||
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. | ||
55 | */ | ||
56 | struct slim_device { | ||
57 | struct device dev; | ||
58 | struct slim_eaddr e_addr; | ||
59 | struct slim_controller *ctrl; | ||
60 | enum slim_device_status status; | ||
61 | u8 laddr; | ||
62 | bool is_laddr_valid; | ||
63 | }; | ||
64 | |||
65 | #define to_slim_device(d) container_of(d, struct slim_device, dev) | ||
66 | |||
67 | /** | ||
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 | ||
77 | * this structure | ||
78 | * @id_table: List of SLIMbus devices supported by this driver | ||
79 | */ | ||
80 | |||
81 | struct slim_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; | ||
89 | }; | ||
90 | #define to_slim_driver(d) container_of(d, struct slim_driver, driver) | ||
91 | |||
92 | /** | ||
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 | ||
98 | * per SLIMbus spec | ||
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. | ||
102 | */ | ||
103 | struct slim_val_inf { | ||
104 | u16 start_offset; | ||
105 | u8 num_bytes; | ||
106 | u8 *rbuf; | ||
107 | const u8 *wbuf; | ||
108 | struct completion *comp; | ||
109 | }; | ||
110 | |||
111 | /* | ||
112 | * use a macro to avoid include chaining to get THIS_MODULE | ||
113 | */ | ||
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); | ||
118 | |||
119 | /** | ||
120 | * module_slim_driver() - Helper macro for registering a SLIMbus driver | ||
121 | * @__slim_driver: slimbus_driver struct | ||
122 | * | ||
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() | ||
126 | */ | ||
127 | #define module_slim_driver(__slim_driver) \ | ||
128 | module_driver(__slim_driver, slim_driver_register, \ | ||
129 | slim_driver_unregister) | ||
130 | |||
131 | static inline void *slim_get_devicedata(const struct slim_device *dev) | ||
132 | { | ||
133 | return dev_get_drvdata(&dev->dev); | ||
134 | } | ||
135 | |||
136 | static inline void slim_set_devicedata(struct slim_device *dev, void *data) | ||
137 | { | ||
138 | dev_set_drvdata(&dev->dev, data); | ||
139 | } | ||
140 | |||
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); | ||
144 | |||
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 | ||
151 | |||
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 | ||
157 | |||
158 | int slim_xfer_msg(struct slim_device *sbdev, struct slim_val_inf *msg, | ||
159 | u8 mc); | ||
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 */ | ||