linux/drivers/net/wireless/microchip/wilc1000/spi.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
 * All rights reserved.
 */

#include <linux/clk.h>
#include <linux/spi/spi.h>
#include <linux/crc7.h>
#include <linux/crc-itu-t.h>
#include <linux/gpio/consumer.h>

#include "netdev.h"
#include "cfg80211.h"

#define SPI_MODALIAS

static bool enable_crc7;	/* protect SPI commands with CRC7 */
module_param(enable_crc7, bool, 0644);
MODULE_PARM_DESC();

static bool enable_crc16;	/* protect SPI data with CRC16 */
module_param(enable_crc16, bool, 0644);
MODULE_PARM_DESC();

/*
 * For CMD_SINGLE_READ and CMD_INTERNAL_READ, WILC may insert one or
 * more zero bytes between the command response and the DATA Start tag
 * (0xf3).  This behavior appears to be undocumented in "ATWILC1000
 * USER GUIDE" (https://tinyurl.com/4hhshdts) but we have observed 1-4
 * zero bytes when the SPI bus operates at 48MHz and none when it
 * operates at 1MHz.
 */
#define WILC_SPI_RSP_HDR_EXTRA_DATA

struct wilc_spi {};

static const struct wilc_hif_func wilc_hif_spi;

static int wilc_spi_reset(struct wilc *wilc);
static int wilc_spi_configure_bus_protocol(struct wilc *wilc);
static int wilc_validate_chipid(struct wilc *wilc);

/********************************************
 *
 *      Spi protocol Function
 *
 ********************************************/

#define CMD_DMA_WRITE
#define CMD_DMA_READ
#define CMD_INTERNAL_WRITE
#define CMD_INTERNAL_READ
#define CMD_TERMINATE
#define CMD_REPEAT
#define CMD_DMA_EXT_WRITE
#define CMD_DMA_EXT_READ
#define CMD_SINGLE_WRITE
#define CMD_SINGLE_READ
#define CMD_RESET

#define SPI_RETRY_MAX_LIMIT
#define SPI_ENABLE_VMM_RETRY_LIMIT

/* SPI response fields (section 11.1.2 in ATWILC1000 User Guide): */
#define RSP_START_FIELD
#define RSP_TYPE_FIELD

/* SPI response values for the response fields: */
#define RSP_START_TAG
#define RSP_TYPE_FIRST_PACKET
#define RSP_TYPE_INNER_PACKET
#define RSP_TYPE_LAST_PACKET
#define RSP_STATE_NO_ERROR

#define PROTOCOL_REG_PKT_SZ_MASK
#define PROTOCOL_REG_CRC16_MASK
#define PROTOCOL_REG_CRC7_MASK

/*
 * The SPI data packet size may be any integer power of two in the
 * range from 256 to 8192 bytes.
 */
#define DATA_PKT_LOG_SZ_MIN
#define DATA_PKT_LOG_SZ_MAX

/*
 * Select the data packet size (log2 of number of bytes): Use the
 * maximum data packet size.  We only retransmit complete packets, so
 * there is no benefit from using smaller data packets.
 */
#define DATA_PKT_LOG_SZ
#define DATA_PKT_SZ

#define WILC_SPI_COMMAND_STAT_SUCCESS
#define WILC_GET_RESP_HDR_START(h)

struct wilc_spi_cmd {} __packed;

struct wilc_spi_read_rsp_data {} __packed;

struct wilc_spi_rsp_data {} __packed;

struct wilc_spi_special_cmd_rsp {} __packed;

static int wilc_parse_gpios(struct wilc *wilc)
{}

static void wilc_wlan_power(struct wilc *wilc, bool on)
{}

static int wilc_bus_probe(struct spi_device *spi)
{}

static void wilc_bus_remove(struct spi_device *spi)
{}

static const struct of_device_id wilc_of_match[] =;
MODULE_DEVICE_TABLE(of, wilc_of_match);

static const struct spi_device_id wilc_spi_id[] =;
MODULE_DEVICE_TABLE(spi, wilc_spi_id);

static struct spi_driver wilc_spi_driver =;
module_spi_driver();
MODULE_DESCRIPTION();
MODULE_LICENSE();

static int wilc_spi_tx(struct wilc *wilc, u8 *b, u32 len)
{}

static int wilc_spi_rx(struct wilc *wilc, u8 *rb, u32 rlen)
{}

static int wilc_spi_tx_rx(struct wilc *wilc, u8 *wb, u8 *rb, u32 rlen)
{}

static int spi_data_write(struct wilc *wilc, u8 *b, u32 sz)
{}

/********************************************
 *
 *      Spi Internal Read/Write Function
 *
 ********************************************/
static u8 wilc_get_crc7(u8 *buffer, u32 len)
{}

static int wilc_spi_single_read(struct wilc *wilc, u8 cmd, u32 adr, void *b,
				u8 clockless)
{}

static int wilc_spi_write_cmd(struct wilc *wilc, u8 cmd, u32 adr, u32 data,
			      u8 clockless)
{}

static int wilc_spi_dma_rw(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz)
{}

static int wilc_spi_special_cmd(struct wilc *wilc, u8 cmd)
{}

static void wilc_spi_reset_cmd_sequence(struct wilc *wl, u8 attempt, u32 addr)
{}

static int wilc_spi_read_reg(struct wilc *wilc, u32 addr, u32 *data)
{}

static int wilc_spi_read(struct wilc *wilc, u32 addr, u8 *buf, u32 size)
{}

static int spi_internal_write(struct wilc *wilc, u32 adr, u32 dat)
{}

static int spi_internal_read(struct wilc *wilc, u32 adr, u32 *data)
{}

/********************************************
 *
 *      Spi interfaces
 *
 ********************************************/

static int wilc_spi_write_reg(struct wilc *wilc, u32 addr, u32 data)
{}

static int spi_data_rsp(struct wilc *wilc, u8 cmd)
{}

static int wilc_spi_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size)
{}

/********************************************
 *
 *      Bus interfaces
 *
 ********************************************/

static int wilc_spi_reset(struct wilc *wilc)
{}

static bool wilc_spi_is_init(struct wilc *wilc)
{}

static int wilc_spi_deinit(struct wilc *wilc)
{}

static int wilc_spi_init(struct wilc *wilc, bool resume)
{}

static int wilc_spi_configure_bus_protocol(struct wilc *wilc)
{}

static int wilc_validate_chipid(struct wilc *wilc)
{}

static int wilc_spi_read_size(struct wilc *wilc, u32 *size)
{}

static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status)
{}

static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val)
{}

static int wilc_spi_sync_ext(struct wilc *wilc, int nint)
{}

/* Global spi HIF function table */
static const struct wilc_hif_func wilc_hif_spi =;