Lines Matching refs:dev
34 static inline uint8_t r852_read_reg(struct r852_device *dev, int address) in r852_read_reg() argument
36 uint8_t reg = readb(dev->mmio + address); in r852_read_reg()
41 static inline void r852_write_reg(struct r852_device *dev, in r852_write_reg() argument
44 writeb(value, dev->mmio + address); in r852_write_reg()
49 static inline uint32_t r852_read_reg_dword(struct r852_device *dev, int address) in r852_read_reg_dword() argument
51 uint32_t reg = le32_to_cpu(readl(dev->mmio + address)); in r852_read_reg_dword()
56 static inline void r852_write_reg_dword(struct r852_device *dev, in r852_write_reg_dword() argument
59 writel(cpu_to_le32(value), dev->mmio + address); in r852_write_reg_dword()
71 static void r852_dma_test(struct r852_device *dev) in r852_dma_test() argument
73 dev->dma_usable = (r852_read_reg(dev, R852_DMA_CAP) & in r852_dma_test()
76 if (!dev->dma_usable) in r852_dma_test()
81 dev->dma_usable = 0; in r852_dma_test()
89 static void r852_dma_enable(struct r852_device *dev) in r852_dma_enable() argument
94 dma_reg = r852_read_reg_dword(dev, R852_DMA_SETTINGS); in r852_dma_enable()
97 if (dev->dma_dir) in r852_dma_enable()
100 if (dev->dma_state == DMA_INTERNAL) { in r852_dma_enable()
104 r852_write_reg_dword(dev, R852_DMA_ADDR, in r852_dma_enable()
105 cpu_to_le32(dev->phys_bounce_buffer)); in r852_dma_enable()
108 r852_write_reg_dword(dev, R852_DMA_ADDR, in r852_dma_enable()
109 cpu_to_le32(dev->phys_dma_addr)); in r852_dma_enable()
113 r852_read_reg_dword(dev, R852_DMA_ADDR); in r852_dma_enable()
115 r852_write_reg_dword(dev, R852_DMA_SETTINGS, dma_reg); in r852_dma_enable()
118 dma_irq_reg = r852_read_reg_dword(dev, R852_DMA_IRQ_ENABLE); in r852_dma_enable()
119 r852_write_reg_dword(dev, R852_DMA_IRQ_ENABLE, in r852_dma_enable()
130 static void r852_dma_done(struct r852_device *dev, int error) in r852_dma_done() argument
132 WARN_ON(dev->dma_stage == 0); in r852_dma_done()
134 r852_write_reg_dword(dev, R852_DMA_IRQ_STA, in r852_dma_done()
135 r852_read_reg_dword(dev, R852_DMA_IRQ_STA)); in r852_dma_done()
137 r852_write_reg_dword(dev, R852_DMA_SETTINGS, 0); in r852_dma_done()
138 r852_write_reg_dword(dev, R852_DMA_IRQ_ENABLE, 0); in r852_dma_done()
141 r852_write_reg_dword(dev, R852_DMA_ADDR, in r852_dma_done()
142 cpu_to_le32(dev->phys_bounce_buffer)); in r852_dma_done()
143 r852_read_reg_dword(dev, R852_DMA_ADDR); in r852_dma_done()
145 dev->dma_error = error; in r852_dma_done()
146 dev->dma_stage = 0; in r852_dma_done()
148 if (dev->phys_dma_addr && dev->phys_dma_addr != dev->phys_bounce_buffer) in r852_dma_done()
149 dma_unmap_single(&dev->pci_dev->dev, dev->phys_dma_addr, in r852_dma_done()
151 dev->dma_dir ? DMA_FROM_DEVICE : DMA_TO_DEVICE); in r852_dma_done()
157 static int r852_dma_wait(struct r852_device *dev) in r852_dma_wait() argument
159 long timeout = wait_for_completion_timeout(&dev->dma_done, in r852_dma_wait()
172 static void r852_do_dma(struct r852_device *dev, uint8_t *buf, int do_read) in r852_do_dma() argument
178 dev->dma_error = 0; in r852_do_dma()
181 dev->dma_dir = do_read; in r852_do_dma()
182 dev->dma_stage = 1; in r852_do_dma()
183 reinit_completion(&dev->dma_done); in r852_do_dma()
189 dev->dma_state = do_read ? DMA_INTERNAL : DMA_MEMORY; in r852_do_dma()
196 dev->phys_dma_addr = dma_map_single(&dev->pci_dev->dev, buf, in r852_do_dma()
199 if (dma_mapping_error(&dev->pci_dev->dev, dev->phys_dma_addr)) in r852_do_dma()
205 dev->phys_dma_addr = dev->phys_bounce_buffer; in r852_do_dma()
207 memcpy(dev->bounce_buffer, buf, R852_DMA_LEN); in r852_do_dma()
211 spin_lock_irqsave(&dev->irqlock, flags); in r852_do_dma()
212 r852_dma_enable(dev); in r852_do_dma()
213 spin_unlock_irqrestore(&dev->irqlock, flags); in r852_do_dma()
216 error = r852_dma_wait(dev); in r852_do_dma()
219 r852_dma_done(dev, error); in r852_do_dma()
224 memcpy((void *)buf, dev->bounce_buffer, R852_DMA_LEN); in r852_do_dma()
232 struct r852_device *dev = r852_get_dev(nand_to_mtd(chip)); in r852_write_buf() local
236 if (dev->card_unstable) in r852_write_buf()
240 if (len == R852_DMA_LEN && dev->dma_usable) { in r852_write_buf()
241 r852_do_dma(dev, (uint8_t *)buf, 0); in r852_write_buf()
248 r852_write_reg_dword(dev, R852_DATALINE, reg); in r852_write_buf()
256 r852_write_reg(dev, R852_DATALINE, *buf++); in r852_write_buf()
266 struct r852_device *dev = r852_get_dev(nand_to_mtd(chip)); in r852_read_buf() local
269 if (dev->card_unstable) { in r852_read_buf()
277 if (len == R852_DMA_LEN && dev->dma_usable) { in r852_read_buf()
278 r852_do_dma(dev, buf, 1); in r852_read_buf()
285 reg = r852_read_reg_dword(dev, R852_DATALINE); in r852_read_buf()
295 *buf++ = r852_read_reg(dev, R852_DATALINE); in r852_read_buf()
303 struct r852_device *dev = r852_get_dev(nand_to_mtd(chip)); in r852_read_byte() local
306 if (dev->card_unstable) in r852_read_byte()
309 return r852_read_reg(dev, R852_DATALINE); in r852_read_byte()
317 struct r852_device *dev = r852_get_dev(nand_to_mtd(chip)); in r852_cmdctl() local
319 if (dev->card_unstable) in r852_cmdctl()
324 dev->ctlreg &= ~(R852_CTL_DATA | R852_CTL_COMMAND | in r852_cmdctl()
328 dev->ctlreg |= R852_CTL_DATA; in r852_cmdctl()
331 dev->ctlreg |= R852_CTL_COMMAND; in r852_cmdctl()
334 dev->ctlreg |= (R852_CTL_CARDENABLE | R852_CTL_ON); in r852_cmdctl()
336 dev->ctlreg &= ~R852_CTL_WRITE; in r852_cmdctl()
340 dev->ctlreg |= R852_CTL_WRITE; in r852_cmdctl()
342 r852_write_reg(dev, R852_CTL, dev->ctlreg); in r852_cmdctl()
347 if (dat == NAND_CMD_SEQIN && (dev->ctlreg & R852_CTL_COMMAND)) { in r852_cmdctl()
348 dev->ctlreg |= R852_CTL_WRITE; in r852_cmdctl()
349 r852_write_reg(dev, R852_CTL, dev->ctlreg); in r852_cmdctl()
353 r852_write_reg(dev, R852_DATALINE, dat); in r852_cmdctl()
362 struct r852_device *dev = nand_get_controller_data(chip); in r852_wait() local
376 if (dev->dma_error) { in r852_wait()
378 dev->dma_error = 0; in r852_wait()
389 struct r852_device *dev = r852_get_dev(nand_to_mtd(chip)); in r852_ready() local
390 return !(r852_read_reg(dev, R852_CARD_STA) & R852_CARD_STA_BUSY); in r852_ready()
400 struct r852_device *dev = r852_get_dev(nand_to_mtd(chip)); in r852_ecc_hwctl() local
402 if (dev->card_unstable) in r852_ecc_hwctl()
409 dev->ctlreg |= R852_CTL_ECC_ENABLE; in r852_ecc_hwctl()
412 r852_write_reg(dev, R852_CTL, in r852_ecc_hwctl()
413 dev->ctlreg | R852_CTL_ECC_ACCESS); in r852_ecc_hwctl()
415 r852_read_reg_dword(dev, R852_DATALINE); in r852_ecc_hwctl()
416 r852_write_reg(dev, R852_CTL, dev->ctlreg); in r852_ecc_hwctl()
421 dev->ctlreg &= ~R852_CTL_ECC_ENABLE; in r852_ecc_hwctl()
422 r852_write_reg(dev, R852_CTL, dev->ctlreg); in r852_ecc_hwctl()
433 struct r852_device *dev = r852_get_dev(nand_to_mtd(chip)); in r852_ecc_calculate() local
437 if (dev->card_unstable) in r852_ecc_calculate()
440 dev->ctlreg &= ~R852_CTL_ECC_ENABLE; in r852_ecc_calculate()
441 r852_write_reg(dev, R852_CTL, dev->ctlreg | R852_CTL_ECC_ACCESS); in r852_ecc_calculate()
443 ecc1 = r852_read_reg_dword(dev, R852_DATALINE); in r852_ecc_calculate()
444 ecc2 = r852_read_reg_dword(dev, R852_DATALINE); in r852_ecc_calculate()
454 r852_write_reg(dev, R852_CTL, dev->ctlreg); in r852_ecc_calculate()
469 struct r852_device *dev = r852_get_dev(nand_to_mtd(chip)); in r852_ecc_correct() local
471 if (dev->card_unstable) in r852_ecc_correct()
474 if (dev->dma_error) { in r852_ecc_correct()
475 dev->dma_error = 0; in r852_ecc_correct()
479 r852_write_reg(dev, R852_CTL, dev->ctlreg | R852_CTL_ECC_ACCESS); in r852_ecc_correct()
480 ecc_reg = r852_read_reg_dword(dev, R852_DATALINE); in r852_ecc_correct()
481 r852_write_reg(dev, R852_CTL, dev->ctlreg); in r852_ecc_correct()
529 static void r852_engine_enable(struct r852_device *dev) in r852_engine_enable() argument
531 if (r852_read_reg_dword(dev, R852_HW) & R852_HW_UNKNOWN) { in r852_engine_enable()
532 r852_write_reg(dev, R852_CTL, R852_CTL_RESET | R852_CTL_ON); in r852_engine_enable()
533 r852_write_reg_dword(dev, R852_HW, R852_HW_ENABLED); in r852_engine_enable()
535 r852_write_reg_dword(dev, R852_HW, R852_HW_ENABLED); in r852_engine_enable()
536 r852_write_reg(dev, R852_CTL, R852_CTL_RESET | R852_CTL_ON); in r852_engine_enable()
539 r852_write_reg(dev, R852_CTL, 0); in r852_engine_enable()
547 static void r852_engine_disable(struct r852_device *dev) in r852_engine_disable() argument
549 r852_write_reg_dword(dev, R852_HW, 0); in r852_engine_disable()
550 r852_write_reg(dev, R852_CTL, R852_CTL_RESET); in r852_engine_disable()
557 static void r852_card_update_present(struct r852_device *dev) in r852_card_update_present() argument
562 spin_lock_irqsave(&dev->irqlock, flags); in r852_card_update_present()
563 reg = r852_read_reg(dev, R852_CARD_STA); in r852_card_update_present()
564 dev->card_detected = !!(reg & R852_CARD_STA_PRESENT); in r852_card_update_present()
565 spin_unlock_irqrestore(&dev->irqlock, flags); in r852_card_update_present()
572 static void r852_update_card_detect(struct r852_device *dev) in r852_update_card_detect() argument
574 int card_detect_reg = r852_read_reg(dev, R852_CARD_IRQ_ENABLE); in r852_update_card_detect()
575 dev->card_unstable = 0; in r852_update_card_detect()
580 card_detect_reg |= dev->card_detected ? in r852_update_card_detect()
583 r852_write_reg(dev, R852_CARD_IRQ_ENABLE, card_detect_reg); in r852_update_card_detect()
589 struct mtd_info *mtd = container_of(sys_dev, struct mtd_info, dev); in media_type_show()
590 struct r852_device *dev = r852_get_dev(mtd); in media_type_show() local
591 char *data = dev->sm ? "smartmedia" : "xd"; in media_type_show()
600 static void r852_update_media_status(struct r852_device *dev) in r852_update_media_status() argument
606 spin_lock_irqsave(&dev->irqlock, flags); in r852_update_media_status()
607 if (!dev->card_detected) { in r852_update_media_status()
609 spin_unlock_irqrestore(&dev->irqlock, flags); in r852_update_media_status()
613 readonly = r852_read_reg(dev, R852_CARD_STA) & R852_CARD_STA_RO; in r852_update_media_status()
614 reg = r852_read_reg(dev, R852_DMA_CAP); in r852_update_media_status()
615 dev->sm = (reg & (R852_DMA1 | R852_DMA2)) && (reg & R852_SMBIT); in r852_update_media_status()
618 dev->sm ? "SmartMedia" : "xD", in r852_update_media_status()
621 dev->readonly = readonly; in r852_update_media_status()
622 spin_unlock_irqrestore(&dev->irqlock, flags); in r852_update_media_status()
629 static int r852_register_nand_device(struct r852_device *dev) in r852_register_nand_device() argument
631 struct mtd_info *mtd = nand_to_mtd(dev->chip); in r852_register_nand_device()
633 WARN_ON(dev->card_registered); in r852_register_nand_device()
635 mtd->dev.parent = &dev->pci_dev->dev; in r852_register_nand_device()
637 if (dev->readonly) in r852_register_nand_device()
638 dev->chip->options |= NAND_ROM; in r852_register_nand_device()
640 r852_engine_enable(dev); in r852_register_nand_device()
642 if (sm_register_device(mtd, dev->sm)) in r852_register_nand_device()
645 if (device_create_file(&mtd->dev, &dev_attr_media_type)) { in r852_register_nand_device()
650 dev->card_registered = 1; in r852_register_nand_device()
653 WARN_ON(mtd_device_unregister(nand_to_mtd(dev->chip))); in r852_register_nand_device()
654 nand_cleanup(dev->chip); in r852_register_nand_device()
657 dev->card_detected = 0; in r852_register_nand_device()
665 static void r852_unregister_nand_device(struct r852_device *dev) in r852_unregister_nand_device() argument
667 struct mtd_info *mtd = nand_to_mtd(dev->chip); in r852_unregister_nand_device()
669 if (!dev->card_registered) in r852_unregister_nand_device()
672 device_remove_file(&mtd->dev, &dev_attr_media_type); in r852_unregister_nand_device()
674 nand_cleanup(dev->chip); in r852_unregister_nand_device()
675 r852_engine_disable(dev); in r852_unregister_nand_device()
676 dev->card_registered = 0; in r852_unregister_nand_device()
682 struct r852_device *dev = in r852_card_detect_work() local
685 r852_card_update_present(dev); in r852_card_detect_work()
686 r852_update_card_detect(dev); in r852_card_detect_work()
687 dev->card_unstable = 0; in r852_card_detect_work()
690 if (dev->card_detected == dev->card_registered) in r852_card_detect_work()
694 r852_update_media_status(dev); in r852_card_detect_work()
697 if (dev->card_detected) in r852_card_detect_work()
698 r852_register_nand_device(dev); in r852_card_detect_work()
700 r852_unregister_nand_device(dev); in r852_card_detect_work()
702 r852_update_card_detect(dev); in r852_card_detect_work()
706 static void r852_disable_irqs(struct r852_device *dev) in r852_disable_irqs() argument
709 reg = r852_read_reg(dev, R852_CARD_IRQ_ENABLE); in r852_disable_irqs()
710 r852_write_reg(dev, R852_CARD_IRQ_ENABLE, reg & ~R852_CARD_IRQ_MASK); in r852_disable_irqs()
712 reg = r852_read_reg_dword(dev, R852_DMA_IRQ_ENABLE); in r852_disable_irqs()
713 r852_write_reg_dword(dev, R852_DMA_IRQ_ENABLE, in r852_disable_irqs()
716 r852_write_reg(dev, R852_CARD_IRQ_STA, R852_CARD_IRQ_MASK); in r852_disable_irqs()
717 r852_write_reg_dword(dev, R852_DMA_IRQ_STA, R852_DMA_IRQ_MASK); in r852_disable_irqs()
723 struct r852_device *dev = (struct r852_device *)data; in r852_irq() local
728 spin_lock(&dev->irqlock); in r852_irq()
731 card_status = r852_read_reg(dev, R852_CARD_IRQ_STA); in r852_irq()
732 r852_write_reg(dev, R852_CARD_IRQ_STA, card_status); in r852_irq()
737 dev->card_detected = !!(card_status & R852_CARD_IRQ_INSERT); in r852_irq()
741 WARN_ON(dev->card_unstable); in r852_irq()
745 r852_disable_irqs(dev); in r852_irq()
747 if (dev->card_unstable) in r852_irq()
751 dev->card_unstable = 1; in r852_irq()
752 queue_delayed_work(dev->card_workqueue, in r852_irq()
753 &dev->card_detect_work, msecs_to_jiffies(100)); in r852_irq()
759 dma_status = r852_read_reg_dword(dev, R852_DMA_IRQ_STA); in r852_irq()
760 r852_write_reg_dword(dev, R852_DMA_IRQ_STA, dma_status); in r852_irq()
768 r852_dma_done(dev, -EIO); in r852_irq()
769 complete(&dev->dma_done); in r852_irq()
774 WARN_ON_ONCE(dev->dma_stage == 0); in r852_irq()
776 if (dev->dma_stage == 0) in r852_irq()
780 if (dev->dma_state == DMA_INTERNAL && in r852_irq()
783 dev->dma_state = DMA_MEMORY; in r852_irq()
784 dev->dma_stage++; in r852_irq()
788 if (dev->dma_state == DMA_MEMORY && in r852_irq()
790 dev->dma_state = DMA_INTERNAL; in r852_irq()
791 dev->dma_stage++; in r852_irq()
795 if (dev->dma_stage == 2) in r852_irq()
796 r852_dma_enable(dev); in r852_irq()
799 if (dev->dma_stage == 3) { in r852_irq()
800 r852_dma_done(dev, 0); in r852_irq()
801 complete(&dev->dma_done); in r852_irq()
814 spin_unlock(&dev->irqlock); in r852_irq()
845 struct r852_device *dev; in r852_probe() local
855 error = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32)); in r852_probe()
883 dev = kzalloc(sizeof(struct r852_device), GFP_KERNEL); in r852_probe()
885 if (!dev) in r852_probe()
888 nand_set_controller_data(chip, dev); in r852_probe()
889 dev->chip = chip; in r852_probe()
890 dev->pci_dev = pci_dev; in r852_probe()
891 pci_set_drvdata(pci_dev, dev); in r852_probe()
893 nand_controller_init(&dev->controller); in r852_probe()
894 dev->controller.ops = &r852_ops; in r852_probe()
895 chip->controller = &dev->controller; in r852_probe()
897 dev->bounce_buffer = dma_alloc_coherent(&pci_dev->dev, R852_DMA_LEN, in r852_probe()
898 &dev->phys_bounce_buffer, GFP_KERNEL); in r852_probe()
900 if (!dev->bounce_buffer) in r852_probe()
905 dev->mmio = pci_ioremap_bar(pci_dev, 0); in r852_probe()
907 if (!dev->mmio) in r852_probe()
911 dev->tmp_buffer = kzalloc(SM_SECTOR_SIZE, GFP_KERNEL); in r852_probe()
913 if (!dev->tmp_buffer) in r852_probe()
916 init_completion(&dev->dma_done); in r852_probe()
918 dev->card_workqueue = create_freezable_workqueue(DRV_NAME); in r852_probe()
920 if (!dev->card_workqueue) in r852_probe()
923 INIT_DELAYED_WORK(&dev->card_detect_work, r852_card_detect_work); in r852_probe()
926 r852_engine_disable(dev); in r852_probe()
927 r852_disable_irqs(dev); in r852_probe()
929 r852_dma_test(dev); in r852_probe()
931 dev->irq = pci_dev->irq; in r852_probe()
932 spin_lock_init(&dev->irqlock); in r852_probe()
934 dev->card_detected = 0; in r852_probe()
935 r852_card_update_present(dev); in r852_probe()
940 DRV_NAME, dev)) in r852_probe()
944 queue_delayed_work(dev->card_workqueue, in r852_probe()
945 &dev->card_detect_work, 0); in r852_probe()
952 destroy_workqueue(dev->card_workqueue); in r852_probe()
954 kfree(dev->tmp_buffer); in r852_probe()
956 pci_iounmap(pci_dev, dev->mmio); in r852_probe()
958 dma_free_coherent(&pci_dev->dev, R852_DMA_LEN, dev->bounce_buffer, in r852_probe()
959 dev->phys_bounce_buffer); in r852_probe()
961 kfree(dev); in r852_probe()
975 struct r852_device *dev = pci_get_drvdata(pci_dev); in r852_remove() local
979 cancel_delayed_work_sync(&dev->card_detect_work); in r852_remove()
980 destroy_workqueue(dev->card_workqueue); in r852_remove()
983 r852_unregister_nand_device(dev); in r852_remove()
986 r852_disable_irqs(dev); in r852_remove()
987 free_irq(dev->irq, dev); in r852_remove()
990 kfree(dev->tmp_buffer); in r852_remove()
991 pci_iounmap(pci_dev, dev->mmio); in r852_remove()
992 dma_free_coherent(&pci_dev->dev, R852_DMA_LEN, dev->bounce_buffer, in r852_remove()
993 dev->phys_bounce_buffer); in r852_remove()
995 kfree(dev->chip); in r852_remove()
996 kfree(dev); in r852_remove()
1005 struct r852_device *dev = pci_get_drvdata(pci_dev); in r852_shutdown() local
1007 cancel_delayed_work_sync(&dev->card_detect_work); in r852_shutdown()
1008 r852_disable_irqs(dev); in r852_shutdown()
1009 synchronize_irq(dev->irq); in r852_shutdown()
1016 struct r852_device *dev = dev_get_drvdata(device); in r852_suspend() local
1018 if (dev->ctlreg & R852_CTL_CARDENABLE) in r852_suspend()
1022 cancel_delayed_work_sync(&dev->card_detect_work); in r852_suspend()
1025 r852_disable_irqs(dev); in r852_suspend()
1026 r852_engine_disable(dev); in r852_suspend()
1031 dev->card_unstable = 0; in r852_suspend()
1037 struct r852_device *dev = dev_get_drvdata(device); in r852_resume() local
1039 r852_disable_irqs(dev); in r852_resume()
1040 r852_card_update_present(dev); in r852_resume()
1041 r852_engine_disable(dev); in r852_resume()
1045 if (dev->card_detected != dev->card_registered) { in r852_resume()
1047 dev->card_detected ? "added" : "removed"); in r852_resume()
1049 queue_delayed_work(dev->card_workqueue, in r852_resume()
1050 &dev->card_detect_work, msecs_to_jiffies(1000)); in r852_resume()
1055 if (dev->card_registered) { in r852_resume()
1056 r852_engine_enable(dev); in r852_resume()
1057 nand_select_target(dev->chip, 0); in r852_resume()
1058 nand_reset_op(dev->chip); in r852_resume()
1059 nand_deselect_target(dev->chip); in r852_resume()
1063 r852_update_card_detect(dev); in r852_resume()