Пример #1
0
/* Must be called with ts->lock held */
static void __ads7846_enable(struct ads7846 *ts)
{
	regulator_enable(ts->reg);
	ads7846_restart(ts);
}
static int akm8975_power_on(void)
{
	if (akm8975_regulator)
		return regulator_enable(akm8975_regulator);
	return -ENXIO;
}
Пример #3
0
static int
usbphy_attach(device_t dev)
{
	struct usbphy_softc * sc;
	int rid, rv;
	phandle_t node;

	sc = device_get_softc(dev);
	sc->dev = dev;

	rid = 0;
	sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
	    RF_ACTIVE | RF_SHAREABLE);
	if (sc->mem_res == NULL) {
		device_printf(dev, "Cannot allocate memory resources\n");
		return (ENXIO);
	}

	rid = 1;
	sc->pads_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
	    RF_ACTIVE | RF_SHAREABLE);
	if (sc->mem_res == NULL) {
		device_printf(dev, "Cannot allocate memory resources\n");
		return (ENXIO);
	}

	node = ofw_bus_get_node(dev);

	rv = hwreset_get_by_ofw_name(sc->dev, "usb", &sc->reset_usb);
	if (rv != 0) {
		device_printf(dev, "Cannot get 'usb' reset\n");
		return (ENXIO);
	}
	rv = hwreset_get_by_ofw_name(sc->dev, "utmi-pads", &sc->reset_pads);
	if (rv != 0) {
		device_printf(dev, "Cannot get 'utmi-pads' reset\n");
		return (ENXIO);
	}

	rv = clk_get_by_ofw_name(sc->dev, "reg", &sc->clk_reg);
	if (rv != 0) {
		device_printf(sc->dev, "Cannot get 'reg' clock\n");
		return (ENXIO);
	}
	rv = clk_get_by_ofw_name(sc->dev, "pll_u", &sc->clk_pllu);
	if (rv != 0) {
		device_printf(sc->dev, "Cannot get 'pll_u' clock\n");
		return (ENXIO);
	}
	rv = clk_get_by_ofw_name(sc->dev, "utmi-pads", &sc->clk_pads);
	if (rv != 0) {
		device_printf(sc->dev, "Cannot get 'utmi-pads' clock\n");
		return (ENXIO);
	}

	rv = hwreset_deassert(sc->reset_usb);
	if (rv != 0) {
		device_printf(dev, "Cannot unreset 'usb' reset\n");
		return (ENXIO);
	}

	rv = clk_enable(sc->clk_pllu);
	if (rv != 0) {
		device_printf(sc->dev, "Cannot enable 'pllu' clock\n");
		return (ENXIO);
	}
	rv = clk_enable(sc->clk_reg);
	if (rv != 0) {
		device_printf(sc->dev, "Cannot enable 'reg' clock\n");
		return (ENXIO);
	}
	if (OF_hasprop(node, "nvidia,has-utmi-pad-registers"))
		sc->have_utmi_regs = true;

	sc->dr_mode = usb_get_dr_mode(dev, node, "dr_mode");
	if (sc->dr_mode == USB_DR_MODE_UNKNOWN)
		sc->dr_mode = USB_DR_MODE_HOST;

	sc->ifc_type = usb_get_ifc_mode(dev, node, "phy_type");

	/* We supports only utmi phy mode for now .... */
	if (sc->ifc_type != USB_IFC_TYPE_UTMI) {
		device_printf(dev, "Unsupported phy type\n");
		return (ENXIO);
	}
	rv = usbphy_utmi_read_params(sc, node);
	if (rv < 0)
		return rv;

	if (OF_hasprop(node, "vbus-supply")) {
		rv = regulator_get_by_ofw_property(sc->dev, "vbus-supply",
		    &sc->supply_vbus);
		if (rv != 0) {
			device_printf(sc->dev,
			   "Cannot get \"vbus\" regulator\n");
			return (ENXIO);
		}
		rv = regulator_enable(sc->supply_vbus);
		if (rv != 0) {
			device_printf(sc->dev,
			    "Cannot enable  \"vbus\" regulator\n");
			return (rv);
		}
	}

	phy_register_provider(dev);
	return (0);
}
Пример #4
0
static int __devinit s5p_tv_probe(struct platform_device *pdev)
{
	int	irq_num;
	int	ret;
	int	i, retval;


	/* Get csis power domain regulator */
	s5ptv_status.tv_regulator = regulator_get(&pdev->dev, "pd");
	if (IS_ERR(s5ptv_status.tv_regulator)) {
		printk(KERN_ERR "%s %d: failed to get resource %s\n",
				__func__, __LINE__, "s3c-tv20 pd");
		return PTR_ERR(s5ptv_status.tv_regulator);
	}

	s5ptv_status.tv_tvout = regulator_get(NULL, "tvout");
	if (IS_ERR(s5ptv_status.tv_tvout)) {
		printk(KERN_ERR "%s %d: failed to get resource %s\n",
				__func__, __LINE__, "s3c-tv20 tvout");
		return PTR_ERR(s5ptv_status.tv_tvout);
	}

#ifdef CONFIG_MACH_P1
	s5ptv_status.tv_tv = regulator_get(NULL, "tv");
	if (IS_ERR(s5ptv_status.tv_tv)) {
		printk(KERN_ERR "%s %d: failed to get resource %s\n",
				__func__, __LINE__, "s3c-tv20 tv");
		return PTR_ERR(s5ptv_status.tv_tv);
	}
	regulator_enable(s5ptv_status.tv_tv);
#endif
	s5ptv_status.dev_fb = &pdev->dev;

	__s5p_sdout_probe(pdev, 0);
	__s5p_vp_probe(pdev, 1);
	__s5p_mixer_probe(pdev, 2);

#ifdef CONFIG_CPU_S5PC100
	__s5p_hdmi_probe(pdev, 3);
	__s5p_tvclk_probe(pdev, 4);
#endif

#ifdef CONFIG_CPU_S5PV210
	tv_clk_get(pdev, &s5ptv_status);
	s5p_tv_clk_gate(true);
	__s5p_hdmi_probe(pdev, 3, 4);
	__s5p_hdcp_init();
#endif
#if defined(CONFIG_MACH_P1)
	retval = i2c_add_driver(&SII9234A_i2c_driver);
	if (retval != 0)
		printk(KERN_ERR "[MHL SII9234A] can't add i2c driver");

	retval = i2c_add_driver(&SII9234B_i2c_driver);
	if (retval != 0)
		printk(KERN_ERR "[MHL SII9234B] can't add i2c driver");

	retval = i2c_add_driver(&SII9234C_i2c_driver);
	if (retval != 0)
		printk(KERN_ERR "[MHL SII9234C] can't add i2c driver");

	retval = i2c_add_driver(&SII9234_i2c_driver);
	if (retval != 0)
		printk(KERN_ERR "[MHL SII9234] can't add i2c driver");
#endif

#ifdef FIX_27M_UNSTABLE_ISSUE /* for smdkc100 pop */
	writel(0x1, S5PC1XX_GPA0_BASE + 0x56c);
#endif

#ifdef I2C_BASE
	/* for dev_dbg err. */
	spin_lock_init(&slock_hpd);

	/* for bh */
	INIT_WORK(&ws_hpd, (void *)set_ddc_port);
#endif
	/* check EINT init state */
#ifdef CONFIG_CPU_S5PC100
	s3c_gpio_cfgpin(S5PC1XX_GPH0(5), S3C_GPIO_SFN(2));
	s3c_gpio_setpull(S5PC1XX_GPH0(5), S3C_GPIO_PULL_UP);

	s5ptv_status.hpd_status = gpio_get_value(S5PC1XX_GPH0(5)) ? \
							false : true;
#endif

#ifdef CONFIG_CPU_S5PV210
#ifdef CONFIG_HDMI_HPD
	s5ptv_status.hpd_status = 0;
#else
	s5ptv_status.hpd_status = 0;
#endif
#endif
	dev_info(&pdev->dev, "hpd status: cable %s\n",\
		s5ptv_status.hpd_status ? "inserted":"removed/not connected");

	/* Interrupt */
	TVOUT_IRQ_INIT(irq_num, ret, pdev, 0, out, __s5p_mixer_irq, "mixer");
	TVOUT_IRQ_INIT(irq_num, ret, pdev, 1, out_hdmi_irq, __s5p_hdmi_irq , \
								"hdmi");
	TVOUT_IRQ_INIT(irq_num, ret, pdev, 2, out_tvenc_irq, s5p_tvenc_irq, \
								"tvenc");

#ifdef CONFIG_CPU_S5PC100
	TVOUT_IRQ_INIT(irq_num, ret, pdev, 3, out_hpd_irq, __s5p_hpd_irq, \
									"hpd");
	set_irq_type(IRQ_EINT5, IRQ_TYPE_LEVEL_LOW);
#endif
	/* v4l2 video device registration */
	for (i = 0; i < S5P_TVMAX_CTRLS; i++) {
		s5ptv_status.video_dev[i] = &s5p_tvout[i];

		if (video_register_device(s5ptv_status.video_dev[i],
				VFL_TYPE_GRABBER, s5p_tvout[i].minor) != 0) {

			dev_err(&pdev->dev,
				"Couldn't register tvout driver.\n");
			return 0;
		}
	}

#ifdef CONFIG_TV_FB
	mutex_init(&s5ptv_status.fb_lock);

	/* for default start up */
	_s5p_tv_if_init_param();

	s5ptv_status.tvout_param.disp_mode = TVOUT_720P_60;
	s5ptv_status.tvout_param.out_mode  = TVOUT_OUTPUT_HDMI;

#ifndef CONFIG_USER_ALLOC_TVOUT
	s5p_tv_clk_gate(true);
/*
	if ((s5ptv_status.tvout_param.out_mode == TVOUT_OUTPUT_HDMI) ||
		(s5ptv_status.tvout_param.out_mode == TVOUT_OUTPUT_HDMI_RGB))
*/
		tv_phy_power(true);
	_s5p_tv_if_set_disp();
#endif
	s5ptvfb_set_lcd_info(&s5ptv_status);

	/* prepare memory */
	if (s5ptvfb_alloc_framebuffer())
		goto err_alloc;

	if (s5ptvfb_register_framebuffer())
		goto err_alloc;
#ifndef CONFIG_USER_ALLOC_TVOUT
	s5ptvfb_display_on(&s5ptv_status);
#endif
#endif
	mutex_for_fo = kmalloc(sizeof(struct mutex),
		GFP_KERNEL);

	if (mutex_for_fo == NULL) {
		dev_err(&pdev->dev,
			"failed to create mutex handle\n");
		goto out;
	}
#ifdef I2C_BASE
	mutex_for_i2c = kmalloc(sizeof(struct mutex),
		GFP_KERNEL);

	if (mutex_for_i2c == NULL) {
		dev_err(&pdev->dev,
			"failed to create mutex handle\n");
		goto out;
	}
	mutex_init(mutex_for_i2c);
#endif
	mutex_init(mutex_for_fo);

#ifdef CONFIG_CPU_S5PV210
	/* added for phy cut off when boot up */
	clk_enable(s5ptv_status.i2c_phy_clk);

	__s5p_hdmi_phy_power(false);
	clk_disable(s5ptv_status.i2c_phy_clk);

	s5p_tv_clk_gate(false);
#endif
	printk(KERN_INFO "%s TV Probing is done\n", __func__);
	return 0;

#ifdef CONFIG_TV_FB
err_alloc:
#endif

#ifdef CONFIG_CPU_S5PC100
out_hpd_irq:
	free_irq(IRQ_TVENC, pdev);
#endif

out_tvenc_irq:
	free_irq(IRQ_HDMI, pdev);

out_hdmi_irq:
	free_irq(IRQ_MIXER, pdev);

out:
	printk(KERN_ERR "not found (%d). \n", ret);

	return ret;
}
/**
 * dwc3_otg_start_host -  helper function for starting/stoping the host controller driver.
 *
 * @otg: Pointer to the otg_transceiver structure.
 * @on: start / stop the host controller driver.
 *
 * Returns 0 on success otherwise negative errno.
 */
