2 * sky81452-regulator.c SKY81452 regulator driver
4 * Copyright 2014 Skyworks Solutions Inc.
5 * Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/platform_device.h>
24 #include <linux/init.h>
25 #include <linux/err.h>
27 #include <linux/regulator/driver.h>
28 #include <linux/regulator/of_regulator.h>
31 #define SKY81452_REG1 0x01
32 #define SKY81452_REG3 0x03
35 #define SKY81452_LEN 0x40
36 #define SKY81452_LOUT 0x1F
38 static struct regulator_ops sky81452_reg_ops
= {
39 .list_voltage
= regulator_list_voltage_linear_range
,
40 .map_voltage
= regulator_map_voltage_linear_range
,
41 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
42 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
43 .enable
= regulator_enable_regmap
,
44 .disable
= regulator_disable_regmap
,
45 .is_enabled
= regulator_is_enabled_regmap
,
48 static const struct regulator_linear_range sky81452_reg_ranges
[] = {
49 REGULATOR_LINEAR_RANGE(4500000, 0, 14, 250000),
50 REGULATOR_LINEAR_RANGE(9000000, 15, 31, 1000000),
53 static const struct regulator_desc sky81452_reg
= {
55 .ops
= &sky81452_reg_ops
,
56 .type
= REGULATOR_VOLTAGE
,
58 .n_voltages
= SKY81452_LOUT
+ 1,
59 .linear_ranges
= sky81452_reg_ranges
,
60 .n_linear_ranges
= ARRAY_SIZE(sky81452_reg_ranges
),
61 .vsel_reg
= SKY81452_REG3
,
62 .vsel_mask
= SKY81452_LOUT
,
63 .enable_reg
= SKY81452_REG1
,
64 .enable_mask
= SKY81452_LEN
,
68 static struct regulator_init_data
*sky81452_reg_parse_dt(struct device
*dev
)
70 struct regulator_init_data
*init_data
;
71 struct device_node
*np
;
73 np
= of_get_child_by_name(dev
->parent
->of_node
, "regulator");
75 dev_err(dev
, "regulator node not found");
79 init_data
= of_get_regulator_init_data(dev
, np
);
85 static struct regulator_init_data
*sky81452_reg_parse_dt(struct device
*dev
)
87 return ERR_PTR(-EINVAL
);
91 static int sky81452_reg_probe(struct platform_device
*pdev
)
93 struct device
*dev
= &pdev
->dev
;
94 const struct regulator_init_data
*init_data
= dev_get_platdata(dev
);
95 struct regulator_config config
= { };
96 struct regulator_dev
*rdev
;
99 init_data
= sky81452_reg_parse_dt(dev
);
100 if (IS_ERR(init_data
))
101 return PTR_ERR(init_data
);
105 config
.init_data
= init_data
;
106 config
.of_node
= dev
->of_node
;
107 config
.regmap
= dev_get_drvdata(dev
->parent
);
109 rdev
= devm_regulator_register(dev
, &sky81452_reg
, &config
);
111 return PTR_ERR(rdev
);
113 platform_set_drvdata(pdev
, rdev
);
118 static struct platform_driver sky81452_reg_driver
= {
120 .name
= "sky81452-regulator",
122 .probe
= sky81452_reg_probe
,
125 module_platform_driver(sky81452_reg_driver
);
127 MODULE_DESCRIPTION("Skyworks SKY81452 Regulator driver");
128 MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>");
129 MODULE_LICENSE("GPL");
130 MODULE_VERSION("1.0");