libsdhcdrivers: Enable reading Present State
Upper layer might be interested in reading Present State Register,
so function was added for reading it.
diff --git a/libsdhcdrivers/include/sdhc/sdio.h b/libsdhcdrivers/include/sdhc/sdio.h
index cdd3c64..d7dd789 100644
--- a/libsdhcdrivers/include/sdhc/sdio.h
+++ b/libsdhcdrivers/include/sdhc/sdio.h
@@ -27,6 +27,8 @@
int (*handle_irq)(struct sdio_host_dev *sdio, int irq);
int (*is_voltage_compatible)(struct sdio_host_dev *sdio, int mv);
int (*nth_irq)(struct sdio_host_dev *sdio, int n);
+ uint32_t (*get_present_state)(struct sdio_host_dev *sdio);
+
void *priv;
};
typedef struct sdio_host_dev sdio_host_dev_t;
@@ -80,6 +82,19 @@
}
/**
+ * @brief Returns Present State Register's value
+ *
+ * @return Value of the Present State Register, see SD specification for more
+ * details.
+ */
+static inline uint32_t sdio_get_present_state(
+ sdio_host_dev_t *sdio //!< [in] Sdio handle.
+)
+{
+ return sdio->get_present_state(sdio);
+}
+
+/**
* Passes control to the IRQ handler of the provided SDIO device
* @param[in] sdio A handle to an initialised SDIO driver
* @param[in] irq The IRQ number that was triggered.
diff --git a/libsdhcdrivers/src/sdhc.c b/libsdhcdrivers/src/sdhc.c
index 29f926e..7710ef7 100644
--- a/libsdhcdrivers/src/sdhc.c
+++ b/libsdhcdrivers/src/sdhc.c
@@ -180,13 +180,12 @@
}
}
-static inline enum dma_mode get_dma_mode(struct sdhc *host, struct mmc_cmd *cmd) {
- if (cmd->data == NULL)
- {
+static inline enum dma_mode get_dma_mode(struct sdhc *host, struct mmc_cmd *cmd)
+{
+ if (cmd->data == NULL) {
return DMA_MODE_NONE;
}
- if (cmd->data->pbuf == 0)
- {
+ if (cmd->data->pbuf == 0) {
return DMA_MODE_NONE;
}
/* Currently only SDMA supported */
@@ -661,6 +660,10 @@
}
}
+static uint32_t sdhc_get_present_state_register(sdio_host_dev_t *sdio)
+{
+ return readl(sdio_get_sdhc(sdio)->base + PRES_STATE);
+}
int sdhc_init(void *iobase, const int *irq_table, int nirqs, ps_io_ops_t *io_ops,
sdio_host_dev_t *dev)
@@ -687,6 +690,7 @@
dev->send_command = &sdhc_send_cmd;
dev->is_voltage_compatible = &sdhc_is_voltage_compatible;
dev->reset = &sdhc_reset;
+ dev->get_present_state = &sdhc_get_present_state_register;
dev->priv = sdhc;
/* Clear IRQs */
writel(0, sdhc->base + INT_STATUS_EN);