static int dwc3_otg_start_host(struct usb_otg *otg, int on)
{
	struct dwc3_otg *dotg = container_of(otg, struct dwc3_otg, otg);
	struct dwc3_ext_xceiv *ext_xceiv = dotg->ext_xceiv;
	struct dwc3 *dwc = dotg->dwc;
	struct usb_hcd *hcd;
	int ret = 0;

	if (!dwc->xhci)
		return -EINVAL;

	if (!dotg->vbus_otg) {
		dotg->vbus_otg = devm_regulator_get(dwc->dev->parent,
							"vbus_dwc3");
		if (IS_ERR(dotg->vbus_otg)) {
			dev_err(dwc->dev, "Failed to get vbus regulator\n");
			ret = PTR_ERR(dotg->vbus_otg);
			dotg->vbus_otg = 0;
			return ret;
		}
	}

	if (on) {
		dev_dbg(otg->phy->dev, "%s: turn on host\n", __func__);

		dwc3_otg_notify_host_mode(otg, on);
		usb_phy_notify_connect(dotg->dwc->usb2_phy, USB_SPEED_HIGH);
		ret = regulator_enable(dotg->vbus_otg);
		if (ret) {
			dev_err(otg->phy->dev, "unable to enable vbus_otg\n");
			dwc3_otg_notify_host_mode(otg, 0);
			return ret;
		}

		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);

		/*
		 * FIXME If micro A cable is disconnected during system suspend,
		 * xhci platform device will be removed before runtime pm is
		 * enabled for xhci device. Due to this, disable_depth becomes
		 * greater than one and runtimepm is not enabled for next microA
		 * connect. Fix this by calling pm_runtime_init for xhci device.
		 */
		pm_runtime_init(&dwc->xhci->dev);
		ret = platform_device_add(dwc->xhci);
		if (ret) {
			dev_err(otg->phy->dev,
				"%s: failed to add XHCI pdev ret=%d\n",
				__func__, ret);
			regulator_disable(dotg->vbus_otg);
			dwc3_otg_notify_host_mode(otg, 0);
			return ret;
		}

		hcd = platform_get_drvdata(dwc->xhci);
		dwc3_otg_set_host(otg, &hcd->self);

		/* re-init OTG EVTEN register as XHCI reset clears it */
		if (ext_xceiv && !ext_xceiv->otg_capability)
			dwc3_otg_reset(dotg);

		dwc3_gadget_usb3_phy_suspend(dwc, true);
	} else {
		dev_dbg(otg->phy->dev, "%s: turn off host\n", __func__);

		ret = regulator_disable(dotg->vbus_otg);
		if (ret) {
			dev_err(otg->phy->dev, "unable to disable vbus_otg\n");
			return ret;
		}

		dbg_event(0xFF, "StHost get", 0);
		pm_runtime_get(dwc->dev);
		usb_phy_notify_disconnect(dotg->dwc->usb2_phy, USB_SPEED_HIGH);
		dwc3_otg_notify_host_mode(otg, on);
		dwc3_otg_set_host(otg, NULL);
		platform_device_del(dwc->xhci);

		/*
		 * Perform USB hardware RESET (both core reset and DBM reset)
		 * when moving from host to peripheral. This is required for
		 * peripheral mode to work.
		 */
		if (ext_xceiv && ext_xceiv->otg_capability &&
						ext_xceiv->ext_block_reset)
			ext_xceiv->ext_block_reset(ext_xceiv, true);

		dwc3_gadget_usb3_phy_suspend(dwc, false);
		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);

		/* re-init core and OTG registers as block reset clears these */
		dwc3_post_host_reset_core_init(dwc);
		if (ext_xceiv && !ext_xceiv->otg_capability)
			dwc3_otg_reset(dotg);
		dbg_event(0xFF, "StHost put", 0);
		pm_runtime_put(dwc->dev);
	}

	return 0;
}
Пример #6
0
static int ad7298_probe(struct spi_device *spi)
{
	struct ad7298_platform_data *pdata = spi->dev.platform_data;
	struct ad7298_state *st;
	struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
	int ret;

	if (indio_dev == NULL)
		return -ENOMEM;

	st = iio_priv(indio_dev);

	if (pdata && pdata->ext_ref)
		st->ext_ref = AD7298_EXTREF;

	if (st->ext_ref) {
		st->reg = regulator_get(&spi->dev, "vref");
		if (IS_ERR(st->reg)) {
			ret = PTR_ERR(st->reg);
			goto error_free;
		}
		ret = regulator_enable(st->reg);
		if (ret)
			goto error_put_reg;
	}

	spi_set_drvdata(spi, indio_dev);

	st->spi = spi;

	indio_dev->name = spi_get_device_id(spi)->name;
	indio_dev->dev.parent = &spi->dev;
	indio_dev->modes = INDIO_DIRECT_MODE;
	indio_dev->channels = ad7298_channels;
	indio_dev->num_channels = ARRAY_SIZE(ad7298_channels);
	indio_dev->info = &ad7298_info;

	/* Setup default message */

	st->scan_single_xfer[0].tx_buf = &st->tx_buf[0];
	st->scan_single_xfer[0].len = 2;
	st->scan_single_xfer[0].cs_change = 1;
	st->scan_single_xfer[1].tx_buf = &st->tx_buf[1];
	st->scan_single_xfer[1].len = 2;
	st->scan_single_xfer[1].cs_change = 1;
	st->scan_single_xfer[2].rx_buf = &st->rx_buf[0];
	st->scan_single_xfer[2].len = 2;

	spi_message_init(&st->scan_single_msg);
	spi_message_add_tail(&st->scan_single_xfer[0], &st->scan_single_msg);
	spi_message_add_tail(&st->scan_single_xfer[1], &st->scan_single_msg);
	spi_message_add_tail(&st->scan_single_xfer[2], &st->scan_single_msg);

	ret = iio_triggered_buffer_setup(indio_dev, NULL,
			&ad7298_trigger_handler, NULL);
	if (ret)
		goto error_disable_reg;

	ret = iio_device_register(indio_dev);
	if (ret)
		goto error_cleanup_ring;

	return 0;

error_cleanup_ring:
	iio_triggered_buffer_cleanup(indio_dev);
error_disable_reg:
	if (st->ext_ref)
		regulator_disable(st->reg);
error_put_reg:
	if (st->ext_ref)
		regulator_put(st->reg);
error_free:
	iio_device_free(indio_dev);

	return ret;
}
Пример #7
0
static mali_bool init_mali_clock(void)
{
	mali_bool ret = MALI_TRUE;

	gpu_power_state = 0;

	if (mali_clock != 0)
		return ret; // already initialized

	mali_dvfs_lock = _mali_osk_lock_init(_MALI_OSK_LOCKFLAG_NONINTERRUPTABLE
			| _MALI_OSK_LOCKFLAG_ONELOCK, 0, 0);
	if (mali_dvfs_lock == NULL)
		return _MALI_OSK_ERR_FAULT;

	if (mali_clk_set_rate(mali_gpu_clk, GPU_MHZ) == MALI_FALSE)
	{
		ret = MALI_FALSE;
		goto err_clock_get;
	}

	MALI_PRINT(("init_mali_clock mali_clock %p \n", mali_clock));


#ifdef CONFIG_REGULATOR
#if USING_MALI_PMM
	g3d_regulator = regulator_get(&mali_gpu_device.dev, "vdd_g3d");
#else
	g3d_regulator = regulator_get(NULL, "vdd_g3d");
#endif

	if (IS_ERR(g3d_regulator))
	{
		MALI_PRINT( ("MALI Error : failed to get vdd_g3d\n"));
		ret = MALI_FALSE;
		goto err_regulator;
	}

	regulator_enable(g3d_regulator);

	MALI_DEBUG_PRINT(1, ("= regulator_enable -> use cnt: %d \n",mali_regulator_get_usecount()));
	mali_regulator_set_voltage(mali_gpu_vol, mali_gpu_vol);
#endif

	MALI_DEBUG_PRINT(2, ("MALI Clock is set at mali driver\n"));


	MALI_DEBUG_PRINT(3,("::clk_put:: %s mali_parent_clock - normal\n", __FUNCTION__));
	MALI_DEBUG_PRINT(3,("::clk_put:: %s mpll_clock  - normal\n", __FUNCTION__));

	mali_clk_put(MALI_FALSE);

	return MALI_TRUE;


#ifdef CONFIG_REGULATOR
err_regulator:
	regulator_put(g3d_regulator);
#endif

err_clock_get:
	mali_clk_put(MALI_TRUE);

	return ret;
}
Пример #8
0
/* Update voltage level given the current votes. */
static int update_vdd(struct clk_vdd_class *vdd_class)
{
	int level, rc = 0, i, ignore;
	struct regulator **r = vdd_class->regulator;
	int *uv = vdd_class->vdd_uv;
	int *ua = vdd_class->vdd_ua;
	int n_reg = vdd_class->num_regulators;
	int cur_lvl = vdd_class->cur_level;
	int max_lvl = vdd_class->num_levels - 1;
	int cur_base = cur_lvl * n_reg;
	int new_base;

	/* aggregate votes */
	for (level = max_lvl; level > 0; level--)
		if (vdd_class->level_votes[level])
			break;

	if (level == cur_lvl)
		return 0;

	max_lvl = max_lvl * n_reg;
	new_base = level * n_reg;
	for (i = 0; i < vdd_class->num_regulators; i++) {
		rc = regulator_set_voltage(r[i], uv[new_base + i],
					   uv[max_lvl + i]);
		if (rc)
			goto set_voltage_fail;

		if (ua) {
			rc = regulator_set_optimum_mode(r[i], ua[new_base + i]);
			rc = rc > 0 ? 0 : rc;
			if (rc)
				goto set_mode_fail;
		}
		if (cur_lvl == 0 || cur_lvl == vdd_class->num_levels)
			rc = regulator_enable(r[i]);
		else if (level == 0)
			rc = regulator_disable(r[i]);
		if (rc)
			goto enable_disable_fail;
	}
	if (vdd_class->set_vdd && !vdd_class->num_regulators)
		rc = vdd_class->set_vdd(vdd_class, level);

	if (!rc)
		vdd_class->cur_level = level;

	return rc;

enable_disable_fail:
	/*
	 * set_optimum_mode could use voltage to derive mode.  Restore
	 * previous voltage setting for r[i] first.
	 */
	if (ua) {
		regulator_set_voltage(r[i], uv[cur_base + i], uv[max_lvl + i]);
		regulator_set_optimum_mode(r[i], ua[cur_base + i]);
	}

set_mode_fail:
	regulator_set_voltage(r[i], uv[cur_base + i], uv[max_lvl + i]);

set_voltage_fail:
	for (i--; i >= 0; i--) {
		regulator_set_voltage(r[i], uv[cur_base + i], uv[max_lvl + i]);
		if (ua)
			regulator_set_optimum_mode(r[i], ua[cur_base + i]);
		if (cur_lvl == 0 || cur_lvl == vdd_class->num_levels)
			regulator_disable(r[i]);
		else if (level == 0)
			ignore = regulator_enable(r[i]);
	}
	return rc;
}
Пример #9
0
		/* In the absence of dedicated ref_clk, xo clocks the HUB */
		smsc_hub->xo_handle = msm_xo_get(MSM_XO_TCXO_D1, "hsic_hub");
		if (IS_ERR(smsc_hub->xo_handle)) {
			dev_err(hub->dev, "not able to get the handle\n"
						 "for TCXO D1 buffer\n");
			return PTR_ERR(smsc_hub->xo_handle);
		}

		ret = msm_xo_mode_vote(smsc_hub->xo_handle, MSM_XO_MODE_ON);
		if (ret) {
			dev_err(hub->dev, "failed to vote for TCXO\n"
				"D1 buffer\n");
			msm_xo_put(smsc_hub->xo_handle);
			return ret;
		}
	} else {
		ret = clk_prepare_enable(hub->ref_clk);
		if (ret)
			dev_err(hub->dev, "clk_enable failed for ref_clk\n");
	}

	return ret;
}
#define HSIC_HUB_INT_VOL_MIN	1800000 /* uV */
#define HSIC_HUB_INT_VOL_MAX	2950000 /* uV */
static int msm_hsic_hub_init_gpio(struct hsic_hub *hub, int init)
{
	int ret;
	struct smsc_hub_platform_data *pdata = hub->pdata;

	if (!init) {
		if (!IS_ERR(smsc_hub->int_pad_reg)) {
			regulator_disable(smsc_hub->int_pad_reg);
			regulator_set_voltage(smsc_hub->int_pad_reg, 0,
						HSIC_HUB_INT_VOL_MAX);
		}
		return 0;
	}

	ret = devm_gpio_request(hub->dev, pdata->hub_reset, "HSIC_HUB_RESET");
	if (ret < 0) {
		dev_err(hub->dev, "gpio request failed for GPIO%d\n",
							pdata->hub_reset);
		return ret;
	}

	if (pdata->refclk_gpio) {
		ret = devm_gpio_request(hub->dev, pdata->refclk_gpio,
							 "HSIC_HUB_CLK");
		if (ret < 0)
			dev_err(hub->dev, "gpio request failed (CLK GPIO)\n");
	}

	if (pdata->int_gpio) {
		ret = devm_gpio_request(hub->dev, pdata->int_gpio,
							 "HSIC_HUB_INT");
		if (ret < 0) {
			dev_err(hub->dev, "gpio request failed (INT GPIO)\n");
			return ret;
		}

		/* Enable LDO if required for external pull-up */
		smsc_hub->int_pad_reg = devm_regulator_get(hub->dev, "hub_int");
		if (IS_ERR(smsc_hub->int_pad_reg)) {
			dev_dbg(hub->dev, "unable to get ext hub_int reg\n");
		} else {
			ret = regulator_set_voltage(smsc_hub->int_pad_reg,
						HSIC_HUB_INT_VOL_MIN,
						HSIC_HUB_INT_VOL_MAX);
			if (ret) {
				dev_err(hub->dev, "unable to set the voltage\n"
						" for hsic hub int reg\n");
				return ret;
			}
			ret = regulator_enable(smsc_hub->int_pad_reg);
			if (ret) {
				dev_err(hub->dev, "unable to enable int reg\n");
				regulator_set_voltage(smsc_hub->int_pad_reg, 0,
							HSIC_HUB_INT_VOL_MAX);
				return ret;
			}
		}
	}

	return 0;
}
int msm_gemini_platform_init(struct platform_device *pdev,
	struct resource **mem,
	void **base,
	int *irq,
	irqreturn_t (*handler) (int, void *),
	void *context)
{
	int rc = -1;
	int gemini_irq;
	struct resource *gemini_mem, *gemini_io, *gemini_irq_res;
	void *gemini_base;
	struct msm_gemini_device *pgmn_dev =
		(struct msm_gemini_device *) context;

	gemini_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!gemini_mem) {
		GMN_PR_ERR("%s: no mem resource?\n", __func__);
		return -ENODEV;
	}

	gemini_irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
	if (!gemini_irq_res) {
		GMN_PR_ERR("no irq resource?\n");
		return -ENODEV;
	}
	gemini_irq = gemini_irq_res->start;

	gemini_io = request_mem_region(gemini_mem->start,
		resource_size(gemini_mem), pdev->name);
	if (!gemini_io) {
		GMN_PR_ERR("%s: region already claimed\n", __func__);
		return -EBUSY;
	}

	gemini_base = ioremap(gemini_mem->start, resource_size(gemini_mem));
	if (!gemini_base) {
		rc = -ENOMEM;
		GMN_PR_ERR("%s: ioremap failed\n", __func__);
		goto fail1;
	}

	pgmn_dev->hw_version = GEMINI_8X60;
	rc = msm_cam_clk_enable(&pgmn_dev->pdev->dev, gemini_8x_clk_info,
	 pgmn_dev->gemini_clk, ARRAY_SIZE(gemini_8x_clk_info), 1);
	if (rc < 0) {
		pgmn_dev->hw_version = GEMINI_7X;
		rc = msm_cam_clk_enable(&pgmn_dev->pdev->dev,
			gemini_7x_clk_info, pgmn_dev->gemini_clk,
			ARRAY_SIZE(gemini_7x_clk_info), 1);
		if (rc < 0) {
			GMN_PR_ERR("%s: clk failed rc = %d\n", __func__, rc);
			goto fail2;
		}
	} else {
#ifndef CONFIG_ARCH_MSM8X60
		rc = msm_cam_clk_enable(&pgmn_dev->pdev->dev,
				gemini_imem_clk_info, &pgmn_dev->gemini_clk[2],
				ARRAY_SIZE(gemini_imem_clk_info), 1);
		if (!rc)
			pgmn_dev->hw_version = GEMINI_8960;
#endif 
	}

	if (pgmn_dev->hw_version != GEMINI_7X) {
		if (pgmn_dev->gemini_fs == NULL) {
			pgmn_dev->gemini_fs =
				regulator_get(&pgmn_dev->pdev->dev, "vdd");
			if (IS_ERR(pgmn_dev->gemini_fs)) {
				pr_err("%s: Regulator FS_ijpeg get failed %ld\n",
					__func__, PTR_ERR(pgmn_dev->gemini_fs));
				pgmn_dev->gemini_fs = NULL;
				goto gemini_fs_failed;
			} else if (regulator_enable(pgmn_dev->gemini_fs)) {
				pr_err("%s: Regulator FS_ijpeg enable failed\n",
								__func__);
				regulator_put(pgmn_dev->gemini_fs);
				pgmn_dev->gemini_fs = NULL;
				goto gemini_fs_failed;
			}
		}
 	}

	msm_gemini_hw_init(gemini_base, resource_size(gemini_mem));
	rc = request_irq(gemini_irq, handler, IRQF_TRIGGER_RISING, "gemini",
		context);
	if (rc) {
		GMN_PR_ERR("%s: request_irq failed, %d\n", __func__,
			gemini_irq);
		goto fail3;
	}

	*mem  = gemini_mem;
	*base = gemini_base;
	*irq  = gemini_irq;

