static int bmp18x_config_regulator(struct i2c_client *client, bool on)
{
	int rc = 0, i;
	int num_vreg = ARRAY_SIZE(bmp_vreg);

	if (on) {
		for (i = 0; i < num_vreg; i++) {
			bmp_vreg[i].vreg = regulator_get(&client->dev,
					bmp_vreg[i].name);
			if (IS_ERR(bmp_vreg[i].vreg)) {
				rc = PTR_ERR(bmp_vreg[i].vreg);
				dev_err(&client->dev, "%s:regulator get failed rc=%d\n",
						__func__, rc);
				bmp_vreg[i].vreg = NULL;
				goto error_vdd;
			}
			if (regulator_count_voltages(bmp_vreg[i].vreg) > 0) {
				rc = regulator_set_voltage(bmp_vreg[i].vreg,
					bmp_vreg[i].min_uV, bmp_vreg[i].max_uV);
				if (rc) {
					dev_err(&client->dev, "%s:set_voltage failed rc=%d\n",
							__func__, rc);
					regulator_put(bmp_vreg[i].vreg);
					bmp_vreg[i].vreg = NULL;
					goto error_vdd;
				}
			}
			rc = regulator_enable(bmp_vreg[i].vreg);
			if (rc) {
				dev_err(&client->dev, "%s: regulator_enable failed rc =%d\n",
						__func__, rc);
				if (regulator_count_voltages(bmp_vreg[i].vreg)
						> 0) {
					regulator_set_voltage(bmp_vreg[i].vreg,
							0, bmp_vreg[i].max_uV);
				}
				regulator_put(bmp_vreg[i].vreg);
				bmp_vreg[i].vreg = NULL;
				goto error_vdd;
			}
		}
		return rc;
	} else {
		i = num_vreg;
	}
error_vdd:
	while (--i >= 0) {
		if (!IS_ERR_OR_NULL(bmp_vreg[i].vreg)) {
			if (regulator_count_voltages(
				bmp_vreg[i].vreg) > 0) {
				regulator_set_voltage(bmp_vreg[i].vreg, 0,
						bmp_vreg[i].max_uV);
			}
			regulator_disable(bmp_vreg[i].vreg);
			regulator_put(bmp_vreg[i].vreg);
			bmp_vreg[i].vreg = NULL;
		}
	}
	return rc;
}
static int max98504_regulator_config(struct i2c_client *i2c, bool pullup, bool on)
{
	int rc;
    #define VCC_I2C_MIN_UV	1800000
    #define VCC_I2C_MAX_UV	1800000
	#define I2C_LOAD_UA		300000

	//pr_info("[RYAN] %s\n", __func__);

	if (pullup) {
		//pr_info("[RYAN] %s I2C PULL UP.\n", __func__);

		max98504_vcc_i2c = regulator_get(&i2c->dev, "vcc_i2c");
		if (IS_ERR(max98504_vcc_i2c)) {
			rc = PTR_ERR(max98504_vcc_i2c);
			pr_info("Regulator get failed rc=%d\n",	rc);
			goto error_get_vtg_i2c;
		}
		if (regulator_count_voltages(max98504_vcc_i2c) > 0) {
			rc = regulator_set_voltage(max98504_vcc_i2c,
				VCC_I2C_MIN_UV, VCC_I2C_MAX_UV);
			if (rc) {
				pr_info("regulator set_vtg failed rc=%d\n", rc);
				goto error_set_vtg_i2c;
			}
		}

		rc = reg_set_optimum_mode_check(max98504_vcc_i2c, I2C_LOAD_UA);
		if (rc < 0) {
			pr_info("Regulator vcc_i2c set_opt failed rc=%d\n", rc);
			goto error_reg_opt_i2c;
		}
		
		rc = regulator_enable(max98504_vcc_i2c);
		if (rc) {
			pr_info("Regulator vcc_i2c enable failed rc=%d\n", rc);
			goto error_reg_en_vcc_i2c;
		}

	}
	//pr_info("[RYAN] %s OUT\n", __func__);

	return 0;

error_reg_en_vcc_i2c:
	if(pullup) reg_set_optimum_mode_check(max98504_vcc_i2c, 0);
error_reg_opt_i2c:
	regulator_disable(max98504_vcc_i2c);
error_set_vtg_i2c:
	if (regulator_count_voltages(max98504_vcc_i2c) > 0)
		regulator_set_voltage(max98504_vcc_i2c, 0,
			VCC_I2C_MAX_UV);
error_get_vtg_i2c:
	regulator_put(max98504_vcc_i2c);

	//pr_info("[RYAN] %s OUT WITH ERROR.\n", __func__);


	return rc;
}
static int mma8x5x_config_regulator(struct i2c_client *client, bool on)
{
	int rc = 0, i;
	int num_vreg = sizeof(mma_vreg)/sizeof(struct sensor_regulator);

	if (on) {
		for (i = 0; i < num_vreg; i++) {
			mma_vreg[i].vreg = regulator_get(&client->dev,
					mma_vreg[i].name);
			if (IS_ERR(mma_vreg[i].vreg)) {
				rc = PTR_ERR(mma_vreg[i].vreg);
				dev_err(&client->dev, "%s:regulator get failed rc=%d\n",
						__func__, rc);
				mma_vreg[i].vreg = NULL;
				goto error_vdd;
			}
			if (regulator_count_voltages(mma_vreg[i].vreg) > 0) {
				rc = regulator_set_voltage(mma_vreg[i].vreg,
					mma_vreg[i].min_uV, mma_vreg[i].max_uV);
				if (rc) {
					dev_err(&client->dev, "%s:set_voltage failed rc=%d\n",
							__func__, rc);
					regulator_put(mma_vreg[i].vreg);
					mma_vreg[i].vreg = NULL;
					goto error_vdd;
				}
			}
			rc = regulator_enable(mma_vreg[i].vreg);
			if (rc) {
				dev_err(&client->dev, "%s: regulator_enable failed rc =%d\n",
						__func__, rc);
				if (regulator_count_voltages(mma_vreg[i].vreg)
						> 0) {
					regulator_set_voltage(mma_vreg[i].vreg,
							0, mma_vreg[i].max_uV);
				}
				regulator_put(mma_vreg[i].vreg);
				mma_vreg[i].vreg = NULL;
				goto error_vdd;
			}
		}
		return rc;
	} else {
		i = num_vreg;
	}
error_vdd:
	while (--i >= 0) {
		if (!IS_ERR_OR_NULL(mma_vreg[i].vreg)) {
			if (regulator_count_voltages(
				mma_vreg[i].vreg) > 0) {
				regulator_set_voltage(mma_vreg[i].vreg, 0,
						mma_vreg[i].max_uV);
			}
			regulator_disable(mma_vreg[i].vreg);
			regulator_put(mma_vreg[i].vreg);
			mma_vreg[i].vreg = NULL;
		}
	}
	return rc;
}
static int capsensor_power_init(struct device *dev, bool on)
{
	int rc;

	if (!on) {
		if (regulator_count_voltages(g_capsensor_pdata->vdd) > 0)
			regulator_set_voltage(g_capsensor_pdata->vdd, 0, CAP_VDD_MAX_UV);

		regulator_put(g_capsensor_pdata->vdd);

	} else {
		g_capsensor_pdata->vdd = regulator_get(dev, "vdd");
		if (IS_ERR(g_capsensor_pdata->vdd)) {
			rc = PTR_ERR(g_capsensor_pdata->vdd);
			printk(KERN_ERR"Regulator get failed vdd rc=%d\n", rc);
			return rc;
		}

		if (regulator_count_voltages(g_capsensor_pdata->vdd) > 0) {
			rc = regulator_set_voltage(g_capsensor_pdata->vdd, CAP_VDD_MIN_UV,
						   CAP_VDD_MAX_UV);
			if (rc) {
				printk(KERN_ERR"Regulator set failed vdd rc=%d\n",rc);
				goto reg_vdd_put;
			}
		}
	}

	return 0;

reg_vdd_put:
	regulator_put(g_capsensor_pdata->vdd);
	return rc;
}
static int max98506_regulator_config(struct device *dev)
{
	struct regulator *max98506_vcc_i2c;
	int ret;

	max98506_vcc_i2c = regulator_get(dev, "vcc_i2c");
	if (IS_ERR(max98506_vcc_i2c)) {
		ret = PTR_ERR(max98506_vcc_i2c);
		dev_err(dev, "%s: regulator get failed ret=%d\n",
				__func__, ret);
		goto err_get_vtg_i2c;
	}
	if (regulator_count_voltages(max98506_vcc_i2c) > 0) {
		ret = regulator_set_voltage(max98506_vcc_i2c,
				VCC_I2C_MIN_UV, VCC_I2C_MAX_UV);
		if (ret) {
			dev_err(dev, "%s: regulator set_vtg failed ret=%d\n",
					__func__, ret);
			goto err_set_vtg_i2c;
		}
	}

	ret = reg_set_optimum_mode_check(max98506_vcc_i2c, I2C_LOAD_UA);
	if (ret < 0) {
		dev_err(dev, "%s: regulator vcc_i2c set_opt failed ret=%d\n",
				__func__, ret);
		goto err_reg_opt_i2c;
	}

	ret = regulator_enable(max98506_vcc_i2c);
	if (ret) {
		dev_err(dev, "%s: regulator vcc_i2c enable failed ret=%d\n",
				__func__, ret);
		goto err_reg_en_vcc_i2c;
	}

	msg_maxim("min_uv:%d max_uv:%d load_ua:%d",
		VCC_I2C_MIN_UV, VCC_I2C_MAX_UV, I2C_LOAD_UA);

	return 0;

err_set_vtg_i2c:
	regulator_put(max98506_vcc_i2c);

err_get_vtg_i2c:
	if (regulator_count_voltages(max98506_vcc_i2c) > 0)
		regulator_set_voltage(max98506_vcc_i2c, 0, VCC_I2C_MAX_UV);

err_reg_en_vcc_i2c:
	reg_set_optimum_mode_check(max98506_vcc_i2c, 0);

err_reg_opt_i2c:
	regulator_disable(max98506_vcc_i2c);

	return ret;
}
static int drv2667_vreg_config(struct drv2667_data *data, bool on)
{
	int rc = 0;

	if (!on)
		goto deconfig_vreg;

	data->vdd = regulator_get(&data->client->dev, "vdd");
	if (IS_ERR(data->vdd)) {
		rc = PTR_ERR(data->vdd);
		dev_err(&data->client->dev, "unable to request vdd\n");
		return rc;
	}

	if (regulator_count_voltages(data->vdd) > 0) {
		rc = regulator_set_voltage(data->vdd,
				DRV2667_VTG_MIN_UV, DRV2667_VTG_MAX_UV);
		if (rc < 0) {
			dev_err(&data->client->dev,
				"vdd set voltage failed(%d)\n", rc);
			goto put_vdd;
		}
	}

	data->vdd_i2c = regulator_get(&data->client->dev, "vdd-i2c");
	if (IS_ERR(data->vdd_i2c)) {
		rc = PTR_ERR(data->vdd_i2c);
		dev_err(&data->client->dev, "unable to request vdd for i2c\n");
		goto reset_vdd_volt;
	}

	if (regulator_count_voltages(data->vdd_i2c) > 0) {
		rc = regulator_set_voltage(data->vdd_i2c,
			DRV2667_I2C_VTG_MIN_UV, DRV2667_I2C_VTG_MAX_UV);
		if (rc < 0) {
			dev_err(&data->client->dev,
				"vdd_i2c set voltage failed(%d)\n", rc);
			goto put_vdd_i2c;
		}
	}

	return rc;

deconfig_vreg:
	if (regulator_count_voltages(data->vdd_i2c) > 0)
		regulator_set_voltage(data->vdd_i2c, 0, DRV2667_I2C_VTG_MAX_UV);
put_vdd_i2c:
	regulator_put(data->vdd_i2c);
reset_vdd_volt:
	if (regulator_count_voltages(data->vdd) > 0)
		regulator_set_voltage(data->vdd, 0, DRV2667_VTG_MAX_UV);
put_vdd:
	regulator_put(data->vdd);
	return rc;
}
int anx7816_regulator_configure(
	struct device *dev, struct anx7816_platform_data *pdata)
{
	int rc = 0;
/* To do : regulator control after H/W change */
#if 0
	pdata->avdd_33 = regulator_get(dev, "analogix,vdd_ana");

