qisda-utils.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * qisda-utils.c
  3. *
  4. * Copyright 2009 Bookeen/Qisda
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. * MA 02110-1301, USA.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/types.h>
  23. #include <linux/init.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/input.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/miscdevice.h>
  28. #include <linux/irq.h>
  29. #include <asm/arch/regs-irq.h>
  30. #include <asm/hardware.h>
  31. #include <asm/io.h>
  32. #include <asm/delay.h>
  33. #include <asm/irq.h>
  34. #include <asm/arch/regs-udc-hs.h>
  35. #include <asm/arch/regs-s3c2416-clock.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/mach/map.h>
  38. #include <asm/mach/irq.h>
  39. #include <asm/setup.h>
  40. #include <asm/hardware.h>
  41. #include <asm/io.h>
  42. #include <asm/irq.h>
  43. #include <asm/mach-types.h>
  44. #include <asm/arch/regs-serial.h>
  45. #include <asm/arch/regs-gpio.h>
  46. #include <asm/arch/regs-gpioj.h>
  47. #include <asm/arch/regs-lcd.h>
  48. #include <asm/arch/regs-mem.h>
  49. #include <asm/plat-s3c24xx/s3c2410.h>
  50. #include <asm/plat-s3c24xx/s3c2440.h>
  51. #include <asm/plat-s3c24xx/clock.h>
  52. #include <asm/plat-s3c24xx/devs.h>
  53. #include <asm/plat-s3c24xx/cpu.h>
  54. #include <asm/plat-s3c24xx/common-smdk.h>
  55. int charging_source = 3;
  56. EXPORT_SYMBOL(charging_source);
  57. /* Qisda, ShiYong Lin, 2009/09/10, Detect insertion source {*/
  58. /*Leo*/
  59. int IsWallCharger(void)
  60. {
  61. /*u32 i=0;*/
  62. /*u32 i=0;*/
  63. u32 read_pin=99;/*, test_pin = 99;*/
  64. udelay(1000);
  65. if((readl(S3C2410_GPGDAT)&0x2)==0x2){
  66. s3c2410_gpio_cfgpin(S3C2443_GPH14, S3C2443_GPH14_OUTP);
  67. s3c2410_gpio_setpin(S3C2443_GPH14, 1); /* usb power enbale */
  68. s3c2410_gpio_cfgpin(S3C2410_GPD13, S3C2410_GPD13_OUTP);
  69. s3c2410_gpio_setpin(S3C2410_GPD13,1); /* usb power enbale */
  70. /* if reset by sleep wakeup, control the retention I/O cell */
  71. if (__raw_readl(S3C_RSTSTAT) & 0x8)
  72. __raw_writel(__raw_readl(S3C_RSTCON)|(1<<16), S3C_RSTCON);
  73. __raw_writel(__raw_readl(S3C2410_MISCCR)&~(1<<12), S3C2410_MISCCR);
  74. __raw_writel(__raw_readl(S3C_PWRCFG)|(1<<4), S3C_PWRCFG);
  75. __raw_writel((0<<2)|(1<<0), S3C_URSTCON);
  76. udelay(1000);
  77. __raw_writel((1<<2)|(0<<0), S3C_URSTCON);
  78. __raw_writel((0<<2)|(0<<0), S3C_URSTCON);
  79. __raw_writel((0<<3)|(0<<2)|(0<<1)|(0<<0), S3C_PHYCTRL);
  80. __raw_writel((1<<31)|(0<<4)|(0<<3)|(0<<2)|(0<<1)|(0<<0), S3C_PHYPWR);
  81. __raw_writel((0<<31)|(1<<2)|(1<<1)|(1<<0), S3C_UCLKCON);
  82. __raw_writel((1<<31)|(1<<2)|(1<<1)|(1<<0), S3C_UCLKCON);
  83. }
  84. read_pin = __raw_readl(S3C_UDC_SYS_STATUS_REG)&0x60;
  85. if(read_pin !=0x60){
  86. // printk("usb\n");
  87. #if defined(CONFIG_QISDA_E600_EVT2)|| defined(CONFIG_QISDA_QD060N00_DVT1_1)
  88. if((readl(S3C2410_GPGDAT) &(1<<1))==0)
  89. {
  90. if((readl(S3C2410_GPHDAT) &&(1<<11))==0)
  91. {
  92. printk("3G Module off\n");
  93. s3c2410_gpio_cfgpin(S3C2443_GPH14, S3C2443_GPH14_OUTP);
  94. s3c2410_gpio_setpin(S3C2443_GPH14, 0);
  95. }
  96. __raw_writel((0<<31)|(0<<2)|(1<<1)|(1<<0), S3C_UCLKCON);
  97. }
  98. #endif
  99. #if defined(CONFIG_QISDA_AS090B00_EVT1)||defined(CONFIG_QISDA_AS090B00_EVT1_1)||defined(CONFIG_QISDA_QD090B00_EVT1)
  100. if((readl(S3C2410_GPGDAT) &(1<<1))==0)
  101. {
  102. if((readl(S3C2410_GPHDAT) &(1<<11))==0)
  103. {
  104. // printk("3G Module off\n");
  105. s3c2410_gpio_cfgpin(S3C2443_GPH14, S3C2443_GPH14_OUTP);
  106. s3c2410_gpio_setpin(S3C2443_GPH14, 0);
  107. }
  108. __raw_writel((0<<31)|(0<<2)|(1<<1)|(1<<0), S3C_UCLKCON);
  109. }
  110. #endif
  111. return 0;
  112. }
  113. else
  114. {
  115. // printk("wall charger\n");
  116. #if defined(CONFIG_QISDA_E600_EVT2)||defined(CONFIG_QISDA_QD060N00_DVT1_1)
  117. if((readl(S3C2410_GPGDAT) &(1<<1))==0)
  118. {
  119. s3c2410_gpio_cfgpin(S3C2443_GPH14, S3C2443_GPH14_OUTP);
  120. s3c2410_gpio_setpin(S3C2443_GPH14, 0);
  121. __raw_writel((0<<31)|(0<<2)|(1<<1)|(1<<0), S3C_UCLKCON);
  122. }
  123. #endif
  124. #if defined(CONFIG_QISDA_AS090B00_EVT1)||defined(CONFIG_QISDA_AS090B00_EVT1_1)||defined(CONFIG_QISDA_QD090B00_EVT1)
  125. if((readl(S3C2410_GPGDAT) &(1<<1))==0)
  126. {
  127. if((readl(S3C2410_GPHDAT) &(1<<11))==0)
  128. {
  129. s3c2410_gpio_cfgpin(S3C2443_GPH14, S3C2443_GPH14_OUTP);
  130. s3c2410_gpio_setpin(S3C2443_GPH14, 0);
  131. }
  132. __raw_writel((0<<31)|(0<<2)|(1<<1)|(1<<0), S3C_UCLKCON);
  133. }
  134. #endif
  135. return 1;
  136. }
  137. }
  138. /*Leo*/
  139. /* } Qisda, ShiYong Lin, 2009/09/10, Detect insertion source */
  140. EXPORT_SYMBOL(IsWallCharger);