static int __devinit mshci_s3c_probe(struct platform_device *pdev) { struct s3c_mshci_platdata *pdata = pdev->dev.platform_data; struct device *dev = &pdev->dev; struct mshci_host *host; struct mshci_s3c *sc; struct resource *res; int ret, irq, ptr, clks; if (!pdata) { dev_err(dev, "no device data specified\n"); return -ENOENT; } irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_err(dev, "no irq specified\n"); return irq; } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(dev, "no memory specified\n"); return -ENOENT; } host = mshci_alloc_host(dev, sizeof(struct mshci_s3c)); if (IS_ERR(host)) { dev_err(dev, "mshci_alloc_host() failed\n"); return PTR_ERR(host); } sc = mshci_priv(host); sc->host = host; sc->pdev = pdev; sc->pdata = pdata; sc->ext_cd_gpio = -1; #ifndef CONFIG_S5PV310_FPGA platform_set_drvdata(pdev, host); sc->clk_io = clk_get(dev, "mshc"); if (IS_ERR(sc->clk_io)) { dev_err(dev, "failed to get io clock\n"); ret = PTR_ERR(sc->clk_io); goto err_io_clk; } /* enable the local io clock and keep it running for the moment. */ clk_enable(sc->clk_io); for (clks = 0, ptr = 0; ptr < MAX_BUS_CLK; ptr++) { struct clk *clk; char *name = pdata->clocks[ptr]; if (name == NULL) continue; clk = clk_get(dev, name); if (IS_ERR(clk)) { dev_err(dev, "failed to get clock %s\n", name); continue; } #if defined (CONFIG_S5PV310_MSHC_VPLL_46MHZ) || \ defined (CONFIG_S5PV310_MSHC_EPLL_45MHZ) if (!strcmp("sclk_mshc",name)) { struct clk *parent_clk; if (!(parent_clk = clk_get_parent(clk))) { dev_err(dev, "failed to get parent clock %s\n" , (char *)(clk->name)); } else { for ( ; ; ) { parent_clk = clk_get_parent(parent_clk); if ( parent_clk ) { #ifdef CONFIG_S5PV310_MSHC_EPLL_45MHZ if (!strcmp("fout_epll", \ parent_clk->name)) { #if defined(CONFIG_MACH_C1Q1_REV02) || defined(CONFIG_MACH_P6_REV02) clk_set_rate \ (parent_clk, 144000000); #else clk_set_rate \ (parent_clk, 180633600); #endif pdata->cfg_ddr(pdev, 0); #elif defined (CONFIG_S5PV310_MSHC_VPLL_46MHZ) if (!strcmp("fout_vpll", \ parent_clk->name)) { clk_set_rate \ (parent_clk, 370882812); pdata->cfg_ddr(pdev, 0); #endif clk_enable(parent_clk); break; } else continue; } else { dev_err(dev, "failed to" "get parent" "clock %s\n" , clk->name); break; } } } } #endif clks++; sc->clk_bus[ptr] = clk; clk_enable(clk); dev_info(dev, "clock source %d: %s (%ld Hz)\n", ptr, name, clk_get_rate(clk)); } if (clks == 0) { dev_err(dev, "failed to find any bus clocks\n"); ret = -ENOENT; goto err_no_busclks; } #endif sc->ioarea = request_mem_region(res->start, resource_size(res), mmc_hostname(host->mmc)); if (!sc->ioarea) { dev_err(dev, "failed to reserve register area\n"); ret = -ENXIO; goto err_req_regs; } host->ioaddr = ioremap_nocache(res->start, resource_size(res)); if (!host->ioaddr) { dev_err(dev, "failed to map registers\n"); ret = -ENXIO; goto err_req_regs; } /* Ensure we have minimal gpio selected CMD/CLK/Detect */ if (pdata->cfg_gpio) { pdata->cfg_gpio(pdev, pdata->max_width); } else { dev_err(dev, "cfg_gpio dose not exist.!\n"); } host->hw_name = "samsung-mshci"; host->ops = &mshci_s3c_ops; host->quirks = 0; host->irq = irq; if (pdata->host_caps) host->mmc->caps = pdata->host_caps; else host->mmc->caps = 0; if (pdata->cd_type == S3C_MSHCI_CD_PERMANENT){ host->quirks |= MSHCI_QUIRK_BROKEN_PRESENT_BIT; host->mmc->caps |= MMC_CAP_NONREMOVABLE; } /* IF SD controller's WP pin donsn't connected with SD card and there * is an allocated GPIO for getting WP data form SD card, * use this quirk and send the GPIO number in pdata->wp_gpio. */ if (pdata->has_wp_gpio && gpio_is_valid(pdata->wp_gpio)) { mshci_s3c_ops.get_ro = mshci_s3c_get_ro; host->quirks |= MSHCI_QUIRK_NO_WP_BIT; mshci_s3c_cfg_wp(pdata->wp_gpio); } ret = mshci_add_host(host); if (pdata->cd_type == S3C_MSHCI_CD_GPIO && gpio_is_valid(pdata->ext_cd_gpio)) { gpio_request(pdata->ext_cd_gpio, "SDHCI EXT CD"); sc->ext_cd_gpio = pdata->ext_cd_gpio; sc->ext_cd_irq = gpio_to_irq(pdata->ext_cd_gpio); if (sc->ext_cd_irq && request_irq(sc->ext_cd_irq, mshci_s3c_gpio_card_detect_isr, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, dev_name(&pdev->dev), sc)) { dev_err(&pdev->dev, "cannot request irq for card detect\n"); sc->ext_cd_irq = 0; } dev_dbg(&pdev->dev, "mshci detects a card insertion/removal" "by EINT\n"); } if (ret) { dev_err(dev, "mshci_add_host() failed\n"); goto err_add_host; } return 0; err_add_host: release_resource(sc->ioarea); kfree(sc->ioarea); err_req_regs: for (ptr = 0; ptr < MAX_BUS_CLK; ptr++) { clk_disable(sc->clk_bus[ptr]); clk_put(sc->clk_bus[ptr]); } err_no_busclks: clk_disable(sc->clk_io); clk_put(sc->clk_io); err_io_clk: mshci_free_host(host); return ret; } static int __devexit mshci_s3c_remove(struct platform_device *pdev) { return 0; } #ifdef CONFIG_PM static int mshci_s3c_suspend(struct platform_device *dev, pm_message_t pm) { struct mshci_host *host = platform_get_drvdata(dev); mshci_suspend_host(host, pm); return 0; } static int mshci_s3c_resume(struct platform_device *dev) { struct mshci_host *host = platform_get_drvdata(dev); mshci_resume_host(host); return 0; } static void mshci_s3c_shutdown(struct platform_device *dev) { struct mshci_host *host = platform_get_drvdata(dev); struct s3c_mshci_platdata *pdata = dev->dev.platform_data; pm_message_t dummy = {0}; // mshci_suspend_host func is pm not used. mshci_suspend_host(host, dummy); if (pdata->shutdown) pdata->shutdown(); } #else static int mshci_s3c_suspend(struct platform_device *dev, pm_message_t pm) { pr_info("%s : is DUMMY\n", __func__); return 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; }