162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Motorola CPCAP PMIC regulator driver 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Based on cpcap-regulator.c from Motorola Linux kernel tree 662306a36Sopenharmony_ci * Copyright (C) 2009-2011 Motorola, Inc. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Rewritten for mainline kernel to use device tree and regmap 962306a36Sopenharmony_ci * Copyright (C) 2017 Tony Lindgren <tony@atomide.com> 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include <linux/err.h> 1362306a36Sopenharmony_ci#include <linux/module.h> 1462306a36Sopenharmony_ci#include <linux/of.h> 1562306a36Sopenharmony_ci#include <linux/platform_device.h> 1662306a36Sopenharmony_ci#include <linux/regmap.h> 1762306a36Sopenharmony_ci#include <linux/regulator/driver.h> 1862306a36Sopenharmony_ci#include <linux/regulator/machine.h> 1962306a36Sopenharmony_ci#include <linux/regulator/of_regulator.h> 2062306a36Sopenharmony_ci#include <linux/mfd/motorola-cpcap.h> 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/* 2362306a36Sopenharmony_ci * Resource assignment register bits. These seem to control the state 2462306a36Sopenharmony_ci * idle modes adn are used at least for omap4. 2562306a36Sopenharmony_ci */ 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* CPCAP_REG_ASSIGN2 bits - Resource Assignment 2 */ 2862306a36Sopenharmony_ci#define CPCAP_BIT_VSDIO_SEL BIT(15) 2962306a36Sopenharmony_ci#define CPCAP_BIT_VDIG_SEL BIT(14) 3062306a36Sopenharmony_ci#define CPCAP_BIT_VCAM_SEL BIT(13) 3162306a36Sopenharmony_ci#define CPCAP_BIT_SW6_SEL BIT(12) 3262306a36Sopenharmony_ci#define CPCAP_BIT_SW5_SEL BIT(11) 3362306a36Sopenharmony_ci#define CPCAP_BIT_SW4_SEL BIT(10) 3462306a36Sopenharmony_ci#define CPCAP_BIT_SW3_SEL BIT(9) 3562306a36Sopenharmony_ci#define CPCAP_BIT_SW2_SEL BIT(8) 3662306a36Sopenharmony_ci#define CPCAP_BIT_SW1_SEL BIT(7) 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci/* CPCAP_REG_ASSIGN3 bits - Resource Assignment 3 */ 3962306a36Sopenharmony_ci#define CPCAP_BIT_VUSBINT2_SEL BIT(15) 4062306a36Sopenharmony_ci#define CPCAP_BIT_VUSBINT1_SEL BIT(14) 4162306a36Sopenharmony_ci#define CPCAP_BIT_VVIB_SEL BIT(13) 4262306a36Sopenharmony_ci#define CPCAP_BIT_VWLAN1_SEL BIT(12) 4362306a36Sopenharmony_ci#define CPCAP_BIT_VRF1_SEL BIT(11) 4462306a36Sopenharmony_ci#define CPCAP_BIT_VHVIO_SEL BIT(10) 4562306a36Sopenharmony_ci#define CPCAP_BIT_VDAC_SEL BIT(9) 4662306a36Sopenharmony_ci#define CPCAP_BIT_VUSB_SEL BIT(8) 4762306a36Sopenharmony_ci#define CPCAP_BIT_VSIM_SEL BIT(7) 4862306a36Sopenharmony_ci#define CPCAP_BIT_VRFREF_SEL BIT(6) 4962306a36Sopenharmony_ci#define CPCAP_BIT_VPLL_SEL BIT(5) 5062306a36Sopenharmony_ci#define CPCAP_BIT_VFUSE_SEL BIT(4) 5162306a36Sopenharmony_ci#define CPCAP_BIT_VCSI_SEL BIT(3) 5262306a36Sopenharmony_ci#define CPCAP_BIT_SPARE_14_2 BIT(2) 5362306a36Sopenharmony_ci#define CPCAP_BIT_VWLAN2_SEL BIT(1) 5462306a36Sopenharmony_ci#define CPCAP_BIT_VRF2_SEL BIT(0) 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci/* CPCAP_REG_ASSIGN4 bits - Resource Assignment 4 */ 5762306a36Sopenharmony_ci#define CPCAP_BIT_VAUDIO_SEL BIT(0) 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/* 6062306a36Sopenharmony_ci * Enable register bits. At least CPCAP_BIT_AUDIO_LOW_PWR is generic, 6162306a36Sopenharmony_ci * and not limited to audio regulator. Let's use the Motorola kernel 6262306a36Sopenharmony_ci * naming for now until we have a better understanding of the other 6362306a36Sopenharmony_ci * enable register bits. No idea why BIT(3) is not defined. 6462306a36Sopenharmony_ci */ 6562306a36Sopenharmony_ci#define CPCAP_BIT_AUDIO_LOW_PWR BIT(6) 6662306a36Sopenharmony_ci#define CPCAP_BIT_AUD_LOWPWR_SPEED BIT(5) 6762306a36Sopenharmony_ci#define CPCAP_BIT_VAUDIOPRISTBY BIT(4) 6862306a36Sopenharmony_ci#define CPCAP_BIT_VAUDIO_MODE1 BIT(2) 6962306a36Sopenharmony_ci#define CPCAP_BIT_VAUDIO_MODE0 BIT(1) 7062306a36Sopenharmony_ci#define CPCAP_BIT_V_AUDIO_EN BIT(0) 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci#define CPCAP_BIT_AUDIO_NORMAL_MODE 0x00 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci/* 7562306a36Sopenharmony_ci * Off mode configuration bit. Used currently only by SW5 on omap4. There's 7662306a36Sopenharmony_ci * the following comment in Motorola Linux kernel tree for it: 7762306a36Sopenharmony_ci * 7862306a36Sopenharmony_ci * When set in the regulator mode, the regulator assignment will be changed 7962306a36Sopenharmony_ci * to secondary when the regulator is disabled. The mode will be set back to 8062306a36Sopenharmony_ci * primary when the regulator is turned on. 8162306a36Sopenharmony_ci */ 8262306a36Sopenharmony_ci#define CPCAP_REG_OFF_MODE_SEC BIT(15) 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci/* 8562306a36Sopenharmony_ci * SoC specific configuration for CPCAP regulator. There are at least three 8662306a36Sopenharmony_ci * different SoCs each with their own parameters: omap3, omap4 and tegra2. 8762306a36Sopenharmony_ci * 8862306a36Sopenharmony_ci * The assign_reg and assign_mask seem to allow toggling between primary 8962306a36Sopenharmony_ci * and secondary mode that at least omap4 uses for off mode. 9062306a36Sopenharmony_ci */ 9162306a36Sopenharmony_cistruct cpcap_regulator { 9262306a36Sopenharmony_ci struct regulator_desc rdesc; 9362306a36Sopenharmony_ci const u16 assign_reg; 9462306a36Sopenharmony_ci const u16 assign_mask; 9562306a36Sopenharmony_ci}; 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci#define CPCAP_REG(_ID, reg, assignment_reg, assignment_mask, val_tbl, \ 9862306a36Sopenharmony_ci mode_mask, volt_mask, mode_val, off_val, \ 9962306a36Sopenharmony_ci volt_trans_time) { \ 10062306a36Sopenharmony_ci .rdesc = { \ 10162306a36Sopenharmony_ci .name = #_ID, \ 10262306a36Sopenharmony_ci .of_match = of_match_ptr(#_ID), \ 10362306a36Sopenharmony_ci .ops = &cpcap_regulator_ops, \ 10462306a36Sopenharmony_ci .regulators_node = of_match_ptr("regulators"), \ 10562306a36Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 10662306a36Sopenharmony_ci .id = CPCAP_##_ID, \ 10762306a36Sopenharmony_ci .owner = THIS_MODULE, \ 10862306a36Sopenharmony_ci .n_voltages = ARRAY_SIZE(val_tbl), \ 10962306a36Sopenharmony_ci .volt_table = (val_tbl), \ 11062306a36Sopenharmony_ci .vsel_reg = (reg), \ 11162306a36Sopenharmony_ci .vsel_mask = (volt_mask), \ 11262306a36Sopenharmony_ci .enable_reg = (reg), \ 11362306a36Sopenharmony_ci .enable_mask = (mode_mask), \ 11462306a36Sopenharmony_ci .enable_val = (mode_val), \ 11562306a36Sopenharmony_ci .disable_val = (off_val), \ 11662306a36Sopenharmony_ci .ramp_delay = (volt_trans_time), \ 11762306a36Sopenharmony_ci .of_map_mode = cpcap_map_mode, \ 11862306a36Sopenharmony_ci }, \ 11962306a36Sopenharmony_ci .assign_reg = (assignment_reg), \ 12062306a36Sopenharmony_ci .assign_mask = (assignment_mask), \ 12162306a36Sopenharmony_ci} 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_cistruct cpcap_ddata { 12462306a36Sopenharmony_ci struct regmap *reg; 12562306a36Sopenharmony_ci struct device *dev; 12662306a36Sopenharmony_ci const struct cpcap_regulator *soc; 12762306a36Sopenharmony_ci}; 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_cienum cpcap_regulator_id { 13062306a36Sopenharmony_ci CPCAP_SW1, 13162306a36Sopenharmony_ci CPCAP_SW2, 13262306a36Sopenharmony_ci CPCAP_SW3, 13362306a36Sopenharmony_ci CPCAP_SW4, 13462306a36Sopenharmony_ci CPCAP_SW5, 13562306a36Sopenharmony_ci CPCAP_SW6, 13662306a36Sopenharmony_ci CPCAP_VCAM, 13762306a36Sopenharmony_ci CPCAP_VCSI, 13862306a36Sopenharmony_ci CPCAP_VDAC, 13962306a36Sopenharmony_ci CPCAP_VDIG, 14062306a36Sopenharmony_ci CPCAP_VFUSE, 14162306a36Sopenharmony_ci CPCAP_VHVIO, 14262306a36Sopenharmony_ci CPCAP_VSDIO, 14362306a36Sopenharmony_ci CPCAP_VPLL, 14462306a36Sopenharmony_ci CPCAP_VRF1, 14562306a36Sopenharmony_ci CPCAP_VRF2, 14662306a36Sopenharmony_ci CPCAP_VRFREF, 14762306a36Sopenharmony_ci CPCAP_VWLAN1, 14862306a36Sopenharmony_ci CPCAP_VWLAN2, 14962306a36Sopenharmony_ci CPCAP_VSIM, 15062306a36Sopenharmony_ci CPCAP_VSIMCARD, 15162306a36Sopenharmony_ci CPCAP_VVIB, 15262306a36Sopenharmony_ci CPCAP_VUSB, 15362306a36Sopenharmony_ci CPCAP_VAUDIO, 15462306a36Sopenharmony_ci CPCAP_NR_REGULATORS, 15562306a36Sopenharmony_ci}; 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci/* 15862306a36Sopenharmony_ci * We need to also configure regulator idle mode for SoC off mode if 15962306a36Sopenharmony_ci * CPCAP_REG_OFF_MODE_SEC is set. 16062306a36Sopenharmony_ci */ 16162306a36Sopenharmony_cistatic int cpcap_regulator_enable(struct regulator_dev *rdev) 16262306a36Sopenharmony_ci{ 16362306a36Sopenharmony_ci struct cpcap_regulator *regulator = rdev_get_drvdata(rdev); 16462306a36Sopenharmony_ci int error; 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci error = regulator_enable_regmap(rdev); 16762306a36Sopenharmony_ci if (error) 16862306a36Sopenharmony_ci return error; 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci if (rdev->desc->enable_val & CPCAP_REG_OFF_MODE_SEC) { 17162306a36Sopenharmony_ci error = regmap_update_bits(rdev->regmap, regulator->assign_reg, 17262306a36Sopenharmony_ci regulator->assign_mask, 17362306a36Sopenharmony_ci regulator->assign_mask); 17462306a36Sopenharmony_ci if (error) 17562306a36Sopenharmony_ci regulator_disable_regmap(rdev); 17662306a36Sopenharmony_ci } 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci return error; 17962306a36Sopenharmony_ci} 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci/* 18262306a36Sopenharmony_ci * We need to also configure regulator idle mode for SoC off mode if 18362306a36Sopenharmony_ci * CPCAP_REG_OFF_MODE_SEC is set. 18462306a36Sopenharmony_ci */ 18562306a36Sopenharmony_cistatic int cpcap_regulator_disable(struct regulator_dev *rdev) 18662306a36Sopenharmony_ci{ 18762306a36Sopenharmony_ci struct cpcap_regulator *regulator = rdev_get_drvdata(rdev); 18862306a36Sopenharmony_ci int error; 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci if (rdev->desc->enable_val & CPCAP_REG_OFF_MODE_SEC) { 19162306a36Sopenharmony_ci error = regmap_update_bits(rdev->regmap, regulator->assign_reg, 19262306a36Sopenharmony_ci regulator->assign_mask, 0); 19362306a36Sopenharmony_ci if (error) 19462306a36Sopenharmony_ci return error; 19562306a36Sopenharmony_ci } 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci error = regulator_disable_regmap(rdev); 19862306a36Sopenharmony_ci if (error && (rdev->desc->enable_val & CPCAP_REG_OFF_MODE_SEC)) { 19962306a36Sopenharmony_ci regmap_update_bits(rdev->regmap, regulator->assign_reg, 20062306a36Sopenharmony_ci regulator->assign_mask, 20162306a36Sopenharmony_ci regulator->assign_mask); 20262306a36Sopenharmony_ci } 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ci return error; 20562306a36Sopenharmony_ci} 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_cistatic unsigned int cpcap_map_mode(unsigned int mode) 20862306a36Sopenharmony_ci{ 20962306a36Sopenharmony_ci switch (mode) { 21062306a36Sopenharmony_ci case CPCAP_BIT_AUDIO_NORMAL_MODE: 21162306a36Sopenharmony_ci return REGULATOR_MODE_NORMAL; 21262306a36Sopenharmony_ci case CPCAP_BIT_AUDIO_LOW_PWR: 21362306a36Sopenharmony_ci return REGULATOR_MODE_STANDBY; 21462306a36Sopenharmony_ci default: 21562306a36Sopenharmony_ci return REGULATOR_MODE_INVALID; 21662306a36Sopenharmony_ci } 21762306a36Sopenharmony_ci} 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_cistatic unsigned int cpcap_regulator_get_mode(struct regulator_dev *rdev) 22062306a36Sopenharmony_ci{ 22162306a36Sopenharmony_ci int value; 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci regmap_read(rdev->regmap, rdev->desc->enable_reg, &value); 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci if (value & CPCAP_BIT_AUDIO_LOW_PWR) 22662306a36Sopenharmony_ci return REGULATOR_MODE_STANDBY; 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_ci return REGULATOR_MODE_NORMAL; 22962306a36Sopenharmony_ci} 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_cistatic int cpcap_regulator_set_mode(struct regulator_dev *rdev, 23262306a36Sopenharmony_ci unsigned int mode) 23362306a36Sopenharmony_ci{ 23462306a36Sopenharmony_ci int value; 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci switch (mode) { 23762306a36Sopenharmony_ci case REGULATOR_MODE_NORMAL: 23862306a36Sopenharmony_ci value = CPCAP_BIT_AUDIO_NORMAL_MODE; 23962306a36Sopenharmony_ci break; 24062306a36Sopenharmony_ci case REGULATOR_MODE_STANDBY: 24162306a36Sopenharmony_ci value = CPCAP_BIT_AUDIO_LOW_PWR; 24262306a36Sopenharmony_ci break; 24362306a36Sopenharmony_ci default: 24462306a36Sopenharmony_ci return -EINVAL; 24562306a36Sopenharmony_ci } 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ci return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 24862306a36Sopenharmony_ci CPCAP_BIT_AUDIO_LOW_PWR, value); 24962306a36Sopenharmony_ci} 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_cistatic const struct regulator_ops cpcap_regulator_ops = { 25262306a36Sopenharmony_ci .enable = cpcap_regulator_enable, 25362306a36Sopenharmony_ci .disable = cpcap_regulator_disable, 25462306a36Sopenharmony_ci .is_enabled = regulator_is_enabled_regmap, 25562306a36Sopenharmony_ci .list_voltage = regulator_list_voltage_table, 25662306a36Sopenharmony_ci .map_voltage = regulator_map_voltage_iterate, 25762306a36Sopenharmony_ci .get_voltage_sel = regulator_get_voltage_sel_regmap, 25862306a36Sopenharmony_ci .set_voltage_sel = regulator_set_voltage_sel_regmap, 25962306a36Sopenharmony_ci .get_mode = cpcap_regulator_get_mode, 26062306a36Sopenharmony_ci .set_mode = cpcap_regulator_set_mode, 26162306a36Sopenharmony_ci}; 26262306a36Sopenharmony_ci 26362306a36Sopenharmony_cistatic const unsigned int unknown_val_tbl[] = { 0, }; 26462306a36Sopenharmony_cistatic const unsigned int sw2_sw4_val_tbl[] = { 612500, 625000, 637500, 26562306a36Sopenharmony_ci 650000, 662500, 675000, 26662306a36Sopenharmony_ci 687500, 700000, 712500, 26762306a36Sopenharmony_ci 725000, 737500, 750000, 26862306a36Sopenharmony_ci 762500, 775000, 787500, 26962306a36Sopenharmony_ci 800000, 812500, 825000, 27062306a36Sopenharmony_ci 837500, 850000, 862500, 27162306a36Sopenharmony_ci 875000, 887500, 900000, 27262306a36Sopenharmony_ci 912500, 925000, 937500, 27362306a36Sopenharmony_ci 950000, 962500, 975000, 27462306a36Sopenharmony_ci 987500, 1000000, 1012500, 27562306a36Sopenharmony_ci 1025000, 1037500, 1050000, 27662306a36Sopenharmony_ci 1062500, 1075000, 1087500, 27762306a36Sopenharmony_ci 1100000, 1112500, 1125000, 27862306a36Sopenharmony_ci 1137500, 1150000, 1162500, 27962306a36Sopenharmony_ci 1175000, 1187500, 1200000, 28062306a36Sopenharmony_ci 1212500, 1225000, 1237500, 28162306a36Sopenharmony_ci 1250000, 1262500, 1275000, 28262306a36Sopenharmony_ci 1287500, 1300000, 1312500, 28362306a36Sopenharmony_ci 1325000, 1337500, 1350000, 28462306a36Sopenharmony_ci 1362500, 1375000, 1387500, 28562306a36Sopenharmony_ci 1400000, 1412500, 1425000, 28662306a36Sopenharmony_ci 1437500, 1450000, 1462500, }; 28762306a36Sopenharmony_cistatic const unsigned int sw5_val_tbl[] = { 0, 5050000, }; 28862306a36Sopenharmony_cistatic const unsigned int vcam_val_tbl[] = { 2600000, 2700000, 2800000, 28962306a36Sopenharmony_ci 2900000, }; 29062306a36Sopenharmony_cistatic const unsigned int vcsi_val_tbl[] = { 1200000, 1800000, }; 29162306a36Sopenharmony_cistatic const unsigned int vdac_val_tbl[] = { 1200000, 1500000, 1800000, 29262306a36Sopenharmony_ci 2500000,}; 29362306a36Sopenharmony_cistatic const unsigned int vdig_val_tbl[] = { 1200000, 1350000, 1500000, 29462306a36Sopenharmony_ci 1875000, }; 29562306a36Sopenharmony_cistatic const unsigned int vfuse_val_tbl[] = { 1500000, 1600000, 1700000, 29662306a36Sopenharmony_ci 1800000, 1900000, 2000000, 29762306a36Sopenharmony_ci 2100000, 2200000, 2300000, 29862306a36Sopenharmony_ci 2400000, 2500000, 2600000, 29962306a36Sopenharmony_ci 2700000, 3150000, }; 30062306a36Sopenharmony_cistatic const unsigned int vhvio_val_tbl[] = { 2775000, }; 30162306a36Sopenharmony_cistatic const unsigned int vsdio_val_tbl[] = { 1500000, 1600000, 1800000, 30262306a36Sopenharmony_ci 2600000, 2700000, 2800000, 30362306a36Sopenharmony_ci 2900000, 3000000, }; 30462306a36Sopenharmony_cistatic const unsigned int vpll_val_tbl[] = { 1200000, 1300000, 1400000, 30562306a36Sopenharmony_ci 1800000, }; 30662306a36Sopenharmony_ci/* Quirk: 2775000 is before 2500000 for vrf1 regulator */ 30762306a36Sopenharmony_cistatic const unsigned int vrf1_val_tbl[] = { 2775000, 2500000, }; 30862306a36Sopenharmony_cistatic const unsigned int vrf2_val_tbl[] = { 0, 2775000, }; 30962306a36Sopenharmony_cistatic const unsigned int vrfref_val_tbl[] = { 2500000, 2775000, }; 31062306a36Sopenharmony_cistatic const unsigned int vwlan1_val_tbl[] = { 1800000, 1900000, }; 31162306a36Sopenharmony_cistatic const unsigned int vwlan2_val_tbl[] = { 2775000, 3000000, 3300000, 31262306a36Sopenharmony_ci 3300000, }; 31362306a36Sopenharmony_cistatic const unsigned int vsim_val_tbl[] = { 1800000, 2900000, }; 31462306a36Sopenharmony_cistatic const unsigned int vsimcard_val_tbl[] = { 1800000, 2900000, }; 31562306a36Sopenharmony_cistatic const unsigned int vvib_val_tbl[] = { 1300000, 1800000, 2000000, 31662306a36Sopenharmony_ci 3000000, }; 31762306a36Sopenharmony_cistatic const unsigned int vusb_val_tbl[] = { 0, 3300000, }; 31862306a36Sopenharmony_cistatic const unsigned int vaudio_val_tbl[] = { 0, 2775000, }; 31962306a36Sopenharmony_ci 32062306a36Sopenharmony_ci/* 32162306a36Sopenharmony_ci * SoC specific configuration for omap4. The data below is comes from Motorola 32262306a36Sopenharmony_ci * Linux kernel tree. It's basically the values of cpcap_regltr_data, 32362306a36Sopenharmony_ci * cpcap_regulator_mode_values and cpcap_regulator_off_mode_values, see 32462306a36Sopenharmony_ci * CPCAP_REG macro above. 32562306a36Sopenharmony_ci * 32662306a36Sopenharmony_ci * SW1 to SW4 and SW6 seems to be unused for mapphone. Note that VSIM and 32762306a36Sopenharmony_ci * VSIMCARD have a shared resource assignment bit. 32862306a36Sopenharmony_ci */ 32962306a36Sopenharmony_cistatic const struct cpcap_regulator omap4_regulators[] = { 33062306a36Sopenharmony_ci CPCAP_REG(SW1, CPCAP_REG_S1C1, CPCAP_REG_ASSIGN2, 33162306a36Sopenharmony_ci CPCAP_BIT_SW1_SEL, unknown_val_tbl, 33262306a36Sopenharmony_ci 0, 0, 0, 0, 0), 33362306a36Sopenharmony_ci CPCAP_REG(SW2, CPCAP_REG_S2C1, CPCAP_REG_ASSIGN2, 33462306a36Sopenharmony_ci CPCAP_BIT_SW2_SEL, unknown_val_tbl, 33562306a36Sopenharmony_ci 0, 0, 0, 0, 0), 33662306a36Sopenharmony_ci CPCAP_REG(SW3, CPCAP_REG_S3C, CPCAP_REG_ASSIGN2, 33762306a36Sopenharmony_ci CPCAP_BIT_SW3_SEL, unknown_val_tbl, 33862306a36Sopenharmony_ci 0, 0, 0, 0, 0), 33962306a36Sopenharmony_ci CPCAP_REG(SW4, CPCAP_REG_S4C1, CPCAP_REG_ASSIGN2, 34062306a36Sopenharmony_ci CPCAP_BIT_SW4_SEL, unknown_val_tbl, 34162306a36Sopenharmony_ci 0, 0, 0, 0, 0), 34262306a36Sopenharmony_ci CPCAP_REG(SW5, CPCAP_REG_S5C, CPCAP_REG_ASSIGN2, 34362306a36Sopenharmony_ci CPCAP_BIT_SW5_SEL, sw5_val_tbl, 34462306a36Sopenharmony_ci 0x28, 0, 0x20 | CPCAP_REG_OFF_MODE_SEC, 0, 0), 34562306a36Sopenharmony_ci CPCAP_REG(SW6, CPCAP_REG_S6C, CPCAP_REG_ASSIGN2, 34662306a36Sopenharmony_ci CPCAP_BIT_SW6_SEL, unknown_val_tbl, 34762306a36Sopenharmony_ci 0, 0, 0, 0, 0), 34862306a36Sopenharmony_ci CPCAP_REG(VCAM, CPCAP_REG_VCAMC, CPCAP_REG_ASSIGN2, 34962306a36Sopenharmony_ci CPCAP_BIT_VCAM_SEL, vcam_val_tbl, 35062306a36Sopenharmony_ci 0x87, 0x30, 0x3, 0, 420), 35162306a36Sopenharmony_ci CPCAP_REG(VCSI, CPCAP_REG_VCSIC, CPCAP_REG_ASSIGN3, 35262306a36Sopenharmony_ci CPCAP_BIT_VCSI_SEL, vcsi_val_tbl, 35362306a36Sopenharmony_ci 0x47, 0x10, 0x43, 0x41, 350), 35462306a36Sopenharmony_ci CPCAP_REG(VDAC, CPCAP_REG_VDACC, CPCAP_REG_ASSIGN3, 35562306a36Sopenharmony_ci CPCAP_BIT_VDAC_SEL, vdac_val_tbl, 35662306a36Sopenharmony_ci 0x87, 0x30, 0x3, 0, 420), 35762306a36Sopenharmony_ci CPCAP_REG(VDIG, CPCAP_REG_VDIGC, CPCAP_REG_ASSIGN2, 35862306a36Sopenharmony_ci CPCAP_BIT_VDIG_SEL, vdig_val_tbl, 35962306a36Sopenharmony_ci 0x87, 0x30, 0x82, 0, 420), 36062306a36Sopenharmony_ci CPCAP_REG(VFUSE, CPCAP_REG_VFUSEC, CPCAP_REG_ASSIGN3, 36162306a36Sopenharmony_ci CPCAP_BIT_VFUSE_SEL, vfuse_val_tbl, 36262306a36Sopenharmony_ci 0x80, 0xf, 0x80, 0, 420), 36362306a36Sopenharmony_ci CPCAP_REG(VHVIO, CPCAP_REG_VHVIOC, CPCAP_REG_ASSIGN3, 36462306a36Sopenharmony_ci CPCAP_BIT_VHVIO_SEL, vhvio_val_tbl, 36562306a36Sopenharmony_ci 0x17, 0, 0, 0x12, 0), 36662306a36Sopenharmony_ci CPCAP_REG(VSDIO, CPCAP_REG_VSDIOC, CPCAP_REG_ASSIGN2, 36762306a36Sopenharmony_ci CPCAP_BIT_VSDIO_SEL, vsdio_val_tbl, 36862306a36Sopenharmony_ci 0x87, 0x38, 0x82, 0, 420), 36962306a36Sopenharmony_ci CPCAP_REG(VPLL, CPCAP_REG_VPLLC, CPCAP_REG_ASSIGN3, 37062306a36Sopenharmony_ci CPCAP_BIT_VPLL_SEL, vpll_val_tbl, 37162306a36Sopenharmony_ci 0x43, 0x18, 0x2, 0, 420), 37262306a36Sopenharmony_ci CPCAP_REG(VRF1, CPCAP_REG_VRF1C, CPCAP_REG_ASSIGN3, 37362306a36Sopenharmony_ci CPCAP_BIT_VRF1_SEL, vrf1_val_tbl, 37462306a36Sopenharmony_ci 0xac, 0x2, 0x4, 0, 10), 37562306a36Sopenharmony_ci CPCAP_REG(VRF2, CPCAP_REG_VRF2C, CPCAP_REG_ASSIGN3, 37662306a36Sopenharmony_ci CPCAP_BIT_VRF2_SEL, vrf2_val_tbl, 37762306a36Sopenharmony_ci 0x23, 0x8, 0, 0, 10), 37862306a36Sopenharmony_ci CPCAP_REG(VRFREF, CPCAP_REG_VRFREFC, CPCAP_REG_ASSIGN3, 37962306a36Sopenharmony_ci CPCAP_BIT_VRFREF_SEL, vrfref_val_tbl, 38062306a36Sopenharmony_ci 0x23, 0x8, 0, 0, 420), 38162306a36Sopenharmony_ci CPCAP_REG(VWLAN1, CPCAP_REG_VWLAN1C, CPCAP_REG_ASSIGN3, 38262306a36Sopenharmony_ci CPCAP_BIT_VWLAN1_SEL, vwlan1_val_tbl, 38362306a36Sopenharmony_ci 0x47, 0x10, 0, 0, 420), 38462306a36Sopenharmony_ci CPCAP_REG(VWLAN2, CPCAP_REG_VWLAN2C, CPCAP_REG_ASSIGN3, 38562306a36Sopenharmony_ci CPCAP_BIT_VWLAN2_SEL, vwlan2_val_tbl, 38662306a36Sopenharmony_ci 0x20c, 0xc0, 0x20c, 0, 420), 38762306a36Sopenharmony_ci CPCAP_REG(VSIM, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3, 38862306a36Sopenharmony_ci 0xffff, vsim_val_tbl, 38962306a36Sopenharmony_ci 0x23, 0x8, 0x3, 0, 420), 39062306a36Sopenharmony_ci CPCAP_REG(VSIMCARD, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3, 39162306a36Sopenharmony_ci 0xffff, vsimcard_val_tbl, 39262306a36Sopenharmony_ci 0x1e80, 0x8, 0x1e00, 0, 420), 39362306a36Sopenharmony_ci CPCAP_REG(VVIB, CPCAP_REG_VVIBC, CPCAP_REG_ASSIGN3, 39462306a36Sopenharmony_ci CPCAP_BIT_VVIB_SEL, vvib_val_tbl, 39562306a36Sopenharmony_ci 0x1, 0xc, 0x1, 0, 500), 39662306a36Sopenharmony_ci CPCAP_REG(VUSB, CPCAP_REG_VUSBC, CPCAP_REG_ASSIGN3, 39762306a36Sopenharmony_ci CPCAP_BIT_VUSB_SEL, vusb_val_tbl, 39862306a36Sopenharmony_ci 0x11c, 0x40, 0xc, 0, 0), 39962306a36Sopenharmony_ci CPCAP_REG(VAUDIO, CPCAP_REG_VAUDIOC, CPCAP_REG_ASSIGN4, 40062306a36Sopenharmony_ci CPCAP_BIT_VAUDIO_SEL, vaudio_val_tbl, 40162306a36Sopenharmony_ci 0x16, 0x1, 0x4, 0, 0), 40262306a36Sopenharmony_ci { /* sentinel */ }, 40362306a36Sopenharmony_ci}; 40462306a36Sopenharmony_ci 40562306a36Sopenharmony_cistatic const struct cpcap_regulator xoom_regulators[] = { 40662306a36Sopenharmony_ci CPCAP_REG(SW1, CPCAP_REG_S1C1, CPCAP_REG_ASSIGN2, 40762306a36Sopenharmony_ci CPCAP_BIT_SW1_SEL, unknown_val_tbl, 40862306a36Sopenharmony_ci 0, 0, 0, 0, 0), 40962306a36Sopenharmony_ci CPCAP_REG(SW2, CPCAP_REG_S2C1, CPCAP_REG_ASSIGN2, 41062306a36Sopenharmony_ci CPCAP_BIT_SW2_SEL, sw2_sw4_val_tbl, 41162306a36Sopenharmony_ci 0xf00, 0x7f, 0x800, 0, 120), 41262306a36Sopenharmony_ci CPCAP_REG(SW3, CPCAP_REG_S3C, CPCAP_REG_ASSIGN2, 41362306a36Sopenharmony_ci CPCAP_BIT_SW3_SEL, unknown_val_tbl, 41462306a36Sopenharmony_ci 0, 0, 0, 0, 0), 41562306a36Sopenharmony_ci CPCAP_REG(SW4, CPCAP_REG_S4C1, CPCAP_REG_ASSIGN2, 41662306a36Sopenharmony_ci CPCAP_BIT_SW4_SEL, sw2_sw4_val_tbl, 41762306a36Sopenharmony_ci 0xf00, 0x7f, 0x900, 0, 100), 41862306a36Sopenharmony_ci CPCAP_REG(SW5, CPCAP_REG_S5C, CPCAP_REG_ASSIGN2, 41962306a36Sopenharmony_ci CPCAP_BIT_SW5_SEL, sw5_val_tbl, 42062306a36Sopenharmony_ci 0x2a, 0, 0x22, 0, 0), 42162306a36Sopenharmony_ci CPCAP_REG(SW6, CPCAP_REG_S6C, CPCAP_REG_ASSIGN2, 42262306a36Sopenharmony_ci CPCAP_BIT_SW6_SEL, unknown_val_tbl, 42362306a36Sopenharmony_ci 0, 0, 0, 0, 0), 42462306a36Sopenharmony_ci CPCAP_REG(VCAM, CPCAP_REG_VCAMC, CPCAP_REG_ASSIGN2, 42562306a36Sopenharmony_ci CPCAP_BIT_VCAM_SEL, vcam_val_tbl, 42662306a36Sopenharmony_ci 0x87, 0x30, 0x7, 0, 420), 42762306a36Sopenharmony_ci CPCAP_REG(VCSI, CPCAP_REG_VCSIC, CPCAP_REG_ASSIGN3, 42862306a36Sopenharmony_ci CPCAP_BIT_VCSI_SEL, vcsi_val_tbl, 42962306a36Sopenharmony_ci 0x47, 0x10, 0x7, 0, 350), 43062306a36Sopenharmony_ci CPCAP_REG(VDAC, CPCAP_REG_VDACC, CPCAP_REG_ASSIGN3, 43162306a36Sopenharmony_ci CPCAP_BIT_VDAC_SEL, vdac_val_tbl, 43262306a36Sopenharmony_ci 0x87, 0x30, 0x3, 0, 420), 43362306a36Sopenharmony_ci CPCAP_REG(VDIG, CPCAP_REG_VDIGC, CPCAP_REG_ASSIGN2, 43462306a36Sopenharmony_ci CPCAP_BIT_VDIG_SEL, vdig_val_tbl, 43562306a36Sopenharmony_ci 0x87, 0x30, 0x5, 0, 420), 43662306a36Sopenharmony_ci CPCAP_REG(VFUSE, CPCAP_REG_VFUSEC, CPCAP_REG_ASSIGN3, 43762306a36Sopenharmony_ci CPCAP_BIT_VFUSE_SEL, vfuse_val_tbl, 43862306a36Sopenharmony_ci 0x80, 0xf, 0x80, 0, 420), 43962306a36Sopenharmony_ci CPCAP_REG(VHVIO, CPCAP_REG_VHVIOC, CPCAP_REG_ASSIGN3, 44062306a36Sopenharmony_ci CPCAP_BIT_VHVIO_SEL, vhvio_val_tbl, 44162306a36Sopenharmony_ci 0x17, 0, 0x2, 0, 0), 44262306a36Sopenharmony_ci CPCAP_REG(VSDIO, CPCAP_REG_VSDIOC, CPCAP_REG_ASSIGN2, 44362306a36Sopenharmony_ci CPCAP_BIT_VSDIO_SEL, vsdio_val_tbl, 44462306a36Sopenharmony_ci 0x87, 0x38, 0x2, 0, 420), 44562306a36Sopenharmony_ci CPCAP_REG(VPLL, CPCAP_REG_VPLLC, CPCAP_REG_ASSIGN3, 44662306a36Sopenharmony_ci CPCAP_BIT_VPLL_SEL, vpll_val_tbl, 44762306a36Sopenharmony_ci 0x43, 0x18, 0x1, 0, 420), 44862306a36Sopenharmony_ci CPCAP_REG(VRF1, CPCAP_REG_VRF1C, CPCAP_REG_ASSIGN3, 44962306a36Sopenharmony_ci CPCAP_BIT_VRF1_SEL, vrf1_val_tbl, 45062306a36Sopenharmony_ci 0xac, 0x2, 0xc, 0, 10), 45162306a36Sopenharmony_ci CPCAP_REG(VRF2, CPCAP_REG_VRF2C, CPCAP_REG_ASSIGN3, 45262306a36Sopenharmony_ci CPCAP_BIT_VRF2_SEL, vrf2_val_tbl, 45362306a36Sopenharmony_ci 0x23, 0x8, 0x3, 0, 10), 45462306a36Sopenharmony_ci CPCAP_REG(VRFREF, CPCAP_REG_VRFREFC, CPCAP_REG_ASSIGN3, 45562306a36Sopenharmony_ci CPCAP_BIT_VRFREF_SEL, vrfref_val_tbl, 45662306a36Sopenharmony_ci 0x23, 0x8, 0x3, 0, 420), 45762306a36Sopenharmony_ci CPCAP_REG(VWLAN1, CPCAP_REG_VWLAN1C, CPCAP_REG_ASSIGN3, 45862306a36Sopenharmony_ci CPCAP_BIT_VWLAN1_SEL, vwlan1_val_tbl, 45962306a36Sopenharmony_ci 0x47, 0x10, 0x5, 0, 420), 46062306a36Sopenharmony_ci CPCAP_REG(VWLAN2, CPCAP_REG_VWLAN2C, CPCAP_REG_ASSIGN3, 46162306a36Sopenharmony_ci CPCAP_BIT_VWLAN2_SEL, vwlan2_val_tbl, 46262306a36Sopenharmony_ci 0x20c, 0xc0, 0x8, 0, 420), 46362306a36Sopenharmony_ci CPCAP_REG(VSIM, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3, 46462306a36Sopenharmony_ci 0xffff, vsim_val_tbl, 46562306a36Sopenharmony_ci 0x23, 0x8, 0x3, 0, 420), 46662306a36Sopenharmony_ci CPCAP_REG(VSIMCARD, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3, 46762306a36Sopenharmony_ci 0xffff, vsimcard_val_tbl, 46862306a36Sopenharmony_ci 0x1e80, 0x8, 0x1e00, 0, 420), 46962306a36Sopenharmony_ci CPCAP_REG(VVIB, CPCAP_REG_VVIBC, CPCAP_REG_ASSIGN3, 47062306a36Sopenharmony_ci CPCAP_BIT_VVIB_SEL, vvib_val_tbl, 47162306a36Sopenharmony_ci 0x1, 0xc, 0, 0x1, 500), 47262306a36Sopenharmony_ci CPCAP_REG(VUSB, CPCAP_REG_VUSBC, CPCAP_REG_ASSIGN3, 47362306a36Sopenharmony_ci CPCAP_BIT_VUSB_SEL, vusb_val_tbl, 47462306a36Sopenharmony_ci 0x11c, 0x40, 0xc, 0, 0), 47562306a36Sopenharmony_ci CPCAP_REG(VAUDIO, CPCAP_REG_VAUDIOC, CPCAP_REG_ASSIGN4, 47662306a36Sopenharmony_ci CPCAP_BIT_VAUDIO_SEL, vaudio_val_tbl, 47762306a36Sopenharmony_ci 0x16, 0x1, 0x4, 0, 0), 47862306a36Sopenharmony_ci { /* sentinel */ }, 47962306a36Sopenharmony_ci}; 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_cistatic const struct of_device_id cpcap_regulator_id_table[] = { 48262306a36Sopenharmony_ci { 48362306a36Sopenharmony_ci .compatible = "motorola,cpcap-regulator", 48462306a36Sopenharmony_ci }, 48562306a36Sopenharmony_ci { 48662306a36Sopenharmony_ci .compatible = "motorola,mapphone-cpcap-regulator", 48762306a36Sopenharmony_ci .data = omap4_regulators, 48862306a36Sopenharmony_ci }, 48962306a36Sopenharmony_ci { 49062306a36Sopenharmony_ci .compatible = "motorola,xoom-cpcap-regulator", 49162306a36Sopenharmony_ci .data = xoom_regulators, 49262306a36Sopenharmony_ci }, 49362306a36Sopenharmony_ci {}, 49462306a36Sopenharmony_ci}; 49562306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, cpcap_regulator_id_table); 49662306a36Sopenharmony_ci 49762306a36Sopenharmony_cistatic int cpcap_regulator_probe(struct platform_device *pdev) 49862306a36Sopenharmony_ci{ 49962306a36Sopenharmony_ci struct cpcap_ddata *ddata; 50062306a36Sopenharmony_ci const struct cpcap_regulator *match_data; 50162306a36Sopenharmony_ci struct regulator_config config; 50262306a36Sopenharmony_ci int i; 50362306a36Sopenharmony_ci 50462306a36Sopenharmony_ci match_data = of_device_get_match_data(&pdev->dev); 50562306a36Sopenharmony_ci if (!match_data) { 50662306a36Sopenharmony_ci dev_err(&pdev->dev, "no configuration data found\n"); 50762306a36Sopenharmony_ci 50862306a36Sopenharmony_ci return -ENODEV; 50962306a36Sopenharmony_ci } 51062306a36Sopenharmony_ci 51162306a36Sopenharmony_ci ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); 51262306a36Sopenharmony_ci if (!ddata) 51362306a36Sopenharmony_ci return -ENOMEM; 51462306a36Sopenharmony_ci 51562306a36Sopenharmony_ci ddata->reg = dev_get_regmap(pdev->dev.parent, NULL); 51662306a36Sopenharmony_ci if (!ddata->reg) 51762306a36Sopenharmony_ci return -ENODEV; 51862306a36Sopenharmony_ci 51962306a36Sopenharmony_ci ddata->dev = &pdev->dev; 52062306a36Sopenharmony_ci ddata->soc = match_data; 52162306a36Sopenharmony_ci platform_set_drvdata(pdev, ddata); 52262306a36Sopenharmony_ci 52362306a36Sopenharmony_ci memset(&config, 0, sizeof(config)); 52462306a36Sopenharmony_ci config.dev = &pdev->dev; 52562306a36Sopenharmony_ci config.regmap = ddata->reg; 52662306a36Sopenharmony_ci 52762306a36Sopenharmony_ci for (i = 0; i < CPCAP_NR_REGULATORS; i++) { 52862306a36Sopenharmony_ci const struct cpcap_regulator *regulator = &ddata->soc[i]; 52962306a36Sopenharmony_ci struct regulator_dev *rdev; 53062306a36Sopenharmony_ci 53162306a36Sopenharmony_ci if (!regulator->rdesc.name) 53262306a36Sopenharmony_ci break; 53362306a36Sopenharmony_ci 53462306a36Sopenharmony_ci if (regulator->rdesc.volt_table == unknown_val_tbl) 53562306a36Sopenharmony_ci continue; 53662306a36Sopenharmony_ci 53762306a36Sopenharmony_ci config.driver_data = (void *)regulator; 53862306a36Sopenharmony_ci rdev = devm_regulator_register(&pdev->dev, 53962306a36Sopenharmony_ci ®ulator->rdesc, 54062306a36Sopenharmony_ci &config); 54162306a36Sopenharmony_ci if (IS_ERR(rdev)) { 54262306a36Sopenharmony_ci dev_err(&pdev->dev, "failed to register regulator %s\n", 54362306a36Sopenharmony_ci regulator->rdesc.name); 54462306a36Sopenharmony_ci 54562306a36Sopenharmony_ci return PTR_ERR(rdev); 54662306a36Sopenharmony_ci } 54762306a36Sopenharmony_ci } 54862306a36Sopenharmony_ci 54962306a36Sopenharmony_ci return 0; 55062306a36Sopenharmony_ci} 55162306a36Sopenharmony_ci 55262306a36Sopenharmony_cistatic struct platform_driver cpcap_regulator_driver = { 55362306a36Sopenharmony_ci .probe = cpcap_regulator_probe, 55462306a36Sopenharmony_ci .driver = { 55562306a36Sopenharmony_ci .name = "cpcap-regulator", 55662306a36Sopenharmony_ci .probe_type = PROBE_PREFER_ASYNCHRONOUS, 55762306a36Sopenharmony_ci .of_match_table = of_match_ptr(cpcap_regulator_id_table), 55862306a36Sopenharmony_ci }, 55962306a36Sopenharmony_ci}; 56062306a36Sopenharmony_ci 56162306a36Sopenharmony_cimodule_platform_driver(cpcap_regulator_driver); 56262306a36Sopenharmony_ci 56362306a36Sopenharmony_ciMODULE_ALIAS("platform:cpcap-regulator"); 56462306a36Sopenharmony_ciMODULE_AUTHOR("Tony Lindgren <tony@atomide.com>"); 56562306a36Sopenharmony_ciMODULE_DESCRIPTION("CPCAP regulator driver"); 56662306a36Sopenharmony_ciMODULE_LICENSE("GPL v2"); 567