max77888_haptic.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * haptic motor driver for max77888 - max77673_haptic.c
  3. *
  4. * Copyright (C) 2011 ByungChang Cha <bc.cha@samsung.com>
  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 version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/hrtimer.h>
  13. #include <linux/pwm.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/err.h>
  16. #include <linux/slab.h>
  17. #include <linux/clk.h>
  18. #include <linux/i2c.h>
  19. #include <linux/regulator/consumer.h>
  20. #include <linux/mfd/max77888.h>
  21. #include <linux/mfd/max77888-private.h>
  22. struct max77888_haptic_data {
  23. struct max77888_dev *max77888;
  24. struct i2c_client *i2c;
  25. struct i2c_client *pmic_i2c;
  26. struct max77888_haptic_platform_data *pdata;
  27. spinlock_t lock;
  28. bool running;
  29. };
  30. struct max77888_haptic_data *g_hap_data;
  31. static void max77888_haptic_i2c(struct max77888_haptic_data *hap_data, bool en)
  32. {
  33. int ret;
  34. u8 value = hap_data->pdata->reg2;
  35. u8 lscnfg_val = 0x00;
  36. pr_debug("[VIB] %s %d\n", __func__, en);
  37. if (en) {
  38. value |= MOTOR_EN;
  39. lscnfg_val = 0x80;
  40. }
  41. ret = max77888_update_reg(hap_data->pmic_i2c, MAX77888_PMIC_REG_LSCNFG,
  42. lscnfg_val, 0x80);
  43. if (ret)
  44. pr_err("[VIB] i2c update error %d\n", ret);
  45. ret = max77888_write_reg(hap_data->i2c,
  46. MAX77888_HAPTIC_REG_CONFIG2, value);
  47. if (ret)
  48. pr_err("[VIB] i2c write error %d\n", ret);
  49. }
  50. #ifdef CONFIG_SS_VIBRATOR
  51. void max77888_vibtonz_en(bool en)
  52. {
  53. if (g_hap_data == NULL) {
  54. printk(KERN_ERR "[VIB] the motor is not ready!!!");
  55. return ;
  56. }
  57. if (en) {
  58. if (g_hap_data->running)
  59. return;
  60. max77888_haptic_i2c(g_hap_data, true);
  61. g_hap_data->running = true;
  62. } else {
  63. if (!g_hap_data->running)
  64. return;
  65. max77888_haptic_i2c(g_hap_data, false);
  66. g_hap_data->running = false;
  67. }
  68. }
  69. EXPORT_SYMBOL(max77888_vibtonz_en);
  70. #endif
  71. static int __devinit max77888_haptic_probe(struct platform_device *pdev)
  72. {
  73. int error = 0;
  74. struct max77888_dev *max77888 = dev_get_drvdata(pdev->dev.parent);
  75. struct max77888_platform_data *max77888_pdata
  76. = dev_get_platdata(max77888->dev);
  77. #ifdef CONFIG_SS_VIBRATOR
  78. struct max77888_haptic_platform_data *pdata
  79. = max77888_pdata->haptic_data;
  80. #endif
  81. struct max77888_haptic_data *hap_data;
  82. pr_err("[VIB] ++ %s\n", __func__);
  83. if (pdata == NULL) {
  84. pr_err("%s: no pdata\n", __func__);
  85. return -ENODEV;
  86. }
  87. hap_data = kzalloc(sizeof(struct max77888_haptic_data), GFP_KERNEL);
  88. if (!hap_data)
  89. return -ENOMEM;
  90. platform_set_drvdata(pdev, hap_data);
  91. g_hap_data = hap_data;
  92. hap_data->max77888 = max77888;
  93. hap_data->i2c = max77888->haptic;
  94. hap_data->pmic_i2c = max77888->i2c;
  95. pdata->reg2 = MOTOR_LRA | EXT_PWM | DIVIDER_128;
  96. hap_data->pdata = pdata;
  97. max77888_haptic_i2c(hap_data, true);
  98. spin_lock_init(&(hap_data->lock));
  99. pr_err("[VIB] -- %s\n", __func__);
  100. return error;
  101. }
  102. static int __devexit max77888_haptic_remove(struct platform_device *pdev)
  103. {
  104. struct max77888_haptic_data *data = platform_get_drvdata(pdev);
  105. kfree(data);
  106. g_hap_data = NULL;
  107. return 0;
  108. }
  109. static void max77888_haptic_shutdown(struct device *dev)
  110. {
  111. struct max77888_haptic_data *data = dev_get_drvdata(dev);
  112. int ret;
  113. pr_info("%s: Disable HAPTIC\n", __func__);
  114. ret = max77888_update_reg(data->i2c, MAX77888_HAPTIC_REG_CONFIG2, 0x0, MOTOR_EN);
  115. if (ret < 0) {
  116. pr_err("%s: fail to update reg\n", __func__);
  117. return;
  118. }
  119. }
  120. static int max77888_haptic_suspend(struct platform_device *pdev,
  121. pm_message_t state)
  122. {
  123. return 0;
  124. }
  125. static int max77888_haptic_resume(struct platform_device *pdev)
  126. {
  127. return 0;
  128. }
  129. static struct platform_driver max77888_haptic_driver = {
  130. .probe = max77888_haptic_probe,
  131. .remove = max77888_haptic_remove,
  132. .suspend = max77888_haptic_suspend,
  133. .resume = max77888_haptic_resume,
  134. .driver = {
  135. .name = "max77888-haptic",
  136. .owner = THIS_MODULE,
  137. .shutdown = max77888_haptic_shutdown,
  138. },
  139. };
  140. static int __init max77888_haptic_init(void)
  141. {
  142. pr_debug("[VIB] %s\n", __func__);
  143. return platform_driver_register(&max77888_haptic_driver);
  144. }
  145. module_init(max77888_haptic_init);
  146. static void __exit max77888_haptic_exit(void)
  147. {
  148. platform_driver_unregister(&max77888_haptic_driver);
  149. }
  150. module_exit(max77888_haptic_exit);
  151. MODULE_AUTHOR("ByungChang Cha <bc.cha@samsung.com>");
  152. MODULE_LICENSE("GPL");
  153. MODULE_DESCRIPTION("MAX77888 haptic driver");