#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
	gemini_client = msm_ion_client_create(-1, "camera/gemini");
#endif
	GMN_DBG("%s:%d] success\n", __func__, __LINE__);

	return rc;

fail3:
	if (pgmn_dev->hw_version != GEMINI_7X) {
		regulator_disable(pgmn_dev->gemini_fs);
		regulator_put(pgmn_dev->gemini_fs);
		pgmn_dev->gemini_fs = NULL;
	}
gemini_fs_failed:
	if (pgmn_dev->hw_version == GEMINI_8960)
		msm_cam_clk_enable(&pgmn_dev->pdev->dev, gemini_imem_clk_info,
		 &pgmn_dev->gemini_clk[2], ARRAY_SIZE(gemini_imem_clk_info), 0);
	if (pgmn_dev->hw_version != GEMINI_7X)
		msm_cam_clk_enable(&pgmn_dev->pdev->dev, gemini_8x_clk_info,
		pgmn_dev->gemini_clk, ARRAY_SIZE(gemini_8x_clk_info), 0);
	else
		msm_cam_clk_enable(&pgmn_dev->pdev->dev, gemini_7x_clk_info,
		pgmn_dev->gemini_clk, ARRAY_SIZE(gemini_7x_clk_info), 0);
fail2:
	iounmap(gemini_base);
fail1:
	release_mem_region(gemini_mem->start, resource_size(gemini_mem));
	GMN_DBG("%s:%d] fail\n", __func__, __LINE__);
	return rc;
}
Пример #11
0
static bool pmu_activate_sim(Int32 volt)
{
    bool bRet = FALSE;

    // we pre-define three slection ==>BCM_SIM_VOLT_0,     BCM_SIM_VOLT_1V8,   BCM_SIM_VOLT_3V
    switch((PMU_SIMVolt_t)volt)
    {
        case PMU_SIM3P0Volt:
        {
            //CLRREG8(&pWords, 0xc0);
			if(!regulator_is_enabled(sim_regulator))
				regulator_enable(sim_regulator);
			regulator_set_voltage(sim_regulator,3000000,3000000);
			pr_info("%s:PMU_SIM3P0Volt\n",__func__);
	    	bRet= TRUE;
            g_bPmuSimInited = TRUE;
        }
        break;

        case PMU_SIM2P5Volt:
        {
            //CLRREG8(&pWords, 0xc0);
            //bRet = WritePMUReg(PMU_REG_LCSIMDOCTRL, pWords);
            //bRet = WritePMUReg(PMU_REG_SOPMODCTRL, 0x00);
            KRIL_DEBUG(DBG_INFO,"---> BCMCpCmdHand: CAPI2_PMU_ActivateSIM -> set to 2.5V\n");
			if(!regulator_is_enabled(sim_regulator))
				regulator_enable(sim_regulator);
			regulator_set_voltage(sim_regulator,2500000,2500000);
			bRet= TRUE;
			g_bPmuSimInited = TRUE;
			pr_info("%s:PMU_SIM2P5Volt\n",__func__);
       }
        break;

        case PMU_SIM1P8Volt:
        {
            //SETREG8(&pWords, 0xc0);
			if(!regulator_is_enabled(sim_regulator))
				regulator_enable(sim_regulator);
			regulator_set_voltage(sim_regulator,1800000,1800000);
			bRet= TRUE;
			g_bPmuSimInited = TRUE;
			pr_info("%s:PMU_SIM1P8Volt\n",__func__);
			KRIL_DEBUG(DBG_INFO,"---> BCMCpCmdHand: CAPI2_PMU_ActivateSIM -> set to 1.8V\n");
            
        }
        break;

        case PMU_SIM0P0Volt:
        {
			if(regulator_is_enabled(sim_regulator))
				regulator_disable(sim_regulator);
			pr_info("%s:PMU_SIM0P0Volt\n",__func__);
            KRIL_DEBUG(DBG_INFO,"---> BCMCpCmdHand: CAPI2_PMU_ActivateSIM -> set to 0V\n");
			bRet= TRUE;
        }
        break;

        default:
        {
            KRIL_DEBUG(DBG_ERROR,"---> BCMCpCmdHand: CAPI2_PMU_ActivateSIM -> unknown Volt!\n");
            bRet = FALSE;
        }
    }

    if(bRet)
    {
        bRet = TRUE;
    }
    else
    {
        KRIL_DEBUG(DBG_ERROR," ---> BCMCpCmdHand: CAPI2_PMU_ActivateSIM fail!\n");
    }


    return bRet;
}
Пример #12
0
int sdhci_kona_sdio_regulator_power(struct sdio_dev *dev, int power_state)
{
	int ret = 0;
	struct device *pdev = dev->dev;
	struct sdio_platform_cfg *hw_cfg = (struct sdio_platform_cfg *)pdev->platform_data;

	/*
	 * Note that from the board file the appropriate regualtor names are
	 * populated. For example, in SD Card case there are two regulators to
	 * control
	 * vddo - That controls the power to the external card
	 * vddsdxc - That controls the power to the IO lines
	 * For the interfaces used for eMMC and WLAN only vddo is present.
	 * The understanding is that,  if for some intefaces like WLAN if the
	 * regulator need not be switched OFF then from the board file do not
	 * populate the regulator names.
	 */
	if( hw_cfg->devtype==SDIO_DEV_TYPE_SDMMC ) {
		if (dev->vdd_sdxc_regulator) {
			if (power_state) {
				dev_err(dev->dev, "Turning ON sdxc sd \r\n");
				if(!regulator_is_enabled(dev->vdd_sdxc_regulator)) {
					ret = regulator_enable(dev->vdd_sdxc_regulator);
				}
			} else {
				dev_err(dev->dev, "Turning OFF sdxc sd \r\n");
				ret = regulator_disable(dev->vdd_sdxc_regulator);
			}
		 }

		 if (dev->vddo_sd_regulator) {
			if (power_state) {
				dev_err(dev->dev, "Turning ON vddo sd \r\n");
				if(!regulator_is_enabled(dev->vddo_sd_regulator)) {
					ret = regulator_enable(dev->vddo_sd_regulator);
				}
			} else{
				dev_err(dev->dev, "Turning OFF vddo sd \r\n");
				ret = regulator_disable(dev->vddo_sd_regulator);
			}
		 }

		if (power_state) {
			if( hw_cfg->configure_sdio_pullup ) {
			    dev_err(dev->dev, "Pull-Up CMD/DAT Line  \r\n");
				mdelay(1);
				hw_cfg->configure_sdio_pullup(1);
				mdelay(1);
			}
		} else{
			if( hw_cfg->configure_sdio_pullup ) {
				dev_err(dev->dev, "Pull Down CMD/DAT Line\r\n");
				hw_cfg->configure_sdio_pullup(0);
				mdelay(1);
			}
		 }

		if (power_state)
			udelay(STABLE_TIME_AFTER_POWER_ON_US);
		else
			mdelay(STABLE_TIME_AFTER_POWER_OFF_MS);
	}


	return ret;
}
Пример #13
0
static int sdhci_pltfm_regulator_init(struct platform_device *pdev,
		struct sdio_platform_cfg *hw_cfg)
{
	int ret;
	struct sdio_dev *dev = platform_get_drvdata(pdev);
	char devname[MAX_DEV_NAME_SIZE];

