sd_pad.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. #include <mach/card_io.h>
  2. #include <linux/cardreader/card_block.h>
  3. #include <linux/cardreader/cardreader.h>
  4. #include <plat/regops.h>
  5. #include <mach/pinmux.h>
  6. static unsigned sd_backup_input_val = 0;
  7. static unsigned sd_backup_output_val = 0;
  8. static unsigned SD_BAKUP_INPUT_REG = (unsigned)&sd_backup_input_val;
  9. static unsigned SD_BAKUP_OUTPUT_REG = (unsigned)&sd_backup_output_val;
  10. unsigned SD_CMD_OUTPUT_EN_REG;
  11. unsigned SD_CMD_OUTPUT_EN_MASK;
  12. unsigned SD_CMD_INPUT_REG;
  13. unsigned SD_CMD_INPUT_MASK;
  14. unsigned SD_CMD_OUTPUT_REG;
  15. unsigned SD_CMD_OUTPUT_MASK;
  16. unsigned SD_CLK_OUTPUT_EN_REG;
  17. unsigned SD_CLK_OUTPUT_EN_MASK;
  18. unsigned SD_CLK_OUTPUT_REG;
  19. unsigned SD_CLK_OUTPUT_MASK;
  20. unsigned SD_DAT_OUTPUT_EN_REG;
  21. unsigned SD_DAT0_OUTPUT_EN_MASK;
  22. unsigned SD_DAT0_3_OUTPUT_EN_MASK;
  23. unsigned SD_DAT_INPUT_REG;
  24. unsigned SD_DAT_OUTPUT_REG;
  25. unsigned SD_DAT0_INPUT_MASK;
  26. unsigned SD_DAT0_OUTPUT_MASK;
  27. unsigned SD_DAT0_3_INPUT_MASK;
  28. unsigned SD_DAT0_3_OUTPUT_MASK;
  29. unsigned SD_DAT_INPUT_OFFSET;
  30. unsigned SD_DAT_OUTPUT_OFFSET;
  31. unsigned SD_INS_OUTPUT_EN_REG;
  32. unsigned SD_INS_OUTPUT_EN_MASK;
  33. unsigned SD_INS_INPUT_REG;
  34. unsigned SD_INS_INPUT_MASK;
  35. unsigned SD_WP_OUTPUT_EN_REG;
  36. unsigned SD_WP_OUTPUT_EN_MASK;
  37. unsigned SD_WP_INPUT_REG;
  38. unsigned SD_WP_INPUT_MASK;
  39. unsigned SD_PWR_OUTPUT_EN_REG;
  40. unsigned SD_PWR_OUTPUT_EN_MASK;
  41. unsigned SD_PWR_OUTPUT_REG;
  42. unsigned SD_PWR_OUTPUT_MASK;
  43. unsigned SD_PWR_EN_LEVEL;
  44. unsigned SD_WORK_MODE;
  45. extern int using_sdxc_controller;
  46. void sd_io_init(struct memory_card *card)
  47. {
  48. struct aml_card_info *aml_card_info = card->card_plat_info;
  49. SD_WORK_MODE = aml_card_info->work_mode;
  50. if ((aml_card_info->io_pad_type == SDXC_CARD_0_5) ||
  51. (aml_card_info->io_pad_type == SDXC_BOOT_0_11) ||
  52. (aml_card_info->io_pad_type == SDXC_GPIOX_0_9))
  53. using_sdxc_controller = 1;
  54. switch (aml_card_info->io_pad_type) {
  55. case SDHC_CARD_0_5: //SDHC-B
  56. SD_CMD_OUTPUT_EN_REG = CARD_GPIO_ENABLE;
  57. SD_CMD_OUTPUT_EN_MASK = PREG_IO_28_MASK;
  58. SD_CMD_OUTPUT_REG = CARD_GPIO_OUTPUT;
  59. SD_CMD_OUTPUT_MASK = PREG_IO_28_MASK;
  60. SD_CMD_INPUT_REG = CARD_GPIO_INPUT;
  61. SD_CMD_INPUT_MASK = PREG_IO_28_MASK;
  62. SD_CLK_OUTPUT_EN_REG = CARD_GPIO_ENABLE;
  63. SD_CLK_OUTPUT_EN_MASK = PREG_IO_27_MASK;
  64. SD_CLK_OUTPUT_REG = CARD_GPIO_OUTPUT;
  65. SD_CLK_OUTPUT_MASK = PREG_IO_27_MASK;
  66. SD_DAT_OUTPUT_EN_REG = CARD_GPIO_ENABLE;
  67. SD_DAT0_OUTPUT_EN_MASK = PREG_IO_23_MASK;
  68. SD_DAT0_3_OUTPUT_EN_MASK = PREG_IO_23_26_MASK;
  69. SD_DAT_OUTPUT_REG = CARD_GPIO_OUTPUT;
  70. SD_DAT0_OUTPUT_MASK = PREG_IO_23_MASK;
  71. SD_DAT0_3_OUTPUT_MASK = PREG_IO_23_26_MASK;
  72. SD_DAT_OUTPUT_OFFSET = 23;
  73. SD_DAT_INPUT_REG = CARD_GPIO_INPUT;
  74. SD_DAT0_INPUT_MASK = PREG_IO_23_MASK;
  75. SD_DAT0_3_INPUT_MASK = PREG_IO_23_26_MASK;
  76. SD_DAT_INPUT_OFFSET = 23;
  77. break;
  78. case SDHC_BOOT_0_11: //SDHC-C
  79. SD_CMD_OUTPUT_EN_REG = BOOT_GPIO_ENABLE;
  80. SD_CMD_OUTPUT_EN_MASK = PREG_IO_10_MASK;
  81. SD_CMD_OUTPUT_REG = BOOT_GPIO_OUTPUT;
  82. SD_CMD_OUTPUT_MASK = PREG_IO_10_MASK;
  83. SD_CMD_INPUT_REG = BOOT_GPIO_INPUT;
  84. SD_CMD_INPUT_MASK = PREG_IO_10_MASK;
  85. SD_CLK_OUTPUT_EN_REG = BOOT_GPIO_ENABLE;
  86. SD_CLK_OUTPUT_EN_MASK = PREG_IO_11_MASK;
  87. SD_CLK_OUTPUT_REG = BOOT_GPIO_OUTPUT;
  88. SD_CLK_OUTPUT_MASK = PREG_IO_11_MASK;
  89. SD_DAT_OUTPUT_EN_REG = BOOT_GPIO_ENABLE;
  90. SD_DAT0_OUTPUT_EN_MASK = PREG_IO_0_MASK;
  91. SD_DAT0_3_OUTPUT_EN_MASK = PREG_IO_0_3_MASK;
  92. SD_DAT_OUTPUT_REG = BOOT_GPIO_OUTPUT;
  93. SD_DAT0_OUTPUT_MASK = PREG_IO_0_MASK;
  94. SD_DAT0_3_OUTPUT_MASK = PREG_IO_0_3_MASK;
  95. SD_DAT_OUTPUT_OFFSET = 0;
  96. SD_DAT_INPUT_REG = BOOT_GPIO_INPUT;
  97. SD_DAT0_INPUT_MASK = PREG_IO_0_MASK;
  98. SD_DAT0_3_INPUT_MASK = PREG_IO_0_3_MASK;
  99. SD_DAT_INPUT_OFFSET = 0;
  100. break;
  101. case SDHC_GPIOX_0_9: //SDHC-A
  102. SD_CMD_OUTPUT_EN_REG = EGPIO_GPIOXL_ENABLE;
  103. SD_CMD_OUTPUT_EN_MASK = PREG_IO_9_MASK;
  104. SD_CMD_OUTPUT_REG = EGPIO_GPIOXL_OUTPUT;
  105. SD_CMD_OUTPUT_MASK = PREG_IO_9_MASK;
  106. SD_CMD_INPUT_REG = EGPIO_GPIOXL_INPUT;
  107. SD_CMD_INPUT_MASK = PREG_IO_9_MASK;
  108. SD_CLK_OUTPUT_EN_REG = EGPIO_GPIOXL_ENABLE;
  109. SD_CLK_OUTPUT_EN_MASK = PREG_IO_8_MASK;
  110. SD_CLK_OUTPUT_REG = EGPIO_GPIOXL_OUTPUT;
  111. SD_CLK_OUTPUT_MASK = PREG_IO_8_MASK;
  112. SD_DAT_OUTPUT_EN_REG = EGPIO_GPIOXL_ENABLE;
  113. SD_DAT0_OUTPUT_EN_MASK = PREG_IO_0_MASK;
  114. SD_DAT0_3_OUTPUT_EN_MASK = PREG_IO_0_3_MASK;
  115. SD_DAT_OUTPUT_REG = EGPIO_GPIOXL_OUTPUT;
  116. SD_DAT0_OUTPUT_MASK = PREG_IO_0_MASK;
  117. SD_DAT0_3_OUTPUT_MASK = PREG_IO_0_3_MASK;
  118. SD_DAT_OUTPUT_OFFSET = 0;
  119. SD_DAT_INPUT_REG = EGPIO_GPIOXL_INPUT;
  120. SD_DAT0_INPUT_MASK = PREG_IO_0_MASK;
  121. SD_DAT0_3_INPUT_MASK = PREG_IO_0_3_MASK;
  122. SD_DAT_INPUT_OFFSET = 0;
  123. break;
  124. case SDXC_CARD_0_5: //SDXC-B
  125. SD_CMD_OUTPUT_EN_REG = CARD_GPIO_ENABLE;
  126. SD_CMD_OUTPUT_EN_MASK = PREG_IO_28_MASK;
  127. SD_CMD_OUTPUT_REG = CARD_GPIO_OUTPUT;
  128. SD_CMD_OUTPUT_MASK = PREG_IO_28_MASK;
  129. SD_CMD_INPUT_REG = CARD_GPIO_INPUT;
  130. SD_CMD_INPUT_MASK = PREG_IO_28_MASK;
  131. SD_CLK_OUTPUT_EN_REG = CARD_GPIO_ENABLE;
  132. SD_CLK_OUTPUT_EN_MASK = PREG_IO_27_MASK;
  133. SD_CLK_OUTPUT_REG = CARD_GPIO_OUTPUT;
  134. SD_CLK_OUTPUT_MASK = PREG_IO_27_MASK;
  135. SD_DAT_OUTPUT_EN_REG = CARD_GPIO_ENABLE;
  136. SD_DAT0_OUTPUT_EN_MASK = PREG_IO_23_MASK;
  137. SD_DAT0_3_OUTPUT_EN_MASK = PREG_IO_23_26_MASK;
  138. SD_DAT_OUTPUT_REG = CARD_GPIO_OUTPUT;
  139. SD_DAT0_OUTPUT_MASK = PREG_IO_23_MASK;
  140. SD_DAT0_3_OUTPUT_MASK = PREG_IO_23_26_MASK;
  141. SD_DAT_OUTPUT_OFFSET = 23;
  142. SD_DAT_INPUT_REG = CARD_GPIO_INPUT;
  143. SD_DAT0_INPUT_MASK = PREG_IO_23_MASK;
  144. SD_DAT0_3_INPUT_MASK = PREG_IO_23_26_MASK;
  145. SD_DAT_INPUT_OFFSET = 23;
  146. break;
  147. case SDXC_BOOT_0_11: //SDXC-C
  148. SD_CMD_OUTPUT_EN_REG = BOOT_GPIO_ENABLE;
  149. SD_CMD_OUTPUT_EN_MASK = PREG_IO_10_MASK;
  150. SD_CMD_OUTPUT_REG = BOOT_GPIO_OUTPUT;
  151. SD_CMD_OUTPUT_MASK = PREG_IO_10_MASK;
  152. SD_CMD_INPUT_REG = BOOT_GPIO_INPUT;
  153. SD_CMD_INPUT_MASK = PREG_IO_10_MASK;
  154. SD_CLK_OUTPUT_EN_REG = BOOT_GPIO_ENABLE;
  155. SD_CLK_OUTPUT_EN_MASK = PREG_IO_11_MASK;
  156. SD_CLK_OUTPUT_REG = BOOT_GPIO_OUTPUT;
  157. SD_CLK_OUTPUT_MASK = PREG_IO_11_MASK;
  158. SD_DAT_OUTPUT_EN_REG = BOOT_GPIO_ENABLE;
  159. SD_DAT0_OUTPUT_EN_MASK = PREG_IO_0_MASK;
  160. SD_DAT0_3_OUTPUT_EN_MASK = PREG_IO_0_3_MASK;
  161. SD_DAT_OUTPUT_REG = BOOT_GPIO_OUTPUT;
  162. SD_DAT0_OUTPUT_MASK = PREG_IO_0_MASK;
  163. SD_DAT0_3_OUTPUT_MASK = PREG_IO_0_3_MASK;
  164. SD_DAT_OUTPUT_OFFSET = 0;
  165. SD_DAT_INPUT_REG = BOOT_GPIO_INPUT;
  166. SD_DAT0_INPUT_MASK = PREG_IO_0_MASK;
  167. SD_DAT0_3_INPUT_MASK = PREG_IO_0_3_MASK;
  168. SD_DAT_INPUT_OFFSET = 0;
  169. break;
  170. case SDXC_GPIOX_0_9: //SDXC-A
  171. SD_CMD_OUTPUT_EN_REG = EGPIO_GPIOXL_ENABLE;
  172. SD_CMD_OUTPUT_EN_MASK = PREG_IO_9_MASK;
  173. SD_CMD_OUTPUT_REG = EGPIO_GPIOXL_OUTPUT;
  174. SD_CMD_OUTPUT_MASK = PREG_IO_9_MASK;
  175. SD_CMD_INPUT_REG = EGPIO_GPIOXL_INPUT;
  176. SD_CMD_INPUT_MASK = PREG_IO_9_MASK;
  177. SD_CLK_OUTPUT_EN_REG = EGPIO_GPIOXL_ENABLE;
  178. SD_CLK_OUTPUT_EN_MASK = PREG_IO_8_MASK;
  179. SD_CLK_OUTPUT_REG = EGPIO_GPIOXL_OUTPUT;
  180. SD_CLK_OUTPUT_MASK = PREG_IO_8_MASK;
  181. SD_DAT_OUTPUT_EN_REG = EGPIO_GPIOXL_ENABLE;
  182. SD_DAT0_OUTPUT_EN_MASK = PREG_IO_0_MASK;
  183. SD_DAT0_3_OUTPUT_EN_MASK = PREG_IO_0_3_MASK;
  184. SD_DAT_OUTPUT_REG = EGPIO_GPIOXL_OUTPUT;
  185. SD_DAT0_OUTPUT_MASK = PREG_IO_0_MASK;
  186. SD_DAT0_3_OUTPUT_MASK = PREG_IO_0_3_MASK;
  187. SD_DAT_OUTPUT_OFFSET = 0;
  188. SD_DAT_INPUT_REG = EGPIO_GPIOXL_INPUT;
  189. SD_DAT0_INPUT_MASK = PREG_IO_0_MASK;
  190. SD_DAT0_3_INPUT_MASK = PREG_IO_0_3_MASK;
  191. SD_DAT_INPUT_OFFSET = 0;
  192. break;
  193. default:
  194. printk("Warning couldn`t find any valid hw io pad!!!\n");
  195. break;
  196. }
  197. if (aml_card_info->card_ins_en_reg) {
  198. SD_INS_OUTPUT_EN_REG = aml_card_info->card_ins_en_reg;
  199. SD_INS_OUTPUT_EN_MASK = aml_card_info->card_ins_en_mask;
  200. SD_INS_INPUT_REG = aml_card_info->card_ins_input_reg;
  201. SD_INS_INPUT_MASK = aml_card_info->card_ins_input_mask;
  202. }
  203. else {
  204. SD_INS_OUTPUT_EN_REG = SD_BAKUP_OUTPUT_REG;
  205. SD_INS_OUTPUT_EN_MASK = 1;
  206. SD_INS_INPUT_REG = SD_BAKUP_INPUT_REG;
  207. SD_INS_INPUT_MASK =
  208. SD_WP_INPUT_MASK = 1;
  209. }
  210. if (aml_card_info->card_power_en_reg) {
  211. SD_PWR_OUTPUT_EN_REG = aml_card_info->card_power_en_reg;
  212. SD_PWR_OUTPUT_EN_MASK = aml_card_info->card_power_en_mask;
  213. SD_PWR_OUTPUT_REG = aml_card_info->card_power_output_reg;
  214. SD_PWR_OUTPUT_MASK = aml_card_info->card_power_output_mask;
  215. SD_PWR_EN_LEVEL = aml_card_info->card_power_en_lev;
  216. }
  217. else {
  218. SD_PWR_OUTPUT_EN_REG = SD_BAKUP_OUTPUT_REG;
  219. SD_PWR_OUTPUT_EN_MASK = 1;
  220. SD_PWR_OUTPUT_REG = SD_BAKUP_OUTPUT_REG;
  221. SD_PWR_OUTPUT_MASK = 1;
  222. SD_PWR_EN_LEVEL = 0;
  223. }
  224. if (aml_card_info->card_wp_en_reg) {
  225. SD_WP_OUTPUT_EN_REG = aml_card_info->card_wp_en_reg;
  226. SD_WP_OUTPUT_EN_MASK = aml_card_info->card_wp_en_mask;
  227. SD_WP_INPUT_REG = aml_card_info->card_wp_input_reg;
  228. SD_WP_INPUT_MASK = aml_card_info->card_wp_input_mask;
  229. }
  230. else {
  231. SD_WP_OUTPUT_EN_REG = SD_BAKUP_OUTPUT_REG;
  232. SD_WP_OUTPUT_EN_MASK = 1;
  233. SD_WP_INPUT_REG = SD_BAKUP_INPUT_REG;
  234. SD_WP_INPUT_MASK = 1;
  235. }
  236. return;
  237. }
  238. //do nothing
  239. static void card_pinmux_dummy(int flag)
  240. {
  241. return;
  242. }
  243. static pinmux_item_t SDHC_CARD_0_5_pins[] = {
  244. {
  245. .reg = PINMUX_REG(2),
  246. .setmask = 0x3f << 10,
  247. },
  248. PINMUX_END_ITEM
  249. };
  250. static pinmux_set_t SDHC_CARD_0_5_set = {
  251. .chip_select = card_pinmux_dummy,
  252. .pinmux = &SDHC_CARD_0_5_pins[0]
  253. };
  254. static pinmux_item_t SDHC_BOOT_0_11_pins[] = {
  255. {
  256. .reg = PINMUX_REG(6),
  257. .setmask = 0x3F<<24,
  258. },
  259. PINMUX_END_ITEM
  260. };
  261. static pinmux_set_t SDHC_BOOT_0_11_set = {
  262. .chip_select = card_pinmux_dummy,
  263. .pinmux = &SDHC_BOOT_0_11_pins[0]
  264. };
  265. static pinmux_item_t SDHC_GPIOX_0_9_pins[] = {
  266. {
  267. .reg = PINMUX_REG(8),
  268. .setmask = 0x3f,
  269. },
  270. PINMUX_END_ITEM
  271. };
  272. static pinmux_set_t SDHC_GPIOX_0_9_set = {
  273. .chip_select = card_pinmux_dummy,
  274. .pinmux = &SDHC_GPIOX_0_9_pins[0]
  275. };
  276. static pinmux_item_t SDXC_CARD_0_5_pins[] = {
  277. {
  278. .reg = PINMUX_REG(2),
  279. .setmask = 0xf << 4,
  280. },
  281. PINMUX_END_ITEM
  282. };
  283. static pinmux_set_t SDXC_CARD_0_5_set = {
  284. .chip_select = card_pinmux_dummy,
  285. .pinmux = &SDXC_CARD_0_5_pins[0]
  286. };
  287. static pinmux_item_t SDXC_BOOT_0_11_pins[] = {
  288. {
  289. .reg = PINMUX_REG(4),
  290. .setmask = 0x1f << 26,
  291. },
  292. PINMUX_END_ITEM
  293. };
  294. static pinmux_set_t SDXC_BOOT_0_11_set = {
  295. .chip_select = card_pinmux_dummy,
  296. .pinmux = &SDXC_BOOT_0_11_pins[0]
  297. };
  298. static pinmux_item_t SDXC_GPIOX_0_9_pins[] = {
  299. {
  300. .reg = PINMUX_REG(5),
  301. .setmask = 0x1f << 10,
  302. },
  303. PINMUX_END_ITEM
  304. };
  305. static pinmux_set_t SDXC_GPIOX_0_9_set = {
  306. .chip_select = card_pinmux_dummy,
  307. .pinmux = &SDXC_GPIOX_0_9_pins[0]
  308. };
  309. void sd_sdio_enable(SDIO_Pad_Type_t io_pad_type)
  310. {
  311. switch (io_pad_type) {
  312. case SDHC_CARD_0_5 : //SDHC-B
  313. pinmux_set(&SDHC_CARD_0_5_set);
  314. SET_CBUS_REG_MASK(SDIO_MULT_CONFIG, (1));
  315. break;
  316. case SDHC_BOOT_0_11 : //SDHC-C
  317. pinmux_set(&SDHC_BOOT_0_11_set);
  318. SET_CBUS_REG_MASK(SDIO_MULT_CONFIG, (2));
  319. break;
  320. case SDHC_GPIOX_0_9 : //SDHC-A
  321. pinmux_set(&SDHC_GPIOX_0_9_set);
  322. SET_CBUS_REG_MASK(SDIO_MULT_CONFIG, (0));
  323. break;
  324. case SDXC_CARD_0_5 : //SDXC-B
  325. pinmux_set(&SDXC_CARD_0_5_set);
  326. break;
  327. case SDXC_BOOT_0_11 : //SDXC-C
  328. pinmux_set(&SDXC_BOOT_0_11_set);
  329. break;
  330. case SDXC_GPIOX_0_9 : //SDXC-A
  331. pinmux_set(&SDXC_GPIOX_0_9_set);
  332. break;
  333. default :
  334. printk("invalid hw io pad!!!\n");
  335. break;
  336. }
  337. return;
  338. }
  339. void sd_gpio_enable(SDIO_Pad_Type_t io_pad_type)
  340. {
  341. switch (io_pad_type) {
  342. case SDHC_CARD_0_5 : //SDHC-B
  343. pinmux_clr(&SDHC_CARD_0_5_set);
  344. CLEAR_CBUS_REG_MASK(SDIO_MULT_CONFIG, (1));
  345. break;
  346. case SDHC_BOOT_0_11 : //SDHC-C
  347. pinmux_clr(&SDHC_BOOT_0_11_set);
  348. CLEAR_CBUS_REG_MASK(SDIO_MULT_CONFIG, (2));
  349. break;
  350. case SDHC_GPIOX_0_9 : //SDHC-A
  351. pinmux_clr(&SDHC_GPIOX_0_9_set);
  352. CLEAR_CBUS_REG_MASK(SDIO_MULT_CONFIG, (0));
  353. break;
  354. case SDXC_CARD_0_5 : //SDXC-B
  355. pinmux_clr(&SDXC_CARD_0_5_set);
  356. break;
  357. case SDXC_BOOT_0_11 : //SDXC-C
  358. pinmux_clr(&SDXC_BOOT_0_11_set);
  359. break;
  360. case SDXC_GPIOX_0_9 : //SDXC-A
  361. pinmux_clr(&SDXC_GPIOX_0_9_set);
  362. break;
  363. default :
  364. printk("invalid hw io pad!!!\n");
  365. break;
  366. }
  367. return;
  368. }