Commit f3d2570a authored by Chris Verges's avatar Chris Verges Committed by Linus Torvalds

rtc-philips-pcf2123-rtc-spi-driver-updates

Signed-off: Chris Verges <chrisv@cyberswitching.com>
Cc: Christian Pellegrin <chripell@fsfe.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7f3923a1
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#define DRV_VERSION "0.5" #define DRV_VERSION "0.6"
#define PCF2123_REG_CTRL1 (0x00) /* Control Register 1 */ #define PCF2123_REG_CTRL1 (0x00) /* Control Register 1 */
#define PCF2123_REG_CTRL2 (0x01) /* Control Register 2 */ #define PCF2123_REG_CTRL2 (0x01) /* Control Register 2 */
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
static struct spi_driver pcf2123_driver; static struct spi_driver pcf2123_driver;
struct pcf2123_sysfs_reg { struct pcf2123_sysfs_reg {
struct device_attribute attr; /* must be first */ struct device_attribute attr;
char name[2]; char name[2];
}; };
...@@ -84,27 +84,42 @@ static ssize_t pcf2123_show(struct device *dev, struct device_attribute *attr, ...@@ -84,27 +84,42 @@ static ssize_t pcf2123_show(struct device *dev, struct device_attribute *attr,
char *buffer) char *buffer)
{ {
struct spi_device *spi = to_spi_device(dev); struct spi_device *spi = to_spi_device(dev);
struct pcf2123_sysfs_reg *r = (struct pcf2123_sysfs_reg *) attr; struct pcf2123_sysfs_reg *r;
u8 txbuf[1], rxbuf[1]; u8 txbuf[1], rxbuf[1];
unsigned long reg;
int ret; int ret;
txbuf[0] = PCF2123_READ | simple_strtoul(r->name, NULL, 16); r = container_of(attr, struct pcf2123_sysfs_reg, attr);
if (strict_strtoul(r->name, 16, &reg))
return -EINVAL;
txbuf[0] = PCF2123_READ | reg;
ret = spi_write_then_read(spi, txbuf, 1, rxbuf, 1); ret = spi_write_then_read(spi, txbuf, 1, rxbuf, 1);
if (ret < 0) if (ret < 0)
return sprintf(buffer, "error: %d", ret); return -EIO;
pcf2123_delay_trec(); pcf2123_delay_trec();
return sprintf(buffer, "0x%x", rxbuf[0]); return sprintf(buffer, "0x%x\n", rxbuf[0]);
} }
static ssize_t pcf2123_store(struct device *dev, struct device_attribute *attr, static ssize_t pcf2123_store(struct device *dev, struct device_attribute *attr,
const char *buffer, size_t count) { const char *buffer, size_t count) {
struct spi_device *spi = to_spi_device(dev); struct spi_device *spi = to_spi_device(dev);
struct pcf2123_sysfs_reg *r = (struct pcf2123_sysfs_reg *) attr; struct pcf2123_sysfs_reg *r;
u8 txbuf[2]; u8 txbuf[2];
unsigned long reg;
unsigned long val;
int ret; int ret;
txbuf[0] = PCF2123_WRITE | simple_strtoul(r->name, NULL, 16); r = container_of(attr, struct pcf2123_sysfs_reg, attr);
txbuf[1] = simple_strtoul(buffer, NULL, 0);
if (strict_strtoul(r->name, 16, &reg)
|| strict_strtoul(buffer, 10, &val))
return -EINVAL;
txbuf[0] = PCF2123_WRITE | reg;
txbuf[1] = val;
ret = spi_write(spi, txbuf, sizeof(txbuf)); ret = spi_write(spi, txbuf, sizeof(txbuf));
if (ret < 0) if (ret < 0)
return -EIO; return -EIO;
...@@ -220,7 +235,7 @@ static int __devinit pcf2123_probe(struct spi_device *spi) ...@@ -220,7 +235,7 @@ static int __devinit pcf2123_probe(struct spi_device *spi)
txbuf[0], txbuf[1]); txbuf[0], txbuf[1]);
ret = spi_write(spi, txbuf, 2 * sizeof(u8)); ret = spi_write(spi, txbuf, 2 * sizeof(u8));
if (ret < 0) if (ret < 0)
return ret; goto kfree_exit;
pcf2123_delay_trec(); pcf2123_delay_trec();
/* Stop the counter */ /* Stop the counter */
...@@ -230,7 +245,7 @@ static int __devinit pcf2123_probe(struct spi_device *spi) ...@@ -230,7 +245,7 @@ static int __devinit pcf2123_probe(struct spi_device *spi)
txbuf[0], txbuf[1]); txbuf[0], txbuf[1]);
ret = spi_write(spi, txbuf, 2 * sizeof(u8)); ret = spi_write(spi, txbuf, 2 * sizeof(u8));
if (ret < 0) if (ret < 0)
return ret; goto kfree_exit;
pcf2123_delay_trec(); pcf2123_delay_trec();
/* See if the counter was actually stopped */ /* See if the counter was actually stopped */
...@@ -284,11 +299,16 @@ static int __devinit pcf2123_probe(struct spi_device *spi) ...@@ -284,11 +299,16 @@ static int __devinit pcf2123_probe(struct spi_device *spi)
if (ret) { if (ret) {
dev_err(&spi->dev, "Unable to create sysfs %s\n", dev_err(&spi->dev, "Unable to create sysfs %s\n",
pdata->regs[i].name); pdata->regs[i].name);
pdata->regs[i].name[0] = '\0'; goto sysfs_exit;
} }
} }
return 0; return 0;
sysfs_exit:
for (i--; i >= 0; i--)
device_remove_file(&spi->dev, &pdata->regs[i].attr);
kfree_exit: kfree_exit:
kfree(pdata); kfree(pdata);
spi->dev.platform_data = NULL; spi->dev.platform_data = NULL;
......
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