diff options
| author | Kenneth Heitke <kheitke@codeaurora.org> | 2014-02-12 14:44:22 -0500 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-02-15 14:55:28 -0500 |
| commit | 5a86bf343976b9c8ab2f240bc866451fa67e5573 (patch) | |
| tree | 26868658105a10869ca43d9eaf72098674eeb458 /include/linux | |
| parent | a2a720e15f59be60c7ae1c58b5b4ac1003dd5078 (diff) | |
spmi: Linux driver framework for SPMI
System Power Management Interface (SPMI) is a specification
developed by the MIPI (Mobile Industry Process Interface) Alliance
optimized for the real time control of Power Management ICs (PMIC).
SPMI is a two-wire serial interface that supports up to 4 master
devices and up to 16 logical slaves.
The framework supports message APIs, multiple busses (1 controller
per bus) and multiple clients/slave devices per controller.
Signed-off-by: Kenneth Heitke <kheitke@codeaurora.org>
Signed-off-by: Michael Bohan <mbohan@codeaurora.org>
Signed-off-by: Josh Cartwright <joshc@codeaurora.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/mod_devicetable.h | 8 | ||||
| -rw-r--r-- | include/linux/spmi.h | 191 |
2 files changed, 199 insertions, 0 deletions
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index 45e921401b06..677e474fc273 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h | |||
| @@ -432,6 +432,14 @@ struct spi_device_id { | |||
| 432 | kernel_ulong_t driver_data; /* Data private to the driver */ | 432 | kernel_ulong_t driver_data; /* Data private to the driver */ |
| 433 | }; | 433 | }; |
| 434 | 434 | ||
| 435 | #define SPMI_NAME_SIZE 32 | ||
| 436 | #define SPMI_MODULE_PREFIX "spmi:" | ||
| 437 | |||
| 438 | struct spmi_device_id { | ||
| 439 | char name[SPMI_NAME_SIZE]; | ||
| 440 | kernel_ulong_t driver_data; /* Data private to the driver */ | ||
| 441 | }; | ||
| 442 | |||
| 435 | /* dmi */ | 443 | /* dmi */ |
| 436 | enum dmi_field { | 444 | enum dmi_field { |
| 437 | DMI_NONE, | 445 | DMI_NONE, |
diff --git a/include/linux/spmi.h b/include/linux/spmi.h new file mode 100644 index 000000000000..91f5eab9e428 --- /dev/null +++ b/include/linux/spmi.h | |||
| @@ -0,0 +1,191 @@ | |||
| 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. | ||
| 2 | * | ||
| 3 | * This program is free software; you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License version 2 and | ||
| 5 | * only version 2 as published by the Free Software Foundation. | ||
| 6 | * | ||
| 7 | * This program is distributed in the hope that it will be useful, | ||
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 10 | * GNU General Public License for more details. | ||
| 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 | /* Maximum slave identifier */ | ||
| 20 | #define SPMI_MAX_SLAVE_ID 16 | ||
| 21 | |||
| 22 | /* SPMI Commands */ | ||
| 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 | * struct spmi_device - Basic representation of an SPMI device | ||
| 43 | * @dev: Driver model representation of the device. | ||
| 44 | * @ctrl: SPMI controller managing the bus hosting this device. | ||
| 45 | * @usid: This devices' Unique Slave IDentifier. | ||
| 46 | */ | ||
| 47 | struct spmi_device { | ||
| 48 | struct device dev; | ||
| 49 | struct spmi_controller *ctrl; | ||
| 50 | u8 usid; | ||
| 51 | }; | ||
| 52 | |||
| 53 | static inline struct spmi_device *to_spmi_device(struct device *d) | ||
| 54 | { | ||
| 55 | return container_of(d, struct spmi_device, dev); | ||
| 56 | } | ||
| 57 | |||
| 58 | static inline void *spmi_device_get_drvdata(const struct spmi_device *sdev) | ||
| 59 | { | ||
| 60 | return dev_get_drvdata(&sdev->dev); | ||
| 61 | } | ||
| 62 | |||
| 63 | static inline void spmi_device_set_drvdata(struct spmi_device *sdev, void *data) | ||
| 64 | { | ||
| 65 | dev_set_drvdata(&sdev->dev, data); | ||
| 66 | } | ||
| 67 | |||
| 68 | struct spmi_device *spmi_device_alloc(struct spmi_controller *ctrl); | ||
| 69 | |||
| 70 | static inline void spmi_device_put(struct spmi_device *sdev) | ||
| 71 | { | ||
| 72 | if (sdev) | ||
| 73 | put_device(&sdev->dev); | ||
| 74 | } | ||
| 75 | |||
| 76 | int spmi_device_add(struct spmi_device *sdev); | ||
| 77 | |||
| 78 | void spmi_device_remove(struct spmi_device *sdev); | ||
| 79 | |||
| 80 | /** | ||
| 81 | * struct spmi_controller - interface to the SPMI master controller | ||
| 82 | * @dev: Driver model representation of the device. | ||
| 83 | * @nr: board-specific number identifier for this controller/bus | ||
| 84 | * @cmd: sends a non-data command sequence on the SPMI bus. | ||
| 85 | * @read_cmd: sends a register read command sequence on the SPMI bus. | ||
| 86 | * @write_cmd: sends a register write command sequence on the SPMI bus. | ||
| 87 | */ | ||
| 88 | struct 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 | |||
| 98 | static inline struct spmi_controller *to_spmi_controller(struct device *d) | ||
| 99 | { | ||
| 100 | return container_of(d, struct spmi_controller, dev); | ||
| 101 | } | ||
| 102 | |||
| 103 | static inline | ||
| 104 | void *spmi_controller_get_drvdata(const struct spmi_controller *ctrl) | ||
| 105 | { | ||
| 106 | return dev_get_drvdata(&ctrl->dev); | ||
| 107 | } | ||
| 108 | |||
| 109 | static inline void spmi_controller_set_drvdata(struct spmi_controller *ctrl, | ||
| 110 | void *data) | ||
| 111 | { | ||
| 112 | dev_set_drvdata(&ctrl->dev, data); | ||
| 113 | } | ||
| 114 | |||
| 115 | struct spmi_controller *spmi_controller_alloc(struct device *parent, | ||
| 116 | size_t size); | ||
| 117 | |||
| 118 | /** | ||
| 119 | * spmi_controller_put() - decrement controller refcount | ||
| 120 | * @ctrl SPMI controller. | ||
| 121 | */ | ||
| 122 | static inline void spmi_controller_put(struct spmi_controller *ctrl) | ||
| 123 | { | ||
| 124 | if (ctrl) | ||
| 125 | put_device(&ctrl->dev); | ||
| 126 | } | ||
| 127 | |||
| 128 | int spmi_controller_add(struct spmi_controller *ctrl); | ||
| 129 | void spmi_controller_remove(struct spmi_controller *ctrl); | ||
| 130 | |||
| 131 | /** | ||
| 132 | * struct spmi_driver - SPMI slave device driver | ||
| 133 | * @driver: SPMI device drivers should initialize name and owner field of | ||
| 134 | * this structure. | ||
| 135 | * @probe: binds this driver to a SPMI device. | ||
| 136 | * @remove: unbinds this driver from the SPMI device. | ||
| 137 | * @shutdown: standard shutdown callback used during powerdown/halt. | ||
| 138 | * @suspend: standard suspend callback used during system suspend. | ||
| 139 | * @resume: standard resume callback used during system resume. | ||
| 140 | * | ||
| 141 | * If PM runtime support is desired for a slave, a device driver can call | ||
| 142 | * pm_runtime_put() from their probe() routine (and a balancing | ||
| 143 | * pm_runtime_get() in remove()). PM runtime support for a slave is | ||
| 144 | * implemented by issuing a SLEEP command to the slave on runtime_suspend(), | ||
| 145 | * transitioning the slave into the SLEEP state. On runtime_resume(), a WAKEUP | ||
| 146 | * command is sent to the slave to bring it back to ACTIVE. | ||
| 147 | */ | ||
| 148 | struct spmi_driver { | ||
| 149 | struct device_driver driver; | ||
| 150 | int (*probe)(struct spmi_device *sdev); | ||
| 151 | void (*remove)(struct spmi_device *sdev); | ||
| 152 | }; | ||
| 153 | |||
| 154 | static inline struct spmi_driver *to_spmi_driver(struct device_driver *d) | ||
| 155 | { | ||
| 156 | return container_of(d, struct spmi_driver, driver); | ||
| 157 | } | ||
| 158 | |||
| 159 | int spmi_driver_register(struct spmi_driver *sdrv); | ||
| 160 | |||
| 161 | /** | ||
| 162 | * spmi_driver_unregister() - unregister an SPMI client driver | ||
| 163 | * @sdrv: the driver to unregister | ||
| 164 | */ | ||
| 165 | static 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 | |||
| 175 | int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf); | ||
| 176 | int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf, | ||
| 177 | size_t len); | ||
| 178 | int spmi_ext_register_readl(struct spmi_device *sdev, u16 addr, u8 *buf, | ||
| 179 | size_t len); | ||
| 180 | int spmi_register_write(struct spmi_device *sdev, u8 addr, u8 data); | ||
| 181 | int spmi_register_zero_write(struct spmi_device *sdev, u8 data); | ||
| 182 | int spmi_ext_register_write(struct spmi_device *sdev, u8 addr, | ||
| 183 | const u8 *buf, size_t len); | ||
| 184 | int spmi_ext_register_writel(struct spmi_device *sdev, u16 addr, | ||
| 185 | const u8 *buf, size_t len); | ||
| 186 | int spmi_command_reset(struct spmi_device *sdev); | ||
| 187 | int spmi_command_sleep(struct spmi_device *sdev); | ||
| 188 | int spmi_command_wakeup(struct spmi_device *sdev); | ||
| 189 | int spmi_command_shutdown(struct spmi_device *sdev); | ||
| 190 | |||
| 191 | #endif | ||
