1 From 1b0018dfd6295cbcc87738601b84bf49f3004419 Mon Sep 17 00:00:00 2001
2 From: Kenneth Heitke <kheitke@codeaurora.org>
3 Date: Wed, 12 Feb 2014 13:44:22 -0600
4 Subject: [PATCH 055/182] spmi: Linux driver framework for SPMI
6 System Power Management Interface (SPMI) is a specification
7 developed by the MIPI (Mobile Industry Process Interface) Alliance
8 optimized for the real time control of Power Management ICs (PMIC).
10 SPMI is a two-wire serial interface that supports up to 4 master
11 devices and up to 16 logical slaves.
13 The framework supports message APIs, multiple busses (1 controller
14 per bus) and multiple clients/slave devices per controller.
16 Signed-off-by: Kenneth Heitke <kheitke@codeaurora.org>
17 Signed-off-by: Michael Bohan <mbohan@codeaurora.org>
18 Signed-off-by: Josh Cartwright <joshc@codeaurora.org>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
22 drivers/Makefile | 1 +
23 drivers/spmi/Kconfig | 9 +
24 drivers/spmi/Makefile | 4 +
25 drivers/spmi/spmi.c | 609 +++++++++++++++++++++++++++++++++++++++
26 include/dt-bindings/spmi/spmi.h | 18 ++
27 include/linux/mod_devicetable.h | 8 +
28 include/linux/spmi.h | 191 ++++++++++++
29 8 files changed, 842 insertions(+)
30 create mode 100644 drivers/spmi/Kconfig
31 create mode 100644 drivers/spmi/Makefile
32 create mode 100644 drivers/spmi/spmi.c
33 create mode 100644 include/dt-bindings/spmi/spmi.h
34 create mode 100644 include/linux/spmi.h
36 diff --git a/drivers/Kconfig b/drivers/Kconfig
37 index b3138fb..e0a4ae6 100644
40 @@ -52,6 +52,8 @@ source "drivers/i2c/Kconfig"
42 source "drivers/spi/Kconfig"
44 +source "drivers/spmi/Kconfig"
46 source "drivers/hsi/Kconfig"
48 source "drivers/pps/Kconfig"
49 diff --git a/drivers/Makefile b/drivers/Makefile
50 index 8e3b8b0..3d6de8b 100644
51 --- a/drivers/Makefile
52 +++ b/drivers/Makefile
53 @@ -66,6 +66,7 @@ obj-$(CONFIG_ATA) += ata/
54 obj-$(CONFIG_TARGET_CORE) += target/
55 obj-$(CONFIG_MTD) += mtd/
56 obj-$(CONFIG_SPI) += spi/
57 +obj-$(CONFIG_SPMI) += spmi/
60 obj-$(CONFIG_ATM) += atm/
61 diff --git a/drivers/spmi/Kconfig b/drivers/spmi/Kconfig
63 index 0000000..1dbfee0
65 +++ b/drivers/spmi/Kconfig
68 +# SPMI driver configuration
71 + tristate "SPMI support"
73 + SPMI (System Power Management Interface) is a two-wire
74 + serial interface between baseband and application processors
75 + and Power Management Integrated Circuits (PMIC).
76 diff --git a/drivers/spmi/Makefile b/drivers/spmi/Makefile
78 index 0000000..1de1acd
80 +++ b/drivers/spmi/Makefile
83 +# Makefile for kernel SPMI framework.
85 +obj-$(CONFIG_SPMI) += spmi.o
86 diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c
88 index 0000000..6122c8f
90 +++ b/drivers/spmi/spmi.c
92 +/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
94 + * This program is free software; you can redistribute it and/or modify
95 + * it under the terms of the GNU General Public License version 2 and
96 + * only version 2 as published by the Free Software Foundation.
98 + * This program is distributed in the hope that it will be useful,
99 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
100 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
101 + * GNU General Public License for more details.
103 +#include <linux/kernel.h>
104 +#include <linux/errno.h>
105 +#include <linux/idr.h>
106 +#include <linux/slab.h>
107 +#include <linux/module.h>
108 +#include <linux/of.h>
109 +#include <linux/of_device.h>
110 +#include <linux/platform_device.h>
111 +#include <linux/spmi.h>
112 +#include <linux/module.h>
113 +#include <linux/pm_runtime.h>
115 +#include <dt-bindings/spmi/spmi.h>
117 +static DEFINE_IDA(ctrl_ida);
119 +static void spmi_dev_release(struct device *dev)
121 + struct spmi_device *sdev = to_spmi_device(dev);
125 +static const struct device_type spmi_dev_type = {
126 + .release = spmi_dev_release,
129 +static void spmi_ctrl_release(struct device *dev)
131 + struct spmi_controller *ctrl = to_spmi_controller(dev);
132 + ida_simple_remove(&ctrl_ida, ctrl->nr);
136 +static const struct device_type spmi_ctrl_type = {
137 + .release = spmi_ctrl_release,
140 +#ifdef CONFIG_PM_RUNTIME
141 +static int spmi_runtime_suspend(struct device *dev)
143 + struct spmi_device *sdev = to_spmi_device(dev);
146 + err = pm_generic_runtime_suspend(dev);
150 + return spmi_command_sleep(sdev);
153 +static int spmi_runtime_resume(struct device *dev)
155 + struct spmi_device *sdev = to_spmi_device(dev);
158 + err = spmi_command_wakeup(sdev);
162 + return pm_generic_runtime_resume(dev);
166 +static const struct dev_pm_ops spmi_pm_ops = {
167 + SET_RUNTIME_PM_OPS(
168 + spmi_runtime_suspend,
169 + spmi_runtime_resume,
174 +static int spmi_device_match(struct device *dev, struct device_driver *drv)
176 + if (of_driver_match_device(dev, drv))
180 + return strncmp(dev_name(dev), drv->name,
181 + SPMI_NAME_SIZE) == 0;
187 + * spmi_device_add() - add a device previously constructed via spmi_device_alloc()
188 + * @sdev: spmi_device to be added
190 +int spmi_device_add(struct spmi_device *sdev)
192 + struct spmi_controller *ctrl = sdev->ctrl;
195 + dev_set_name(&sdev->dev, "%d-%02x", ctrl->nr, sdev->usid);
197 + err = device_add(&sdev->dev);
199 + dev_err(&sdev->dev, "Can't add %s, status %d\n",
200 + dev_name(&sdev->dev), err);
201 + goto err_device_add;
204 + dev_dbg(&sdev->dev, "device %s registered\n", dev_name(&sdev->dev));
209 +EXPORT_SYMBOL_GPL(spmi_device_add);
212 + * spmi_device_remove(): remove an SPMI device
213 + * @sdev: spmi_device to be removed
215 +void spmi_device_remove(struct spmi_device *sdev)
217 + device_unregister(&sdev->dev);
219 +EXPORT_SYMBOL_GPL(spmi_device_remove);
222 +spmi_cmd(struct spmi_controller *ctrl, u8 opcode, u8 sid)
224 + if (!ctrl || !ctrl->cmd || ctrl->dev.type != &spmi_ctrl_type)
227 + return ctrl->cmd(ctrl, opcode, sid);
230 +static inline int spmi_read_cmd(struct spmi_controller *ctrl, u8 opcode,
231 + u8 sid, u16 addr, u8 *buf, size_t len)
233 + if (!ctrl || !ctrl->read_cmd || ctrl->dev.type != &spmi_ctrl_type)
236 + return ctrl->read_cmd(ctrl, opcode, sid, addr, buf, len);
239 +static inline int spmi_write_cmd(struct spmi_controller *ctrl, u8 opcode,
240 + u8 sid, u16 addr, const u8 *buf, size_t len)
242 + if (!ctrl || !ctrl->write_cmd || ctrl->dev.type != &spmi_ctrl_type)
245 + return ctrl->write_cmd(ctrl, opcode, sid, addr, buf, len);
249 + * spmi_register_read() - register read
250 + * @sdev: SPMI device.
251 + * @addr: slave register address (5-bit address).
252 + * @buf: buffer to be populated with data from the Slave.
254 + * Reads 1 byte of data from a Slave device register.
256 +int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf)
258 + /* 5-bit register address */
262 + return spmi_read_cmd(sdev->ctrl, SPMI_CMD_READ, sdev->usid, addr,
265 +EXPORT_SYMBOL_GPL(spmi_register_read);
268 + * spmi_ext_register_read() - extended register read
269 + * @sdev: SPMI device.
270 + * @addr: slave register address (8-bit address).
271 + * @buf: buffer to be populated with data from the Slave.
272 + * @len: the request number of bytes to read (up to 16 bytes).
274 + * Reads up to 16 bytes of data from the extended register space on a
277 +int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf,
280 + /* 8-bit register address, up to 16 bytes */
281 + if (len == 0 || len > 16)
284 + return spmi_read_cmd(sdev->ctrl, SPMI_CMD_EXT_READ, sdev->usid, addr,
287 +EXPORT_SYMBOL_GPL(spmi_ext_register_read);
290 + * spmi_ext_register_readl() - extended register read long
291 + * @sdev: SPMI device.
292 + * @addr: slave register address (16-bit address).
293 + * @buf: buffer to be populated with data from the Slave.
294 + * @len: the request number of bytes to read (up to 8 bytes).
296 + * Reads up to 8 bytes of data from the extended register space on a
297 + * Slave device using 16-bit address.
299 +int spmi_ext_register_readl(struct spmi_device *sdev, u16 addr, u8 *buf,
302 + /* 16-bit register address, up to 8 bytes */
303 + if (len == 0 || len > 8)
306 + return spmi_read_cmd(sdev->ctrl, SPMI_CMD_EXT_READL, sdev->usid, addr,
309 +EXPORT_SYMBOL_GPL(spmi_ext_register_readl);
312 + * spmi_register_write() - register write
313 + * @sdev: SPMI device
314 + * @addr: slave register address (5-bit address).
315 + * @data: buffer containing the data to be transferred to the Slave.
317 + * Writes 1 byte of data to a Slave device register.
319 +int spmi_register_write(struct spmi_device *sdev, u8 addr, u8 data)
321 + /* 5-bit register address */
325 + return spmi_write_cmd(sdev->ctrl, SPMI_CMD_WRITE, sdev->usid, addr,
328 +EXPORT_SYMBOL_GPL(spmi_register_write);
331 + * spmi_register_zero_write() - register zero write
332 + * @sdev: SPMI device.
333 + * @data: the data to be written to register 0 (7-bits).
335 + * Writes data to register 0 of the Slave device.
337 +int spmi_register_zero_write(struct spmi_device *sdev, u8 data)
339 + return spmi_write_cmd(sdev->ctrl, SPMI_CMD_ZERO_WRITE, sdev->usid, 0,
342 +EXPORT_SYMBOL_GPL(spmi_register_zero_write);
345 + * spmi_ext_register_write() - extended register write
346 + * @sdev: SPMI device.
347 + * @addr: slave register address (8-bit address).
348 + * @buf: buffer containing the data to be transferred to the Slave.
349 + * @len: the request number of bytes to read (up to 16 bytes).
351 + * Writes up to 16 bytes of data to the extended register space of a
354 +int spmi_ext_register_write(struct spmi_device *sdev, u8 addr, const u8 *buf,
357 + /* 8-bit register address, up to 16 bytes */
358 + if (len == 0 || len > 16)
361 + return spmi_write_cmd(sdev->ctrl, SPMI_CMD_EXT_WRITE, sdev->usid, addr,
364 +EXPORT_SYMBOL_GPL(spmi_ext_register_write);
367 + * spmi_ext_register_writel() - extended register write long
368 + * @sdev: SPMI device.
369 + * @addr: slave register address (16-bit address).
370 + * @buf: buffer containing the data to be transferred to the Slave.
371 + * @len: the request number of bytes to read (up to 8 bytes).
373 + * Writes up to 8 bytes of data to the extended register space of a
374 + * Slave device using 16-bit address.
376 +int spmi_ext_register_writel(struct spmi_device *sdev, u16 addr, const u8 *buf,
379 + /* 4-bit Slave Identifier, 16-bit register address, up to 8 bytes */
380 + if (len == 0 || len > 8)
383 + return spmi_write_cmd(sdev->ctrl, SPMI_CMD_EXT_WRITEL, sdev->usid,
386 +EXPORT_SYMBOL_GPL(spmi_ext_register_writel);
389 + * spmi_command_reset() - sends RESET command to the specified slave
390 + * @sdev: SPMI device.
392 + * The Reset command initializes the Slave and forces all registers to
393 + * their reset values. The Slave shall enter the STARTUP state after
394 + * receiving a Reset command.
396 +int spmi_command_reset(struct spmi_device *sdev)
398 + return spmi_cmd(sdev->ctrl, SPMI_CMD_RESET, sdev->usid);
400 +EXPORT_SYMBOL_GPL(spmi_command_reset);
403 + * spmi_command_sleep() - sends SLEEP command to the specified SPMI device
404 + * @sdev: SPMI device.
406 + * The Sleep command causes the Slave to enter the user defined SLEEP state.
408 +int spmi_command_sleep(struct spmi_device *sdev)
410 + return spmi_cmd(sdev->ctrl, SPMI_CMD_SLEEP, sdev->usid);
412 +EXPORT_SYMBOL_GPL(spmi_command_sleep);
415 + * spmi_command_wakeup() - sends WAKEUP command to the specified SPMI device
416 + * @sdev: SPMI device.
418 + * The Wakeup command causes the Slave to move from the SLEEP state to
419 + * the ACTIVE state.
421 +int spmi_command_wakeup(struct spmi_device *sdev)
423 + return spmi_cmd(sdev->ctrl, SPMI_CMD_WAKEUP, sdev->usid);
425 +EXPORT_SYMBOL_GPL(spmi_command_wakeup);
428 + * spmi_command_shutdown() - sends SHUTDOWN command to the specified SPMI device
429 + * @sdev: SPMI device.
431 + * The Shutdown command causes the Slave to enter the SHUTDOWN state.
433 +int spmi_command_shutdown(struct spmi_device *sdev)
435 + return spmi_cmd(sdev->ctrl, SPMI_CMD_SHUTDOWN, sdev->usid);
437 +EXPORT_SYMBOL_GPL(spmi_command_shutdown);
439 +static int spmi_drv_probe(struct device *dev)
441 + const struct spmi_driver *sdrv = to_spmi_driver(dev->driver);
442 + struct spmi_device *sdev = to_spmi_device(dev);
445 + /* Ensure the slave is in ACTIVE state */
446 + err = spmi_command_wakeup(sdev);
450 + pm_runtime_get_noresume(dev);
451 + pm_runtime_set_active(dev);
452 + pm_runtime_enable(dev);
454 + err = sdrv->probe(sdev);
461 + pm_runtime_disable(dev);
462 + pm_runtime_set_suspended(dev);
463 + pm_runtime_put_noidle(dev);
468 +static int spmi_drv_remove(struct device *dev)
470 + const struct spmi_driver *sdrv = to_spmi_driver(dev->driver);
472 + pm_runtime_get_sync(dev);
473 + sdrv->remove(to_spmi_device(dev));
474 + pm_runtime_put_noidle(dev);
476 + pm_runtime_disable(dev);
477 + pm_runtime_set_suspended(dev);
478 + pm_runtime_put_noidle(dev);
482 +static struct bus_type spmi_bus_type = {
484 + .match = spmi_device_match,
485 + .pm = &spmi_pm_ops,
486 + .probe = spmi_drv_probe,
487 + .remove = spmi_drv_remove,
491 + * spmi_controller_alloc() - Allocate a new SPMI device
492 + * @ctrl: associated controller
494 + * Caller is responsible for either calling spmi_device_add() to add the
495 + * newly allocated controller, or calling spmi_device_put() to discard it.
497 +struct spmi_device *spmi_device_alloc(struct spmi_controller *ctrl)
499 + struct spmi_device *sdev;
501 + sdev = kzalloc(sizeof(*sdev), GFP_KERNEL);
506 + device_initialize(&sdev->dev);
507 + sdev->dev.parent = &ctrl->dev;
508 + sdev->dev.bus = &spmi_bus_type;
509 + sdev->dev.type = &spmi_dev_type;
512 +EXPORT_SYMBOL_GPL(spmi_device_alloc);
515 + * spmi_controller_alloc() - Allocate a new SPMI controller
516 + * @parent: parent device
517 + * @size: size of private data
519 + * Caller is responsible for either calling spmi_controller_add() to add the
520 + * newly allocated controller, or calling spmi_controller_put() to discard it.
521 + * The allocated private data region may be accessed via
522 + * spmi_controller_get_drvdata()
524 +struct spmi_controller *spmi_controller_alloc(struct device *parent,
527 + struct spmi_controller *ctrl;
530 + if (WARN_ON(!parent))
533 + ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL);
537 + device_initialize(&ctrl->dev);
538 + ctrl->dev.type = &spmi_ctrl_type;
539 + ctrl->dev.bus = &spmi_bus_type;
540 + ctrl->dev.parent = parent;
541 + ctrl->dev.of_node = parent->of_node;
542 + spmi_controller_set_drvdata(ctrl, &ctrl[1]);
544 + id = ida_simple_get(&ctrl_ida, 0, 0, GFP_KERNEL);
547 + "unable to allocate SPMI controller identifier.\n");
548 + spmi_controller_put(ctrl);
553 + dev_set_name(&ctrl->dev, "spmi-%d", id);
555 + dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id);
558 +EXPORT_SYMBOL_GPL(spmi_controller_alloc);
560 +static void of_spmi_register_devices(struct spmi_controller *ctrl)
562 + struct device_node *node;
565 + if (!ctrl->dev.of_node)
568 + for_each_available_child_of_node(ctrl->dev.of_node, node) {
569 + struct spmi_device *sdev;
572 + dev_dbg(&ctrl->dev, "adding child %s\n", node->full_name);
574 + err = of_property_read_u32_array(node, "reg", reg, 2);
576 + dev_err(&ctrl->dev,
577 + "node %s err (%d) does not have 'reg' property\n",
578 + node->full_name, err);
582 + if (reg[1] != SPMI_USID) {
583 + dev_err(&ctrl->dev,
584 + "node %s contains unsupported 'reg' entry\n",
589 + if (reg[0] >= SPMI_MAX_SLAVE_ID) {
590 + dev_err(&ctrl->dev,
591 + "invalid usid on node %s\n",
596 + dev_dbg(&ctrl->dev, "read usid %02x\n", reg[0]);
598 + sdev = spmi_device_alloc(ctrl);
602 + sdev->dev.of_node = node;
603 + sdev->usid = (u8) reg[0];
605 + err = spmi_device_add(sdev);
607 + dev_err(&sdev->dev,
608 + "failure adding device. status %d\n", err);
609 + spmi_device_put(sdev);
615 + * spmi_controller_add() - Add an SPMI controller
616 + * @ctrl: controller to be registered.
618 + * Register a controller previously allocated via spmi_controller_alloc() with
621 +int spmi_controller_add(struct spmi_controller *ctrl)
625 + /* Can't register until after driver model init */
626 + if (WARN_ON(!spmi_bus_type.p))
629 + ret = device_add(&ctrl->dev);
633 + if (IS_ENABLED(CONFIG_OF))
634 + of_spmi_register_devices(ctrl);
636 + dev_dbg(&ctrl->dev, "spmi-%d registered: dev:%p\n",
637 + ctrl->nr, &ctrl->dev);
641 +EXPORT_SYMBOL_GPL(spmi_controller_add);
643 +/* Remove a device associated with a controller */
644 +static int spmi_ctrl_remove_device(struct device *dev, void *data)
646 + struct spmi_device *spmidev = to_spmi_device(dev);
647 + if (dev->type == &spmi_dev_type)
648 + spmi_device_remove(spmidev);
653 + * spmi_controller_remove(): remove an SPMI controller
654 + * @ctrl: controller to remove
656 + * Remove a SPMI controller. Caller is responsible for calling
657 + * spmi_controller_put() to discard the allocated controller.
659 +void spmi_controller_remove(struct spmi_controller *ctrl)
666 + dummy = device_for_each_child(&ctrl->dev, NULL,
667 + spmi_ctrl_remove_device);
668 + device_del(&ctrl->dev);
670 +EXPORT_SYMBOL_GPL(spmi_controller_remove);
673 + * spmi_driver_register() - Register client driver with SPMI core
674 + * @sdrv: client driver to be associated with client-device.
676 + * This API will register the client driver with the SPMI framework.
677 + * It is typically called from the driver's module-init function.
679 +int spmi_driver_register(struct spmi_driver *sdrv)
681 + sdrv->driver.bus = &spmi_bus_type;
682 + return driver_register(&sdrv->driver);
684 +EXPORT_SYMBOL_GPL(spmi_driver_register);
686 +static void __exit spmi_exit(void)
688 + bus_unregister(&spmi_bus_type);
690 +module_exit(spmi_exit);
692 +static int __init spmi_init(void)
694 + return bus_register(&spmi_bus_type);
696 +postcore_initcall(spmi_init);
698 +MODULE_LICENSE("GPL v2");
699 +MODULE_DESCRIPTION("SPMI module");
700 +MODULE_ALIAS("platform:spmi");
701 diff --git a/include/dt-bindings/spmi/spmi.h b/include/dt-bindings/spmi/spmi.h
703 index 0000000..d11e1e5
705 +++ b/include/dt-bindings/spmi/spmi.h
707 +/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
709 + * This program is free software; you can redistribute it and/or modify
710 + * it under the terms of the GNU General Public License version 2 and
711 + * only version 2 as published by the Free Software Foundation.
713 + * This program is distributed in the hope that it will be useful,
714 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
715 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
716 + * GNU General Public License for more details.
718 +#ifndef __DT_BINDINGS_SPMI_H
719 +#define __DT_BINDINGS_SPMI_H
725 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
726 index 45e9214..677e474 100644
727 --- a/include/linux/mod_devicetable.h
728 +++ b/include/linux/mod_devicetable.h
729 @@ -432,6 +432,14 @@ struct spi_device_id {
730 kernel_ulong_t driver_data; /* Data private to the driver */
733 +#define SPMI_NAME_SIZE 32
734 +#define SPMI_MODULE_PREFIX "spmi:"
736 +struct spmi_device_id {
737 + char name[SPMI_NAME_SIZE];
738 + kernel_ulong_t driver_data; /* Data private to the driver */
744 diff --git a/include/linux/spmi.h b/include/linux/spmi.h
746 index 0000000..91f5eab
748 +++ b/include/linux/spmi.h
750 +/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
752 + * This program is free software; you can redistribute it and/or modify
753 + * it under the terms of the GNU General Public License version 2 and
754 + * only version 2 as published by the Free Software Foundation.
756 + * This program is distributed in the hope that it will be useful,
757 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
758 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
759 + * GNU General Public License for more details.
761 +#ifndef _LINUX_SPMI_H
762 +#define _LINUX_SPMI_H
764 +#include <linux/types.h>
765 +#include <linux/device.h>
766 +#include <linux/mod_devicetable.h>
768 +/* Maximum slave identifier */
769 +#define SPMI_MAX_SLAVE_ID 16
772 +#define SPMI_CMD_EXT_WRITE 0x00
773 +#define SPMI_CMD_RESET 0x10
774 +#define SPMI_CMD_SLEEP 0x11
775 +#define SPMI_CMD_SHUTDOWN 0x12
776 +#define SPMI_CMD_WAKEUP 0x13
777 +#define SPMI_CMD_AUTHENTICATE 0x14
778 +#define SPMI_CMD_MSTR_READ 0x15
779 +#define SPMI_CMD_MSTR_WRITE 0x16
780 +#define SPMI_CMD_TRANSFER_BUS_OWNERSHIP 0x1A
781 +#define SPMI_CMD_DDB_MASTER_READ 0x1B
782 +#define SPMI_CMD_DDB_SLAVE_READ 0x1C
783 +#define SPMI_CMD_EXT_READ 0x20
784 +#define SPMI_CMD_EXT_WRITEL 0x30
785 +#define SPMI_CMD_EXT_READL 0x38
786 +#define SPMI_CMD_WRITE 0x40
787 +#define SPMI_CMD_READ 0x60
788 +#define SPMI_CMD_ZERO_WRITE 0x80
791 + * struct spmi_device - Basic representation of an SPMI device
792 + * @dev: Driver model representation of the device.
793 + * @ctrl: SPMI controller managing the bus hosting this device.
794 + * @usid: This devices' Unique Slave IDentifier.
796 +struct spmi_device {
798 + struct spmi_controller *ctrl;
802 +static inline struct spmi_device *to_spmi_device(struct device *d)
804 + return container_of(d, struct spmi_device, dev);
807 +static inline void *spmi_device_get_drvdata(const struct spmi_device *sdev)
809 + return dev_get_drvdata(&sdev->dev);
812 +static inline void spmi_device_set_drvdata(struct spmi_device *sdev, void *data)
814 + dev_set_drvdata(&sdev->dev, data);
817 +struct spmi_device *spmi_device_alloc(struct spmi_controller *ctrl);
819 +static inline void spmi_device_put(struct spmi_device *sdev)
822 + put_device(&sdev->dev);
825 +int spmi_device_add(struct spmi_device *sdev);
827 +void spmi_device_remove(struct spmi_device *sdev);
830 + * struct spmi_controller - interface to the SPMI master controller
831 + * @dev: Driver model representation of the device.
832 + * @nr: board-specific number identifier for this controller/bus
833 + * @cmd: sends a non-data command sequence on the SPMI bus.
834 + * @read_cmd: sends a register read command sequence on the SPMI bus.
835 + * @write_cmd: sends a register write command sequence on the SPMI bus.
837 +struct spmi_controller {
840 + int (*cmd)(struct spmi_controller *ctrl, u8 opcode, u8 sid);
841 + int (*read_cmd)(struct spmi_controller *ctrl, u8 opcode,
842 + u8 sid, u16 addr, u8 *buf, size_t len);
843 + int (*write_cmd)(struct spmi_controller *ctrl, u8 opcode,
844 + u8 sid, u16 addr, const u8 *buf, size_t len);
847 +static inline struct spmi_controller *to_spmi_controller(struct device *d)
849 + return container_of(d, struct spmi_controller, dev);
853 +void *spmi_controller_get_drvdata(const struct spmi_controller *ctrl)
855 + return dev_get_drvdata(&ctrl->dev);
858 +static inline void spmi_controller_set_drvdata(struct spmi_controller *ctrl,
861 + dev_set_drvdata(&ctrl->dev, data);
864 +struct spmi_controller *spmi_controller_alloc(struct device *parent,
868 + * spmi_controller_put() - decrement controller refcount
869 + * @ctrl SPMI controller.
871 +static inline void spmi_controller_put(struct spmi_controller *ctrl)
874 + put_device(&ctrl->dev);
877 +int spmi_controller_add(struct spmi_controller *ctrl);
878 +void spmi_controller_remove(struct spmi_controller *ctrl);
881 + * struct spmi_driver - SPMI slave device driver
882 + * @driver: SPMI device drivers should initialize name and owner field of
884 + * @probe: binds this driver to a SPMI device.
885 + * @remove: unbinds this driver from the SPMI device.
886 + * @shutdown: standard shutdown callback used during powerdown/halt.
887 + * @suspend: standard suspend callback used during system suspend.
888 + * @resume: standard resume callback used during system resume.
890 + * If PM runtime support is desired for a slave, a device driver can call
891 + * pm_runtime_put() from their probe() routine (and a balancing
892 + * pm_runtime_get() in remove()). PM runtime support for a slave is
893 + * implemented by issuing a SLEEP command to the slave on runtime_suspend(),
894 + * transitioning the slave into the SLEEP state. On runtime_resume(), a WAKEUP
895 + * command is sent to the slave to bring it back to ACTIVE.
897 +struct spmi_driver {
898 + struct device_driver driver;
899 + int (*probe)(struct spmi_device *sdev);
900 + void (*remove)(struct spmi_device *sdev);
903 +static inline struct spmi_driver *to_spmi_driver(struct device_driver *d)
905 + return container_of(d, struct spmi_driver, driver);
908 +int spmi_driver_register(struct spmi_driver *sdrv);
911 + * spmi_driver_unregister() - unregister an SPMI client driver
912 + * @sdrv: the driver to unregister
914 +static inline void spmi_driver_unregister(struct spmi_driver *sdrv)
917 + driver_unregister(&sdrv->driver);
920 +#define module_spmi_driver(__spmi_driver) \
921 + module_driver(__spmi_driver, spmi_driver_register, \
922 + spmi_driver_unregister)
924 +int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf);
925 +int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf,
927 +int spmi_ext_register_readl(struct spmi_device *sdev, u16 addr, u8 *buf,
929 +int spmi_register_write(struct spmi_device *sdev, u8 addr, u8 data);
930 +int spmi_register_zero_write(struct spmi_device *sdev, u8 data);
931 +int spmi_ext_register_write(struct spmi_device *sdev, u8 addr,
932 + const u8 *buf, size_t len);
933 +int spmi_ext_register_writel(struct spmi_device *sdev, u16 addr,
934 + const u8 *buf, size_t len);
935 +int spmi_command_reset(struct spmi_device *sdev);
936 +int spmi_command_sleep(struct spmi_device *sdev);
937 +int spmi_command_wakeup(struct spmi_device *sdev);
938 +int spmi_command_shutdown(struct spmi_device *sdev);