mt_pmic_wrap.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /******************************************************************************
  2. * pmic_wrapper.c - Linux pmic_wrapper Driver
  3. *
  4. *
  5. * DESCRIPTION:
  6. * This file provid the other drivers PMIC wrapper relative functions
  7. *
  8. ******************************************************************************/
  9. #include <linux/kernel.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/types.h>
  12. #include <linux/device.h>
  13. #include <linux/fs.h>
  14. #include <linux/module.h>
  15. /*#include <mach/mt_typedefs.h>*/
  16. #include <linux/timer.h>
  17. #include <mt_pmic_wrap.h>
  18. #include <linux/syscore_ops.h>
  19. #define PMIC_WRAP_DEVICE "pmic_wrap"
  20. #define VERSION "Revision"
  21. static struct mt_pmic_wrap_driver mt_wrp = {
  22. .driver = {
  23. .name = "pmic_wrap",
  24. .bus = &platform_bus_type,
  25. .owner = THIS_MODULE,
  26. },
  27. };
  28. struct mt_pmic_wrap_driver *get_mt_pmic_wrap_drv(void)
  29. {
  30. return &mt_wrp;
  31. }
  32. /*this function only used for ROME plus*/
  33. int check_pmic_wrap_init(void)
  34. {
  35. if (mt_wrp.wacs2_hal == NULL)
  36. return -1;
  37. else
  38. return 0;
  39. }
  40. /* ****************************************************************************** */
  41. /* --external API for pmic_wrap user------------------------------------------------- */
  42. /* ****************************************************************************** */
  43. s32 pwrap_wacs2(u32 write, u32 adr, u32 wdata, u32 *rdata)
  44. {
  45. if (mt_wrp.wacs2_hal != NULL)
  46. return mt_wrp.wacs2_hal(write, adr, wdata, rdata);
  47. pr_err("[WRAP]" "driver need registered!!");
  48. return -5;
  49. }
  50. EXPORT_SYMBOL(pwrap_wacs2);
  51. s32 pwrap_read(u32 adr, u32 *rdata)
  52. {
  53. return pwrap_wacs2(PWRAP_READ, adr, 0, rdata);
  54. }
  55. EXPORT_SYMBOL(pwrap_read);
  56. s32 pwrap_write(u32 adr, u32 wdata)
  57. {
  58. return pwrap_wacs2(PWRAP_WRITE, adr, wdata, 0);
  59. }
  60. EXPORT_SYMBOL(pwrap_write);
  61. /********************************************************************/
  62. /********************************************************************/
  63. /* return value : EINT_STA: [0]: CPU IRQ status in PMIC1 */
  64. /* [1]: MD32 IRQ status in PMIC1 */
  65. /* [2]: CPU IRQ status in PMIC2 */
  66. /* [3]: RESERVED */
  67. /********************************************************************/
  68. u32 pmic_wrap_eint_status(void)
  69. {
  70. return mt_pmic_wrap_eint_status();
  71. }
  72. EXPORT_SYMBOL(pmic_wrap_eint_status);
  73. /********************************************************************/
  74. /* set value(W1C) : EINT_CLR: [0]: CPU IRQ status in PMIC1 */
  75. /* [1]: MD32 IRQ status in PMIC1 */
  76. /* [2]: CPU IRQ status in PMIC2 */
  77. /* [3]: RESERVED */
  78. /* para: offset is shift of clear bit which needs to clear */
  79. /********************************************************************/
  80. void pmic_wrap_eint_clr(int offset)
  81. {
  82. mt_pmic_wrap_eint_clr(offset);
  83. }
  84. EXPORT_SYMBOL(pmic_wrap_eint_clr);
  85. /************************************************************************/
  86. static ssize_t mt_pwrap_show(struct device_driver *driver, char *buf)
  87. {
  88. if (mt_wrp.show_hal != NULL)
  89. return mt_wrp.show_hal(buf);
  90. return snprintf(buf, PAGE_SIZE, "%s\n", "[WRAP]driver need registered!! ");
  91. }
  92. static ssize_t mt_pwrap_store(struct device_driver *driver, const char *buf, size_t count)
  93. {
  94. if (mt_wrp.store_hal != NULL)
  95. return mt_wrp.store_hal(buf, count);
  96. pr_err("[WRAP]" "driver need registered!!");
  97. return count;
  98. }
  99. DRIVER_ATTR(pwrap, 0664, mt_pwrap_show, mt_pwrap_store);
  100. /*-----suspend/resume for pmic_wrap-------------------------------------------*/
  101. /* infra power down while suspend,pmic_wrap will gate clock after suspend. */
  102. /* so,need to init PPB when resume. */
  103. /* only affect PWM and I2C */
  104. static int pwrap_suspend(void)
  105. {
  106. /* PWRAPLOG("pwrap_suspend\n"); */
  107. if (mt_wrp.suspend != NULL)
  108. return mt_wrp.suspend();
  109. return 0;
  110. }
  111. static void pwrap_resume(void)
  112. {
  113. if (mt_wrp.resume != NULL)
  114. mt_wrp.resume();
  115. }
  116. static struct syscore_ops pwrap_syscore_ops = {
  117. .resume = pwrap_resume,
  118. .suspend = pwrap_suspend,
  119. };
  120. static int __init mt_pwrap_init(void)
  121. {
  122. u32 ret = 0;
  123. ret = driver_register(&mt_wrp.driver);
  124. if (ret)
  125. pr_err("[WRAP]" "Fail to register mt_wrp");
  126. ret = driver_create_file(&mt_wrp.driver, &driver_attr_pwrap);
  127. if (ret)
  128. pr_err("[WRAP]" "Fail to create mt_wrp sysfs files");
  129. /* PWRAPLOG("pwrap_init_ops\n"); */
  130. register_syscore_ops(&pwrap_syscore_ops);
  131. return ret;
  132. }
  133. postcore_initcall(mt_pwrap_init);
  134. /* device_initcall(mt_pwrap_init); */
  135. /* ---------------------------------------------------------------------*/
  136. /* static void __exit mt_pwrap_exit(void) */
  137. /* { */
  138. /* platform_driver_unregister(&mt_pwrap_driver); */
  139. /* return; */
  140. /* } */
  141. /* ---------------------------------------------------------------------*/
  142. /* postcore_initcall(mt_pwrap_init); */
  143. /* module_exit(mt_pwrap_exit); */
  144. /* #define PWRAP_EARLY_PORTING */
  145. /*-----suspend/resume for pmic_wrap-------------------------------------------*/
  146. /* infra power down while suspend,pmic_wrap will gate clock after suspend. */
  147. /* so,need to init PPB when resume. */
  148. /* only affect PWM and I2C */
  149. /* static struct syscore_ops pwrap_syscore_ops = { */
  150. /* .resume = pwrap_resume, */
  151. /* .suspend = pwrap_suspend, */
  152. /* }; */
  153. /* */
  154. /* static int __init pwrap_init_ops(void) */
  155. /* { */
  156. /* PWRAPLOG("pwrap_init_ops\n"); */
  157. /* register_syscore_ops(&pwrap_syscore_ops); */
  158. /* return 0; */
  159. /* } */
  160. /* device_initcall(pwrap_init_ops); */
  161. MODULE_AUTHOR("mediatek");
  162. MODULE_DESCRIPTION("pmic_wrapper Driver Revision");
  163. MODULE_LICENSE("GPL");