From patchwork Tue Nov 18 14:46:27 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alessandro Zummo X-Patchwork-Id: 9421 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from yx-out-2122.google.com (yx-out-2122.google.com [74.125.44.25]) by ozlabs.org (Postfix) with ESMTP id D939FDDE04 for ; Wed, 19 Nov 2008 01:46:43 +1100 (EST) Received: by yx-out-2122.google.com with SMTP id 35so730759yxh.11 for ; Tue, 18 Nov 2008 06:46:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :received:received:received-spf:authentication-results:received :received:from:subject:to:cc:date:message-id:user-agent:mime-version :content-type:reply-to:sender:precedence:x-google-loop:mailing-list :list-id:list-post:list-help:list-unsubscribe:x-beenthere-env :x-beenthere; bh=ZpKU7iHA39AX+peVT9kVQbYbxwiOlycjrKAvGiizEh0=; b=xDUPZ8DoKw0Qwd9hgcXd5casF+4taVcFUlzKWkNhKE/5jgTm1xEBsJaUM8u36+Mf90 fcdrpfAkPyj0IyJFjhl5X+/C/FXPinxvRcUAAsHPX3J4nPzbrhVAtBjZTDjKs0kS/Xf0 not7NCxoGNzVEOdhbqSQH4DrY5ErvzVR/Auhc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results:from :subject:to:cc:date:message-id:user-agent:mime-version:content-type :reply-to:sender:precedence:x-google-loop:mailing-list:list-id :list-post:list-help:list-unsubscribe:x-beenthere-env:x-beenthere; b=fIMHYRSZR/I437YS8YtpCh36LJQpqHTehJ6SHBamtFxTaD5LFpRjfKaqxnTQdPSgvn w4tJacD0tPK0g11qsQJy+6XQvhbRAnN+AfMYgd1RDhlYGhpm27S598NaY4CUx8VhD9YH /8IawmgQ5BN9UAYO7PoGa2YS2XV3PqHTMhl20= Received: by 10.114.204.7 with SMTP id b7mr328649wag.2.1227019597924; Tue, 18 Nov 2008 06:46:37 -0800 (PST) Received: by 10.106.212.23 with SMTP id k23gr1630prg.0; Tue, 18 Nov 2008 06:46:37 -0800 (PST) X-Sender: a.zummo@towertech.it X-Apparently-To: rtc-linux@googlegroups.com Received: by 10.141.132.1 with SMTP id j1mr1526846rvn.2.1227019597333; Tue, 18 Nov 2008 06:46:37 -0800 (PST) Received: from mx0.towertech.it (mx0.towertech.it [213.215.222.73]) by mx.google.com with SMTP id k32si2536085wah.1.2008.11.18.06.46.31; Tue, 18 Nov 2008 06:46:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of a.zummo@towertech.it designates 213.215.222.73 as permitted sender) client-ip=213.215.222.73; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of a.zummo@towertech.it designates 213.215.222.73 as permitted sender) smtp.mail=a.zummo@towertech.it Received: (qmail 3381 invoked from network); 18 Nov 2008 15:46:28 +0100 Received: from unknown (HELO i1501.lan.towertech.it) (81.208.60.204) by mx0.towertech.it with SMTP; 18 Nov 2008 15:46:28 +0100 From: Alessandro Zummo Subject: [rtc-linux] [RFC PATCH] rtc: rtc-max6902 fixes To: rtc-linux@googlegroups.com Cc: Alessandro Zummo , David Brownell , Raphael Assenat Date: Tue, 18 Nov 2008 15:46:27 +0100 Message-ID: <20081118144626.8327.25255.stgit@i1501.lan.towertech.it> User-Agent: StGIT/0.14.2 Mime-Version: 1.0 Reply-To: rtc-linux@googlegroups.com Sender: rtc-linux@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rtc-linux@googlegroups.com; contact rtc-linux+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rtc-linux@googlegroups.com X-BeenThere: rtc-linux@googlegroups.com - no changelogs in code - no banners - use local buffers - fix probe sequence - fixed style issues - use dev_dbg instead of printk Signed-off-by: Alessandro Zummo Cc: David Brownell Cc: Raphael Assenat --- drivers/rtc/rtc-max6902.c | 161 ++++++++++++++++----------------------------- 1 files changed, 58 insertions(+), 103 deletions(-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist before submitting a driver. -~----------~----~----~----~------~----~------~--~--- diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c index 2f6507d..ef5a42a 100644 --- a/drivers/rtc/rtc-max6902.c +++ b/drivers/rtc/rtc-max6902.c @@ -9,14 +9,6 @@ * * Driver for MAX6902 spi RTC * - * Changelog: - * - * 24-May-2006: Raphael Assenat - * - Major rework - * Converted to rtc_device and uses the SPI layer. - * - * ??-???-2005: Someone at Compulab - * - Initial driver creation. */ #include @@ -26,7 +18,6 @@ #include #include #include -#include #define MAX6902_REG_SECONDS 0x01 #define MAX6902_REG_MINUTES 0x03 @@ -40,13 +31,6 @@ #undef MAX6902_DEBUG -struct max6902 { - struct rtc_device *rtc; - u8 buf[9]; /* Burst read cmd + 8 registers */ - u8 tx_buf[2]; - u8 rx_buf[2]; -}; - static void max6902_set_reg(struct device *dev, unsigned char address, unsigned char data) { @@ -64,10 +48,10 @@ static int max6902_get_reg(struct device *dev, unsigned char address, unsigned char *data) { struct spi_device *spi = to_spi_device(dev); - struct max6902 *chip = dev_get_drvdata(dev); struct spi_message message; struct spi_transfer xfer; int status; + unsigned char buf[2]; if (!data) return -EINVAL; @@ -76,93 +60,91 @@ static int max6902_get_reg(struct device *dev, unsigned char address, spi_message_init(&message); memset(&xfer, 0, sizeof(xfer)); xfer.len = 2; - /* Can tx_buf and rx_buf be equal? The doc in spi.h is not sure... */ - xfer.tx_buf = chip->tx_buf; - xfer.rx_buf = chip->rx_buf; + xfer.tx_buf = &buf; + xfer.rx_buf = &buf; /* Set MSB to indicate read */ - chip->tx_buf[0] = address | 0x80; + buf[0] = address | 0x80; spi_message_add_tail(&xfer, &message); /* do the i/o */ status = spi_sync(spi, &message); - if (status == 0) - *data = chip->rx_buf[1]; + *data = buf[1]; + return status; } -static int max6902_get_datetime(struct device *dev, struct rtc_time *dt) +static int max6902_read_time(struct device *dev, struct rtc_time *dt) { - unsigned char tmp; - int century; - int err; + int err, century; struct spi_device *spi = to_spi_device(dev); - struct max6902 *chip = dev_get_drvdata(dev); struct spi_message message; struct spi_transfer xfer; - int status; - - err = max6902_get_reg(dev, MAX6902_REG_CENTURY, &tmp); - if (err) - return err; + unsigned char buf[8]; /* build the message */ spi_message_init(&message); memset(&xfer, 0, sizeof(xfer)); xfer.len = 1 + 7; /* Burst read command + 7 registers */ - xfer.tx_buf = chip->buf; - xfer.rx_buf = chip->buf; - chip->buf[0] = 0xbf; /* Burst read */ + xfer.tx_buf = &buf; + xfer.rx_buf = &buf; + + buf[0] = 0xbf; /* Burst read */ spi_message_add_tail(&xfer, &message); /* do the i/o */ - status = spi_sync(spi, &message); - if (status) - return status; + err = spi_sync(spi, &message); + if (err != 0) + return err; /* The chip sends data in this order: * Seconds, Minutes, Hours, Date, Month, Day, Year */ - dt->tm_sec = bcd2bin(chip->buf[1]); - dt->tm_min = bcd2bin(chip->buf[2]); - dt->tm_hour = bcd2bin(chip->buf[3]); - dt->tm_mday = bcd2bin(chip->buf[4]); - dt->tm_mon = bcd2bin(chip->buf[5]) - 1; - dt->tm_wday = bcd2bin(chip->buf[6]); - dt->tm_year = bcd2bin(chip->buf[7]); + dt->tm_sec = bcd2bin(buf[1]); + dt->tm_min = bcd2bin(buf[2]); + dt->tm_hour = bcd2bin(buf[3]); + dt->tm_mday = bcd2bin(buf[4]); + dt->tm_mon = bcd2bin(buf[5]) - 1; + dt->tm_wday = bcd2bin(buf[6]); + dt->tm_year = bcd2bin(buf[7]); + + /* Read century */ + err = max6902_get_reg(dev, MAX6902_REG_CENTURY, &buf[0]); + if (err != 0) + return err; - century = bcd2bin(tmp) * 100; + century = bcd2bin(buf[0]) * 100; dt->tm_year += century; dt->tm_year -= 1900; #ifdef MAX6902_DEBUG - printk("\n%s : Read RTC values\n",__func__); - printk("tm_hour: %i\n",dt->tm_hour); - printk("tm_min : %i\n",dt->tm_min); - printk("tm_sec : %i\n",dt->tm_sec); - printk("tm_year: %i\n",dt->tm_year); - printk("tm_mon : %i\n",dt->tm_mon); - printk("tm_mday: %i\n",dt->tm_mday); - printk("tm_wday: %i\n",dt->tm_wday); + dev_dbg(dev, ("\n%s : Read RTC values\n", __func__); + dev_dbg(dev, ("tm_hour: %i\n", dt->tm_hour); + dev_dbg(dev, ("tm_min : %i\n", dt->tm_min); + dev_dbg(dev, ("tm_sec : %i\n", dt->tm_sec); + dev_dbg(dev, ("tm_year: %i\n", dt->tm_year); + dev_dbg(dev, ("tm_mon : %i\n", dt->tm_mon); + dev_dbg(dev, ("tm_mday: %i\n", dt->tm_mday); + dev_dbg(dev, ("tm_wday: %i\n", dt->tm_wday); #endif - return 0; + return rtc_valid_tm(dt); } -static int max6902_set_datetime(struct device *dev, struct rtc_time *dt) +static int max6902_set_time(struct device *dev, struct rtc_time *dt) { - dt->tm_year = dt->tm_year+1900; + dt->tm_year = dt->tm_year + 1900; #ifdef MAX6902_DEBUG - printk("\n%s : Setting RTC values\n",__func__); - printk("tm_sec : %i\n",dt->tm_sec); - printk("tm_min : %i\n",dt->tm_min); - printk("tm_hour: %i\n",dt->tm_hour); - printk("tm_mday: %i\n",dt->tm_mday); - printk("tm_wday: %i\n",dt->tm_wday); - printk("tm_year: %i\n",dt->tm_year); + dev_dbg(dev, ("\n%s : Setting RTC values\n", __func__); + dev_dbg(dev, ("tm_sec : %i\n", dt->tm_sec); + dev_dbg(dev, ("tm_min : %i\n", dt->tm_min); + dev_dbg(dev, ("tm_hour: %i\n", dt->tm_hour); + dev_dbg(dev, ("tm_mday: %i\n", dt->tm_mday); + dev_dbg(dev, ("tm_wday: %i\n", dt->tm_wday); + dev_dbg(dev, ("tm_year: %i\n", dt->tm_year); #endif /* Remove write protection */ @@ -173,10 +155,10 @@ static int max6902_set_datetime(struct device *dev, struct rtc_time *dt) max6902_set_reg(dev, 0x05, bin2bcd(dt->tm_hour)); max6902_set_reg(dev, 0x07, bin2bcd(dt->tm_mday)); - max6902_set_reg(dev, 0x09, bin2bcd(dt->tm_mon+1)); + max6902_set_reg(dev, 0x09, bin2bcd(dt->tm_mon + 1)); max6902_set_reg(dev, 0x0B, bin2bcd(dt->tm_wday)); - max6902_set_reg(dev, 0x0D, bin2bcd(dt->tm_year%100)); - max6902_set_reg(dev, 0x13, bin2bcd(dt->tm_year/100)); + max6902_set_reg(dev, 0x0D, bin2bcd(dt->tm_year % 100)); + max6902_set_reg(dev, 0x13, bin2bcd(dt->tm_year / 100)); /* Compulab used a delay here. However, the datasheet * does not mention a delay being required anywhere... */ @@ -188,16 +170,6 @@ static int max6902_set_datetime(struct device *dev, struct rtc_time *dt) return 0; } -static int max6902_read_time(struct device *dev, struct rtc_time *tm) -{ - return max6902_get_datetime(dev, tm); -} - -static int max6902_set_time(struct device *dev, struct rtc_time *tm) -{ - return max6902_set_datetime(dev, tm); -} - static const struct rtc_class_ops max6902_rtc_ops = { .read_time = max6902_read_time, .set_time = max6902_set_time, @@ -207,45 +179,29 @@ static int __devinit max6902_probe(struct spi_device *spi) { struct rtc_device *rtc; unsigned char tmp; - struct max6902 *chip; int res; - rtc = rtc_device_register("max6902", - &spi->dev, &max6902_rtc_ops, THIS_MODULE); - if (IS_ERR(rtc)) - return PTR_ERR(rtc); - spi->mode = SPI_MODE_3; spi->bits_per_word = 8; spi_setup(spi); - chip = kzalloc(sizeof *chip, GFP_KERNEL); - if (!chip) { - rtc_device_unregister(rtc); - return -ENOMEM; - } - chip->rtc = rtc; - dev_set_drvdata(&spi->dev, chip); - res = max6902_get_reg(&spi->dev, MAX6902_REG_SECONDS, &tmp); - if (res) { - rtc_device_unregister(rtc); + if (res != 0) return res; - } + + rtc = rtc_device_register("max6902", + &spi->dev, &max6902_rtc_ops, THIS_MODULE); + if (IS_ERR(rtc)) + return PTR_ERR(rtc); return 0; } static int __devexit max6902_remove(struct spi_device *spi) { - struct max6902 *chip = platform_get_drvdata(spi); - struct rtc_device *rtc = chip->rtc; - - if (rtc) - rtc_device_unregister(rtc); - - kfree(chip); + struct rtc_device *rtc = platform_get_drvdata(spi); + rtc_device_unregister(rtc); return 0; } @@ -261,7 +217,6 @@ static struct spi_driver max6902_driver = { static __init int max6902_init(void) { - printk("max6902 spi driver\n"); return spi_register_driver(&max6902_driver); } module_init(max6902_init);