	pr_err("anx test ");
	if (IS_ERR(pdata->avdd_33)) {
		rc = PTR_ERR(pdata->avdd_33);
		pr_err("%s : Regulator get failed avdd_33 rc=%d\n",
			   __func__, rc);
		return rc;
	}

	if (regulator_count_voltages(pdata->avdd_33) > 0) {
		rc = regulator_set_voltage(pdata->avdd_33, 3300000,
							3300000);
		if (rc) {
			pr_err("%s : Regulator set_vtg failed rc=%d\n",
				   __func__, rc);
			goto error_set_vtg_avdd_33;
		}
	}
#endif

	pdata->dvdd_10 = regulator_get(dev, "analogix,vdd_dig");
	if (IS_ERR(pdata->dvdd_10)) {
		rc = PTR_ERR(pdata->dvdd_10);
		pr_err("%s : Regulator get failed dvdd_10 rc=%d\n",
			   __func__, rc);
		return rc;
	}

	if (regulator_count_voltages(pdata->dvdd_10) > 0) {
		rc = regulator_set_voltage(pdata->dvdd_10, 1000000,
							1000000);
		if (rc) {
			pr_err("%s : Regulator set_vtg failed rc=%d\n",
				   __func__, rc);
			goto error_set_vtg_dvdd_10;
		}
	}

