2017-03-12 16:48:09 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/wireless/ieee80211/bcmf_sdio.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Simon Piriou <spiriou31@gmail.com>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/sdio.h>
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
|
2017-03-14 21:06:19 +01:00
|
|
|
#include <nuttx/wireless/ieee80211/mmc_sdio.h>
|
2017-03-12 16:48:09 +01:00
|
|
|
#include <nuttx/wireless/ieee80211/bcmf_sdio.h>
|
|
|
|
#include <nuttx/wireless/ieee80211/bcmf_board.h>
|
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
#include "bcmf_sdio.h"
|
|
|
|
#include "bcmf_core.h"
|
2017-03-20 22:40:25 +01:00
|
|
|
|
2017-03-12 16:48:09 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define BCMF_DEVICE_RESET_DELAY_MS 10
|
|
|
|
#define BCMF_DEVICE_START_DELAY_MS 10
|
2017-03-14 21:06:19 +01:00
|
|
|
#define BCMF_CLOCK_SETUP_DELAY_MS 500
|
|
|
|
|
2017-03-12 16:48:09 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int bcmf_probe(FAR struct bcmf_dev_s *priv);
|
|
|
|
static int bcmf_hwinitialize(FAR struct bcmf_dev_s *priv);
|
|
|
|
static void bcmf_hwuninitialize(FAR struct bcmf_dev_s *priv);
|
2017-03-20 22:40:25 +01:00
|
|
|
static int bcmf_chipinitialize(FAR struct bcmf_dev_s *priv);
|
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
static int bcmf_oob_irq(int irq, FAR void *context, FAR void *arg);
|
2017-03-12 16:48:09 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
int bcmf_oob_irq(int irq, FAR void *context, FAR void *arg)
|
2017-03-20 22:40:25 +01:00
|
|
|
{
|
2017-03-26 17:42:53 +02:00
|
|
|
/* TODO */
|
|
|
|
return OK;
|
2017-03-12 16:48:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_probe
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int bcmf_probe(FAR struct bcmf_dev_s *priv)
|
|
|
|
{
|
|
|
|
int ret;
|
2017-03-14 21:06:19 +01:00
|
|
|
uint8_t value;
|
2017-03-12 16:48:09 +01:00
|
|
|
|
2017-03-14 21:06:19 +01:00
|
|
|
/* Probe sdio card compatible device */
|
2017-03-12 16:48:09 +01:00
|
|
|
|
2017-03-14 21:06:19 +01:00
|
|
|
ret = sdio_probe(priv->sdio_dev);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
goto exit_error;
|
|
|
|
}
|
2017-03-12 16:48:09 +01:00
|
|
|
|
2017-03-14 21:06:19 +01:00
|
|
|
/* Set FN0 / FN1 / FN2 default block size */
|
|
|
|
|
|
|
|
ret = sdio_set_blocksize(priv->sdio_dev, 0, 64);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
goto exit_error;
|
|
|
|
}
|
2017-03-12 16:48:09 +01:00
|
|
|
|
2017-03-14 21:06:19 +01:00
|
|
|
ret = sdio_set_blocksize(priv->sdio_dev, 1, 64);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
goto exit_error;
|
|
|
|
}
|
2017-03-12 16:48:09 +01:00
|
|
|
|
2017-03-14 21:06:19 +01:00
|
|
|
ret = sdio_set_blocksize(priv->sdio_dev, 2, 64);
|
2017-03-12 16:48:09 +01:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
goto exit_error;
|
|
|
|
}
|
|
|
|
|
2017-03-14 21:06:19 +01:00
|
|
|
/* Enable device interrupts for FN0, FN1 and FN2 */
|
2017-03-12 16:48:09 +01:00
|
|
|
|
2017-03-20 22:40:25 +01:00
|
|
|
ret = bcmf_write_reg(priv, 0, SDIO_CCCR_INTEN,
|
|
|
|
(1 << 0) | (1 << 1) | (1 << 2));
|
2017-03-14 21:06:19 +01:00
|
|
|
if (ret != OK)
|
2017-03-12 16:48:09 +01:00
|
|
|
{
|
|
|
|
goto exit_error;
|
|
|
|
}
|
|
|
|
|
2017-03-14 21:06:19 +01:00
|
|
|
/* Default device clock speed is up to 25 Mhz
|
|
|
|
* We could set EHS bit to operate at a clock rate up to 50 Mhz */
|
|
|
|
|
|
|
|
SDIO_CLOCK(priv->sdio_dev, CLOCK_SD_TRANSFER_4BIT);
|
|
|
|
up_mdelay(BCMF_CLOCK_SETUP_DELAY_MS);
|
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
/* Enable bus FN1 */
|
2017-03-14 21:06:19 +01:00
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
ret = sdio_enable_function(priv->sdio_dev, 1);
|
|
|
|
if (ret != OK)
|
2017-03-14 21:06:19 +01:00
|
|
|
{
|
2017-03-26 17:42:53 +02:00
|
|
|
goto exit_error;
|
2017-03-14 21:06:19 +01:00
|
|
|
}
|
|
|
|
|
2017-03-12 16:48:09 +01:00
|
|
|
return OK;
|
|
|
|
|
|
|
|
exit_error:
|
|
|
|
|
|
|
|
_err("ERROR: failed to probe device %d\n", priv->minor);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-14 21:06:19 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_businitialize
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
int bcmf_businitialize(FAR struct bcmf_dev_s *priv)
|
2017-03-14 21:06:19 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int loops;
|
2017-03-26 17:42:53 +02:00
|
|
|
uint8_t value;
|
2017-03-14 21:06:19 +01:00
|
|
|
|
|
|
|
/* Send Active Low-Power clock request */
|
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
ret = bcmf_write_reg(priv, 1, SBSDIO_FUNC1_CHIPCLKCSR,
|
2017-03-20 22:40:25 +01:00
|
|
|
SBSDIO_FORCE_HW_CLKREQ_OFF |
|
|
|
|
SBSDIO_ALP_AVAIL_REQ |
|
|
|
|
SBSDIO_FORCE_ALP);
|
2017-03-14 21:06:19 +01:00
|
|
|
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
2017-03-20 22:40:25 +01:00
|
|
|
return ret;
|
2017-03-14 21:06:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
loops = 10;
|
|
|
|
while (--loops > 0)
|
|
|
|
{
|
|
|
|
up_mdelay(10);
|
2017-03-26 17:42:53 +02:00
|
|
|
ret = bcmf_read_reg(priv, 1, SBSDIO_FUNC1_CHIPCLKCSR, &value);
|
2017-03-14 21:06:19 +01:00
|
|
|
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-20 22:40:25 +01:00
|
|
|
if (value & SBSDIO_ALP_AVAIL)
|
2017-03-14 21:06:19 +01:00
|
|
|
{
|
|
|
|
/* Active Low-Power clock is ready */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loops <= 0)
|
|
|
|
{
|
|
|
|
_err("failed to enable ALP\n");
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear Active Low-Power clock request */
|
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
ret = bcmf_write_reg(priv, 1, SBSDIO_FUNC1_CHIPCLKCSR, 0);
|
2017-03-14 21:06:19 +01:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable pull-ups on SDIO cmd, d0-2 lines */
|
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
ret = bcmf_write_reg(priv, 1, SBSDIO_FUNC1_SDIOPULLUP, 0);
|
2017-03-14 21:06:19 +01:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-20 22:40:25 +01:00
|
|
|
/* Do chip specific initialization */
|
2017-03-14 21:06:19 +01:00
|
|
|
|
2017-03-20 22:40:25 +01:00
|
|
|
ret = bcmf_chipinitialize(priv);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-03-14 21:06:19 +01:00
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
/* Upload firmware */
|
|
|
|
|
|
|
|
ret = bcmf_core_upload_firmware(priv);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable FN2 (frame transfers) */
|
2017-03-14 21:06:19 +01:00
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
ret = sdio_enable_function(priv->sdio_dev, 2);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-03-14 21:06:19 +01:00
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
/* Configure gpio interrupt pin */
|
2017-03-20 22:40:25 +01:00
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
bcmf_board_setup_oob_irq(priv->minor, bcmf_oob_irq, (void*)priv);
|
2017-03-20 22:40:25 +01:00
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
/* Enable function 2 interrupt */
|
2017-03-20 22:40:25 +01:00
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
ret = sdio_enable_interrupt(priv->sdio_dev, 0);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = sdio_enable_interrupt(priv->sdio_dev, 2);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-03-20 22:40:25 +01:00
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
/* Redirect, configure and enable io for out-of-band interrupt signal */
|
2017-03-20 22:40:25 +01:00
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
ret = sdio_io_rw_direct(priv->sdio_dev, true, 0, SDIO_CCCR_BRCM_SEPINT,
|
|
|
|
SDIO_SEPINT_MASK | SDIO_SEPINT_OE | SDIO_SEPINT_ACT_HI, NULL);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
_info("wait high throughput clock\n");
|
|
|
|
|
|
|
|
/* Wait for High Troughput clock to be sure function 2 is running */
|
|
|
|
|
|
|
|
loops = 10;
|
|
|
|
while (--loops > 0)
|
|
|
|
{
|
|
|
|
up_mdelay(10);
|
|
|
|
ret = bcmf_read_reg(priv, 1, SBSDIO_FUNC1_CHIPCLKCSR, &value);
|
|
|
|
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-03-20 22:40:25 +01:00
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
if (value & SBSDIO_HT_AVAIL)
|
|
|
|
{
|
|
|
|
/* High Throughput clock is ready */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loops <= 0)
|
|
|
|
{
|
|
|
|
_err("HT clock not ready\n");
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FN2 successfully enabled, set core and enable interrupts */
|
|
|
|
|
|
|
|
bcmf_write_sbregw(priv,
|
|
|
|
CORE_BUS_REG(priv->get_core_base_address(SDIOD_CORE_ID),
|
|
|
|
hostintmask), I_HMB_SW_MASK);
|
|
|
|
|
|
|
|
bcmf_write_sbregb(priv,
|
|
|
|
CORE_BUS_REG(priv->get_core_base_address(SDIOD_CORE_ID),
|
|
|
|
funcintmask), 2);
|
|
|
|
|
|
|
|
bcmf_write_reg(priv, 1, SBSDIO_WATERMARK, 8);
|
2017-03-14 21:06:19 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-12 16:48:09 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_hwinitialize
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int bcmf_hwinitialize(FAR struct bcmf_dev_s *priv)
|
|
|
|
{
|
|
|
|
/* Attach and prepare SDIO interrupts */
|
|
|
|
|
|
|
|
SDIO_ATTACH(priv->sdio_dev);
|
|
|
|
|
|
|
|
/* Set ID mode clocking (<400KHz) */
|
|
|
|
|
|
|
|
SDIO_CLOCK(priv->sdio_dev, CLOCK_IDMODE);
|
|
|
|
|
|
|
|
/* Configure hardware */
|
|
|
|
|
|
|
|
bcmf_board_initialize(priv->minor);
|
|
|
|
|
|
|
|
/* Reset and power device */
|
|
|
|
|
|
|
|
bcmf_board_reset(priv->minor, true);
|
|
|
|
bcmf_board_power(priv->minor, true);
|
|
|
|
up_mdelay(BCMF_DEVICE_RESET_DELAY_MS);
|
|
|
|
bcmf_board_reset(priv->minor, false);
|
|
|
|
|
|
|
|
/* Wait for device to start */
|
|
|
|
|
|
|
|
up_mdelay(BCMF_DEVICE_START_DELAY_MS);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_hwuninitialize
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void bcmf_hwuninitialize(FAR struct bcmf_dev_s *priv)
|
|
|
|
{
|
|
|
|
/* Shutdown device */
|
|
|
|
|
|
|
|
bcmf_board_power(priv->minor, false);
|
|
|
|
bcmf_board_reset(priv->minor, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_transfer_bytes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int bcmf_transfer_bytes(FAR struct bcmf_dev_s *priv, bool write,
|
|
|
|
uint8_t function, uint32_t address,
|
|
|
|
uint8_t *buf, unsigned int len)
|
|
|
|
{
|
|
|
|
/* Use rw_io_direct method if len is 1 */
|
|
|
|
|
|
|
|
if (len == 1)
|
|
|
|
{
|
|
|
|
if (write)
|
|
|
|
{
|
|
|
|
return sdio_io_rw_direct(priv->sdio_dev, write,
|
|
|
|
function, address, *buf, NULL);
|
|
|
|
}
|
|
|
|
return sdio_io_rw_direct(priv->sdio_dev, write,
|
|
|
|
function, address, 0, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find best block size / count values for transfer */
|
|
|
|
|
|
|
|
unsigned int blocklen;
|
|
|
|
unsigned int nblocks;
|
|
|
|
|
|
|
|
if (len == 64 || len > 0 && len % 64 == 0)
|
|
|
|
{
|
|
|
|
blocklen = 64;
|
|
|
|
nblocks = len / 64;
|
|
|
|
}
|
|
|
|
else if (len > 20)
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
blocklen = 64;
|
|
|
|
nblocks = (len+63) / 64;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
blocklen = len;
|
|
|
|
nblocks = 0;
|
|
|
|
}
|
|
|
|
// _info("try extended %d %d %d\n", len, blocklen, nblocks);
|
|
|
|
return sdio_io_rw_extended(priv->sdio_dev, write,
|
|
|
|
function, address, true, buf, blocklen, nblocks);
|
|
|
|
|
|
|
|
// return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_read_reg
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int bcmf_read_reg(FAR struct bcmf_dev_s *priv, uint8_t function,
|
|
|
|
uint32_t address, uint8_t *reg)
|
|
|
|
{
|
|
|
|
*reg = 0;
|
|
|
|
return bcmf_transfer_bytes(priv, false, function, address, reg, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_write_reg
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int bcmf_write_reg(FAR struct bcmf_dev_s *priv, uint8_t function,
|
|
|
|
uint32_t address, uint8_t reg)
|
|
|
|
{
|
|
|
|
return bcmf_transfer_bytes(priv, true, function, address, ®, 1);
|
|
|
|
}
|
|
|
|
|
2017-03-12 16:48:09 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_sdio_initialize
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int bcmf_sdio_initialize(int minor, FAR struct sdio_dev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct bcmf_dev_s *priv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
_info("minor: %d\n", minor);
|
|
|
|
|
|
|
|
/* Allocate a bcmf device structure */
|
|
|
|
|
|
|
|
priv = (FAR struct bcmf_dev_s *)kmm_malloc(sizeof(*priv));
|
|
|
|
|
|
|
|
if (!priv)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize bcmf device structure */
|
|
|
|
|
|
|
|
memset(priv, 0, sizeof(*priv));
|
|
|
|
priv->sdio_dev = dev;
|
|
|
|
priv->minor = minor;
|
|
|
|
|
|
|
|
/* Initialize device hardware */
|
|
|
|
|
|
|
|
ret = bcmf_hwinitialize(priv);
|
|
|
|
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
goto exit_free_priv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Probe device */
|
|
|
|
|
|
|
|
ret = bcmf_probe(priv);
|
|
|
|
|
2017-03-14 21:06:19 +01:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
goto exit_uninit_hw;
|
|
|
|
}
|
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
/* Initialize device bus */
|
2017-03-14 21:06:19 +01:00
|
|
|
|
|
|
|
ret = bcmf_businitialize(priv);
|
|
|
|
|
2017-03-12 16:48:09 +01:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
goto exit_uninit_hw;
|
|
|
|
}
|
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
/* FIXME wait for the chip to be ready to receive commands */
|
|
|
|
|
|
|
|
up_mdelay(100);
|
|
|
|
|
|
|
|
/* Device is up and running
|
|
|
|
TODO Create a wlan device name and register network driver here */
|
2017-03-12 16:48:09 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
exit_uninit_hw:
|
|
|
|
bcmf_hwuninitialize(priv);
|
|
|
|
|
|
|
|
exit_free_priv:
|
|
|
|
kmm_free(priv);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-03-20 22:40:25 +01:00
|
|
|
|
|
|
|
int bcmf_chipinitialize(FAR struct bcmf_dev_s *priv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
uint32_t value = 0;
|
|
|
|
|
2017-03-26 17:42:53 +02:00
|
|
|
ret = bcmf_read_sbregw(priv, SI_ENUM_BASE, &value);
|
2017-03-20 22:40:25 +01:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
_info("chip id is 0x%x\n", value);
|
|
|
|
|
|
|
|
int chipid = value & 0xffff;
|
|
|
|
switch (chipid)
|
|
|
|
{
|
2017-03-26 17:42:53 +02:00
|
|
|
case SDIO_DEVICE_ID_BROADCOM_43362:
|
|
|
|
_info("bcm43362 chip detected\n");
|
|
|
|
priv->get_core_base_address = bcmf_43362_get_core_base_address;
|
2017-03-20 22:40:25 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_err("chip 0x%x is not supported\n", chipid);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|