msm_sdcc.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. /*
  2. * linux/drivers/mmc/host/msmsdcc.h - QCT MSM7K SDC Controller
  3. *
  4. * Copyright (C) 2008 Google, All Rights Reserved.
  5. * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved.
  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. * - Based on mmci.h
  12. */
  13. #ifndef _MSM_SDCC_H
  14. #define _MSM_SDCC_H
  15. #include <linux/types.h>
  16. #include <linux/ioport.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/mmc/host.h>
  19. #include <linux/mmc/card.h>
  20. #include <linux/mmc/mmc.h>
  21. #include <linux/mmc/sdio.h>
  22. #include <linux/scatterlist.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/wakelock.h>
  25. #include <linux/pm_qos.h>
  26. #include <mach/sps.h>
  27. #include <asm/sizes.h>
  28. #include <asm/mach/mmc.h>
  29. #include <mach/dma.h>
  30. #define MMCIPOWER 0x000
  31. #define MCI_PWR_OFF 0x00
  32. #define MCI_PWR_UP 0x02
  33. #define MCI_PWR_ON 0x03
  34. #define MCI_OD (1 << 6)
  35. #define MCI_SW_RST (1 << 7)
  36. #define MCI_SW_RST_CFG (1 << 8)
  37. #define MMCICLOCK 0x004
  38. #define MCI_CLK_ENABLE (1 << 8)
  39. #define MCI_CLK_PWRSAVE (1 << 9)
  40. #define MCI_CLK_WIDEBUS_1 (0 << 10)
  41. #define MCI_CLK_WIDEBUS_4 (2 << 10)
  42. #define MCI_CLK_WIDEBUS_8 (3 << 10)
  43. #define MCI_CLK_FLOWENA (1 << 12)
  44. #define MCI_CLK_INVERTOUT (1 << 13)
  45. #define MCI_CLK_SELECTIN (1 << 15)
  46. #define IO_PAD_PWR_SWITCH (1 << 21)
  47. #define MMCIARGUMENT 0x008
  48. #define MMCICOMMAND 0x00c
  49. #define MCI_CPSM_RESPONSE (1 << 6)
  50. #define MCI_CPSM_LONGRSP (1 << 7)
  51. #define MCI_CPSM_INTERRUPT (1 << 8)
  52. #define MCI_CPSM_PENDING (1 << 9)
  53. #define MCI_CPSM_ENABLE (1 << 10)
  54. #define MCI_CPSM_PROGENA (1 << 11)
  55. #define MCI_CSPM_DATCMD (1 << 12)
  56. #define MCI_CSPM_MCIABORT (1 << 13)
  57. #define MCI_CSPM_CCSENABLE (1 << 14)
  58. #define MCI_CSPM_CCSDISABLE (1 << 15)
  59. #define MCI_CSPM_AUTO_CMD19 (1 << 16)
  60. #define MCI_CSPM_AUTO_CMD21 (1 << 21)
  61. #define MMCIRESPCMD 0x010
  62. #define MMCIRESPONSE0 0x014
  63. #define MMCIRESPONSE1 0x018
  64. #define MMCIRESPONSE2 0x01c
  65. #define MMCIRESPONSE3 0x020
  66. #define MMCIDATATIMER 0x024
  67. #define MMCIDATALENGTH 0x028
  68. #define MMCIDATACTRL 0x02c
  69. #define MCI_DPSM_ENABLE (1 << 0)
  70. #define MCI_DPSM_DIRECTION (1 << 1)
  71. #define MCI_DPSM_MODE (1 << 2)
  72. #define MCI_DPSM_DMAENABLE (1 << 3)
  73. #define MCI_DATA_PEND (1 << 17)
  74. #define MCI_AUTO_PROG_DONE (1 << 19)
  75. #define MCI_RX_DATA_PEND (1 << 20)
  76. #define MMCIDATACNT 0x030
  77. #define MMCISTATUS 0x034
  78. #define MCI_CMDCRCFAIL (1 << 0)
  79. #define MCI_DATACRCFAIL (1 << 1)
  80. #define MCI_CMDTIMEOUT (1 << 2)
  81. #define MCI_DATATIMEOUT (1 << 3)
  82. #define MCI_TXUNDERRUN (1 << 4)
  83. #define MCI_RXOVERRUN (1 << 5)
  84. #define MCI_CMDRESPEND (1 << 6)
  85. #define MCI_CMDSENT (1 << 7)
  86. #define MCI_DATAEND (1 << 8)
  87. #define MCI_DATABLOCKEND (1 << 10)
  88. #define MCI_CMDACTIVE (1 << 11)
  89. #define MCI_TXACTIVE (1 << 12)
  90. #define MCI_RXACTIVE (1 << 13)
  91. #define MCI_TXFIFOHALFEMPTY (1 << 14)
  92. #define MCI_RXFIFOHALFFULL (1 << 15)
  93. #define MCI_TXFIFOFULL (1 << 16)
  94. #define MCI_RXFIFOFULL (1 << 17)
  95. #define MCI_TXFIFOEMPTY (1 << 18)
  96. #define MCI_RXFIFOEMPTY (1 << 19)
  97. #define MCI_TXDATAAVLBL (1 << 20)
  98. #define MCI_RXDATAAVLBL (1 << 21)
  99. #define MCI_SDIOINTR (1 << 22)
  100. #define MCI_PROGDONE (1 << 23)
  101. #define MCI_ATACMDCOMPL (1 << 24)
  102. #define MCI_SDIOINTROPE (1 << 25)
  103. #define MCI_CCSTIMEOUT (1 << 26)
  104. #define MCI_AUTOCMD19TIMEOUT (1 << 30)
  105. #define MMCICLEAR 0x038
  106. #define MCI_CMDCRCFAILCLR (1 << 0)
  107. #define MCI_DATACRCFAILCLR (1 << 1)
  108. #define MCI_CMDTIMEOUTCLR (1 << 2)
  109. #define MCI_DATATIMEOUTCLR (1 << 3)
  110. #define MCI_TXUNDERRUNCLR (1 << 4)
  111. #define MCI_RXOVERRUNCLR (1 << 5)
  112. #define MCI_CMDRESPENDCLR (1 << 6)
  113. #define MCI_CMDSENTCLR (1 << 7)
  114. #define MCI_DATAENDCLR (1 << 8)
  115. #define MCI_STARTBITERRCLR (1 << 9)
  116. #define MCI_DATABLOCKENDCLR (1 << 10)
  117. #define MCI_SDIOINTRCLR (1 << 22)
  118. #define MCI_PROGDONECLR (1 << 23)
  119. #define MCI_ATACMDCOMPLCLR (1 << 24)
  120. #define MCI_SDIOINTROPECLR (1 << 25)
  121. #define MCI_CCSTIMEOUTCLR (1 << 26)
  122. #define MCI_CLEAR_STATIC_MASK \
  123. (MCI_CMDCRCFAILCLR|MCI_DATACRCFAILCLR|MCI_CMDTIMEOUTCLR|\
  124. MCI_DATATIMEOUTCLR|MCI_TXUNDERRUNCLR|MCI_RXOVERRUNCLR| \
  125. MCI_CMDRESPENDCLR|MCI_CMDSENTCLR|MCI_DATAENDCLR| \
  126. MCI_STARTBITERRCLR|MCI_DATABLOCKENDCLR|MCI_SDIOINTRCLR| \
  127. MCI_SDIOINTROPECLR|MCI_PROGDONECLR|MCI_ATACMDCOMPLCLR| \
  128. MCI_CCSTIMEOUTCLR)
  129. #define MMCIMASK0 0x03c
  130. #define MCI_CMDCRCFAILMASK (1 << 0)
  131. #define MCI_DATACRCFAILMASK (1 << 1)
  132. #define MCI_CMDTIMEOUTMASK (1 << 2)
  133. #define MCI_DATATIMEOUTMASK (1 << 3)
  134. #define MCI_TXUNDERRUNMASK (1 << 4)
  135. #define MCI_RXOVERRUNMASK (1 << 5)
  136. #define MCI_CMDRESPENDMASK (1 << 6)
  137. #define MCI_CMDSENTMASK (1 << 7)
  138. #define MCI_DATAENDMASK (1 << 8)
  139. #define MCI_DATABLOCKENDMASK (1 << 10)
  140. #define MCI_CMDACTIVEMASK (1 << 11)
  141. #define MCI_TXACTIVEMASK (1 << 12)
  142. #define MCI_RXACTIVEMASK (1 << 13)
  143. #define MCI_TXFIFOHALFEMPTYMASK (1 << 14)
  144. #define MCI_RXFIFOHALFFULLMASK (1 << 15)
  145. #define MCI_TXFIFOFULLMASK (1 << 16)
  146. #define MCI_RXFIFOFULLMASK (1 << 17)
  147. #define MCI_TXFIFOEMPTYMASK (1 << 18)
  148. #define MCI_RXFIFOEMPTYMASK (1 << 19)
  149. #define MCI_TXDATAAVLBLMASK (1 << 20)
  150. #define MCI_RXDATAAVLBLMASK (1 << 21)
  151. #define MCI_SDIOINTMASK (1 << 22)
  152. #define MCI_PROGDONEMASK (1 << 23)
  153. #define MCI_ATACMDCOMPLMASK (1 << 24)
  154. #define MCI_SDIOINTOPERMASK (1 << 25)
  155. #define MCI_CCSTIMEOUTMASK (1 << 26)
  156. #define MCI_AUTOCMD19TIMEOUTMASK (1 << 30)
  157. #define MMCIMASK1 0x040
  158. #define MMCIFIFOCNT 0x044
  159. #define MCI_VERSION 0x050
  160. #define MCICCSTIMER 0x058
  161. #define MCI_DLL_CONFIG 0x060
  162. #define MCI_DLL_EN (1 << 16)
  163. #define MCI_CDR_EN (1 << 17)
  164. #define MCI_CK_OUT_EN (1 << 18)
  165. #define MCI_CDR_EXT_EN (1 << 19)
  166. #define MCI_DLL_PDN (1 << 29)
  167. #define MCI_DLL_RST (1 << 30)
  168. #define MCI_DLL_STATUS 0x068
  169. #define MCI_DLL_LOCK (1 << 7)
  170. #define MCI_STATUS2 0x06C
  171. #define MCI_MCLK_REG_WR_ACTIVE (1 << 0)
  172. #define MMCIFIFO 0x080 /* to 0x0bc */
  173. #define MCI_TEST_INPUT 0x0D4
  174. #define MCI_TESTBUS_CONFIG 0x0CC
  175. #define MCI_TESTBUS_SEL_MASK (0x7)
  176. #define MAX_TESTBUS 8
  177. #define MCI_TESTBUS_ENA (1 << 3)
  178. #define MCI_CORE_HC_MODE 0x78
  179. #define MCI_SDCC_DEBUG_REG 0x124
  180. #define MCI_IRQENABLE \
  181. (MCI_CMDCRCFAILMASK|MCI_DATACRCFAILMASK|MCI_CMDTIMEOUTMASK| \
  182. MCI_DATATIMEOUTMASK|MCI_TXUNDERRUNMASK|MCI_RXOVERRUNMASK| \
  183. MCI_CMDRESPENDMASK|MCI_CMDSENTMASK|MCI_DATAENDMASK| \
  184. MCI_PROGDONEMASK|MCI_AUTOCMD19TIMEOUTMASK)
  185. #define MCI_IRQ_PIO \
  186. (MCI_RXDATAAVLBLMASK | MCI_TXDATAAVLBLMASK | \
  187. MCI_RXFIFOEMPTYMASK | MCI_TXFIFOEMPTYMASK | MCI_RXFIFOFULLMASK |\
  188. MCI_TXFIFOFULLMASK | MCI_RXFIFOHALFFULLMASK | \
  189. MCI_TXFIFOHALFEMPTYMASK | MCI_RXACTIVEMASK | MCI_TXACTIVEMASK)
  190. /*
  191. * The size of the FIFO in bytes.
  192. */
  193. #define MCI_FIFOSIZE (16*4)
  194. #define MCI_FIFOHALFSIZE (MCI_FIFOSIZE / 2)
  195. #define NR_SG 128
  196. #define MSM_MMC_DEFAULT_IDLE_TIMEOUT 5000 /* msecs */
  197. #define MSM_MMC_CLK_GATE_DELAY 200 /* msecs */
  198. /* Set the request timeout to 10secs */
  199. #define MSM_MMC_REQ_TIMEOUT 10000 /* msecs */
  200. /*
  201. * Controller HW limitations
  202. */
  203. #define MCI_DATALENGTH_BITS 25
  204. #define MMC_MAX_REQ_SIZE ((1 << MCI_DATALENGTH_BITS) - 1)
  205. /* MCI_DATA_CTL BLOCKSIZE up to 4096 */
  206. #define MMC_MAX_BLK_SIZE 4096
  207. #define MMC_MIN_BLK_SIZE 512
  208. #define MMC_MAX_BLK_CNT (MMC_MAX_REQ_SIZE / MMC_MIN_BLK_SIZE)
  209. /* 64KiB */
  210. #define MAX_SG_SIZE (64 * 1024)
  211. #define MAX_NR_SG_DMA_PIO (MMC_MAX_REQ_SIZE / MAX_SG_SIZE)
  212. /*
  213. * BAM limitations
  214. */
  215. /* upto 16 bits (64K - 1) */
  216. #define SPS_MAX_DESC_FIFO_SIZE 65535
  217. /* 16KiB */
  218. #define SPS_MAX_DESC_SIZE (16 * 1024)
  219. /* Each descriptor is of length 8 bytes */
  220. #define SPS_MAX_DESC_LENGTH 8
  221. #define SPS_MAX_DESCS (SPS_MAX_DESC_FIFO_SIZE / SPS_MAX_DESC_LENGTH)
  222. /*
  223. * DMA limitations
  224. */
  225. /* upto 16 bits (64K - 1) */
  226. #define MMC_MAX_DMA_ROWS (64 * 1024 - 1)
  227. #define MMC_MAX_DMA_BOX_LENGTH (MMC_MAX_DMA_ROWS * MCI_FIFOSIZE)
  228. #define MMC_MAX_DMA_CMDS (MAX_NR_SG_DMA_PIO * (MMC_MAX_REQ_SIZE / \
  229. MMC_MAX_DMA_BOX_LENGTH))
  230. /*
  231. * Peripheral bus clock scaling vote rates
  232. */
  233. #define MSMSDCC_BUS_VOTE_MAX_RATE 64000000 /* Hz */
  234. #define MSMSDCC_BUS_VOTE_MIN_RATE 32000000 /* Hz */
  235. struct clk;
  236. struct msmsdcc_nc_dmadata {
  237. dmov_box cmd[MMC_MAX_DMA_CMDS];
  238. uint32_t cmdptr;
  239. };
  240. struct msmsdcc_dma_data {
  241. struct msmsdcc_nc_dmadata *nc;
  242. dma_addr_t nc_busaddr;
  243. dma_addr_t cmd_busaddr;
  244. dma_addr_t cmdptr_busaddr;
  245. struct msm_dmov_cmd hdr;
  246. enum dma_data_direction dir;
  247. struct scatterlist *sg;
  248. int num_ents;
  249. int channel;
  250. int crci;
  251. struct msmsdcc_host *host;
  252. int busy; /* Set if DM is busy */
  253. unsigned int result;
  254. struct msm_dmov_errdata err;
  255. };
  256. struct msmsdcc_pio_data {
  257. struct sg_mapping_iter sg_miter;
  258. char bounce_buf[4];
  259. /* valid bytes in bounce_buf */
  260. int bounce_buf_len;
  261. };
  262. struct msmsdcc_curr_req {
  263. struct mmc_request *mrq;
  264. struct mmc_command *cmd;
  265. struct mmc_data *data;
  266. unsigned int xfer_size; /* Total data size */
  267. unsigned int xfer_remain; /* Bytes remaining to send */
  268. unsigned int data_xfered; /* Bytes acked by BLKEND irq */
  269. int got_dataend;
  270. bool wait_for_auto_prog_done;
  271. bool got_auto_prog_done;
  272. bool use_wr_data_pend;
  273. int user_pages;
  274. u32 req_tout_ms;
  275. };
  276. struct msmsdcc_sps_ep_conn_data {
  277. struct sps_pipe *pipe_handle;
  278. struct sps_connect config;
  279. struct sps_register_event event;
  280. };
  281. struct msmsdcc_sps_data {
  282. struct msmsdcc_sps_ep_conn_data prod;
  283. struct msmsdcc_sps_ep_conn_data cons;
  284. struct sps_event_notify notify;
  285. enum dma_data_direction dir;
  286. struct scatterlist *sg;
  287. int num_ents;
  288. u32 bam_handle;
  289. unsigned int src_pipe_index;
  290. unsigned int dest_pipe_index;
  291. unsigned int busy;
  292. unsigned int xfer_req_cnt;
  293. bool reset_bam;
  294. struct tasklet_struct tlet;
  295. };
  296. struct msmsdcc_msm_bus_vote {
  297. uint32_t client_handle;
  298. uint32_t curr_vote;
  299. int min_bw_vote;
  300. int max_bw_vote;
  301. bool is_max_bw_needed;
  302. struct delayed_work vote_work;
  303. };
  304. struct msmsdcc_host {
  305. struct resource *core_irqres;
  306. struct resource *bam_irqres;
  307. struct resource *core_memres;
  308. struct resource *bam_memres;
  309. struct resource *dml_memres;
  310. struct resource *dmares;
  311. struct resource *dma_crci_res;
  312. void __iomem *base;
  313. void __iomem *dml_base;
  314. void __iomem *bam_base;
  315. struct platform_device *pdev;
  316. struct msmsdcc_curr_req curr;
  317. struct mmc_host *mmc;
  318. struct clk *clk; /* main MMC bus clock */
  319. struct clk *pclk; /* SDCC peripheral bus clock */
  320. struct clk *bus_clk; /* SDCC bus voter clock */
  321. unsigned long bus_clk_rate; /* peripheral bus clk rate */
  322. atomic_t clks_on; /* set if clocks are enabled */
  323. unsigned int eject; /* eject state */
  324. spinlock_t lock;
  325. unsigned int clk_rate; /* Current clock rate */
  326. unsigned int pclk_rate;
  327. u32 pwr;
  328. struct mmc_platform_data *plat;
  329. unsigned int hw_caps;
  330. unsigned int oldstat;
  331. struct msmsdcc_dma_data dma;
  332. struct msmsdcc_sps_data sps;
  333. struct msmsdcc_pio_data pio;
  334. struct tasklet_struct dma_tlet;
  335. unsigned int prog_enable;
  336. /* Command parameters */
  337. unsigned int cmd_timeout;
  338. unsigned int cmd_pio_irqmask;
  339. unsigned int cmd_datactrl;
  340. struct mmc_command *cmd_cmd;
  341. u32 cmd_c;
  342. unsigned int mci_irqenable;
  343. unsigned int dummy_52_needed;
  344. unsigned int dummy_52_sent;
  345. struct wake_lock sdio_wlock;
  346. struct wake_lock sdio_suspend_wlock;
  347. struct timer_list req_tout_timer;
  348. unsigned long reg_write_delay;
  349. bool io_pad_pwr_switch;
  350. bool tuning_in_progress;
  351. bool tuning_needed;
  352. bool tuning_done;
  353. bool en_auto_cmd19;
  354. bool en_auto_cmd21;
  355. bool sdio_gpio_lpm;
  356. bool irq_wake_enabled;
  357. struct pm_qos_request pm_qos_req_dma;
  358. u32 cpu_dma_latency;
  359. bool sdcc_suspending;
  360. bool sdcc_irq_disabled;
  361. bool sdcc_suspended;
  362. bool sdio_wakeupirq_disabled;
  363. struct mutex clk_mutex;
  364. bool pending_resume;
  365. unsigned int idle_tout; /* Timeout in msecs */
  366. bool enforce_pio_mode;
  367. bool print_pm_stats;
  368. struct msmsdcc_msm_bus_vote msm_bus_vote;
  369. struct device_attribute max_bus_bw;
  370. struct device_attribute polling;
  371. struct device_attribute idle_timeout;
  372. struct device_attribute auto_cmd19_attr;
  373. struct device_attribute auto_cmd21_attr;
  374. struct dentry *debugfs_host_dir;
  375. struct dentry *debugfs_idle_tout;
  376. struct dentry *debugfs_pio_mode;
  377. struct dentry *debugfs_pm_stats;
  378. int saved_tuning_phase;
  379. };
  380. #define MSMSDCC_VERSION_STEP_MASK 0x0000FFFF
  381. #define MSMSDCC_VERSION_MINOR_MASK 0x0FFF0000
  382. #define MSMSDCC_VERSION_MINOR_SHIFT 16
  383. #define MSMSDCC_VERSION_MAJOR_MASK 0xF0000000
  384. #define MSMSDCC_VERSION_MAJOR_SHIFT 28
  385. #define MSMSDCC_DMA_SUP (1 << 0)
  386. #define MSMSDCC_SPS_BAM_SUP (1 << 1)
  387. #define MSMSDCC_SOFT_RESET (1 << 2)
  388. #define MSMSDCC_AUTO_PROG_DONE (1 << 3)
  389. #define MSMSDCC_REG_WR_ACTIVE (1 << 4)
  390. #define MSMSDCC_SW_RST (1 << 5)
  391. #define MSMSDCC_SW_RST_CFG (1 << 6)
  392. #define MSMSDCC_WAIT_FOR_TX_RX (1 << 7)
  393. #define MSMSDCC_IO_PAD_PWR_SWITCH (1 << 8)
  394. #define MSMSDCC_AUTO_CMD19 (1 << 9)
  395. #define MSMSDCC_AUTO_CMD21 (1 << 10)
  396. #define MSMSDCC_SW_RST_CFG_BROKEN (1 << 11)
  397. #define MSMSDCC_DATA_PEND_FOR_CMD53 (1 << 12)
  398. #define MSMSDCC_TESTBUS_DEBUG (1 << 13)
  399. #define MSMSDCC_SDHCI_MODE_SUPPORTED (1 << 14)
  400. #define set_hw_caps(h, val) ((h)->hw_caps |= val)
  401. #define is_sps_mode(h) ((h)->hw_caps & MSMSDCC_SPS_BAM_SUP)
  402. #define is_dma_mode(h) ((h)->hw_caps & MSMSDCC_DMA_SUP)
  403. #define is_soft_reset(h) ((h)->hw_caps & MSMSDCC_SOFT_RESET)
  404. #define is_auto_prog_done(h) ((h)->hw_caps & MSMSDCC_AUTO_PROG_DONE)
  405. #define is_wait_for_reg_write(h) ((h)->hw_caps & MSMSDCC_REG_WR_ACTIVE)
  406. #define is_sw_hard_reset(h) ((h)->hw_caps & MSMSDCC_SW_RST)
  407. #define is_sw_reset_save_config(h) ((h)->hw_caps & MSMSDCC_SW_RST_CFG)
  408. #define is_wait_for_tx_rx_active(h) ((h)->hw_caps & MSMSDCC_WAIT_FOR_TX_RX)
  409. #define is_io_pad_pwr_switch(h) ((h)->hw_caps & MSMSDCC_IO_PAD_PWR_SWITCH)
  410. #define is_auto_cmd19(h) ((h)->hw_caps & MSMSDCC_AUTO_CMD19)
  411. #define is_auto_cmd21(h) ((h)->hw_caps & MSMSDCC_AUTO_CMD21)
  412. #define is_sw_reset_save_config_broken(h) \
  413. ((h)->hw_caps & MSMSDCC_SW_RST_CFG_BROKEN)
  414. #define is_data_pend_for_cmd53(h) ((h)->hw_caps & MSMSDCC_DATA_PEND_FOR_CMD53)
  415. #define is_testbus_debug(h) ((h)->hw_caps & MSMSDCC_TESTBUS_DEBUG)
  416. #define is_sdhci_supported(h) ((h)->hw_caps & MSMSDCC_SDHCI_MODE_SUPPORTED)
  417. /* Set controller capabilities based on version */
  418. static inline void set_default_hw_caps(struct msmsdcc_host *host)
  419. {
  420. u32 version;
  421. u16 step, minor;
  422. /*
  423. * Lookup the Controller Version, to identify the supported features
  424. * Version number read as 0 would indicate SDCC3 or earlier versions.
  425. */
  426. version = readl_relaxed(host->base + MCI_VERSION);
  427. pr_info("%s: SDCC Version: 0x%.8x\n", mmc_hostname(host->mmc), version);
  428. if (!version)
  429. return;
  430. step = version & MSMSDCC_VERSION_STEP_MASK;
  431. minor = (version & MSMSDCC_VERSION_MINOR_MASK) >>
  432. MSMSDCC_VERSION_MINOR_SHIFT;
  433. if (version) /* SDCC v4 and greater */
  434. host->hw_caps |= MSMSDCC_AUTO_PROG_DONE |
  435. MSMSDCC_SOFT_RESET | MSMSDCC_REG_WR_ACTIVE
  436. | MSMSDCC_WAIT_FOR_TX_RX | MSMSDCC_IO_PAD_PWR_SWITCH
  437. | MSMSDCC_AUTO_CMD19;
  438. if ((step == 0x18) && (minor >= 3)) {
  439. host->hw_caps |= MSMSDCC_AUTO_CMD21;
  440. /* Version 0x06000018 need hard reset on errors */
  441. host->hw_caps &= ~MSMSDCC_SOFT_RESET;
  442. }
  443. if (step >= 0x2b) /* SDCC v4 2.1.0 and greater */
  444. host->hw_caps |= MSMSDCC_SW_RST | MSMSDCC_SW_RST_CFG |
  445. MSMSDCC_AUTO_CMD21 |
  446. MSMSDCC_DATA_PEND_FOR_CMD53 |
  447. MSMSDCC_TESTBUS_DEBUG |
  448. MSMSDCC_SW_RST_CFG_BROKEN |
  449. MSMSDCC_SDHCI_MODE_SUPPORTED;
  450. }
  451. int msmsdcc_set_pwrsave(struct mmc_host *mmc, int pwrsave);
  452. int msmsdcc_sdio_al_lpm(struct mmc_host *mmc, bool enable);
  453. #ifdef CONFIG_MSM_SDIO_AL
  454. static inline int msmsdcc_lpm_enable(struct mmc_host *mmc)
  455. {
  456. return msmsdcc_sdio_al_lpm(mmc, true);
  457. }
  458. static inline int msmsdcc_lpm_disable(struct mmc_host *mmc)
  459. {
  460. struct msmsdcc_host *host = mmc_priv(mmc);
  461. int ret;
  462. ret = msmsdcc_sdio_al_lpm(mmc, false);
  463. wake_unlock(&host->sdio_wlock);
  464. return ret;
  465. }
  466. #endif
  467. #endif