.. | .. |
---|
1 | | -/* SPDX-License-Identifier: GPL-2.0 */ |
---|
2 | 1 | /* |
---|
3 | 2 | * Broadcom SPI Host Controller Driver - Linux Per-port |
---|
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. |
---|
.. | .. |
---|
34 | 35 | #include <bcmsdbus.h> /* bcmsdh to/from specific controller APIs */ |
---|
35 | 36 | #include <sdiovar.h> /* to get msglevel bit values */ |
---|
36 | 37 | |
---|
| 38 | +#ifdef BCMSPI_ANDROID |
---|
| 39 | +#include <bcmsdh.h> |
---|
| 40 | +#include <bcmspibrcm.h> |
---|
| 41 | +#include <linux/spi/spi.h> |
---|
| 42 | +#else |
---|
37 | 43 | #include <pcicfg.h> |
---|
38 | 44 | #include <sdio.h> /* SDIO Device and Protocol Specs */ |
---|
39 | 45 | #include <linux/sched.h> /* request_irq(), free_irq() */ |
---|
40 | 46 | #include <bcmsdspi.h> |
---|
| 47 | +#include <bcmdevs.h> |
---|
41 | 48 | #include <bcmspi.h> |
---|
| 49 | +#endif /* BCMSPI_ANDROID */ |
---|
42 | 50 | |
---|
| 51 | +#ifndef GSPIBCM |
---|
| 52 | +#ifndef BCMSPI_ANDROID |
---|
43 | 53 | extern uint sd_crc; |
---|
44 | 54 | module_param(sd_crc, uint, 0); |
---|
45 | 55 | |
---|
46 | 56 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) |
---|
47 | 57 | #define KERNEL26 |
---|
48 | | -#endif |
---|
| 58 | +#endif // endif |
---|
| 59 | +#endif /* !BCMSPI_ANDROID */ |
---|
49 | 60 | |
---|
50 | 61 | struct sdos_info { |
---|
51 | 62 | sdioh_info_t *sd; |
---|
52 | 63 | spinlock_t lock; |
---|
| 64 | +#ifndef BCMSPI_ANDROID |
---|
53 | 65 | wait_queue_head_t intr_wait_queue; |
---|
| 66 | +#endif /* !BCMSPI_ANDROID */ |
---|
54 | 67 | }; |
---|
| 68 | +#endif /* !GSPIBCM */ |
---|
55 | 69 | |
---|
| 70 | +#ifndef BCMSPI_ANDROID |
---|
56 | 71 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) |
---|
57 | 72 | #define BLOCKABLE() (!in_atomic()) |
---|
58 | 73 | #else |
---|
59 | 74 | #define BLOCKABLE() (!in_interrupt()) |
---|
60 | | -#endif |
---|
| 75 | +#endif // endif |
---|
61 | 76 | |
---|
| 77 | +/* For Broadcom PCI-SPI Host controller (Raggedstone) */ |
---|
| 78 | +#if defined(BCMSPI) && (defined(BCMPCISPIHOST) || defined(GSPIBCM)) |
---|
| 79 | +#ifndef SDLX_MSG |
---|
| 80 | +#define SDLX_MSG(x) printf x |
---|
| 81 | +#endif // endif |
---|
| 82 | +extern void* bcmsdh_probe(osl_t *osh, void *dev, void *sdioh, void *adapter_info, |
---|
| 83 | + uint bus_type, uint bus_num, uint slot_num); |
---|
| 84 | +extern int bcmsdh_remove(bcmsdh_info_t *bcmsdh); |
---|
| 85 | +extern sdioh_info_t * sdioh_attach(osl_t *osh, void *bar0, uint irq); |
---|
| 86 | +extern SDIOH_API_RC sdioh_detach(osl_t *osh, sdioh_info_t *sd); |
---|
| 87 | + |
---|
| 88 | +/* forward declarations for PCI probe and remove functions. */ |
---|
| 89 | +static int __devinit bcmsdh_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
---|
| 90 | +static void __devexit bcmsdh_pci_remove(struct pci_dev *pdev); |
---|
| 91 | + |
---|
| 92 | +/* forward declarations for PCI probe and remove functions. */ |
---|
| 93 | +static int __devinit bcmsdh_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
---|
| 94 | +static void __devexit bcmsdh_pci_remove(struct pci_dev *pdev); |
---|
| 95 | + |
---|
| 96 | +/** |
---|
| 97 | + * pci id table |
---|
| 98 | + */ |
---|
| 99 | +static struct pci_device_id bcmsdh_pci_devid[] __devinitdata = { |
---|
| 100 | + { vendor: PCI_ANY_ID, |
---|
| 101 | + device: PCI_ANY_ID, |
---|
| 102 | + subvendor: PCI_ANY_ID, |
---|
| 103 | + subdevice: PCI_ANY_ID, |
---|
| 104 | + class: 0, |
---|
| 105 | + class_mask: 0, |
---|
| 106 | + driver_data: 0, |
---|
| 107 | + }, |
---|
| 108 | + { 0, } |
---|
| 109 | +}; |
---|
| 110 | +MODULE_DEVICE_TABLE(pci, bcmsdh_pci_devid); |
---|
| 111 | + |
---|
| 112 | +/** |
---|
| 113 | + * PCI-SPI Host Controller: pci driver info |
---|
| 114 | + */ |
---|
| 115 | +static struct pci_driver bcmsdh_pci_driver = { |
---|
| 116 | + node: {}, |
---|
| 117 | + name: "bcmsdh", |
---|
| 118 | + id_table: bcmsdh_pci_devid, |
---|
| 119 | + probe: bcmsdh_pci_probe, |
---|
| 120 | + remove: bcmsdh_pci_remove, |
---|
| 121 | +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) |
---|
| 122 | + save_state: NULL, |
---|
| 123 | +#endif // endif |
---|
| 124 | + suspend: NULL, |
---|
| 125 | + resume: NULL, |
---|
| 126 | +}; |
---|
| 127 | + |
---|
| 128 | +/* Force detection to a particular PCI */ |
---|
| 129 | +/* slot only . Allows for having multiple */ |
---|
| 130 | +/* WL devices at once in a PC */ |
---|
| 131 | +/* Only one instance of dhd will be */ |
---|
| 132 | +/* usable at a time */ |
---|
| 133 | +/* Upper word is bus number, */ |
---|
| 134 | +/* lower word is slot number */ |
---|
| 135 | +/* Default value of 0xffffffff turns this off */ |
---|
| 136 | +extern uint sd_pci_slot; |
---|
| 137 | +module_param(sd_pci_slot, uint, 0); |
---|
| 138 | + |
---|
| 139 | +/** |
---|
| 140 | + * Detect supported Host Controller and attach if found. |
---|
| 141 | + * |
---|
| 142 | + * Determine if the device described by pdev is a supported PCI Host |
---|
| 143 | + * Controller. If so, attach to it and attach to the target device. |
---|
| 144 | + */ |
---|
| 145 | +static int __devinit |
---|
| 146 | +bcmsdh_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
---|
| 147 | +{ |
---|
| 148 | + osl_t *osh = NULL; |
---|
| 149 | + sdioh_info_t *sdioh = NULL; |
---|
| 150 | + void *bcmsdh; |
---|
| 151 | + |
---|
| 152 | + int rc; |
---|
| 153 | + |
---|
| 154 | + if (sd_pci_slot != 0xFFFFFFFF) { |
---|
| 155 | + if (pdev->bus->number != (sd_pci_slot>>16) || |
---|
| 156 | + PCI_SLOT(pdev->devfn) != (sd_pci_slot&0xffff)) { |
---|
| 157 | + SDLX_MSG(("%s: %s: bus %X, slot %X, vend %X, dev %X\n", |
---|
| 158 | + __FUNCTION__, |
---|
| 159 | + bcmsdh_chipmatch(pdev->vendor, pdev->device) |
---|
| 160 | + ?"Found compatible SDIOHC" |
---|
| 161 | + :"Probing unknown device", |
---|
| 162 | + pdev->bus->number, PCI_SLOT(pdev->devfn), pdev->vendor, |
---|
| 163 | + pdev->device)); |
---|
| 164 | + return -ENODEV; |
---|
| 165 | + } |
---|
| 166 | + SDLX_MSG(("%s: %s: bus %X, slot %X, vendor %X, device %X (good PCI location)\n", |
---|
| 167 | + __FUNCTION__, |
---|
| 168 | + bcmsdh_chipmatch(pdev->vendor, pdev->device) |
---|
| 169 | + ?"Using compatible SDIOHC" |
---|
| 170 | + :"WARNING, forced use of unkown device", |
---|
| 171 | + pdev->bus->number, PCI_SLOT(pdev->devfn), pdev->vendor, pdev->device)); |
---|
| 172 | + } |
---|
| 173 | + |
---|
| 174 | + if ((pdev->vendor == VENDOR_TI) && ((pdev->device == PCIXX21_FLASHMEDIA_ID) || |
---|
| 175 | + (pdev->device == PCIXX21_FLASHMEDIA0_ID))) { |
---|
| 176 | + uint32 config_reg; |
---|
| 177 | + |
---|
| 178 | + SDLX_MSG(("%s: Disabling TI FlashMedia Controller.\n", __FUNCTION__)); |
---|
| 179 | + if (!(osh = osl_attach(pdev, PCI_BUS, FALSE))) { |
---|
| 180 | + SDLX_MSG(("%s: osl_attach failed\n", __FUNCTION__)); |
---|
| 181 | + goto err; |
---|
| 182 | + } |
---|
| 183 | + config_reg = OSL_PCI_READ_CONFIG(osh, 0x4c, 4); |
---|
| 184 | + |
---|
| 185 | + /* |
---|
| 186 | + * Set MMC_SD_DIS bit in FlashMedia Controller. |
---|
| 187 | + * Disbling the SD/MMC Controller in the FlashMedia Controller |
---|
| 188 | + * allows the Standard SD Host Controller to take over control |
---|
| 189 | + * of the SD Slot. |
---|
| 190 | + */ |
---|
| 191 | + config_reg |= 0x02; |
---|
| 192 | + OSL_PCI_WRITE_CONFIG(osh, 0x4c, 4, config_reg); |
---|
| 193 | + osl_detach(osh); |
---|
| 194 | + } |
---|
| 195 | + /* match this pci device with what we support */ |
---|
| 196 | + /* we can't solely rely on this to believe it is our SDIO Host Controller! */ |
---|
| 197 | + if (!bcmsdh_chipmatch(pdev->vendor, pdev->device)) { |
---|
| 198 | + if (pdev->vendor == VENDOR_BROADCOM) { |
---|
| 199 | + SDLX_MSG(("%s: Unknown Broadcom device (vendor: %#x, device: %#x).\n", |
---|
| 200 | + __FUNCTION__, pdev->vendor, pdev->device)); |
---|
| 201 | + } |
---|
| 202 | + return -ENODEV; |
---|
| 203 | + } |
---|
| 204 | + |
---|
| 205 | + /* this is a pci device we might support */ |
---|
| 206 | + SDLX_MSG(("%s: Found possible SDIO Host Controller: bus %d slot %d func %d irq %d\n", |
---|
| 207 | + __FUNCTION__, |
---|
| 208 | + pdev->bus->number, PCI_SLOT(pdev->devfn), |
---|
| 209 | + PCI_FUNC(pdev->devfn), pdev->irq)); |
---|
| 210 | + |
---|
| 211 | + /* use bcmsdh_query_device() to get the vendor ID of the target device so |
---|
| 212 | + * it will eventually appear in the Broadcom string on the console |
---|
| 213 | + */ |
---|
| 214 | + |
---|
| 215 | + /* allocate SDIO Host Controller state info */ |
---|
| 216 | + if (!(osh = osl_attach(pdev, PCI_BUS, FALSE))) { |
---|
| 217 | + SDLX_MSG(("%s: osl_attach failed\n", __FUNCTION__)); |
---|
| 218 | + goto err; |
---|
| 219 | + } |
---|
| 220 | + |
---|
| 221 | + /* map to address where host can access */ |
---|
| 222 | + pci_set_master(pdev); |
---|
| 223 | + rc = pci_enable_device(pdev); |
---|
| 224 | + if (rc) { |
---|
| 225 | + SDLX_MSG(("%s: Cannot enable PCI device\n", __FUNCTION__)); |
---|
| 226 | + goto err; |
---|
| 227 | + } |
---|
| 228 | + |
---|
| 229 | + if (!(sdioh = sdioh_attach(osh, (void *)(ulong)pci_resource_start(pdev, 0), pdev->irq))) { |
---|
| 230 | + SDLX_MSG(("%s: bcmsdh_attach failed\n", __FUNCTION__)); |
---|
| 231 | + goto err; |
---|
| 232 | + } |
---|
| 233 | + |
---|
| 234 | +#ifdef GSPIBCM |
---|
| 235 | + bcmsdh = bcmsdh_probe(osh, &pdev->dev, sdioh, NULL, PCI_BUS, -1, -1); |
---|
| 236 | + if (bcmsdh == NULL) { |
---|
| 237 | +#else |
---|
| 238 | + sdioh->bcmsdh = bcmsdh_probe(osh, &pdev->dev, sdioh, NULL, PCI_BUS, -1, -1); |
---|
| 239 | + if (sdioh->bcmsdh == NULL) { |
---|
| 240 | +#endif /* GSPIBCM */ |
---|
| 241 | + sd_err(("%s: bcmsdh_probe failed\n", __FUNCTION__)); |
---|
| 242 | + goto err; |
---|
| 243 | + } |
---|
| 244 | + |
---|
| 245 | + pci_set_drvdata(pdev, sdioh); |
---|
| 246 | + return 0; |
---|
| 247 | + |
---|
| 248 | + /* error handling */ |
---|
| 249 | +err: |
---|
| 250 | + if (sdioh != NULL) |
---|
| 251 | + sdioh_detach(osh, sdioh); |
---|
| 252 | + if (osh != NULL) |
---|
| 253 | + osl_detach(osh); |
---|
| 254 | + return -ENOMEM; |
---|
| 255 | + |
---|
| 256 | +} |
---|
| 257 | + |
---|
| 258 | +/** |
---|
| 259 | + * Detach from target devices and PCI-SPI Host Controller |
---|
| 260 | + */ |
---|
| 261 | +static void __devexit |
---|
| 262 | +bcmsdh_pci_remove(struct pci_dev *pdev) |
---|
| 263 | +{ |
---|
| 264 | + |
---|
| 265 | + sdioh_info_t *sdioh = NULL; |
---|
| 266 | + osl_t *osh; |
---|
| 267 | + |
---|
| 268 | + sdioh = pci_get_drvdata(pdev); |
---|
| 269 | + if (sdioh == NULL) { |
---|
| 270 | + sd_err(("%s: error, no sdh handler found\n", __FUNCTION__)); |
---|
| 271 | + return; |
---|
| 272 | + } |
---|
| 273 | + |
---|
| 274 | + osh = sdioh->osh; |
---|
| 275 | + bcmsdh_remove(sdioh->bcmsdh); |
---|
| 276 | + sdioh_detach(osh, sdioh); |
---|
| 277 | + osl_detach(osh); |
---|
| 278 | + |
---|
| 279 | +} |
---|
| 280 | +#endif /* BCMSPI && BCMPCISPIHOST */ |
---|
| 281 | + |
---|
| 282 | +#ifndef GSPIBCM |
---|
62 | 283 | /* Interrupt handler */ |
---|
63 | 284 | static irqreturn_t |
---|
64 | 285 | sdspi_isr(int irq, void *dev_id |
---|
65 | 286 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
---|
66 | 287 | , struct pt_regs *ptregs |
---|
67 | | -#endif |
---|
| 288 | +#endif // endif |
---|
68 | 289 | ) |
---|
69 | 290 | { |
---|
70 | 291 | sdioh_info_t *sd; |
---|
.. | .. |
---|
89 | 310 | return IRQ_RETVAL(ours); |
---|
90 | 311 | } |
---|
91 | 312 | } |
---|
| 313 | +#endif /* !GSPIBCM */ |
---|
| 314 | +#endif /* !BCMSPI_ANDROID */ |
---|
92 | 315 | |
---|
| 316 | +#ifdef BCMSPI_ANDROID |
---|
| 317 | +static struct spi_device *gBCMSPI = NULL; |
---|
93 | 318 | |
---|
| 319 | +extern int bcmsdh_probe(struct device *dev); |
---|
| 320 | +extern int bcmsdh_remove(struct device *dev); |
---|
| 321 | + |
---|
| 322 | +static int bcmsdh_spi_probe(struct spi_device *spi_dev) |
---|
| 323 | +{ |
---|
| 324 | + int ret = 0; |
---|
| 325 | + |
---|
| 326 | + gBCMSPI = spi_dev; |
---|
| 327 | + |
---|
| 328 | +#ifdef SPI_PIO_32BIT_RW |
---|
| 329 | + spi_dev->bits_per_word = 32; |
---|
| 330 | +#else |
---|
| 331 | + spi_dev->bits_per_word = 8; |
---|
| 332 | +#endif /* SPI_PIO_32BIT_RW */ |
---|
| 333 | + ret = spi_setup(spi_dev); |
---|
| 334 | + |
---|
| 335 | + if (ret) { |
---|
| 336 | + sd_err(("bcmsdh_spi_probe: spi_setup fail with %d\n", ret)); |
---|
| 337 | + } |
---|
| 338 | + sd_err(("bcmsdh_spi_probe: spi_setup with %d, bits_per_word=%d\n", |
---|
| 339 | + ret, spi_dev->bits_per_word)); |
---|
| 340 | + ret = bcmsdh_probe(&spi_dev->dev); |
---|
| 341 | + |
---|
| 342 | + return ret; |
---|
| 343 | +} |
---|
| 344 | + |
---|
| 345 | +static int bcmsdh_spi_remove(struct spi_device *spi_dev) |
---|
| 346 | +{ |
---|
| 347 | + int ret = 0; |
---|
| 348 | + |
---|
| 349 | + ret = bcmsdh_remove(&spi_dev->dev); |
---|
| 350 | + gBCMSPI = NULL; |
---|
| 351 | + |
---|
| 352 | + return ret; |
---|
| 353 | +} |
---|
| 354 | + |
---|
| 355 | +static struct spi_driver bcmsdh_spi_driver = { |
---|
| 356 | + .probe = bcmsdh_spi_probe, |
---|
| 357 | + .remove = bcmsdh_spi_remove, |
---|
| 358 | + .driver = { |
---|
| 359 | + .name = "wlan_spi", |
---|
| 360 | + .bus = &spi_bus_type, |
---|
| 361 | + .owner = THIS_MODULE, |
---|
| 362 | + }, |
---|
| 363 | +}; |
---|
| 364 | +#endif /* BCMSPI_ANDROID */ |
---|
| 365 | + |
---|
| 366 | +/* |
---|
| 367 | + * module init |
---|
| 368 | +*/ |
---|
| 369 | +int bcmsdh_register_client_driver(void) |
---|
| 370 | +{ |
---|
| 371 | + int error = 0; |
---|
| 372 | + sd_trace(("bcmsdh_gspi: %s Enter\n", __FUNCTION__)); |
---|
| 373 | +#if defined(BCMSPI) && (defined(BCMPCISPIHOST) || defined(GSPIBCM)) |
---|
| 374 | + error = pci_module_init(&bcmsdh_pci_driver); |
---|
| 375 | +#else |
---|
| 376 | + error = spi_register_driver(&bcmsdh_spi_driver); |
---|
| 377 | +#endif /* BCMSPI && BCMPCISPIHOST */ |
---|
| 378 | + |
---|
| 379 | + return error; |
---|
| 380 | +} |
---|
| 381 | + |
---|
| 382 | +/* |
---|
| 383 | + * module cleanup |
---|
| 384 | +*/ |
---|
| 385 | +void bcmsdh_unregister_client_driver(void) |
---|
| 386 | +{ |
---|
| 387 | + sd_trace(("%s Enter\n", __FUNCTION__)); |
---|
| 388 | +#if defined(BCMSPI) && (defined(BCMPCISPIHOST) || defined(GSPIBCM)) |
---|
| 389 | + pci_unregister_driver(&bcmsdh_pci_driver); |
---|
| 390 | +#else |
---|
| 391 | + spi_unregister_driver(&bcmsdh_spi_driver); |
---|
| 392 | +#endif /* BCMSPI && BCMPCISPIHOST */ |
---|
| 393 | +} |
---|
| 394 | + |
---|
| 395 | +#ifndef GSPIBCM |
---|
94 | 396 | /* Register with Linux for interrupts */ |
---|
95 | 397 | int |
---|
96 | 398 | spi_register_irq(sdioh_info_t *sd, uint irq) |
---|
97 | 399 | { |
---|
| 400 | +#ifndef BCMSPI_ANDROID |
---|
98 | 401 | sd_trace(("Entering %s: irq == %d\n", __FUNCTION__, irq)); |
---|
99 | 402 | if (request_irq(irq, sdspi_isr, IRQF_SHARED, "bcmsdspi", sd) < 0) { |
---|
100 | 403 | sd_err(("%s: request_irq() failed\n", __FUNCTION__)); |
---|
101 | 404 | return ERROR; |
---|
102 | 405 | } |
---|
| 406 | +#endif /* !BCMSPI_ANDROID */ |
---|
103 | 407 | return SUCCESS; |
---|
104 | 408 | } |
---|
105 | 409 | |
---|
.. | .. |
---|
107 | 411 | void |
---|
108 | 412 | spi_free_irq(uint irq, sdioh_info_t *sd) |
---|
109 | 413 | { |
---|
| 414 | +#ifndef BCMSPI_ANDROID |
---|
110 | 415 | free_irq(irq, sd); |
---|
| 416 | +#endif /* !BCMSPI_ANDROID */ |
---|
111 | 417 | } |
---|
112 | 418 | |
---|
113 | 419 | /* Map Host controller registers */ |
---|
| 420 | +#ifndef BCMSPI_ANDROID |
---|
114 | 421 | uint32 * |
---|
115 | 422 | spi_reg_map(osl_t *osh, uintptr addr, int size) |
---|
116 | 423 | { |
---|
.. | .. |
---|
122 | 429 | { |
---|
123 | 430 | REG_UNMAP((void*)(uintptr)addr); |
---|
124 | 431 | } |
---|
| 432 | +#endif /* !BCMSPI_ANDROID */ |
---|
125 | 433 | |
---|
126 | 434 | int |
---|
127 | 435 | spi_osinit(sdioh_info_t *sd) |
---|
.. | .. |
---|
135 | 443 | |
---|
136 | 444 | sdos->sd = sd; |
---|
137 | 445 | spin_lock_init(&sdos->lock); |
---|
| 446 | +#ifndef BCMSPI_ANDROID |
---|
138 | 447 | init_waitqueue_head(&sdos->intr_wait_queue); |
---|
| 448 | +#endif /* !BCMSPI_ANDROID */ |
---|
139 | 449 | return BCME_OK; |
---|
140 | 450 | } |
---|
141 | 451 | |
---|
.. | .. |
---|
166 | 476 | return SDIOH_API_RC_FAIL; |
---|
167 | 477 | } |
---|
168 | 478 | |
---|
| 479 | +#ifndef BCMSPI_ANDROID |
---|
169 | 480 | if (enable && !(sd->intr_handler && sd->intr_handler_arg)) { |
---|
170 | 481 | sd_err(("%s: no handler registered, will not enable\n", __FUNCTION__)); |
---|
171 | 482 | return SDIOH_API_RC_FAIL; |
---|
172 | 483 | } |
---|
| 484 | +#endif /* !BCMSPI_ANDROID */ |
---|
173 | 485 | |
---|
174 | 486 | /* Ensure atomicity for enable/disable calls */ |
---|
175 | 487 | spin_lock_irqsave(&sdos->lock, flags); |
---|
176 | 488 | |
---|
177 | 489 | sd->client_intr_enabled = enable; |
---|
| 490 | +#ifndef BCMSPI_ANDROID |
---|
178 | 491 | if (enable && !sd->lockcount) |
---|
179 | 492 | spi_devintr_on(sd); |
---|
180 | 493 | else |
---|
181 | 494 | spi_devintr_off(sd); |
---|
| 495 | +#endif /* !BCMSPI_ANDROID */ |
---|
182 | 496 | |
---|
183 | 497 | spin_unlock_irqrestore(&sdos->lock, flags); |
---|
184 | 498 | |
---|
.. | .. |
---|
202 | 516 | sd_err(("%s: Already locked!\n", __FUNCTION__)); |
---|
203 | 517 | ASSERT(sd->lockcount == 0); |
---|
204 | 518 | } |
---|
| 519 | +#ifdef BCMSPI_ANDROID |
---|
| 520 | + if (sd->client_intr_enabled) |
---|
| 521 | + bcmsdh_oob_intr_set(0); |
---|
| 522 | +#else |
---|
205 | 523 | spi_devintr_off(sd); |
---|
| 524 | +#endif /* BCMSPI_ANDROID */ |
---|
206 | 525 | sd->lockcount++; |
---|
207 | 526 | spin_unlock_irqrestore(&sdos->lock, flags); |
---|
208 | 527 | } |
---|
.. | .. |
---|
222 | 541 | |
---|
223 | 542 | spin_lock_irqsave(&sdos->lock, flags); |
---|
224 | 543 | if (--sd->lockcount == 0 && sd->client_intr_enabled) { |
---|
| 544 | +#ifdef BCMSPI_ANDROID |
---|
| 545 | + bcmsdh_oob_intr_set(1); |
---|
| 546 | +#else |
---|
225 | 547 | spi_devintr_on(sd); |
---|
| 548 | +#endif /* BCMSPI_ANDROID */ |
---|
226 | 549 | } |
---|
227 | 550 | spin_unlock_irqrestore(&sdos->lock, flags); |
---|
228 | 551 | } |
---|
229 | 552 | |
---|
| 553 | +#ifndef BCMSPI_ANDROID |
---|
230 | 554 | void spi_waitbits(sdioh_info_t *sd, bool yield) |
---|
231 | 555 | { |
---|
232 | 556 | #ifndef BCMSDYIELD |
---|
233 | 557 | ASSERT(!yield); |
---|
234 | | -#endif |
---|
| 558 | +#endif // endif |
---|
235 | 559 | sd_trace(("%s: yield %d canblock %d\n", |
---|
236 | 560 | __FUNCTION__, yield, BLOCKABLE())); |
---|
237 | 561 | |
---|
.. | .. |
---|
251 | 575 | } |
---|
252 | 576 | |
---|
253 | 577 | } |
---|
| 578 | +#else /* !BCMSPI_ANDROID */ |
---|
| 579 | +int bcmgspi_dump = 0; /* Set to dump complete trace of all SPI bus transactions */ |
---|
| 580 | + |
---|
| 581 | +static void |
---|
| 582 | +hexdump(char *pfx, unsigned char *msg, int msglen) |
---|
| 583 | +{ |
---|
| 584 | + int i, col; |
---|
| 585 | + char buf[80]; |
---|
| 586 | + |
---|
| 587 | + ASSERT(strlen(pfx) + 49 <= sizeof(buf)); |
---|
| 588 | + |
---|
| 589 | + col = 0; |
---|
| 590 | + |
---|
| 591 | + for (i = 0; i < msglen; i++, col++) { |
---|
| 592 | + if (col % 16 == 0) |
---|
| 593 | + strcpy(buf, pfx); |
---|
| 594 | + sprintf(buf + strlen(buf), "%02x", msg[i]); |
---|
| 595 | + if ((col + 1) % 16 == 0) |
---|
| 596 | + printf("%s\n", buf); |
---|
| 597 | + else |
---|
| 598 | + sprintf(buf + strlen(buf), " "); |
---|
| 599 | + } |
---|
| 600 | + |
---|
| 601 | + if (col % 16 != 0) |
---|
| 602 | + printf("%s\n", buf); |
---|
| 603 | +} |
---|
| 604 | + |
---|
| 605 | +/* Send/Receive an SPI Packet */ |
---|
| 606 | +void |
---|
| 607 | +spi_sendrecv(sdioh_info_t *sd, uint8 *msg_out, uint8 *msg_in, int msglen) |
---|
| 608 | +{ |
---|
| 609 | + int write = 0; |
---|
| 610 | + int tx_len = 0; |
---|
| 611 | + struct spi_message msg; |
---|
| 612 | + struct spi_transfer t[2]; |
---|
| 613 | + |
---|
| 614 | + spi_message_init(&msg); |
---|
| 615 | + memset(t, 0, 2*sizeof(struct spi_transfer)); |
---|
| 616 | + |
---|
| 617 | + if (sd->wordlen == 2) |
---|
| 618 | +#if !(defined(SPI_PIO_RW_BIGENDIAN) && defined(SPI_PIO_32BIT_RW)) |
---|
| 619 | + write = msg_out[2] & 0x80; |
---|
| 620 | +#else |
---|
| 621 | + write = msg_out[1] & 0x80; |
---|
| 622 | +#endif /* !(defined(SPI_PIO_RW_BIGENDIAN) && defined(SPI_PIO_32BIT_RW)) */ |
---|
| 623 | + if (sd->wordlen == 4) |
---|
| 624 | +#if !(defined(SPI_PIO_RW_BIGENDIAN) && defined(SPI_PIO_32BIT_RW)) |
---|
| 625 | + write = msg_out[0] & 0x80; |
---|
| 626 | +#else |
---|
| 627 | + write = msg_out[3] & 0x80; |
---|
| 628 | +#endif /* !(defined(SPI_PIO_RW_BIGENDIAN) && defined(SPI_PIO_32BIT_RW)) */ |
---|
| 629 | + |
---|
| 630 | + if (bcmgspi_dump) { |
---|
| 631 | + hexdump(" OUT: ", msg_out, msglen); |
---|
| 632 | + } |
---|
| 633 | + |
---|
| 634 | + tx_len = write ? msglen-4 : 4; |
---|
| 635 | + |
---|
| 636 | + sd_trace(("spi_sendrecv: %s, wordlen %d, cmd : 0x%02x 0x%02x 0x%02x 0x%02x\n", |
---|
| 637 | + write ? "WR" : "RD", sd->wordlen, |
---|
| 638 | + msg_out[0], msg_out[1], msg_out[2], msg_out[3])); |
---|
| 639 | + |
---|
| 640 | + t[0].tx_buf = (char *)&msg_out[0]; |
---|
| 641 | + t[0].rx_buf = 0; |
---|
| 642 | + t[0].len = tx_len; |
---|
| 643 | + |
---|
| 644 | + spi_message_add_tail(&t[0], &msg); |
---|
| 645 | + |
---|
| 646 | + t[1].rx_buf = (char *)&msg_in[tx_len]; |
---|
| 647 | + t[1].tx_buf = 0; |
---|
| 648 | + t[1].len = msglen-tx_len; |
---|
| 649 | + |
---|
| 650 | + spi_message_add_tail(&t[1], &msg); |
---|
| 651 | + spi_sync(gBCMSPI, &msg); |
---|
| 652 | + |
---|
| 653 | + if (bcmgspi_dump) { |
---|
| 654 | + hexdump(" IN : ", msg_in, msglen); |
---|
| 655 | + } |
---|
| 656 | +} |
---|
| 657 | +#endif /* !BCMSPI_ANDROID */ |
---|
| 658 | +#endif /* !GSPIBCM */ |
---|