Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 164801
b: refs/heads/master
c: f3d2570
h: refs/heads/master
i:
  164799: f66e715
v: v3
  • Loading branch information
Chris Verges authored and Linus Torvalds committed Sep 23, 2009
1 parent 6a0b301 commit b5e62b9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7f3923a184bb8e7ede5e5f58f1114bf7b8c611ea
refs/heads/master: f3d2570a1482a6d897ba29276964965f6fe970d8
44 changes: 32 additions & 12 deletions trunk/drivers/rtc/rtc-pcf2123.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <linux/rtc.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_CTRL2 (0x01) /* Control Register 2 */
Expand All @@ -61,7 +61,7 @@
static struct spi_driver pcf2123_driver;

struct pcf2123_sysfs_reg {
struct device_attribute attr; /* must be first */
struct device_attribute attr;
char name[2];
};

Expand All @@ -84,27 +84,42 @@ static ssize_t pcf2123_show(struct device *dev, struct device_attribute *attr,
char *buffer)
{
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];
unsigned long reg;
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);
if (ret < 0)
return sprintf(buffer, "error: %d", ret);
return -EIO;
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,
const char *buffer, size_t count) {
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];
unsigned long reg;
unsigned long val;

int ret;

txbuf[0] = PCF2123_WRITE | simple_strtoul(r->name, NULL, 16);
txbuf[1] = simple_strtoul(buffer, NULL, 0);
r = container_of(attr, struct pcf2123_sysfs_reg, attr);

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));
if (ret < 0)
return -EIO;
Expand Down Expand Up @@ -220,7 +235,7 @@ static int __devinit pcf2123_probe(struct spi_device *spi)
txbuf[0], txbuf[1]);
ret = spi_write(spi, txbuf, 2 * sizeof(u8));
if (ret < 0)
return ret;
goto kfree_exit;
pcf2123_delay_trec();

/* Stop the counter */
Expand All @@ -230,7 +245,7 @@ static int __devinit pcf2123_probe(struct spi_device *spi)
txbuf[0], txbuf[1]);
ret = spi_write(spi, txbuf, 2 * sizeof(u8));
if (ret < 0)
return ret;
goto kfree_exit;
pcf2123_delay_trec();

/* See if the counter was actually stopped */
Expand Down Expand Up @@ -284,11 +299,16 @@ static int __devinit pcf2123_probe(struct spi_device *spi)
if (ret) {
dev_err(&spi->dev, "Unable to create sysfs %s\n",
pdata->regs[i].name);
pdata->regs[i].name[0] = '\0';
goto sysfs_exit;
}
}

return 0;

sysfs_exit:
for (i--; i >= 0; i--)
device_remove_file(&spi->dev, &pdata->regs[i].attr);

kfree_exit:
kfree(pdata);
spi->dev.platform_data = NULL;
Expand Down

0 comments on commit b5e62b9

Please sign in to comment.