• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Sunxi SD/MMC host driver
3 *
4 * Copyright (C) 2015 AllWinnertech Ltd.
5 * Author: lixiang <lixiang@allwinnertech>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
12 * kind, whether express or implied; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 */
16 
17 
18 #include <linux/clk.h>
19 #include <linux/reset/sunxi.h>
20 
21 #include <linux/gpio.h>
22 #include <linux/platform_device.h>
23 #include <linux/spinlock.h>
24 #include <linux/scatterlist.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/slab.h>
27 #include <linux/reset.h>
28 
29 #include <linux/of_address.h>
30 #include <linux/of_gpio.h>
31 #include <linux/of_platform.h>
32 #include <linux/regulator/consumer.h>
33 
34 #include <linux/mmc/host.h>
35 #include <linux/mmc/sd.h>
36 #include <linux/mmc/sdio.h>
37 #include <linux/mmc/mmc.h>
38 #include <linux/mmc/core.h>
39 #include <linux/mmc/card.h>
40 #include <linux/mmc/slot-gpio.h>
41 
42 #include "sunxi-mmc.h"
43 #include "sunxi-mmc-export.h"
44 #include "sunxi-mmc-debug.h"
45 
46 #define SUNXI_MAX_CONTROL	4
47 
48 static struct sunxi_mmc_host *sunxi_hosts[SUNXI_MAX_CONTROL] = { NULL };
49 
sunxi_mmc_rescan_card(unsigned id)50 void sunxi_mmc_rescan_card(unsigned id)
51 {
52 
53 	if (id > SUNXI_MAX_CONTROL) {
54 		pr_err("%d id over max id", id);
55 		return;
56 	}
57 
58 	if (sunxi_hosts[id] == NULL) {
59 		pr_err("sunxi_hosts[%d] should not be null", id);
60 		return;
61 	}
62 
63 	if (sunxi_hosts[id] == NULL) {
64 		SM_ERR(mmc_dev(sunxi_hosts[id]->mmc),
65 			"%s:can't find the host\n", __func__);
66 		return;
67 	}
68 	mmc_detect_change(sunxi_hosts[id]->mmc, 0);
69 }
70 EXPORT_SYMBOL_GPL(sunxi_mmc_rescan_card);
71 
sunxi_mmc_reg_ex_res_inter(struct sunxi_mmc_host * host,u32 phy_id)72 void sunxi_mmc_reg_ex_res_inter(struct sunxi_mmc_host *host, u32 phy_id)
73 {
74 	if (phy_id > SUNXI_MAX_CONTROL) {
75 		pr_err("%d id over max id", phy_id);
76 		return;
77 	}
78 	sunxi_hosts[phy_id] = host;
79 }
80 EXPORT_SYMBOL_GPL(sunxi_mmc_reg_ex_res_inter);
81 
sunxi_mmc_check_r1_ready(struct mmc_host * mmc,unsigned ms)82 int sunxi_mmc_check_r1_ready(struct mmc_host *mmc, unsigned ms)
83 {
84 	struct sunxi_mmc_host *host = mmc_priv(mmc);
85 	unsigned long expire = jiffies + msecs_to_jiffies(ms);
86 
87 	do {
88 		if (!(mmc_readl(host, REG_STAS) & SDXC_CARD_DATA_BUSY))
89 			break;
90 	} while (time_before(jiffies, expire));
91 
92 	if ((mmc_readl(host, REG_STAS) & SDXC_CARD_DATA_BUSY)) {
93 		SM_ERR(mmc_dev(mmc), "wait r1 rdy %d ms timeout\n", ms);
94 		return -1;
95 	} else
96 		return 0;
97 }
98 EXPORT_SYMBOL_GPL(sunxi_mmc_check_r1_ready);
99 
100