18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci// 38c2ecf20Sopenharmony_ci// sky81452-regulator.c SKY81452 regulator driver 48c2ecf20Sopenharmony_ci// 58c2ecf20Sopenharmony_ci// Copyright 2014 Skyworks Solutions Inc. 68c2ecf20Sopenharmony_ci// Author : Gyungoh Yoo <jack.yoo@skyworksinc.com> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/module.h> 98c2ecf20Sopenharmony_ci#include <linux/kernel.h> 108c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 118c2ecf20Sopenharmony_ci#include <linux/init.h> 128c2ecf20Sopenharmony_ci#include <linux/err.h> 138c2ecf20Sopenharmony_ci#include <linux/of.h> 148c2ecf20Sopenharmony_ci#include <linux/regulator/driver.h> 158c2ecf20Sopenharmony_ci#include <linux/regulator/of_regulator.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* registers */ 188c2ecf20Sopenharmony_ci#define SKY81452_REG1 0x01 198c2ecf20Sopenharmony_ci#define SKY81452_REG3 0x03 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/* bit mask */ 228c2ecf20Sopenharmony_ci#define SKY81452_LEN 0x40 238c2ecf20Sopenharmony_ci#define SKY81452_LOUT 0x1F 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistatic const struct regulator_ops sky81452_reg_ops = { 268c2ecf20Sopenharmony_ci .list_voltage = regulator_list_voltage_linear_range, 278c2ecf20Sopenharmony_ci .map_voltage = regulator_map_voltage_linear_range, 288c2ecf20Sopenharmony_ci .get_voltage_sel = regulator_get_voltage_sel_regmap, 298c2ecf20Sopenharmony_ci .set_voltage_sel = regulator_set_voltage_sel_regmap, 308c2ecf20Sopenharmony_ci .enable = regulator_enable_regmap, 318c2ecf20Sopenharmony_ci .disable = regulator_disable_regmap, 328c2ecf20Sopenharmony_ci .is_enabled = regulator_is_enabled_regmap, 338c2ecf20Sopenharmony_ci}; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cistatic const struct linear_range sky81452_reg_ranges[] = { 368c2ecf20Sopenharmony_ci REGULATOR_LINEAR_RANGE(4500000, 0, 14, 250000), 378c2ecf20Sopenharmony_ci REGULATOR_LINEAR_RANGE(9000000, 15, 31, 1000000), 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistatic const struct regulator_desc sky81452_reg = { 418c2ecf20Sopenharmony_ci .name = "LOUT", 428c2ecf20Sopenharmony_ci .of_match = of_match_ptr("lout"), 438c2ecf20Sopenharmony_ci .regulators_node = of_match_ptr("regulator"), 448c2ecf20Sopenharmony_ci .ops = &sky81452_reg_ops, 458c2ecf20Sopenharmony_ci .type = REGULATOR_VOLTAGE, 468c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 478c2ecf20Sopenharmony_ci .n_voltages = SKY81452_LOUT + 1, 488c2ecf20Sopenharmony_ci .linear_ranges = sky81452_reg_ranges, 498c2ecf20Sopenharmony_ci .n_linear_ranges = ARRAY_SIZE(sky81452_reg_ranges), 508c2ecf20Sopenharmony_ci .vsel_reg = SKY81452_REG3, 518c2ecf20Sopenharmony_ci .vsel_mask = SKY81452_LOUT, 528c2ecf20Sopenharmony_ci .enable_reg = SKY81452_REG1, 538c2ecf20Sopenharmony_ci .enable_mask = SKY81452_LEN, 548c2ecf20Sopenharmony_ci}; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic int sky81452_reg_probe(struct platform_device *pdev) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 598c2ecf20Sopenharmony_ci const struct regulator_init_data *init_data = dev_get_platdata(dev); 608c2ecf20Sopenharmony_ci struct regulator_config config = { }; 618c2ecf20Sopenharmony_ci struct regulator_dev *rdev; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci config.dev = dev->parent; 648c2ecf20Sopenharmony_ci config.init_data = init_data; 658c2ecf20Sopenharmony_ci config.of_node = dev->of_node; 668c2ecf20Sopenharmony_ci config.regmap = dev_get_drvdata(dev->parent); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci rdev = devm_regulator_register(dev, &sky81452_reg, &config); 698c2ecf20Sopenharmony_ci if (IS_ERR(rdev)) { 708c2ecf20Sopenharmony_ci dev_err(dev, "failed to register. err=%ld\n", PTR_ERR(rdev)); 718c2ecf20Sopenharmony_ci return PTR_ERR(rdev); 728c2ecf20Sopenharmony_ci } 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, rdev); 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci return 0; 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic struct platform_driver sky81452_reg_driver = { 808c2ecf20Sopenharmony_ci .driver = { 818c2ecf20Sopenharmony_ci .name = "sky81452-regulator", 828c2ecf20Sopenharmony_ci }, 838c2ecf20Sopenharmony_ci .probe = sky81452_reg_probe, 848c2ecf20Sopenharmony_ci}; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cimodule_platform_driver(sky81452_reg_driver); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Skyworks SKY81452 Regulator driver"); 898c2ecf20Sopenharmony_ciMODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>"); 908c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 91