M7350/external/compat-wireless/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c

373 lines
8.7 KiB
C
Raw Normal View History

2024-09-09 08:52:07 +00:00
/*
* Copyright (c) 2010 Broadcom Corporation
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* ****************** SDIO CARD Interface Functions **************************/
#include <linux/types.h>
#include <linux/netdevice.h>
#include <linux/export.h>
#include <linux/pci.h>
#include <linux/pci_ids.h>
#include <linux/sched.h>
#include <linux/completion.h>
#include <linux/mmc/sdio.h>
#include <linux/mmc/sdio_func.h>
#include <linux/mmc/card.h>
#include <defs.h>
#include <brcm_hw_ids.h>
#include <brcmu_utils.h>
#include <brcmu_wifi.h>
#include <soc.h>
2024-09-09 08:57:42 +00:00
#include "dhd.h"
2024-09-09 08:52:07 +00:00
#include "dhd_bus.h"
#include "dhd_dbg.h"
#include "sdio_host.h"
#define SDIOH_API_ACCESS_RETRY_LIMIT 2
2024-09-09 08:57:42 +00:00
static void brcmf_sdioh_irqhandler(struct sdio_func *func)
2024-09-09 08:52:07 +00:00
{
struct brcmf_sdio_dev *sdiodev = dev_get_drvdata(&func->card->dev);
2024-09-09 08:57:42 +00:00
brcmf_dbg(TRACE, "***IRQHandler\n");
sdio_release_host(func);
2024-09-09 08:52:07 +00:00
brcmf_sdbrcm_isr(sdiodev->bus);
2024-09-09 08:57:42 +00:00
sdio_claim_host(func);
2024-09-09 08:52:07 +00:00
}
2024-09-09 08:57:42 +00:00
int brcmf_sdcard_intr_reg(struct brcmf_sdio_dev *sdiodev)
2024-09-09 08:52:07 +00:00
{
brcmf_dbg(TRACE, "Entering\n");
sdio_claim_host(sdiodev->func[1]);
2024-09-09 08:57:42 +00:00
sdio_claim_irq(sdiodev->func[1], brcmf_sdioh_irqhandler);
2024-09-09 08:52:07 +00:00
sdio_release_host(sdiodev->func[1]);
return 0;
}
2024-09-09 08:57:42 +00:00
int brcmf_sdcard_intr_dereg(struct brcmf_sdio_dev *sdiodev)
2024-09-09 08:52:07 +00:00
{
brcmf_dbg(TRACE, "Entering\n");
sdio_claim_host(sdiodev->func[1]);
sdio_release_irq(sdiodev->func[1]);
sdio_release_host(sdiodev->func[1]);
return 0;
}
2024-09-09 08:57:42 +00:00
u8 brcmf_sdcard_cfg_read(struct brcmf_sdio_dev *sdiodev, uint fnc_num, u32 addr,
int *err)
2024-09-09 08:52:07 +00:00
{
2024-09-09 08:57:42 +00:00
int status;
s32 retry = 0;
u8 data = 0;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
do {
if (retry) /* wait for 1 ms till bus get settled down */
udelay(1000);
status = brcmf_sdioh_request_byte(sdiodev, SDIOH_READ, fnc_num,
addr, (u8 *) &data);
} while (status != 0
&& (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT));
if (err)
*err = status;
brcmf_dbg(INFO, "fun = %d, addr = 0x%x, u8data = 0x%x\n",
fnc_num, addr, data);
return data;
2024-09-09 08:52:07 +00:00
}
2024-09-09 08:57:42 +00:00
void
brcmf_sdcard_cfg_write(struct brcmf_sdio_dev *sdiodev, uint fnc_num, u32 addr,
u8 data, int *err)
2024-09-09 08:52:07 +00:00
{
2024-09-09 08:57:42 +00:00
int status;
2024-09-09 08:52:07 +00:00
s32 retry = 0;
do {
if (retry) /* wait for 1 ms till bus get settled down */
2024-09-09 08:57:42 +00:00
udelay(1000);
status = brcmf_sdioh_request_byte(sdiodev, SDIOH_WRITE, fnc_num,
addr, (u8 *) &data);
} while (status != 0
&& (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT));
if (err)
*err = status;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
brcmf_dbg(INFO, "fun = %d, addr = 0x%x, u8data = 0x%x\n",
fnc_num, addr, data);
2024-09-09 08:52:07 +00:00
}
2024-09-09 08:57:42 +00:00
int
brcmf_sdcard_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address)
2024-09-09 08:52:07 +00:00
{
2024-09-09 08:57:42 +00:00
int err = 0;
brcmf_sdcard_cfg_write(sdiodev, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW,
(address >> 8) & SBSDIO_SBADDRLOW_MASK, &err);
if (!err)
brcmf_sdcard_cfg_write(sdiodev, SDIO_FUNC_1,
SBSDIO_FUNC1_SBADDRMID,
(address >> 16) & SBSDIO_SBADDRMID_MASK,
&err);
if (!err)
brcmf_sdcard_cfg_write(sdiodev, SDIO_FUNC_1,
SBSDIO_FUNC1_SBADDRHIGH,
(address >> 24) & SBSDIO_SBADDRHIGH_MASK,
&err);
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
return err;
2024-09-09 08:52:07 +00:00
}
2024-09-09 08:57:42 +00:00
u32 brcmf_sdcard_reg_read(struct brcmf_sdio_dev *sdiodev, u32 addr, uint size)
2024-09-09 08:52:07 +00:00
{
2024-09-09 08:57:42 +00:00
int status;
u32 word = 0;
uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
brcmf_dbg(INFO, "fun = 1, addr = 0x%x\n", addr);
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
if (bar0 != sdiodev->sbwad) {
if (brcmf_sdcard_set_sbaddr_window(sdiodev, bar0))
return 0xFFFFFFFF;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
sdiodev->sbwad = bar0;
}
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
addr &= SBSDIO_SB_OFT_ADDR_MASK;
if (size == 4)
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
status = brcmf_sdioh_request_word(sdiodev, SDIOH_READ, SDIO_FUNC_1,
addr, &word, size);
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
sdiodev->regfail = (status != 0);
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
brcmf_dbg(INFO, "u32data = 0x%x\n", word);
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
/* if ok, return appropriately masked word */
if (status == 0) {
switch (size) {
case sizeof(u8):
return word & 0xff;
case sizeof(u16):
return word & 0xffff;
case sizeof(u32):
return word;
default:
sdiodev->regfail = true;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
}
}
/* otherwise, bad sdio access or invalid size */
brcmf_dbg(ERROR, "error reading addr 0x%04x size %d\n", addr, size);
return 0xFFFFFFFF;
2024-09-09 08:52:07 +00:00
}
2024-09-09 08:57:42 +00:00
u32 brcmf_sdcard_reg_write(struct brcmf_sdio_dev *sdiodev, u32 addr, uint size,
u32 data)
2024-09-09 08:52:07 +00:00
{
2024-09-09 08:57:42 +00:00
int status;
uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK;
2024-09-09 08:52:07 +00:00
int err = 0;
2024-09-09 08:57:42 +00:00
brcmf_dbg(INFO, "fun = 1, addr = 0x%x, uint%ddata = 0x%x\n",
addr, size * 8, data);
2024-09-09 08:52:07 +00:00
if (bar0 != sdiodev->sbwad) {
err = brcmf_sdcard_set_sbaddr_window(sdiodev, bar0);
if (err)
return err;
sdiodev->sbwad = bar0;
}
2024-09-09 08:57:42 +00:00
addr &= SBSDIO_SB_OFT_ADDR_MASK;
if (size == 4)
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
status =
brcmf_sdioh_request_word(sdiodev, SDIOH_WRITE, SDIO_FUNC_1,
addr, &data, size);
sdiodev->regfail = (status != 0);
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
if (status == 0)
return 0;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
brcmf_dbg(ERROR, "error writing 0x%08x to addr 0x%04x size %d\n",
data, addr, size);
return 0xFFFFFFFF;
2024-09-09 08:52:07 +00:00
}
2024-09-09 08:57:42 +00:00
bool brcmf_sdcard_regfail(struct brcmf_sdio_dev *sdiodev)
2024-09-09 08:52:07 +00:00
{
2024-09-09 08:57:42 +00:00
return sdiodev->regfail;
2024-09-09 08:52:07 +00:00
}
int
2024-09-09 08:57:42 +00:00
brcmf_sdcard_recv_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
uint flags,
u8 *buf, uint nbytes, struct sk_buff *pkt)
2024-09-09 08:52:07 +00:00
{
2024-09-09 08:57:42 +00:00
int status;
2024-09-09 08:52:07 +00:00
uint incr_fix;
uint width;
2024-09-09 08:57:42 +00:00
uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK;
2024-09-09 08:52:07 +00:00
int err = 0;
2024-09-09 08:57:42 +00:00
brcmf_dbg(INFO, "fun = %d, addr = 0x%x, size = %d\n", fn, addr, nbytes);
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
/* Async not implemented yet */
if (flags & SDIO_REQ_ASYNC)
return -ENOTSUPP;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
if (bar0 != sdiodev->sbwad) {
err = brcmf_sdcard_set_sbaddr_window(sdiodev, bar0);
if (err)
return err;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
sdiodev->sbwad = bar0;
}
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
addr &= SBSDIO_SB_OFT_ADDR_MASK;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC;
2024-09-09 08:52:07 +00:00
width = (flags & SDIO_REQ_4BYTE) ? 4 : 2;
2024-09-09 08:57:42 +00:00
if (width == 4)
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
status = brcmf_sdioh_request_buffer(sdiodev, incr_fix, SDIOH_READ,
fn, addr, width, nbytes, buf, pkt);
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
return status;
2024-09-09 08:52:07 +00:00
}
int
brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
2024-09-09 08:57:42 +00:00
uint flags, u8 *buf, uint nbytes, struct sk_buff *pkt)
2024-09-09 08:52:07 +00:00
{
uint incr_fix;
uint width;
uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK;
int err = 0;
2024-09-09 08:57:42 +00:00
brcmf_dbg(INFO, "fun = %d, addr = 0x%x, size = %d\n", fn, addr, nbytes);
2024-09-09 08:52:07 +00:00
/* Async not implemented yet */
if (flags & SDIO_REQ_ASYNC)
return -ENOTSUPP;
if (bar0 != sdiodev->sbwad) {
err = brcmf_sdcard_set_sbaddr_window(sdiodev, bar0);
if (err)
return err;
sdiodev->sbwad = bar0;
}
addr &= SBSDIO_SB_OFT_ADDR_MASK;
incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC;
width = (flags & SDIO_REQ_4BYTE) ? 4 : 2;
if (width == 4)
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
return brcmf_sdioh_request_buffer(sdiodev, incr_fix, SDIOH_WRITE, fn,
2024-09-09 08:57:42 +00:00
addr, width, nbytes, buf, pkt);
2024-09-09 08:52:07 +00:00
}
int brcmf_sdcard_rwdata(struct brcmf_sdio_dev *sdiodev, uint rw, u32 addr,
u8 *buf, uint nbytes)
{
addr &= SBSDIO_SB_OFT_ADDR_MASK;
addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
2024-09-09 08:57:42 +00:00
return brcmf_sdioh_request_buffer(sdiodev, SDIOH_DATA_INC,
(rw ? SDIOH_WRITE : SDIOH_READ), SDIO_FUNC_1,
addr, 4, nbytes, buf, NULL);
2024-09-09 08:52:07 +00:00
}
int brcmf_sdcard_abort(struct brcmf_sdio_dev *sdiodev, uint fn)
{
char t_func = (char)fn;
brcmf_dbg(TRACE, "Enter\n");
/* issue abort cmd52 command through F0 */
brcmf_sdioh_request_byte(sdiodev, SDIOH_WRITE, SDIO_FUNC_0,
SDIO_CCCR_ABORT, &t_func);
brcmf_dbg(TRACE, "Exit\n");
return 0;
}
int brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
{
u32 regs = 0;
int ret = 0;
ret = brcmf_sdioh_attach(sdiodev);
if (ret)
goto out;
regs = SI_ENUM_BASE;
/* Report the BAR, to fix if needed */
sdiodev->sbwad = SI_ENUM_BASE;
/* try to attach to the target device */
2024-09-09 08:57:42 +00:00
sdiodev->bus = brcmf_sdbrcm_probe(0, 0, 0, 0, regs, sdiodev);
2024-09-09 08:52:07 +00:00
if (!sdiodev->bus) {
brcmf_dbg(ERROR, "device attach failed\n");
ret = -ENODEV;
goto out;
}
out:
if (ret)
brcmf_sdio_remove(sdiodev);
return ret;
}
EXPORT_SYMBOL(brcmf_sdio_probe);
int brcmf_sdio_remove(struct brcmf_sdio_dev *sdiodev)
{
if (sdiodev->bus) {
brcmf_sdbrcm_disconnect(sdiodev->bus);
sdiodev->bus = NULL;
}
brcmf_sdioh_detach(sdiodev);
sdiodev->sbwad = 0;
return 0;
}
EXPORT_SYMBOL(brcmf_sdio_remove);
void brcmf_sdio_wdtmr_enable(struct brcmf_sdio_dev *sdiodev, bool enable)
{
if (enable)
brcmf_sdbrcm_wd_timer(sdiodev->bus, BRCMF_WD_POLL_MS);
else
brcmf_sdbrcm_wd_timer(sdiodev->bus, 0);
}