arch/risc-v/src/litex/litex_sdio: add litesdcard peripheral driver

See the following for details on the pepheral:
https://github.com/enjoy-digital/litesdcard
This commit is contained in:
Richard Tucker
2022-03-24 15:05:16 +11:00
committed by Xiang Xiao
parent 163e3fd93c
commit 6d8cd4ec92
7 changed files with 1773 additions and 4 deletions
+2 -1
View File
@@ -35,9 +35,10 @@
#define LITEX_IRQ_UART0 (RISCV_IRQ_MEXT + 1)
#define LITEX_IRQ_TIMER0 (RISCV_IRQ_MEXT + 2)
#define LITEX_IRQ_SDCARD (RISCV_IRQ_MEXT + 3)
/* Total number of IRQs */
#define NR_IRQS (LITEX_IRQ_TIMER0 + 1)
#define NR_IRQS (LITEX_IRQ_SDCARD + 1)
#endif /* __ARCH_RISCV_INCLUDE_LITEX_IRQ_H */
+38
View File
@@ -25,4 +25,42 @@ config LITEX_UART0
select ARCH_HAVE_SERIAL_TERMIOS
select LITEX_UART
config LITEX_SDIO
bool "SDIO"
default n
select SCHED_WORKQUEUE
select SCHED_HPWORK
select MMCSD
select MMCSD_SDIO
select SDIO_BLOCKSETUP
select ARCH_HAVE_SDIO
select SDIO_DMA
config LITEX_SDIO1
bool "Enable SDIO1"
default y if LITEX_SDIO
select LITEX_SDIO_DMA
depends on LITEX_SDIO
if LITEX_SDIO1
config LITEX_IDMODE_FREQ
int "ID mode frequency"
default 400000
---help---
Initial, ID mode SD frequency
config LITEX_MMCXFR_FREQ
int "MMC transfer frequency"
default 25000000
---help---
Frequency to use for transferring data to/from an MMC card
config LITEX_SD4BIT_FREQ
int "SD 4-bit transfer frequency"
default 50000000
---help---
Frequency to use for transferring data to/from an SD card using all four data lines.
endif
endmenu
+4
View File
@@ -53,3 +53,7 @@ CHIP_CSRCS += litex_irq.c litex_irq_dispatch.c
CHIP_CSRCS += litex_lowputc.c litex_serial.c
CHIP_CSRCS += litex_start.c litex_timerisr.c
CHIP_ASRCS += litex_cache.S
ifeq ($(CONFIG_LITEX_SDIO),y)
CHIP_CSRCS += litex_sdio.c
endif
@@ -31,8 +31,13 @@
* uses two additional CSRs: mask and pending.
*/
#define LITEX_CPUTIMER_BASE 0xf0000800 /* riscv clint timer */
#define LITEX_TIMER0_BASE 0xf0002800
#define LITEX_UART0_BASE 0xf0002000 /* 0xf0002000 - : UART0 */
#define LITEX_CPUTIMER_BASE 0xf0000800
#define LITEX_SDBLOCK2MEM_BASE 0xf0002000
#define LITEX_SDCORE_BASE 0xf0002800
#define LITEX_SDIRQ_BASE 0xf0003000
#define LITEX_SDMEM2BLOCK_BASE 0xf0003800
#define LITEX_SDPHY_BASE 0xf0004000
#define LITEX_TIMER0_BASE 0xf0005000
#define LITEX_UART0_BASE 0xf0005800
#endif /* __ARCH_RISCV_SRC_LITEX_HARDWARE_LITEX_MEMORYMAP_H */
+104
View File
@@ -0,0 +1,104 @@
/****************************************************************************
* arch/risc-v/src/litex/hardware/litex_sdio.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_RISCV_SRC_LITEX_HARDWARE_LITEX_SDIO_H
#define __ARCH_RISCV_SRC_LITEX_HARDWARE_LITEX_SDIO_H
/****************************************************************************
* Included Files
****************************************************************************/
#include "hardware/litex_memorymap.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* LITEX_SDIO register offsets **********************************************/
#define LITEX_SDBLOCK2MEM_DMA_BASE_OFFSET 0x0000
#define LITEX_SDBLOCK2MEM_DMA_LENGTH_OFFSET 0x0008
#define LITEX_SDBLOCK2MEM_DMA_ENABLE_OFFSET 0x000C
#define LITEX_SDBLOCK2MEM_DMA_DONE_OFFSET 0x0010
#define LITEX_SDBLOCK2MEM_DMA_LOOP_OFFSET 0x0014
#define LITEX_SDBLOCK2MEM_DMA_OFFSET_OFFSET 0x0018
#define LITEX_SDCORE_CMD_ARGUMENT_OFFSET 0x0000
#define LITEX_SDCORE_CMD_COMMAND_OFFSET 0x0004
#define LITEX_SDCORE_CMD_SEND_OFFSET 0x0008
#define LITEX_SDCORE_CMD_RESPONSE_OFFSET 0x000C
#define LITEX_SDCORE_CMD_EVENT_OFFSET 0x001C
#define LITEX_SDCORE_DATA_EVENT_OFFSET 0x0020
#define LITEX_SDCORE_BLOCK_LENGTH_OFFSET 0x0024
#define LITEX_SDCORE_BLOCK_COUNT_OFFSET 0x0028
#define LITEX_SDIRQ_STATUS_OFFSET 0x0000
#define LITEX_SDIRQ_PENDING_OFFSET 0x0004
#define LITEX_SDIRQ_ENABLE_OFFSET 0x0008
#define LITEX_SDMEM2BLOCK_DMA_BASE_OFFSET 0x0000
#define LITEX_SDMEM2BLOCK_DMA_LENGTH_OFFSET 0x0008
#define LITEX_SDMEM2BLOCK_DMA_ENABLE_OFFSET 0x000C
#define LITEX_SDMEM2BLOCK_DMA_DONE_OFFSET 0x0010
#define LITEX_SDMEM2BLOCK_DMA_LOOP_OFFSET 0x0014
#define LITEX_SDMEM2BLOCK_DMA_OFFSET_OFFSET 0x0018
#define LITEX_SDPHY_CARD_DETECT_OFFSET 0x0000
#define LITEX_SDPHY_CLOCKER_DIVIDER_OFFSET 0x0004
#define LITEX_SDPHY_INIT_INITIALIZE_OFFSET 0x0008
#define LITEX_SDPHY_DATAW_STATUS_OFFSET 0x000C
/* LITEX_SDIO register addresses ********************************************/
#define LITEX_SDBLOCK2MEM_DMA_BASE (LITEX_SDBLOCK2MEM_BASE+LITEX_SDBLOCK2MEM_DMA_BASE_OFFSET)
#define LITEX_SDBLOCK2MEM_DMA_LENGTH (LITEX_SDBLOCK2MEM_BASE+LITEX_SDBLOCK2MEM_DMA_LENGTH_OFFSET)
#define LITEX_SDBLOCK2MEM_DMA_ENABLE (LITEX_SDBLOCK2MEM_BASE+LITEX_SDBLOCK2MEM_DMA_ENABLE_OFFSET)
#define LITEX_SDBLOCK2MEM_DMA_DONE (LITEX_SDBLOCK2MEM_BASE+LITEX_SDBLOCK2MEM_DMA_DONE_OFFSET)
#define LITEX_SDBLOCK2MEM_DMA_LOOP (LITEX_SDBLOCK2MEM_BASE+LITEX_SDBLOCK2MEM_DMA_LOOP_OFFSET)
#define LITEX_SDBLOCK2MEM_DMA_OFFSET (LITEX_SDBLOCK2MEM_BASE+LITEX_SDBLOCK2MEM_DMA_OFFSET_OFFSET)
#define LITEX_SDCORE_CMD_ARGUMENT (LITEX_SDCORE_BASE+LITEX_SDCORE_CMD_ARGUMENT_OFFSET)
#define LITEX_SDCORE_CMD_COMMAND (LITEX_SDCORE_BASE+LITEX_SDCORE_CMD_COMMAND_OFFSET)
#define LITEX_SDCORE_CMD_SEND (LITEX_SDCORE_BASE+LITEX_SDCORE_CMD_SEND_OFFSET)
#define LITEX_SDCORE_CMD_RESPONSE (LITEX_SDCORE_BASE+LITEX_SDCORE_CMD_RESPONSE_OFFSET)
#define LITEX_SDCORE_CMD_EVENT (LITEX_SDCORE_BASE+LITEX_SDCORE_CMD_EVENT_OFFSET)
#define LITEX_SDCORE_DATA_EVENT (LITEX_SDCORE_BASE+LITEX_SDCORE_DATA_EVENT_OFFSET)
#define LITEX_SDCORE_BLOCK_LENGTH (LITEX_SDCORE_BASE+LITEX_SDCORE_BLOCK_LENGTH_OFFSET)
#define LITEX_SDCORE_BLOCK_COUNT (LITEX_SDCORE_BASE+LITEX_SDCORE_BLOCK_COUNT_OFFSET)
#define LITEX_SDIRQ_STATUS (LITEX_SDIRQ_BASE+LITEX_SDIRQ_STATUS_OFFSET)
#define LITEX_SDIRQ_PENDING (LITEX_SDIRQ_BASE+LITEX_SDIRQ_PENDING_OFFSET)
#define LITEX_SDIRQ_ENABLE (LITEX_SDIRQ_BASE+LITEX_SDIRQ_ENABLE_OFFSET)
#define LITEX_SDMEM2BLOCK_DMA_BASE (LITEX_SDMEM2BLOCK_BASE+LITEX_SDMEM2BLOCK_DMA_BASE_OFFSET)
#define LITEX_SDMEM2BLOCK_DMA_LENGTH (LITEX_SDMEM2BLOCK_BASE+LITEX_SDMEM2BLOCK_DMA_LENGTH_OFFSET)
#define LITEX_SDMEM2BLOCK_DMA_ENABLE (LITEX_SDMEM2BLOCK_BASE+LITEX_SDMEM2BLOCK_DMA_ENABLE_OFFSET)
#define LITEX_SDMEM2BLOCK_DMA_DONE (LITEX_SDMEM2BLOCK_BASE+LITEX_SDMEM2BLOCK_DMA_DONE_OFFSET)
#define LITEX_SDMEM2BLOCK_DMA_LOOP (LITEX_SDMEM2BLOCK_BASE+LITEX_SDMEM2BLOCK_DMA_LOOP_OFFSET)
#define LITEX_SDMEM2BLOCK_DMA_OFFSET (LITEX_SDMEM2BLOCK_BASE+LITEX_SDMEM2BLOCK_DMA_OFFSET_OFFSET)
#define LITEX_SDPHY_CARD_DETECT (LITEX_SDPHY_BASE+LITEX_SDPHY_CARD_DETECT_OFFSET)
#define LITEX_SDPHY_CLOCKER_DIVIDER (LITEX_SDPHY_BASE+LITEX_SDPHY_CLOCKER_DIVIDER_OFFSET)
#define LITEX_SDPHY_INIT_INITIALIZER (LITEX_SDPHY_BASE+LITEX_SDPHY_INIT_INITIALIZE_OFFSET)
#define LITEX_SDPHY_DATAW_STATUS (LITEX_SDPHY_BASE+LITEX_SDPHY_DATAW_STATUS_OFFSET)
/* LITEX_SDIO register bit definitions **************************************/
#endif /* __ARCH_RISCV_SRC_LITEX_HARDWARE_LITEX_SDIO_H */
File diff suppressed because it is too large Load Diff
+120
View File
@@ -0,0 +1,120 @@
/****************************************************************************
* arch/risc-v/src/litex/litex_sdio.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_RISCV_SRC_LITEX_LITEX_SDIO_H
#define __ARCH_RISCV_SRC_LITEX_LITEX_SDIO_H
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: litex_sdio_get_card_detect
*
* Description:
* Get the card detection state determined by the peripheral.
*
* Input Parameters:
* None
*
* Returned Value:
* Card detected state.
* True when a card is present.
*
****************************************************************************/
bool litex_sdio_get_card_detect(void);
/****************************************************************************
* Name: litex_sdio_set_card_isr
*
* Description:
* SDIO card generates interrupt via SDIO_DATA_1 pin.
* Called by board-specific logic to register an ISR for SDIO card.
*
* Input Parameters:
* func - callback function.
* arg - arg to be passed to the function.
*
* Returned Value:
* None
*
****************************************************************************/
void litex_sdio_set_card_isr(struct sdio_dev_s *dev,
void (*func)(void *), void *arg);
/****************************************************************************
* Name: sdio_initialize
*
* Description:
* Initialize SDIO for operation.
*
* Input Parameters:
* slotno - Not used.
*
* Returned Value:
* A reference to an SDIO interface structure. NULL is returned on
* failures.
*
****************************************************************************/
struct sdio_dev_s; /* See include/nuttx/sdio.h */
struct sdio_dev_s *sdio_initialize(int slotno);
/****************************************************************************
* Name: sdio_mediachange
*
* Description:
* Called by board-specific logic -- possibly from an interrupt handler --
* in order to signal to the driver that a card has been inserted or
* removed from the slot
*
* Input Parameters:
* dev - An instance of the SDIO driver device state structure.
* cardinslot - true is a card has been detected in the slot; false if a
* card has been removed from the slot. Only transitions
* (inserted->removed or removed->inserted should be reported)
*
* Returned Value:
* None
*
****************************************************************************/
void sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_RISCV_SRC_LITEX_LITEX_SDIO_H */