All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 11/18] drivers: Add SPMI bus uclass
Date: Sun, 24 Jan 2016 21:53:03 +0100	[thread overview]
Message-ID: <1453668790-20236-12-git-send-email-mateusz.kulikowski@gmail.com> (raw)
In-Reply-To: <1453668790-20236-1-git-send-email-mateusz.kulikowski@gmail.com>

Qualcom processors use proprietary bus to talk with PMIC devices -
SPMI (System Power Management Interface).
On wiring level it is similar to I2C, but on protocol level, it's
multi-master and has simple autodetection capabilities.
This commit adds simple uclass that provides bus read/write interface.

Signed-off-by: Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Use proper  entry order in Kconfig
- Rename CONFIG_DM_SPMI -> CONFIG_SPMI
- Fix header ordering
- Add reviewed-by

Changes in v1:
- Reorder includes
- Add read/write arguments documentation

 drivers/Kconfig            |  2 ++
 drivers/Makefile           |  1 +
 drivers/spmi/Kconfig       | 10 ++++++++++
 drivers/spmi/Makefile      |  7 +++++++
 drivers/spmi/spmi-uclass.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h     |  1 +
 include/spmi/spmi.h        | 47 +++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 116 insertions(+)
 create mode 100644 drivers/spmi/Kconfig
 create mode 100644 drivers/spmi/Makefile
 create mode 100644 drivers/spmi/spmi-uclass.c
 create mode 100644 include/spmi/spmi.h

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 70993fd..c82a94b 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -60,6 +60,8 @@ source "drivers/sound/Kconfig"
 
 source "drivers/spi/Kconfig"
 
+source "drivers/spmi/Kconfig"
+
 source "drivers/thermal/Kconfig"
 
 source "drivers/timer/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 00da40b..2b2a9cf 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -53,6 +53,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += spmi/
 obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
diff --git a/drivers/spmi/Kconfig b/drivers/spmi/Kconfig
new file mode 100644
index 0000000..0b9bd31
--- /dev/null
+++ b/drivers/spmi/Kconfig
@@ -0,0 +1,10 @@
+menu "SPMI support"
+
+config SPMI
+	bool "Enable SPMI bus support"
+	depends on DM
+	---help---
+	  Select this to enable to support SPMI bus.
+	  SPMI (System Power Management Interface) bus is used
+	  to connect PMIC devices on various SoCs.
+endmenu
diff --git a/drivers/spmi/Makefile b/drivers/spmi/Makefile
new file mode 100644
index 0000000..99092eb
--- /dev/null
+++ b/drivers/spmi/Makefile
@@ -0,0 +1,7 @@
+#
+# (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_SPMI)  += spmi-uclass.o
diff --git a/drivers/spmi/spmi-uclass.c b/drivers/spmi/spmi-uclass.c
new file mode 100644
index 0000000..4ddd51b
--- /dev/null
+++ b/drivers/spmi/spmi-uclass.c
@@ -0,0 +1,48 @@
+/*
+ * SPMI bus uclass driver
+ *
+ * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <dm/root.h>
+#include <spmi/spmi.h>
+#include <linux/ctype.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int spmi_reg_read(struct udevice *dev, int usid, int pid, int reg)
+{
+	const struct dm_spmi_ops *ops = dev_get_driver_ops(dev);
+
+	if (!ops || !ops->read)
+		return -ENOSYS;
+
+	return ops->read(dev, usid, pid, reg);
+}
+
+int spmi_reg_write(struct udevice *dev, int usid, int pid, int reg,
+		   uint8_t value)
+{
+	const struct dm_spmi_ops *ops = dev_get_driver_ops(dev);
+
+	if (!ops || !ops->write)
+		return -ENOSYS;
+
+	return ops->write(dev, usid, pid, reg, value);
+}
+
+static int spmi_post_bind(struct udevice *dev)
+{
+	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+}
+
+UCLASS_DRIVER(spmi) = {
+	.id		= UCLASS_SPMI,
+	.name		= "spmi",
+	.post_bind	= spmi_post_bind,
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 8391e38..e896c2f 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -61,6 +61,7 @@ enum uclass_id {
 	UCLASS_RTC,		/* Real time clock device */
 	UCLASS_SERIAL,		/* Serial UART */
 	UCLASS_SPI,		/* SPI bus */
+	UCLASS_SPMI,		/* System Power Management Interface bus */
 	UCLASS_SPI_FLASH,	/* SPI flash */
 	UCLASS_SPI_GENERIC,	/* Generic SPI flash target */
 	UCLASS_SYSCON,		/* System configuration device */
