Linux Audio

Check our new training course

Loading...
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0
 2//
 3// sky81452-regulator.c	SKY81452 regulator driver
 4//
 5// Copyright 2014 Skyworks Solutions Inc.
 6// Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>
 
 
 
 
 
 
 
 
 
 
 
 
 7
 8#include <linux/module.h>
 9#include <linux/kernel.h>
10#include <linux/platform_device.h>
11#include <linux/init.h>
12#include <linux/err.h>
13#include <linux/of.h>
14#include <linux/regulator/driver.h>
15#include <linux/regulator/of_regulator.h>
16
17/* registers */
18#define SKY81452_REG1	0x01
19#define SKY81452_REG3	0x03
20
21/* bit mask */
22#define SKY81452_LEN	0x40
23#define SKY81452_LOUT	0x1F
24
25static const struct regulator_ops sky81452_reg_ops = {
26	.list_voltage = regulator_list_voltage_linear_range,
27	.map_voltage = regulator_map_voltage_linear_range,
28	.get_voltage_sel = regulator_get_voltage_sel_regmap,
29	.set_voltage_sel = regulator_set_voltage_sel_regmap,
30	.enable = regulator_enable_regmap,
31	.disable = regulator_disable_regmap,
32	.is_enabled = regulator_is_enabled_regmap,
33};
34
35static const struct linear_range sky81452_reg_ranges[] = {
36	REGULATOR_LINEAR_RANGE(4500000, 0, 14, 250000),
37	REGULATOR_LINEAR_RANGE(9000000, 15, 31, 1000000),
38};
39
40static const struct regulator_desc sky81452_reg = {
41	.name = "LOUT",
42	.of_match = of_match_ptr("lout"),
43	.regulators_node = of_match_ptr("regulator"),
44	.ops = &sky81452_reg_ops,
45	.type = REGULATOR_VOLTAGE,
46	.owner = THIS_MODULE,
47	.n_voltages = SKY81452_LOUT + 1,
48	.linear_ranges = sky81452_reg_ranges,
49	.n_linear_ranges = ARRAY_SIZE(sky81452_reg_ranges),
50	.vsel_reg = SKY81452_REG3,
51	.vsel_mask = SKY81452_LOUT,
52	.enable_reg = SKY81452_REG1,
53	.enable_mask = SKY81452_LEN,
54};
55
56static int sky81452_reg_probe(struct platform_device *pdev)
57{
58	struct device *dev = &pdev->dev;
59	const struct regulator_init_data *init_data = dev_get_platdata(dev);
60	struct regulator_config config = { };
61	struct regulator_dev *rdev;
62
63	config.dev = dev->parent;
64	config.init_data = init_data;
65	config.of_node = dev->of_node;
66	config.regmap = dev_get_drvdata(dev->parent);
67
68	rdev = devm_regulator_register(dev, &sky81452_reg, &config);
69	if (IS_ERR(rdev)) {
70		dev_err(dev, "failed to register. err=%ld\n", PTR_ERR(rdev));
71		return PTR_ERR(rdev);
72	}
73
74	platform_set_drvdata(pdev, rdev);
75
76	return 0;
77}
78
79static struct platform_driver sky81452_reg_driver = {
80	.driver = {
81		.name = "sky81452-regulator",
82		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
83	},
84	.probe = sky81452_reg_probe,
85};
86
87module_platform_driver(sky81452_reg_driver);
88
89MODULE_DESCRIPTION("Skyworks SKY81452 Regulator driver");
90MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>");
91MODULE_LICENSE("GPL v2");
v4.10.11
  1/*
  2 * sky81452-regulator.c	SKY81452 regulator driver
  3 *
  4 * Copyright 2014 Skyworks Solutions Inc.
  5 * Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>
  6 *
  7 * This program is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU General Public License version 2
  9 * as published by the Free Software Foundation.
 10 *
 11 * This program is distributed in the hope that it will be useful, but
 12 * WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14 * General Public License for more details.
 15 *
 16 * You should have received a copy of the GNU General Public License along
 17 * with this program; if not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20#include <linux/module.h>
 21#include <linux/kernel.h>
 22#include <linux/platform_device.h>
 23#include <linux/init.h>
 24#include <linux/err.h>
 25#include <linux/of.h>
 26#include <linux/regulator/driver.h>
 27#include <linux/regulator/of_regulator.h>
 28
 29/* registers */
 30#define SKY81452_REG1	0x01
 31#define SKY81452_REG3	0x03
 32
 33/* bit mask */
 34#define SKY81452_LEN	0x40
 35#define SKY81452_LOUT	0x1F
 36
 37static struct regulator_ops sky81452_reg_ops = {
 38	.list_voltage = regulator_list_voltage_linear_range,
 39	.map_voltage = regulator_map_voltage_linear_range,
 40	.get_voltage_sel = regulator_get_voltage_sel_regmap,
 41	.set_voltage_sel = regulator_set_voltage_sel_regmap,
 42	.enable = regulator_enable_regmap,
 43	.disable = regulator_disable_regmap,
 44	.is_enabled = regulator_is_enabled_regmap,
 45};
 46
 47static const struct regulator_linear_range sky81452_reg_ranges[] = {
 48	REGULATOR_LINEAR_RANGE(4500000, 0, 14, 250000),
 49	REGULATOR_LINEAR_RANGE(9000000, 15, 31, 1000000),
 50};
 51
 52static const struct regulator_desc sky81452_reg = {
 53	.name = "LOUT",
 54	.of_match = of_match_ptr("lout"),
 55	.regulators_node = of_match_ptr("regulator"),
 56	.ops = &sky81452_reg_ops,
 57	.type = REGULATOR_VOLTAGE,
 58	.owner = THIS_MODULE,
 59	.n_voltages = SKY81452_LOUT + 1,
 60	.linear_ranges = sky81452_reg_ranges,
 61	.n_linear_ranges = ARRAY_SIZE(sky81452_reg_ranges),
 62	.vsel_reg = SKY81452_REG3,
 63	.vsel_mask = SKY81452_LOUT,
 64	.enable_reg = SKY81452_REG1,
 65	.enable_mask = SKY81452_LEN,
 66};
 67
 68static int sky81452_reg_probe(struct platform_device *pdev)
 69{
 70	struct device *dev = &pdev->dev;
 71	const struct regulator_init_data *init_data = dev_get_platdata(dev);
 72	struct regulator_config config = { };
 73	struct regulator_dev *rdev;
 74
 75	config.dev = dev->parent;
 76	config.init_data = init_data;
 77	config.of_node = dev->of_node;
 78	config.regmap = dev_get_drvdata(dev->parent);
 79
 80	rdev = devm_regulator_register(dev, &sky81452_reg, &config);
 81	if (IS_ERR(rdev)) {
 82		dev_err(dev, "failed to register. err=%ld\n", PTR_ERR(rdev));
 83		return PTR_ERR(rdev);
 84	}
 85
 86	platform_set_drvdata(pdev, rdev);
 87
 88	return 0;
 89}
 90
 91static struct platform_driver sky81452_reg_driver = {
 92	.driver = {
 93		.name = "sky81452-regulator",
 
 94	},
 95	.probe = sky81452_reg_probe,
 96};
 97
 98module_platform_driver(sky81452_reg_driver);
 99
100MODULE_DESCRIPTION("Skyworks SKY81452 Regulator driver");
101MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>");
102MODULE_LICENSE("GPL v2");