ts3a225e.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* drivers/hwmon/mt6516/amit/IQS128.c - IQS128/PS driver
  2. *
  3. * Author: MingHsien Hsieh <minghsien.hsieh@mediatek.com>
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #include <linux/interrupt.h>
  16. #include <linux/i2c.h>
  17. #include <linux/slab.h>
  18. #include <linux/irq.h>
  19. #include <linux/miscdevice.h>
  20. #include <linux/uaccess.h>
  21. #include <linux/delay.h>
  22. #include <linux/input.h>
  23. #include <linux/workqueue.h>
  24. #include <linux/kobject.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/atomic.h>
  27. #include <linux/module.h>
  28. #include "upmu_common.h"
  29. /*
  30. #include <linux/hwmsensor.h>
  31. #include <linux/hwmsen_dev.h>
  32. #include <linux/sensors_io.h>
  33. */
  34. #include <linux/io.h>
  35. #include "ts3a225e.h"
  36. /******************************************************************************
  37. * configuration
  38. *******************************************************************************/
  39. #define TS3A225E_DEV_NAME "TS3A225E"
  40. struct i2c_client *ts3a225e_i2c_client;
  41. static const struct i2c_device_id ts3a225e_i2c_id[] = { {"TS3A225E", 0}, {} };
  42. /*static struct i2c_board_info i2c_TS3A225E __initdata = { I2C_BOARD_INFO("TS3A225E", (0X76 >> 1)) };*/
  43. static int ts3a225e_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
  44. {
  45. unsigned char devicve_id[1];
  46. pr_warn("ts3a225e_i2c_probe\n");
  47. ts3a225e_i2c_client = client;
  48. ts3a225e_read_byte(0x01, &devicve_id[0]);
  49. pr_warn("ts3a225e_i2c_probe ID=%x\n", devicve_id[0]);
  50. return 0;
  51. }
  52. static int ts3a225e_i2c_remove(struct i2c_client *client)
  53. {
  54. pr_warn("TS3A225E_i2c_remove\n");
  55. ts3a225e_i2c_client = NULL;
  56. return 0;
  57. }
  58. static int ts3a225e_i2c_suspend(struct i2c_client *client, pm_message_t msg)
  59. {
  60. pr_debug("TS3A225E_i2c_suspend\n");
  61. return 0;
  62. }
  63. static int ts3a225e_i2c_resume(struct i2c_client *client)
  64. {
  65. pr_debug("TS3A225E_i2c_resume\n");
  66. return 0;
  67. }
  68. static const struct of_device_id ts3a225e_of_match[] = {
  69. {.compatible = "mediatek,ts3a225e"},
  70. {},
  71. };
  72. static struct i2c_driver ts3a225e_i2c_driver = {
  73. .probe = ts3a225e_i2c_probe,
  74. .remove = ts3a225e_i2c_remove,
  75. .suspend = ts3a225e_i2c_suspend,
  76. .resume = ts3a225e_i2c_resume,
  77. .id_table = ts3a225e_i2c_id,
  78. .driver = {
  79. .name = TS3A225E_DEV_NAME,
  80. .of_match_table = ts3a225e_of_match,
  81. },
  82. };
  83. static DEFINE_MUTEX(ts3a225e_i2c_access);
  84. int ts3a225e_read_byte(unsigned char cmd, unsigned char *returnData)
  85. {
  86. char cmd_buf[1] = { 0x00 };
  87. char readData = 0;
  88. int ret = 0;
  89. mutex_lock(&ts3a225e_i2c_access);
  90. /*new_client->addr = ((new_client->addr) & I2C_MASK_FLAG) | I2C_WR_FLAG;*/
  91. ts3a225e_i2c_client->ext_flag =
  92. ((ts3a225e_i2c_client->ext_flag) & I2C_MASK_FLAG) | I2C_WR_FLAG | I2C_DIRECTION_FLAG;
  93. cmd_buf[0] = cmd;
  94. ret = i2c_master_send(ts3a225e_i2c_client, &cmd_buf[0], (1 << 8 | 1));
  95. if (ret < 0) {
  96. /*new_client->addr = new_client->addr & I2C_MASK_FLAG;*/
  97. ts3a225e_i2c_client->ext_flag = 0;
  98. mutex_unlock(&ts3a225e_i2c_access);
  99. return 0;
  100. }
  101. readData = cmd_buf[0];
  102. *returnData = readData;
  103. /*new_client->addr = new_client->addr & I2C_MASK_FLAG;*/
  104. ts3a225e_i2c_client->ext_flag = 0;
  105. mutex_unlock(&ts3a225e_i2c_access);
  106. return 1;
  107. }
  108. int ts3a225e_write_byte(unsigned char cmd, unsigned char writeData)
  109. {
  110. char write_data[2] = { 0 };
  111. int ret = 0;
  112. mutex_lock(&ts3a225e_i2c_access);
  113. write_data[0] = cmd;
  114. write_data[1] = writeData;
  115. ts3a225e_i2c_client->ext_flag = ((ts3a225e_i2c_client->ext_flag) & I2C_MASK_FLAG) | I2C_DIRECTION_FLAG;
  116. ret = i2c_master_send(ts3a225e_i2c_client, write_data, 2);
  117. if (ret < 0) {
  118. ts3a225e_i2c_client->ext_flag = 0;
  119. mutex_unlock(&ts3a225e_i2c_access);
  120. return 0;
  121. }
  122. ts3a225e_i2c_client->ext_flag = 0;
  123. mutex_unlock(&ts3a225e_i2c_access);
  124. return 1;
  125. }
  126. /******************************************************************************
  127. * extern functions
  128. *******************************************************************************/
  129. /*----------------------------------------------------------------------------*/
  130. static int ts3a225e_probe(struct platform_device *pdev)
  131. {
  132. pr_warn("ts3a225e_probe\n");
  133. if (i2c_add_driver(&ts3a225e_i2c_driver)) {
  134. pr_err("ts3a225e add driver error\n");
  135. return -1;
  136. }
  137. return 0;
  138. }
  139. /*----------------------------------------------------------------------------*/
  140. static int ts3a225e_remove(struct platform_device *pdev)
  141. {
  142. pr_warn("ts3a225e remove\n");
  143. i2c_del_driver(&ts3a225e_i2c_driver);
  144. return 0;
  145. }
  146. /*----------------------------------------------------------------------------*/
  147. static const struct of_device_id audio_switch_of_match[] = {
  148. {.compatible = "mediatek,audio_switch",},
  149. {},
  150. };
  151. static struct platform_driver ts3a225e_audio_switch_driver = {
  152. .probe = ts3a225e_probe,
  153. .remove = ts3a225e_remove,
  154. .driver = {
  155. .name = "audio_switch",
  156. .of_match_table = audio_switch_of_match,
  157. }
  158. };
  159. /*----------------------------------------------------------------------------*/
  160. static int __init ts3a225e_init(void)
  161. {
  162. pr_warn("ts3a225e_init\n");
  163. /*i2c_register_board_info(3, &i2c_TS3A225E, 1);*/
  164. if (platform_driver_register(&ts3a225e_audio_switch_driver)) {
  165. pr_err("ts3a225e failed to register driver");
  166. return -ENODEV;
  167. }
  168. return 0;
  169. }
  170. /*----------------------------------------------------------------------------*/
  171. static void __exit ts3a225e_exit(void)
  172. {
  173. pr_warn("ts3a225e_exit\n");
  174. }
  175. /*----------------------------------------------------------------------------*/
  176. module_init(ts3a225e_init);
  177. module_exit(ts3a225e_exit);
  178. /*----------------------------------------------------------------------------*/
  179. MODULE_AUTHOR("Dexiang Liu");
  180. MODULE_DESCRIPTION("TS3A225E driver");
  181. MODULE_LICENSE("GPL");