Adding new setting to System Settings <Accessory Power Supply -- off by default). This setting can be used to enable/disable the power supply for accessories. With this commit implemented for iPods with PCF50605 power controller.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17193 a1c6a512-1295-4272-9138-f99709370657
diff --git a/apps/lang/deutsch.lang b/apps/lang/deutsch.lang
index c50268c..b77f13c 100644
--- a/apps/lang/deutsch.lang
+++ b/apps/lang/deutsch.lang
@@ -11533,3 +11533,17 @@
     swcodec: "Tastentöne Wiederholung"
   </voice>
 </phrase>
+<phrase>
+  id: LANG_ACCESSORY_SUPPLY
+  desc: in keyclick settings menu
+  user:
+  <source>
+    *: "Zubehör Spannungsversorgung"
+  </source>
+  <dest>
+    *: "Zubehör Spannungsversorgung"
+  </dest>
+  <voice>
+    *: "Zubehör Spannungsversorgung"
+  </voice>
+</phrase>
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index e3b632f..6a79371 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -11576,3 +11576,17 @@
     swcodec: "Keyclick Repeats"
   </voice>
 </phrase>
+<phrase>
+  id: LANG_ACCESSORY_SUPPLY
+  desc: in keyclick settings menu
+  user:
+  <source>
+    *: "Accessory Power Supply"
+  </source>
+  <dest>
+    *: "Accessory Power Supply"
+  </dest>
+  <voice>
+    *: "Accessory Power Supply"
+  </voice>
+</phrase>
diff --git a/apps/main.c b/apps/main.c
index 8b1e2e4..e84a672 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -583,6 +583,9 @@
 #if CONFIG_CHARGING
     car_adapter_mode_init();
 #endif
+#ifdef HAVE_ACCESSORY_SUPPLY
+    accessory_supply_set(global_settings.accessory_supply);
+#endif
 }
 
 #ifdef CPU_PP
diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c
index 9d816c9..635651e 100644
--- a/apps/menus/settings_menu.c
+++ b/apps/menus/settings_menu.c
@@ -34,19 +34,19 @@
 #include "splash.h"
 #include "talk.h"
 #include "sprintf.h"
-#include "powermgmt.h"

-#if CONFIG_CODEC == SWCODEC

-#include "playback.h"

-#endif

+#include "powermgmt.h"
+#if CONFIG_CODEC == SWCODEC
+#include "playback.h"
+#endif
 #ifdef HAVE_RTC_ALARM
 #include "alarm_menu.h"
 #endif
 #if CONFIG_TUNER
 #include "radio.h"
 #endif
-#if CONFIG_RTC

-#include "screens.h"

-#endif

+#if CONFIG_RTC
+#include "screens.h"
+#endif
 
 /***********************************/
 /*    TAGCACHE MENU                */
@@ -348,6 +348,9 @@
 #if CONFIG_CHARGING
 MENUITEM_SETTING(car_adapter_mode, &global_settings.car_adapter_mode, NULL);
 #endif
+#ifdef HAVE_ACCESSORY_SUPPLY
+MENUITEM_SETTING(accessory_supply, &global_settings.accessory_supply, NULL);
+#endif
 MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
 
 #ifdef HAVE_BUTTON_LIGHT
@@ -385,6 +388,9 @@
 #if CONFIG_CHARGING
             &car_adapter_mode,
 #endif
+#ifdef HAVE_ACCESSORY_SUPPLY
+            &accessory_supply,
+#endif
 #ifdef HAVE_BUTTON_LIGHT
             &buttonlight_timeout,
 #endif
diff --git a/apps/settings.h b/apps/settings.h
index 25314d7..7c32ba2 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -453,6 +453,9 @@
     bool peak_meter_clipcounter;    /* clipping count indicator */
 #endif
     bool car_adapter_mode; /* 0=off 1=on */
+#ifdef HAVE_ACCESSORY_SUPPLY
+    bool accessory_supply; /* 0=off 1=on, accessory power supply for iPod */
+#endif
 
     /* show status bar */
     bool statusbar;    /* 0=hide, 1=show */
