Colour targets: Revert an optimisation from almost 18 months ago that actually turned...
[Rockbox.git] / firmware / drivers / pcf50605.c
blob64a4d527ea2546d9f7ebc781dc300dcb72b487e6
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 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version 2
22 * of the License, or (at your option) any later version.
24 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
25 * KIND, either express or implied.
27 ****************************************************************************/
28 #include "system.h"
29 #include "config.h"
30 #if CONFIG_I2C == I2C_PP5020 || CONFIG_I2C == I2C_PP5002
31 #include "i2c-pp.h"
32 #endif
33 #include "rtc.h"
34 #include "pcf5060x.h"
36 unsigned char pcf50605_wakeup_flags = 0;
38 int pcf50605_read(int address)
40 return i2c_readbyte(0x8,address);
43 int pcf50605_read_multiple(int address, unsigned char* buf, int count)
45 int read = i2c_readbytes(0x08, address, count, buf);
46 return read - count;
49 int pcf50605_write(int address, unsigned char val)
51 pp_i2c_send(0x8, address, val);
52 return 0;
55 int pcf50605_write_multiple(int address, const unsigned char* buf, int count)
57 int i;
59 i2c_lock();
61 for (i = 0; i < count; i++)
62 pp_i2c_send(0x8, address + i, buf[i]);
64 i2c_unlock();
66 return 0;
69 /* The following command puts the iPod into a deep sleep. Warning
70 from the good people of ipodlinux - never issue this command
71 without setting CHGWAK or EXTONWAK if you ever want to be able to
72 power on your iPod again. */
73 void pcf50605_standby_mode(void)
75 pcf50605_write(PCF5060X_OOCC1,
76 GOSTDBY | CHGWAK | EXTONWAK | pcf50605_wakeup_flags);
79 void pcf50605_init(void)
81 #if (defined (IPOD_VIDEO) || defined (IPOD_NANO))
82 /* I/O and GPO voltage supply. ECO not allowed regarding data sheet. Defaults:
83 * iPod Video = 0xf8 = 3.3V ON
84 * iPod nano = 0xf5 = 3.0V ON */
85 pcf50605_write(PCF5060X_IOREGC, 0xf5); /* 3.0V ON */
87 /* Core voltage supply. ECO not stable, assumed due to less precision of
88 * voltage in ECO mode. DCDC2 is not relevant as this may be used for
89 * voltage scaling. Default is 1.2V ON for PP5022/PP5024 */
90 pcf50605_write(PCF5060X_DCDC1, 0xec); /* 1.2V ON */
91 pcf50605_write(PCF5060X_DCDC2, 0x0c); /* OFF */
93 /* Unknown. Defaults:
94 * iPod Video = 0xe3 = 1.8V ON
95 * iPod nano = 0xe3 = 1.8V ON */
96 pcf50605_write(PCF5060X_DCUDC1, 0xe3); /* 1.8V ON */
98 /* Codec voltage supply. ECO not allowed as max. current of 5mA is not
99 * sufficient. Defaults:
100 * iPod Video = 0xf5 = 3.0V ON
101 * iPod nano = 0xef = 2.4V ON */
102 pcf50605_write(PCF5060X_D1REGC1, 0xf0); /* 2.5V ON */
104 /* PCF5060X_D2REGC1 is set in accordance to the accessory power setting */
106 /* LCD voltage supply. Defaults:
107 * iPod Video = 0xf5 = 3.0V ON
108 * iPod nano = 0xf5 = 3.0V ON */
109 pcf50605_write(PCF5060X_D3REGC1, 0xf1); /* 2.6V ON */
111 /* PCF5060X_LPREGC1 is leaved untouched as the setting varies over the
112 * different iPod platforms. Defaults:
113 * iPod Video = 0x1f = 0ff
114 * iPod nano = 0xf6 = 3.1V ON */
115 #else
116 /* keep initialization from svn for other iPods */
117 pcf50605_write(PCF5060X_D1REGC1, 0xf5); /* 3.0V ON */
118 pcf50605_write(PCF5060X_D3REGC1, 0xf5); /* 3.0V ON */
119 #endif