	return 0;

error_set_vtg_dvdd_10:
	regulator_put(pdata->dvdd_10);
#if 0
error_set_vtg_avdd_33:
	regulator_put(pdata->avdd_33);
#endif
	return rc;
}
static int mpu6050_power_init(struct platform_device *pdev)
{
	int ret = 0;

	sms_pwr_ctrl->vdd_io = regulator_get(&pdev->dev, "vdd-io");
	if (IS_ERR(sms_pwr_ctrl->vdd_io)) {
		ret = PTR_ERR(sms_pwr_ctrl->vdd_io);
		dev_err(&pdev->dev,
			"Regulator get failed vdd io ret=%d\n", ret);
		goto error;
	}

	if (regulator_count_voltages(sms_pwr_ctrl->vdd_io) > 0) {
		ret = regulator_set_voltage(sms_pwr_ctrl->vdd_io,
				SMS4470_VDD_IO_MIN_UV,
				SMS4470_VDD_IO_MAX_UV);
		if (ret) {
			dev_err(&pdev->dev,
			"Regulator set_vtg failed vdd_io ret=%d\n", ret);
			goto reg_vddio_put;
		}
	}

	sms_pwr_ctrl->vdd_emi= regulator_get(&&pdev->dev, "vdd-emi");
	if (IS_ERR(sms_pwr_ctrl->vdd_emi)) {
		ret = PTR_ERR(sms_pwr_ctrl->vdd_emi);
		dev_err(&pdev->dev,
			"Regulator get failed vdd io ret=%d\n", ret);
		goto reg_vddio_set_vtg;
	}

	if (regulator_count_voltages(sms_pwr_ctrl->vdd_emi) > 0) {
		ret = regulator_set_voltage(sms_pwr_ctrl->vdd_emi,
				SMS4470_VDD_IO_MIN_UV,
				SMS4470_VDD_IO_MAX_UV);
		if (ret) {
			dev_err(&pdev->dev,
			"Regulator set_vtg failed vdd_emi ret=%d\n", ret);
			goto reg_vddemi_put;
		}
	}

	return 0;

reg_vddemi_put:
	regulator_put(sms_power_ctrl->vdd_emi);
reg_vddio_set_vtg:
	if (regulator_count_voltages(sms_power_ctrl->vdd_io) > 0)
		regulator_set_voltage(sms_power_ctrl->vdd_io, 0, SMS4470_VDD_IO_MAX_UV);
reg_vddio_put:
	regulator_put(sms_power_ctrl->vdd_io);	
	return ret;
}
int fpc1020_io_regulator_configure(struct fpc1020_data *fpc1020)
{
	int error = 0;

	dev_dbg(&fpc1020->spi->dev, "%s\n", __func__);

	fpc1020->vdd_io = regulator_get(&fpc1020->spi->dev, "vdd_io");
	if (IS_ERR(fpc1020->vdd_io)) {
		error = PTR_ERR(fpc1020->vdd_io);
		dev_err(&fpc1020->spi->dev,
			"vdd_io get failed, error=%d\n", error);
		goto supply_err;
	}

	if (regulator_count_voltages(fpc1020->vdd_io) > 0) {
		error = regulator_set_voltage(fpc1020->vdd_io,
						SUPPLY_TX_MIN, SUPPLY_TX_MAX);
		if (error) {
			dev_err(&fpc1020->spi->dev,
				"vdd_io set(tx) failed, error=%d\n", error);
			goto supply_err;
		}
	}
	return 0;

supply_err:
	fpc1020_io_regulator_release(fpc1020);
	return error;
}
Example #10
0
static int ufs_qcom_phy_cfg_vreg(struct device *dev,
                                 struct ufs_qcom_phy_vreg *vreg, bool on)
{
    int ret = 0;
    struct regulator *reg = vreg->reg;
    const char *name = vreg->name;
    int min_uV;
    int uA_load;

