Пример #1
0
static int adxl34x_config_gpio(struct device *dev, struct adxl34x *acc_data)
{

	int ret = 0;

	/* get gpio block*/
	acc_data->gpio_block = iomux_get_block(GPIO_BOLCK_NAME);
	if (IS_ERR(acc_data->gpio_block)) {
		dev_err(dev, "%s: failed to get gpio block\n", __func__);
		ret = -EINVAL;
		return ret;
	}

	/* get gpio block config*/
	acc_data->gpio_block_config = iomux_get_blockconfig(GPIO_BOLCK_NAME);
	if (IS_ERR(acc_data->gpio_block_config)) {
		dev_err(dev, "%s: failed to get gpio block config\n", __func__);
		ret = -EINVAL;
		goto err_block_config;
	}

	/* config gpio work mode*/
	ret = blockmux_set(acc_data->gpio_block, acc_data->gpio_block_config, LOWPOWER);
	if (ret) {
		dev_err(dev, "%s: failed to config gpio\n", __func__);
		ret = -EINVAL;
		goto err_mux_set;
	}

	return ret;

err_mux_set:
	if (acc_data->gpio_block_config)
		acc_data->gpio_block_config = NULL;
err_block_config:
	if (acc_data->gpio_block)
		acc_data->gpio_block = NULL;

	return ret;

}
static int ispv1_get_iomux(u8 *name, struct iomux_block **block,
		    struct block_config **block_conf)
{

	*block = iomux_get_block(name);

	if (!*block) {
		print_error("%s: failed to get iomux %s\n", __func__, name);
		return PTR_ERR(*block);
	}

	*block_conf = iomux_get_blockconfig(name);

	if (!*block_conf) {
		print_error("%s: failed to get iomux isp %s\n", __func__, name);
		return PTR_ERR(*block_conf);
	}

