1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020 MaxLinear, Inc.
5 * This driver is a hardware monitoring driver for PVT controller
6 * (MR75203) which is used to configure & control Moortec embedded
7 * analog IP to enable multiple embedded temperature sensor(TS),
8 * voltage monitor(VM) & process detector(PD) modules.
10 #include <linux/bits.h>
11 #include <linux/clk.h>
12 #include <linux/debugfs.h>
13 #include <linux/hwmon.h>
14 #include <linux/module.h>
15 #include <linux/mod_devicetable.h>
16 #include <linux/mutex.h>
17 #include <linux/platform_device.h>
18 #include <linux/property.h>
19 #include <linux/regmap.h>
20 #include <linux/reset.h>
21 #include <linux/slab.h>
22 #include <linux/units.h>
24 /* PVT Common register */
25 #define PVT_IP_CONFIG 0x04
26 #define TS_NUM_MSK GENMASK(4, 0)
28 #define PD_NUM_MSK GENMASK(12, 8)
30 #define VM_NUM_MSK GENMASK(20, 16)
32 #define CH_NUM_MSK GENMASK(31, 24)
35 #define VM_NUM_MAX (VM_NUM_MSK >> VM_NUM_SFT)
37 /* Macro Common Register */
38 #define CLK_SYNTH 0x00
39 #define CLK_SYNTH_LO_SFT 0
40 #define CLK_SYNTH_HI_SFT 8
41 #define CLK_SYNTH_HOLD_SFT 16
42 #define CLK_SYNTH_EN BIT(24)
43 #define CLK_SYS_CYCLES_MAX 514
44 #define CLK_SYS_CYCLES_MIN 2
46 #define SDIF_DISABLE 0x04
48 #define SDIF_STAT 0x08
49 #define SDIF_BUSY BIT(0)
50 #define SDIF_LOCK BIT(1)
53 #define SDIF_PROG BIT(31)
54 #define SDIF_WRN_W BIT(27)
55 #define SDIF_WRN_R 0x00
56 #define SDIF_ADDR_SFT 24
58 #define SDIF_HALT 0x10
59 #define SDIF_CTRL 0x14
60 #define SDIF_SMPL_CTRL 0x20
62 /* TS & PD Individual Macro Register */
63 #define COM_REG_SIZE 0x40
65 #define SDIF_DONE(n) (COM_REG_SIZE + 0x14 + 0x40 * (n))
66 #define SDIF_SMPL_DONE BIT(0)
68 #define SDIF_DATA(n) (COM_REG_SIZE + 0x18 + 0x40 * (n))
69 #define SAMPLE_DATA_MSK GENMASK(15, 0)
71 #define HILO_RESET(n) (COM_REG_SIZE + 0x2c + 0x40 * (n))
73 /* VM Individual Macro Register */
74 #define VM_COM_REG_SIZE 0x200
75 #define VM_SDIF_DONE(vm) (VM_COM_REG_SIZE + 0x34 + 0x200 * (vm))
76 #define VM_SDIF_DATA(vm, ch) \
77 (VM_COM_REG_SIZE + 0x40 + 0x200 * (vm) + 0x4 * (ch))
79 /* SDA Slave Register */
81 #define IP_RST_REL BIT(1)
82 #define IP_RUN_CONT BIT(3)
83 #define IP_AUTO BIT(8)
84 #define IP_VM_MODE BIT(10)
87 #define CFG0_MODE_2 BIT(0)
88 #define CFG0_PARALLEL_OUT 0
90 #define CFG1_VOL_MEAS_MODE 0
91 #define CFG1_PARALLEL_OUT 0
97 #define VM_CH_INIT BIT(20)
98 #define VM_CH_REQ BIT(21)
101 #define POWER_DELAY_CYCLE_256 0x100
102 #define POWER_DELAY_CYCLE_64 0x40
104 #define PVT_POLL_DELAY_US 20
105 #define PVT_POLL_TIMEOUT_US 20000
106 #define PVT_CONV_BITS 10
107 #define PVT_N_CONST 90
108 #define PVT_R_CONST 245805
110 #define PVT_TEMP_MIN_mC -40000
111 #define PVT_TEMP_MAX_mC 125000
113 /* Temperature coefficients for series 5 */
114 #define PVT_SERIES5_H_CONST 200000
115 #define PVT_SERIES5_G_CONST 60000
116 #define PVT_SERIES5_J_CONST -100
117 #define PVT_SERIES5_CAL5_CONST 4094
119 /* Temperature coefficients for series 6 */
120 #define PVT_SERIES6_H_CONST 249400
121 #define PVT_SERIES6_G_CONST 57400
122 #define PVT_SERIES6_J_CONST 0
123 #define PVT_SERIES6_CAL5_CONST 4096
125 #define TEMPERATURE_SENSOR_SERIES_5 5
126 #define TEMPERATURE_SENSOR_SERIES_6 6
128 #define PRE_SCALER_X1 1
129 #define PRE_SCALER_X2 2
132 * struct voltage_device - VM single input parameters.
133 * @vm_map: Map channel number to VM index.
134 * @ch_map: Map channel number to channel index.
135 * @pre_scaler: Pre scaler value (1 or 2) used to normalize the voltage output
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.
140 * It also provides normalization factor for the VM equation.
142 struct voltage_device {
149 * struct voltage_channels - VM channel count.
150 * @total: Total number of channels in all VMs.
151 * @max: Maximum number of channels among all VMs.
153 * The structure provides channel count information across all VMs.
155 struct voltage_channels {
168 struct regmap *c_map;
169 struct regmap *t_map;
170 struct regmap *p_map;
171 struct regmap *v_map;
173 struct reset_control *rst;
174 struct dentry *dbgfs_dir;
175 struct voltage_device *vd;
176 struct voltage_channels vm_channels;
177 struct temp_coeff ts_coeff;
184 static ssize_t pvt_ts_coeff_j_read(struct file *file, char __user *user_buf,
185 size_t count, loff_t *ppos)
187 struct pvt_device *pvt = file->private_data;
191 len = scnprintf(buf, sizeof(buf), "%d\n", pvt->ts_coeff.j);
193 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
196 static ssize_t pvt_ts_coeff_j_write(struct file *file,
197 const char __user *user_buf,
198 size_t count, loff_t *ppos)
200 struct pvt_device *pvt = file->private_data;
203 ret = kstrtos32_from_user(user_buf, count, 0, &pvt->ts_coeff.j);
210 static const struct file_operations pvt_ts_coeff_j_fops = {
211 .read = pvt_ts_coeff_j_read,
212 .write = pvt_ts_coeff_j_write,
214 .owner = THIS_MODULE,
215 .llseek = default_llseek,
218 static void devm_pvt_ts_dbgfs_remove(void *data)
220 struct pvt_device *pvt = (struct pvt_device *)data;
222 debugfs_remove_recursive(pvt->dbgfs_dir);
223 pvt->dbgfs_dir = NULL;
226 static int pvt_ts_dbgfs_create(struct pvt_device *pvt, struct device *dev)
228 pvt->dbgfs_dir = debugfs_create_dir(dev_name(dev), NULL);
230 debugfs_create_u32("ts_coeff_h", 0644, pvt->dbgfs_dir,
232 debugfs_create_u32("ts_coeff_g", 0644, pvt->dbgfs_dir,
234 debugfs_create_u32("ts_coeff_cal5", 0644, pvt->dbgfs_dir,
235 &pvt->ts_coeff.cal5);
236 debugfs_create_file("ts_coeff_j", 0644, pvt->dbgfs_dir, pvt,
237 &pvt_ts_coeff_j_fops);
239 return devm_add_action_or_reset(dev, devm_pvt_ts_dbgfs_remove, pvt);
242 static umode_t pvt_is_visible(const void *data, enum hwmon_sensor_types type,
243 u32 attr, int channel)
247 if (attr == hwmon_temp_input)
251 if (attr == hwmon_in_input)
260 static long pvt_calc_temp(struct pvt_device *pvt, u32 nbs)
263 * Convert the register value to degrees centigrade temperature:
264 * T = G + H * (n / cal5 - 0.5) + J * F
266 struct temp_coeff *ts_coeff = &pvt->ts_coeff;
268 s64 tmp = ts_coeff->g +
269 div_s64(ts_coeff->h * (s64)nbs, ts_coeff->cal5) -
271 div_s64(ts_coeff->j * (s64)pvt->ip_freq, HZ_PER_MHZ);
273 return clamp_val(tmp, PVT_TEMP_MIN_mC, PVT_TEMP_MAX_mC);
276 static int pvt_read_temp(struct device *dev, u32 attr, int channel, long *val)
278 struct pvt_device *pvt = dev_get_drvdata(dev);
279 struct regmap *t_map = pvt->t_map;
284 case hwmon_temp_input:
285 ret = regmap_read_poll_timeout(t_map, SDIF_DONE(channel),
286 stat, stat & SDIF_SMPL_DONE,
288 PVT_POLL_TIMEOUT_US);
292 ret = regmap_read(t_map, SDIF_DATA(channel), &nbs);
296 nbs &= SAMPLE_DATA_MSK;
299 * Convert the register value to
300 * degrees centigrade temperature
302 *val = pvt_calc_temp(pvt, nbs);
310 static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val)
312 struct pvt_device *pvt = dev_get_drvdata(dev);
313 struct regmap *v_map = pvt->v_map;
314 u32 n, stat, pre_scaler;
318 if (channel >= pvt->vm_channels.total)
321 vm_idx = pvt->vd[channel].vm_map;
322 ch_idx = pvt->vd[channel].ch_map;
326 ret = regmap_read_poll_timeout(v_map, VM_SDIF_DONE(vm_idx),
327 stat, stat & SDIF_SMPL_DONE,
329 PVT_POLL_TIMEOUT_US);
333 ret = regmap_read(v_map, VM_SDIF_DATA(vm_idx, ch_idx), &n);
337 n &= SAMPLE_DATA_MSK;
338 pre_scaler = pvt->vd[channel].pre_scaler;
340 * Convert the N bitstream count into voltage.
341 * To support negative voltage calculation for 64bit machines
342 * n must be cast to long, since n and *val differ both in
343 * signedness and in size.
344 * Division is used instead of right shift, because for signed
345 * numbers, the sign bit is used to fill the vacated bit
346 * positions, and if the number is negative, 1 is used.
347 * BIT(x) may not be used instead of (1 << x) because it's
350 *val = pre_scaler * (PVT_N_CONST * (long)n - PVT_R_CONST) /
351 (1 << PVT_CONV_BITS);
359 static int pvt_read(struct device *dev, enum hwmon_sensor_types type,
360 u32 attr, int channel, long *val)
364 return pvt_read_temp(dev, attr, channel, val);
366 return pvt_read_in(dev, attr, channel, val);
372 static struct hwmon_channel_info pvt_temp = {
376 static struct hwmon_channel_info pvt_in = {
380 static const struct hwmon_ops pvt_hwmon_ops = {
381 .is_visible = pvt_is_visible,
385 static struct hwmon_chip_info pvt_chip_info = {
386 .ops = &pvt_hwmon_ops,
389 static int pvt_init(struct pvt_device *pvt)
391 u16 sys_freq, key, middle, low = 4, high = 8;
392 struct regmap *t_map = pvt->t_map;
393 struct regmap *p_map = pvt->p_map;
394 struct regmap *v_map = pvt->v_map;
395 u32 t_num = pvt->t_num;
396 u32 p_num = pvt->p_num;
397 u32 v_num = pvt->v_num;
401 sys_freq = clk_get_rate(pvt->clk) / HZ_PER_MHZ;
402 while (high >= low) {
403 middle = (low + high + 1) / 2;
404 key = DIV_ROUND_CLOSEST(sys_freq, middle);
405 if (key > CLK_SYS_CYCLES_MAX) {
408 } else if (key < CLK_SYS_CYCLES_MIN) {
417 * The system supports 'clk_sys' to 'clk_ip' frequency ratios
420 key = clamp_val(key, CLK_SYS_CYCLES_MIN, CLK_SYS_CYCLES_MAX) - 2;
422 clk_synth = ((key + 1) >> 1) << CLK_SYNTH_LO_SFT |
423 (key >> 1) << CLK_SYNTH_HI_SFT |
424 (key >> 1) << CLK_SYNTH_HOLD_SFT | CLK_SYNTH_EN;
426 pvt->ip_freq = clk_get_rate(pvt->clk) / (key + 2);
429 ret = regmap_write(t_map, SDIF_SMPL_CTRL, 0x0);
433 ret = regmap_write(t_map, SDIF_HALT, 0x0);
437 ret = regmap_write(t_map, CLK_SYNTH, clk_synth);
441 ret = regmap_write(t_map, SDIF_DISABLE, 0x0);
445 ret = regmap_read_poll_timeout(t_map, SDIF_STAT,
446 val, !(val & SDIF_BUSY),
448 PVT_POLL_TIMEOUT_US);
452 val = CFG0_MODE_2 | CFG0_PARALLEL_OUT | CFG0_12_BIT |
453 IP_CFG << SDIF_ADDR_SFT | SDIF_WRN_W | SDIF_PROG;
454 ret = regmap_write(t_map, SDIF_W, val);
458 ret = regmap_read_poll_timeout(t_map, SDIF_STAT,
459 val, !(val & SDIF_BUSY),
461 PVT_POLL_TIMEOUT_US);
465 val = POWER_DELAY_CYCLE_256 | IP_TMR << SDIF_ADDR_SFT |
466 SDIF_WRN_W | SDIF_PROG;
467 ret = regmap_write(t_map, SDIF_W, val);
471 ret = regmap_read_poll_timeout(t_map, SDIF_STAT,
472 val, !(val & SDIF_BUSY),
474 PVT_POLL_TIMEOUT_US);
478 val = IP_RST_REL | IP_RUN_CONT | IP_AUTO |
479 IP_CTRL << SDIF_ADDR_SFT |
480 SDIF_WRN_W | SDIF_PROG;
481 ret = regmap_write(t_map, SDIF_W, val);
487 ret = regmap_write(p_map, SDIF_HALT, 0x0);
491 ret = regmap_write(p_map, SDIF_DISABLE, BIT(p_num) - 1);
495 ret = regmap_write(p_map, CLK_SYNTH, clk_synth);
501 ret = regmap_write(v_map, SDIF_SMPL_CTRL, 0x0);
505 ret = regmap_write(v_map, SDIF_HALT, 0x0);
509 ret = regmap_write(v_map, CLK_SYNTH, clk_synth);
513 ret = regmap_write(v_map, SDIF_DISABLE, 0x0);
517 ret = regmap_read_poll_timeout(v_map, SDIF_STAT,
518 val, !(val & SDIF_BUSY),
520 PVT_POLL_TIMEOUT_US);
524 val = (BIT(pvt->vm_channels.max) - 1) | VM_CH_INIT |
525 IP_POLL << SDIF_ADDR_SFT | SDIF_WRN_W | SDIF_PROG;
526 ret = regmap_write(v_map, SDIF_W, val);
530 ret = regmap_read_poll_timeout(v_map, SDIF_STAT,
531 val, !(val & SDIF_BUSY),
533 PVT_POLL_TIMEOUT_US);
537 val = CFG1_VOL_MEAS_MODE | CFG1_PARALLEL_OUT |
538 CFG1_14_BIT | IP_CFG << SDIF_ADDR_SFT |
539 SDIF_WRN_W | SDIF_PROG;
540 ret = regmap_write(v_map, SDIF_W, val);
544 ret = regmap_read_poll_timeout(v_map, SDIF_STAT,
545 val, !(val & SDIF_BUSY),
547 PVT_POLL_TIMEOUT_US);
551 val = POWER_DELAY_CYCLE_64 | IP_TMR << SDIF_ADDR_SFT |
552 SDIF_WRN_W | SDIF_PROG;
553 ret = regmap_write(v_map, SDIF_W, val);
557 ret = regmap_read_poll_timeout(v_map, SDIF_STAT,
558 val, !(val & SDIF_BUSY),
560 PVT_POLL_TIMEOUT_US);
564 val = IP_RST_REL | IP_RUN_CONT | IP_AUTO | IP_VM_MODE |
565 IP_CTRL << SDIF_ADDR_SFT |
566 SDIF_WRN_W | SDIF_PROG;
567 ret = regmap_write(v_map, SDIF_W, val);
575 static struct regmap_config pvt_regmap_config = {
581 static int pvt_get_regmap(struct platform_device *pdev, char *reg_name,
582 struct pvt_device *pvt)
584 struct device *dev = &pdev->dev;
585 struct regmap **reg_map;
586 void __iomem *io_base;
588 if (!strcmp(reg_name, "common"))
589 reg_map = &pvt->c_map;
590 else if (!strcmp(reg_name, "ts"))
591 reg_map = &pvt->t_map;
592 else if (!strcmp(reg_name, "pd"))
593 reg_map = &pvt->p_map;
594 else if (!strcmp(reg_name, "vm"))
595 reg_map = &pvt->v_map;
599 io_base = devm_platform_ioremap_resource_byname(pdev, reg_name);
601 return PTR_ERR(io_base);
603 pvt_regmap_config.name = reg_name;
604 *reg_map = devm_regmap_init_mmio(dev, io_base, &pvt_regmap_config);
605 if (IS_ERR(*reg_map)) {
606 dev_err(dev, "failed to init register map\n");
607 return PTR_ERR(*reg_map);
613 static void pvt_reset_control_assert(void *data)
615 struct pvt_device *pvt = data;
617 reset_control_assert(pvt->rst);
620 static int pvt_reset_control_deassert(struct device *dev, struct pvt_device *pvt)
624 ret = reset_control_deassert(pvt->rst);
628 return devm_add_action_or_reset(dev, pvt_reset_control_assert, pvt);
631 static int pvt_get_active_channel(struct device *dev, struct pvt_device *pvt,
632 u32 vm_num, u32 ch_num, u8 *vm_idx)
634 u8 vm_active_ch[VM_NUM_MAX];
637 ret = device_property_read_u8_array(dev, "moortec,vm-active-channels",
638 vm_active_ch, vm_num);
641 * Incase "moortec,vm-active-channels" property is not defined,
642 * we assume each VM sensor has all of its channels active.
644 memset(vm_active_ch, ch_num, vm_num);
645 pvt->vm_channels.max = ch_num;
646 pvt->vm_channels.total = ch_num * vm_num;
648 for (i = 0; i < vm_num; i++) {
649 if (vm_active_ch[i] > ch_num) {
650 dev_err(dev, "invalid active channels: %u\n",
655 pvt->vm_channels.total += vm_active_ch[i];
657 if (vm_active_ch[i] > pvt->vm_channels.max)
658 pvt->vm_channels.max = vm_active_ch[i];
663 * Map between the channel-number to VM-index and channel-index.
664 * Example - 3 VMs, "moortec,vm_active_ch" = <5 2 4>:
665 * vm_map = [0 0 0 0 0 1 1 2 2 2 2]
666 * ch_map = [0 1 2 3 4 0 1 0 1 2 3]
668 pvt->vd = devm_kcalloc(dev, pvt->vm_channels.total, sizeof(*pvt->vd),
674 for (i = 0; i < vm_num; i++) {
675 for (j = 0; j < vm_active_ch[i]; j++) {
676 pvt->vd[k].vm_map = vm_idx[i];
677 pvt->vd[k].ch_map = j;
685 static int pvt_get_pre_scaler(struct device *dev, struct pvt_device *pvt)
687 u8 *pre_scaler_ch_list;
691 /* Set default pre-scaler value to be 1. */
692 for (i = 0; i < pvt->vm_channels.total; i++)
693 pvt->vd[i].pre_scaler = PRE_SCALER_X1;
695 /* Get number of channels configured in "moortec,vm-pre-scaler-x2". */
696 num_ch = device_property_count_u8(dev, "moortec,vm-pre-scaler-x2");
700 pre_scaler_ch_list = kcalloc(num_ch, sizeof(*pre_scaler_ch_list),
702 if (!pre_scaler_ch_list)
705 /* Get list of all channels that have pre-scaler of 2. */
706 ret = device_property_read_u8_array(dev, "moortec,vm-pre-scaler-x2",
707 pre_scaler_ch_list, num_ch);
711 for (i = 0; i < num_ch; i++) {
712 channel = pre_scaler_ch_list[i];
713 pvt->vd[channel].pre_scaler = PRE_SCALER_X2;
717 kfree(pre_scaler_ch_list);
722 static int pvt_set_temp_coeff(struct device *dev, struct pvt_device *pvt)
724 struct temp_coeff *ts_coeff = &pvt->ts_coeff;
728 /* Incase ts-series property is not defined, use default 5. */
729 ret = device_property_read_u32(dev, "moortec,ts-series", &series);
731 series = TEMPERATURE_SENSOR_SERIES_5;
734 case TEMPERATURE_SENSOR_SERIES_5:
735 ts_coeff->h = PVT_SERIES5_H_CONST;
736 ts_coeff->g = PVT_SERIES5_G_CONST;
737 ts_coeff->j = PVT_SERIES5_J_CONST;
738 ts_coeff->cal5 = PVT_SERIES5_CAL5_CONST;
740 case TEMPERATURE_SENSOR_SERIES_6:
741 ts_coeff->h = PVT_SERIES6_H_CONST;
742 ts_coeff->g = PVT_SERIES6_G_CONST;
743 ts_coeff->j = PVT_SERIES6_J_CONST;
744 ts_coeff->cal5 = PVT_SERIES6_CAL5_CONST;
747 dev_err(dev, "invalid temperature sensor series (%u)\n",
752 dev_dbg(dev, "temperature sensor series = %u\n", series);
754 /* Override ts-coeff-h/g/j/cal5 if they are defined. */
755 device_property_read_u32(dev, "moortec,ts-coeff-h", &ts_coeff->h);
756 device_property_read_u32(dev, "moortec,ts-coeff-g", &ts_coeff->g);
757 device_property_read_u32(dev, "moortec,ts-coeff-j", &ts_coeff->j);
758 device_property_read_u32(dev, "moortec,ts-coeff-cal5", &ts_coeff->cal5);
760 dev_dbg(dev, "ts-coeff: h = %u, g = %u, j = %d, cal5 = %u\n",
761 ts_coeff->h, ts_coeff->g, ts_coeff->j, ts_coeff->cal5);
766 static int mr75203_probe(struct platform_device *pdev)
768 u32 ts_num, vm_num, pd_num, ch_num, val, index, i;
769 const struct hwmon_channel_info **pvt_info;
770 struct device *dev = &pdev->dev;
771 u32 *temp_config, *in_config;
772 struct device *hwmon_dev;
773 struct pvt_device *pvt;
776 pvt = devm_kzalloc(dev, sizeof(*pvt), GFP_KERNEL);
780 ret = pvt_get_regmap(pdev, "common", pvt);
784 pvt->clk = devm_clk_get_enabled(dev, NULL);
785 if (IS_ERR(pvt->clk))
786 return dev_err_probe(dev, PTR_ERR(pvt->clk), "failed to get clock\n");
788 pvt->rst = devm_reset_control_get_optional_exclusive(dev, NULL);
789 if (IS_ERR(pvt->rst))
790 return dev_err_probe(dev, PTR_ERR(pvt->rst),
791 "failed to get reset control\n");
794 ret = pvt_reset_control_deassert(dev, pvt);
796 return dev_err_probe(dev, ret,
797 "cannot deassert reset control\n");
800 ret = regmap_read(pvt->c_map, PVT_IP_CONFIG, &val);
804 ts_num = (val & TS_NUM_MSK) >> TS_NUM_SFT;
805 pd_num = (val & PD_NUM_MSK) >> PD_NUM_SFT;
806 vm_num = (val & VM_NUM_MSK) >> VM_NUM_SFT;
807 ch_num = (val & CH_NUM_MSK) >> CH_NUM_SFT;
819 pvt_info = devm_kcalloc(dev, val + 2, sizeof(*pvt_info), GFP_KERNEL);
822 pvt_info[0] = HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ);
826 ret = pvt_get_regmap(pdev, "ts", pvt);
830 ret = pvt_set_temp_coeff(dev, pvt);
834 temp_config = devm_kcalloc(dev, ts_num + 1,
835 sizeof(*temp_config), GFP_KERNEL);
839 memset32(temp_config, HWMON_T_INPUT, ts_num);
840 pvt_temp.config = temp_config;
841 pvt_info[index++] = &pvt_temp;
843 pvt_ts_dbgfs_create(pvt, dev);
847 ret = pvt_get_regmap(pdev, "pd", pvt);
853 u8 vm_idx[VM_NUM_MAX];
855 ret = pvt_get_regmap(pdev, "vm", pvt);
859 ret = device_property_read_u8_array(dev, "intel,vm-map", vm_idx,
863 * Incase intel,vm-map property is not defined, we
864 * assume incremental channel numbers.
866 for (i = 0; i < vm_num; i++)
869 for (i = 0; i < vm_num; i++)
870 if (vm_idx[i] >= vm_num || vm_idx[i] == 0xff) {
877 ret = pvt_get_active_channel(dev, pvt, vm_num, ch_num, vm_idx);
881 ret = pvt_get_pre_scaler(dev, pvt);
885 in_config = devm_kcalloc(dev, pvt->vm_channels.total + 1,
886 sizeof(*in_config), GFP_KERNEL);
890 memset32(in_config, HWMON_I_INPUT, pvt->vm_channels.total);
891 in_config[pvt->vm_channels.total] = 0;
892 pvt_in.config = in_config;
894 pvt_info[index++] = &pvt_in;
899 dev_err(dev, "failed to init pvt: %d\n", ret);
903 pvt_chip_info.info = pvt_info;
904 hwmon_dev = devm_hwmon_device_register_with_info(dev, "pvt",
909 return PTR_ERR_OR_ZERO(hwmon_dev);
912 static const struct of_device_id moortec_pvt_of_match[] = {
913 { .compatible = "moortec,mr75203" },
916 MODULE_DEVICE_TABLE(of, moortec_pvt_of_match);
918 static struct platform_driver moortec_pvt_driver = {
920 .name = "moortec-pvt",
921 .of_match_table = moortec_pvt_of_match,
923 .probe = mr75203_probe,
925 module_platform_driver(moortec_pvt_driver);
927 MODULE_LICENSE("GPL v2");