    if (regulator_count_voltages(reg) > 0) {
        min_uV = on ? vreg->min_uV : 0;
        ret = regulator_set_voltage(reg, min_uV, vreg->max_uV);
        if (ret) {
            dev_err(dev, "%s: %s set voltage failed, err=%d\n",
                    __func__, name, ret);
            goto out;
        }
        uA_load = on ? vreg->max_uA : 0;
        ret = regulator_set_load(reg, uA_load);
        if (ret >= 0) {
            /*
             * regulator_set_load() returns new regulator
             * mode upon success.
             */
            ret = 0;
        } else {
            dev_err(dev, "%s: %s set optimum mode(uA_load=%d) failed, err=%d\n",
                    __func__, name, uA_load, ret);
            goto out;
        }
    }
out:
    return ret;
}
Example #11
0
static int pmu_enable(void)
{
	int rc = 0;

	pn544_dev->vdd = regulator_get(&pn544_dev->client->dev, "vdd");
	if (IS_ERR(pn544_dev->vdd)) {
		rc = PTR_ERR(pn544_dev->vdd);
		printk("Regulator get failed vdd rc=%d\n", rc);
		return rc;
	}else{
		if (regulator_count_voltages(pn544_dev->vdd) > 0) {
		rc = regulator_set_voltage(pn544_dev->vdd,
				PMU_VDD_VALUE, PMU_VDD_VALUE);
		if (rc) {
			printk("Regulator set failed vdd rc=%d\n",
				rc);
			goto reg_vdd_put;
			}
		}

	rc = regulator_enable(pn544_dev->vdd);
	if (rc) {
	printk(
		"Regulator enable vdd failed. rc=%d\n", rc);
	goto reg_vdd_put;
	}
   }
	return 0;

reg_vdd_put:
	regulator_put(pn544_dev->vdd);
	return rc;
}
Example #12
0
static int __ufs_qcom_phy_init_vreg(struct device *dev,
                                    struct ufs_qcom_phy_vreg *vreg, const char *name, bool optional)
{
    int err = 0;

    char prop_name[MAX_PROP_NAME];

    vreg->name = devm_kstrdup(dev, name, GFP_KERNEL);
    if (!vreg->name) {
        err = -ENOMEM;
        goto out;
    }

    vreg->reg = devm_regulator_get(dev, name);
    if (IS_ERR(vreg->reg)) {
        err = PTR_ERR(vreg->reg);
        vreg->reg = NULL;
        if (!optional)
            dev_err(dev, "failed to get %s, %d\n", name, err);
        goto out;
    }

    if (dev->of_node) {
        snprintf(prop_name, MAX_PROP_NAME, "%s-max-microamp", name);
        err = of_property_read_u32(dev->of_node,
                                   prop_name, &vreg->max_uA);
        if (err && err != -EINVAL) {
            dev_err(dev, "%s: failed to read %s\n",
                    __func__, prop_name);
            goto out;
        } else if (err == -EINVAL || !vreg->max_uA) {
            if (regulator_count_voltages(vreg->reg) > 0) {
                dev_err(dev, "%s: %s is mandatory\n",
                        __func__, prop_name);
                goto out;
            }
            err = 0;
        }
        snprintf(prop_name, MAX_PROP_NAME, "%s-always-on", name);
        vreg->is_always_on = of_property_read_bool(dev->of_node,
                             prop_name);
    }

