diff options
author | Alex Dubov <oakad@yahoo.com> | 2007-04-12 02:59:23 -0400 |
---|---|---|
committer | Pierre Ossman <drzeus@drzeus.cx> | 2007-05-01 07:04:14 -0400 |
commit | 0007d4837ac94d672f313cfc462f879b5d06f221 (patch) | |
tree | 4c4b0b816f572dc7be56351ed0a1dacd6faa6d82 /drivers/mmc/tifm_sd.c | |
parent | 592d372ae89dd5b43117cf5113a910f67f6e6a7e (diff) |
tifm_sd: separate command flags, socket flags and register bit masks
host->flags variable was hosting a collection of bits with different
semantics. For clarity, hardware bit masks are now defined as macros,
socket flags represented as bit fields and flags (now cmd_flags) only
hosts command processing modifiers.
Signed-off-by: Alex Dubov <oakad@yahoo.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
Diffstat (limited to 'drivers/mmc/tifm_sd.c')
-rw-r--r-- | drivers/mmc/tifm_sd.c | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/drivers/mmc/tifm_sd.c b/drivers/mmc/tifm_sd.c index bf00e8cf670c..fe8cb1aa681f 100644 --- a/drivers/mmc/tifm_sd.c +++ b/drivers/mmc/tifm_sd.c | |||
@@ -50,6 +50,9 @@ module_param(fixed_timeout, bool, 0644); | |||
50 | #define TIFM_MMCSD_AE 0x0800 /* fifo almost empty */ | 50 | #define TIFM_MMCSD_AE 0x0800 /* fifo almost empty */ |
51 | #define TIFM_MMCSD_CERR 0x4000 /* card status error */ | 51 | #define TIFM_MMCSD_CERR 0x4000 /* card status error */ |
52 | 52 | ||
53 | #define TIFM_MMCSD_ODTO 0x0040 /* open drain / extended timeout */ | ||
54 | #define TIFM_MMCSD_CARD_RO 0x0200 /* card is read-only */ | ||
55 | |||
53 | #define TIFM_MMCSD_FIFO_SIZE 0x0020 | 56 | #define TIFM_MMCSD_FIFO_SIZE 0x0020 |
54 | 57 | ||
55 | #define TIFM_MMCSD_RSP_R0 0x0000 | 58 | #define TIFM_MMCSD_RSP_R0 0x0000 |
@@ -79,17 +82,16 @@ typedef enum { | |||
79 | 82 | ||
80 | enum { | 83 | enum { |
81 | FIFO_RDY = 0x0001, /* hardware dependent value */ | 84 | FIFO_RDY = 0x0001, /* hardware dependent value */ |
82 | EJECT = 0x0004, | 85 | CARD_BUSY = 0x0010 |
83 | CARD_BUSY = 0x0010, | 86 | }; |
84 | OPENDRAIN = 0x0040, /* hardware dependent value */ | ||
85 | CARD_EVENT = 0x0100, /* hardware dependent value */ | ||
86 | CARD_RO = 0x0200, /* hardware dependent value */ | ||
87 | FIFO_EVENT = 0x10000 }; /* hardware dependent value */ | ||
88 | 87 | ||
89 | struct tifm_sd { | 88 | struct tifm_sd { |
90 | struct tifm_dev *dev; | 89 | struct tifm_dev *dev; |
91 | 90 | ||
92 | unsigned int flags; | 91 | unsigned short eject:1, |
92 | open_drain:1, | ||
93 | no_dma:1; | ||
94 | unsigned short cmd_flags; | ||
93 | card_state_t state; | 95 | card_state_t state; |
94 | unsigned int clk_freq; | 96 | unsigned int clk_freq; |
95 | unsigned int clk_div; | 97 | unsigned int clk_div; |
@@ -119,7 +121,7 @@ static int tifm_sd_transfer_data(struct tifm_dev *sock, struct tifm_sd *host, | |||
119 | 121 | ||
120 | if (host_status & TIFM_MMCSD_BRS) { | 122 | if (host_status & TIFM_MMCSD_BRS) { |
121 | /* in non-dma rx mode BRS fires when fifo is still not empty */ | 123 | /* in non-dma rx mode BRS fires when fifo is still not empty */ |
122 | if (no_dma && (cmd->data->flags & MMC_DATA_READ)) { | 124 | if (host->no_dma && (cmd->data->flags & MMC_DATA_READ)) { |
123 | buffer = tifm_sd_data_buffer(host->req->data); | 125 | buffer = tifm_sd_data_buffer(host->req->data); |
124 | while (host->buffer_size > host->buffer_pos) { | 126 | while (host->buffer_size > host->buffer_pos) { |
125 | t_val = readl(sock->addr + SOCK_MMCSD_DATA); | 127 | t_val = readl(sock->addr + SOCK_MMCSD_DATA); |
@@ -129,7 +131,7 @@ static int tifm_sd_transfer_data(struct tifm_dev *sock, struct tifm_sd *host, | |||
129 | } | 131 | } |
130 | } | 132 | } |
131 | return 1; | 133 | return 1; |
132 | } else if (no_dma) { | 134 | } else if (host->no_dma) { |
133 | buffer = tifm_sd_data_buffer(host->req->data); | 135 | buffer = tifm_sd_data_buffer(host->req->data); |
134 | if ((cmd->data->flags & MMC_DATA_READ) && | 136 | if ((cmd->data->flags & MMC_DATA_READ) && |
135 | (host_status & TIFM_MMCSD_AF)) { | 137 | (host_status & TIFM_MMCSD_AF)) { |
@@ -204,8 +206,10 @@ static unsigned int tifm_sd_op_flags(struct mmc_command *cmd) | |||
204 | static void tifm_sd_exec(struct tifm_sd *host, struct mmc_command *cmd) | 206 | static void tifm_sd_exec(struct tifm_sd *host, struct mmc_command *cmd) |
205 | { | 207 | { |
206 | struct tifm_dev *sock = host->dev; | 208 | struct tifm_dev *sock = host->dev; |
207 | unsigned int cmd_mask = tifm_sd_op_flags(cmd) | | 209 | unsigned int cmd_mask = tifm_sd_op_flags(cmd); |
208 | (host->flags & OPENDRAIN); | 210 | |
211 | if (host->open_drain) | ||
212 | cmd_mask |= TIFM_MMCSD_ODTO; | ||
209 | 213 | ||
210 | if (cmd->data && (cmd->data->flags & MMC_DATA_READ)) | 214 | if (cmd->data && (cmd->data->flags & MMC_DATA_READ)) |
211 | cmd_mask |= TIFM_MMCSD_READ; | 215 | cmd_mask |= TIFM_MMCSD_READ; |
@@ -255,7 +259,7 @@ change_state: | |||
255 | if (cmd->data->flags & MMC_DATA_WRITE) { | 259 | if (cmd->data->flags & MMC_DATA_WRITE) { |
256 | host->state = CARD; | 260 | host->state = CARD; |
257 | } else { | 261 | } else { |
258 | if (no_dma) { | 262 | if (host->no_dma) { |
259 | if (host->req->stop) { | 263 | if (host->req->stop) { |
260 | tifm_sd_exec(host, host->req->stop); | 264 | tifm_sd_exec(host, host->req->stop); |
261 | host->state = SCMD; | 265 | host->state = SCMD; |
@@ -279,9 +283,9 @@ change_state: | |||
279 | case CARD: | 283 | case CARD: |
280 | dev_dbg(&sock->dev, "waiting for CARD, have %zd blocks\n", | 284 | dev_dbg(&sock->dev, "waiting for CARD, have %zd blocks\n", |
281 | host->written_blocks); | 285 | host->written_blocks); |
282 | if (!(host->flags & CARD_BUSY) | 286 | if (!(host->cmd_flags & CARD_BUSY) |
283 | && (host->written_blocks == cmd->data->blocks)) { | 287 | && (host->written_blocks == cmd->data->blocks)) { |
284 | if (no_dma) { | 288 | if (host->no_dma) { |
285 | if (host->req->stop) { | 289 | if (host->req->stop) { |
286 | tifm_sd_exec(host, host->req->stop); | 290 | tifm_sd_exec(host, host->req->stop); |
287 | host->state = SCMD; | 291 | host->state = SCMD; |
@@ -295,8 +299,8 @@ change_state: | |||
295 | } | 299 | } |
296 | break; | 300 | break; |
297 | case FIFO: | 301 | case FIFO: |
298 | if (host->flags & FIFO_RDY) { | 302 | if (host->cmd_flags & FIFO_RDY) { |
299 | host->flags &= ~FIFO_RDY; | 303 | host->cmd_flags &= ~FIFO_RDY; |
300 | if (host->req->stop) { | 304 | if (host->req->stop) { |
301 | tifm_sd_exec(host, host->req->stop); | 305 | tifm_sd_exec(host, host->req->stop); |
302 | host->state = SCMD; | 306 | host->state = SCMD; |
@@ -325,7 +329,7 @@ static void tifm_sd_data_event(struct tifm_dev *sock) | |||
325 | fifo_status = readl(sock->addr + SOCK_DMA_FIFO_STATUS); | 329 | fifo_status = readl(sock->addr + SOCK_DMA_FIFO_STATUS); |
326 | writel(fifo_status, sock->addr + SOCK_DMA_FIFO_STATUS); | 330 | writel(fifo_status, sock->addr + SOCK_DMA_FIFO_STATUS); |
327 | 331 | ||
328 | host->flags |= fifo_status & FIFO_RDY; | 332 | host->cmd_flags |= fifo_status & FIFO_RDY; |
329 | 333 | ||
330 | if (host->req) | 334 | if (host->req) |
331 | tifm_sd_process_cmd(sock, host, 0); | 335 | tifm_sd_process_cmd(sock, host, 0); |
@@ -383,11 +387,11 @@ static void tifm_sd_card_event(struct tifm_dev *sock) | |||
383 | } | 387 | } |
384 | 388 | ||
385 | if (host_status & TIFM_MMCSD_CB) | 389 | if (host_status & TIFM_MMCSD_CB) |
386 | host->flags |= CARD_BUSY; | 390 | host->cmd_flags |= CARD_BUSY; |
387 | if ((host_status & TIFM_MMCSD_EOFB) | 391 | if ((host_status & TIFM_MMCSD_EOFB) |
388 | && (host->flags & CARD_BUSY)) { | 392 | && (host->cmd_flags & CARD_BUSY)) { |
389 | host->written_blocks++; | 393 | host->written_blocks++; |
390 | host->flags &= ~CARD_BUSY; | 394 | host->cmd_flags &= ~CARD_BUSY; |
391 | } | 395 | } |
392 | 396 | ||
393 | if (host->req) | 397 | if (host->req) |
@@ -466,7 +470,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
466 | struct mmc_data *r_data = mrq->cmd->data; | 470 | struct mmc_data *r_data = mrq->cmd->data; |
467 | 471 | ||
468 | spin_lock_irqsave(&sock->lock, flags); | 472 | spin_lock_irqsave(&sock->lock, flags); |
469 | if (host->flags & EJECT) { | 473 | if (host->eject) { |
470 | spin_unlock_irqrestore(&sock->lock, flags); | 474 | spin_unlock_irqrestore(&sock->lock, flags); |
471 | goto err_out; | 475 | goto err_out; |
472 | } | 476 | } |
@@ -491,7 +495,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
491 | } | 495 | } |
492 | 496 | ||
493 | host->written_blocks = 0; | 497 | host->written_blocks = 0; |
494 | host->flags &= ~CARD_BUSY; | 498 | host->cmd_flags &= ~CARD_BUSY; |
495 | tifm_sd_prepare_data(host, mrq->cmd); | 499 | tifm_sd_prepare_data(host, mrq->cmd); |
496 | } | 500 | } |
497 | 501 | ||
@@ -568,7 +572,7 @@ static void tifm_sd_request_nodma(struct mmc_host *mmc, struct mmc_request *mrq) | |||
568 | struct mmc_data *r_data = mrq->cmd->data; | 572 | struct mmc_data *r_data = mrq->cmd->data; |
569 | 573 | ||
570 | spin_lock_irqsave(&sock->lock, flags); | 574 | spin_lock_irqsave(&sock->lock, flags); |
571 | if (host->flags & EJECT) { | 575 | if (host->eject) { |
572 | spin_unlock_irqrestore(&sock->lock, flags); | 576 | spin_unlock_irqrestore(&sock->lock, flags); |
573 | goto err_out; | 577 | goto err_out; |
574 | } | 578 | } |
@@ -593,7 +597,7 @@ static void tifm_sd_request_nodma(struct mmc_host *mmc, struct mmc_request *mrq) | |||
593 | sock->addr + SOCK_MMCSD_BUFFER_CONFIG); | 597 | sock->addr + SOCK_MMCSD_BUFFER_CONFIG); |
594 | 598 | ||
595 | host->written_blocks = 0; | 599 | host->written_blocks = 0; |
596 | host->flags &= ~CARD_BUSY; | 600 | host->cmd_flags &= ~CARD_BUSY; |
597 | host->buffer_pos = 0; | 601 | host->buffer_pos = 0; |
598 | writel(r_data->blocks - 1, sock->addr + SOCK_MMCSD_NUM_BLOCKS); | 602 | writel(r_data->blocks - 1, sock->addr + SOCK_MMCSD_NUM_BLOCKS); |
599 | writel(r_data->blksz - 1, sock->addr + SOCK_MMCSD_BLOCK_LEN); | 603 | writel(r_data->blksz - 1, sock->addr + SOCK_MMCSD_BLOCK_LEN); |
@@ -728,10 +732,7 @@ static void tifm_sd_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
728 | & readl(sock->addr + SOCK_MMCSD_CONFIG)), | 732 | & readl(sock->addr + SOCK_MMCSD_CONFIG)), |
729 | sock->addr + SOCK_MMCSD_CONFIG); | 733 | sock->addr + SOCK_MMCSD_CONFIG); |
730 | 734 | ||
731 | if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) | 735 | host->open_drain = (ios->bus_mode == MMC_BUSMODE_OPENDRAIN); |
732 | host->flags |= OPENDRAIN; | ||
733 | else | ||
734 | host->flags &= ~OPENDRAIN; | ||
735 | 736 | ||
736 | /* chip_select : maybe later */ | 737 | /* chip_select : maybe later */ |
737 | //vdd | 738 | //vdd |
@@ -742,16 +743,14 @@ static void tifm_sd_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
742 | 743 | ||
743 | static int tifm_sd_ro(struct mmc_host *mmc) | 744 | static int tifm_sd_ro(struct mmc_host *mmc) |
744 | { | 745 | { |
745 | int rc; | 746 | int rc = 0; |
746 | struct tifm_sd *host = mmc_priv(mmc); | 747 | struct tifm_sd *host = mmc_priv(mmc); |
747 | struct tifm_dev *sock = host->dev; | 748 | struct tifm_dev *sock = host->dev; |
748 | unsigned long flags; | 749 | unsigned long flags; |
749 | 750 | ||
750 | spin_lock_irqsave(&sock->lock, flags); | 751 | spin_lock_irqsave(&sock->lock, flags); |
751 | 752 | if (TIFM_MMCSD_CARD_RO & readl(sock->addr + SOCK_PRESENT_STATE)) | |
752 | host->flags |= (CARD_RO & readl(sock->addr + SOCK_PRESENT_STATE)); | 753 | rc = 1; |
753 | rc = (host->flags & CARD_RO) ? 1 : 0; | ||
754 | |||
755 | spin_unlock_irqrestore(&sock->lock, flags); | 754 | spin_unlock_irqrestore(&sock->lock, flags); |
756 | return rc; | 755 | return rc; |
757 | } | 756 | } |
@@ -842,16 +841,17 @@ static int tifm_sd_probe(struct tifm_dev *sock) | |||
842 | return -ENOMEM; | 841 | return -ENOMEM; |
843 | 842 | ||
844 | host = mmc_priv(mmc); | 843 | host = mmc_priv(mmc); |
844 | host->no_dma = no_dma; | ||
845 | tifm_set_drvdata(sock, mmc); | 845 | tifm_set_drvdata(sock, mmc); |
846 | host->dev = sock; | 846 | host->dev = sock; |
847 | host->timeout_jiffies = msecs_to_jiffies(1000); | 847 | host->timeout_jiffies = msecs_to_jiffies(1000); |
848 | 848 | ||
849 | tasklet_init(&host->finish_tasklet, | 849 | tasklet_init(&host->finish_tasklet, |
850 | no_dma ? tifm_sd_end_cmd_nodma : tifm_sd_end_cmd, | 850 | host->no_dma ? tifm_sd_end_cmd_nodma : tifm_sd_end_cmd, |
851 | (unsigned long)host); | 851 | (unsigned long)host); |
852 | setup_timer(&host->timer, tifm_sd_abort, (unsigned long)host); | 852 | setup_timer(&host->timer, tifm_sd_abort, (unsigned long)host); |
853 | 853 | ||
854 | tifm_sd_ops.request = no_dma ? tifm_sd_request_nodma : tifm_sd_request; | 854 | tifm_sd_ops.request = host->no_dma ? tifm_sd_request_nodma : tifm_sd_request; |
855 | mmc->ops = &tifm_sd_ops; | 855 | mmc->ops = &tifm_sd_ops; |
856 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; | 856 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; |
857 | mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE; | 857 | mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE; |
@@ -888,7 +888,7 @@ static void tifm_sd_remove(struct tifm_dev *sock) | |||
888 | unsigned long flags; | 888 | unsigned long flags; |
889 | 889 | ||
890 | spin_lock_irqsave(&sock->lock, flags); | 890 | spin_lock_irqsave(&sock->lock, flags); |
891 | host->flags |= EJECT; | 891 | host->eject = 1; |
892 | writel(0, sock->addr + SOCK_MMCSD_INT_ENABLE); | 892 | writel(0, sock->addr + SOCK_MMCSD_INT_ENABLE); |
893 | mmiowb(); | 893 | mmiowb(); |
894 | spin_unlock_irqrestore(&sock->lock, flags); | 894 | spin_unlock_irqrestore(&sock->lock, flags); |