/* * Shared part of driver for MMC/SDHC controller on Cavium OCTEON and * ThunderX SOCs. * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2012-2017 Cavium Inc. * Authors: * David Daney <david.daney@cavium.com> * Peter Swain <pswain@cavium.com> * Steven J. Hill <steven.hill@cavium.com> * Jan Glauber <jglauber@cavium.com>
*/ #include <linux/bitfield.h> #include <linux/delay.h> #include <linux/dma-direction.h> #include <linux/dma-mapping.h> #include <linux/gpio/consumer.h> #include <linux/interrupt.h> #include <linux/mmc/mmc.h> #include <linux/mmc/slot-gpio.h> #include <linux/module.h> #include <linux/regulator/consumer.h> #include <linux/scatterlist.h> #include <linux/time.h>
/* * We never set the switch_exe bit since that would interfere * with the commands send by the MMC core.
*/ staticvoid do_switch(struct cvm_mmc_host *host, u64 emm_switch)
{ int retries = 100;
u64 rsp_sts; int bus_id;
/* * Modes setting only taken from slot 0. Work around that hardware * issue by first switching to slot 0.
*/
bus_id = get_bus_id(emm_switch);
clear_bus_id(&emm_switch);
writeq(emm_switch, host->base + MIO_EMM_SWITCH(host));
/* wait for the switch to finish */ do {
rsp_sts = readq(host->base + MIO_EMM_RSP_STS(host)); if (!(rsp_sts & MIO_EMM_RSP_STS_SWITCH_VAL)) break;
udelay(10);
} while (--retries);
check_switch_errors(host);
}
staticbool switch_val_changed(struct cvm_mmc_slot *slot, u64 new_val)
{ /* Match BUS_ID, HS_TIMING, BUS_WIDTH, POWER_CLASS, CLK_HI, CLK_LO */
u64 match = 0x3001070fffffffffull;
/* Check if there are any pending requests left */
fifo_cfg = readq(host->dma_base + MIO_EMM_DMA_FIFO_CFG(host));
count = FIELD_GET(MIO_EMM_DMA_FIFO_CFG_COUNT, fifo_cfg); if (count)
dev_err(host->dev, "%u requests still pending\n", count);
if (emm_int & MIO_EMM_INT_SWITCH_ERR)
check_switch_errors(host);
req = host->current_req; if (!req) goto out;
rsp_sts = readq(host->base + MIO_EMM_RSP_STS(host)); /* * dma_val set means DMA is still in progress. Don't touch * the request and wait for the interrupt indicating that * the DMA is finished.
*/ if ((rsp_sts & MIO_EMM_RSP_STS_DMA_VAL) && host->dma_active) goto out;
if (!host->dma_active && req->data &&
(emm_int & MIO_EMM_INT_BUF_DONE)) { unsignedint type = (rsp_sts >> 7) & 3;
/* * If we have scatter-gather support we also have an extra * register for the DMA addr, so no need to check * host->big_dma_addr here.
*/
rw = (data->flags & MMC_DATA_WRITE) ? 1 : 0;
fifo_cmd = FIELD_PREP(MIO_EMM_DMA_FIFO_CMD_RW, rw);
/* enable interrupts on the last element */
fifo_cmd |= FIELD_PREP(MIO_EMM_DMA_FIFO_CMD_INTDIS,
(i + 1 == count) ? 0 : 1);
#ifdef __LITTLE_ENDIAN
fifo_cmd |= FIELD_PREP(MIO_EMM_DMA_FIFO_CMD_ENDIAN, 1); #endif
fifo_cmd |= FIELD_PREP(MIO_EMM_DMA_FIFO_CMD_SIZE,
sg_dma_len(sg) / 8 - 1); /* * The write copies the address and the command to the FIFO * and increments the FIFO's COUNT field.
*/
writeq(fifo_cmd, host->dma_base + MIO_EMM_DMA_FIFO_CMD(host));
pr_debug("[%s] sg_dma_len: %u sg_elem: %d/%d\n",
(rw) ? "W" : "R", sg_dma_len(sg), i, count);
}
/* * In difference to prepare_dma_single we don't return the * address here, as it would not make sense for scatter-gather. * The dma fixup is only required on models that don't support * scatter-gather, so that is not a problem.
*/ return 1;
if (host->dmar_fixup)
host->dmar_fixup(host, mrq->cmd, data, addr);
/* * If we have a valid SD card in the slot, we set the response * bit mask to check for CRC errors and timeouts only. * Otherwise, use the default power reset value.
*/ if (mmc_card_sd(mmc->card))
writeq(0x00b00000ull, host->base + MIO_EMM_STS_MASK(host)); else
writeq(0xe4390080ull, host->base + MIO_EMM_STS_MASK(host));
writeq(emm_dma, host->base + MIO_EMM_DMA(host)); return;
error:
mrq->cmd->error = -EINVAL; if (mrq->done)
mrq->done(mrq);
host->release_bus(host);
}
/* * Note about locking: * All MMC devices share the same bus and controller. Allow only a * single user of the bootbus/MMC bus at a time. The lock is acquired * on all entry points from the MMC layer. * * For requests the lock is only released after the completion * interrupt!
*/
host->acquire_bus(host);
/* Make the changes take effect on this bus slot. */
set_bus_id(&emm_switch, slot->bus_id);
do_switch(host, emm_switch);
slot->cached_switch = emm_switch;
/* * Set watchdog timeout value and default reset value * for the mask register. Finally, set the CARD_RCA * bit so that we can get the card address relative * to the CMD register for CMD7 transactions.
*/
set_wdog(slot, 0);
writeq(0xe4390080ull, host->base + MIO_EMM_STS_MASK(host));
writeq(1, host->base + MIO_EMM_RCA(host)); return 0;
}
ret = of_property_read_u32(node, "reg", &id); if (ret) {
dev_err(dev, "Missing or invalid reg property on %pOF\n", node); return ret;
}
if (id >= CAVIUM_MAX_MMC || slot->host->slot[id]) {
dev_err(dev, "Invalid reg property on %pOF\n", node); return -EINVAL;
}
ret = mmc_regulator_get_supply(mmc); if (ret) return ret; /* * Legacy Octeon firmware has no regulator entry, fall-back to * a hard-coded voltage to get a sane OCR.
*/ if (IS_ERR(mmc->supply.vmmc))
mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
/* Common MMC bindings */
ret = mmc_of_parse(mmc); if (ret) return ret;
/* Set bus width */ if (!(mmc->caps & (MMC_CAP_8_BIT_DATA | MMC_CAP_4_BIT_DATA))) {
of_property_read_u32(node, "cavium,bus-max-width", &bus_width); if (bus_width == 8)
mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_4_BIT_DATA; elseif (bus_width == 4)
mmc->caps |= MMC_CAP_4_BIT_DATA;
}
/* Set maximum and minimum frequency */ if (!mmc->f_max)
of_property_read_u32(node, "spi-max-frequency", &mmc->f_max); if (!mmc->f_max || mmc->f_max > 52000000)
mmc->f_max = 52000000;
mmc->f_min = 400000;
ret = cvm_mmc_of_parse(dev, slot); if (ret < 0) return ret;
id = ret;
/* Set up host parameters */
mmc->ops = &cvm_mmc_ops;
/* * We only have a 3.3v supply, we cannot support any * of the UHS modes. We do support the high speed DDR * modes up to 52MHz. * * Disable bounce buffers for max_segs = 1
*/
mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
MMC_CAP_CMD23 | MMC_CAP_POWER_OFF_CARD | MMC_CAP_3_3V_DDR;
if (host->use_sg)
mmc->max_segs = 16; else
mmc->max_segs = 1;
/* DMA size field can address up to 8 MB */
mmc->max_seg_size = min_t(unsignedint, 8 * 1024 * 1024,
dma_get_max_seg_size(host->dev));
mmc->max_req_size = mmc->max_seg_size; /* External DMA is in 512 byte blocks */
mmc->max_blk_size = 512; /* DMA block count field is 15 bits */
mmc->max_blk_count = 32767;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.