mmc: add helpers mmc_regulator_set_ocr_vmmc_up/off
Subsystems (2)
cover mmc: add helpers mmc_regulator_set_ocr_vmmc_up/off
A lot of drivers use this code, therefore let's factor it out to helpers.
Heiner Kallweit (2):
mmc: core: add helpers mmc_regulator_set_ocr_vmmc_up/off
mmc: meson-gx: use new helpers mmc_regulator_set_ocr_vmmc_off/up
drivers/mmc/host/meson-gx-mmc.c | 6 ++---- include/linux/mmc/host.h | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-)
Signature · 1 line
2.39.1
PATCH 1/2 mmc: core: add helpers mmc_regulator_set_ocr_vmmc_up/off
A lot of drivers use this code, therefore let's factor it out to helpers.
--- include/linux/mmc/host.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
include/linux/mmc/host.h +17 -0
@@ -597,6 +597,23 @@ static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, }#endif +static inline int mmc_regulator_set_ocr_vmmc_up (struct mmc_host *mmc, +struct mmc_ios *ios) +{ +if (IS_ERR (mmc->supply.vmmc)) +return 0 ; + +return mmc_regulator_set_ocr (mmc, mmc->supply.vmmc, ios->vdd); +} + +static inline int mmc_regulator_set_ocr_vmmc_off (struct mmc_host *mmc) +{ +if (IS_ERR (mmc->supply.vmmc)) +return 0 ; + +return mmc_regulator_set_ocr (mmc, mmc->supply.vmmc,0 ); +} +int mmc_regulator_get_supply (struct mmc_host *mmc);static inline int mmc_card_is_removable (struct mmc_host *host)
Signature · 1 line
2.39.1
Re: [PATCH 1/2] mmc: core: add helpers mmc_regulator_set_ocr_vmmc_up/off
Quoted 14 lines · Heiner Kallweit
A lot of drivers use this code, therefore let's factor it out to helpers.
Signed-off-by Heiner Kallweit <[email protected]>--- include/linux/mmc/host.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)include/linux/mmc/host.h +0
-0
include/linux/mmc/host.h static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, · line 604
Quoted 8 lines
include/linux/mmc/host.h +5
-0@@ -597,6 +597,23 @@ static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, }#endif +static inline int mmc_regulator_set_ocr_vmmc_up (struct mmc_host *mmc, +struct mmc_ios *ios) +{ +if (IS_ERR (mmc->supply.vmmc)) +return 0 ;
Rather than adding these two new helper functions, how about adding the similar check in mmc_regulator_set_ocr() instead?
That should allow us to simplify some code in the host drivers too, right?
Quoted 16 lines
include/linux/mmc/host.h +12
-1+ +return mmc_regulator_set_ocr (mmc, mmc->supply.vmmc, ios->vdd); +} + +static inline int mmc_regulator_set_ocr_vmmc_off (struct mmc_host *mmc) +{ +if (IS_ERR (mmc->supply.vmmc)) +return 0 ; + +return mmc_regulator_set_ocr (mmc, mmc->supply.vmmc,0 ); +} +int mmc_regulator_get_supply (struct mmc_host *mmc);static inline int mmc_card_is_removable (struct mmc_host *host) --
Quoted 3 lines
2.39.1
Kind regards
Uffe
_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Re: [PATCH 1/2] mmc: core: add helpers mmc_regulator_set_ocr_vmmc_up/off
Quoted 18 lines · Ulf Hansson
Quoted 17 lines · Heiner Kallweit
A lot of drivers use this code, therefore let's factor it out to helpers.
Signed-off-by Heiner Kallweit <[email protected]>--- include/linux/mmc/host.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)include/linux/mmc/host.h +0
-0@@ -597,6 +597,23 @@ static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, }#endif
Quoted 9 lines
include/linux/mmc/host.h static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, · line 604
Quoted 5 lines
include/linux/mmc/host.h +5
-0+static inline int mmc_regulator_set_ocr_vmmc_up (struct mmc_host *mmc, +struct mmc_ios *ios) +{ +if (IS_ERR (mmc->supply.vmmc)) +return 0 ;Rather than adding these two new helper functions, how about adding the similar check in
mmc_regulator_set_ocr()instead?
There's a number of drivers having 3 paths here:
1. IS_ERR() is true -> do nothing and go one
2. mmc_regulator_set_ocr() returns 0 -> some action and go on
3. mmc_regulator_set_ocr() returns an error -> bail out
So the question is: what should mmc_regulator_set_ocr_vmmc_up return if IS_ERR() is true:
1. An errno? Then this errno would have to be different from the error codes the function can normally return.
2. A positive value? Seems to be the best option
Then we could write:
ret = mmc_regulator_set_ocr()
if (ret < 0)
return ret;
if (!ret) {
some_action();
}...
Works but I'm not sure whether it's very intuitive.
The other benefit of the proposed helpers is that they hide the complexity of using mmc->supply.vmmc and ios->vdd.
Mileage may vary here. Do you have any preference?
Quoted 24 lines
That should allow us to simplify some code in the host drivers too, right?
Quoted 16 lines
include/linux/mmc/host.h +12
-1+ +return mmc_regulator_set_ocr (mmc, mmc->supply.vmmc, ios->vdd); +} + +static inline int mmc_regulator_set_ocr_vmmc_off (struct mmc_host *mmc) +{ +if (IS_ERR (mmc->supply.vmmc)) +return 0 ; + +return mmc_regulator_set_ocr (mmc, mmc->supply.vmmc,0 ); +} +int mmc_regulator_get_supply (struct mmc_host *mmc);static inline int mmc_card_is_removable (struct mmc_host *host) --Quoted 3 lines
2.39.1
Kind regards
Uffe
Re: [PATCH 1/2] mmc: core: add helpers mmc_regulator_set_ocr_vmmc_up/off
Quoted 29 lines · Heiner Kallweit
Quoted 18 lines · Ulf Hansson
Quoted 17 lines · Heiner Kallweit
A lot of drivers use this code, therefore let's factor it out to helpers.
Signed-off-by Heiner Kallweit <[email protected]>--- include/linux/mmc/host.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)include/linux/mmc/host.h +0
-0@@ -597,6 +597,23 @@ static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, }#endif Quoted 9 lines
include/linux/mmc/host.h static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, · line 604
Quoted 5 lines
include/linux/mmc/host.h +5
-0+static inline int mmc_regulator_set_ocr_vmmc_up (struct mmc_host *mmc, +struct mmc_ios *ios) +{ +if (IS_ERR (mmc->supply.vmmc)) +return 0 ;Rather than adding these two new helper functions, how about adding the similar check in
mmc_regulator_set_ocr()instead?
Quoted 4 lines
There's a number of drivers having 3 paths here:
1.IS_ERR()is true -> do nothing and go one
2.mmc_regulator_set_ocr()returns 0 -> some action and go on
3.mmc_regulator_set_ocr()returns an error -> bail out
Right, thanks for pointing this out.
The important point I am trying to make is that the mmc core is treating "mmc->supply.vmmc" as optional (see mmc_regulator_get_supply()). To be consistent with that behaviour, I think it would make sense to bail out and return 0, in mmc_regulator_set_ocr() "if (IS_ERR(mmc->supply.vmmc))". We don't need a new set of helper functions to do that.
Quoted 15 lines
So the question is: what should
mmc_regulator_set_ocr_vmmc_upreturn ifIS_ERR()is true:
1. An errno? Then this errno would have to be different from the error codes the function can normally return.
2. A positive value? Seems to be the best optionThen we could write:
ret =
mmc_regulator_set_ocr()
if (ret < 0)return ret; if (!ret) { some_action(); }
Quoted 8 lines
...
Works but I'm not sure whether it's very intuitive.
The other benefit of the proposed helpers is that they hide the complexity of using
mmc->supply.vmmcandios->vdd.Mileage may vary here. Do you have any preference?
Actually, there is no complexity. Drivers should always be able to pass 'ios->vdd' to mmc_regulator_set_ocr() (as it holds the correct value).
For some reasons, some driver authors seem to find it clearer (I guess) to call mmc_regulator_set_ocr() with an explicit '0' at MMC_POWER_OFF, but it isn't needed (see mmc_power_off()).
[...]
Kind regards
Uffe
Re: [PATCH 1/2] mmc: core: add helpers mmc_regulator_set_ocr_vmmc_up/off
Quoted 35 lines · Ulf Hansson
Quoted 29 lines · Heiner Kallweit
Quoted 18 lines · Ulf Hansson
Quoted 17 lines · Heiner Kallweit
A lot of drivers use this code, therefore let's factor it out to helpers.
Signed-off-by Heiner Kallweit <[email protected]>--- include/linux/mmc/host.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)include/linux/mmc/host.h +0
-0@@ -597,6 +597,23 @@ static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, }#endif Quoted 9 lines
include/linux/mmc/host.h static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, · line 604
Quoted 5 lines
include/linux/mmc/host.h +5
-0+static inline int mmc_regulator_set_ocr_vmmc_up (struct mmc_host *mmc, +struct mmc_ios *ios) +{ +if (IS_ERR (mmc->supply.vmmc)) +return 0 ;Rather than adding these two new helper functions, how about adding the similar check in
mmc_regulator_set_ocr()instead?Quoted 4 lines
There's a number of drivers having 3 paths here:
1.IS_ERR()is true -> do nothing and go one
2.mmc_regulator_set_ocr()returns 0 -> some action and go on
3.mmc_regulator_set_ocr()returns an error -> bail out
Quoted 9 lines
Right, thanks for pointing this out.
The important point I am trying to make is that the mmc core is treating "
mmc->supply.vmmc" as optional (seemmc_regulator_get_supply()). To be consistent with that behaviour, I think it would make sense to bail out and return 0, inmmc_regulator_set_ocr()"if (IS_ERR(mmc->supply.vmmc))". We don't need a new set of helper functions to do that.
You're right. I'll submit a patch for it.
Quoted 36 lines
Quoted 15 lines
So the question is: what should
mmc_regulator_set_ocr_vmmc_upreturn ifIS_ERR()is true:
1. An errno? Then this errno would have to be different from the error codes the function can normally return.
2. A positive value? Seems to be the best optionThen we could write:
ret =
mmc_regulator_set_ocr()
if (ret < 0)return ret; if (!ret) { some_action(); }Quoted 8 lines
...
Works but I'm not sure whether it's very intuitive.
The other benefit of the proposed helpers is that they hide the complexity of using
mmc->supply.vmmcandios->vdd.Mileage may vary here. Do you have any preference?
Actually, there is no complexity. Drivers should always be able to pass '
ios->vdd' tommc_regulator_set_ocr()(as it holds the correct value).For some reasons, some driver authors seem to find it clearer (I guess) to call
mmc_regulator_set_ocr()with an explicit '0' atMMC_POWER_OFF, but it isn't needed (seemmc_power_off()).[...]
Kind regards
Uffe
PATCH 2/2 mmc: meson-gx: use new helpers mmc_regulator_set_ocr_vmmc_off/up
In reply to Heiner KallweitMake use of the new helpers to simplify the code.
--- drivers/mmc/host/meson-gx-mmc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/mmc/host/meson-gx-mmc.c +2 -4
@@ -604,8 +604,7 @@ static void meson_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)*/ switch (ios->power_mode) {case MMC_POWER_OFF : -if (!IS_ERR (mmc->supply.vmmc)) -mmc_regulator_set_ocr (mmc, mmc->supply.vmmc,0 ); +mmc_regulator_set_ocr_vmmc_off (mmc);if (!IS_ERR (mmc->supply.vqmmc) && host->vqmmc_enabled) {regulator_disable (mmc->supply.vqmmc);
@@ -615,8 +614,7 @@ static void meson_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)break ;case MMC_POWER_UP : -if (!IS_ERR (mmc->supply.vmmc)) -mmc_regulator_set_ocr (mmc, mmc->supply.vmmc, ios->vdd); +mmc_regulator_set_ocr_vmmc_up (mmc, ios);break ;
Signature · 1 line
2.39.1