diff mbox

[U-Boot,v1,10/16] drivers: Add SPMI bus uclass

Message ID 1452104488-5502-11-git-send-email-mateusz.kulikowski@gmail.com
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Mateusz Kulikowski Jan. 6, 2016, 6:21 p.m. UTC
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>
---

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

Comments

Simon Glass Jan. 11, 2016, 4:57 p.m. UTC | #1
Hi Mateusz,

On 6 January 2016 at 11:21, Mateusz Kulikowski
<mateusz.kulikowski@gmail.com> wrote:
> 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>
> ---
>
> 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
>

Reviewed-by: Simon Glass <sjg@chromium.org>

with nits...

> diff --git a/drivers/Kconfig b/drivers/Kconfig
> index c481e93..4cbe976 100644
> --- a/drivers/Kconfig
> +++ b/drivers/Kconfig
> @@ -52,6 +52,8 @@ source "drivers/remoteproc/Kconfig"
>
>  source "drivers/rtc/Kconfig"
>
> +source "drivers/spmi/Kconfig"
> +

spmi comes after sound, so please move it down a bit.

>  source "drivers/serial/Kconfig"
>
>  source "drivers/sound/Kconfig"
> diff --git a/drivers/Makefile b/drivers/Makefile
> index c9031f2..7ae72c0 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/

like you have here

>  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..440431a
> --- /dev/null
> +++ b/drivers/spmi/Kconfig
> @@ -0,0 +1,10 @@
> +menu "SPMI support"
> +
> +config DM_SPMI

Can we just use SPMI, or is that is use? We want to remove all the DM_
options when everything is converted to driver model. So if you are
adding a new class you should be able to avoid the DM_ prefix.

> +       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..2015b1a
> --- /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_DM_SPMI)  += spmi-uclass.o
> diff --git a/drivers/spmi/spmi-uclass.c b/drivers/spmi/spmi-uclass.c
> new file mode 100644
> index 0000000..7d5429a
> --- /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 <dm/root.h>
> +#include <errno.h>
> +#include <spmi/spmi.h>
> +#include <linux/ctype.h>

http://www.denx.de/wiki/U-Boot/CodingStyle

common.h
dm.h
errno.h
dm/...
spmi/...
linux/...

> +
> +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 27fa0b6..772e780 100644
> --- a/include/dm/uclass-id.h
> +++ b/include/dm/uclass-id.h
> @@ -57,6 +57,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
>

Regards,
Simon
Mateusz Kulikowski Jan. 11, 2016, 9:41 p.m. UTC | #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi Simon ,

On 11.01.2016 17:57, Simon Glass wrote:
[...]
>> @@ -0,0 +1,10 @@
>> +menu "SPMI support"
>> +
>> +config DM_SPMI
> 
> Can we just use SPMI, or is that is use? We want to remove all the DM_
> options when everything is converted to driver model. So if you are
> adding a new class you should be able to avoid the DM_ prefix.

Sure, I thought it's mandatory :)

[..]
>> +
>> +#include <common.h>
>> +#include <dm.h>
>> +#include <dm/root.h>
>> +#include <errno.h>
>> +#include <spmi/spmi.h>
>> +#include <linux/ctype.h>
> 
> http://www.denx.de/wiki/U-Boot/CodingStyle
> 
> common.h
> dm.h
> errno.h
> dm/...
> spmi/...
> linux/...

Oops, this slipped - my bad

Regards,
Mateusz

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJWlCGaAAoJELvtohmVtQzB8HsH/2C5C6qWhUpBlXiyhXLBa7TG
6KWy+NwrGdadwi1IT/UiBbryM7O6YT+H/Ey7MIfC0VNyhPnSiMimCYH7RQoNtoYT
lA5QUb1FAAvVbyypD9t0CRl32uORbG/2WocDdPbAjyTJp3/GldwZ0ZjeQo2uOedv
zUmwEmMiylff7m2wjD4EhEJayyTF/8oVCaqH4OtlxwupIHMgekPNUBjtW5VfjPMP
oldrwD2k2nbAj7Y91nxKPQiMgql4eOdXQCnwkW4ovz6wB1jb9/b8d42W75rhFoDu
2FRcP6NWR9XurMQIjtSz7O587UrGWrKm4ts7MjjhMMt4aPjDVNd+9CE+R8mEu3A=
=gUUy
-----END PGP SIGNATURE-----
diff mbox

Patch

diff --git a/drivers/Kconfig b/drivers/Kconfig
index c481e93..4cbe976 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -52,6 +52,8 @@  source "drivers/remoteproc/Kconfig"
 
 source "drivers/rtc/Kconfig"
 
+source "drivers/spmi/Kconfig"
+
 source "drivers/serial/Kconfig"
 
 source "drivers/sound/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index c9031f2..7ae72c0 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..440431a
--- /dev/null
+++ b/drivers/spmi/Kconfig
@@ -0,0 +1,10 @@ 
+menu "SPMI support"
+
+config DM_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..2015b1a
--- /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_DM_SPMI)  += spmi-uclass.o
diff --git a/drivers/spmi/spmi-uclass.c b/drivers/spmi/spmi-uclass.c
new file mode 100644
index 0000000..7d5429a
--- /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 <dm/root.h>
+#include <errno.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 27fa0b6..772e780 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -57,6 +57,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
+