123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- /* Copyright (c) 2012-2014, 2016 The Linux Foundation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #ifndef _LINUX_SPMI_H
- #define _LINUX_SPMI_H
- #include <linux/types.h>
- #include <linux/device.h>
- #include <linux/mod_devicetable.h>
- /* Maximum slave identifier */
- #define SPMI_MAX_SLAVE_ID 16
- /* SPMI Commands */
- enum spmi_commands {
- SPMI_CMD_EXT_WRITE = 0x00,
- SPMI_CMD_RESET = 0x10,
- SPMI_CMD_SLEEP = 0x11,
- SPMI_CMD_SHUTDOWN = 0x12,
- SPMI_CMD_WAKEUP = 0x13,
- SPMI_CMD_AUTHENTICATE = 0x14,
- SPMI_CMD_MSTR_READ = 0x15,
- SPMI_CMD_MSTR_WRITE = 0x16,
- SPMI_CMD_TRANSFER_BUS_OWNERSHIP = 0x1A,
- SPMI_CMD_DDB_MASTER_READ = 0x1B,
- SPMI_CMD_DDB_SLAVE_READ = 0x1C,
- SPMI_CMD_EXT_READ = 0x20,
- SPMI_CMD_EXT_WRITEL = 0x30,
- SPMI_CMD_EXT_READL = 0x38,
- SPMI_CMD_WRITE = 0x40,
- SPMI_CMD_READ = 0x60,
- SPMI_CMD_ZERO_WRITE = 0x80,
- };
- struct spmi_device;
- /**
- * struct spmi_controller: interface to the SPMI master controller
- * @nr: board-specific number identifier for this controller/bus
- * @name: name for this controller
- * @cmd: sends a non-data command sequence on the SPMI bus.
- * @read_cmd: sends a register read command sequence on the SPMI bus.
- * @write_cmd: sends a register write command sequence on the SPMI bus.
- */
- struct spmi_controller {
- struct device dev;
- unsigned int nr;
- struct completion dev_released;
- int (*cmd)(struct spmi_controller *, u8 opcode, u8 sid);
- int (*read_cmd)(struct spmi_controller *,
- u8 opcode, u8 sid, u16 addr, u8 bc, u8 *buf);
- int (*write_cmd)(struct spmi_controller *,
- u8 opcode, u8 sid, u16 addr, u8 bc, u8 *buf);
- };
- #define to_spmi_controller(d) container_of(d, struct spmi_controller, dev)
- /**
- * struct spmi_driver: Manage SPMI generic/slave device driver
- * @probe: binds this driver to a SPMI device.
- * @remove: unbinds this driver from the SPMI device.
- * @shutdown: standard shutdown callback used during powerdown/halt.
- * @suspend: standard suspend callback used during system suspend
- * @resume: standard resume callback used during system resume
- * @driver: SPMI device drivers should initialize name and owner field of
- * this structure
- * @id_table: list of SPMI devices supported by this driver
- */
- struct spmi_driver {
- int (*probe)(struct spmi_device *dev);
- int (*remove)(struct spmi_device *dev);
- void (*shutdown)(struct spmi_device *dev);
- int (*suspend)(struct spmi_device *dev,
- pm_message_t pmesg);
- int (*resume)(struct spmi_device *dev);
- struct device_driver driver;
- const struct spmi_device_id *id_table;
- };
- #define to_spmi_driver(d) container_of(d, struct spmi_driver, driver)
- /**
- * struct spmi_resource: spmi_resource for one device_node
- * @num_resources: number of resources for this device node
- * @resources: array of resources for this device_node
- * @of_node: device_node of the resource in question
- * @label: name used to reference the device from the driver
- *
- * Note that we explicitly add a 'label' pointer here since per
- * the ePAPR 2.2.2, the device_node->name should be generic and not
- * reflect precise programming model. Thus label enables a
- * platform specific name to be assigned with the 'label' binding to
- * allow for unique query names.
- */
- struct spmi_resource {
- struct resource *resource;
- u32 num_resources;
- struct device_node *of_node;
- const char *label;
- };
- /**
- * Client/device handle (struct spmi_device):
- * ------------------------------------------
- * This is the client/device handle returned when a SPMI device
- * is registered with a controller.
- * Pointer to this structure is used by client-driver as a handle.
- * @dev: Driver model representation of the device.
- * @name: Name of driver to use with this device.
- * @ctrl: SPMI controller managing the bus hosting this device.
- * @res: SPMI resource for the primary node
- * @dev_node: array of SPMI resources when used with spmi-dev-container.
- * @num_dev_node: number of device_node structures.
- * @sid: Slave Identifier.
- * @id: Unique identifier to differentiate from other spmi devices with
- * possibly same name.
- *
- */
- struct spmi_device {
- struct device dev;
- const char *name;
- struct spmi_controller *ctrl;
- struct spmi_resource res;
- struct spmi_resource *dev_node;
- u32 num_dev_node;
- u8 sid;
- int id;
- };
- #define to_spmi_device(d) container_of(d, struct spmi_device, dev)
- /**
- * struct spmi_boardinfo: Declare board info for SPMI device bringup.
- * @name: Name of driver to use with this device.
- * @slave_id: slave identifier.
- * @spmi_device: device to be registered with the SPMI framework.
- * @of_node: pointer to the OpenFirmware device node.
- * @res: SPMI resource for the primary node
- * @dev_node: array of SPMI resources when used with spmi-dev-container.
- * @num_dev_node: number of device_node structures.
- * @platform_data: goes to spmi_device.dev.platform_data
- */
- struct spmi_boardinfo {
- char name[SPMI_NAME_SIZE];
- uint8_t slave_id;
- struct device_node *of_node;
- struct spmi_resource res;
- struct spmi_resource *dev_node;
- u32 num_dev_node;
- const void *platform_data;
- };
- /**
- * spmi_driver_register: Client driver registration with SPMI framework.
- * @drv: client driver to be associated with client-device.
- *
- * This API will register the client driver with the SPMI framework.
- * It is called from the driver's module-init function.
- */
- extern int spmi_driver_register(struct spmi_driver *drv);
- /**
- * spmi_driver_unregister - reverse effect of spmi_driver_register
- * @sdrv: the driver to unregister
- * Context: can sleep
- */
- static inline void spmi_driver_unregister(struct spmi_driver *sdrv)
- {
- if (sdrv)
- driver_unregister(&sdrv->driver);
- }
- /**
- * spmi_add_controller: Controller bring-up.
- * @ctrl: controller to be registered.
- *
- * A controller is registered with the framework using this API. ctrl->nr is the
- * desired number with which SPMI framework registers the controller.
- * Function will return -EBUSY if the number is in use.
- */
- extern int spmi_add_controller(struct spmi_controller *ctrl);
- /**
- * spmi_del_controller: Controller tear-down.
- * Controller added with the above API is teared down using this API.
- */
- extern int spmi_del_controller(struct spmi_controller *ctrl);
- /**
- * spmi_busnum_to_ctrl: Map bus number to controller
- * @busnum: bus number
- *
- * Returns controller device representing this bus number
- */
- extern struct spmi_controller *spmi_busnum_to_ctrl(u32 bus_num);
- /**
- * spmi_alloc_device: Allocate a new SPMI devices.
- * @ctrl: controller to which this device is to be added to.
- * Context: can sleep
- *
- * Allows a driver to allocate and initialize a SPMI device without
- * registering it immediately. This allows a driver to directly fill
- * the spmi_device structure before calling spmi_add_device().
- *
- * Caller is responsible to call spmi_add_device() on the returned
- * spmi_device. If the caller needs to discard the spmi_device without
- * adding it, then spmi_dev_put() should be called.
- */
- extern struct spmi_device *spmi_alloc_device(struct spmi_controller *ctrl);
- /**
- * spmi_add_device: Add spmi_device allocated with spmi_alloc_device().
- * @spmi_dev: spmi_device to be added (registered).
- */
- extern int spmi_add_device(struct spmi_device *spmi_dev);
- /**
- * spmi_new_device: Instantiates a new SPMI device
- * @ctrl: controller to which this device is to be added to.
- * @info: board information for this device.
- *
- * Returns the new device or NULL.
- */
- extern struct spmi_device *spmi_new_device(struct spmi_controller *ctrl,
- struct spmi_boardinfo const *info);
- /* spmi_remove_device: Remove the effect of spmi_add_device() */
- extern void spmi_remove_device(struct spmi_device *spmi_dev);
- #ifdef CONFIG_SPMI
- /**
- * spmi_register_board_info: Board-initialization routine.
- * @bus_num: controller number (bus) on which this device will sit.
- * @info: list of all devices on all controllers present on the board.
- * @n: number of entries.
- *
- * API enumerates respective devices on corresponding controller.
- * Called from board-init function.
- */
- extern int spmi_register_board_info(int busnum,
- struct spmi_boardinfo const *info, unsigned n);
- #else
- static inline int spmi_register_board_info(int busnum,
- struct spmi_boardinfo const *info, unsigned n)
- {
- return 0;
- }
- #endif
- static inline void *spmi_get_ctrldata(const struct spmi_controller *ctrl)
- {
- return dev_get_drvdata(&ctrl->dev);
- }
- static inline void spmi_set_ctrldata(struct spmi_controller *ctrl, void *data)
- {
- dev_set_drvdata(&ctrl->dev, data);
- }
- static inline void *spmi_get_devicedata(const struct spmi_device *dev)
- {
- return dev_get_drvdata(&dev->dev);
- }
- static inline void spmi_set_devicedata(struct spmi_device *dev, void *data)
- {
- dev_set_drvdata(&dev->dev, data);
- }
- static inline void spmi_dev_put(struct spmi_device *spmidev)
- {
- if (spmidev)
- put_device(&spmidev->dev);
- }
- /**
- * spmi_register_read() - register read
- * @ctrl: SPMI controller.
- * @sid: slave identifier.
- * @ad: slave register address (5-bit address).
- * @buf: buffer to be populated with data from the Slave.
- *
- * Reads 1 byte of data from a Slave device register.
- */
- extern int spmi_register_read(struct spmi_controller *ctrl,
- u8 sid, u8 ad, u8 *buf);
- /**
- * spmi_ext_register_read() - extended register read
- * @ctrl: SPMI controller.
- * @sid: slave identifier.
- * @ad: slave register address (8-bit address).
- * @len: the request number of bytes to read (up to 16 bytes).
- * @buf: buffer to be populated with data from the Slave.
- *
- * Reads up to 16 bytes of data from the extended register space on a
- * Slave device.
- */
- extern int spmi_ext_register_read(struct spmi_controller *ctrl,
- u8 sid, u8 ad, u8 *buf, int len);
- /**
- * spmi_ext_register_readl() - extended register read long
- * @ctrl: SPMI controller.
- * @sid: slave identifier.
- * @ad: slave register address (16-bit address).
- * @len: the request number of bytes to read (up to 8 bytes).
- * @buf: buffer to be populated with data from the Slave.
- *
- * Reads up to 8 bytes of data from the extended register space on a
- * Slave device using 16-bit address.
- */
- extern int spmi_ext_register_readl(struct spmi_controller *ctrl,
- u8 sid, u16 ad, u8 *buf, int len);
- /**
- * spmi_register_write() - register write
- * @ctrl: SPMI controller.
- * @sid: slave identifier.
- * @ad: slave register address (5-bit address).
- * @buf: buffer containing the data to be transferred to the Slave.
- *
- * Writes 1 byte of data to a Slave device register.
- */
- extern int spmi_register_write(struct spmi_controller *ctrl,
- u8 sid, u8 ad, u8 *buf);
- /**
- * spmi_register_zero_write() - register zero write
- * @ctrl: SPMI controller.
- * @sid: slave identifier.
- * @data: the data to be written to register 0 (7-bits).
- *
- * Writes data to register 0 of the Slave device.
- */
- extern int spmi_register_zero_write(struct spmi_controller *ctrl,
- u8 sid, u8 data);
- /**
- * spmi_ext_register_write() - extended register write
- * @ctrl: SPMI controller.
- * @sid: slave identifier.
- * @ad: slave register address (8-bit address).
- * @buf: buffer containing the data to be transferred to the Slave.
- * @len: the request number of bytes to read (up to 16 bytes).
- *
- * Writes up to 16 bytes of data to the extended register space of a
- * Slave device.
- */
- extern int spmi_ext_register_write(struct spmi_controller *ctrl,
- u8 sid, u8 ad, u8 *buf, int len);
- /**
- * spmi_ext_register_writel() - extended register write long
- * @ctrl: SPMI controller.
- * @sid: slave identifier.
- * @ad: slave register address (16-bit address).
- * @buf: buffer containing the data to be transferred to the Slave.
- * @len: the request number of bytes to read (up to 8 bytes).
- *
- * Writes up to 8 bytes of data to the extended register space of a
- * Slave device using 16-bit address.
- */
- extern int spmi_ext_register_writel(struct spmi_controller *ctrl,
- u8 sid, u16 ad, u8 *buf, int len);
- /**
- * spmi_command_reset() - sends RESET command to the specified slave
- * @ctrl: SPMI controller.
- * @sid: slave identifier.
- *
- * The Reset command initializes the Slave and forces all registers to
- * their reset values. The Slave shall enter the STARTUP state after
- * receiving a Reset command.
- *
- * Returns
- * -EINVAL for invalid slave identifier.
- * -EPERM if the SPMI transaction is denied due to permission issues.
- * -EIO if the SPMI transaction fails (parity errors, etc).
- * -ETIMEDOUT if the SPMI transaction times out.
- * -EAGAIN if the SPMI transaction is temporarily unavailable
- */
- extern int spmi_command_reset(struct spmi_controller *ctrl, u8 sid);
- /**
- * spmi_command_sleep() - sends SLEEP command to the specified slave
- * @ctrl: SPMI controller.
- * @sid: slave identifier.
- *
- * The Sleep command causes the Slave to enter the user defined SLEEP state.
- *
- * Returns
- * -EINVAL for invalid slave identifier.
- * -EPERM if the SPMI transaction is denied due to permission issues.
- * -EIO if the SPMI transaction fails (parity errors, etc).
- * -ETIMEDOUT if the SPMI transaction times out.
- * -EAGAIN if the SPMI transaction is temporarily unavailable
- */
- extern int spmi_command_sleep(struct spmi_controller *ctrl, u8 sid);
- /**
- * spmi_command_wakeup() - sends WAKEUP command to the specified slave
- * @ctrl: SPMI controller.
- * @sid: slave identifier.
- *
- * The Wakeup command causes the Slave to move from the SLEEP state to
- * the ACTIVE state.
- *
- * Returns
- * -EINVAL for invalid slave identifier.
- * -EPERM if the SPMI transaction is denied due to permission issues.
- * -EIO if the SPMI transaction fails (parity errors, etc).
- * -ETIMEDOUT if the SPMI transaction times out.
- * -EAGAIN if the SPMI transaction is temporarily unavailable
- */
- extern int spmi_command_wakeup(struct spmi_controller *ctrl, u8 sid);
- /**
- * spmi_command_shutdown() - sends SHUTDOWN command to the specified slave
- * @ctrl: SPMI controller.
- * @sid: slave identifier.
- *
- * The Shutdown command causes the Slave to enter the SHUTDOWN state.
- *
- * Returns
- * -EINVAL for invalid slave identifier.
- * -EPERM if the SPMI transaction is denied due to permission issues.
- * -EIO if the SPMI transaction fails (parity errors, etc).
- * -ETIMEDOUT if the SPMI transaction times out.
- * -EAGAIN if the SPMI transaction is temporarily unavailable
- */
- extern int spmi_command_shutdown(struct spmi_controller *ctrl, u8 sid);
- /**
- * spmi_for_each_container_dev - iterate over the array of devnode resources.
- * @res: spmi_resource pointer used as the array cursor
- * @spmi_dev: spmi_device to iterate
- *
- * Only useable in spmi-dev-container configurations.
- */
- #define spmi_for_each_container_dev(res, spmi_dev) \
- for (res = ((spmi_dev)->dev_node ? &(spmi_dev)->dev_node[0] : NULL); \
- (res - (spmi_dev)->dev_node) < (spmi_dev)->num_dev_node; res++)
- extern struct resource *spmi_get_resource(struct spmi_device *dev,
- struct spmi_resource *node,
- unsigned int type, unsigned int res_num);
- struct resource *spmi_get_resource_byname(struct spmi_device *dev,
- struct spmi_resource *node,
- unsigned int type,
- const char *name);
- extern int spmi_get_irq(struct spmi_device *dev, struct spmi_resource *node,
- unsigned int res_num);
- extern int spmi_get_irq_byname(struct spmi_device *dev,
- struct spmi_resource *node, const char *name);
- /**
- * spmi_get_node_name - return device name for spmi node
- * @dev: spmi device handle
- *
- * Get the primary node name of a spmi_device coresponding with
- * with the 'label' binding.
- *
- * Returns NULL if no primary dev name has been assigned to this spmi_device.
- */
- static inline const char *spmi_get_primary_dev_name(struct spmi_device *dev)
- {
- if (dev->res.label)
- return dev->res.label;
- return NULL;
- }
- struct spmi_resource *spmi_get_dev_container_byname(struct spmi_device *dev,
- const char *label);
- #endif
|