Lines Matching refs:pcr

71 static inline void rtsx_pci_enable_aspm(struct rtsx_pcr *pcr)  in rtsx_pci_enable_aspm()  argument
73 rtsx_pci_update_cfg_byte(pcr, pcr->pcie_cap + PCI_EXP_LNKCTL, in rtsx_pci_enable_aspm()
74 0xFC, pcr->aspm_en); in rtsx_pci_enable_aspm()
77 static inline void rtsx_pci_disable_aspm(struct rtsx_pcr *pcr) in rtsx_pci_disable_aspm() argument
79 rtsx_pci_update_cfg_byte(pcr, pcr->pcie_cap + PCI_EXP_LNKCTL, in rtsx_pci_disable_aspm()
83 static int rtsx_comm_set_ltr_latency(struct rtsx_pcr *pcr, u32 latency) in rtsx_comm_set_ltr_latency() argument
85 rtsx_pci_write_register(pcr, MSGTXDATA0, in rtsx_comm_set_ltr_latency()
87 rtsx_pci_write_register(pcr, MSGTXDATA1, in rtsx_comm_set_ltr_latency()
89 rtsx_pci_write_register(pcr, MSGTXDATA2, in rtsx_comm_set_ltr_latency()
91 rtsx_pci_write_register(pcr, MSGTXDATA3, in rtsx_comm_set_ltr_latency()
93 rtsx_pci_write_register(pcr, LTR_CTL, LTR_TX_EN_MASK | in rtsx_comm_set_ltr_latency()
99 int rtsx_set_ltr_latency(struct rtsx_pcr *pcr, u32 latency) in rtsx_set_ltr_latency() argument
101 if (pcr->ops->set_ltr_latency) in rtsx_set_ltr_latency()
102 return pcr->ops->set_ltr_latency(pcr, latency); in rtsx_set_ltr_latency()
104 return rtsx_comm_set_ltr_latency(pcr, latency); in rtsx_set_ltr_latency()
107 static void rtsx_comm_set_aspm(struct rtsx_pcr *pcr, bool enable) in rtsx_comm_set_aspm() argument
109 struct rtsx_cr_option *option = &pcr->option; in rtsx_comm_set_aspm()
111 if (pcr->aspm_enabled == enable) in rtsx_comm_set_aspm()
116 rtsx_pci_enable_aspm(pcr); in rtsx_comm_set_aspm()
118 rtsx_pci_disable_aspm(pcr); in rtsx_comm_set_aspm()
124 val = pcr->aspm_en; in rtsx_comm_set_aspm()
125 rtsx_pci_write_register(pcr, ASPM_FORCE_CTL, mask, val); in rtsx_comm_set_aspm()
128 pcr->aspm_enabled = enable; in rtsx_comm_set_aspm()
131 static void rtsx_disable_aspm(struct rtsx_pcr *pcr) in rtsx_disable_aspm() argument
133 if (pcr->ops->set_aspm) in rtsx_disable_aspm()
134 pcr->ops->set_aspm(pcr, false); in rtsx_disable_aspm()
136 rtsx_comm_set_aspm(pcr, false); in rtsx_disable_aspm()
139 int rtsx_set_l1off_sub(struct rtsx_pcr *pcr, u8 val) in rtsx_set_l1off_sub() argument
141 rtsx_pci_write_register(pcr, L1SUB_CONFIG3, 0xFF, val); in rtsx_set_l1off_sub()
146 static void rtsx_set_l1off_sub_cfg_d0(struct rtsx_pcr *pcr, int active) in rtsx_set_l1off_sub_cfg_d0() argument
148 if (pcr->ops->set_l1off_cfg_sub_d0) in rtsx_set_l1off_sub_cfg_d0()
149 pcr->ops->set_l1off_cfg_sub_d0(pcr, active); in rtsx_set_l1off_sub_cfg_d0()
152 static void rtsx_comm_pm_full_on(struct rtsx_pcr *pcr) in rtsx_comm_pm_full_on() argument
154 struct rtsx_cr_option *option = &pcr->option; in rtsx_comm_pm_full_on()
156 rtsx_disable_aspm(pcr); in rtsx_comm_pm_full_on()
159 rtsx_set_ltr_latency(pcr, option->ltr_active_latency); in rtsx_comm_pm_full_on()
161 if (rtsx_check_dev_flag(pcr, LTR_L1SS_PWR_GATE_EN)) in rtsx_comm_pm_full_on()
162 rtsx_set_l1off_sub_cfg_d0(pcr, 1); in rtsx_comm_pm_full_on()
165 static void rtsx_pm_full_on(struct rtsx_pcr *pcr) in rtsx_pm_full_on() argument
167 if (pcr->ops->full_on) in rtsx_pm_full_on()
168 pcr->ops->full_on(pcr); in rtsx_pm_full_on()
170 rtsx_comm_pm_full_on(pcr); in rtsx_pm_full_on()
173 void rtsx_pci_start_run(struct rtsx_pcr *pcr) in rtsx_pci_start_run() argument
176 if (pcr->remove_pci) in rtsx_pci_start_run()
179 if (pcr->state != PDEV_STAT_RUN) { in rtsx_pci_start_run()
180 pcr->state = PDEV_STAT_RUN; in rtsx_pci_start_run()
181 if (pcr->ops->enable_auto_blink) in rtsx_pci_start_run()
182 pcr->ops->enable_auto_blink(pcr); in rtsx_pci_start_run()
183 rtsx_pm_full_on(pcr); in rtsx_pci_start_run()
186 mod_delayed_work(system_wq, &pcr->idle_work, msecs_to_jiffies(200)); in rtsx_pci_start_run()
190 int rtsx_pci_write_register(struct rtsx_pcr *pcr, u16 addr, u8 mask, u8 data) in rtsx_pci_write_register() argument
199 rtsx_pci_writel(pcr, RTSX_HAIMR, val); in rtsx_pci_write_register()
202 val = rtsx_pci_readl(pcr, RTSX_HAIMR); in rtsx_pci_write_register()
214 int rtsx_pci_read_register(struct rtsx_pcr *pcr, u16 addr, u8 *data) in rtsx_pci_read_register() argument
220 rtsx_pci_writel(pcr, RTSX_HAIMR, val); in rtsx_pci_read_register()
223 val = rtsx_pci_readl(pcr, RTSX_HAIMR); in rtsx_pci_read_register()
238 int __rtsx_pci_write_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 val) in __rtsx_pci_write_phy_register() argument
243 rtsx_pci_init_cmd(pcr); in __rtsx_pci_write_phy_register()
245 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYDATA0, 0xFF, (u8)val); in __rtsx_pci_write_phy_register()
246 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYDATA1, 0xFF, (u8)(val >> 8)); in __rtsx_pci_write_phy_register()
247 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYADDR, 0xFF, addr); in __rtsx_pci_write_phy_register()
248 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYRWCTL, 0xFF, 0x81); in __rtsx_pci_write_phy_register()
250 err = rtsx_pci_send_cmd(pcr, 100); in __rtsx_pci_write_phy_register()
255 err = rtsx_pci_read_register(pcr, PHYRWCTL, &tmp); in __rtsx_pci_write_phy_register()
271 int rtsx_pci_write_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 val) in rtsx_pci_write_phy_register() argument
273 if (pcr->ops->write_phy) in rtsx_pci_write_phy_register()
274 return pcr->ops->write_phy(pcr, addr, val); in rtsx_pci_write_phy_register()
276 return __rtsx_pci_write_phy_register(pcr, addr, val); in rtsx_pci_write_phy_register()
280 int __rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val) in __rtsx_pci_read_phy_register() argument
286 rtsx_pci_init_cmd(pcr); in __rtsx_pci_read_phy_register()
288 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYADDR, 0xFF, addr); in __rtsx_pci_read_phy_register()
289 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYRWCTL, 0xFF, 0x80); in __rtsx_pci_read_phy_register()
291 err = rtsx_pci_send_cmd(pcr, 100); in __rtsx_pci_read_phy_register()
296 err = rtsx_pci_read_register(pcr, PHYRWCTL, &tmp); in __rtsx_pci_read_phy_register()
309 rtsx_pci_init_cmd(pcr); in __rtsx_pci_read_phy_register()
311 rtsx_pci_add_cmd(pcr, READ_REG_CMD, PHYDATA0, 0, 0); in __rtsx_pci_read_phy_register()
312 rtsx_pci_add_cmd(pcr, READ_REG_CMD, PHYDATA1, 0, 0); in __rtsx_pci_read_phy_register()
314 err = rtsx_pci_send_cmd(pcr, 100); in __rtsx_pci_read_phy_register()
318 ptr = rtsx_pci_get_cmd_data(pcr); in __rtsx_pci_read_phy_register()
327 int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val) in rtsx_pci_read_phy_register() argument
329 if (pcr->ops->read_phy) in rtsx_pci_read_phy_register()
330 return pcr->ops->read_phy(pcr, addr, val); in rtsx_pci_read_phy_register()
332 return __rtsx_pci_read_phy_register(pcr, addr, val); in rtsx_pci_read_phy_register()
336 void rtsx_pci_stop_cmd(struct rtsx_pcr *pcr) in rtsx_pci_stop_cmd() argument
338 if (pcr->ops->stop_cmd) in rtsx_pci_stop_cmd()
339 return pcr->ops->stop_cmd(pcr); in rtsx_pci_stop_cmd()
341 rtsx_pci_writel(pcr, RTSX_HCBCTLR, STOP_CMD); in rtsx_pci_stop_cmd()
342 rtsx_pci_writel(pcr, RTSX_HDBCTLR, STOP_DMA); in rtsx_pci_stop_cmd()
344 rtsx_pci_write_register(pcr, DMACTL, 0x80, 0x80); in rtsx_pci_stop_cmd()
345 rtsx_pci_write_register(pcr, RBCTL, 0x80, 0x80); in rtsx_pci_stop_cmd()
349 void rtsx_pci_add_cmd(struct rtsx_pcr *pcr, in rtsx_pci_add_cmd() argument
354 u32 *ptr = (u32 *)(pcr->host_cmds_ptr); in rtsx_pci_add_cmd()
361 spin_lock_irqsave(&pcr->lock, flags); in rtsx_pci_add_cmd()
362 ptr += pcr->ci; in rtsx_pci_add_cmd()
363 if (pcr->ci < (HOST_CMDS_BUF_LEN / 4)) { in rtsx_pci_add_cmd()
366 pcr->ci++; in rtsx_pci_add_cmd()
368 spin_unlock_irqrestore(&pcr->lock, flags); in rtsx_pci_add_cmd()
372 void rtsx_pci_send_cmd_no_wait(struct rtsx_pcr *pcr) in rtsx_pci_send_cmd_no_wait() argument
376 rtsx_pci_writel(pcr, RTSX_HCBAR, pcr->host_cmds_addr); in rtsx_pci_send_cmd_no_wait()
378 val |= (u32)(pcr->ci * 4) & 0x00FFFFFF; in rtsx_pci_send_cmd_no_wait()
381 rtsx_pci_writel(pcr, RTSX_HCBCTLR, val); in rtsx_pci_send_cmd_no_wait()
385 int rtsx_pci_send_cmd(struct rtsx_pcr *pcr, int timeout) in rtsx_pci_send_cmd() argument
393 spin_lock_irqsave(&pcr->lock, flags); in rtsx_pci_send_cmd()
396 pcr->done = &trans_done; in rtsx_pci_send_cmd()
397 pcr->trans_result = TRANS_NOT_READY; in rtsx_pci_send_cmd()
400 rtsx_pci_writel(pcr, RTSX_HCBAR, pcr->host_cmds_addr); in rtsx_pci_send_cmd()
402 val |= (u32)(pcr->ci * 4) & 0x00FFFFFF; in rtsx_pci_send_cmd()
405 rtsx_pci_writel(pcr, RTSX_HCBCTLR, val); in rtsx_pci_send_cmd()
407 spin_unlock_irqrestore(&pcr->lock, flags); in rtsx_pci_send_cmd()
413 pcr_dbg(pcr, "Timeout (%s %d)\n", __func__, __LINE__); in rtsx_pci_send_cmd()
418 spin_lock_irqsave(&pcr->lock, flags); in rtsx_pci_send_cmd()
419 if (pcr->trans_result == TRANS_RESULT_FAIL) in rtsx_pci_send_cmd()
421 else if (pcr->trans_result == TRANS_RESULT_OK) in rtsx_pci_send_cmd()
423 else if (pcr->trans_result == TRANS_NO_DEVICE) in rtsx_pci_send_cmd()
425 spin_unlock_irqrestore(&pcr->lock, flags); in rtsx_pci_send_cmd()
428 spin_lock_irqsave(&pcr->lock, flags); in rtsx_pci_send_cmd()
429 pcr->done = NULL; in rtsx_pci_send_cmd()
430 spin_unlock_irqrestore(&pcr->lock, flags); in rtsx_pci_send_cmd()
433 rtsx_pci_stop_cmd(pcr); in rtsx_pci_send_cmd()
435 if (pcr->finish_me) in rtsx_pci_send_cmd()
436 complete(pcr->finish_me); in rtsx_pci_send_cmd()
442 static void rtsx_pci_add_sg_tbl(struct rtsx_pcr *pcr, in rtsx_pci_add_sg_tbl() argument
445 u64 *ptr = (u64 *)(pcr->host_sg_tbl_ptr) + pcr->sgi; in rtsx_pci_add_sg_tbl()
449 pcr_dbg(pcr, "DMA addr: 0x%x, Len: 0x%x\n", (unsigned int)addr, len); in rtsx_pci_add_sg_tbl()
456 pcr->sgi++; in rtsx_pci_add_sg_tbl()
459 int rtsx_pci_transfer_data(struct rtsx_pcr *pcr, struct scatterlist *sglist, in rtsx_pci_transfer_data() argument
464 pcr_dbg(pcr, "--> %s: num_sg = %d\n", __func__, num_sg); in rtsx_pci_transfer_data()
465 count = rtsx_pci_dma_map_sg(pcr, sglist, num_sg, read); in rtsx_pci_transfer_data()
468 pcr_dbg(pcr, "DMA mapping count: %d\n", count); in rtsx_pci_transfer_data()
470 err = rtsx_pci_dma_transfer(pcr, sglist, count, read, timeout); in rtsx_pci_transfer_data()
472 rtsx_pci_dma_unmap_sg(pcr, sglist, num_sg, read); in rtsx_pci_transfer_data()
478 int rtsx_pci_dma_map_sg(struct rtsx_pcr *pcr, struct scatterlist *sglist, in rtsx_pci_dma_map_sg() argument
483 if (pcr->remove_pci) in rtsx_pci_dma_map_sg()
489 return dma_map_sg(&(pcr->pci->dev), sglist, num_sg, dir); in rtsx_pci_dma_map_sg()
493 void rtsx_pci_dma_unmap_sg(struct rtsx_pcr *pcr, struct scatterlist *sglist, in rtsx_pci_dma_unmap_sg() argument
498 dma_unmap_sg(&(pcr->pci->dev), sglist, num_sg, dir); in rtsx_pci_dma_unmap_sg()
502 int rtsx_pci_dma_transfer(struct rtsx_pcr *pcr, struct scatterlist *sglist, in rtsx_pci_dma_transfer() argument
515 if (pcr->remove_pci) in rtsx_pci_dma_transfer()
522 pcr->sgi = 0; in rtsx_pci_dma_transfer()
526 rtsx_pci_add_sg_tbl(pcr, addr, len, i == count - 1); in rtsx_pci_dma_transfer()
529 spin_lock_irqsave(&pcr->lock, flags); in rtsx_pci_dma_transfer()
531 pcr->done = &trans_done; in rtsx_pci_dma_transfer()
532 pcr->trans_result = TRANS_NOT_READY; in rtsx_pci_dma_transfer()
534 rtsx_pci_writel(pcr, RTSX_HDBAR, pcr->host_sg_tbl_addr); in rtsx_pci_dma_transfer()
535 rtsx_pci_writel(pcr, RTSX_HDBCTLR, val); in rtsx_pci_dma_transfer()
537 spin_unlock_irqrestore(&pcr->lock, flags); in rtsx_pci_dma_transfer()
542 pcr_dbg(pcr, "Timeout (%s %d)\n", __func__, __LINE__); in rtsx_pci_dma_transfer()
547 spin_lock_irqsave(&pcr->lock, flags); in rtsx_pci_dma_transfer()
548 if (pcr->trans_result == TRANS_RESULT_FAIL) { in rtsx_pci_dma_transfer()
550 if (pcr->dma_error_count < RTS_MAX_TIMES_FREQ_REDUCTION) in rtsx_pci_dma_transfer()
551 pcr->dma_error_count++; in rtsx_pci_dma_transfer()
554 else if (pcr->trans_result == TRANS_NO_DEVICE) in rtsx_pci_dma_transfer()
556 spin_unlock_irqrestore(&pcr->lock, flags); in rtsx_pci_dma_transfer()
559 spin_lock_irqsave(&pcr->lock, flags); in rtsx_pci_dma_transfer()
560 pcr->done = NULL; in rtsx_pci_dma_transfer()
561 spin_unlock_irqrestore(&pcr->lock, flags); in rtsx_pci_dma_transfer()
564 rtsx_pci_stop_cmd(pcr); in rtsx_pci_dma_transfer()
566 if (pcr->finish_me) in rtsx_pci_dma_transfer()
567 complete(pcr->finish_me); in rtsx_pci_dma_transfer()
573 int rtsx_pci_read_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len) in rtsx_pci_read_ppbuf() argument
586 rtsx_pci_init_cmd(pcr); in rtsx_pci_read_ppbuf()
589 rtsx_pci_add_cmd(pcr, READ_REG_CMD, reg++, 0, 0); in rtsx_pci_read_ppbuf()
591 err = rtsx_pci_send_cmd(pcr, 250); in rtsx_pci_read_ppbuf()
595 memcpy(ptr, rtsx_pci_get_cmd_data(pcr), 256); in rtsx_pci_read_ppbuf()
600 rtsx_pci_init_cmd(pcr); in rtsx_pci_read_ppbuf()
603 rtsx_pci_add_cmd(pcr, READ_REG_CMD, reg++, 0, 0); in rtsx_pci_read_ppbuf()
605 err = rtsx_pci_send_cmd(pcr, 250); in rtsx_pci_read_ppbuf()
610 memcpy(ptr, rtsx_pci_get_cmd_data(pcr), buf_len % 256); in rtsx_pci_read_ppbuf()
616 int rtsx_pci_write_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len) in rtsx_pci_write_ppbuf() argument
629 rtsx_pci_init_cmd(pcr); in rtsx_pci_write_ppbuf()
632 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, in rtsx_pci_write_ppbuf()
637 err = rtsx_pci_send_cmd(pcr, 250); in rtsx_pci_write_ppbuf()
643 rtsx_pci_init_cmd(pcr); in rtsx_pci_write_ppbuf()
646 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, in rtsx_pci_write_ppbuf()
651 err = rtsx_pci_send_cmd(pcr, 250); in rtsx_pci_write_ppbuf()
660 static int rtsx_pci_set_pull_ctl(struct rtsx_pcr *pcr, const u32 *tbl) in rtsx_pci_set_pull_ctl() argument
662 rtsx_pci_init_cmd(pcr); in rtsx_pci_set_pull_ctl()
665 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, in rtsx_pci_set_pull_ctl()
670 return rtsx_pci_send_cmd(pcr, 100); in rtsx_pci_set_pull_ctl()
673 int rtsx_pci_card_pull_ctl_enable(struct rtsx_pcr *pcr, int card) in rtsx_pci_card_pull_ctl_enable() argument
678 tbl = pcr->sd_pull_ctl_enable_tbl; in rtsx_pci_card_pull_ctl_enable()
680 tbl = pcr->ms_pull_ctl_enable_tbl; in rtsx_pci_card_pull_ctl_enable()
684 return rtsx_pci_set_pull_ctl(pcr, tbl); in rtsx_pci_card_pull_ctl_enable()
688 int rtsx_pci_card_pull_ctl_disable(struct rtsx_pcr *pcr, int card) in rtsx_pci_card_pull_ctl_disable() argument
693 tbl = pcr->sd_pull_ctl_disable_tbl; in rtsx_pci_card_pull_ctl_disable()
695 tbl = pcr->ms_pull_ctl_disable_tbl; in rtsx_pci_card_pull_ctl_disable()
700 return rtsx_pci_set_pull_ctl(pcr, tbl); in rtsx_pci_card_pull_ctl_disable()
704 static void rtsx_pci_enable_bus_int(struct rtsx_pcr *pcr) in rtsx_pci_enable_bus_int() argument
706 pcr->bier = TRANS_OK_INT_EN | TRANS_FAIL_INT_EN | SD_INT_EN; in rtsx_pci_enable_bus_int()
708 if (pcr->num_slots > 1) in rtsx_pci_enable_bus_int()
709 pcr->bier |= MS_INT_EN; in rtsx_pci_enable_bus_int()
712 rtsx_pci_writel(pcr, RTSX_BIER, pcr->bier); in rtsx_pci_enable_bus_int()
714 pcr_dbg(pcr, "RTSX_BIER: 0x%08x\n", pcr->bier); in rtsx_pci_enable_bus_int()
734 int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock, in rtsx_pci_switch_clock() argument
754 err = rtsx_pci_write_register(pcr, SD_CFG1, in rtsx_pci_switch_clock()
761 pcr->dma_error_count && in rtsx_pci_switch_clock()
762 PCI_PID(pcr) == RTS5227_DEVICE_ID) in rtsx_pci_switch_clock()
764 (pcr->dma_error_count * 20000000); in rtsx_pci_switch_clock()
767 pcr_dbg(pcr, "Switch card clock to %dMHz\n", card_clock); in rtsx_pci_switch_clock()
772 pcr_dbg(pcr, "Internal SSC clock: %dMHz (cur_clock = %d)\n", in rtsx_pci_switch_clock()
773 clk, pcr->cur_clock); in rtsx_pci_switch_clock()
775 if (clk == pcr->cur_clock) in rtsx_pci_switch_clock()
778 if (pcr->ops->conv_clk_and_div_n) in rtsx_pci_switch_clock()
779 n = (u8)pcr->ops->conv_clk_and_div_n(clk, CLK_TO_DIV_N); in rtsx_pci_switch_clock()
792 if (pcr->ops->conv_clk_and_div_n) { in rtsx_pci_switch_clock()
793 int dbl_clk = pcr->ops->conv_clk_and_div_n(n, in rtsx_pci_switch_clock()
795 n = (u8)pcr->ops->conv_clk_and_div_n(dbl_clk, in rtsx_pci_switch_clock()
802 pcr_dbg(pcr, "n = %d, div = %d\n", n, div); in rtsx_pci_switch_clock()
809 pcr_dbg(pcr, "ssc_depth = %d\n", ssc_depth); in rtsx_pci_switch_clock()
811 rtsx_pci_init_cmd(pcr); in rtsx_pci_switch_clock()
812 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CLK_CTL, in rtsx_pci_switch_clock()
814 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CLK_DIV, in rtsx_pci_switch_clock()
816 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL1, SSC_RSTB, 0); in rtsx_pci_switch_clock()
817 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL2, in rtsx_pci_switch_clock()
819 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_DIV_N_0, 0xFF, n); in rtsx_pci_switch_clock()
820 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL1, SSC_RSTB, SSC_RSTB); in rtsx_pci_switch_clock()
822 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD_VPCLK0_CTL, in rtsx_pci_switch_clock()
824 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD_VPCLK0_CTL, in rtsx_pci_switch_clock()
828 err = rtsx_pci_send_cmd(pcr, 2000); in rtsx_pci_switch_clock()
834 err = rtsx_pci_write_register(pcr, CLK_CTL, CLK_LOW_FREQ, 0); in rtsx_pci_switch_clock()
838 pcr->cur_clock = clk; in rtsx_pci_switch_clock()
843 int rtsx_pci_card_power_on(struct rtsx_pcr *pcr, int card) in rtsx_pci_card_power_on() argument
845 if (pcr->ops->card_power_on) in rtsx_pci_card_power_on()
846 return pcr->ops->card_power_on(pcr, card); in rtsx_pci_card_power_on()
852 int rtsx_pci_card_power_off(struct rtsx_pcr *pcr, int card) in rtsx_pci_card_power_off() argument
854 if (pcr->ops->card_power_off) in rtsx_pci_card_power_off()
855 return pcr->ops->card_power_off(pcr, card); in rtsx_pci_card_power_off()
861 int rtsx_pci_card_exclusive_check(struct rtsx_pcr *pcr, int card) in rtsx_pci_card_exclusive_check() argument
868 if (!(pcr->flags & PCR_MS_PMOS)) { in rtsx_pci_card_exclusive_check()
872 if (pcr->card_exist & (~cd_mask[card])) in rtsx_pci_card_exclusive_check()
880 int rtsx_pci_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage) in rtsx_pci_switch_output_voltage() argument
882 if (pcr->ops->switch_output_voltage) in rtsx_pci_switch_output_voltage()
883 return pcr->ops->switch_output_voltage(pcr, voltage); in rtsx_pci_switch_output_voltage()
889 unsigned int rtsx_pci_card_exist(struct rtsx_pcr *pcr) in rtsx_pci_card_exist() argument
893 val = rtsx_pci_readl(pcr, RTSX_BIPR); in rtsx_pci_card_exist()
894 if (pcr->ops->cd_deglitch) in rtsx_pci_card_exist()
895 val = pcr->ops->cd_deglitch(pcr); in rtsx_pci_card_exist()
901 void rtsx_pci_complete_unfinished_transfer(struct rtsx_pcr *pcr) in rtsx_pci_complete_unfinished_transfer() argument
905 pcr->finish_me = &finish; in rtsx_pci_complete_unfinished_transfer()
908 if (pcr->done) in rtsx_pci_complete_unfinished_transfer()
909 complete(pcr->done); in rtsx_pci_complete_unfinished_transfer()
911 if (!pcr->remove_pci) in rtsx_pci_complete_unfinished_transfer()
912 rtsx_pci_stop_cmd(pcr); in rtsx_pci_complete_unfinished_transfer()
916 pcr->finish_me = NULL; in rtsx_pci_complete_unfinished_transfer()
923 struct rtsx_pcr *pcr; in rtsx_pci_card_detect() local
929 pcr = container_of(dwork, struct rtsx_pcr, carddet_work); in rtsx_pci_card_detect()
931 pcr_dbg(pcr, "--> %s\n", __func__); in rtsx_pci_card_detect()
933 mutex_lock(&pcr->pcr_mutex); in rtsx_pci_card_detect()
934 spin_lock_irqsave(&pcr->lock, flags); in rtsx_pci_card_detect()
936 irq_status = rtsx_pci_readl(pcr, RTSX_BIPR); in rtsx_pci_card_detect()
937 pcr_dbg(pcr, "irq_status: 0x%08x\n", irq_status); in rtsx_pci_card_detect()
940 card_inserted = pcr->card_inserted & irq_status; in rtsx_pci_card_detect()
941 card_removed = pcr->card_removed; in rtsx_pci_card_detect()
942 pcr->card_inserted = 0; in rtsx_pci_card_detect()
943 pcr->card_removed = 0; in rtsx_pci_card_detect()
945 spin_unlock_irqrestore(&pcr->lock, flags); in rtsx_pci_card_detect()
948 pcr_dbg(pcr, "card_inserted: 0x%x, card_removed: 0x%x\n", in rtsx_pci_card_detect()
951 if (pcr->ops->cd_deglitch) in rtsx_pci_card_detect()
952 card_inserted = pcr->ops->cd_deglitch(pcr); in rtsx_pci_card_detect()
956 pcr->card_exist |= card_inserted; in rtsx_pci_card_detect()
957 pcr->card_exist &= ~card_removed; in rtsx_pci_card_detect()
960 mutex_unlock(&pcr->pcr_mutex); in rtsx_pci_card_detect()
962 if ((card_detect & SD_EXIST) && pcr->slots[RTSX_SD_CARD].card_event) in rtsx_pci_card_detect()
963 pcr->slots[RTSX_SD_CARD].card_event( in rtsx_pci_card_detect()
964 pcr->slots[RTSX_SD_CARD].p_dev); in rtsx_pci_card_detect()
965 if ((card_detect & MS_EXIST) && pcr->slots[RTSX_MS_CARD].card_event) in rtsx_pci_card_detect()
966 pcr->slots[RTSX_MS_CARD].card_event( in rtsx_pci_card_detect()
967 pcr->slots[RTSX_MS_CARD].p_dev); in rtsx_pci_card_detect()
970 static void rtsx_pci_process_ocp(struct rtsx_pcr *pcr) in rtsx_pci_process_ocp() argument
972 if (pcr->ops->process_ocp) in rtsx_pci_process_ocp()
973 pcr->ops->process_ocp(pcr); in rtsx_pci_process_ocp()
976 static int rtsx_pci_process_ocp_interrupt(struct rtsx_pcr *pcr) in rtsx_pci_process_ocp_interrupt() argument
978 if (pcr->option.ocp_en) in rtsx_pci_process_ocp_interrupt()
979 rtsx_pci_process_ocp(pcr); in rtsx_pci_process_ocp_interrupt()
986 struct rtsx_pcr *pcr = dev_id; in rtsx_pci_isr() local
989 if (!pcr) in rtsx_pci_isr()
992 spin_lock(&pcr->lock); in rtsx_pci_isr()
994 int_reg = rtsx_pci_readl(pcr, RTSX_BIPR); in rtsx_pci_isr()
996 rtsx_pci_writel(pcr, RTSX_BIPR, int_reg); in rtsx_pci_isr()
997 if ((int_reg & pcr->bier) == 0) { in rtsx_pci_isr()
998 spin_unlock(&pcr->lock); in rtsx_pci_isr()
1002 spin_unlock(&pcr->lock); in rtsx_pci_isr()
1006 int_reg &= (pcr->bier | 0x7FFFFF); in rtsx_pci_isr()
1009 rtsx_pci_process_ocp_interrupt(pcr); in rtsx_pci_isr()
1013 pcr->card_inserted |= SD_EXIST; in rtsx_pci_isr()
1015 pcr->card_removed |= SD_EXIST; in rtsx_pci_isr()
1016 pcr->card_inserted &= ~SD_EXIST; in rtsx_pci_isr()
1018 pcr->dma_error_count = 0; in rtsx_pci_isr()
1023 pcr->card_inserted |= MS_EXIST; in rtsx_pci_isr()
1025 pcr->card_removed |= MS_EXIST; in rtsx_pci_isr()
1026 pcr->card_inserted &= ~MS_EXIST; in rtsx_pci_isr()
1032 pcr->trans_result = TRANS_RESULT_FAIL; in rtsx_pci_isr()
1033 if (pcr->done) in rtsx_pci_isr()
1034 complete(pcr->done); in rtsx_pci_isr()
1036 pcr->trans_result = TRANS_RESULT_OK; in rtsx_pci_isr()
1037 if (pcr->done) in rtsx_pci_isr()
1038 complete(pcr->done); in rtsx_pci_isr()
1042 if (pcr->card_inserted || pcr->card_removed) in rtsx_pci_isr()
1043 schedule_delayed_work(&pcr->carddet_work, in rtsx_pci_isr()
1046 spin_unlock(&pcr->lock); in rtsx_pci_isr()
1050 static int rtsx_pci_acquire_irq(struct rtsx_pcr *pcr) in rtsx_pci_acquire_irq() argument
1052 pcr_dbg(pcr, "%s: pcr->msi_en = %d, pci->irq = %d\n", in rtsx_pci_acquire_irq()
1053 __func__, pcr->msi_en, pcr->pci->irq); in rtsx_pci_acquire_irq()
1055 if (request_irq(pcr->pci->irq, rtsx_pci_isr, in rtsx_pci_acquire_irq()
1056 pcr->msi_en ? 0 : IRQF_SHARED, in rtsx_pci_acquire_irq()
1057 DRV_NAME_RTSX_PCI, pcr)) { in rtsx_pci_acquire_irq()
1058 dev_err(&(pcr->pci->dev), in rtsx_pci_acquire_irq()
1060 pcr->pci->irq); in rtsx_pci_acquire_irq()
1064 pcr->irq = pcr->pci->irq; in rtsx_pci_acquire_irq()
1065 pci_intx(pcr->pci, !pcr->msi_en); in rtsx_pci_acquire_irq()
1070 static void rtsx_enable_aspm(struct rtsx_pcr *pcr) in rtsx_enable_aspm() argument
1072 if (pcr->ops->set_aspm) in rtsx_enable_aspm()
1073 pcr->ops->set_aspm(pcr, true); in rtsx_enable_aspm()
1075 rtsx_comm_set_aspm(pcr, true); in rtsx_enable_aspm()
1078 static void rtsx_comm_pm_power_saving(struct rtsx_pcr *pcr) in rtsx_comm_pm_power_saving() argument
1080 struct rtsx_cr_option *option = &pcr->option; in rtsx_comm_pm_power_saving()
1085 if (rtsx_check_dev_flag(pcr, L1_SNOOZE_TEST_EN)) in rtsx_comm_pm_power_saving()
1088 rtsx_set_ltr_latency(pcr, latency); in rtsx_comm_pm_power_saving()
1091 if (rtsx_check_dev_flag(pcr, LTR_L1SS_PWR_GATE_EN)) in rtsx_comm_pm_power_saving()
1092 rtsx_set_l1off_sub_cfg_d0(pcr, 0); in rtsx_comm_pm_power_saving()
1094 rtsx_enable_aspm(pcr); in rtsx_comm_pm_power_saving()
1097 static void rtsx_pm_power_saving(struct rtsx_pcr *pcr) in rtsx_pm_power_saving() argument
1099 if (pcr->ops->power_saving) in rtsx_pm_power_saving()
1100 pcr->ops->power_saving(pcr); in rtsx_pm_power_saving()
1102 rtsx_comm_pm_power_saving(pcr); in rtsx_pm_power_saving()
1108 struct rtsx_pcr *pcr = container_of(dwork, struct rtsx_pcr, idle_work); in rtsx_pci_idle_work() local
1110 pcr_dbg(pcr, "--> %s\n", __func__); in rtsx_pci_idle_work()
1112 mutex_lock(&pcr->pcr_mutex); in rtsx_pci_idle_work()
1114 pcr->state = PDEV_STAT_IDLE; in rtsx_pci_idle_work()
1116 if (pcr->ops->disable_auto_blink) in rtsx_pci_idle_work()
1117 pcr->ops->disable_auto_blink(pcr); in rtsx_pci_idle_work()
1118 if (pcr->ops->turn_off_led) in rtsx_pci_idle_work()
1119 pcr->ops->turn_off_led(pcr); in rtsx_pci_idle_work()
1121 rtsx_pm_power_saving(pcr); in rtsx_pci_idle_work()
1123 mutex_unlock(&pcr->pcr_mutex); in rtsx_pci_idle_work()
1127 static void rtsx_pci_power_off(struct rtsx_pcr *pcr, u8 pm_state) in rtsx_pci_power_off() argument
1129 if (pcr->ops->turn_off_led) in rtsx_pci_power_off()
1130 pcr->ops->turn_off_led(pcr); in rtsx_pci_power_off()
1132 rtsx_pci_writel(pcr, RTSX_BIER, 0); in rtsx_pci_power_off()
1133 pcr->bier = 0; in rtsx_pci_power_off()
1135 rtsx_pci_write_register(pcr, PETXCFG, 0x08, 0x08); in rtsx_pci_power_off()
1136 rtsx_pci_write_register(pcr, HOST_SLEEP_STATE, 0x03, pm_state); in rtsx_pci_power_off()
1138 if (pcr->ops->force_power_down) in rtsx_pci_power_off()
1139 pcr->ops->force_power_down(pcr, pm_state); in rtsx_pci_power_off()
1143 void rtsx_pci_enable_ocp(struct rtsx_pcr *pcr) in rtsx_pci_enable_ocp() argument
1147 if (pcr->ops->enable_ocp) in rtsx_pci_enable_ocp()
1148 pcr->ops->enable_ocp(pcr); in rtsx_pci_enable_ocp()
1150 rtsx_pci_write_register(pcr, REG_OCPCTL, 0xFF, val); in rtsx_pci_enable_ocp()
1154 void rtsx_pci_disable_ocp(struct rtsx_pcr *pcr) in rtsx_pci_disable_ocp() argument
1158 if (pcr->ops->disable_ocp) in rtsx_pci_disable_ocp()
1159 pcr->ops->disable_ocp(pcr); in rtsx_pci_disable_ocp()
1161 rtsx_pci_write_register(pcr, REG_OCPCTL, mask, 0); in rtsx_pci_disable_ocp()
1164 void rtsx_pci_init_ocp(struct rtsx_pcr *pcr) in rtsx_pci_init_ocp() argument
1166 if (pcr->ops->init_ocp) { in rtsx_pci_init_ocp()
1167 pcr->ops->init_ocp(pcr); in rtsx_pci_init_ocp()
1169 struct rtsx_cr_option *option = &(pcr->option); in rtsx_pci_init_ocp()
1174 rtsx_pci_write_register(pcr, FPDCTL, OC_POWER_DOWN, 0); in rtsx_pci_init_ocp()
1175 rtsx_pci_write_register(pcr, REG_OCPPARA1, in rtsx_pci_init_ocp()
1177 rtsx_pci_write_register(pcr, REG_OCPPARA2, in rtsx_pci_init_ocp()
1179 rtsx_pci_write_register(pcr, REG_OCPGLITCH, in rtsx_pci_init_ocp()
1180 SD_OCP_GLITCH_MASK, pcr->hw_param.ocp_glitch); in rtsx_pci_init_ocp()
1181 rtsx_pci_enable_ocp(pcr); in rtsx_pci_init_ocp()
1184 rtsx_pci_write_register(pcr, FPDCTL, OC_POWER_DOWN, in rtsx_pci_init_ocp()
1190 int rtsx_pci_get_ocpstat(struct rtsx_pcr *pcr, u8 *val) in rtsx_pci_get_ocpstat() argument
1192 if (pcr->ops->get_ocpstat) in rtsx_pci_get_ocpstat()
1193 return pcr->ops->get_ocpstat(pcr, val); in rtsx_pci_get_ocpstat()
1195 return rtsx_pci_read_register(pcr, REG_OCPSTAT, val); in rtsx_pci_get_ocpstat()
1198 void rtsx_pci_clear_ocpstat(struct rtsx_pcr *pcr) in rtsx_pci_clear_ocpstat() argument
1200 if (pcr->ops->clear_ocpstat) { in rtsx_pci_clear_ocpstat()
1201 pcr->ops->clear_ocpstat(pcr); in rtsx_pci_clear_ocpstat()
1206 rtsx_pci_write_register(pcr, REG_OCPCTL, mask, val); in rtsx_pci_clear_ocpstat()
1207 rtsx_pci_write_register(pcr, REG_OCPCTL, mask, 0); in rtsx_pci_clear_ocpstat()
1211 int rtsx_sd_power_off_card3v3(struct rtsx_pcr *pcr) in rtsx_sd_power_off_card3v3() argument
1213 rtsx_pci_write_register(pcr, CARD_CLK_EN, SD_CLK_EN | in rtsx_sd_power_off_card3v3()
1215 rtsx_pci_write_register(pcr, CARD_OE, SD_OUTPUT_EN, 0); in rtsx_sd_power_off_card3v3()
1217 rtsx_pci_card_power_off(pcr, RTSX_SD_CARD); in rtsx_sd_power_off_card3v3()
1221 rtsx_pci_card_pull_ctl_disable(pcr, RTSX_SD_CARD); in rtsx_sd_power_off_card3v3()
1226 int rtsx_ms_power_off_card3v3(struct rtsx_pcr *pcr) in rtsx_ms_power_off_card3v3() argument
1228 rtsx_pci_write_register(pcr, CARD_CLK_EN, SD_CLK_EN | in rtsx_ms_power_off_card3v3()
1231 rtsx_pci_card_pull_ctl_disable(pcr, RTSX_MS_CARD); in rtsx_ms_power_off_card3v3()
1233 rtsx_pci_write_register(pcr, CARD_OE, MS_OUTPUT_EN, 0); in rtsx_ms_power_off_card3v3()
1234 rtsx_pci_card_power_off(pcr, RTSX_MS_CARD); in rtsx_ms_power_off_card3v3()
1239 static int rtsx_pci_init_hw(struct rtsx_pcr *pcr) in rtsx_pci_init_hw() argument
1243 pcr->pcie_cap = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP); in rtsx_pci_init_hw()
1244 rtsx_pci_writel(pcr, RTSX_HCBAR, pcr->host_cmds_addr); in rtsx_pci_init_hw()
1246 rtsx_pci_enable_bus_int(pcr); in rtsx_pci_init_hw()
1249 err = rtsx_pci_write_register(pcr, FPDCTL, SSC_POWER_DOWN, 0); in rtsx_pci_init_hw()
1256 rtsx_pci_disable_aspm(pcr); in rtsx_pci_init_hw()
1257 if (pcr->ops->optimize_phy) { in rtsx_pci_init_hw()
1258 err = pcr->ops->optimize_phy(pcr); in rtsx_pci_init_hw()
1263 rtsx_pci_init_cmd(pcr); in rtsx_pci_init_hw()
1266 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CLK_DIV, 0x07, 0x07); in rtsx_pci_init_hw()
1268 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, HOST_SLEEP_STATE, 0x03, 0x00); in rtsx_pci_init_hw()
1270 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_CLK_EN, 0x1E, 0); in rtsx_pci_init_hw()
1272 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CHANGE_LINK_STATE, 0x0A, 0); in rtsx_pci_init_hw()
1274 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_DRIVE_SEL, in rtsx_pci_init_hw()
1275 0xFF, pcr->card_drive_sel); in rtsx_pci_init_hw()
1277 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL1, in rtsx_pci_init_hw()
1279 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL2, 0xFF, 0x12); in rtsx_pci_init_hw()
1281 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CHANGE_LINK_STATE, 0x16, 0x10); in rtsx_pci_init_hw()
1283 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, IRQSTAT0, in rtsx_pci_init_hw()
1288 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PERST_GLITCH_WIDTH, 0xFF, 0x80); in rtsx_pci_init_hw()
1293 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, RCCTL, 0x01, 0x00); in rtsx_pci_init_hw()
1299 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, NFTS_TX_CTRL, 0x02, 0); in rtsx_pci_init_hw()
1301 err = rtsx_pci_send_cmd(pcr, 100); in rtsx_pci_init_hw()
1305 switch (PCI_PID(pcr)) { in rtsx_pci_init_hw()
1310 rtsx_pci_write_register(pcr, PM_CLK_FORCE_CTL, 1, 1); in rtsx_pci_init_hw()
1317 rtsx_pci_write_config_byte(pcr, pcr->pcie_cap + PCI_EXP_LNKCTL + 1, 1); in rtsx_pci_init_hw()
1319 rtsx_pci_write_config_byte(pcr, 0x70F, 0x5B); in rtsx_pci_init_hw()
1321 if (pcr->ops->extra_init_hw) { in rtsx_pci_init_hw()
1322 err = pcr->ops->extra_init_hw(pcr); in rtsx_pci_init_hw()
1330 if (pcr->ops->cd_deglitch) in rtsx_pci_init_hw()
1331 pcr->card_exist = pcr->ops->cd_deglitch(pcr); in rtsx_pci_init_hw()
1333 pcr->card_exist = rtsx_pci_readl(pcr, RTSX_BIPR) & CARD_EXIST; in rtsx_pci_init_hw()
1338 static int rtsx_pci_init_chip(struct rtsx_pcr *pcr) in rtsx_pci_init_chip() argument
1342 spin_lock_init(&pcr->lock); in rtsx_pci_init_chip()
1343 mutex_init(&pcr->pcr_mutex); in rtsx_pci_init_chip()
1345 switch (PCI_PID(pcr)) { in rtsx_pci_init_chip()
1348 rts5209_init_params(pcr); in rtsx_pci_init_chip()
1352 rts5229_init_params(pcr); in rtsx_pci_init_chip()
1356 rtl8411_init_params(pcr); in rtsx_pci_init_chip()
1360 rts5227_init_params(pcr); in rtsx_pci_init_chip()
1364 rts522a_init_params(pcr); in rtsx_pci_init_chip()
1368 rts5249_init_params(pcr); in rtsx_pci_init_chip()
1372 rts524a_init_params(pcr); in rtsx_pci_init_chip()
1376 rts525a_init_params(pcr); in rtsx_pci_init_chip()
1380 rtl8411b_init_params(pcr); in rtsx_pci_init_chip()
1384 rtl8402_init_params(pcr); in rtsx_pci_init_chip()
1387 rts5260_init_params(pcr); in rtsx_pci_init_chip()
1391 pcr_dbg(pcr, "PID: 0x%04x, IC version: 0x%02x\n", in rtsx_pci_init_chip()
1392 PCI_PID(pcr), pcr->ic_version); in rtsx_pci_init_chip()
1394 pcr->slots = kcalloc(pcr->num_slots, sizeof(struct rtsx_slot), in rtsx_pci_init_chip()
1396 if (!pcr->slots) in rtsx_pci_init_chip()
1399 if (pcr->ops->fetch_vendor_settings) in rtsx_pci_init_chip()
1400 pcr->ops->fetch_vendor_settings(pcr); in rtsx_pci_init_chip()
1402 pcr_dbg(pcr, "pcr->aspm_en = 0x%x\n", pcr->aspm_en); in rtsx_pci_init_chip()
1403 pcr_dbg(pcr, "pcr->sd30_drive_sel_1v8 = 0x%x\n", in rtsx_pci_init_chip()
1404 pcr->sd30_drive_sel_1v8); in rtsx_pci_init_chip()
1405 pcr_dbg(pcr, "pcr->sd30_drive_sel_3v3 = 0x%x\n", in rtsx_pci_init_chip()
1406 pcr->sd30_drive_sel_3v3); in rtsx_pci_init_chip()
1407 pcr_dbg(pcr, "pcr->card_drive_sel = 0x%x\n", in rtsx_pci_init_chip()
1408 pcr->card_drive_sel); in rtsx_pci_init_chip()
1409 pcr_dbg(pcr, "pcr->flags = 0x%x\n", pcr->flags); in rtsx_pci_init_chip()
1411 pcr->state = PDEV_STAT_IDLE; in rtsx_pci_init_chip()
1412 err = rtsx_pci_init_hw(pcr); in rtsx_pci_init_chip()
1414 kfree(pcr->slots); in rtsx_pci_init_chip()
1424 struct rtsx_pcr *pcr; in rtsx_pci_probe() local
1446 pcr = kzalloc(sizeof(*pcr), GFP_KERNEL); in rtsx_pci_probe()
1447 if (!pcr) { in rtsx_pci_probe()
1457 handle->pcr = pcr; in rtsx_pci_probe()
1461 ret = idr_alloc(&rtsx_pci_idr, pcr, 0, 0, GFP_NOWAIT); in rtsx_pci_probe()
1463 pcr->id = ret; in rtsx_pci_probe()
1469 pcr->pci = pcidev; in rtsx_pci_probe()
1472 if (CHK_PCI_PID(pcr, 0x525A)) in rtsx_pci_probe()
1476 pcr->remap_addr = ioremap_nocache(base, len); in rtsx_pci_probe()
1477 if (!pcr->remap_addr) { in rtsx_pci_probe()
1482 pcr->rtsx_resv_buf = dma_alloc_coherent(&(pcidev->dev), in rtsx_pci_probe()
1483 RTSX_RESV_BUF_LEN, &(pcr->rtsx_resv_buf_addr), in rtsx_pci_probe()
1485 if (pcr->rtsx_resv_buf == NULL) { in rtsx_pci_probe()
1489 pcr->host_cmds_ptr = pcr->rtsx_resv_buf; in rtsx_pci_probe()
1490 pcr->host_cmds_addr = pcr->rtsx_resv_buf_addr; in rtsx_pci_probe()
1491 pcr->host_sg_tbl_ptr = pcr->rtsx_resv_buf + HOST_CMDS_BUF_LEN; in rtsx_pci_probe()
1492 pcr->host_sg_tbl_addr = pcr->rtsx_resv_buf_addr + HOST_CMDS_BUF_LEN; in rtsx_pci_probe()
1494 pcr->card_inserted = 0; in rtsx_pci_probe()
1495 pcr->card_removed = 0; in rtsx_pci_probe()
1496 INIT_DELAYED_WORK(&pcr->carddet_work, rtsx_pci_card_detect); in rtsx_pci_probe()
1497 INIT_DELAYED_WORK(&pcr->idle_work, rtsx_pci_idle_work); in rtsx_pci_probe()
1499 pcr->msi_en = msi_en; in rtsx_pci_probe()
1500 if (pcr->msi_en) { in rtsx_pci_probe()
1503 pcr->msi_en = false; in rtsx_pci_probe()
1506 ret = rtsx_pci_acquire_irq(pcr); in rtsx_pci_probe()
1511 synchronize_irq(pcr->irq); in rtsx_pci_probe()
1513 ret = rtsx_pci_init_chip(pcr); in rtsx_pci_probe()
1521 ret = mfd_add_devices(&pcidev->dev, pcr->id, rtsx_pcr_cells, in rtsx_pci_probe()
1526 schedule_delayed_work(&pcr->idle_work, msecs_to_jiffies(200)); in rtsx_pci_probe()
1531 free_irq(pcr->irq, (void *)pcr); in rtsx_pci_probe()
1533 if (pcr->msi_en) in rtsx_pci_probe()
1534 pci_disable_msi(pcr->pci); in rtsx_pci_probe()
1535 dma_free_coherent(&(pcr->pci->dev), RTSX_RESV_BUF_LEN, in rtsx_pci_probe()
1536 pcr->rtsx_resv_buf, pcr->rtsx_resv_buf_addr); in rtsx_pci_probe()
1538 iounmap(pcr->remap_addr); in rtsx_pci_probe()
1542 kfree(pcr); in rtsx_pci_probe()
1554 struct rtsx_pcr *pcr = handle->pcr; in rtsx_pci_remove() local
1556 pcr->remove_pci = true; in rtsx_pci_remove()
1559 spin_lock_irq(&pcr->lock); in rtsx_pci_remove()
1560 rtsx_pci_writel(pcr, RTSX_BIER, 0); in rtsx_pci_remove()
1561 pcr->bier = 0; in rtsx_pci_remove()
1562 spin_unlock_irq(&pcr->lock); in rtsx_pci_remove()
1564 cancel_delayed_work_sync(&pcr->carddet_work); in rtsx_pci_remove()
1565 cancel_delayed_work_sync(&pcr->idle_work); in rtsx_pci_remove()
1569 dma_free_coherent(&(pcr->pci->dev), RTSX_RESV_BUF_LEN, in rtsx_pci_remove()
1570 pcr->rtsx_resv_buf, pcr->rtsx_resv_buf_addr); in rtsx_pci_remove()
1571 free_irq(pcr->irq, (void *)pcr); in rtsx_pci_remove()
1572 if (pcr->msi_en) in rtsx_pci_remove()
1573 pci_disable_msi(pcr->pci); in rtsx_pci_remove()
1574 iounmap(pcr->remap_addr); in rtsx_pci_remove()
1580 idr_remove(&rtsx_pci_idr, pcr->id); in rtsx_pci_remove()
1583 kfree(pcr->slots); in rtsx_pci_remove()
1584 kfree(pcr); in rtsx_pci_remove()
1597 struct rtsx_pcr *pcr; in rtsx_pci_suspend() local
1602 pcr = handle->pcr; in rtsx_pci_suspend()
1604 cancel_delayed_work(&pcr->carddet_work); in rtsx_pci_suspend()
1605 cancel_delayed_work(&pcr->idle_work); in rtsx_pci_suspend()
1607 mutex_lock(&pcr->pcr_mutex); in rtsx_pci_suspend()
1609 rtsx_pci_power_off(pcr, HOST_ENTER_S3); in rtsx_pci_suspend()
1616 mutex_unlock(&pcr->pcr_mutex); in rtsx_pci_suspend()
1623 struct rtsx_pcr *pcr; in rtsx_pci_resume() local
1629 pcr = handle->pcr; in rtsx_pci_resume()
1631 mutex_lock(&pcr->pcr_mutex); in rtsx_pci_resume()
1640 ret = rtsx_pci_write_register(pcr, HOST_SLEEP_STATE, 0x03, 0x00); in rtsx_pci_resume()
1644 ret = rtsx_pci_init_hw(pcr); in rtsx_pci_resume()
1648 schedule_delayed_work(&pcr->idle_work, msecs_to_jiffies(200)); in rtsx_pci_resume()
1651 mutex_unlock(&pcr->pcr_mutex); in rtsx_pci_resume()
1658 struct rtsx_pcr *pcr; in rtsx_pci_shutdown() local
1663 pcr = handle->pcr; in rtsx_pci_shutdown()
1664 rtsx_pci_power_off(pcr, HOST_ENTER_S1); in rtsx_pci_shutdown()
1667 free_irq(pcr->irq, (void *)pcr); in rtsx_pci_shutdown()
1668 if (pcr->msi_en) in rtsx_pci_shutdown()
1669 pci_disable_msi(pcr->pci); in rtsx_pci_shutdown()