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