Lines Matching refs:vreg

624 static inline int spmi_vreg_read(struct spmi_regulator *vreg, u16 addr, u8 *buf,  in spmi_vreg_read()  argument
627 return regmap_bulk_read(vreg->regmap, vreg->base + addr, buf, len); in spmi_vreg_read()
630 static inline int spmi_vreg_write(struct spmi_regulator *vreg, u16 addr, in spmi_vreg_write() argument
633 return regmap_bulk_write(vreg->regmap, vreg->base + addr, buf, len); in spmi_vreg_write()
636 static int spmi_vreg_update_bits(struct spmi_regulator *vreg, u16 addr, u8 val, in spmi_vreg_update_bits() argument
639 return regmap_update_bits(vreg->regmap, vreg->base + addr, mask, val); in spmi_vreg_update_bits()
644 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_vs_enable() local
646 if (vreg->ocp_irq) { in spmi_regulator_vs_enable()
647 vreg->ocp_count = 0; in spmi_regulator_vs_enable()
648 vreg->vs_enable_time = ktime_get(); in spmi_regulator_vs_enable()
657 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_vs_ocp() local
663 return spmi_vreg_write(vreg, SPMI_VS_REG_OCP, &reg, 1); in spmi_regulator_vs_ocp()
666 static int spmi_regulator_select_voltage(struct spmi_regulator *vreg, in spmi_regulator_select_voltage() argument
675 lim_min_uV = vreg->set_points->range[0].set_point_min_uV; in spmi_regulator_select_voltage()
677 vreg->set_points->range[vreg->set_points->count - 1].set_point_max_uV; in spmi_regulator_select_voltage()
683 dev_err(vreg->dev, in spmi_regulator_select_voltage()
690 for (i = vreg->set_points->count - 1; i > 0; i--) { in spmi_regulator_select_voltage()
691 range_max_uV = vreg->set_points->range[i - 1].set_point_max_uV; in spmi_regulator_select_voltage()
697 range = &vreg->set_points->range[range_id]; in spmi_regulator_select_voltage()
707 dev_err(vreg->dev, in spmi_regulator_select_voltage()
716 selector += vreg->set_points->range[i].n_voltages; in spmi_regulator_select_voltage()
722 static int spmi_sw_selector_to_hw(struct spmi_regulator *vreg, in spmi_sw_selector_to_hw() argument
729 range = vreg->set_points->range; in spmi_sw_selector_to_hw()
730 end = range + vreg->set_points->count; in spmi_sw_selector_to_hw()
751 static int spmi_hw_selector_to_sw(struct spmi_regulator *vreg, u8 hw_sel, in spmi_hw_selector_to_sw() argument
756 const struct spmi_voltage_range *r = vreg->set_points->range; in spmi_hw_selector_to_sw()
757 const struct spmi_voltage_range *end = r + vreg->set_points->count; in spmi_hw_selector_to_sw()
786 spmi_regulator_find_range(struct spmi_regulator *vreg) in spmi_regulator_find_range() argument
791 range = vreg->set_points->range; in spmi_regulator_find_range()
792 end = range + vreg->set_points->count; in spmi_regulator_find_range()
794 spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, &range_sel, 1); in spmi_regulator_find_range()
803 static int spmi_regulator_select_voltage_same_range(struct spmi_regulator *vreg, in spmi_regulator_select_voltage_same_range() argument
810 range = spmi_regulator_find_range(vreg); in spmi_regulator_select_voltage_same_range()
838 for (i = 0; i < vreg->set_points->count; i++) { in spmi_regulator_select_voltage_same_range()
839 if (uV >= vreg->set_points->range[i].set_point_min_uV in spmi_regulator_select_voltage_same_range()
840 && uV <= vreg->set_points->range[i].set_point_max_uV) { in spmi_regulator_select_voltage_same_range()
842 (uV - vreg->set_points->range[i].set_point_min_uV) in spmi_regulator_select_voltage_same_range()
843 / vreg->set_points->range[i].step_uV; in spmi_regulator_select_voltage_same_range()
847 selector += vreg->set_points->range[i].n_voltages; in spmi_regulator_select_voltage_same_range()
850 if (selector >= vreg->set_points->n_voltages) in spmi_regulator_select_voltage_same_range()
856 return spmi_regulator_select_voltage(vreg, min_uV, max_uV); in spmi_regulator_select_voltage_same_range()
862 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_common_map_voltage() local
868 return spmi_regulator_select_voltage_same_range(vreg, min_uV, max_uV); in spmi_regulator_common_map_voltage()
874 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_common_set_voltage() local
879 ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel); in spmi_regulator_common_set_voltage()
885 return spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, buf, 2); in spmi_regulator_common_set_voltage()
894 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_ftsmps426_set_voltage() local
902 return spmi_vreg_write(vreg, SPMI_FTSMPS426_REG_VOLTAGE_LSB, buf, 2); in spmi_regulator_ftsmps426_set_voltage()
908 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_set_voltage_time_sel() local
914 return DIV_ROUND_UP(diff_uV, vreg->slew_rate); in spmi_regulator_set_voltage_time_sel()
919 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_common_get_voltage() local
923 spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &voltage_sel, 1); in spmi_regulator_common_get_voltage()
925 range = spmi_regulator_find_range(vreg); in spmi_regulator_common_get_voltage()
929 return spmi_hw_selector_to_sw(vreg, voltage_sel, range); in spmi_regulator_common_get_voltage()
934 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_ftsmps426_get_voltage() local
939 spmi_vreg_read(vreg, SPMI_FTSMPS426_REG_VOLTAGE_LSB, buf, 2); in spmi_regulator_ftsmps426_get_voltage()
942 range = vreg->set_points->range; in spmi_regulator_ftsmps426_get_voltage()
950 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_single_map_voltage() local
952 return spmi_regulator_select_voltage(vreg, min_uV, max_uV); in spmi_regulator_single_map_voltage()
958 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_single_range_set_voltage() local
965 return spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &sel, 1); in spmi_regulator_single_range_set_voltage()
970 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_single_range_get_voltage() local
974 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &selector, 1); in spmi_regulator_single_range_get_voltage()
984 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_ult_lo_smps_set_voltage() local
988 ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel); in spmi_regulator_ult_lo_smps_set_voltage()
1002 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_VOLTAGE_SET, in spmi_regulator_ult_lo_smps_set_voltage()
1008 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_ult_lo_smps_get_voltage() local
1012 spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &voltage_sel, 1); in spmi_regulator_ult_lo_smps_get_voltage()
1014 range = spmi_regulator_find_range(vreg); in spmi_regulator_ult_lo_smps_get_voltage()
1021 return spmi_hw_selector_to_sw(vreg, voltage_sel, range); in spmi_regulator_ult_lo_smps_get_voltage()
1027 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_common_list_voltage() local
1031 if (selector >= vreg->set_points->n_voltages) in spmi_regulator_common_list_voltage()
1034 for (i = 0; i < vreg->set_points->count; i++) { in spmi_regulator_common_list_voltage()
1035 if (selector < vreg->set_points->range[i].n_voltages) { in spmi_regulator_common_list_voltage()
1036 uV = selector * vreg->set_points->range[i].step_uV in spmi_regulator_common_list_voltage()
1037 + vreg->set_points->range[i].set_point_min_uV; in spmi_regulator_common_list_voltage()
1041 selector -= vreg->set_points->range[i].n_voltages; in spmi_regulator_common_list_voltage()
1050 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_common_set_bypass() local
1057 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); in spmi_regulator_common_set_bypass()
1063 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_common_get_bypass() local
1067 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &val, 1); in spmi_regulator_common_get_bypass()
1075 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_common_get_mode() local
1078 spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &reg, 1); in spmi_regulator_common_get_mode()
1094 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_ftsmps426_get_mode() local
1097 spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &reg, 1); in spmi_regulator_ftsmps426_get_mode()
1111 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_hfsmps_get_mode() local
1114 spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &reg, 1); in spmi_regulator_hfsmps_get_mode()
1129 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_common_set_mode() local
1145 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); in spmi_regulator_common_set_mode()
1151 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_ftsmps426_set_mode() local
1169 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); in spmi_regulator_ftsmps426_set_mode()
1175 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_hfsmps_set_mode() local
1187 val = vreg->logical_type == in spmi_regulator_hfsmps_set_mode()
1196 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); in spmi_regulator_hfsmps_set_mode()
1202 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_common_set_load() local
1205 if (load_uA >= vreg->hpm_min_load) in spmi_regulator_common_set_load()
1215 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_common_set_pull_down() local
1218 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_PULL_DOWN, in spmi_regulator_common_set_pull_down()
1224 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_hfsmps_set_pull_down() local
1227 return spmi_vreg_update_bits(vreg, SPMI_HFSMPS_REG_PULL_DOWN, in spmi_regulator_hfsmps_set_pull_down()
1233 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_common_set_soft_start() local
1236 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_SOFT_START, in spmi_regulator_common_set_soft_start()
1242 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_set_ilim() local
1243 enum spmi_regulator_logical_type type = vreg->logical_type; in spmi_regulator_set_ilim()
1261 return spmi_vreg_update_bits(vreg, current_reg, reg, mask); in spmi_regulator_set_ilim()
1264 static int spmi_regulator_vs_clear_ocp(struct spmi_regulator *vreg) in spmi_regulator_vs_clear_ocp() argument
1268 ret = spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE, in spmi_regulator_vs_clear_ocp()
1271 vreg->vs_enable_time = ktime_get(); in spmi_regulator_vs_clear_ocp()
1273 ret = spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE, in spmi_regulator_vs_clear_ocp()
1282 struct spmi_regulator *vreg in spmi_regulator_vs_ocp_work() local
1285 spmi_regulator_vs_clear_ocp(vreg); in spmi_regulator_vs_ocp_work()
1290 struct spmi_regulator *vreg = data; in spmi_regulator_vs_ocp_isr() local
1296 vreg->vs_enable_time); in spmi_regulator_vs_ocp_isr()
1304 vreg->ocp_count = 0; in spmi_regulator_vs_ocp_isr()
1309 vreg->ocp_count++; in spmi_regulator_vs_ocp_isr()
1311 if (vreg->ocp_count == 1) { in spmi_regulator_vs_ocp_isr()
1313 spmi_regulator_vs_clear_ocp(vreg); in spmi_regulator_vs_ocp_isr()
1314 } else if (vreg->ocp_count <= vreg->ocp_max_retries) { in spmi_regulator_vs_ocp_isr()
1316 schedule_delayed_work(&vreg->ocp_work, in spmi_regulator_vs_ocp_isr()
1317 msecs_to_jiffies(vreg->ocp_retry_delay_ms) + 1); in spmi_regulator_vs_ocp_isr()
1319 dev_err(vreg->dev, in spmi_regulator_vs_ocp_isr()
1321 vreg->ocp_count); in spmi_regulator_vs_ocp_isr()
1389 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); in spmi_regulator_saw_set_voltage() local
1393 ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel); in spmi_regulator_saw_set_voltage()
1693 static int spmi_regulator_match(struct spmi_regulator *vreg, u16 force_type) in spmi_regulator_match() argument
1701 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_DIG_MAJOR_REV, version, in spmi_regulator_match()
1704 dev_dbg(vreg->dev, "could not read version registers\n"); in spmi_regulator_match()
1728 dev_err(vreg->dev, in spmi_regulator_match()
1730 vreg->desc.name, type, subtype, dig_major_rev); in spmi_regulator_match()
1735 vreg->logical_type = mapping->logical_type; in spmi_regulator_match()
1736 vreg->set_points = mapping->set_points; in spmi_regulator_match()
1737 vreg->hpm_min_load = mapping->hpm_min_load; in spmi_regulator_match()
1738 vreg->desc.ops = mapping->ops; in spmi_regulator_match()
1743 vreg->desc.n_voltages = mapping->set_points->n_voltages; in spmi_regulator_match()
1749 static int spmi_regulator_init_slew_rate(struct spmi_regulator *vreg) in spmi_regulator_init_slew_rate() argument
1756 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, &reg, 1); in spmi_regulator_init_slew_rate()
1758 dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret); in spmi_regulator_init_slew_rate()
1762 range = spmi_regulator_find_range(vreg); in spmi_regulator_init_slew_rate()
1766 switch (vreg->logical_type) { in spmi_regulator_init_slew_rate()
1788 vreg->slew_rate = max(slew_rate, 1); in spmi_regulator_init_slew_rate()
1793 static int spmi_regulator_init_slew_rate_ftsmps426(struct spmi_regulator *vreg, in spmi_regulator_init_slew_rate_ftsmps426() argument
1799 const struct spmi_voltage_range *range = &vreg->set_points->range[0]; in spmi_regulator_init_slew_rate_ftsmps426()
1801 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, &reg, 1); in spmi_regulator_init_slew_rate_ftsmps426()
1803 dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret); in spmi_regulator_init_slew_rate_ftsmps426()
1817 vreg->slew_rate = max(slew_rate, 1); in spmi_regulator_init_slew_rate_ftsmps426()
1822 static int spmi_regulator_init_slew_rate_hfsmps(struct spmi_regulator *vreg) in spmi_regulator_init_slew_rate_hfsmps() argument
1828 ret = spmi_vreg_read(vreg, SPMI_HFSMPS_REG_STEP_CTRL, &reg, 1); in spmi_regulator_init_slew_rate_hfsmps()
1830 dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret); in spmi_regulator_init_slew_rate_hfsmps()
1837 vreg->slew_rate = SPMI_HFSMPS_SLEW_RATE_38p4 >> delay; in spmi_regulator_init_slew_rate_hfsmps()
1842 static int spmi_regulator_init_registers(struct spmi_regulator *vreg, in spmi_regulator_init_registers() argument
1849 type = vreg->logical_type; in spmi_regulator_init_registers()
1851 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, ctrl_reg, 8); in spmi_regulator_init_registers()
1896 ret = spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, ctrl_reg, 8); in spmi_regulator_init_registers()
1907 return spmi_vreg_update_bits(vreg, in spmi_regulator_init_registers()
1916 static void spmi_regulator_get_dt_config(struct spmi_regulator *vreg, in spmi_regulator_get_dt_config() argument
1929 &vreg->ocp_max_retries); in spmi_regulator_get_dt_config()
1931 &vreg->ocp_retry_delay_ms); in spmi_regulator_get_dt_config()
1954 struct spmi_regulator *vreg = config->driver_data; in spmi_regulator_of_parse() local
1958 spmi_regulator_get_dt_config(vreg, node, &data); in spmi_regulator_of_parse()
1960 if (!vreg->ocp_max_retries) in spmi_regulator_of_parse()
1961 vreg->ocp_max_retries = SPMI_VS_OCP_DEFAULT_MAX_RETRIES; in spmi_regulator_of_parse()
1962 if (!vreg->ocp_retry_delay_ms) in spmi_regulator_of_parse()
1963 vreg->ocp_retry_delay_ms = SPMI_VS_OCP_DEFAULT_RETRY_DELAY_MS; in spmi_regulator_of_parse()
1965 ret = spmi_regulator_init_registers(vreg, &data); in spmi_regulator_of_parse()
1971 switch (vreg->logical_type) { in spmi_regulator_of_parse()
1976 ret = spmi_regulator_init_slew_rate(vreg); in spmi_regulator_of_parse()
1981 ret = spmi_regulator_init_slew_rate_ftsmps426(vreg, in spmi_regulator_of_parse()
1987 ret = spmi_regulator_init_slew_rate_ftsmps426(vreg, in spmi_regulator_of_parse()
1994 ret = spmi_regulator_init_slew_rate_hfsmps(vreg); in spmi_regulator_of_parse()
2002 if (vreg->logical_type != SPMI_REGULATOR_LOGICAL_TYPE_VS) in spmi_regulator_of_parse()
2003 vreg->ocp_irq = 0; in spmi_regulator_of_parse()
2005 if (vreg->ocp_irq) { in spmi_regulator_of_parse()
2006 ret = devm_request_irq(dev, vreg->ocp_irq, in spmi_regulator_of_parse()
2008 vreg); in spmi_regulator_of_parse()
2011 vreg->ocp_irq, ret); in spmi_regulator_of_parse()
2015 ret = devm_delayed_work_autocancel(dev, &vreg->ocp_work, in spmi_regulator_of_parse()
2378 struct spmi_regulator *vreg; in qcom_spmi_regulator_probe() local
2421 vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL); in qcom_spmi_regulator_probe()
2422 if (!vreg) in qcom_spmi_regulator_probe()
2425 vreg->dev = dev; in qcom_spmi_regulator_probe()
2426 vreg->base = reg->base; in qcom_spmi_regulator_probe()
2427 vreg->regmap = regmap; in qcom_spmi_regulator_probe()
2429 vreg->ocp_irq = platform_get_irq_byname(pdev, reg->ocp); in qcom_spmi_regulator_probe()
2430 if (vreg->ocp_irq < 0) in qcom_spmi_regulator_probe()
2431 return vreg->ocp_irq; in qcom_spmi_regulator_probe()
2433 vreg->desc.id = -1; in qcom_spmi_regulator_probe()
2434 vreg->desc.owner = THIS_MODULE; in qcom_spmi_regulator_probe()
2435 vreg->desc.type = REGULATOR_VOLTAGE; in qcom_spmi_regulator_probe()
2436 vreg->desc.enable_reg = reg->base + SPMI_COMMON_REG_ENABLE; in qcom_spmi_regulator_probe()
2437 vreg->desc.enable_mask = SPMI_COMMON_ENABLE_MASK; in qcom_spmi_regulator_probe()
2438 vreg->desc.enable_val = SPMI_COMMON_ENABLE; in qcom_spmi_regulator_probe()
2439 vreg->desc.name = name = reg->name; in qcom_spmi_regulator_probe()
2440 vreg->desc.supply_name = reg->supply; in qcom_spmi_regulator_probe()
2441 vreg->desc.of_match = reg->name; in qcom_spmi_regulator_probe()
2442 vreg->desc.of_parse_cb = spmi_regulator_of_parse; in qcom_spmi_regulator_probe()
2443 vreg->desc.of_map_mode = spmi_regulator_of_map_mode; in qcom_spmi_regulator_probe()
2445 ret = spmi_regulator_match(vreg, reg->force_type); in qcom_spmi_regulator_probe()
2455 spmi_saw_ops = *(vreg->desc.ops); in qcom_spmi_regulator_probe()
2458 vreg->desc.ops = &spmi_saw_ops; in qcom_spmi_regulator_probe()
2462 if (vreg->set_points && vreg->set_points->count == 1) { in qcom_spmi_regulator_probe()
2464 range = vreg->set_points->range; in qcom_spmi_regulator_probe()
2465 vreg->desc.uV_step = range->step_uV; in qcom_spmi_regulator_probe()
2469 config.driver_data = vreg; in qcom_spmi_regulator_probe()
2471 rdev = devm_regulator_register(dev, &vreg->desc, &config); in qcom_spmi_regulator_probe()
2477 INIT_LIST_HEAD(&vreg->node); in qcom_spmi_regulator_probe()
2478 list_add(&vreg->node, vreg_list); in qcom_spmi_regulator_probe()