    if (!strcmp(name, "vdda-pll")) {
        vreg->max_uV = VDDA_PLL_MAX_UV;
        vreg->min_uV = VDDA_PLL_MIN_UV;
    } else if (!strcmp(name, "vdda-phy")) {
        vreg->max_uV = VDDA_PHY_MAX_UV;
        vreg->min_uV = VDDA_PHY_MIN_UV;
    } else if (!strcmp(name, "vddp-ref-clk")) {
        vreg->max_uV = VDDP_REF_CLK_MAX_UV;
        vreg->min_uV = VDDP_REF_CLK_MIN_UV;
    }

out:
    if (err)
        kfree(vreg->name);
    return err;
}
static int tpiu_reg_set_voltage(struct regulator *reg, unsigned int reg_low,
				unsigned int reg_high)
{
	if (regulator_count_voltages(reg) <= 0)
		return 0;

	return regulator_set_voltage(reg, reg_low, reg_high);
}
static int tpiu_reg_set_optimum_mode(struct regulator *reg,
				     unsigned int reg_hpm)
{
	if (regulator_count_voltages(reg) <= 0)
		return 0;

	return regulator_set_optimum_mode(reg, reg_hpm);
}
static int vreg_setup(struct fpc1020_data *fpc1020, const char *name,
	bool enable)
{
	size_t i;
	int rc;
	struct regulator *vreg;
	struct device *dev = fpc1020->dev;

	for (i = 0; i < ARRAY_SIZE(fpc1020->vreg); i++) {
		const char *n = vreg_conf[i].name;
		if (!strncmp(n, name, strlen(n)))
			goto found;
	}
	dev_err(dev, "Regulator %s not found\n", name);
	return -EINVAL;
found:
	vreg = fpc1020->vreg[i];
	if (enable) {
		if (!vreg) {
			vreg = regulator_get(dev, name);
			if (!vreg) {
				dev_err(dev, "Unable to get  %s\n", name);
				return -ENODEV;
			}
		}
		if (regulator_count_voltages(vreg) > 0) {
			rc = regulator_set_voltage(vreg, vreg_conf[i].vmin,
					vreg_conf[i].vmax);
			if (rc)
				dev_err(dev,
					"Unable to set voltage on %s, %d\n",
					name, rc);
		}
		rc = regulator_set_optimum_mode(vreg, vreg_conf[i].ua_load);
		if (rc < 0)
			dev_err(dev, "Unable to set current on %s, %d\n",
					name, rc);
		rc = regulator_enable(vreg);
		if (rc) {
			dev_err(dev, "error enabling %s: %d\n", name, rc);
			regulator_put(vreg);
			vreg = NULL;
		}
		fpc1020->vreg[i] = vreg;
	} else {
		if (vreg) {
			if (regulator_is_enabled(vreg)) {
				regulator_disable(vreg);
				dev_dbg(dev, "disabled %s\n", name);
			}
			regulator_put(vreg);
			fpc1020->vreg[i] = NULL;
		}
		rc = 0;
	}
	return rc;
}
static int max98504_regulator_config(struct i2c_client *i2c,
	bool pullup, bool on)
{
	struct regulator *max98504_vcc_i2c;
	int rc;
	#define VCC_I2C_MIN_UV 1800000
	#define VCC_I2C_MAX_UV 1800000
	#define I2C_LOAD_UA 300000

	msg_maxim("pullup=%d\n", pullup);

	if (pullup) {
		max98504_vcc_i2c = regulator_get(&i2c->dev, "vcc_i2c");

		if (IS_ERR(max98504_vcc_i2c)) {
			rc = PTR_ERR(max98504_vcc_i2c);
			pr_err("Regulator get failed rc=%d\n",	rc);
			return rc;
		}

		if (regulator_count_voltages(max98504_vcc_i2c) > 0) {
			rc = regulator_set_voltage(max98504_vcc_i2c,
				VCC_I2C_MIN_UV, VCC_I2C_MAX_UV);
			if (rc) {
				pr_err("regulator set_vtg failed rc=%d\n", rc);
				goto error_set_vtg_i2c;
			}
		}

		rc = reg_set_optimum_mode_check(max98504_vcc_i2c, I2C_LOAD_UA);
		if (rc < 0) {
			pr_err("Regulator vcc_i2c set_opt failed rc=%d\n", rc);
			goto error_reg_opt_i2c;
		}

		rc = regulator_enable(max98504_vcc_i2c);
		if (rc) {
			pr_err("Regulator vcc_i2c enable failed rc=%d\n", rc);
			goto error_reg_en_vcc_i2c;
		}
	}

	return 0;

error_reg_en_vcc_i2c:
	if (pullup)
		reg_set_optimum_mode_check(max98504_vcc_i2c, 0);
error_reg_opt_i2c:
	regulator_disable(max98504_vcc_i2c);
error_set_vtg_i2c:
	regulator_put(max98504_vcc_i2c);

	return rc;
}
static int cw_bat_regulator_configure(struct cw_battery *cw_bat, bool on)
{
	int retval;

	if (on == false)
		goto hw_shutdown;

	cw_bat->vcc_i2c = regulator_get(&cw_bat->client->dev,
			"vcc_i2c");
	if (IS_ERR(cw_bat->vcc_i2c)) {
		dev_err(&cw_bat->client->dev,
				"%s: Failed to get i2c regulator\n",
				__func__);
		retval = PTR_ERR(cw_bat->vcc_i2c);
		goto hw_shutdown;
	}

	if (regulator_count_voltages(cw_bat->vcc_i2c) > 0) {
		retval = regulator_set_voltage(cw_bat->vcc_i2c,
			CW_I2C_VTG_MIN_UV, CW_I2C_VTG_MAX_UV);
		if (retval) {
			dev_err(&cw_bat->client->dev,
				"%s reg set i2c vtg failed retval =%d\n", __func__,
				retval);
		goto err_set_vtg_i2c;
		}
	}
	return 0;

err_set_vtg_i2c:
	regulator_put(cw_bat->vcc_i2c);

hw_shutdown:
	if (regulator_count_voltages(cw_bat->vcc_i2c) > 0)
		regulator_set_voltage(cw_bat->vcc_i2c, 0,
				CW_I2C_VTG_MAX_UV);
	regulator_put(cw_bat->vcc_i2c);

	return 0;
};
static inline int led_regulator_get_max_brightness(struct regulator *supply)
{
	int ret;
	int voltage = regulator_list_voltage(supply, 0);

	if (voltage <= 0)
		return 1;

	ret = regulator_set_voltage(supply, voltage, voltage);
	if (ret < 0)
		return 1;

	return regulator_count_voltages(supply);
}
static int hall_config_regulator(struct platform_device *dev, bool on)
{
	struct hall_data *data = dev_get_drvdata(&dev->dev);
	int rc = 0;

	if (on) {
		data->vddio = devm_regulator_get(&dev->dev, "vddio");
		if (IS_ERR(data->vddio)) {
			rc = PTR_ERR(data->vddio);
			dev_err(&dev->dev, "Regulator vddio get failed rc=%d\n",
					rc);
			data->vddio = NULL;
			return rc;
		}

		if (regulator_count_voltages(data->vddio) > 0) {
			rc = regulator_set_voltage(
					data->vddio,
					data->min_uv,
					data->max_uv);
			if (rc) {
				dev_err(&dev->dev, "Regulator vddio Set voltage failed rc=%d\n",
						rc);
				goto deinit_vregs;
			}
		}
		return rc;
	} else {
		goto deinit_vregs;
	}

deinit_vregs:
	if (regulator_count_voltages(data->vddio) > 0)
		regulator_set_voltage(data->vddio, 0, data->max_uv);

	return rc;
}
Example #20
0
static int msm_sata_vreg_get_enable_set_vdd(struct device *dev,
			const char *name, struct regulator **out_vreg,
			int min_uV, int max_uV, int hpm_uA)
{
	int ret = 0;
	struct regulator *vreg;

	vreg = devm_regulator_get(dev, name);
	if (IS_ERR(vreg)) {
		ret = PTR_ERR(vreg);
		dev_err(dev, "Regulator: %s get failed, err=%d\n", name, ret);
		goto out;
	}

	if (regulator_count_voltages(vreg) > 0) {
		ret = regulator_set_voltage(vreg, min_uV, max_uV);
		if (ret) {
			dev_err(dev, "Regulator: %s set voltage failed, err=%d\n",
					name, ret);
			goto err;
		}

		ret = regulator_set_optimum_mode(vreg, hpm_uA);
		if (ret < 0) {
			dev_err(dev, "Regulator: %s set optimum mode(uA_load=%d) failed, err=%d\n",
					name, hpm_uA, ret);
			goto err;
		} else {
			/*
			 * regulator_set_optimum_mode() can return non zero
			 * value even for success case.
			 */
			ret = 0;
		}
	}

	ret = regulator_enable(vreg);
	if (ret)
		dev_err(dev, "Regulator: %s enable failed, err=%d\n",
				name, ret);
err:
	if (!ret)
		*out_vreg = vreg;
	else
		devm_regulator_put(vreg);
out:
	return ret;
}
static int lcd_avdd_power_init(struct lcd_avdd_data *chip)
{
    struct i2c_client *client = chip->client;
    int ret = 0;

    chip->vcc_i2c = regulator_get(&client->dev, "vcc_i2c");
	if (IS_ERR(chip->vcc_i2c ))
	{
		ret = PTR_ERR(chip->vcc_i2c );
		LOG_ERROR("Regulator get failed ret=%d\n", ret);
	}

    if (regulator_count_voltages(chip->vcc_i2c ) > 0)
    {
        ret = regulator_set_voltage(chip->vcc_i2c , 1800000, 1800000);
        if (ret)
        {
            LOG_ERROR("Regulator set vcc_i2c_power failed ret=%d\n", ret);
            goto error_set_voltage;
        }
    }
    
    ret = regulator_set_optimum_mode(chip->vcc_i2c , 600000);
    if (ret < 0)
    {
        LOG_ERROR("Regulator vcc_i2c_power set_opt failed ret=%d\n", ret);
        goto error_set_optimum;
    }
       
	ret = regulator_enable(chip->vcc_i2c);
	if (ret)
    {
        LOG_ERROR("Regulator vcc_i2c enable failed ret=%d\n", ret);
    }
    return ret;

error_set_optimum:
    regulator_set_voltage(chip->vcc_i2c , 0, 1800000);
    regulator_put(chip->vcc_i2c );

error_set_voltage:
	regulator_put(chip->vcc_i2c );
    LOG_ERROR("failed\n");
	return ret;

}
Example #22
0
static inline int led_regulator_get_max_brightness(struct regulator *supply)
{
	int ret;
	int voltage = regulator_list_voltage(supply, 0);

	if (voltage <= 0)
		return 1;

	/* even if regulator can't change voltages,
	 * we still assume it can change status
	 * and the LED can be turned on and off.
	 */
	ret = regulator_set_voltage(supply, voltage, voltage);
	if (ret < 0)
		return 1;

	return regulator_count_voltages(supply);
}
Example #23
0
static int maxq616_power_init(struct maxq616_chip *chip)
{
	int rc;

    chip->power = regulator_get(&(chip->client->dev), "vdd-chip");

	if (IS_ERR(chip->power))
    {
		rc = PTR_ERR(chip->power);
		SENSOR_LOG_ERROR("Regulator get failed chip->power rc=%d\n", rc);
		return rc;
	}

	if (regulator_count_voltages(chip->power) > 0)
    {
		rc = regulator_set_voltage(chip->power, 1800000, 1800000);
		if (rc)
        {
			SENSOR_LOG_ERROR("Regulator set chip->power failed rc=%d\n", rc);
			goto error_set_voltage;
		}
	}
    
    rc = regulator_set_optimum_mode(chip->power, 600000);
    if (rc < 0)
    {
        SENSOR_LOG_ERROR("Regulator chip->power set_opt failed rc=%d\n", rc);
        goto error_set_optimum;
    }
    
    SENSOR_LOG_INFO("success\n");
    return 0;

error_set_optimum:
    regulator_set_voltage(chip->power, 0, 1800000);
    regulator_put(chip->power);

error_set_voltage:
	regulator_put(chip->power);
    SENSOR_LOG_INFO("failed\n");
	return rc;
}
Example #24
0
static int msm_sata_vreg_put_disable(struct device *dev,
		struct regulator *reg, const char *name, int max_uV)
{
	int ret;

