25 #define pr_fmt(fmt) "intel_mid_thermal: " fmt
27 #include <linux/module.h>
31 #include <linux/device.h>
33 #include <linux/slab.h>
39 #define MSIC_THERMAL_SENSORS 4
42 #define MSIC_ADC_ENBL 0x10
43 #define MSIC_ADC_START 0x08
45 #define MSIC_ADCTHERM_ENBL 0x04
46 #define MSIC_ADCRRDATA_ENBL 0x05
47 #define MSIC_CHANL_MASK_VAL 0x0F
49 #define MSIC_STOPBIT_MASK 16
50 #define MSIC_ADCTHERM_MASK 4
52 #define ADC_CHANLS_MAX 15
53 #define ADC_LOOP_MAX (ADC_CHANLS_MAX - MSIC_THERMAL_SENSORS)
56 #define SKIN_SENSOR0_CODE 0x08
57 #define SKIN_SENSOR1_CODE 0x09
58 #define SYS_SENSOR_CODE 0x0A
59 #define MSIC_DIE_SENSOR_CODE 0x03
61 #define SKIN_THERM_SENSOR0 0
62 #define SKIN_THERM_SENSOR1 1
63 #define SYS_THERM_SENSOR2 2
64 #define MSIC_DIE_THERM_SENSOR3 3
70 #define ADC_VAL20C 720
71 #define ADC_VAL40C 508
72 #define ADC_VAL60C 315
75 #define ADC_CHNL_START_ADDR INTEL_MSIC_ADC1ADDR0
76 #define ADC_DATA_START_ADDR INTEL_MSIC_ADC1SNS0H
79 #define MSIC_DIE_ADC_MIN 488
80 #define MSIC_DIE_ADC_MAX 1004
85 static int channel_index;
105 static int to_msic_die_temp(
uint16_t adc_val)
107 return (368 * (adc_val) / 1000) - 220;
119 return (adc_val >= min) && (adc_val <=
max);
135 static int adc_to_temp(
int direct,
uint16_t adc_val,
unsigned long *tp)
142 *tp = to_msic_die_temp(adc_val) * 1000;
153 temp = 177 - (adc_val/5);
155 temp = 111 - (adc_val/8);
157 temp = 92 - (adc_val/10);
159 temp = 91 - (adc_val/10);
161 temp = 112 - (adc_val/6);
204 adc_val = (data << 2);
216 ret = adc_to_temp(td_info->
direct, adc_val, &curr_temp);
230 static int configure_adc(
int val)
257 static int set_up_therm_channel(
u16 base_addr)
282 return configure_adc(1);
291 static int reset_stopbit(
uint16_t addr)
315 static int find_free_channel(
void)
349 static int mid_initialize_adc(
struct device *
dev)
369 channel_index = find_free_channel();
370 if (channel_index < 0) {
371 dev_err(dev,
"No free ADC channels");
372 return channel_index;
377 if (!(channel_index == 0 || channel_index ==
ADC_LOOP_MAX)) {
379 ret = reset_stopbit(base_addr);
388 ret = set_up_therm_channel(base_addr);
390 dev_err(dev,
"unable to enable ADC");
393 dev_dbg(dev,
"ADC initialization successful");
425 static int mid_thermal_resume(
struct device *dev)
427 return mid_initialize_adc(dev);
437 static int mid_thermal_suspend(
struct device *dev)
444 return configure_adc(0);
448 mid_thermal_suspend, mid_thermal_resume);
459 return mid_read_temp(tzd, temp);
464 .get_temp = read_curr_temp,
477 "skin0",
"skin1",
"sys",
"msicdie"
489 ret = mid_initialize_adc(&pdev->
dev);
505 0, 0, td_info, &tzd_ops, 0, 0);
506 if (IS_ERR(pinfo->
tzd[i])) {
508 ret = PTR_ERR(pinfo->
tzd[i]);
514 platform_set_drvdata(pdev, pinfo);
545 platform_set_drvdata(pdev,
NULL);
548 return configure_adc(0);
551 #define DRIVER_NAME "msic_thermal"
555 {
"msic_thermal", 1 },
563 .pm = &mid_thermal_pm,
565 .probe = mid_thermal_probe,
567 .id_table = therm_id_table,