Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Regulator driver for STw4810/STw4811 VMMC regulator.
  4 *
  5 * Copyright (C) 2013 ST-Ericsson SA
  6 * Written on behalf of Linaro for ST-Ericsson
  7 *
  8 * Author: Linus Walleij <linus.walleij@linaro.org>
 
 
  9 */
 10
 11#include <linux/err.h>
 12#include <linux/init.h>
 13#include <linux/mfd/stw481x.h>
 14#include <linux/module.h>
 15#include <linux/platform_device.h>
 16#include <linux/regulator/driver.h>
 17#include <linux/regulator/of_regulator.h>
 18
 19static const unsigned int stw481x_vmmc_voltages[] = {
 20	1800000,
 21	1800000,
 22	2850000,
 23	3000000,
 24	1850000,
 25	2600000,
 26	2700000,
 27	3300000,
 28};
 29
 30static const struct regulator_ops stw481x_vmmc_ops = {
 31	.list_voltage = regulator_list_voltage_table,
 32	.enable      = regulator_enable_regmap,
 33	.disable     = regulator_disable_regmap,
 34	.is_enabled  = regulator_is_enabled_regmap,
 35	.get_voltage_sel = regulator_get_voltage_sel_regmap,
 36	.set_voltage_sel = regulator_set_voltage_sel_regmap,
 37};
 38
 39static const struct regulator_desc vmmc_regulator = {
 40	.name = "VMMC",
 41	.id   = 0,
 42	.ops  = &stw481x_vmmc_ops,
 43	.type = REGULATOR_VOLTAGE,
 44	.owner = THIS_MODULE,
 45	.n_voltages = ARRAY_SIZE(stw481x_vmmc_voltages),
 46	.volt_table = stw481x_vmmc_voltages,
 47	.enable_time = 200, /* FIXME: look this up */
 48	.enable_reg = STW_CONF1,
 49	.enable_mask = STW_CONF1_PDN_VMMC | STW_CONF1_MMC_LS_STATUS,
 50	.enable_val = STW_CONF1_PDN_VMMC,
 51	.vsel_reg = STW_CONF1,
 52	.vsel_mask = STW_CONF1_VMMC_MASK,
 53};
 54
 55static int stw481x_vmmc_regulator_probe(struct platform_device *pdev)
 56{
 57	struct stw481x *stw481x = dev_get_platdata(&pdev->dev);
 58	struct regulator_config config = { };
 59	struct regulator_dev *rdev;
 60	int ret;
 61
 62	/* First disable the external VMMC if it's active */
 63	ret = regmap_update_bits(stw481x->map, STW_CONF2,
 64				 STW_CONF2_VMMC_EXT, 0);
 65	if (ret) {
 66		dev_err(&pdev->dev, "could not disable external VMMC\n");
 67		return ret;
 68	}
 69
 70	/* Register VMMC regulator */
 71	config.dev = &pdev->dev;
 72	config.driver_data = stw481x;
 73	config.regmap = stw481x->map;
 74	config.of_node = pdev->dev.of_node;
 75	config.init_data = of_get_regulator_init_data(&pdev->dev,
 76						      pdev->dev.of_node,
 77						      &vmmc_regulator);
 78
 79	rdev = devm_regulator_register(&pdev->dev, &vmmc_regulator, &config);
 80	if (IS_ERR(rdev)) {
 81		dev_err(&pdev->dev,
 82			"error initializing STw481x VMMC regulator\n");
 83		return PTR_ERR(rdev);
 84	}
 85
 86	dev_info(&pdev->dev, "initialized STw481x VMMC regulator\n");
 87	return 0;
 88}
 89
 90static const struct of_device_id stw481x_vmmc_match[] = {
 91	{ .compatible = "st,stw481x-vmmc", },
 92	{},
 93};
 94
 95static struct platform_driver stw481x_vmmc_regulator_driver = {
 96	.driver = {
 97		.name  = "stw481x-vmmc-regulator",
 98		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
 99		.of_match_table = stw481x_vmmc_match,
100	},
101	.probe = stw481x_vmmc_regulator_probe,
102};
103
104module_platform_driver(stw481x_vmmc_regulator_driver);
v4.10.11
 
  1/*
  2 * Regulator driver for STw4810/STw4811 VMMC regulator.
  3 *
  4 * Copyright (C) 2013 ST-Ericsson SA
  5 * Written on behalf of Linaro for ST-Ericsson
  6 *
  7 * Author: Linus Walleij <linus.walleij@linaro.org>
  8 *
  9 * License terms: GNU General Public License (GPL) version 2
 10 */
 11
 12#include <linux/err.h>
 13#include <linux/init.h>
 14#include <linux/mfd/stw481x.h>
 15#include <linux/module.h>
 16#include <linux/platform_device.h>
 17#include <linux/regulator/driver.h>
 18#include <linux/regulator/of_regulator.h>
 19
 20static const unsigned int stw481x_vmmc_voltages[] = {
 21	1800000,
 22	1800000,
 23	2850000,
 24	3000000,
 25	1850000,
 26	2600000,
 27	2700000,
 28	3300000,
 29};
 30
 31static struct regulator_ops stw481x_vmmc_ops = {
 32	.list_voltage = regulator_list_voltage_table,
 33	.enable      = regulator_enable_regmap,
 34	.disable     = regulator_disable_regmap,
 35	.is_enabled  = regulator_is_enabled_regmap,
 36	.get_voltage_sel = regulator_get_voltage_sel_regmap,
 37	.set_voltage_sel = regulator_set_voltage_sel_regmap,
 38};
 39
 40static struct regulator_desc vmmc_regulator = {
 41	.name = "VMMC",
 42	.id   = 0,
 43	.ops  = &stw481x_vmmc_ops,
 44	.type = REGULATOR_VOLTAGE,
 45	.owner = THIS_MODULE,
 46	.n_voltages = ARRAY_SIZE(stw481x_vmmc_voltages),
 47	.volt_table = stw481x_vmmc_voltages,
 48	.enable_time = 200, /* FIXME: look this up */
 49	.enable_reg = STW_CONF1,
 50	.enable_mask = STW_CONF1_PDN_VMMC | STW_CONF1_MMC_LS_STATUS,
 51	.enable_val = STW_CONF1_PDN_VMMC,
 52	.vsel_reg = STW_CONF1,
 53	.vsel_mask = STW_CONF1_VMMC_MASK,
 54};
 55
 56static int stw481x_vmmc_regulator_probe(struct platform_device *pdev)
 57{
 58	struct stw481x *stw481x = dev_get_platdata(&pdev->dev);
 59	struct regulator_config config = { };
 60	struct regulator_dev *rdev;
 61	int ret;
 62
 63	/* First disable the external VMMC if it's active */
 64	ret = regmap_update_bits(stw481x->map, STW_CONF2,
 65				 STW_CONF2_VMMC_EXT, 0);
 66	if (ret) {
 67		dev_err(&pdev->dev, "could not disable external VMMC\n");
 68		return ret;
 69	}
 70
 71	/* Register VMMC regulator */
 72	config.dev = &pdev->dev;
 73	config.driver_data = stw481x;
 74	config.regmap = stw481x->map;
 75	config.of_node = pdev->dev.of_node;
 76	config.init_data = of_get_regulator_init_data(&pdev->dev,
 77						      pdev->dev.of_node,
 78						      &vmmc_regulator);
 79
 80	rdev = devm_regulator_register(&pdev->dev, &vmmc_regulator, &config);
 81	if (IS_ERR(rdev)) {
 82		dev_err(&pdev->dev,
 83			"error initializing STw481x VMMC regulator\n");
 84		return PTR_ERR(rdev);
 85	}
 86
 87	dev_info(&pdev->dev, "initialized STw481x VMMC regulator\n");
 88	return 0;
 89}
 90
 91static const struct of_device_id stw481x_vmmc_match[] = {
 92	{ .compatible = "st,stw481x-vmmc", },
 93	{},
 94};
 95
 96static struct platform_driver stw481x_vmmc_regulator_driver = {
 97	.driver = {
 98		.name  = "stw481x-vmmc-regulator",
 
 99		.of_match_table = stw481x_vmmc_match,
100	},
101	.probe = stw481x_vmmc_regulator_probe,
102};
103
104module_platform_driver(stw481x_vmmc_regulator_driver);