tsens-8916.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2015, The Linux Foundation. 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 version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. */
  14. #include <linux/platform_device.h>
  15. #include "tsens.h"
  16. /* eeprom layout data for 8916 */
  17. #define BASE0_MASK 0x0000007f
  18. #define BASE1_MASK 0xfe000000
  19. #define BASE0_SHIFT 0
  20. #define BASE1_SHIFT 25
  21. #define S0_P1_MASK 0x00000f80
  22. #define S1_P1_MASK 0x003e0000
  23. #define S2_P1_MASK 0xf8000000
  24. #define S3_P1_MASK 0x000003e0
  25. #define S4_P1_MASK 0x000f8000
  26. #define S0_P2_MASK 0x0001f000
  27. #define S1_P2_MASK 0x07c00000
  28. #define S2_P2_MASK 0x0000001f
  29. #define S3_P2_MASK 0x00007c00
  30. #define S4_P2_MASK 0x01f00000
  31. #define S0_P1_SHIFT 7
  32. #define S1_P1_SHIFT 17
  33. #define S2_P1_SHIFT 27
  34. #define S3_P1_SHIFT 5
  35. #define S4_P1_SHIFT 15
  36. #define S0_P2_SHIFT 12
  37. #define S1_P2_SHIFT 22
  38. #define S2_P2_SHIFT 0
  39. #define S3_P2_SHIFT 10
  40. #define S4_P2_SHIFT 20
  41. #define CAL_SEL_MASK 0xe0000000
  42. #define CAL_SEL_SHIFT 29
  43. static int calibrate_8916(struct tsens_device *tmdev)
  44. {
  45. int base0 = 0, base1 = 0, i;
  46. u32 p1[5], p2[5];
  47. int mode = 0;
  48. u32 *qfprom_cdata, *qfprom_csel;
  49. qfprom_cdata = (u32 *)qfprom_read(tmdev->dev, "calib");
  50. if (IS_ERR(qfprom_cdata))
  51. return PTR_ERR(qfprom_cdata);
  52. qfprom_csel = (u32 *)qfprom_read(tmdev->dev, "calib_sel");
  53. if (IS_ERR(qfprom_csel))
  54. return PTR_ERR(qfprom_csel);
  55. mode = (qfprom_csel[0] & CAL_SEL_MASK) >> CAL_SEL_SHIFT;
  56. dev_dbg(tmdev->dev, "calibration mode is %d\n", mode);
  57. switch (mode) {
  58. case TWO_PT_CALIB:
  59. base1 = (qfprom_cdata[1] & BASE1_MASK) >> BASE1_SHIFT;
  60. p2[0] = (qfprom_cdata[0] & S0_P2_MASK) >> S0_P2_SHIFT;
  61. p2[1] = (qfprom_cdata[0] & S1_P2_MASK) >> S1_P2_SHIFT;
  62. p2[2] = (qfprom_cdata[1] & S2_P2_MASK) >> S2_P2_SHIFT;
  63. p2[3] = (qfprom_cdata[1] & S3_P2_MASK) >> S3_P2_SHIFT;
  64. p2[4] = (qfprom_cdata[1] & S4_P2_MASK) >> S4_P2_SHIFT;
  65. for (i = 0; i < tmdev->num_sensors; i++)
  66. p2[i] = ((base1 + p2[i]) << 3);
  67. /* Fall through */
  68. case ONE_PT_CALIB2:
  69. base0 = (qfprom_cdata[0] & BASE0_MASK);
  70. p1[0] = (qfprom_cdata[0] & S0_P1_MASK) >> S0_P1_SHIFT;
  71. p1[1] = (qfprom_cdata[0] & S1_P1_MASK) >> S1_P1_SHIFT;
  72. p1[2] = (qfprom_cdata[0] & S2_P1_MASK) >> S2_P1_SHIFT;
  73. p1[3] = (qfprom_cdata[1] & S3_P1_MASK) >> S3_P1_SHIFT;
  74. p1[4] = (qfprom_cdata[1] & S4_P1_MASK) >> S4_P1_SHIFT;
  75. for (i = 0; i < tmdev->num_sensors; i++)
  76. p1[i] = (((base0) + p1[i]) << 3);
  77. break;
  78. default:
  79. for (i = 0; i < tmdev->num_sensors; i++) {
  80. p1[i] = 500;
  81. p2[i] = 780;
  82. }
  83. break;
  84. }
  85. compute_intercept_slope(tmdev, p1, p2, mode);
  86. return 0;
  87. }
  88. static const struct tsens_ops ops_8916 = {
  89. .init = init_common,
  90. .calibrate = calibrate_8916,
  91. .get_temp = get_temp_common,
  92. };
  93. const struct tsens_data data_8916 = {
  94. .num_sensors = 5,
  95. .ops = &ops_8916,
  96. .hw_ids = (unsigned int []){0, 1, 2, 4, 5 },
  97. };