Lines Matching refs:hsmci
19 LOG_MODULE_REGISTER(hsmci, CONFIG_SDHC_LOG_LEVEL);
81 Hsmci *hsmci = config->base; in sam_hsmci_reset() local
83 uint32_t mr = hsmci->HSMCI_MR; in sam_hsmci_reset()
84 uint32_t dtor = hsmci->HSMCI_DTOR; in sam_hsmci_reset()
85 uint32_t sdcr = hsmci->HSMCI_SDCR; in sam_hsmci_reset()
86 uint32_t cstor = hsmci->HSMCI_CSTOR; in sam_hsmci_reset()
87 uint32_t cfg = hsmci->HSMCI_CFG; in sam_hsmci_reset()
89 hsmci->HSMCI_CR = HSMCI_CR_SWRST; in sam_hsmci_reset()
90 hsmci->HSMCI_MR = mr; in sam_hsmci_reset()
91 hsmci->HSMCI_DTOR = dtor; in sam_hsmci_reset()
92 hsmci->HSMCI_SDCR = sdcr; in sam_hsmci_reset()
93 hsmci->HSMCI_CSTOR = cstor; in sam_hsmci_reset()
94 hsmci->HSMCI_CFG = cfg; in sam_hsmci_reset()
96 hsmci->HSMCI_CR = HSMCI_CR_PWSEN | HSMCI_CR_MCIEN; in sam_hsmci_reset()
119 Hsmci *hsmci = config->base; in sam_hsmci_set_io() local
153 hsmci->HSMCI_MR &= ~HSMCI_MR_CLKDIV_Msk; in sam_hsmci_set_io()
154 hsmci->HSMCI_MR |= in sam_hsmci_set_io()
159 hsmci->HSMCI_SDCR &= ~HSMCI_SDCR_SDCBUS_Msk; in sam_hsmci_set_io()
163 hsmci->HSMCI_SDCR = HSMCI_SDCR_SDCBUS_1; in sam_hsmci_set_io()
166 hsmci->HSMCI_SDCR = HSMCI_SDCR_SDCBUS_4; in sam_hsmci_set_io()
178 hsmci->HSMCI_CFG &= ~HSMCI_CFG_HSMODE; in sam_hsmci_set_io()
181 hsmci->HSMCI_CFG |= HSMCI_CFG_HSMODE; in sam_hsmci_set_io()
218 Hsmci *hsmci = config->base; in sam_hsmci_init() local
221 hsmci->HSMCI_CR = HSMCI_CR_SWRST; in sam_hsmci_init()
222 hsmci->HSMCI_CR = HSMCI_CR_PWSDIS; in sam_hsmci_init()
223 hsmci->HSMCI_CR = HSMCI_CR_MCIEN; in sam_hsmci_init()
225 hsmci->HSMCI_MR = in sam_hsmci_init()
227 hsmci->HSMCI_CR = HSMCI_CR_PWSEN; in sam_hsmci_init()
229 hsmci->HSMCI_MR = HSMCI_MR_RDPROOF | HSMCI_MR_WRPROOF; in sam_hsmci_init()
249 Hsmci *hsmci = config->base; in sam_hsmci_card_busy() local
251 return (hsmci->HSMCI_SR & HSMCI_SR_NOTBUSY) == 0; in sam_hsmci_card_busy()
254 static void sam_hsmci_send_clocks(Hsmci *hsmci) in sam_hsmci_send_clocks() argument
256 hsmci->HSMCI_MR &= ~(HSMCI_MR_WRPROOF | HSMCI_MR_RDPROOF | HSMCI_MR_FBYTE); in sam_hsmci_send_clocks()
257 hsmci->HSMCI_ARGR = 0; in sam_hsmci_send_clocks()
258 hsmci->HSMCI_CMDR = in sam_hsmci_send_clocks()
260 while (!(hsmci->HSMCI_SR & HSMCI_SR_CMDRDY)) { in sam_hsmci_send_clocks()
263 hsmci->HSMCI_MR |= HSMCI_MR_WRPROOF | HSMCI_MR_RDPROOF; in sam_hsmci_send_clocks()
266 static int sam_hsmci_send_cmd(Hsmci *hsmci, struct sdhc_command *cmd, uint32_t cmdr, in sam_hsmci_send_cmd() argument
271 hsmci->HSMCI_ARGR = cmd->arg; in sam_hsmci_send_cmd()
285 hsmci->HSMCI_CMDR = cmdr; in sam_hsmci_send_cmd()
287 sr = hsmci->HSMCI_SR; in sam_hsmci_send_cmd()
302 sr = hsmci->HSMCI_SR; in sam_hsmci_send_cmd()
307 cmd->response[3] = hsmci->HSMCI_RSPR[0]; in sam_hsmci_send_cmd()
308 cmd->response[2] = hsmci->HSMCI_RSPR[0]; in sam_hsmci_send_cmd()
309 cmd->response[1] = hsmci->HSMCI_RSPR[0]; in sam_hsmci_send_cmd()
310 cmd->response[0] = hsmci->HSMCI_RSPR[0]; in sam_hsmci_send_cmd()
314 static int sam_hsmci_wait_write_end(Hsmci *hsmci) in sam_hsmci_wait_write_end() argument
321 sr = hsmci->HSMCI_SR; in sam_hsmci_wait_write_end()
330 sr = hsmci->HSMCI_SR; in sam_hsmci_wait_write_end()
337 if (!(hsmci->HSMCI_SR & HSMCI_SR_FIFOEMPTY)) { in sam_hsmci_wait_write_end()
343 static int sam_hsmci_wait_read_end(Hsmci *hsmci) in sam_hsmci_wait_read_end() argument
349 sr = hsmci->HSMCI_SR; in sam_hsmci_wait_read_end()
359 sr = hsmci->HSMCI_SR; in sam_hsmci_wait_read_end()
367 static int sam_hsmci_write_timeout(Hsmci *hsmci, int timeout_ms) in sam_hsmci_write_timeout() argument
377 hsmci->HSMCI_DTOR = ((i << HSMCI_DTOR_DTOMUL_Pos) & HSMCI_DTOR_DTOMUL_Msk) | in sam_hsmci_write_timeout()
386 hsmci->HSMCI_DTOR = HSMCI_DTOR_DTOMUL_Msk | HSMCI_DTOR_DTOCYC_Msk; in sam_hsmci_write_timeout()
390 static inline int wait_write_transfer_done(Hsmci *hsmci) in wait_write_transfer_done() argument
395 sr = hsmci->HSMCI_SR; in wait_write_transfer_done()
403 static inline int wait_read_transfer_done(Hsmci *hsmci) in wait_read_transfer_done() argument
418 static int hsmci_do_manual_transfer(Hsmci *hsmci, bool byte_mode, bool is_write, void *data, in hsmci_do_manual_transfer() argument
428 ret = wait_write_transfer_done(hsmci); in hsmci_do_manual_transfer()
432 hsmci->HSMCI_TDR = *ptr; in hsmci_do_manual_transfer()
439 ret = wait_write_transfer_done(hsmci); in hsmci_do_manual_transfer()
443 hsmci->HSMCI_TDR = *ptr; in hsmci_do_manual_transfer()
447 ret = sam_hsmci_wait_write_end(hsmci); in hsmci_do_manual_transfer()
453 ret = wait_read_transfer_done(hsmci); in hsmci_do_manual_transfer()
457 *ptr = hsmci->HSMCI_RDR; in hsmci_do_manual_transfer()
464 ret = wait_read_transfer_done(hsmci); in hsmci_do_manual_transfer()
468 *ptr = hsmci->HSMCI_RDR; in hsmci_do_manual_transfer()
472 ret = sam_hsmci_wait_read_end(hsmci); in hsmci_do_manual_transfer()
484 Hsmci *hsmci = config->base; in sam_hsmci_request_inner() local
497 sam_hsmci_send_clocks(hsmci); in sam_hsmci_request_inner()
503 ret = sam_hsmci_write_timeout(hsmci, cmd->timeout_ms); in sam_hsmci_request_inner()
540 hsmci->HSMCI_MR &= ~HSMCI_MR_FBYTE; in sam_hsmci_request_inner()
544 hsmci->HSMCI_MR |= HSMCI_MR_FBYTE; in sam_hsmci_request_inner()
548 hsmci->HSMCI_BLKR = in sam_hsmci_request_inner()
554 hsmci->HSMCI_MR |= HSMCI_MR_PDCMODE; in sam_hsmci_request_inner()
556 hsmci->HSMCI_RNCR = 0; in sam_hsmci_request_inner()
559 hsmci->HSMCI_TCR = transfer_count; in sam_hsmci_request_inner()
560 hsmci->HSMCI_TPR = (uint32_t)sd_data->data; in sam_hsmci_request_inner()
562 hsmci->HSMCI_RCR = transfer_count; in sam_hsmci_request_inner()
563 hsmci->HSMCI_RPR = (uint32_t)sd_data->data; in sam_hsmci_request_inner()
564 hsmci->HSMCI_PTCR = HSMCI_PTCR_RXTEN; in sam_hsmci_request_inner()
568 hsmci->HSMCI_MR &= ~HSMCI_MR_PDCMODE; in sam_hsmci_request_inner()
572 ret = sam_hsmci_send_cmd(hsmci, cmd, cmdr, data); in sam_hsmci_request_inner()
578 hsmci->HSMCI_PTCR = HSMCI_PTCR_TXTEN; in sam_hsmci_request_inner()
579 ret = sam_hsmci_wait_write_end(hsmci); in sam_hsmci_request_inner()
581 ret = sam_hsmci_wait_read_end(hsmci); in sam_hsmci_request_inner()
584 hsmci->HSMCI_PTCR = HSMCI_PTCR_TXTDIS | HSMCI_PTCR_RXTDIS; in sam_hsmci_request_inner()
585 hsmci->HSMCI_MR &= ~HSMCI_MR_PDCMODE; in sam_hsmci_request_inner()
588 ret = hsmci_do_manual_transfer(hsmci, byte_mode, is_write, sd_data->data, in sam_hsmci_request_inner()
594 sr = hsmci->HSMCI_SR; in sam_hsmci_request_inner()
606 Hsmci *hsmci = config->base; in sam_hsmci_abort() local
608 hsmci->HSMCI_PTCR = HSMCI_PTCR_RXTDIS | HSMCI_PTCR_TXTDIS; in sam_hsmci_abort()
631 Hsmci *hsmci = config->base; in sam_hsmci_request() local
633 hsmci->HSMCI_CR = HSMCI_CR_PWSDIS; in sam_hsmci_request()
655 hsmci->HSMCI_CR = HSMCI_CR_PWSEN; in sam_hsmci_request()