Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
0003  */
0004 #ifndef _LINUX_SPMI_H
0005 #define _LINUX_SPMI_H
0006 
0007 #include <linux/types.h>
0008 #include <linux/device.h>
0009 #include <linux/mod_devicetable.h>
0010 
0011 /* Maximum slave identifier */
0012 #define SPMI_MAX_SLAVE_ID       16
0013 
0014 /* SPMI Commands */
0015 #define SPMI_CMD_EXT_WRITE      0x00
0016 #define SPMI_CMD_RESET          0x10
0017 #define SPMI_CMD_SLEEP          0x11
0018 #define SPMI_CMD_SHUTDOWN       0x12
0019 #define SPMI_CMD_WAKEUP         0x13
0020 #define SPMI_CMD_AUTHENTICATE       0x14
0021 #define SPMI_CMD_MSTR_READ      0x15
0022 #define SPMI_CMD_MSTR_WRITE     0x16
0023 #define SPMI_CMD_TRANSFER_BUS_OWNERSHIP 0x1A
0024 #define SPMI_CMD_DDB_MASTER_READ    0x1B
0025 #define SPMI_CMD_DDB_SLAVE_READ     0x1C
0026 #define SPMI_CMD_EXT_READ       0x20
0027 #define SPMI_CMD_EXT_WRITEL     0x30
0028 #define SPMI_CMD_EXT_READL      0x38
0029 #define SPMI_CMD_WRITE          0x40
0030 #define SPMI_CMD_READ           0x60
0031 #define SPMI_CMD_ZERO_WRITE     0x80
0032 
0033 /**
0034  * struct spmi_device - Basic representation of an SPMI device
0035  * @dev:    Driver model representation of the device.
0036  * @ctrl:   SPMI controller managing the bus hosting this device.
0037  * @usid:   This devices' Unique Slave IDentifier.
0038  */
0039 struct spmi_device {
0040     struct device       dev;
0041     struct spmi_controller  *ctrl;
0042     u8          usid;
0043 };
0044 
0045 static inline struct spmi_device *to_spmi_device(struct device *d)
0046 {
0047     return container_of(d, struct spmi_device, dev);
0048 }
0049 
0050 static inline void *spmi_device_get_drvdata(const struct spmi_device *sdev)
0051 {
0052     return dev_get_drvdata(&sdev->dev);
0053 }
0054 
0055 static inline void spmi_device_set_drvdata(struct spmi_device *sdev, void *data)
0056 {
0057     dev_set_drvdata(&sdev->dev, data);
0058 }
0059 
0060 struct spmi_device *spmi_device_alloc(struct spmi_controller *ctrl);
0061 
0062 static inline void spmi_device_put(struct spmi_device *sdev)
0063 {
0064     if (sdev)
0065         put_device(&sdev->dev);
0066 }
0067 
0068 int spmi_device_add(struct spmi_device *sdev);
0069 
0070 void spmi_device_remove(struct spmi_device *sdev);
0071 
0072 /**
0073  * struct spmi_controller - interface to the SPMI master controller
0074  * @dev:    Driver model representation of the device.
0075  * @nr:     board-specific number identifier for this controller/bus
0076  * @cmd:    sends a non-data command sequence on the SPMI bus.
0077  * @read_cmd:   sends a register read command sequence on the SPMI bus.
0078  * @write_cmd:  sends a register write command sequence on the SPMI bus.
0079  */
0080 struct spmi_controller {
0081     struct device       dev;
0082     unsigned int        nr;
0083     int (*cmd)(struct spmi_controller *ctrl, u8 opcode, u8 sid);
0084     int (*read_cmd)(struct spmi_controller *ctrl, u8 opcode,
0085                 u8 sid, u16 addr, u8 *buf, size_t len);
0086     int (*write_cmd)(struct spmi_controller *ctrl, u8 opcode,
0087                  u8 sid, u16 addr, const u8 *buf, size_t len);
0088 };
0089 
0090 static inline struct spmi_controller *to_spmi_controller(struct device *d)
0091 {
0092     return container_of(d, struct spmi_controller, dev);
0093 }
0094 
0095 static inline
0096 void *spmi_controller_get_drvdata(const struct spmi_controller *ctrl)
0097 {
0098     return dev_get_drvdata(&ctrl->dev);
0099 }
0100 
0101 static inline void spmi_controller_set_drvdata(struct spmi_controller *ctrl,
0102                            void *data)
0103 {
0104     dev_set_drvdata(&ctrl->dev, data);
0105 }
0106 
0107 struct spmi_controller *spmi_controller_alloc(struct device *parent,
0108                           size_t size);
0109 
0110 /**
0111  * spmi_controller_put() - decrement controller refcount
0112  * @ctrl    SPMI controller.
0113  */
0114 static inline void spmi_controller_put(struct spmi_controller *ctrl)
0115 {
0116     if (ctrl)
0117         put_device(&ctrl->dev);
0118 }
0119 
0120 int spmi_controller_add(struct spmi_controller *ctrl);
0121 void spmi_controller_remove(struct spmi_controller *ctrl);
0122 
0123 /**
0124  * struct spmi_driver - SPMI slave device driver
0125  * @driver: SPMI device drivers should initialize name and owner field of
0126  *      this structure.
0127  * @probe:  binds this driver to a SPMI device.
0128  * @remove: unbinds this driver from the SPMI device.
0129  *
0130  * If PM runtime support is desired for a slave, a device driver can call
0131  * pm_runtime_put() from their probe() routine (and a balancing
0132  * pm_runtime_get() in remove()).  PM runtime support for a slave is
0133  * implemented by issuing a SLEEP command to the slave on runtime_suspend(),
0134  * transitioning the slave into the SLEEP state.  On runtime_resume(), a WAKEUP
0135  * command is sent to the slave to bring it back to ACTIVE.
0136  */
0137 struct spmi_driver {
0138     struct device_driver driver;
0139     int (*probe)(struct spmi_device *sdev);
0140     void    (*remove)(struct spmi_device *sdev);
0141     void    (*shutdown)(struct spmi_device *sdev);
0142 };
0143 
0144 static inline struct spmi_driver *to_spmi_driver(struct device_driver *d)
0145 {
0146     return container_of(d, struct spmi_driver, driver);
0147 }
0148 
0149 #define spmi_driver_register(sdrv) \
0150     __spmi_driver_register(sdrv, THIS_MODULE)
0151 int __spmi_driver_register(struct spmi_driver *sdrv, struct module *owner);
0152 
0153 /**
0154  * spmi_driver_unregister() - unregister an SPMI client driver
0155  * @sdrv:   the driver to unregister
0156  */
0157 static inline void spmi_driver_unregister(struct spmi_driver *sdrv)
0158 {
0159     if (sdrv)
0160         driver_unregister(&sdrv->driver);
0161 }
0162 
0163 #define module_spmi_driver(__spmi_driver) \
0164     module_driver(__spmi_driver, spmi_driver_register, \
0165             spmi_driver_unregister)
0166 
0167 struct device_node;
0168 
0169 struct spmi_device *spmi_device_from_of(struct device_node *np);
0170 int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf);
0171 int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf,
0172                size_t len);
0173 int spmi_ext_register_readl(struct spmi_device *sdev, u16 addr, u8 *buf,
0174                 size_t len);
0175 int spmi_register_write(struct spmi_device *sdev, u8 addr, u8 data);
0176 int spmi_register_zero_write(struct spmi_device *sdev, u8 data);
0177 int spmi_ext_register_write(struct spmi_device *sdev, u8 addr,
0178                 const u8 *buf, size_t len);
0179 int spmi_ext_register_writel(struct spmi_device *sdev, u16 addr,
0180                  const u8 *buf, size_t len);
0181 int spmi_command_reset(struct spmi_device *sdev);
0182 int spmi_command_sleep(struct spmi_device *sdev);
0183 int spmi_command_wakeup(struct spmi_device *sdev);
0184 int spmi_command_shutdown(struct spmi_device *sdev);
0185 
0186 #endif