1af873fceSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
23615a34eSLinus Walleij /*
33615a34eSLinus Walleij * Regulator driver for STw4810/STw4811 VMMC regulator.
43615a34eSLinus Walleij *
53615a34eSLinus Walleij * Copyright (C) 2013 ST-Ericsson SA
63615a34eSLinus Walleij * Written on behalf of Linaro for ST-Ericsson
73615a34eSLinus Walleij *
83615a34eSLinus Walleij * Author: Linus Walleij <linus.walleij@linaro.org>
93615a34eSLinus Walleij */
103615a34eSLinus Walleij
113615a34eSLinus Walleij #include <linux/err.h>
123615a34eSLinus Walleij #include <linux/init.h>
133615a34eSLinus Walleij #include <linux/mfd/stw481x.h>
143615a34eSLinus Walleij #include <linux/module.h>
153615a34eSLinus Walleij #include <linux/platform_device.h>
163615a34eSLinus Walleij #include <linux/regulator/driver.h>
173615a34eSLinus Walleij #include <linux/regulator/of_regulator.h>
183615a34eSLinus Walleij
193615a34eSLinus Walleij static const unsigned int stw481x_vmmc_voltages[] = {
203615a34eSLinus Walleij 1800000,
213615a34eSLinus Walleij 1800000,
223615a34eSLinus Walleij 2850000,
233615a34eSLinus Walleij 3000000,
243615a34eSLinus Walleij 1850000,
253615a34eSLinus Walleij 2600000,
263615a34eSLinus Walleij 2700000,
273615a34eSLinus Walleij 3300000,
283615a34eSLinus Walleij };
293615a34eSLinus Walleij
309032693eSRikard Falkeborn static const struct regulator_ops stw481x_vmmc_ops = {
313615a34eSLinus Walleij .list_voltage = regulator_list_voltage_table,
323615a34eSLinus Walleij .enable = regulator_enable_regmap,
333615a34eSLinus Walleij .disable = regulator_disable_regmap,
343615a34eSLinus Walleij .is_enabled = regulator_is_enabled_regmap,
353615a34eSLinus Walleij .get_voltage_sel = regulator_get_voltage_sel_regmap,
363615a34eSLinus Walleij .set_voltage_sel = regulator_set_voltage_sel_regmap,
373615a34eSLinus Walleij };
383615a34eSLinus Walleij
399032693eSRikard Falkeborn static const struct regulator_desc vmmc_regulator = {
403615a34eSLinus Walleij .name = "VMMC",
413615a34eSLinus Walleij .id = 0,
423615a34eSLinus Walleij .ops = &stw481x_vmmc_ops,
433615a34eSLinus Walleij .type = REGULATOR_VOLTAGE,
443615a34eSLinus Walleij .owner = THIS_MODULE,
453615a34eSLinus Walleij .n_voltages = ARRAY_SIZE(stw481x_vmmc_voltages),
463615a34eSLinus Walleij .volt_table = stw481x_vmmc_voltages,
473615a34eSLinus Walleij .enable_time = 200, /* FIXME: look this up */
483615a34eSLinus Walleij .enable_reg = STW_CONF1,
49295070e9SLinus Walleij .enable_mask = STW_CONF1_PDN_VMMC | STW_CONF1_MMC_LS_STATUS,
50295070e9SLinus Walleij .enable_val = STW_CONF1_PDN_VMMC,
513615a34eSLinus Walleij .vsel_reg = STW_CONF1,
523615a34eSLinus Walleij .vsel_mask = STW_CONF1_VMMC_MASK,
533615a34eSLinus Walleij };
543615a34eSLinus Walleij
stw481x_vmmc_regulator_probe(struct platform_device * pdev)553615a34eSLinus Walleij static int stw481x_vmmc_regulator_probe(struct platform_device *pdev)
563615a34eSLinus Walleij {
573615a34eSLinus Walleij struct stw481x *stw481x = dev_get_platdata(&pdev->dev);
583615a34eSLinus Walleij struct regulator_config config = { };
5914aef291SAxel Lin struct regulator_dev *rdev;
603615a34eSLinus Walleij int ret;
613615a34eSLinus Walleij
623615a34eSLinus Walleij /* First disable the external VMMC if it's active */
633615a34eSLinus Walleij ret = regmap_update_bits(stw481x->map, STW_CONF2,
643615a34eSLinus Walleij STW_CONF2_VMMC_EXT, 0);
653615a34eSLinus Walleij if (ret) {
663615a34eSLinus Walleij dev_err(&pdev->dev, "could not disable external VMMC\n");
673615a34eSLinus Walleij return ret;
683615a34eSLinus Walleij }
693615a34eSLinus Walleij
703615a34eSLinus Walleij /* Register VMMC regulator */
713615a34eSLinus Walleij config.dev = &pdev->dev;
723615a34eSLinus Walleij config.driver_data = stw481x;
733615a34eSLinus Walleij config.regmap = stw481x->map;
743615a34eSLinus Walleij config.of_node = pdev->dev.of_node;
753615a34eSLinus Walleij config.init_data = of_get_regulator_init_data(&pdev->dev,
76072e78b1SJavier Martinez Canillas pdev->dev.of_node,
77072e78b1SJavier Martinez Canillas &vmmc_regulator);
783615a34eSLinus Walleij
7914aef291SAxel Lin rdev = devm_regulator_register(&pdev->dev, &vmmc_regulator, &config);
8014aef291SAxel Lin if (IS_ERR(rdev)) {
813615a34eSLinus Walleij dev_err(&pdev->dev,
823615a34eSLinus Walleij "error initializing STw481x VMMC regulator\n");
8314aef291SAxel Lin return PTR_ERR(rdev);
843615a34eSLinus Walleij }
853615a34eSLinus Walleij
863615a34eSLinus Walleij dev_info(&pdev->dev, "initialized STw481x VMMC regulator\n");
873615a34eSLinus Walleij return 0;
883615a34eSLinus Walleij }
893615a34eSLinus Walleij
903615a34eSLinus Walleij static const struct of_device_id stw481x_vmmc_match[] = {
913615a34eSLinus Walleij { .compatible = "st,stw481x-vmmc", },
923615a34eSLinus Walleij {},
933615a34eSLinus Walleij };
943615a34eSLinus Walleij
953615a34eSLinus Walleij static struct platform_driver stw481x_vmmc_regulator_driver = {
963615a34eSLinus Walleij .driver = {
973615a34eSLinus Walleij .name = "stw481x-vmmc-regulator",
98259b93b2SDouglas Anderson .probe_type = PROBE_PREFER_ASYNCHRONOUS,
9918dca93eSAxel Lin .of_match_table = stw481x_vmmc_match,
1003615a34eSLinus Walleij },
1013615a34eSLinus Walleij .probe = stw481x_vmmc_regulator_probe,
1023615a34eSLinus Walleij };
1033615a34eSLinus Walleij
1043615a34eSLinus Walleij module_platform_driver(stw481x_vmmc_regulator_driver);
105