18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Regulator driver for the Richtek RT5033 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2014 Samsung Electronics, Co., Ltd. 68c2ecf20Sopenharmony_ci * Author: Beomho Seo <beomho.seo@samsung.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 118c2ecf20Sopenharmony_ci#include <linux/regulator/driver.h> 128c2ecf20Sopenharmony_ci#include <linux/mfd/rt5033.h> 138c2ecf20Sopenharmony_ci#include <linux/mfd/rt5033-private.h> 148c2ecf20Sopenharmony_ci#include <linux/regulator/of_regulator.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistatic const struct regulator_ops rt5033_safe_ldo_ops = { 178c2ecf20Sopenharmony_ci .is_enabled = regulator_is_enabled_regmap, 188c2ecf20Sopenharmony_ci .enable = regulator_enable_regmap, 198c2ecf20Sopenharmony_ci .disable = regulator_disable_regmap, 208c2ecf20Sopenharmony_ci .list_voltage = regulator_list_voltage_linear, 218c2ecf20Sopenharmony_ci}; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic const struct regulator_ops rt5033_buck_ops = { 248c2ecf20Sopenharmony_ci .is_enabled = regulator_is_enabled_regmap, 258c2ecf20Sopenharmony_ci .enable = regulator_enable_regmap, 268c2ecf20Sopenharmony_ci .disable = regulator_disable_regmap, 278c2ecf20Sopenharmony_ci .list_voltage = regulator_list_voltage_linear, 288c2ecf20Sopenharmony_ci .map_voltage = regulator_map_voltage_linear, 298c2ecf20Sopenharmony_ci .get_voltage_sel = regulator_get_voltage_sel_regmap, 308c2ecf20Sopenharmony_ci .set_voltage_sel = regulator_set_voltage_sel_regmap, 318c2ecf20Sopenharmony_ci}; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistatic const struct regulator_desc rt5033_supported_regulators[] = { 348c2ecf20Sopenharmony_ci [RT5033_BUCK] = { 358c2ecf20Sopenharmony_ci .name = "BUCK", 368c2ecf20Sopenharmony_ci .of_match = of_match_ptr("BUCK"), 378c2ecf20Sopenharmony_ci .regulators_node = of_match_ptr("regulators"), 388c2ecf20Sopenharmony_ci .id = RT5033_BUCK, 398c2ecf20Sopenharmony_ci .ops = &rt5033_buck_ops, 408c2ecf20Sopenharmony_ci .type = REGULATOR_VOLTAGE, 418c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 428c2ecf20Sopenharmony_ci .n_voltages = RT5033_REGULATOR_BUCK_VOLTAGE_STEP_NUM, 438c2ecf20Sopenharmony_ci .min_uV = RT5033_REGULATOR_BUCK_VOLTAGE_MIN, 448c2ecf20Sopenharmony_ci .uV_step = RT5033_REGULATOR_BUCK_VOLTAGE_STEP, 458c2ecf20Sopenharmony_ci .enable_reg = RT5033_REG_CTRL, 468c2ecf20Sopenharmony_ci .enable_mask = RT5033_CTRL_EN_BUCK_MASK, 478c2ecf20Sopenharmony_ci .vsel_reg = RT5033_REG_BUCK_CTRL, 488c2ecf20Sopenharmony_ci .vsel_mask = RT5033_BUCK_CTRL_MASK, 498c2ecf20Sopenharmony_ci }, 508c2ecf20Sopenharmony_ci [RT5033_LDO] = { 518c2ecf20Sopenharmony_ci .name = "LDO", 528c2ecf20Sopenharmony_ci .of_match = of_match_ptr("LDO"), 538c2ecf20Sopenharmony_ci .regulators_node = of_match_ptr("regulators"), 548c2ecf20Sopenharmony_ci .id = RT5033_LDO, 558c2ecf20Sopenharmony_ci .ops = &rt5033_buck_ops, 568c2ecf20Sopenharmony_ci .type = REGULATOR_VOLTAGE, 578c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 588c2ecf20Sopenharmony_ci .n_voltages = RT5033_REGULATOR_LDO_VOLTAGE_STEP_NUM, 598c2ecf20Sopenharmony_ci .min_uV = RT5033_REGULATOR_LDO_VOLTAGE_MIN, 608c2ecf20Sopenharmony_ci .uV_step = RT5033_REGULATOR_LDO_VOLTAGE_STEP, 618c2ecf20Sopenharmony_ci .enable_reg = RT5033_REG_CTRL, 628c2ecf20Sopenharmony_ci .enable_mask = RT5033_CTRL_EN_LDO_MASK, 638c2ecf20Sopenharmony_ci .vsel_reg = RT5033_REG_LDO_CTRL, 648c2ecf20Sopenharmony_ci .vsel_mask = RT5033_LDO_CTRL_MASK, 658c2ecf20Sopenharmony_ci }, 668c2ecf20Sopenharmony_ci [RT5033_SAFE_LDO] = { 678c2ecf20Sopenharmony_ci .name = "SAFE_LDO", 688c2ecf20Sopenharmony_ci .of_match = of_match_ptr("SAFE_LDO"), 698c2ecf20Sopenharmony_ci .regulators_node = of_match_ptr("regulators"), 708c2ecf20Sopenharmony_ci .id = RT5033_SAFE_LDO, 718c2ecf20Sopenharmony_ci .ops = &rt5033_safe_ldo_ops, 728c2ecf20Sopenharmony_ci .type = REGULATOR_VOLTAGE, 738c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 748c2ecf20Sopenharmony_ci .n_voltages = 1, 758c2ecf20Sopenharmony_ci .min_uV = RT5033_REGULATOR_SAFE_LDO_VOLTAGE, 768c2ecf20Sopenharmony_ci .enable_reg = RT5033_REG_CTRL, 778c2ecf20Sopenharmony_ci .enable_mask = RT5033_CTRL_EN_SAFE_LDO_MASK, 788c2ecf20Sopenharmony_ci }, 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistatic int rt5033_regulator_probe(struct platform_device *pdev) 828c2ecf20Sopenharmony_ci{ 838c2ecf20Sopenharmony_ci struct rt5033_dev *rt5033 = dev_get_drvdata(pdev->dev.parent); 848c2ecf20Sopenharmony_ci int ret, i; 858c2ecf20Sopenharmony_ci struct regulator_config config = {}; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci config.dev = rt5033->dev; 888c2ecf20Sopenharmony_ci config.driver_data = rt5033; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rt5033_supported_regulators); i++) { 918c2ecf20Sopenharmony_ci struct regulator_dev *regulator; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci config.regmap = rt5033->regmap; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci regulator = devm_regulator_register(&pdev->dev, 968c2ecf20Sopenharmony_ci &rt5033_supported_regulators[i], &config); 978c2ecf20Sopenharmony_ci if (IS_ERR(regulator)) { 988c2ecf20Sopenharmony_ci ret = PTR_ERR(regulator); 998c2ecf20Sopenharmony_ci dev_err(&pdev->dev, 1008c2ecf20Sopenharmony_ci "Regulator init failed %d: with error: %d\n", 1018c2ecf20Sopenharmony_ci i, ret); 1028c2ecf20Sopenharmony_ci return ret; 1038c2ecf20Sopenharmony_ci } 1048c2ecf20Sopenharmony_ci } 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci return 0; 1078c2ecf20Sopenharmony_ci} 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic const struct platform_device_id rt5033_regulator_id[] = { 1108c2ecf20Sopenharmony_ci { "rt5033-regulator", }, 1118c2ecf20Sopenharmony_ci { } 1128c2ecf20Sopenharmony_ci}; 1138c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(platform, rt5033_regulator_id); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistatic struct platform_driver rt5033_regulator_driver = { 1168c2ecf20Sopenharmony_ci .driver = { 1178c2ecf20Sopenharmony_ci .name = "rt5033-regulator", 1188c2ecf20Sopenharmony_ci }, 1198c2ecf20Sopenharmony_ci .probe = rt5033_regulator_probe, 1208c2ecf20Sopenharmony_ci .id_table = rt5033_regulator_id, 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_cimodule_platform_driver(rt5033_regulator_driver); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Richtek RT5033 Regulator driver"); 1258c2ecf20Sopenharmony_ciMODULE_AUTHOR("Beomho Seo <beomho.seo@samsung.com>"); 1268c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 127