Commit 4fbeac95 authored by Chris Verges's avatar Chris Verges Committed by James Toy

Here's an updated patch with the changes requested by Andrew.

Major points of the update include:

   - Moved PCF2123 section in Kconfig to be inside the
     "if SPI_MASTER" blob, to take care of dependencies.

   - Changed udelay() to macro w/ comment, and shifted to
     using ndelay() instead due to 30 nsec requirement,
     not 30 usec as was originally coded.

   - Bypass delay if spi_*() commands fail.

Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent cf421744
......@@ -224,15 +224,6 @@ config RTC_DRV_PCF8583
This driver can also be built as a module. If so, the module
will be called rtc-pcf8583.
config RTC_DRV_PCF2123
tristate "NXP PCF2123"
help
If you say yes here you get support for the NXP PCF2123
RTC chip.
This driver can also be built as a module. If so, the module
will be called rtc-pcf2123.
config RTC_DRV_M41T80
tristate "ST M41T62/65/M41T80/81/82/83/84/85/87"
help
......@@ -387,6 +378,15 @@ config RTC_DRV_DS3234
This driver can also be built as a module. If so, the module
will be called rtc-ds3234.
config RTC_DRV_PCF2123
tristate "NXP PCF2123"
help
If you say yes here you get support for the NXP PCF2123
RTC chip.
This driver can also be built as a module. If so, the module
will be called rtc-pcf2123.
endif # SPI_MASTER
comment "Platform RTC drivers"
......
......@@ -23,7 +23,7 @@
#include <linux/workqueue.h>
#include <linux/spi/spi.h>
#define DRV_VERSION "0.2"
#define DRV_VERSION "0.3"
#define PCF2123_REG_CTRL1 0x00 /* Control Register 1 */
#define PCF2123_REG_CTRL2 0x01 /* Control Register 2 */
......@@ -39,6 +39,9 @@
#define PCF2123_CMD_W(addr) (((addr) & 0x0F) | 0x40) /* single write */
#define PCF2123_CMD_R(addr) (((addr) & 0x0F) | 0x90) /* single read */
/* The Trec (chip enable recovery time) is specified by the PCF2123 */
#define PCF2123_DELAY_TREC() { ndelay(30); }
static struct spi_driver pcf2123_driver;
struct pcf2123_plat_data {
......@@ -54,9 +57,9 @@ static int pcf2123_rtc_read_time(struct device *dev, struct rtc_time *tm)
txbuf[0] = PCF2123_CMD_R(PCF2123_REG_SC);
ret = spi_write_then_read(spi, txbuf, sizeof(txbuf),
rxbuf, sizeof(rxbuf));
udelay(30); /* Trec 30us */
if (ret < 0)
return ret;
PCF2123_DELAY_TREC();
tm->tm_sec = bcd2bin(rxbuf[0] & 0x7F);
tm->tm_min = bcd2bin(rxbuf[1] & 0x7F);
......@@ -99,9 +102,9 @@ static int pcf2123_rtc_set_time(struct device *dev, struct rtc_time *tm)
txbuf[0] = PCF2123_CMD_W(PCF2123_REG_CTRL1);
txbuf[1] = 0x20;
ret = spi_write(spi, txbuf, 2);
udelay(30); /* Trec 30us */
if (ret < 0)
return ret;
PCF2123_DELAY_TREC();
/* Set the new time */
txbuf[0] = PCF2123_CMD_W(PCF2123_REG_SC);
......@@ -114,17 +117,17 @@ static int pcf2123_rtc_set_time(struct device *dev, struct rtc_time *tm)
txbuf[7] = bin2bcd(tm->tm_year < 100 ? tm->tm_year : tm->tm_year - 100);
ret = spi_write(spi, txbuf, sizeof(txbuf));
udelay(30); /* Trec 30us */
if (ret < 0)
return ret;
PCF2123_DELAY_TREC();
/* Start the counter */
txbuf[0] = PCF2123_CMD_W(PCF2123_REG_CTRL1);
txbuf[1] = 0x00;
ret = spi_write(spi, txbuf, 2);
udelay(30); /* Trec 30us */
if (ret < 0)
return ret;
PCF2123_DELAY_TREC();
return 0;
}
......@@ -150,24 +153,24 @@ static int __devinit pcf2123_probe(struct spi_device *spi)
txbuf[0] = PCF2123_CMD_W(PCF2123_REG_CTRL1);
txbuf[1] = 0x58;
ret = spi_write(spi, txbuf, sizeof(txbuf));
udelay(30); /* Trec 30us */
if (ret < 0)
return ret;
PCF2123_DELAY_TREC();
/* Stop the counter */
txbuf[0] = PCF2123_CMD_W(PCF2123_REG_CTRL1);
txbuf[1] = 0x20;
ret = spi_write(spi, txbuf, sizeof(txbuf));
udelay(30); /* Trec 30us */
if (ret < 0)
return ret;
PCF2123_DELAY_TREC();
/* See if the counter was actually stopped */
txbuf[0] = PCF2123_CMD_R(PCF2123_REG_CTRL1);
ret = spi_write_then_read(spi, txbuf, 1, rxbuf, sizeof(rxbuf));
udelay(30); /* Trec 30us */
if (ret < 0)
goto kfree_exit;
PCF2123_DELAY_TREC();
if (!(rxbuf[0] & 0x20)) {
dev_err(&spi->dev, "not found.\n");
......@@ -182,9 +185,9 @@ static int __devinit pcf2123_probe(struct spi_device *spi)
txbuf[0] = PCF2123_CMD_W(PCF2123_REG_CTRL1);
txbuf[1] = 0x00;
ret = spi_write(spi, txbuf, sizeof(txbuf));
udelay(30); /* Trec 30us */
if (ret < 0)
goto kfree_exit;
PCF2123_DELAY_TREC();
/* Finalize the initialization */
rtc = rtc_device_register(pcf2123_driver.driver.name, &spi->dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment