Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964940AbcDTL1j (ORCPT ); Wed, 20 Apr 2016 07:27:39 -0400 Received: from mail-am1on0146.outbound.protection.outlook.com ([157.56.112.146]:31290 "EHLO emea01-am1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751006AbcDTL1g (ORCPT ); Wed, 20 Apr 2016 07:27:36 -0400 Authentication-Results: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=gomspace.com; From: Jeppe Ledet-Pedersen To: , , , , , , , , , CC: , , , Jeppe Ledet-Pedersen Subject: [PATCH 3/3] rtc: add Cypress FM33256B RTC driver Date: Wed, 20 Apr 2016 13:07:51 +0200 Message-ID: <1461150471-23163-4-git-send-email-jlp@gomspace.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1461150471-23163-1-git-send-email-jlp@gomspace.com> References: <1461150471-23163-1-git-send-email-jlp@gomspace.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [77.243.61.136] X-ClientProxiedBy: VI1PR02CA0003.eurprd02.prod.outlook.com (10.162.7.141) To DB4PR04MB0637.eurprd04.prod.outlook.com (10.242.221.15) X-MS-Office365-Filtering-Correlation-Id: d4c74692-754a-4669-44b6-08d3690c8a10 X-Microsoft-Exchange-Diagnostics: 1;DB4PR04MB0637;2:pF+eL7drk62VKBe2WSE4ZnxMhOmnsBKRSLlIf9uTU2xi/ocrQ+81bttB3M4o0eeITDRO18UCVqm4+OEJUBZsmjy0lBdGepB53nveumAIBlSNG4505PRekGGPRcHerPbYYWH6A5Xl/dN6JC7NUa4GWWAI2DwZDmjsOVMAygY07zhanmMUcSZGuRg+hMyrwNou;3:WHK0D2hvqIiMwgshlIUOcuJgREQKZ/aRk+DKtxGD362jihXE8/V4msmxPk+9+UzxNas5uwg6kP5Ke2qNESZgamofKeNI7i8Tcn6+mwyY1qGuw1mGZSyI9EEBR7BPxn+K X-Micro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QELjCgJ/xFLjI4wO6s8dfEzrVUr6iH/lbu4INMbK8uA9ablqifmjFcS+z07vP34MElKLdjFXeLR/hzSLv7/2p23dFL2yuOpnhnNDuFMBpvKgKwJDmOyTSADzhC1EKxJ+JFjKCbOcfiA83ICsVG66pIbc8bwcHgZMIk4+TS8AQ03cMTi8/r2klL3AF0EG0Z5CDXJOrJATJNQ1Dux1mcLDlFha2AWMxXBns03dlUwrD17MaOqJeStgzw4/jhy;4:5S9uN9f2nft3/5oWbbA+HGPve5YkzvXl1gsfSGme6rUvGnCya6/9pG883Mgi/x1wdR0OqAGvecGewp7qtGPDTZgmoVHsXaxoMm1uJ1+n10qTPGr5gZIDEVad+Tl0C9zd0cCeUoS7UnaO3+P49Myu7hkuvFFARoVZstm1ED9w3g/hvgPxv9dVSznK3WC/hvtGJ/A6qcwstxbwFGAb1I6HgRt24Pu1OJ42hX8pgGq4Wrl3Qm1Xcof1C472QjTIWj5d0Xrushq+x3WasTskySvx62SuwmIADKjc4NKQgjffM5v3VUAfAki5FH3/4fIXuzLkm/iaRT034QSikUc6uI1ixO7M8zubGAC99AaGH9nxA5HzmfWjFYtVeBrvT1Edgh+I7Gpkm/ydAo+kdgND7SfY/JvwGvBkNufZjPeGaYah3fu4kj6b1FYgmcUQRV0lupsTx0OrgZYR7VpssKy/03lGEQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521026)(6040130)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041046)(6043046);SRVR:DB4PR04MB0637;BCL:0;PCL:0;RULEID:;SRVR:DB4PR04MB0637; X-Forefront-PRVS: 0918748D70 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6069001)(6009001)(4001430100002)(92566002)(36756003)(229853001)(5003940100001)(2950100001)(2201001)(33646002)(19580395003)(1096002)(4326007)(15975445007)(6116002)(77096005)(5001770100001)(50226001)(189998001)(42186005)(19580405001)(50986999)(76176999)(5004730100002)(47776003)(48376002)(2906002)(586003)(86362001)(107886002)(3846002)(5008740100001)(50466002)(81166005)(575784001)(66066001)(2004002)(921003)(83996005)(2101003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:DB4PR04MB0637;H:localhost.localdomain;FPR:;SPF:None;MLV:nov;PTR:InfoNoRecords;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DB4PR04MB0637;23:9PPJJlLCvL9Yx1OZ1YxILaAjWsNnWDe8KKD5Jvqr8?= =?us-ascii?Q?qsHbcwD6ZwOSsylwbNEnTQ1ALHHKwzU1wzUN/lR02S81jn/toUhEE5z/smkA?= =?us-ascii?Q?tcNZuaGjo225cG/34wYRfBjXOVfs5MAUHb8V+g4HhKJDw/MVq0mTg6tx1LQZ?= =?us-ascii?Q?jUcVg7X3gGa6XxarZtheUWdr6Nh1L65I/cw9E6Ds3zm1/d5nqUMORZDkjlAi?= =?us-ascii?Q?SUQrRIDhTq/+Gnwc88Hxdn63nJ9gtj/6FfuYKY3i527Ww8a/32NU0+E5yJSR?= =?us-ascii?Q?CWrfqLdWSiSvv4L4t0L+GNLXAaVl+gO9LnZOqrR9/JHhKQO2i7nboae2oMgW?= =?us-ascii?Q?QYpQxqbgbbywlXuwJlrq/EUgCwNDpv5bHvGnzk9cgLLIr5OnEQFzgTIfHduv?= =?us-ascii?Q?HmDQk2SOLJhcCRoowaoNRwwxLYEAuMaJhm7SYLVPvWYJe1vj8tbNvRnmebRx?= =?us-ascii?Q?FdOfBnh8QpXT3WV14otGRtW9995sU3q9kb1eIfE/96ukKnnOV/cNExqq46gj?= =?us-ascii?Q?Wh7J3HW8X6Y87XGOc6u3aFozZrd4u4Mc2dme/yB9BRzT/DwTP3yBTc9jMyhD?= =?us-ascii?Q?qt5rL09lCwwKZw4cdvz6Chk13w9ntXQq+si7+hKxslfsWuuHMQMszUaIlhoM?= =?us-ascii?Q?vfu0A7O8bQ6LyArBH6gGRE0xHdD01/QNhposOwJaHweGuXTK70B542OkXnju?= =?us-ascii?Q?bsZT+ear4e8JeMWdAgKTlkklM69WnL3CBiHWDMigIgqGQ+Orj7D4cDXODppi?= =?us-ascii?Q?D171H0Z4LDzvzpLmdd4lcVjpPNwDGFhbcvPSUPXitT5hVBvLxokaVSZOa6JX?= =?us-ascii?Q?A1FzpzrSBjmLNbZsDIZJOKcFqTepm922/sxoQsy1tfqA9bXIvfX4myMLP9st?= =?us-ascii?Q?41BHV3hltIrKeN14lAo8ndOPhU7O3IZr8bRhjZZNIrcD+ybxYCUs5P1BKBHV?= =?us-ascii?Q?RLWgxr+aEuXsf/446mD+T38t3Q2iQSGykca2fr7DqH6dxm1PwD4UQXr5TAS6?= =?us-ascii?Q?FZ0XOgDI/vREzBy4UNeQDE5gIQUmoDY7Yt9MiRqXFkwfptfydXYSEVBkA91y?= =?us-ascii?Q?bLEgUrO036iR2sKbAyHFR24q47XmHDmPBwPMVfNW+nzolqmwSNzxy3OlHhh6?= =?us-ascii?Q?zn8JD/cvJs=3D?= X-Microsoft-Exchange-Diagnostics: 1;DB4PR04MB0637;5:+6vhKK7GAVIYKAyQsWF2p36A1dvhdr6kEjpwazVwNXlp5510jrEjv03sPODFy7AdcC0E8V5GypYZNjSP6/RJ7rpgW4LepzgX7sttyJN++6BpXeijIGBPO8WGwoM5G0RNBm7N49sGcSHPeZW4qlUB0Q==;24:1CnQJ7W7HXP0BjTL5/t0F85pumX/+sxslykxS9Q0vzcB+VpOv+HH9LFth6omZf3lABkWmX+YkdSfLmKiCLPjl9b0saBTtZTI9hx3p+SknlI= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: gomspace.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2016 11:11:35.4186 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR04MB0637 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6486 Lines: 228 Signed-off-by: Jeppe Ledet-Pedersen --- 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 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 . + */ + +#include +#include +#include +#include +#include +#include + +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 "); +MODULE_DESCRIPTION("Cypress FM33256B Processor Companion RTC Driver"); +MODULE_LICENSE("GPL v2"); -- 2.1.4