Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
pl18x.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_PL18X_H
27#define _ULTIBO_PL18X_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include "ultibo/mmc.h"
34
36#define PL180_MMCI_DESCRIPTION "ARM PrimeCell PL180 MMCI Host"
37#define PL181_MMCI_DESCRIPTION "ARM PrimeCell PL181 MMCI Host"
38
40#define PL18X_MMCI_POWER 0x000
41#define PL18X_MMCI_POWER_OFF 0x00
43#define PL18X_MMCI_POWER_UP 0x02
44#define PL18X_MMCI_POWER_ON 0x03
46#define PL18X_MMCI_POWER_OD (1 << 6)
47#define PL18X_MMCI_POWER_ROD (1 << 7)
48
50#define PL18X_MMCI_POWER_ST_DATA2DIREN (1 << 2)
51#define PL18X_MMCI_POWER_ST_CMDDIREN (1 << 3)
52#define PL18X_MMCI_POWER_ST_DATA0DIREN (1 << 4)
53#define PL18X_MMCI_POWER_ST_DATA31DIREN (1 << 5)
54#define PL18X_MMCI_POWER_ST_FBCLKEN (1 << 7)
55#define PL18X_MMCI_POWER_ST_DATA74DIREN (1 << 8)
56
58#define PL18X_MMCI_CLOCK 0x004
59#define PL18X_MMCI_CLOCK_ENABLE (1 << 8)
60#define PL18X_MMCI_CLOCK_PWRSAVE (1 << 9)
61#define PL18X_MMCI_CLOCK_BYPASS (1 << 10)
62#define PL18X_MMCI_CLOCK_4BIT_BUS (1 << 11)
63
65#define PL18X_MMCI_CLOCK_ST_8BIT_BUS (1 << 12)
66#define PL18X_MMCI_CLOCK_ST_U300_HWFCEN (1 << 13)
67#define PL18X_MMCI_CLOCK_ST_UX500_NEG_EDGE (1 << 13)
68#define PL18X_MMCI_CLOCK_ST_UX500_HWFCEN (1 << 14)
69#define PL18X_MMCI_CLOCK_ST_UX500_CLK_INV (1 << 15)
71#define PL18X_MMCI_CLOCK_ARM_HWFCEN (1 << 12)
72
74#define PL18X_MMCI_CLOCK_QCOM_WIDEBUS_8 (1 << 10) | (1 << 11)
75#define PL18X_MMCI_CLOCK_QCOM_FLOWENA (1 << 12)
76#define PL18X_MMCI_CLOCK_QCOM_INVERTOUT (1 << 13)
77
79#define PL18X_MMCI_CLOCK_QCOM_SELECT_IN_FBCLK (1 << 15)
80#define PL18X_MMCI_CLOCK_QCOM_SELECT_IN_DDR_MODE (1 << 14) | (1 << 15)
81
83#define PL18X_MMCI_ARGUMENT 0x008
85
87#define PL18X_MMCI_COMMAND 0x00c
89#define PL18X_MMCI_CPSM_RESPONSE (1 << 6)
90#define PL18X_MMCI_CPSM_LONGRSP (1 << 7)
91#define PL18X_MMCI_CPSM_INTERRUPT (1 << 8)
92#define PL18X_MMCI_CPSM_PENDING (1 << 9)
93#define PL18X_MMCI_CPSM_ENABLE (1 << 10)
95#define PL18X_MMCI_CPSM_ST_SDIO_SUSP (1 << 11)
96#define PL18X_MMCI_CPSM_ST_ENCMD_COMPL (1 << 12)
97#define PL18X_MMCI_CPSM_ST_NIEN (1 << 13)
98#define PL18X_MMCI_CPSM_ST_CE_ATACMD (1 << 14)
99
101#define PL18X_MMCI_CPSM_QCOM_DATCMD (1 << 12)
102#define PL18X_MMCI_CPSM_QCOM_MCIABORT (1 << 13)
103#define PL18X_MMCI_CPSM_QCOM_CCSENABLE (1 << 14)
104#define PL18X_MMCI_CPSM_QCOM_CCSDISABLE (1 << 15)
105#define PL18X_MMCI_CPSM_QCOM_AUTO_CMD19 (1 << 16)
106#define PL18X_MMCI_CPSM_QCOM_AUTO_CMD21 (1 << 21)
107
109#define PL18X_MMCI_RESPCMD 0x010
112
114#define PL18X_MMCI_RESPONSE0 0x014
115#define PL18X_MMCI_RESPONSE1 0x018
116#define PL18X_MMCI_RESPONSE2 0x01c
117#define PL18X_MMCI_RESPONSE3 0x020
119
121#define PL18X_MMCI_DATATIMER 0x024
123
125#define PL18X_MMCI_DATALENGTH 0x028
128
130#define PL18X_MMCI_DATACTRL 0x02c
131#define PL18X_MMCI_DPSM_ENABLE (1 << 0)
132#define PL18X_MMCI_DPSM_DIRECTION (1 << 1)
133#define PL18X_MMCI_DPSM_MODE (1 << 2)
134#define PL18X_MMCI_DPSM_DMAENABLE (1 << 3)
135#define PL18X_MMCI_DPSM_BLOCKSIZE (1 << 4)
137#define PL18X_MMCI_ST_DPSM_RWSTART (1 << 8)
138#define PL18X_MMCI_ST_DPSM_RWSTOP (1 << 9)
139#define PL18X_MMCI_ST_DPSM_RWMOD (1 << 10)
140#define PL18X_MMCI_ST_DPSM_SDIOEN (1 << 11)
142#define PL18X_MMCI_ST_DPSM_DMAREQCTL (1 << 12)
143#define PL18X_MMCI_ST_DPSM_DBOOTMODEEN (1 << 13)
144#define PL18X_MMCI_ST_DPSM_BUSYMODE (1 << 14)
145#define PL18X_MMCI_ST_DPSM_DDRMODE (1 << 15)
146
148#define PL18X_MMCI_DATACNT 0x030
151
153#define PL18X_MMCI_STATUS 0x034
154#define PL18X_MMCI_CMDCRCFAIL (1 << 0)
155#define PL18X_MMCI_DATACRCFAIL (1 << 1)
156#define PL18X_MMCI_CMDTIMEOUT (1 << 2)
157#define PL18X_MMCI_DATATIMEOUT (1 << 3)
158#define PL18X_MMCI_TXUNDERRUN (1 << 4)
159#define PL18X_MMCI_RXOVERRUN (1 << 5)
160#define PL18X_MMCI_CMDRESPEND (1 << 6)
161#define PL18X_MMCI_CMDSENT (1 << 7)
162#define PL18X_MMCI_DATAEND (1 << 8)
163#define PL18X_MMCI_STARTBITERR (1 << 9)
164#define PL18X_MMCI_DATABLOCKEND (1 << 10)
165#define PL18X_MMCI_CMDACTIVE (1 << 11)
166#define PL18X_MMCI_TXACTIVE (1 << 12)
167#define PL18X_MMCI_RXACTIVE (1 << 13)
168#define PL18X_MMCI_TXFIFOHALFEMPTY (1 << 14)
169#define PL18X_MMCI_RXFIFOHALFFULL (1 << 15)
170#define PL18X_MMCI_TXFIFOFULL (1 << 16)
171#define PL18X_MMCI_RXFIFOFULL (1 << 17)
172#define PL18X_MMCI_TXFIFOEMPTY (1 << 18)
173#define PL18X_MMCI_RXFIFOEMPTY (1 << 19)
174#define PL18X_MMCI_TXDATAAVLBL (1 << 20)
175#define PL18X_MMCI_RXDATAAVLBL (1 << 21)
177#define PL18X_MMCI_ST_SDIOIT (1 << 22)
178#define PL18X_MMCI_ST_CEATAEND (1 << 23)
179#define PL18X_MMCI_ST_CARDBUSY (1 << 24)
180
182#define PL18X_MMCI_CLEAR 0x038
183#define PL18X_MMCI_CMDCRCFAILCLR (1 << 0)
184#define PL18X_MMCI_DATACRCFAILCLR (1 << 1)
185#define PL18X_MMCI_CMDTIMEOUTCLR (1 << 2)
186#define PL18X_MMCI_DATATIMEOUTCLR (1 << 3)
187#define PL18X_MMCI_TXUNDERRUNCLR (1 << 4)
188#define PL18X_MMCI_RXOVERRUNCLR (1 << 5)
189#define PL18X_MMCI_CMDRESPENDCLR (1 << 6)
190#define PL18X_MMCI_CMDSENTCLR (1 << 7)
191#define PL18X_MMCI_DATAENDCLR (1 << 8)
192#define PL18X_MMCI_STARTBITERRCLR (1 << 9)
193#define PL18X_MMCI_DATABLOCKENDCLR (1 << 10)
195#define PL18X_MMCI_ST_SDIOITC (1 << 22)
196#define PL18X_MMCI_ST_CEATAENDC (1 << 23)
197#define PL18X_MMCI_ST_BUSYENDC (1 << 24)
198
200#define PL18X_MMCI_MASK0 0x03c
201#define PL18X_MMCI_MASK1 0x040
202#define PL18X_MMCI_CMDCRCFAILMASK (1 << 0)
203#define PL18X_MMCI_DATACRCFAILMASK (1 << 1)
204#define PL18X_MMCI_CMDTIMEOUTMASK (1 << 2)
205#define PL18X_MMCI_DATATIMEOUTMASK (1 << 3)
206#define PL18X_MMCI_TXUNDERRUNMASK (1 << 4)
207#define PL18X_MMCI_RXOVERRUNMASK (1 << 5)
208#define PL18X_MMCI_CMDRESPENDMASK (1 << 6)
209#define PL18X_MMCI_CMDSENTMASK (1 << 7)
210#define PL18X_MMCI_DATAENDMASK (1 << 8)
211#define PL18X_MMCI_STARTBITERRMASK (1 << 9)
212#define PL18X_MMCI_DATABLOCKENDMASK (1 << 10)
213#define PL18X_MMCI_CMDACTIVEMASK (1 << 11)
214#define PL18X_MMCI_TXACTIVEMASK (1 << 12)
215#define PL18X_MMCI_RXACTIVEMASK (1 << 13)
216#define PL18X_MMCI_TXFIFOHALFEMPTYMASK (1 << 14)
217#define PL18X_MMCI_RXFIFOHALFFULLMASK (1 << 15)
218#define PL18X_MMCI_TXFIFOFULLMASK (1 << 16)
219#define PL18X_MMCI_RXFIFOFULLMASK (1 << 17)
220#define PL18X_MMCI_TXFIFOEMPTYMASK (1 << 18)
221#define PL18X_MMCI_RXFIFOEMPTYMASK (1 << 19)
222#define PL18X_MMCI_TXDATAAVLBLMASK (1 << 20)
223#define PL18X_MMCI_RXDATAAVLBLMASK (1 << 21)
225#define PL18X_MMCI_ST_SDIOITMASK (1 << 22)
226#define PL18X_MMCI_ST_CEATAENDMASK (1 << 23)
227#define PL18X_MMCI_ST_BUSYEND (1 << 24)
228
230#define PL18X_MMCI_SELECT 0x044
231
233#define PL18X_MMCI_FIFOCNT 0x048
234
236#define PL18X_MMCI_FIFO 0x080
237
239#define PL18X_MMCI_PERIPHID 0xFE0
240
242#define PL18X_MMCI_PCELLID 0xFF0
243
244#define PL18X_MMCI_IRQENABLE (PL18X_MMCI_CMDCRCFAILMASK | PL18X_MMCI_DATACRCFAILMASK | PL18X_MMCI_CMDTIMEOUTMASK | PL18X_MMCI_DATATIMEOUTMASK | PL18X_MMCI_TXUNDERRUNMASK | PL18X_MMCI_RXOVERRUNMASK | PL18X_MMCI_CMDRESPENDMASK | PL18X_MMCI_CMDSENTMASK | PL18X_MMCI_STARTBITERRMASK)
246#define PL18X_MMCI_IRQ1MASK (PL18X_MMCI_RXFIFOHALFFULLMASK | PL18X_MMCI_RXDATAAVLBLMASK | PL18X_MMCI_TXFIFOHALFEMPTYMASK)
247
250
258
259
288
289
293{
294 uint32_t power;
295 uint32_t clock;
296 uint32_t argument;
297 uint32_t command;
298 uint32_t respcmd;
299 uint32_t response0;
300 uint32_t response1;
301 uint32_t response2;
302 uint32_t response3;
303 uint32_t datatimer;
304 uint32_t datalength;
305 uint32_t datactrl;
306 uint32_t datacnt;
307 uint32_t status;
308 uint32_t clear;
309 uint32_t mask0;
310 uint32_t mask1;
311 uint32_t select;
312 uint32_t fifocnt;
313 uint8_t reserved[0x30];
314 uint32_t fifo;
315};
316
317
320
322typedef uint32_t STDCALL (*pl18xsdhci_get_rxfifo_count_proc)(PL18X_SDHCIHOST *sdhci, uint32_t status, uint32_t remain);
323
341
344
346
357SDHCI_HOST * STDCALL pl180sdhci_create(size_t address, char *name, uint32_t irq0, uint32_t irq1, uint32_t clockminimum, uint32_t clockmaximum, mmc_device_get_card_detect_proc carddetect, mmc_device_get_write_protect_proc writeprotect);
358
369SDHCI_HOST * STDCALL pl181sdhci_create(size_t address, char *name, uint32_t irq0, uint32_t irq1, uint32_t clockminimum, uint32_t clockmaximum, mmc_device_get_card_detect_proc carddetect, mmc_device_get_write_protect_proc writeprotect);
370
377
378#ifdef __cplusplus
379}
380#endif
381
382#endif // _ULTIBO_PL18X_H
int32_t LONGBOOL
Compatibility with FPC LongBool type (4 bytes).
Definition globaltypes.h:56
#define STDCALL
Definition globaltypes.h:45
struct _SDHCI_HOST SDHCI_HOST
Definition mmc.h:2237
uint32_t STDCALL(* mmc_device_get_write_protect_proc)(MMC_DEVICE *mmc)
Definition mmc.h:2042
uint32_t STDCALL(* mmc_device_get_card_detect_proc)(MMC_DEVICE *mmc)
Definition mmc.h:2041
uint32_t STDCALL pl18xsdhci_destroy(SDHCI_HOST *sdhci)
Stop, deregister and destroy a PL18X SDHCI device created by this driver.
struct _PL18X_SDHCIHOST PL18X_SDHCIHOST
Definition pl18x.h:319
uint32_t STDCALL(* pl18xsdhci_get_rxfifo_count_proc)(PL18X_SDHCIHOST *sdhci, uint32_t status, uint32_t remain)
Definition pl18x.h:322
SDHCI_HOST *STDCALL pl181sdhci_create(size_t address, char *name, uint32_t irq0, uint32_t irq1, uint32_t clockminimum, uint32_t clockmaximum, mmc_device_get_card_detect_proc carddetect, mmc_device_get_write_protect_proc writeprotect)
Create and register a new PL181 SDHCI device which can be accessed using the SDHCI API.
struct _PL18X_VERSIONID PL18X_VERSIONID
Definition pl18x.h:251
struct _PL18X_MMCIREGISTERS PL18X_MMCIREGISTERS
Definition pl18x.h:291
struct _PL18X_VERSIONDATA PL18X_VERSIONDATA
Definition pl18x.h:249
SDHCI_HOST *STDCALL pl180sdhci_create(size_t address, char *name, uint32_t irq0, uint32_t irq1, uint32_t clockminimum, uint32_t clockmaximum, mmc_device_get_card_detect_proc carddetect, mmc_device_get_write_protect_proc writeprotect)
Create and register a new PL180 SDHCI device which can be accessed using the SDHCI API.
void STDCALL pl18x_init(void)
Definition pl18x.h:293
uint32_t datalength
Data length register.
Definition pl18x.h:304
uint32_t mask0
Interrupt 0 mask register.
Definition pl18x.h:309
uint32_t response2
Response register.
Definition pl18x.h:301
uint32_t respcmd
Response command register.
Definition pl18x.h:298
uint32_t datatimer
Data timer.
Definition pl18x.h:303
uint32_t argument
Argument register.
Definition pl18x.h:296
uint32_t mask1
Interrupt 1 mask register.
Definition pl18x.h:310
uint32_t clear
Clear register.
Definition pl18x.h:308
uint32_t datacnt
Data counter.
Definition pl18x.h:306
uint32_t select
Secure digital memory card select register.
Definition pl18x.h:311
uint8_t reserved[0x30]
Reserved.
Definition pl18x.h:313
uint32_t fifo
Data FIFO register (0x80 to 0xBC).
Definition pl18x.h:314
uint32_t clock
Clock control register.
Definition pl18x.h:295
uint32_t datactrl
Data control register.
Definition pl18x.h:305
uint32_t response3
Response register.
Definition pl18x.h:302
uint32_t status
Status register.
Definition pl18x.h:307
uint32_t fifocnt
FIFO counter.
Definition pl18x.h:312
uint32_t response1
Response register.
Definition pl18x.h:300
uint32_t response0
Response register.
Definition pl18x.h:299
uint32_t command
Command register.
Definition pl18x.h:297
uint32_t power
Power control register.
Definition pl18x.h:294
Definition pl18x.h:325
uint32_t datactrlregister
Current data control register value.
Definition pl18x.h:337
uint32_t irq1
Second host IRQ line.
Definition pl18x.h:330
PL18X_VERSIONDATA * version
Host version data.
Definition pl18x.h:334
PL18X_MMCIREGISTERS * registers
Host registers.
Definition pl18x.h:333
uint32_t powerregister
Current power register value.
Definition pl18x.h:336
LONGBOOL enablefiq
Use FIQ instead of IRQ.
Definition pl18x.h:331
SDHCI_HOST sdhci
Definition pl18x.h:327
uint32_t clockregister
Current clock register value.
Definition pl18x.h:335
LONGBOOL singleirq
The host only has a single IRQ line instead of the standard 2 lines.
Definition pl18x.h:332
uint32_t busystatus
Current Busy Status for ST Micro variants.
Definition pl18x.h:338
pl18xsdhci_get_rxfifo_count_proc getrxfifocount
Model specific get_rxfifo_count function.
Definition pl18x.h:339
uint32_t irq0
First host IRQ line.
Definition pl18x.h:329
Definition pl18x.h:261
LONGBOOL qualcommdma
Enable Qualcomm specific DMA glue for DMA transfers.
Definition pl18x.h:285
LONGBOOL blocksizedatacontrol4
True if Block size is at b4..b16 position in MMCIDATACTRL register.
Definition pl18x.h:276
LONGBOOL powernopower
Bits in MMCIPOWER don't control external power supply.
Definition pl18x.h:282
uint32_t datalengthbits
Number of bits in the MMCIDATALENGTH register.
Definition pl18x.h:267
LONGBOOL blocksizedatacontrol16
True if Block size is at b16..b30 position in MMCIDATACTRL register.
Definition pl18x.h:275
uint32_t clock8bitenable
Enable value for 8 bit bus.
Definition pl18x.h:265
uint32_t fifosize
Number of bytes that can be written when MMCI_TXFIFOEMPTY is asserted (likewise for RX).
Definition pl18x.h:268
uint32_t datacontrolmaskddr
DDR mode mask in MMCIDATACTRL register.
Definition pl18x.h:271
char * name
Name of the device.
Definition pl18x.h:262
LONGBOOL busydetect
True if busy detection on dat0 is supported.
Definition pl18x.h:281
LONGBOOL stsdio
Enable ST specific SDIO logic.
Definition pl18x.h:273
uint32_t clockmaximum
Maximum clk frequency supported by the controller.
Definition pl18x.h:278
uint32_t powerpowerup
Power up value for MMCIPOWER register.
Definition pl18x.h:277
uint32_t clockenable
Enable value for MMCICLOCK register.
Definition pl18x.h:264
LONGBOOL powerclockgate
MMCIPOWER register must be used to gate the clock.
Definition pl18x.h:280
LONGBOOL stclockdivider
True if using a ST-specific clock divider algorithm.
Definition pl18x.h:274
LONGBOOL reversedirq
Handle data irq before cmd irq.
Definition pl18x.h:286
uint32_t clockregister
Default value for MCICLOCK register.
Definition pl18x.h:263
uint32_t clocknegativeedgeenable
Enable value for inverted data/cmd output.
Definition pl18x.h:266
LONGBOOL signaldirection
Input/out direction of bus signals can be indicated.
Definition pl18x.h:279
uint32_t fifohalfsize
Number of bytes that can be written when MCI_TXFIFOHALFEMPTY is asserted (likewise for RX).
Definition pl18x.h:269
uint32_t datacontrolmasksdio
SDIO enable mask in MMCIDATACTRL register.
Definition pl18x.h:272
LONGBOOL qualcommfifo
Enable Qualcomm specific FIFO PIO read logic.
Definition pl18x.h:284
LONGBOOL explicitmclockcontrol
Enable explicit mclk control in driver.
Definition pl18x.h:283
uint32_t datacommandenable
Enable value for data commands.
Definition pl18x.h:270
Definition pl18x.h:253
uint32_t peripheralmask
Definition pl18x.h:255
PL18X_VERSIONDATA * versiondata
Definition pl18x.h:256
uint32_t peripheralid
Definition pl18x.h:254