From patchwork Mon Mar 14 14:45:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 597060 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-pf0-x23d.google.com (mail-pf0-x23d.google.com [IPv6:2607:f8b0:400e:c00::23d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qP0sr67y2z9sR9 for ; Tue, 15 Mar 2016 01:45:36 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=JDM+EgMA; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=aCGWrVFK; dkim-atps=neutral Received: by mail-pf0-x23d.google.com with SMTP id q129sf38810073pfb.1 for ; Mon, 14 Mar 2016 07:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group :list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe; bh=7XjQF2NB3TMAOy1BKrfyD/gFeGT2IQgO07CO1fk86Cs=; b=JDM+EgMAI/wdxSBdmtAuCSqSWlKi8j6fKANFHLWErGuIFvDhi1miAMTYHyf3uAHAvE OEWulhXZ3IyEpMxzmmFxPBO1x5niezRaVioqsckfjU6/BjeE6gmTAktSFg3PkXi/evn0 /fP+TVYnzUwV0qIk2YxSMqi8KewbidDproSrGf3kLVOi8KF4yNIPkVgtPIWqH99cuOP7 rHb7rlUKZLlQ5BGrzS1WYiZFB8y7o9vcTMWWCfvu9n78ccQ9AuAvQFHQ7lT+rvknF/nC PDpglXnQ7bMNpr2IhBabKKITh2s/cwNB+Rm2e3EkKQp0Vqmx2mWjDGd92HU8BdaFpazm e2uQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group :list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe; bh=7XjQF2NB3TMAOy1BKrfyD/gFeGT2IQgO07CO1fk86Cs=; b=aCGWrVFKiSdhTUm9S8n/uV1dDcyVljHGYKaWSQ1GlpD5Vrb/Re1qec3j0m/rwftlg2 eLGYMwWmHWNCUwZolVX3XhtghVYs5rA9i8QOz00gvvLYSYYkG5c/RFw2/O1bRiR4St0N uL92yhD4WGe7U1Bk+8Ye3KA4xNh3t8y2zybaPSPOmJN5g/kjP+rC0hQFe0fp4dNOc9xC R0vgRSoVM3besRX0dHHlQdHha6a32eSQWmUyQn60/yVO2tnU5EsmujspxvrqNGOrZr8m 3+ZyCTyaLW73fC/mpbhpTopAVInutH/UCw9tkqhpwOCeyOjIsKwWsnAgsZ4Ci43cchUF 1C1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe; bh=7XjQF2NB3TMAOy1BKrfyD/gFeGT2IQgO07CO1fk86Cs=; b=U/VM1mtvKAPuvWvFy10VpoOC2Z9a7ltbCA5hdyD3ji0jZjMS6HMV0SlAM4T8o0nzR+ +wlbKc9OrMgKfnl3BuuyOa+2qOZTcwvOiBMymDe+Sp7jU7VLrqVnrgqpetK7qRhpuDFT rXiR9q/2zwtxaZIDa1FD7GyXkihgyZKMcrC1I6vHwtX5j7oEXxgDi21RsDoej4gp72mc O3lHXgkonwmgMJ/LFd5/nqFNBCdp5Ig39v0IB3C0KCkiRkVeEX3Hy3T5R72EvTdgF1vC cMaP/Cr2mZNdqYTOvKKt6tx73h480J8InqRnmJ/zWXywJEDD5DaKqE4kMPKk/e8v/O2+ fucQ== X-Gm-Message-State: AD7BkJJ1ktzpIcwFyre8CggTdu9T6NkVs0izBXQpOv1nBRmWLiYrthqgiWAzqX7u8cQxNA== X-Received: by 10.182.19.129 with SMTP id f1mr239830obe.20.1457966734976; Mon, 14 Mar 2016 07:45:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.182.20.164 with SMTP id o4ls1104246obe.54.gmail; Mon, 14 Mar 2016 07:45:34 -0700 (PDT) X-Received: by 10.182.63.17 with SMTP id c17mr7484755obs.49.1457966734613; Mon, 14 Mar 2016 07:45:34 -0700 (PDT) Received: from mail-pf0-x243.google.com (mail-pf0-x243.google.com. [2607:f8b0:400e:c00::243]) by gmr-mx.google.com with ESMTPS id sf5si3328105pac.1.2016.03.14.07.45.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Mar 2016 07:45:34 -0700 (PDT) Received-SPF: pass (google.com: domain of akinobu.mita@gmail.com designates 2607:f8b0:400e:c00::243 as permitted sender) client-ip=2607:f8b0:400e:c00::243; Received: by mail-pf0-x243.google.com with SMTP id n5so7998572pfn.1 for ; Mon, 14 Mar 2016 07:45:34 -0700 (PDT) X-Received: by 10.98.93.205 with SMTP id n74mr30432479pfj.99.1457966734439; Mon, 14 Mar 2016 07:45:34 -0700 (PDT) Received: from localhost.localdomain (KD113159139091.ppp-bb.dion.ne.jp. [113.159.139.91]) by smtp.gmail.com with ESMTPSA id wx3sm32909754pab.25.2016.03.14.07.45.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Mar 2016 07:45:33 -0700 (PDT) From: Akinobu Mita To: rtc-linux@googlegroups.com Cc: Akinobu Mita , Alessandro Zummo , Alexandre Belloni Subject: [rtc-linux] [PATCH v2 2/3] rtc: pcf2127: add support for spi interface Date: Mon, 14 Mar 2016 23:45:00 +0900 Message-Id: <1457966701-6532-2-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1457966701-6532-1-git-send-email-akinobu.mita@gmail.com> References: <1457966701-6532-1-git-send-email-akinobu.mita@gmail.com> X-Original-Sender: Akinobu.Mita@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of akinobu.mita@gmail.com designates 2607:f8b0:400e:c00::243 as permitted sender) smtp.mailfrom=akinobu.mita@gmail.com; dkim=pass header.i=@gmail.com; dmarc=pass (p=NONE dis=NONE) header.from=gmail.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: rtc-linux@googlegroups.com X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , pcf2127 has selectable I2C-bus and SPI-bus interface support. This adds support for SPI interface. Signed-off-by: Akinobu Mita Cc: Alessandro Zummo Cc: Alexandre Belloni --- * No changes from v1 drivers/rtc/Kconfig | 19 ++++---- drivers/rtc/rtc-pcf2127.c | 118 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 126 insertions(+), 11 deletions(-) diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 777fa2d..9d0f4da 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -400,15 +400,6 @@ config RTC_DRV_PALMAS This driver can also be built as a module. If so, the module will be called rtc-palma. -config RTC_DRV_PCF2127 - tristate "NXP PCF2127" - help - If you say yes here you get support for the NXP PCF2127/29 RTC - chips. - - This driver can also be built as a module. If so, the module - will be called rtc-pcf2127. - config RTC_DRV_PCF8523 tristate "NXP PCF8523" help @@ -767,6 +758,16 @@ config RTC_DRV_DS3232 This driver can also be built as a module. If so, the module will be called rtc-ds3232. +config RTC_DRV_PCF2127 + tristate "NXP PCF2127" + depends on RTC_I2C_AND_SPI + help + If you say yes here you get support for the NXP PCF2127/29 RTC + chips. + + This driver can also be built as a module. If so, the module + will be called rtc-pcf2127. + comment "Platform RTC drivers" # this 'CMOS' RTC driver is arch dependent because diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index fa492cd..194c440 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -1,5 +1,5 @@ /* - * An I2C driver for the NXP PCF2127 RTC + * An I2C and SPI driver for the NXP PCF2127 RTC * Copyright 2013 Til-Technologies * * Author: Renaud Cerrato @@ -14,6 +14,7 @@ */ #include +#include #include #include #include @@ -200,6 +201,8 @@ static const struct of_device_id pcf2127_of_match[] = { MODULE_DEVICE_TABLE(of, pcf2127_of_match); #endif +#if IS_ENABLED(CONFIG_I2C) + static int pcf2127_i2c_write(void *context, const void *data, size_t count) { struct device *dev = context; @@ -311,7 +314,118 @@ static struct i2c_driver pcf2127_i2c_driver = { .probe = pcf2127_i2c_probe, .id_table = pcf2127_i2c_id, }; -module_i2c_driver(pcf2127_i2c_driver); + +static int pcf2127_i2c_register_driver(void) +{ + return i2c_add_driver(&pcf2127_i2c_driver); +} + +static void pcf2127_i2c_unregister_driver(void) +{ + i2c_del_driver(&pcf2127_i2c_driver); +} + +#else + +static int pcf2127_i2c_register_driver(void) +{ + return 0; +} + +static void pcf2127_i2c_unregister_driver(void) +{ +} + +#endif + +#if IS_ENABLED(CONFIG_SPI_MASTER) + +static struct spi_driver pcf2127_spi_driver; + +static int pcf2127_spi_probe(struct spi_device *spi) +{ + static const struct regmap_config config = { + .reg_bits = 8, + .val_bits = 8, + .read_flag_mask = 0xa0, + .write_flag_mask = 0x20, + }; + struct regmap *regmap; + + regmap = devm_regmap_init_spi(spi, &config); + if (IS_ERR(regmap)) { + dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n", + __func__, PTR_ERR(regmap)); + return PTR_ERR(regmap); + } + + return pcf2127_probe(&spi->dev, regmap, pcf2127_spi_driver.driver.name); +} + +static const struct spi_device_id pcf2127_spi_id[] = { + { "pcf2127", 0 }, + { } +}; +MODULE_DEVICE_TABLE(spi, pcf2127_spi_id); + +static struct spi_driver pcf2127_spi_driver = { + .driver = { + .name = "rtc-pcf2127-spi", + .of_match_table = of_match_ptr(pcf2127_of_match), + }, + .probe = pcf2127_spi_probe, + .id_table = pcf2127_spi_id, +}; + +static int pcf2127_spi_register_driver(void) +{ + return spi_register_driver(&pcf2127_spi_driver); +} + +static void pcf2127_spi_unregister_driver(void) +{ + spi_unregister_driver(&pcf2127_spi_driver); +} + +#else + +static int pcf2127_spi_register_driver(void) +{ + return 0; +} + +static void pcf2127_spi_unregister_driver(void) +{ +} + +#endif + +static int __init pcf2127_init(void) +{ + int ret; + + ret = pcf2127_i2c_register_driver(); + if (ret) { + pr_err("Failed to register pcf2127 i2c driver: %d\n", ret); + return ret; + } + + ret = pcf2127_spi_register_driver(); + if (ret) { + pr_err("Failed to register pcf2127 spi driver: %d\n", ret); + pcf2127_i2c_unregister_driver(); + } + + return ret; +} +module_init(pcf2127_init) + +static void __exit pcf2127_exit(void) +{ + pcf2127_spi_unregister_driver(); + pcf2127_i2c_unregister_driver(); +} +module_exit(pcf2127_exit) MODULE_AUTHOR("Renaud Cerrato "); MODULE_DESCRIPTION("NXP PCF2127 RTC driver");