diff --git a/apps/settings_list.c b/apps/settings_list.c
index e72b259..d8b2154 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -512,6 +512,10 @@
     OFFON_SETTING(NVRAM(1), car_adapter_mode,
         LANG_CAR_ADAPTER_MODE, false, "car adapter mode", NULL),
 #endif
+#ifdef HAVE_ACCESSORY_SUPPLY
+    OFFON_SETTING(0, accessory_supply, LANG_ACCESSORY_SUPPLY, 
+        false, "accessory power supply", accessory_supply_set),
+#endif
     /* tuner */
 #if CONFIG_TUNER
     OFFON_SETTING(0,fm_force_mono, LANG_FM_MONO_MODE,
diff --git a/firmware/drivers/pcf50605.c b/firmware/drivers/pcf50605.c
index 7d88e46..9fb04dd 100644
--- a/firmware/drivers/pcf50605.c
+++ b/firmware/drivers/pcf50605.c
@@ -79,27 +79,25 @@
 #if defined (IPOD_VIDEO)    
     /* I/O and GPO voltage supply (default: 0xf8 = 3.3V ON) */
     /* ECO not allowed regarding data sheet */
-    pcf50605_write(PCF5060X_IOREGC,  0xf8);  /* 3.3V ON */
+    pcf50605_write(PCF5060X_IOREGC,  0xf8); /* 3.3V ON */
     
     /* core voltage supply (default DCDC1/DCDC2: 0xec = 1.2V ON) */
     /* ECO not stable, assumed due to less precision of voltage in ECO mode */
-    pcf50605_write(PCF5060X_DCDC1,   0xec);  /* 1.2V ON */
-    pcf50605_write(PCF5060X_DCDC2,   0x0c);  /* OFF */
+    pcf50605_write(PCF5060X_DCDC1,   0xec); /* 1.2V ON */
+    pcf50605_write(PCF5060X_DCDC2,   0x0c); /* OFF */
     
     /* unknown (default: 0xe3 = 1.8V ON) */
-    pcf50605_write(PCF5060X_DCUDC1,  0xe3);  /* 1.8V ON */
+    pcf50605_write(PCF5060X_DCUDC1,  0xe3); /* 1.8V ON */
     
     /* WM8758 voltage supply (default: 0xf5 = 3.0V ON) */
     /* ECO not allowed as max. current of 5mA is not sufficient */
-    pcf50605_write(PCF5060X_D1REGC1, 0xf0);  /* 2.5V ON */
+    pcf50605_write(PCF5060X_D1REGC1, 0xf0); /* 2.5V ON */
     
     /* LCD voltage supply (default: 0xf5 = 3.0V ON) */
-    pcf50605_write(PCF5060X_D3REGC1, 0xf1);  /* 2.6V ON */
+    pcf50605_write(PCF5060X_D3REGC1, 0xf1); /* 2.6V ON */
 #else
     /* keep initialization from svn for other iPods */
     pcf50605_write(PCF5060X_D1REGC1, 0xf5); /* 3.0V ON */
     pcf50605_write(PCF5060X_D3REGC1, 0xf5); /* 3.0V ON */
 #endif
-    /* Dock Connector pin 17 (default: OFF) */
-    pcf50605_write(PCF5060X_D2REGC1, 0xf8); /* 3.3V ON */
 }
diff --git a/firmware/export/config-ipod3g.h b/firmware/export/config-ipod3g.h
index 4644a82..d5f403c 100644
--- a/firmware/export/config-ipod3g.h
+++ b/firmware/export/config-ipod3g.h
@@ -63,6 +63,9 @@
 /* Define if the device can wake from an RTC alarm */
 #define HAVE_RTC_ALARM
 
+/* Define this if you can switch on/off the accessory power supply */
+#define HAVE_ACCESSORY_SUPPLY
+
 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
 
diff --git a/firmware/export/config-ipod4g.h b/firmware/export/config-ipod4g.h
index 133b682..ad03f41 100644
--- a/firmware/export/config-ipod4g.h
+++ b/firmware/export/config-ipod4g.h
@@ -71,6 +71,9 @@
 /* Define if the device can wake from an RTC alarm */
 #define HAVE_RTC_ALARM
 
+/* Define this if you can switch on/off the accessory power supply */
+#define HAVE_ACCESSORY_SUPPLY
+
 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
 