	if (!reg)
		return 0;

	ret = regulator_disable(reg);
	if (ret) {
		dev_err(dev, "Regulator: %s disable failed err=%d\n",
				name, ret);
		goto err;
	}

	if (regulator_count_voltages(reg) > 0) {
		ret = regulator_set_voltage(reg, 0, max_uV);
		if (ret < 0) {
			dev_err(dev, "Regulator: %s set voltage to 0 failed, err=%d\n",
					name, ret);
			goto err;
		}

		ret = regulator_set_optimum_mode(reg, 0);
		if (ret < 0) {
			dev_err(dev, "Regulator: %s set optimum mode(uA_load = 0) failed, err=%d\n",
					name, ret);
			goto err;
		} else {
			/*
			 * regulator_set_optimum_mode() can return non zero
			 * value even for success case.
			 */
			ret = 0;
		}
	}

err:
	devm_regulator_put(reg);
	return ret;
}
static int bt_vreg_init(struct bt_power_vreg_data *vreg)
{
	int rc = 0;
	struct device *dev = &btpdev->dev;

	BT_PWR_DBG("vreg_get for : %s", vreg->name);

	/* Get the regulator handle */
	vreg->reg = regulator_get(dev, vreg->name);
	if (IS_ERR(vreg->reg)) {
		rc = PTR_ERR(vreg->reg);
		pr_err("%s: regulator_get(%s) failed. rc=%d\n",
			__func__, vreg->name, rc);
		goto out;
	}

	if ((regulator_count_voltages(vreg->reg) > 0)
			&& (vreg->low_vol_level) && (vreg->high_vol_level))
		vreg->set_voltage_sup = 1;

out:
	return rc;
}
Example #26
0
static int ath6kl_vreg_init(struct ath6kl_power_vreg_data *vreg)
{
	int rc = 0;
	struct device *dev = &(gpdata->pdev->dev);

	ath6kl_dbg(ATH6KL_DBG_BOOT, "vreg_get for : %s\n", vreg->name);

	/* Get the regulator handle */
	vreg->reg = regulator_get(dev, vreg->name);
	if (IS_ERR(vreg->reg)) {
		rc = PTR_ERR(vreg->reg);
		ath6kl_err("%s: regulator_get(%s) failed. rc=%d\n",
			__func__, vreg->name, rc);
		goto out;
	}

	if ((regulator_count_voltages(vreg->reg) > 0)
			&& (vreg->low_vol_level) && (vreg->high_vol_level))
		vreg->set_voltage_sup = 1;

out:
	return rc;
}
Example #27
0
/**
 * mmc_regulator_get_ocrmask - return mask of supported voltages
 * @supply: regulator to use
 *
 * This returns either a negative errno, or a mask of voltages that
 * can be provided to MMC/SD/SDIO devices using the specified voltage
 * regulator.  This would normally be called before registering the
 * MMC host adapter.
 */
