aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-11-27 05:43:40 -0500
committerJeff Garzik <jeff@garzik.org>2008-01-23 05:24:11 -0500
commit70cd071e4ecc06c985189665af75c108601fd5a3 (patch)
treef28aae811d01f8ef44f27e5d469fe330ff834980 /drivers/ata
parent6357357cae7794dcb89cace758108dec612e7ed5 (diff)
libata: clean up xfermode / PATA timing related stuff
* s/ATA_BITS_(PIO|MWDMA|UDMA)/ATA_NR_\1_MODES/g * Consistently use 0xff to indicate invalid transfer mode (0x00 is valid for PIO_SLOW). * Make ata_xfer_mode2mask() return proper mode mask instead of just the highest bit. * Sort ata_timing table in increasing xfermode order and update ata_timing_find_mode() accordingly. This patch doesn't introduce any behavior change. Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/libata-core.c82
1 files changed, 40 insertions, 42 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index a2f2ff864b37..a70ed7b3bc55 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -487,9 +487,9 @@ static const struct ata_xfer_ent {
487 int shift, bits; 487 int shift, bits;
488 u8 base; 488 u8 base;
489} ata_xfer_tbl[] = { 489} ata_xfer_tbl[] = {
490 { ATA_SHIFT_PIO, ATA_BITS_PIO, XFER_PIO_0 }, 490 { ATA_SHIFT_PIO, ATA_NR_PIO_MODES, XFER_PIO_0 },
491 { ATA_SHIFT_MWDMA, ATA_BITS_MWDMA, XFER_MW_DMA_0 }, 491 { ATA_SHIFT_MWDMA, ATA_NR_MWDMA_MODES, XFER_MW_DMA_0 },
492 { ATA_SHIFT_UDMA, ATA_BITS_UDMA, XFER_UDMA_0 }, 492 { ATA_SHIFT_UDMA, ATA_NR_UDMA_MODES, XFER_UDMA_0 },
493 { -1, }, 493 { -1, },
494}; 494};
495 495
@@ -504,7 +504,7 @@ static const struct ata_xfer_ent {
504 * None. 504 * None.
505 * 505 *
506 * RETURNS: 506 * RETURNS:
507 * Matching XFER_* value, 0 if no match found. 507 * Matching XFER_* value, 0xff if no match found.
508 */ 508 */
509u8 ata_xfer_mask2mode(unsigned int xfer_mask) 509u8 ata_xfer_mask2mode(unsigned int xfer_mask)
510{ 510{
@@ -514,7 +514,7 @@ u8 ata_xfer_mask2mode(unsigned int xfer_mask)
514 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) 514 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++)
515 if (highbit >= ent->shift && highbit < ent->shift + ent->bits) 515 if (highbit >= ent->shift && highbit < ent->shift + ent->bits)
516 return ent->base + highbit - ent->shift; 516 return ent->base + highbit - ent->shift;
517 return 0; 517 return 0xff;
518} 518}
519 519
520/** 520/**
@@ -535,7 +535,8 @@ unsigned int ata_xfer_mode2mask(u8 xfer_mode)
535 535
536 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) 536 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++)
537 if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) 537 if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits)
538 return 1 << (ent->shift + xfer_mode - ent->base); 538 return ((2 << (ent->shift + xfer_mode - ent->base)) - 1)
539 & ~((1 << ent->shift) - 1);
539 return 0; 540 return 0;
540} 541}
541 542
@@ -1314,7 +1315,7 @@ void ata_id_to_dma_mode(struct ata_device *dev, u8 unknown)
1314 /* Select the mode in use */ 1315 /* Select the mode in use */
1315 mode = ata_xfer_mask2mode(mask); 1316 mode = ata_xfer_mask2mode(mask);
1316 1317
1317 if (mode != 0) { 1318 if (mode != 0xff) {
1318 ata_dev_printk(dev, KERN_INFO, "configured for %s\n", 1319 ata_dev_printk(dev, KERN_INFO, "configured for %s\n",
1319 ata_mode_string(mask)); 1320 ata_mode_string(mask));
1320 } else { 1321 } else {
@@ -2788,38 +2789,33 @@ int sata_set_spd(struct ata_link *link)
2788 */ 2789 */
2789 2790
2790static const struct ata_timing ata_timing[] = { 2791static const struct ata_timing ata_timing[] = {
2792/* { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 960, 0 }, */
2793 { XFER_PIO_0, 70, 290, 240, 600, 165, 150, 600, 0 },
2794 { XFER_PIO_1, 50, 290, 93, 383, 125, 100, 383, 0 },
2795 { XFER_PIO_2, 30, 290, 40, 330, 100, 90, 240, 0 },
2796 { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 180, 0 },
2797 { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 120, 0 },
2798 { XFER_PIO_5, 15, 65, 25, 100, 65, 25, 100, 0 },
2799 { XFER_PIO_6, 10, 55, 20, 80, 55, 20, 80, 0 },
2791 2800
2792 { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 }, 2801 { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 },
2793 { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 }, 2802 { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 },
2794 { XFER_UDMA_4, 0, 0, 0, 0, 0, 0, 0, 30 }, 2803 { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 },
2795 { XFER_UDMA_3, 0, 0, 0, 0, 0, 0, 0, 45 },
2796 2804
2797 { XFER_MW_DMA_4, 25, 0, 0, 0, 55, 20, 80, 0 }, 2805 { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 },
2806 { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 },
2807 { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 },
2798 { XFER_MW_DMA_3, 25, 0, 0, 0, 65, 25, 100, 0 }, 2808 { XFER_MW_DMA_3, 25, 0, 0, 0, 65, 25, 100, 0 },
2799 { XFER_UDMA_2, 0, 0, 0, 0, 0, 0, 0, 60 }, 2809 { XFER_MW_DMA_4, 25, 0, 0, 0, 55, 20, 80, 0 },
2800 { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 80 },
2801 { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 },
2802 2810
2803/* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */ 2811/* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */
2804 2812 { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 },
2805 { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 }, 2813 { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 80 },
2806 { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 }, 2814 { XFER_UDMA_2, 0, 0, 0, 0, 0, 0, 0, 60 },
2807 { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 }, 2815 { XFER_UDMA_3, 0, 0, 0, 0, 0, 0, 0, 45 },
2808 2816 { XFER_UDMA_4, 0, 0, 0, 0, 0, 0, 0, 30 },
2809 { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 }, 2817 { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 },
2810 { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 }, 2818 { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 },
2811 { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 },
2812
2813 { XFER_PIO_6, 10, 55, 20, 80, 55, 20, 80, 0 },
2814 { XFER_PIO_5, 15, 65, 25, 100, 65, 25, 100, 0 },
2815 { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 120, 0 },
2816 { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 180, 0 },
2817
2818 { XFER_PIO_2, 30, 290, 40, 330, 100, 90, 240, 0 },
2819 { XFER_PIO_1, 50, 290, 93, 383, 125, 100, 383, 0 },
2820 { XFER_PIO_0, 70, 290, 240, 600, 165, 150, 600, 0 },
2821
2822/* { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 960, 0 }, */
2823 2819
2824 { 0xFF } 2820 { 0xFF }
2825}; 2821};
@@ -2854,12 +2850,14 @@ void ata_timing_merge(const struct ata_timing *a, const struct ata_timing *b,
2854 2850
2855const struct ata_timing *ata_timing_find_mode(u8 xfer_mode) 2851const struct ata_timing *ata_timing_find_mode(u8 xfer_mode)
2856{ 2852{
2857 const struct ata_timing *t; 2853 const struct ata_timing *t = ata_timing;
2854
2855 while (xfer_mode > t->mode)
2856 t++;
2858 2857
2859 for (t = ata_timing; t->mode != xfer_mode; t++) 2858 if (xfer_mode == t->mode)
2860 if (t->mode == 0xFF) 2859 return t;
2861 return NULL; 2860 return NULL;
2862 return t;
2863} 2861}
2864 2862
2865int ata_timing_compute(struct ata_device *adev, unsigned short speed, 2863int ata_timing_compute(struct ata_device *adev, unsigned short speed,
@@ -3122,7 +3120,7 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3122 dev->dma_mode = ata_xfer_mask2mode(dma_mask); 3120 dev->dma_mode = ata_xfer_mask2mode(dma_mask);
3123 3121
3124 found = 1; 3122 found = 1;
3125 if (dev->dma_mode) 3123 if (dev->dma_mode != 0xff)
3126 used_dma = 1; 3124 used_dma = 1;
3127 } 3125 }
3128 if (!found) 3126 if (!found)
@@ -3133,7 +3131,7 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3133 if (!ata_dev_enabled(dev)) 3131 if (!ata_dev_enabled(dev))
3134 continue; 3132 continue;
3135 3133
3136 if (!dev->pio_mode) { 3134 if (dev->pio_mode == 0xff) {
3137 ata_dev_printk(dev, KERN_WARNING, "no PIO support\n"); 3135 ata_dev_printk(dev, KERN_WARNING, "no PIO support\n");
3138 rc = -EINVAL; 3136 rc = -EINVAL;
3139 goto out; 3137 goto out;
@@ -3147,7 +3145,7 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3147 3145
3148 /* step 3: set host DMA timings */ 3146 /* step 3: set host DMA timings */
3149 ata_link_for_each_dev(dev, link) { 3147 ata_link_for_each_dev(dev, link) {
3150 if (!ata_dev_enabled(dev) || !dev->dma_mode) 3148 if (!ata_dev_enabled(dev) || dev->dma_mode == 0xff)
3151 continue; 3149 continue;
3152 3150
3153 dev->xfer_mode = dev->dma_mode; 3151 dev->xfer_mode = dev->dma_mode;