1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum
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 ****************************************************************************/
32 int rtc_read_datetime(struct tm
*tm
)
38 oldlevel
= disable_irq_save();
40 rc
= pcf50606_read_multiple(0x0a, buf
, sizeof(buf
));
42 restore_irq(oldlevel
);
44 for (i
= 0; i
< sizeof(buf
); i
++)
45 buf
[i
] = BCD2DEC(buf
[i
]);
52 tm
->tm_mon
= buf
[5] - 1;
53 #ifdef IRIVER_H300_SERIES
54 /* Special kludge to coexist with the iriver firmware. The iriver firmware
55 stores the date as 1965+nn, and allows a range of 1980..2064. We use
56 1964+nn here to make leap years work correctly, so the date will be one
57 year off in the iriver firmware but at least won't be reset anymore. */
58 tm
->tm_year
= buf
[6] + 64;
59 #else /* Not IRIVER_H300_SERIES */
60 tm
->tm_year
= buf
[6] + 100;
61 #endif /* IRIVER_H300_SERIES */
66 int rtc_write_datetime(const struct tm
*tm
)
77 buf
[5] = tm
->tm_mon
+ 1;
78 #ifdef IRIVER_H300_SERIES
79 /* Iriver firmware compatibility kludge, see rtc_read_datetime(). */
80 buf
[6] = tm
->tm_year
- 64;
81 #else /* Not IRIVER_H300_SERIES */
82 buf
[6] = tm
->tm_year
- 100;
83 #endif /* IRIVER_H300_SERIES */
85 for (i
= 0; i
< sizeof(buf
); i
++)
86 buf
[i
] = DEC2BCD(buf
[i
]);
88 oldlevel
= disable_irq_save();
90 rc
= pcf50606_write_multiple(0x0a, buf
, sizeof(buf
));
92 restore_irq(oldlevel
);