Lines Matching refs:pvt
134 static inline void pvt_set_mode(struct pvt_hwmon *pvt, u32 mode) in pvt_set_mode() argument
140 old = pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_set_mode()
141 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_MODE_MASK | PVT_CTRL_EN, in pvt_set_mode()
152 static inline void pvt_set_trim(struct pvt_hwmon *pvt, u32 trim) in pvt_set_trim() argument
158 old = pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_set_trim()
159 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_TRIM_MASK | PVT_CTRL_EN, in pvt_set_trim()
163 static inline void pvt_set_tout(struct pvt_hwmon *pvt, u32 tout) in pvt_set_tout() argument
167 old = pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_set_tout()
168 writel(tout, pvt->regs + PVT_TTIMEOUT); in pvt_set_tout()
169 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, old); in pvt_set_tout()
207 struct pvt_hwmon *pvt = data; in pvt_soft_isr() local
216 thres_sts = readl(pvt->regs + PVT_RAW_INTR_STAT); in pvt_soft_isr()
223 cache = &pvt->cache[pvt->sensor]; in pvt_soft_isr()
224 info = &pvt_info[pvt->sensor]; in pvt_soft_isr()
225 pvt->sensor = (pvt->sensor == PVT_SENSOR_LAST) ? in pvt_soft_isr()
226 PVT_SENSOR_FIRST : (pvt->sensor + 1); in pvt_soft_isr()
237 mutex_lock(&pvt->iface_mtx); in pvt_soft_isr()
239 old = pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, in pvt_soft_isr()
242 val = readl(pvt->regs + PVT_DATA); in pvt_soft_isr()
244 pvt_set_mode(pvt, pvt_info[pvt->sensor].mode); in pvt_soft_isr()
246 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, old); in pvt_soft_isr()
248 mutex_unlock(&pvt->iface_mtx); in pvt_soft_isr()
269 hwmon_notify_event(pvt->hwmon, info->type, info->attr_min_alarm, in pvt_soft_isr()
273 hwmon_notify_event(pvt->hwmon, info->type, info->attr_max_alarm, in pvt_soft_isr()
290 static int pvt_read_data(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_read_data() argument
293 struct pvt_cache *cache = &pvt->cache[type]; in pvt_read_data()
310 static int pvt_read_limit(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_read_limit() argument
316 data = readl(pvt->regs + pvt_info[type].thres_base); in pvt_read_limit()
331 static int pvt_write_limit(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_write_limit() argument
346 ret = mutex_lock_interruptible(&pvt->iface_mtx); in pvt_write_limit()
351 limit = readl(pvt->regs + pvt_info[type].thres_base); in pvt_write_limit()
364 pvt_update(pvt->regs + pvt_info[type].thres_base, mask, data); in pvt_write_limit()
366 mutex_unlock(&pvt->iface_mtx); in pvt_write_limit()
371 static int pvt_read_alarm(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_read_alarm() argument
375 *val = !!READ_ONCE(pvt->cache[type].thres_sts_lo); in pvt_read_alarm()
377 *val = !!READ_ONCE(pvt->cache[type].thres_sts_hi); in pvt_read_alarm()
410 struct pvt_hwmon *pvt = data; in pvt_hard_isr() local
418 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, in pvt_hard_isr()
425 val = readl(pvt->regs + PVT_DATA); in pvt_hard_isr()
427 dev_err(pvt->dev, "Got IRQ when data isn't valid\n"); in pvt_hard_isr()
431 cache = &pvt->cache[pvt->sensor]; in pvt_hard_isr()
452 static int pvt_read_data(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_read_data() argument
455 struct pvt_cache *cache = &pvt->cache[type]; in pvt_read_data()
466 ret = mutex_lock_interruptible(&pvt->iface_mtx); in pvt_read_data()
470 pvt->sensor = type; in pvt_read_data()
471 pvt_set_mode(pvt, pvt_info[type].mode); in pvt_read_data()
477 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, 0); in pvt_read_data()
478 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, PVT_CTRL_EN); in pvt_read_data()
486 timeout = 2 * usecs_to_jiffies(ktime_to_us(pvt->timeout)); in pvt_read_data()
489 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_read_data()
490 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, in pvt_read_data()
495 mutex_unlock(&pvt->iface_mtx); in pvt_read_data()
508 static int pvt_read_limit(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_read_limit() argument
514 static int pvt_write_limit(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_write_limit() argument
520 static int pvt_read_alarm(struct pvt_hwmon *pvt, enum pvt_sensor_type type, in pvt_read_alarm() argument
612 static int pvt_read_trim(struct pvt_hwmon *pvt, long *val) in pvt_read_trim() argument
616 data = readl(pvt->regs + PVT_CTRL); in pvt_read_trim()
622 static int pvt_write_trim(struct pvt_hwmon *pvt, long val) in pvt_write_trim() argument
631 ret = mutex_lock_interruptible(&pvt->iface_mtx); in pvt_write_trim()
636 pvt_set_trim(pvt, trim); in pvt_write_trim()
638 mutex_unlock(&pvt->iface_mtx); in pvt_write_trim()
643 static int pvt_read_timeout(struct pvt_hwmon *pvt, long *val) in pvt_read_timeout() argument
647 ret = mutex_lock_interruptible(&pvt->iface_mtx); in pvt_read_timeout()
652 *val = ktime_to_ms(pvt->timeout); in pvt_read_timeout()
654 mutex_unlock(&pvt->iface_mtx); in pvt_read_timeout()
659 static int pvt_write_timeout(struct pvt_hwmon *pvt, long val) in pvt_write_timeout() argument
666 rate = clk_get_rate(pvt->clks[PVT_CLOCK_REF].clk); in pvt_write_timeout()
699 ret = mutex_lock_interruptible(&pvt->iface_mtx); in pvt_write_timeout()
703 pvt_set_tout(pvt, data); in pvt_write_timeout()
704 pvt->timeout = cache; in pvt_write_timeout()
706 mutex_unlock(&pvt->iface_mtx); in pvt_write_timeout()
714 struct pvt_hwmon *pvt = dev_get_drvdata(dev); in pvt_hwmon_read() local
723 return pvt_read_timeout(pvt, val); in pvt_hwmon_read()
729 return pvt_read_data(pvt, ch, val); in pvt_hwmon_read()
734 return pvt_read_limit(pvt, ch, true, val); in pvt_hwmon_read()
736 return pvt_read_limit(pvt, ch, false, val); in pvt_hwmon_read()
738 return pvt_read_alarm(pvt, ch, true, val); in pvt_hwmon_read()
740 return pvt_read_alarm(pvt, ch, false, val); in pvt_hwmon_read()
742 return pvt_read_trim(pvt, val); in pvt_hwmon_read()
748 return pvt_read_data(pvt, PVT_VOLT + ch, val); in pvt_hwmon_read()
750 return pvt_read_limit(pvt, PVT_VOLT + ch, true, val); in pvt_hwmon_read()
752 return pvt_read_limit(pvt, PVT_VOLT + ch, false, val); in pvt_hwmon_read()
754 return pvt_read_alarm(pvt, PVT_VOLT + ch, true, val); in pvt_hwmon_read()
756 return pvt_read_alarm(pvt, PVT_VOLT + ch, false, val); in pvt_hwmon_read()
798 struct pvt_hwmon *pvt = dev_get_drvdata(dev); in pvt_hwmon_write() local
807 return pvt_write_timeout(pvt, val); in pvt_hwmon_write()
813 return pvt_write_limit(pvt, ch, true, val); in pvt_hwmon_write()
815 return pvt_write_limit(pvt, ch, false, val); in pvt_hwmon_write()
817 return pvt_write_trim(pvt, val); in pvt_hwmon_write()
823 return pvt_write_limit(pvt, PVT_VOLT + ch, true, val); in pvt_hwmon_write()
825 return pvt_write_limit(pvt, PVT_VOLT + ch, false, val); in pvt_hwmon_write()
849 struct pvt_hwmon *pvt = data; in pvt_clear_data() local
854 complete_all(&pvt->cache[idx].conversion); in pvt_clear_data()
857 mutex_destroy(&pvt->iface_mtx); in pvt_clear_data()
863 struct pvt_hwmon *pvt; in pvt_create_data() local
866 pvt = devm_kzalloc(dev, sizeof(*pvt), GFP_KERNEL); in pvt_create_data()
867 if (!pvt) in pvt_create_data()
870 ret = devm_add_action(dev, pvt_clear_data, pvt); in pvt_create_data()
876 pvt->dev = dev; in pvt_create_data()
877 pvt->sensor = PVT_SENSOR_FIRST; in pvt_create_data()
878 mutex_init(&pvt->iface_mtx); in pvt_create_data()
882 seqlock_init(&pvt->cache[idx].data_seqlock); in pvt_create_data()
885 init_completion(&pvt->cache[idx].conversion); in pvt_create_data()
888 return pvt; in pvt_create_data()
891 static int pvt_request_regs(struct pvt_hwmon *pvt) in pvt_request_regs() argument
893 struct platform_device *pdev = to_platform_device(pvt->dev); in pvt_request_regs()
898 dev_err(pvt->dev, "Couldn't find PVT memresource\n"); in pvt_request_regs()
902 pvt->regs = devm_ioremap_resource(pvt->dev, res); in pvt_request_regs()
903 if (IS_ERR(pvt->regs)) in pvt_request_regs()
904 return PTR_ERR(pvt->regs); in pvt_request_regs()
911 struct pvt_hwmon *pvt = data; in pvt_disable_clks() local
913 clk_bulk_disable_unprepare(PVT_CLOCK_NUM, pvt->clks); in pvt_disable_clks()
916 static int pvt_request_clks(struct pvt_hwmon *pvt) in pvt_request_clks() argument
920 pvt->clks[PVT_CLOCK_APB].id = "pclk"; in pvt_request_clks()
921 pvt->clks[PVT_CLOCK_REF].id = "ref"; in pvt_request_clks()
923 ret = devm_clk_bulk_get(pvt->dev, PVT_CLOCK_NUM, pvt->clks); in pvt_request_clks()
925 dev_err(pvt->dev, "Couldn't get PVT clocks descriptors\n"); in pvt_request_clks()
929 ret = clk_bulk_prepare_enable(PVT_CLOCK_NUM, pvt->clks); in pvt_request_clks()
931 dev_err(pvt->dev, "Couldn't enable the PVT clocks\n"); in pvt_request_clks()
935 ret = devm_add_action_or_reset(pvt->dev, pvt_disable_clks, pvt); in pvt_request_clks()
937 dev_err(pvt->dev, "Can't add PVT clocks disable action\n"); in pvt_request_clks()
944 static int pvt_check_pwr(struct pvt_hwmon *pvt) in pvt_check_pwr() argument
960 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_ALL, PVT_INTR_ALL); in pvt_check_pwr()
961 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, PVT_CTRL_EN); in pvt_check_pwr()
962 pvt_set_tout(pvt, 0); in pvt_check_pwr()
963 readl(pvt->regs + PVT_DATA); in pvt_check_pwr()
968 data = readl(pvt->regs + PVT_DATA); in pvt_check_pwr()
971 dev_err(pvt->dev, "Sensor is powered down\n"); in pvt_check_pwr()
974 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_check_pwr()
979 static int pvt_init_iface(struct pvt_hwmon *pvt) in pvt_init_iface() argument
984 rate = clk_get_rate(pvt->clks[PVT_CLOCK_REF].clk); in pvt_init_iface()
986 dev_err(pvt->dev, "Invalid reference clock rate\n"); in pvt_init_iface()
995 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_ALL, PVT_INTR_ALL); in pvt_init_iface()
996 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_init_iface()
997 readl(pvt->regs + PVT_CLR_INTR); in pvt_init_iface()
998 readl(pvt->regs + PVT_DATA); in pvt_init_iface()
1001 pvt_set_mode(pvt, pvt_info[pvt->sensor].mode); in pvt_init_iface()
1002 pvt_set_tout(pvt, PVT_TOUT_DEF); in pvt_init_iface()
1018 pvt->timeout = ktime_set(PVT_SENSORS_NUM * PVT_TOUT_DEF, 0); in pvt_init_iface()
1019 pvt->timeout = ktime_divns(pvt->timeout, rate); in pvt_init_iface()
1020 pvt->timeout = ktime_add_ns(pvt->timeout, PVT_SENSORS_NUM * PVT_TOUT_MIN); in pvt_init_iface()
1022 pvt->timeout = ktime_set(PVT_TOUT_DEF, 0); in pvt_init_iface()
1023 pvt->timeout = ktime_divns(pvt->timeout, rate); in pvt_init_iface()
1024 pvt->timeout = ktime_add_ns(pvt->timeout, PVT_TOUT_MIN); in pvt_init_iface()
1028 if (!of_property_read_u32(pvt->dev->of_node, in pvt_init_iface()
1032 pvt_set_trim(pvt, trim); in pvt_init_iface()
1037 static int pvt_request_irq(struct pvt_hwmon *pvt) in pvt_request_irq() argument
1039 struct platform_device *pdev = to_platform_device(pvt->dev); in pvt_request_irq()
1042 pvt->irq = platform_get_irq(pdev, 0); in pvt_request_irq()
1043 if (pvt->irq < 0) in pvt_request_irq()
1044 return pvt->irq; in pvt_request_irq()
1046 ret = devm_request_threaded_irq(pvt->dev, pvt->irq, in pvt_request_irq()
1054 "pvt", pvt); in pvt_request_irq()
1056 dev_err(pvt->dev, "Couldn't request PVT IRQ\n"); in pvt_request_irq()
1063 static int pvt_create_hwmon(struct pvt_hwmon *pvt) in pvt_create_hwmon() argument
1065 pvt->hwmon = devm_hwmon_device_register_with_info(pvt->dev, "pvt", pvt, in pvt_create_hwmon()
1067 if (IS_ERR(pvt->hwmon)) { in pvt_create_hwmon()
1068 dev_err(pvt->dev, "Couldn't create hwmon device\n"); in pvt_create_hwmon()
1069 return PTR_ERR(pvt->hwmon); in pvt_create_hwmon()
1079 struct pvt_hwmon *pvt = data; in pvt_disable_iface() local
1081 mutex_lock(&pvt->iface_mtx); in pvt_disable_iface()
1082 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0); in pvt_disable_iface()
1083 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, in pvt_disable_iface()
1085 mutex_unlock(&pvt->iface_mtx); in pvt_disable_iface()
1088 static int pvt_enable_iface(struct pvt_hwmon *pvt) in pvt_enable_iface() argument
1092 ret = devm_add_action(pvt->dev, pvt_disable_iface, pvt); in pvt_enable_iface()
1094 dev_err(pvt->dev, "Can't add PVT disable interface action\n"); in pvt_enable_iface()
1104 mutex_lock(&pvt->iface_mtx); in pvt_enable_iface()
1105 pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, 0); in pvt_enable_iface()
1106 pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, PVT_CTRL_EN); in pvt_enable_iface()
1107 mutex_unlock(&pvt->iface_mtx); in pvt_enable_iface()
1114 static int pvt_enable_iface(struct pvt_hwmon *pvt) in pvt_enable_iface() argument
1123 struct pvt_hwmon *pvt; in pvt_probe() local
1126 pvt = pvt_create_data(pdev); in pvt_probe()
1127 if (IS_ERR(pvt)) in pvt_probe()
1128 return PTR_ERR(pvt); in pvt_probe()
1130 ret = pvt_request_regs(pvt); in pvt_probe()
1134 ret = pvt_request_clks(pvt); in pvt_probe()
1138 ret = pvt_check_pwr(pvt); in pvt_probe()
1142 ret = pvt_init_iface(pvt); in pvt_probe()
1146 ret = pvt_request_irq(pvt); in pvt_probe()
1150 ret = pvt_create_hwmon(pvt); in pvt_probe()
1154 ret = pvt_enable_iface(pvt); in pvt_probe()