Lines Matching +full:auto +full:- +full:string +full:- +full:detection

1 // SPDX-License-Identifier: GPL-2.0-only
61 /* WLED3 specific per-'string' registers below */
93 /* WLED4 specific per-'string' registers below */
140 /* WLED5 specific per-'string' registers below */
225 * Determines if the auto string detection is required.
238 for (i = 0; i < wled->cfg.num_strings; ++i) { in wled3_set_brightness()
239 rc = regmap_bulk_write(wled->regmap, wled->ctrl_addr + in wled3_set_brightness()
240 WLED3_SINK_REG_BRIGHT(wled->cfg.enabled_strings[i]), in wled3_set_brightness()
252 u16 low_limit = wled->max_brightness * 4 / 1000; in wled4_set_brightness()
261 for (i = 0; i < wled->cfg.num_strings; ++i) { in wled4_set_brightness()
262 rc = regmap_bulk_write(wled->regmap, wled->sink_addr + in wled4_set_brightness()
263 WLED4_SINK_REG_BRIGHT(wled->cfg.enabled_strings[i]), in wled4_set_brightness()
275 u16 low_limit = wled->max_brightness * 1 / 1000; in wled5_set_brightness()
284 offset = (wled->cfg.mod_sel == MOD_A) ? in wled5_set_brightness()
288 rc = regmap_bulk_write(wled->regmap, wled->sink_addr + offset, in wled5_set_brightness()
297 enable_irq(wled->ovp_irq); in wled_ovp_work()
304 if (wled->disabled_by_short) in wled_module_enable()
305 return -ENXIO; in wled_module_enable()
307 rc = regmap_update_bits(wled->regmap, wled->ctrl_addr + in wled_module_enable()
314 if (wled->ovp_irq > 0) { in wled_module_enable()
322 schedule_delayed_work(&wled->ovp_work, HZ / 100); in wled_module_enable()
324 if (!cancel_delayed_work_sync(&wled->ovp_work)) in wled_module_enable()
325 disable_irq(wled->ovp_irq); in wled_module_enable()
335 unsigned int mask = GENMASK(wled->max_string_count - 1, 0); in wled3_sync_toggle()
337 rc = regmap_update_bits(wled->regmap, in wled3_sync_toggle()
338 wled->sink_addr + WLED3_SINK_REG_SYNC, in wled3_sync_toggle()
343 rc = regmap_update_bits(wled->regmap, in wled3_sync_toggle()
344 wled->sink_addr + WLED3_SINK_REG_SYNC, in wled3_sync_toggle()
355 rc = regmap_update_bits(wled->regmap, in wled5_mod_sync_toggle()
356 wled->sink_addr + WLED5_SINK_REG_MOD_SYNC_BIT, in wled5_mod_sync_toggle()
361 val = (wled->cfg.mod_sel == MOD_A) ? WLED5_SINK_REG_SYNC_MOD_A_BIT : in wled5_mod_sync_toggle()
363 return regmap_update_bits(wled->regmap, in wled5_mod_sync_toggle()
364 wled->sink_addr + WLED5_SINK_REG_MOD_SYNC_BIT, in wled5_mod_sync_toggle()
374 rc = regmap_read(wled->regmap, in wled_ovp_fault_status()
375 wled->ctrl_addr + WLED3_CTRL_REG_INT_RT_STS, in wled_ovp_fault_status()
378 dev_err(wled->dev, "Failed to read INT_RT_STS rc=%d\n", rc); in wled_ovp_fault_status()
382 rc = regmap_read(wled->regmap, in wled_ovp_fault_status()
383 wled->ctrl_addr + WLED3_CTRL_REG_FAULT_STATUS, in wled_ovp_fault_status()
386 dev_err(wled->dev, "Failed to read FAULT_STATUS rc=%d\n", rc); in wled_ovp_fault_status()
393 if (wled->version == 4 && (fault_sts & WLED3_CTRL_REG_OVP_FAULT_BIT)) in wled_ovp_fault_status()
396 if (wled->version == 5 && (fault_sts & (WLED3_CTRL_REG_OVP_FAULT_BIT | in wled_ovp_fault_status()
401 dev_dbg(wled->dev, "WLED OVP fault detected, int_rt_sts=0x%x fault_sts=0x%x\n", in wled_ovp_fault_status()
419 rc = regmap_read(wled->regmap, wled->ctrl_addr + in wled5_ovp_delay()
427 dev_dbg(wled->dev, "delay_time_us: %d\n", delay_us); in wled5_ovp_delay()
438 mutex_lock(&wled->lock); in wled_update_status()
440 rc = wled->wled_set_brightness(wled, brightness); in wled_update_status()
442 dev_err(wled->dev, "wled failed to set brightness rc:%d\n", in wled_update_status()
447 if (wled->version < 5) { in wled_update_status()
448 rc = wled->wled_sync_toggle(wled); in wled_update_status()
450 dev_err(wled->dev, "wled sync failed rc:%d\n", rc); in wled_update_status()
460 dev_err(wled->dev, "wled mod sync failed rc:%d\n", in wled_update_status()
467 if (!!brightness != !!wled->brightness) { in wled_update_status()
470 dev_err(wled->dev, "wled enable failed rc:%d\n", rc); in wled_update_status()
475 wled->brightness = brightness; in wled_update_status()
478 mutex_unlock(&wled->lock); in wled_update_status()
488 for (i = 0; i < wled->cfg.num_strings; i++) { in wled4_cabc_config()
489 j = wled->cfg.enabled_strings[i]; in wled4_cabc_config()
492 rc = regmap_update_bits(wled->regmap, wled->sink_addr + in wled4_cabc_config()
507 if (wled->cabc_disabled) in wled5_cabc_config()
510 reg = enable ? wled->cfg.cabc_sel : 0; in wled5_cabc_config()
511 offset = (wled->cfg.mod_sel == MOD_A) ? WLED5_SINK_REG_MOD_A_SRC_SEL : in wled5_cabc_config()
514 rc = regmap_update_bits(wled->regmap, wled->sink_addr + offset, in wled5_cabc_config()
521 if (!wled->cfg.cabc_sel) in wled5_cabc_config()
522 wled->cabc_disabled = true; in wled5_cabc_config()
537 wled->short_count++; in wled_short_irq_handler()
538 mutex_lock(&wled->lock); in wled_short_irq_handler()
541 dev_err(wled->dev, "wled disable failed rc:%d\n", rc); in wled_short_irq_handler()
546 wled->last_short_event); in wled_short_irq_handler()
548 wled->short_count = 1; in wled_short_irq_handler()
550 if (wled->short_count > WLED_SHORT_CNT_MAX) { in wled_short_irq_handler()
551 dev_err(wled->dev, "Short triggered %d times, disabling WLED forever!\n", in wled_short_irq_handler()
552 wled->short_count); in wled_short_irq_handler()
553 wled->disabled_by_short = true; in wled_short_irq_handler()
557 wled->last_short_event = ktime_get(); in wled_short_irq_handler()
562 dev_err(wled->dev, "wled enable failed rc:%d\n", rc); in wled_short_irq_handler()
565 mutex_unlock(&wled->lock); in wled_short_irq_handler()
580 rc = regmap_read(wled->regmap, wled->sink_addr + in wled_auto_string_detection()
583 dev_err(wled->dev, "Failed to read SINK configuration rc=%d\n", in wled_auto_string_detection()
588 /* Disable the module before starting detection */ in wled_auto_string_detection()
589 rc = regmap_update_bits(wled->regmap, in wled_auto_string_detection()
590 wled->ctrl_addr + WLED3_CTRL_REG_MOD_EN, in wled_auto_string_detection()
593 dev_err(wled->dev, "Failed to disable WLED module rc=%d\n", rc); in wled_auto_string_detection()
600 dev_err(wled->dev, "Failed to set brightness for auto detection rc=%d\n", in wled_auto_string_detection()
605 if (wled->cfg.cabc) { in wled_auto_string_detection()
606 rc = wled->wled_cabc_config(wled, false); in wled_auto_string_detection()
612 rc = regmap_write(wled->regmap, in wled_auto_string_detection()
613 wled->sink_addr + WLED4_SINK_REG_CURR_SINK, 0); in wled_auto_string_detection()
615 dev_err(wled->dev, "Failed to disable all sinks rc=%d\n", rc); in wled_auto_string_detection()
620 for (i = 0; i < wled->cfg.num_strings; i++) { in wled_auto_string_detection()
621 j = wled->cfg.enabled_strings[i]; in wled_auto_string_detection()
625 rc = regmap_write(wled->regmap, wled->ctrl_addr + in wled_auto_string_detection()
628 dev_err(wled->dev, "Failed to enable feedback for SINK %d rc = %d\n", in wled_auto_string_detection()
634 rc = regmap_write(wled->regmap, wled->sink_addr + in wled_auto_string_detection()
637 dev_err(wled->dev, "Failed to configure SINK %d rc=%d\n", in wled_auto_string_detection()
643 rc = regmap_update_bits(wled->regmap, wled->ctrl_addr + in wled_auto_string_detection()
648 dev_err(wled->dev, "Failed to enable WLED module rc=%d\n", in wled_auto_string_detection()
653 delay_time_us = wled->wled_ovp_delay(wled); in wled_auto_string_detection()
658 dev_err(wled->dev, "Error in getting OVP fault_sts, rc=%d\n", in wled_auto_string_detection()
664 dev_dbg(wled->dev, "WLED OVP fault detected with SINK %d\n", in wled_auto_string_detection()
670 rc = regmap_update_bits(wled->regmap, in wled_auto_string_detection()
671 wled->ctrl_addr + WLED3_CTRL_REG_MOD_EN, in wled_auto_string_detection()
674 dev_err(wled->dev, "Failed to disable WLED module rc=%d\n", in wled_auto_string_detection()
681 dev_err(wled->dev, "No valid WLED sinks found\n"); in wled_auto_string_detection()
682 wled->disabled_by_short = true; in wled_auto_string_detection()
687 dev_warn(wled->dev, "%x is not a valid sink configuration - using %x instead\n", in wled_auto_string_detection()
693 rc = regmap_write(wled->regmap, in wled_auto_string_detection()
694 wled->sink_addr + WLED4_SINK_REG_CURR_SINK, in wled_auto_string_detection()
697 dev_err(wled->dev, "Failed to reconfigure the default sink rc=%d\n", in wled_auto_string_detection()
703 if (wled->version == 4) { in wled_auto_string_detection()
704 for (i = 0; i < wled->cfg.num_strings; i++) { in wled_auto_string_detection()
705 j = wled->cfg.enabled_strings[i]; in wled_auto_string_detection()
713 rc = regmap_write(wled->regmap, wled->sink_addr + in wled_auto_string_detection()
716 dev_err(wled->dev, "Failed to configure MODULATOR_EN rc=%d\n", in wled_auto_string_detection()
724 rc = wled->wled_cabc_config(wled, true); in wled_auto_string_detection()
729 rc = regmap_write(wled->regmap, in wled_auto_string_detection()
730 wled->ctrl_addr + WLED3_CTRL_REG_FEEDBACK_CONTROL, 0); in wled_auto_string_detection()
732 dev_err(wled->dev, "Failed to restore feedback setting rc=%d\n", in wled_auto_string_detection()
738 rc = wled4_set_brightness(wled, wled->brightness); in wled_auto_string_detection()
740 dev_err(wled->dev, "Failed to set brightness after auto detection rc=%d\n", in wled_auto_string_detection()
745 rc = regmap_update_bits(wled->regmap, in wled_auto_string_detection()
746 wled->ctrl_addr + WLED3_CTRL_REG_MOD_EN, in wled_auto_string_detection()
750 dev_err(wled->dev, "Failed to enable WLED module rc=%d\n", rc); in wled_auto_string_detection()
765 if (!wled->cfg.auto_detection_enabled) in wled4_auto_detection_required()
771 * for an auto-detection check. in wled4_auto_detection_required()
773 if (!wled->auto_detection_ovp_count) { in wled4_auto_detection_required()
774 wled->start_ovp_fault_time = ktime_get(); in wled4_auto_detection_required()
775 wled->auto_detection_ovp_count++; in wled4_auto_detection_required()
778 wled->start_ovp_fault_time); in wled4_auto_detection_required()
780 wled->auto_detection_ovp_count = 0; in wled4_auto_detection_required()
782 wled->auto_detection_ovp_count++; in wled4_auto_detection_required()
784 if (wled->auto_detection_ovp_count >= in wled4_auto_detection_required()
786 wled->auto_detection_ovp_count = 0; in wled4_auto_detection_required()
796 if (!wled->cfg.auto_detection_enabled) in wled5_auto_detection_required()
805 * should qualify for a real OVP fault condition to run auto detection in wled5_auto_detection_required()
816 if (!wled->cfg.auto_detection_enabled) in wled_auto_detection_at_init()
821 dev_err(wled->dev, "Error in getting OVP fault_sts, rc=%d\n", in wled_auto_detection_at_init()
827 mutex_lock(&wled->lock); in wled_auto_detection_at_init()
829 mutex_unlock(&wled->lock); in wled_auto_detection_at_init()
841 rc = regmap_read(wled->regmap, in wled_ovp_irq_handler()
842 wled->ctrl_addr + WLED3_CTRL_REG_INT_RT_STS, &int_sts); in wled_ovp_irq_handler()
844 dev_err(wled->dev, "Error in reading WLED3_INT_RT_STS rc=%d\n", in wled_ovp_irq_handler()
849 rc = regmap_read(wled->regmap, wled->ctrl_addr + in wled_ovp_irq_handler()
852 dev_err(wled->dev, "Error in reading WLED_FAULT_STATUS rc=%d\n", in wled_ovp_irq_handler()
859 dev_dbg(wled->dev, "WLED OVP fault detected, int_sts=%x fault_sts= %x\n", in wled_ovp_irq_handler()
863 if (wled->wled_auto_detection_required(wled)) { in wled_ovp_irq_handler()
864 mutex_lock(&wled->lock); in wled_ovp_irq_handler()
866 mutex_unlock(&wled->lock); in wled_ovp_irq_handler()
879 rc = regmap_update_bits(wled->regmap, in wled3_setup()
880 wled->ctrl_addr + WLED3_CTRL_REG_OVP, in wled3_setup()
881 WLED3_CTRL_REG_OVP_MASK, wled->cfg.ovp); in wled3_setup()
885 rc = regmap_update_bits(wled->regmap, in wled3_setup()
886 wled->ctrl_addr + WLED3_CTRL_REG_ILIMIT, in wled3_setup()
888 wled->cfg.boost_i_limit); in wled3_setup()
892 rc = regmap_update_bits(wled->regmap, in wled3_setup()
893 wled->ctrl_addr + WLED3_CTRL_REG_FREQ, in wled3_setup()
895 wled->cfg.switch_freq); in wled3_setup()
899 for (i = 0; i < wled->cfg.num_strings; ++i) { in wled3_setup()
900 j = wled->cfg.enabled_strings[i]; in wled3_setup()
901 addr = wled->ctrl_addr + WLED3_SINK_REG_STR_MOD_EN(j); in wled3_setup()
902 rc = regmap_update_bits(wled->regmap, addr, in wled3_setup()
908 if (wled->cfg.ext_gen) { in wled3_setup()
909 addr = wled->ctrl_addr + WLED3_SINK_REG_STR_MOD_SRC(j); in wled3_setup()
910 rc = regmap_update_bits(wled->regmap, addr, in wled3_setup()
917 addr = wled->ctrl_addr + WLED3_SINK_REG_STR_FULL_SCALE_CURR(j); in wled3_setup()
918 rc = regmap_update_bits(wled->regmap, addr, in wled3_setup()
920 wled->cfg.string_i_limit); in wled3_setup()
924 addr = wled->ctrl_addr + WLED3_SINK_REG_STR_CABC(j); in wled3_setup()
925 rc = regmap_update_bits(wled->regmap, addr, in wled3_setup()
927 wled->cfg.cabc ? in wled3_setup()
935 rc = regmap_update_bits(wled->regmap, in wled3_setup()
936 wled->ctrl_addr + WLED3_SINK_REG_CURR_SINK, in wled3_setup()
963 rc = regmap_update_bits(wled->regmap, in wled4_setup()
964 wled->ctrl_addr + WLED3_CTRL_REG_OVP, in wled4_setup()
965 WLED3_CTRL_REG_OVP_MASK, wled->cfg.ovp); in wled4_setup()
969 rc = regmap_update_bits(wled->regmap, in wled4_setup()
970 wled->ctrl_addr + WLED3_CTRL_REG_ILIMIT, in wled4_setup()
972 wled->cfg.boost_i_limit); in wled4_setup()
976 rc = regmap_update_bits(wled->regmap, in wled4_setup()
977 wled->ctrl_addr + WLED3_CTRL_REG_FREQ, in wled4_setup()
979 wled->cfg.switch_freq); in wled4_setup()
983 if (wled->cfg.external_pfet) { in wled4_setup()
985 rc = regmap_write(wled->regmap, wled->ctrl_addr + in wled4_setup()
991 rc = regmap_write(wled->regmap, in wled4_setup()
992 wled->ctrl_addr + WLED4_CTRL_REG_TEST1, in wled4_setup()
998 rc = regmap_read(wled->regmap, wled->sink_addr + in wled4_setup()
1003 for (i = 0; i < wled->cfg.num_strings; i++) { in wled4_setup()
1004 j = wled->cfg.enabled_strings[i]; in wled4_setup()
1014 rc = regmap_update_bits(wled->regmap, in wled4_setup()
1015 wled->sink_addr + WLED4_SINK_REG_CURR_SINK, in wled4_setup()
1020 rc = regmap_update_bits(wled->regmap, wled->ctrl_addr + in wled4_setup()
1026 /* Per sink/string configuration */ in wled4_setup()
1027 for (i = 0; i < wled->cfg.num_strings; i++) { in wled4_setup()
1028 j = wled->cfg.enabled_strings[i]; in wled4_setup()
1030 addr = wled->sink_addr + in wled4_setup()
1032 rc = regmap_update_bits(wled->regmap, addr, in wled4_setup()
1038 addr = wled->sink_addr + in wled4_setup()
1040 rc = regmap_update_bits(wled->regmap, addr, in wled4_setup()
1042 wled->cfg.string_i_limit); in wled4_setup()
1047 rc = wled4_cabc_config(wled, wled->cfg.cabc); in wled4_setup()
1051 rc = regmap_update_bits(wled->regmap, wled->ctrl_addr + in wled4_setup()
1058 rc = regmap_update_bits(wled->regmap, in wled4_setup()
1059 wled->sink_addr + WLED4_SINK_REG_CURR_SINK, in wled4_setup()
1064 rc = wled->wled_sync_toggle(wled); in wled4_setup()
1066 dev_err(wled->dev, "Failed to toggle sync reg rc:%d\n", rc); in wled4_setup()
1094 rc = regmap_update_bits(wled->regmap, in wled5_setup()
1095 wled->ctrl_addr + WLED3_CTRL_REG_OVP, in wled5_setup()
1096 WLED5_CTRL_REG_OVP_MASK, wled->cfg.ovp); in wled5_setup()
1100 rc = regmap_update_bits(wled->regmap, in wled5_setup()
1101 wled->ctrl_addr + WLED3_CTRL_REG_ILIMIT, in wled5_setup()
1103 wled->cfg.boost_i_limit); in wled5_setup()
1107 rc = regmap_update_bits(wled->regmap, in wled5_setup()
1108 wled->ctrl_addr + WLED3_CTRL_REG_FREQ, in wled5_setup()
1110 wled->cfg.switch_freq); in wled5_setup()
1114 /* Per sink/string configuration */ in wled5_setup()
1115 for (i = 0; i < wled->cfg.num_strings; ++i) { in wled5_setup()
1116 j = wled->cfg.enabled_strings[i]; in wled5_setup()
1117 addr = wled->sink_addr + in wled5_setup()
1119 rc = regmap_update_bits(wled->regmap, addr, in wled5_setup()
1121 wled->cfg.string_i_limit); in wled5_setup()
1125 addr = wled->sink_addr + WLED5_SINK_REG_STR_SRC_SEL(j); in wled5_setup()
1126 rc = regmap_update_bits(wled->regmap, addr, in wled5_setup()
1128 wled->cfg.mod_sel == MOD_A ? in wled5_setup()
1136 rc = wled5_cabc_config(wled, wled->cfg.cabc_sel ? true : false); in wled5_setup()
1141 addr = wled->sink_addr + WLED5_SINK_REG_MOD_A_EN; in wled5_setup()
1142 val = (wled->cfg.mod_sel == MOD_A) ? WLED5_SINK_REG_MOD_EN_MASK : 0; in wled5_setup()
1143 rc = regmap_update_bits(wled->regmap, addr, in wled5_setup()
1148 addr = wled->sink_addr + WLED5_SINK_REG_MOD_B_EN; in wled5_setup()
1149 val = (wled->cfg.mod_sel == MOD_B) ? WLED5_SINK_REG_MOD_EN_MASK : 0; in wled5_setup()
1150 rc = regmap_update_bits(wled->regmap, addr, in wled5_setup()
1155 offset = (wled->cfg.mod_sel == MOD_A) ? in wled5_setup()
1159 addr = wled->sink_addr + offset; in wled5_setup()
1160 val = (wled->max_brightness == WLED5_SINK_REG_BRIGHT_MAX_15B) ? in wled5_setup()
1163 rc = regmap_write(wled->regmap, addr, val); in wled5_setup()
1167 rc = regmap_update_bits(wled->regmap, in wled5_setup()
1168 wled->sink_addr + WLED4_SINK_REG_CURR_SINK, in wled5_setup()
1174 rc = wled->wled_sync_toggle(wled); in wled5_setup()
1250 * 0000 - 38.5 V in wled5_ovp_values_fn()
1251 * 0001 - 37 V .. in wled5_ovp_values_fn()
1252 * 1111 - 16 V in wled5_ovp_values_fn()
1254 return 38500 - (idx * 1500); in wled5_ovp_values_fn()
1296 if (idx >= cfg->size) in wled_values()
1298 if (cfg->fn) in wled_values()
1299 return cfg->fn(idx); in wled_values()
1300 if (cfg->values) in wled_values()
1301 return cfg->values[idx]; in wled_values()
1307 struct wled_config *cfg = &wled->cfg; in wled_configure()
1308 struct device *dev = wled->dev; in wled_configure()
1316 .name = "qcom,current-boost-limit", in wled_configure()
1317 .val_ptr = &cfg->boost_i_limit, in wled_configure()
1321 .name = "qcom,current-limit", in wled_configure()
1322 .val_ptr = &cfg->string_i_limit, in wled_configure()
1327 .val_ptr = &cfg->ovp, in wled_configure()
1331 .name = "qcom,switching-freq", in wled_configure()
1332 .val_ptr = &cfg->switch_freq, in wled_configure()
1339 .name = "qcom,current-boost-limit", in wled_configure()
1340 .val_ptr = &cfg->boost_i_limit, in wled_configure()
1344 .name = "qcom,current-limit-microamp", in wled_configure()
1345 .val_ptr = &cfg->string_i_limit, in wled_configure()
1349 .name = "qcom,ovp-millivolt", in wled_configure()
1350 .val_ptr = &cfg->ovp, in wled_configure()
1354 .name = "qcom,switching-freq", in wled_configure()
1355 .val_ptr = &cfg->switch_freq, in wled_configure()
1362 .name = "qcom,current-boost-limit", in wled_configure()
1363 .val_ptr = &cfg->boost_i_limit, in wled_configure()
1367 .name = "qcom,current-limit-microamp", in wled_configure()
1368 .val_ptr = &cfg->string_i_limit, in wled_configure()
1372 .name = "qcom,ovp-millivolt", in wled_configure()
1373 .val_ptr = &cfg->ovp, in wled_configure()
1377 .name = "qcom,switching-freq", in wled_configure()
1378 .val_ptr = &cfg->switch_freq, in wled_configure()
1382 .name = "qcom,modulator-sel", in wled_configure()
1383 .val_ptr = &cfg->mod_sel, in wled_configure()
1387 .name = "qcom,cabc-sel", in wled_configure()
1388 .val_ptr = &cfg->cabc_sel, in wled_configure()
1394 { "qcom,cs-out", &cfg->cs_out_en, }, in wled_configure()
1395 { "qcom,ext-gen", &cfg->ext_gen, }, in wled_configure()
1396 { "qcom,cabc", &cfg->cabc, }, in wled_configure()
1397 { "qcom,external-pfet", &cfg->external_pfet, }, in wled_configure()
1398 { "qcom,auto-string-detection", &cfg->auto_detection_enabled, }, in wled_configure()
1401 prop_addr = of_get_address(dev->of_node, 0, NULL, NULL); in wled_configure()
1403 dev_err(wled->dev, "invalid IO resources\n"); in wled_configure()
1404 return -EINVAL; in wled_configure()
1406 wled->ctrl_addr = be32_to_cpu(*prop_addr); in wled_configure()
1408 rc = of_property_read_string(dev->of_node, "label", &wled->name); in wled_configure()
1410 wled->name = devm_kasprintf(dev, GFP_KERNEL, "%pOFn", dev->of_node); in wled_configure()
1412 switch (wled->version) { in wled_configure()
1417 wled->wled_set_brightness = wled3_set_brightness; in wled_configure()
1418 wled->wled_sync_toggle = wled3_sync_toggle; in wled_configure()
1419 wled->max_string_count = 3; in wled_configure()
1420 wled->sink_addr = wled->ctrl_addr; in wled_configure()
1427 wled->wled_set_brightness = wled4_set_brightness; in wled_configure()
1428 wled->wled_sync_toggle = wled3_sync_toggle; in wled_configure()
1429 wled->wled_cabc_config = wled4_cabc_config; in wled_configure()
1430 wled->wled_ovp_delay = wled4_ovp_delay; in wled_configure()
1431 wled->wled_auto_detection_required = in wled_configure()
1433 wled->max_string_count = 4; in wled_configure()
1435 prop_addr = of_get_address(dev->of_node, 1, NULL, NULL); in wled_configure()
1437 dev_err(wled->dev, "invalid IO resources\n"); in wled_configure()
1438 return -EINVAL; in wled_configure()
1440 wled->sink_addr = be32_to_cpu(*prop_addr); in wled_configure()
1447 wled->wled_set_brightness = wled5_set_brightness; in wled_configure()
1448 wled->wled_sync_toggle = wled3_sync_toggle; in wled_configure()
1449 wled->wled_cabc_config = wled5_cabc_config; in wled_configure()
1450 wled->wled_ovp_delay = wled5_ovp_delay; in wled_configure()
1451 wled->wled_auto_detection_required = in wled_configure()
1453 wled->max_string_count = 4; in wled_configure()
1455 prop_addr = of_get_address(dev->of_node, 1, NULL, NULL); in wled_configure()
1457 dev_err(wled->dev, "invalid IO resources\n"); in wled_configure()
1458 return -EINVAL; in wled_configure()
1460 wled->sink_addr = be32_to_cpu(*prop_addr); in wled_configure()
1464 dev_err(wled->dev, "Invalid WLED version\n"); in wled_configure()
1465 return -EINVAL; in wled_configure()
1469 rc = of_property_read_u32(dev->of_node, u32_opts[i].name, &val); in wled_configure()
1470 if (rc == -EINVAL) { in wled_configure()
1483 return -EINVAL; in wled_configure()
1495 if (of_property_read_bool(dev->of_node, bool_opts[i].name)) in wled_configure()
1499 string_len = of_property_count_elems_of_size(dev->of_node, in wled_configure()
1500 "qcom,enabled-strings", in wled_configure()
1503 if (string_len > wled->max_string_count) { in wled_configure()
1505 wled->max_string_count); in wled_configure()
1506 return -EINVAL; in wled_configure()
1509 rc = of_property_read_u32_array(dev->of_node, in wled_configure()
1510 "qcom,enabled-strings", in wled_configure()
1511 wled->cfg.enabled_strings, in wled_configure()
1514 dev_err(dev, "Failed to read %d elements from qcom,enabled-strings: %d\n", in wled_configure()
1520 if (wled->cfg.enabled_strings[i] >= wled->max_string_count) { in wled_configure()
1522 "qcom,enabled-strings index %d at %d is out of bounds\n", in wled_configure()
1523 wled->cfg.enabled_strings[i], i); in wled_configure()
1524 return -EINVAL; in wled_configure()
1528 cfg->num_strings = string_len; in wled_configure()
1531 rc = of_property_read_u32(dev->of_node, "qcom,num-strings", &val); in wled_configure()
1533 if (val < 1 || val > wled->max_string_count) { in wled_configure()
1534 dev_err(dev, "qcom,num-strings must be between 1 and %d\n", in wled_configure()
1535 wled->max_string_count); in wled_configure()
1536 return -EINVAL; in wled_configure()
1540 dev_warn(dev, "Only one of qcom,num-strings or qcom,enabled-strings" in wled_configure()
1543 dev_err(dev, "qcom,num-strings exceeds qcom,enabled-strings\n"); in wled_configure()
1544 return -EINVAL; in wled_configure()
1548 cfg->num_strings = val; in wled_configure()
1559 if (!wled->has_short_detect) in wled_configure_short_irq()
1562 rc = regmap_update_bits(wled->regmap, wled->ctrl_addr + in wled_configure_short_irq()
1569 wled->short_irq = platform_get_irq_byname(pdev, "short"); in wled_configure_short_irq()
1570 if (wled->short_irq < 0) { in wled_configure_short_irq()
1571 dev_dbg(&pdev->dev, "short irq is not used\n"); in wled_configure_short_irq()
1575 rc = devm_request_threaded_irq(wled->dev, wled->short_irq, in wled_configure_short_irq()
1580 dev_err(wled->dev, "Unable to request short_irq (err:%d)\n", in wled_configure_short_irq()
1592 wled->ovp_irq = platform_get_irq_byname(pdev, "ovp"); in wled_configure_ovp_irq()
1593 if (wled->ovp_irq < 0) { in wled_configure_ovp_irq()
1594 dev_dbg(&pdev->dev, "OVP IRQ not found - disabling automatic string detection\n"); in wled_configure_ovp_irq()
1598 rc = devm_request_threaded_irq(wled->dev, wled->ovp_irq, NULL, in wled_configure_ovp_irq()
1602 dev_err(wled->dev, "Unable to request ovp_irq (err:%d)\n", in wled_configure_ovp_irq()
1604 wled->ovp_irq = 0; in wled_configure_ovp_irq()
1608 rc = regmap_read(wled->regmap, wled->ctrl_addr + in wled_configure_ovp_irq()
1615 disable_irq(wled->ovp_irq); in wled_configure_ovp_irq()
1633 regmap = dev_get_regmap(pdev->dev.parent, NULL); in wled_probe()
1635 dev_err(&pdev->dev, "Unable to get regmap\n"); in wled_probe()
1636 return -EINVAL; in wled_probe()
1639 wled = devm_kzalloc(&pdev->dev, sizeof(*wled), GFP_KERNEL); in wled_probe()
1641 return -ENOMEM; in wled_probe()
1643 wled->regmap = regmap; in wled_probe()
1644 wled->dev = &pdev->dev; in wled_probe()
1646 wled->version = (uintptr_t)of_device_get_match_data(&pdev->dev); in wled_probe()
1647 if (!wled->version) { in wled_probe()
1648 dev_err(&pdev->dev, "Unknown device version\n"); in wled_probe()
1649 return -ENODEV; in wled_probe()
1652 mutex_init(&wled->lock); in wled_probe()
1658 of_property_read_u32(pdev->dev.of_node, "max-brightness", &val); in wled_probe()
1659 wled->max_brightness = val; in wled_probe()
1661 switch (wled->version) { in wled_probe()
1663 wled->cfg.auto_detection_enabled = false; in wled_probe()
1666 dev_err(&pdev->dev, "wled3_setup failed\n"); in wled_probe()
1672 wled->has_short_detect = true; in wled_probe()
1675 dev_err(&pdev->dev, "wled4_setup failed\n"); in wled_probe()
1681 wled->has_short_detect = true; in wled_probe()
1682 if (wled->cfg.cabc_sel) in wled_probe()
1683 wled->max_brightness = WLED5_SINK_REG_BRIGHT_MAX_12B; in wled_probe()
1687 dev_err(&pdev->dev, "wled5_setup failed\n"); in wled_probe()
1693 dev_err(wled->dev, "Invalid WLED version\n"); in wled_probe()
1697 INIT_DELAYED_WORK(&wled->ovp_work, wled_ovp_work); in wled_probe()
1708 of_property_read_u32(pdev->dev.of_node, "default-brightness", &val); in wled_probe()
1713 props.max_brightness = wled->max_brightness; in wled_probe()
1714 bl = devm_backlight_device_register(&pdev->dev, wled->name, in wled_probe()
1715 &pdev->dev, wled, in wled_probe()
1724 mutex_destroy(&wled->lock); in wled_remove()
1725 cancel_delayed_work_sync(&wled->ovp_work); in wled_remove()
1726 disable_irq(wled->short_irq); in wled_remove()
1727 disable_irq(wled->ovp_irq); in wled_remove()
1731 { .compatible = "qcom,pm8941-wled", .data = (void *)3 },
1732 { .compatible = "qcom,pmi8950-wled", .data = (void *)4 },
1733 { .compatible = "qcom,pmi8994-wled", .data = (void *)4 },
1734 { .compatible = "qcom,pmi8998-wled", .data = (void *)4 },
1735 { .compatible = "qcom,pm660l-wled", .data = (void *)4 },
1736 { .compatible = "qcom,pm6150l-wled", .data = (void *)5 },
1737 { .compatible = "qcom,pm8150l-wled", .data = (void *)5 },