diff --git a/include/spmi/spmi.h b/include/spmi/spmi.h
new file mode 100644
index 0000000..65a49bd
--- /dev/null
+++ b/include/spmi/spmi.h
@@ -0,0 +1,47 @@
+#ifndef _SPMI_SPMI_H
+#define _SPMI_SPMI_H
+
+/**
+ * struct dm_spmi_ops - SPMI device I/O interface
+ *
+ * Should be implemented by UCLASS_SPMI device drivers. The standard
+ * device operations provides the I/O interface for it's childs.
+ *
+ * @read:      read register 'reg' of slave 'usid' and peripheral 'pid'
+ * @write:     write register 'reg' of slave 'usid' and peripheral 'pid'
+ *
+ * Each register is 8-bit, both read and write can return negative values
+ * on error.
+ */
+struct dm_spmi_ops {
+	int (*read)(struct udevice *dev, int usid, int pid, int reg);
+	int (*write)(struct udevice *dev, int usid, int pid, int reg,
+		     uint8_t value);
+};
+
+/**
+ * spmi_reg_read() - read a register from specific slave/peripheral
+ *
+ * @dev:	SPMI bus to read
+ * @usid	SlaveID
+ * @pid		Peripheral ID
+ * @reg:	Register to read
+ * @return value read on success or negative value of errno.
+ */
+int spmi_reg_read(struct udevice *dev, int usid, int pid, int reg);
+
+/**
+ * spmi_reg_write() - write a register of specific slave/peripheral
+ *
+ * @dev:	SPMI bus to write
+ * @usid	SlaveID
+ * @pid		Peripheral ID
+ * @reg:	Register to write
+ * @value:	Value to write
+ * @return 0 on success or negative value of errno.
+ */
+int spmi_reg_write(struct udevice *dev, int usid, int pid, int reg,
+		   uint8_t value);
+
+#endif
+
-- 
2.5.0

  parent reply	other threads:[~2016-01-24 20:53 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-24 20:52 [U-Boot] [PATCH v2 00/18] Add support for 96boards Dragonboard410C board Mateusz Kulikowski
2016-01-24 20:52 ` [U-Boot] [PATCH v2 01/18] serial: Add support for Qualcomm serial port Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:52 ` [U-Boot] [PATCH v2 02/18] gpio: Add support for Qualcomm gpio controller Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:52 ` [U-Boot] [PATCH v2 03/18] mmc: Add support for Qualcomm SDHCI controller Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:52 ` [U-Boot] [PATCH v2 04/18] ehci-hcd: Add init_after_reset Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:52 ` [U-Boot] [PATCH v2 05/18] usb: ulpi: Add Kconfig options for ULPI Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:52 ` [U-Boot] [PATCH v2 06/18] Migrate CONFIG_ULPI* to Kconfig Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:52 ` [U-Boot] [PATCH v2 07/18] usb: Rename ehci-fsl.h to ehci-ci.h Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:53 ` [U-Boot] [PATCH v2 08/18] usb: ehci-ci: Add missing registers Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:53 ` [U-Boot] [PATCH v2 09/18] ehci-ci.h: drop generic USBCMD fields Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:53 ` [U-Boot] [PATCH v2 10/18] ehci: Add support for Qualcomm EHCI Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:53 ` Mateusz Kulikowski [this message]
2016-01-31 15:16   ` [U-Boot] [PATCH v2 11/18] drivers: Add SPMI bus uclass Simon Glass
2016-01-24 20:53 ` [U-Boot] [PATCH v2 12/18] spmi: Add sandbox test driver Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:53 ` [U-Boot] [PATCH v2 13/18] drivers: spmi: Add support for Qualcomm SPMI bus driver Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:53 ` [U-Boot] [PATCH v2 14/18] pmic: Add support for Qualcomm PM8916 PMIC Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:53 ` [U-Boot] [PATCH v2 15/18] gpio: Add support for Qualcomm PM8916 gpios Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:53 ` [U-Boot] [PATCH v2 16/18] arm: Add support for Qualcomm Snapdragon family Mateusz Kulikowski
2016-01-31 15:16   ` Simon Glass
2016-01-24 20:53 ` [U-Boot] [PATCH v2 17/18] board: Add Qualcomm Dragonboard 410C support Mateusz Kulikowski
2016-01-31 15:17   ` Simon Glass
2016-02-07 21:05     ` Mateusz Kulikowski
2016-02-09 21:56   ` Jagan Teki
2016-01-24 20:53 ` [U-Boot] [PATCH v2 18/18] Add myself as Snapdragon and SPMI maintainer Mateusz Kulikowski
2016-01-31 15:17   ` Simon Glass
2016-02-07 20:57 [U-Boot] [PATCH v2 00/18] Add support for 96boards Dragonboard410C board Mateusz Kulikowski
2016-02-07 20:57 ` [U-Boot] [PATCH v2 11/18] drivers: Add SPMI bus uclass Mateusz Kulikowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453668790-20236-12-git-send-email-mateusz.kulikowski@gmail.com \
    --to=mateusz.kulikowski@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.