Linux Audio

Check our new training course

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