fix: the problem to which new filetypes cannot be registered.
[kugel-rb.git] / firmware / drivers / rtc / rtc_rx5x348ab.c
blobf31ab5623e91d5d117f76682ce595355d59a7ebf
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include "spi.h"
24 #include "rtc.h"
26 /* Choose one of: */
27 #define ADDR_READ 0x04
28 #define ADDR_WRITE 0x00
29 /* and one of: */
30 #define ADDR_ONE 0x08
31 #define ADDR_BURST 0x00
33 void rtc_init(void)
37 int rtc_read_datetime(struct tm *tm)
39 unsigned int i;
40 unsigned char buf[7];
41 char command = ADDR_READ|ADDR_BURST; /* burst read from the start of the time/date reg */
43 spi_block_transfer(SPI_target_RX5X348AB, &command, 1, buf, sizeof(buf));
45 for (i = 0; i < sizeof(buf); i++)
46 buf[i] = BCD2DEC(buf[i]);
48 tm->tm_sec = buf[0];
49 tm->tm_min = buf[1];
50 tm->tm_hour = buf[2];
51 tm->tm_wday = buf[3];
52 tm->tm_mday = buf[4];
53 tm->tm_mon = buf[5] - 1;
54 tm->tm_year = buf[6] + 100;
56 return 1;
59 int rtc_write_datetime(const struct tm *tm)
61 unsigned int i;
62 char command = ADDR_WRITE|ADDR_BURST; /* burst read from the start of the time/date reg */
63 unsigned char buf[8];
65 buf[0] = command;
66 buf[1] = tm->tm_sec;
67 buf[2] = tm->tm_min;
68 buf[3] = tm->tm_hour;
69 buf[4] = tm->tm_wday;
70 buf[5] = tm->tm_mday;
71 buf[6] = tm->tm_mon + 1;
72 buf[7] = tm->tm_year - 100;
74 /* don't encode the comand byte */
75 for (i = 1; i < sizeof(buf); i++)
76 buf[i] = DEC2BCD(buf[i]);
78 spi_block_transfer(SPI_target_RX5X348AB, buf, sizeof(buf), NULL, 0);
79 return 1;