[PATCH 5/8] mfd: Add ST's Low Power Controller driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On current ST platforms the LPC controls a number of functions.  This
patch enables possible support for the LPC Watchdog and LPC RTC devices
and ensures only one of them operates at any one time.

Signed-off-by: Lee Jones <lee.jones@xxxxxxxxxx>
---
 drivers/mfd/Kconfig  |  8 +++++
 drivers/mfd/Makefile |  1 +
 drivers/mfd/st-lpc.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+)
 create mode 100644 drivers/mfd/st-lpc.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index de5abf2..75db2f2 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -752,6 +752,14 @@ config STMPE_SPI
 	  This is used to enable SPI interface of STMPE
 endmenu
 
+config MFD_ST_LPC
+	tristate "STMicroelectronics Low-Power-Controller"
+	depends on OF
+	select MFD_CORE
+	help
+	  Say yes here to add support for ST's Low-Power-Controller (LPC).
+	  This device provides Real-Time Clock and Watchdog functionality.
+
 config MFD_STA2X11
 	bool "STMicroelectronics STA2X11"
 	depends on STA2X11
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index f001487..09aeb95 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_MFD_STA2X11)	+= sta2x11-mfd.o
 obj-$(CONFIG_MFD_STMPE)		+= stmpe.o
 obj-$(CONFIG_STMPE_I2C)		+= stmpe-i2c.o
 obj-$(CONFIG_STMPE_SPI)		+= stmpe-spi.o
+obj-$(CONFIG_MFD_ST_LPC)	+= st-lpc.o
 obj-$(CONFIG_MFD_SUN6I_PRCM)	+= sun6i-prcm.o
 obj-$(CONFIG_MFD_TC3589X)	+= tc3589x.o
 obj-$(CONFIG_MFD_T7L66XB)	+= t7l66xb.o tmio_core.o
diff --git a/drivers/mfd/st-lpc.c b/drivers/mfd/st-lpc.c
new file mode 100644
index 0000000..13906d9
--- /dev/null
+++ b/drivers/mfd/st-lpc.c
@@ -0,0 +1,88 @@
+/*
+ * st-lpc.c - ST's Low Power Controller (LPC) Multi-Function Device Driver
+ *
+ * Copyright (C) 2014 STMicroelectronics -- All Rights Reserved
+ *
+ * Author: Lee Jones <lee.jones@xxxxxxxxxx> for STMicroelectronics
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <linux/err.h>
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <dt-bindings/mfd/st-lpc.h>
+
+static int st_lpc_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct mfd_cell *cell;
+	u32 mode;
+	int ret;
+
+	cell = devm_kzalloc(&pdev->dev, sizeof(*cell), GFP_KERNEL);
+	if (!cell)
+		return -ENOMEM;
+
+	ret = of_property_read_u32(np, "st,lpc-mode", &mode);
+	if (ret) {
+		dev_err(&pdev->dev, "An LPC mode must be selected\n");
+		return ret;
+	}
+
+	switch (mode) {
+	case ST_LPC_MODE_RTC:
+		cell->name = "st-lpc-rtc";
+		break;
+	case ST_LPC_MODE_WDT:
+		cell->name = "st-lpc-wdt";
+		break;
+	default:
+		dev_err(&pdev->dev, "Unsupported mode: %d\n", mode);
+		return ret;
+	}
+
+	/* Pass resources though to selected child device. */
+	cell->resources = pdev->resource;
+	cell->num_resources = pdev->num_resources;
+
+	ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO,
+			      cell, 1, NULL, 0, NULL);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to register child devices\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static int st_lpc_remove(struct platform_device *pdev)
+{
+	mfd_remove_devices(&pdev->dev);
+
+	return 0;
+}
+
+static const struct of_device_id st_lpc_dt_match[] = {
+	{ .compatible = "st,stih407-lpc" },
+	{ }
+};
+
+static struct platform_driver st_lpc_driver = {
+	.driver = {
+		.name = "st-lpc",
+		.of_match_table = st_lpc_dt_match,
+	},
+	.probe = st_lpc_probe,
+	.remove = st_lpc_remove,
+};
+
+module_platform_driver(st_lpc_driver);
+
+MODULE_AUTHOR("Lee Jones <lee.jones@xxxxxxxxxx>");
+MODULE_DESCRIPTION("ST's Low Power Controller (LPC) Multi-Function Device");
+MODULE_LICENSE("GPL");
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]
  Powered by Linux