Lines Matching full:st
161 struct ltc4282_state *st = container_of(hw, struct ltc4282_state, in ltc4282_set_rate() local
168 return regmap_update_bits(st->map, LTC4282_CLK_DIV, LTC4282_CLKOUT_MASK, in ltc4282_set_rate()
192 struct ltc4282_state *st = container_of(hw, struct ltc4282_state, in ltc4282_recalc_rate() local
197 ret = regmap_read(st->map, LTC4282_CLK_DIV, &clkdiv); in ltc4282_recalc_rate()
212 struct ltc4282_state *st = container_of(clk_hw, struct ltc4282_state, in ltc4282_disable() local
215 regmap_clear_bits(st->map, LTC4282_CLK_DIV, LTC4282_CLKOUT_MASK); in ltc4282_disable()
218 static int ltc4282_read_voltage_word(const struct ltc4282_state *st, u32 reg, in ltc4282_read_voltage_word() argument
224 ret = regmap_bulk_read(st->map, reg, &in, sizeof(in)); in ltc4282_read_voltage_word()
236 static int ltc4282_read_voltage_byte_cached(const struct ltc4282_state *st, in ltc4282_read_voltage_byte_cached() argument
246 ret = regmap_read(st->map, reg, &in); in ltc4282_read_voltage_byte_cached()
255 static int ltc4282_read_voltage_byte(const struct ltc4282_state *st, u32 reg, in ltc4282_read_voltage_byte() argument
258 return ltc4282_read_voltage_byte_cached(st, reg, fs, val, NULL); in ltc4282_read_voltage_byte()
261 static int __ltc4282_read_alarm(struct ltc4282_state *st, u32 reg, u32 mask, in __ltc4282_read_alarm() argument
267 ret = regmap_read(st->map, reg, &alarm); in __ltc4282_read_alarm()
275 return regmap_clear_bits(st->map, reg, mask); in __ltc4282_read_alarm()
280 static int ltc4282_read_alarm(struct ltc4282_state *st, u32 reg, u32 mask, in ltc4282_read_alarm() argument
283 guard(mutex)(&st->lock); in ltc4282_read_alarm()
284 return __ltc4282_read_alarm(st, reg, mask, val); in ltc4282_read_alarm()
287 static int ltc4282_vdd_source_read_in(struct ltc4282_state *st, u32 channel, in ltc4282_vdd_source_read_in() argument
290 guard(mutex)(&st->lock); in ltc4282_vdd_source_read_in()
291 if (!st->in0_1_cache[channel].en) in ltc4282_vdd_source_read_in()
294 return ltc4282_read_voltage_word(st, LTC4282_VSOURCE, st->vfs_out, val); in ltc4282_vdd_source_read_in()
297 static int ltc4282_vdd_source_read_hist(struct ltc4282_state *st, u32 reg, in ltc4282_vdd_source_read_hist() argument
302 guard(mutex)(&st->lock); in ltc4282_vdd_source_read_hist()
303 if (!st->in0_1_cache[channel].en) { in ltc4282_vdd_source_read_hist()
308 ret = ltc4282_read_voltage_word(st, reg, st->vfs_out, val); in ltc4282_vdd_source_read_hist()
316 static int ltc4282_vdd_source_read_lim(struct ltc4282_state *st, u32 reg, in ltc4282_vdd_source_read_lim() argument
319 guard(mutex)(&st->lock); in ltc4282_vdd_source_read_lim()
320 if (!st->in0_1_cache[channel].en) in ltc4282_vdd_source_read_lim()
321 return ltc4282_read_voltage_byte_cached(st, reg, st->vfs_out, in ltc4282_vdd_source_read_lim()
324 return ltc4282_read_voltage_byte(st, reg, st->vfs_out, val); in ltc4282_vdd_source_read_lim()
327 static int ltc4282_vdd_source_read_alm(struct ltc4282_state *st, u32 mask, in ltc4282_vdd_source_read_alm() argument
330 guard(mutex)(&st->lock); in ltc4282_vdd_source_read_alm()
331 if (!st->in0_1_cache[channel].en) { in ltc4282_vdd_source_read_alm()
344 return __ltc4282_read_alarm(st, LTC4282_ADC_ALERT_LOG, mask, val); in ltc4282_vdd_source_read_alm()
347 static int ltc4282_read_in(struct ltc4282_state *st, u32 attr, long *val, in ltc4282_read_in() argument
353 return ltc4282_read_voltage_word(st, LTC4282_VGPIO, in ltc4282_read_in()
356 return ltc4282_vdd_source_read_in(st, channel, val); in ltc4282_read_in()
359 return ltc4282_read_voltage_word(st, in ltc4282_read_in()
363 return ltc4282_vdd_source_read_hist(st, LTC4282_VSOURCE_HIGHEST, in ltc4282_read_in()
365 &st->in0_1_cache[channel].in_highest, val); in ltc4282_read_in()
368 return ltc4282_read_voltage_word(st, LTC4282_VGPIO_LOWEST, in ltc4282_read_in()
371 return ltc4282_vdd_source_read_hist(st, LTC4282_VSOURCE_LOWEST, in ltc4282_read_in()
373 &st->in0_1_cache[channel].in_lowest, val); in ltc4282_read_in()
376 return ltc4282_read_alarm(st, LTC4282_ADC_ALERT_LOG, in ltc4282_read_in()
380 return ltc4282_vdd_source_read_alm(st, in ltc4282_read_in()
385 ltc4282_read_alarm(st, LTC4282_ADC_ALERT_LOG, in ltc4282_read_in()
388 return ltc4282_vdd_source_read_alm(st, in ltc4282_read_in()
392 return ltc4282_read_alarm(st, LTC4282_STATUS_LSB, in ltc4282_read_in()
395 return ltc4282_read_alarm(st, LTC4282_STATUS_LSB, in ltc4282_read_in()
399 return ltc4282_read_voltage_byte(st, LTC4282_VGPIO_MAX, in ltc4282_read_in()
402 return ltc4282_vdd_source_read_lim(st, LTC4282_VSOURCE_MAX, in ltc4282_read_in()
404 &st->in0_1_cache[channel].in_max_raw, val); in ltc4282_read_in()
407 return ltc4282_read_voltage_byte(st, LTC4282_VGPIO_MIN, in ltc4282_read_in()
410 return ltc4282_vdd_source_read_lim(st, LTC4282_VSOURCE_MIN, in ltc4282_read_in()
412 &st->in0_1_cache[channel].in_min_raw, val); in ltc4282_read_in()
414 scoped_guard(mutex, &st->lock) { in ltc4282_read_in()
415 *val = st->in0_1_cache[channel].en; in ltc4282_read_in()
423 return ltc4282_read_alarm(st, LTC4282_STATUS_LSB, in ltc4282_read_in()
430 static int ltc4282_read_current_word(const struct ltc4282_state *st, u32 reg, in ltc4282_read_current_word() argument
440 ret = ltc4282_read_voltage_word(st, reg, DECA * 40 * MILLI, &in); in ltc4282_read_current_word()
444 *val = DIV_ROUND_CLOSEST(in * MILLI, st->rsense); in ltc4282_read_current_word()
449 static int ltc4282_read_current_byte(const struct ltc4282_state *st, u32 reg, in ltc4282_read_current_byte() argument
455 ret = ltc4282_read_voltage_byte(st, reg, DECA * 40 * MILLI, &in); in ltc4282_read_current_byte()
459 *val = DIV_ROUND_CLOSEST(in * MILLI, st->rsense); in ltc4282_read_current_byte()
464 static int ltc4282_read_curr(struct ltc4282_state *st, const u32 attr, in ltc4282_read_curr() argument
469 return ltc4282_read_current_word(st, LTC4282_VSENSE, val); in ltc4282_read_curr()
471 return ltc4282_read_current_word(st, LTC4282_VSENSE_HIGHEST, in ltc4282_read_curr()
474 return ltc4282_read_current_word(st, LTC4282_VSENSE_LOWEST, in ltc4282_read_curr()
477 return ltc4282_read_current_byte(st, LTC4282_VSENSE_MAX, val); in ltc4282_read_curr()
479 return ltc4282_read_current_byte(st, LTC4282_VSENSE_MIN, val); in ltc4282_read_curr()
481 return ltc4282_read_alarm(st, LTC4282_ADC_ALERT_LOG, in ltc4282_read_curr()
484 return ltc4282_read_alarm(st, LTC4282_ADC_ALERT_LOG, in ltc4282_read_curr()
487 return ltc4282_read_alarm(st, LTC4282_STATUS_LSB, in ltc4282_read_curr()
494 static int ltc4282_read_power_word(const struct ltc4282_state *st, u32 reg, in ltc4282_read_power_word() argument
497 u64 temp = DECA * 40ULL * st->vfs_out * BIT(16), temp_2; in ltc4282_read_power_word()
502 ret = regmap_bulk_read(st->map, reg, &raw, sizeof(raw)); in ltc4282_read_power_word()
514 U16_MAX * (u64)st->rsense); in ltc4282_read_power_word()
519 st->rsense * int_pow(U16_MAX, 2)); in ltc4282_read_power_word()
524 static int ltc4282_read_power_byte(const struct ltc4282_state *st, u32 reg, in ltc4282_read_power_byte() argument
531 ret = regmap_read(st->map, reg, &power); in ltc4282_read_power_byte()
535 temp = power * 40 * DECA * st->vfs_out * BIT_ULL(8); in ltc4282_read_power_byte()
537 int_pow(U8_MAX, 2) * st->rsense); in ltc4282_read_power_byte()
542 static int ltc4282_read_energy(const struct ltc4282_state *st, u64 *val) in ltc4282_read_energy() argument
548 ret = regmap_bulk_read(st->map, LTC4282_ENERGY, &raw, 6); in ltc4282_read_energy()
565 if (check_mul_overflow(DECA * st->vfs_out * 40 * BIT(8), energy, &temp)) { in ltc4282_read_energy()
566 temp = DIV_ROUND_CLOSEST(DECA * st->vfs_out * 40 * BIT(8), U16_MAX); in ltc4282_read_energy()
567 *val = DIV_ROUND_CLOSEST_ULL(temp * energy, st->rsense); in ltc4282_read_energy()
571 *val = DIV64_U64_ROUND_CLOSEST(temp, U16_MAX * (u64)st->rsense); in ltc4282_read_energy()
576 static int ltc4282_read_power(struct ltc4282_state *st, const u32 attr, in ltc4282_read_power() argument
581 return ltc4282_read_power_word(st, LTC4282_POWER, val); in ltc4282_read_power()
583 return ltc4282_read_power_word(st, LTC4282_POWER_HIGHEST, val); in ltc4282_read_power()
585 return ltc4282_read_power_word(st, LTC4282_POWER_LOWEST, val); in ltc4282_read_power()
587 return ltc4282_read_alarm(st, LTC4282_ADC_ALERT_LOG, in ltc4282_read_power()
590 return ltc4282_read_alarm(st, LTC4282_ADC_ALERT_LOG, in ltc4282_read_power()
593 return ltc4282_read_power_byte(st, LTC4282_POWER_MAX, val); in ltc4282_read_power()
595 return ltc4282_read_power_byte(st, LTC4282_POWER_MIN, val); in ltc4282_read_power()
604 struct ltc4282_state *st = dev_get_drvdata(dev); in ltc4282_read() local
608 return ltc4282_read_in(st, attr, val, channel); in ltc4282_read()
610 return ltc4282_read_curr(st, attr, val); in ltc4282_read()
612 return ltc4282_read_power(st, attr, val); in ltc4282_read()
614 scoped_guard(mutex, &st->lock) { in ltc4282_read()
615 *val = st->energy_en; in ltc4282_read()
623 static int ltc4282_write_power_byte(const struct ltc4282_state *st, u32 reg, in ltc4282_write_power_byte() argument
629 if (val > st->power_max) in ltc4282_write_power_byte()
630 val = st->power_max; in ltc4282_write_power_byte()
632 temp = val * int_pow(U8_MAX, 2) * st->rsense; in ltc4282_write_power_byte()
634 MICRO * DECA * 256ULL * st->vfs_out * 40); in ltc4282_write_power_byte()
636 return regmap_write(st->map, reg, power); in ltc4282_write_power_byte()
639 static int ltc4282_write_power_word(const struct ltc4282_state *st, u32 reg, in ltc4282_write_power_word() argument
642 u64 temp = int_pow(U16_MAX, 2) * st->rsense, temp_2; in ltc4282_write_power_word()
649 40ULL * BIT(16) * st->vfs_out); in ltc4282_write_power_word()
651 temp = DECA * MICRO * 40ULL * BIT(16) * st->vfs_out; in ltc4282_write_power_word()
656 return regmap_bulk_write(st->map, reg, &__raw, sizeof(__raw)); in ltc4282_write_power_word()
659 static int __ltc4282_in_write_history(const struct ltc4282_state *st, u32 reg, in __ltc4282_in_write_history() argument
670 ret = regmap_bulk_write(st->map, reg, &__raw, 2); in __ltc4282_in_write_history()
678 return regmap_bulk_write(st->map, reg + 2, &__raw, 2); in __ltc4282_in_write_history()
681 static int ltc4282_in_write_history(struct ltc4282_state *st, u32 reg, in ltc4282_in_write_history() argument
684 guard(mutex)(&st->lock); in ltc4282_in_write_history()
685 return __ltc4282_in_write_history(st, reg, lowest, highest, fs); in ltc4282_in_write_history()
688 static int ltc4282_power_reset_hist(struct ltc4282_state *st) in ltc4282_power_reset_hist() argument
692 guard(mutex)(&st->lock); in ltc4282_power_reset_hist()
694 ret = ltc4282_write_power_word(st, LTC4282_POWER_LOWEST, in ltc4282_power_reset_hist()
695 st->power_max); in ltc4282_power_reset_hist()
699 ret = ltc4282_write_power_word(st, LTC4282_POWER_HIGHEST, 0); in ltc4282_power_reset_hist()
704 return regmap_clear_bits(st->map, LTC4282_FAULT_LOG, in ltc4282_power_reset_hist()
708 static int ltc4282_write_power(struct ltc4282_state *st, u32 attr, in ltc4282_write_power() argument
713 return ltc4282_write_power_byte(st, LTC4282_POWER_MAX, val); in ltc4282_write_power()
715 return ltc4282_write_power_byte(st, LTC4282_POWER_MIN, val); in ltc4282_write_power()
717 return ltc4282_power_reset_hist(st); in ltc4282_write_power()
723 static int ltc4282_write_voltage_byte_cached(const struct ltc4282_state *st, in ltc4282_write_voltage_byte_cached() argument
737 return regmap_write(st->map, reg, in); in ltc4282_write_voltage_byte_cached()
740 static int ltc4282_write_voltage_byte(const struct ltc4282_state *st, u32 reg, in ltc4282_write_voltage_byte() argument
743 return ltc4282_write_voltage_byte_cached(st, reg, fs, val, NULL); in ltc4282_write_voltage_byte()
746 static int ltc4282_cache_history(struct ltc4282_state *st, u32 channel) in ltc4282_cache_history() argument
751 ret = ltc4282_read_voltage_word(st, LTC4282_VSOURCE_LOWEST, st->vfs_out, in ltc4282_cache_history()
756 st->in0_1_cache[channel].in_lowest = val; in ltc4282_cache_history()
758 ret = ltc4282_read_voltage_word(st, LTC4282_VSOURCE_HIGHEST, in ltc4282_cache_history()
759 st->vfs_out, &val); in ltc4282_cache_history()
763 st->in0_1_cache[channel].in_highest = val; in ltc4282_cache_history()
765 ret = regmap_read(st->map, LTC4282_VSOURCE_MIN, in ltc4282_cache_history()
766 &st->in0_1_cache[channel].in_min_raw); in ltc4282_cache_history()
770 return regmap_read(st->map, LTC4282_VSOURCE_MAX, in ltc4282_cache_history()
771 &st->in0_1_cache[channel].in_max_raw); in ltc4282_cache_history()
774 static int ltc4282_cache_sync(struct ltc4282_state *st, u32 channel) in ltc4282_cache_sync() argument
778 ret = __ltc4282_in_write_history(st, LTC4282_VSOURCE_LOWEST, in ltc4282_cache_sync()
779 st->in0_1_cache[channel].in_lowest, in ltc4282_cache_sync()
780 st->in0_1_cache[channel].in_highest, in ltc4282_cache_sync()
781 st->vfs_out); in ltc4282_cache_sync()
785 ret = regmap_write(st->map, LTC4282_VSOURCE_MIN, in ltc4282_cache_sync()
786 st->in0_1_cache[channel].in_min_raw); in ltc4282_cache_sync()
790 return regmap_write(st->map, LTC4282_VSOURCE_MAX, in ltc4282_cache_sync()
791 st->in0_1_cache[channel].in_max_raw); in ltc4282_cache_sync()
794 static int ltc4282_vdd_source_write_lim(struct ltc4282_state *st, u32 reg, in ltc4282_vdd_source_write_lim() argument
799 guard(mutex)(&st->lock); in ltc4282_vdd_source_write_lim()
800 if (st->in0_1_cache[channel].en) in ltc4282_vdd_source_write_lim()
801 ret = ltc4282_write_voltage_byte(st, reg, st->vfs_out, val); in ltc4282_vdd_source_write_lim()
803 ret = ltc4282_write_voltage_byte_cached(st, reg, st->vfs_out, in ltc4282_vdd_source_write_lim()
809 static int ltc4282_vdd_source_reset_hist(struct ltc4282_state *st, int channel) in ltc4282_vdd_source_reset_hist() argument
811 long lowest = st->vfs_out; in ltc4282_vdd_source_reset_hist()
815 lowest = st->vdd; in ltc4282_vdd_source_reset_hist()
817 guard(mutex)(&st->lock); in ltc4282_vdd_source_reset_hist()
818 if (st->in0_1_cache[channel].en) { in ltc4282_vdd_source_reset_hist()
819 ret = __ltc4282_in_write_history(st, LTC4282_VSOURCE_LOWEST, in ltc4282_vdd_source_reset_hist()
820 lowest, 0, st->vfs_out); in ltc4282_vdd_source_reset_hist()
825 st->in0_1_cache[channel].in_lowest = lowest; in ltc4282_vdd_source_reset_hist()
826 st->in0_1_cache[channel].in_highest = 0; in ltc4282_vdd_source_reset_hist()
837 return regmap_clear_bits(st->map, LTC4282_FAULT_LOG, in ltc4282_vdd_source_reset_hist()
840 return regmap_clear_bits(st->map, LTC4282_FAULT_LOG, in ltc4282_vdd_source_reset_hist()
851 static int ltc4282_vdd_source_enable(struct ltc4282_state *st, int channel, in ltc4282_vdd_source_enable() argument
857 guard(mutex)(&st->lock); in ltc4282_vdd_source_enable()
858 if (st->in0_1_cache[channel].en == !!val) in ltc4282_vdd_source_enable()
865 ret = regmap_update_bits(st->map, LTC4282_ILIM_ADJUST, in ltc4282_vdd_source_enable()
871 st->in0_1_cache[channel].en = !!val; in ltc4282_vdd_source_enable()
872 st->in0_1_cache[other_chan].en = !val; in ltc4282_vdd_source_enable()
874 if (st->in0_1_cache[channel].en) { in ltc4282_vdd_source_enable()
879 ret = ltc4282_cache_history(st, other_chan); in ltc4282_vdd_source_enable()
883 return ltc4282_cache_sync(st, channel); in ltc4282_vdd_source_enable()
889 ret = ltc4282_cache_history(st, channel); in ltc4282_vdd_source_enable()
893 return ltc4282_cache_sync(st, other_chan); in ltc4282_vdd_source_enable()
896 static int ltc4282_write_in(struct ltc4282_state *st, u32 attr, long val, in ltc4282_write_in() argument
902 return ltc4282_write_voltage_byte(st, LTC4282_VGPIO_MAX, in ltc4282_write_in()
905 return ltc4282_vdd_source_write_lim(st, LTC4282_VSOURCE_MAX, in ltc4282_write_in()
907 &st->in0_1_cache[channel].in_max_raw, val); in ltc4282_write_in()
910 return ltc4282_write_voltage_byte(st, LTC4282_VGPIO_MIN, in ltc4282_write_in()
913 return ltc4282_vdd_source_write_lim(st, LTC4282_VSOURCE_MIN, in ltc4282_write_in()
915 &st->in0_1_cache[channel].in_min_raw, val); in ltc4282_write_in()
918 return ltc4282_in_write_history(st, in ltc4282_write_in()
922 return ltc4282_vdd_source_reset_hist(st, channel); in ltc4282_write_in()
924 return ltc4282_vdd_source_enable(st, channel, val); in ltc4282_write_in()
930 static int ltc4282_curr_reset_hist(struct ltc4282_state *st) in ltc4282_curr_reset_hist() argument
934 guard(mutex)(&st->lock); in ltc4282_curr_reset_hist()
936 ret = __ltc4282_in_write_history(st, LTC4282_VSENSE_LOWEST, in ltc4282_curr_reset_hist()
937 st->vsense_max, 0, 40 * MILLI); in ltc4282_curr_reset_hist()
942 return regmap_clear_bits(st->map, LTC4282_FAULT_LOG, in ltc4282_curr_reset_hist()
946 static int ltc4282_write_curr(struct ltc4282_state *st, u32 attr, in ltc4282_write_curr() argument
950 u32 in = DIV_ROUND_CLOSEST_ULL((u64)val * st->rsense, DECA * MICRO); in ltc4282_write_curr()
954 return ltc4282_write_voltage_byte(st, LTC4282_VSENSE_MAX, 40, in ltc4282_write_curr()
957 return ltc4282_write_voltage_byte(st, LTC4282_VSENSE_MIN, 40, in ltc4282_write_curr()
960 return ltc4282_curr_reset_hist(st); in ltc4282_write_curr()
966 static int ltc4282_energy_enable_set(struct ltc4282_state *st, long val) in ltc4282_energy_enable_set() argument
970 guard(mutex)(&st->lock); in ltc4282_energy_enable_set()
972 ret = regmap_update_bits(st->map, LTC4282_ADC_CTRL, in ltc4282_energy_enable_set()
978 st->energy_en = !!val; in ltc4282_energy_enable_set()
987 struct ltc4282_state *st = dev_get_drvdata(dev); in ltc4282_write() local
991 return ltc4282_write_power(st, attr, val); in ltc4282_write()
993 return ltc4282_write_in(st, attr, val, channel); in ltc4282_write()
995 return ltc4282_write_curr(st, attr, val); in ltc4282_write()
997 return ltc4282_energy_enable_set(st, val); in ltc4282_write()
1003 static umode_t ltc4282_in_is_visible(const struct ltc4282_state *st, u32 attr) in ltc4282_in_is_visible() argument
1110 struct ltc4282_state *st = dev_get_drvdata(dev); in ltc4282_energy_show() local
1114 guard(mutex)(&st->lock); in ltc4282_energy_show()
1115 if (!st->energy_en) in ltc4282_energy_show()
1118 ret = ltc4282_read_energy(st, &energy); in ltc4282_energy_show()
1132 static int ltc428_clk_provider_setup(struct ltc4282_state *st, in ltc428_clk_provider_setup() argument
1148 st->clk_hw.init = &init; in ltc428_clk_provider_setup()
1150 ret = devm_clk_hw_register(dev, &st->clk_hw); in ltc428_clk_provider_setup()
1155 &st->clk_hw); in ltc428_clk_provider_setup()
1158 static int ltc428_clks_setup(struct ltc4282_state *st, struct device *dev) in ltc428_clks_setup() argument
1165 ret = ltc428_clk_provider_setup(st, dev); in ltc428_clks_setup()
1189 return regmap_update_bits(st->map, LTC4282_CLK_DIV, in ltc428_clks_setup()
1198 static int ltc4282_get_defaults(struct ltc4282_state *st, u32 *vin_mode) in ltc4282_get_defaults() argument
1203 ret = regmap_read(st->map, LTC4282_ADC_CTRL, ®_val); in ltc4282_get_defaults()
1207 st->energy_en = !FIELD_GET(LTC4282_METER_HALT_MASK, reg_val); in ltc4282_get_defaults()
1209 ret = regmap_read(st->map, LTC4282_CTRL_MSB, ®_val); in ltc4282_get_defaults()
1215 ret = regmap_read(st->map, LTC4282_ILIM_ADJUST, ®_val); in ltc4282_get_defaults()
1220 st->vsense_max = ltc4282_curr_lim_uv[ilm_adjust]; in ltc4282_get_defaults()
1222 st->in0_1_cache[LTC4282_CHAN_VSOURCE].en = FIELD_GET(LTC4282_VDD_MONITOR_MASK, in ltc4282_get_defaults()
1224 if (!st->in0_1_cache[LTC4282_CHAN_VSOURCE].en) { in ltc4282_get_defaults()
1225 st->in0_1_cache[LTC4282_CHAN_VDD].en = true; in ltc4282_get_defaults()
1226 return regmap_read(st->map, LTC4282_VSOURCE_MAX, in ltc4282_get_defaults()
1227 &st->in0_1_cache[LTC4282_CHAN_VSOURCE].in_max_raw); in ltc4282_get_defaults()
1230 return regmap_read(st->map, LTC4282_VSOURCE_MAX, in ltc4282_get_defaults()
1231 &st->in0_1_cache[LTC4282_CHAN_VDD].in_max_raw); in ltc4282_get_defaults()
1244 static int ltc4282_set_max_limits(struct ltc4282_state *st) in ltc4282_set_max_limits() argument
1248 ret = ltc4282_write_voltage_byte(st, LTC4282_VSENSE_MAX, 40 * MILLI, in ltc4282_set_max_limits()
1249 st->vsense_max); in ltc4282_set_max_limits()
1254 st->power_max = DIV_ROUND_CLOSEST(st->vsense_max * DECA * MILLI, st->rsense) * st->vfs_out; in ltc4282_set_max_limits()
1255 ret = ltc4282_write_power_byte(st, LTC4282_POWER_MAX, st->power_max); in ltc4282_set_max_limits()
1259 if (st->in0_1_cache[LTC4282_CHAN_VDD].en) { in ltc4282_set_max_limits()
1260 st->in0_1_cache[LTC4282_CHAN_VSOURCE].in_lowest = st->vfs_out; in ltc4282_set_max_limits()
1261 return __ltc4282_in_write_history(st, LTC4282_VSOURCE_LOWEST, in ltc4282_set_max_limits()
1262 st->vdd, 0, st->vfs_out); in ltc4282_set_max_limits()
1265 st->in0_1_cache[LTC4282_CHAN_VDD].in_lowest = st->vdd; in ltc4282_set_max_limits()
1266 return __ltc4282_in_write_history(st, LTC4282_VSOURCE_LOWEST, in ltc4282_set_max_limits()
1267 st->vfs_out, 0, st->vfs_out); in ltc4282_set_max_limits()
1278 static int ltc4282_gpio_setup(struct ltc4282_state *st, struct device *dev) in ltc4282_gpio_setup() argument
1292 ret = regmap_update_bits(st->map, LTC4282_GPIO_CONFIG, in ltc4282_gpio_setup()
1309 ret = regmap_set_bits(st->map, LTC4282_ILIM_ADJUST, in ltc4282_gpio_setup()
1312 ret = regmap_update_bits(st->map, LTC4282_GPIO_CONFIG, in ltc4282_gpio_setup()
1328 return regmap_clear_bits(st->map, LTC4282_ILIM_ADJUST, in ltc4282_gpio_setup()
1348 static int ltc4282_setup(struct ltc4282_state *st, struct device *dev) in ltc4282_setup() argument
1355 ret = ltc4282_get_defaults(st, &vin_mode); in ltc4282_setup()
1360 &st->rsense); in ltc4282_setup()
1364 if (st->rsense < CENTI) in ltc4282_setup()
1375 st->rsense /= CENTI; in ltc4282_setup()
1399 ret = regmap_update_bits(st->map, LTC4282_CTRL_MSB, in ltc4282_setup()
1406 ret = regmap_update_bits(st->map, LTC4282_ILIM_ADJUST, in ltc4282_setup()
1413 st->vfs_out = ltc4282_vfs_milli[val]; in ltc4282_setup()
1414 st->vdd = ltc4282_vdd_milli[val]; in ltc4282_setup()
1417 &st->vsense_max); in ltc4282_setup()
1449 st->vsense_max); in ltc4282_setup()
1452 ret = regmap_update_bits(st->map, LTC4282_ILIM_ADJUST, in ltc4282_setup()
1459 ret = ltc4282_set_max_limits(st); in ltc4282_setup()
1473 ret = regmap_update_bits(st->map, LTC4282_CTRL_MSB, in ltc4282_setup()
1488 ret = regmap_update_bits(st->map, LTC4282_CTRL_MSB, in ltc4282_setup()
1494 ret = regmap_set_bits(st->map, LTC4282_CTRL_LSB, in ltc4282_setup()
1501 ret = regmap_clear_bits(st->map, LTC4282_CTRL_LSB, in ltc4282_setup()
1508 ret = regmap_clear_bits(st->map, LTC4282_CTRL_LSB, in ltc4282_setup()
1515 ret = regmap_set_bits(st->map, LTC4282_ADC_CTRL, in ltc4282_setup()
1522 ret = regmap_set_bits(st->map, LTC4282_ADC_CTRL, LTC4282_FAULT_LOG_EN_MASK); in ltc4282_setup()
1534 ret = regmap_write(st->map, LTC4282_FET_BAD_FAULT_TIMEOUT, val); in ltc4282_setup()
1539 return ltc4282_gpio_setup(st, dev); in ltc4282_setup()
1622 struct ltc4282_state *st = arg; in ltc4282_show_fault_log() local
1626 ret = ltc4282_read_alarm(st, LTC4282_FAULT_LOG, mask, &alarm); in ltc4282_show_fault_log()
1682 static void ltc4282_debugfs_init(struct ltc4282_state *st, in ltc4282_debugfs_init() argument
1707 debugfs_create_file_unsafe("power1_bad_fault_log", 0400, dentry, st, in ltc4282_debugfs_init()
1709 debugfs_create_file_unsafe("in0_fet_short_fault_log", 0400, dentry, st, in ltc4282_debugfs_init()
1711 debugfs_create_file_unsafe("in0_fet_bad_fault_log", 0400, dentry, st, in ltc4282_debugfs_init()
1713 debugfs_create_file_unsafe("in1_crit_fault_log", 0400, dentry, st, in ltc4282_debugfs_init()
1715 debugfs_create_file_unsafe("in1_lcrit_fault_log", 0400, dentry, st, in ltc4282_debugfs_init()
1717 debugfs_create_file_unsafe("curr1_crit_fault_log", 0400, dentry, st, in ltc4282_debugfs_init()
1724 struct ltc4282_state *st; in ltc4282_probe() local
1727 st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); in ltc4282_probe()
1728 if (!st) in ltc4282_probe()
1732 st->map = devm_regmap_init_i2c(i2c, <c4282_regmap_config); in ltc4282_probe()
1733 if (IS_ERR(st->map)) in ltc4282_probe()
1734 return dev_err_probe(dev, PTR_ERR(st->map), in ltc4282_probe()
1738 ret = regmap_set_bits(st->map, LTC4282_ADC_CTRL, LTC4282_RESET_MASK); in ltc4282_probe()
1745 ret = ltc428_clks_setup(st, dev); in ltc4282_probe()
1749 ret = ltc4282_setup(st, dev); in ltc4282_probe()
1753 mutex_init(&st->lock); in ltc4282_probe()
1754 hwmon = devm_hwmon_device_register_with_info(dev, "ltc4282", st, in ltc4282_probe()
1760 ltc4282_debugfs_init(st, i2c, hwmon); in ltc4282_probe()