Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
bcmsdhost.h
Go to the documentation of this file.
1/*
2 * This file is part of the Ultibo project, https://ultibo.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2026 Garry Wood <garry@softoz.com.au>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26#ifndef _ULTIBO_BCMSDHOST_H
27#define _ULTIBO_BCMSDHOST_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include "ultibo/threads.h"
34#include "ultibo/mmc.h"
35
37#define BCMSDHOST_DESCRIPTION "Broadcom BCM27XX SDHOST"
38
39#define BCMSDHOST_FIFO_READ_THRESHOLD 4
40#define BCMSDHOST_FIFO_WRITE_THRESHOLD 4
41#define BCMSDHOST_ALLOW_CMD23_READ 1
42#define BCMSDHOST_ALLOW_CMD23_WRITE 0
43#define BCMSDHOST_SDDATA_FIFO_PIO_BURST 8
44#define BCMSDHOST_CMD_DALLY_US 1
45
47#define BCMSDHOST_SDCMD 0x00
48#define BCMSDHOST_SDARG 0x04
49#define BCMSDHOST_SDTOUT 0x08
50#define BCMSDHOST_SDCDIV 0x0c
51#define BCMSDHOST_SDRSP0 0x10
52#define BCMSDHOST_SDRSP1 0x14
53#define BCMSDHOST_SDRSP2 0x18
54#define BCMSDHOST_SDRSP3 0x1c
55#define BCMSDHOST_SDHSTS 0x20
56#define BCMSDHOST_SDVDD 0x30
57#define BCMSDHOST_SDEDM 0x34
58#define BCMSDHOST_SDHCFG 0x38
59#define BCMSDHOST_SDHBCT 0x3c
60#define BCMSDHOST_SDDATA 0x40
61#define BCMSDHOST_SDHBLC 0x50
62
64#define BCMSDHOST_SDCMD_NEW_FLAG 0x8000
65#define BCMSDHOST_SDCMD_FAIL_FLAG 0x4000
66#define BCMSDHOST_SDCMD_BUSYWAIT 0x800
67#define BCMSDHOST_SDCMD_NO_RESPONSE 0x400
68#define BCMSDHOST_SDCMD_LONG_RESPONSE 0x200
69#define BCMSDHOST_SDCMD_WRITE_CMD 0x80
70#define BCMSDHOST_SDCMD_READ_CMD 0x40
71#define BCMSDHOST_SDCMD_CMD_MASK 0x3f
72
74#define BCMSDHOST_SDCDIV_MAX_CDIV 0x7ff
75
77#define BCMSDHOST_SDHSTS_BUSY_IRPT 0x400
78#define BCMSDHOST_SDHSTS_BLOCK_IRPT 0x200
79#define BCMSDHOST_SDHSTS_SDIO_IRPT 0x100
80#define BCMSDHOST_SDHSTS_REW_TIME_OUT 0x80
81#define BCMSDHOST_SDHSTS_CMD_TIME_OUT 0x40
82#define BCMSDHOST_SDHSTS_CRC16_ERROR 0x20
83#define BCMSDHOST_SDHSTS_CRC7_ERROR 0x10
84#define BCMSDHOST_SDHSTS_FIFO_ERROR 0x08
87#define BCMSDHOST_SDHSTS_DATA_FLAG 0x01
88
89#define BCMSDHOST_SDHSTS_TRANSFER_ERROR_MASK BCMSDHOST_SDHSTS_CRC7_ERROR | BCMSDHOST_SDHSTS_CRC16_ERROR | BCMSDHOST_SDHSTS_REW_TIME_OUT | BCMSDHOST_SDHSTS_FIFO_ERROR
90#define BCMSDHOST_SDHSTS_ERROR_MASK BCMSDHOST_SDHSTS_CMD_TIME_OUT | BCMSDHOST_SDHSTS_TRANSFER_ERROR_MASK
91
93#define BCMSDHOST_SDHCFG_BUSY_IRPT_EN (1 << 10)
94#define BCMSDHOST_SDHCFG_BLOCK_IRPT_EN (1 << 8)
95#define BCMSDHOST_SDHCFG_SDIO_IRPT_EN (1 << 5)
96#define BCMSDHOST_SDHCFG_DATA_IRPT_EN (1 << 4)
97#define BCMSDHOST_SDHCFG_SLOW_CARD (1 << 3)
98#define BCMSDHOST_SDHCFG_WIDE_EXT_BUS (1 << 2)
99#define BCMSDHOST_SDHCFG_WIDE_INT_BUS (1 << 1)
100#define BCMSDHOST_SDHCFG_REL_CMD_LINE (1 << 0)
101
103#define BCMSDHOST_SDEDM_FORCE_DATA_MODE (1 << 19)
104#define BCMSDHOST_SDEDM_CLOCK_PULSE (1 << 20)
105#define BCMSDHOST_SDEDM_BYPASS (1 << 21)
106
107#define BCMSDHOST_SDEDM_WRITE_THRESHOLD_SHIFT 9
108#define BCMSDHOST_SDEDM_READ_THRESHOLD_SHIFT 14
109#define BCMSDHOST_SDEDM_THRESHOLD_MASK 0x1f
110
111#define BCMSDHOST_SDEDM_FSM_MASK 0xf
112#define BCMSDHOST_SDEDM_FSM_IDENTMODE 0x0
113#define BCMSDHOST_SDEDM_FSM_DATAMODE 0x1
114#define BCMSDHOST_SDEDM_FSM_READDATA 0x2
115#define BCMSDHOST_SDEDM_FSM_WRITEDATA 0x3
116#define BCMSDHOST_SDEDM_FSM_READWAIT 0x4
117#define BCMSDHOST_SDEDM_FSM_READCRC 0x5
118#define BCMSDHOST_SDEDM_FSM_WRITECRC 0x6
119#define BCMSDHOST_SDEDM_FSM_WRITEWAIT1 0x7
120#define BCMSDHOST_SDEDM_FSM_POWERDOWN 0x8
121#define BCMSDHOST_SDEDM_FSM_POWERUP 0x9
122#define BCMSDHOST_SDEDM_FSM_WRITESTART1 0xa
123#define BCMSDHOST_SDEDM_FSM_WRITESTART2 0xb
124#define BCMSDHOST_SDEDM_FSM_GENPULSES 0xc
125#define BCMSDHOST_SDEDM_FSM_WRITEWAIT2 0xd
126#define BCMSDHOST_SDEDM_FSM_STARTPOWDOWN 0xf
127
128#define BCMSDHOST_SDDATA_FIFO_WORDS 16
129
130#define BCMSDHOST_USE_CMD23_FLAGS (BCMSDHOST_ALLOW_CMD23_READ * MMC_DATA_READ) | (BCMSDHOST_ALLOW_CMD23_WRITE * MMC_DATA_WRITE)
131
133#define BCMSDHOST_MBOX_TAG_SET_SDHOST_CLOCK 0x00038042
134
139{
140 uint32_t clock;
141 uint32_t value1;
142 uint32_t value2;
143};
144
178
181
183
198SDHCI_HOST * STDCALL bcmsdhost_create(size_t address, char *name, uint32_t irq, uint32_t dreq, uint32_t clockminimum, uint32_t clockmaximum, uint32_t gpiofirst, uint32_t gpiolast, uint32_t gpiofunction, BOOL enablefiq);
199
206
207#ifdef __cplusplus
208}
209#endif
210
211#endif // _ULTIBO_BCMSDHOST_H
uint32_t STDCALL bcmsdhost_destroy(SDHCI_HOST *sdhci)
Stop, deregister and destroy a BCMSDHOST SDHCI device created by this driver.
struct _BCMSDHOST_HOST BCMSDHOST_HOST
Definition bcmsdhost.h:145
SDHCI_HOST *STDCALL bcmsdhost_create(size_t address, char *name, uint32_t irq, uint32_t dreq, uint32_t clockminimum, uint32_t clockmaximum, uint32_t gpiofirst, uint32_t gpiolast, uint32_t gpiofunction, BOOL enablefiq)
Create and register a new BCMSDHOST SDHCI device which can be accessed using the SDHCI API.
void STDCALL bcmsdhost_init(void)
struct _BCMSDHOST_MAILBOX_TAG_SET_SDHOST_CLOCK BCMSDHOST_MAILBOX_TAG_SET_SDHOST_CLOCK
Definition bcmsdhost.h:137
int32_t LONGBOOL
Compatibility with FPC LongBool type (4 bytes).
Definition globaltypes.h:56
#define STDCALL
Definition globaltypes.h:45
HANDLE SPIN_HANDLE
Definition globaltypes.h:104
_Bool BOOL
Built in Boolean type (1 byte) (Redeclared here for flexibility).
Definition globaltypes.h:55
struct _SDHCI_HOST SDHCI_HOST
Definition mmc.h:2237
Definition bcmsdhost.h:147
LONGBOOL allowdma
Allow DMA to be used for data transfers.
Definition bcmsdhost.h:162
uint32_t hostconfiguration
Cached Host Configuration (HCFG) register.
Definition bcmsdhost.h:158
uint32_t irq
The IRQ number for this device.
Definition bcmsdhost.h:151
uint32_t drainoffset
Offset for data during FIFO drain on DMA read.
Definition bcmsdhost.h:167
LONGBOOL firmwaresetsclockdivider
True if the firmware controls the clock divider.
Definition bcmsdhost.h:159
uint32_t commandquickpollretries
Definition bcmsdhost.h:160
uint32_t overclock
Current frequency if overclocked, else zero (in Hz).
Definition bcmsdhost.h:174
uint32_t overclock50
Frequency to use when 50MHz is requested (in MHz).
Definition bcmsdhost.h:173
SPIN_HANDLE lock
Host lock (Differs from lock in Host portion) (Spin lock due to use by interrupt handler).
Definition bcmsdhost.h:152
LONGBOOL enablefiq
Use FIQ instead of IRQ.
Definition bcmsdhost.h:153
uint32_t useroverclock50
User's preferred frequency to use when 50MHz is requested (in MHz).
Definition bcmsdhost.h:172
uint32_t piotimeout
PIO Read or Write block timeout (in milliseconds).
Definition bcmsdhost.h:176
SDHCI_HOST sdhci
Definition bcmsdhost.h:149
uint32_t piolimit
Maximum block count for PIO (0 = always DMA / 0x7FFFFFF = always PIO).
Definition bcmsdhost.h:175
uint32_t delayafterthisstop
Minimum time between this stop and subsequent data transfer (in Microseconds).
Definition bcmsdhost.h:171
uint32_t nanosecondsperfifoword
Definition bcmsdhost.h:161
LONGBOOL usebusy
Wait for busy interrupt on current command.
Definition bcmsdhost.h:169
LONGBOOL resetclock
Reset the clock for the next request.
Definition bcmsdhost.h:163
uint32_t clockdivider
Cached Clock Divider (CDIV) register.
Definition bcmsdhost.h:157
uint32_t gpiolast
The ending pin number for GPIO assignments (or GPIO_PIN_UNKNOWN if externally configured).
Definition bcmsdhost.h:155
uint32_t gpiofunction
The function number for GPIO assignments (or GPIO_FUNCTION_UNKNOWN if externally configured).
Definition bcmsdhost.h:156
LONGBOOL usesbc
Use CMD23 (Set Block Count) for the current transfer.
Definition bcmsdhost.h:168
uint32_t drainwords
Last words of FIFO to drain on DMA read.
Definition bcmsdhost.h:166
uint32_t gpiofirst
The starting pin number for GPIO assignments (or GPIO_PIN_UNKNOWN if externally configured).
Definition bcmsdhost.h:154
int64_t stoptime
When the last stop was issued (in Clock Ticks).
Definition bcmsdhost.h:165
uint32_t delayafterstop
Minimum time between stop and subsequent data transfer (in Microseconds).
Definition bcmsdhost.h:170
uint32_t maxdelay
Maximum length of time spent waiting (in Milliseconds).
Definition bcmsdhost.h:164
Definition bcmsdhost.h:139
uint32_t value1
Definition bcmsdhost.h:141
uint32_t value2
Definition bcmsdhost.h:142
uint32_t clock
Definition bcmsdhost.h:140