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