diff --git a/firmware/export/config-ipodcolor.h b/firmware/export/config-ipodcolor.h
index 5823af1..9a7c055 100644
--- a/firmware/export/config-ipodcolor.h
+++ b/firmware/export/config-ipodcolor.h
@@ -58,6 +58,9 @@
 /* Define if the device can wake from an RTC alarm */
 #define HAVE_RTC_ALARM
 
+/* Define this if you can switch on/off the accessory power supply */
+#define HAVE_ACCESSORY_SUPPLY
+
 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
 
diff --git a/firmware/export/config-ipodmini.h b/firmware/export/config-ipodmini.h
index 34632fa..6e5fe26 100644
--- a/firmware/export/config-ipodmini.h
+++ b/firmware/export/config-ipodmini.h
@@ -62,6 +62,9 @@
 /* Define if the device can wake from an RTC alarm */
 #define HAVE_RTC_ALARM
 
+/* Define this if you can switch on/off the accessory power supply */
+#define HAVE_ACCESSORY_SUPPLY
+
 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
 
diff --git a/firmware/export/config-ipodmini2g.h b/firmware/export/config-ipodmini2g.h
index 124d0db..c861f5a 100644
--- a/firmware/export/config-ipodmini2g.h
+++ b/firmware/export/config-ipodmini2g.h
@@ -62,6 +62,9 @@
 /* Define if the device can wake from an RTC alarm */
 #define HAVE_RTC_ALARM
 
+/* Define this if you can switch on/off the accessory power supply */
+#define HAVE_ACCESSORY_SUPPLY
+
 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
 
diff --git a/firmware/export/config-ipodnano.h b/firmware/export/config-ipodnano.h
index 6a47247..ced2c47 100644
--- a/firmware/export/config-ipodnano.h
+++ b/firmware/export/config-ipodnano.h
@@ -58,6 +58,9 @@
 /* Define if the device can wake from an RTC alarm */
 #define HAVE_RTC_ALARM
 
+/* Define this if you can switch on/off the accessory power supply */
+#define HAVE_ACCESSORY_SUPPLY
+
 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
 
diff --git a/firmware/export/config-ipodvideo.h b/firmware/export/config-ipodvideo.h
index 364ae65..d15494c 100644
--- a/firmware/export/config-ipodvideo.h
+++ b/firmware/export/config-ipodvideo.h
@@ -58,6 +58,9 @@
 /* Define if the device can wake from an RTC alarm */
 #define HAVE_RTC_ALARM
 
+/* Define this if you can switch on/off the accessory power supply */
+#define HAVE_ACCESSORY_SUPPLY
+
 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
 
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h
index 56e14b3..4b8d239 100644
--- a/firmware/export/powermgmt.h
+++ b/firmware/export/powermgmt.h
@@ -182,5 +182,7 @@
 void cancel_shutdown(void);
 void shutdown_hw(void);
 void sys_poweroff(void);
-
+#ifdef HAVE_ACCESSORY_SUPPLY
+void accessory_supply_set(bool);
+#endif
 #endif
diff --git a/firmware/target/arm/ipod/powermgmt-ipod-pcf.c b/firmware/target/arm/ipod/powermgmt-ipod-pcf.c
index aaf4fab..2f97c29 100644
--- a/firmware/target/arm/ipod/powermgmt-ipod-pcf.c
+++ b/firmware/target/arm/ipod/powermgmt-ipod-pcf.c
@@ -21,6 +21,8 @@
 #include "config.h"
 #include "adc.h"
 #include "powermgmt.h"
+#include "pcf5060x.h"
+#include "pcf50605.h"
 
 const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
 {
@@ -88,3 +90,20 @@
 {
     return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
 }
+
+#ifdef HAVE_ACCESSORY_SUPPLY
+void accessory_supply_set(bool enable)
+{
+    if (enable)
+    {
+        /* Accessory voltage supply */
+        pcf50605_write(PCF5060X_D2REGC1, 0xf8); /* 3.3V ON */
+    }
+    else
+    {
+        /* Accessory voltage supply */
+        pcf50605_write(PCF5060X_D2REGC1, 0x18); /* OFF */
+    }
+    
+}
+#endif