Lines Matching +full:no +full:- +full:mmc

1 // SPDX-License-Identifier: GPL-2.0-only
3 * cb710/mmc.c
5 * Copyright by Michał Mirosław, 2008-2009
11 #include "cb710-mmc.h"
20 (ARRAY_SIZE(cb710_clock_divider_log2) - 1)
27 static void cb710_mmc_select_clock_divider(struct mmc_host *mmc, int hz) in cb710_mmc_select_clock_divider() argument
29 struct cb710_slot *slot = cb710_mmc_to_slot(mmc); in cb710_mmc_select_clock_divider()
30 struct pci_dev *pdev = cb710_slot_to_chip(slot)->pdev; in cb710_mmc_select_clock_divider()
37 * indexes 1-7 work as written in the table in cb710_mmc_select_clock_divider()
38 * indexes 0,8-15 give no clock output in cb710_mmc_select_clock_divider()
66 * - it gets set later if any interrupt sources are enabled */ in __cb710_mmc_enable_irq()
71 * -> bit 15 port 0x0C seems to be global interrupt enable in __cb710_mmc_enable_irq()
89 spin_lock_irqsave(&reader->irq_lock, flags); in cb710_mmc_enable_irq()
92 spin_unlock_irqrestore(&reader->irq_lock, flags); in cb710_mmc_enable_irq()
133 return -EIO; in cb710_check_event()
156 if (!--limit) { in cb710_wait_for_event()
159 err = -ETIMEDOUT; in cb710_wait_for_event()
168 limit = 2000000 - limit; in cb710_wait_for_event()
189 if (!--limit) { in cb710_wait_while_busy()
192 err = -ETIMEDOUT; in cb710_wait_while_busy()
201 limit = 500000 - limit; in cb710_wait_while_busy()
215 ((count - 1) << 16)|(blocksize - 1)); in cb710_mmc_set_transfer_size()
223 /* without this, received data is prepended with 8-bytes of zeroes */ in cb710_mmc_fifo_hack()
237 "FIFO-read-hack: expected STATUS0 bit was %s\n", in cb710_mmc_fifo_hack()
240 "FIFO-read-hack: dwords ignored: %08X %08X - %s\n", in cb710_mmc_fifo_hack()
255 slot->iobase + CB710_MMC_DATA_PORT, dw_count); in cb710_mmc_receive_pio()
262 return !(data->blksz & 15 && (data->blocks != 1 || data->blksz != 8)); in cb710_is_transfer_size_supported()
268 size_t len, blocks = data->blocks; in cb710_mmc_receive()
271 /* TODO: I don't know how/if the hardware handles non-16B-boundary blocks in cb710_mmc_receive()
273 if (unlikely(data->blksz & 15 && (data->blocks != 1 || data->blksz != 8))) in cb710_mmc_receive()
274 return -EINVAL; in cb710_mmc_receive()
276 sg_miter_start(&miter, data->sg, data->sg_len, SG_MITER_TO_SG); in cb710_mmc_receive()
283 while (blocks-- > 0) { in cb710_mmc_receive()
284 len = data->blksz; in cb710_mmc_receive()
290 len -= 16; in cb710_mmc_receive()
297 len - 1, CB710_MMC_C2_READ_PIO_SIZE_MASK); in cb710_mmc_receive()
312 size_t len, blocks = data->blocks; in cb710_mmc_send()
316 * non-16B-boundary blocks */ in cb710_mmc_send()
317 if (unlikely(data->blocks > 1 && data->blksz & 15)) in cb710_mmc_send()
318 return -EINVAL; in cb710_mmc_send()
320 sg_miter_start(&miter, data->sg, data->sg_len, SG_MITER_FROM_SG); in cb710_mmc_send()
325 while (blocks-- > 0) { in cb710_mmc_send()
326 len = (data->blksz + 15) >> 4; in cb710_mmc_send()
336 slot->iobase + CB710_MMC_DATA_PORT, 4); in cb710_mmc_send()
337 } while (--len); in cb710_mmc_send()
347 unsigned int flags = cmd->flags; in cb710_encode_cmd_flags()
350 /* Windows driver returned 0 for commands for which no response in cb710_encode_cmd_flags()
355 * Original driver set bit 14 for MMC/SD application in cb710_encode_cmd_flags()
356 * commands. There's no difference 'on the wire' and in cb710_encode_cmd_flags()
370 cb_flags |= cmd->opcode << CB710_MMC_CMD_CODE_SHIFT; in cb710_encode_cmd_flags()
372 if (cmd->data && (cmd->data->flags & MMC_DATA_READ)) in cb710_encode_cmd_flags()
382 * I assume that 00 here means no response is expected. in cb710_encode_cmd_flags()
401 if (cmd->flags & MMC_RSP_136) { in cb710_receive_response()
410 cmd->resp[0] = (resp[0] << 8)|(resp[1] >> 24); in cb710_receive_response()
411 cmd->resp[1] = (resp[1] << 8)|(resp[2] >> 24); in cb710_receive_response()
412 cmd->resp[2] = (resp[2] << 8)|(resp[3] >> 24); in cb710_receive_response()
413 cmd->resp[3] = (resp[3] << 8); in cb710_receive_response()
416 cmd->resp[0] = cb710_read_port_32(slot, CB710_MMC_RESPONSE0_PORT); in cb710_receive_response()
419 wanted_opcode = (cmd->flags & MMC_RSP_OPCODE) ? cmd->opcode : 0x3F; in cb710_receive_response()
421 cmd->error = -EILSEQ; in cb710_receive_response()
429 if (data->flags & MMC_DATA_READ) in cb710_mmc_transfer_data()
439 data->bytes_xfered = data->blksz * data->blocks; in cb710_mmc_transfer_data()
443 static int cb710_mmc_command(struct mmc_host *mmc, struct mmc_command *cmd) in cb710_mmc_command() argument
445 struct cb710_slot *slot = cb710_mmc_to_slot(mmc); in cb710_mmc_command()
446 struct cb710_mmc_reader *reader = mmc_priv(mmc); in cb710_mmc_command()
447 struct mmc_data *data = cmd->data; in cb710_mmc_command()
454 data->error = -EINVAL; in cb710_mmc_command()
455 return -1; in cb710_mmc_command()
457 cb710_mmc_set_transfer_size(slot, data->blocks, data->blksz); in cb710_mmc_command()
463 cb710_write_port_32(slot, CB710_MMC_CMD_PARAM_PORT, cmd->arg); in cb710_mmc_command()
468 cmd->error = cb710_wait_for_event(slot, CB710_MMC_S1_COMMAND_SENT); in cb710_mmc_command()
469 if (cmd->error) in cb710_mmc_command()
470 return -1; in cb710_mmc_command()
472 if (cmd->flags & MMC_RSP_PRESENT) { in cb710_mmc_command()
474 if (cmd->error) in cb710_mmc_command()
475 return -1; in cb710_mmc_command()
479 data->error = cb710_mmc_transfer_data(slot, data); in cb710_mmc_command()
483 static void cb710_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq) in cb710_mmc_request() argument
485 struct cb710_slot *slot = cb710_mmc_to_slot(mmc); in cb710_mmc_request()
486 struct cb710_mmc_reader *reader = mmc_priv(mmc); in cb710_mmc_request()
488 WARN_ON(reader->mrq != NULL); in cb710_mmc_request()
490 reader->mrq = mrq; in cb710_mmc_request()
493 if (!cb710_mmc_command(mmc, mrq->cmd) && mrq->stop) in cb710_mmc_request()
494 cb710_mmc_command(mmc, mrq->stop); in cb710_mmc_request()
496 queue_work(system_bh_wq, &reader->finish_req_bh_work); in cb710_mmc_request()
545 * (it doesn't depend on write-to-read delay) */ in cb710_mmc_powerup()
560 static void cb710_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) in cb710_mmc_set_ios() argument
562 struct cb710_slot *slot = cb710_mmc_to_slot(mmc); in cb710_mmc_set_ios()
563 struct cb710_mmc_reader *reader = mmc_priv(mmc); in cb710_mmc_set_ios()
566 cb710_mmc_select_clock_divider(mmc, ios->clock); in cb710_mmc_set_ios()
568 if (ios->power_mode != reader->last_power_mode) { in cb710_mmc_set_ios()
569 switch (ios->power_mode) { in cb710_mmc_set_ios()
574 "powerup failed (%d)- retrying\n", err); in cb710_mmc_set_ios()
580 "powerup retry failed (%d) - expect errors\n", in cb710_mmc_set_ios()
583 reader->last_power_mode = MMC_POWER_ON; in cb710_mmc_set_ios()
587 reader->last_power_mode = MMC_POWER_OFF; in cb710_mmc_set_ios()
596 cb710_mmc_enable_4bit_data(slot, ios->bus_width != MMC_BUS_WIDTH_1); in cb710_mmc_set_ios()
601 static int cb710_mmc_get_ro(struct mmc_host *mmc) in cb710_mmc_get_ro() argument
603 struct cb710_slot *slot = cb710_mmc_to_slot(mmc); in cb710_mmc_get_ro()
609 static int cb710_mmc_get_cd(struct mmc_host *mmc) in cb710_mmc_get_cd() argument
611 struct cb710_slot *slot = cb710_mmc_to_slot(mmc); in cb710_mmc_get_cd()
619 struct mmc_host *mmc = cb710_slot_to_mmc(slot); in cb710_mmc_irq_handler() local
620 struct cb710_mmc_reader *reader = mmc_priv(mmc); in cb710_mmc_irq_handler()
638 mmc_detect_change(mmc, HZ/5); in cb710_mmc_irq_handler()
641 spin_lock(&reader->irq_lock); in cb710_mmc_irq_handler()
643 spin_unlock(&reader->irq_lock); in cb710_mmc_irq_handler()
653 struct mmc_request *mrq = reader->mrq; in cb710_mmc_finish_request_bh_work()
655 reader->mrq = NULL; in cb710_mmc_finish_request_bh_work()
690 struct mmc_host *mmc; in cb710_mmc_init() local
695 mmc = mmc_alloc_host(sizeof(*reader), cb710_slot_dev(slot)); in cb710_mmc_init()
696 if (!mmc) in cb710_mmc_init()
697 return -ENOMEM; in cb710_mmc_init()
699 platform_set_drvdata(pdev, mmc); in cb710_mmc_init()
702 pci_read_config_dword(chip->pdev, 0x48, &val); in cb710_mmc_init()
707 mmc->ops = &cb710_mmc_host; in cb710_mmc_init()
708 mmc->f_max = val; in cb710_mmc_init()
709 mmc->f_min = val >> cb710_clock_divider_log2[CB710_MAX_DIVIDER_IDX]; in cb710_mmc_init()
710 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34; in cb710_mmc_init()
711 mmc->caps = MMC_CAP_4_BIT_DATA; in cb710_mmc_init()
715 * use of the cmd->busy_timeout. in cb710_mmc_init()
717 mmc->max_busy_timeout = CB710_MMC_REQ_TIMEOUT_MS; in cb710_mmc_init()
719 reader = mmc_priv(mmc); in cb710_mmc_init()
721 INIT_WORK(&reader->finish_req_bh_work, in cb710_mmc_init()
723 spin_lock_init(&reader->irq_lock); in cb710_mmc_init()
729 err = mmc_add_host(mmc); in cb710_mmc_init()
734 mmc_hostname(mmc)); in cb710_mmc_init()
744 mmc_free_host(mmc); in cb710_mmc_init()
751 struct mmc_host *mmc = cb710_slot_to_mmc(slot); in cb710_mmc_exit() local
752 struct cb710_mmc_reader *reader = mmc_priv(mmc); in cb710_mmc_exit()
756 mmc_remove_host(mmc); in cb710_mmc_exit()
762 /* clear config ports - just in case */ in cb710_mmc_exit()
766 cancel_work_sync(&reader->finish_req_bh_work); in cb710_mmc_exit()
768 mmc_free_host(mmc); in cb710_mmc_exit()
772 .driver.name = "cb710-mmc",
783 MODULE_AUTHOR("Michał Mirosław <mirq-linux@rere.qmqm.pl>");
784 MODULE_DESCRIPTION("ENE CB710 memory card reader driver - MMC/SD part");
786 MODULE_ALIAS("platform:cb710-mmc");