1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
|
/*
* GPS Power Management code for the FIC Neo1973 GSM Phone
*
* (C) 2007-2009 by Openmoko Inc.
* Author: Harald Welte <laforge@openmoko.org>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation
*
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <mach/hardware.h>
#include <mach/cpu.h>
#include <asm/mach-types.h>
#include <asm/plat-s3c24xx/neo1973.h>
/* For GTA01 */
#include <mach/gta01.h>
#include <linux/mfd/pcf50606/core.h>
#include <linux/mfd/pcf50606/gpo.h>
/* For GTA02 */
#include <mach/gta02.h>
#include <linux/mfd/pcf50633/core.h>
#include <linux/mfd/pcf50633/pmic.h>
#include <linux/regulator/consumer.h>
#include <linux/err.h>
enum gta01_pm_gps_supplies {
/* GTA01 */
GTA01_GPS_REG_2V8,
GTA01_GPS_REG_3V,
GTA01_GPS_REG_3V3,
GTA01_GPS_REG_1V5,
GTA01_GPS_REG_2V5,
/* GTA02 */
GTA02_GPS_REG_RF_3V,
/* Always last */
GTA01_GPS_NUM_REG
};
struct neo1973_pm_gps_data {
#ifdef CONFIG_PM
int keep_on_in_suspend;
#endif
int power_was_on; /* For GTA02 only */
int regulator_state[GTA01_GPS_NUM_REG];
struct regulator *regulator[GTA01_GPS_NUM_REG];
};
static struct neo1973_pm_gps_data neo1973_gps;
int neo1973_pm_gps_is_on(void)
{
return neo1973_gps.power_was_on;
}
EXPORT_SYMBOL_GPL(neo1973_pm_gps_is_on);
#ifdef CONFIG_MACH_NEO1973_GTA01
/* This is the 2.8V supply for the RTC crystal, the mail clock crystal and
* the input to VDD_RF */
static void gps_power_2v8_set(int on)
{
struct regulator *regulator = neo1973_gps.regulator[GTA01_GPS_REG_2V8];
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
case GTA01v4_SYSTEM_REV:
if (on)
regulator_enable(regulator);
else
regulator_disable(regulator);
neo1973_gps.regulator_state[GTA01_GPS_REG_2V8] = on;
break;
case GTA01Bv2_SYSTEM_REV:
s3c2410_gpio_setpin(GTA01_GPIO_GPS_EN_2V8, on);
break;
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
break;
}
}
static int gps_power_2v8_get(void)
{
int ret = 0;
struct regulator *regulator = neo1973_gps.regulator[GTA01_GPS_REG_2V8];
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
case GTA01v4_SYSTEM_REV:
ret = regulator_is_enabled(regulator);
break;
case GTA01Bv2_SYSTEM_REV:
if (s3c2410_gpio_getpin(GTA01_GPIO_GPS_EN_2V8))
ret = 1;
break;
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
break;
}
return ret;
}
/* This is the 3V supply (AVDD) for the external RF frontend (LNA bias) */
static void gps_power_3v_set(int on)
{
struct regulator *regulator = neo1973_gps.regulator[GTA01_GPS_REG_3V];
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
case GTA01v4_SYSTEM_REV:
if (on)
regulator_enable(regulator);
else
regulator_disable(regulator);
neo1973_gps.regulator_state[GTA01_GPS_REG_3V] = on;
break;
case GTA01Bv2_SYSTEM_REV:
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
s3c2410_gpio_setpin(GTA01_GPIO_GPS_EN_3V, on);
break;
}
}
static int gps_power_3v_get(void)
{
int ret = 0;
struct regulator *regulator = neo1973_gps.regulator[GTA01_GPS_REG_3V];
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
case GTA01v4_SYSTEM_REV:
ret = regulator_is_enabled(regulator);
break;
case GTA01Bv2_SYSTEM_REV:
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
if (s3c2410_gpio_getpin(GTA01_GPIO_GPS_EN_3V))
ret = 1;
break;
}
return ret;
}
/* This is the 3.3V supply for VDD_IO and VDD_LPREG input */
static void gps_power_3v3_set(int on)
{
struct regulator *regulator = neo1973_gps.regulator[GTA01_GPS_REG_3V3];
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
case GTA01v4_SYSTEM_REV:
case GTA01Bv2_SYSTEM_REV:
if (on)
regulator_enable(regulator);
else
regulator_disable(regulator);
neo1973_gps.regulator_state[GTA01_GPS_REG_3V3] = on;
break;
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
s3c2410_gpio_setpin(GTA01_GPIO_GPS_EN_3V3, on);
break;
}
}
static int gps_power_3v3_get(void)
{
int ret = 0;
struct regulator *regulator = neo1973_gps.regulator[GTA01_GPS_REG_3V3];
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
case GTA01v4_SYSTEM_REV:
case GTA01Bv2_SYSTEM_REV:
ret = regulator_is_enabled(regulator);
break;
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
if (s3c2410_gpio_getpin(GTA01_GPIO_GPS_EN_3V3))
ret = 1;
break;
}
return ret;
}
/* This is the 2.5V supply for VDD_PLLREG and VDD_COREREG input */
static void gps_power_2v5_set(int on)
{
struct regulator *regulator = neo1973_gps.regulator[GTA01_GPS_REG_2V5];
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
/* This is CORE_1V8 and cannot be disabled */
break;
case GTA01v4_SYSTEM_REV:
case GTA01Bv2_SYSTEM_REV:
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
if (on)
regulator_enable(regulator);
else
regulator_disable(regulator);
neo1973_gps.regulator_state[GTA01_GPS_REG_2V5] = on;
break;
}
}
static int gps_power_2v5_get(void)
{
int ret = 0;
struct regulator *regulator = neo1973_gps.regulator[GTA01_GPS_REG_2V5];
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
/* This is CORE_1V8 and cannot be disabled */
ret = 1;
break;
case GTA01v4_SYSTEM_REV:
case GTA01Bv2_SYSTEM_REV:
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
ret = regulator_is_enabled(regulator);
break;
}
return ret;
}
/* This is the 1.5V supply for VDD_CORE */
static void gps_power_1v5_set(int on)
{
struct regulator *regulator = neo1973_gps.regulator[GTA01_GPS_REG_1V5];
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
case GTA01v4_SYSTEM_REV:
case GTA01Bv2_SYSTEM_REV:
/* This is switched via 2v5 */
break;
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
if (on)
regulator_enable(regulator);
else
regulator_disable(regulator);
neo1973_gps.regulator_state[GTA01_GPS_REG_1V5] = on;
break;
}
}
static int gps_power_1v5_get(void)
{
int ret = 0;
struct regulator *regulator = neo1973_gps.regulator[GTA01_GPS_REG_1V5];
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
case GTA01v4_SYSTEM_REV:
case GTA01Bv2_SYSTEM_REV:
/* This is switched via 2v5 */
ret = 1;
break;
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
ret = regulator_is_enabled(regulator);
break;
}
return ret;
}
#endif
/* This is the POWERON pin */
static void gps_pwron_set(int on)
{
if (machine_is_neo1973_gta01())
neo1973_gpb_setpin(GTA01_GPIO_GPS_PWRON, on);
if (machine_is_neo1973_gta02()) {
if (on) {
/* return UART pins to being UART pins */
s3c2410_gpio_cfgpin(S3C2410_GPH4, S3C2410_GPH4_TXD1);
/* remove pulldown now it won't be floating any more */
s3c2410_gpio_pullup(S3C2410_GPH5, 0);
if (!regulator_is_enabled(neo1973_gps.regulator[
GTA02_GPS_REG_RF_3V]))
regulator_enable(neo1973_gps.regulator[
GTA02_GPS_REG_RF_3V]);
return;
}
/*
* take care not to power unpowered GPS from UART TX
* return them to GPIO and force low
*/
s3c2410_gpio_cfgpin(S3C2410_GPH4, S3C2410_GPH4_OUTP);
s3c2410_gpio_setpin(S3C2410_GPH4, 0);
/* don't let RX from unpowered GPS float */
s3c2410_gpio_pullup(S3C2410_GPH5, 1);
if (neo1973_gps.power_was_on)
regulator_disable(neo1973_gps.regulator[
GTA02_GPS_REG_RF_3V]);
}
}
static int gps_pwron_get(void)
{
if (machine_is_neo1973_gta01())
return !!s3c2410_gpio_getpin(GTA01_GPIO_GPS_PWRON);
if (machine_is_neo1973_gta02())
return regulator_is_enabled(neo1973_gps.regulator[GTA02_GPS_REG_RF_3V]);
return -1;
}
#ifdef CONFIG_MACH_NEO1973_GTA01
static void gps_rst_set(int on);
static int gps_rst_get(void);
#endif
#ifdef CONFIG_PM
/* This is the flag for keeping gps ON during suspend */
static void gps_keep_on_in_suspend_set(int on)
{
neo1973_gps.keep_on_in_suspend = on;
}
static int gps_keep_on_in_suspend_get(void)
{
return neo1973_gps.keep_on_in_suspend;
}
#endif
static ssize_t power_gps_read(struct device *dev,
struct device_attribute *attr, char *buf)
{
int ret = 0;
if (!strcmp(attr->attr.name, "power_on") ||
!strcmp(attr->attr.name, "pwron")) {
ret = gps_pwron_get();
#ifdef CONFIG_PM
} else if (!strcmp(attr->attr.name, "keep_on_in_suspend")) {
ret = gps_keep_on_in_suspend_get();
#endif
#ifdef CONFIG_MACH_NEO1973_GTA01
} else if (!strcmp(attr->attr.name, "power_avdd_3v")) {
ret = gps_power_3v_get();
} else if (!strcmp(attr->attr.name, "power_tcxo_2v8")) {
ret = gps_power_2v8_get();
} else if (!strcmp(attr->attr.name, "reset")) {
ret = gps_rst_get();
} else if (!strcmp(attr->attr.name, "power_lp_io_3v3")) {
ret = gps_power_3v3_get();
} else if (!strcmp(attr->attr.name, "power_pll_core_2v5")) {
ret = gps_power_2v5_get();
} else if (!strcmp(attr->attr.name, "power_core_1v5") ||
!strcmp(attr->attr.name, "power_vdd_core_1v5")) {
ret = gps_power_1v5_get();
#endif
}
if (ret)
return strlcpy(buf, "1\n", 3);
else
return strlcpy(buf, "0\n", 3);
}
static ssize_t power_gps_write(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{
unsigned long on = simple_strtoul(buf, NULL, 10);
if (!strcmp(attr->attr.name, "power_on") ||
!strcmp(attr->attr.name, "pwron")) {
gps_pwron_set(on);
neo1973_gps.power_was_on = !!on;
#ifdef CONFIG_PM
} else if (!strcmp(attr->attr.name, "keep_on_in_suspend")) {
gps_keep_on_in_suspend_set(on);
#endif
#ifdef CONFIG_MACH_NEO1973_GTA01
} else if (!strcmp(attr->attr.name, "power_avdd_3v")) {
gps_power_3v_set(on);
} else if (!strcmp(attr->attr.name, "power_tcxo_2v8")) {
gps_power_2v8_set(on);
} else if (!strcmp(attr->attr.name, "reset")) {
gps_rst_set(on);
} else if (!strcmp(attr->attr.name, "power_lp_io_3v3")) {
gps_power_3v3_set(on);
} else if (!strcmp(attr->attr.name, "power_pll_core_2v5")) {
gps_power_2v5_set(on);
} else if (!strcmp(attr->attr.name, "power_core_1v5") ||
!strcmp(attr->attr.name, "power_vdd_core_1v5")) {
gps_power_1v5_set(on);
#endif
}
return count;
}
#ifdef CONFIG_MACH_NEO1973_GTA01
/* This is the nRESET pin */
static void gps_rst_set(int on)
{
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
pcf50606_gpo_set_active(gta01_pcf, PCF50606_GPO1, on);
break;
case GTA01v4_SYSTEM_REV:
case GTA01Bv2_SYSTEM_REV:
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
s3c2410_gpio_setpin(GTA01_GPIO_GPS_RESET, on);
break;
}
}
static int gps_rst_get(void)
{
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
return pcf50606_gpo_get_active(gta01_pcf, PCF50606_GPO1);
break;
case GTA01v4_SYSTEM_REV:
case GTA01Bv2_SYSTEM_REV:
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
if (s3c2410_gpio_getpin(GTA01_GPIO_GPS_RESET))
return 1;
break;
}
return 0;
}
static void gps_power_sequence_up(void)
{
/* According to PMB2520 Data Sheet, Rev. 2006-06-05,
* Chapter 4.2.2 */
/* nRESET must be asserted low */
gps_rst_set(0);
/* POWERON must be de-asserted (low) */
gps_pwron_set(0);
/* Apply VDD_IO and VDD_LPREG_IN */
gps_power_3v3_set(1);
/* VDD_COREREG_IN, VDD_PLLREG_IN */
gps_power_1v5_set(1);
gps_power_2v5_set(1);
/* and VDD_RF may be applied */
gps_power_2v8_set(1);
/* We need to enable AVDD, since in GTA01Bv3 it is
* shared with RFREG_IN */
gps_power_3v_set(1);
msleep(3); /* Is 3ms enough? */
/* De-asert nRESET */
gps_rst_set(1);
/* Switch power on */
gps_pwron_set(1);
}
static void gps_power_sequence_down(void)
{
/* According to PMB2520 Data Sheet, Rev. 2006-06-05,
* Chapter 4.2.3.1 */
gps_pwron_set(0);
/* Don't disable AVDD before PWRON is cleared, since
* in GTA01Bv3, AVDD and RFREG_IN are shared */
if (neo1973_gps.regulator_state[GTA01_GPS_REG_3V])
gps_power_3v_set(0);
/* Remove VDD_COREREG_IN, VDD_PLLREG_IN and VDD_REFREG_IN */
if (neo1973_gps.regulator_state[GTA01_GPS_REG_1V5])
gps_power_1v5_set(0);
if (neo1973_gps.regulator_state[GTA01_GPS_REG_2V5])
gps_power_2v5_set(0);
if (neo1973_gps.regulator_state[GTA01_GPS_REG_2V8])
gps_power_2v8_set(0);
/* Remove VDD_LPREG_IN and VDD_IO */
if (neo1973_gps.regulator_state[GTA01_GPS_REG_3V3])
gps_power_3v3_set(0);
}
static ssize_t power_sequence_read(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return strlcpy(buf, "power_up power_down\n", PAGE_SIZE);
}
static ssize_t power_sequence_write(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
dev_dbg(dev, "wrote: '%s'\n", buf);
if (!strncmp(buf, "power_up", 8))
gps_power_sequence_up();
else if (!strncmp(buf, "power_down", 10))
gps_power_sequence_down();
else
return -EINVAL;
return count;
}
static DEVICE_ATTR(power_tcxo_2v8, 0644, power_gps_read, power_gps_write);
static DEVICE_ATTR(power_avdd_3v, 0644, power_gps_read, power_gps_write);
static DEVICE_ATTR(reset, 0644, power_gps_read, power_gps_write);
static DEVICE_ATTR(power_lp_io_3v3, 0644, power_gps_read, power_gps_write);
static DEVICE_ATTR(power_pll_core_2v5, 0644, power_gps_read, power_gps_write);
static DEVICE_ATTR(power_core_1v5, 0644, power_gps_read, power_gps_write);
static DEVICE_ATTR(power_vdd_core_1v5, 0644, power_gps_read, power_gps_write);
static DEVICE_ATTR(power_sequence, 0644, power_sequence_read,
power_sequence_write);
#endif
#ifdef CONFIG_PM
static int gta01_pm_gps_suspend(struct platform_device *pdev,
pm_message_t state)
{
#ifdef CONFIG_MACH_NEO1973_GTA01
if (machine_is_neo1973_gta01())
/* FIXME */
gps_power_sequence_down();
#endif
if (machine_is_neo1973_gta02()) {
if (!neo1973_gps.keep_on_in_suspend ||
!neo1973_gps.power_was_on)
gps_pwron_set(0);
else
dev_warn(&pdev->dev, "GTA02: keeping gps ON "
"during suspend\n");
}
return 0;
}
static int gta01_pm_gps_resume(struct platform_device *pdev)
{
#ifdef CONFIG_MACH_NEO1973_GTA01
if (machine_is_neo1973_gta01())
if (neo1973_gps.power_was_on)
gps_power_sequence_up();
#endif
if (machine_is_neo1973_gta02())
if (!neo1973_gps.keep_on_in_suspend && neo1973_gps.power_was_on)
gps_pwron_set(1);
return 0;
}
static DEVICE_ATTR(keep_on_in_suspend, 0644, power_gps_read, power_gps_write);
#else
#define gta01_pm_gps_suspend NULL
#define gta01_pm_gps_resume NULL
#endif
static DEVICE_ATTR(power_on, 0644, power_gps_read, power_gps_write);
static DEVICE_ATTR(pwron, 0644, power_gps_read, power_gps_write);
static struct attribute *gta01_gps_sysfs_entries[] = {
&dev_attr_power_on.attr,
&dev_attr_pwron.attr,
#ifdef CONFIG_MACH_NEO1973_GTA01
&dev_attr_power_avdd_3v.attr,
&dev_attr_reset.attr,
&dev_attr_power_lp_io_3v3.attr,
&dev_attr_power_pll_core_2v5.attr,
&dev_attr_power_sequence.attr,
NULL, /* power_core_1v5 */
NULL, /* power_vdd_core_1v5 */
#endif
NULL /* terminating entry */
};
static struct attribute_group gta01_gps_attr_group = {
.name = NULL,
.attrs = gta01_gps_sysfs_entries,
};
static struct attribute *gta02_gps_sysfs_entries[] = {
&dev_attr_power_on.attr,
#ifdef CONFIG_PM
&dev_attr_keep_on_in_suspend.attr,
#endif
NULL
};
static struct attribute_group gta02_gps_attr_group = {
.name = NULL,
.attrs = gta02_gps_sysfs_entries,
};
static int __init gta01_pm_gps_probe(struct platform_device *pdev)
{
int ret;
#ifdef CONFIG_MACH_NEO1973_GTA01
int entries = ARRAY_SIZE(gta01_gps_sysfs_entries);
#endif
if (machine_is_neo1973_gta01()) {
s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_PWRON, S3C2410_GPIO_OUTPUT);
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
break;
case GTA01v4_SYSTEM_REV:
s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_RESET,
S3C2410_GPIO_OUTPUT);
break;
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_EN_3V3,
S3C2410_GPIO_OUTPUT);
/* fallthrough */
case GTA01Bv2_SYSTEM_REV:
s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_EN_2V8,
S3C2410_GPIO_OUTPUT);
s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_EN_3V,
S3C2410_GPIO_OUTPUT);
s3c2410_gpio_cfgpin(GTA01_GPIO_GPS_RESET,
S3C2410_GPIO_OUTPUT);
break;
default:
dev_warn(&pdev->dev, "Unknown GTA01 Revision 0x%x, "
"AGPS PM features not available!!!\n",
system_rev);
return -1;
break;
}
#ifdef CONFIG_MACH_NEO1973_GTA01
neo1973_gps.regulator[GTA01_GPS_REG_2V8] =
regulator_get(&pdev->dev, "GPS_2V8");
neo1973_gps.regulator[GTA01_GPS_REG_3V] =
regulator_get(&pdev->dev, "GPS_3V");
neo1973_gps.regulator[GTA01_GPS_REG_3V3] =
regulator_get(&pdev->dev, "GPS_3V3");
neo1973_gps.regulator[GTA01_GPS_REG_1V5] =
regulator_get(&pdev->dev, "GPS_1V5");
neo1973_gps.regulator[GTA01_GPS_REG_2V5] =
regulator_get(&pdev->dev, "GPS_2V5");
gps_power_sequence_down();
switch (S3C_SYSTEM_REV_ATAG) {
case GTA01v3_SYSTEM_REV:
case GTA01v4_SYSTEM_REV:
case GTA01Bv2_SYSTEM_REV:
gta01_gps_sysfs_entries[entries-3] =
&dev_attr_power_tcxo_2v8.attr;
break;
case GTA01Bv3_SYSTEM_REV:
case GTA01Bv4_SYSTEM_REV:
gta01_gps_sysfs_entries[entries-3] =
&dev_attr_power_core_1v5.attr;
gta01_gps_sysfs_entries[entries-2] =
&dev_attr_power_vdd_core_1v5.attr;
break;
}
#endif
ret = sysfs_create_group(&pdev->dev.kobj,
>a01_gps_attr_group);
if (ret)
return ret;
return bus_create_device_link(&platform_bus_type,
&pdev->dev.kobj, "gta01-pm-gps.0");
}
if (machine_is_neo1973_gta02()) {
neo1973_gps.regulator[GTA02_GPS_REG_RF_3V] = regulator_get(
&pdev->dev, "RF_3V");
if (IS_ERR(neo1973_gps.regulator)) {
dev_err(&pdev->dev, "probe failed %ld\n",
PTR_ERR(neo1973_gps.regulator));
return PTR_ERR(neo1973_gps.regulator);
}
dev_info(&pdev->dev, "starting\n");
/*
* Here we should call the code that handles the set GPS power
* off action. But, the regulator API does not allow us to
* reassert regulator state, and when we read the regulator API
* logical state, it can differ from the actual state, So
* a workaround for this is to just set the regulator off in the
* PMU directly. Because that's different from normal flow, we
* have to reproduce other things from the OFF action here too.
*/
/*
* u-boot enables LDO5 (GPS), which doesn't make sense and
* causes confusion. We therefore disable the regulator here.
*/
pcf50633_reg_write(gta02_pcf, PCF50633_REG_LDO5ENA, 0);
/*
* take care not to power unpowered GPS from UART TX
* return them to GPIO and force low
*/
s3c2410_gpio_cfgpin(S3C2410_GPH4, S3C2410_GPH4_OUTP);
s3c2410_gpio_setpin(S3C2410_GPH4, 0);
/* don't let RX from unpowered GPS float */
s3c2410_gpio_pullup(S3C2410_GPH5, 1);
return sysfs_create_group(&pdev->dev.kobj,
>a02_gps_attr_group);
}
return -1;
}
static int gta01_pm_gps_remove(struct platform_device *pdev)
{
if (machine_is_neo1973_gta01()) {
#ifdef CONFIG_MACH_NEO1973_GTA01
int i;
gps_power_sequence_down();
/* Now disable all regulators */
for (i = 0; i < GTA01_GPS_NUM_REG; i++) {
regulator_put(neo1973_gps.regulator[i]);
}
#endif
bus_remove_device_link(&platform_bus_type, "gta01-pm-gps.0");
sysfs_remove_group(&pdev->dev.kobj, >a01_gps_attr_group);
}
if (machine_is_neo1973_gta02()) {
regulator_put(neo1973_gps.regulator[GTA02_GPS_REG_RF_3V]);
sysfs_remove_group(&pdev->dev.kobj, >a02_gps_attr_group);
}
return 0;
}
static struct platform_driver gta01_pm_gps_driver = {
.probe = gta01_pm_gps_probe,
.remove = gta01_pm_gps_remove,
.suspend = gta01_pm_gps_suspend,
.resume = gta01_pm_gps_resume,
.driver = {
.name = "neo1973-pm-gps",
},
};
static int __devinit gta01_pm_gps_init(void)
{
return platform_driver_register(>a01_pm_gps_driver);
}
static void gta01_pm_gps_exit(void)
{
platform_driver_unregister(>a01_pm_gps_driver);
}
module_init(gta01_pm_gps_init);
module_exit(gta01_pm_gps_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
MODULE_DESCRIPTION("FIC Neo1973 GPS Power Management");
|