	if (dev == NULL) {
		printk(KERN_ERR "%s dev is null\n", __func__);
		return -EINVAL;
	}

	snprintf(devname, sizeof(devname), "%s%d", DEV_NAME, pdev->id);

	/* VDDMMC used for our low level regulator control. Valid for SD*/
	dev->vddo_sd_regulator = regulator_get(&pdev->dev, "vddmmc");
	if (IS_ERR(dev->vddo_sd_regulator)) {
		pr_err("Unable to get vddmmc regulator, err: %ld\n",
				PTR_ERR(dev->vddo_sd_regulator));
		dev->vddo_sd_regulator = NULL;
		return 0;
	}

	if (dev->vddo_sd_regulator)
		ret = regulator_enable(dev->vddo_sd_regulator);
	if (ret < 0) {
		printk(KERN_ERR "Unable to enable vddmmc regulator\n");
		goto err_put_vddmmc_reg;
	}

	printk(KERN_INFO "Found and enabled vddmmc regulator for %s\n",
		devname);

	/* VDDO */
	dev->vdd_sdxc_regulator = regulator_get(&pdev->dev, "vddo");
	if (IS_ERR(dev->vdd_sdxc_regulator)) {
		pr_err("Unable to get vddo regulator, err: %ld\n",
				PTR_ERR(dev->vdd_sdxc_regulator));
		dev->vdd_sdxc_regulator = NULL;
		ret = 0;
		goto err_disable_vddmmc_reg;
	}

	if (dev->vdd_sdxc_regulator)
		ret = regulator_enable(dev->vdd_sdxc_regulator);
	if (ret < 0) {
		printk(KERN_ERR "Unable to enable vddo regulator\n");
		goto err_put_vddo_reg;
	}

	/* set to 3.3V by default */
	if (dev->vdd_sdxc_regulator)
		ret = regulator_set_voltage(dev->vdd_sdxc_regulator, 3000000, 3000000);
	if (ret < 0) {
		printk(KERN_ERR "Unable to set vddo regulator to 3.3V\n");
		goto err_disable_vddo_reg;
	}

	printk(KERN_INFO "Found and enabled vddo regulator for %s\n", devname);

	udelay(STABLE_TIME_AFTER_POWER_ON_US);

	return 0;


err_disable_vddo_reg:
	if (dev->vdd_sdxc_regulator)
		regulator_disable(dev->vdd_sdxc_regulator);

err_put_vddo_reg:
	if (dev->vdd_sdxc_regulator) {
		regulator_put(dev->vdd_sdxc_regulator);
		dev->vdd_sdxc_regulator = NULL;
	}

err_disable_vddmmc_reg:
	if (dev->vddo_sd_regulator)
		regulator_disable(dev->vddo_sd_regulator);

err_put_vddmmc_reg:
	if (dev->vddo_sd_regulator) {
		regulator_put(dev->vddo_sd_regulator);
		dev->vddo_sd_regulator = NULL;
	}


	return ret;
}
Пример #14
0
static int host_start(struct ci_hdrc *ci)
{
	struct usb_hcd *hcd;
	struct ehci_hcd *ehci;
	struct ehci_ci_priv *priv;
	int ret;

	if (usb_disabled())
		return -ENODEV;

	hcd = usb_create_hcd(&ci_ehci_hc_driver, ci->dev, dev_name(ci->dev));
	if (!hcd)
		return -ENOMEM;

	dev_set_drvdata(ci->dev, ci);
	hcd->rsrc_start = ci->hw_bank.phys;
	hcd->rsrc_len = ci->hw_bank.size;
	hcd->regs = ci->hw_bank.abs;
	hcd->has_tt = 1;

	hcd->power_budget = ci->platdata->power_budget;
	hcd->tpl_support = ci->platdata->tpl_support;
	if (ci->phy)
		hcd->phy = ci->phy;
	else
		hcd->usb_phy = ci->usb_phy;

	ehci = hcd_to_ehci(hcd);
	ehci->caps = ci->hw_bank.cap;
	ehci->has_hostpc = ci->hw_bank.lpm;
	ehci->has_tdi_phy_lpm = ci->hw_bank.lpm;
	ehci->imx28_write_fix = ci->imx28_write_fix;

	priv = (struct ehci_ci_priv *)ehci->priv;
	priv->reg_vbus = NULL;

	if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci)) {
		if (ci->platdata->flags & CI_HDRC_IMX_VBUS_EARLY_ON) {
			ret = regulator_enable(ci->platdata->reg_vbus);
			if (ret) {
				dev_err(ci->dev,
				"Failed to enable vbus regulator, ret=%d\n",
									ret);
				goto put_hcd;
			}
		} else {
			priv->reg_vbus = ci->platdata->reg_vbus;
		}
	}

	ret = usb_add_hcd(hcd, 0, 0);
	if (ret) {
		goto disable_reg;
	} else {
		struct usb_otg *otg = &ci->otg;

		ci->hcd = hcd;

		if (ci_otg_is_fsm_mode(ci)) {
			hcd->self.otg_fsm = &ci->fsm;
			otg->host = &hcd->self;
			hcd->self.otg_port = 1;
		}
	}

	if (ci->platdata->flags & CI_HDRC_DISABLE_STREAMING)
		hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);

	if (ci->platdata->notify_event &&
		(ci->platdata->flags & CI_HDRC_IMX_IS_HSIC))
		ci->platdata->notify_event
			(ci, CI_HDRC_IMX_HSIC_ACTIVE_EVENT);

	if (ci->platdata->flags & CI_HDRC_DISABLE_HOST_STREAMING)
		hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);

	ci_hdrc_ahb_config(ci);

	return ret;

disable_reg:
	if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) &&
			(ci->platdata->flags & CI_HDRC_IMX_VBUS_EARLY_ON))
		regulator_disable(ci->platdata->reg_vbus);
