blob: e450e31fd11dce84b2a6544759ee34befc77a567 [file] [log] [blame]
Colin McCabed2b21f12009-01-09 14:58:09 -08001/*
2 * linux/drivers/net/wireless/libertas/if_spi.c
3 *
4 * Driver for Marvell SPI WLAN cards.
5 *
6 * Copyright 2008 Analog Devices Inc.
7 *
8 * Authors:
9 * Andrey Yurovsky <andrey@cozybit.com>
10 * Colin McCabe <colin@cozybit.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
16 */
17
18#ifndef _LBS_IF_SPI_H_
19#define _LBS_IF_SPI_H_
20
21#define IPFIELD_ALIGN_OFFSET 2
22#define IF_SPI_CMD_BUF_SIZE 2400
23
24/***************** Firmware *****************/
John W. Linvillecadeba32009-05-27 00:49:36 +020025
26#define IF_SPI_FW_NAME_MAX 30
27
Colin McCabed2b21f12009-01-09 14:58:09 -080028#define MAX_MAIN_FW_LOAD_CRC_ERR 10
29
30/* Chunk size when loading the helper firmware */
31#define HELPER_FW_LOAD_CHUNK_SZ 64
32
33/* Value to write to indicate end of helper firmware dnld */
34#define FIRMWARE_DNLD_OK 0x0000
35
36/* Value to check once the main firmware is downloaded */
37#define SUCCESSFUL_FW_DOWNLOAD_MAGIC 0x88888888
38
39/***************** SPI Interface Unit *****************/
40/* Masks used in SPI register read/write operations */
41#define IF_SPI_READ_OPERATION_MASK 0x0
42#define IF_SPI_WRITE_OPERATION_MASK 0x8000
43
44/* SPI register offsets. 4-byte aligned. */
45#define IF_SPI_DEVICEID_CTRL_REG 0x00 /* DeviceID controller reg */
46#define IF_SPI_IO_READBASE_REG 0x04 /* Read I/O base reg */
47#define IF_SPI_IO_WRITEBASE_REG 0x08 /* Write I/O base reg */
48#define IF_SPI_IO_RDWRPORT_REG 0x0C /* Read/Write I/O port reg */
49
50#define IF_SPI_CMD_READBASE_REG 0x10 /* Read command base reg */
51#define IF_SPI_CMD_WRITEBASE_REG 0x14 /* Write command base reg */
52#define IF_SPI_CMD_RDWRPORT_REG 0x18 /* Read/Write command port reg */
53
54#define IF_SPI_DATA_READBASE_REG 0x1C /* Read data base reg */
55#define IF_SPI_DATA_WRITEBASE_REG 0x20 /* Write data base reg */
56#define IF_SPI_DATA_RDWRPORT_REG 0x24 /* Read/Write data port reg */
57
58#define IF_SPI_SCRATCH_1_REG 0x28 /* Scratch reg 1 */
59#define IF_SPI_SCRATCH_2_REG 0x2C /* Scratch reg 2 */
60#define IF_SPI_SCRATCH_3_REG 0x30 /* Scratch reg 3 */
61#define IF_SPI_SCRATCH_4_REG 0x34 /* Scratch reg 4 */
62
63#define IF_SPI_TX_FRAME_SEQ_NUM_REG 0x38 /* Tx frame sequence number reg */
64#define IF_SPI_TX_FRAME_STATUS_REG 0x3C /* Tx frame status reg */
65
66#define IF_SPI_HOST_INT_CTRL_REG 0x40 /* Host interrupt controller reg */
67
68#define IF_SPI_CARD_INT_CAUSE_REG 0x44 /* Card interrupt cause reg */
Lucas De Marchi25985ed2011-03-30 22:57:33 -030069#define IF_SPI_CARD_INT_STATUS_REG 0x48 /* Card interrupt status reg */
Colin McCabed2b21f12009-01-09 14:58:09 -080070#define IF_SPI_CARD_INT_EVENT_MASK_REG 0x4C /* Card interrupt event mask */
71#define IF_SPI_CARD_INT_STATUS_MASK_REG 0x50 /* Card interrupt status mask */
72
73#define IF_SPI_CARD_INT_RESET_SELECT_REG 0x54 /* Card interrupt reset select */
74
75#define IF_SPI_HOST_INT_CAUSE_REG 0x58 /* Host interrupt cause reg */
76#define IF_SPI_HOST_INT_STATUS_REG 0x5C /* Host interrupt status reg */
77#define IF_SPI_HOST_INT_EVENT_MASK_REG 0x60 /* Host interrupt event mask */
78#define IF_SPI_HOST_INT_STATUS_MASK_REG 0x64 /* Host interrupt status mask */
79#define IF_SPI_HOST_INT_RESET_SELECT_REG 0x68 /* Host interrupt reset select */
80
81#define IF_SPI_DELAY_READ_REG 0x6C /* Delay read reg */
82#define IF_SPI_SPU_BUS_MODE_REG 0x70 /* SPU BUS mode reg */
83
84/***************** IF_SPI_DEVICEID_CTRL_REG *****************/
85#define IF_SPI_DEVICEID_CTRL_REG_TO_CARD_ID(dc) ((dc & 0xffff0000)>>16)
86#define IF_SPI_DEVICEID_CTRL_REG_TO_CARD_REV(dc) (dc & 0x000000ff)
87
88/***************** IF_SPI_HOST_INT_CTRL_REG *****************/
Randy Dunlap8973a6e2011-04-26 15:25:29 -070089/* Host Interrupt Control bit : Wake up */
Colin McCabed2b21f12009-01-09 14:58:09 -080090#define IF_SPI_HICT_WAKE_UP (1<<0)
Randy Dunlap8973a6e2011-04-26 15:25:29 -070091/* Host Interrupt Control bit : WLAN ready */
Colin McCabed2b21f12009-01-09 14:58:09 -080092#define IF_SPI_HICT_WLAN_READY (1<<1)
93/*#define IF_SPI_HICT_FIFO_FIRST_HALF_EMPTY (1<<2) */
94/*#define IF_SPI_HICT_FIFO_SECOND_HALF_EMPTY (1<<3) */
95/*#define IF_SPI_HICT_IRQSRC_WLAN (1<<4) */
Randy Dunlap8973a6e2011-04-26 15:25:29 -070096/* Host Interrupt Control bit : Tx auto download */
Colin McCabed2b21f12009-01-09 14:58:09 -080097#define IF_SPI_HICT_TX_DOWNLOAD_OVER_AUTO (1<<5)
Randy Dunlap8973a6e2011-04-26 15:25:29 -070098/* Host Interrupt Control bit : Rx auto upload */
Colin McCabed2b21f12009-01-09 14:58:09 -080099#define IF_SPI_HICT_RX_UPLOAD_OVER_AUTO (1<<6)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700100/* Host Interrupt Control bit : Command auto download */
Colin McCabed2b21f12009-01-09 14:58:09 -0800101#define IF_SPI_HICT_CMD_DOWNLOAD_OVER_AUTO (1<<7)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700102/* Host Interrupt Control bit : Command auto upload */
Colin McCabed2b21f12009-01-09 14:58:09 -0800103#define IF_SPI_HICT_CMD_UPLOAD_OVER_AUTO (1<<8)
104
105/***************** IF_SPI_CARD_INT_CAUSE_REG *****************/
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700106/* Card Interrupt Case bit : Tx download over */
Colin McCabed2b21f12009-01-09 14:58:09 -0800107#define IF_SPI_CIC_TX_DOWNLOAD_OVER (1<<0)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700108/* Card Interrupt Case bit : Rx upload over */
Colin McCabed2b21f12009-01-09 14:58:09 -0800109#define IF_SPI_CIC_RX_UPLOAD_OVER (1<<1)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700110/* Card Interrupt Case bit : Command download over */
Colin McCabed2b21f12009-01-09 14:58:09 -0800111#define IF_SPI_CIC_CMD_DOWNLOAD_OVER (1<<2)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700112/* Card Interrupt Case bit : Host event */
Colin McCabed2b21f12009-01-09 14:58:09 -0800113#define IF_SPI_CIC_HOST_EVENT (1<<3)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700114/* Card Interrupt Case bit : Command upload over */
Colin McCabed2b21f12009-01-09 14:58:09 -0800115#define IF_SPI_CIC_CMD_UPLOAD_OVER (1<<4)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700116/* Card Interrupt Case bit : Power down */
Colin McCabed2b21f12009-01-09 14:58:09 -0800117#define IF_SPI_CIC_POWER_DOWN (1<<5)
118
119/***************** IF_SPI_CARD_INT_STATUS_REG *****************/
120#define IF_SPI_CIS_TX_DOWNLOAD_OVER (1<<0)
121#define IF_SPI_CIS_RX_UPLOAD_OVER (1<<1)
122#define IF_SPI_CIS_CMD_DOWNLOAD_OVER (1<<2)
123#define IF_SPI_CIS_HOST_EVENT (1<<3)
124#define IF_SPI_CIS_CMD_UPLOAD_OVER (1<<4)
125#define IF_SPI_CIS_POWER_DOWN (1<<5)
126
127/***************** IF_SPI_HOST_INT_CAUSE_REG *****************/
128#define IF_SPI_HICU_TX_DOWNLOAD_RDY (1<<0)
129#define IF_SPI_HICU_RX_UPLOAD_RDY (1<<1)
130#define IF_SPI_HICU_CMD_DOWNLOAD_RDY (1<<2)
131#define IF_SPI_HICU_CARD_EVENT (1<<3)
132#define IF_SPI_HICU_CMD_UPLOAD_RDY (1<<4)
133#define IF_SPI_HICU_IO_WR_FIFO_OVERFLOW (1<<5)
134#define IF_SPI_HICU_IO_RD_FIFO_UNDERFLOW (1<<6)
135#define IF_SPI_HICU_DATA_WR_FIFO_OVERFLOW (1<<7)
136#define IF_SPI_HICU_DATA_RD_FIFO_UNDERFLOW (1<<8)
137#define IF_SPI_HICU_CMD_WR_FIFO_OVERFLOW (1<<9)
138#define IF_SPI_HICU_CMD_RD_FIFO_UNDERFLOW (1<<10)
139
140/***************** IF_SPI_HOST_INT_STATUS_REG *****************/
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700141/* Host Interrupt Status bit : Tx download ready */
Colin McCabed2b21f12009-01-09 14:58:09 -0800142#define IF_SPI_HIST_TX_DOWNLOAD_RDY (1<<0)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700143/* Host Interrupt Status bit : Rx upload ready */
Colin McCabed2b21f12009-01-09 14:58:09 -0800144#define IF_SPI_HIST_RX_UPLOAD_RDY (1<<1)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700145/* Host Interrupt Status bit : Command download ready */
Colin McCabed2b21f12009-01-09 14:58:09 -0800146#define IF_SPI_HIST_CMD_DOWNLOAD_RDY (1<<2)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700147/* Host Interrupt Status bit : Card event */
Colin McCabed2b21f12009-01-09 14:58:09 -0800148#define IF_SPI_HIST_CARD_EVENT (1<<3)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700149/* Host Interrupt Status bit : Command upload ready */
Colin McCabed2b21f12009-01-09 14:58:09 -0800150#define IF_SPI_HIST_CMD_UPLOAD_RDY (1<<4)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700151/* Host Interrupt Status bit : I/O write FIFO overflow */
Colin McCabed2b21f12009-01-09 14:58:09 -0800152#define IF_SPI_HIST_IO_WR_FIFO_OVERFLOW (1<<5)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700153/* Host Interrupt Status bit : I/O read FIFO underflow */
Colin McCabed2b21f12009-01-09 14:58:09 -0800154#define IF_SPI_HIST_IO_RD_FIFO_UNDRFLOW (1<<6)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700155/* Host Interrupt Status bit : Data write FIFO overflow */
Colin McCabed2b21f12009-01-09 14:58:09 -0800156#define IF_SPI_HIST_DATA_WR_FIFO_OVERFLOW (1<<7)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700157/* Host Interrupt Status bit : Data read FIFO underflow */
Colin McCabed2b21f12009-01-09 14:58:09 -0800158#define IF_SPI_HIST_DATA_RD_FIFO_UNDERFLOW (1<<8)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700159/* Host Interrupt Status bit : Command write FIFO overflow */
Colin McCabed2b21f12009-01-09 14:58:09 -0800160#define IF_SPI_HIST_CMD_WR_FIFO_OVERFLOW (1<<9)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700161/* Host Interrupt Status bit : Command read FIFO underflow */
Colin McCabed2b21f12009-01-09 14:58:09 -0800162#define IF_SPI_HIST_CMD_RD_FIFO_UNDERFLOW (1<<10)
163
164/***************** IF_SPI_HOST_INT_STATUS_MASK_REG *****************/
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700165/* Host Interrupt Status Mask bit : Tx download ready */
Colin McCabed2b21f12009-01-09 14:58:09 -0800166#define IF_SPI_HISM_TX_DOWNLOAD_RDY (1<<0)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700167/* Host Interrupt Status Mask bit : Rx upload ready */
Colin McCabed2b21f12009-01-09 14:58:09 -0800168#define IF_SPI_HISM_RX_UPLOAD_RDY (1<<1)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700169/* Host Interrupt Status Mask bit : Command download ready */
Colin McCabed2b21f12009-01-09 14:58:09 -0800170#define IF_SPI_HISM_CMD_DOWNLOAD_RDY (1<<2)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700171/* Host Interrupt Status Mask bit : Card event */
Colin McCabed2b21f12009-01-09 14:58:09 -0800172#define IF_SPI_HISM_CARDEVENT (1<<3)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700173/* Host Interrupt Status Mask bit : Command upload ready */
Colin McCabed2b21f12009-01-09 14:58:09 -0800174#define IF_SPI_HISM_CMD_UPLOAD_RDY (1<<4)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700175/* Host Interrupt Status Mask bit : I/O write FIFO overflow */
Colin McCabed2b21f12009-01-09 14:58:09 -0800176#define IF_SPI_HISM_IO_WR_FIFO_OVERFLOW (1<<5)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700177/* Host Interrupt Status Mask bit : I/O read FIFO underflow */
Colin McCabed2b21f12009-01-09 14:58:09 -0800178#define IF_SPI_HISM_IO_RD_FIFO_UNDERFLOW (1<<6)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700179/* Host Interrupt Status Mask bit : Data write FIFO overflow */
Colin McCabed2b21f12009-01-09 14:58:09 -0800180#define IF_SPI_HISM_DATA_WR_FIFO_OVERFLOW (1<<7)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700181/* Host Interrupt Status Mask bit : Data write FIFO underflow */
Colin McCabed2b21f12009-01-09 14:58:09 -0800182#define IF_SPI_HISM_DATA_RD_FIFO_UNDERFLOW (1<<8)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700183/* Host Interrupt Status Mask bit : Command write FIFO overflow */
Colin McCabed2b21f12009-01-09 14:58:09 -0800184#define IF_SPI_HISM_CMD_WR_FIFO_OVERFLOW (1<<9)
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700185/* Host Interrupt Status Mask bit : Command write FIFO underflow */
Colin McCabed2b21f12009-01-09 14:58:09 -0800186#define IF_SPI_HISM_CMD_RD_FIFO_UNDERFLOW (1<<10)
187
188/***************** IF_SPI_SPU_BUS_MODE_REG *****************/
189/* SCK edge on which the WLAN module outputs data on MISO */
190#define IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_FALLING 0x8
191#define IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_RISING 0x0
192
193/* In a SPU read operation, there is a delay between writing the SPU
194 * register name and getting back data from the WLAN module.
195 * This can be specified in terms of nanoseconds or in terms of dummy
196 * clock cycles which the master must output before receiving a response. */
197#define IF_SPI_BUS_MODE_DELAY_METHOD_DUMMY_CLOCK 0x4
198#define IF_SPI_BUS_MODE_DELAY_METHOD_TIMED 0x0
199
200/* Some different modes of SPI operation */
201#define IF_SPI_BUS_MODE_8_BIT_ADDRESS_16_BIT_DATA 0x00
202#define IF_SPI_BUS_MODE_8_BIT_ADDRESS_32_BIT_DATA 0x01
203#define IF_SPI_BUS_MODE_16_BIT_ADDRESS_16_BIT_DATA 0x02
204#define IF_SPI_BUS_MODE_16_BIT_ADDRESS_32_BIT_DATA 0x03
205
206#endif