Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 198331
b: refs/heads/master
c: 72cc8e5
h: refs/heads/master
i:
  198329: d2b527d
  198327: 14a9435
v: v3
  • Loading branch information
Marc Zyngier authored and Linus Torvalds committed May 25, 2010
1 parent 91550ba commit 21967eb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 19 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: e17ab5cbed795d3823da830f5e8d3ffe25a38446
refs/heads/master: 72cc8e51cfdde9007adab7d841ac4113b05b2c56
85 changes: 67 additions & 18 deletions trunk/drivers/rtc/rtc-ds1302.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <linux/rtc.h>
#include <linux/io.h>
#include <linux/bcd.h>
#include <asm/rtc.h>

#define DRV_NAME "rtc-ds1302"
#define DRV_VERSION "0.1.1"
Expand All @@ -34,14 +33,55 @@
#define RTC_ADDR_MIN 0x01 /* Address of minute register */
#define RTC_ADDR_SEC 0x00 /* Address of second register */

#ifdef CONFIG_SH_SECUREEDGE5410
#include <asm/rtc.h>
#include <mach/snapgear.h>

#define RTC_RESET 0x1000
#define RTC_IODATA 0x0800
#define RTC_SCLK 0x0400

#ifdef CONFIG_SH_SECUREEDGE5410
#include <mach/snapgear.h>
#define set_dp(x) SECUREEDGE_WRITE_IOPORT(x, 0x1c00)
#define get_dp() SECUREEDGE_READ_IOPORT()
#define ds1302_set_tx()
#define ds1302_set_rx()

static inline int ds1302_hw_init(void)
{
return 0;
}

static inline void ds1302_reset(void)
{
set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK));
}

static inline void ds1302_clock(void)
{
set_dp(get_dp() | RTC_SCLK); /* clock high */
set_dp(get_dp() & ~RTC_SCLK); /* clock low */
}

static inline void ds1302_start(void)
{
set_dp(get_dp() | RTC_RESET);
}

static inline void ds1302_stop(void)
{
set_dp(get_dp() & ~RTC_RESET);
}

static inline void ds1302_txbit(int bit)
{
set_dp((get_dp() & ~RTC_IODATA) | (bit ? RTC_IODATA : 0));
}

static inline int ds1302_rxbit(void)
{
return !!(get_dp() & RTC_IODATA);
}

#else
#error "Add support for your platform"
#endif
Expand All @@ -50,11 +90,11 @@ static void ds1302_sendbits(unsigned int val)
{
int i;

ds1302_set_tx();

for (i = 8; (i); i--, val >>= 1) {
set_dp((get_dp() & ~RTC_IODATA) | ((val & 0x1) ?
RTC_IODATA : 0));
set_dp(get_dp() | RTC_SCLK); /* clock high */
set_dp(get_dp() & ~RTC_SCLK); /* clock low */
ds1302_txbit(val & 0x1);
ds1302_clock();
}
}

Expand All @@ -63,10 +103,11 @@ static unsigned int ds1302_recvbits(void)
unsigned int val;
int i;

ds1302_set_rx();

for (i = 0, val = 0; (i < 8); i++) {
val |= (((get_dp() & RTC_IODATA) ? 1 : 0) << i);
set_dp(get_dp() | RTC_SCLK); /* clock high */
set_dp(get_dp() & ~RTC_SCLK); /* clock low */
val |= (ds1302_rxbit() << i);
ds1302_clock();
}

return val;
Expand All @@ -76,23 +117,24 @@ static unsigned int ds1302_readbyte(unsigned int addr)
{
unsigned int val;

set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK));
ds1302_reset();

set_dp(get_dp() | RTC_RESET);
ds1302_start();
ds1302_sendbits(((addr & 0x3f) << 1) | RTC_CMD_READ);
val = ds1302_recvbits();
set_dp(get_dp() & ~RTC_RESET);
ds1302_stop();

return val;
}

static void ds1302_writebyte(unsigned int addr, unsigned int val)
{
set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK));
set_dp(get_dp() | RTC_RESET);
ds1302_reset();

ds1302_start();
ds1302_sendbits(((addr & 0x3f) << 1) | RTC_CMD_WRITE);
ds1302_sendbits(val);
set_dp(get_dp() & ~RTC_RESET);
ds1302_stop();
}

static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm)
Expand Down Expand Up @@ -167,13 +209,20 @@ static int __init ds1302_rtc_probe(struct platform_device *pdev)
{
struct rtc_device *rtc;

if (ds1302_hw_init()) {
dev_err(&pdev->dev, "Failed to init communication channel");
return -EINVAL;
}

/* Reset */
set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK));
ds1302_reset();

/* Write a magic value to the DS1302 RAM, and see if it sticks. */
ds1302_writebyte(RTC_ADDR_RAM0, 0x42);
if (ds1302_readbyte(RTC_ADDR_RAM0) != 0x42)
if (ds1302_readbyte(RTC_ADDR_RAM0) != 0x42) {
dev_err(&pdev->dev, "Failed to probe");
return -ENODEV;
}

rtc = rtc_device_register("ds1302", &pdev->dev,
&ds1302_rtc_ops, THIS_MODULE);
Expand Down

0 comments on commit 21967eb

Please sign in to comment.