/
board-htcleo.c
1814 lines (1586 loc) · 46.6 KB
/
board-htcleo.c
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
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* linux/arch/arm/mach-msm/board-htcleo.c
*
* Copyright (C) 2009 Google, Inc.
* Copyright (C) 2009 HTC Corporation.
* Author: Dima Zavin <dima@android.com>
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/i2c.h>
#include <linux/i2c-msm.h>
#include <linux/init.h>
#include <linux/input.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/bootmem.h>
#include <linux/platform_device.h>
#include <linux/android_pmem.h>
#include <linux/regulator/machine.h>
#include <linux/usb/composite.h>
#include <linux/usb/android_composite.h>
#include <linux/leds.h>
#include <linux/spi/spi.h>
#include <linux/bma150.h>
#include <linux/akm8973.h>
#include <../../../drivers/staging/android/timed_gpio.h>
#include <linux/ds2746_battery.h>
#include <linux/msm_kgsl.h>
#include <linux/regulator/machine.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include <asm/mach/map.h>
#include <asm/setup.h>
#include <mach/board.h>
#include <mach/board_htc.h>
#include <mach/hardware.h>
#include <mach/system.h>
#include <mach/msm_iomap.h>
#include <mach/perflock.h>
#include <mach/htc_usb.h>
#include <mach/msm_flashlight.h>
#include <mach/msm_serial_hs.h>
#ifdef CONFIG_USB_MSM_OTG_72K
#include <mach/msm_hsusb.h>
#else
#include <linux/usb/msm_hsusb.h>
#endif
#include <mach/msm_hsusb_hw.h>
#ifdef CONFIG_SERIAL_BCM_BT_LPM
#include <mach/bcm_bt_lpm.h>
#endif
#include <mach/htc_headset_mgr.h>
#include <mach/htc_headset_gpio.h>
#include <mach/board-htcleo-mac.h>
#include <mach/board-htcleo-microp.h>
#include <mach/board-htcleo-ts.h>
#include <mach/socinfo.h>
#include <mach/msm_memtypes.h>
#include "acpuclock.h"
#include "board-htcleo.h"
#include "devices.h"
#include "proc_comm.h"
#include "dex_comm.h"
#include "footswitch.h"
#include "pm.h"
#include "pm-boot.h"
#define ATAG_MAGLDR_BOOT 0x4C47414D
struct tag_magldr_entry
{
_Bool fNoNandBoot;
};
extern int __init htcleo_init_mmc(unsigned debug_uart);
extern void __init htcleo_audio_init(void);
extern unsigned char *get_bt_bd_ram(void);
static unsigned int nand_boot = 0;
///////////////////////////////////////////////////////////////////////
// Nand boot Option
///////////////////////////////////////////////////////////////////////
int htcleo_is_nand_boot(void)
{
return nand_boot;
}
static int __init parse_tag_nand_boot(const struct tag *tag)
{
struct tag_magldr_entry *mentry = (struct tag_magldr_entry *)(&tag->u);
nand_boot = !(unsigned int)mentry->fNoNandBoot;
if(*((unsigned*)&tag->u)==0x004b4c63) nand_boot = 2; // cLK signature
pr_info("Nand Boot: %d\n", nand_boot);
return 0;
}
__tagtable(ATAG_MAGLDR_BOOT, parse_tag_nand_boot);
///////////////////////////////////////////////////////////////////////
// Regulator
///////////////////////////////////////////////////////////////////////
static struct regulator_consumer_supply tps65023_dcdc1_supplies[] =
{
{
.supply = "acpu_vcore",
},
};
static struct regulator_init_data tps65023_data[5] =
{
{
.constraints = {
.name = "dcdc1", /* VREG_MSMC2_1V29 */
.min_uV = HTCLEO_TPS65023_MIN_UV_MV * 1000,
.max_uV = HTCLEO_TPS65023_MAX_UV_MV * 1000,
.valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
},
.consumer_supplies = tps65023_dcdc1_supplies,
.num_consumer_supplies = ARRAY_SIZE(tps65023_dcdc1_supplies),
},
/* dummy values for unused regulators to not crash driver: */
{
.constraints = {
.name = "dcdc2", /* VREG_MSMC1_1V26 */
.min_uV = 1260000,
.max_uV = 1260000,
},
},
{
.constraints = {
.name = "dcdc3", /* unused */
.min_uV = 800000,
.max_uV = 3300000,
},
},
{
.constraints = {
.name = "ldo1", /* unused */
.min_uV = 1000000,
.max_uV = 3150000,
},
},
{
.constraints = {
.name = "ldo2", /* V_USBPHY_3V3 */
.min_uV = 3300000,
.max_uV = 3300000,
},
},
};
///////////////////////////////////////////////////////////////////////
// Headset
///////////////////////////////////////////////////////////////////////
static struct htc_headset_mgr_platform_data htc_headset_mgr_data = {
};
static struct platform_device htc_headset_mgr = {
.name = "HTC_HEADSET_MGR",
.id = -1,
.dev = {
.platform_data = &htc_headset_mgr_data,
},
};
static struct htc_headset_gpio_platform_data htc_headset_gpio_data = {
.hpin_gpio = HTCLEO_GPIO_HDS_DET,
.mic_detect_gpio = HTCLEO_GPIO_HDS_MIC,
.microp_channel = 1,
.key_enable_gpio = 0,
.mic_select_gpio = 0,
};
static struct platform_device htc_headset_gpio = {
.name = "HTC_HEADSET_GPIO",
.id = -1,
.dev = {
.platform_data = &htc_headset_gpio_data,
},
};
///////////////////////////////////////////////////////////////////////
// Compass
///////////////////////////////////////////////////////////////////////
static struct akm8973_platform_data compass_platform_data =
{
.layouts = HTCLEO_LAYOUTS,
.project_name = HTCLEO_PROJECT_NAME,
.reset = HTCLEO_GPIO_COMPASS_RST_N,
.intr = HTCLEO_GPIO_COMPASS_INT_N,
};
///////////////////////////////////////////////////////////////////////
// LED Driver (drivers/leds/leds-microp.c - Atmega microp driver
///////////////////////////////////////////////////////////////////////
static struct microp_led_config led_config[] = {
{
.name = "amber",
.type = LED_RGB,
},
{
.name = "green",
.type = LED_RGB,
},
};
static struct microp_led_platform_data microp_leds_data = {
.num_leds = ARRAY_SIZE(led_config),
.led_config = led_config,
};
///////////////////////////////////////////////////////////////////////
// Microp
///////////////////////////////////////////////////////////////////////
static struct bma150_platform_data htcleo_g_sensor_pdata = {
.microp_new_cmd = 0,
.chip_layout = 1,
};
static struct platform_device microp_devices[] = {
{
.name = BMA150_G_SENSOR_NAME,
.dev = {
.platform_data = &htcleo_g_sensor_pdata,
},
},
{
.name = "htcleo-backlight",
.id = -1,
},
{
.name = "htcleo-proximity",
.id = -1,
},
{
.name = "leds-microp",
.id = -1,
.dev = {
.platform_data = µp_leds_data,
},
},
{
.name = "htcleo-lsensor",
.id = -1,
},
};
static struct microp_i2c_platform_data microp_data = {
.num_devices = ARRAY_SIZE(microp_devices),
.microp_devices = microp_devices,
.gpio_reset = HTCLEO_GPIO_UP_RESET_N,
};
static struct i2c_board_info base_i2c_devices[] =
{
{
// Only a dummy
I2C_BOARD_INFO(LEO_TOUCH_DRV_NAME, 0x22),
},
{
I2C_BOARD_INFO("tps65023", 0x48),
.platform_data = tps65023_data,
},
{
I2C_BOARD_INFO(MICROP_I2C_NAME, 0xCC >> 1),
.platform_data = µp_data,
.irq = MSM_GPIO_TO_INT(HTCLEO_GPIO_UP_INT_N)
},
{
I2C_BOARD_INFO(AKM8973_I2C_NAME, 0x1C),
.platform_data = &compass_platform_data,
.irq = MSM_GPIO_TO_INT(HTCLEO_GPIO_COMPASS_INT_N),
},
{
I2C_BOARD_INFO("s5k3e2fx", 0x20 >> 1),
},
};
///////////////////////////////////////////////////////////////////////
// USB
///////////////////////////////////////////////////////////////////////
static unsigned ulpi_on_gpio_table[] = {
GPIO_CFG(0x68, 1, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA),
GPIO_CFG(0x6f, 1, GPIO_INPUT, GPIO_NO_PULL, GPIO_2MA),
GPIO_CFG(0x70, 1, GPIO_INPUT, GPIO_NO_PULL, GPIO_2MA),
GPIO_CFG(0x71, 1, GPIO_INPUT, GPIO_NO_PULL, GPIO_2MA),
GPIO_CFG(0x72, 1, GPIO_INPUT, GPIO_NO_PULL, GPIO_2MA),
GPIO_CFG(0x73, 1, GPIO_INPUT, GPIO_NO_PULL, GPIO_2MA),
GPIO_CFG(0x74, 1, GPIO_INPUT, GPIO_NO_PULL, GPIO_2MA),
GPIO_CFG(0x75, 1, GPIO_INPUT, GPIO_NO_PULL, GPIO_2MA),
GPIO_CFG(0x76, 1, GPIO_INPUT, GPIO_NO_PULL, GPIO_2MA),
GPIO_CFG(0x77, 1, GPIO_INPUT, GPIO_NO_PULL, GPIO_2MA),
GPIO_CFG(0x78, 1, GPIO_INPUT, GPIO_NO_PULL, GPIO_2MA),
GPIO_CFG(0x79, 1, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA),
};
static unsigned ulpi_off_gpio_table[] = {
GPIO_CFG(0x68, 1, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_4MA),
GPIO_CFG(0x6f, 1, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_2MA),
GPIO_CFG(0x70, 1, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_2MA),
GPIO_CFG(0x71, 1, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_2MA),
GPIO_CFG(0x72, 1, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_2MA),
GPIO_CFG(0x73, 1, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_2MA),
GPIO_CFG(0x74, 1, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_2MA),
GPIO_CFG(0x75, 1, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_2MA),
GPIO_CFG(0x76, 1, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_2MA),
GPIO_CFG(0x77, 1, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_2MA),
GPIO_CFG(0x78, 1, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_2MA),
GPIO_CFG(0x79, 1, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_2MA),
};
static void usb_gpio_init(void)
{
if (gpio_request(0x68, "htcleo_3v3_enable"))
pr_err("failed to request gpio htcleo_3v3_enable\n");
if (gpio_request(0x6f, "ulpi_data_0"))
pr_err("failed to request gpio ulpi_data_0\n");
if (gpio_request(0x70, "ulpi_data_1"))
pr_err("failed to request gpio ulpi_data_1\n");
if (gpio_request(0x71, "ulpi_data_2"))
pr_err("failed to request gpio ulpi_data_2\n");
if (gpio_request(0x72, "ulpi_data_3"))
pr_err("failed to request gpio ulpi_data_3\n");
if (gpio_request(0x73, "ulpi_data_4"))
pr_err("failed to request gpio ulpi_data_4\n");
if (gpio_request(0x74, "ulpi_data_5"))
pr_err("failed to request gpio ulpi_data_5\n");
if (gpio_request(0x75, "ulpi_data_6"))
pr_err("failed to request gpio ulpi_data_6\n");
if (gpio_request(0x76, "ulpi_data_7"))
pr_err("failed to request gpio ulpi_data_7\n");
if (gpio_request(0x77, "ulpi_dir"))
pr_err("failed to request gpio ulpi_dir\n");
if (gpio_request(0x78, "ulpi_next"))
pr_err("failed to request gpio ulpi_next\n");
if (gpio_request(0x79, "ulpi_stop"))
pr_err("failed to request gpio ulpi_stop\n");
}
static int usb_config_gpio(int config)
{
int pin, rc;
if (config) {
for (pin = 0; pin < ARRAY_SIZE(ulpi_on_gpio_table); pin++) {
rc = gpio_tlmm_config(ulpi_on_gpio_table[pin],
GPIO_CFG_ENABLE);
if (rc) {
printk(KERN_ERR
"%s: gpio_tlmm_config(%#x)=%d\n",
__func__, ulpi_off_gpio_table[pin], rc);
return -EIO;
}
}
} else {
for (pin = 0; pin < ARRAY_SIZE(ulpi_off_gpio_table); pin++) {
rc = gpio_tlmm_config(ulpi_off_gpio_table[pin],
GPIO_CFG_ENABLE);
if (rc) {
printk(KERN_ERR
"%s: gpio_tlmm_config(%#x)=%d\n",
__func__, ulpi_on_gpio_table[pin], rc);
return -EIO;
}
}
}
return 0;
}
static void usb_phy_shutdown(void)
{
printk("%s: %s\n", __FILE__, __func__);
gpio_set_value(HTCLEO_GPIO_USBPHY_3V3_ENABLE, 1);
mdelay(3);
gpio_set_value(HTCLEO_GPIO_USBPHY_3V3_ENABLE, 0);
mdelay(3);
}
int usb_phy_reset(void __iomem *regs)
{
printk("%s: %s\n", __FILE__, __func__);
usb_phy_shutdown();
gpio_set_value(HTCLEO_GPIO_USBPHY_3V3_ENABLE, 0);
mdelay(3);
gpio_set_value(HTCLEO_GPIO_USBPHY_3V3_ENABLE, 1);
mdelay(3);
usb_config_gpio(1);
return 0;
}
#define USB_LINK_RESET_TIMEOUT (msecs_to_jiffies(10))
#define CLKRGM_APPS_RESET_USBH 37
#define CLKRGM_APPS_RESET_USB_PHY 34
#define ULPI_VERIFY_MAX_LOOP_COUNT 3
static void *usb_base;
#ifndef MSM_USB_BASE
#define MSM_USB_BASE ((unsigned)usb_base)
#endif
static unsigned htcleo_ulpi_read(void __iomem *usb_base, unsigned reg)
{
unsigned timeout = 100000;
/* initiate read operation */
writel(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg),
USB_ULPI_VIEWPORT);
/* wait for completion */
while ((readl(USB_ULPI_VIEWPORT) & ULPI_RUN) && (--timeout))
cpu_relax();
if (timeout == 0) {
printk(KERN_ERR "ulpi_read: timeout %08x\n",
readl(USB_ULPI_VIEWPORT));
return 0xffffffff;
}
return ULPI_DATA_READ(readl(USB_ULPI_VIEWPORT));
}
static int htcleo_ulpi_write(void __iomem *usb_base, unsigned val, unsigned reg)
{
unsigned timeout = 10000;
/* initiate write operation */
writel(ULPI_RUN | ULPI_WRITE |
ULPI_ADDR(reg) | ULPI_DATA(val),
USB_ULPI_VIEWPORT);
/* wait for completion */
while ((readl(USB_ULPI_VIEWPORT) & ULPI_RUN) && (--timeout))
cpu_relax();
if (timeout == 0) {
printk(KERN_ERR "ulpi_write: timeout\n");
return -1;
}
return 0;
}
void msm_hsusb_apps_reset_link(int reset)
{
int ret;
unsigned usb_id = CLKRGM_APPS_RESET_USBH;
if (reset)
ret = msm_proc_comm(PCOM_CLK_REGIME_SEC_RESET_ASSERT,
&usb_id, NULL);
else
ret = msm_proc_comm(PCOM_CLK_REGIME_SEC_RESET_DEASSERT,
&usb_id, NULL);
if (ret)
printk(KERN_INFO "%s: Cannot set reset to %d (%d)\n",
__func__, reset, ret);
}
EXPORT_SYMBOL(msm_hsusb_apps_reset_link);
void msm_hsusb_apps_reset_phy(void)
{
int ret;
unsigned usb_phy_id = CLKRGM_APPS_RESET_USB_PHY;
ret = msm_proc_comm(PCOM_CLK_REGIME_SEC_RESET_ASSERT,
&usb_phy_id, NULL);
if (ret) {
printk(KERN_INFO "%s: Cannot assert (%d)\n", __func__, ret);
return;
}
msleep(1);
ret = msm_proc_comm(PCOM_CLK_REGIME_SEC_RESET_DEASSERT,
&usb_phy_id, NULL);
if (ret) {
printk(KERN_INFO "%s: Cannot assert (%d)\n", __func__, ret);
return;
}
}
EXPORT_SYMBOL(msm_hsusb_apps_reset_phy);
static int msm_hsusb_phy_verify_access(void __iomem *usb_base)
{
int temp;
for (temp = 0; temp < ULPI_VERIFY_MAX_LOOP_COUNT; temp++) {
if (htcleo_ulpi_read(usb_base, ULPI_DEBUG) != (unsigned)-1)
break;
msm_hsusb_apps_reset_phy();
}
if (temp == ULPI_VERIFY_MAX_LOOP_COUNT) {
pr_err("%s: ulpi read failed for %d times\n",
__func__, ULPI_VERIFY_MAX_LOOP_COUNT);
return -1;
}
return 0;
}
static unsigned msm_hsusb_ulpi_read_with_reset(void __iomem *usb_base, unsigned reg)
{
int temp;
unsigned res;
for (temp = 0; temp < ULPI_VERIFY_MAX_LOOP_COUNT; temp++) {
res = htcleo_ulpi_read(usb_base, reg);
if (res != -1)
return res;
msm_hsusb_apps_reset_phy();
}
pr_err("%s: ulpi read failed for %d times\n",
__func__, ULPI_VERIFY_MAX_LOOP_COUNT);
return -1;
}
static int msm_hsusb_ulpi_write_with_reset(void __iomem *usb_base,
unsigned val, unsigned reg)
{
int temp;
int res;
for (temp = 0; temp < ULPI_VERIFY_MAX_LOOP_COUNT; temp++) {
res = htcleo_ulpi_write(usb_base, val, reg);
if (!res)
return 0;
msm_hsusb_apps_reset_phy();
}
pr_err("%s: ulpi write failed for %d times\n",
__func__, ULPI_VERIFY_MAX_LOOP_COUNT);
return -1;
}
static int msm_hsusb_phy_caliberate(void __iomem *usb_base)
{
int ret;
unsigned res;
ret = msm_hsusb_phy_verify_access(usb_base);
if (ret)
return -ETIMEDOUT;
res = msm_hsusb_ulpi_read_with_reset(usb_base, ULPI_FUNC_CTRL_CLR);
if (res == -1)
return -ETIMEDOUT;
res = msm_hsusb_ulpi_write_with_reset(usb_base,
res | ULPI_SUSPENDM,
ULPI_FUNC_CTRL_CLR);
if (res)
return -ETIMEDOUT;
msm_hsusb_apps_reset_phy();
return msm_hsusb_phy_verify_access(usb_base);
}
void msm_hsusb_8x50_phy_reset(void)
{
u32 temp;
unsigned long timeout;
int ret, usb_phy_error;
printk(KERN_INFO "msm_hsusb_phy_reset\n");
usb_base = ioremap(MSM_HSUSB_PHYS, 4096);
msm_hsusb_apps_reset_link(1);
msm_hsusb_apps_reset_phy();
msm_hsusb_apps_reset_link(0);
/* select ULPI phy */
temp = (readl(USB_PORTSC) & ~PORTSC_PTS);
writel(temp | PORTSC_PTS_ULPI, USB_PORTSC);
if ((ret = msm_hsusb_phy_caliberate(usb_base))) {
usb_phy_error = 1;
pr_err("msm_hsusb_phy_caliberate returned with %i\n", ret);
return;
}
/* soft reset phy */
writel(USBCMD_RESET, USB_USBCMD);
timeout = jiffies + USB_LINK_RESET_TIMEOUT;
while (readl(USB_USBCMD) & USBCMD_RESET) {
if (time_after(jiffies, timeout)) {
pr_err("usb link reset timeout\n");
break;
}
msleep(1);
}
usb_phy_error = 0;
return;
}
#if 0
static struct msm_otg_platform_data msm_otg_pdata = {
.phy_reset = msm_hsusb_8x50_phy_reset,
.pemp_level = PRE_EMPHASIS_WITH_20_PERCENT,
.cdr_autoreset = CDR_AUTO_RESET_DISABLE,
.drv_ampl = HS_DRV_AMPLITUDE_DEFAULT,
.se1_gating = SE1_GATING_DISABLE,
};
#else
static int htcleo_phy_init_seq[] ={0x0C, 0x31, 0x30, 0x32, 0x1D, 0x0D, 0x1D, 0x10, -1};
static struct msm_otg_platform_data msm_otg_pdata = {
.phy_init_seq = htcleo_phy_init_seq,
.mode = USB_PERIPHERAL,
.otg_control = OTG_PHY_CONTROL,
};
#endif
#if 0
static struct msm_hsusb_gadget_platform_data msm_gadget_pdata = {
.is_phy_status_timer_on = 1,
};
#endif
static uint32_t usb_phy_3v3_table[] =
{
PCOM_GPIO_CFG(HTCLEO_GPIO_USBPHY_3V3_ENABLE, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA)
};
#if 0
// modified to further reflect bravo kernel code
static struct msm_hsusb_platform_data msm_hsusb_pdata = {
.phy_init_seq = htcleo_phy_init_seq,
.phy_reset = msm_hsusb_8x50_phy_reset,
.accessory_detect = 0, /* detect by ID pin gpio */
};
#endif
static struct usb_mass_storage_platform_data mass_storage_pdata = {
.nluns = 1,
.vendor = "HTC",
.product = "HD2",
.release = 0x0100,
};
static struct platform_device usb_mass_storage_device = {
.name = "usb_mass_storage",
.id = -1,
.dev = {
.platform_data = &mass_storage_pdata,
},
};
#ifdef CONFIG_USB_ANDROID_RNDIS
static struct usb_ether_platform_data rndis_pdata = {
.vendorID = 0x0bb4,
.vendorDescr = "HTC",
};
static struct platform_device rndis_device = {
.name = "rndis",
.id = -1,
.dev = {
.platform_data = &rndis_pdata,
},
};
#endif
static struct android_usb_platform_data android_usb_pdata = {
.vendor_id = 0x0bb4,
.product_id = 0x0c02,
.version = 0x0100,
.product_name = "HD2",
.manufacturer_name = "HTC",
.num_products = ARRAY_SIZE(usb_products),
.products = usb_products,
.num_functions = ARRAY_SIZE(usb_functions_all),
.functions = usb_functions_all,
};
static struct platform_device android_usb_device = {
.name = "android_usb",
.id = -1,
.dev = {
.platform_data = &android_usb_pdata,
},
};
static void htcleo_add_usb_devices(void)
{
#if 0
android_usb_pdata.products[0].product_id =
android_usb_pdata.product_id;
android_usb_pdata.serial_number = board_serialno();
msm_hsusb_pdata.serial_number = board_serialno();
msm_device_hsusb.dev.platform_data = &msm_hsusb_pdata;
config_gpio_table(usb_phy_3v3_table, ARRAY_SIZE(usb_phy_3v3_table));
gpio_set_value(HTCLEO_GPIO_USBPHY_3V3_ENABLE, 1);
platform_device_register(&msm_device_hsusb);
platform_device_register(&usb_mass_storage_device);
#ifdef CONFIG_USB_ANDROID_RNDIS
platform_device_register(&rndis_device);
#endif
#endif
msm_device_otg.dev.platform_data = &msm_otg_pdata;
//msm_device_gadget_peripheral.dev.platform_data = &msm_gadget_pdata;
msm_device_gadget_peripheral.dev.parent = &msm_device_otg.dev;
usb_gpio_init();
platform_device_register(&msm_device_gadget_peripheral);
platform_device_register(&android_usb_device);
}
unsigned htcleo_get_vbus_state(void)
{
if(readl(MSM_SHARED_RAM_BASE+0xef20c))
return 1;
else
return 0;
}
///////////////////////////////////////////////////////////////////////
// Flashlight
///////////////////////////////////////////////////////////////////////
static uint32_t flashlight_gpio_table[] =
{
PCOM_GPIO_CFG(HTCLEO_GPIO_FLASHLIGHT_TORCH, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA),
PCOM_GPIO_CFG(HTCLEO_GPIO_FLASHLIGHT_FLASH, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA),
};
static void config_htcleo_flashlight_gpios(void)
{
config_gpio_table(flashlight_gpio_table, ARRAY_SIZE(flashlight_gpio_table));
}
static struct flashlight_platform_data htcleo_flashlight_data =
{
.gpio_init = config_htcleo_flashlight_gpios,
.torch = HTCLEO_GPIO_FLASHLIGHT_TORCH,
.flash = HTCLEO_GPIO_FLASHLIGHT_FLASH,
.flash_duration_ms = 600
};
static struct platform_device htcleo_flashlight_device =
{
.name = "flashlight",
.dev =
{
.platform_data = &htcleo_flashlight_data,
},
};
///////////////////////////////////////////////////////////////////////
// Camera
///////////////////////////////////////////////////////////////////////
static uint32_t camera_off_gpio_table[] =
{
PCOM_GPIO_CFG(0, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* DAT0 */
PCOM_GPIO_CFG(1, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* DAT1 */
PCOM_GPIO_CFG(2, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* DAT2 */
PCOM_GPIO_CFG(3, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* DAT3 */
PCOM_GPIO_CFG(4, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* DAT4 */
PCOM_GPIO_CFG(5, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* DAT5 */
PCOM_GPIO_CFG(6, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* DAT6 */
PCOM_GPIO_CFG(7, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* DAT7 */
PCOM_GPIO_CFG(8, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* DAT8 */
PCOM_GPIO_CFG(9, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* DAT9 */
PCOM_GPIO_CFG(10, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* DAT10 */
PCOM_GPIO_CFG(11, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* DAT11 */
PCOM_GPIO_CFG(12, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* PCLK */
PCOM_GPIO_CFG(13, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* HSYNC */
PCOM_GPIO_CFG(14, 0, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_4MA), /* VSYNC */
PCOM_GPIO_CFG(15, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* MCLK */
};
static uint32_t camera_on_gpio_table[] =
{
PCOM_GPIO_CFG(0, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* DAT0 */
PCOM_GPIO_CFG(1, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* DAT1 */
PCOM_GPIO_CFG(2, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* DAT2 */
PCOM_GPIO_CFG(3, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* DAT3 */
PCOM_GPIO_CFG(4, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* DAT4 */
PCOM_GPIO_CFG(5, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* DAT5 */
PCOM_GPIO_CFG(6, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* DAT6 */
PCOM_GPIO_CFG(7, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* DAT7 */
PCOM_GPIO_CFG(8, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* DAT8 */
PCOM_GPIO_CFG(9, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* DAT9 */
PCOM_GPIO_CFG(10, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* DAT10 */
PCOM_GPIO_CFG(11, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* DAT11 */
PCOM_GPIO_CFG(12, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_16MA), /* PCLK */
PCOM_GPIO_CFG(13, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* HSYNC */
PCOM_GPIO_CFG(14, 1, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA), /* VSYNC */
PCOM_GPIO_CFG(15, 1, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* MCLK */
};
int config_camera_on_gpios(void)
{
config_gpio_table(camera_on_gpio_table, ARRAY_SIZE(camera_on_gpio_table));
return 0;
}
void config_camera_off_gpios(void)
{
config_gpio_table(camera_off_gpio_table, ARRAY_SIZE(camera_off_gpio_table));
}
static struct resource msm_camera_resources[] =
{
{
.start = MSM_VFE_PHYS,
.end = MSM_VFE_PHYS + MSM_VFE_SIZE - 1,
.flags = IORESOURCE_MEM,
},
{
.start = INT_VFE,
INT_VFE,
.flags = IORESOURCE_IRQ,
},
};
static struct msm_camera_device_platform_data msm_camera_device_data =
{
.camera_gpio_on = config_camera_on_gpios,
.camera_gpio_off = config_camera_off_gpios,
.ioext.mdcphy = MSM_MDC_PHYS,
.ioext.mdcsz = MSM_MDC_SIZE,
.ioext.appphy = MSM_CLK_CTL_PHYS,
.ioext.appsz = MSM_CLK_CTL_SIZE,
};
static int flashlight_control(int mode)
{
return aat1271_flashlight_control(mode);
}
static struct camera_flash_cfg msm_camera_sensor_flash_cfg = {
.camera_flash = flashlight_control,
.num_flash_levels = FLASHLIGHT_NUM,
.low_temp_limit = 5,
.low_cap_limit = 15,
};
static struct msm_camera_sensor_info msm_camera_sensor_s5k3e2fx_data =
{
.sensor_name = "s5k3e2fx",
.sensor_reset = 144,
/* CAM1_PWDN, enabled in a9 */
//.sensor_pwd = 143,
/* CAM1_VCM_EN, enabled in a9 */
//.vcm_pwd = 31,
.pdata = &msm_camera_device_data,
.flash_type = MSM_CAMERA_FLASH_LED,
.resource = msm_camera_resources,
.num_resources = ARRAY_SIZE(msm_camera_resources),
.flash_cfg = &msm_camera_sensor_flash_cfg,
};
static struct platform_device msm_camera_sensor_s5k3e2fx =
{
.name = "msm_camera_s5k3e2fx",
.dev = {
.platform_data = &msm_camera_sensor_s5k3e2fx_data,
},
};
///////////////////////////////////////////////////////////////////////
// bluetooth
///////////////////////////////////////////////////////////////////////
/* AOSP style interface */
/*
* bluetooth mac address will be parsed in msm_nand_probe
* see drivers/mtd/devices/htcleo_nand.c
*/
char bdaddr[BDADDR_STR_SIZE];
module_param_string(bdaddr, bdaddr, sizeof(bdaddr), 0400);
MODULE_PARM_DESC(bdaddr, "bluetooth address");
/* end AOSP style interface */
#ifdef CONFIG_SERIAL_MSM_HS
static struct msm_serial_hs_platform_data msm_uart_dm1_pdata = {
.rx_wakeup_irq = -1,
.inject_rx_on_wakeup = 0,
#ifdef CONFIG_SERIAL_BCM_BT_LPM
.exit_lpm_cb = bcm_bt_lpm_exit_lpm_locked,
#endif
};
#ifdef CONFIG_SERIAL_BCM_BT_LPM
static struct bcm_bt_lpm_platform_data bcm_bt_lpm_pdata = {
.gpio_wake = HTCLEO_GPIO_BT_CHIP_WAKE,
.gpio_host_wake = HTCLEO_GPIO_BT_HOST_WAKE,
.request_clock_off_locked = msm_hs_request_clock_off,
.request_clock_on_locked = msm_hs_request_clock_on_locked,
};
struct platform_device bcm_bt_lpm_device = {
.name = "bcm_bt_lpm",
.id = 0,
.dev = {
.platform_data = &bcm_bt_lpm_pdata,
},
};
#endif
#endif
static uint32_t bt_gpio_table[] = {
PCOM_GPIO_CFG(HTCLEO_GPIO_BT_UART1_RTS, 2, GPIO_OUTPUT,
GPIO_PULL_UP, GPIO_8MA),
PCOM_GPIO_CFG(HTCLEO_GPIO_BT_UART1_CTS, 2, GPIO_INPUT,
GPIO_PULL_UP, GPIO_8MA),
PCOM_GPIO_CFG(HTCLEO_GPIO_BT_UART1_RX, 2, GPIO_INPUT,
GPIO_PULL_UP, GPIO_8MA),
PCOM_GPIO_CFG(HTCLEO_GPIO_BT_UART1_TX, 2, GPIO_OUTPUT,
GPIO_PULL_UP, GPIO_8MA),
PCOM_GPIO_CFG(HTCLEO_GPIO_BT_RESET_N, 0, GPIO_OUTPUT,
GPIO_PULL_DOWN, GPIO_4MA),
PCOM_GPIO_CFG(HTCLEO_GPIO_BT_SHUTDOWN_N, 0, GPIO_OUTPUT,
GPIO_PULL_DOWN, GPIO_4MA),
PCOM_GPIO_CFG(HTCLEO_GPIO_BT_CHIP_WAKE, 0, GPIO_OUTPUT,
GPIO_PULL_DOWN, GPIO_4MA),
PCOM_GPIO_CFG(HTCLEO_GPIO_BT_HOST_WAKE, 0, GPIO_INPUT,
GPIO_PULL_DOWN, GPIO_4MA),
};
static struct platform_device htcleo_rfkill =
{
.name = "htcleo_rfkill",
.id = -1,
};
///////////////////////////////////////////////////////////////////////
// PM Platform data
///////////////////////////////////////////////////////////////////////
static struct msm_pm_platform_data msm_pm_data[MSM_PM_SLEEP_MODE_NR] = {
[MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = {
.idle_supported = 1,
.suspend_supported = 1,
.idle_enabled = 1,
.suspend_enabled = 1,
.latency = 8594,
.residency = 23740,
},
[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN] = {
.idle_supported = 1,
.suspend_supported = 1,
.idle_enabled = 1,
.suspend_enabled = 1,
.latency = 4594,
.residency = 23740,
},
[MSM_PM_SLEEP_MODE_RAMP_DOWN_AND_WAIT_FOR_INTERRUPT] = {
.idle_supported = 1,
.suspend_supported = 1,
.idle_enabled = 0,
.suspend_enabled = 1,
.latency = 443,
.residency = 1098,
},
[MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT] = {
.idle_supported = 1,
.suspend_supported = 1,
.idle_enabled = 1,
.suspend_enabled = 1,
.latency = 2,
.residency = 0,
},
};
///////////////////////////////////////////////////////////////////////
// SPI
///////////////////////////////////////////////////////////////////////
static struct resource qsd_spi_resources[] = {
{
.name = "spi_irq_in",