rtucker85 commented on a change in pull request #5835: URL: https://github.com/apache/incubator-nuttx/pull/5835#discussion_r835994940
########## File path: arch/risc-v/src/litex/litex_sdio.c ########## @@ -0,0 +1,1450 @@ +/**************************************************************************** + * arch/risc-v/src/litex/litex_sdio.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <debug.h> +#include <errno.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> +#include <string.h> + +#include <nuttx/arch.h> +#include <nuttx/cache.h> +#include <nuttx/clock.h> +#include <nuttx/mmcsd.h> +#include <nuttx/sdio.h> +#include <nuttx/semaphore.h> +#include <nuttx/signal.h> +#include <nuttx/wdog.h> +#include <nuttx/wqueue.h> + +#include <nuttx/irq.h> +#include <arch/board/board.h> + +#include "chip.h" +#include "riscv_internal.h" + +#include "litex_sdio.h" +#include "litex_clockconfig.h" +#include "hardware/litex_sdio.h" + +#define SD_CTL_DATA_XFER_NONE 0 +#define SD_CTL_DATA_XFER_READ 1 +#define SD_CTL_DATA_XFER_WRITE 2 + +#define SDCARD_CTRL_RESPONSE_NONE 0 +#define SDCARD_CTRL_RESPONSE_SHORT 1 +#define SDCARD_CTRL_RESPONSE_LONG 2 + +#define LITEX_INT_CARDDETECT (1 << 0) +#define LITEX_INT_BLOCK2MEM (1 << 1) +#define LITEX_INT_MEM2BLOCK (1 << 2) +#define LITEX_INT_CMDDONE (1 << 3) + +#ifndef CONFIG_LITEX_IDMODE_FREQ +# define CONFIG_LITEX_IDMODE_FREQ 400000 /* 400 KHz, ID mode */ +#endif + +#ifndef CONFIG_LITEX_MMCXFR_FREQ +# define CONFIG_LITEX_MMCXFR_FREQ 25000000 /* 25MHz MMC, normal clocking */ +#endif + +#ifndef CONFIG_LITEX_SD4BIT_FREQ +# define CONFIG_LITEX_SD4BIT_FREQ 50000000 /* 25MHz SD 4-bit, normal clocking */ +#endif + +#define max(x, y) (((x) > (y)) ? (x) : (y)) +#define min(x, y) (((x) < (y)) ? (x) : (y)) + +struct litex_dev_s Review comment: Done ########## File path: arch/risc-v/src/litex/litex_sdio.c ########## @@ -0,0 +1,1450 @@ +/**************************************************************************** + * arch/risc-v/src/litex/litex_sdio.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <debug.h> +#include <errno.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> +#include <string.h> + +#include <nuttx/arch.h> +#include <nuttx/cache.h> +#include <nuttx/clock.h> +#include <nuttx/mmcsd.h> +#include <nuttx/sdio.h> +#include <nuttx/semaphore.h> +#include <nuttx/signal.h> +#include <nuttx/wdog.h> +#include <nuttx/wqueue.h> + +#include <nuttx/irq.h> +#include <arch/board/board.h> + +#include "chip.h" +#include "riscv_internal.h" + +#include "litex_sdio.h" +#include "litex_clockconfig.h" +#include "hardware/litex_sdio.h" + +#define SD_CTL_DATA_XFER_NONE 0 +#define SD_CTL_DATA_XFER_READ 1 +#define SD_CTL_DATA_XFER_WRITE 2 + +#define SDCARD_CTRL_RESPONSE_NONE 0 +#define SDCARD_CTRL_RESPONSE_SHORT 1 +#define SDCARD_CTRL_RESPONSE_LONG 2 + +#define LITEX_INT_CARDDETECT (1 << 0) +#define LITEX_INT_BLOCK2MEM (1 << 1) +#define LITEX_INT_MEM2BLOCK (1 << 2) +#define LITEX_INT_CMDDONE (1 << 3) + +#ifndef CONFIG_LITEX_IDMODE_FREQ +# define CONFIG_LITEX_IDMODE_FREQ 400000 /* 400 KHz, ID mode */ +#endif + +#ifndef CONFIG_LITEX_MMCXFR_FREQ +# define CONFIG_LITEX_MMCXFR_FREQ 25000000 /* 25MHz MMC, normal clocking */ +#endif + +#ifndef CONFIG_LITEX_SD4BIT_FREQ +# define CONFIG_LITEX_SD4BIT_FREQ 50000000 /* 25MHz SD 4-bit, normal clocking */ +#endif + +#define max(x, y) (((x) > (y)) ? (x) : (y)) +#define min(x, y) (((x) < (y)) ? (x) : (y)) + +struct litex_dev_s +{ + struct sdio_dev_s dev; /* Standard, base SDIO interface */ + + /* Event support */ + + sem_t waitsem; /* Implements event waiting */ + sdio_eventset_t waitevents; /* Set of events to be waited for */ + uint32_t waitints; /* Interrupt enables for event waiting */ + volatile sdio_eventset_t wkupevent; /* The event that caused the wakeup */ + struct wdog_s waitwdog; /* Watchdog that handles event timeouts */ + + /* Callback support */ + + sdio_statset_t cdstatus; /* Card status */ + sdio_eventset_t cbevents; /* Set of events to be cause callbacks */ + worker_t callback; /* Registered callback function */ + void *cbarg; /* Registered callback argument */ + struct work_s cbwork; /* Callback work queue structure */ + + /* Interrupt mode data transfer support */ + + uint32_t xfrints; /* Interrupt enables for data transfer */ + + /* Card interrupt support for SDIO */ + + uint32_t cintints; /* Interrupt enables for card ints */ + int (*do_sdio_card)(void *); /* SDIO card ISR */ + void *do_sdio_arg; /* arg for SDIO card ISR */ + + /* Fixed transfer block size support */ + + uint8_t block_size; +}; + +static int litex_interrupt(int irq, void *context, void *arg); + +static void litex_reset(FAR struct sdio_dev_s *dev); +static sdio_capset_t litex_capabilities(FAR struct sdio_dev_s *dev); +static sdio_statset_t litex_status(FAR struct sdio_dev_s *dev); +static void litex_widebus(FAR struct sdio_dev_s *dev, + bool enable); Review comment: Done ########## File path: arch/risc-v/src/litex/litex_sdio.c ########## @@ -0,0 +1,1450 @@ +/**************************************************************************** + * arch/risc-v/src/litex/litex_sdio.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <debug.h> +#include <errno.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> +#include <string.h> + +#include <nuttx/arch.h> +#include <nuttx/cache.h> +#include <nuttx/clock.h> +#include <nuttx/mmcsd.h> +#include <nuttx/sdio.h> +#include <nuttx/semaphore.h> +#include <nuttx/signal.h> +#include <nuttx/wdog.h> +#include <nuttx/wqueue.h> + +#include <nuttx/irq.h> +#include <arch/board/board.h> + +#include "chip.h" +#include "riscv_internal.h" + +#include "litex_sdio.h" +#include "litex_clockconfig.h" +#include "hardware/litex_sdio.h" + +#define SD_CTL_DATA_XFER_NONE 0 +#define SD_CTL_DATA_XFER_READ 1 +#define SD_CTL_DATA_XFER_WRITE 2 + +#define SDCARD_CTRL_RESPONSE_NONE 0 +#define SDCARD_CTRL_RESPONSE_SHORT 1 +#define SDCARD_CTRL_RESPONSE_LONG 2 + +#define LITEX_INT_CARDDETECT (1 << 0) +#define LITEX_INT_BLOCK2MEM (1 << 1) +#define LITEX_INT_MEM2BLOCK (1 << 2) +#define LITEX_INT_CMDDONE (1 << 3) + +#ifndef CONFIG_LITEX_IDMODE_FREQ +# define CONFIG_LITEX_IDMODE_FREQ 400000 /* 400 KHz, ID mode */ +#endif + +#ifndef CONFIG_LITEX_MMCXFR_FREQ +# define CONFIG_LITEX_MMCXFR_FREQ 25000000 /* 25MHz MMC, normal clocking */ +#endif + +#ifndef CONFIG_LITEX_SD4BIT_FREQ +# define CONFIG_LITEX_SD4BIT_FREQ 50000000 /* 25MHz SD 4-bit, normal clocking */ +#endif + +#define max(x, y) (((x) > (y)) ? (x) : (y)) +#define min(x, y) (((x) < (y)) ? (x) : (y)) + +struct litex_dev_s +{ + struct sdio_dev_s dev; /* Standard, base SDIO interface */ + + /* Event support */ + + sem_t waitsem; /* Implements event waiting */ + sdio_eventset_t waitevents; /* Set of events to be waited for */ + uint32_t waitints; /* Interrupt enables for event waiting */ + volatile sdio_eventset_t wkupevent; /* The event that caused the wakeup */ + struct wdog_s waitwdog; /* Watchdog that handles event timeouts */ + + /* Callback support */ + + sdio_statset_t cdstatus; /* Card status */ + sdio_eventset_t cbevents; /* Set of events to be cause callbacks */ + worker_t callback; /* Registered callback function */ + void *cbarg; /* Registered callback argument */ + struct work_s cbwork; /* Callback work queue structure */ + + /* Interrupt mode data transfer support */ + + uint32_t xfrints; /* Interrupt enables for data transfer */ + + /* Card interrupt support for SDIO */ + + uint32_t cintints; /* Interrupt enables for card ints */ + int (*do_sdio_card)(void *); /* SDIO card ISR */ + void *do_sdio_arg; /* arg for SDIO card ISR */ + + /* Fixed transfer block size support */ + + uint8_t block_size; +}; + +static int litex_interrupt(int irq, void *context, void *arg); + +static void litex_reset(FAR struct sdio_dev_s *dev); +static sdio_capset_t litex_capabilities(FAR struct sdio_dev_s *dev); +static sdio_statset_t litex_status(FAR struct sdio_dev_s *dev); +static void litex_widebus(FAR struct sdio_dev_s *dev, + bool enable); +static void litex_clock(FAR struct sdio_dev_s *dev, + enum sdio_clock_e rate); +static int litex_attach(FAR struct sdio_dev_s *dev); +static int litex_sendcmd(FAR struct sdio_dev_s *dev, + uint32_t cmd, uint32_t arg); +static void litex_blocksetup(FAR struct sdio_dev_s *dev, + unsigned int blocklen, unsigned int nblocks); +static int litex_cancel(FAR struct sdio_dev_s *dev); +static int litex_recvsetup(FAR struct sdio_dev_s *dev, + FAR uint8_t *buffer, size_t nbytes); +static int litex_sendsetup(FAR struct sdio_dev_s *dev, + FAR const uint8_t *buffer, size_t buflen); +static int litex_waitresponse(FAR struct sdio_dev_s *dev, + uint32_t cmd); +static void litex_callbackenable(FAR struct sdio_dev_s *dev, + sdio_eventset_t eventset); +static int litex_registercallback(FAR struct sdio_dev_s *dev, + worker_t callback, void *arg); +static int litex_recvlong(FAR struct sdio_dev_s *dev, + uint32_t cmd, uint32_t rlong[4]); +static int litex_recvshort(FAR struct sdio_dev_s *dev, + uint32_t cmd, uint32_t *rshort); +static void litex_waitenable(FAR struct sdio_dev_s *dev, + sdio_eventset_t eventset, uint32_t timeout); +static sdio_eventset_t litex_eventwait(FAR struct sdio_dev_s *dev); + +static void litex_configwaitints(struct litex_dev_s *priv, uint32_t waitmask, + sdio_eventset_t waitevents, sdio_eventset_t wkupevents); +static void litex_configxfrints(struct litex_dev_s *priv, + uint32_t xfrints); + +/* Data Transfer Helpers ****************************************************/ + +static void litex_eventtimeout(wdparm_t arg); +static void litex_endwait(struct litex_dev_s *priv, + sdio_eventset_t wkupevent); +static void litex_callback(void *arg); + +struct litex_dev_s g_sdiodev = +{ + .dev = + { + .reset = litex_reset, + .capabilities = litex_capabilities, + .status = litex_status, + .widebus = litex_widebus, + .clock = litex_clock, + .attach = litex_attach, + .sendcmd = litex_sendcmd, + .blocksetup = litex_blocksetup, + .recvsetup = litex_recvsetup, + .sendsetup = litex_sendsetup, + .cancel = litex_cancel, + .dmarecvsetup = litex_recvsetup, + .dmasendsetup = litex_sendsetup, + .waitresponse = litex_waitresponse, + .recv_r1 = litex_recvshort, + .recv_r2 = litex_recvlong, + .recv_r3 = litex_recvshort, + .recv_r4 = litex_recvshort, + .recv_r5 = litex_recvshort, + .recv_r6 = litex_recvshort, + .recv_r7 = litex_recvshort, + .waitenable = litex_waitenable, + .eventwait = litex_eventwait, + .callbackenable = litex_callbackenable, + .registercallback = litex_registercallback, + }, +}; + +/**************************************************************************** + * Name: litex_pow2roundup + * + * Description: + * + ****************************************************************************/ + +static inline uint32_t litex_pow2roundup(uint32_t r) +{ + r--; + r |= r >> 1; + r |= r >> 2; + r |= r >> 4; + r |= r >> 8; + r |= r >> 16; + r++; + return r; +} + +/**************************************************************************** + * Name: litex_configwaitints + * + * Description: + * Enable/disable SDIO interrupts needed to support the wait function + * + * Input Parameters: + * priv - A reference to the SDIO device state structure + * waitmask - The set of bits in the SDIO MASK register to set + * waitevents - Waited for events + * wkupevent - Wake-up events + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void litex_configwaitints(struct litex_dev_s *priv, uint32_t waitints, + sdio_eventset_t waitevents, + sdio_eventset_t wkupevent) +{ + irqstate_t flags; + + flags = enter_critical_section(); + priv->waitevents = waitevents; + priv->wkupevent = wkupevent; + priv->waitints = waitints; + + putreg32(priv->xfrints | priv->waitints | priv->cintints, + LITEX_SDIRQ_ENABLE); + + mcinfo("pending irq: %08" PRIx32 " enabled irq: %08" PRIx32 "\n", + getreg32(LITEX_SDIRQ_PENDING), + getreg32(LITEX_SDIRQ_ENABLE)); + + leave_critical_section(flags); +} + +/**************************************************************************** + * Name: litex_configxfrints + * + * Description: + * Enable SDIO interrupts needed to support the data transfer event + * + * Input Parameters: + * priv - A reference to the SDIO device state structure + * xfrints - The set of bits in the SDIO MASK register to set + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void litex_configxfrints(struct litex_dev_s *priv, uint32_t xfrints) +{ + irqstate_t flags; + + flags = enter_critical_section(); + priv->xfrints = xfrints; + + putreg32(priv->xfrints | priv->waitints | priv->cintints, + LITEX_SDIRQ_ENABLE); + + mcinfo("pending irq: %08" PRIx32 " enabled irq: %08" PRIx32 "\n", + getreg32(LITEX_SDIRQ_PENDING), + getreg32(LITEX_SDIRQ_ENABLE)); + + leave_critical_section(flags); +} + +/**************************************************************************** + * Name: litex_interrupt + * + * Description: + * SDIO interrupt handler + * + * Input Parameters: + * dev - An instance of the SDIO device interface + * + * Returned Value: + * None + * + ****************************************************************************/ + +static int litex_interrupt(int irq, void *context, void *arg) +{ + struct litex_dev_s *priv = &g_sdiodev; + uint32_t pending; + + mcinfo("pending irq: %08" PRIx32 " enabled irq: %08" PRIx32 "\n", + getreg32(LITEX_SDIRQ_PENDING), + getreg32(LITEX_SDIRQ_ENABLE)); + + pending = getreg32(LITEX_SDIRQ_PENDING) & getreg32(LITEX_SDIRQ_ENABLE); + putreg32(pending, LITEX_SDIRQ_PENDING); + + mcinfo("pending irq: %08" PRIx32 " enabled irq: %08" PRIx32 "\n", + getreg32(LITEX_SDIRQ_PENDING), + getreg32(LITEX_SDIRQ_ENABLE)); + + /* check for card change interrupt */ + + if (pending & LITEX_INT_CARDDETECT) + { + mcinfo("Card Detect State: %lu\n", getreg32(LITEX_SDPHY_CARD_DETECT)); + + /* Perform callback */ + + if (priv->do_sdio_card) Review comment: Done ########## File path: arch/risc-v/src/litex/litex_sdio.c ########## @@ -0,0 +1,1450 @@ +/**************************************************************************** + * arch/risc-v/src/litex/litex_sdio.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <debug.h> +#include <errno.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> +#include <string.h> + +#include <nuttx/arch.h> +#include <nuttx/cache.h> +#include <nuttx/clock.h> +#include <nuttx/mmcsd.h> +#include <nuttx/sdio.h> +#include <nuttx/semaphore.h> +#include <nuttx/signal.h> +#include <nuttx/wdog.h> +#include <nuttx/wqueue.h> + +#include <nuttx/irq.h> +#include <arch/board/board.h> + +#include "chip.h" +#include "riscv_internal.h" + +#include "litex_sdio.h" +#include "litex_clockconfig.h" +#include "hardware/litex_sdio.h" + +#define SD_CTL_DATA_XFER_NONE 0 +#define SD_CTL_DATA_XFER_READ 1 +#define SD_CTL_DATA_XFER_WRITE 2 + +#define SDCARD_CTRL_RESPONSE_NONE 0 +#define SDCARD_CTRL_RESPONSE_SHORT 1 +#define SDCARD_CTRL_RESPONSE_LONG 2 + +#define LITEX_INT_CARDDETECT (1 << 0) +#define LITEX_INT_BLOCK2MEM (1 << 1) +#define LITEX_INT_MEM2BLOCK (1 << 2) +#define LITEX_INT_CMDDONE (1 << 3) + +#ifndef CONFIG_LITEX_IDMODE_FREQ +# define CONFIG_LITEX_IDMODE_FREQ 400000 /* 400 KHz, ID mode */ +#endif + +#ifndef CONFIG_LITEX_MMCXFR_FREQ +# define CONFIG_LITEX_MMCXFR_FREQ 25000000 /* 25MHz MMC, normal clocking */ +#endif + +#ifndef CONFIG_LITEX_SD4BIT_FREQ +# define CONFIG_LITEX_SD4BIT_FREQ 50000000 /* 25MHz SD 4-bit, normal clocking */ +#endif + +#define max(x, y) (((x) > (y)) ? (x) : (y)) +#define min(x, y) (((x) < (y)) ? (x) : (y)) + +struct litex_dev_s +{ + struct sdio_dev_s dev; /* Standard, base SDIO interface */ + + /* Event support */ + + sem_t waitsem; /* Implements event waiting */ + sdio_eventset_t waitevents; /* Set of events to be waited for */ + uint32_t waitints; /* Interrupt enables for event waiting */ + volatile sdio_eventset_t wkupevent; /* The event that caused the wakeup */ + struct wdog_s waitwdog; /* Watchdog that handles event timeouts */ + + /* Callback support */ + + sdio_statset_t cdstatus; /* Card status */ + sdio_eventset_t cbevents; /* Set of events to be cause callbacks */ + worker_t callback; /* Registered callback function */ + void *cbarg; /* Registered callback argument */ + struct work_s cbwork; /* Callback work queue structure */ + + /* Interrupt mode data transfer support */ + + uint32_t xfrints; /* Interrupt enables for data transfer */ + + /* Card interrupt support for SDIO */ + + uint32_t cintints; /* Interrupt enables for card ints */ + int (*do_sdio_card)(void *); /* SDIO card ISR */ + void *do_sdio_arg; /* arg for SDIO card ISR */ + + /* Fixed transfer block size support */ + + uint8_t block_size; +}; + +static int litex_interrupt(int irq, void *context, void *arg); + +static void litex_reset(FAR struct sdio_dev_s *dev); +static sdio_capset_t litex_capabilities(FAR struct sdio_dev_s *dev); +static sdio_statset_t litex_status(FAR struct sdio_dev_s *dev); +static void litex_widebus(FAR struct sdio_dev_s *dev, + bool enable); +static void litex_clock(FAR struct sdio_dev_s *dev, + enum sdio_clock_e rate); +static int litex_attach(FAR struct sdio_dev_s *dev); +static int litex_sendcmd(FAR struct sdio_dev_s *dev, + uint32_t cmd, uint32_t arg); +static void litex_blocksetup(FAR struct sdio_dev_s *dev, + unsigned int blocklen, unsigned int nblocks); +static int litex_cancel(FAR struct sdio_dev_s *dev); +static int litex_recvsetup(FAR struct sdio_dev_s *dev, + FAR uint8_t *buffer, size_t nbytes); +static int litex_sendsetup(FAR struct sdio_dev_s *dev, + FAR const uint8_t *buffer, size_t buflen); +static int litex_waitresponse(FAR struct sdio_dev_s *dev, + uint32_t cmd); +static void litex_callbackenable(FAR struct sdio_dev_s *dev, + sdio_eventset_t eventset); +static int litex_registercallback(FAR struct sdio_dev_s *dev, + worker_t callback, void *arg); +static int litex_recvlong(FAR struct sdio_dev_s *dev, + uint32_t cmd, uint32_t rlong[4]); +static int litex_recvshort(FAR struct sdio_dev_s *dev, + uint32_t cmd, uint32_t *rshort); +static void litex_waitenable(FAR struct sdio_dev_s *dev, + sdio_eventset_t eventset, uint32_t timeout); +static sdio_eventset_t litex_eventwait(FAR struct sdio_dev_s *dev); + +static void litex_configwaitints(struct litex_dev_s *priv, uint32_t waitmask, + sdio_eventset_t waitevents, sdio_eventset_t wkupevents); +static void litex_configxfrints(struct litex_dev_s *priv, + uint32_t xfrints); + +/* Data Transfer Helpers ****************************************************/ + +static void litex_eventtimeout(wdparm_t arg); +static void litex_endwait(struct litex_dev_s *priv, + sdio_eventset_t wkupevent); +static void litex_callback(void *arg); + +struct litex_dev_s g_sdiodev = +{ + .dev = + { + .reset = litex_reset, + .capabilities = litex_capabilities, + .status = litex_status, + .widebus = litex_widebus, + .clock = litex_clock, + .attach = litex_attach, + .sendcmd = litex_sendcmd, + .blocksetup = litex_blocksetup, + .recvsetup = litex_recvsetup, + .sendsetup = litex_sendsetup, + .cancel = litex_cancel, + .dmarecvsetup = litex_recvsetup, + .dmasendsetup = litex_sendsetup, + .waitresponse = litex_waitresponse, + .recv_r1 = litex_recvshort, + .recv_r2 = litex_recvlong, + .recv_r3 = litex_recvshort, + .recv_r4 = litex_recvshort, + .recv_r5 = litex_recvshort, + .recv_r6 = litex_recvshort, + .recv_r7 = litex_recvshort, + .waitenable = litex_waitenable, + .eventwait = litex_eventwait, + .callbackenable = litex_callbackenable, + .registercallback = litex_registercallback, + }, +}; + +/**************************************************************************** + * Name: litex_pow2roundup + * + * Description: + * + ****************************************************************************/ + +static inline uint32_t litex_pow2roundup(uint32_t r) +{ + r--; + r |= r >> 1; + r |= r >> 2; + r |= r >> 4; + r |= r >> 8; + r |= r >> 16; + r++; + return r; +} + +/**************************************************************************** + * Name: litex_configwaitints + * + * Description: + * Enable/disable SDIO interrupts needed to support the wait function + * + * Input Parameters: + * priv - A reference to the SDIO device state structure + * waitmask - The set of bits in the SDIO MASK register to set + * waitevents - Waited for events + * wkupevent - Wake-up events + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void litex_configwaitints(struct litex_dev_s *priv, uint32_t waitints, + sdio_eventset_t waitevents, + sdio_eventset_t wkupevent) +{ + irqstate_t flags; + + flags = enter_critical_section(); + priv->waitevents = waitevents; + priv->wkupevent = wkupevent; + priv->waitints = waitints; + + putreg32(priv->xfrints | priv->waitints | priv->cintints, + LITEX_SDIRQ_ENABLE); + + mcinfo("pending irq: %08" PRIx32 " enabled irq: %08" PRIx32 "\n", + getreg32(LITEX_SDIRQ_PENDING), + getreg32(LITEX_SDIRQ_ENABLE)); + + leave_critical_section(flags); +} + +/**************************************************************************** + * Name: litex_configxfrints + * + * Description: + * Enable SDIO interrupts needed to support the data transfer event + * + * Input Parameters: + * priv - A reference to the SDIO device state structure + * xfrints - The set of bits in the SDIO MASK register to set + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void litex_configxfrints(struct litex_dev_s *priv, uint32_t xfrints) +{ + irqstate_t flags; + + flags = enter_critical_section(); + priv->xfrints = xfrints; + + putreg32(priv->xfrints | priv->waitints | priv->cintints, + LITEX_SDIRQ_ENABLE); + + mcinfo("pending irq: %08" PRIx32 " enabled irq: %08" PRIx32 "\n", + getreg32(LITEX_SDIRQ_PENDING), + getreg32(LITEX_SDIRQ_ENABLE)); + + leave_critical_section(flags); +} + +/**************************************************************************** + * Name: litex_interrupt + * + * Description: + * SDIO interrupt handler + * + * Input Parameters: + * dev - An instance of the SDIO device interface + * + * Returned Value: + * None + * + ****************************************************************************/ + +static int litex_interrupt(int irq, void *context, void *arg) +{ + struct litex_dev_s *priv = &g_sdiodev; + uint32_t pending; + + mcinfo("pending irq: %08" PRIx32 " enabled irq: %08" PRIx32 "\n", + getreg32(LITEX_SDIRQ_PENDING), + getreg32(LITEX_SDIRQ_ENABLE)); + + pending = getreg32(LITEX_SDIRQ_PENDING) & getreg32(LITEX_SDIRQ_ENABLE); + putreg32(pending, LITEX_SDIRQ_PENDING); + + mcinfo("pending irq: %08" PRIx32 " enabled irq: %08" PRIx32 "\n", + getreg32(LITEX_SDIRQ_PENDING), + getreg32(LITEX_SDIRQ_ENABLE)); + + /* check for card change interrupt */ + + if (pending & LITEX_INT_CARDDETECT) Review comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org