Esempio n. 1
0
static int veyron_init(void)
{
	struct udevice *dev;
	struct clk clk;
	int ret;

	ret = regulator_get_by_platname("vdd_arm", &dev);
	if (ret) {
		debug("Cannot set regulator name\n");
		return ret;
	}

	/* Slowly raise to max CPU voltage to prevent overshoot */
	ret = regulator_set_value(dev, 1200000);
	if (ret)
		return ret;
	udelay(175); /* Must wait for voltage to stabilize, 2mV/us */
	ret = regulator_set_value(dev, 1400000);
	if (ret)
		return ret;
	udelay(100); /* Must wait for voltage to stabilize, 2mV/us */

	ret = rockchip_get_clk(&clk.dev);
	if (ret)
		return ret;
	clk.id = PLL_APLL;
	ret = clk_set_rate(&clk, 1800000000);
	if (IS_ERR_VALUE(ret))
		return ret;

	ret = regulator_get_by_platname("vcc33_sd", &dev);
	if (ret) {
		debug("Cannot get regulator name\n");
		return ret;
	}

	ret = regulator_set_value(dev, 3300000);
	if (ret)
		return ret;

	ret = regulators_enable_boot_on(false);
	if (ret) {
		debug("%s: Cannot enable boot on regulators\n", __func__);
		return ret;
	}

	return 0;
}
Esempio n. 2
0
static int veyron_init(void)
{
	struct udevice *dev;
	struct clk clk;
	int ret;

	ret = regulator_get_by_platname("vdd_arm", &dev);
	if (ret)
		return ret;

	/* Slowly raise to max CPU voltage to prevent overshoot */
	ret = regulator_set_value(dev, 1200000);
	if (ret)
		return ret;
	udelay(175); /* Must wait for voltage to stabilize, 2mV/us */
	ret = regulator_set_value(dev, 1400000);
	if (ret)
		return ret;
	udelay(100); /* Must wait for voltage to stabilize, 2mV/us */

	ret = rockchip_get_clk(&clk.dev);
	if (ret)
		return ret;
	clk.id = PLL_APLL;
	ret = clk_set_rate(&clk, 1800000000);
	if (IS_ERR_VALUE(ret))
		return ret;

	return 0;
}
Esempio n. 3
0
/**
 * Switch power at an external regulator (for our root hub).
 *
 * @param ctrl pointer to the xHCI controller
 * @param port port number as in the control message (one-based)
 * @param enable boolean indicating whether to enable or disable power
 * @return returns 0 on success, an error-code on failure
 */
