diff options
author | Tejun Heo <htejun@gmail.com> | 2006-04-11 09:22:29 -0400 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2006-04-11 13:19:11 -0400 |
commit | c22daff41001e9ccead87179ac0547f85447139e (patch) | |
tree | b8faa6e19419704c19f07a9f7043ab2435f719df /drivers/scsi/libata-core.c | |
parent | 643be977f9feba8c3c1e768fc06cac84596ec6f8 (diff) |
[PATCH] libata: implement ata_wait_register()
As waiting for some register bits to change seems to be a common
operation shared by some controllers, implement helper function
ata_wait_register(). This function also takes care of register write
flushing.
Note that the condition is inverted, the wait is over when the masked
value does NOT match @val. As we're waiting for bits to change, this
test is more powerful and allows the function to be used in more
places.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r-- | drivers/scsi/libata-core.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index 2d76ce23728f..0075fe7404d5 100644 --- a/drivers/scsi/libata-core.c +++ b/drivers/scsi/libata-core.c | |||
@@ -5029,6 +5029,52 @@ int ata_ratelimit(void) | |||
5029 | return rc; | 5029 | return rc; |
5030 | } | 5030 | } |
5031 | 5031 | ||
5032 | /** | ||
5033 | * ata_wait_register - wait until register value changes | ||
5034 | * @reg: IO-mapped register | ||
5035 | * @mask: Mask to apply to read register value | ||
5036 | * @val: Wait condition | ||
5037 | * @interval_msec: polling interval in milliseconds | ||
5038 | * @timeout_msec: timeout in milliseconds | ||
5039 | * | ||
5040 | * Waiting for some bits of register to change is a common | ||
5041 | * operation for ATA controllers. This function reads 32bit LE | ||
5042 | * IO-mapped register @reg and tests for the following condition. | ||
5043 | * | ||
5044 | * (*@reg & mask) != val | ||
5045 | * | ||
5046 | * If the condition is met, it returns; otherwise, the process is | ||
5047 | * repeated after @interval_msec until timeout. | ||
5048 | * | ||
5049 | * LOCKING: | ||
5050 | * Kernel thread context (may sleep) | ||
5051 | * | ||
5052 | * RETURNS: | ||
5053 | * The final register value. | ||
5054 | */ | ||
5055 | u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val, | ||
5056 | unsigned long interval_msec, | ||
5057 | unsigned long timeout_msec) | ||
5058 | { | ||
5059 | unsigned long timeout; | ||
5060 | u32 tmp; | ||
5061 | |||
5062 | tmp = ioread32(reg); | ||
5063 | |||
5064 | /* Calculate timeout _after_ the first read to make sure | ||
5065 | * preceding writes reach the controller before starting to | ||
5066 | * eat away the timeout. | ||
5067 | */ | ||
5068 | timeout = jiffies + (timeout_msec * HZ) / 1000; | ||
5069 | |||
5070 | while ((tmp & mask) == val && time_before(jiffies, timeout)) { | ||
5071 | msleep(interval_msec); | ||
5072 | tmp = ioread32(reg); | ||
5073 | } | ||
5074 | |||
5075 | return tmp; | ||
5076 | } | ||
5077 | |||
5032 | /* | 5078 | /* |
5033 | * libata is essentially a library of internal helper functions for | 5079 | * libata is essentially a library of internal helper functions for |
5034 | * low-level ATA host controller drivers. As such, the API/ABI is | 5080 | * low-level ATA host controller drivers. As such, the API/ABI is |
@@ -5079,6 +5125,7 @@ EXPORT_SYMBOL_GPL(ata_dev_classify); | |||
5079 | EXPORT_SYMBOL_GPL(ata_dev_pair); | 5125 | EXPORT_SYMBOL_GPL(ata_dev_pair); |
5080 | EXPORT_SYMBOL_GPL(ata_port_disable); | 5126 | EXPORT_SYMBOL_GPL(ata_port_disable); |
5081 | EXPORT_SYMBOL_GPL(ata_ratelimit); | 5127 | EXPORT_SYMBOL_GPL(ata_ratelimit); |
5128 | EXPORT_SYMBOL_GPL(ata_wait_register); | ||
5082 | EXPORT_SYMBOL_GPL(ata_busy_sleep); | 5129 | EXPORT_SYMBOL_GPL(ata_busy_sleep); |
5083 | EXPORT_SYMBOL_GPL(ata_port_queue_task); | 5130 | EXPORT_SYMBOL_GPL(ata_port_queue_task); |
5084 | EXPORT_SYMBOL_GPL(ata_scsi_ioctl); | 5131 | EXPORT_SYMBOL_GPL(ata_scsi_ioctl); |