1da65e367SBjorn Andersson /* 2da65e367SBjorn Andersson * Copyright (c) 2015, Sony Mobile Communications AB. 3da65e367SBjorn Andersson * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. 4da65e367SBjorn Andersson * 5da65e367SBjorn Andersson * This program is free software; you can redistribute it and/or modify 6da65e367SBjorn Andersson * it under the terms of the GNU General Public License version 2 and 7da65e367SBjorn Andersson * only version 2 as published by the Free Software Foundation. 8da65e367SBjorn Andersson * 9da65e367SBjorn Andersson * This program is distributed in the hope that it will be useful, 10da65e367SBjorn Andersson * but WITHOUT ANY WARRANTY; without even the implied warranty of 11da65e367SBjorn Andersson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12da65e367SBjorn Andersson * GNU General Public License for more details. 13da65e367SBjorn Andersson */ 14da65e367SBjorn Andersson 15da65e367SBjorn Andersson #include <linux/module.h> 16da65e367SBjorn Andersson #include <linux/of.h> 17da65e367SBjorn Andersson #include <linux/of_device.h> 18da65e367SBjorn Andersson #include <linux/platform_device.h> 19da65e367SBjorn Andersson #include <linux/regulator/driver.h> 20da65e367SBjorn Andersson #include <linux/regulator/machine.h> 21da65e367SBjorn Andersson #include <linux/regulator/of_regulator.h> 22da65e367SBjorn Andersson #include <linux/soc/qcom/smd-rpm.h> 23da65e367SBjorn Andersson 24da65e367SBjorn Andersson struct qcom_rpm_reg { 25da65e367SBjorn Andersson struct device *dev; 26da65e367SBjorn Andersson 27da65e367SBjorn Andersson struct qcom_smd_rpm *rpm; 28da65e367SBjorn Andersson 29da65e367SBjorn Andersson u32 type; 30da65e367SBjorn Andersson u32 id; 31da65e367SBjorn Andersson 32da65e367SBjorn Andersson struct regulator_desc desc; 33da65e367SBjorn Andersson 34da65e367SBjorn Andersson int is_enabled; 35da65e367SBjorn Andersson int uV; 36da65e367SBjorn Andersson }; 37da65e367SBjorn Andersson 38da65e367SBjorn Andersson struct rpm_regulator_req { 392c652a98SStephen Boyd __le32 key; 402c652a98SStephen Boyd __le32 nbytes; 412c652a98SStephen Boyd __le32 value; 42da65e367SBjorn Andersson }; 43da65e367SBjorn Andersson 44da65e367SBjorn Andersson #define RPM_KEY_SWEN 0x6e657773 /* "swen" */ 45da65e367SBjorn Andersson #define RPM_KEY_UV 0x00007675 /* "uv" */ 46da65e367SBjorn Andersson #define RPM_KEY_MA 0x0000616d /* "ma" */ 47da65e367SBjorn Andersson 48da65e367SBjorn Andersson static int rpm_reg_write_active(struct qcom_rpm_reg *vreg, 49da65e367SBjorn Andersson struct rpm_regulator_req *req, 50da65e367SBjorn Andersson size_t size) 51da65e367SBjorn Andersson { 52da65e367SBjorn Andersson return qcom_rpm_smd_write(vreg->rpm, 53da65e367SBjorn Andersson QCOM_SMD_RPM_ACTIVE_STATE, 54da65e367SBjorn Andersson vreg->type, 55da65e367SBjorn Andersson vreg->id, 56da65e367SBjorn Andersson req, size); 57da65e367SBjorn Andersson } 58da65e367SBjorn Andersson 59da65e367SBjorn Andersson static int rpm_reg_enable(struct regulator_dev *rdev) 60da65e367SBjorn Andersson { 61da65e367SBjorn Andersson struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); 62da65e367SBjorn Andersson struct rpm_regulator_req req; 63da65e367SBjorn Andersson int ret; 64da65e367SBjorn Andersson 652c652a98SStephen Boyd req.key = cpu_to_le32(RPM_KEY_SWEN); 662c652a98SStephen Boyd req.nbytes = cpu_to_le32(sizeof(u32)); 672c652a98SStephen Boyd req.value = cpu_to_le32(1); 68da65e367SBjorn Andersson 69da65e367SBjorn Andersson ret = rpm_reg_write_active(vreg, &req, sizeof(req)); 70da65e367SBjorn Andersson if (!ret) 71da65e367SBjorn Andersson vreg->is_enabled = 1; 72da65e367SBjorn Andersson 73da65e367SBjorn Andersson return ret; 74da65e367SBjorn Andersson } 75da65e367SBjorn Andersson 76da65e367SBjorn Andersson static int rpm_reg_is_enabled(struct regulator_dev *rdev) 77da65e367SBjorn Andersson { 78da65e367SBjorn Andersson struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); 79da65e367SBjorn Andersson 80da65e367SBjorn Andersson return vreg->is_enabled; 81da65e367SBjorn Andersson } 82da65e367SBjorn Andersson 83da65e367SBjorn Andersson static int rpm_reg_disable(struct regulator_dev *rdev) 84da65e367SBjorn Andersson { 85da65e367SBjorn Andersson struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); 86da65e367SBjorn Andersson struct rpm_regulator_req req; 87da65e367SBjorn Andersson int ret; 88da65e367SBjorn Andersson 892c652a98SStephen Boyd req.key = cpu_to_le32(RPM_KEY_SWEN); 902c652a98SStephen Boyd req.nbytes = cpu_to_le32(sizeof(u32)); 91da65e367SBjorn Andersson req.value = 0; 92da65e367SBjorn Andersson 93da65e367SBjorn Andersson ret = rpm_reg_write_active(vreg, &req, sizeof(req)); 94da65e367SBjorn Andersson if (!ret) 95da65e367SBjorn Andersson vreg->is_enabled = 0; 96da65e367SBjorn Andersson 97da65e367SBjorn Andersson return ret; 98da65e367SBjorn Andersson } 99da65e367SBjorn Andersson 100da65e367SBjorn Andersson static int rpm_reg_get_voltage(struct regulator_dev *rdev) 101da65e367SBjorn Andersson { 102da65e367SBjorn Andersson struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); 103da65e367SBjorn Andersson 104da65e367SBjorn Andersson return vreg->uV; 105da65e367SBjorn Andersson } 106da65e367SBjorn Andersson 107da65e367SBjorn Andersson static int rpm_reg_set_voltage(struct regulator_dev *rdev, 108da65e367SBjorn Andersson int min_uV, 109da65e367SBjorn Andersson int max_uV, 110da65e367SBjorn Andersson unsigned *selector) 111da65e367SBjorn Andersson { 112da65e367SBjorn Andersson struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); 113da65e367SBjorn Andersson struct rpm_regulator_req req; 114da65e367SBjorn Andersson int ret = 0; 115da65e367SBjorn Andersson 1162c652a98SStephen Boyd req.key = cpu_to_le32(RPM_KEY_UV); 1172c652a98SStephen Boyd req.nbytes = cpu_to_le32(sizeof(u32)); 1182c652a98SStephen Boyd req.value = cpu_to_le32(min_uV); 119da65e367SBjorn Andersson 120da65e367SBjorn Andersson ret = rpm_reg_write_active(vreg, &req, sizeof(req)); 121da65e367SBjorn Andersson if (!ret) 122da65e367SBjorn Andersson vreg->uV = min_uV; 123da65e367SBjorn Andersson 124da65e367SBjorn Andersson return ret; 125da65e367SBjorn Andersson } 126da65e367SBjorn Andersson 127da65e367SBjorn Andersson static int rpm_reg_set_load(struct regulator_dev *rdev, int load_uA) 128da65e367SBjorn Andersson { 129da65e367SBjorn Andersson struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); 130da65e367SBjorn Andersson struct rpm_regulator_req req; 131da65e367SBjorn Andersson 1322c652a98SStephen Boyd req.key = cpu_to_le32(RPM_KEY_MA); 1332c652a98SStephen Boyd req.nbytes = cpu_to_le32(sizeof(u32)); 134a3e123c1SBjorn Andersson req.value = cpu_to_le32(load_uA / 1000); 135da65e367SBjorn Andersson 136da65e367SBjorn Andersson return rpm_reg_write_active(vreg, &req, sizeof(req)); 137da65e367SBjorn Andersson } 138da65e367SBjorn Andersson 139da65e367SBjorn Andersson static const struct regulator_ops rpm_smps_ldo_ops = { 140da65e367SBjorn Andersson .enable = rpm_reg_enable, 141da65e367SBjorn Andersson .disable = rpm_reg_disable, 142da65e367SBjorn Andersson .is_enabled = rpm_reg_is_enabled, 143da65e367SBjorn Andersson 144da65e367SBjorn Andersson .get_voltage = rpm_reg_get_voltage, 145da65e367SBjorn Andersson .set_voltage = rpm_reg_set_voltage, 146da65e367SBjorn Andersson 147da65e367SBjorn Andersson .set_load = rpm_reg_set_load, 148da65e367SBjorn Andersson }; 149da65e367SBjorn Andersson 150da65e367SBjorn Andersson static const struct regulator_ops rpm_switch_ops = { 151da65e367SBjorn Andersson .enable = rpm_reg_enable, 152da65e367SBjorn Andersson .disable = rpm_reg_disable, 153da65e367SBjorn Andersson .is_enabled = rpm_reg_is_enabled, 154da65e367SBjorn Andersson }; 155da65e367SBjorn Andersson 156da65e367SBjorn Andersson static const struct regulator_desc pm8x41_hfsmps = { 157da65e367SBjorn Andersson .linear_ranges = (struct regulator_linear_range[]) { 158da65e367SBjorn Andersson REGULATOR_LINEAR_RANGE( 375000, 0, 95, 12500), 159da65e367SBjorn Andersson REGULATOR_LINEAR_RANGE(1550000, 96, 158, 25000), 160da65e367SBjorn Andersson }, 161da65e367SBjorn Andersson .n_linear_ranges = 2, 162da65e367SBjorn Andersson .n_voltages = 159, 163da65e367SBjorn Andersson .ops = &rpm_smps_ldo_ops, 164da65e367SBjorn Andersson }; 165da65e367SBjorn Andersson 166da65e367SBjorn Andersson static const struct regulator_desc pm8841_ftsmps = { 167da65e367SBjorn Andersson .linear_ranges = (struct regulator_linear_range[]) { 168da65e367SBjorn Andersson REGULATOR_LINEAR_RANGE(350000, 0, 184, 5000), 169da65e367SBjorn Andersson REGULATOR_LINEAR_RANGE(700000, 185, 339, 10000), 170da65e367SBjorn Andersson }, 171da65e367SBjorn Andersson .n_linear_ranges = 2, 172da65e367SBjorn Andersson .n_voltages = 340, 173da65e367SBjorn Andersson .ops = &rpm_smps_ldo_ops, 174da65e367SBjorn Andersson }; 175da65e367SBjorn Andersson 176da65e367SBjorn Andersson static const struct regulator_desc pm8941_boost = { 177da65e367SBjorn Andersson .linear_ranges = (struct regulator_linear_range[]) { 178da65e367SBjorn Andersson REGULATOR_LINEAR_RANGE(4000000, 0, 15, 100000), 179da65e367SBjorn Andersson }, 180da65e367SBjorn Andersson .n_linear_ranges = 1, 181da65e367SBjorn Andersson .n_voltages = 16, 182da65e367SBjorn Andersson .ops = &rpm_smps_ldo_ops, 183da65e367SBjorn Andersson }; 184da65e367SBjorn Andersson 185da65e367SBjorn Andersson static const struct regulator_desc pm8941_pldo = { 186da65e367SBjorn Andersson .linear_ranges = (struct regulator_linear_range[]) { 187da65e367SBjorn Andersson REGULATOR_LINEAR_RANGE( 750000, 0, 30, 25000), 188da65e367SBjorn Andersson REGULATOR_LINEAR_RANGE(1500000, 31, 99, 50000), 189da65e367SBjorn Andersson }, 190da65e367SBjorn Andersson .n_linear_ranges = 2, 191da65e367SBjorn Andersson .n_voltages = 100, 192da65e367SBjorn Andersson .ops = &rpm_smps_ldo_ops, 193da65e367SBjorn Andersson }; 194da65e367SBjorn Andersson 195da65e367SBjorn Andersson static const struct regulator_desc pm8941_nldo = { 196da65e367SBjorn Andersson .linear_ranges = (struct regulator_linear_range[]) { 197da65e367SBjorn Andersson REGULATOR_LINEAR_RANGE(750000, 0, 63, 12500), 198da65e367SBjorn Andersson }, 199da65e367SBjorn Andersson .n_linear_ranges = 1, 200da65e367SBjorn Andersson .n_voltages = 64, 201da65e367SBjorn Andersson .ops = &rpm_smps_ldo_ops, 202da65e367SBjorn Andersson }; 203da65e367SBjorn Andersson 204da65e367SBjorn Andersson static const struct regulator_desc pm8941_lnldo = { 205da65e367SBjorn Andersson .fixed_uV = 1740000, 2065a286aaeSAxel Lin .n_voltages = 1, 207da65e367SBjorn Andersson .ops = &rpm_smps_ldo_ops, 208da65e367SBjorn Andersson }; 209da65e367SBjorn Andersson 210da65e367SBjorn Andersson static const struct regulator_desc pm8941_switch = { 211da65e367SBjorn Andersson .ops = &rpm_switch_ops, 212da65e367SBjorn Andersson }; 213da65e367SBjorn Andersson 21457d65676SAndy Gross static const struct regulator_desc pm8916_pldo = { 21557d65676SAndy Gross .linear_ranges = (struct regulator_linear_range[]) { 21657d65676SAndy Gross REGULATOR_LINEAR_RANGE(750000, 0, 208, 12500), 21757d65676SAndy Gross }, 21857d65676SAndy Gross .n_linear_ranges = 1, 21957d65676SAndy Gross .n_voltages = 209, 22057d65676SAndy Gross .ops = &rpm_smps_ldo_ops, 22157d65676SAndy Gross }; 22257d65676SAndy Gross 22357d65676SAndy Gross static const struct regulator_desc pm8916_nldo = { 22457d65676SAndy Gross .linear_ranges = (struct regulator_linear_range[]) { 22557d65676SAndy Gross REGULATOR_LINEAR_RANGE(375000, 0, 93, 12500), 22657d65676SAndy Gross }, 22757d65676SAndy Gross .n_linear_ranges = 1, 22857d65676SAndy Gross .n_voltages = 94, 22957d65676SAndy Gross .ops = &rpm_smps_ldo_ops, 23057d65676SAndy Gross }; 23157d65676SAndy Gross 23257d65676SAndy Gross static const struct regulator_desc pm8916_buck_lvo_smps = { 23357d65676SAndy Gross .linear_ranges = (struct regulator_linear_range[]) { 23457d65676SAndy Gross REGULATOR_LINEAR_RANGE(375000, 0, 95, 12500), 23557d65676SAndy Gross REGULATOR_LINEAR_RANGE(750000, 96, 127, 25000), 23657d65676SAndy Gross }, 23757d65676SAndy Gross .n_linear_ranges = 2, 23857d65676SAndy Gross .n_voltages = 128, 23957d65676SAndy Gross .ops = &rpm_smps_ldo_ops, 24057d65676SAndy Gross }; 24157d65676SAndy Gross 24257d65676SAndy Gross static const struct regulator_desc pm8916_buck_hvo_smps = { 24357d65676SAndy Gross .linear_ranges = (struct regulator_linear_range[]) { 24457d65676SAndy Gross REGULATOR_LINEAR_RANGE(1550000, 0, 31, 25000), 24557d65676SAndy Gross }, 24657d65676SAndy Gross .n_linear_ranges = 1, 24757d65676SAndy Gross .n_voltages = 32, 24857d65676SAndy Gross .ops = &rpm_smps_ldo_ops, 24957d65676SAndy Gross }; 25057d65676SAndy Gross 251da65e367SBjorn Andersson struct rpm_regulator_data { 252da65e367SBjorn Andersson const char *name; 253da65e367SBjorn Andersson u32 type; 254da65e367SBjorn Andersson u32 id; 255da65e367SBjorn Andersson const struct regulator_desc *desc; 256da65e367SBjorn Andersson const char *supply; 257da65e367SBjorn Andersson }; 258da65e367SBjorn Andersson 259da65e367SBjorn Andersson static const struct rpm_regulator_data rpm_pm8841_regulators[] = { 260da65e367SBjorn Andersson { "s1", QCOM_SMD_RPM_SMPB, 1, &pm8x41_hfsmps, "vdd_s1" }, 261da65e367SBjorn Andersson { "s2", QCOM_SMD_RPM_SMPB, 2, &pm8841_ftsmps, "vdd_s2" }, 262da65e367SBjorn Andersson { "s3", QCOM_SMD_RPM_SMPB, 3, &pm8x41_hfsmps, "vdd_s3" }, 263da65e367SBjorn Andersson { "s4", QCOM_SMD_RPM_SMPB, 4, &pm8841_ftsmps, "vdd_s4" }, 264da65e367SBjorn Andersson { "s5", QCOM_SMD_RPM_SMPB, 5, &pm8841_ftsmps, "vdd_s5" }, 265da65e367SBjorn Andersson { "s6", QCOM_SMD_RPM_SMPB, 6, &pm8841_ftsmps, "vdd_s6" }, 266da65e367SBjorn Andersson { "s7", QCOM_SMD_RPM_SMPB, 7, &pm8841_ftsmps, "vdd_s7" }, 267da65e367SBjorn Andersson { "s8", QCOM_SMD_RPM_SMPB, 8, &pm8841_ftsmps, "vdd_s8" }, 268da65e367SBjorn Andersson {} 269da65e367SBjorn Andersson }; 270da65e367SBjorn Andersson 27157d65676SAndy Gross static const struct rpm_regulator_data rpm_pm8916_regulators[] = { 27257d65676SAndy Gross { "s1", QCOM_SMD_RPM_SMPA, 1, &pm8916_buck_lvo_smps, "vdd_s1" }, 27357d65676SAndy Gross { "s2", QCOM_SMD_RPM_SMPA, 2, &pm8916_buck_lvo_smps, "vdd_s2" }, 27457d65676SAndy Gross { "s3", QCOM_SMD_RPM_SMPA, 3, &pm8916_buck_lvo_smps, "vdd_s3" }, 27557d65676SAndy Gross { "s4", QCOM_SMD_RPM_SMPA, 4, &pm8916_buck_hvo_smps, "vdd_s4" }, 27657d65676SAndy Gross { "l1", QCOM_SMD_RPM_LDOA, 1, &pm8916_nldo, "vdd_l1_l2_l3" }, 27757d65676SAndy Gross { "l2", QCOM_SMD_RPM_LDOA, 2, &pm8916_nldo, "vdd_l1_l2_l3" }, 27857d65676SAndy Gross { "l3", QCOM_SMD_RPM_LDOA, 3, &pm8916_nldo, "vdd_l1_l2_l3" }, 27957d65676SAndy Gross { "l4", QCOM_SMD_RPM_LDOA, 4, &pm8916_pldo, "vdd_l4_l5_l6" }, 28057d65676SAndy Gross { "l5", QCOM_SMD_RPM_LDOA, 5, &pm8916_pldo, "vdd_l4_l5_l6" }, 28157d65676SAndy Gross { "l6", QCOM_SMD_RPM_LDOA, 6, &pm8916_pldo, "vdd_l4_l5_l6" }, 28257d65676SAndy Gross { "l7", QCOM_SMD_RPM_LDOA, 7, &pm8916_pldo, "vdd_l7" }, 28357d65676SAndy Gross { "l8", QCOM_SMD_RPM_LDOA, 8, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18" }, 28457d65676SAndy Gross { "l9", QCOM_SMD_RPM_LDOA, 9, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18" }, 28557d65676SAndy Gross { "l10", QCOM_SMD_RPM_LDOA, 10, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"}, 28657d65676SAndy Gross { "l11", QCOM_SMD_RPM_LDOA, 11, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"}, 28757d65676SAndy Gross { "l12", QCOM_SMD_RPM_LDOA, 12, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"}, 28857d65676SAndy Gross { "l13", QCOM_SMD_RPM_LDOA, 13, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"}, 28957d65676SAndy Gross { "l14", QCOM_SMD_RPM_LDOA, 14, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"}, 29057d65676SAndy Gross { "l15", QCOM_SMD_RPM_LDOA, 15, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"}, 29157d65676SAndy Gross { "l16", QCOM_SMD_RPM_LDOA, 16, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"}, 29257d65676SAndy Gross { "l17", QCOM_SMD_RPM_LDOA, 17, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"}, 29357d65676SAndy Gross { "l18", QCOM_SMD_RPM_LDOA, 18, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"}, 29457d65676SAndy Gross {} 29557d65676SAndy Gross }; 29657d65676SAndy Gross 297da65e367SBjorn Andersson static const struct rpm_regulator_data rpm_pm8941_regulators[] = { 298da65e367SBjorn Andersson { "s1", QCOM_SMD_RPM_SMPA, 1, &pm8x41_hfsmps, "vdd_s1" }, 299da65e367SBjorn Andersson { "s2", QCOM_SMD_RPM_SMPA, 2, &pm8x41_hfsmps, "vdd_s2" }, 300da65e367SBjorn Andersson { "s3", QCOM_SMD_RPM_SMPA, 3, &pm8x41_hfsmps, "vdd_s3" }, 301da65e367SBjorn Andersson { "s4", QCOM_SMD_RPM_BOOST, 1, &pm8941_boost }, 302da65e367SBjorn Andersson 303da65e367SBjorn Andersson { "l1", QCOM_SMD_RPM_LDOA, 1, &pm8941_nldo, "vdd_l1_l3" }, 304da65e367SBjorn Andersson { "l2", QCOM_SMD_RPM_LDOA, 2, &pm8941_nldo, "vdd_l2_lvs1_2_3" }, 305da65e367SBjorn Andersson { "l3", QCOM_SMD_RPM_LDOA, 3, &pm8941_nldo, "vdd_l1_l3" }, 306da65e367SBjorn Andersson { "l4", QCOM_SMD_RPM_LDOA, 4, &pm8941_nldo, "vdd_l4_l11" }, 307da65e367SBjorn Andersson { "l5", QCOM_SMD_RPM_LDOA, 5, &pm8941_lnldo, "vdd_l5_l7" }, 308da65e367SBjorn Andersson { "l6", QCOM_SMD_RPM_LDOA, 6, &pm8941_pldo, "vdd_l6_l12_l14_l15" }, 309da65e367SBjorn Andersson { "l7", QCOM_SMD_RPM_LDOA, 7, &pm8941_lnldo, "vdd_l5_l7" }, 310da65e367SBjorn Andersson { "l8", QCOM_SMD_RPM_LDOA, 8, &pm8941_pldo, "vdd_l8_l16_l18_l19" }, 311da65e367SBjorn Andersson { "l9", QCOM_SMD_RPM_LDOA, 9, &pm8941_pldo, "vdd_l9_l10_l17_l22" }, 312da65e367SBjorn Andersson { "l10", QCOM_SMD_RPM_LDOA, 10, &pm8941_pldo, "vdd_l9_l10_l17_l22" }, 313da65e367SBjorn Andersson { "l11", QCOM_SMD_RPM_LDOA, 11, &pm8941_nldo, "vdd_l4_l11" }, 314da65e367SBjorn Andersson { "l12", QCOM_SMD_RPM_LDOA, 12, &pm8941_pldo, "vdd_l6_l12_l14_l15" }, 315da65e367SBjorn Andersson { "l13", QCOM_SMD_RPM_LDOA, 13, &pm8941_pldo, "vdd_l13_l20_l23_l24" }, 316da65e367SBjorn Andersson { "l14", QCOM_SMD_RPM_LDOA, 14, &pm8941_pldo, "vdd_l6_l12_l14_l15" }, 317da65e367SBjorn Andersson { "l15", QCOM_SMD_RPM_LDOA, 15, &pm8941_pldo, "vdd_l6_l12_l14_l15" }, 318da65e367SBjorn Andersson { "l16", QCOM_SMD_RPM_LDOA, 16, &pm8941_pldo, "vdd_l8_l16_l18_l19" }, 319da65e367SBjorn Andersson { "l17", QCOM_SMD_RPM_LDOA, 17, &pm8941_pldo, "vdd_l9_l10_l17_l22" }, 320da65e367SBjorn Andersson { "l18", QCOM_SMD_RPM_LDOA, 18, &pm8941_pldo, "vdd_l8_l16_l18_l19" }, 321da65e367SBjorn Andersson { "l19", QCOM_SMD_RPM_LDOA, 19, &pm8941_pldo, "vdd_l8_l16_l18_l19" }, 322da65e367SBjorn Andersson { "l20", QCOM_SMD_RPM_LDOA, 20, &pm8941_pldo, "vdd_l13_l20_l23_l24" }, 323da65e367SBjorn Andersson { "l21", QCOM_SMD_RPM_LDOA, 21, &pm8941_pldo, "vdd_l21" }, 324da65e367SBjorn Andersson { "l22", QCOM_SMD_RPM_LDOA, 22, &pm8941_pldo, "vdd_l9_l10_l17_l22" }, 325da65e367SBjorn Andersson { "l23", QCOM_SMD_RPM_LDOA, 23, &pm8941_pldo, "vdd_l13_l20_l23_l24" }, 326da65e367SBjorn Andersson { "l24", QCOM_SMD_RPM_LDOA, 24, &pm8941_pldo, "vdd_l13_l20_l23_l24" }, 327da65e367SBjorn Andersson 328da65e367SBjorn Andersson { "lvs1", QCOM_SMD_RPM_VSA, 1, &pm8941_switch, "vdd_l2_lvs1_2_3" }, 329da65e367SBjorn Andersson { "lvs2", QCOM_SMD_RPM_VSA, 2, &pm8941_switch, "vdd_l2_lvs1_2_3" }, 330da65e367SBjorn Andersson { "lvs3", QCOM_SMD_RPM_VSA, 3, &pm8941_switch, "vdd_l2_lvs1_2_3" }, 331da65e367SBjorn Andersson 332da65e367SBjorn Andersson { "5vs1", QCOM_SMD_RPM_VSA, 4, &pm8941_switch, "vin_5vs" }, 333da65e367SBjorn Andersson { "5vs2", QCOM_SMD_RPM_VSA, 5, &pm8941_switch, "vin_5vs" }, 334da65e367SBjorn Andersson 335da65e367SBjorn Andersson {} 336da65e367SBjorn Andersson }; 337da65e367SBjorn Andersson 338da65e367SBjorn Andersson static const struct of_device_id rpm_of_match[] = { 339da65e367SBjorn Andersson { .compatible = "qcom,rpm-pm8841-regulators", .data = &rpm_pm8841_regulators }, 34057d65676SAndy Gross { .compatible = "qcom,rpm-pm8916-regulators", .data = &rpm_pm8916_regulators }, 341da65e367SBjorn Andersson { .compatible = "qcom,rpm-pm8941-regulators", .data = &rpm_pm8941_regulators }, 342da65e367SBjorn Andersson {} 343da65e367SBjorn Andersson }; 344da65e367SBjorn Andersson MODULE_DEVICE_TABLE(of, rpm_of_match); 345da65e367SBjorn Andersson 346da65e367SBjorn Andersson static int rpm_reg_probe(struct platform_device *pdev) 347da65e367SBjorn Andersson { 348da65e367SBjorn Andersson const struct rpm_regulator_data *reg; 349da65e367SBjorn Andersson const struct of_device_id *match; 350da65e367SBjorn Andersson struct regulator_config config = { }; 351da65e367SBjorn Andersson struct regulator_dev *rdev; 352da65e367SBjorn Andersson struct qcom_rpm_reg *vreg; 353da65e367SBjorn Andersson struct qcom_smd_rpm *rpm; 354da65e367SBjorn Andersson 355da65e367SBjorn Andersson rpm = dev_get_drvdata(pdev->dev.parent); 356da65e367SBjorn Andersson if (!rpm) { 357da65e367SBjorn Andersson dev_err(&pdev->dev, "unable to retrieve handle to rpm\n"); 358da65e367SBjorn Andersson return -ENODEV; 359da65e367SBjorn Andersson } 360da65e367SBjorn Andersson 361da65e367SBjorn Andersson match = of_match_device(rpm_of_match, &pdev->dev); 362da65e367SBjorn Andersson for (reg = match->data; reg->name; reg++) { 363da65e367SBjorn Andersson vreg = devm_kzalloc(&pdev->dev, sizeof(*vreg), GFP_KERNEL); 364da65e367SBjorn Andersson if (!vreg) 365da65e367SBjorn Andersson return -ENOMEM; 366da65e367SBjorn Andersson 367da65e367SBjorn Andersson vreg->dev = &pdev->dev; 368da65e367SBjorn Andersson vreg->type = reg->type; 369da65e367SBjorn Andersson vreg->id = reg->id; 370da65e367SBjorn Andersson vreg->rpm = rpm; 371da65e367SBjorn Andersson 372da65e367SBjorn Andersson memcpy(&vreg->desc, reg->desc, sizeof(vreg->desc)); 373da65e367SBjorn Andersson 374da65e367SBjorn Andersson vreg->desc.id = -1; 375da65e367SBjorn Andersson vreg->desc.owner = THIS_MODULE; 376da65e367SBjorn Andersson vreg->desc.type = REGULATOR_VOLTAGE; 377da65e367SBjorn Andersson vreg->desc.name = reg->name; 378da65e367SBjorn Andersson vreg->desc.supply_name = reg->supply; 379da65e367SBjorn Andersson vreg->desc.of_match = reg->name; 380da65e367SBjorn Andersson 381da65e367SBjorn Andersson config.dev = &pdev->dev; 382da65e367SBjorn Andersson config.driver_data = vreg; 383da65e367SBjorn Andersson rdev = devm_regulator_register(&pdev->dev, &vreg->desc, &config); 384da65e367SBjorn Andersson if (IS_ERR(rdev)) { 385da65e367SBjorn Andersson dev_err(&pdev->dev, "failed to register %s\n", reg->name); 386da65e367SBjorn Andersson return PTR_ERR(rdev); 387da65e367SBjorn Andersson } 388da65e367SBjorn Andersson } 389da65e367SBjorn Andersson 390da65e367SBjorn Andersson return 0; 391da65e367SBjorn Andersson } 392da65e367SBjorn Andersson 393da65e367SBjorn Andersson static struct platform_driver rpm_reg_driver = { 394da65e367SBjorn Andersson .probe = rpm_reg_probe, 395da65e367SBjorn Andersson .driver = { 396da65e367SBjorn Andersson .name = "qcom_rpm_smd_regulator", 397da65e367SBjorn Andersson .of_match_table = rpm_of_match, 398da65e367SBjorn Andersson }, 399da65e367SBjorn Andersson }; 400da65e367SBjorn Andersson 401da65e367SBjorn Andersson static int __init rpm_reg_init(void) 402da65e367SBjorn Andersson { 403da65e367SBjorn Andersson return platform_driver_register(&rpm_reg_driver); 404da65e367SBjorn Andersson } 405da65e367SBjorn Andersson subsys_initcall(rpm_reg_init); 406da65e367SBjorn Andersson 407da65e367SBjorn Andersson static void __exit rpm_reg_exit(void) 408da65e367SBjorn Andersson { 409da65e367SBjorn Andersson platform_driver_unregister(&rpm_reg_driver); 410da65e367SBjorn Andersson } 411da65e367SBjorn Andersson module_exit(rpm_reg_exit) 412da65e367SBjorn Andersson 413da65e367SBjorn Andersson MODULE_DESCRIPTION("Qualcomm RPM regulator driver"); 414da65e367SBjorn Andersson MODULE_LICENSE("GPL v2"); 415