put_hcd:
	usb_put_hcd(hcd);

	return ret;
}
Пример #15
0
static int w1_gpio_probe(struct platform_device *pdev)
{
	struct w1_bus_master *master;
	struct w1_gpio_platform_data *pdata;
	struct pinctrl *pinctrl;
	int err;

	pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
	if (IS_ERR(pinctrl))
		dev_warn(&pdev->dev, "unable to select pin group\n");

	if (of_have_populated_dt()) {
		err = w1_gpio_probe_dt(pdev);
		if (err < 0) {
			dev_err(&pdev->dev, "Failed to parse DT\n");
			return err;
		}
	}

	pdata = pdev->dev.platform_data;

	if (!pdata) {
		dev_err(&pdev->dev, "No configuration data\n");
		return -ENXIO;
	}

	master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL);
	if (!master) {
		dev_err(&pdev->dev, "Out of memory\n");
		return -ENOMEM;
	}

	err = gpio_request(pdata->pin, "w1");
	if (err) {
		dev_err(&pdev->dev, "gpio_request (pin) failed\n");
		goto free_master;
	}

	if (gpio_is_valid(pdata->ext_pullup_enable_pin)) {
		err = gpio_request_one(pdata->ext_pullup_enable_pin,
				       GPIOF_INIT_LOW, "w1 pullup");
		if (err < 0) {
			dev_err(&pdev->dev, "gpio_request_one "
					"(ext_pullup_enable_pin) failed\n");
			goto free_gpio;
		}
	}

	master->data = pdata;
	master->read_bit = w1_gpio_read_bit;

	if (pdata->is_open_drain) {
		gpio_direction_output(pdata->pin, 1);
		master->write_bit = w1_gpio_write_bit_val;
	} else {
		gpio_direction_input(pdata->pin);
		master->write_bit = w1_gpio_write_bit_dir;
	}

	err = w1_add_master_device(master);
	if (err) {
		dev_err(&pdev->dev, "w1_add_master device failed\n");
		goto free_gpio_ext_pu;
	}

	/* voltage regulator support */
	pdata->regulator_en = 0;
	pdata->w1_gpio_vdd = regulator_get(&pdev->dev, "w1_vdd");
	if (IS_ERR(pdata->w1_gpio_vdd)) {
		pdata->w1_gpio_vdd = NULL;
		dev_err(&pdev->dev,
				"%s: Failed to get w1_vdd regulator\n",
				__func__);
	} else {
		dev_err(&pdev->dev, "w1-vdd regulator is initially %s\n",
			regulator_is_enabled(pdata->w1_gpio_vdd) ?
			"on" : "off");
		err = regulator_enable(pdata->w1_gpio_vdd);
		if (err) {
			pr_err("%s: Error %d enabling w1-vdd regulator\n",
				__func__, err);
			goto free_regulator;
		} else {
			pdata->regulator_en = 1;
		}
	}

	if (pdata->enable_external_pullup)
		pdata->enable_external_pullup(1);

	if (gpio_is_valid(pdata->ext_pullup_enable_pin))
		gpio_set_value(pdata->ext_pullup_enable_pin, 1);

	platform_set_drvdata(pdev, master);

	return 0;

 free_regulator:
	if (pdata->w1_gpio_vdd != NULL)
		regulator_put(pdata->w1_gpio_vdd);
 free_gpio_ext_pu:
	if (gpio_is_valid(pdata->ext_pullup_enable_pin))
		gpio_free(pdata->ext_pullup_enable_pin);
 free_gpio:
	gpio_free(pdata->pin);
 free_master:
	kfree(master);

	return err;
}
Пример #16
0
static int __devinit smsc_hub_probe(struct platform_device *pdev)
{
	int ret = 0;
	const struct smsc_hub_platform_data *pdata;
	struct device_node *node = pdev->dev.of_node;
	struct i2c_adapter *i2c_adap;
	struct i2c_board_info i2c_info;

	if (pdev->dev.of_node) {
		dev_dbg(&pdev->dev, "device tree enabled\n");
		pdev->dev.platform_data = msm_hub_dt_to_pdata(pdev);
		if (IS_ERR(pdev->dev.platform_data))
			return PTR_ERR(pdev->dev.platform_data);

		dev_set_name(&pdev->dev, smsc_hub_driver.driver.name);
	}

	if (!pdev->dev.platform_data) {
		dev_err(&pdev->dev, "No platform data\n");
		return -ENODEV;
	}

	pdata = pdev->dev.platform_data;
	if (!pdata->hub_reset)
		return -EINVAL;

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

	smsc_hub->dev = &pdev->dev;
	smsc_hub->pdata = pdev->dev.platform_data;

	smsc_hub->hub_vbus_reg = devm_regulator_get(&pdev->dev, "hub_vbus");
	ret = PTR_ERR(smsc_hub->hub_vbus_reg);
	if (ret == -EPROBE_DEFER) {
		dev_dbg(&pdev->dev, "failed to get hub_vbus\n");
		return ret;
	}

	ret = msm_hsic_hub_init_vdd(smsc_hub, 1);
	if (ret) {
		dev_err(&pdev->dev, "failed to init hub VDD\n");
		return ret;
	}
	ret = msm_hsic_hub_init_clock(smsc_hub, 1);
	if (ret) {
		dev_err(&pdev->dev, "failed to init hub clock\n");
		goto uninit_vdd;
	}
	ret = msm_hsic_hub_init_gpio(smsc_hub, 1);
	if (ret) {
		dev_err(&pdev->dev, "failed to init hub gpios\n");
		goto uninit_clock;
	}

	gpio_direction_output(pdata->hub_reset, 0);
	/* Hub reset should be asserted for minimum 2microsec
	 * before deasserting.
	 */
	udelay(5);
	gpio_direction_output(pdata->hub_reset, 1);

	ret = of_platform_populate(node, NULL, NULL, &pdev->dev);
	if (ret) {
		dev_err(&pdev->dev, "failed to add child node, ret=%d\n", ret);
		goto uninit_gpio;
	}

	if (!IS_ERR(smsc_hub->hub_vbus_reg)) {
		ret = regulator_enable(smsc_hub->hub_vbus_reg);
		if (ret) {
			dev_err(&pdev->dev, "unable to enable hub_vbus\n");
			goto uninit_gpio;
		}
	}

	ret = i2c_add_driver(&hsic_hub_driver);
	if (ret < 0) {
		dev_err(&pdev->dev, "failed to add I2C hsic_hub_driver\n");
		goto i2c_add_fail;
	}
	usleep_range(10000, 12000);
	i2c_adap = i2c_get_adapter(SMSC_GSBI_I2C_BUS_ID);

	if (!i2c_adap) {
		dev_err(&pdev->dev, "failed to get i2c adapter\n");
		i2c_del_driver(&hsic_hub_driver);
		goto i2c_add_fail;
	}

	memset(&i2c_info, 0, sizeof(struct i2c_board_info));
	strlcpy(i2c_info.type, "i2c_hsic_hub", I2C_NAME_SIZE);

	smsc_hub->client = i2c_new_probed_device(i2c_adap, &i2c_info,
						   normal_i2c, NULL);
	i2c_put_adapter(i2c_adap);
	if (!smsc_hub->client)
		dev_err(&pdev->dev, "failed to connect to smsc_hub"
			 "through I2C\n");

i2c_add_fail:
	pm_runtime_set_active(&pdev->dev);
	pm_runtime_enable(&pdev->dev);

	return 0;

uninit_gpio:
	msm_hsic_hub_init_gpio(smsc_hub, 0);
uninit_clock:
	msm_hsic_hub_init_clock(smsc_hub, 0);
uninit_vdd:
	msm_hsic_hub_init_vdd(smsc_hub, 0);

	return ret;
}
Пример #17
0
int mdss_dsi_panel_power_on(struct mdss_panel_data *pdata, int enable)
{
	int ret;
	struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;

	if (pdata == NULL) {
		pr_err("%s: Invalid input data\n", __func__);
		return -EINVAL;
	}

	ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
				panel_data);
	pr_debug("%s: enable=%d\n", __func__, enable);

       /* Z OLED power on start */
	if (enable) {
		if (ctrl_pdata->power_data.num_vreg > 0) {
			ret = msm_dss_enable_vreg(
				ctrl_pdata->power_data.vreg_config,
				ctrl_pdata->power_data.num_vreg, 1);
			if (ret) {
				pr_err("%s:Failed to enable regulators.rc=%d\n",
					__func__, ret);
				return ret;
			}

			/*
			 * A small delay is needed here after enabling
			 * all regulators and before issuing panel reset
			 */
			msleep(20);
		} else {

			ret = regulator_set_optimum_mode(
				(ctrl_pdata->shared_pdata).vdd_io_vreg, 100000);
			if (ret < 0) {
				pr_err("%s: vdd_io_vreg set opt mode failed.\n",
					__func__);
				return ret;
			}

			ret = regulator_set_optimum_mode(
				(ctrl_pdata->shared_pdata).vdda_vreg, 100000);
			if (ret < 0) {
				pr_err("%s: vdda_vreg set opt mode failed.\n",
					__func__);
				return ret;
			}

			if (gpio_is_valid(ctrl_pdata->disp_en_gpio)) {
				gpio_set_value((ctrl_pdata->disp_en_gpio), 1);
				msleep(1);
			} else
				pr_err("%s:%d, disp_en_gpio is not valid\n",
				__func__, __LINE__);

			ret = regulator_enable(
				(ctrl_pdata->shared_pdata).vdd_io_vreg);
			if (ret) {
				pr_err("%s: Failed to enable regulator.\n",
					__func__);
				return ret;
			}

			ret = regulator_enable(
				(ctrl_pdata->shared_pdata).vdda_vreg);
			if (ret) {
				pr_err("%s: Failed to enable regulator.\n",
					__func__);
				return ret;
			}
			msleep(10);
		}
	/* Z OLED power off start */
	} else {
		msleep(20);
		mdss_dsi_panel_reset(pdata, 0);
		msleep(20);

		if (ctrl_pdata->power_data.num_vreg > 0) {
			ret = msm_dss_enable_vreg(
				ctrl_pdata->power_data.vreg_config,
				ctrl_pdata->power_data.num_vreg, 0);
			if (ret) {
				pr_err("%s: Failed to disable regs.rc=%d\n",
					__func__, ret);
				return ret;
			}
		} else {
			ret = regulator_disable(
				(ctrl_pdata->shared_pdata).vdda_vreg);
			if (ret) {
				pr_err("%s: Failed to disable regulator.\n",
					__func__);
				return ret;
			}

#if 0
			ret = regulator_disable(
				(ctrl_pdata->shared_pdata).vdd_io_vreg);
			if (ret) {
				pr_err("%s: Failed to disable regulator.\n",
					__func__);
				return ret;
			}
#endif
			if (gpio_is_valid(ctrl_pdata->disp_en_gpio)) {
				gpio_set_value((ctrl_pdata->disp_en_gpio), 0);
				msleep(1);
			} else
				pr_err("%s:%d, disp_en_gpio is not valid\n",
				__func__, __LINE__);

			ret = regulator_set_optimum_mode(
				(ctrl_pdata->shared_pdata).vdd_io_vreg, 100);
			if (ret < 0) {
				pr_err("%s: vdd_io_vreg set opt mode failed.\n",
					__func__);
				return ret;
			}

			ret = regulator_set_optimum_mode(
				(ctrl_pdata->shared_pdata).vdda_vreg, 100);
			if (ret < 0) {
				pr_err("%s: vdda_vreg set opt mode failed.\n",
					__func__);
				return ret;
			}
		}
	}
	pr_info("[Zee][OLED] mdss_dsi_panel_power %s\n", enable ? "on" : "off");
	return 0;
}
Пример #18
0
static int bq27520_power(bool enable, struct bq27520_device_info *di)
{
	int rc = 0, ret;
	const struct bq27520_platform_data *platdata;

	platdata = di->pdata;
	if (enable) {
		/* switch on Vreg_S3 */
		rc = regulator_enable(vreg_bq27520);
		if (rc < 0) {
			dev_err(di->dev, "%s: vreg %s %s failed (%d)\n",
				__func__, platdata->vreg_name, "enable", rc);
			goto vreg_fail;
		}

		/* Battery gauge enable and switch on onchip 2.5V LDO */
		rc = gpio_request(platdata->chip_en, "GAUGE_EN");
		if (rc) {
			dev_err(di->dev, "%s: fail to request gpio %d (%d)\n",
				__func__, platdata->chip_en, rc);
			goto vreg_fail;
		}

		gpio_direction_output(platdata->chip_en, 0);
		gpio_set_value(platdata->chip_en, 1);
		rc = gpio_request(platdata->soc_int, "GAUGE_SOC_INT");
		if (rc) {
			dev_err(di->dev, "%s: fail to request gpio %d (%d)\n",
				__func__, platdata->soc_int, rc);
			goto gpio_fail;
		}
		gpio_direction_input(platdata->soc_int);
		di->irq = gpio_to_irq(platdata->soc_int);
		rc = request_threaded_irq(di->irq, NULL, soc_irqhandler,
				IRQF_TRIGGER_FALLING|IRQF_TRIGGER_RISING,
				"BQ27520_IRQ", di);
		if (rc) {
			dev_err(di->dev, "%s: fail to request irq %d (%d)\n",
				__func__, platdata->soc_int, rc);
			goto irqreq_fail;
		} else {
			disable_irq_nosync(di->irq);
		}
	} else {
		free_irq(di->irq, di);
		gpio_free(platdata->soc_int);
		/* switch off on-chip 2.5V LDO and disable Battery gauge */
		gpio_set_value(platdata->chip_en, 0);
		gpio_free(platdata->chip_en);
		/* switch off Vreg_S3 */
		rc = regulator_disable(vreg_bq27520);
		if (rc < 0) {
			dev_err(di->dev, "%s: vreg %s %s failed (%d)\n",
				__func__, platdata->vreg_name, "disable", rc);
			goto vreg_fail;
		}
	}
	return rc;

irqreq_fail:
	gpio_free(platdata->soc_int);
gpio_fail:
	gpio_set_value(platdata->chip_en, 0);
	gpio_free(platdata->chip_en);
vreg_fail:
	ret = !enable ? regulator_enable(vreg_bq27520) :
		regulator_disable(vreg_bq27520);
	if (ret < 0) {
		dev_err(di->dev, "%s: vreg %s %s failed (%d) in err path\n",
			__func__, platdata->vreg_name,
			!enable ? "enable" : "disable", ret);
	}
	return rc;
}
static int mipi_dsi_panel_power(int on)
{
	static struct regulator *v_lcm, *v_lcmio, *v_dsivdd;
	static bool bPanelPowerOn = false;
	int rc;

	char *lcm_str = "8921_l11";
	char *lcmio_str = "8921_lvs5";
	char *dsivdd_str = "8921_l2";
        
        printk(KERN_ERR  "[DISP] %s +++\n", __func__);
	/* To avoid system crash in shutdown for non-panel case */
	if (panel_type == PANEL_ID_NONE)
		return -ENODEV;

	printk(KERN_INFO "%s: state : %d\n", __func__, on);

	if (!dsi_power_on) {
		v_lcm = regulator_get(&msm_mipi_dsi1_device.dev,
				lcm_str);
		if (IS_ERR_OR_NULL(v_lcm)) {
			printk(KERN_ERR "could not get %s, rc = %ld\n",
				lcm_str, PTR_ERR(v_lcm));
			return -ENODEV;
		}

		v_lcmio = regulator_get(&msm_mipi_dsi1_device.dev,
				lcmio_str);
		if (IS_ERR_OR_NULL(v_lcmio)) {
			printk(KERN_ERR "could not get %s, rc = %ld\n",
				lcmio_str, PTR_ERR(v_lcmio));
			return -ENODEV;
		}


		v_dsivdd = regulator_get(&msm_mipi_dsi1_device.dev,
				dsivdd_str);
		if (IS_ERR_OR_NULL(v_dsivdd)) {
			printk(KERN_ERR "could not get %s, rc = %ld\n",
				dsivdd_str, PTR_ERR(v_dsivdd));
			return -ENODEV;
		}

		rc = regulator_set_voltage(v_lcm, 3000000, 3000000);
		if (rc) {
			printk(KERN_ERR "%s#%d: set_voltage %s failed, rc=%d\n", __func__, __LINE__, lcm_str, rc);
			return -EINVAL;
		}

		rc = regulator_set_voltage(v_dsivdd, 1200000, 1200000);
		if (rc) {
			printk(KERN_ERR "%s#%d: set_voltage %s failed, rc=%d\n", __func__, __LINE__, dsivdd_str, rc);
			return -EINVAL;
		}

		rc = gpio_request(VILLE_GPIO_LCD_RSTz, "LCM_RST_N");
		if (rc) {
			printk(KERN_ERR "%s:LCM gpio %d request failed, rc=%d\n", __func__,  VILLE_GPIO_LCD_RSTz, rc);
			return -EINVAL;
		}

		dsi_power_on = true;
	}

	if (on) {
		printk(KERN_INFO "%s: on\n", __func__);
		rc = regulator_set_optimum_mode(v_lcm, 100000);
		if (rc < 0) {
			printk(KERN_ERR "set_optimum_mode %s failed, rc=%d\n", lcm_str, rc);
			return -EINVAL;
		}

		rc = regulator_set_optimum_mode(v_dsivdd, 100000);
		if (rc < 0) {
			printk(KERN_ERR "set_optimum_mode %s failed, rc=%d\n", dsivdd_str, rc);
			return -EINVAL;
		}

		rc = regulator_enable(v_dsivdd);
		if (rc) {
			printk(KERN_ERR "enable regulator %s failed, rc=%d\n", dsivdd_str, rc);
			return -ENODEV;
		}
		msleep(1);
		rc = regulator_enable(v_lcmio);
		if (rc) {
			printk(KERN_ERR "enable regulator %s failed, rc=%d\n", lcmio_str, rc);
			return -ENODEV;
		}

		rc = regulator_enable(v_lcm);
		if (rc) {
			printk(KERN_ERR "enable regulator %s failed, rc=%d\n", lcm_str, rc);
			return -ENODEV;
		}

		if (!mipi_lcd_on) {
			msleep(10);
			gpio_set_value(VILLE_GPIO_LCD_RSTz, 1);
			msleep(1);
			gpio_set_value(VILLE_GPIO_LCD_RSTz, 0);
			msleep(35);
			gpio_set_value(VILLE_GPIO_LCD_RSTz, 1);
		}
		msleep(60);

		bPanelPowerOn = true;
	} else {
		printk(KERN_INFO "%s: off\n", __func__);
		if (!bPanelPowerOn) return 0;
		msleep(100);
		gpio_set_value(VILLE_GPIO_LCD_RSTz, 0);
		msleep(10);

		if (regulator_disable(v_dsivdd)) {
			printk(KERN_ERR "%s: Unable to enable the regulator: %s\n", __func__, dsivdd_str);
			return -EINVAL;
		}

		if (regulator_disable(v_lcm)) {
			printk(KERN_ERR "%s: Unable to enable the regulator: %s\n", __func__, lcm_str);
			return -EINVAL;
		}
		msleep(5);
		if (regulator_disable(v_lcmio)) {
			printk(KERN_ERR "%s: Unable to enable the regulator: %s\n", __func__, lcmio_str);
			return -EINVAL;
		}

		rc = regulator_set_optimum_mode(v_dsivdd, 100);
		if (rc < 0) {
			printk(KERN_ERR "%s: Unable to enable the regulator: %s\n", __func__, dsivdd_str);
			return -EINVAL;
		}

		bPanelPowerOn = false;
	}
	return 0;
}
static int lm3530_init_registers(struct lm3530_data *drvdata)
{
	int ret = 0;
	int i;
	u8 gen_config;
	u8 als_config = 0;
	u8 brt_ramp;
	u8 als_imp_sel = 0;
	u8 brightness;
	u8 reg_val[LM3530_REG_MAX];
	u8 zones[LM3530_ALS_ZB_MAX];
	u32 als_vmin, als_vmax, als_vstep;
	struct lm3530_platform_data *pdata = drvdata->pdata;
	struct i2c_client *client = drvdata->client;
	struct lm3530_pwm_data *pwm = &pdata->pwm_data;

	gen_config = (pdata->brt_ramp_law << LM3530_RAMP_LAW_SHIFT) |
			((pdata->max_current & 7) << LM3530_MAX_CURR_SHIFT);

	switch (drvdata->mode) {
	case LM3530_BL_MODE_MANUAL:
	case LM3530_BL_MODE_ALS:
		gen_config |= LM3530_ENABLE_I2C;
		break;
	case LM3530_BL_MODE_PWM:
		gen_config |= LM3530_ENABLE_PWM | LM3530_ENABLE_PWM_SIMPLE |
			      (pdata->pwm_pol_hi << LM3530_PWM_POL_SHIFT);
		break;
	}

	if (drvdata->mode == LM3530_BL_MODE_ALS) {
		if (pdata->als_vmax == 0) {
			pdata->als_vmin = 0;
			pdata->als_vmax = LM3530_ALS_WINDOW_mV;
		}

		als_vmin = pdata->als_vmin;
		als_vmax = pdata->als_vmax;

		if ((als_vmax - als_vmin) > LM3530_ALS_WINDOW_mV)
			pdata->als_vmax = als_vmax =
				als_vmin + LM3530_ALS_WINDOW_mV;

		
		als_vstep = (als_vmax - als_vmin) / (LM3530_ALS_ZB_MAX + 1);

		for (i = 0; i < LM3530_ALS_ZB_MAX; i++)
			zones[i] = (((als_vmin + LM3530_ALS_OFFSET_mV) +
					als_vstep + (i * als_vstep)) * LED_FULL)
					/ 1000;

		als_config =
			(pdata->als_avrg_time << LM3530_ALS_AVG_TIME_SHIFT) |
			(LM3530_ENABLE_ALS) |
			(pdata->als_input_mode << LM3530_ALS_SEL_SHIFT);

		als_imp_sel =
			(pdata->als1_resistor_sel << LM3530_ALS1_IMP_SHIFT) |
			(pdata->als2_resistor_sel << LM3530_ALS2_IMP_SHIFT);

	}

	brt_ramp = (pdata->brt_ramp_fall << LM3530_BRT_RAMP_FALL_SHIFT) |
			(pdata->brt_ramp_rise << LM3530_BRT_RAMP_RISE_SHIFT);

	if (drvdata->brightness)
		brightness = drvdata->brightness;
	else
		brightness = drvdata->brightness = pdata->brt_val;

	if (brightness > drvdata->led_dev.max_brightness)
		brightness = drvdata->led_dev.max_brightness;

	reg_val[0] = gen_config;	
	reg_val[1] = als_config;	
	reg_val[2] = brt_ramp;		
	reg_val[3] = als_imp_sel;	
	reg_val[4] = brightness;	
	reg_val[5] = zones[0];		
	reg_val[6] = zones[1];		
	reg_val[7] = zones[2];		
	reg_val[8] = zones[3];		
	reg_val[9] = LM3530_DEF_ZT_0;	
	reg_val[10] = LM3530_DEF_ZT_1;	
	reg_val[11] = LM3530_DEF_ZT_2;	
	reg_val[12] = LM3530_DEF_ZT_3;	
	reg_val[13] = LM3530_DEF_ZT_4;	

	if (!drvdata->enable) {
		ret = regulator_enable(drvdata->regulator);
		if (ret) {
			dev_err(&drvdata->client->dev,
					"Enable regulator failed\n");
			return ret;
		}
		drvdata->enable = true;
	}

	for (i = 0; i < LM3530_REG_MAX; i++) {
		
		if (lm3530_reg[i] == LM3530_BRT_CTRL_REG &&
		    drvdata->mode == LM3530_BL_MODE_PWM) {
			if (pwm->pwm_set_intensity)
				pwm->pwm_set_intensity(reg_val[i],
					drvdata->led_dev.max_brightness);
			continue;
		}

		ret = i2c_smbus_write_byte_data(client,
				lm3530_reg[i], reg_val[i]);
		if (ret)
			break;
	}

	return ret;
}
static int mipi_dsi_cdp_panel_power(int on)
{
	static struct regulator *reg_l8, *reg_l23, *reg_l2;
	int rc;

	pr_debug("%s: state : %d\n", __func__, on);

	if (!dsi_power_on) {

		reg_l8 = regulator_get(&msm_mipi_dsi1_device.dev,
				"dsi_vdc");
		if (IS_ERR(reg_l8)) {
			pr_err("could not get 8038_l8, rc = %ld\n",
				PTR_ERR(reg_l8));
			return -ENODEV;
		}
		reg_l23 = regulator_get(&msm_mipi_dsi1_device.dev,
				"dsi_vddio");
		if (IS_ERR(reg_l23)) {
			pr_err("could not get 8038_l23, rc = %ld\n",
				PTR_ERR(reg_l23));
			return -ENODEV;
		}
		reg_l2 = regulator_get(&msm_mipi_dsi1_device.dev,
				"dsi_vdda");
		if (IS_ERR(reg_l2)) {
			pr_err("could not get 8038_l2, rc = %ld\n",
				PTR_ERR(reg_l2));
			return -ENODEV;
		}
		rc = regulator_set_voltage(reg_l8, 2800000, 3000000);
		if (rc) {
			pr_err("set_voltage l8 failed, rc=%d\n", rc);
			return -EINVAL;
		}
		rc = regulator_set_voltage(reg_l23, 1800000, 1800000);
		if (rc) {
			pr_err("set_voltage l23 failed, rc=%d\n", rc);
			return -EINVAL;
		}
		rc = regulator_set_voltage(reg_l2, 1200000, 1200000);
		if (rc) {
			pr_err("set_voltage l2 failed, rc=%d\n", rc);
			return -EINVAL;
		}
		rc = gpio_request(DISP_RST_GPIO, "disp_rst_n");
		if (rc) {
			pr_err("request gpio DISP_RST_GPIO failed, rc=%d\n",
				rc);
			gpio_free(DISP_RST_GPIO);
			return -ENODEV;
		}
		dsi_power_on = true;
	}
	if (on) {
		rc = regulator_set_optimum_mode(reg_l8, 100000);
		if (rc < 0) {
			pr_err("set_optimum_mode l8 failed, rc=%d\n", rc);
			return -EINVAL;
		}
		rc = regulator_set_optimum_mode(reg_l23, 100000);
		if (rc < 0) {
			pr_err("set_optimum_mode l23 failed, rc=%d\n", rc);
			return -EINVAL;
		}
		rc = regulator_set_optimum_mode(reg_l2, 100000);
		if (rc < 0) {
			pr_err("set_optimum_mode l2 failed, rc=%d\n", rc);
			return -EINVAL;
		}
		rc = regulator_enable(reg_l8);
		if (rc) {
			pr_err("enable l8 failed, rc=%d\n", rc);
			return -ENODEV;
		}
		rc = regulator_enable(reg_l23);
		if (rc) {
			pr_err("enable l8 failed, rc=%d\n", rc);
			return -ENODEV;
		}
		rc = regulator_enable(reg_l2);
		if (rc) {
			pr_err("enable l2 failed, rc=%d\n", rc);
			return -ENODEV;
		}
		gpio_set_value(DISP_RST_GPIO, 1);
	} else {

		gpio_set_value(DISP_RST_GPIO, 0);

		rc = regulator_disable(reg_l2);
		if (rc) {
			pr_err("disable reg_l2 failed, rc=%d\n", rc);
			return -ENODEV;
		}
		rc = regulator_disable(reg_l8);
		if (rc) {
			pr_err("disable reg_l8 failed, rc=%d\n", rc);
			return -ENODEV;
		}
		rc = regulator_disable(reg_l23);
		if (rc) {
			pr_err("disable reg_l23 failed, rc=%d\n", rc);
			return -ENODEV;
		}
		rc = regulator_set_optimum_mode(reg_l8, 100);
		if (rc < 0) {
			pr_err("set_optimum_mode l8 failed, rc=%d\n", rc);
			return -EINVAL;
		}
		rc = regulator_set_optimum_mode(reg_l23, 100);
		if (rc < 0) {
			pr_err("set_optimum_mode l23 failed, rc=%d\n", rc);
			return -EINVAL;
		}
		rc = regulator_set_optimum_mode(reg_l2, 100);
		if (rc < 0) {
			pr_err("set_optimum_mode l2 failed, rc=%d\n", rc);
			return -EINVAL;
		}
	}
	return 0;
}
static void display_panel_power(int on)
{
	int rc;
	static struct regulator *display_reg;
	static struct regulator *lvds_reg;
      #if S7_HWID_L3H(S7, S7301, B)
      static struct regulator *iovcc_reg;
      #endif

      if(on) {
          /* LCD VCCS set to 3.3V */
          _GET_REGULATOR(display_reg, "8901_l2");
          if (!display_reg)
            return;
          rc = regulator_set_voltage(display_reg,
          	3300000, 3300000);
          if (rc)
          	goto out_display_reg;
          rc = regulator_enable(display_reg);
          if (rc)
          	goto out_display_reg;

          /* LVDS VCCS set to 3.3V */
          _GET_REGULATOR(lvds_reg, "8901_l3");
          if (!lvds_reg)
          	return;
#if 0
          rc = regulator_set_voltage(lvds_reg,
          	3000000, 3000000);
#else
          rc = regulator_set_voltage(lvds_reg,
          	3300000, 3300000);
#endif
          if (rc)
          	goto out_lvds_reg;
          rc = regulator_enable(lvds_reg);
          if (rc)
          	goto out_lvds_reg;

          #if S7_HWID_L3H(S7, S7301, B)
          /* LVDS_IOVCC set to 1.8V */
          _GET_REGULATOR(iovcc_reg, "8058_l11");
          if (!iovcc_reg)
          	return;
          rc = regulator_set_voltage(iovcc_reg,
          	1800000, 1800000);
          if (rc)
          	goto out_iovcc_reg;
          rc = regulator_enable(iovcc_reg);
          if (rc)
          	goto out_iovcc_reg;
          #endif

          /* LCD_H_REV */
          rc = gpio_request(lcd_h_rev, "lcd_h_rev");
          if (rc == 0) {
		/* output, pull low to enable */
		gpio_direction_output(lcd_h_rev, 0);
          } else {
		pr_err("%s: lcd_h_rev=%d, gpio_request failed\n",
			__func__, lcd_h_rev);
             goto out_pm_reg;
          }
          
          /* LCD_V_REV */
          rc = gpio_request(lcd_v_rev, "lcd_v_rev");
          if (rc == 0) {
		/* output, pull low to enable */
		gpio_direction_output(lcd_v_rev, 0);
          } else {
		pr_err("%s: lcd_v_rev=%d, gpio_request failed\n",
			__func__, lcd_v_rev);
             goto out_lcd_h_rev;
          }

		  
          /* LCD_ID */
          rc = gpio_request(lcd_panel_id, "lcd_panel_id");
          if (rc == 0) {
		/* output, pull high to enable */
		gpio_direction_input(lcd_panel_id);
          } else {
		pr_err("%s: lcd_panel_id=%d, gpio_request failed\n",
			__func__, lcd_panel_id);
             goto out_lcd_v_rev;
          } 

          display_power_on = 1;
      }else {
          if (display_power_on) {       
            display_power_on = 0;
            goto out_lcd_panel_id;
          }
      }
      return;


out_lcd_panel_id:
       gpio_free(lcd_panel_id);          
out_lcd_v_rev:
       gpio_free(lcd_v_rev);     
out_lcd_h_rev:
       gpio_free(lcd_h_rev);      
out_pm_reg:
#if S7_HWID_L3L(S7, S7301, T0)
	regulator_disable(lvds_reg);
#elif S7_HWID_L3H(S7, S7301, B)
	regulator_disable(iovcc_reg);
#endif      
#if S7_HWID_L3H(S7, S7301, B)   
out_iovcc_reg:
	regulator_disable(lvds_reg);
	regulator_put(iovcc_reg);
	iovcc_reg = NULL;     
#endif
out_lvds_reg:
	regulator_disable(display_reg);
	regulator_put(lvds_reg);
	lvds_reg = NULL;
out_display_reg:
	regulator_put(display_reg);
	display_reg = NULL;    
}
Пример #23
0
static int vf610_adc_probe(struct platform_device *pdev)
{
    struct vf610_adc *info;
    struct iio_dev *indio_dev;
    struct resource *mem;
    int irq;
    int ret;
    u32 channels;

    indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct vf610_adc));
    if (!indio_dev) {
        dev_err(&pdev->dev, "Failed allocating iio device\n");
        return -ENOMEM;
    }

    info = iio_priv(indio_dev);
    info->dev = &pdev->dev;

    mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
    info->regs = devm_ioremap_resource(&pdev->dev, mem);
    if (IS_ERR(info->regs))
        return PTR_ERR(info->regs);

    irq = platform_get_irq(pdev, 0);
    if (irq <= 0) {
        dev_err(&pdev->dev, "no irq resource?\n");
        return -EINVAL;
    }

    ret = devm_request_irq(info->dev, irq,
                           vf610_adc_isr, 0,
                           dev_name(&pdev->dev), info);
    if (ret < 0) {
        dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq);
        return ret;
    }

    info->clk = devm_clk_get(&pdev->dev, "adc");
    if (IS_ERR(info->clk)) {
        dev_err(&pdev->dev, "failed getting clock, err = %ld\n",
                PTR_ERR(info->clk));
        ret = PTR_ERR(info->clk);
        return ret;
    }

    info->vref = devm_regulator_get(&pdev->dev, "vref");
    if (IS_ERR(info->vref))
        return PTR_ERR(info->vref);

    ret = regulator_enable(info->vref);
    if (ret)
        return ret;

    info->vref_uv = regulator_get_voltage(info->vref);

    platform_set_drvdata(pdev, indio_dev);

    init_completion(&info->completion);

    ret  = of_property_read_u32(pdev->dev.of_node,
                                "num-channels", &channels);
    if (ret)
        channels = ARRAY_SIZE(vf610_adc_iio_channels);

    indio_dev->name = dev_name(&pdev->dev);
    indio_dev->dev.parent = &pdev->dev;
    indio_dev->dev.of_node = pdev->dev.of_node;
    indio_dev->info = &vf610_adc_iio_info;
    indio_dev->modes = INDIO_DIRECT_MODE;
    indio_dev->channels = vf610_adc_iio_channels;
    indio_dev->num_channels = (int)channels;

    ret = clk_prepare_enable(info->clk);
    if (ret) {
        dev_err(&pdev->dev,
                "Could not prepare or enable the clock.\n");
        goto error_adc_clk_enable;
    }

    vf610_adc_cfg_init(info);
    vf610_adc_hw_init(info);

    ret = iio_device_register(indio_dev);
    if (ret) {
        dev_err(&pdev->dev, "Couldn't register the device.\n");
        goto error_iio_device_register;
    }

    return 0;


