Lines Matching +full:convert +full:- +full:channels

1 // SPDX-License-Identifier: GPL-2.0
111 #define PVT_TEMP_MIN_mC -40000
117 #define PVT_SERIES5_J_CONST -100
133 * struct voltage_device - VM single input parameters.
139 * The structure provides mapping between channel-number (0..N-1) to VM-index
140 * (0..num_vm-1) and channel-index (0..ch_num-1) where N = num_vm * ch_num.
150 * struct voltage_channels - VM channel count.
151 * @total: Total number of channels in all VMs.
152 * @max: Maximum number of channels among all VMs.
188 struct pvt_device *pvt = file->private_data; in pvt_ts_coeff_j_read()
192 len = scnprintf(buf, sizeof(buf), "%d\n", pvt->ts_coeff.j); in pvt_ts_coeff_j_read()
201 struct pvt_device *pvt = file->private_data; in pvt_ts_coeff_j_write()
204 ret = kstrtos32_from_user(user_buf, count, 0, &pvt->ts_coeff.j); in pvt_ts_coeff_j_write()
223 debugfs_remove_recursive(pvt->dbgfs_dir); in devm_pvt_ts_dbgfs_remove()
224 pvt->dbgfs_dir = NULL; in devm_pvt_ts_dbgfs_remove()
229 pvt->dbgfs_dir = debugfs_create_dir(dev_name(dev), NULL); in pvt_ts_dbgfs_create()
231 debugfs_create_u32("ts_coeff_h", 0644, pvt->dbgfs_dir, in pvt_ts_dbgfs_create()
232 &pvt->ts_coeff.h); in pvt_ts_dbgfs_create()
233 debugfs_create_u32("ts_coeff_g", 0644, pvt->dbgfs_dir, in pvt_ts_dbgfs_create()
234 &pvt->ts_coeff.g); in pvt_ts_dbgfs_create()
235 debugfs_create_u32("ts_coeff_cal5", 0644, pvt->dbgfs_dir, in pvt_ts_dbgfs_create()
236 &pvt->ts_coeff.cal5); in pvt_ts_dbgfs_create()
237 debugfs_create_file("ts_coeff_j", 0644, pvt->dbgfs_dir, pvt, in pvt_ts_dbgfs_create()
264 * Convert the register value to degrees centigrade temperature: in pvt_calc_temp()
265 * T = G + H * (n / cal5 - 0.5) + J * F in pvt_calc_temp()
267 struct temp_coeff *ts_coeff = &pvt->ts_coeff; in pvt_calc_temp()
269 s64 tmp = ts_coeff->g + in pvt_calc_temp()
270 div_s64(ts_coeff->h * (s64)nbs, ts_coeff->cal5) - in pvt_calc_temp()
271 ts_coeff->h / 2 + in pvt_calc_temp()
272 div_s64(ts_coeff->j * (s64)pvt->ip_freq, HZ_PER_MHZ); in pvt_calc_temp()
280 struct regmap *t_map = pvt->t_map; in pvt_read_temp()
300 * Convert the register value to in pvt_read_temp()
307 return -EOPNOTSUPP; in pvt_read_temp()
314 struct regmap *v_map = pvt->v_map; in pvt_read_in()
319 if (channel >= pvt->vm_channels.total) in pvt_read_in()
320 return -EINVAL; in pvt_read_in()
322 vm_idx = pvt->vd[channel].vm_map; in pvt_read_in()
323 ch_idx = pvt->vd[channel].ch_map; in pvt_read_in()
339 pre_scaler = pvt->vd[channel].pre_scaler; in pvt_read_in()
341 * Convert the N bitstream count into voltage. in pvt_read_in()
351 *val = pre_scaler * (PVT_N_CONST * (long)n - PVT_R_CONST) / in pvt_read_in()
356 return -EOPNOTSUPP; in pvt_read_in()
369 return -EOPNOTSUPP; in pvt_read()
393 struct regmap *t_map = pvt->t_map; in pvt_init()
394 struct regmap *p_map = pvt->p_map; in pvt_init()
395 struct regmap *v_map = pvt->v_map; in pvt_init()
396 u32 t_num = pvt->t_num; in pvt_init()
397 u32 p_num = pvt->p_num; in pvt_init()
398 u32 v_num = pvt->v_num; in pvt_init()
402 sys_freq = clk_get_rate(pvt->clk) / HZ_PER_MHZ; in pvt_init()
410 high = middle - 1; in pvt_init()
421 key = clamp_val(key, CLK_SYS_CYCLES_MIN, CLK_SYS_CYCLES_MAX) - 2; in pvt_init()
427 pvt->ip_freq = clk_get_rate(pvt->clk) / (key + 2); in pvt_init()
492 ret = regmap_write(p_map, SDIF_DISABLE, BIT(p_num) - 1); in pvt_init()
525 val = (BIT(pvt->vm_channels.max) - 1) | VM_CH_INIT | in pvt_init()
585 struct device *dev = &pdev->dev; in pvt_get_regmap()
590 reg_map = &pvt->c_map; in pvt_get_regmap()
592 reg_map = &pvt->t_map; in pvt_get_regmap()
594 reg_map = &pvt->p_map; in pvt_get_regmap()
596 reg_map = &pvt->v_map; in pvt_get_regmap()
598 return -EINVAL; in pvt_get_regmap()
618 reset_control_assert(pvt->rst); in pvt_reset_control_assert()
625 ret = reset_control_deassert(pvt->rst); in pvt_reset_control_deassert()
638 ret = device_property_read_u8_array(dev, "moortec,vm-active-channels", in pvt_get_active_channel()
642 * Incase "moortec,vm-active-channels" property is not defined, in pvt_get_active_channel()
643 * we assume each VM sensor has all of its channels active. in pvt_get_active_channel()
646 pvt->vm_channels.max = ch_num; in pvt_get_active_channel()
647 pvt->vm_channels.total = ch_num * vm_num; in pvt_get_active_channel()
651 dev_err(dev, "invalid active channels: %u\n", in pvt_get_active_channel()
653 return -EINVAL; in pvt_get_active_channel()
656 pvt->vm_channels.total += vm_active_ch[i]; in pvt_get_active_channel()
658 if (vm_active_ch[i] > pvt->vm_channels.max) in pvt_get_active_channel()
659 pvt->vm_channels.max = vm_active_ch[i]; in pvt_get_active_channel()
664 * Map between the channel-number to VM-index and channel-index. in pvt_get_active_channel()
665 * Example - 3 VMs, "moortec,vm_active_ch" = <5 2 4>: in pvt_get_active_channel()
669 pvt->vd = devm_kcalloc(dev, pvt->vm_channels.total, sizeof(*pvt->vd), in pvt_get_active_channel()
671 if (!pvt->vd) in pvt_get_active_channel()
672 return -ENOMEM; in pvt_get_active_channel()
677 pvt->vd[k].vm_map = vm_idx[i]; in pvt_get_active_channel()
678 pvt->vd[k].ch_map = j; in pvt_get_active_channel()
692 /* Set default pre-scaler value to be 1. */ in pvt_get_pre_scaler()
693 for (i = 0; i < pvt->vm_channels.total; i++) in pvt_get_pre_scaler()
694 pvt->vd[i].pre_scaler = PRE_SCALER_X1; in pvt_get_pre_scaler()
696 /* Get number of channels configured in "moortec,vm-pre-scaler-x2". */ in pvt_get_pre_scaler()
697 num_ch = device_property_count_u8(dev, "moortec,vm-pre-scaler-x2"); in pvt_get_pre_scaler()
704 return -ENOMEM; in pvt_get_pre_scaler()
706 /* Get list of all channels that have pre-scaler of 2. */ in pvt_get_pre_scaler()
707 ret = device_property_read_u8_array(dev, "moortec,vm-pre-scaler-x2", in pvt_get_pre_scaler()
714 pvt->vd[channel].pre_scaler = PRE_SCALER_X2; in pvt_get_pre_scaler()
725 struct temp_coeff *ts_coeff = &pvt->ts_coeff; in pvt_set_temp_coeff()
729 /* Incase ts-series property is not defined, use default 5. */ in pvt_set_temp_coeff()
730 ret = device_property_read_u32(dev, "moortec,ts-series", &series); in pvt_set_temp_coeff()
736 ts_coeff->h = PVT_SERIES5_H_CONST; in pvt_set_temp_coeff()
737 ts_coeff->g = PVT_SERIES5_G_CONST; in pvt_set_temp_coeff()
738 ts_coeff->j = PVT_SERIES5_J_CONST; in pvt_set_temp_coeff()
739 ts_coeff->cal5 = PVT_SERIES5_CAL5_CONST; in pvt_set_temp_coeff()
742 ts_coeff->h = PVT_SERIES6_H_CONST; in pvt_set_temp_coeff()
743 ts_coeff->g = PVT_SERIES6_G_CONST; in pvt_set_temp_coeff()
744 ts_coeff->j = PVT_SERIES6_J_CONST; in pvt_set_temp_coeff()
745 ts_coeff->cal5 = PVT_SERIES6_CAL5_CONST; in pvt_set_temp_coeff()
750 return -EINVAL; in pvt_set_temp_coeff()
755 /* Override ts-coeff-h/g/j/cal5 if they are defined. */ in pvt_set_temp_coeff()
756 device_property_read_u32(dev, "moortec,ts-coeff-h", &ts_coeff->h); in pvt_set_temp_coeff()
757 device_property_read_u32(dev, "moortec,ts-coeff-g", &ts_coeff->g); in pvt_set_temp_coeff()
758 device_property_read_u32(dev, "moortec,ts-coeff-j", &ts_coeff->j); in pvt_set_temp_coeff()
759 device_property_read_u32(dev, "moortec,ts-coeff-cal5", &ts_coeff->cal5); in pvt_set_temp_coeff()
761 dev_dbg(dev, "ts-coeff: h = %u, g = %u, j = %d, cal5 = %u\n", in pvt_set_temp_coeff()
762 ts_coeff->h, ts_coeff->g, ts_coeff->j, ts_coeff->cal5); in pvt_set_temp_coeff()
771 struct device *dev = &pdev->dev; in mr75203_probe()
779 return -ENOMEM; in mr75203_probe()
785 pvt->clk = devm_clk_get_enabled(dev, NULL); in mr75203_probe()
786 if (IS_ERR(pvt->clk)) in mr75203_probe()
787 return dev_err_probe(dev, PTR_ERR(pvt->clk), "failed to get clock\n"); in mr75203_probe()
789 pvt->rst = devm_reset_control_get_optional_exclusive(dev, NULL); in mr75203_probe()
790 if (IS_ERR(pvt->rst)) in mr75203_probe()
791 return dev_err_probe(dev, PTR_ERR(pvt->rst), in mr75203_probe()
794 if (pvt->rst) { in mr75203_probe()
801 ret = regmap_read(pvt->c_map, PVT_IP_CONFIG, &val); in mr75203_probe()
809 pvt->t_num = ts_num; in mr75203_probe()
810 pvt->p_num = pd_num; in mr75203_probe()
811 pvt->v_num = vm_num; in mr75203_probe()
818 return -ENODEV; in mr75203_probe()
822 return -ENOMEM; in mr75203_probe()
838 return -ENOMEM; in mr75203_probe()
860 ret = device_property_read_u8_array(dev, "intel,vm-map", vm_idx, in mr75203_probe()
864 * Incase intel,vm-map property is not defined, we in mr75203_probe()
872 pvt->v_num = i; in mr75203_probe()
886 in_config = devm_kcalloc(dev, pvt->vm_channels.total + 1, in mr75203_probe()
889 return -ENOMEM; in mr75203_probe()
891 memset32(in_config, HWMON_I_INPUT, pvt->vm_channels.total); in mr75203_probe()
892 in_config[pvt->vm_channels.total] = 0; in mr75203_probe()
921 .name = "moortec-pvt",