static int board_usb_port_power_set(struct udevice *dev, int port,
				    bool enable)
{
#if CONFIG_IS_ENABLED(OF_CONTROL) && CONFIG_IS_ENABLED(DM_REGULATOR)
	/* We start counting ports at 0, while USB counts from 1. */
	int index = port - 1;
	const char *regname = NULL;
	struct udevice *regulator;
	const char *prop = "tsd,usb-port-power";
	int ret;

	debug("%s: ctrl '%s' port %d enable %s\n", __func__,
	      dev_read_name(dev), port, enable ? "true" : "false");

	ret = dev_read_string_index(dev, prop, index, &regname);
	if (ret < 0) {
		debug("%s: ctrl '%s' port %d: no entry in '%s'\n",
		      __func__, dev_read_name(dev), port, prop);
		return ret;
	}

	ret = regulator_get_by_platname(regname, &regulator);
	if (ret) {
		debug("%s: ctrl '%s' port %d: could not get regulator '%s'\n",
		      __func__, dev_read_name(dev), port, regname);
		return ret;
	}

	regulator_set_enable(regulator, enable);
	return 0;
#else
	return -ENOTSUPP;
#endif
}
Esempio n. 4
0
/* Test regulator autoset method */
static int dm_test_power_regulator_autoset(struct unit_test_state *uts)
{
	const char *platname;
	struct udevice *dev, *dev_autoset;

	/*
	 * Test the BUCK1 with fdt properties
	 * - min-microvolt = max-microvolt = 1200000
	 * - min-microamp = max-microamp = 200000
	 * - always-on = set
	 * - boot-on = not set
	 * Expected output state: uV=1200000; uA=200000; output enabled
	 */
	platname = regulator_names[BUCK1][PLATNAME];
	ut_assertok(regulator_autoset_by_name(platname, &dev_autoset));

	/* Check, that the returned device is proper */
	ut_assertok(regulator_get_by_platname(platname, &dev));
	ut_asserteq_ptr(dev, dev_autoset);

	/* Check the setup after autoset */
	ut_asserteq(regulator_get_value(dev),
		    SANDBOX_BUCK1_AUTOSET_EXPECTED_UV);
	ut_asserteq(regulator_get_current(dev),
		    SANDBOX_BUCK1_AUTOSET_EXPECTED_UA);
	ut_asserteq(regulator_get_enable(dev),
		    SANDBOX_BUCK1_AUTOSET_EXPECTED_ENABLE);

	return 0;
}
Esempio n. 5
0
void exynos_backlight_on(unsigned int on)
{
	struct udevice *dev;
	int ret;

	debug("%s(%u)\n", __func__, on);
	if (!on)
		return;

	ret = regulator_get_by_platname("vcd_led", &dev);
	if (!ret)
		ret = regulator_set_enable(dev, true);
	if (ret)
		debug("Failed to enable backlight: ret=%d\n", ret);

	/* T5 in the LCD timing spec (defined as > 10ms) */
	mdelay(10);

	/* board_dp_backlight_pwm */
	gpio_direction_output(EXYNOS5_GPIO_B20, 1);

	/* T6 in the LCD timing spec (defined as > 10ms) */
	mdelay(10);

	/* try to set the backlight in the bridge registers */
	ret = board_dp_set_backlight(80);

	/* if we have no bridge or it does not support backlight, use a GPIO */
	if (ret == -ENODEV || ret == -ENOSYS) {
		gpio_request(EXYNOS5_GPIO_X30, "board_dp_backlight_en");
		gpio_direction_output(EXYNOS5_GPIO_X30, 1);
	}
}
Esempio n. 6
0
/* Basic test of the panel uclass */
static int dm_test_panel(struct unit_test_state *uts)
{
	struct udevice *dev, *pwm, *gpio, *reg;
	uint period_ns;
	uint duty_ns;
	bool enable;
	bool polarity;

	ut_assertok(uclass_first_device_err(UCLASS_PANEL, &dev));
	ut_assertok(uclass_first_device_err(UCLASS_PWM, &pwm));
	ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
	ut_assertok(regulator_get_by_platname("VDD_EMMC_1.8V", &reg));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(false, enable);
	ut_asserteq(false, regulator_get_enable(reg));

	ut_assertok(panel_enable_backlight(dev));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(1000, period_ns);
	ut_asserteq(170 * 1000 / 256, duty_ns);
	ut_asserteq(true, enable);
	ut_asserteq(false, polarity);
	ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
	ut_asserteq(true, regulator_get_enable(reg));

	ut_assertok(panel_set_backlight(dev, 40));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(64 * 1000 / 256, duty_ns);

	ut_assertok(panel_set_backlight(dev, BACKLIGHT_MAX));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(255 * 1000 / 256, duty_ns);

	ut_assertok(panel_set_backlight(dev, BACKLIGHT_MIN));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(0 * 1000 / 256, duty_ns);
	ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));

	ut_assertok(panel_set_backlight(dev, BACKLIGHT_DEFAULT));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(true, enable);
	ut_asserteq(170 * 1000 / 256, duty_ns);

	ut_assertok(panel_set_backlight(dev, BACKLIGHT_OFF));
	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
					   &enable, &polarity));
	ut_asserteq(0 * 1000 / 256, duty_ns);
	ut_asserteq(0, sandbox_gpio_get_value(gpio, 1));
	ut_asserteq(false, regulator_get_enable(reg));

	return 0;
}
Esempio n. 7
0
int board_init(void)
{
	struct udevice *pinctrl, *regulator;
	int ret;

	/*
	 * The PWM do not have decicated interrupt number in dts and can
	 * not get periph_id by pinctrl framework, so let's init them here.
	 * The PWM2 and PWM3 are for pwm regulater.
	 */
	ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
	if (ret) {
		debug("%s: Cannot find pinctrl device\n", __func__);
		goto out;
	}

	/* Enable pwm0 for panel backlight */
	ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM0);
	if (ret) {
		debug("%s PWM0 pinctrl init fail! (ret=%d)\n", __func__, ret);
		goto out;
	}

	ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM2);
	if (ret) {
		debug("%s PWM2 pinctrl init fail!\n", __func__);
		goto out;
	}

	ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM3);
	if (ret) {
		debug("%s PWM3 pinctrl init fail!\n", __func__);
		goto out;
	}

	ret = regulators_enable_boot_on(false);
	if (ret)
		debug("%s: Cannot enable boot on regulator\n", __func__);

	ret = regulator_get_by_platname("vcc5v0_host", &regulator);
	if (ret) {
		debug("%s vcc5v0_host init fail! ret %d\n", __func__, ret);
		goto out;
	}

	ret = regulator_set_enable(regulator, true);
	if (ret) {
		debug("%s vcc5v0-host-en set fail!\n", __func__);
		goto out;
	}