int mmc_regulator_get_ocrmask(struct regulator *supply)
{
	int			result = 0;
	int			count;
	int			i;

	count = regulator_count_voltages(supply);
	if (count < 0)
		return count;

	for (i = 0; i < count; i++) {
		int		vdd_uV;
		int		vdd_mV;

		vdd_uV = regulator_list_voltage(supply, i);
		if (vdd_uV <= 0)
			continue;

		vdd_mV = vdd_uV / 1000;
		result |= mmc_vddrange_to_ocrmask(vdd_mV, vdd_mV);
	}

	return result;
}
static int __devinit pil_riva_probe(struct platform_device *pdev)
{
	struct riva_data *drv;
	struct resource *res;
	struct pil_desc *desc;
	int ret;

	drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
	if (!drv)
		return -ENOMEM;
	platform_set_drvdata(pdev, drv);


	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	drv->base = devm_request_and_ioremap(&pdev->dev, res);
	if (!drv->base)
		return -ENOMEM;

	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
	drv->cbase = devm_request_and_ioremap(&pdev->dev, res);
	if (!drv->cbase)
		return -ENOMEM;

	drv->pll_supply = devm_regulator_get(&pdev->dev, "pll_vdd");
	if (IS_ERR(drv->pll_supply)) {
		dev_err(&pdev->dev, "failed to get pll supply\n");
		return PTR_ERR(drv->pll_supply);
	}
	if (regulator_count_voltages(drv->pll_supply) > 0) {
		ret = regulator_set_voltage(drv->pll_supply, 1800000, 1800000);
		if (ret) {
			dev_err(&pdev->dev,
				"failed to set pll supply voltage\n");
			return ret;
		}

		ret = regulator_set_optimum_mode(drv->pll_supply, 100000);
		if (ret < 0) {
			dev_err(&pdev->dev,
				"failed to set pll supply optimum mode\n");
			return ret;
		}
	}

	drv->irq = platform_get_irq(pdev, 0);
	if (drv->irq < 0)
		return drv->irq;

	drv->xo = devm_clk_get(&pdev->dev, "cxo");
	if (IS_ERR(drv->xo))
		return PTR_ERR(drv->xo);

	desc = &drv->pil_desc;
	desc->name = "wcnss";
	desc->dev = &pdev->dev;
	desc->owner = THIS_MODULE;
	desc->proxy_timeout = 10000;

	if (pas_supported(PAS_WCNSS) > 0) {
		desc->ops = &pil_riva_ops_trusted;
		dev_info(&pdev->dev, "using secure boot\n");
	} else {
		desc->ops = &pil_riva_ops;
		dev_info(&pdev->dev, "using non-secure boot\n");
	}
	ret = pil_desc_init(desc);

	ret = smsm_state_cb_register(SMSM_WCNSS_STATE, SMSM_RESET,
					smsm_state_cb_hdlr, drv);
	if (ret < 0)
		goto err_smsm;

	drv->subsys_desc.name = "wcnss";
	drv->subsys_desc.dev = &pdev->dev;
	drv->subsys_desc.owner = THIS_MODULE;
	drv->subsys_desc.start = riva_start;
	drv->subsys_desc.stop = riva_stop;
	drv->subsys_desc.shutdown = riva_shutdown;
	drv->subsys_desc.powerup = riva_powerup;
	drv->subsys_desc.ramdump = riva_ramdump;
	drv->subsys_desc.crash_shutdown = riva_crash_shutdown;

	INIT_DELAYED_WORK(&drv->cancel_work, riva_post_bootup);

	drv->ramdump_dev = create_ramdump_device("riva", &pdev->dev);
	if (!drv->ramdump_dev) {
		ret = -ENOMEM;
		goto err_ramdump;
	}

	drv->subsys = subsys_register(&drv->subsys_desc);
	if (IS_ERR(drv->subsys)) {
		ret = PTR_ERR(drv->subsys);
		goto err_subsys;
	}

	scm_pas_init(MSM_BUS_MASTER_SPS);

	ret = devm_request_irq(&pdev->dev, drv->irq, riva_wdog_bite_irq_hdlr,
			IRQF_TRIGGER_RISING, "riva_wdog", drv);
	if (ret < 0)
		goto err;

	return 0;
err:
	subsys_unregister(drv->subsys);
err_subsys:
	destroy_ramdump_device(drv->ramdump_dev);
err_ramdump:
	smsm_state_cb_deregister(SMSM_WCNSS_STATE, SMSM_RESET,
					smsm_state_cb_hdlr, drv);
err_smsm:
	pil_desc_release(desc);
	return ret;
}
static void cypress_power_onoff(struct cypress_touchkey_info *info, int onoff)
{
	int ret = 0, rc = 0;

	dev_info(&info->client->dev, "%s: power %s\n",
			__func__, onoff ? "on" : "off");

	if (!info->vcc_en) {
		if (info->pdata->i2c_pull_up) {
			info->vcc_en = regulator_get(&info->client->dev,
				"vcc_en");
			if (IS_ERR(info->vcc_en)) {
				rc = PTR_ERR(info->vcc_en);
				dev_info(&info->client->dev,
					"Regulator(vcc_en) get failed rc=%d\n", rc);
				goto error_get_vtg_i2c;
			}
			if (regulator_count_voltages(info->vcc_en) > 0) {
				rc = regulator_set_voltage(info->vcc_en,
				1800000, 1800000);
				if (rc) {
					dev_info(&info->client->dev,
					"regulator(vcc_en) set_vtg failed rc=%d\n",
					rc);
					goto error_set_vtg_i2c;
				}
			}
		}
	}
	if (info->pdata->vdd_led < 0) {
		if (!info->vdd_led) {
			info->vdd_led = regulator_get(&info->client->dev,
				"vdd_led");
			if (IS_ERR(info->vdd_led)) {
				rc = PTR_ERR(info->vdd_led);
				dev_info(&info->client->dev,
					"Regulator(vdd_led) get failed rc=%d\n", rc);
				goto error_get_vtg_i2c;
			}
#if 0
			if (regulator_count_voltages(info->vdd_led) > 0) {
				rc = regulator_set_voltage(info->vdd_led,
				3300000, 3300000);
				if (rc) {
					dev_info(&info->client->dev,
					"regulator(vdd_led) set_vtg failed rc=%d\n",
					rc);
					goto error_set_vtg_i2c;
				}
			}
#endif
		}
	}
	if (onoff) {
		if (info->pdata->i2c_pull_up) {
			rc = reg_set_optimum_mode_check(info->vcc_en,
						10000);
			if (rc < 0) {
				dev_info(&info->client->dev,
				"Regulator vcc_en set_opt failed rc=%d\n",
				rc);
				goto error_reg_opt_i2c;
			}

			rc = regulator_enable(info->vcc_en);
			if (rc) {
				dev_info(&info->client->dev,
				"Regulator vcc_en enable failed rc=%d\n",
				rc);
				goto error_reg_en_vcc_en;
			}
			if (info->pdata->vdd_led < 0) {
				rc = reg_set_optimum_mode_check(info->vdd_led,
							10000);
				if (rc < 0) {
					dev_info(&info->client->dev,
					"Regulator vdd_led set_opt failed rc=%d\n",
					rc);
					goto error_reg_opt_i2c;
				}

				rc = regulator_enable(info->vdd_led);
				if (rc) {
					dev_info(&info->client->dev,
					"Regulator vdd_led enable failed rc=%d\n",
					rc);
					goto error_reg_en_vcc_en;
				}
			}
		}
	} else {
		if (info->pdata->i2c_pull_up) {
			reg_set_optimum_mode_check(info->vcc_en, 0);
			regulator_disable(info->vcc_en);
			if (info->pdata->vdd_led < 0) {
				reg_set_optimum_mode_check(info->vdd_led, 0);
				regulator_disable(info->vdd_led);
			}
		}
	}
	/*msleep(50);*/

	if (info->pdata->vdd_led > 0) {
		ret = gpio_direction_output(info->pdata->vdd_led, onoff);
		if (ret) {
			dev_info(&info->client->dev,
					"[TKEY]%s: unable to set_direction for vdd_led [%d]\n",
					__func__, info->pdata->vdd_led);
		}
		/*msleep(30);*/
	}
	return;

error_reg_en_vcc_en:
	if (info->pdata->i2c_pull_up) {
		reg_set_optimum_mode_check(info->vcc_en, 0);
		if (info->pdata->vdd_led < 0)
			reg_set_optimum_mode_check(info->vdd_led, 0);
	}
error_reg_opt_i2c:
error_set_vtg_i2c:
	regulator_put(info->vcc_en);
	if (info->pdata->vdd_led < 0)
		regulator_put(info->vdd_led);
error_get_vtg_i2c:
	return;
}
static int reg_set_optimum_mode_check(struct regulator *reg, int load_uA)
{
	return (regulator_count_voltages(reg) > 0) ?
		regulator_set_optimum_mode(reg, load_uA) : 0;
}