error_iio_device_register:
    clk_disable_unprepare(info->clk);
error_adc_clk_enable:
    regulator_disable(info->vref);

    return ret;
}
Пример #24
0
static int hdmi_core_power(int on, int show)
{
    /* Both HDMI "avdd" and "vcc" are powered by 8038_l23 regulator */
    static struct regulator *reg_8038_l23;
    static int prev_on;
    int rc;

    if (on == prev_on)
        return 0;

    if (!reg_8038_l23) {
        reg_8038_l23 = regulator_get(&hdmi_msm_device.dev, "hdmi_avdd");
        if (IS_ERR(reg_8038_l23)) {
            pr_err("could not get reg_8038_l23, rc = %ld\n",
                   PTR_ERR(reg_8038_l23));
            return -ENODEV;
        }
        rc = regulator_set_voltage(reg_8038_l23, 1800000, 1800000);
        if (rc) {
            pr_err("set_voltage failed for 8921_l23, rc=%d\n", rc);
            return -EINVAL;
        }
    }

    if (on) {
        rc = regulator_set_optimum_mode(reg_8038_l23, 100000);
        if (rc < 0) {
            pr_err("set_optimum_mode l23 failed, rc=%d\n", rc);
            return -EINVAL;
        }
        rc = regulator_enable(reg_8038_l23);
        if (rc) {
            pr_err("'%s' regulator enable failed, rc=%d\n",
                   "hdmi_avdd", rc);
            return rc;
        }
        rc = gpio_request(100, "HDMI_DDC_CLK");
        if (rc) {
            pr_err("'%s'(%d) gpio_request failed, rc=%d\n",
                   "HDMI_DDC_CLK", 100, rc);
            goto error1;
        }
        rc = gpio_request(101, "HDMI_DDC_DATA");
        if (rc) {
            pr_err("'%s'(%d) gpio_request failed, rc=%d\n",
                   "HDMI_DDC_DATA", 101, rc);
            goto error2;
        }
        rc = gpio_request(102, "HDMI_HPD");
        if (rc) {
            pr_err("'%s'(%d) gpio_request failed, rc=%d\n",
                   "HDMI_HPD", 102, rc);
            goto error3;
        }
        pr_debug("%s(on): success\n", __func__);
    } else {
        gpio_free(100);
        gpio_free(101);
        gpio_free(102);

        rc = regulator_disable(reg_8038_l23);
        if (rc) {
            pr_err("disable reg_8038_l23 failed, rc=%d\n", rc);
            return -ENODEV;
        }
        rc = regulator_set_optimum_mode(reg_8038_l23, 100);
        if (rc < 0) {
            pr_err("set_optimum_mode l23 failed, rc=%d\n", rc);
            return -EINVAL;
        }
        pr_debug("%s(off): success\n", __func__);
    }

    prev_on = on;

    return 0;

error3:
    gpio_free(101);
error2:
    gpio_free(100);
error1:
    regulator_disable(reg_8038_l23);
    return rc;
}
static int kxtf9_power_on(void)
{
	return regulator_enable(kxtf9_regulator);
}
static void msm_camera_vreg_config(int vreg_en)
{
	static int gpio_initialzed;
	static struct regulator *ldo2;
	static struct regulator *ldo3;
	static struct regulator *ldo4;
	int rc;

	if (!gpio_initialzed) {
		gpio_request(GPIO_CAM_RESET, "cam_reset");
		gpio_direction_output(GPIO_CAM_RESET, 0);
		gpio_initialzed = 1;
	}

	if (vreg_en) {
		gpio_set_value(GPIO_CAM_RESET, 1);
		mdelay(1);

		/* TODO : error checking */
		ldo4 = regulator_get(NULL, "RT8053_LDO4");
		if (ldo4 == NULL)
			pr_err("%s: regulator_get(ldo4) failed\n", __func__);

		ldo2 = regulator_get(NULL, "RT8053_LDO2");
		if (ldo2 == NULL)
			pr_err("%s: regulator_get(ldo2) failed\n", __func__);

		ldo3 = regulator_get(NULL, "RT8053_LDO3");
		if (ldo3 == NULL)
			pr_err("%s: regulator_get(ldo3) failed\n", __func__);

		rc = regulator_set_voltage(ldo4, 1800000, 1800000);
		if (rc < 0)
			pr_err("%s: regulator_set_voltage(ldo4) failed\n",
				__func__);
		rc = regulator_enable(ldo4);
		if (rc < 0)
			pr_err("%s: regulator_enable(ldo4) failed\n",
				__func__);

		rc = regulator_set_voltage(ldo2, 2800000, 2800000);
		if (rc < 0)
			pr_err("%s: regulator_set_voltage(ldo2) failed\n",
				__func__);
		rc = regulator_enable(ldo2);
		if (rc < 0)
			pr_err("%s: regulator_enable(ldo2) failed\n",
				__func__);

		rc = regulator_set_voltage(ldo3, 2800000, 2800000);
		if (rc < 0)
			pr_err("%s: regulator_set_voltage(ldo3) failed\n",
				__func__);
		rc = regulator_enable(ldo3);
		if (rc < 0)
			pr_err("%s: regulator_enable(ldo3) failed\n",
				__func__);
	} else {
		gpio_set_value(GPIO_CAM_RESET, 0);

		rc = regulator_disable(ldo3);
		if (rc < 0)
			pr_err("%s: regulator_disable(ldo3) failed\n",
				__func__);
		regulator_put(ldo3);

		rc = regulator_disable(ldo2);
		if (rc < 0)
			pr_err("%s: regulator_disble(ldo2) failed\n",
				__func__);
		regulator_put(ldo2);

		rc = regulator_disable(ldo4);
		if (rc < 0)
			pr_err("%s: regulator_disable(ldo4) failed\n",
				__func__);
		regulator_put(ldo4);
	}

	return;
}
static int tegra_l3g4200d_power_on(void)
{
        if (tegra_l3g4200d_regulator)
                return regulator_enable(tegra_l3g4200d_regulator);
        return 0;
}
static int mipi_dsi_panel_power(int on)
{
	static struct regulator *v_lcm, *v_lcmio, *v_dsivdd;
	static bool bPanelPowerOn = false;
	int rc;

	char *lcm_str = "8921_l11";
	char *lcmio_str = "8921_lvs5";
	char *dsivdd_str = "8921_l2";

	printk(KERN_INFO "%s: state : %d\n", __func__, on);

	if (!dsi_power_on) {

		v_lcm = regulator_get(&msm_mipi_dsi1_device.dev,
				lcm_str);
		if (IS_ERR(v_lcm)) {
			printk(KERN_ERR "could not get %s, rc = %ld\n",
				lcm_str, PTR_ERR(v_lcm));
			return -ENODEV;
		}

		v_lcmio = regulator_get(&msm_mipi_dsi1_device.dev,
				lcmio_str);
		if (IS_ERR(v_lcmio)) {
			printk(KERN_ERR "could not get %s, rc = %ld\n",
				lcmio_str, PTR_ERR(v_lcmio));
			return -ENODEV;
		}

		v_dsivdd = regulator_get(&msm_mipi_dsi1_device.dev,
				dsivdd_str);
		if (IS_ERR(v_dsivdd)) {
			printk(KERN_ERR "could not get %s, rc = %ld\n",
				dsivdd_str, PTR_ERR(v_dsivdd));
			return -ENODEV;
		}
		if (system_rev >= 2) /* XC */
			rc = regulator_set_voltage(v_lcm, 3000000, 3000000);
		else
			rc = regulator_set_voltage(v_lcm, 3200000, 3200000);
		if (rc) {
			printk(KERN_ERR "%s#%d: set_voltage %s failed, rc=%d\n", __func__, __LINE__, lcm_str, rc);
			return -EINVAL;
		}

		rc = regulator_set_voltage(v_dsivdd, 1200000, 1200000);
		if (rc) {
			printk(KERN_ERR "%s#%d: set_voltage %s failed, rc=%d\n", __func__, __LINE__, dsivdd_str, rc);
			return -EINVAL;
		}

		rc = gpio_request(JET_GPIO_LCD_RSTz, "LCM_RST_N");
		if (rc) {
			printk(KERN_ERR "%s:LCM gpio %d request failed, rc=%d\n", __func__,  JET_GPIO_LCD_RSTz, rc);
			return -EINVAL;
		}

		dsi_power_on = true;
	}

	if (on) {
		printk(KERN_INFO "%s: on\n", __func__);
		rc = regulator_set_optimum_mode(v_lcm, 100000);
		if (rc < 0) {
			printk(KERN_ERR "set_optimum_mode %s failed, rc=%d\n", lcm_str, rc);
			return -EINVAL;
		}

		rc = regulator_set_optimum_mode(v_dsivdd, 100000);
		if (rc < 0) {
			printk(KERN_ERR "set_optimum_mode %s failed, rc=%d\n", dsivdd_str, rc);
			return -EINVAL;
		}

		rc = regulator_enable(v_lcm);
		if (rc) {
			printk(KERN_ERR "enable regulator %s failed, rc=%d\n", lcm_str, rc);
			return -ENODEV;
		}

		rc = regulator_enable(v_dsivdd);
		if (rc) {
			printk(KERN_ERR "enable regulator %s failed, rc=%d\n", dsivdd_str, rc);
			return -ENODEV;
		}
		rc = regulator_enable(v_lcmio);
		if (rc) {
			printk(KERN_ERR "enable regulator %s failed, rc=%d\n", lcmio_str, rc);
			return -ENODEV;
		}

		jet_lcd_id_power(PM_GPIO_PULL_NO);

		if (!jet_panel_first_init) {
                        msleep(20);
			gpio_set_value(JET_GPIO_LCD_RSTz, 1);
			msleep(1);
		}

		bPanelPowerOn = true;

	} else {
		printk(KERN_INFO "%s: off\n", __func__);
		if (!bPanelPowerOn) return 0;
		jet_lcd_id_power(PM_GPIO_PULL_DN);

		gpio_set_value(JET_GPIO_LCD_RSTz, 0);
		msleep(10);

		if (regulator_disable(v_lcmio)) {
			printk(KERN_ERR "%s: Unable to enable the regulator: %s\n", __func__, lcmio_str);
			return -EINVAL;
		}

		if (regulator_disable(v_dsivdd)) {
			printk(KERN_ERR "%s: Unable to enable the regulator: %s\n", __func__, dsivdd_str);
			return -EINVAL;
		}

		if (regulator_disable(v_lcm)) {
			printk(KERN_ERR "%s: Unable to enable the regulator: %s\n", __func__, lcm_str);
			return -EINVAL;
		}

		rc = regulator_set_optimum_mode(v_dsivdd, 100);
		if (rc < 0) {
			printk(KERN_ERR "%s: Unable to enable the regulator: %s\n", __func__, dsivdd_str);
			return -EINVAL;
		}

		bPanelPowerOn = false;
	}
	return 0;
}
Пример #29
0
/**
 *  Power on request.
 *
 *  Set clocks to ON.
 *  Set sensors chip-select GPIO to non-reset (on) value.
 *
 */
