12 #include <linux/module.h>
13 #include <linux/types.h>
23 #define MODNAME "tx4939ide"
26 #define TX4939IDE_Data 0x000
27 #define TX4939IDE_Error_Feature 0x001
28 #define TX4939IDE_Sec 0x002
29 #define TX4939IDE_LBA0 0x003
30 #define TX4939IDE_LBA1 0x004
31 #define TX4939IDE_LBA2 0x005
32 #define TX4939IDE_DevHead 0x006
33 #define TX4939IDE_Stat_Cmd 0x007
34 #define TX4939IDE_AltStat_DevCtl 0x402
36 #define TX4939IDE_DMA_Cmd 0x800
37 #define TX4939IDE_DMA_Stat 0x802
38 #define TX4939IDE_PRD_Ptr 0x804
40 #define TX4939IDE_Sys_Ctl 0xc00
41 #define TX4939IDE_Xfer_Cnt_1 0xc08
42 #define TX4939IDE_Xfer_Cnt_2 0xc0a
43 #define TX4939IDE_Sec_Cnt 0xc10
44 #define TX4939IDE_Start_Lo_Addr 0xc18
45 #define TX4939IDE_Start_Up_Addr 0xc20
46 #define TX4939IDE_Add_Ctl 0xc28
47 #define TX4939IDE_Lo_Burst_Cnt 0xc30
48 #define TX4939IDE_Up_Burst_Cnt 0xc38
49 #define TX4939IDE_PIO_Addr 0xc88
50 #define TX4939IDE_H_Rst_Tim 0xc90
51 #define TX4939IDE_Int_Ctl 0xc98
52 #define TX4939IDE_Pkt_Cmd 0xcb8
53 #define TX4939IDE_Bxfer_Cnt_Hi 0xcc0
54 #define TX4939IDE_Bxfer_Cnt_Lo 0xcc8
55 #define TX4939IDE_Dev_TErr 0xcd0
56 #define TX4939IDE_Pkt_Xfer_Ctl 0xcd8
57 #define TX4939IDE_Start_TAddr 0xce0
60 #define TX4939IDE_INT_ADDRERR 0x80
61 #define TX4939IDE_INT_REACHMUL 0x40
62 #define TX4939IDE_INT_DEVTIMING 0x20
63 #define TX4939IDE_INT_UDMATERM 0x10
64 #define TX4939IDE_INT_TIMER 0x08
65 #define TX4939IDE_INT_BUSERR 0x04
66 #define TX4939IDE_INT_XFEREND 0x02
67 #define TX4939IDE_INT_HOST 0x01
69 #define TX4939IDE_IGNORE_INTS \
70 (TX4939IDE_INT_ADDRERR | TX4939IDE_INT_REACHMUL | \
71 TX4939IDE_INT_DEVTIMING | TX4939IDE_INT_UDMATERM | \
72 TX4939IDE_INT_TIMER | TX4939IDE_INT_XFEREND)
75 #define tx4939ide_swizzlel(a) ((a) ^ 4)
76 #define tx4939ide_swizzlew(a) ((a) ^ 6)
77 #define tx4939ide_swizzleb(a) ((a) ^ 7)
79 #define tx4939ide_swizzlel(a) (a)
80 #define tx4939ide_swizzlew(a) (a)
81 #define tx4939ide_swizzleb(a) (a)
96 static void tx4939ide_writew(
u16 val,
void __iomem *base,
u32 reg)
100 static void tx4939ide_writeb(
u8 val,
void __iomem *base,
u32 reg)
105 #define TX4939IDE_BASE(hwif) ((void __iomem *)(hwif)->extra_base)
109 int is_slave = drive->
dn;
115 pair = ide_get_pair_dev(drive);
122 mask = is_slave ? 0x07f00000 : 0x000007f0;
123 val = ((safe << 8) | (pio << 4)) << (is_slave ? 16 : 0);
166 pr_err(
"%s: Error interrupt %#x (%s%s%s )\n",
170 ctl & TX4939IDE_INT_BUSERR ?
" Bus-Error" :
"");
174 static void tx4939ide_clear_irq(
ide_drive_t *drive)
188 ctl = tx4939ide_check_error_ints(hwif);
209 dma_stat |= (1 << (5 +
unit));
211 dma_stat &= ~(1 << (5 +
unit));
216 #define tx4939ide_dma_host_set ide_dma_host_set
219 static u8 tx4939ide_clear_dma_status(
void __iomem *base)
239 unsigned int count = 0;
255 goto use_pio_instead;
257 bcount = 0x10000 - (cur_addr & 0xffff);
258 if (bcount > cur_len)
264 if (bcount == 0x10000)
266 *table++ = bcount & 0xffff;
274 *(table - 2) |= 0x80000000;
280 count ?
"DMA table too small" :
"empty DMA table?");
285 #define tx4939ide_build_dmatable ide_build_dmatable
305 tx4939ide_clear_dma_status(base);
318 u8 dma_stat, dma_cmd;
328 dma_stat = tx4939ide_clear_dma_status(base);
330 #define CHECK_DMA_MASK (ATA_DMA_ACTIVE | ATA_DMA_ERR | ATA_DMA_INTR)
333 if ((dma_stat & CHECK_DMA_MASK) == 0 &&
338 return ((dma_stat & CHECK_DMA_MASK) !=
343 static int tx4939ide_dma_test_irq(
ide_drive_t *drive)
351 ctl = tx4939ide_check_error_ints(hwif);
368 "DMA_Stat %#02x int_ctl %#04x\n",
369 hwif->
name, dma_stat, ctl);
390 #define tx4939ide_dma_sff_read_status ide_dma_sff_read_status
393 static void tx4939ide_init_hwif(
ide_hwif_t *hwif)
422 static void tx4939ide_tf_load_fixup(
ide_drive_t *drive)
443 tx4939ide_tf_load_fixup(drive);
450 void *
buf,
unsigned int len)
452 unsigned long port = drive->
hwif->io_ports.data_addr;
453 unsigned short *
ptr =
buf;
454 unsigned int count = (len + 1) / 2;
458 __ide_flush_dcache_range((
unsigned long)buf,
roundup(len, 2));
462 void *buf,
unsigned int len)
464 unsigned long port = drive->
hwif->io_ports.data_addr;
465 unsigned short *ptr =
buf;
466 unsigned int count = (len + 1) / 2;
472 __ide_flush_dcache_range((
unsigned long)buf,
roundup(len, 2));
475 static const struct ide_tp_ops tx4939ide_tp_ops = {
482 .tf_load = tx4939ide_tf_load,
485 .input_data = tx4939ide_input_data_swap,
486 .output_data = tx4939ide_output_data_swap,
491 static const struct ide_tp_ops tx4939ide_tp_ops = {
498 .tf_load = tx4939ide_tf_load,
508 .set_pio_mode = tx4939ide_set_pio_mode,
509 .set_dma_mode = tx4939ide_set_dma_mode,
510 .clear_irq = tx4939ide_clear_irq,
511 .cable_detect = tx4939ide_cable_detect,
514 static const struct ide_dma_ops tx4939ide_dma_ops = {
516 .dma_setup = tx4939ide_dma_setup,
518 .dma_end = tx4939ide_dma_end,
519 .dma_test_irq = tx4939ide_dma_test_irq,
526 .init_hwif = tx4939ide_init_hwif,
527 .init_dma = tx4939ide_init_dma,
528 .port_ops = &tx4939ide_port_ops,
529 .dma_ops = &tx4939ide_dma_ops,
530 .tp_ops = &tx4939ide_tp_ops,
544 unsigned long mapbase;
554 resource_size(res),
"tx4938ide"))
561 hw.io_ports.data_addr =
563 hw.io_ports.error_addr =
565 hw.io_ports.nsect_addr =
567 hw.io_ports.lbal_addr =
569 hw.io_ports.lbam_addr =
571 hw.io_ports.lbah_addr =
573 hw.io_ports.device_addr =
575 hw.io_ports.command_addr =
577 hw.io_ports.ctl_addr =
582 pr_info(
"TX4939 IDE interface (base %#lx, irq %d)\n", mapbase, irq);
593 platform_set_drvdata(pdev, host);
599 struct ide_host *host = platform_get_drvdata(pdev);
608 struct ide_host *host = platform_get_drvdata(dev);
611 tx4939ide_init_hwif(hwif);
615 #define tx4939ide_resume NULL
623 .remove =
__exit_p(tx4939ide_remove),
627 static int __init tx4939ide_init(
void)
632 static void __exit tx4939ide_exit(
void)