mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeppe Ledet-Pedersen <jlp@gomspace.com>
To: <lee.jones@linaro.org>, <arnd@arndb.de>,
	<gregkh@linuxfoundation.org>,
	<alexandre.belloni@free-electrons.com>, <a.zummo@towertech.it>,
	<robh+dt@kernel.org>, <pawel.moll@arm.com>,
	<mark.rutland@arm.com>, <ijc+devicetree@hellion.org.uk>,
	<galak@codeaurora.org>
Cc: <rtc-linux@googlegroups.com>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	Jeppe Ledet-Pedersen <jlp@gomspace.com>
Subject: [PATCH 3/3] rtc: add Cypress FM33256B RTC driver
Date: Wed, 20 Apr 2016 13:07:51 +0200	[thread overview]
Message-ID: <1461150471-23163-4-git-send-email-jlp@gomspace.com> (raw)
In-Reply-To: <1461150471-23163-1-git-send-email-jlp@gomspace.com>

Signed-off-by: Jeppe Ledet-Pedersen <jlp@gomspace.com>
---
 MAINTAINERS                |   1 +
 drivers/rtc/Kconfig        |  10 +++
 drivers/rtc/Makefile       |   1 +
 drivers/rtc/rtc-fm33256b.c | 166 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 178 insertions(+)
 create mode 100644 drivers/rtc/rtc-fm33256b.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a8b71d8..9ccc285 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3388,6 +3388,7 @@ S:	Maintained
 F:	include/linux/mfd/fm33256b.h
 F:	drivers/mfd/fm33256b.c
 F:	drivers/misc/eeprom/fm33256b-fram.c
+F:	drivers/rtc/rtc-fm33256b.c
 
 CYTTSP TOUCHSCREEN DRIVER
 M:	Ferruh Yigit <fery@cypress.com>
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 3e84315..7856f0b 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -740,6 +740,16 @@ config RTC_DRV_MCP795
 	  This driver can also be built as a module. If so the module
 	  will be called rtc-mcp795.
 
+config RTC_DRV_FM33256B
+	tristate "Cypress FM33256B RTC support"
+	depends on MFD_FM33256B
+	help
+	  If you say Y here you will get support for the RTC found in the
+	  Cypress FM33256B Processor Companion.
+
+	  This driver can also be built as a module. If so the module
+	  will be called rtc-fm33256b.
+
 endif # SPI_MASTER
 
 #
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index ea28337..1478fb6 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -64,6 +64,7 @@ obj-$(CONFIG_RTC_DRV_EFI)	+= rtc-efi.o
 obj-$(CONFIG_RTC_DRV_EM3027)	+= rtc-em3027.o
 obj-$(CONFIG_RTC_DRV_EP93XX)	+= rtc-ep93xx.o
 obj-$(CONFIG_RTC_DRV_FM3130)	+= rtc-fm3130.o
+obj-$(CONFIG_RTC_DRV_FM33256B)	+= rtc-fm33256b.o
 obj-$(CONFIG_RTC_DRV_GEMINI)	+= rtc-gemini.o
 obj-$(CONFIG_RTC_DRV_GENERIC)	+= rtc-generic.o
 obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
