| .. | .. |
|---|
| 1 | | -/* SPDX-License-Identifier: GPL-2.0 */ |
|---|
| 2 | 1 | /* |
|---|
| 3 | 2 | * Broadcom BCMSDH to gSPI Protocol Conversion Layer |
|---|
| 4 | 3 | * |
|---|
| 5 | | - * Copyright (C) 1999-2019, Broadcom Corporation |
|---|
| 6 | | - * |
|---|
| 4 | + * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation |
|---|
| 5 | + * |
|---|
| 6 | + * Copyright (C) 1999-2017, Broadcom Corporation |
|---|
| 7 | + * |
|---|
| 7 | 8 | * Unless you and Broadcom execute a separate written software license |
|---|
| 8 | 9 | * agreement governing use of this software, this software is licensed to you |
|---|
| 9 | 10 | * under the terms of the GNU General Public License version 2 (the "GPL"), |
|---|
| 10 | 11 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the |
|---|
| 11 | 12 | * following added to such license: |
|---|
| 12 | | - * |
|---|
| 13 | + * |
|---|
| 13 | 14 | * As a special exception, the copyright holders of this software give you |
|---|
| 14 | 15 | * permission to link this software with independent modules, and to copy and |
|---|
| 15 | 16 | * distribute the resulting executable under terms of your choice, provided that |
|---|
| .. | .. |
|---|
| 17 | 18 | * the license of that module. An independent module is a module which is not |
|---|
| 18 | 19 | * derived from this software. The special exception does not apply to any |
|---|
| 19 | 20 | * modifications of the software. |
|---|
| 20 | | - * |
|---|
| 21 | + * |
|---|
| 21 | 22 | * Notwithstanding the above, under no circumstances may you combine this |
|---|
| 22 | 23 | * software in any way with any other Broadcom software provided under a license |
|---|
| 23 | 24 | * other than the GPL, without Broadcom's express prior written consent. |
|---|
| .. | .. |
|---|
| 25 | 26 | * |
|---|
| 26 | 27 | * <<Broadcom-WL-IPTag/Open:>> |
|---|
| 27 | 28 | * |
|---|
| 28 | | - * $Id: bcmspibrcm.c 514727 2014-11-12 03:02:48Z $ |
|---|
| 29 | + * $Id: bcmspibrcm.c 700323 2017-05-18 16:12:11Z $ |
|---|
| 29 | 30 | */ |
|---|
| 30 | 31 | |
|---|
| 31 | 32 | #define HSMODE |
|---|
| .. | .. |
|---|
| 48 | 49 | |
|---|
| 49 | 50 | #include <pcicfg.h> |
|---|
| 50 | 51 | |
|---|
| 51 | | - |
|---|
| 52 | 52 | #include <bcmspibrcm.h> |
|---|
| 53 | +#ifdef BCMSPI_ANDROID |
|---|
| 54 | +extern void spi_sendrecv(sdioh_info_t *sd, uint8 *msg_out, uint8 *msg_in, int msglen); |
|---|
| 55 | +#else |
|---|
| 53 | 56 | #include <bcmspi.h> |
|---|
| 57 | +#endif /* BCMSPI_ANDROID */ |
|---|
| 54 | 58 | |
|---|
| 55 | 59 | /* these are for the older cores... for newer cores we have control for each of them */ |
|---|
| 56 | 60 | #define F0_RESPONSE_DELAY 16 |
|---|
| 57 | 61 | #define F1_RESPONSE_DELAY 16 |
|---|
| 58 | 62 | #define F2_RESPONSE_DELAY F0_RESPONSE_DELAY |
|---|
| 59 | | - |
|---|
| 60 | 63 | |
|---|
| 61 | 64 | #define GSPI_F0_RESP_DELAY 0 |
|---|
| 62 | 65 | #define GSPI_F1_RESP_DELAY F1_RESPONSE_DELAY |
|---|
| .. | .. |
|---|
| 65 | 68 | |
|---|
| 66 | 69 | #define CMDLEN 4 |
|---|
| 67 | 70 | |
|---|
| 68 | | -#define DWORDMODE_ON (sd->chip == BCM4329_CHIP_ID) && (sd->chiprev == 2) && (sd->dwordmode == TRUE) |
|---|
| 69 | | - |
|---|
| 70 | 71 | /* Globals */ |
|---|
| 71 | 72 | #if defined(DHD_DEBUG) |
|---|
| 72 | 73 | uint sd_msglevel = SDH_ERROR_VAL; |
|---|
| 73 | 74 | #else |
|---|
| 74 | 75 | uint sd_msglevel = 0; |
|---|
| 75 | | -#endif |
|---|
| 76 | +#endif // endif |
|---|
| 76 | 77 | |
|---|
| 77 | 78 | uint sd_hiok = FALSE; /* Use hi-speed mode if available? */ |
|---|
| 78 | 79 | uint sd_sdmode = SDIOH_MODE_SPI; /* Use SD4 mode by default */ |
|---|
| 80 | +uint sd_f1_blocksize = 64; /* Default blocksize */ |
|---|
| 79 | 81 | uint sd_f2_blocksize = 64; /* Default blocksize */ |
|---|
| 80 | 82 | |
|---|
| 81 | | - |
|---|
| 82 | | -uint sd_divisor = 2; |
|---|
| 83 | +uint sd_divisor = 1; |
|---|
| 83 | 84 | uint sd_power = 1; /* Default to SD Slot powered ON */ |
|---|
| 84 | 85 | uint sd_clock = 1; /* Default to SD Clock turned ON */ |
|---|
| 85 | 86 | uint sd_crc = 0; /* Default to SPI CRC Check turned OFF */ |
|---|
| .. | .. |
|---|
| 94 | 95 | #define BUF2_PKT_LEN 128 |
|---|
| 95 | 96 | uint8 spi_outbuf2[BUF2_PKT_LEN]; |
|---|
| 96 | 97 | uint8 spi_inbuf2[BUF2_PKT_LEN]; |
|---|
| 98 | +#ifdef BCMSPI_ANDROID |
|---|
| 99 | +uint *dhd_spi_lockcount = NULL; |
|---|
| 100 | +#endif /* BCMSPI_ANDROID */ |
|---|
| 97 | 101 | |
|---|
| 102 | +#if !(defined(SPI_PIO_RW_BIGENDIAN) && defined(SPI_PIO_32BIT_RW)) |
|---|
| 98 | 103 | #define SPISWAP_WD4(x) bcmswap32(x); |
|---|
| 99 | 104 | #define SPISWAP_WD2(x) (bcmswap16(x & 0xffff)) | \ |
|---|
| 100 | 105 | (bcmswap16((x & 0xffff0000) >> 16) << 16); |
|---|
| 106 | +#else |
|---|
| 107 | +#define SPISWAP_WD4(x) x; |
|---|
| 108 | +#define SPISWAP_WD2(x) bcmswap32by16(x); |
|---|
| 109 | +#endif // endif |
|---|
| 101 | 110 | |
|---|
| 102 | 111 | /* Prototypes */ |
|---|
| 103 | 112 | static bool bcmspi_test_card(sdioh_info_t *sd); |
|---|
| .. | .. |
|---|
| 140 | 149 | return NULL; |
|---|
| 141 | 150 | } |
|---|
| 142 | 151 | |
|---|
| 152 | +#ifndef BCMSPI_ANDROID |
|---|
| 143 | 153 | sd->bar0 = bar0; |
|---|
| 154 | +#endif /* !BCMSPI_ANDROID */ |
|---|
| 144 | 155 | sd->irq = irq; |
|---|
| 156 | +#ifndef BCMSPI_ANDROID |
|---|
| 145 | 157 | sd->intr_handler = NULL; |
|---|
| 146 | 158 | sd->intr_handler_arg = NULL; |
|---|
| 147 | 159 | sd->intr_handler_valid = FALSE; |
|---|
| 160 | +#endif /* !BCMSPI_ANDROID */ |
|---|
| 148 | 161 | |
|---|
| 149 | 162 | /* Set defaults */ |
|---|
| 150 | 163 | sd->use_client_ints = TRUE; |
|---|
| .. | .. |
|---|
| 155 | 168 | */ |
|---|
| 156 | 169 | sd->wordlen = 2; |
|---|
| 157 | 170 | |
|---|
| 171 | +#ifdef BCMSPI_ANDROID |
|---|
| 172 | + dhd_spi_lockcount = &sd->lockcount; |
|---|
| 173 | +#endif /* BCMSPI_ANDROID */ |
|---|
| 158 | 174 | |
|---|
| 175 | +#ifndef BCMSPI_ANDROID |
|---|
| 159 | 176 | if (!spi_hw_attach(sd)) { |
|---|
| 160 | 177 | sd_err(("%s: spi_hw_attach() failed\n", __FUNCTION__)); |
|---|
| 161 | 178 | spi_osfree(sd); |
|---|
| 162 | 179 | MFREE(sd->osh, sd, sizeof(sdioh_info_t)); |
|---|
| 163 | 180 | return (NULL); |
|---|
| 164 | 181 | } |
|---|
| 182 | +#endif /* !BCMSPI_ANDROID */ |
|---|
| 165 | 183 | |
|---|
| 166 | 184 | if (bcmspi_driver_init(sd) != SUCCESS) { |
|---|
| 167 | 185 | sd_err(("%s: bcmspi_driver_init() failed()\n", __FUNCTION__)); |
|---|
| 186 | +#ifndef BCMSPI_ANDROID |
|---|
| 168 | 187 | spi_hw_detach(sd); |
|---|
| 188 | +#endif /* !BCMSPI_ANDROID */ |
|---|
| 169 | 189 | spi_osfree(sd); |
|---|
| 170 | 190 | MFREE(sd->osh, sd, sizeof(sdioh_info_t)); |
|---|
| 171 | 191 | return (NULL); |
|---|
| .. | .. |
|---|
| 173 | 193 | |
|---|
| 174 | 194 | if (spi_register_irq(sd, irq) != SUCCESS) { |
|---|
| 175 | 195 | sd_err(("%s: spi_register_irq() failed for irq = %d\n", __FUNCTION__, irq)); |
|---|
| 196 | +#ifndef BCMSPI_ANDROID |
|---|
| 176 | 197 | spi_hw_detach(sd); |
|---|
| 198 | +#endif /* !BCMSPI_ANDROID */ |
|---|
| 177 | 199 | spi_osfree(sd); |
|---|
| 178 | 200 | MFREE(sd->osh, sd, sizeof(sdioh_info_t)); |
|---|
| 179 | 201 | return (NULL); |
|---|
| .. | .. |
|---|
| 191 | 213 | if (sd) { |
|---|
| 192 | 214 | sd_err(("%s: detaching from hardware\n", __FUNCTION__)); |
|---|
| 193 | 215 | spi_free_irq(sd->irq, sd); |
|---|
| 216 | +#ifndef BCMSPI_ANDROID |
|---|
| 194 | 217 | spi_hw_detach(sd); |
|---|
| 218 | +#endif /* !BCMSPI_ANDROID */ |
|---|
| 195 | 219 | spi_osfree(sd); |
|---|
| 220 | +#ifdef BCMSPI_ANDROID |
|---|
| 221 | + dhd_spi_lockcount = NULL; |
|---|
| 222 | +#endif /* !BCMSPI_ANDROID */ |
|---|
| 196 | 223 | MFREE(sd->osh, sd, sizeof(sdioh_info_t)); |
|---|
| 197 | 224 | } |
|---|
| 198 | 225 | return SDIOH_API_RC_SUCCESS; |
|---|
| .. | .. |
|---|
| 226 | 253 | extern SDIOH_API_RC |
|---|
| 227 | 254 | sdioh_interrupt_query(sdioh_info_t *sd, bool *onoff) |
|---|
| 228 | 255 | { |
|---|
| 256 | +#ifndef BCMSPI_ANDROID |
|---|
| 229 | 257 | sd_trace(("%s: Entering\n", __FUNCTION__)); |
|---|
| 230 | 258 | *onoff = sd->client_intr_enabled; |
|---|
| 259 | +#endif /* !BCMSPI_ANDROID */ |
|---|
| 231 | 260 | return SDIOH_API_RC_SUCCESS; |
|---|
| 232 | 261 | } |
|---|
| 233 | 262 | |
|---|
| .. | .. |
|---|
| 237 | 266 | { |
|---|
| 238 | 267 | return 0; |
|---|
| 239 | 268 | } |
|---|
| 240 | | -#endif |
|---|
| 241 | | - |
|---|
| 242 | | -extern SDIOH_API_RC |
|---|
| 243 | | -sdioh_query_device(sdioh_info_t *sd) |
|---|
| 244 | | -{ |
|---|
| 245 | | - /* Return a BRCM ID appropriate to the dongle class */ |
|---|
| 246 | | - return (sd->num_funcs > 1) ? BCM4329_D11N_ID : BCM4318_D11G_ID; |
|---|
| 247 | | -} |
|---|
| 269 | +#endif // endif |
|---|
| 248 | 270 | |
|---|
| 249 | 271 | /* Provide dstatus bits of spi-transaction for dhd layers. */ |
|---|
| 250 | 272 | extern uint32 |
|---|
| .. | .. |
|---|
| 289 | 311 | } |
|---|
| 290 | 312 | } |
|---|
| 291 | 313 | |
|---|
| 292 | | - |
|---|
| 293 | 314 | uint |
|---|
| 294 | 315 | sdioh_query_iofnum(sdioh_info_t *sd) |
|---|
| 295 | 316 | { |
|---|
| .. | .. |
|---|
| 318 | 339 | }; |
|---|
| 319 | 340 | |
|---|
| 320 | 341 | const bcm_iovar_t sdioh_iovars[] = { |
|---|
| 321 | | - {"sd_msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0 }, |
|---|
| 322 | | - {"sd_blocksize", IOV_BLOCKSIZE, 0, IOVT_UINT32, 0 }, /* ((fn << 16) | size) */ |
|---|
| 323 | | - {"sd_dma", IOV_DMA, 0, IOVT_BOOL, 0 }, |
|---|
| 324 | | - {"sd_ints", IOV_USEINTS, 0, IOVT_BOOL, 0 }, |
|---|
| 325 | | - {"sd_numints", IOV_NUMINTS, 0, IOVT_UINT32, 0 }, |
|---|
| 326 | | - {"sd_numlocalints", IOV_NUMLOCALINTS, 0, IOVT_UINT32, 0 }, |
|---|
| 327 | | - {"sd_hostreg", IOV_HOSTREG, 0, IOVT_BUFFER, sizeof(sdreg_t) }, |
|---|
| 328 | | - {"sd_devreg", IOV_DEVREG, 0, IOVT_BUFFER, sizeof(sdreg_t) }, |
|---|
| 329 | | - {"sd_divisor", IOV_DIVISOR, 0, IOVT_UINT32, 0 }, |
|---|
| 330 | | - {"sd_power", IOV_POWER, 0, IOVT_UINT32, 0 }, |
|---|
| 331 | | - {"sd_clock", IOV_CLOCK, 0, IOVT_UINT32, 0 }, |
|---|
| 332 | | - {"sd_mode", IOV_SDMODE, 0, IOVT_UINT32, 100}, |
|---|
| 333 | | - {"sd_highspeed", IOV_HISPEED, 0, IOVT_UINT32, 0}, |
|---|
| 334 | | - {"spi_errstats", IOV_SPIERRSTATS, 0, IOVT_BUFFER, sizeof(struct spierrstats_t) }, |
|---|
| 335 | | - {"spi_respdelay", IOV_RESP_DELAY_ALL, 0, IOVT_BOOL, 0 }, |
|---|
| 336 | | - {NULL, 0, 0, 0, 0 } |
|---|
| 342 | + {"sd_msglevel", IOV_MSGLEVEL, 0, 0, IOVT_UINT32, 0 }, |
|---|
| 343 | + {"sd_blocksize", IOV_BLOCKSIZE, 0, 0, IOVT_UINT32, 0 }, |
|---|
| 344 | + {"sd_dma", IOV_DMA, 0, 0, IOVT_BOOL, 0 }, |
|---|
| 345 | + {"sd_ints", IOV_USEINTS, 0, 0, IOVT_BOOL, 0 }, |
|---|
| 346 | + {"sd_numints", IOV_NUMINTS, 0, 0, IOVT_UINT32, 0 }, |
|---|
| 347 | + {"sd_numlocalints", IOV_NUMLOCALINTS, 0, 0, IOVT_UINT32, 0 }, |
|---|
| 348 | + {"sd_hostreg", IOV_HOSTREG, 0, 0, IOVT_BUFFER, sizeof(sdreg_t) }, |
|---|
| 349 | + {"sd_devreg", IOV_DEVREG, 0, 0, IOVT_BUFFER, sizeof(sdreg_t) }, |
|---|
| 350 | + {"sd_divisor", IOV_DIVISOR, 0, 0, IOVT_UINT32, 0 }, |
|---|
| 351 | + {"sd_power", IOV_POWER, 0, 0, IOVT_UINT32, 0 }, |
|---|
| 352 | + {"sd_clock", IOV_CLOCK, 0, 0, IOVT_UINT32, 0 }, |
|---|
| 353 | + {"sd_mode", IOV_SDMODE, 0, 0, IOVT_UINT32, 100}, |
|---|
| 354 | + {"sd_highspeed", IOV_HISPEED, 0, 0, IOVT_UINT32, 0}, |
|---|
| 355 | + {"spi_errstats", IOV_SPIERRSTATS, 0, 0, IOVT_BUFFER, sizeof(struct spierrstats_t) }, |
|---|
| 356 | + {"spi_respdelay", IOV_RESP_DELAY_ALL, 0, 0, IOVT_BOOL, 0 }, |
|---|
| 357 | + {NULL, 0, 0, 0, 0, 0 } |
|---|
| 337 | 358 | }; |
|---|
| 338 | 359 | |
|---|
| 339 | 360 | int |
|---|
| .. | .. |
|---|
| 344 | 365 | int bcmerror = 0; |
|---|
| 345 | 366 | int val_size; |
|---|
| 346 | 367 | int32 int_val = 0; |
|---|
| 347 | | - bool bool_val; |
|---|
| 348 | 368 | uint32 actionid; |
|---|
| 349 | 369 | /* |
|---|
| 350 | 370 | sdioh_regs_t *regs; |
|---|
| .. | .. |
|---|
| 382 | 402 | |
|---|
| 383 | 403 | if (plen >= (int)sizeof(int_val)) |
|---|
| 384 | 404 | bcopy(params, &int_val, sizeof(int_val)); |
|---|
| 385 | | - |
|---|
| 386 | | - bool_val = (int_val != 0) ? TRUE : FALSE; |
|---|
| 387 | 405 | |
|---|
| 388 | 406 | actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid); |
|---|
| 389 | 407 | switch (actionid) { |
|---|
| .. | .. |
|---|
| 427 | 445 | bcopy(&int_val, arg, val_size); |
|---|
| 428 | 446 | break; |
|---|
| 429 | 447 | |
|---|
| 448 | +#ifndef BCMSPI_ANDROID |
|---|
| 430 | 449 | case IOV_SVAL(IOV_DIVISOR): |
|---|
| 431 | 450 | sd_divisor = int_val; |
|---|
| 432 | 451 | if (!spi_start_clock(si, (uint16)sd_divisor)) { |
|---|
| .. | .. |
|---|
| 434 | 453 | bcmerror = BCME_ERROR; |
|---|
| 435 | 454 | } |
|---|
| 436 | 455 | break; |
|---|
| 456 | +#endif /* !BCMSPI_ANDROID */ |
|---|
| 437 | 457 | |
|---|
| 438 | 458 | case IOV_GVAL(IOV_POWER): |
|---|
| 439 | 459 | int_val = (uint32)sd_power; |
|---|
| .. | .. |
|---|
| 513 | 533 | } |
|---|
| 514 | 534 | break; |
|---|
| 515 | 535 | } |
|---|
| 516 | | - |
|---|
| 517 | 536 | |
|---|
| 518 | 537 | case IOV_GVAL(IOV_SPIERRSTATS): |
|---|
| 519 | 538 | { |
|---|
| .. | .. |
|---|
| 598 | 617 | int offset; |
|---|
| 599 | 618 | uint32 cis_byte; |
|---|
| 600 | 619 | uint16 *cis = (uint16 *)cisd; |
|---|
| 601 | | - uint bar0 = SI_ENUM_BASE; |
|---|
| 620 | + uint bar0 = SI_ENUM_BASE_DEFAULT; |
|---|
| 602 | 621 | int status; |
|---|
| 603 | 622 | uint8 data; |
|---|
| 604 | 623 | |
|---|
| .. | .. |
|---|
| 762 | 781 | |
|---|
| 763 | 782 | sd_trace(("%s cmd_arg = 0x%x\n", __FUNCTION__, cmd_arg)); |
|---|
| 764 | 783 | |
|---|
| 765 | | - |
|---|
| 766 | 784 | /* Set up and issue the SPI command. MSByte goes out on bus first. Increase datalen |
|---|
| 767 | 785 | * according to the wordlen mode(16/32bit) the device is in. |
|---|
| 768 | 786 | */ |
|---|
| .. | .. |
|---|
| 847 | 865 | bcmspi_resync_f1(sdioh_info_t *sd) |
|---|
| 848 | 866 | { |
|---|
| 849 | 867 | uint32 cmd_arg = GSPI_RESYNC_PATTERN, data = 0, datalen = 0; |
|---|
| 850 | | - |
|---|
| 851 | 868 | |
|---|
| 852 | 869 | /* Set up and issue the SPI command. MSByte goes out on bus first. Increase datalen |
|---|
| 853 | 870 | * according to the wordlen mode(16/32bit) the device is in. |
|---|
| .. | .. |
|---|
| 978 | 995 | return SUCCESS; |
|---|
| 979 | 996 | } |
|---|
| 980 | 997 | |
|---|
| 981 | | - |
|---|
| 982 | 998 | /* |
|---|
| 983 | 999 | * Private/Static work routines |
|---|
| 984 | 1000 | */ |
|---|
| .. | .. |
|---|
| 1032 | 1048 | uint32 status_en_reg = 0; |
|---|
| 1033 | 1049 | sd_trace(("%s: Powering up slot %d\n", __FUNCTION__, sd->adapter_slot)); |
|---|
| 1034 | 1050 | |
|---|
| 1051 | +#ifndef BCMSPI_ANDROID |
|---|
| 1035 | 1052 | #ifdef HSMODE |
|---|
| 1036 | 1053 | if (!spi_start_clock(sd, (uint16)sd_divisor)) { |
|---|
| 1037 | 1054 | sd_err(("spi_start_clock failed\n")); |
|---|
| .. | .. |
|---|
| 1044 | 1061 | return ERROR; |
|---|
| 1045 | 1062 | } |
|---|
| 1046 | 1063 | #endif /* HSMODE */ |
|---|
| 1064 | +#endif /* !BCMSPI_ANDROID */ |
|---|
| 1047 | 1065 | |
|---|
| 1048 | 1066 | if (!bcmspi_host_device_init_adapt(sd)) { |
|---|
| 1049 | 1067 | sd_err(("bcmspi_host_device_init_adapt failed\n")); |
|---|
| .. | .. |
|---|
| 1076 | 1094 | } |
|---|
| 1077 | 1095 | |
|---|
| 1078 | 1096 | #ifndef HSMODE |
|---|
| 1097 | +#ifndef BCMSPI_ANDROID |
|---|
| 1079 | 1098 | /* After configuring for High-Speed mode, set the desired clock rate. */ |
|---|
| 1080 | 1099 | if (!spi_start_clock(sd, 4)) { |
|---|
| 1081 | 1100 | sd_err(("spi_start_clock failed\n")); |
|---|
| 1082 | 1101 | return ERROR; |
|---|
| 1083 | 1102 | } |
|---|
| 1103 | +#endif /* !BCMSPI_ANDROID */ |
|---|
| 1084 | 1104 | #endif /* HSMODE */ |
|---|
| 1085 | 1105 | |
|---|
| 1086 | 1106 | /* check to see if the response delay needs to be programmed properly */ |
|---|
| .. | .. |
|---|
| 1127 | 1147 | } |
|---|
| 1128 | 1148 | } |
|---|
| 1129 | 1149 | |
|---|
| 1130 | | - |
|---|
| 1131 | 1150 | sd->card_init_done = TRUE; |
|---|
| 1132 | 1151 | |
|---|
| 1133 | 1152 | /* get the device rev to program the prop respdelays */ |
|---|
| .. | .. |
|---|
| 1146 | 1165 | return status; |
|---|
| 1147 | 1166 | |
|---|
| 1148 | 1167 | sd_trace(("In %s spih-ctrl = 0x%x \n", __FUNCTION__, regdata)); |
|---|
| 1149 | | - |
|---|
| 1150 | 1168 | |
|---|
| 1151 | 1169 | if (hsmode == TRUE) { |
|---|
| 1152 | 1170 | sd_trace(("Attempting to enable High-Speed mode.\n")); |
|---|
| .. | .. |
|---|
| 1167 | 1185 | |
|---|
| 1168 | 1186 | if (regdata & HIGH_SPEED_MODE) { |
|---|
| 1169 | 1187 | regdata &= ~HIGH_SPEED_MODE; |
|---|
| 1188 | + regdata |= CLOCK_POLARITY; |
|---|
| 1170 | 1189 | sd_trace(("Writing %08x to device at %08x\n", regdata, SPID_CONFIG)); |
|---|
| 1171 | 1190 | if ((status = bcmspi_card_regwrite(sd, 0, SPID_CONFIG, |
|---|
| 1172 | 1191 | 4, regdata)) != SUCCESS) |
|---|
| .. | .. |
|---|
| 1177 | 1196 | return status; |
|---|
| 1178 | 1197 | } |
|---|
| 1179 | 1198 | } |
|---|
| 1199 | +#ifndef BCMSPI_ANDROID |
|---|
| 1180 | 1200 | spi_controller_highspeed_mode(sd, hsmode); |
|---|
| 1201 | +#endif /* !BCMSPI_ANDROID */ |
|---|
| 1181 | 1202 | |
|---|
| 1182 | 1203 | return TRUE; |
|---|
| 1183 | 1204 | } |
|---|
| .. | .. |
|---|
| 1287 | 1308 | OSL_DELAY(1000); |
|---|
| 1288 | 1309 | } |
|---|
| 1289 | 1310 | |
|---|
| 1311 | +#if defined(CHANGE_SPI_INTR_POLARITY_ACTIVE_HIGH) |
|---|
| 1312 | + /* Change to host controller intr-polarity of active-high */ |
|---|
| 1313 | + wrregdata |= INTR_POLARITY; |
|---|
| 1314 | +#else |
|---|
| 1290 | 1315 | /* Change to host controller intr-polarity of active-low */ |
|---|
| 1291 | 1316 | wrregdata &= ~INTR_POLARITY; |
|---|
| 1317 | +#endif /* CHANGE_SPI_INTR_POLARITY_ACTIVE_HIGH */ |
|---|
| 1318 | + |
|---|
| 1292 | 1319 | sd_trace(("(we are still in 16bit mode) 32bit Write LE reg-ctrl-data = 0x%x\n", |
|---|
| 1293 | 1320 | wrregdata)); |
|---|
| 1294 | 1321 | /* Change to 32bit mode */ |
|---|
| .. | .. |
|---|
| 1311 | 1338 | } |
|---|
| 1312 | 1339 | } |
|---|
| 1313 | 1340 | |
|---|
| 1314 | | - |
|---|
| 1315 | 1341 | return TRUE; |
|---|
| 1316 | 1342 | } |
|---|
| 1317 | 1343 | |
|---|
| .. | .. |
|---|
| 1330 | 1356 | sd_trace(("Incorrect 32bit LE regdata = 0x%x\n", regdata)); |
|---|
| 1331 | 1357 | return FALSE; |
|---|
| 1332 | 1358 | } |
|---|
| 1333 | | - |
|---|
| 1334 | 1359 | |
|---|
| 1335 | 1360 | #define RW_PATTERN1 0xA0A1A2A3 |
|---|
| 1336 | 1361 | #define RW_PATTERN2 0x4B5B6B7B |
|---|
| .. | .. |
|---|
| 1518 | 1543 | uint8 resp_delay = 0; |
|---|
| 1519 | 1544 | int err = SUCCESS; |
|---|
| 1520 | 1545 | uint32 hostlen; |
|---|
| 1521 | | - uint32 spilen = 0; |
|---|
| 1522 | 1546 | uint32 dstatus_idx = 0; |
|---|
| 1523 | | - uint16 templen, buslen, len, *ptr = NULL; |
|---|
| 1547 | +// uint16 templen, buslen, len; |
|---|
| 1524 | 1548 | |
|---|
| 1525 | 1549 | sd_trace(("spi cmd = 0x%x\n", cmd_arg)); |
|---|
| 1526 | | - |
|---|
| 1527 | | - if (DWORDMODE_ON) { |
|---|
| 1528 | | - spilen = GFIELD(cmd_arg, SPI_LEN); |
|---|
| 1529 | | - if ((GFIELD(cmd_arg, SPI_FUNCTION) == SPI_FUNC_0) || |
|---|
| 1530 | | - (GFIELD(cmd_arg, SPI_FUNCTION) == SPI_FUNC_1)) |
|---|
| 1531 | | - dstatus_idx = spilen * 3; |
|---|
| 1532 | | - |
|---|
| 1533 | | - if ((GFIELD(cmd_arg, SPI_FUNCTION) == SPI_FUNC_2) && |
|---|
| 1534 | | - (GFIELD(cmd_arg, SPI_RW_FLAG) == 1)) { |
|---|
| 1535 | | - spilen = spilen << 2; |
|---|
| 1536 | | - dstatus_idx = (spilen % 16) ? (16 - (spilen % 16)) : 0; |
|---|
| 1537 | | - /* convert len to mod16 size */ |
|---|
| 1538 | | - spilen = ROUNDUP(spilen, 16); |
|---|
| 1539 | | - cmd_arg = SFIELD(cmd_arg, SPI_LEN, (spilen >> 2)); |
|---|
| 1540 | | - } |
|---|
| 1541 | | - } |
|---|
| 1542 | 1550 | |
|---|
| 1543 | 1551 | /* Set up and issue the SPI command. MSByte goes out on bus first. Increase datalen |
|---|
| 1544 | 1552 | * according to the wordlen mode(16/32bit) the device is in. |
|---|
| .. | .. |
|---|
| 1562 | 1570 | /* for Write, put the data into the output buffer */ |
|---|
| 1563 | 1571 | if (GFIELD(cmd_arg, SPI_RW_FLAG) == 1) { |
|---|
| 1564 | 1572 | /* We send len field of hw-header always a mod16 size, both from host and dongle */ |
|---|
| 1565 | | - if (DWORDMODE_ON) { |
|---|
| 1566 | | - if (GFIELD(cmd_arg, SPI_FUNCTION) == SPI_FUNC_2) { |
|---|
| 1567 | | - ptr = (uint16 *)&data[0]; |
|---|
| 1568 | | - templen = *ptr; |
|---|
| 1569 | | - /* ASSERT(*ptr == ~*(ptr + 1)); */ |
|---|
| 1570 | | - templen = ROUNDUP(templen, 16); |
|---|
| 1571 | | - *ptr = templen; |
|---|
| 1572 | | - sd_trace(("actual tx len = %d\n", (uint16)(~*(ptr+1)))); |
|---|
| 1573 | | - } |
|---|
| 1574 | | - } |
|---|
| 1575 | | - |
|---|
| 1576 | 1573 | if (datalen != 0) { |
|---|
| 1577 | 1574 | for (i = 0; i < datalen/4; i++) { |
|---|
| 1578 | 1575 | if (sd->wordlen == 4) { /* 32bit spid */ |
|---|
| .. | .. |
|---|
| 1620 | 1617 | /* +4 for cmd and +4 for dstatus */ |
|---|
| 1621 | 1618 | hostlen = datalen + 8 + resp_delay; |
|---|
| 1622 | 1619 | hostlen += dstatus_idx; |
|---|
| 1620 | +#ifdef BCMSPI_ANDROID |
|---|
| 1621 | + if (hostlen%4) { |
|---|
| 1622 | + sd_err(("Unaligned data len %d, hostlen %d\n", |
|---|
| 1623 | + datalen, hostlen)); |
|---|
| 1624 | +#endif /* BCMSPI_ANDROID */ |
|---|
| 1623 | 1625 | hostlen += (4 - (hostlen & 0x3)); |
|---|
| 1626 | +#ifdef BCMSPI_ANDROID |
|---|
| 1627 | + } |
|---|
| 1628 | +#endif /* BCMSPI_ANDROID */ |
|---|
| 1624 | 1629 | spi_sendrecv(sd, spi_outbuf, spi_inbuf, hostlen); |
|---|
| 1625 | 1630 | |
|---|
| 1626 | 1631 | /* for Read, get the data into the input buffer */ |
|---|
| .. | .. |
|---|
| 1635 | 1640 | CMDLEN + resp_delay]); |
|---|
| 1636 | 1641 | } |
|---|
| 1637 | 1642 | } |
|---|
| 1638 | | - |
|---|
| 1639 | | - if ((DWORDMODE_ON) && (GFIELD(cmd_arg, SPI_FUNCTION) == SPI_FUNC_2)) { |
|---|
| 1640 | | - ptr = (uint16 *)&data[0]; |
|---|
| 1641 | | - templen = *ptr; |
|---|
| 1642 | | - buslen = len = ~(*(ptr + 1)); |
|---|
| 1643 | | - buslen = ROUNDUP(buslen, 16); |
|---|
| 1644 | | - /* populate actual len in hw-header */ |
|---|
| 1645 | | - if (templen == buslen) |
|---|
| 1646 | | - *ptr = len; |
|---|
| 1647 | | - } |
|---|
| 1648 | | - } |
|---|
| 1649 | | - } |
|---|
| 1650 | | - |
|---|
| 1651 | | - /* Restore back the len field of the hw header */ |
|---|
| 1652 | | - if (DWORDMODE_ON) { |
|---|
| 1653 | | - if ((GFIELD(cmd_arg, SPI_FUNCTION) == SPI_FUNC_2) && |
|---|
| 1654 | | - (GFIELD(cmd_arg, SPI_RW_FLAG) == 1)) { |
|---|
| 1655 | | - ptr = (uint16 *)&data[0]; |
|---|
| 1656 | | - *ptr = (uint16)(~*(ptr+1)); |
|---|
| 1657 | 1643 | } |
|---|
| 1658 | 1644 | } |
|---|
| 1659 | 1645 | |
|---|
| .. | .. |
|---|
| 1761 | 1747 | __FUNCTION__, write ? "Wd" : "Rd", func, "INCR", |
|---|
| 1762 | 1748 | addr, nbytes, sd->r_cnt, sd->t_cnt)); |
|---|
| 1763 | 1749 | |
|---|
| 1764 | | - |
|---|
| 1765 | 1750 | if ((status = bcmspi_cmd_issue(sd, sd->sd_use_dma, cmd_arg, data, nbytes)) != SUCCESS) { |
|---|
| 1766 | 1751 | sd_err(("%s: cmd_issue failed for %s\n", __FUNCTION__, |
|---|
| 1767 | 1752 | (write ? "write" : "read"))); |
|---|
| 1768 | 1753 | return status; |
|---|
| 1769 | | - } |
|---|
| 1770 | | - |
|---|
| 1771 | | - /* gSPI expects that hw-header-len is equal to spi-command-len */ |
|---|
| 1772 | | - if ((func == 2) && (rw == SDIOH_WRITE) && (sd->dwordmode == FALSE)) { |
|---|
| 1773 | | - ASSERT((uint16)sd->data_xfer_count == (uint16)(*data & 0xffff)); |
|---|
| 1774 | | - ASSERT((uint16)sd->data_xfer_count == (uint16)(~((*data & 0xffff0000) >> 16))); |
|---|
| 1775 | 1754 | } |
|---|
| 1776 | 1755 | |
|---|
| 1777 | 1756 | if ((nbytes > 2000) && !write) { |
|---|