18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2008 Christian Lamparter <chunkeey@web.de>
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This driver is a port from stlc45xx:
68c2ecf20Sopenharmony_ci *	Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef P54SPI_H
108c2ecf20Sopenharmony_ci#define P54SPI_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/mutex.h>
138c2ecf20Sopenharmony_ci#include <linux/list.h>
148c2ecf20Sopenharmony_ci#include <net/mac80211.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include "p54.h"
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/* Bit 15 is read/write bit; ON = READ, OFF = WRITE */
198c2ecf20Sopenharmony_ci#define SPI_ADRS_READ_BIT_15		0x8000
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define SPI_ADRS_ARM_INTERRUPTS		0x00
228c2ecf20Sopenharmony_ci#define SPI_ADRS_ARM_INT_EN		0x04
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define SPI_ADRS_HOST_INTERRUPTS	0x08
258c2ecf20Sopenharmony_ci#define SPI_ADRS_HOST_INT_EN		0x0c
268c2ecf20Sopenharmony_ci#define SPI_ADRS_HOST_INT_ACK		0x10
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define SPI_ADRS_GEN_PURP_1		0x14
298c2ecf20Sopenharmony_ci#define SPI_ADRS_GEN_PURP_2		0x18
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define SPI_ADRS_DEV_CTRL_STAT		0x26    /* high word */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define SPI_ADRS_DMA_DATA		0x28
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define SPI_ADRS_DMA_WRITE_CTRL		0x2c
368c2ecf20Sopenharmony_ci#define SPI_ADRS_DMA_WRITE_LEN		0x2e
378c2ecf20Sopenharmony_ci#define SPI_ADRS_DMA_WRITE_BASE		0x30
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define SPI_ADRS_DMA_READ_CTRL		0x34
408c2ecf20Sopenharmony_ci#define SPI_ADRS_DMA_READ_LEN		0x36
418c2ecf20Sopenharmony_ci#define SPI_ADRS_DMA_READ_BASE		0x38
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define SPI_CTRL_STAT_HOST_OVERRIDE	0x8000
448c2ecf20Sopenharmony_ci#define SPI_CTRL_STAT_START_HALTED	0x4000
458c2ecf20Sopenharmony_ci#define SPI_CTRL_STAT_RAM_BOOT		0x2000
468c2ecf20Sopenharmony_ci#define SPI_CTRL_STAT_HOST_RESET	0x1000
478c2ecf20Sopenharmony_ci#define SPI_CTRL_STAT_HOST_CPU_EN	0x0800
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define SPI_DMA_WRITE_CTRL_ENABLE	0x0001
508c2ecf20Sopenharmony_ci#define SPI_DMA_READ_CTRL_ENABLE	0x0001
518c2ecf20Sopenharmony_ci#define HOST_ALLOWED			(1 << 7)
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#define SPI_TIMEOUT			100         /* msec */
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define SPI_MAX_TX_PACKETS		32
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define SPI_MAX_PACKET_SIZE		32767
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define SPI_TARGET_INT_WAKEUP		0x00000001
608c2ecf20Sopenharmony_ci#define SPI_TARGET_INT_SLEEP		0x00000002
618c2ecf20Sopenharmony_ci#define SPI_TARGET_INT_RDDONE		0x00000004
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define SPI_TARGET_INT_CTS		0x00004000
648c2ecf20Sopenharmony_ci#define SPI_TARGET_INT_DR		0x00008000
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define SPI_HOST_INT_READY		0x00000001
678c2ecf20Sopenharmony_ci#define SPI_HOST_INT_WR_READY		0x00000002
688c2ecf20Sopenharmony_ci#define SPI_HOST_INT_SW_UPDATE		0x00000004
698c2ecf20Sopenharmony_ci#define SPI_HOST_INT_UPDATE		0x10000000
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci/* clear to send */
728c2ecf20Sopenharmony_ci#define SPI_HOST_INT_CR			0x00004000
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/* data ready */
758c2ecf20Sopenharmony_ci#define SPI_HOST_INT_DR			0x00008000
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#define SPI_HOST_INTS_DEFAULT 						    \
788c2ecf20Sopenharmony_ci	(SPI_HOST_INT_READY | SPI_HOST_INT_UPDATE | SPI_HOST_INT_SW_UPDATE)
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci#define TARGET_BOOT_SLEEP 50
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cistruct p54s_dma_regs {
838c2ecf20Sopenharmony_ci	__le16 cmd;
848c2ecf20Sopenharmony_ci	__le16 len;
858c2ecf20Sopenharmony_ci	__le32 addr;
868c2ecf20Sopenharmony_ci} __packed;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistruct p54s_tx_info {
898c2ecf20Sopenharmony_ci	struct list_head tx_list;
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistruct p54s_priv {
938c2ecf20Sopenharmony_ci	/* p54_common has to be the first entry */
948c2ecf20Sopenharmony_ci	struct p54_common common;
958c2ecf20Sopenharmony_ci	struct ieee80211_hw *hw;
968c2ecf20Sopenharmony_ci	struct spi_device *spi;
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	struct work_struct work;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	struct mutex mutex;
1018c2ecf20Sopenharmony_ci	struct completion fw_comp;
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	spinlock_t tx_lock;
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	/* protected by tx_lock */
1068c2ecf20Sopenharmony_ci	struct list_head tx_pending;
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	enum fw_state fw_state;
1098c2ecf20Sopenharmony_ci	const struct firmware *firmware;
1108c2ecf20Sopenharmony_ci};
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#endif /* P54SPI_H */
113