[U-Boot] [PATCH 1/2] sunxi: Request card detect gpio

This is necessary for the device-model enabled builds to work properly.
Signed-off-by: Hans de Goede hdegoede@redhat.com --- drivers/mmc/sunxi_mmc.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c index f2fa12e..231f0a0 100644 --- a/drivers/mmc/sunxi_mmc.c +++ b/drivers/mmc/sunxi_mmc.c @@ -30,10 +30,22 @@ struct sunxi_mmc_host { /* support 4 mmc hosts */ struct sunxi_mmc_host mmc_host[4];
+static int sunxi_mmc_getcd_gpio(int sdc_no) +{ + switch (sdc_no) { + case 0: return sunxi_name_to_gpio(CONFIG_MMC0_CD_PIN); + case 1: return sunxi_name_to_gpio(CONFIG_MMC1_CD_PIN); + case 2: return sunxi_name_to_gpio(CONFIG_MMC2_CD_PIN); + case 3: return sunxi_name_to_gpio(CONFIG_MMC3_CD_PIN); + } + return -1; +} + static int mmc_resource_init(int sdc_no) { struct sunxi_mmc_host *mmchost = &mmc_host[sdc_no]; struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; + int cd_pin, ret = 0;
debug("init mmc %d resource\n", sdc_no);
@@ -60,7 +72,11 @@ static int mmc_resource_init(int sdc_no) } mmchost->mmc_no = sdc_no;
- return 0; + cd_pin = sunxi_mmc_getcd_gpio(sdc_no); + if (cd_pin != -1) + ret = gpio_request(cd_pin, "mmc_cd"); + + return ret; }
static int mmc_clk_io_on(int sdc_no) @@ -351,15 +367,9 @@ out: static int sunxi_mmc_getcd(struct mmc *mmc) { struct sunxi_mmc_host *mmchost = mmc->priv; - int cd_pin = -1; - - switch (mmchost->mmc_no) { - case 0: cd_pin = sunxi_name_to_gpio(CONFIG_MMC0_CD_PIN); break; - case 1: cd_pin = sunxi_name_to_gpio(CONFIG_MMC1_CD_PIN); break; - case 2: cd_pin = sunxi_name_to_gpio(CONFIG_MMC2_CD_PIN); break; - case 3: cd_pin = sunxi_name_to_gpio(CONFIG_MMC3_CD_PIN); break; - } + int cd_pin;
+ cd_pin = sunxi_mmc_getcd_gpio(mmchost->mmc_no); if (cd_pin == -1) return 1;
@@ -393,7 +403,9 @@ struct mmc *sunxi_mmc_init(int sdc_no) cfg->f_min = 400000; cfg->f_max = 52000000;
- mmc_resource_init(sdc_no); + if (mmc_resource_init(sdc_no) != 0) + return NULL; + mmc_clk_io_on(sdc_no);
return mmc_create(cfg, &mmc_host[sdc_no]);

This is necessary for the device-model enabled builds to work properly.
Signed-off-by: Hans de Goede hdegoede@redhat.com --- drivers/usb/host/ehci-sunxi.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/drivers/usb/host/ehci-sunxi.c b/drivers/usb/host/ehci-sunxi.c index d65e798..4befd57 100644 --- a/drivers/usb/host/ehci-sunxi.c +++ b/drivers/usb/host/ehci-sunxi.c @@ -163,11 +163,16 @@ int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, { struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; struct sunxi_ehci_hcd *sunxi_ehci = &sunxi_echi_hcd[index]; + int err;
/* enable common PHY only once */ if (index == 0) setbits_le32(&ccm->usb_clk_cfg, CCM_USB_CTRL_PHYGATE);
+ err = gpio_request(sunxi_ehci->gpio_vbus, "ehci_vbus"); + if (err) + return err; + sunxi_ehci_enable(sunxi_ehci);
*hccr = get_io_base(sunxi_ehci->id); @@ -188,9 +193,14 @@ int ehci_hcd_stop(int index) { struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; struct sunxi_ehci_hcd *sunxi_ehci = &sunxi_echi_hcd[index]; + int err;
sunxi_ehci_disable(sunxi_ehci);
+ err = gpio_free(sunxi_ehci->gpio_vbus); + if (err) + return err; + /* disable common PHY only once, for the last enabled hcd */ if (enabled_hcd_count == 1) clrbits_le32(&ccm->usb_clk_cfg, CCM_USB_CTRL_PHYGATE);

Hi Hans,
On 31 October 2014 10:23, Hans de Goede hdegoede@redhat.com wrote:
This is necessary for the device-model enabled builds to work properly.
Signed-off-by: Hans de Goede hdegoede@redhat.com
Acked-by: Simon Glass sjg@chromium.org
drivers/usb/host/ehci-sunxi.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/drivers/usb/host/ehci-sunxi.c b/drivers/usb/host/ehci-sunxi.c index d65e798..4befd57 100644 --- a/drivers/usb/host/ehci-sunxi.c +++ b/drivers/usb/host/ehci-sunxi.c @@ -163,11 +163,16 @@ int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, { struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; struct sunxi_ehci_hcd *sunxi_ehci = &sunxi_echi_hcd[index];
int err; /* enable common PHY only once */ if (index == 0) setbits_le32(&ccm->usb_clk_cfg, CCM_USB_CTRL_PHYGATE);
err = gpio_request(sunxi_ehci->gpio_vbus, "ehci_vbus");
if (err)
return err;
sunxi_ehci_enable(sunxi_ehci); *hccr = get_io_base(sunxi_ehci->id);
@@ -188,9 +193,14 @@ int ehci_hcd_stop(int index) { struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; struct sunxi_ehci_hcd *sunxi_ehci = &sunxi_echi_hcd[index];
int err; sunxi_ehci_disable(sunxi_ehci);
err = gpio_free(sunxi_ehci->gpio_vbus);
if (err)
return err;
I suppose we could ignore this error, or at least let the function finish before returning it. But I doubt this will ever happen.
/* disable common PHY only once, for the last enabled hcd */ if (enabled_hcd_count == 1) clrbits_le32(&ccm->usb_clk_cfg, CCM_USB_CTRL_PHYGATE);
-- 2.1.0
Regards, Simon

HI Hans,
On 31 October 2014 10:23, Hans de Goede hdegoede@redhat.com wrote:
This is necessary for the device-model enabled builds to work properly.
Signed-off-by: Hans de Goede hdegoede@redhat.com
Acked-by: Simon Glass sjg@chromium.org
drivers/mmc/sunxi_mmc.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c index f2fa12e..231f0a0 100644 --- a/drivers/mmc/sunxi_mmc.c +++ b/drivers/mmc/sunxi_mmc.c @@ -30,10 +30,22 @@ struct sunxi_mmc_host { /* support 4 mmc hosts */ struct sunxi_mmc_host mmc_host[4];
+static int sunxi_mmc_getcd_gpio(int sdc_no) +{
switch (sdc_no) {
case 0: return sunxi_name_to_gpio(CONFIG_MMC0_CD_PIN);
case 1: return sunxi_name_to_gpio(CONFIG_MMC1_CD_PIN);
case 2: return sunxi_name_to_gpio(CONFIG_MMC2_CD_PIN);
case 3: return sunxi_name_to_gpio(CONFIG_MMC3_CD_PIN);
}
return -1;
+}
static int mmc_resource_init(int sdc_no) { struct sunxi_mmc_host *mmchost = &mmc_host[sdc_no]; struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
int cd_pin, ret = 0; debug("init mmc %d resource\n", sdc_no);
@@ -60,7 +72,11 @@ static int mmc_resource_init(int sdc_no) } mmchost->mmc_no = sdc_no;
return 0;
cd_pin = sunxi_mmc_getcd_gpio(sdc_no);
if (cd_pin != -1)
ret = gpio_request(cd_pin, "mmc_cd");
You could be clever and do something like:
ret = gpio_request(cd_pin, "mmc_cd%d", sdc_no);
return ret;
}
static int mmc_clk_io_on(int sdc_no) @@ -351,15 +367,9 @@ out: static int sunxi_mmc_getcd(struct mmc *mmc) { struct sunxi_mmc_host *mmchost = mmc->priv;
int cd_pin = -1;
switch (mmchost->mmc_no) {
case 0: cd_pin = sunxi_name_to_gpio(CONFIG_MMC0_CD_PIN); break;
case 1: cd_pin = sunxi_name_to_gpio(CONFIG_MMC1_CD_PIN); break;
case 2: cd_pin = sunxi_name_to_gpio(CONFIG_MMC2_CD_PIN); break;
case 3: cd_pin = sunxi_name_to_gpio(CONFIG_MMC3_CD_PIN); break;
}
int cd_pin;
cd_pin = sunxi_mmc_getcd_gpio(mmchost->mmc_no); if (cd_pin == -1) return 1;
@@ -393,7 +403,9 @@ struct mmc *sunxi_mmc_init(int sdc_no) cfg->f_min = 400000; cfg->f_max = 52000000;
mmc_resource_init(sdc_no);
if (mmc_resource_init(sdc_no) != 0)
return NULL;
mmc_clk_io_on(sdc_no); return mmc_create(cfg, &mmc_host[sdc_no]);
-- 2.1.0
Regards, Simon
participants (2)
-
Hans de Goede
-
Simon Glass