Lines Matching refs:data
344 static int ntc_adc_iio_read(struct ntc_data *data)
346 struct iio_channel *channel = data->chan;
366 uv = (data->pullup_uv * (s64)raw) >> 12;
382 static int get_ohm_of_thermistor(struct ntc_data *data, unsigned int uv)
384 u32 puv = data->pullup_uv;
386 puo = data->pullup_ohm;
387 pdo = data->pulldown_ohm;
390 return (data->connect == NTC_CONNECTED_POSITIVE) ?
393 return (data->connect == NTC_CONNECTED_POSITIVE) ?
396 if (data->connect == NTC_CONNECTED_POSITIVE && puo == 0)
398 else if (data->connect == NTC_CONNECTED_GROUND && pdo == 0)
400 else if (data->connect == NTC_CONNECTED_POSITIVE)
411 static void lookup_comp(struct ntc_data *data, unsigned int ohm,
423 if (ohm >= data->comp[0].ohm) {
428 if (ohm <= data->comp[data->n_comp - 1].ohm) {
429 *i_low = data->n_comp - 1;
430 *i_high = data->n_comp - 1;
436 end = data->n_comp;
441 * data->comp[start].ohm > ohm >= data->comp[end].ohm
443 * We could check for "ohm == data->comp[mid].ohm" here, but
448 if (ohm >= data->comp[mid].ohm) {
453 * ohm >= data->comp[start].ohm might be true here,
458 if (ohm >= data->comp[start].ohm)
463 * data->comp[start].ohm >= ohm >= data->comp[end].ohm
468 * ohm >= data->comp[end].ohm
471 if (ohm == data->comp[end].ohm)
477 static int get_temp_mc(struct ntc_data *data, unsigned int ohm)
482 lookup_comp(data, ohm, &low, &high);
488 temp = fixp_linear_interpolate(data->comp[low].ohm,
489 data->comp[low].temp_c * 1000,
490 data->comp[high].ohm,
491 data->comp[high].temp_c * 1000,
496 static int ntc_thermistor_get_ohm(struct ntc_data *data)
500 read_uv = ntc_adc_iio_read(data);
503 return get_ohm_of_thermistor(data, read_uv);
509 struct ntc_data *data = dev_get_drvdata(dev);
516 ohm = ntc_thermistor_get_ohm(data);
519 *val = get_temp_mc(data, ohm);
534 static umode_t ntc_is_visible(const void *data, enum hwmon_sensor_types type,
566 struct ntc_data *data)
583 ret = device_property_read_u32(dev, "pullup-uv", &data->pullup_uv);
587 ret = device_property_read_u32(dev, "pullup-ohm", &data->pullup_ohm);
591 ret = device_property_read_u32(dev, "pulldown-ohm", &data->pulldown_ohm);
596 data->connect = NTC_CONNECTED_POSITIVE;
598 data->connect = NTC_CONNECTED_GROUND;
600 data->chan = chan;
610 struct ntc_data *data;
613 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
614 if (!data)
617 ret = ntc_thermistor_parse_props(dev, data);
621 if (data->pullup_uv == 0 ||
622 (data->pullup_ohm == 0 && data->connect ==
624 (data->pulldown_ohm == 0 && data->connect ==
626 (data->connect != NTC_CONNECTED_POSITIVE &&
627 data->connect != NTC_CONNECTED_GROUND)) {
628 dev_err(dev, "Required data to use NTC driver not supplied.\n");
640 data->comp = ntc_type[pdev_id->driver_data].comp;
641 data->n_comp = ntc_type[pdev_id->driver_data].n_comp;
644 data, &ntc_chip_info,
659 .data = &ntc_thermistor_id[NTC_B57330V2103]},
661 .data = &ntc_thermistor_id[NTC_B57891S0103] },
663 .data = &ntc_thermistor_id[NTC_NCP03WB473] },
665 .data = &ntc_thermistor_id[NTC_NCP03WF104] },
667 .data = &ntc_thermistor_id[NTC_NCP15WB473] },
669 .data = &ntc_thermistor_id[NTC_NCP15WL333] },
671 .data = &ntc_thermistor_id[NTC_NCP15XH103] },
673 .data = &ntc_thermistor_id[NTC_NCP18WB473] },
675 .data = &ntc_thermistor_id[NTC_NCP21WB473] },
677 .data = &ntc_thermistor_id[NTC_SSG1404001221] },
681 .data = &ntc_thermistor_id[NTC_NCP03WB473] },
683 .data = &ntc_thermistor_id[NTC_NCP15WB473] },
685 .data = &ntc_thermistor_id[NTC_NCP15WL333] },
687 .data = &ntc_thermistor_id[NTC_NCP18WB473] },
689 .data = &ntc_thermistor_id[NTC_NCP21WB473] },