blob: 37658affe072de82affce1d68ee7a6e0ca6e5063 [file] [log] [blame]
Axel Linfb9bf5c2019-04-20 15:20:01 +08001// 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>
Gyungoh Yoo9839d622014-08-08 18:10:22 +09007
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
Axel Linc7e3ddd2019-04-20 15:20:00 +080025static const struct regulator_ops sky81452_reg_ops = {
Gyungoh Yoo9839d622014-08-08 18:10:22 +090026 .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
Matti Vaittinen60ab7f42020-05-08 18:43:36 +030035static const struct linear_range sky81452_reg_ranges[] = {
Gyungoh Yoo9839d622014-08-08 18:10:22 +090036 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",
Gyungoh Yoo586b1512014-12-02 17:05:28 +090042 .of_match = of_match_ptr("lout"),
43 .regulators_node = of_match_ptr("regulator"),
Gyungoh Yoo9839d622014-08-08 18:10:22 +090044 .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
Gyungoh Yoo9839d622014-08-08 18:10:22 +090056static 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
Gyungoh Yoo586b1512014-12-02 17:05:28 +090063 config.dev = dev->parent;
Gyungoh Yoo9839d622014-08-08 18:10:22 +090064 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);
Gyungoh Yoo586b1512014-12-02 17:05:28 +090069 if (IS_ERR(rdev)) {
70 dev_err(dev, "failed to register. err=%ld\n", PTR_ERR(rdev));
Gyungoh Yoo9839d622014-08-08 18:10:22 +090071 return PTR_ERR(rdev);
Gyungoh Yoo586b1512014-12-02 17:05:28 +090072 }
Gyungoh Yoo9839d622014-08-08 18:10:22 +090073
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 },
83 .probe = sky81452_reg_probe,
84};
85
86module_platform_driver(sky81452_reg_driver);
87
88MODULE_DESCRIPTION("Skyworks SKY81452 Regulator driver");
89MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>");
Gyungoh Yoo586b1512014-12-02 17:05:28 +090090MODULE_LICENSE("GPL v2");