On Wed, 20 Feb 2019 at 06:18, George Hilliard <thirtythreeforty@xxxxxxxxx> wrote: > > 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"); > + Selecting the PINCTRL_STATE_DEFAULT is already automatically done by the driver core on probe time[1], before calling the probe function, so this seems redundant here. The only difference is that you enforce the presence of a pinctrl node, while the core code is fine without one. Regards Jonas [1] https://elixir.bootlin.com/linux/latest/source/drivers/base/pinctrl.c#L21