^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Regulator driver for the Richtek RT5033
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2014 Samsung Electronics, Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Beomho Seo <beomho.seo@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/mfd/rt5033.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/mfd/rt5033-private.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static const struct regulator_ops rt5033_safe_ldo_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static const struct regulator_ops rt5033_buck_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) .map_voltage = regulator_map_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static const struct regulator_desc rt5033_supported_regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) [RT5033_BUCK] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .name = "BUCK",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .of_match = of_match_ptr("BUCK"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .id = RT5033_BUCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .ops = &rt5033_buck_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .n_voltages = RT5033_REGULATOR_BUCK_VOLTAGE_STEP_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .min_uV = RT5033_REGULATOR_BUCK_VOLTAGE_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .uV_step = RT5033_REGULATOR_BUCK_VOLTAGE_STEP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .enable_reg = RT5033_REG_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .enable_mask = RT5033_CTRL_EN_BUCK_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .vsel_reg = RT5033_REG_BUCK_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .vsel_mask = RT5033_BUCK_CTRL_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) [RT5033_LDO] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .name = "LDO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .of_match = of_match_ptr("LDO"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .id = RT5033_LDO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .ops = &rt5033_buck_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .n_voltages = RT5033_REGULATOR_LDO_VOLTAGE_STEP_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .min_uV = RT5033_REGULATOR_LDO_VOLTAGE_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .uV_step = RT5033_REGULATOR_LDO_VOLTAGE_STEP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .enable_reg = RT5033_REG_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .enable_mask = RT5033_CTRL_EN_LDO_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .vsel_reg = RT5033_REG_LDO_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .vsel_mask = RT5033_LDO_CTRL_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) [RT5033_SAFE_LDO] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .name = "SAFE_LDO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .of_match = of_match_ptr("SAFE_LDO"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .id = RT5033_SAFE_LDO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .ops = &rt5033_safe_ldo_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) .n_voltages = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) .min_uV = RT5033_REGULATOR_SAFE_LDO_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .enable_reg = RT5033_REG_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .enable_mask = RT5033_CTRL_EN_SAFE_LDO_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static int rt5033_regulator_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct rt5033_dev *rt5033 = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct regulator_config config = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) config.dev = rt5033->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) config.driver_data = rt5033;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) for (i = 0; i < ARRAY_SIZE(rt5033_supported_regulators); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct regulator_dev *regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) config.regmap = rt5033->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) regulator = devm_regulator_register(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) &rt5033_supported_regulators[i], &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (IS_ERR(regulator)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ret = PTR_ERR(regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) "Regulator init failed %d: with error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) i, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static const struct platform_device_id rt5033_regulator_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) { "rt5033-regulator", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) MODULE_DEVICE_TABLE(platform, rt5033_regulator_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static struct platform_driver rt5033_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .name = "rt5033-regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .probe = rt5033_regulator_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .id_table = rt5033_regulator_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) module_platform_driver(rt5033_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) MODULE_DESCRIPTION("Richtek RT5033 Regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) MODULE_AUTHOR("Beomho Seo <beomho.seo@samsung.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) MODULE_LICENSE("GPL");