static int dsps_power_on_handler(void)
{
	int ret = 0;
	int i, ci, gi, ri;

	pr_debug("%s.\n", __func__);

	if (drv->is_on) {
		pr_debug("%s: already ON.\n",  __func__);
		return 0;
	}

	for (ci = 0; ci < drv->pdata->clks_num; ci++) {
		const char *name = drv->pdata->clks[ci].name;
		u32 rate = drv->pdata->clks[ci].rate;
		struct clk *clock = drv->pdata->clks[ci].clock;

		if (clock == NULL)
			continue;

		if (rate > 0) {
			ret = clk_set_rate(clock, rate);
			pr_debug("%s: clk %s set rate %d.",
				__func__, name, rate);
			if (ret) {
				pr_err("%s: clk %s set rate %d. err=%d.",
					__func__, name, rate, ret);
				goto clk_err;
			}

		}

		ret = clk_prepare_enable(clock);
		if (ret) {
			pr_err("%s: enable clk %s err %d.",
			       __func__, name, ret);
			goto clk_err;
		}
	}

	for (gi = 0; gi < drv->pdata->gpios_num; gi++) {
		const char *name = drv->pdata->gpios[gi].name;
		int num = drv->pdata->gpios[gi].num;
		int val = drv->pdata->gpios[gi].on_val;
		int is_owner = drv->pdata->gpios[gi].is_owner;

		if (!is_owner)
			continue;

		ret = gpio_direction_output(num, val);
		if (ret) {
			pr_err("%s: set GPIO %s num %d to %d err %d.",
			       __func__, name, num, val, ret);
			goto gpio_err;
		}
	}

	for (ri = 0; ri < drv->pdata->regs_num; ri++) {
		const char *name = drv->pdata->regs[ri].name;
		struct regulator *reg = drv->pdata->regs[ri].reg;
		int volt = drv->pdata->regs[ri].volt;

		if (reg == NULL)
			continue;

		pr_debug("%s: set regulator %s.", __func__, name);

		ret = regulator_set_voltage(reg, volt, volt);

		if (ret) {
			pr_err("%s: set regulator %s voltage %d err = %d.\n",
				__func__, name, volt, ret);
			goto reg_err;
		}

		ret = regulator_enable(reg);
		if (ret) {
			pr_err("%s: enable regulator %s err = %d.\n",
				__func__, name, ret);
			goto reg_err;
		}
	}

	drv->is_on = true;

	return 0;

	/*
	 * If failling to set ANY clock/gpio/regulator to ON then we set
	 * them back to OFF to avoid consuming power for unused
	 * clocks/gpios/regulators.
	 */
reg_err:
	for (i = 0; i < ri; i++) {
		struct regulator *reg = drv->pdata->regs[ri].reg;

		if (reg == NULL)
			continue;

		regulator_disable(reg);
	}

gpio_err:
	for (i = 0; i < gi; i++) {
		int num = drv->pdata->gpios[i].num;
		int val = drv->pdata->gpios[i].off_val;
		int is_owner = drv->pdata->gpios[i].is_owner;

		if (!is_owner)
			continue;

		ret = gpio_direction_output(num, val);
	}

clk_err:
	for (i = 0; i < ci; i++) {
		struct clk *clock = drv->pdata->clks[i].clock;

		if (clock == NULL)
			continue;

		clk_disable_unprepare(clock);
	}

	return -ENODEV;
}
Пример #30
0
/**
 * ehci_hcd_omap_probe - initialize TI-based HCDs
 *
 * Allocates basic resources for this USB host controller, and
 * then invokes the start() method for the HCD associated with it
 * through the hotplug entry's driver_data.
 */
