Lines Matching +full:ts +full:- +full:coeff +full:- +full:cal5
1 // SPDX-License-Identifier: GPL-2.0
7 * analog IP to enable multiple embedded temperature sensor(TS),
62 /* TS & PD Individual Macro Register */
110 #define PVT_TEMP_MIN_mC -40000
116 #define PVT_SERIES5_J_CONST -100
132 * struct voltage_device - VM single input parameters.
138 * The structure provides mapping between channel-number (0..N-1) to VM-index
139 * (0..num_vm-1) and channel-index (0..ch_num-1) where N = num_vm * ch_num.
149 * struct voltage_channels - VM channel count.
163 u32 cal5; member
187 struct pvt_device *pvt = file->private_data; in pvt_ts_coeff_j_read()
191 len = scnprintf(buf, sizeof(buf), "%d\n", pvt->ts_coeff.j); in pvt_ts_coeff_j_read()
200 struct pvt_device *pvt = file->private_data; in pvt_ts_coeff_j_write()
203 ret = kstrtos32_from_user(user_buf, count, 0, &pvt->ts_coeff.j); in pvt_ts_coeff_j_write()
222 debugfs_remove_recursive(pvt->dbgfs_dir); in devm_pvt_ts_dbgfs_remove()
223 pvt->dbgfs_dir = NULL; in devm_pvt_ts_dbgfs_remove()
228 pvt->dbgfs_dir = debugfs_create_dir(dev_name(dev), NULL); in pvt_ts_dbgfs_create()
230 debugfs_create_u32("ts_coeff_h", 0644, pvt->dbgfs_dir, in pvt_ts_dbgfs_create()
231 &pvt->ts_coeff.h); in pvt_ts_dbgfs_create()
232 debugfs_create_u32("ts_coeff_g", 0644, pvt->dbgfs_dir, in pvt_ts_dbgfs_create()
233 &pvt->ts_coeff.g); in pvt_ts_dbgfs_create()
234 debugfs_create_u32("ts_coeff_cal5", 0644, pvt->dbgfs_dir, in pvt_ts_dbgfs_create()
235 &pvt->ts_coeff.cal5); in pvt_ts_dbgfs_create()
236 debugfs_create_file("ts_coeff_j", 0644, pvt->dbgfs_dir, pvt, in pvt_ts_dbgfs_create()
264 * T = G + H * (n / cal5 - 0.5) + J * F in pvt_calc_temp()
266 struct temp_coeff *ts_coeff = &pvt->ts_coeff; in pvt_calc_temp()
268 s64 tmp = ts_coeff->g + in pvt_calc_temp()
269 div_s64(ts_coeff->h * (s64)nbs, ts_coeff->cal5) - in pvt_calc_temp()
270 ts_coeff->h / 2 + in pvt_calc_temp()
271 div_s64(ts_coeff->j * (s64)pvt->ip_freq, HZ_PER_MHZ); in pvt_calc_temp()
279 struct regmap *t_map = pvt->t_map; in pvt_read_temp()
306 return -EOPNOTSUPP; in pvt_read_temp()
313 struct regmap *v_map = pvt->v_map; in pvt_read_in()
318 if (channel >= pvt->vm_channels.total) in pvt_read_in()
319 return -EINVAL; in pvt_read_in()
321 vm_idx = pvt->vd[channel].vm_map; in pvt_read_in()
322 ch_idx = pvt->vd[channel].ch_map; in pvt_read_in()
338 pre_scaler = pvt->vd[channel].pre_scaler; in pvt_read_in()
350 *val = pre_scaler * (PVT_N_CONST * (long)n - PVT_R_CONST) / in pvt_read_in()
355 return -EOPNOTSUPP; in pvt_read_in()
368 return -EOPNOTSUPP; in pvt_read()
392 struct regmap *t_map = pvt->t_map; in pvt_init()
393 struct regmap *p_map = pvt->p_map; in pvt_init()
394 struct regmap *v_map = pvt->v_map; in pvt_init()
395 u32 t_num = pvt->t_num; in pvt_init()
396 u32 p_num = pvt->p_num; in pvt_init()
397 u32 v_num = pvt->v_num; in pvt_init()
401 sys_freq = clk_get_rate(pvt->clk) / HZ_PER_MHZ; in pvt_init()
409 high = middle - 1; in pvt_init()
420 key = clamp_val(key, CLK_SYS_CYCLES_MIN, CLK_SYS_CYCLES_MAX) - 2; in pvt_init()
426 pvt->ip_freq = clk_get_rate(pvt->clk) / (key + 2); in pvt_init()
491 ret = regmap_write(p_map, SDIF_DISABLE, BIT(p_num) - 1); in pvt_init()
524 val = (BIT(pvt->vm_channels.max) - 1) | VM_CH_INIT | in pvt_init()
584 struct device *dev = &pdev->dev; in pvt_get_regmap()
589 reg_map = &pvt->c_map; in pvt_get_regmap()
590 else if (!strcmp(reg_name, "ts")) in pvt_get_regmap()
591 reg_map = &pvt->t_map; in pvt_get_regmap()
593 reg_map = &pvt->p_map; in pvt_get_regmap()
595 reg_map = &pvt->v_map; in pvt_get_regmap()
597 return -EINVAL; in pvt_get_regmap()
617 reset_control_assert(pvt->rst); in pvt_reset_control_assert()
624 ret = reset_control_deassert(pvt->rst); in pvt_reset_control_deassert()
637 ret = device_property_read_u8_array(dev, "moortec,vm-active-channels", in pvt_get_active_channel()
641 * Incase "moortec,vm-active-channels" property is not defined, in pvt_get_active_channel()
645 pvt->vm_channels.max = ch_num; in pvt_get_active_channel()
646 pvt->vm_channels.total = ch_num * vm_num; in pvt_get_active_channel()
652 return -EINVAL; in pvt_get_active_channel()
655 pvt->vm_channels.total += vm_active_ch[i]; in pvt_get_active_channel()
657 if (vm_active_ch[i] > pvt->vm_channels.max) in pvt_get_active_channel()
658 pvt->vm_channels.max = vm_active_ch[i]; in pvt_get_active_channel()
663 * Map between the channel-number to VM-index and channel-index. in pvt_get_active_channel()
664 * Example - 3 VMs, "moortec,vm_active_ch" = <5 2 4>: in pvt_get_active_channel()
668 pvt->vd = devm_kcalloc(dev, pvt->vm_channels.total, sizeof(*pvt->vd), in pvt_get_active_channel()
670 if (!pvt->vd) in pvt_get_active_channel()
671 return -ENOMEM; in pvt_get_active_channel()
676 pvt->vd[k].vm_map = vm_idx[i]; in pvt_get_active_channel()
677 pvt->vd[k].ch_map = j; in pvt_get_active_channel()
691 /* Set default pre-scaler value to be 1. */ in pvt_get_pre_scaler()
692 for (i = 0; i < pvt->vm_channels.total; i++) in pvt_get_pre_scaler()
693 pvt->vd[i].pre_scaler = PRE_SCALER_X1; in pvt_get_pre_scaler()
695 /* Get number of channels configured in "moortec,vm-pre-scaler-x2". */ in pvt_get_pre_scaler()
696 num_ch = device_property_count_u8(dev, "moortec,vm-pre-scaler-x2"); in pvt_get_pre_scaler()
703 return -ENOMEM; in pvt_get_pre_scaler()
705 /* Get list of all channels that have pre-scaler of 2. */ in pvt_get_pre_scaler()
706 ret = device_property_read_u8_array(dev, "moortec,vm-pre-scaler-x2", in pvt_get_pre_scaler()
713 pvt->vd[channel].pre_scaler = PRE_SCALER_X2; in pvt_get_pre_scaler()
724 struct temp_coeff *ts_coeff = &pvt->ts_coeff; in pvt_set_temp_coeff()
728 /* Incase ts-series property is not defined, use default 5. */ in pvt_set_temp_coeff()
729 ret = device_property_read_u32(dev, "moortec,ts-series", &series); in pvt_set_temp_coeff()
735 ts_coeff->h = PVT_SERIES5_H_CONST; in pvt_set_temp_coeff()
736 ts_coeff->g = PVT_SERIES5_G_CONST; in pvt_set_temp_coeff()
737 ts_coeff->j = PVT_SERIES5_J_CONST; in pvt_set_temp_coeff()
738 ts_coeff->cal5 = PVT_SERIES5_CAL5_CONST; in pvt_set_temp_coeff()
741 ts_coeff->h = PVT_SERIES6_H_CONST; in pvt_set_temp_coeff()
742 ts_coeff->g = PVT_SERIES6_G_CONST; in pvt_set_temp_coeff()
743 ts_coeff->j = PVT_SERIES6_J_CONST; in pvt_set_temp_coeff()
744 ts_coeff->cal5 = PVT_SERIES6_CAL5_CONST; in pvt_set_temp_coeff()
749 return -EINVAL; in pvt_set_temp_coeff()
754 /* Override ts-coeff-h/g/j/cal5 if they are defined. */ in pvt_set_temp_coeff()
755 device_property_read_u32(dev, "moortec,ts-coeff-h", &ts_coeff->h); in pvt_set_temp_coeff()
756 device_property_read_u32(dev, "moortec,ts-coeff-g", &ts_coeff->g); in pvt_set_temp_coeff()
757 device_property_read_u32(dev, "moortec,ts-coeff-j", &ts_coeff->j); in pvt_set_temp_coeff()
758 device_property_read_u32(dev, "moortec,ts-coeff-cal5", &ts_coeff->cal5); in pvt_set_temp_coeff()
760 dev_dbg(dev, "ts-coeff: h = %u, g = %u, j = %d, cal5 = %u\n", in pvt_set_temp_coeff()
761 ts_coeff->h, ts_coeff->g, ts_coeff->j, ts_coeff->cal5); in pvt_set_temp_coeff()
770 struct device *dev = &pdev->dev; in mr75203_probe()
778 return -ENOMEM; in mr75203_probe()
784 pvt->clk = devm_clk_get_enabled(dev, NULL); in mr75203_probe()
785 if (IS_ERR(pvt->clk)) in mr75203_probe()
786 return dev_err_probe(dev, PTR_ERR(pvt->clk), "failed to get clock\n"); in mr75203_probe()
788 pvt->rst = devm_reset_control_get_optional_exclusive(dev, NULL); in mr75203_probe()
789 if (IS_ERR(pvt->rst)) in mr75203_probe()
790 return dev_err_probe(dev, PTR_ERR(pvt->rst), in mr75203_probe()
793 if (pvt->rst) { in mr75203_probe()
800 ret = regmap_read(pvt->c_map, PVT_IP_CONFIG, &val); in mr75203_probe()
808 pvt->t_num = ts_num; in mr75203_probe()
809 pvt->p_num = pd_num; in mr75203_probe()
810 pvt->v_num = vm_num; in mr75203_probe()
817 return -ENODEV; in mr75203_probe()
821 return -ENOMEM; in mr75203_probe()
826 ret = pvt_get_regmap(pdev, "ts", pvt); in mr75203_probe()
837 return -ENOMEM; in mr75203_probe()
859 ret = device_property_read_u8_array(dev, "intel,vm-map", vm_idx, in mr75203_probe()
863 * Incase intel,vm-map property is not defined, we in mr75203_probe()
871 pvt->v_num = i; in mr75203_probe()
885 in_config = devm_kcalloc(dev, pvt->vm_channels.total + 1, in mr75203_probe()
888 return -ENOMEM; in mr75203_probe()
890 memset32(in_config, HWMON_I_INPUT, pvt->vm_channels.total); in mr75203_probe()
891 in_config[pvt->vm_channels.total] = 0; in mr75203_probe()
920 .name = "moortec-pvt",