pressure_bmp182.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * Copyright (C) 2012, Samsung Electronics Co. Ltd. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  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 "../ssp.h"
  16. #if defined(CONFIG_MACH_KS01SKT) || defined(CONFIG_MACH_KS01KTT)\
  17. || defined(CONFIG_MACH_KS01LGT) || defined(CONFIG_MACH_JACTIVESKT)
  18. #define LPS25H_REV 4
  19. #endif
  20. #define VENDOR "BOSCH"
  21. #define CHIP_ID "BMP180"
  22. #define VENDOR_STM "STM"
  23. #define CHIP_ID_LPS25H "LPS25H"
  24. #define CALIBRATION_FILE_PATH "/efs/FactoryApp/baro_delta"
  25. #define PR_ABS_MAX 8388607 /* 24 bit 2'compl */
  26. #define PR_ABS_MIN -8388608
  27. /*************************************************************************/
  28. /* factory Sysfs */
  29. /*************************************************************************/
  30. static ssize_t sea_level_pressure_store(struct device *dev,
  31. struct device_attribute *attr, const char *buf, size_t size)
  32. {
  33. struct ssp_data *data = dev_get_drvdata(dev);
  34. int iNewSeaLevelPressure;
  35. sscanf(buf, "%d", &iNewSeaLevelPressure);
  36. if (iNewSeaLevelPressure == 0) {
  37. pr_info("%s, our->temperature = 0\n", __func__);
  38. iNewSeaLevelPressure = -1;
  39. }
  40. input_report_rel(data->pressure_input_dev, REL_DIAL,
  41. iNewSeaLevelPressure);
  42. input_sync(data->pressure_input_dev);
  43. return size;
  44. }
  45. int pressure_open_calibration(struct ssp_data *data)
  46. {
  47. char chBuf[10] = {0,};
  48. int iErr = 0;
  49. mm_segment_t old_fs;
  50. struct file *cal_filp = NULL;
  51. old_fs = get_fs();
  52. set_fs(KERNEL_DS);
  53. cal_filp = filp_open(CALIBRATION_FILE_PATH, O_RDONLY, 0666);
  54. if (IS_ERR(cal_filp)) {
  55. iErr = PTR_ERR(cal_filp);
  56. if (iErr != -ENOENT)
  57. pr_err("[SSP]: %s - Can't open calibration file(%d)\n",
  58. __func__, iErr);
  59. set_fs(old_fs);
  60. return iErr;
  61. }
  62. iErr = cal_filp->f_op->read(cal_filp,
  63. chBuf, 10 * sizeof(char), &cal_filp->f_pos);
  64. if (iErr < 0) {
  65. pr_err("[SSP]: %s - Can't read the cal data from file (%d)\n",
  66. __func__, iErr);
  67. return iErr;
  68. }
  69. filp_close(cal_filp, current->files);
  70. set_fs(old_fs);
  71. iErr = kstrtoint(chBuf, 10, &data->iPressureCal);
  72. if (iErr < 0) {
  73. pr_err("[SSP]: %s - kstrtoint failed. %d", __func__, iErr);
  74. return iErr;
  75. }
  76. ssp_dbg("[SSP]: open barometer calibration %d\n", data->iPressureCal);
  77. if (data->iPressureCal < PR_ABS_MIN || data->iPressureCal > PR_ABS_MAX)
  78. pr_err("[SSP]: %s - wrong offset value!!!\n", __func__);
  79. return iErr;
  80. }
  81. static ssize_t pressure_cabratioin_store(struct device *dev,
  82. struct device_attribute *attr, const char *buf, size_t size)
  83. {
  84. struct ssp_data *data = dev_get_drvdata(dev);
  85. int iPressureCal = 0, iErr = 0;
  86. iErr = kstrtoint(buf, 10, &iPressureCal);
  87. if (iErr < 0) {
  88. pr_err("[SSP]: %s - kstrtoint failed.(%d)", __func__, iErr);
  89. return iErr;
  90. }
  91. if (iPressureCal < PR_ABS_MIN || iPressureCal > PR_ABS_MAX)
  92. return -EINVAL;
  93. data->iPressureCal = (s32)iPressureCal;
  94. return size;
  95. }
  96. static ssize_t pressure_cabratioin_show(struct device *dev,
  97. struct device_attribute *attr, char *buf)
  98. {
  99. struct ssp_data *data = dev_get_drvdata(dev);
  100. pressure_open_calibration(data);
  101. return sprintf(buf, "%d\n", data->iPressureCal);
  102. }
  103. static ssize_t eeprom_check_show(struct device *dev,
  104. struct device_attribute *attr, char *buf)
  105. {
  106. char chTempBuf = 0;
  107. int iRet = 0;
  108. struct ssp_data *data = dev_get_drvdata(dev);
  109. struct ssp_msg *msg = kzalloc(sizeof(*msg), GFP_KERNEL);
  110. msg->cmd = PRESSURE_FACTORY;
  111. msg->length = 1;
  112. msg->options = AP2HUB_READ;
  113. msg->buffer = &chTempBuf;
  114. msg->free_buffer = 0;
  115. iRet = ssp_spi_sync(data, msg, 3000);
  116. if (iRet != SUCCESS) {
  117. pr_err("[SSP]: %s - Pressure Selftest Timeout!!\n", __func__);
  118. goto exit;
  119. }
  120. ssp_dbg("[SSP]: %s - %u\n", __func__, chTempBuf);
  121. exit:
  122. return snprintf(buf, PAGE_SIZE, "%d", chTempBuf);
  123. }
  124. /* sysfs for vendor & name */
  125. static ssize_t pressure_vendor_show(struct device *dev,
  126. struct device_attribute *attr, char *buf)
  127. {
  128. #if defined (LPS25H_REV)
  129. struct ssp_data *data = dev_get_drvdata(dev);
  130. if(data->ap_rev >= LPS25H_REV)
  131. return sprintf(buf, "%s\n", VENDOR_STM);
  132. else
  133. return sprintf(buf, "%s\n", VENDOR);
  134. #else
  135. return sprintf(buf, "%s\n", VENDOR);
  136. #endif
  137. }
  138. static ssize_t pressure_name_show(struct device *dev,
  139. struct device_attribute *attr, char *buf)
  140. {
  141. #if defined (LPS25H_REV)
  142. struct ssp_data *data = dev_get_drvdata(dev);
  143. if(data->ap_rev >= LPS25H_REV)
  144. return sprintf(buf, "%s\n", CHIP_ID_LPS25H);
  145. else
  146. return sprintf(buf, "%s\n", CHIP_ID);
  147. #else
  148. return sprintf(buf, "%s\n", CHIP_ID);
  149. #endif
  150. }
  151. static DEVICE_ATTR(vendor, S_IRUGO, pressure_vendor_show, NULL);
  152. static DEVICE_ATTR(name, S_IRUGO, pressure_name_show, NULL);
  153. static DEVICE_ATTR(eeprom_check, S_IRUGO, eeprom_check_show, NULL);
  154. static DEVICE_ATTR(calibration, S_IRUGO | S_IWUSR | S_IWGRP,
  155. pressure_cabratioin_show, pressure_cabratioin_store);
  156. static DEVICE_ATTR(sea_level_pressure, S_IRUGO | S_IWUSR | S_IWGRP,
  157. NULL, sea_level_pressure_store);
  158. static struct device_attribute *pressure_attrs[] = {
  159. &dev_attr_vendor,
  160. &dev_attr_name,
  161. &dev_attr_calibration,
  162. &dev_attr_sea_level_pressure,
  163. &dev_attr_eeprom_check,
  164. NULL,
  165. };
  166. #if defined (LPS25H_REV)
  167. static struct device_attribute *pressure_attrs_lps25h[] = {
  168. &dev_attr_vendor,
  169. &dev_attr_name,
  170. &dev_attr_calibration,
  171. &dev_attr_sea_level_pressure,
  172. NULL,
  173. };
  174. #endif
  175. void initialize_pressure_factorytest(struct ssp_data *data)
  176. {
  177. #if defined (LPS25H_REV)
  178. if(data->ap_rev >= LPS25H_REV)
  179. sensors_register(data->prs_device, data, pressure_attrs_lps25h,
  180. "barometer_sensor");
  181. else
  182. sensors_register(data->prs_device, data, pressure_attrs,
  183. "barometer_sensor");
  184. #else
  185. sensors_register(data->prs_device, data, pressure_attrs,
  186. "barometer_sensor");
  187. #endif
  188. }
  189. void remove_pressure_factorytest(struct ssp_data *data)
  190. {
  191. #if defined (LPS25H_REV)
  192. if(data->ap_rev >= LPS25H_REV)
  193. sensors_unregister(data->prs_device, pressure_attrs_lps25h);
  194. else
  195. sensors_unregister(data->prs_device, pressure_attrs);
  196. #else
  197. sensors_unregister(data->prs_device, pressure_attrs);
  198. #endif
  199. }