162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci// 362306a36Sopenharmony_ci// sky81452-regulator.c SKY81452 regulator driver 462306a36Sopenharmony_ci// 562306a36Sopenharmony_ci// Copyright 2014 Skyworks Solutions Inc. 662306a36Sopenharmony_ci// Author : Gyungoh Yoo <jack.yoo@skyworksinc.com> 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include <linux/module.h> 962306a36Sopenharmony_ci#include <linux/kernel.h> 1062306a36Sopenharmony_ci#include <linux/platform_device.h> 1162306a36Sopenharmony_ci#include <linux/init.h> 1262306a36Sopenharmony_ci#include <linux/err.h> 1362306a36Sopenharmony_ci#include <linux/of.h> 1462306a36Sopenharmony_ci#include <linux/regulator/driver.h> 1562306a36Sopenharmony_ci#include <linux/regulator/of_regulator.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci/* registers */ 1862306a36Sopenharmony_ci#define SKY81452_REG1 0x01 1962306a36Sopenharmony_ci#define SKY81452_REG3 0x03 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci/* bit mask */ 2262306a36Sopenharmony_ci#define SKY81452_LEN 0x40 2362306a36Sopenharmony_ci#define SKY81452_LOUT 0x1F 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cistatic const struct regulator_ops sky81452_reg_ops = { 2662306a36Sopenharmony_ci .list_voltage = regulator_list_voltage_linear_range, 2762306a36Sopenharmony_ci .map_voltage = regulator_map_voltage_linear_range, 2862306a36Sopenharmony_ci .get_voltage_sel = regulator_get_voltage_sel_regmap, 2962306a36Sopenharmony_ci .set_voltage_sel = regulator_set_voltage_sel_regmap, 3062306a36Sopenharmony_ci .enable = regulator_enable_regmap, 3162306a36Sopenharmony_ci .disable = regulator_disable_regmap, 3262306a36Sopenharmony_ci .is_enabled = regulator_is_enabled_regmap, 3362306a36Sopenharmony_ci}; 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_cistatic const struct linear_range sky81452_reg_ranges[] = { 3662306a36Sopenharmony_ci REGULATOR_LINEAR_RANGE(4500000, 0, 14, 250000), 3762306a36Sopenharmony_ci REGULATOR_LINEAR_RANGE(9000000, 15, 31, 1000000), 3862306a36Sopenharmony_ci}; 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_cistatic const struct regulator_desc sky81452_reg = { 4162306a36Sopenharmony_ci .name = "LOUT", 4262306a36Sopenharmony_ci .of_match = of_match_ptr("lout"), 4362306a36Sopenharmony_ci .regulators_node = of_match_ptr("regulator"), 4462306a36Sopenharmony_ci .ops = &sky81452_reg_ops, 4562306a36Sopenharmony_ci .type = REGULATOR_VOLTAGE, 4662306a36Sopenharmony_ci .owner = THIS_MODULE, 4762306a36Sopenharmony_ci .n_voltages = SKY81452_LOUT + 1, 4862306a36Sopenharmony_ci .linear_ranges = sky81452_reg_ranges, 4962306a36Sopenharmony_ci .n_linear_ranges = ARRAY_SIZE(sky81452_reg_ranges), 5062306a36Sopenharmony_ci .vsel_reg = SKY81452_REG3, 5162306a36Sopenharmony_ci .vsel_mask = SKY81452_LOUT, 5262306a36Sopenharmony_ci .enable_reg = SKY81452_REG1, 5362306a36Sopenharmony_ci .enable_mask = SKY81452_LEN, 5462306a36Sopenharmony_ci}; 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_cistatic int sky81452_reg_probe(struct platform_device *pdev) 5762306a36Sopenharmony_ci{ 5862306a36Sopenharmony_ci struct device *dev = &pdev->dev; 5962306a36Sopenharmony_ci const struct regulator_init_data *init_data = dev_get_platdata(dev); 6062306a36Sopenharmony_ci struct regulator_config config = { }; 6162306a36Sopenharmony_ci struct regulator_dev *rdev; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci config.dev = dev->parent; 6462306a36Sopenharmony_ci config.init_data = init_data; 6562306a36Sopenharmony_ci config.of_node = dev->of_node; 6662306a36Sopenharmony_ci config.regmap = dev_get_drvdata(dev->parent); 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci rdev = devm_regulator_register(dev, &sky81452_reg, &config); 6962306a36Sopenharmony_ci if (IS_ERR(rdev)) { 7062306a36Sopenharmony_ci dev_err(dev, "failed to register. err=%ld\n", PTR_ERR(rdev)); 7162306a36Sopenharmony_ci return PTR_ERR(rdev); 7262306a36Sopenharmony_ci } 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci platform_set_drvdata(pdev, rdev); 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci return 0; 7762306a36Sopenharmony_ci} 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_cistatic struct platform_driver sky81452_reg_driver = { 8062306a36Sopenharmony_ci .driver = { 8162306a36Sopenharmony_ci .name = "sky81452-regulator", 8262306a36Sopenharmony_ci .probe_type = PROBE_PREFER_ASYNCHRONOUS, 8362306a36Sopenharmony_ci }, 8462306a36Sopenharmony_ci .probe = sky81452_reg_probe, 8562306a36Sopenharmony_ci}; 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_cimodule_platform_driver(sky81452_reg_driver); 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciMODULE_DESCRIPTION("Skyworks SKY81452 Regulator driver"); 9062306a36Sopenharmony_ciMODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>"); 9162306a36Sopenharmony_ciMODULE_LICENSE("GPL v2"); 92