Add a note about Rockbox not running on Sansas v2 (FS#8477 by Marc Guay).
[Rockbox.git] / firmware / drivers / pcf50605.c
blobafa0a5ca11ce12c98f0ff789487535f83361dbb2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Driver for pcf50605 PMU and RTC
12 * Based on code from the ipodlinux project - http://ipodlinux.org/
13 * Adapted for Rockbox in December 2005
15 * Original file: linux/arch/armnommu/mach-ipod/pcf50605.c
17 * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org)
19 * All files in this archive are subject to the GNU General Public License.
20 * See the file COPYING in the source tree root for full license agreement.
22 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
23 * KIND, either express or implied.
25 ****************************************************************************/
26 #include "system.h"
27 #include "config.h"
28 #if CONFIG_I2C == I2C_PP5020 || CONFIG_I2C == I2C_PP5002
29 #include "i2c-pp.h"
30 #endif
31 #include "rtc.h"
33 #define OOCS 0x01
34 #define INT1 0x02
35 #define INT2 0x03
36 #define INT3 0x04
37 #define INT1M 0x05
38 #define INT2M 0x06
39 #define INT3M 0x07
40 #define OOCC1 0x08
41 #define GOSTDBY 0x1
42 #define TOTRST (0x1 << 1)
43 #define CLK32ON (0x1 << 2)
44 #define WDTRST (0x1 << 3)
45 #define RTCWAK (0x1 << 4)
46 #define CHGWAK (0x1 << 5)
47 #define EXTONWAK (0x01 << 6)
48 #define OOCC2 0x09
49 #define RTCSC 0x0a
50 #define RTCMN 0x0b
51 #define RTCHR 0x0c
52 #define RTCWD 0x0d
53 #define RTCDT 0x0e
54 #define RTCMT 0x0f
55 #define RTCYR 0x10
56 #define RTCSCA 0x11
57 #define RTCMNA 0x12
58 #define RTCHRA 0x13
59 #define RTCWDA 0x14
60 #define RTCDTA 0x15
61 #define RTCMTA 0x16
62 #define RTCYRA 0x17
63 #define PSSC 0x18
64 #define PWROKM 0x19
65 #define PWROKS 0x1a
66 #define DCDC1 0x1b
67 #define DCDC2 0x1c
68 #define DCDC3 0x1d
69 #define DCDC4 0x1e
70 #define DCDEC1 0x1f
71 #define DCDEC2 0x20
72 #define DCUDC1 0x21
73 #define DCUDC2 0x22
74 #define IOREGC 0x23
75 #define D1REGC1 0x24
76 #define D2REGC1 0x25
77 #define D3REGC1 0x26
78 #define LPREG1C 0x27
81 unsigned char pcf50605_wakeup_flags = 0;
83 int pcf50605_read(int address)
85 return i2c_readbyte(0x8,address);
88 int pcf50605_read_multiple(int address, unsigned char* buf, int count)
90 int read = i2c_readbytes(0x08, address, count, buf);
91 return read - count;
94 int pcf50605_write(int address, unsigned char val)
96 pp_i2c_send(0x8, address, val);
97 return 0;
100 int pcf50605_write_multiple(int address, const unsigned char* buf, int count)
102 int i;
104 i2c_lock();
106 for (i = 0; i < count; i++)
107 pp_i2c_send(0x8, address + i, buf[i]);
109 i2c_unlock();
111 return 0;
114 /* The following command puts the iPod into a deep sleep. Warning
115 from the good people of ipodlinux - never issue this command
116 without setting CHGWAK or EXTONWAK if you ever want to be able to
117 power on your iPod again. */
118 void pcf50605_standby_mode(void)
120 pcf50605_write(OOCC1, GOSTDBY | CHGWAK | EXTONWAK | pcf50605_wakeup_flags);
123 void pcf50605_init(void)
125 #if defined (IPOD_VIDEO)
126 /* I/O and GPO voltage supply (default: 0xf8 = 3.3V ON) */
127 /* ECO not allowed regarding data sheet */
128 pcf50605_write(IOREGC, 0xf8); /* 3.3V ON */
130 /* core voltage supply (default DCDC1/DCDC2: 0xec = 1.2V ON) */
131 /* ECO not stable, assumed due to less precision of voltage in ECO mode */
132 pcf50605_write(DCDC1, 0xec); /* 1.2V ON */
133 pcf50605_write(DCDC2, 0x0c); /* OFF */
135 /* unknown (default: 0xe3 = 1.8V ON) */
136 pcf50605_write(DCUDC1, 0xe3); /* 1.8V ON */
138 /* WM8758 voltage supply (default: 0xf5 = 3.0V ON) */
139 /* ECO not allowed as max. current of 5mA is not sufficient */
140 pcf50605_write(D1REGC1, 0xf0); /* 2.5V ON */
142 /* LCD voltage supply (default: 0xf5 = 3.0V ON) */
143 pcf50605_write(D3REGC1, 0xf1); /* 2.6V ON */
144 #else
145 /* keep initialization from svn for other iPods */
146 pcf50605_write(D1REGC1, 0xf5); /* 3.0V ON */
147 pcf50605_write(D3REGC1, 0xf5); /* 3.0V ON */
148 #endif
149 /* Dock Connector pin 17 (default: OFF) */
150 pcf50605_write(D2REGC1, 0xf8); /* 3.3V ON */