[brcm63xx] resync kernel configuration
[openwrt.git] / target / linux / s3c24xx / patches-2.6.24 / 1014-gta01-power_control.patch.patch
1 From b627ce9e57a5263ddcc4e6db49625057b6461ad3 Mon Sep 17 00:00:00 2001
2 From: mokopatches <mokopatches@openmoko.org>
3 Date: Fri, 4 Apr 2008 11:31:35 +0100
4 Subject: [PATCH] gta01-power_control.patch
5 [PATCH] Neo1973 GPS / GSM / Bluetooth power control via sysfs
6
7 Signed-off-by: Harald Welte <laforge@openmoko.org>
8 ---
9 arch/arm/plat-s3c24xx/Makefile | 1 +
10 arch/arm/plat-s3c24xx/neo1973_pm_bt.c | 152 +++++++++
11 arch/arm/plat-s3c24xx/neo1973_pm_gps.c | 560 ++++++++++++++++++++++++++++++++
12 arch/arm/plat-s3c24xx/neo1973_pm_gsm.c | 217 ++++++++++++
13 4 files changed, 930 insertions(+), 0 deletions(-)
14 create mode 100644 arch/arm/plat-s3c24xx/neo1973_pm_bt.c
15 create mode 100644 arch/arm/plat-s3c24xx/neo1973_pm_gps.c
16 create mode 100644 arch/arm/plat-s3c24xx/neo1973_pm_gsm.c
17
18 diff --git a/arch/arm/plat-s3c24xx/Makefile b/arch/arm/plat-s3c24xx/Makefile
19 index 8e5ccaa..7192912 100644
20 --- a/arch/arm/plat-s3c24xx/Makefile
21 +++ b/arch/arm/plat-s3c24xx/Makefile
22 @@ -28,3 +28,4 @@ obj-$(CONFIG_PM) += pm.o
23 obj-$(CONFIG_PM) += sleep.o
24 obj-$(CONFIG_S3C2410_DMA) += dma.o
25 obj-$(CONFIG_MACH_SMDK) += common-smdk.o
26 +obj-$(CONFIG_MACH_NEO1973) += neo1973_pm_gsm.o neo1973_pm_gps.o neo1973_pm_bt.o
27 diff --git a/arch/arm/plat-s3c24xx/neo1973_pm_bt.c b/arch/arm/plat-s3c24xx/neo1973_pm_bt.c
28 new file mode 100644
29 index 0000000..b1af441
30 --- /dev/null
31 +++ b/arch/arm/plat-s3c24xx/neo1973_pm_bt.c
32 @@ -0,0 +1,152 @@
33 +/*
34 + * Bluetooth PM code for the FIC Neo1973 GSM Phone
35 + *
36 + * (C) 2007 by OpenMoko Inc.
37 + * Author: Harald Welte <laforge@openmoko.org>
38 + * All rights reserved.
39 + *
40 + * This program is free software; you can redistribute it and/or modify
41 + * it under the terms of the GNU General Public License version 2 as
42 + * published by the Free Software Foundation
43 + *
44 + */
45 +
46 +#include <linux/module.h>
47 +#include <linux/init.h>
48 +#include <linux/kernel.h>
49 +#include <linux/platform_device.h>
50 +
51 +#include <linux/pcf50606.h>
52 +
53 +#include <asm/hardware.h>
54 +#include <asm/arch/gta01.h>
55 +
56 +#define DRVMSG "FIC Neo1973 Bluetooth Power Management"
57 +
58 +static ssize_t bt_read(struct device *dev, struct device_attribute *attr,
59 + char *buf)
60 +{
61 + if (!strcmp(attr->attr.name, "power_on")) {
62 + if (pcf50606_onoff_get(pcf50606_global,
63 + PCF50606_REGULATOR_D1REG) &&
64 + pcf50606_voltage_get(pcf50606_global,
65 + PCF50606_REGULATOR_D1REG) == 3100)
66 + goto out_1;
67 + } else if (!strcmp(attr->attr.name, "reset")) {
68 + if (s3c2410_gpio_getpin(GTA01_GPIO_BT_EN) == 0)
69 + goto out_1;
70 + }
71 +
72 + return strlcpy(buf, "0\n", 3);
73 +out_1:
74 + return strlcpy(buf, "1\n", 3);
75 +}
76 +
77 +static ssize_t bt_write(struct device *dev, struct device_attribute *attr,
78 + const char *buf, size_t count)
79 +{
80 + unsigned long on = simple_strtoul(buf, NULL, 10);
81 +
82 + if (!strcmp(attr->attr.name, "power_on")) {
83 + /* if we are powering up, assert reset, then power, then
84 + * release reset */
85 + if (on) {
86 + s3c2410_gpio_setpin(GTA01_GPIO_BT_EN, 0);
87 + pcf50606_voltage_set(pcf50606_global,
88 + PCF50606_REGULATOR_D1REG,
89 + 3100);
90 + }
91 + pcf50606_onoff_set(pcf50606_global,
92 + PCF50606_REGULATOR_D1REG, on);
93 + s3c2410_gpio_setpin(GTA01_GPIO_BT_EN, on);
94 + } else if (!strcmp(attr->attr.name, "reset")) {
95 + /* reset is low-active, so we need to invert */
96 + s3c2410_gpio_setpin(GTA01_GPIO_BT_EN, on ? 0 : 1);
97 + }
98 +
99 + return count;
100 +}
101 +
102 +static DEVICE_ATTR(power_on, 0644, bt_read, bt_write);
103 +static DEVICE_ATTR(reset, 0644, bt_read, bt_write);
104 +
105 +#ifdef CONFIG_PM
106 +static int gta01_bt_suspend(struct platform_device *pdev, pm_message_t state)
107 +{
108 + dev_dbg(&pdev->dev, DRVMSG ": suspending\n");
109 + /* FIXME: The PMU should save the PMU status, and the GPIO code should
110 + * preserve the GPIO level, so there shouldn't be anything left to do
111 + * for us, should there? */
112 +
113 + return 0;
114 +}
115 +
116 +static int gta01_bt_resume(struct platform_device *pdev)
117 +{
118 + dev_dbg(&pdev->dev, DRVMSG ": resuming\n");
119 +
120 + return 0;
121 +}
122 +#else
123 +#define gta01_bt_suspend NULL
124 +#define gta01_bt_resume NULL
125 +#endif
126 +
127 +static struct attribute *gta01_bt_sysfs_entries[] = {
128 + &dev_attr_power_on.attr,
129 + &dev_attr_reset.attr,
130 + NULL
131 +};
132 +
133 +static struct attribute_group gta01_bt_attr_group = {
134 + .name = NULL,
135 + .attrs = gta01_bt_sysfs_entries,
136 +};
137 +
138 +static int __init gta01_bt_probe(struct platform_device *pdev)
139 +{
140 + dev_info(&pdev->dev, DRVMSG ": starting\n");
141 +
142 + /* we make sure that the voltage is off */
143 + pcf50606_onoff_set(pcf50606_global,
144 + PCF50606_REGULATOR_D1REG, 0);
145 + /* we pull reset to low to make sure that the chip doesn't
146 + * drain power through the reset line */
147 + s3c2410_gpio_setpin(GTA01_GPIO_BT_EN, 0);
148 +
149 + return sysfs_create_group(&pdev->dev.kobj, &gta01_bt_attr_group);
150 +}
151 +
152 +static int gta01_bt_remove(struct platform_device *pdev)
153 +{
154 + sysfs_remove_group(&pdev->dev.kobj, &gta01_bt_attr_group);
155 +
156 + return 0;
157 +}
158 +
159 +static struct platform_driver gta01_bt_driver = {
160 + .probe = gta01_bt_probe,
161 + .remove = gta01_bt_remove,
162 + .suspend = gta01_bt_suspend,
163 + .resume = gta01_bt_resume,
164 + .driver = {
165 + .name = "neo1973-pm-bt",
166 + },
167 +};
168 +
169 +static int __devinit gta01_bt_init(void)
170 +{
171 + return platform_driver_register(&gta01_bt_driver);
172 +}
173 +
174 +static void gta01_bt_exit(void)
175 +{
176 + platform_driver_unregister(&gta01_bt_driver);
177 +}
178 +
179 +module_init(gta01_bt_init);
180 +module_exit(gta01_bt_exit);
181 +
182 +MODULE_LICENSE("GPL");
183 +MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
184 +MODULE_DESCRIPTION(DRVMSG);
185 diff --git a/arch/arm/plat-s3c24xx/neo1973_pm_gps.c b/arch/arm/plat-s3c24xx/neo1973_pm_gps.c
186 new file mode 100644
187 index 0000000..f8cf719
188 --- /dev/null
189 +++ b/arch/arm/plat-s3c24xx/neo1973_pm_gps.c
190 @@ -0,0 +1,560 @@
191 +/*
192 + * GPS Power Management code for the FIC Neo1973 GSM Phone
193 + *
194 + * (C) 2007 by OpenMoko Inc.
195 + * Author: Harald Welte <laforge@openmoko.org>
196 + * All rights reserved.
197 + *
198 + * This program is free software; you can redistribute it and/or modify
199 + * it under the terms of the GNU General Public License version 2 as
200 + * published by the Free Software Foundation
201 + *
202 + */
203 +
204 +#include <linux/module.h>
205 +#include <linux/init.h>
206 +#include <linux/kernel.h>
207 +#include <linux/delay.h>
208 +#include <linux/platform_device.h>
209 +
210 +#include <linux/pcf50606.h>
211 +
212 +#include <asm/hardware.h>
213 +#include <asm/arch/gta01.h>
214 +
215 +/* This is the 2.8V supply for the RTC crystal, the mail clock crystal and
216 + * the input to VDD_RF */
217 +static void gps_power_2v8_set(int on)
218 +{
219 + switch (system_rev) {
220 + case GTA01v3_SYSTEM_REV:
221 + case GTA01v4_SYSTEM_REV:
222 + if (on)
223 + pcf50606_voltage_set(pcf50606_global,
224 + PCF50606_REGULATOR_IOREG, 2800);
225 + pcf50606_onoff_set(pcf50606_global,
226 + PCF50606_REGULATOR_IOREG, on);
227 + break;
228 + case GTA01Bv2_SYSTEM_REV:
229 + s3c2410_gpio_setpin(GTA01_GPIO_GPS_EN_2V8, on);
230 + break;
231 + case GTA01Bv3_SYSTEM_REV:
232 + case GTA01Bv4_SYSTEM_REV:
233 + break;
234 + }
235 +}
236 +
237 +static int gps_power_2v8_get(void)
238 +{
239 + int ret = 0;
240 +
241 + switch (system_rev) {
242 + case GTA01v3_SYSTEM_REV:
243 + case GTA01v4_SYSTEM_REV:
244 + if (pcf50606_onoff_get(pcf50606_global,
245 + PCF50606_REGULATOR_IOREG) &&
246 + pcf50606_voltage_get(pcf50606_global,
247 + PCF50606_REGULATOR_IOREG) == 2800)
248 + ret = 1;
249 + break;
250 + case GTA01Bv2_SYSTEM_REV:
251 + if (s3c2410_gpio_getpin(GTA01_GPIO_GPS_EN_2V8))
252 + ret = 1;
253 + break;
254 + case GTA01Bv3_SYSTEM_REV:
255 + case GTA01Bv4_SYSTEM_REV:
256 + break;
257 + }
258 +
259 + return ret;
260 +}
261 +
262 +/* This is the 3V supply (AVDD) for the external RF frontend (LNA bias) */
263 +static void gps_power_3v_set(int on)
264 +{
265 + switch (system_rev) {
266 + case GTA01v3_SYSTEM_REV:
267 + case GTA01v4_SYSTEM_REV:
268 + if (on)
269 + pcf50606_voltage_set(pcf50606_global,
270 + PCF50606_REGULATOR_D1REG, 3000);
271 + pcf50606_onoff_set(pcf50606_global,
272 + PCF50606_REGULATOR_D1REG, on);
273 + break;
274 + case GTA01Bv2_SYSTEM_REV:
275 + case GTA01Bv3_SYSTEM_REV:
276 + case GTA01Bv4_SYSTEM_REV:
277 + s3c2410_gpio_setpin(GTA01_GPIO_GPS_EN_3V, on);
278 + break;
279 + }
280 +}
281 +
282 +static int gps_power_3v_get(void)
283 +{
284 + int ret = 0;
285 +
286 + switch (system_rev) {
287 + case GTA01v3_SYSTEM_REV:
288 + case GTA01v4_SYSTEM_REV:
289 + if (pcf50606_onoff_get(pcf50606_global,
290 + PCF50606_REGULATOR_D1REG) &&
291 + pcf50606_voltage_get(pcf50606_global,
292 + PCF50606_REGULATOR_D1REG) == 3000)
293 + ret = 1;
294 + break;
295 + case GTA01Bv2_SYSTEM_REV:
296 + case GTA01Bv3_SYSTEM_REV:
297 + case GTA01Bv4_SYSTEM_REV:
298 + if (s3c2410_gpio_getpin(GTA01_GPIO_GPS_EN_3V))
299 + ret = 1;
300 + break;
301 + }
302 +
303 + return ret;
304 +}
305 +
306 +/* This is the 3.3V supply for VDD_IO and VDD_LPREG input */
307 +static void gps_power_3v3_set(int on)
308 +{
309 + switch (system_rev) {
310 + case GTA01v3_SYSTEM_REV:
311 + case GTA01v4_SYSTEM_REV:
312 + case GTA01Bv2_SYSTEM_REV:
313 + if (on)
314 + pcf50606_voltage_set(pcf50606_global,
315 + PCF50606_REGULATOR_DCD, 3300);
316 + pcf50606_onoff_set(pcf50606_global,
317 + PCF50606_REGULATOR_DCD, on);
318 + break;
319 + case GTA01Bv3_SYSTEM_REV:
320 + case GTA01Bv4_SYSTEM_REV:
321 + s3c2410_gpio_setpin(GTA01_GPIO_GPS_EN_3V3, on);
322 + break;
323 + }
324 +}
325 +
326 +static int gps_power_3v3_get(void)
327 +{
328 + int ret = 0;
329 +
330 + switch (system_rev) {
331 + case GTA01v3_SYSTEM_REV:
332 + case GTA01v4_SYSTEM_REV:
333 + case GTA01Bv2_SYSTEM_REV:
334 + if (pcf50606_onoff_get(pcf50606_global,
335 + PCF50606_REGULATOR_DCD) &&
336 + pcf50606_voltage_get(pcf50606_global,
337 + PCF50606_REGULATOR_DCD) == 3300)
338 + ret = 1;
339 + break;
340 + case GTA01Bv3_SYSTEM_REV:
341 + case GTA01Bv4_SYSTEM_REV:
342 + if (s3c2410_gpio_getpin(GTA01_GPIO_GPS_EN_3V3))
343 + ret = 1;
344 + break;
345 + }
346 +
347 + return ret;
348 +}
349 +
350 +/* This is the 2.5V supply for VDD_PLLREG and VDD_COREREG input */
351 +static void gps_power_2v5_set(int on)
352 +{
353 + switch (system_rev) {
354 + case GTA01v3_SYSTEM_REV:
355 + /* This is CORE_1V8 and cannot be disabled */
356 + break;
357 + case GTA01v4_SYSTEM_REV:
358 + case GTA01Bv2_SYSTEM_REV:
359 + case GTA01Bv3_SYSTEM_REV:
360 + case GTA01Bv4_SYSTEM_REV:
361 + if (on)
362 + pcf50606_voltage_set(pcf50606_global,
363 + PCF50606_REGULATOR_D2REG, 2500);
364 + pcf50606_onoff_set(pcf50606_global,
365 + PCF50606_REGULATOR_D2REG, on);
366 + break;
367 + }
368 +}
369 +
370 +static int gps_power_2v5_get(void)
371 +{
372 + int ret = 0;
373 +
374 + switch (system_rev) {
375 + case GTA01v3_SYSTEM_REV:
376 + /* This is CORE_1V8 and cannot be disabled */
377 + ret = 1;
378 + break;
379 + case GTA01v4_SYSTEM_REV:
380 + case GTA01Bv2_SYSTEM_REV:
381 + case GTA01Bv3_SYSTEM_REV:
382 + case GTA01Bv4_SYSTEM_REV:
383 + if (pcf50606_onoff_get(pcf50606_global,
384 + PCF50606_REGULATOR_D2REG) &&
385 + pcf50606_voltage_get(pcf50606_global,
386 + PCF50606_REGULATOR_D2REG) == 2500)
387 + ret = 1;
388 + break;
389 + }
390 +
391 + return ret;
392 +}
393 +
394 +/* This is the 1.5V supply for VDD_CORE */
395 +static void gps_power_1v5_set(int on)
396 +{
397 + switch (system_rev) {
398 + case GTA01v3_SYSTEM_REV:
399 + case GTA01v4_SYSTEM_REV:
400 + case GTA01Bv2_SYSTEM_REV:
401 + /* This is switched via 2v5 */
402 + break;
403 + case GTA01Bv3_SYSTEM_REV:
404 + case GTA01Bv4_SYSTEM_REV:
405 + if (on)
406 + pcf50606_voltage_set(pcf50606_global,
407 + PCF50606_REGULATOR_DCD, 1500);
408 + pcf50606_onoff_set(pcf50606_global,
409 + PCF50606_REGULATOR_DCD, on);
410 + break;
411 + }
412 +}
413 +
414 +static int gps_power_1v5_get(void)
415 +{
416 + int ret = 0;
417 +
418 + switch (system_rev) {
419 + case GTA01v3_SYSTEM_REV:
420 + case GTA01v4_SYSTEM_REV:
421 + case GTA01Bv2_SYSTEM_REV:
422 + /* This is switched via 2v5 */
423 + ret = 1;
424 + break;
425 + case GTA01Bv3_SYSTEM_REV:
426 + case GTA01Bv4_SYSTEM_REV:
427 + if (pcf50606_onoff_get(pcf50606_global,
428 + PCF50606_REGULATOR_DCD) &&
429 + pcf50606_voltage_get(pcf50606_global,
430 + PCF50606_REGULATOR_DCD) == 1500)
431 + ret = 1;
432 + break;
433 + }
434 +
435 + return ret;
436 +}
437 +
438 +/* This is the POWERON pin */
439 +static void gps_pwron_set(int on)
440 +{
441 + s3c2410_gpio_setpin(GTA01_GPIO_GPS_PWRON, on);
442 +}
443 +
444 +static int gps_pwron_get(void)
445 +{
446 + if (s3c2410_gpio_getpin(GTA01_GPIO_GPS_PWRON))
447 + return 1;
448 + else
449 + return 0;
450 +}
451 +
452 +/* This is the nRESET pin */
453 +static void gps_rst_set(int on)
454 +{
455 + switch (system_rev) {
456 + case GTA01v3_SYSTEM_REV:
457 + pcf50606_gpo0_set(pcf50606_global, on);
458 + break;
459 + case GTA01v4_SYSTEM_REV:
460 + case GTA01Bv2_SYSTEM_REV:
461 + case GTA01Bv3_SYSTEM_REV:
462 + case GTA01Bv4_SYSTEM_REV:
463 + s3c2410_gpio_setpin(GTA01_GPIO_GPS_RESET, on);
464 + break;
465 + }
466 +}
467 +
468 +static int gps_rst_get(void)
469 +{
470 + switch (system_rev) {
471 + case GTA01v3_SYSTEM_REV:
472 + if (pcf50606_gpo0_get(pcf50606_global))
473 + return 1;
474 + break;
475 + case GTA01v4_SYSTEM_REV:
476 + case GTA01Bv2_SYSTEM_REV:
477 + case GTA01Bv3_SYSTEM_REV:
478 + case GTA01Bv4_SYSTEM_REV:
479 + if (s3c2410_gpio_getpin(GTA01_GPIO_GPS_RESET))
480 + return 1;
481 + break;
482 + }
483 +
484 + return 0;
485 +}
486 +
487 +static ssize_t power_gps_read(struct device *dev,
488 + struct device_attribute *attr, char *buf)
489 +{
490 + int ret = 0;
491 +
492 + if (!strcmp(attr->attr.name, "power_tcxo_2v8")) {
493 + ret = gps_power_2v8_get();
494 + } else if (!strcmp(attr->attr.name, "power_avdd_3v")) {
495 + ret = gps_power_3v_get();
496 + } else if (!strcmp(attr->attr.name, "pwron")) {
497 + ret = gps_pwron_get();
498 + } else if (!strcmp(attr->attr.name, "reset")) {
499 + ret = gps_rst_get();
500 + } else if (!strcmp(attr->attr.name, "power_lp_io_3v3")) {
501 + ret = gps_power_3v3_get();
502 + } else if (!strcmp(attr->attr.name, "power_pll_core_2v5")) {
503 + ret = gps_power_2v5_get();
504 + } else if (!strcmp(attr->attr.name, "power_core_1v5") ||
505 + !strcmp(attr->attr.name, "power_vdd_core_1v5")) {
506 + ret = gps_power_1v5_get();
507 + }
508 +
509 + if (ret)
510 + return strlcpy(buf, "1\n", 3);
511 + else
512 + return strlcpy(buf, "0\n", 3);
513 +}
514 +
515 +static ssize_t power_gps_write(struct device *dev,
516 + struct device_attribute *attr, const char *buf,
517 + size_t count)
518 +{
519 + unsigned long on = simple_strtoul(buf, NULL, 10);
520 +
521 + if (!strcmp(attr->attr.name, "power_tcxo_2v8")) {
522 + gps_power_2v8_set(on);
523 + } else if (!strcmp(attr->attr.name, "power_avdd_3v")) {
524 + gps_power_3v_set(on);
525 + } else if (!strcmp(attr->attr.name, "pwron")) {
526 + gps_pwron_set(on);
527 + } else if (!strcmp(attr->attr.name, "reset")) {
528 + gps_rst_set(on);
529 + } else if (!strcmp(attr->attr.name, "power_lp_io_3v3")) {
530 + gps_power_3v3_set(on);
531 + } else if (!strcmp(attr->attr.name, "power_pll_core_2v5")) {
532 + gps_power_2v5_set(on);
533 + } else if (!strcmp(attr->attr.name, "power_core_1v5") ||
534 + !strcmp(attr->attr.name, "power_vdd_core_1v5")) {
535 + gps_power_1v5_set(on);
536 + }
537 +
538 + return count;
539 +}
540 +
541 +static void gps_power_sequence_up(void)
542 +{
543 + /* According to PMB2520 Data Sheet, Rev. 2006-06-05,
544 + * Chapter 4.2.2 */
545 +
546 + /* nRESET must be asserted low */
547 + gps_rst_set(0);
548 +
549 + /* POWERON must be de-asserted (low) */
550 + gps_pwron_set(0);
551 +
552 + /* Apply VDD_IO and VDD_LPREG_IN */
553 + gps_power_3v3_set(1);
554 +
555 + /* VDD_COREREG_IN, VDD_PLLREG_IN */
556 + gps_power_1v5_set(1);
557 + gps_power_2v5_set(1);
558 +
559 + /* and VDD_RF may be applied */
560 + gps_power_2v8_set(1);
561 +
562 + /* We need to enable AVDD, since in GTA01Bv3 it is
563 + * shared with RFREG_IN */
564 + gps_power_3v_set(1);
565 +
566 + msleep(3); /* Is 3ms enough? */
567 +
568 + /* De-asert nRESET */
569 + gps_rst_set(1);
570 +
571 + /* Switch power on */
572 + gps_pwron_set(1);
573 +
574 +}
575 +
576 +static void gps_power_sequence_down(void)
577 +{
578 + /* According to PMB2520 Data Sheet, Rev. 2006-06-05,
579 + * Chapter 4.2.3.1 */
580 + gps_pwron_set(0);
581 +
582 + /* Don't disable AVDD before PWRON is cleared, since
583 + * in GTA01Bv3, AVDD and RFREG_IN are shared */
584 + gps_power_3v_set(0);
585 +
586 + /* Remove VDD_COREREG_IN, VDD_PLLREG_IN and VDD_REFREG_IN */
587 + gps_power_1v5_set(0);
588 + gps_power_2v5_set(0);
589 + gps_power_2v8_set(0);
590 +
591 + /* Remove VDD_LPREG_IN and VDD_IO */
592 + gps_power_3v3_set(0);
593 +}
594 +
595 +
596 +static ssize_t power_sequence_read(struct device *dev,
597 + struct device_attribute *attr,
598 + char *buf)
599 +{
600 + return strlcpy(buf, "power_up power_down\n", PAGE_SIZE);
601 +}
602 +
603 +static ssize_t power_sequence_write(struct device *dev,
604 + struct device_attribute *attr,
605 + const char *buf, size_t count)
606 +{
607 + dev_dbg(dev, "wrote: '%s'\n", buf);
608 +
609 + if (!strncmp(buf, "power_up", 8))
610 + gps_power_sequence_up();
611 + else if (!strncmp(buf, "power_down", 10))
612 + gps_power_sequence_down();
613 + else
614 + return -EINVAL;
615 +
616 + return count;
617 +}
618 +
619 +static DEVICE_ATTR(power_tcxo_2v8, 0644, power_gps_read, power_gps_write);
620 +static DEVICE_ATTR(power_avdd_3v, 0644, power_gps_read, power_gps_write);
621 +static DEVICE_ATTR(pwron, 0644, power_gps_read, power_gps_write);
622 +static DEVICE_ATTR(reset, 0644, power_gps_read, power_gps_write);
623 +static DEVICE_ATTR(power_lp_io_3v3, 0644, power_gps_read, power_gps_write);
624 +static DEVICE_ATTR(power_pll_core_2v5, 0644, power_gps_read, power_gps_write);
625 +static DEVICE_ATTR(power_core_1v5, 0644, power_gps_read, power_gps_write);
626 +static DEVICE_ATTR(power_vdd_core_1v5, 0644, power_gps_read, power_gps_write);
627 +static DEVICE_ATTR(power_sequence, 0644, power_sequence_read,
628 + power_sequence_write);
629 +
630 +#ifdef CONFIG_PM
631 +static int gta01_pm_gps_suspend(struct platform_device *pdev,
632 + pm_message_t state)
633 +{
634 + /* FIXME */
635 + gps_power_sequence_down();
636 +
637 + return 0;
638 +}
639 +
640 +static int gta01_pm_gps_resume(struct platform_device *pdev)
641 +{
642 + /* FIXME */
643 + gps_power_sequence_up();
644 +
645 + return 0;
646 +}
647 +#else
648 +#define gta01_pm_gps_suspend NULL
649 +#define gta01_pm_gps_resume NULL
650 +#endif
651 +
652 +static struct attribute *gta01_gps_sysfs_entries[] = {
653 + &dev_attr_power_avdd_3v.attr,
654 + &dev_attr_pwron.attr,
655 + &dev_attr_reset.attr,
656 + &dev_attr_power_lp_io_3v3.attr,
657 + &dev_attr_power_pll_core_2v5.attr,
658 + &dev_attr_power_sequence.attr,
659 + NULL, /* power_core_1v5 */
660 + NULL, /* power_vdd_core_1v5 */
661 + NULL /* terminating entry */
662 +};
663 +
664 +static struct attribute_group gta01_gps_attr_group = {
665 + .name = NULL,
666 + .attrs = gta01_gps_sysfs_entries,
667 +};
668 +
669 +static int __init gta01_pm_gps_probe(struct platform_device *pdev)
670 +{
671 + s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_PWRON, S3C2410_GPIO_OUTPUT);
672 +
673 + switch (system_rev) {
674 + case GTA01v3_SYSTEM_REV:
675 + break;
676 + case GTA01v4_SYSTEM_REV:
677 + s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_RESET, S3C2410_GPIO_OUTPUT);
678 + break;
679 + case GTA01Bv3_SYSTEM_REV:
680 + case GTA01Bv4_SYSTEM_REV:
681 + s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_EN_3V3, S3C2410_GPIO_OUTPUT);
682 + /* fallthrough */
683 + case GTA01Bv2_SYSTEM_REV:
684 + s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_EN_2V8, S3C2410_GPIO_OUTPUT);
685 + s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_EN_3V, S3C2410_GPIO_OUTPUT);
686 + s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_RESET, S3C2410_GPIO_OUTPUT);
687 + break;
688 + default:
689 + dev_warn(&pdev->dev, "Unknown GTA01 Revision 0x%x, "
690 + "AGPS PM features not available!!!\n",
691 + system_rev);
692 + return -1;
693 + break;
694 + }
695 +
696 + gps_power_sequence_down();
697 +
698 + switch (system_rev) {
699 + case GTA01v3_SYSTEM_REV:
700 + case GTA01v4_SYSTEM_REV:
701 + case GTA01Bv2_SYSTEM_REV:
702 + gta01_gps_sysfs_entries[ARRAY_SIZE(gta01_gps_sysfs_entries)-3] =
703 + &dev_attr_power_tcxo_2v8.attr;
704 + break;
705 + case GTA01Bv3_SYSTEM_REV:
706 + case GTA01Bv4_SYSTEM_REV:
707 + gta01_gps_sysfs_entries[ARRAY_SIZE(gta01_gps_sysfs_entries)-3] =
708 + &dev_attr_power_core_1v5.attr;
709 + gta01_gps_sysfs_entries[ARRAY_SIZE(gta01_gps_sysfs_entries)-2] =
710 + &dev_attr_power_vdd_core_1v5.attr;
711 + break;
712 + }
713 +
714 + return sysfs_create_group(&pdev->dev.kobj, &gta01_gps_attr_group);
715 +}
716 +
717 +static int gta01_pm_gps_remove(struct platform_device *pdev)
718 +{
719 + gps_power_sequence_down();
720 + sysfs_remove_group(&pdev->dev.kobj, &gta01_gps_attr_group);
721 +
722 + return 0;
723 +}
724 +
725 +static struct platform_driver gta01_pm_gps_driver = {
726 + .probe = gta01_pm_gps_probe,
727 + .remove = gta01_pm_gps_remove,
728 + .suspend = gta01_pm_gps_suspend,
729 + .resume = gta01_pm_gps_resume,
730 + .driver = {
731 + .name = "neo1973-pm-gps",
732 + },
733 +};
734 +
735 +static int __devinit gta01_pm_gps_init(void)
736 +{
737 + return platform_driver_register(&gta01_pm_gps_driver);
738 +}
739 +
740 +static void gta01_pm_gps_exit(void)
741 +{
742 + platform_driver_unregister(&gta01_pm_gps_driver);
743 +}
744 +
745 +module_init(gta01_pm_gps_init);
746 +module_exit(gta01_pm_gps_exit);
747 +
748 +MODULE_LICENSE("GPL");
749 +MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
750 +MODULE_DESCRIPTION("FIC Neo1973 GPS Power Management");
751 diff --git a/arch/arm/plat-s3c24xx/neo1973_pm_gsm.c b/arch/arm/plat-s3c24xx/neo1973_pm_gsm.c
752 new file mode 100644
753 index 0000000..a1615f8
754 --- /dev/null
755 +++ b/arch/arm/plat-s3c24xx/neo1973_pm_gsm.c
756 @@ -0,0 +1,217 @@
757 +/*
758 + * GSM Management code for the FIC Neo1973 GSM Phone
759 + *
760 + * (C) 2007 by OpenMoko Inc.
761 + * Author: Harald Welte <laforge@openmoko.org>
762 + * All rights reserved.
763 + *
764 + * This program is free software; you can redistribute it and/or modify
765 + * it under the terms of the GNU General Public License version 2 as
766 + * published by the Free Software Foundation
767 + *
768 + */
769 +
770 +#include <linux/module.h>
771 +#include <linux/init.h>
772 +#include <linux/kernel.h>
773 +#include <linux/platform_device.h>
774 +#include <linux/console.h>
775 +#include <linux/errno.h>
776 +
777 +#include <asm/hardware.h>
778 +#include <asm/arch/gta01.h>
779 +
780 +struct gta01pm_priv {
781 + int gpio_ngsm_en;
782 + struct console *con;
783 +};
784 +
785 +static struct gta01pm_priv gta01_gsm;
786 +
787 +static struct console *find_s3c24xx_console(void)
788 +{
789 + struct console *con;
790 +
791 + acquire_console_sem();
792 +
793 + for (con = console_drivers; con; con = con->next) {
794 + if (!strcmp(con->name, "ttySAC"))
795 + break;
796 + }
797 +
798 + release_console_sem();
799 +
800 + return con;
801 +}
802 +
803 +static ssize_t gsm_read(struct device *dev, struct device_attribute *attr,
804 + char *buf)
805 +{
806 + if (!strcmp(attr->attr.name, "power_on")) {
807 + if (s3c2410_gpio_getpin(GTA01_GPIO_MODEM_ON))
808 + goto out_1;
809 + } else if (!strcmp(attr->attr.name, "reset")) {
810 + if (s3c2410_gpio_getpin(GTA01_GPIO_MODEM_RST))
811 + goto out_1;
812 + } else if (!strcmp(attr->attr.name, "download")) {
813 + if (s3c2410_gpio_getpin(GTA01_GPIO_MODEM_DNLOAD))
814 + goto out_1;
815 + }
816 +
817 + return strlcpy(buf, "0\n", 3);
818 +out_1:
819 + return strlcpy(buf, "1\n", 3);
820 +}
821 +
822 +static ssize_t gsm_write(struct device *dev, struct device_attribute *attr,
823 + const char *buf, size_t count)
824 +{
825 + unsigned long on = simple_strtoul(buf, NULL, 10);
826 +
827 + if (!strcmp(attr->attr.name, "power_on")) {
828 + if (on) {
829 + dev_info(dev, "powering up GSM, thus disconnecting "
830 + "serial console\n");
831 +
832 + if (gta01_gsm.con)
833 + console_stop(gta01_gsm.con);
834 +
835 + if (gta01_gsm.gpio_ngsm_en)
836 + s3c2410_gpio_setpin(gta01_gsm.gpio_ngsm_en, 0);
837 +
838 + s3c2410_gpio_setpin(GTA01_GPIO_MODEM_ON, 1);
839 + } else {
840 + s3c2410_gpio_setpin(GTA01_GPIO_MODEM_ON, 0);
841 +
842 + if (gta01_gsm.gpio_ngsm_en)
843 + s3c2410_gpio_setpin(gta01_gsm.gpio_ngsm_en, 1);
844 +
845 + if (gta01_gsm.con)
846 + console_start(gta01_gsm.con);
847 +
848 + dev_info(dev, "powered down GSM, thus enabling "
849 + "serial console\n");
850 + }
851 + } else if (!strcmp(attr->attr.name, "reset")) {
852 + s3c2410_gpio_setpin(GTA01_GPIO_MODEM_RST, on);
853 + } else if (!strcmp(attr->attr.name, "download")) {
854 + s3c2410_gpio_setpin(GTA01_GPIO_MODEM_DNLOAD, on);
855 + }
856 +
857 + return count;
858 +}
859 +
860 +static DEVICE_ATTR(power_on, 0644, gsm_read, gsm_write);
861 +static DEVICE_ATTR(reset, 0644, gsm_read, gsm_write);
862 +static DEVICE_ATTR(download, 0644, gsm_read, gsm_write);
863 +
864 +#ifdef CONFIG_PM
865 +static int gta01_gsm_suspend(struct platform_device *pdev, pm_message_t state)
866 +{
867 + /* GPIO state is saved/restored by S3C2410 core GPIO driver, so we
868 + * don't need to do anything here */
869 +
870 + return 0;
871 +}
872 +
873 +static int gta01_gsm_resume(struct platform_device *pdev)
874 +{
875 + /* GPIO state is saved/restored by S3C2410 core GPIO driver, so we
876 + * don't need to do anything here */
877 +
878 + /* Make sure that the kernel console on the serial port is still
879 + * disabled. FIXME: resume ordering race with serial driver! */
880 + if (s3c2410_gpio_getpin(GTA01_GPIO_MODEM_ON) && gta01_gsm.con)
881 + console_stop(gta01_gsm.con);
882 +
883 + return 0;
884 +}
885 +#else
886 +#define gta01_gsm_suspend NULL
887 +#define gta01_gsm_resume NULL
888 +#endif
889 +
890 +static struct attribute *gta01_gsm_sysfs_entries[] = {
891 + &dev_attr_power_on.attr,
892 + &dev_attr_reset.attr,
893 + NULL,
894 + NULL
895 +};
896 +
897 +static struct attribute_group gta01_gsm_attr_group = {
898 + .name = NULL,
899 + .attrs = gta01_gsm_sysfs_entries,
900 +};
901 +
902 +static int __init gta01_gsm_probe(struct platform_device *pdev)
903 +{
904 + switch (system_rev) {
905 + case GTA01v3_SYSTEM_REV:
906 + gta01_gsm.gpio_ngsm_en = GTA01v3_GPIO_nGSM_EN;
907 + break;
908 + case GTA01v4_SYSTEM_REV:
909 + gta01_gsm.gpio_ngsm_en = 0;
910 + break;
911 + case GTA01Bv2_SYSTEM_REV:
912 + case GTA01Bv3_SYSTEM_REV:
913 + case GTA01Bv4_SYSTEM_REV:
914 + gta01_gsm.gpio_ngsm_en = GTA01Bv2_GPIO_nGSM_EN;
915 + s3c2410_gpio_setpin(GTA01v3_GPIO_nGSM_EN, 0);
916 + break;
917 + default:
918 + dev_warn(&pdev->dev, "Unknown GTA01 Revision 0x%x, "
919 + "some PM features not available!!!\n",
920 + system_rev);
921 + break;
922 + }
923 +
924 + switch (system_rev) {
925 + case GTA01v4_SYSTEM_REV:
926 + case GTA01Bv2_SYSTEM_REV:
927 + gta01_gsm_sysfs_entries[ARRAY_SIZE(gta01_gsm_sysfs_entries)-2] =
928 + &dev_attr_download.attr;
929 + break;
930 + default:
931 + break;
932 + }
933 +
934 + gta01_gsm.con = find_s3c24xx_console();
935 + if (!gta01_gsm.con)
936 + dev_warn(&pdev->dev, "cannot find S3C24xx console driver\n");
937 +
938 + return sysfs_create_group(&pdev->dev.kobj, &gta01_gsm_attr_group);
939 +}
940 +
941 +static int gta01_gsm_remove(struct platform_device *pdev)
942 +{
943 + sysfs_remove_group(&pdev->dev.kobj, &gta01_gsm_attr_group);
944 +
945 + return 0;
946 +}
947 +
948 +static struct platform_driver gta01_gsm_driver = {
949 + .probe = gta01_gsm_probe,
950 + .remove = gta01_gsm_remove,
951 + .suspend = gta01_gsm_suspend,
952 + .resume = gta01_gsm_resume,
953 + .driver = {
954 + .name = "neo1973-pm-gsm",
955 + },
956 +};
957 +
958 +static int __devinit gta01_gsm_init(void)
959 +{
960 + return platform_driver_register(&gta01_gsm_driver);
961 +}
962 +
963 +static void gta01_gsm_exit(void)
964 +{
965 + platform_driver_unregister(&gta01_gsm_driver);
966 +}
967 +
968 +module_init(gta01_gsm_init);
969 +module_exit(gta01_gsm_exit);
970 +
971 +MODULE_LICENSE("GPL");
972 +MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
973 +MODULE_DESCRIPTION("FIC Neo1973 GSM Power Management");
974 --
975 1.5.6.5
976
This page took 0.083053 seconds and 5 git commands to generate.