add support for target 3c24xx (more known as Openmoko GTA02 "Freerunner") and merge...
[openwrt/svn-archive/archive.git] / target / linux / s3c24xx / patches / 0182-fix-pcf50633-migrate-gta02-peripherals-out.patch.patch
1 From d74710dd508eb1b60b410048a151e1d541d749d2 Mon Sep 17 00:00:00 2001
2 From: Andy Green <andy@openmoko.com>
3 Date: Fri, 25 Jul 2008 23:06:15 +0100
4 Subject: [PATCH] fix-pcf50633-migrate-gta02-peripherals-out.patch
5
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).
11
12 Signed-off-by: Andy Green <andy@openmoko.com>
13 ---
14 arch/arm/mach-s3c2440/mach-gta02.c | 30 ++++++++++++++++++-
15 drivers/i2c/chips/pcf50633.c | 57 ++++++++++++++++++-----------------
16 include/linux/pcf50633.h | 9 +++++-
17 3 files changed, 66 insertions(+), 30 deletions(-)
18
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,
24 return 0;
25 }
26
27 +static struct platform_device gta01_pm_gps_dev = {
28 + .name = "neo1973-pm-gps",
29 +};
30 +
31 +static struct platform_device gta01_pm_bt_dev = {
32 + .name = "neo1973-pm-bt",
33 +};
34 +
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.
40 + */
41 +
42 +static void gta02_pcf50633_attach_child_devices(struct device *parent_device)
43 +{
44 + gta01_pm_gps_dev.dev.parent = parent_device;
45 + gta01_pm_bt_dev.dev.parent = parent_device;
46 + platform_device_register(&gta01_pm_bt_dev);
47 + platform_device_register(&gta01_pm_gps_dev);
48 +}
49 +
50 static struct pcf50633_platform_data gta02_pcf_pdata = {
51 .used_features = PCF50633_FEAT_MBC |
52 PCF50633_FEAT_BBC |
53 @@ -478,6 +501,7 @@ static struct pcf50633_platform_data gta02_pcf_pdata = {
54 .r_fix_batt = 10000,
55 .r_fix_batt_par = 10000,
56 .r_sense_milli = 220,
57 + .flag_use_apm_emulation = 0,
58 .resumers = {
59 [0] = PCF50633_INT1_USBINS |
60 PCF50633_INT1_USBREM |
61 @@ -577,7 +601,9 @@ static struct pcf50633_platform_data gta02_pcf_pdata = {
62 },
63 },
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
68 +
69 };
70
71 #if 0 /* currently unused */
72 @@ -772,6 +798,7 @@ struct platform_device s3c24xx_pwm_device = {
73 .num_resources = 0,
74 };
75
76 +
77 static struct platform_device *gta02_devices[] __initdata = {
78 &s3c_device_usb,
79 &s3c_device_wdt,
80 @@ -786,6 +813,7 @@ static struct platform_device *gta02_devices[] __initdata = {
81 &gta02_version_device,
82 &gta02_resume_reason_device,
83 &s3c24xx_pwm_device,
84 +
85 };
86
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 6745993..850bf93 100644
90 --- a/drivers/i2c/chips/pcf50633.c
91 +++ b/drivers/i2c/chips/pcf50633.c
92 @@ -50,7 +50,6 @@
93 #include <linux/jiffies.h>
94
95 #include <asm/mach-types.h>
96 -#include <asm/arch/gta02.h>
97
98 #include "pcf50633.h"
99 #include <linux/resume-dependency.h>
100 @@ -2004,18 +2003,6 @@ static DEVICE_ATTR(dump_regs, 0400, show_dump_regs, NULL);
101 * Driver initialization
102 ***********************************************************************/
103
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",
109 -};
110 -
111 -static struct platform_device gta01_pm_bt_dev = {
112 - .name = "neo1973-pm-bt",
113 -};
114 -#endif
115 -
116 /*
117 * CARE! This table is modified at runtime!
118 */
119 @@ -2209,14 +2196,15 @@ static int pcf50633_detect(struct i2c_adapter *adapter, int address, int kind)
120 apm_get_power_status = pcf50633_get_power_status;
121 data->probe_completed = 1;
122
123 -#ifdef CONFIG_MACH_NEO1973_GTA02
124 - if (machine_is_neo1973_gta02()) {
125 - gta01_pm_gps_dev.dev.parent = &new_client->dev;
126 - gta01_pm_bt_dev.dev.parent = &new_client->dev;
127 - platform_device_register(&gta01_pm_bt_dev);
128 - platform_device_register(&gta01_pm_gps_dev);
129 - }
130 -#endif
131 + if (data->pdata->flag_use_apm_emulation)
132 + apm_get_power_status = pcf50633_get_power_status;
133 +
134 + /* if platform was interested, give him a chance to register
135 + * platform devices that switch power with us as the parent
136 + * at registration time -- ensures suspend / resume ordering
137 + */
138 + if (data->pdata->attach_child_devices)
139 + (data->pdata->attach_child_devices)(&new_client->dev);
140
141 return 0;
142 exit_rtc:
143 @@ -2261,13 +2249,6 @@ static int pcf50633_detach_client(struct i2c_client *client)
144 if (pcf->pdata->used_features & PCF50633_FEAT_RTC)
145 rtc_device_unregister(pcf->rtc);
146
147 -#ifdef CONFIG_MACH_NEO1973_GTA02
148 - if (machine_is_neo1973_gta02()) {
149 - platform_device_unregister(&gta01_pm_bt_dev);
150 - platform_device_unregister(&gta01_pm_gps_dev);
151 - }
152 -#endif
153 -
154 sysfs_remove_group(&client->dev.kobj, &pcf_attr_group);
155
156 pm_power_off = NULL;
157 @@ -2465,6 +2446,26 @@ int pcf50633_ready(struct pcf50633_data *pcf)
158 }
159 EXPORT_SYMBOL_GPL(pcf50633_ready);
160
161 +int pcf50633_wait_for_ready(struct pcf50633_data *pcf, int timeout_ms,
162 + char *name)
163 +{
164 + /* so we always go once */
165 + timeout_ms += 5;
166 +
167 + while ((timeout_ms >= 5) && (pcf50633_ready(pcf))) {
168 + timeout_ms -= 5; /* well, it isn't very accurate, but OK */
169 + msleep(5);
170 + }
171 +
172 + if (timeout_ms < 5) {
173 + printk(KERN_ERR"pcf50633_wait_for_ready: "
174 + "%s BAILING on timeout\n", name);
175 + return -EBUSY;
176 + }
177 +
178 + return 0;
179 +}
180 +EXPORT_SYMBOL_GPL(pcf50633_wait_for_ready);
181
182 /*
183 * if backlight resume is selected to be deferred by platform, then it
184 diff --git a/include/linux/pcf50633.h b/include/linux/pcf50633.h
185 index b94b72a..4653285 100644
186 --- a/include/linux/pcf50633.h
187 +++ b/include/linux/pcf50633.h
188 @@ -132,7 +132,9 @@ pcf50633_register_resume_dependency(struct pcf50633_data *pcf,
189 extern int
190 pcf50633_notify_usb_current_limit_change(struct pcf50633_data *pcf,
191 unsigned int ma);
192 -
193 +extern int
194 +pcf50633_wait_for_ready(struct pcf50633_data *pcf, int timeout_ms,
195 + char *name);
196
197 /* 0 = initialized and resumed and ready to roll, !=0 = either not
198 * initialized or not resumed yet
199 @@ -155,6 +157,10 @@ struct pcf50633_platform_data {
200 unsigned int onkey_seconds_sig_init;
201 unsigned int onkey_seconds_shutdown;
202
203 + /* callback to attach platform children (to enforce suspend / resume
204 + * ordering */
205 + void (*attach_child_devices)(struct device *parent_device);
206 +
207 /* voltage regulator related */
208 struct pmu_voltage_rail rails[__NUM_PCF50633_REGULATORS];
209 unsigned int used_regulators;
210 @@ -163,6 +169,7 @@ struct pcf50633_platform_data {
211 unsigned int r_fix_batt;
212 unsigned int r_fix_batt_par;
213 unsigned int r_sense_milli;
214 + int flag_use_apm_emulation;
215
216 unsigned char resumers[5];
217
218 --
219 1.5.6.3
220