Dave Chapman | e066a20 | 2005-12-11 10:52:17 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
Dave Chapman | c3f9d00 | 2005-12-19 14:30:52 +0000 | [diff] [blame] | 10 | * Driver for pcf50605 PMU and RTC |
Dave Chapman | e066a20 | 2005-12-11 10:52:17 +0000 | [diff] [blame] | 11 | * |
Dave Chapman | c3f9d00 | 2005-12-19 14:30:52 +0000 | [diff] [blame] | 12 | * 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 Chapman | e066a20 | 2005-12-11 10:52:17 +0000 | [diff] [blame] | 18 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Dave Chapman | e066a20 | 2005-12-11 10:52:17 +0000 | [diff] [blame] | 23 | * |
| 24 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 25 | * KIND, either express or implied. |
| 26 | * |
| 27 | ****************************************************************************/ |
Brandon Low | 19f4c2a | 2006-03-09 19:47:12 +0000 | [diff] [blame] | 28 | #include "system.h" |
Dave Chapman | e066a20 | 2005-12-11 10:52:17 +0000 | [diff] [blame] | 29 | #include "config.h" |
Daniel Ankers | df8446a | 2007-01-27 20:39:09 +0000 | [diff] [blame] | 30 | #if CONFIG_I2C == I2C_PP5020 || CONFIG_I2C == I2C_PP5002 |
| 31 | #include "i2c-pp.h" |
Dave Chapman | 465596b | 2006-02-05 17:16:34 +0000 | [diff] [blame] | 32 | #endif |
Dave Chapman | e066a20 | 2005-12-11 10:52:17 +0000 | [diff] [blame] | 33 | #include "rtc.h" |
Rob Purchase | 9b691d3 | 2008-04-04 20:24:08 +0000 | [diff] [blame] | 34 | #include "pcf5060x.h" |
Dave Chapman | f79d35a | 2006-05-02 08:08:10 +0000 | [diff] [blame] | 35 | |
Thom Johansen | 1ef5dad | 2007-09-28 15:09:54 +0000 | [diff] [blame] | 36 | unsigned char pcf50605_wakeup_flags = 0; |
Dave Chapman | 4ba9eac | 2005-12-21 23:32:19 +0000 | [diff] [blame] | 37 | |
Dave Chapman | e066a20 | 2005-12-11 10:52:17 +0000 | [diff] [blame] | 38 | int pcf50605_read(int address) |
| 39 | { |
| 40 | return i2c_readbyte(0x8,address); |
| 41 | } |
| 42 | |
| 43 | int pcf50605_read_multiple(int address, unsigned char* buf, int count) |
| 44 | { |
Brandon Low | 19f4c2a | 2006-03-09 19:47:12 +0000 | [diff] [blame] | 45 | int read = i2c_readbytes(0x08, address, count, buf); |
| 46 | return read - count; |
Dave Chapman | e066a20 | 2005-12-11 10:52:17 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | int pcf50605_write(int address, unsigned char val) |
| 50 | { |
Daniel Stenberg | 77c915a | 2006-10-27 11:24:23 +0000 | [diff] [blame] | 51 | pp_i2c_send(0x8, address, val); |
Dave Chapman | e066a20 | 2005-12-11 10:52:17 +0000 | [diff] [blame] | 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | int pcf50605_write_multiple(int address, const unsigned char* buf, int count) |
| 56 | { |
Thom Johansen | 8fd6d65 | 2007-02-28 21:55:11 +0000 | [diff] [blame] | 57 | int i; |
Michael Sevakis | 9beb210 | 2007-11-26 07:59:42 +0000 | [diff] [blame] | 58 | |
| 59 | i2c_lock(); |
| 60 | |
Thom Johansen | 8fd6d65 | 2007-02-28 21:55:11 +0000 | [diff] [blame] | 61 | for (i = 0; i < count; i++) |
| 62 | pp_i2c_send(0x8, address + i, buf[i]); |
Michael Sevakis | 9beb210 | 2007-11-26 07:59:42 +0000 | [diff] [blame] | 63 | |
| 64 | i2c_unlock(); |
| 65 | |
Dave Chapman | e066a20 | 2005-12-11 10:52:17 +0000 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
Dave Chapman | 4ba9eac | 2005-12-21 23:32:19 +0000 | [diff] [blame] | 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) |
| 74 | { |
Rob Purchase | 9b691d3 | 2008-04-04 20:24:08 +0000 | [diff] [blame] | 75 | pcf50605_write(PCF5060X_OOCC1, |
| 76 | GOSTDBY | CHGWAK | EXTONWAK | pcf50605_wakeup_flags); |
Dave Chapman | 4ba9eac | 2005-12-21 23:32:19 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Dave Chapman | f79d35a | 2006-05-02 08:08:10 +0000 | [diff] [blame] | 79 | void pcf50605_init(void) |
| 80 | { |
Andree Buschmann | 3d40144 | 2008-06-14 22:22:51 +0000 | [diff] [blame] | 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 */ |
Michael Giacomelli | 054447f | 2008-02-10 05:39:20 +0000 | [diff] [blame] | 86 | |
Andree Buschmann | 3d40144 | 2008-06-14 22:22:51 +0000 | [diff] [blame] | 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 */ |
Andree Buschmann | 850a112 | 2008-04-20 18:28:25 +0000 | [diff] [blame] | 90 | pcf50605_write(PCF5060X_DCDC1, 0xec); /* 1.2V ON */ |
| 91 | pcf50605_write(PCF5060X_DCDC2, 0x0c); /* OFF */ |
Michael Giacomelli | 054447f | 2008-02-10 05:39:20 +0000 | [diff] [blame] | 92 | |
Andree Buschmann | 3d40144 | 2008-06-14 22:22:51 +0000 | [diff] [blame] | 93 | /* Unknown. Defaults: |
| 94 | * iPod Video = 0xe3 = 1.8V ON |
| 95 | * iPod nano = 0xe3 = 1.8V ON */ |
Andree Buschmann | 850a112 | 2008-04-20 18:28:25 +0000 | [diff] [blame] | 96 | pcf50605_write(PCF5060X_DCUDC1, 0xe3); /* 1.8V ON */ |
Michael Giacomelli | 054447f | 2008-02-10 05:39:20 +0000 | [diff] [blame] | 97 | |
Andree Buschmann | 3d40144 | 2008-06-14 22:22:51 +0000 | [diff] [blame] | 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 */ |
Andree Buschmann | 850a112 | 2008-04-20 18:28:25 +0000 | [diff] [blame] | 102 | pcf50605_write(PCF5060X_D1REGC1, 0xf0); /* 2.5V ON */ |
Michael Giacomelli | 054447f | 2008-02-10 05:39:20 +0000 | [diff] [blame] | 103 | |
Andree Buschmann | 3d40144 | 2008-06-14 22:22:51 +0000 | [diff] [blame] | 104 | /* 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 Buschmann | 850a112 | 2008-04-20 18:28:25 +0000 | [diff] [blame] | 109 | pcf50605_write(PCF5060X_D3REGC1, 0xf1); /* 2.6V ON */ |
Andree Buschmann | 3d40144 | 2008-06-14 22:22:51 +0000 | [diff] [blame] | 110 | |
| 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 Giacomelli | 054447f | 2008-02-10 05:39:20 +0000 | [diff] [blame] | 115 | #else |
| 116 | /* keep initialization from svn for other iPods */ |
Rob Purchase | 9b691d3 | 2008-04-04 20:24:08 +0000 | [diff] [blame] | 117 | pcf50605_write(PCF5060X_D1REGC1, 0xf5); /* 3.0V ON */ |
| 118 | pcf50605_write(PCF5060X_D3REGC1, 0xf5); /* 3.0V ON */ |
Andree Buschmann | df243a1 | 2008-04-14 17:06:32 +0000 | [diff] [blame] | 119 | #endif |
Dave Chapman | f79d35a | 2006-05-02 08:08:10 +0000 | [diff] [blame] | 120 | } |