diff --git a/drivers/rtc/rtc-fm33256b.c b/drivers/rtc/rtc-fm33256b.c
new file mode 100644
index 0000000..a9650d4
--- /dev/null
+++ b/drivers/rtc/rtc-fm33256b.c
@@ -0,0 +1,166 @@
+/*
+ * Cypress FM33256B Processor Companion RTC Driver
+ *
+ * Copyright (C) 2016 GomSpace ApS
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/mfd/fm33256b.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/rtc.h>
+#include <linux/bcd.h>
+
+struct fm33256b_rtc {
+	struct fm33256b *fm33256b;
+	struct rtc_device *rtcdev;
+};
+
+static int fm33256b_rtc_readtime(struct device *dev, struct rtc_time *tm)
+{
+	int ret;
+	struct fm33256b_rtc *rtc = dev_get_drvdata(dev);
+	uint8_t time[7];
+
+	/* Lock time update */
+	ret = regmap_update_bits(rtc->fm33256b->regmap_pc,
+				 FM33256B_RTC_ALARM_CONTROL_REG,
+				 FM33256B_R, FM33256B_R);
+	if (ret < 0)
+		return ret;
+
+	ret = regmap_bulk_read(rtc->fm33256b->regmap_pc,
+			       FM33256B_SECONDS_REG, time, sizeof(time));
+	if (ret < 0)
+		return ret;
+
+	/* Unlock time update */
+	ret = regmap_update_bits(rtc->fm33256b->regmap_pc,
+				 FM33256B_RTC_ALARM_CONTROL_REG,
+				 FM33256B_R, 0);
+	if (ret < 0)
+		return ret;
+
+	tm->tm_sec	= bcd2bin(time[0]);
+	tm->tm_min	= bcd2bin(time[1]);
+	tm->tm_hour	= bcd2bin(time[2]);
+	tm->tm_wday	= bcd2bin(time[3]) - 1;
+	tm->tm_mday	= bcd2bin(time[4]);
+	tm->tm_mon	= bcd2bin(time[5]) - 1;
+	tm->tm_year	= bcd2bin(time[6]);
+
+	if (tm->tm_year < 70)
+		tm->tm_year += 100;
+
+	return rtc_valid_tm(tm);
+}
+
+static int fm33256b_rtc_settime(struct device *dev, struct rtc_time *tm)
+{
+	int ret;
+	struct fm33256b_rtc *rtc = dev_get_drvdata(dev);
+	uint8_t time[7];
+
+	time[0] = bin2bcd(tm->tm_sec);
+	time[1] = bin2bcd(tm->tm_min);
+	time[2] = bin2bcd(tm->tm_hour);
+	time[3] = bin2bcd(tm->tm_wday + 1);
+	time[4] = bin2bcd(tm->tm_mday);
+	time[5] = bin2bcd(tm->tm_mon + 1);
+	time[6] = bin2bcd(tm->tm_year % 100);
+
+	/* Unlock time update */
+	ret = regmap_update_bits(rtc->fm33256b->regmap_pc,
+				 FM33256B_RTC_ALARM_CONTROL_REG,
+				 FM33256B_W, FM33256B_W);
+	if (ret < 0)
+		return ret;
+
+	ret = regmap_bulk_write(rtc->fm33256b->regmap_pc,
+				FM33256B_SECONDS_REG, time, sizeof(time));
+	if (ret < 0)
+		return ret;
+
+	/* Lock time update */
+	ret = regmap_update_bits(rtc->fm33256b->regmap_pc,
+				 FM33256B_RTC_ALARM_CONTROL_REG,
+				 FM33256B_W, 0);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static const struct rtc_class_ops fm33256b_rtc_ops = {
+	.read_time	= fm33256b_rtc_readtime,
+	.set_time	= fm33256b_rtc_settime,
+};
+
+static int fm33256b_rtc_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct fm33256b *fm33256b;
+	struct fm33256b_rtc *rtc;
+
+	fm33256b = dev_get_drvdata(dev->parent);
+
+	rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, rtc);
+
+	rtc->fm33256b = fm33256b;
+	rtc->rtcdev = devm_rtc_device_register(&pdev->dev, KBUILD_MODNAME,
+					       &fm33256b_rtc_ops, THIS_MODULE);
+	if (IS_ERR(rtc->rtcdev))
+		return PTR_ERR(rtc->rtcdev);
+
+	return 0;
+}
+
+static int fm33256b_rtc_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct fm33256b *fm33256b;
+	struct fm33256b_rtc *rtc = platform_get_drvdata(pdev);
+
+	fm33256b = dev_get_drvdata(dev->parent);
+
+	devm_rtc_device_unregister(&pdev->dev, rtc->rtcdev);
+
+	return 0;
+}
+
+static const struct of_device_id fm33256b_rtc_dt_ids[] = {
+	{ .compatible = "cypress,fm33256b-rtc" },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, fm33256b_rtc_dt_ids);
+
+static struct platform_driver fm33256b_rtc_driver = {
+	.driver = {
+		.name = "fm33256b-rtc",
+		.of_match_table = fm33256b_rtc_dt_ids,
+	},
+	.probe = fm33256b_rtc_probe,
+	.remove = fm33256b_rtc_remove,
+};
+module_platform_driver(fm33256b_rtc_driver);
+
+MODULE_ALIAS("platform:fm33256b-rtc");
+MODULE_AUTHOR("Jeppe Ledet-Pedersen <jlp@gomspace.com>");
+MODULE_DESCRIPTION("Cypress FM33256B Processor Companion RTC Driver");
+MODULE_LICENSE("GPL v2");
-- 
2.1.4

  parent reply	other threads:[~2016-04-20 11:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-20 11:07 [PATCH 0/3] Cypress FM33256B processor companion support Jeppe Ledet-Pedersen
2016-04-20 11:07 ` [PATCH 1/3] mfd: add Cypress FM33256B Processor Companion driver Jeppe Ledet-Pedersen
2016-04-22  0:47   ` kbuild test robot
2016-04-22 19:32   ` Rob Herring
2016-04-22 20:11     ` Alexandre Belloni
2016-04-26 14:31       ` Jeppe Ledet-Pedersen
2016-05-03  8:14         ` Alexandre Belloni
2016-04-26 14:42     ` Jeppe Ledet-Pedersen
2016-04-20 11:07 ` [PATCH 2/3] misc: eeprom: add Cypress FM33256B FRAM driver Jeppe Ledet-Pedersen
2016-04-21 23:54   ` Alexandre Belloni
2016-04-26 12:08     ` Jeppe Ledet-Pedersen
2016-04-20 11:07 ` Jeppe Ledet-Pedersen [this message]
2016-04-21 23:44   ` [PATCH 3/3] rtc: add Cypress FM33256B RTC driver Alexandre Belloni
2016-04-26 12:17     ` Jeppe Ledet-Pedersen

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=1461150471-23163-4-git-send-email-jlp@gomspace.com \
    --to=jlp@gomspace.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=rtc-linux@googlegroups.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®