1 /* SPDX-License-Identifier: GPL-2.0-only */ << 2 /* Copyright (c) 2012-2013, The Linux Foundati 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. 3 */ 11 */ 4 #ifndef _LINUX_SPMI_H 12 #ifndef _LINUX_SPMI_H 5 #define _LINUX_SPMI_H 13 #define _LINUX_SPMI_H 6 14 7 #include <linux/types.h> 15 #include <linux/types.h> 8 #include <linux/device.h> 16 #include <linux/device.h> 9 #include <linux/mod_devicetable.h> 17 #include <linux/mod_devicetable.h> 10 18 11 /* Maximum slave identifier */ 19 /* Maximum slave identifier */ 12 #define SPMI_MAX_SLAVE_ID 16 20 #define SPMI_MAX_SLAVE_ID 16 13 21 14 /* SPMI Commands */ 22 /* SPMI Commands */ 15 #define SPMI_CMD_EXT_WRITE 0x00 23 #define SPMI_CMD_EXT_WRITE 0x00 16 #define SPMI_CMD_RESET 0x10 24 #define SPMI_CMD_RESET 0x10 17 #define SPMI_CMD_SLEEP 0x11 25 #define SPMI_CMD_SLEEP 0x11 18 #define SPMI_CMD_SHUTDOWN 0x12 26 #define SPMI_CMD_SHUTDOWN 0x12 19 #define SPMI_CMD_WAKEUP 0x13 27 #define SPMI_CMD_WAKEUP 0x13 20 #define SPMI_CMD_AUTHENTICATE 0x14 28 #define SPMI_CMD_AUTHENTICATE 0x14 21 #define SPMI_CMD_MSTR_READ 0x15 29 #define SPMI_CMD_MSTR_READ 0x15 22 #define SPMI_CMD_MSTR_WRITE 0x16 30 #define SPMI_CMD_MSTR_WRITE 0x16 23 #define SPMI_CMD_TRANSFER_BUS_OWNERSHIP 0x1A 31 #define SPMI_CMD_TRANSFER_BUS_OWNERSHIP 0x1A 24 #define SPMI_CMD_DDB_MASTER_READ 0x1B 32 #define SPMI_CMD_DDB_MASTER_READ 0x1B 25 #define SPMI_CMD_DDB_SLAVE_READ 0x1C 33 #define SPMI_CMD_DDB_SLAVE_READ 0x1C 26 #define SPMI_CMD_EXT_READ 0x20 34 #define SPMI_CMD_EXT_READ 0x20 27 #define SPMI_CMD_EXT_WRITEL 0x30 35 #define SPMI_CMD_EXT_WRITEL 0x30 28 #define SPMI_CMD_EXT_READL 0x38 36 #define SPMI_CMD_EXT_READL 0x38 29 #define SPMI_CMD_WRITE 0x40 37 #define SPMI_CMD_WRITE 0x40 30 #define SPMI_CMD_READ 0x60 38 #define SPMI_CMD_READ 0x60 31 #define SPMI_CMD_ZERO_WRITE 0x80 39 #define SPMI_CMD_ZERO_WRITE 0x80 32 40 33 /** 41 /** 34 * struct spmi_device - Basic representation o 42 * struct spmi_device - Basic representation of an SPMI device 35 * @dev: Driver model representation of 43 * @dev: Driver model representation of the device. 36 * @ctrl: SPMI controller managing the b 44 * @ctrl: SPMI controller managing the bus hosting this device. 37 * @usid: This devices' Unique Slave IDe 45 * @usid: This devices' Unique Slave IDentifier. 38 */ 46 */ 39 struct spmi_device { 47 struct spmi_device { 40 struct device dev; 48 struct device dev; 41 struct spmi_controller *ctrl; 49 struct spmi_controller *ctrl; 42 u8 usid; 50 u8 usid; 43 }; 51 }; 44 52 45 static inline struct spmi_device *to_spmi_devi 53 static inline struct spmi_device *to_spmi_device(struct device *d) 46 { 54 { 47 return container_of(d, struct spmi_dev 55 return container_of(d, struct spmi_device, dev); 48 } 56 } 49 57 50 static inline void *spmi_device_get_drvdata(co 58 static inline void *spmi_device_get_drvdata(const struct spmi_device *sdev) 51 { 59 { 52 return dev_get_drvdata(&sdev->dev); 60 return dev_get_drvdata(&sdev->dev); 53 } 61 } 54 62 55 static inline void spmi_device_set_drvdata(str 63 static inline void spmi_device_set_drvdata(struct spmi_device *sdev, void *data) 56 { 64 { 57 dev_set_drvdata(&sdev->dev, data); 65 dev_set_drvdata(&sdev->dev, data); 58 } 66 } 59 67 60 struct spmi_device *spmi_device_alloc(struct s 68 struct spmi_device *spmi_device_alloc(struct spmi_controller *ctrl); 61 69 62 static inline void spmi_device_put(struct spmi 70 static inline void spmi_device_put(struct spmi_device *sdev) 63 { 71 { 64 if (sdev) 72 if (sdev) 65 put_device(&sdev->dev); 73 put_device(&sdev->dev); 66 } 74 } 67 75 68 int spmi_device_add(struct spmi_device *sdev); 76 int spmi_device_add(struct spmi_device *sdev); 69 77 70 void spmi_device_remove(struct spmi_device *sd 78 void spmi_device_remove(struct spmi_device *sdev); 71 79 72 /** 80 /** 73 * struct spmi_controller - interface to the S 81 * struct spmi_controller - interface to the SPMI master controller 74 * @dev: Driver model representation of 82 * @dev: Driver model representation of the device. 75 * @nr: board-specific number identifi 83 * @nr: board-specific number identifier for this controller/bus 76 * @cmd: sends a non-data command seque 84 * @cmd: sends a non-data command sequence on the SPMI bus. 77 * @read_cmd: sends a register read command 85 * @read_cmd: sends a register read command sequence on the SPMI bus. 78 * @write_cmd: sends a register write command 86 * @write_cmd: sends a register write command sequence on the SPMI bus. 79 */ 87 */ 80 struct spmi_controller { 88 struct spmi_controller { 81 struct device dev; 89 struct device dev; 82 unsigned int nr; 90 unsigned int nr; 83 int (*cmd)(struct spmi_controller 91 int (*cmd)(struct spmi_controller *ctrl, u8 opcode, u8 sid); 84 int (*read_cmd)(struct spmi_contro 92 int (*read_cmd)(struct spmi_controller *ctrl, u8 opcode, 85 u8 sid, u16 addr, 93 u8 sid, u16 addr, u8 *buf, size_t len); 86 int (*write_cmd)(struct spmi_contr 94 int (*write_cmd)(struct spmi_controller *ctrl, u8 opcode, 87 u8 sid, u16 addr, 95 u8 sid, u16 addr, const u8 *buf, size_t len); 88 }; 96 }; 89 97 90 static inline struct spmi_controller *to_spmi_ 98 static inline struct spmi_controller *to_spmi_controller(struct device *d) 91 { 99 { 92 return container_of(d, struct spmi_con 100 return container_of(d, struct spmi_controller, dev); 93 } 101 } 94 102 95 static inline 103 static inline 96 void *spmi_controller_get_drvdata(const struct 104 void *spmi_controller_get_drvdata(const struct spmi_controller *ctrl) 97 { 105 { 98 return dev_get_drvdata(&ctrl->dev); 106 return dev_get_drvdata(&ctrl->dev); 99 } 107 } 100 108 101 static inline void spmi_controller_set_drvdata 109 static inline void spmi_controller_set_drvdata(struct spmi_controller *ctrl, 102 110 void *data) 103 { 111 { 104 dev_set_drvdata(&ctrl->dev, data); 112 dev_set_drvdata(&ctrl->dev, data); 105 } 113 } 106 114 107 struct spmi_controller *spmi_controller_alloc( 115 struct spmi_controller *spmi_controller_alloc(struct device *parent, 108 116 size_t size); 109 117 110 /** 118 /** 111 * spmi_controller_put() - decrement controlle 119 * spmi_controller_put() - decrement controller refcount 112 * @ctrl SPMI controller. 120 * @ctrl SPMI controller. 113 */ 121 */ 114 static inline void spmi_controller_put(struct 122 static inline void spmi_controller_put(struct spmi_controller *ctrl) 115 { 123 { 116 if (ctrl) 124 if (ctrl) 117 put_device(&ctrl->dev); 125 put_device(&ctrl->dev); 118 } 126 } 119 127 120 int spmi_controller_add(struct spmi_controller 128 int spmi_controller_add(struct spmi_controller *ctrl); 121 void spmi_controller_remove(struct spmi_contro 129 void spmi_controller_remove(struct spmi_controller *ctrl); 122 130 123 struct spmi_controller *devm_spmi_controller_a << 124 int devm_spmi_controller_add(struct device *pa << 125 << 126 /** 131 /** 127 * struct spmi_driver - SPMI slave device driv 132 * struct spmi_driver - SPMI slave device driver 128 * @driver: SPMI device drivers should ini 133 * @driver: SPMI device drivers should initialize name and owner field of 129 * this structure. 134 * this structure. 130 * @probe: binds this driver to a SPMI de 135 * @probe: binds this driver to a SPMI device. 131 * @remove: unbinds this driver from the S 136 * @remove: unbinds this driver from the SPMI device. 132 * 137 * 133 * If PM runtime support is desired for a slav 138 * If PM runtime support is desired for a slave, a device driver can call 134 * pm_runtime_put() from their probe() routine 139 * pm_runtime_put() from their probe() routine (and a balancing 135 * pm_runtime_get() in remove()). PM runtime 140 * pm_runtime_get() in remove()). PM runtime support for a slave is 136 * implemented by issuing a SLEEP command to t 141 * implemented by issuing a SLEEP command to the slave on runtime_suspend(), 137 * transitioning the slave into the SLEEP stat 142 * transitioning the slave into the SLEEP state. On runtime_resume(), a WAKEUP 138 * command is sent to the slave to bring it ba 143 * command is sent to the slave to bring it back to ACTIVE. 139 */ 144 */ 140 struct spmi_driver { 145 struct spmi_driver { 141 struct device_driver driver; 146 struct device_driver driver; 142 int (*probe)(struct spmi_device *s 147 int (*probe)(struct spmi_device *sdev); 143 void (*remove)(struct spmi_device * 148 void (*remove)(struct spmi_device *sdev); 144 void (*shutdown)(struct spmi_device << 145 }; 149 }; 146 150 147 static inline struct spmi_driver *to_spmi_driv 151 static inline struct spmi_driver *to_spmi_driver(struct device_driver *d) 148 { 152 { 149 return container_of(d, struct spmi_dri 153 return container_of(d, struct spmi_driver, driver); 150 } 154 } 151 155 152 #define spmi_driver_register(sdrv) \ 156 #define spmi_driver_register(sdrv) \ 153 __spmi_driver_register(sdrv, THIS_MODU 157 __spmi_driver_register(sdrv, THIS_MODULE) 154 int __spmi_driver_register(struct spmi_driver 158 int __spmi_driver_register(struct spmi_driver *sdrv, struct module *owner); 155 159 156 /** 160 /** 157 * spmi_driver_unregister() - unregister an SP 161 * spmi_driver_unregister() - unregister an SPMI client driver 158 * @sdrv: the driver to unregister 162 * @sdrv: the driver to unregister 159 */ 163 */ 160 static inline void spmi_driver_unregister(stru 164 static inline void spmi_driver_unregister(struct spmi_driver *sdrv) 161 { 165 { 162 if (sdrv) 166 if (sdrv) 163 driver_unregister(&sdrv->drive 167 driver_unregister(&sdrv->driver); 164 } 168 } 165 169 166 #define module_spmi_driver(__spmi_driver) \ 170 #define module_spmi_driver(__spmi_driver) \ 167 module_driver(__spmi_driver, spmi_driv 171 module_driver(__spmi_driver, spmi_driver_register, \ 168 spmi_driver_unregister 172 spmi_driver_unregister) 169 173 170 struct device_node; << 171 << 172 struct spmi_device *spmi_find_device_by_of_nod << 173 int spmi_register_read(struct spmi_device *sde 174 int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf); 174 int spmi_ext_register_read(struct spmi_device 175 int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf, 175 size_t len); 176 size_t len); 176 int spmi_ext_register_readl(struct spmi_device 177 int spmi_ext_register_readl(struct spmi_device *sdev, u16 addr, u8 *buf, 177 size_t len); 178 size_t len); 178 int spmi_register_write(struct spmi_device *sd 179 int spmi_register_write(struct spmi_device *sdev, u8 addr, u8 data); 179 int spmi_register_zero_write(struct spmi_devic 180 int spmi_register_zero_write(struct spmi_device *sdev, u8 data); 180 int spmi_ext_register_write(struct spmi_device 181 int spmi_ext_register_write(struct spmi_device *sdev, u8 addr, 181 const u8 *buf, siz 182 const u8 *buf, size_t len); 182 int spmi_ext_register_writel(struct spmi_devic 183 int spmi_ext_register_writel(struct spmi_device *sdev, u16 addr, 183 const u8 *buf, si 184 const u8 *buf, size_t len); 184 int spmi_command_reset(struct spmi_device *sde 185 int spmi_command_reset(struct spmi_device *sdev); 185 int spmi_command_sleep(struct spmi_device *sde 186 int spmi_command_sleep(struct spmi_device *sdev); 186 int spmi_command_wakeup(struct spmi_device *sd 187 int spmi_command_wakeup(struct spmi_device *sdev); 187 int spmi_command_shutdown(struct spmi_device * 188 int spmi_command_shutdown(struct spmi_device *sdev); 188 189 189 #endif 190 #endif 190 191
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.