This source file includes following definitions.
- to_spmi_device
- spmi_device_get_drvdata
- spmi_device_set_drvdata
- spmi_device_put
- to_spmi_controller
- spmi_controller_get_drvdata
- spmi_controller_set_drvdata
- spmi_controller_put
- to_spmi_driver
- spmi_driver_unregister
1
2
3
4 #ifndef _LINUX_SPMI_H
5 #define _LINUX_SPMI_H
6
7 #include <linux/types.h>
8 #include <linux/device.h>
9 #include <linux/mod_devicetable.h>
10
11
12 #define SPMI_MAX_SLAVE_ID 16
13
14
15 #define SPMI_CMD_EXT_WRITE 0x00
16 #define SPMI_CMD_RESET 0x10
17 #define SPMI_CMD_SLEEP 0x11
18 #define SPMI_CMD_SHUTDOWN 0x12
19 #define SPMI_CMD_WAKEUP 0x13
20 #define SPMI_CMD_AUTHENTICATE 0x14
21 #define SPMI_CMD_MSTR_READ 0x15
22 #define SPMI_CMD_MSTR_WRITE 0x16
23 #define SPMI_CMD_TRANSFER_BUS_OWNERSHIP 0x1A
24 #define SPMI_CMD_DDB_MASTER_READ 0x1B
25 #define SPMI_CMD_DDB_SLAVE_READ 0x1C
26 #define SPMI_CMD_EXT_READ 0x20
27 #define SPMI_CMD_EXT_WRITEL 0x30
28 #define SPMI_CMD_EXT_READL 0x38
29 #define SPMI_CMD_WRITE 0x40
30 #define SPMI_CMD_READ 0x60
31 #define SPMI_CMD_ZERO_WRITE 0x80
32
33
34
35
36
37
38
39 struct spmi_device {
40 struct device dev;
41 struct spmi_controller *ctrl;
42 u8 usid;
43 };
44
45 static inline struct spmi_device *to_spmi_device(struct device *d)
46 {
47 return container_of(d, struct spmi_device, dev);
48 }
49
50 static inline void *spmi_device_get_drvdata(const struct spmi_device *sdev)
51 {
52 return dev_get_drvdata(&sdev->dev);
53 }
54
55 static inline void spmi_device_set_drvdata(struct spmi_device *sdev, void *data)
56 {
57 dev_set_drvdata(&sdev->dev, data);
58 }
59
60 struct spmi_device *spmi_device_alloc(struct spmi_controller *ctrl);
61
62 static inline void spmi_device_put(struct spmi_device *sdev)
63 {
64 if (sdev)
65 put_device(&sdev->dev);
66 }
67
68 int spmi_device_add(struct spmi_device *sdev);
69
70 void spmi_device_remove(struct spmi_device *sdev);
71
72
73
74
75
76
77
78
79
80 struct spmi_controller {
81 struct device dev;
82 unsigned int nr;
83 int (*cmd)(struct spmi_controller *ctrl, u8 opcode, u8 sid);
84 int (*read_cmd)(struct spmi_controller *ctrl, u8 opcode,
85 u8 sid, u16 addr, u8 *buf, size_t len);
86 int (*write_cmd)(struct spmi_controller *ctrl, u8 opcode,
87 u8 sid, u16 addr, const u8 *buf, size_t len);
88 };
89
90 static inline struct spmi_controller *to_spmi_controller(struct device *d)
91 {
92 return container_of(d, struct spmi_controller, dev);
93 }
94
95 static inline
96 void *spmi_controller_get_drvdata(const struct spmi_controller *ctrl)
97 {
98 return dev_get_drvdata(&ctrl->dev);
99 }
100
101 static inline void spmi_controller_set_drvdata(struct spmi_controller *ctrl,
102 void *data)
103 {
104 dev_set_drvdata(&ctrl->dev, data);
105 }
106
107 struct spmi_controller *spmi_controller_alloc(struct device *parent,
108 size_t size);
109
110
111
112
113
114 static inline void spmi_controller_put(struct spmi_controller *ctrl)
115 {
116 if (ctrl)
117 put_device(&ctrl->dev);
118 }
119
120 int spmi_controller_add(struct spmi_controller *ctrl);
121 void spmi_controller_remove(struct spmi_controller *ctrl);
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137 struct spmi_driver {
138 struct device_driver driver;
139 int (*probe)(struct spmi_device *sdev);
140 void (*remove)(struct spmi_device *sdev);
141 };
142
143 static inline struct spmi_driver *to_spmi_driver(struct device_driver *d)
144 {
145 return container_of(d, struct spmi_driver, driver);
146 }
147
148 #define spmi_driver_register(sdrv) \
149 __spmi_driver_register(sdrv, THIS_MODULE)
150 int __spmi_driver_register(struct spmi_driver *sdrv, struct module *owner);
151
152
153
154
155
156 static inline void spmi_driver_unregister(struct spmi_driver *sdrv)
157 {
158 if (sdrv)
159 driver_unregister(&sdrv->driver);
160 }
161
162 #define module_spmi_driver(__spmi_driver) \
163 module_driver(__spmi_driver, spmi_driver_register, \
164 spmi_driver_unregister)
165
166 int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf);
167 int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf,
168 size_t len);
169 int spmi_ext_register_readl(struct spmi_device *sdev, u16 addr, u8 *buf,
170 size_t len);
171 int spmi_register_write(struct spmi_device *sdev, u8 addr, u8 data);
172 int spmi_register_zero_write(struct spmi_device *sdev, u8 data);
173 int spmi_ext_register_write(struct spmi_device *sdev, u8 addr,
174 const u8 *buf, size_t len);
175 int spmi_ext_register_writel(struct spmi_device *sdev, u16 addr,
176 const u8 *buf, size_t len);
177 int spmi_command_reset(struct spmi_device *sdev);
178 int spmi_command_sleep(struct spmi_device *sdev);
179 int spmi_command_wakeup(struct spmi_device *sdev);
180 int spmi_command_shutdown(struct spmi_device *sdev);
181
182 #endif