static int ehci_hcd_omap_probe(struct platform_device *pdev)
{
	struct ehci_hcd_omap_platform_data *pdata = pdev->dev.platform_data;
	struct ehci_hcd_omap *omap;
	struct resource *res;
	struct usb_hcd *hcd;

	int irq = platform_get_irq(pdev, 0);
	int ret = -ENODEV;
	int i;
	char supply[7];

	if (!pdata) {
		dev_dbg(&pdev->dev, "missing platform_data\n");
		goto err_pdata;
	}

	if (usb_disabled())
		goto err_disabled;

	omap = kzalloc(sizeof(*omap), GFP_KERNEL);
	if (!omap) {
		ret = -ENOMEM;
		goto err_disabled;
	}

	hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev,
			dev_name(&pdev->dev));
	if (!hcd) {
		dev_dbg(&pdev->dev, "failed to create hcd with err %d\n", ret);
		ret = -ENOMEM;
		goto err_create_hcd;
	}

	platform_set_drvdata(pdev, omap);
	omap->dev		= &pdev->dev;
	omap->phy_reset		= pdata->phy_reset;
	omap->reset_gpio_port[0]	= pdata->reset_gpio_port[0];
	omap->reset_gpio_port[1]	= pdata->reset_gpio_port[1];
	omap->reset_gpio_port[2]	= pdata->reset_gpio_port[2];
	omap->port_mode[0]		= pdata->port_mode[0];
	omap->port_mode[1]		= pdata->port_mode[1];
	omap->port_mode[2]		= pdata->port_mode[2];
	omap->ehci		= hcd_to_ehci(hcd);
	omap->ehci->sbrn	= 0x20;

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

	hcd->rsrc_start = res->start;
	hcd->rsrc_len = resource_size(res);

	hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
	if (!hcd->regs) {
		dev_err(&pdev->dev, "EHCI ioremap failed\n");
		ret = -ENOMEM;
		goto err_ioremap;
	}

	/* we know this is the memory we want, no need to ioremap again */
	omap->ehci->caps = hcd->regs;
	omap->ehci_base = hcd->regs;

	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
	omap->uhh_base = ioremap(res->start, resource_size(res));
	if (!omap->uhh_base) {
		dev_err(&pdev->dev, "UHH ioremap failed\n");
		ret = -ENOMEM;
		goto err_uhh_ioremap;
	}

	res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
	omap->tll_base = ioremap(res->start, resource_size(res));
	if (!omap->tll_base) {
		dev_err(&pdev->dev, "TLL ioremap failed\n");
		ret = -ENOMEM;
		goto err_tll_ioremap;
	}

	/* get ehci regulator and enable */
	for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
		if (omap->port_mode[i] != EHCI_HCD_OMAP_MODE_PHY) {
			omap->regulator[i] = NULL;
			continue;
		}
		snprintf(supply, sizeof(supply), "hsusb%d", i);
		omap->regulator[i] = regulator_get(omap->dev, supply);
		if (IS_ERR(omap->regulator[i])) {
			omap->regulator[i] = NULL;
			dev_dbg(&pdev->dev,
			"failed to get ehci port%d regulator\n", i);
		} else {
			regulator_enable(omap->regulator[i]);
		}
	}

	ret = omap_start_ehc(omap, hcd);
	if (ret) {
		dev_dbg(&pdev->dev, "failed to start ehci\n");
		goto err_start;
	}

	omap->ehci->regs = hcd->regs
		+ HC_LENGTH(readl(&omap->ehci->caps->hc_capbase));

	dbg_hcs_params(omap->ehci, "reset");
	dbg_hcc_params(omap->ehci, "reset");

	/* cache this readonly data; minimize chip reads */
	omap->ehci->hcs_params = readl(&omap->ehci->caps->hcs_params);

	ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
	if (ret) {
		dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
		goto err_add_hcd;
	}

	/* root ports should always stay powered */
	ehci_port_power(omap->ehci, 1);

	((struct  ehci_hcd *)
	((char *)hcd_to_ehci(hcd)))->omap_p = omap;

	return 0;

err_add_hcd:
	omap_stop_ehc(omap, hcd);

err_start:
	for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
		if (omap->regulator[i]) {
			regulator_disable(omap->regulator[i]);
			regulator_put(omap->regulator[i]);
		}
	}
	iounmap(omap->tll_base);

err_tll_ioremap:
	iounmap(omap->uhh_base);

err_uhh_ioremap:
	iounmap(hcd->regs);

err_ioremap:
	usb_put_hcd(hcd);

err_create_hcd:
	kfree(omap);
err_disabled:
err_pdata:
	return ret;
}