Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Regulator driver for the Richtek RT5033
0004  *
0005  * Copyright (C) 2014 Samsung Electronics, Co., Ltd.
0006  * Author: Beomho Seo <beomho.seo@samsung.com>
0007  */
0008 
0009 #include <linux/module.h>
0010 #include <linux/platform_device.h>
0011 #include <linux/regulator/driver.h>
0012 #include <linux/mfd/rt5033.h>
0013 #include <linux/mfd/rt5033-private.h>
0014 #include <linux/regulator/of_regulator.h>
0015 
0016 static const struct linear_range rt5033_buck_ranges[] = {
0017     REGULATOR_LINEAR_RANGE(1000000, 0, 20, 100000),
0018     REGULATOR_LINEAR_RANGE(3000000, 21, 31, 0),
0019 };
0020 
0021 static const struct linear_range rt5033_ldo_ranges[] = {
0022     REGULATOR_LINEAR_RANGE(1200000, 0, 18, 100000),
0023     REGULATOR_LINEAR_RANGE(3000000, 19, 31, 0),
0024 };
0025 
0026 static const struct regulator_ops rt5033_safe_ldo_ops = {
0027     .is_enabled     = regulator_is_enabled_regmap,
0028     .enable         = regulator_enable_regmap,
0029     .disable        = regulator_disable_regmap,
0030     .list_voltage       = regulator_list_voltage_linear,
0031 };
0032 
0033 static const struct regulator_ops rt5033_buck_ops = {
0034     .is_enabled     = regulator_is_enabled_regmap,
0035     .enable         = regulator_enable_regmap,
0036     .disable        = regulator_disable_regmap,
0037     .list_voltage       = regulator_list_voltage_linear_range,
0038     .get_voltage_sel    = regulator_get_voltage_sel_regmap,
0039     .set_voltage_sel    = regulator_set_voltage_sel_regmap,
0040 };
0041 
0042 static const struct regulator_desc rt5033_supported_regulators[] = {
0043     [RT5033_BUCK] = {
0044         .name       = "BUCK",
0045         .of_match   = of_match_ptr("BUCK"),
0046         .regulators_node = of_match_ptr("regulators"),
0047         .id     = RT5033_BUCK,
0048         .ops        = &rt5033_buck_ops,
0049         .type       = REGULATOR_VOLTAGE,
0050         .owner      = THIS_MODULE,
0051         .n_voltages = RT5033_REGULATOR_BUCK_VOLTAGE_STEP_NUM,
0052         .linear_ranges  = rt5033_buck_ranges,
0053         .n_linear_ranges = ARRAY_SIZE(rt5033_buck_ranges),
0054         .enable_reg = RT5033_REG_CTRL,
0055         .enable_mask    = RT5033_CTRL_EN_BUCK_MASK,
0056         .vsel_reg   = RT5033_REG_BUCK_CTRL,
0057         .vsel_mask  = RT5033_BUCK_CTRL_MASK,
0058     },
0059     [RT5033_LDO] = {
0060         .name       = "LDO",
0061         .of_match   = of_match_ptr("LDO"),
0062         .regulators_node = of_match_ptr("regulators"),
0063         .id     = RT5033_LDO,
0064         .ops        = &rt5033_buck_ops,
0065         .type       = REGULATOR_VOLTAGE,
0066         .owner      = THIS_MODULE,
0067         .n_voltages = RT5033_REGULATOR_LDO_VOLTAGE_STEP_NUM,
0068         .linear_ranges  = rt5033_ldo_ranges,
0069         .n_linear_ranges = ARRAY_SIZE(rt5033_ldo_ranges),
0070         .enable_reg = RT5033_REG_CTRL,
0071         .enable_mask    = RT5033_CTRL_EN_LDO_MASK,
0072         .vsel_reg   = RT5033_REG_LDO_CTRL,
0073         .vsel_mask  = RT5033_LDO_CTRL_MASK,
0074     },
0075     [RT5033_SAFE_LDO] = {
0076         .name       = "SAFE_LDO",
0077         .of_match   = of_match_ptr("SAFE_LDO"),
0078         .regulators_node = of_match_ptr("regulators"),
0079         .id     = RT5033_SAFE_LDO,
0080         .ops        = &rt5033_safe_ldo_ops,
0081         .type       = REGULATOR_VOLTAGE,
0082         .owner      = THIS_MODULE,
0083         .n_voltages = 1,
0084         .min_uV     = RT5033_REGULATOR_SAFE_LDO_VOLTAGE,
0085         .enable_reg = RT5033_REG_CTRL,
0086         .enable_mask    = RT5033_CTRL_EN_SAFE_LDO_MASK,
0087     },
0088 };
0089 
0090 static int rt5033_regulator_probe(struct platform_device *pdev)
0091 {
0092     struct rt5033_dev *rt5033 = dev_get_drvdata(pdev->dev.parent);
0093     int ret, i;
0094     struct regulator_config config = {};
0095 
0096     config.dev = rt5033->dev;
0097     config.driver_data = rt5033;
0098 
0099     for (i = 0; i < ARRAY_SIZE(rt5033_supported_regulators); i++) {
0100         struct regulator_dev *regulator;
0101 
0102         config.regmap = rt5033->regmap;
0103 
0104         regulator = devm_regulator_register(&pdev->dev,
0105                 &rt5033_supported_regulators[i], &config);
0106         if (IS_ERR(regulator)) {
0107             ret = PTR_ERR(regulator);
0108             dev_err(&pdev->dev,
0109                 "Regulator init failed %d: with error: %d\n",
0110                 i, ret);
0111             return ret;
0112         }
0113     }
0114 
0115     return 0;
0116 }
0117 
0118 static const struct platform_device_id rt5033_regulator_id[] = {
0119     { "rt5033-regulator", },
0120     { }
0121 };
0122 MODULE_DEVICE_TABLE(platform, rt5033_regulator_id);
0123 
0124 static struct platform_driver rt5033_regulator_driver = {
0125     .driver = {
0126         .name = "rt5033-regulator",
0127     },
0128     .probe      = rt5033_regulator_probe,
0129     .id_table   = rt5033_regulator_id,
0130 };
0131 module_platform_driver(rt5033_regulator_driver);
0132 
0133 MODULE_DESCRIPTION("Richtek RT5033 Regulator driver");
0134 MODULE_AUTHOR("Beomho Seo <beomho.seo@samsung.com>");
0135 MODULE_LICENSE("GPL");