board-sapphire-mmc.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. /* linux/arch/arm/mach-msm/board-sapphire-mmc.c
  2. * Copyright (C) 2007-2009 HTC Corporation.
  3. * Author: Thomas Tsai <thomas_tsai@htc.com>
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/delay.h>
  18. #include <linux/mmc/host.h>
  19. #include <linux/mmc/sdio_ids.h>
  20. #include <linux/err.h>
  21. #include <linux/debugfs.h>
  22. #include <linux/gpio.h>
  23. #include <linux/io.h>
  24. #include <asm/mach-types.h>
  25. #include <mach/vreg.h>
  26. #include <mach/htc_pwrsink.h>
  27. #include <mach/proc_comm.h>
  28. #include <asm/mach/mmc.h>
  29. #include "devices.h"
  30. #include "gpio_chip.h"
  31. #include "board-sapphire.h"
  32. #define DEBUG_SDSLOT_VDD 0
  33. extern int msm_add_sdcc(unsigned int controller, struct mmc_platform_data *plat,
  34. unsigned int stat_irq, unsigned long stat_irq_flags);
  35. /* ---- COMMON ---- */
  36. static void config_gpio_table(uint32_t *table, int len)
  37. {
  38. int n;
  39. unsigned id;
  40. for (n = 0; n < len; n++) {
  41. id = table[n];
  42. msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX, &id, 0);
  43. }
  44. }
  45. /* ---- SDCARD ---- */
  46. static uint32_t sdcard_on_gpio_table[] = {
  47. PCOM_GPIO_CFG(62, 2, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_8MA), /* CLK */
  48. PCOM_GPIO_CFG(63, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* CMD */
  49. PCOM_GPIO_CFG(64, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* DAT3 */
  50. PCOM_GPIO_CFG(65, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* DAT2 */
  51. PCOM_GPIO_CFG(66, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT1 */
  52. PCOM_GPIO_CFG(67, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT0 */
  53. };
  54. static uint32_t sdcard_off_gpio_table[] = {
  55. PCOM_GPIO_CFG(62, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* CLK */
  56. PCOM_GPIO_CFG(63, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* CMD */
  57. PCOM_GPIO_CFG(64, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT3 */
  58. PCOM_GPIO_CFG(65, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT2 */
  59. PCOM_GPIO_CFG(66, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT1 */
  60. PCOM_GPIO_CFG(67, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT0 */
  61. };
  62. static uint opt_disable_sdcard;
  63. static int __init sapphire_disablesdcard_setup(char *str)
  64. {
  65. int cal = simple_strtol(str, NULL, 0);
  66. opt_disable_sdcard = cal;
  67. return 1;
  68. }
  69. __setup("board_sapphire.disable_sdcard=", sapphire_disablesdcard_setup);
  70. static struct vreg *vreg_sdslot; /* SD slot power */
  71. struct mmc_vdd_xlat {
  72. int mask;
  73. int level;
  74. };
  75. static struct mmc_vdd_xlat mmc_vdd_table[] = {
  76. { MMC_VDD_165_195, 1800 },
  77. { MMC_VDD_20_21, 2050 },
  78. { MMC_VDD_21_22, 2150 },
  79. { MMC_VDD_22_23, 2250 },
  80. { MMC_VDD_23_24, 2350 },
  81. { MMC_VDD_24_25, 2450 },
  82. { MMC_VDD_25_26, 2550 },
  83. { MMC_VDD_26_27, 2650 },
  84. { MMC_VDD_27_28, 2750 },
  85. { MMC_VDD_28_29, 2850 },
  86. { MMC_VDD_29_30, 2950 },
  87. };
  88. static unsigned int sdslot_vdd = 0xffffffff;
  89. static unsigned int sdslot_vreg_enabled;
  90. static uint32_t sapphire_sdslot_switchvdd(struct device *dev, unsigned int vdd)
  91. {
  92. int i, rc;
  93. BUG_ON(!vreg_sdslot);
  94. if (vdd == sdslot_vdd)
  95. return 0;
  96. sdslot_vdd = vdd;
  97. if (vdd == 0) {
  98. #if DEBUG_SDSLOT_VDD
  99. printk(KERN_DEBUG "%s: Disabling SD slot power\n", __func__);
  100. #endif
  101. config_gpio_table(sdcard_off_gpio_table,
  102. ARRAY_SIZE(sdcard_off_gpio_table));
  103. vreg_disable(vreg_sdslot);
  104. sdslot_vreg_enabled = 0;
  105. return 0;
  106. }
  107. if (!sdslot_vreg_enabled) {
  108. rc = vreg_enable(vreg_sdslot);
  109. if (rc) {
  110. printk(KERN_ERR "%s: Error enabling vreg (%d)\n",
  111. __func__, rc);
  112. }
  113. config_gpio_table(sdcard_on_gpio_table,
  114. ARRAY_SIZE(sdcard_on_gpio_table));
  115. sdslot_vreg_enabled = 1;
  116. }
  117. for (i = 0; i < ARRAY_SIZE(mmc_vdd_table); i++) {
  118. if (mmc_vdd_table[i].mask == (1 << vdd)) {
  119. #if DEBUG_SDSLOT_VDD
  120. printk(KERN_DEBUG "%s: Setting level to %u\n",
  121. __func__, mmc_vdd_table[i].level);
  122. #endif
  123. rc = vreg_set_level(vreg_sdslot,
  124. mmc_vdd_table[i].level);
  125. if (rc) {
  126. printk(KERN_ERR
  127. "%s: Error setting vreg level (%d)\n",
  128. __func__, rc);
  129. }
  130. return 0;
  131. }
  132. }
  133. printk(KERN_ERR "%s: Invalid VDD %d specified\n", __func__, vdd);
  134. return 0;
  135. }
  136. static unsigned int sapphire_sdslot_status(struct device *dev)
  137. {
  138. unsigned int status;
  139. status = (unsigned int) gpio_get_value(SAPPHIRE_GPIO_SDMC_CD_N);
  140. return !status;
  141. }
  142. #define SAPPHIRE_MMC_VDD (MMC_VDD_165_195 | MMC_VDD_20_21 | MMC_VDD_21_22 \
  143. | MMC_VDD_22_23 | MMC_VDD_23_24 | MMC_VDD_24_25 \
  144. | MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 \
  145. | MMC_VDD_28_29 | MMC_VDD_29_30)
  146. static struct mmc_platform_data sapphire_sdslot_data = {
  147. .ocr_mask = SAPPHIRE_MMC_VDD,
  148. .status = sapphire_sdslot_status,
  149. .translate_vdd = sapphire_sdslot_switchvdd,
  150. };
  151. /* ---- WIFI ---- */
  152. static uint32_t wifi_on_gpio_table[] = {
  153. PCOM_GPIO_CFG(51, 1, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT3 */
  154. PCOM_GPIO_CFG(52, 1, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT2 */
  155. PCOM_GPIO_CFG(53, 1, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT1 */
  156. PCOM_GPIO_CFG(54, 1, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT0 */
  157. PCOM_GPIO_CFG(55, 1, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* CMD */
  158. PCOM_GPIO_CFG(56, 1, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_8MA), /* CLK */
  159. PCOM_GPIO_CFG(29, 0, GPIO_INPUT, GPIO_NO_PULL, GPIO_4MA), /* WLAN IRQ */
  160. };
  161. static uint32_t wifi_off_gpio_table[] = {
  162. PCOM_GPIO_CFG(51, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT3 */
  163. PCOM_GPIO_CFG(52, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT2 */
  164. PCOM_GPIO_CFG(53, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT1 */
  165. PCOM_GPIO_CFG(54, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT0 */
  166. PCOM_GPIO_CFG(55, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* CMD */
  167. PCOM_GPIO_CFG(56, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* CLK */
  168. PCOM_GPIO_CFG(29, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* WLAN IRQ */
  169. };
  170. static struct vreg *vreg_wifi_osc; /* WIFI 32khz oscilator */
  171. static int sapphire_wifi_cd = 0; /* WIFI virtual 'card detect' status */
  172. static struct sdio_embedded_func wifi_func = {
  173. .f_class = SDIO_CLASS_WLAN,
  174. .f_maxblksize = 512,
  175. };
  176. static struct embedded_sdio_data sapphire_wifi_emb_data = {
  177. .cis = {
  178. .vendor = 0x104c,
  179. .device = 0x9066,
  180. .blksize = 512,
  181. .max_dtr = 20000000,
  182. },
  183. .cccr = {
  184. .multi_block = 0,
  185. .low_speed = 0,
  186. .wide_bus = 1,
  187. .high_power = 0,
  188. .high_speed = 0,
  189. },
  190. .funcs = &wifi_func,
  191. .num_funcs = 1,
  192. };
  193. static void (*wifi_status_cb)(int card_present, void *dev_id);
  194. static void *wifi_status_cb_devid;
  195. static int sapphire_wifi_status_register(void (*callback)(int card_present,
  196. void *dev_id),
  197. void *dev_id)
  198. {
  199. if (wifi_status_cb)
  200. return -EAGAIN;
  201. wifi_status_cb = callback;
  202. wifi_status_cb_devid = dev_id;
  203. return 0;
  204. }
  205. static unsigned int sapphire_wifi_status(struct device *dev)
  206. {
  207. return sapphire_wifi_cd;
  208. }
  209. int sapphire_wifi_set_carddetect(int val)
  210. {
  211. printk(KERN_DEBUG "%s: %d\n", __func__, val);
  212. sapphire_wifi_cd = val;
  213. if (wifi_status_cb)
  214. wifi_status_cb(val, wifi_status_cb_devid);
  215. else
  216. printk(KERN_WARNING "%s: Nobody to notify\n", __func__);
  217. return 0;
  218. }
  219. #ifndef CONFIG_WIFI_CONTROL_FUNC
  220. EXPORT_SYMBOL(sapphire_wifi_set_carddetect);
  221. #endif
  222. int sapphire_wifi_power_state=0;
  223. int sapphire_bt_power_state=0;
  224. int sapphire_wifi_power(int on)
  225. {
  226. int rc;
  227. printk(KERN_DEBUG "%s: %d\n", __func__, on);
  228. if (on) {
  229. config_gpio_table(wifi_on_gpio_table,
  230. ARRAY_SIZE(wifi_on_gpio_table));
  231. rc = vreg_enable(vreg_wifi_osc);
  232. if (rc)
  233. return rc;
  234. htc_pwrsink_set(PWRSINK_WIFI, 70);
  235. } else {
  236. config_gpio_table(wifi_off_gpio_table,
  237. ARRAY_SIZE(wifi_off_gpio_table));
  238. htc_pwrsink_set(PWRSINK_WIFI, 0);
  239. }
  240. gpio_set_value(SAPPHIRE_GPIO_MAC_32K_EN, on);
  241. mdelay(100);
  242. gpio_set_value(SAPPHIRE_GPIO_WIFI_EN, on);
  243. mdelay(100);
  244. if (!on) {
  245. if(!sapphire_bt_power_state)
  246. {
  247. vreg_disable(vreg_wifi_osc);
  248. printk("WiFi disable vreg_wifi_osc.\n");
  249. }
  250. else
  251. printk("WiFi shouldn't disable vreg_wifi_osc. BT is using it!!\n");
  252. }
  253. sapphire_wifi_power_state = on;
  254. return 0;
  255. }
  256. #ifndef CONFIG_WIFI_CONTROL_FUNC
  257. EXPORT_SYMBOL(sapphire_wifi_power);
  258. #endif
  259. /* Eenable VREG_MMC pin to turn on fastclock oscillator : colin */
  260. int sapphire_bt_fastclock_power(int on)
  261. {
  262. int rc;
  263. printk(KERN_DEBUG "sapphire_bt_fastclock_power on = %d\n", on);
  264. if (vreg_wifi_osc) {
  265. if (on) {
  266. rc = vreg_enable(vreg_wifi_osc);
  267. printk(KERN_DEBUG "BT vreg_enable vreg_mmc, rc=%d\n",
  268. rc);
  269. if (rc) {
  270. printk("Error turn sapphire_bt_fastclock_power rc=%d\n", rc);
  271. return rc;
  272. }
  273. } else {
  274. if (!sapphire_wifi_power_state) {
  275. vreg_disable(vreg_wifi_osc);
  276. printk(KERN_DEBUG "BT disable vreg_wifi_osc.\n");
  277. } else
  278. printk(KERN_DEBUG "BT shouldn't disable vreg_wifi_osc. WiFi is using it!!\n");
  279. }
  280. }
  281. sapphire_bt_power_state = on;
  282. return 0;
  283. }
  284. EXPORT_SYMBOL(sapphire_bt_fastclock_power);
  285. static int sapphire_wifi_reset_state;
  286. void sapphire_wifi_reset(int on)
  287. {
  288. printk(KERN_DEBUG "%s: %d\n", __func__, on);
  289. gpio_set_value(SAPPHIRE_GPIO_WIFI_PA_RESETX, !on);
  290. sapphire_wifi_reset_state = on;
  291. mdelay(50);
  292. }
  293. #ifndef CONFIG_WIFI_CONTROL_FUNC
  294. EXPORT_SYMBOL(sapphire_wifi_reset);
  295. #endif
  296. static struct mmc_platform_data sapphire_wifi_data = {
  297. .ocr_mask = MMC_VDD_28_29,
  298. .status = sapphire_wifi_status,
  299. .register_status_notify = sapphire_wifi_status_register,
  300. .embedded_sdio = &sapphire_wifi_emb_data,
  301. };
  302. int __init sapphire_init_mmc(unsigned int sys_rev)
  303. {
  304. wifi_status_cb = NULL;
  305. sdslot_vreg_enabled = 0;
  306. vreg_sdslot = vreg_get(0, "gp6");
  307. if (IS_ERR(vreg_sdslot))
  308. return PTR_ERR(vreg_sdslot);
  309. vreg_wifi_osc = vreg_get(0, "mmc");
  310. if (IS_ERR(vreg_wifi_osc))
  311. return PTR_ERR(vreg_wifi_osc);
  312. set_irq_wake(SAPPHIRE_GPIO_TO_INT(SAPPHIRE_GPIO_SDMC_CD_N), 1);
  313. msm_add_sdcc(1, &sapphire_wifi_data, 0, 0);
  314. if (!opt_disable_sdcard)
  315. msm_add_sdcc(2, &sapphire_sdslot_data,
  316. SAPPHIRE_GPIO_TO_INT(SAPPHIRE_GPIO_SDMC_CD_N), 0);
  317. else
  318. printk(KERN_INFO "sapphire: SD-Card interface disabled\n");
  319. return 0;
  320. }
  321. #if defined(CONFIG_DEBUG_FS)
  322. static int sapphiremmc_dbg_wifi_reset_set(void *data, u64 val)
  323. {
  324. sapphire_wifi_reset((int) val);
  325. return 0;
  326. }
  327. static int sapphiremmc_dbg_wifi_reset_get(void *data, u64 *val)
  328. {
  329. *val = sapphire_wifi_reset_state;
  330. return 0;
  331. }
  332. static int sapphiremmc_dbg_wifi_cd_set(void *data, u64 val)
  333. {
  334. sapphire_wifi_set_carddetect((int) val);
  335. return 0;
  336. }
  337. static int sapphiremmc_dbg_wifi_cd_get(void *data, u64 *val)
  338. {
  339. *val = sapphire_wifi_cd;
  340. return 0;
  341. }
  342. static int sapphiremmc_dbg_wifi_pwr_set(void *data, u64 val)
  343. {
  344. sapphire_wifi_power((int) val);
  345. return 0;
  346. }
  347. static int sapphiremmc_dbg_wifi_pwr_get(void *data, u64 *val)
  348. {
  349. *val = sapphire_wifi_power_state;
  350. return 0;
  351. }
  352. static int sapphiremmc_dbg_sd_pwr_set(void *data, u64 val)
  353. {
  354. sapphire_sdslot_switchvdd(NULL, (unsigned int) val);
  355. return 0;
  356. }
  357. static int sapphiremmc_dbg_sd_pwr_get(void *data, u64 *val)
  358. {
  359. *val = sdslot_vdd;
  360. return 0;
  361. }
  362. static int sapphiremmc_dbg_sd_cd_set(void *data, u64 val)
  363. {
  364. return -ENOSYS;
  365. }
  366. static int sapphiremmc_dbg_sd_cd_get(void *data, u64 *val)
  367. {
  368. *val = sapphire_sdslot_status(NULL);
  369. return 0;
  370. }
  371. DEFINE_SIMPLE_ATTRIBUTE(sapphiremmc_dbg_wifi_reset_fops,
  372. sapphiremmc_dbg_wifi_reset_get,
  373. sapphiremmc_dbg_wifi_reset_set, "%llu\n");
  374. DEFINE_SIMPLE_ATTRIBUTE(sapphiremmc_dbg_wifi_cd_fops,
  375. sapphiremmc_dbg_wifi_cd_get,
  376. sapphiremmc_dbg_wifi_cd_set, "%llu\n");
  377. DEFINE_SIMPLE_ATTRIBUTE(sapphiremmc_dbg_wifi_pwr_fops,
  378. sapphiremmc_dbg_wifi_pwr_get,
  379. sapphiremmc_dbg_wifi_pwr_set, "%llu\n");
  380. DEFINE_SIMPLE_ATTRIBUTE(sapphiremmc_dbg_sd_pwr_fops,
  381. sapphiremmc_dbg_sd_pwr_get,
  382. sapphiremmc_dbg_sd_pwr_set, "%llu\n");
  383. DEFINE_SIMPLE_ATTRIBUTE(sapphiremmc_dbg_sd_cd_fops,
  384. sapphiremmc_dbg_sd_cd_get,
  385. sapphiremmc_dbg_sd_cd_set, "%llu\n");
  386. static int __init sapphiremmc_dbg_init(void)
  387. {
  388. struct dentry *dent;
  389. if (!machine_is_sapphire())
  390. return 0;
  391. dent = debugfs_create_dir("sapphiremmc_dbg", 0);
  392. if (IS_ERR(dent))
  393. return PTR_ERR(dent);
  394. debugfs_create_file("wifi_reset", 0644, dent, NULL,
  395. &sapphiremmc_dbg_wifi_reset_fops);
  396. debugfs_create_file("wifi_cd", 0644, dent, NULL,
  397. &sapphiremmc_dbg_wifi_cd_fops);
  398. debugfs_create_file("wifi_pwr", 0644, dent, NULL,
  399. &sapphiremmc_dbg_wifi_pwr_fops);
  400. debugfs_create_file("sd_pwr", 0644, dent, NULL,
  401. &sapphiremmc_dbg_sd_pwr_fops);
  402. debugfs_create_file("sd_cd", 0644, dent, NULL,
  403. &sapphiremmc_dbg_sd_cd_fops);
  404. return 0;
  405. }
  406. device_initcall(sapphiremmc_dbg_init);
  407. #endif