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
7 Signed-off-by: Harald Welte <laforge@openmoko.org>
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
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
29 index 0000000..b1af441
31 +++ b/arch/arm/plat-s3c24xx/neo1973_pm_bt.c
34 + * Bluetooth PM code for the FIC Neo1973 GSM Phone
36 + * (C) 2007 by OpenMoko Inc.
37 + * Author: Harald Welte <laforge@openmoko.org>
38 + * All rights reserved.
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
46 +#include <linux/module.h>
47 +#include <linux/init.h>
48 +#include <linux/kernel.h>
49 +#include <linux/platform_device.h>
51 +#include <linux/pcf50606.h>
53 +#include <asm/hardware.h>
54 +#include <asm/arch/gta01.h>
56 +#define DRVMSG "FIC Neo1973 Bluetooth Power Management"
58 +static ssize_t bt_read(struct device *dev, struct device_attribute *attr,
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)
67 + } else if (!strcmp(attr->attr.name, "reset")) {
68 + if (s3c2410_gpio_getpin(GTA01_GPIO_BT_EN) == 0)
72 + return strlcpy(buf, "0\n", 3);
74 + return strlcpy(buf, "1\n", 3);
77 +static ssize_t bt_write(struct device *dev, struct device_attribute *attr,
78 + const char *buf, size_t count)
80 + unsigned long on = simple_strtoul(buf, NULL, 10);
82 + if (!strcmp(attr->attr.name, "power_on")) {
83 + /* if we are powering up, assert reset, then power, then
86 + s3c2410_gpio_setpin(GTA01_GPIO_BT_EN, 0);
87 + pcf50606_voltage_set(pcf50606_global,
88 + PCF50606_REGULATOR_D1REG,
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);
102 +static DEVICE_ATTR(power_on, 0644, bt_read, bt_write);
103 +static DEVICE_ATTR(reset, 0644, bt_read, bt_write);
106 +static int gta01_bt_suspend(struct platform_device *pdev, pm_message_t state)
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? */
116 +static int gta01_bt_resume(struct platform_device *pdev)
118 + dev_dbg(&pdev->dev, DRVMSG ": resuming\n");
123 +#define gta01_bt_suspend NULL
124 +#define gta01_bt_resume NULL
127 +static struct attribute *gta01_bt_sysfs_entries[] = {
128 + &dev_attr_power_on.attr,
129 + &dev_attr_reset.attr,
133 +static struct attribute_group gta01_bt_attr_group = {
135 + .attrs = gta01_bt_sysfs_entries,
138 +static int __init gta01_bt_probe(struct platform_device *pdev)
140 + dev_info(&pdev->dev, DRVMSG ": starting\n");
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);
149 + return sysfs_create_group(&pdev->dev.kobj, >a01_bt_attr_group);
152 +static int gta01_bt_remove(struct platform_device *pdev)
154 + sysfs_remove_group(&pdev->dev.kobj, >a01_bt_attr_group);
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,
165 + .name = "neo1973-pm-bt",
169 +static int __devinit gta01_bt_init(void)
171 + return platform_driver_register(>a01_bt_driver);
174 +static void gta01_bt_exit(void)
176 + platform_driver_unregister(>a01_bt_driver);
179 +module_init(gta01_bt_init);
180 +module_exit(gta01_bt_exit);
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
187 index 0000000..f8cf719
189 +++ b/arch/arm/plat-s3c24xx/neo1973_pm_gps.c
192 + * GPS Power Management code for the FIC Neo1973 GSM Phone
194 + * (C) 2007 by OpenMoko Inc.
195 + * Author: Harald Welte <laforge@openmoko.org>
196 + * All rights reserved.
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
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>
210 +#include <linux/pcf50606.h>
212 +#include <asm/hardware.h>
213 +#include <asm/arch/gta01.h>
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)
219 + switch (system_rev) {
220 + case GTA01v3_SYSTEM_REV:
221 + case GTA01v4_SYSTEM_REV:
223 + pcf50606_voltage_set(pcf50606_global,
224 + PCF50606_REGULATOR_IOREG, 2800);
225 + pcf50606_onoff_set(pcf50606_global,
226 + PCF50606_REGULATOR_IOREG, on);
228 + case GTA01Bv2_SYSTEM_REV:
229 + s3c2410_gpio_setpin(GTA01_GPIO_GPS_EN_2V8, on);
231 + case GTA01Bv3_SYSTEM_REV:
232 + case GTA01Bv4_SYSTEM_REV:
237 +static int gps_power_2v8_get(void)
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)
250 + case GTA01Bv2_SYSTEM_REV:
251 + if (s3c2410_gpio_getpin(GTA01_GPIO_GPS_EN_2V8))
254 + case GTA01Bv3_SYSTEM_REV:
255 + case GTA01Bv4_SYSTEM_REV:
262 +/* This is the 3V supply (AVDD) for the external RF frontend (LNA bias) */
263 +static void gps_power_3v_set(int on)
265 + switch (system_rev) {
266 + case GTA01v3_SYSTEM_REV:
267 + case GTA01v4_SYSTEM_REV:
269 + pcf50606_voltage_set(pcf50606_global,
270 + PCF50606_REGULATOR_D1REG, 3000);
271 + pcf50606_onoff_set(pcf50606_global,
272 + PCF50606_REGULATOR_D1REG, on);
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);
282 +static int gps_power_3v_get(void)
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)
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))
306 +/* This is the 3.3V supply for VDD_IO and VDD_LPREG input */
307 +static void gps_power_3v3_set(int on)
309 + switch (system_rev) {
310 + case GTA01v3_SYSTEM_REV:
311 + case GTA01v4_SYSTEM_REV:
312 + case GTA01Bv2_SYSTEM_REV:
314 + pcf50606_voltage_set(pcf50606_global,
315 + PCF50606_REGULATOR_DCD, 3300);
316 + pcf50606_onoff_set(pcf50606_global,
317 + PCF50606_REGULATOR_DCD, on);
319 + case GTA01Bv3_SYSTEM_REV:
320 + case GTA01Bv4_SYSTEM_REV:
321 + s3c2410_gpio_setpin(GTA01_GPIO_GPS_EN_3V3, on);
326 +static int gps_power_3v3_get(void)
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)
340 + case GTA01Bv3_SYSTEM_REV:
341 + case GTA01Bv4_SYSTEM_REV:
342 + if (s3c2410_gpio_getpin(GTA01_GPIO_GPS_EN_3V3))
350 +/* This is the 2.5V supply for VDD_PLLREG and VDD_COREREG input */
351 +static void gps_power_2v5_set(int on)
353 + switch (system_rev) {
354 + case GTA01v3_SYSTEM_REV:
355 + /* This is CORE_1V8 and cannot be disabled */
357 + case GTA01v4_SYSTEM_REV:
358 + case GTA01Bv2_SYSTEM_REV:
359 + case GTA01Bv3_SYSTEM_REV:
360 + case GTA01Bv4_SYSTEM_REV:
362 + pcf50606_voltage_set(pcf50606_global,
363 + PCF50606_REGULATOR_D2REG, 2500);
364 + pcf50606_onoff_set(pcf50606_global,
365 + PCF50606_REGULATOR_D2REG, on);
370 +static int gps_power_2v5_get(void)
374 + switch (system_rev) {
375 + case GTA01v3_SYSTEM_REV:
376 + /* This is CORE_1V8 and cannot be disabled */
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)
394 +/* This is the 1.5V supply for VDD_CORE */
395 +static void gps_power_1v5_set(int on)
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 */
403 + case GTA01Bv3_SYSTEM_REV:
404 + case GTA01Bv4_SYSTEM_REV:
406 + pcf50606_voltage_set(pcf50606_global,
407 + PCF50606_REGULATOR_DCD, 1500);
408 + pcf50606_onoff_set(pcf50606_global,
409 + PCF50606_REGULATOR_DCD, on);
414 +static int gps_power_1v5_get(void)
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 */
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)
438 +/* This is the POWERON pin */
439 +static void gps_pwron_set(int on)
441 + s3c2410_gpio_setpin(GTA01_GPIO_GPS_PWRON, on);
444 +static int gps_pwron_get(void)
446 + if (s3c2410_gpio_getpin(GTA01_GPIO_GPS_PWRON))
452 +/* This is the nRESET pin */
453 +static void gps_rst_set(int on)
455 + switch (system_rev) {
456 + case GTA01v3_SYSTEM_REV:
457 + pcf50606_gpo0_set(pcf50606_global, on);
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);
468 +static int gps_rst_get(void)
470 + switch (system_rev) {
471 + case GTA01v3_SYSTEM_REV:
472 + if (pcf50606_gpo0_get(pcf50606_global))
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))
487 +static ssize_t power_gps_read(struct device *dev,
488 + struct device_attribute *attr, char *buf)
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();
510 + return strlcpy(buf, "1\n", 3);
512 + return strlcpy(buf, "0\n", 3);
515 +static ssize_t power_gps_write(struct device *dev,
516 + struct device_attribute *attr, const char *buf,
519 + unsigned long on = simple_strtoul(buf, NULL, 10);
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")) {
527 + } else if (!strcmp(attr->attr.name, "reset")) {
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);
541 +static void gps_power_sequence_up(void)
543 + /* According to PMB2520 Data Sheet, Rev. 2006-06-05,
546 + /* nRESET must be asserted low */
549 + /* POWERON must be de-asserted (low) */
552 + /* Apply VDD_IO and VDD_LPREG_IN */
553 + gps_power_3v3_set(1);
555 + /* VDD_COREREG_IN, VDD_PLLREG_IN */
556 + gps_power_1v5_set(1);
557 + gps_power_2v5_set(1);
559 + /* and VDD_RF may be applied */
560 + gps_power_2v8_set(1);
562 + /* We need to enable AVDD, since in GTA01Bv3 it is
563 + * shared with RFREG_IN */
564 + gps_power_3v_set(1);
566 + msleep(3); /* Is 3ms enough? */
568 + /* De-asert nRESET */
571 + /* Switch power on */
576 +static void gps_power_sequence_down(void)
578 + /* According to PMB2520 Data Sheet, Rev. 2006-06-05,
579 + * Chapter 4.2.3.1 */
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);
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);
591 + /* Remove VDD_LPREG_IN and VDD_IO */
592 + gps_power_3v3_set(0);
596 +static ssize_t power_sequence_read(struct device *dev,
597 + struct device_attribute *attr,
600 + return strlcpy(buf, "power_up power_down\n", PAGE_SIZE);
603 +static ssize_t power_sequence_write(struct device *dev,
604 + struct device_attribute *attr,
605 + const char *buf, size_t count)
607 + dev_dbg(dev, "wrote: '%s'\n", buf);
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();
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);
631 +static int gta01_pm_gps_suspend(struct platform_device *pdev,
632 + pm_message_t state)
635 + gps_power_sequence_down();
640 +static int gta01_pm_gps_resume(struct platform_device *pdev)
643 + gps_power_sequence_up();
648 +#define gta01_pm_gps_suspend NULL
649 +#define gta01_pm_gps_resume NULL
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 */
664 +static struct attribute_group gta01_gps_attr_group = {
666 + .attrs = gta01_gps_sysfs_entries,
669 +static int __init gta01_pm_gps_probe(struct platform_device *pdev)
671 + s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_PWRON, S3C2410_GPIO_OUTPUT);
673 + switch (system_rev) {
674 + case GTA01v3_SYSTEM_REV:
676 + case GTA01v4_SYSTEM_REV:
677 + s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_RESET, S3C2410_GPIO_OUTPUT);
679 + case GTA01Bv3_SYSTEM_REV:
680 + case GTA01Bv4_SYSTEM_REV:
681 + s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_EN_3V3, S3C2410_GPIO_OUTPUT);
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);
689 + dev_warn(&pdev->dev, "Unknown GTA01 Revision 0x%x, "
690 + "AGPS PM features not available!!!\n",
696 + gps_power_sequence_down();
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;
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;
714 + return sysfs_create_group(&pdev->dev.kobj, >a01_gps_attr_group);
717 +static int gta01_pm_gps_remove(struct platform_device *pdev)
719 + gps_power_sequence_down();
720 + sysfs_remove_group(&pdev->dev.kobj, >a01_gps_attr_group);
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,
731 + .name = "neo1973-pm-gps",
735 +static int __devinit gta01_pm_gps_init(void)
737 + return platform_driver_register(>a01_pm_gps_driver);
740 +static void gta01_pm_gps_exit(void)
742 + platform_driver_unregister(>a01_pm_gps_driver);
745 +module_init(gta01_pm_gps_init);
746 +module_exit(gta01_pm_gps_exit);
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
753 index 0000000..a1615f8
755 +++ b/arch/arm/plat-s3c24xx/neo1973_pm_gsm.c
758 + * GSM Management code for the FIC Neo1973 GSM Phone
760 + * (C) 2007 by OpenMoko Inc.
761 + * Author: Harald Welte <laforge@openmoko.org>
762 + * All rights reserved.
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
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>
777 +#include <asm/hardware.h>
778 +#include <asm/arch/gta01.h>
780 +struct gta01pm_priv {
782 + struct console *con;
785 +static struct gta01pm_priv gta01_gsm;
787 +static struct console *find_s3c24xx_console(void)
789 + struct console *con;
791 + acquire_console_sem();
793 + for (con = console_drivers; con; con = con->next) {
794 + if (!strcmp(con->name, "ttySAC"))
798 + release_console_sem();
803 +static ssize_t gsm_read(struct device *dev, struct device_attribute *attr,
806 + if (!strcmp(attr->attr.name, "power_on")) {
807 + if (s3c2410_gpio_getpin(GTA01_GPIO_MODEM_ON))
809 + } else if (!strcmp(attr->attr.name, "reset")) {
810 + if (s3c2410_gpio_getpin(GTA01_GPIO_MODEM_RST))
812 + } else if (!strcmp(attr->attr.name, "download")) {
813 + if (s3c2410_gpio_getpin(GTA01_GPIO_MODEM_DNLOAD))
817 + return strlcpy(buf, "0\n", 3);
819 + return strlcpy(buf, "1\n", 3);
822 +static ssize_t gsm_write(struct device *dev, struct device_attribute *attr,
823 + const char *buf, size_t count)
825 + unsigned long on = simple_strtoul(buf, NULL, 10);
827 + if (!strcmp(attr->attr.name, "power_on")) {
829 + dev_info(dev, "powering up GSM, thus disconnecting "
830 + "serial console\n");
833 + console_stop(gta01_gsm.con);
835 + if (gta01_gsm.gpio_ngsm_en)
836 + s3c2410_gpio_setpin(gta01_gsm.gpio_ngsm_en, 0);
838 + s3c2410_gpio_setpin(GTA01_GPIO_MODEM_ON, 1);
840 + s3c2410_gpio_setpin(GTA01_GPIO_MODEM_ON, 0);
842 + if (gta01_gsm.gpio_ngsm_en)
843 + s3c2410_gpio_setpin(gta01_gsm.gpio_ngsm_en, 1);
846 + console_start(gta01_gsm.con);
848 + dev_info(dev, "powered down GSM, thus enabling "
849 + "serial console\n");
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);
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);
865 +static int gta01_gsm_suspend(struct platform_device *pdev, pm_message_t state)
867 + /* GPIO state is saved/restored by S3C2410 core GPIO driver, so we
868 + * don't need to do anything here */
873 +static int gta01_gsm_resume(struct platform_device *pdev)
875 + /* GPIO state is saved/restored by S3C2410 core GPIO driver, so we
876 + * don't need to do anything here */
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);
886 +#define gta01_gsm_suspend NULL
887 +#define gta01_gsm_resume NULL
890 +static struct attribute *gta01_gsm_sysfs_entries[] = {
891 + &dev_attr_power_on.attr,
892 + &dev_attr_reset.attr,
897 +static struct attribute_group gta01_gsm_attr_group = {
899 + .attrs = gta01_gsm_sysfs_entries,
902 +static int __init gta01_gsm_probe(struct platform_device *pdev)
904 + switch (system_rev) {
905 + case GTA01v3_SYSTEM_REV:
906 + gta01_gsm.gpio_ngsm_en = GTA01v3_GPIO_nGSM_EN;
908 + case GTA01v4_SYSTEM_REV:
909 + gta01_gsm.gpio_ngsm_en = 0;
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);
918 + dev_warn(&pdev->dev, "Unknown GTA01 Revision 0x%x, "
919 + "some PM features not available!!!\n",
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;
934 + gta01_gsm.con = find_s3c24xx_console();
935 + if (!gta01_gsm.con)
936 + dev_warn(&pdev->dev, "cannot find S3C24xx console driver\n");
938 + return sysfs_create_group(&pdev->dev.kobj, >a01_gsm_attr_group);
941 +static int gta01_gsm_remove(struct platform_device *pdev)
943 + sysfs_remove_group(&pdev->dev.kobj, >a01_gsm_attr_group);
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,
954 + .name = "neo1973-pm-gsm",
958 +static int __devinit gta01_gsm_init(void)
960 + return platform_driver_register(>a01_gsm_driver);
963 +static void gta01_gsm_exit(void)
965 + platform_driver_unregister(>a01_gsm_driver);
968 +module_init(gta01_gsm_init);
969 +module_exit(gta01_gsm_exit);
971 +MODULE_LICENSE("GPL");
972 +MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
973 +MODULE_DESCRIPTION("FIC Neo1973 GSM Power Management");