Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 1 | /* |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 2 | * This file is part of wl1251 |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 1998-2007 Texas Instruments Incorporated |
| 5 | * Copyright (C) 2008 Nokia Corporation |
| 6 | * |
| 7 | * Contact: Kalle Valo <kalle.valo@nokia.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * version 2 as published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 21 | * 02110-1301 USA |
| 22 | * |
| 23 | */ |
| 24 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 25 | #ifndef __WL1251_SPI_H__ |
| 26 | #define __WL1251_SPI_H__ |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 27 | |
Kalle Valo | ef2f8d4 | 2009-06-12 14:17:19 +0300 | [diff] [blame] | 28 | #include "wl1251_cmd.h" |
| 29 | #include "wl1251_acx.h" |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 30 | #include "reg.h" |
| 31 | |
| 32 | #define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0 |
| 33 | |
| 34 | #define HW_ACCESS_PART0_SIZE_ADDR 0x1FFC0 |
| 35 | #define HW_ACCESS_PART0_START_ADDR 0x1FFC4 |
| 36 | #define HW_ACCESS_PART1_SIZE_ADDR 0x1FFC8 |
| 37 | #define HW_ACCESS_PART1_START_ADDR 0x1FFCC |
| 38 | |
| 39 | #define HW_ACCESS_REGISTER_SIZE 4 |
| 40 | |
| 41 | #define HW_ACCESS_PRAM_MAX_RANGE 0x3c000 |
| 42 | |
| 43 | #define WSPI_CMD_READ 0x40000000 |
| 44 | #define WSPI_CMD_WRITE 0x00000000 |
| 45 | #define WSPI_CMD_FIXED 0x20000000 |
| 46 | #define WSPI_CMD_BYTE_LENGTH 0x1FFE0000 |
| 47 | #define WSPI_CMD_BYTE_LENGTH_OFFSET 17 |
| 48 | #define WSPI_CMD_BYTE_ADDR 0x0001FFFF |
| 49 | |
| 50 | #define WSPI_INIT_CMD_CRC_LEN 5 |
| 51 | |
| 52 | #define WSPI_INIT_CMD_START 0x00 |
| 53 | #define WSPI_INIT_CMD_TX 0x40 |
| 54 | /* the extra bypass bit is sampled by the TNET as '1' */ |
| 55 | #define WSPI_INIT_CMD_BYPASS_BIT 0x80 |
| 56 | #define WSPI_INIT_CMD_FIXEDBUSY_LEN 0x07 |
| 57 | #define WSPI_INIT_CMD_EN_FIXEDBUSY 0x80 |
| 58 | #define WSPI_INIT_CMD_DIS_FIXEDBUSY 0x00 |
| 59 | #define WSPI_INIT_CMD_IOD 0x40 |
| 60 | #define WSPI_INIT_CMD_IP 0x20 |
| 61 | #define WSPI_INIT_CMD_CS 0x10 |
| 62 | #define WSPI_INIT_CMD_WS 0x08 |
| 63 | #define WSPI_INIT_CMD_WSPI 0x01 |
| 64 | #define WSPI_INIT_CMD_END 0x01 |
| 65 | |
| 66 | #define WSPI_INIT_CMD_LEN 8 |
| 67 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 68 | #define HW_ACCESS_WSPI_FIXED_BUSY_LEN \ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 69 | ((WL1251_BUSY_WORD_LEN - 4) / sizeof(u32)) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 70 | #define HW_ACCESS_WSPI_INIT_CMD_MASK 0 |
| 71 | |
| 72 | |
| 73 | /* Raw target IO, address is not translated */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 74 | void wl1251_spi_write(struct wl1251 *wl, int addr, void *buf, |
Juuso Oikarinen | 8ec8beb | 2009-06-12 14:16:00 +0300 | [diff] [blame] | 75 | size_t len, bool fixed); |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 76 | void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf, |
Luciano Coelho | 052a625 | 2009-06-12 14:15:41 +0300 | [diff] [blame] | 77 | size_t len, bool fixed); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 78 | |
| 79 | /* Memory target IO, address is tranlated to partition 0 */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 80 | void wl1251_spi_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len); |
| 81 | void wl1251_spi_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len); |
| 82 | u32 wl1251_mem_read32(struct wl1251 *wl, int addr); |
| 83 | void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 84 | |
| 85 | /* Registers IO */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 86 | void wl1251_spi_reg_read(struct wl1251 *wl, int addr, void *buf, size_t len, |
Luciano Coelho | 052a625 | 2009-06-12 14:15:41 +0300 | [diff] [blame] | 87 | bool fixed); |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 88 | void wl1251_spi_reg_write(struct wl1251 *wl, int addr, void *buf, size_t len, |
Juuso Oikarinen | 8ec8beb | 2009-06-12 14:16:00 +0300 | [diff] [blame] | 89 | bool fixed); |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 90 | u32 wl1251_reg_read32(struct wl1251 *wl, int addr); |
| 91 | void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 92 | |
| 93 | /* INIT and RESET words */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 94 | void wl1251_spi_reset(struct wl1251 *wl); |
| 95 | void wl1251_spi_init(struct wl1251 *wl); |
| 96 | int wl1251_set_partition(struct wl1251 *wl, |
Kalle Valo | 8d47cdb | 2009-06-12 14:14:41 +0300 | [diff] [blame] | 97 | u32 part_start, u32 part_size, |
| 98 | u32 reg_start, u32 reg_size); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 99 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 100 | static inline u32 wl1251_read32(struct wl1251 *wl, int addr) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 101 | { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 102 | wl1251_spi_read(wl, addr, &wl->buffer_32, |
Luciano Coelho | 052a625 | 2009-06-12 14:15:41 +0300 | [diff] [blame] | 103 | sizeof(wl->buffer_32), false); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 104 | |
Kalle Valo | 1d3b813 | 2009-06-12 14:14:28 +0300 | [diff] [blame] | 105 | return wl->buffer_32; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 106 | } |
| 107 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 108 | static inline void wl1251_write32(struct wl1251 *wl, int addr, u32 val) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 109 | { |
Kalle Valo | 1d3b813 | 2009-06-12 14:14:28 +0300 | [diff] [blame] | 110 | wl->buffer_32 = val; |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 111 | wl1251_spi_write(wl, addr, &wl->buffer_32, |
Juuso Oikarinen | 8ec8beb | 2009-06-12 14:16:00 +0300 | [diff] [blame] | 112 | sizeof(wl->buffer_32), false); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 113 | } |
| 114 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame^] | 115 | #endif /* __WL1251_SPI_H__ */ |