vibrator.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /******************************************************************************
  2. * mt6575_vibrator.c - MT6575 Android Linux Vibrator Device Driver
  3. *
  4. * Copyright 2009-2010 MediaTek Co.,Ltd.
  5. *
  6. * DESCRIPTION:
  7. * This file provid the other drivers vibrator relative functions
  8. *
  9. ******************************************************************************/
  10. #include <linux/init.h>
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/types.h>
  14. #include <linux/device.h>
  15. #include <linux/slab.h>
  16. #include <linux/of.h>
  17. #include <linux/types.h>
  18. #include <mt-plat/mt_pwm.h>
  19. #include <mt-plat/upmu_common.h>
  20. #include "vibrator.h"
  21. struct vibrator_hw *pvib_cust = NULL;
  22. static int debug_enable_vib_hal = 1;
  23. /* #define pr_fmt(fmt) "[vibrator]"fmt */
  24. #define VIB_DEBUG(format, args...) do { \
  25. if (debug_enable_vib_hal) {\
  26. pr_debug(format, ##args);\
  27. } \
  28. } while (0)
  29. void vibr_Enable_HW(void)
  30. {
  31. pmic_set_register_value(PMIC_RG_VIBR_EN, 1); /* [bit 1]: VIBR_EN, 1=enable */
  32. }
  33. void vibr_Disable_HW(void)
  34. {
  35. pmic_set_register_value(PMIC_RG_VIBR_EN, 0); /* [bit 1]: VIBR_EN, 1=enable */
  36. }
  37. /******************************************
  38. * Set RG_VIBR_VOSEL Output voltage select
  39. * hw->vib_vol: Voltage selection
  40. * 3'b000: 1.3V
  41. * 3'b001: 1.5V
  42. * 3'b010: 1.8V
  43. * 3'b011: 2.0V
  44. * 3'b100: 2.5V
  45. * 3'b101: 2.8V
  46. * 3'b110: 3.0V
  47. * 3'b111: 3.3V
  48. *******************************************/
  49. struct vibrator_hw *get_cust_vibrator_dtsi(void)
  50. {
  51. int ret;
  52. struct device_node *led_node = NULL;
  53. if (pvib_cust == NULL) {
  54. pvib_cust = kmalloc(sizeof(struct vibrator_hw), GFP_KERNEL);
  55. if (pvib_cust == NULL) {
  56. VIB_DEBUG("get_cust_vibrator_dtsi kmalloc fail\n");
  57. goto out;
  58. }
  59. led_node =
  60. of_find_compatible_node(NULL, NULL, "mediatek,vibrator");
  61. if (!led_node) {
  62. VIB_DEBUG("Cannot find vibrator node from dts\n");
  63. kfree(pvib_cust);
  64. pvib_cust = NULL;
  65. goto out;
  66. } else {
  67. ret =
  68. of_property_read_u32(led_node, "vib_timer",
  69. &(pvib_cust->vib_timer));
  70. if (!ret) {
  71. VIB_DEBUG
  72. ("The vibrator timer from dts is : %d\n",
  73. pvib_cust->vib_timer);
  74. } else {
  75. pvib_cust->vib_timer = 25;
  76. }
  77. #ifdef CUST_VIBR_LIMIT
  78. ret =
  79. of_property_read_u32(led_node, "vib_limit",
  80. &(pvib_cust->vib_limit));
  81. if (!ret) {
  82. VIB_DEBUG
  83. ("The vibrator limit from dts is : %d\n",
  84. pvib_cust->vib_limit);
  85. } else {
  86. pvib_cust->vib_limit = 9;
  87. }
  88. #endif
  89. #ifdef CUST_VIBR_VOL
  90. ret =
  91. of_property_read_u32(led_node, "vib_vol",
  92. &(pvib_cust->vib_vol));
  93. if (!ret) {
  94. VIB_DEBUG("The vibrator vol from dts is : %d\n",
  95. pvib_cust->vib_vol);
  96. } else {
  97. pvib_cust->vib_vol = 0x05;
  98. }
  99. #endif
  100. }
  101. }
  102. out:
  103. return pvib_cust;
  104. }
  105. void vibr_power_set(void)
  106. {
  107. #ifdef CUST_VIBR_VOL
  108. struct vibrator_hw *hw = get_cust_vibrator_dtsi();
  109. VIB_DEBUG("vibr_init: vibrator set voltage = %d\n", hw->vib_vol);
  110. pmic_set_register_value(PMIC_RG_VIBR_VOSEL, hw->vib_vol);
  111. #endif
  112. }
  113. struct vibrator_hw *mt_get_cust_vibrator_hw(void)
  114. {
  115. struct vibrator_hw *hw = get_cust_vibrator_dtsi();
  116. return hw;
  117. }