blob: 64a4d527ea2546d9f7ebc781dc300dcb72b487e6 [file] [log] [blame]
Dave Chapmane066a202005-12-11 10:52:17 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
Dave Chapmanc3f9d002005-12-19 14:30:52 +000010 * Driver for pcf50605 PMU and RTC
Dave Chapmane066a202005-12-11 10:52:17 +000011 *
Dave Chapmanc3f9d002005-12-19 14:30:52 +000012 * Based on code from the ipodlinux project - http://ipodlinux.org/
13 * Adapted for Rockbox in December 2005
14 *
15 * Original file: linux/arch/armnommu/mach-ipod/pcf50605.c
16 *
17 * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org)
Dave Chapmane066a202005-12-11 10:52:17 +000018 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000019 * 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.
Dave Chapmane066a202005-12-11 10:52:17 +000023 *
24 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
25 * KIND, either express or implied.
26 *
27 ****************************************************************************/
Brandon Low19f4c2a2006-03-09 19:47:12 +000028#include "system.h"
Dave Chapmane066a202005-12-11 10:52:17 +000029#include "config.h"
Daniel Ankersdf8446a2007-01-27 20:39:09 +000030#if CONFIG_I2C == I2C_PP5020 || CONFIG_I2C == I2C_PP5002
31#include "i2c-pp.h"
Dave Chapman465596b2006-02-05 17:16:34 +000032#endif
Dave Chapmane066a202005-12-11 10:52:17 +000033#include "rtc.h"
Rob Purchase9b691d32008-04-04 20:24:08 +000034#include "pcf5060x.h"
Dave Chapmanf79d35a2006-05-02 08:08:10 +000035
Thom Johansen1ef5dad2007-09-28 15:09:54 +000036unsigned char pcf50605_wakeup_flags = 0;
Dave Chapman4ba9eac2005-12-21 23:32:19 +000037
Dave Chapmane066a202005-12-11 10:52:17 +000038int pcf50605_read(int address)
39{
40 return i2c_readbyte(0x8,address);
41}
42
43int pcf50605_read_multiple(int address, unsigned char* buf, int count)
44{
Brandon Low19f4c2a2006-03-09 19:47:12 +000045 int read = i2c_readbytes(0x08, address, count, buf);
46 return read - count;
Dave Chapmane066a202005-12-11 10:52:17 +000047}
48
49int pcf50605_write(int address, unsigned char val)
50{
Daniel Stenberg77c915a2006-10-27 11:24:23 +000051 pp_i2c_send(0x8, address, val);
Dave Chapmane066a202005-12-11 10:52:17 +000052 return 0;
53}
54
55int pcf50605_write_multiple(int address, const unsigned char* buf, int count)
56{
Thom Johansen8fd6d652007-02-28 21:55:11 +000057 int i;
Michael Sevakis9beb2102007-11-26 07:59:42 +000058
59 i2c_lock();
60
Thom Johansen8fd6d652007-02-28 21:55:11 +000061 for (i = 0; i < count; i++)
62 pp_i2c_send(0x8, address + i, buf[i]);
Michael Sevakis9beb2102007-11-26 07:59:42 +000063
64 i2c_unlock();
65
Dave Chapmane066a202005-12-11 10:52:17 +000066 return 0;
67}
68
Dave Chapman4ba9eac2005-12-21 23:32:19 +000069/* 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. */
73void pcf50605_standby_mode(void)
74{
Rob Purchase9b691d32008-04-04 20:24:08 +000075 pcf50605_write(PCF5060X_OOCC1,
76 GOSTDBY | CHGWAK | EXTONWAK | pcf50605_wakeup_flags);
Dave Chapman4ba9eac2005-12-21 23:32:19 +000077}
78
Dave Chapmanf79d35a2006-05-02 08:08:10 +000079void pcf50605_init(void)
80{
Andree Buschmann3d401442008-06-14 22:22:51 +000081#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 */
Michael Giacomelli054447f2008-02-10 05:39:20 +000086
Andree Buschmann3d401442008-06-14 22:22:51 +000087 /* 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 */
Andree Buschmann850a1122008-04-20 18:28:25 +000090 pcf50605_write(PCF5060X_DCDC1, 0xec); /* 1.2V ON */
91 pcf50605_write(PCF5060X_DCDC2, 0x0c); /* OFF */
Michael Giacomelli054447f2008-02-10 05:39:20 +000092
Andree Buschmann3d401442008-06-14 22:22:51 +000093 /* Unknown. Defaults:
94 * iPod Video = 0xe3 = 1.8V ON
95 * iPod nano = 0xe3 = 1.8V ON */
Andree Buschmann850a1122008-04-20 18:28:25 +000096 pcf50605_write(PCF5060X_DCUDC1, 0xe3); /* 1.8V ON */
Michael Giacomelli054447f2008-02-10 05:39:20 +000097
Andree Buschmann3d401442008-06-14 22:22:51 +000098 /* 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 */
Andree Buschmann850a1122008-04-20 18:28:25 +0000102 pcf50605_write(PCF5060X_D1REGC1, 0xf0); /* 2.5V ON */
Michael Giacomelli054447f2008-02-10 05:39:20 +0000103
Andree Buschmann3d401442008-06-14 22:22:51 +0000104 /* PCF5060X_D2REGC1 is set in accordance to the accessory power setting */
105
106 /* LCD voltage supply. Defaults:
107 * iPod Video = 0xf5 = 3.0V ON
108 * iPod nano = 0xf5 = 3.0V ON */
Andree Buschmann850a1122008-04-20 18:28:25 +0000109 pcf50605_write(PCF5060X_D3REGC1, 0xf1); /* 2.6V ON */
Andree Buschmann3d401442008-06-14 22:22:51 +0000110
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 */
Michael Giacomelli054447f2008-02-10 05:39:20 +0000115#else
116 /* keep initialization from svn for other iPods */
Rob Purchase9b691d32008-04-04 20:24:08 +0000117 pcf50605_write(PCF5060X_D1REGC1, 0xf5); /* 3.0V ON */
118 pcf50605_write(PCF5060X_D3REGC1, 0xf5); /* 3.0V ON */
Andree Buschmanndf243a12008-04-14 17:06:32 +0000119#endif
Dave Chapmanf79d35a2006-05-02 08:08:10 +0000120}