	return 0;

}
STATIC int hiusb_init_resource(struct lm_device *dev)
{
    int ret = 0;
    struct lm_device *lm_dev;
    struct hiusb_info *hiusb_info;

    lm_dev = dev;
    hiusb_info = dev->hiusb_info;

    ATOMIC_INIT_NOTIFIER_HEAD(&hiusb_info->charger_type_notifier_head);
    spin_lock_init(&hiusb_info->intr_flag_lock);
    wake_lock_init(&hiusb_info->dev_wakelock, WAKE_LOCK_SUSPEND, "hiusb_dev_wakelock");
    wake_lock_init(&hiusb_info->host_wakelock, WAKE_LOCK_SUSPEND, "hiusb_host_wakelock");
    sema_init(&hiusb_info->hiusb_info_sema, 0);
    spin_lock_init(&hiusb_info->switch_lock);
    hiusb_info->charger_type = CHARGER_REMOVED;
    hiusb_info->hiusb_status = HIUSB_OFF;
    hiusb_info->gadget_enable = 0;

    get_hw_config_int("usb/otg_without_mhl", &hiusb_info->otg_without_mhl, NULL);
    dev_info(&lm_dev->dev, "otg_without_mhl:%d.\n", hiusb_info->otg_without_mhl);

    ret = get_hw_config_int("usb/gpio_otg_int", &hiusb_info->otg_int_gpio, NULL);
    dev_info(&lm_dev->dev, "gpio_otg_int:%d.\n", hiusb_info->otg_int_gpio);

    hiusb_info->usb_block = iomux_get_block("block_switch");
    hiusb_info->usb_config = iomux_get_blockconfig("block_switch");

    hiusb_info->clk_usbotg_off= clk_get(NULL, "clk_usbotg_off");
    ret = IS_ERR(hiusb_info->clk_usbotg_off);
    if (ret) {
        dev_err(&lm_dev->dev, "get clk_usbotg_off failed!\n");
        goto get_clk_usbotg_off_fail;
    }
#if defined(CHIP_BB_HI6210)/*B020 Modify*/
#else
    hiusb_info->clk_picophy= clk_get(NULL, "clk_picophy");
    ret = IS_ERR(hiusb_info->clk_picophy);
    if (ret) {
        dev_err(&lm_dev->dev, "get clk_picophy failed!\n");
        goto get_clk_picophy_fail;
    }
#endif    
    switch_init(lm_dev);

    if (hiusb_info->vbus_pin != 0) {
        ret = gpio_request(hiusb_info->vbus_pin, "USB_VBUS");
        if (ret < 0) {
            dev_err(&dev->dev, "%s usb vbus gpio error", __func__);
            goto request_vbus_pin_fail;
        }
        gpio_direction_output(hiusb_info->vbus_pin, 0);
    }

    if (hiusb_info->phy_reset_pin != 0) {
        ret = gpio_request(hiusb_info->phy_reset_pin, "USBPHY_REST");
        if (ret < 0) {
            dev_err(&dev->dev, "%s usb phy reset gpio error", __func__);
            goto request_gpio_fail;
        }
        gpio_direction_output(hiusb_info->phy_reset_pin, 0);
        mdelay(100);
        gpio_direction_output(hiusb_info->phy_reset_pin, 1);
    }

    if (hiusb_info->otg_int_gpio != -1) {
        ret = gpio_request(hiusb_info->otg_int_gpio, "OTG_INT_GPIO");
        if (ret < 0) {
            dev_err(&dev->dev, "%s usb otg int gpio error", __func__);
            goto request_gpio_fail;
        }
        gpio_direction_input(hiusb_info->otg_int_gpio);
    }

    /* init workqueue for usb insert/draw : only for debug */
    INIT_DELAYED_WORK(&hiusb_info->otg_intr_work, hiusb_otg_intr_work);
    dev_info(&lm_dev->dev, "%s.\n", __func__);

    return 0;

request_gpio_fail:
    if (hiusb_info->vbus_pin != 0) {
        gpio_free(hiusb_info->vbus_pin);
    }
request_vbus_pin_fail:
#if defined(CHIP_BB_HI6210)/*B020 Modify*/
#else
    clk_put(hiusb_info->clk_picophy);
#endif
get_clk_picophy_fail:
    clk_put(hiusb_info->clk_usbotg_off);
get_clk_usbotg_off_fail:
    return ret;
}
static int __devinit k3_gps_bcm_probe(struct platform_device *pdev)
{
	GPS_BCM_INFO *gps_bcm;
	struct resource *res;
	int ret = 0;

	gps_bcm = kzalloc(sizeof(GPS_BCM_INFO), GFP_KERNEL);
	if (!gps_bcm) {
		dev_err(&pdev->dev, "Alloc memory failed\n");
		return -ENOMEM;
	}

	platform_set_drvdata(pdev, gps_bcm);

	/* Get enable gpio */
	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
	if (!res) {
		dev_err(&pdev->dev, "Get enable gpio resourse failed\n");
		ret = -ENXIO;
		goto err_free;
	}
	gps_bcm->gpioid_en = res->start;

	ret = gpio_request(gps_bcm->gpioid_en, "gps_enbale");
	if (ret < 0) {
		dev_err(&pdev->dev,  "gpio_request failed, gpio=%lu, ret=%d\n", gps_bcm->gpioid_en, ret);
		goto err_free;
	}
	gpio_export(gps_bcm->gpioid_en, false);

	/* Get reset gpio */
	res = platform_get_resource(pdev, IORESOURCE_IO, 1);
	if (!res) {
		dev_err(&pdev->dev, "Get reset gpio resourse failed\n");
		ret = -ENXIO;
		goto err_free_gpio_en;
	}
	gps_bcm->gpioid_ret = res->start;

	ret = gpio_request(gps_bcm->gpioid_ret, "gps_reset");
	if (ret < 0) {
		dev_err(&pdev->dev,  "gpio_request failed, gpio=%lu, ret=%d\n", gps_bcm->gpioid_ret, ret);
		goto err_free_gpio_en;
	}
	gpio_export(gps_bcm->gpioid_ret, false);

#ifndef CONFIG_MACH_K3V2OEM1
	/* Get power gpio (VDDIO 1.8V), Only for FPGA */
	res = platform_get_resource(pdev, IORESOURCE_IO, 2);
	if (!res) {
		dev_err(&pdev->dev, "Get power gpio resourse failed\n");
		ret = -ENXIO;
		goto err_free_gpio_ret;
	}
	gps_bcm->gpioid_power = res->start;

	ret = gpio_request(gps_bcm->gpioid_power, "gps_power");
	if (ret < 0) {
		dev_err(&pdev->dev, "gpio_request failed, gpio=%lu, rc=%d\n", gps_bcm->gpioid_power, ret);
		gpio_free(gps_bcm->gpioid_en);
		goto err_free_gpio_ret;
	}

	/* Low GPS power, only for FPGA */
	gpio_direction_output(gps_bcm->gpioid_power, 0);

	/* High GPS power, only for FPGA */
	gpio_set_value(gps_bcm->gpioid_power, 1);
	dev_dbg(&pdev->dev,  "High power\n");
#else
	/* Set 32KC clock */
	gps_bcm->clk = clk_get(NULL, "clk_pmu32kc");
	if (IS_ERR(gps_bcm->clk)) {
		dev_err(&pdev->dev, "Get gps clk failed\n");
		ret = PTR_ERR(gps_bcm->clk);
		goto err_free_gpio_ret;
	}
	ret = clk_enable(gps_bcm->clk);
	if (ret) {
		dev_err(&pdev->dev, "Enable clk failed, ret=%d\n", ret);
		goto err_free_clk;
	}

	/* Set iomux NORMAL, If set iomux failed, we still go on */
	gps_bcm->piomux_block  = iomux_get_block("block_gps_boardcom");
	if (!gps_bcm->piomux_block)
		dev_err(&pdev->dev, "Get gps iomux_block failed\n");

	gps_bcm->pblock_config = iomux_get_blockconfig("block_gps_boardcom");
	if (!gps_bcm->pblock_config)
		dev_err(&pdev->dev, "Get gps block_config failed\n");

	if ((gps_bcm->piomux_block) && (gps_bcm->pblock_config)) {
		ret = blockmux_set(gps_bcm->piomux_block, gps_bcm->pblock_config, NORMAL);
		if (ret)
			dev_err(&pdev->dev, "Set gps iomux to NORMAL failed, ret=%d\n", ret);
	}
#endif

	/* Low Reset GPIO */
	gpio_direction_output(gps_bcm->gpioid_ret, 0);
	dev_dbg(&pdev->dev,  "Low reset\n");

	/* Low Enable GPIO */
	gpio_direction_output(gps_bcm->gpioid_en, 0);
	dev_dbg(&pdev->dev,  "Low enable\n");

	/* High Reset GPIO*/
	gpio_set_value(gps_bcm->gpioid_ret, 1);
	dev_dbg(&pdev->dev,  "High reset\n");

	return 0;

#ifdef CONFIG_MACH_K3V2OEM1
err_free_clk:
	clk_put(gps_bcm->clk);
#endif

err_free_gpio_ret:
	gpio_free(gps_bcm->gpioid_ret);

err_free_gpio_en:
	gpio_free(gps_bcm->gpioid_en);

err_free:
	kfree(gps_bcm);
	gps_bcm = NULL;
	return ret;
}
Пример #5
0
static int __devinit hi_mci_probe(struct platform_device *pdev)
{
	struct mshci_host *ms_host = NULL;
	struct himci_host *hi_host = NULL;
	struct hisik3_mmc_platform_data *plat = NULL;
	struct resource *memres = NULL;


	int ret = 0, irq;
	int err;
	bool RetVal = 0;
	unsigned long flags;
	unsigned int sdcard_frequency = 0;



    #ifdef CONFIG_MACH_HI6620OEM
    if(1 == pdev->id)
    {
        raw_mmc_turn_on();
    }
    #endif

	himci_trace(HIMCI_TRACE_GEN_API, "++");

	himci_assert(pdev);

	plat = pdev->dev.platform_data;

	himci_trace(HIMCI_TRACE_SIGNIFICANT, "id:%d", pdev->id);

    /*通过读取硬件配置项,或者sdcard时钟配置,只需要SD卡流程走,走一遍*/
    #ifdef CONFIG_MACH_HI6620OEM

    if(1 == pdev->id)
    {
        RetVal = get_hw_config_int("sd_card/sdcard_frequency", &sdcard_frequency, NULL);

    	printk("hsad: sd_card/sdcard_frequency = %d, RetVal = %d\n", sdcard_frequency, RetVal);

        /*读取失败,配置默认值*/
    	if (RetVal == false) {
            printk(KERN_ERR "get board type failed.\n");
            g_sdcard_frequency = 90;
    	}

        /*如果获取配置值异常,则配置默认值*/
    	if ((sdcard_frequency != 100)&&(sdcard_frequency != 90)) {
            printk(KERN_ERR "sdcard_frequency %x is error.\n",sdcard_frequency);
            g_sdcard_frequency = 90;
    	}

    	g_sdcard_frequency = sdcard_frequency;
	}

    #endif

	/* 获取自己定义的数据 */
	if (!plat) {
		himci_error("Platform data not available");
		return -ENOENT;
	}
	if(0 == pdev->id)
	{
	     sema_init(&sem_to_rfile_sync_req,0);
	}

    /*创建硬件信号量IPC_SEM_EMMC*/
    if (0 == pdev->id) {
        mutex_lock(&emmc_mutex);
        emmc_sem_flag = 1;
        mutex_unlock(&emmc_mutex);
    }

	irq = platform_get_irq(pdev, 0);
	memres = platform_get_resource(pdev, IORESOURCE_MEM, 0);

	if ((!irq) || (!memres)) {
		himci_error("resource error");
		ret = -ENOENT;
        goto err_resource_get;
	}

	himci_trace(HIMCI_TRACE_SIGNIFICANT, "irq:%d,start:0x%x,size:0x%x", irq, \
										memres->start, resource_size(memres));

	ms_host = mshci_alloc_host(&pdev->dev, sizeof(struct himci_host));
	if (IS_ERR(ms_host)) {
		himci_error("mshci_alloc_host() failed\n");
		ret = PTR_ERR(ms_host);
        goto err_resource_get;
	}

	hi_host = mshci_priv(ms_host);
	hi_host->ms_host = ms_host;
	hi_host->pdev = pdev;
	hi_host->dev = &pdev->dev;
	hi_host->plat = plat;


	platform_set_drvdata(pdev, ms_host);

	/* MMC IP rstdis */
	if (plat->rstdis_mmc){
        ret = plat->rstdis_mmc();
        if ( ret < 0 ){
	        goto err_resource_get;
	    }
	}

    /* set emmc clk */

	hi_host->pclk = clk_get(&pdev->dev, plat->clk_mmc_low); /* work clk */

	if (IS_ERR(hi_host->pclk)) {
		himci_error("clk_get clk_mmc_low fail!");
		ret = PTR_ERR(hi_host->pclk);
		goto err_io_clk;
	}
	hi_host->clk_mmc_high= clk_get(&pdev->dev, plat->clk_mmc_high); /* highclk used for tuning */

    if (IS_ERR(hi_host->clk_mmc_high)) {
		himci_error("clk_get clk_mmc_high fail!");
		ret = PTR_ERR(hi_host->clk_mmc_high);
		goto err_io_clk;
	}

    ms_host->pclk = NULL;
    ms_host->clk_ref_counter = CLK_DISABLED;
    ms_host->clk_mmc_high = NULL;

	ms_host->pclk = hi_host->pclk;
	ms_host->clk_mmc_high = hi_host->clk_mmc_high;

	if (ret) {
	    himci_error("failed to clk_set_rate");
	}

    if(ms_host->clk_ref_counter == CLK_DISABLED){
        ret = clk_enable(hi_host->pclk);
        ms_host->clk_ref_counter = CLK_ENABLED;
        if (ret) {
            himci_error("clk_enable failed");
            ret = -ENOENT;
            goto err_clk_ops;
        }
    }



	ms_host->ioaddr = ioremap_nocache(memres->start, resource_size(memres));
	if (!ms_host->ioaddr) {
		himci_error("ioremap_nocache failed");
		ret = -ENXIO;
		goto err_req_regs;
	}

	ms_host->hw_name = "hisi_hi6620_mmc";
	ms_host->hw_mmc_id = hi_host->pdev->id;
	ms_host->ops = &mshci_hi_ops;
	ms_host->quirks = 0;
	ms_host->irq = irq;

	/* Setup quirks for the controller */

	if (plat->quirks) {
		ms_host->quirks |= plat->quirks;
	}

	if (plat->caps & MMC_CAP_CLOCK_GATING) {
		/* there is no reason not to use interral clock gating */
		ms_host->mmc->caps |= plat->caps;
		ms_host->mmc->caps |= MMC_CAP_CLOCK_GATING;
		ms_host->clock_gate = 1;
    } else {
		ms_host->mmc->caps |= plat->caps;
		ms_host->clock_gate = 0;
	}

	ms_host->mmc->caps2 = plat->caps2;

	/* sandisk card need clock longer than spec ask */
	/* sdcard also disable ip clock gate c00261379*/
	if (ms_host->hw_mmc_id == 0 || ms_host->hw_mmc_id == 1)
		ms_host->clock_gate = 0;

	if (plat->ocr_mask)
		ms_host->mmc->ocr_avail |= plat->ocr_mask;


    #ifdef CONFIG_MACH_HI6620OEM
    if (plat->iomux_name){
        hi_host->piomux_block = iomux_get_block(plat->iomux_name);
	    hi_host->pblock_config = iomux_get_blockconfig(plat->iomux_name);
    }

    /* todo requlator */
	if (plat->reg_name_ldo) {
		himci_trace(HIMCI_TRACE_SIGNIFICANT, "devname : %s, regname: %s",
					dev_name(hi_host->dev), plat->reg_name_ldo);
		hi_host->vcc_ldo = regulator_get(hi_host->dev, plat->reg_name_ldo);
		if (!IS_ERR(hi_host->vcc_ldo)) {
			/*
			 * Setup a notifier block to update this if another device
			 * causes the voltage to change
			 */
			hi_host->nb.notifier_call = &mshci_hi_disable_voltage;
			ret = regulator_register_notifier(hi_host->vcc_ldo, &hi_host->nb);
			if (ret) {
				dev_err(&pdev->dev,
					"regulator notifier request failed\n");
			}
		} else {
			dev_err(&pdev->dev, "regulator_get() failed\n");
			hi_host->vcc_ldo = NULL;
		}
	}

	if (plat->reg_name_lvs) {
		himci_trace(HIMCI_TRACE_SIGNIFICANT, "devname : %s, regname: %s",
					dev_name(hi_host->dev), plat->reg_name_lvs);
		hi_host->vcc_lvs = regulator_get(hi_host->dev, plat->reg_name_lvs);
		if (!IS_ERR(hi_host->vcc_lvs)) {
			/*
			 * Setup a notifier block to update this if another device
			 * causes the voltage to change
			 */
			hi_host->nb.notifier_call = &mshci_hi_disable_voltage;
			ret = regulator_register_notifier(hi_host->vcc_lvs, &hi_host->nb);
			if (ret) {
				dev_err(&pdev->dev,
					"regulator notifier request failed\n");
			}
		} else {
			dev_err(&pdev->dev, "regulator_get() failed\n");
			hi_host->vcc_lvs = NULL;
		}
	}
	hi_host->ocp_flag = 0;

	if (plat->signal_reg_name) {
		himci_trace(HIMCI_TRACE_SIGNIFICANT, "devname : %s, signal regname: %s",
						dev_name(hi_host->dev), plat->signal_reg_name);
		hi_host->signal_vcc = regulator_get(hi_host->dev, plat->signal_reg_name);
		if (IS_ERR(hi_host->signal_vcc)) {
			dev_err(&pdev->dev, "regulator_get() failed\n");
			hi_host->signal_vcc = NULL;
		}
	}
    #endif

	if( (1 == pdev->id)&&( (ms_host->quirks & MSHCI_QUIRK_CBP_DETECTION) == 0)) {
		ret = blockmux_set(hi_host->piomux_block, hi_host->pblock_config, LOWPOWER);
		if (ret) {
			himci_error("failed to blockmux_set");
		}
		mshci_sd_lowpower();
		if (hi_host->vcc_lvs){
			ret = regulator_enable(hi_host->vcc_lvs);
			if (ret) {
				himci_error("failed to regulator_enable LDO7");
			}
			ret = regulator_disable(hi_host->vcc_lvs);
			if (ret) {
			himci_error("failed to regulator_disable LDO7");
			}
		}
		udelay(30);
		if (hi_host->signal_vcc){
			ret = regulator_enable(hi_host->signal_vcc);
			if (ret) {
				himci_error("failed to regulator_enable LDO22");
			}
			ret = regulator_disable(hi_host->signal_vcc);
			if (ret) {
				himci_error("failed to regulator_disable LDO22");
			}
		}
	}else {/*for cbp*/
		ret = blockmux_set(hi_host->piomux_block, hi_host->pblock_config, NORMAL);
		if (ret) {
			himci_error("failed to blockmux_set");
		}

		if (hi_host->vcc_lvs){
			ret = regulator_enable(hi_host->vcc_lvs);
			if (ret) {
				himci_error("failed to regulator_enable LDO7");
			}
		}
		udelay(30);
		if (hi_host->signal_vcc){
			ret = regulator_enable(hi_host->signal_vcc);
			if (ret) {
				himci_error("failed to regulator_enable LDO22");
			}

			ret = regulator_disable(hi_host->signal_vcc);
			if (ret) {
				himci_error("failed to regulator_disable LDO22");
			}
		}
	}

	hi_host->old_sig_voltage = plat->default_signal_voltage;
	hi_host->old_timing = MMC_TIMING_UHS_DDR50;
	hi_host->timing_config = plat->timing_config;
	hi_host->allow_switch_signal_voltage = plat->allow_switch_signal_voltage;
	hi_host->suspend_timing_config = plat->suspend_timing_config;

	if (ms_host->quirks & MSHCI_QUIRK_WLAN_DETECTION) {
		ms_host->flags |= MSHCI_DEVICE_DEAD;
		ms_host->flags |= MMC_PM_KEEP_POWER;
		ms_host->mmc->pm_caps |= MMC_PM_KEEP_POWER;
	}

	ret = mshci_add_host(ms_host);
	if (ret) {
		dev_err(&pdev->dev, "mshci_add_host() failed\n");
		goto err_add_host;
	}

	if (ms_host->quirks & MSHCI_QUIRK_WLAN_DETECTION) {
		ms_host->flags |= MSHCI_DEVICE_DEAD;
	        ms_host->flags |= MMC_PM_KEEP_POWER;
	        ms_host->mmc->pm_caps |= MMC_PM_KEEP_POWER;
		if (plat->ext_cd_init)
			plat->ext_cd_init(&mshci_hi_notify_change);
		plat->set_power = mshci_hi_sdio_set_power;
	}

	if( (1 == pdev->id)&&( (ms_host->quirks & MSHCI_QUIRK_CBP_DETECTION) != 0)) {
	        ms_host->flags |= MMC_PM_KEEP_POWER;
	        ms_host->mmc->pm_caps |= MMC_PM_KEEP_POWER;
	}


	if (ms_host->quirks & MSHCI_QUIRK_EXTERNAL_CARD_DETECTION) {

		err = gpio_request_one(plat->cd_gpio, GPIOF_IN, "ESDHC_CD");
		if (err) {
			dev_warn(mmc_dev(ms_host->mmc),
				"no card-detect pin available!\n");
			goto no_card_detect_pin;
		}
		/*SD_INT_FIX_suspend DTS:2013082704916 modifier: y00241633*/
		err = request_irq(gpio_to_irq(plat->cd_gpio), mshci_hi_card_detect_gpio,
				 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_NO_SUSPEND,
				 mmc_hostname(ms_host->mmc), ms_host);
		if (err) {
			dev_warn(mmc_dev(ms_host->mmc), "request gpio irq error\n");
			goto no_card_detect_irq;
		}

        if ( plat->sw_gpio ){
            /* only sft has this gpio */
		    err = gpio_request_one(plat->sw_gpio, 0, "ESDHC_POWER_SWITCH");
		    if (err) {
			    dev_warn(mmc_dev(ms_host->mmc),
				    "no card-power-switch pin available!\n");
			    goto no_card_power_switch_pin;
		    }

            /*控制I/O口电平 1V8 or 3V3*/
            gpio_direction_output(plat->sw_gpio, 1);
        }

	}

	return 0;

no_card_power_switch_pin:
	plat->sw_gpio = err;
no_card_detect_irq:
	gpio_free(plat->cd_gpio);
no_card_detect_pin:
	plat->cd_gpio = err;
err_add_host:
	iounmap(ms_host->ioaddr);
	ms_host->ioaddr = NULL;
err_req_regs:
	spin_lock_irqsave(&ms_host->lock, flags);
	if(ms_host->clk_ref_counter == CLK_ENABLED){
		clk_disable(hi_host->pclk);
		ms_host->clk_ref_counter = CLK_DISABLED;
	}
	spin_unlock_irqrestore(&ms_host->lock, flags);
err_clk_ops:
    clk_put(hi_host->clk_mmc_high);
	clk_put(hi_host->pclk);
err_io_clk:
	mshci_free_host(ms_host);

err_resource_get:

	return ret;
}
static int xmm_power_probe(struct platform_device *pdev)
{
	int status = -1;

	dev_dbg(&pdev->dev, "xmm_power_probe\n");

	xmm_driver_plat_data = pdev->dev.platform_data;

	if (xmm_driver_plat_data) {
		status = gpio_request_array(xmm_driver_plat_data->gpios, XMM_GPIO_NUM);
		if (status) {
			dev_err(&pdev->dev, "GPIO request failed.\n");
			goto error;
		}
	}

	xmm_iomux_block = iomux_get_block(xmm_driver_plat_data->block_name);
	if (!xmm_iomux_block) {
		dev_err(&pdev->dev, "iomux_get_block failed.\n");
		goto error;
	}

	xmm_iomux_config = iomux_get_blockconfig(xmm_driver_plat_data->block_name);
	if (!xmm_iomux_config) {
		dev_err(&pdev->dev, "iomux_get_blockconfig failed.\n");
		goto error;
	}

	/* Register IRQ for HOST_WAKEUP gpio */
	status = request_irq(gpio_to_irq(GPIO_HOST_WAKEUP),
				host_wakeup_isr,
				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_NO_SUSPEND,
				"HOST_WAKEUP_IRQ",
				&pdev->dev);
	if (status) {
		dev_err(&pdev->dev, "Request irq for host wakeup\n");
		goto error;
	}

	/* sysfs entries for IO control */
	status = device_create_file(&(pdev->dev), &dev_attr_state);
	if (status) {
		dev_err(&pdev->dev, "Failed to create sysfs entry\n");
		goto error;
	}

	status = device_create_file(&(pdev->dev), &dev_attr_gpio);
	if (status) {
		dev_err(&pdev->dev, "Failed to create sysfs entry\n");
		goto error;
	}

        status = device_create_file(&(pdev->dev), &dev_attr_cp_shutdown);
	if (status) {
	        dev_err(&pdev->dev,"XMD: BOOT error creating sysfs entry cp_shutdown\n");
	        goto error;
	}
	
	status = device_create_file(&(pdev->dev), &dev_attr_delay);
	if (status) {
		dev_err(&pdev->dev, "Failed to create sysfs entry\n");
		goto error;
	}

	status = device_create_file(&(pdev->dev), &dev_attr_modem_state);
	if (status) {
		dev_err(&pdev->dev, "Failed to create sysfs modem_state entry\n");
		goto error;
	}

    //Register hisik3_ehci_bus_post_suspend and hisik3_ehci_bus_pre_resume function for dynamic compatible with multi modem
    status = hisik3_ehci_bus_post_suspend_register( NULL, xmm_power_runtime_idle );
    if (status)
        dev_info(&pdev->dev, "Warning: Register hisik3_ehci_bus_post_suspend fn failed!\n");

    status = hisik3_ehci_bus_pre_resume_register( NULL, xmm_power_runtime_resume );
    if (status)
        dev_info(&pdev->dev, "Warning: Register hisik3_ehci_bus_pre_resume fn failed!\n");

	/* Initialize works */
	workqueue = create_singlethread_workqueue("xmm_power_workqueue");
	if (!workqueue) {
		dev_err(&pdev->dev, "Create workqueue failed\n");
		status = -1;
		goto error;
	}

	INIT_WORK(&l2_resume_work, xmm_power_l2_resume);
	INIT_WORK(&l3_resume_work, xmm_power_l3_resume);
	INIT_WORK(&modem_reset_work, xmm_power_reset_work);

	init_waitqueue_head(&xmm_wait_q);

	/* This wakelock will be used to arrest system sleeping when USB is in L0 state */
	wake_lock_init(&xmm_wakelock, WAKE_LOCK_SUSPEND, "xmm_power");

	xmm_curr_power_state = XMM_POW_S_OFF;

	return 0;

error:
	if (xmm_driver_plat_data) {
		gpio_free_array(xmm_driver_plat_data->gpios, XMM_GPIO_NUM);
	}

	device_remove_file(&(pdev->dev), &dev_attr_state);
	device_remove_file(&(pdev->dev), &dev_attr_gpio);
	device_remove_file(&(pdev->dev), &dev_attr_delay);

	return status;
}
Пример #7
0
static int __devinit k3_bq24161_charger_probe(struct i2c_client *client,
				 const struct i2c_device_id *id)
{
	u8 read_reg = 0;
	int ret = 0;
	enum usb_charger_type plugin_stat = CHARGER_REMOVED;
	struct k3_bq24161_device_info *di = NULL;
	struct k3_bq24161_platform_data *pdata = NULL;
	/*enum plugin_status plugin_stat;*/

	if (!g_battery_measure_by_bq27510_device) {
		dev_err(&client->dev, "g_battery_measure_by_bq27510_device is NULL!\n");
		return -ENOMEM;
	}

	pdata = client->dev.platform_data;
	if (!pdata) {
		dev_err(&client->dev, "pdata is NULL!\n");
		return -ENOMEM;
	}

	di = kzalloc(sizeof(*di), GFP_KERNEL);
	if (!di) {
		dev_err(&client->dev, "di is NULL!\n");
		return -ENOMEM;
	}

	di->dev = &client->dev;
	di->client = client;

	i2c_set_clientdata(client, di);

	ret = k3_bq24161_read_byte(di, &read_reg, REG_PART_REVISION);

	if (ret < 0) {
		dev_err(&client->dev, "chip not present at address %x\n",
								client->addr);
		ret = -EINVAL;
		goto err_kfree;
	}

	if (((read_reg & BQ24161_VERSION_MSK) == 0x00)
		&& (client->addr == I2C_ADDR_BQ24161))
		di->bqchip_version = BQ24161;

	if (di->bqchip_version == 0) {
		dev_err(&client->dev, "unknown bq chip\n");
		dev_err(&client->dev, "Chip address %x", client->addr);
		dev_err(&client->dev, "bq chip version reg value %x", read_reg);
		ret = -EINVAL;
		goto err_kfree;
	}

	di->max_voltagemV = pdata->max_charger_voltagemV;
	di->max_currentmA = pdata->max_charger_currentmA;
	di->voltagemV = di->max_voltagemV;
	di->currentmA = CURRENT_USB_CHARGE_IN ;
	di->term_currentmA = CURRENT_TERM_CHARGE_IN;
	di->dppm_voltagemV = VOLT_DPPM_ADJUST;
	di->cin_limit = CURRENT_USB_LIMIT_IN;
	di->gpio = pdata->gpio;

	/**********ADD BY 00186176 begin****************/
	 /* Set iomux normal */
#ifdef CONFIG_GPIO_BAT
	if (!di->piomux_block)
		di->piomux_block  = iomux_get_block("block_charger");

	if (!di->pblock_config)
		di->pblock_config = iomux_get_blockconfig("block_charger");

	ret = blockmux_set(di->piomux_block, di->pblock_config, NORMAL);
	if (ret) {
		dev_err(&client->dev, "blockmux_set NORMAL failed, ret=%d\n", ret);
		goto err_kfree;
	}
#endif

    /*set gpio_074 to control CD pin to disable/enable bq24161 IC*/
	ret = gpio_request(di->gpio, "gpio_074_cd");
	if (ret) {
		dev_err(&client->dev, "could not request irq\n");
		ret = -ENOMEM;
		goto err_io;
	}

	 /* set charger CD pin to low level and enable it to supply power normally*/
	gpio_direction_output(di->gpio, 0);

	 /**********ADD BY 00186176 END****************/

	di->enable_low_chg = ENABLE_LOW_CHG;

	/*enable low charge,100mA charging*/
	k3_bq24161_config_safety_reg(di);

	/*disable charge current termination*/
	di->enable_iterm = DISABLE_ITERM;

	di->factory_flag = 0;

	di->enable_ce = ENABLE_CE;
	di->hz_mode = 0;
	di->cd_active = 0;

#if BQ2416X_USE_WAKE_LOCK
	wake_lock_init(&di->charger_wake_lock, WAKE_LOCK_SUSPEND, "charger_wake_lock");
#endif

	INIT_DELAYED_WORK(&di->bq24161_charger_work,
				k3_bq24161_charger_work);

	INIT_WORK(&di->usb_work, k3_bq24161_usb_charger_work);

	di->active = 0;
	di->params.enable = 1;
	di->cfg_params = 1;
	/*di->enable_iterm = 1;*/

	k3_bq24161_config_control_reg(di);
	k3_bq24161_config_voltage_reg(di);
	k3_bq24161_config_current_reg(di);
	k3_bq24161_config_dppm_voltage_reg(di, di->dppm_voltagemV);
	k3_bq24161_config_safety_reg(di);

	ret = sysfs_create_group(&client->dev.kobj, &k3_bq24161_attr_group);
	if (ret) {
		dev_err(&client->dev, "could not create sysfs files\n");
		goto err_gpio;
	}

	/**********ADD BY 00186176 begin****************/

	di->nb.notifier_call = k3_bq24161_usb_notifier_call;

	ret = hiusb_charger_registe_notifier(&di->nb);
	if (ret < 0) {
		dev_err(&client->dev, "hiusb_charger_registe_notifier failed\n");
		goto err_sysfs;
	}

	plugin_stat = get_charger_name();
	if ((CHARGER_TYPE_USB == plugin_stat) || (CHARGER_TYPE_NON_STANDARD == plugin_stat)) {
		di->event = plugin_stat;
		k3_bq24161_start_500mA_charger(di);
	} else if (CHARGER_TYPE_BC_USB == plugin_stat) {
		k3_bq24161_start_BCUSB_charger(di);
	} else if (CHARGER_TYPE_STANDARD == plugin_stat) {
		k3_bq24161_start_ac_charger(di);
	} else {
		k3_bq24161_stop_charger(di);
	}

	return 0;

err_sysfs:
	sysfs_remove_group(&client->dev.kobj, &k3_bq24161_attr_group);
err_gpio:
	gpio_free(di->gpio);
err_io:
#ifdef CONFIG_GPIO_BAT
	if (blockmux_set(di->piomux_block, di->pblock_config, LOWPOWER))
		dev_err(&client->dev, "blockmux_set LOWPOWER failed\n");
#endif
	/**********ADD BY 00186176 END****************/
err_kfree:
	kfree(di);
	di = NULL;

	return ret;
}
static int st_host_wake_probe(struct platform_device *pdev)
{
	int ret = 0;
	struct resource *res;

	pr_info("TI Host Wakeup Driver - Version %s", VERSION);

	hwi = kzalloc(sizeof(struct st_host_wake_info), GFP_KERNEL);
	if (!hwi)
		return -ENOMEM;

	res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
			"host_wake");
	if (!res) {
		pr_info("couldn't find host_wake irq\n");
		ret = -ENODEV;
		goto free_hwi;
	}

	btuart4_block = iomux_get_block(BTUART4_GPIO_IOMUX_BLOCK);
	if (IS_ERR(btuart4_block)) {
		pr_info("%s	: iomux_get_block btuart4_block failed\n", __func__);
		return -ENXIO;
	}
	btuart4_config = iomux_get_blockconfig(BTUART4_GPIO_IOMUX_BLOCK);
	if (IS_ERR(btuart4_config)) {
		pr_info("%s	: iomux_get_blockconfig btuart4_config:\n", __func__);
		return -ENXIO;
	}
	ret = blockmux_set(btuart4_block, btuart4_config, NORMAL);
	if (ret) {
		pr_info("%s	: btuart4_block blockmux set err %d\r\n", __func__, ret);
		return ret;
	}
	gpio_request(res->start, NULL);
	gpio_direction_input(res->start);

	hwi->host_wake_irq = gpio_to_irq(res->start);
	pr_info(" host_wake irq  %d",hwi->host_wake_irq);
	if (hwi->host_wake_irq < 0) {
		pr_info("couldn't find host_wake irq");
		ret = -ENODEV;
		goto free_hwi;
	}
	/* Initialize spinlock.*/
	spin_lock_init(&irq_enable_lock);

	wake_lock_init(&wake_host_lock, WAKE_LOCK_SUSPEND, "st_host_wake");

	if (res->flags & IORESOURCE_IRQ_LOWEDGE)
		ret = request_irq(hwi->host_wake_irq, st_host_wake_isr,
				 IRQF_TRIGGER_RISING | IRQF_NO_SUSPEND,
				"bluetooth hostwake", dev_id);
	else
		ret = request_irq(hwi->host_wake_irq, st_host_wake_isr,
				  IRQF_TRIGGER_RISING | IRQF_NO_SUSPEND,
				"bluetooth hostwake", dev_id);

	if (ret < 0) {
		pr_info("Couldn't acquire ST_HOST_WAKE IRQ");
		goto free_hwi;
	}

	clear_bit(ST_HOST_WAKE, &flags);
	clear_bit(IRQ_WAKE, &flags);
	goto finish;	

