1 From 80b4a26a51a75a92ddbb64b342068b741ef88416 Mon Sep 17 00:00:00 2001
2 From: Andy Green <andy@openmoko.com>
3 Date: Wed, 2 Jul 2008 22:42:39 +0100
4 Subject: [PATCH] fix-pcf50633-migrate-gta02-peripherals-out.patch
6 pcf50633.c shouldn't know GTAxx at all. Move to using a
7 platform callback to allow definition of platform devices
8 with pcf50633 as parent device (good for enforcing suspend /
9 resume ordering). Remove all code references to GTAxx from
10 the sources (one string left for compatability).
12 Signed-off-by: Andy Green <andy@openmoko.com>
14 arch/arm/mach-s3c2440/mach-gta02.c | 30 +++++++++++++++++++-
15 drivers/i2c/chips/pcf50633.c | 54 ++++++++++++++++++-----------------
16 include/linux/pcf50633.h | 9 +++++-
17 3 files changed, 65 insertions(+), 28 deletions(-)
19 diff --git a/arch/arm/mach-s3c2440/mach-gta02.c b/arch/arm/mach-s3c2440/mach-gta02.c
20 index 309e484..fd746fd 100644
21 --- a/arch/arm/mach-s3c2440/mach-gta02.c
22 +++ b/arch/arm/mach-s3c2440/mach-gta02.c
23 @@ -464,6 +464,29 @@ static int pmu_callback(struct device *dev, unsigned int feature,
27 +static struct platform_device gta01_pm_gps_dev = {
28 + .name = "neo1973-pm-gps",
31 +static struct platform_device gta01_pm_bt_dev = {
32 + .name = "neo1973-pm-bt",
35 +/* this is called when pc50633 is probed, unfortunately quite late in the
36 + * day since it is an I2C bus device. Here we can belatedly define some
37 + * platform devices with the advantage that we can mark the pcf50633 as the
38 + * parent. This makes them get suspended and resumed with their parent
39 + * the pcf50633 still around.
42 +static void gta02_pcf50633_attach_child_devices(struct device *parent_device)
44 + gta01_pm_gps_dev.dev.parent = parent_device;
45 + gta01_pm_bt_dev.dev.parent = parent_device;
46 + platform_device_register(>a01_pm_bt_dev);
47 + platform_device_register(>a01_pm_gps_dev);
50 static struct pcf50633_platform_data gta02_pcf_pdata = {
51 .used_features = PCF50633_FEAT_MBC |
53 @@ -478,6 +501,7 @@ static struct pcf50633_platform_data gta02_pcf_pdata = {
55 .r_fix_batt_par = 10000,
57 + .flag_use_apm_emulation = 0,
59 [0] = PCF50633_INT1_USBINS |
60 PCF50633_INT1_USBREM |
61 @@ -577,7 +601,9 @@ static struct pcf50633_platform_data gta02_pcf_pdata = {
64 .defer_resume_backlight = 1,
65 - .resume_backlight_ramp_speed = 5
66 + .resume_backlight_ramp_speed = 5,
67 + .attach_child_devices = gta02_pcf50633_attach_child_devices
71 #if 0 /* currently unused */
72 @@ -772,6 +798,7 @@ struct platform_device s3c24xx_pwm_device = {
77 static struct platform_device *gta02_devices[] __initdata = {
80 @@ -786,6 +813,7 @@ static struct platform_device *gta02_devices[] __initdata = {
81 >a02_version_device,
82 >a02_resume_reason_device,
87 static struct s3c2410_nand_set gta02_nand_sets[] = {
88 diff --git a/drivers/i2c/chips/pcf50633.c b/drivers/i2c/chips/pcf50633.c
89 index a697ee1..0f40f3f 100644
90 --- a/drivers/i2c/chips/pcf50633.c
91 +++ b/drivers/i2c/chips/pcf50633.c
93 #include <linux/jiffies.h>
95 #include <asm/mach-types.h>
96 -#include <asm/arch/gta02.h>
99 #include <linux/resume-dependency.h>
100 @@ -2011,18 +2010,6 @@ static DEVICE_ATTR(dump_regs, 0400, show_dump_regs, NULL);
101 * Driver initialization
102 ***********************************************************************/
104 -#ifdef CONFIG_MACH_NEO1973_GTA02
105 -/* We currently place those platform devices here to make sure the device
106 - * suspend/resume order is correct */
107 -static struct platform_device gta01_pm_gps_dev = {
108 - .name = "neo1973-pm-gps",
111 -static struct platform_device gta01_pm_bt_dev = {
112 - .name = "neo1973-pm-bt",
117 * CARE! This table is modified at runtime!
119 @@ -2217,14 +2204,16 @@ static int pcf50633_detect(struct i2c_adapter *adapter, int address, int kind)
121 data->probe_completed = 1;
123 - if (machine_is_neo1973_gta02()) {
124 - gta01_pm_gps_dev.dev.parent = &new_client->dev;
125 - gta01_pm_bt_dev.dev.parent = &new_client->dev;
126 - platform_device_register(>a01_pm_bt_dev);
127 - platform_device_register(>a01_pm_gps_dev);
129 + if (data->pdata->flag_use_apm_emulation)
130 apm_get_power_status = pcf50633_get_power_status;
132 + /* if platform was interested, give him a chance to register
133 + * platform devices that switch power with us as the parent
134 + * at registration time -- ensures suspend / resume ordering
136 + if (data->pdata->attach_child_devices)
137 + (data->pdata->attach_child_devices)(&new_client->dev);
141 if (data->pdata->used_features & PCF50633_FEAT_RTC)
142 @@ -2268,13 +2257,6 @@ static int pcf50633_detach_client(struct i2c_client *client)
143 if (pcf->pdata->used_features & PCF50633_FEAT_RTC)
144 rtc_device_unregister(pcf->rtc);
146 -#ifdef CONFIG_MACH_NEO1973_GTA02
147 - if (machine_is_neo1973_gta02()) {
148 - platform_device_unregister(>a01_pm_bt_dev);
149 - platform_device_unregister(>a01_pm_gps_dev);
153 sysfs_remove_group(&client->dev.kobj, &pcf_attr_group);
156 @@ -2472,6 +2454,26 @@ int pcf50633_ready(struct pcf50633_data *pcf)
158 EXPORT_SYMBOL_GPL(pcf50633_ready);
160 +int pcf50633_wait_for_ready(struct pcf50633_data *pcf, int timeout_ms,
163 + /* so we always go once */
166 + while ((timeout_ms >= 5) && (pcf50633_ready(pcf))) {
167 + timeout_ms -= 5; /* well, it isn't very accurate, but OK */
171 + if (timeout_ms < 5) {
172 + printk(KERN_ERR"pcf50633_wait_for_ready: "
173 + "%s BAILING on timeout\n", name);
179 +EXPORT_SYMBOL_GPL(pcf50633_wait_for_ready);
182 * if backlight resume is selected to be deferred by platform, then it
183 diff --git a/include/linux/pcf50633.h b/include/linux/pcf50633.h
184 index b94b72a..4653285 100644
185 --- a/include/linux/pcf50633.h
186 +++ b/include/linux/pcf50633.h
187 @@ -132,7 +132,9 @@ pcf50633_register_resume_dependency(struct pcf50633_data *pcf,
189 pcf50633_notify_usb_current_limit_change(struct pcf50633_data *pcf,
193 +pcf50633_wait_for_ready(struct pcf50633_data *pcf, int timeout_ms,
196 /* 0 = initialized and resumed and ready to roll, !=0 = either not
197 * initialized or not resumed yet
198 @@ -155,6 +157,10 @@ struct pcf50633_platform_data {
199 unsigned int onkey_seconds_sig_init;
200 unsigned int onkey_seconds_shutdown;
202 + /* callback to attach platform children (to enforce suspend / resume
204 + void (*attach_child_devices)(struct device *parent_device);
206 /* voltage regulator related */
207 struct pmu_voltage_rail rails[__NUM_PCF50633_REGULATORS];
208 unsigned int used_regulators;
209 @@ -163,6 +169,7 @@ struct pcf50633_platform_data {
210 unsigned int r_fix_batt;
211 unsigned int r_fix_batt_par;
212 unsigned int r_sense_milli;
213 + int flag_use_apm_emulation;
215 unsigned char resumers[5];