omap_hsmmc: reuse mmc/slot-gpio functions
Subsystems (2)
cover omap_hsmmc: reuse mmc/slot-gpio functions
Hi,
I would like to reuse mmc_of_parse for standard mmc features:
- cd-gpios / wp-gpios
- bus-width
- max-frequency
- keep-power-in-suspend
- enable-sdio-wakeup
- ti,non-removable, evtl.
Currently these are open-coded in of_get_hsmmc_pdata. I tried removing them from of_get_hsmmc_pdata and call mmc_of_parse at the end of the probe function:
@@ -2241,8 +2264,6 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
omap_hsmmc_protect_card(host);
+ mmc_of_parse(host->mmc);
mmc_add_host(mmc);This could work transparently for most features but definitely not for cd-gpios/wp-gpios. Pls can somebody have a look at the followup patches? I tried an intermediate step mapping card detect / read-only detect onto mmc/slot-gpio, that are used by mmc_of_parse. I don't have card detect/read-only detect pins, so patches are untested, :-(
Do we need cover_detect functionality or could it be merged with card detect?
Another issue is 'ti,non-removable' which could be mappend to stanadard 'non-removable' if 'no_regulator_off_init' was handled in a different way.
if (of_find_property(np, "ti,non-removable", NULL)) {
pdata->slots[0].nonremovable = true;
pdata->slots[0].no_regulator_off_init = true;
} /Andreas
Andreas Fenkart (3):
omap_hsmmc: reuse mmc/slot-gpio for write protect detection
omap_hsmmc: separate card_detect/cover detect logic
omap_hsmmc: reuse mmc/slot-gpio for card detect instead of open-coded
version
drivers/mmc/host/omap_hsmmc.c | 172 ++++++++++++++------------------- include/linux/platform_data/mmc-omap.h | 6 +- 2 files changed, 73 insertions(+), 105 deletions(-)
Signature · 1 line
2.0.0
PATCH RESEND 1/3 omap_hsmmc: reuse mmc/slot-gpio for write protect detection
drivers/mmc/host/omap_hsmmc.c +27 -45
@@ -36,6 +36,7 @@#include <linux/mmc/host.h> #include <linux/mmc/core.h> #include <linux/mmc/mmc.h> +#include <linux/mmc/slot-gpio.h> #include <linux/io.h> #include <linux/irq.h> #include <linux/gpio.h>
@@ -239,15 +240,6 @@ static int omap_hsmmc_card_detect(struct device *dev, int slot)return !gpio_get_value_cansleep (mmc->slots[0 ].switch_pin); } -static int omap_hsmmc_get_wp (struct device *dev,int slot) -{ -struct omap_hsmmc_host *host =dev_get_drvdata (dev); -struct omap_mmc_platform_data *mmc = host->pdata; - -/* NOTE: assumes write protect signal is active-high */ -return gpio_get_value_cansleep (mmc->slots[0 ].gpio_wp); -} -static int omap_hsmmc_get_cover_state (struct device *dev,int slot) {struct omap_hsmmc_host *host =dev_get_drvdata (dev);
@@ -449,7 +441,8 @@ static inline int omap_hsmmc_have_reg(void)#endif -static int omap_hsmmc_gpio_init (struct omap_mmc_platform_data *pdata) +static int omap_hsmmc_gpio_init (struct mmc_host *mmc, +struct omap_mmc_platform_data *pdata) {int ret;
@@ -471,31 +464,31 @@ static int omap_hsmmc_gpio_init(struct omap_mmc_platform_data *pdata) pdata->slots[0 ].switch_pin = -EINVAL ;if (gpio_is_valid (pdata->slots[0 ].gpio_wp)) { - pdata->slots[0 ].get_ro = omap_hsmmc_get_wp; - ret =gpio_request (pdata->slots[0 ].gpio_wp,"mmc_wp" ); -if (ret) - goto err_free_cd; - ret =gpio_direction_input (pdata->slots[0 ].gpio_wp); -if (ret) - goto err_free_wp; - }else - pdata->slots[0 ].gpio_wp = -EINVAL ; +/* copy & paste from from mmc_of_parse */ + ret =mmc_gpio_request_ro (mmc, pdata->slots[0 ].gpio_wp); +if (ret <0 ) { +dev_err (pdata->dev, +"Failed to request WP GPIO: %d!\n" , ret); + goto err; + }else { +dev_info (pdata->dev,"Got WP GPIO #%d.\n" , + pdata->slots[0 ].gpio_wp); + } + }return 0 ; -err_free_wp: -gpio_free (pdata->slots[0 ].gpio_wp); -err_free_cd: +err:if (gpio_is_valid (pdata->slots[0 ].switch_pin)) err_free_sp:gpio_free (pdata->slots[0 ].switch_pin);return ret; } -static void omap_hsmmc_gpio_free (struct omap_mmc_platform_data *pdata) +static void omap_hsmmc_gpio_free (struct mmc_host *mmc, +struct omap_mmc_platform_data *pdata) { -if (gpio_is_valid (pdata->slots[0 ].gpio_wp)) -gpio_free (pdata->slots[0 ].gpio_wp); +mmc_gpio_free_ro (mmc);if (gpio_is_valid (pdata->slots[0 ].switch_pin))gpio_free (pdata->slots[0 ].switch_pin); }
@@ -1673,15 +1666,6 @@ static int omap_hsmmc_get_cd(struct mmc_host *mmc)return mmc_slot (host).card_detect (host->dev, host->slot_id); } -static int omap_hsmmc_get_ro (struct mmc_host *mmc) -{ -struct omap_hsmmc_host *host =mmc_priv (mmc); - -if (!mmc_slot (host).get_ro) -return -ENOSYS ; -return mmc_slot (host).get_ro (host->dev,0 ); -} -static void omap_hsmmc_init_card (struct mmc_host *mmc,struct mmc_card *card) {struct omap_hsmmc_host *host =mmc_priv (mmc);
@@ -1837,7 +1821,7 @@ static const struct mmc_host_ops omap_hsmmc_ops = { .request = omap_hsmmc_request, .set_ios = omap_hsmmc_set_ios, .get_cd = omap_hsmmc_get_cd, - .get_ro = omap_hsmmc_get_ro, + .get_ro = mmc_gpio_get_ro, .init_card = omap_hsmmc_init_card, .enable_sdio_irq = omap_hsmmc_enable_sdio_irq, };
@@ -2063,16 +2047,15 @@ static int omap_hsmmc_probe(struct platform_device *pdev)if (IS_ERR (base))return PTR_ERR (base); - ret =omap_hsmmc_gpio_init (pdata); -if (ret) - goto err; - mmc =mmc_alloc_host (sizeof (struct omap_hsmmc_host ), &pdev->dev);if (!mmc) { - ret = -ENOMEM ; - goto err_alloc; +return -ENOMEM ; } + ret =omap_hsmmc_gpio_init (mmc, pdata); +if (ret) + goto err; + host =mmc_priv (mmc); host->mmc = mmc; host->pdata = pdata;
@@ -2302,10 +2285,9 @@ err_irq:if (host->dbclk)clk_disable_unprepare (host->dbclk); err1: -mmc_free_host (mmc); -err_alloc: -omap_hsmmc_gpio_free (pdata); +omap_hsmmc_gpio_free (mmc, pdata); err: +mmc_free_host (mmc);return ret; }
@@ -2330,7 +2312,7 @@ static int omap_hsmmc_remove(struct platform_device *pdev)if (host->dbclk)clk_disable_unprepare (host->dbclk); -omap_hsmmc_gpio_free (host->pdata); +omap_hsmmc_gpio_free (host->mmc, host->pdata);mmc_free_host (host->mmc);return 0 ;
include/linux/platform_data/mmc-omap.h +0 -1
@@ -120,7 +120,6 @@ struct omap_mmc_platform_data {int (*set_bus_mode)(struct device *dev,int slot,int bus_mode);int (*set_power)(struct device *dev,int slot,int power_on,int vdd); -int (*get_ro)(struct device *dev,int slot);void (*remux)(struct device *dev,int slot,int power_on);/* Call back before enabling / disabling regulators */ void (*before_set_reg)(struct device *dev, int slot,
Signature · 1 line
2.0.0
PATCH RESEND 2/3 omap_hsmmc: separate card_detect/cover detect logic
In reply to Andreas Fenkartassuming cover is the door like thing on cameras that needs to be closed after replacing sd cards. card detect is a gpio connected to sdio slot. in a follow up patch card_detect will be replaced by generic mmc/slot-gpio a git bisect patch
drivers/mmc/host/omap_hsmmc.c +30 -18
@@ -447,19 +447,32 @@ static int omap_hsmmc_gpio_init(struct mmc_host *mmc,int ret;if (gpio_is_valid (pdata->slots[0 ].switch_pin)) { -if (pdata->slots[0 ].cover) +if (pdata->slots[0 ].cover) { pdata->slots[0 ].get_cover_state = omap_hsmmc_get_cover_state; -else + pdata->slots[0 ].cover_detect_irq = +gpio_to_irq (pdata->slots[0 ].switch_pin); + + ret =gpio_request (pdata->slots[0 ].switch_pin, +"mmc_cd" ); +if (ret) +return ret; + ret =gpio_direction_input (pdata->slots[0 ].switch_pin); +if (ret) + goto err_free_sp; + }else { pdata->slots[0 ].card_detect = omap_hsmmc_card_detect; - pdata->slots[0 ].card_detect_irq = + pdata->slots[0 ].card_detect_irq =gpio_to_irq (pdata->slots[0 ].switch_pin); - ret =gpio_request (pdata->slots[0 ].switch_pin,"mmc_cd" ); -if (ret) -return ret; - ret =gpio_direction_input (pdata->slots[0 ].switch_pin); -if (ret) - goto err_free_sp; + + ret =gpio_request (pdata->slots[0 ].switch_pin, +"mmc_cd" ); +if (ret) +return ret; + ret =gpio_direction_input (pdata->slots[0 ].switch_pin); +if (ret) + goto err_free_sp; + } }else pdata->slots[0 ].switch_pin = -EINVAL ;
@@ -1282,19 +1295,18 @@ static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id)struct omap_mmc_slot_data *slot = &mmc_slot (host);int carddetect; -sysfs_notify (&host->mmc->class_dev.kobj,NULL ,"cover_switch" ); - -if (slot->card_detect) +if (slot->card_detect) { carddetect = slot->card_detect (host->dev, host->slot_id); -else { +if (carddetect) +mmc_detect_change (host->mmc, (HZ *200 ) /1000 ); +else +mmc_detect_change (host->mmc, (HZ *50 ) /1000 ); + }else { +sysfs_notify (&host->mmc->class_dev.kobj,NULL ,"cover_switch" );omap_hsmmc_protect_card (host); - carddetect = -ENOSYS ; +mmc_detect_change (host->mmc, (HZ *200 ) /1000 ); } -if (carddetect) -mmc_detect_change (host->mmc, (HZ *200 ) /1000 ); -else -mmc_detect_change (host->mmc, (HZ *50 ) /1000 );return IRQ_HANDLED ; }
include/linux/platform_data/mmc-omap.h +1 -0
@@ -136,6 +136,7 @@ struct omap_mmc_platform_data {* 0 - closed * 1 - open */ +int cover_detect_irq;int (*get_cover_state)(struct device *dev,int slot);const char *name;
Signature · 1 line
2.0.0
PATCH RESEND 3/3 omap_hsmmc: reuse mmc/slot-gpio for card detect instead of open-coded version
In reply to Andreas Fenkartdrivers/mmc/host/omap_hsmmc.c +35 -57
@@ -231,15 +231,6 @@ struct omap_mmc_of_data {static void omap_hsmmc_start_dma_transfer (struct omap_hsmmc_host *host); -static int omap_hsmmc_card_detect (struct device *dev,int slot) -{ -struct omap_hsmmc_host *host =dev_get_drvdata (dev); -struct omap_mmc_platform_data *mmc = host->pdata; - -/* NOTE: assumes card detect signal is active-low */ -return !gpio_get_value_cansleep (mmc->slots[0 ].switch_pin); -} -static int omap_hsmmc_get_cover_state (struct device *dev,int slot) {struct omap_hsmmc_host *host =dev_get_drvdata (dev);
@@ -256,7 +247,7 @@ static int omap_hsmmc_suspend_cdirq(struct device *dev, int slot)struct omap_hsmmc_host *host =dev_get_drvdata (dev);struct omap_mmc_platform_data *mmc = host->pdata; -disable_irq (mmc->slots[0 ].card_detect_irq); +disable_irq (mmc->slots[0 ].cover_detect_irq);return 0 ; }
@@ -265,7 +256,7 @@ static int omap_hsmmc_resume_cdirq(struct device *dev, int slot)struct omap_hsmmc_host *host =dev_get_drvdata (dev);struct omap_mmc_platform_data *mmc = host->pdata; -enable_irq (mmc->slots[0 ].card_detect_irq); +enable_irq (mmc->slots[0 ].cover_detect_irq);return 0 ; }
@@ -458,23 +449,26 @@ static int omap_hsmmc_gpio_init(struct mmc_host *mmc,if (ret)return ret; ret =gpio_direction_input (pdata->slots[0 ].switch_pin); -if (ret) - goto err_free_sp; +if (ret) { +gpio_free (pdata->slots[0 ].switch_pin); +return ret; + } }else { - pdata->slots[0 ].card_detect = omap_hsmmc_card_detect; - pdata->slots[0 ].card_detect_irq = -gpio_to_irq (pdata->slots[0 ].switch_pin); - - ret =gpio_request (pdata->slots[0 ].switch_pin, -"mmc_cd" ); -if (ret) +/* copy & paste from from mmc_of_parse */ + ret =mmc_gpio_request_cd (mmc, + pdata->slots[0 ].switch_pin, +0 ); +if (ret <0 ) { +dev_err (pdata->dev, +"Failed to request CD GPIO #%d: %d!\n" , + pdata->slots[0 ].switch_pin, ret);return ret; - ret =gpio_direction_input (pdata->slots[0 ].switch_pin); -if (ret) - goto err_free_sp; + }else { +dev_info (pdata->dev,"Got CD GPIO #%d.\n" , + pdata->slots[0 ].switch_pin); + } } - }else - pdata->slots[0 ].switch_pin = -EINVAL ; + }if (gpio_is_valid (pdata->slots[0 ].gpio_wp)) {/* copy & paste from from mmc_of_parse */
@@ -492,8 +486,9 @@ static int omap_hsmmc_gpio_init(struct mmc_host *mmc,return 0 ; err: -if (gpio_is_valid (pdata->slots[0 ].switch_pin)) -err_free_sp: +mmc_gpio_free_cd (mmc); +if (gpio_is_valid (pdata->slots[0 ].switch_pin) && + (pdata->slots[0 ].cover))gpio_free (pdata->slots[0 ].switch_pin);return ret; }
@@ -501,8 +496,11 @@ err_free_sp:static void omap_hsmmc_gpio_free (struct mmc_host *mmc,struct omap_mmc_platform_data *pdata) { +mmc_gpio_free_cd (mmc);mmc_gpio_free_ro (mmc); -if (gpio_is_valid (pdata->slots[0 ].switch_pin)) + +if (gpio_is_valid (pdata->slots[0 ].switch_pin) && + (pdata->slots[0 ].cover))gpio_free (pdata->slots[0 ].switch_pin); }
@@ -1289,24 +1287,13 @@ static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)/* * irq handler to notify the core about card insertion/removal */ -static irqreturn_t omap_hsmmc_detect (int irq,void *dev_id) +static irqreturn_t omap_hsmmc_cover_detect (int irq,void *dev_id) {struct omap_hsmmc_host *host = dev_id; -struct omap_mmc_slot_data *slot = &mmc_slot (host); -int carddetect; - -if (slot->card_detect) { - carddetect = slot->card_detect (host->dev, host->slot_id); -if (carddetect) -mmc_detect_change (host->mmc, (HZ *200 ) /1000 ); -else -mmc_detect_change (host->mmc, (HZ *50 ) /1000 ); - }else { -sysfs_notify (&host->mmc->class_dev.kobj,NULL ,"cover_switch" ); -omap_hsmmc_protect_card (host); -mmc_detect_change (host->mmc, (HZ *200 ) /1000 ); - } +sysfs_notify (&host->mmc->class_dev.kobj,NULL ,"cover_switch" ); +omap_hsmmc_protect_card (host); +mmc_detect_change (host->mmc, (HZ *200 ) /1000 );return IRQ_HANDLED ; }
@@ -1669,15 +1656,6 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)pm_runtime_put_autosuspend (host->dev); } -static int omap_hsmmc_get_cd (struct mmc_host *mmc) -{ -struct omap_hsmmc_host *host =mmc_priv (mmc); - -if (!mmc_slot (host).card_detect) -return -ENOSYS ; -return mmc_slot (host).card_detect (host->dev, host->slot_id); -} -static void omap_hsmmc_init_card (struct mmc_host *mmc,struct mmc_card *card) {struct omap_hsmmc_host *host =mmc_priv (mmc);
@@ -1832,7 +1810,7 @@ static const struct mmc_host_ops omap_hsmmc_ops = { .pre_req = omap_hsmmc_pre_req, .request = omap_hsmmc_request, .set_ios = omap_hsmmc_set_ios, - .get_cd = omap_hsmmc_get_cd, + .get_cd = mmc_gpio_get_cd, .get_ro = mmc_gpio_get_ro, .init_card = omap_hsmmc_init_card, .enable_sdio_irq = omap_hsmmc_enable_sdio_irq,
@@ -2228,10 +2206,10 @@ static int omap_hsmmc_probe(struct platform_device *pdev) mmc->ocr_avail =mmc_slot (host).ocr_mask;/* Request IRQ for card detect */ -if ((mmc_slot (host).card_detect_irq)) { +if ((mmc_slot (host).cover_detect_irq)) { ret =devm_request_threaded_irq (&pdev->dev, -mmc_slot (host).card_detect_irq, -NULL , omap_hsmmc_detect, +mmc_slot (host).cover_detect_irq, +NULL , omap_hsmmc_cover_detect,IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING |IRQF_ONESHOT ,mmc_hostname (mmc), host);if (ret) {
@@ -2266,7 +2244,7 @@ static int omap_hsmmc_probe(struct platform_device *pdev)if (ret <0 ) goto err_slot_name; } -if (mmc_slot (host).card_detect_irq &&mmc_slot (host).get_cover_state) { +if (mmc_slot (host).cover_detect_irq &&mmc_slot (host).get_cover_state) { ret =device_create_file (&mmc->class_dev, &dev_attr_cover_switch);if (ret <0 )
include/linux/platform_data/mmc-omap.h +0 -4
@@ -142,10 +142,6 @@ struct omap_mmc_platform_data {const char *name;u32 ocr_mask; -/* Card detection IRQs */ -int card_detect_irq; -int (*card_detect)(struct device *dev,int slot); - unsigned int ban_openended:1; } slots[OMAP_MMC_MAX_SLOTS ];
Signature · 1 line
2.0.0