[PATCH 05/10] staging: mt7621-mmc: Use pinctrl subsystem to select SDXC pin mode
From: George Hilliard
Date: Wed Feb 20 2019 - 00:18:17 EST
The driver previously grabbed the SD pins for itself, ignoring the pin
controller. Replace this direct register access with appropriate calls
to the pinctrl subsystem.
This also allows this driver to work on related devices that have a
different pin controller mapping, such as the MT7688. The hardcoded
bit index was incorrect on that device.
This change could break SD controller functionality on existing devices
whose device trees do not specify a pin controller and state for the SD
node.
Signed-off-by: George Hilliard <thirtythreeforty@xxxxxxxxx>
---
drivers/staging/mt7621-mmc/sd.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index a7c7ec0d7bbb..97ed7510e96d 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -38,6 +38,7 @@
#include <linux/dma-mapping.h>
#include <linux/spinlock.h>
#include <linux/platform_device.h>
+#include <linux/pinctrl/consumer.h>
#include <linux/interrupt.h>
#include <linux/mmc/host.h>
@@ -1599,6 +1600,8 @@ static int msdc_drv_probe(struct platform_device *pdev)
struct msdc_host *host;
struct msdc_hw *hw;
int ret;
+ struct pinctrl *pctrl;
+ struct pinctrl_state *pins_default;
hw = &msdc0_hw;
@@ -1671,6 +1674,25 @@ static int msdc_drv_probe(struct platform_device *pdev)
host->mrq = NULL;
+ /* Read pin control settings from device tree */
+ pctrl = devm_pinctrl_get(&pdev->dev);
+ if (IS_ERR(pctrl)) {
+ ret = PTR_ERR(pctrl);
+ dev_err(&pdev->dev, "Cannot find pinctrl in device tree\n");
+ goto host_free;
+ }
+
+ pins_default = pinctrl_lookup_state(pctrl, PINCTRL_STATE_DEFAULT);
+ if (IS_ERR(pins_default)) {
+ ret = PTR_ERR(pins_default);
+ dev_err(&pdev->dev, "Cannot find pinctrl state default\n");
+ goto host_free;
+ }
+
+ ret = pinctrl_select_state(pctrl, pins_default);
+ if (ret < 0)
+ dev_warn(&pdev->dev, "Cannot select pinctrl state\n");
+
dma_coerce_mask_and_coherent(mmc_dev(mmc), DMA_BIT_MASK(32));
/* using dma_alloc_coherent*/ /* todo: using 1, for all 4 slots */
@@ -1822,12 +1844,6 @@ static struct platform_driver mt_msdc_driver = {
static int __init mt_msdc_init(void)
{
int ret;
- u32 reg;
-
- // Set the pins for sdxc to sdxc mode
- //FIXME: this should be done by pinctl and not by the sd driver
- reg = readl((void __iomem *)(RALINK_SYSCTL_BASE + 0x60)) & ~(0x3 << 18);
- writel(reg, (void __iomem *)(RALINK_SYSCTL_BASE + 0x60));
ret = platform_driver_register(&mt_msdc_driver);
if (ret) {
--
2.20.1