Re: [rtc-linux] [PATCH] isl12022: added Intersil ISL12022 RTC

From: Wan ZongShun
Date: Fri Jun 18 2010 - 01:34:02 EST


2010/6/18 Roman Fietze <roman.fietze@xxxxxxxxxxxxx>:
> Hallo Wan,
>
> On Friday 18 June 2010 04:08:02 Wan ZongShun wrote:
>
>> I have to remind you to use scripts/checkpatch.pl' to check your
>> patch format. There are more warning and errors in your patch.
>
> Ok, all done. One patch and checkpatch.pl tells me it's ok.
>

Hmmm, which mail client was used by you?
It seem to have destroyed your patch.

Would you mind sending your patch to me as attached file?
I will help you fix this issue.

>
> From 62d43961b73aafe10d1b33b0702b378cc29d0881 Mon Sep 17 00:00:00 2001
> From: Roman Fietze <roman.fietze@xxxxxxxxxxxxx>
> Date: Fri, 18 Jun 2010 07:20:44 +0200
> Subject: [PATCH] isl12022: add Intersil ISL12022 RTC driver
>
> - derived from rtc-pcf8563
> - no SRAM driver
>
> Signed-off-by: Roman Fietze <roman.fietze@xxxxxxxxxxxxx>
> ---
> Âdrivers/rtc/Kconfig    Â|  Â9 ++
> Âdrivers/rtc/Makefile    |  Â1 +
> Âdrivers/rtc/rtc-isl12022.c | Â327 ++++++++++++++++++++++++++++++++++++++++++++
> Â3 files changed, 337 insertions(+), 0 deletions(-)
> Âcreate mode 100644 drivers/rtc/rtc-isl12022.c
>
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 6a13037..ade6427 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -203,6 +203,15 @@ config RTC_DRV_ISL1208
> Â Â Â Â ÂThis driver can also be built as a module. If so, the module
> Â Â Â Â Âwill be called rtc-isl1208.
>
> +config RTC_DRV_ISL12022
> + Â Â Â tristate "Intersil ISL12022"
> + Â Â Â help
> + Â Â Â Â If you say yes here you get support for the
> + Â Â Â Â Intersil ISL12022 RTC chip.
> +
> + Â Â Â Â This driver can also be built as a module. If so, the module
> + Â Â Â Â will be called rtc-isl12022.
> +
> Âconfig RTC_DRV_X1205
> Â Â Â Âtristate "Xicor/Intersil X1205"
> Â Â Â Âhelp
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index 44ef194..782d516 100644
> --- a/drivers/rtc/Makefile
> +++ b/drivers/rtc/Makefile
> @@ -45,6 +45,7 @@ obj-$(CONFIG_RTC_DRV_EP93XX) Â+= rtc-ep93xx.o
> Âobj-$(CONFIG_RTC_DRV_FM3130) Â += rtc-fm3130.o
> Âobj-$(CONFIG_RTC_DRV_GENERIC) Â+= rtc-generic.o
> Âobj-$(CONFIG_RTC_DRV_ISL1208) Â+= rtc-isl1208.o
> +obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o
> Âobj-$(CONFIG_RTC_DRV_M41T80) Â += rtc-m41t80.o
> Âobj-$(CONFIG_RTC_DRV_M41T94) Â += rtc-m41t94.o
> Âobj-$(CONFIG_RTC_DRV_M48T35) Â += rtc-m48t35.o
> diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
> new file mode 100644
> index 0000000..4a8c9dd
> --- /dev/null
> +++ b/drivers/rtc/rtc-isl12022.c
> @@ -0,0 +1,327 @@
> +/*
> + * An I2C driver for the Intersil ISL 12022
> + *
> + * Author: Roman Fietze <roman.fietze@xxxxxxxxxxxxx>
> + *
> + * Based on the Philips PCF8563 RTC
> + * by Alessandro Zummo <a.zummo@xxxxxxxxxxxx>.
> + *
> + * 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.
> + */
> +
> +#include <linux/i2c.h>
> +#include <linux/bcd.h>
> +#include <linux/rtc.h>
> +#include <linux/slab.h>
> +
> +#define DRV_VERSION "0.1"
> +
> +/* ISL register offsets */
> +#define ISL12022_REG_SC Â Â Â Â Â Â Â Â0x00
> +#define ISL12022_REG_MN Â Â Â Â Â Â Â Â0x01
> +#define ISL12022_REG_HR Â Â Â Â Â Â Â Â0x02
> +#define ISL12022_REG_DT Â Â Â Â Â Â Â Â0x03
> +#define ISL12022_REG_MO Â Â Â Â Â Â Â Â0x04
> +#define ISL12022_REG_YR Â Â Â Â Â Â Â Â0x05
> +#define ISL12022_REG_DW Â Â Â Â Â Â Â Â0x06
> +
> +#define ISL12022_REG_SR Â Â Â Â Â Â Â Â0x07
> +#define ISL12022_REG_INT Â Â Â 0x08
> +
> +/* ISL register bits */
> +#define ISL12022_HR_MIL Â Â Â Â Â Â Â Â(1 << 7) Â Â Â Â/* military or 24 hour time */
> +
> +#define ISL12022_SR_LBAT85 Â Â (1 << 2)
> +#define ISL12022_SR_LBAT75 Â Â (1 << 1)
> +
> +#define ISL12022_INT_WRTC Â Â Â(1 << 6)
> +
> +
> +static struct i2c_driver isl12022_driver;
> +
> +struct isl12022 {
> + Â Â Â struct rtc_device *rtc;
> +
> + Â Â Â bool write_enabled; Â Â /* true if write enable is set */
> +};
> +
> +
> +static int isl12022_read_regs(struct i2c_client *client, uint8_t reg,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â uint8_t *data, size_t n)
> +{
> + Â Â Â struct i2c_msg msgs[] = {
> + Â Â Â Â Â Â Â {
> +            .addr  = client->addr,
> + Â Â Â Â Â Â Â Â Â Â Â .flags Â= 0,
> +            .len  Â= 1,
> +            .buf  Â= data
> + Â Â Â Â Â Â Â }, Â Â Â Â Â Â Â/* setup read ptr */
> + Â Â Â Â Â Â Â {
> +            .addr  = client->addr,
> + Â Â Â Â Â Â Â Â Â Â Â .flags Â= I2C_M_RD,
> +            .len  Â= n,
> +            .buf  Â= data
> + Â Â Â Â Â Â Â }
> + Â Â Â };
> +
> + Â Â Â int ret;
> +
> + Â Â Â data[0] = reg;
> + Â Â Â ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
> + Â Â Â if (ret != ARRAY_SIZE(msgs)) {
> + Â Â Â Â Â Â Â dev_err(&client->dev, "%s: read error, ret=%d\n",
> + Â Â Â Â Â Â Â Â Â Â Â __func__, ret);
> + Â Â Â Â Â Â Â return -EIO;
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +
> +static int isl12022_write_reg(struct i2c_client *client,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â uint8_t reg, uint8_t val)
> +{
> + Â Â Â uint8_t data[2] = { reg, val };
> + Â Â Â int err;
> +
> + Â Â Â err = i2c_master_send(client, data, sizeof(data));
> + Â Â Â if (err != sizeof(data)) {
> + Â Â Â Â Â Â Â dev_err(&client->dev,
> + Â Â Â Â Â Â Â Â Â Â Â "%s: err=%d addr=%02x, data=%02x\n",
> + Â Â Â Â Â Â Â Â Â Â Â __func__, err, data[0], data[1]);
> + Â Â Â Â Â Â Â return -EIO;
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +
> +/*
> + * In the routines that deal directly with the isl12022 hardware, we use
> + * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
> + */
> +static int isl12022_get_datetime(struct i2c_client *client, struct rtc_time *tm)
> +{
> + Â Â Â uint8_t buf[ISL12022_REG_INT + 1];
> + Â Â Â int ret;
> +
> + Â Â Â ret = isl12022_read_regs(client, ISL12022_REG_SC, buf, sizeof(buf));
> + Â Â Â if (ret)
> + Â Â Â Â Â Â Â return ret;
> +
> + Â Â Â if (buf[ISL12022_REG_SR] & (ISL12022_SR_LBAT85 | ISL12022_SR_LBAT75)) {
> + Â Â Â Â Â Â Â dev_warn(&client->dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â"voltage dropped below %u%%, "
> + Â Â Â Â Â Â Â Â Â Â Â Â"date and time is not reliable.\n",
> + Â Â Â Â Â Â Â Â Â Â Â Âbuf[ISL12022_REG_SR] & ISL12022_SR_LBAT85 ? 85 : 75);
> + Â Â Â }
> +
> + Â Â Â dev_dbg(&client->dev,
> + Â Â Â Â Â Â Â "%s: raw data is sec=%02x, min=%02x, hr=%02x, "
> + Â Â Â Â Â Â Â "mday=%02x, mon=%02x, year=%02x, wday=%02x, "
> + Â Â Â Â Â Â Â "sr=%02x, int=%02x",
> + Â Â Â Â Â Â Â __func__,
> + Â Â Â Â Â Â Â buf[ISL12022_REG_SC],
> + Â Â Â Â Â Â Â buf[ISL12022_REG_MN],
> + Â Â Â Â Â Â Â buf[ISL12022_REG_HR],
> + Â Â Â Â Â Â Â buf[ISL12022_REG_DT],
> + Â Â Â Â Â Â Â buf[ISL12022_REG_MO],
> + Â Â Â Â Â Â Â buf[ISL12022_REG_YR],
> + Â Â Â Â Â Â Â buf[ISL12022_REG_DW],
> + Â Â Â Â Â Â Â buf[ISL12022_REG_SR],
> + Â Â Â Â Â Â Â buf[ISL12022_REG_INT]);
> +
> + Â Â Â tm->tm_sec = bcd2bin(buf[ISL12022_REG_SC] & 0x7F);
> + Â Â Â tm->tm_min = bcd2bin(buf[ISL12022_REG_MN] & 0x7F);
> + Â Â Â tm->tm_hour = bcd2bin(buf[ISL12022_REG_HR] & 0x3F);
> + Â Â Â tm->tm_mday = bcd2bin(buf[ISL12022_REG_DT] & 0x3F);
> + Â Â Â tm->tm_wday = buf[ISL12022_REG_DW] & 0x07;
> + Â Â Â tm->tm_mon = bcd2bin(buf[ISL12022_REG_MO] & 0x1F) - 1;
> + Â Â Â tm->tm_year = bcd2bin(buf[ISL12022_REG_YR]) + 100;
> +
> + Â Â Â dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
> + Â Â Â Â Â Â Â "mday=%d, mon=%d, year=%d, wday=%d\n",
> + Â Â Â Â Â Â Â __func__,
> + Â Â Â Â Â Â Â tm->tm_sec, tm->tm_min, tm->tm_hour,
> + Â Â Â Â Â Â Â tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
> +
> + Â Â Â /* The clock can give out invalid datetime, but we cannot return
> + Â Â Â Â* -EINVAL otherwise hwclock will refuse to set the time on bootup. */
> + Â Â Â if (rtc_valid_tm(tm) < 0)
> + Â Â Â Â Â Â Â dev_err(&client->dev, "retrieved date and time is invalid.\n");
> +
> + Â Â Â return 0;
> +}
> +
> +static int isl12022_set_datetime(struct i2c_client *client, struct rtc_time *tm)
> +{
> + Â Â Â struct isl12022 *isl12022 = i2c_get_clientdata(client);
> + Â Â Â size_t i;
> + Â Â Â int ret;
> + Â Â Â uint8_t buf[ISL12022_REG_DW + 1];
> +
> + Â Â Â dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
> + Â Â Â Â Â Â Â "mday=%d, mon=%d, year=%d, wday=%d\n",
> + Â Â Â Â Â Â Â __func__,
> + Â Â Â Â Â Â Â tm->tm_sec, tm->tm_min, tm->tm_hour,
> + Â Â Â Â Â Â Â tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
> +
> + Â Â Â if (!isl12022->write_enabled) {
> +
> + Â Â Â Â Â Â Â ret = isl12022_read_regs(client, ISL12022_REG_INT, buf, 1);
> + Â Â Â Â Â Â Â if (ret)
> + Â Â Â Â Â Â Â Â Â Â Â return ret;
> +
> + Â Â Â Â Â Â Â /* Check if WRTC (write rtc enable) is set factory default is
> + Â Â Â Â Â Â Â Â* 0 (not set) */
> + Â Â Â Â Â Â Â if (!(buf[0] & ISL12022_INT_WRTC)) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(&client->dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"init write enable and 24 hour format\n");
> +
> + Â Â Â Â Â Â Â Â Â Â Â /* Set the write enable bit. */
> + Â Â Â Â Â Â Â Â Â Â Â ret = isl12022_write_reg(client,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂISL12022_REG_INT,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âbuf[0] | ISL12022_INT_WRTC);
> + Â Â Â Â Â Â Â Â Â Â Â if (ret)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return ret;
> +
> + Â Â Â Â Â Â Â Â Â Â Â /* Write to any RTC register to start RTC, we use the
> + Â Â Â Â Â Â Â Â Â Â Â Â* HR register, setting the MIL bit to use the 24 hour
> + Â Â Â Â Â Â Â Â Â Â Â Â* format. */
> + Â Â Â Â Â Â Â Â Â Â Â ret = isl12022_read_regs(client, ISL12022_REG_HR,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âbuf, 1);
> + Â Â Â Â Â Â Â Â Â Â Â if (ret)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return ret;
> +
> + Â Â Â Â Â Â Â Â Â Â Â ret = isl12022_write_reg(client,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂISL12022_REG_HR,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âbuf[0] | ISL12022_HR_MIL);
> + Â Â Â Â Â Â Â Â Â Â Â if (ret)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return ret;
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â isl12022->write_enabled = 1;
> + Â Â Â }
> +
> + Â Â Â /* hours, minutes and seconds */
> + Â Â Â buf[ISL12022_REG_SC] = bin2bcd(tm->tm_sec);
> + Â Â Â buf[ISL12022_REG_MN] = bin2bcd(tm->tm_min);
> + Â Â Â buf[ISL12022_REG_HR] = bin2bcd(tm->tm_hour);
> +
> + Â Â Â buf[ISL12022_REG_DT] = bin2bcd(tm->tm_mday);
> +
> + Â Â Â /* month, 1 - 12 */
> + Â Â Â buf[ISL12022_REG_MO] = bin2bcd(tm->tm_mon + 1);
> +
> + Â Â Â /* year and century */
> + Â Â Â buf[ISL12022_REG_YR] = bin2bcd(tm->tm_year % 100);
> +
> + Â Â Â buf[ISL12022_REG_DW] = tm->tm_wday & 0x07;
> +
> + Â Â Â /* write register's data */
> + Â Â Â for (i = 0; i < ARRAY_SIZE(buf); i++) {
> + Â Â Â Â Â Â Â ret = isl12022_write_reg(client, ISL12022_REG_SC + i,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âbuf[ISL12022_REG_SC + i]);
> + Â Â Â Â Â Â Â if (ret)
> + Â Â Â Â Â Â Â Â Â Â Â return -EIO;
> + Â Â Â };
> +
> + Â Â Â return 0;
> +}
> +
> +static int isl12022_rtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> + Â Â Â return isl12022_get_datetime(to_i2c_client(dev), tm);
> +}
> +
> +static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> + Â Â Â return isl12022_set_datetime(to_i2c_client(dev), tm);
> +}
> +
> +static const struct rtc_class_ops isl12022_rtc_ops = {
> +    .read_time   Â= isl12022_rtc_read_time,
> +    .set_time    = isl12022_rtc_set_time,
> +};
> +
> +static int isl12022_probe(struct i2c_client *client,
> + Â Â Â Â Â Â Â Â Â Â Â Â const struct i2c_device_id *id)
> +{
> + Â Â Â struct isl12022 *isl12022;
> +
> + Â Â Â int ret = 0;
> +
> + Â Â Â if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
> + Â Â Â Â Â Â Â return -ENODEV;
> +
> + Â Â Â isl12022 = kzalloc(sizeof(struct isl12022), GFP_KERNEL);
> + Â Â Â if (!isl12022)
> + Â Â Â Â Â Â Â return -ENOMEM;
> +
> + Â Â Â dev_dbg(&client->dev, "chip found, driver version " DRV_VERSION "\n");
> +
> + Â Â Â i2c_set_clientdata(client, isl12022);
> +
> + Â Â Â isl12022->rtc = rtc_device_register(isl12022_driver.driver.name,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &client->dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &isl12022_rtc_ops,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â THIS_MODULE);
> +
> + Â Â Â if (IS_ERR(isl12022->rtc)) {
> + Â Â Â Â Â Â Â ret = PTR_ERR(isl12022->rtc);
> + Â Â Â Â Â Â Â goto exit_kfree;
> + Â Â Â }
> +
> + Â Â Â return 0;
> +
> +exit_kfree:
> + Â Â Â kfree(isl12022);
> +
> + Â Â Â return ret;
> +}
> +
> +static int isl12022_remove(struct i2c_client *client)
> +{
> + Â Â Â struct isl12022 *isl12022 = i2c_get_clientdata(client);
> +
> + Â Â Â rtc_device_unregister(isl12022->rtc);
> + Â Â Â kfree(isl12022);
> +
> + Â Â Â return 0;
> +}
> +
> +static const struct i2c_device_id isl12022_id[] = {
> + Â Â Â { "isl12022", 0 },
> + Â Â Â { "rtc8564", 0 },
> + Â Â Â { }
> +};
> +MODULE_DEVICE_TABLE(i2c, isl12022_id);
> +
> +static struct i2c_driver isl12022_driver = {
> +    .driver     = {
> +        .name  = "rtc-isl12022",
> + Â Â Â },
> +    .probe     Â= isl12022_probe,
> +    .remove     = isl12022_remove,
> +    .id_table    = isl12022_id,
> +};
> +
> +static int __init isl12022_init(void)
> +{
> + Â Â Â return i2c_add_driver(&isl12022_driver);
> +}
> +
> +static void __exit isl12022_exit(void)
> +{
> + Â Â Â i2c_del_driver(&isl12022_driver);
> +}
> +
> +module_init(isl12022_init);
> +module_exit(isl12022_exit);
> +
> +MODULE_AUTHOR("roman.fietze@xxxxxxxxxxxxx");
> +MODULE_DESCRIPTION("ISL 12022 RTC driver");
> +MODULE_LICENSE("GPL");
> +MODULE_VERSION(DRV_VERSION);
> --
> 1.7.1
>
>
> --
> Roman Fietze        ÂTelemotive AG BÃro MÃhlhausen
> Breitwiesen               Â73347 MÃhlhausen
> Tel.: +49(0)7335/18493-45 Â Â Â Âhttp://www.telemotive.de
>



--
*linux-arm-kernel mailing list
mail addr:linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
you can subscribe by:
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

* linux-arm-NUC900 mailing list
mail addr:NUC900@xxxxxxxxxxxxxxxx
main web: https://groups.google.com/group/NUC900
you can subscribe it by sending me mail:
mcuos.com@xxxxxxxxx
¢éì®&Þ~º&¶¬–+-±éÝ¥Šw®žË±Êâmébžìdz¹Þ)í…æèw*jg¬±¨¶‰šŽŠÝj/êäz¹ÞŠà2ŠÞ¨è­Ú&¢)ß«a¶Úþø®G«éh®æj:+v‰¨Šwè†Ù>Wš±êÞiÛaxPjØm¶Ÿÿà -»+ƒùdš_