free_hwi:
	kfree(hwi);
finish:
	return ret;
	
}
Пример #9
0
static int __init k3v2_wifi_init(void)
{
	int ret = 0;

	ret = init_wifi_mem();
	if (ret) {
		pr_err("%s: init_wifi_mem failed.\n", __func__);
		goto err_malloc_wifi_host;
	}

	wifi_host = kzalloc(sizeof(struct wifi_host_s), GFP_KERNEL);
	if (!wifi_host)	{
		pr_err("%s: malloc wifi_host failed.\n", __func__);
		ret = -ENOMEM;
		goto err_malloc_wifi_host;
	}

#if defined CONFIG_MACH_K3V2OEM1
	wifi_host->bEnable = false;

	/* get 32kb clock */
	wifi_host->clk = clk_get(NULL, "clk_pmu32kb");
	if (IS_ERR(wifi_host->clk)) {
		pr_err("%s: clk_get failed\n", __func__);
		ret = -ENXIO;
		goto err_clk_get;
	}

	/* get wifiio vdd */
	wifi_host->vdd = regulator_get(NULL, "wifiio-vcc");
	if (IS_ERR(wifi_host->vdd)) {
		pr_err("%s: regulator_get failed.\n", __func__);
		ret = -ENXIO;
		goto err_regulator_get;
	}

	ret = regulator_set_voltage(wifi_host->vdd,
		K3V2_WIFI_VDD_VOLTAGE, K3V2_WIFI_VDD_VOLTAGE);
	if (ret < 0) {
		pr_err("%s: regulator_set_voltage failed, ret:%d.\n",
			__func__, ret);
		ret = -ENXIO;
		goto err_regulator_set_voltage;
	}

	/* set io mux*/
	wifi_host->block = iomux_get_block("block_wifi");
	if (!wifi_host->block) {
		pr_err("%s: iomux_lookup_block failed.\n", __func__);
		ret = -ENXIO;
		goto err_iomux_get_block;
	}

	wifi_host->config = iomux_get_blockconfig("block_wifi");
	if (!wifi_host->config) {
		pr_err("%s: iomux_get_blockconfig failed.\n", __func__);
		ret = -ENXIO;
		goto err_iomux_get_blockconfig;
	}

	ret	= blockmux_set(wifi_host->block, wifi_host->config, LOWPOWER);
	if (ret < 0) {
		pr_err("%s: blockmux_set failed, ret.\n", __func__);
		goto err_blockmux_set;
	}
#else
	/* fpga VDD open forver,if can not request other driver maybe has open*/
	ret = gpio_request(K3V2_WIFI_VDD_GPIO, NULL);
	if (ret < 0) {
		pr_err("%s: gpio_request failed, ret:%d.\n", __func__,
			K3V2_WIFI_VDD_GPIO);
	} else
		gpio_direction_output(K3V2_WIFI_VDD_GPIO, 1);
#endif
	/* set power gpio */
	ret = gpio_request(K3V2_WIFI_POWER_GPIO, NULL);
	if (ret < 0) {
		pr_err("%s: gpio_request failed, ret:%d.\n", __func__,
			K3V2_WIFI_POWER_GPIO);
		goto err_power_gpio_request;
	}
	gpio_direction_output(K3V2_WIFI_POWER_GPIO, 0);
	/* set apwake gpio */
	ret = gpio_request(K3V2_WIFI_IRQ_GPIO, NULL);
	if (ret < 0) {
		pr_err("%s: gpio_request failed, ret:%d.\n", __func__,
			K3V2_WIFI_IRQ_GPIO);
		goto err_irq_gpio_request;
	}
	gpio_direction_input(K3V2_WIFI_IRQ_GPIO);

#ifdef CONFIG_WIFI_CONTROL_FUNC
	ret = platform_device_register(&k3v2_wifi_device);
	if (ret) {
		pr_err("%s: platform_device_register failed, ret:%d.\n",
			__func__, ret);
		goto err_platform_device_register;
	}
#endif

	return 0;

err_platform_device_register:
	gpio_free(K3V2_WIFI_IRQ_GPIO);
err_irq_gpio_request:
	gpio_free(K3V2_WIFI_POWER_GPIO);
err_power_gpio_request:

#if defined(CONFIG_MACH_K3V2OEM1)
err_blockmux_set:
err_iomux_get_blockconfig:
err_iomux_get_block:
err_regulator_set_voltage:
	regulator_put(wifi_host->vdd);
err_regulator_get:
	clk_put(wifi_host->clk);
err_clk_get:
	kfree(wifi_host);
	wifi_host = NULL;
#else
	gpio_free(K3V2_WIFI_VDD_GPIO);
#endif
err_malloc_wifi_host:
	deinit_wifi_mem();
	return ret;
}