Skip to content

Commit 65bae54

Browse files
wensbroonie
authored andcommitted
regulator: mt6358: Merge VCN33_* regulators
The VCN33_BT and VCN33_WIFI regulators are actually the same regulator, having the same voltage setting and output pin. There are simply two enable bits that are ORed together to enable the regulator. Having two regulators representing the same output pin is misleading from a design matching standpoint, and also error-prone in driver implementations. If consumers try to set different voltages on either regulator, the one set later would override the one set before. There are ways around this, such as chaining them together and having the downstream one act as a switch. But given there's only one output pin, such a workaround doesn't match reality. Remove the VCN33_WIFI regulator. During the probe phase, have the driver sync the enable status of VCN33_WIFI to VCN33_BT. Also drop the suffix so that the regulator name matches the pin name in the datasheet. Signed-off-by: Chen-Yu Tsai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 82f305b commit 65bae54

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

drivers/regulator/mt6358-regulator.c

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static const unsigned int vcama_voltages[] = {
277277
2800000, 2900000, 3000000,
278278
};
279279

280-
static const unsigned int vcn33_bt_wifi_voltages[] = {
280+
static const unsigned int vcn33_voltages[] = {
281281
3300000, 3400000, 3500000,
282282
};
283283

@@ -321,7 +321,7 @@ static const u32 vcama_idx[] = {
321321
0, 7, 9, 10, 11, 12,
322322
};
323323

324-
static const u32 vcn33_bt_wifi_idx[] = {
324+
static const u32 vcn33_idx[] = {
325325
1, 2, 3,
326326
};
327327

@@ -566,12 +566,8 @@ static struct mt6358_regulator_info mt6358_regulators[] = {
566566
MT6358_LDO_VCAMA1_CON0, 0, MT6358_VCAMA1_ANA_CON0, 0xf00),
567567
MT6358_LDO("ldo_vemc", VEMC, vmch_vemc_voltages, vmch_vemc_idx,
568568
MT6358_LDO_VEMC_CON0, 0, MT6358_VEMC_ANA_CON0, 0x700),
569-
MT6358_LDO("ldo_vcn33_bt", VCN33_BT, vcn33_bt_wifi_voltages,
570-
vcn33_bt_wifi_idx, MT6358_LDO_VCN33_CON0_0,
571-
0, MT6358_VCN33_ANA_CON0, 0x300),
572-
MT6358_LDO("ldo_vcn33_wifi", VCN33_WIFI, vcn33_bt_wifi_voltages,
573-
vcn33_bt_wifi_idx, MT6358_LDO_VCN33_CON0_1,
574-
0, MT6358_VCN33_ANA_CON0, 0x300),
569+
MT6358_LDO("ldo_vcn33", VCN33, vcn33_voltages, vcn33_idx,
570+
MT6358_LDO_VCN33_CON0_0, 0, MT6358_VCN33_ANA_CON0, 0x300),
575571
MT6358_LDO("ldo_vcama2", VCAMA2, vcama_voltages, vcama_idx,
576572
MT6358_LDO_VCAMA2_CON0, 0, MT6358_VCAMA2_ANA_CON0, 0xf00),
577573
MT6358_LDO("ldo_vmc", VMC, vmc_voltages, vmc_idx,
@@ -662,12 +658,8 @@ static struct mt6358_regulator_info mt6366_regulators[] = {
662658
MT6358_LDO_VMCH_CON0, 0, MT6358_VMCH_ANA_CON0, 0x700),
663659
MT6366_LDO("ldo_vemc", VEMC, vmch_vemc_voltages, vmch_vemc_idx,
664660
MT6358_LDO_VEMC_CON0, 0, MT6358_VEMC_ANA_CON0, 0x700),
665-
MT6366_LDO("ldo_vcn33_bt", VCN33_BT, vcn33_bt_wifi_voltages,
666-
vcn33_bt_wifi_idx, MT6358_LDO_VCN33_CON0_0,
667-
0, MT6358_VCN33_ANA_CON0, 0x300),
668-
MT6366_LDO("ldo_vcn33_wifi", VCN33_WIFI, vcn33_bt_wifi_voltages,
669-
vcn33_bt_wifi_idx, MT6358_LDO_VCN33_CON0_1,
670-
0, MT6358_VCN33_ANA_CON0, 0x300),
661+
MT6366_LDO("ldo_vcn33", VCN33, vcn33_voltages, vcn33_idx,
662+
MT6358_LDO_VCN33_CON0_0, 0, MT6358_VCN33_ANA_CON0, 0x300),
671663
MT6366_LDO("ldo_vmc", VMC, vmc_voltages, vmc_idx,
672664
MT6358_LDO_VMC_CON0, 0, MT6358_VMC_ANA_CON0, 0xf00),
673665
MT6366_LDO("ldo_vsim2", VSIM2, vsim_voltages, vsim_idx,
@@ -690,13 +682,56 @@ static struct mt6358_regulator_info mt6366_regulators[] = {
690682
MT6358_LDO_VSRAM_CON1, 0x7f),
691683
};
692684

685+
static int mt6358_sync_vcn33_setting(struct device *dev)
686+
{
687+
struct mt6397_chip *mt6397 = dev_get_drvdata(dev->parent);
688+
unsigned int val;
689+
int ret;
690+
691+
/*
692+
* VCN33_WIFI and VCN33_BT are two separate enable bits for the same
693+
* regulator. They share the same voltage setting and output pin.
694+
* Instead of having two potentially conflicting regulators, just have
695+
* one VCN33 regulator. Sync the two enable bits and only use one in
696+
* the regulator device.
697+
*/
698+
ret = regmap_read(mt6397->regmap, MT6358_LDO_VCN33_CON0_1, &val);
699+
if (ret) {
700+
dev_err(dev, "Failed to read VCN33_WIFI setting\n");
701+
return ret;
702+
}
703+
704+
if (!(val & BIT(0)))
705+
return 0;
706+
707+
/* Sync VCN33_WIFI enable status to VCN33_BT */
708+
ret = regmap_update_bits(mt6397->regmap, MT6358_LDO_VCN33_CON0_0, BIT(0), BIT(0));
709+
if (ret) {
710+
dev_err(dev, "Failed to sync VCN33_WIFI setting to VCN33_BT\n");
711+
return ret;
712+
}
713+
714+
/* Disable VCN33_WIFI */
715+
ret = regmap_update_bits(mt6397->regmap, MT6358_LDO_VCN33_CON0_1, BIT(0), 0);
716+
if (ret) {
717+
dev_err(dev, "Failed to disable VCN33_BT\n");
718+
return ret;
719+
}
720+
721+
return 0;
722+
}
723+
693724
static int mt6358_regulator_probe(struct platform_device *pdev)
694725
{
695726
struct mt6397_chip *mt6397 = dev_get_drvdata(pdev->dev.parent);
696727
struct regulator_config config = {};
697728
struct regulator_dev *rdev;
698729
struct mt6358_regulator_info *mt6358_info;
699-
int i, max_regulator;
730+
int i, max_regulator, ret;
731+
732+
ret = mt6358_sync_vcn33_setting(&pdev->dev);
733+
if (ret)
734+
return ret;
700735

701736
if (mt6397->chip_id == MT6366_CHIP_ID) {
702737
max_regulator = MT6366_MAX_REGULATOR;

include/linux/regulator/mt6358-regulator.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ enum {
4141
MT6358_ID_VIO28,
4242
MT6358_ID_VA12,
4343
MT6358_ID_VRF18,
44-
MT6358_ID_VCN33_BT,
45-
MT6358_ID_VCN33_WIFI,
44+
MT6358_ID_VCN33,
4645
MT6358_ID_VCAMA2,
4746
MT6358_ID_VMC,
4847
MT6358_ID_VLDO28,
@@ -85,8 +84,7 @@ enum {
8584
MT6366_ID_VIO28,
8685
MT6366_ID_VA12,
8786
MT6366_ID_VRF18,
88-
MT6366_ID_VCN33_BT,
89-
MT6366_ID_VCN33_WIFI,
87+
MT6366_ID_VCN33,
9088
MT6366_ID_VMC,
9189
MT6366_ID_VAUD28,
9290
MT6366_ID_VSIM2,

0 commit comments

Comments
 (0)