Lines Matching refs:pvt
158 static inline void pvt_set_mode(struct pvt_hwmon *pvt, u32 mode) in pvt_set_mode() argument
164 old = pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_set_mode()
165 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_MODE_MASK | PVT_CTRL_EN, in pvt_set_mode()
176 static inline void pvt_set_trim(struct pvt_hwmon *pvt, u32 trim) in pvt_set_trim() argument
182 old = pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_set_trim()
183 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_TRIM_MASK | PVT_CTRL_EN, in pvt_set_trim()
187 static inline void pvt_set_tout(struct pvt_hwmon *pvt, u32 tout) in pvt_set_tout() argument
191 old = pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_set_tout()
192 writel(tout, pvt->regs + PVT_TTIMEOUT); in pvt_set_tout()
193 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, old); in pvt_set_tout()
231 struct pvt_hwmon *pvt = data; in pvt_soft_isr() local
240 thres_sts = readl(pvt->regs + PVT_RAW_INTR_STAT); in pvt_soft_isr()
247 cache = &pvt->cache[pvt->sensor]; in pvt_soft_isr()
248 info = &pvt_info[pvt->sensor]; in pvt_soft_isr()
249 pvt->sensor = (pvt->sensor == PVT_SENSOR_LAST) ? in pvt_soft_isr()
250 PVT_SENSOR_FIRST : (pvt->sensor + 1); in pvt_soft_isr()
261 mutex_lock(&pvt->iface_mtx); in pvt_soft_isr()
263 old = pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, in pvt_soft_isr()
266 val = readl(pvt->regs + PVT_DATA); in pvt_soft_isr()
268 pvt_set_mode(pvt, pvt_info[pvt->sensor].mode); in pvt_soft_isr()
270 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, old); in pvt_soft_isr()
272 mutex_unlock(&pvt->iface_mtx); in pvt_soft_isr()
293 hwmon_notify_event(pvt->hwmon, info->type, info->attr_min_alarm, in pvt_soft_isr()
297 hwmon_notify_event(pvt->hwmon, info->type, info->attr_max_alarm, in pvt_soft_isr()
314 static int pvt_read_data(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_read_data() argument
317 struct pvt_cache *cache = &pvt->cache[type]; in pvt_read_data()
334 static int pvt_read_limit(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_read_limit() argument
340 data = readl(pvt->regs + pvt_info[type].thres_base); in pvt_read_limit()
355 static int pvt_write_limit(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_write_limit() argument
370 ret = mutex_lock_interruptible(&pvt->iface_mtx); in pvt_write_limit()
375 limit = readl(pvt->regs + pvt_info[type].thres_base); in pvt_write_limit()
388 pvt_update(pvt->regs + pvt_info[type].thres_base, mask, data); in pvt_write_limit()
390 mutex_unlock(&pvt->iface_mtx); in pvt_write_limit()
395 static int pvt_read_alarm(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_read_alarm() argument
399 *val = !!READ_ONCE(pvt->cache[type].thres_sts_lo); in pvt_read_alarm()
401 *val = !!READ_ONCE(pvt->cache[type].thres_sts_hi); in pvt_read_alarm()
434 struct pvt_hwmon *pvt = data; in pvt_hard_isr() local
442 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, in pvt_hard_isr()
449 val = readl(pvt->regs + PVT_DATA); in pvt_hard_isr()
451 dev_err(pvt->dev, "Got IRQ when data isn't valid\n"); in pvt_hard_isr()
455 cache = &pvt->cache[pvt->sensor]; in pvt_hard_isr()
476 static int pvt_read_data(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_read_data() argument
479 struct pvt_cache *cache = &pvt->cache[type]; in pvt_read_data()
490 ret = mutex_lock_interruptible(&pvt->iface_mtx); in pvt_read_data()
494 pvt->sensor = type; in pvt_read_data()
495 pvt_set_mode(pvt, pvt_info[type].mode); in pvt_read_data()
501 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, 0); in pvt_read_data()
502 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, PVT_CTRL_EN); in pvt_read_data()
510 timeout = 2 * usecs_to_jiffies(ktime_to_us(pvt->timeout)); in pvt_read_data()
513 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_read_data()
514 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, in pvt_read_data()
519 mutex_unlock(&pvt->iface_mtx); in pvt_read_data()
532 static int pvt_read_limit(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_read_limit() argument
538 static int pvt_write_limit(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_write_limit() argument
544 static int pvt_read_alarm(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_read_alarm() argument
636 static int pvt_read_trim(struct pvt_hwmon *pvt, long *val) in pvt_read_trim() argument
640 data = readl(pvt->regs + PVT_CTRL); in pvt_read_trim()
646 static int pvt_write_trim(struct pvt_hwmon *pvt, long val) in pvt_write_trim() argument
655 ret = mutex_lock_interruptible(&pvt->iface_mtx); in pvt_write_trim()
660 pvt_set_trim(pvt, trim); in pvt_write_trim()
662 mutex_unlock(&pvt->iface_mtx); in pvt_write_trim()
667 static int pvt_read_timeout(struct pvt_hwmon *pvt, long *val) in pvt_read_timeout() argument
671 ret = mutex_lock_interruptible(&pvt->iface_mtx); in pvt_read_timeout()
676 *val = ktime_to_ms(pvt->timeout); in pvt_read_timeout()
678 mutex_unlock(&pvt->iface_mtx); in pvt_read_timeout()
683 static int pvt_write_timeout(struct pvt_hwmon *pvt, long val) in pvt_write_timeout() argument
690 rate = clk_get_rate(pvt->clks[PVT_CLOCK_REF].clk); in pvt_write_timeout()
723 ret = mutex_lock_interruptible(&pvt->iface_mtx); in pvt_write_timeout()
727 pvt_set_tout(pvt, data); in pvt_write_timeout()
728 pvt->timeout = cache; in pvt_write_timeout()
730 mutex_unlock(&pvt->iface_mtx); in pvt_write_timeout()
738 struct pvt_hwmon *pvt = dev_get_drvdata(dev); in pvt_hwmon_read() local
747 return pvt_read_timeout(pvt, val); in pvt_hwmon_read()
753 return pvt_read_data(pvt, ch, val); in pvt_hwmon_read()
758 return pvt_read_limit(pvt, ch, true, val); in pvt_hwmon_read()
760 return pvt_read_limit(pvt, ch, false, val); in pvt_hwmon_read()
762 return pvt_read_alarm(pvt, ch, true, val); in pvt_hwmon_read()
764 return pvt_read_alarm(pvt, ch, false, val); in pvt_hwmon_read()
766 return pvt_read_trim(pvt, val); in pvt_hwmon_read()
772 return pvt_read_data(pvt, PVT_VOLT + ch, val); in pvt_hwmon_read()
774 return pvt_read_limit(pvt, PVT_VOLT + ch, true, val); in pvt_hwmon_read()
776 return pvt_read_limit(pvt, PVT_VOLT + ch, false, val); in pvt_hwmon_read()
778 return pvt_read_alarm(pvt, PVT_VOLT + ch, true, val); in pvt_hwmon_read()
780 return pvt_read_alarm(pvt, PVT_VOLT + ch, false, val); in pvt_hwmon_read()
822 struct pvt_hwmon *pvt = dev_get_drvdata(dev); in pvt_hwmon_write() local
831 return pvt_write_timeout(pvt, val); in pvt_hwmon_write()
837 return pvt_write_limit(pvt, ch, true, val); in pvt_hwmon_write()
839 return pvt_write_limit(pvt, ch, false, val); in pvt_hwmon_write()
841 return pvt_write_trim(pvt, val); in pvt_hwmon_write()
847 return pvt_write_limit(pvt, PVT_VOLT + ch, true, val); in pvt_hwmon_write()
849 return pvt_write_limit(pvt, PVT_VOLT + ch, false, val); in pvt_hwmon_write()
873 struct pvt_hwmon *pvt = data; in pvt_clear_data() local
878 complete_all(&pvt->cache[idx].conversion); in pvt_clear_data()
881 mutex_destroy(&pvt->iface_mtx); in pvt_clear_data()
887 struct pvt_hwmon *pvt; in pvt_create_data() local
890 pvt = devm_kzalloc(dev, sizeof(*pvt), GFP_KERNEL); in pvt_create_data()
891 if (!pvt) in pvt_create_data()
894 ret = devm_add_action(dev, pvt_clear_data, pvt); in pvt_create_data()
900 pvt->dev = dev; in pvt_create_data()
901 pvt->sensor = PVT_SENSOR_FIRST; in pvt_create_data()
902 mutex_init(&pvt->iface_mtx); in pvt_create_data()
906 seqlock_init(&pvt->cache[idx].data_seqlock); in pvt_create_data()
909 init_completion(&pvt->cache[idx].conversion); in pvt_create_data()
912 return pvt; in pvt_create_data()
915 static int pvt_request_regs(struct pvt_hwmon *pvt) in pvt_request_regs() argument
917 struct platform_device *pdev = to_platform_device(pvt->dev); in pvt_request_regs()
922 dev_err(pvt->dev, "Couldn't find PVT memresource\n"); in pvt_request_regs()
926 pvt->regs = devm_ioremap_resource(pvt->dev, res); in pvt_request_regs()
927 if (IS_ERR(pvt->regs)) in pvt_request_regs()
928 return PTR_ERR(pvt->regs); in pvt_request_regs()
935 struct pvt_hwmon *pvt = data; in pvt_disable_clks() local
937 clk_bulk_disable_unprepare(PVT_CLOCK_NUM, pvt->clks); in pvt_disable_clks()
940 static int pvt_request_clks(struct pvt_hwmon *pvt) in pvt_request_clks() argument
944 pvt->clks[PVT_CLOCK_APB].id = "pclk"; in pvt_request_clks()
945 pvt->clks[PVT_CLOCK_REF].id = "ref"; in pvt_request_clks()
947 ret = devm_clk_bulk_get(pvt->dev, PVT_CLOCK_NUM, pvt->clks); in pvt_request_clks()
949 dev_err(pvt->dev, "Couldn't get PVT clocks descriptors\n"); in pvt_request_clks()
953 ret = clk_bulk_prepare_enable(PVT_CLOCK_NUM, pvt->clks); in pvt_request_clks()
955 dev_err(pvt->dev, "Couldn't enable the PVT clocks\n"); in pvt_request_clks()
959 ret = devm_add_action_or_reset(pvt->dev, pvt_disable_clks, pvt); in pvt_request_clks()
961 dev_err(pvt->dev, "Can't add PVT clocks disable action\n"); in pvt_request_clks()
968 static int pvt_check_pwr(struct pvt_hwmon *pvt) in pvt_check_pwr() argument
984 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_ALL, PVT_INTR_ALL); in pvt_check_pwr()
985 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, PVT_CTRL_EN); in pvt_check_pwr()
986 pvt_set_tout(pvt, 0); in pvt_check_pwr()
987 readl(pvt->regs + PVT_DATA); in pvt_check_pwr()
992 data = readl(pvt->regs + PVT_DATA); in pvt_check_pwr()
995 dev_err(pvt->dev, "Sensor is powered down\n"); in pvt_check_pwr()
998 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_check_pwr()
1003 static int pvt_init_iface(struct pvt_hwmon *pvt) in pvt_init_iface() argument
1008 rate = clk_get_rate(pvt->clks[PVT_CLOCK_REF].clk); in pvt_init_iface()
1010 dev_err(pvt->dev, "Invalid reference clock rate\n"); in pvt_init_iface()
1019 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_ALL, PVT_INTR_ALL); in pvt_init_iface()
1020 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_init_iface()
1021 readl(pvt->regs + PVT_CLR_INTR); in pvt_init_iface()
1022 readl(pvt->regs + PVT_DATA); in pvt_init_iface()
1025 pvt_set_mode(pvt, pvt_info[pvt->sensor].mode); in pvt_init_iface()
1026 pvt_set_tout(pvt, PVT_TOUT_DEF); in pvt_init_iface()
1042 pvt->timeout = ktime_set(PVT_SENSORS_NUM * PVT_TOUT_DEF, 0); in pvt_init_iface()
1043 pvt->timeout = ktime_divns(pvt->timeout, rate); in pvt_init_iface()
1044 pvt->timeout = ktime_add_ns(pvt->timeout, PVT_SENSORS_NUM * PVT_TOUT_MIN); in pvt_init_iface()
1046 pvt->timeout = ktime_set(PVT_TOUT_DEF, 0); in pvt_init_iface()
1047 pvt->timeout = ktime_divns(pvt->timeout, rate); in pvt_init_iface()
1048 pvt->timeout = ktime_add_ns(pvt->timeout, PVT_TOUT_MIN); in pvt_init_iface()
1052 if (!of_property_read_u32(pvt->dev->of_node, in pvt_init_iface()
1056 pvt_set_trim(pvt, trim); in pvt_init_iface()
1061 static int pvt_request_irq(struct pvt_hwmon *pvt) in pvt_request_irq() argument
1063 struct platform_device *pdev = to_platform_device(pvt->dev); in pvt_request_irq()
1066 pvt->irq = platform_get_irq(pdev, 0); in pvt_request_irq()
1067 if (pvt->irq < 0) in pvt_request_irq()
1068 return pvt->irq; in pvt_request_irq()
1070 ret = devm_request_threaded_irq(pvt->dev, pvt->irq, in pvt_request_irq()
1078 "pvt", pvt); in pvt_request_irq()
1080 dev_err(pvt->dev, "Couldn't request PVT IRQ\n"); in pvt_request_irq()
1087 static int pvt_create_hwmon(struct pvt_hwmon *pvt) in pvt_create_hwmon() argument
1089 pvt->hwmon = devm_hwmon_device_register_with_info(pvt->dev, "pvt", pvt, in pvt_create_hwmon()
1091 if (IS_ERR(pvt->hwmon)) { in pvt_create_hwmon()
1092 dev_err(pvt->dev, "Couldn't create hwmon device\n"); in pvt_create_hwmon()
1093 return PTR_ERR(pvt->hwmon); in pvt_create_hwmon()
1103 struct pvt_hwmon *pvt = data; in pvt_disable_iface() local
1105 mutex_lock(&pvt->iface_mtx); in pvt_disable_iface()
1106 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_disable_iface()
1107 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, in pvt_disable_iface()
1109 mutex_unlock(&pvt->iface_mtx); in pvt_disable_iface()
1112 static int pvt_enable_iface(struct pvt_hwmon *pvt) in pvt_enable_iface() argument
1116 ret = devm_add_action(pvt->dev, pvt_disable_iface, pvt); in pvt_enable_iface()
1118 dev_err(pvt->dev, "Can't add PVT disable interface action\n"); in pvt_enable_iface()
1128 mutex_lock(&pvt->iface_mtx); in pvt_enable_iface()
1129 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, 0); in pvt_enable_iface()
1130 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, PVT_CTRL_EN); in pvt_enable_iface()
1131 mutex_unlock(&pvt->iface_mtx); in pvt_enable_iface()
1138 static int pvt_enable_iface(struct pvt_hwmon *pvt) in pvt_enable_iface() argument
1147 struct pvt_hwmon *pvt; in pvt_probe() local
1150 pvt = pvt_create_data(pdev); in pvt_probe()
1151 if (IS_ERR(pvt)) in pvt_probe()
1152 return PTR_ERR(pvt); in pvt_probe()
1154 ret = pvt_request_regs(pvt); in pvt_probe()
1158 ret = pvt_request_clks(pvt); in pvt_probe()
1162 ret = pvt_check_pwr(pvt); in pvt_probe()
1166 ret = pvt_init_iface(pvt); in pvt_probe()
1170 ret = pvt_request_irq(pvt); in pvt_probe()
1174 ret = pvt_create_hwmon(pvt); in pvt_probe()
1178 ret = pvt_enable_iface(pvt); in pvt_probe()