// SPDX-License-Identifier: GPL-2.0-or-later /* * linux/drivers/net/wireless/libertas/if_sdio.c * * Copyright 2007-2008 Pierre Ossman * * Inspired by if_cs.c, Copyright 2007 Holger Schurig * * This hardware has more or less no CMD53 support, so all registers * must be accessed using sdio_readb()/sdio_writeb(). * * Transfers must be in one transaction or the firmware goes bonkers. * This means that the transfer must either be small enough to do a * byte based transfer or it must be padded to a multiple of the * current block size. * * As SDIO is still new to the kernel, it is unfortunately common with * bugs in the host controllers related to that. One such bug is that * controllers cannot do transfers that aren't a multiple of 4 bytes. * If you don't have time to fix the host controller driver, you can * work around the problem by modifying if_sdio_host_to_card() and * if_sdio_card_to_host() to pad the data.
*/
/* The if_sdio_remove() callback function is called when * user removes this module from kernel space or ejects * the card from the slot. The driver handles these 2 cases * differently for SD8688 combo chip. * If the user is removing the module, the FUNC_SHUTDOWN * command for SD8688 is sent to the firmware. * If the card is removed, there is no need to send this command. * * The variable 'user_rmmod' is used to distinguish these two * scenarios. This flag is initialized as FALSE in case the card * is removed, and will be set to TRUE for module removal when * module_exit function is called.
*/ static u8 user_rmmod;
/* * For SD8385/SD8686, this function reads firmware status after * the image is downloaded, or reads RX packet length when * interrupt (with IF_SDIO_H_INT_UPLD bit set) is received. * For SD8688, this function reads firmware status only.
*/ static u16 if_sdio_read_scratch(struct if_sdio_card *card, int *err)
{ int ret;
u16 scratch;
size = if_sdio_read_rx_len(card, &ret); if (ret) goto out;
if (size < 4) {
lbs_deb_sdio("invalid packet size (%d bytes) from firmware\n",
(int)size);
ret = -EINVAL; goto out;
}
ret = if_sdio_wait_status(card, IF_SDIO_IO_RDY); if (ret) goto out;
/* * The transfer must be in one transaction or the firmware * goes suicidal. There's no way to guarantee that for all * controllers, but we can at least try.
*/
chunk = sdio_align_size(card->func, size);
ret = sdio_readsb(card->func, card->buffer, card->ioport, chunk); if (ret) goto out;
/* an empty block marks the end of the transfer */
memset(chunk_buffer, 0, 4);
ret = sdio_writesb(card->func, card->ioport, chunk_buffer, 64); if (ret) goto release;
lbs_deb_sdio("waiting for helper to boot...\n");
/* wait for the helper to boot by looking at the size register */
timeout = jiffies + HZ; while (1) {
u16 req_size;
req_size = sdio_readb(card->func, IF_SDIO_RD_BASE, &ret); if (ret) goto release;
/* * For SD8688 wait until the length is not 0, 1 or 2 * before downloading the first FW block, * since BOOT code writes the register to indicate the * helper/FW download winner, * the value could be 1 or 2 (Func1 or Func2).
*/ if ((size != fw->size) || (req_size > 2)) break; if (time_after(jiffies, timeout)) {
ret = -ETIMEDOUT; goto release;
}
mdelay(1);
}
/* lbs_deb_sdio("firmware wants %d bytes\n", (int)req_size);
*/ if (req_size == 0) {
lbs_deb_sdio("firmware helper gave up early\n");
ret = -EIO; goto release;
}
if (req_size & 0x01) {
lbs_deb_sdio("firmware helper signalled error\n");
ret = -EIO; goto release;
}
if (req_size > size)
req_size = size;
while (req_size) {
chunk_size = min_t(size_t, req_size, 512);
lbs_deb_sdio("firmware status = %#x\n", scratch);
lbs_deb_sdio("scratch ret = %d\n", ret);
if (ret) goto out;
/* * The manual clearly describes that FEDC is the right code to use * to detect firmware presence, but for SD8686 it is not that simple. * Scratch is also used to store the RX packet length, so we lose * the FEDC value early on. So we use a non-zero check in order * to validate firmware presence. * Additionally, the SD8686 in the Gumstix always has the high scratch * bit set, even when the firmware is not loaded. So we have to * exclude that from the test.
*/ if (scratch == IF_SDIO_FIRMWARE_OK) {
lbs_deb_sdio("firmware already loaded\n");
if_sdio_finish_power_on(card); return 0;
} elseif ((card->model == MODEL_8686) && (scratch & 0x7fff)) {
lbs_deb_sdio("firmware may be running\n");
if_sdio_finish_power_on(card); return 0;
}
ret = lbs_get_firmware_async(card->priv, &card->func->dev, card->model,
fw_table, if_sdio_do_prog_firmware);
out: return ret;
}
/********************************************************************/ /* Power management */ /********************************************************************/
/* Finish power on sequence (after firmware is loaded) */ staticvoid if_sdio_finish_power_on(struct if_sdio_card *card)
{ struct sdio_func *func = card->func; struct lbs_private *priv = card->priv; int ret;
/* * Get rx_unit if the chip is SD8688 or newer. * SD8385 & SD8686 do not have rx_unit.
*/ if ((card->model != MODEL_8385)
&& (card->model != MODEL_8686))
card->rx_unit = if_sdio_read_rx_unit(card); else
card->rx_unit = 0;
/* * Set up the interrupt handler late. * * If we set it up earlier, the (buggy) hardware generates a spurious * interrupt, even before the interrupt has been enabled, with * CCCR_INTx = 0. * * We register the interrupt handler late so that we can handle any * spurious interrupts, and also to avoid generation of that known * spurious interrupt in the first place.
*/
ret = sdio_claim_irq(func, if_sdio_interrupt); if (ret) goto release;
/* * Enable interrupts now that everything is set up
*/
sdio_writeb(func, 0x0f, IF_SDIO_H_INT_MASK, &ret); if (ret) goto release_irq;
sdio_release_host(func);
/* Set fw_ready before queuing any commands so that * lbs_thread won't block from sending them to firmware.
*/
priv->fw_ready = 1;
/* * FUNC_INIT is required for SD8688 WLAN/BT multiple functions
*/ if (card->model == MODEL_8688) { struct cmd_header cmd;
memset(&cmd, 0, sizeof(cmd));
lbs_deb_sdio("send function INIT command\n"); if (__lbs_cmd(priv, CMD_FUNC_INIT, &cmd, sizeof(cmd),
lbs_cmd_copyback, (unsignedlong) &cmd))
netdev_alert(priv->dev, "CMD_FUNC_INIT cmd failed\n");
}
wake_up(&card->pwron_waitq);
if (!card->started) {
ret = lbs_start_card(priv);
if_sdio_power_off(card); if (ret == 0) {
card->started = true; /* Tell PM core that we don't need the card to be
* powered now */
pm_runtime_put(&func->dev);
}
}
ret = sdio_enable_func(func); if (ret) goto release;
/* For 1-bit transfers to the 8686 model, we need to enable the * interrupt flag in the CCCR register. Set the MMC_QUIRK_LENIENT_FN0
* bit to allow access to non-vendor registers. */ if ((card->model == MODEL_8686) &&
(host->caps & MMC_CAP_SDIO_IRQ) &&
(host->ios.bus_width == MMC_BUS_WIDTH_1)) {
u8 reg;
if (nb > (65536 - sizeof(struct if_sdio_packet) - 4)) {
ret = -EINVAL; goto out;
}
/* * The transfer must be in one transaction or the firmware * goes suicidal. There's no way to guarantee that for all * controllers, but we can at least try.
*/
size = sdio_align_size(card->func, nb + 4);
packet = kzalloc(sizeof(struct if_sdio_packet) + size,
GFP_ATOMIC); if (!packet) {
ret = -ENOMEM; goto out;
}
card = container_of(work, struct if_sdio_card, reset_worker);
reset_host = card->func->card->host;
name = card->priv->dev->name;
dev = &card->func->dev;
/* * The actual reset operation must be run outside of lbs_thread. This * is because mmc_remove_host() will cause the device to be instantly * destroyed, and the libertas driver then needs to end lbs_thread, * leading to a deadlock. * * We run it in a workqueue totally independent from the if_sdio_card * instance for that reason.
*/
sdio_writeb(card->func, ~cause, IF_SDIO_H_INT_STATUS, &ret); if (ret) return;
/* * Ignore the define name, this really means the card has * successfully received the command.
*/
card->priv->is_activity_detected = 1; if (cause & IF_SDIO_H_INT_DNLD)
lbs_host_to_card_done(card->priv);
if (cause & IF_SDIO_H_INT_UPLD) {
ret = if_sdio_card_to_host(card); if (ret) return;
}
}
/* Check if we support this card */ for (i = 0; i < ARRAY_SIZE(fw_table); i++) { if (card->model == fw_table[i].model) break;
} if (i == ARRAY_SIZE(fw_table)) {
pr_err("unknown card model 0x%x\n", card->model);
ret = -ENODEV; goto free;
}
/* If we're powered off anyway, just let the mmc layer remove the
* card. */ if (!lbs_iface_active(priv)) { if (priv->fw_ready) {
priv->power_up_on_resume = true;
if_sdio_power_off(card);
}
/* If we aren't being asked to wake on anything, we should bail out * and let the SD stack power down the card.
*/ if (priv->wol_criteria == EHS_REMOVE_WAKEUP) {
dev_info(dev, "Suspend without wake params -- powering down card\n"); if (priv->fw_ready) {
ret = lbs_suspend(priv); if (ret) return ret;
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.