out:
	return 0;
}
Esempio n. 8
0
int board_usb_init(int index, enum usb_init_type init)
{
#ifdef CONFIG_CMD_USB
	struct udevice *dev;
	int ret;

	/* Set Ref freq 0 => 24MHz, 1 => 26MHz*/
	/* Odroid Us have it at 24MHz, Odroid Xs at 26MHz */
	if (gd->board_type == ODROID_TYPE_U3)
		gpio_direction_output(EXYNOS4X12_GPIO_X30, 0);
	else
		gpio_direction_output(EXYNOS4X12_GPIO_X30, 1);

	/* Disconnect, Reset, Connect */
	gpio_direction_output(EXYNOS4X12_GPIO_X34, 0);
	gpio_direction_output(EXYNOS4X12_GPIO_X35, 0);
	gpio_direction_output(EXYNOS4X12_GPIO_X35, 1);
	gpio_direction_output(EXYNOS4X12_GPIO_X34, 1);

	/* Power off and on BUCK8 for LAN9730 */
	debug("LAN9730 - Turning power buck 8 OFF and ON.\n");

	ret = regulator_get_by_platname("VCC_P3V3_2.85V", &dev);
	if (ret) {
		error("Regulator get error: %d", ret);
		return ret;
	}

	ret = regulator_set_enable(dev, true);
	if (ret) {
		error("Regulator %s enable setting error: %d", dev->name, ret);
		return ret;
	}

	ret = regulator_set_value(dev, 750000);
	if (ret) {
		error("Regulator %s value setting error: %d", dev->name, ret);
		return ret;
	}

	ret = regulator_set_value(dev, 3300000);
	if (ret) {
		error("Regulator %s value setting error: %d", dev->name, ret);
		return ret;
	}
#endif
	debug("USB_udc_probe\n");
	return s3c_udc_probe(&s5pc210_otg_data);
}
Esempio n. 9
0
/* Test regulator set and get Current method */
static int dm_test_power_regulator_set_get_current(struct unit_test_state *uts)
{
	struct dm_regulator_uclass_platdata *uc_pdata;
	struct udevice *dev;
	const char *platname;
	int val_set, val_get;

	/* Set and get the Current of LDO1 - set to 'min' constraint */
	platname = regulator_names[LDO1][PLATNAME];
	ut_assertok(regulator_get_by_platname(platname, &dev));

	uc_pdata = dev_get_uclass_platdata(dev);
	ut_assert(uc_pdata);

	val_set = uc_pdata->min_uA;
	ut_assertok(regulator_set_current(dev, val_set));

	val_get = regulator_get_current(dev);
	ut_assert(val_get >= 0);

	ut_asserteq(val_set, val_get);

	/* Check LDO2 current limit constraints - should be -ENODATA */
	platname = regulator_names[LDO2][PLATNAME];
	ut_assertok(regulator_get_by_platname(platname, &dev));

	uc_pdata = dev_get_uclass_platdata(dev);
	ut_assert(uc_pdata);
	ut_asserteq(-ENODATA, uc_pdata->min_uA);
	ut_asserteq(-ENODATA, uc_pdata->max_uA);

	/* Try set the Current of LDO2 - should return -ENOSYS */
	ut_asserteq(-ENOSYS, regulator_set_current(dev, 0));

	return 0;
}
Esempio n. 10
0
static int s5pc210_phy_control(int on)
{
	struct udevice *dev;
	int ret;

	ret = regulator_get_by_platname("VDD_UOTG_3.0V", &dev);
	if (ret) {
		error("Regulator get error: %d", ret);
		return ret;
	}

	if (on)
		return regulator_set_mode(dev, OPMODE_ON);
	else
		return regulator_set_mode(dev, OPMODE_LPM);
}
Esempio n. 11
0
/* Test regulator set and get mode method */
static int dm_test_power_regulator_set_get_mode(struct unit_test_state *uts)
{
	const char *platname;
	struct udevice *dev;
	int val_set = LDO_OM_SLEEP;

	/* Set the mode id to LDO_OM_SLEEP of LDO1 - default is LDO_OM_OFF */
	platname = regulator_names[LDO1][PLATNAME];
	ut_assertok(regulator_get_by_platname(platname, &dev));
	ut_assertok(regulator_set_mode(dev, val_set));

	/* Get the mode id of LDO1 and compare it with the requested one */
	ut_asserteq(regulator_get_mode(dev), val_set);

	return 0;
}
Esempio n. 12
0
/* Test regulator set and get Enable method */
static int dm_test_power_regulator_set_get_enable(struct unit_test_state *uts)
{
	const char *platname;
	struct udevice *dev;
	bool val_set = true;

	/* Set the Enable of LDO1 - default is disabled */
	platname = regulator_names[LDO1][PLATNAME];
	ut_assertok(regulator_get_by_platname(platname, &dev));
	ut_assertok(regulator_set_enable(dev, val_set));

	/* Get the Enable state of LDO1 and compare it with the requested one */
	ut_asserteq(regulator_get_enable(dev), val_set);

	return 0;
}
Esempio n. 13
0
void exynos_lcd_power_on(void)
{
	struct udevice *dev;
	int ret;

	debug("%s\n", __func__);
	ret = regulator_get_by_platname("lcd_vdd", &dev);
	if (!ret)
		ret = regulator_set_enable(dev, true);
	if (ret)
		debug("Failed to enable LCD panel: ret=%d\n", ret);

	ret = board_dp_bridge_setup(gd->fdt_blob);
	if (ret && ret != -ENODEV)
		printf("LCD bridge failed to enable: %d\n", ret);
}
Esempio n. 14
0
static int exynos_set_regulator(const char *name, uint uv)
{
	struct udevice *dev;
	int ret;

	ret = regulator_get_by_platname(name, &dev);
	if (ret) {
		debug("%s: Cannot find regulator %s\n", __func__, name);
		return ret;
	}
	ret = regulator_set_value(dev, uv);
	if (ret) {
		debug("%s: Cannot set regulator %s\n", __func__, name);
		return ret;
	}

	return 0;
}
Esempio n. 15
0
/* Test regulator get method */
static int dm_test_power_regulator_get(struct unit_test_state *uts)
{
	struct dm_regulator_uclass_platdata *uc_pdata;
	struct udevice *dev_by_devname;
	struct udevice *dev_by_platname;
	const char *devname;
	const char *platname;
	int i;

	for (i = 0; i < OUTPUT_COUNT; i++) {
		/*
		 * Do the test for each regulator's devname and platname,
		 * which are related to a single device.
		 */
		devname = regulator_names[i][DEVNAME];
		platname = regulator_names[i][PLATNAME];

		/*
		 * Check, that regulator_get_by_devname() function, returns
		 * a device with the name equal to the requested one.
		 */
		ut_assertok(regulator_get_by_devname(devname, &dev_by_devname));
		ut_asserteq_str(devname, dev_by_devname->name);

		/*
		 * Check, that regulator_get_by_platname() function, returns
		 * a device with the name equal to the requested one.
		 */
		ut_assertok(regulator_get_by_platname(platname, &dev_by_platname));
		uc_pdata = dev_get_uclass_platdata(dev_by_platname);
		ut_assert(uc_pdata);
		ut_asserteq_str(platname, uc_pdata->name);

		/*
		 * Check, that the pointers returned by both get functions,
		 * points to the same regulator device.
		 */
		ut_asserteq_ptr(dev_by_devname, dev_by_platname);
	}

	return 0;
}
Esempio n. 16
0
/* Test regulator set and get Voltage method */
static int dm_test_power_regulator_set_get_voltage(struct unit_test_state *uts)
{
	struct dm_regulator_uclass_platdata *uc_pdata;
	struct udevice *dev;
	const char *platname;
	int val_set, val_get;

	/* Set and get Voltage of BUCK1 - set to 'min' constraint */
	platname = regulator_names[BUCK1][PLATNAME];
	ut_assertok(regulator_get_by_platname(platname, &dev));

	uc_pdata = dev_get_uclass_platdata(dev);
	ut_assert(uc_pdata);

	val_set = uc_pdata->min_uV;
	ut_assertok(regulator_set_value(dev, val_set));

	val_get = regulator_get_value(dev);
	ut_assert(val_get >= 0);

	ut_asserteq(val_set, val_get);

	return 0;
}