Hi, Petr Kulhavy <[email protected]> writes: > This adds two functions to get DT properties "mentor,power" and "dr_mode": > musb_get_power() and musb_get_mode() > > Signed-off-by: Petr Kulhavy <[email protected]>
Bin, is this okay for you ?
> ---
> v4: <initial>
> - created musb_get_dr_mode()
>
> v5:
> - musb_get_dr_mode() renamed to musb_get_mode()
> - added musb_get_power()
>
> v6:
> - musb_get_power() : added missing boundary check for the maximum value 510mA
> - formatting
> - added empty implementation of musb_get_power()
>
> v7:
> - removed empty implementation of musb_get_power()
> - musb_get_mode() returns MUSB_OTG if the property is not found
>
> drivers/usb/musb/musb_core.c | 37 +++++++++++++++++++++++++++++++++++++
> drivers/usb/musb/musb_core.h | 15 +++++++++++++++
> 2 files changed, 52 insertions(+)
>
> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
> index c3791a0..ff7f5d0 100644
> --- a/drivers/usb/musb/musb_core.c
> +++ b/drivers/usb/musb/musb_core.c
> @@ -100,6 +100,7 @@
> #include <linux/io.h>
> #include <linux/dma-mapping.h>
> #include <linux/usb.h>
> +#include <linux/usb/of.h>
>
> #include "musb_core.h"
>
> @@ -129,6 +130,42 @@ static inline struct musb *dev_to_musb(struct device
> *dev)
> return dev_get_drvdata(dev);
> }
>
> +enum musb_mode musb_get_mode(struct device *dev)
> +{
> + enum usb_dr_mode mode;
> +
> + mode = usb_get_dr_mode(dev);
> + switch (mode) {
> + case USB_DR_MODE_HOST:
> + return MUSB_HOST;
> + case USB_DR_MODE_PERIPHERAL:
> + return MUSB_PERIPHERAL;
> + case USB_DR_MODE_OTG:
> + case USB_DR_MODE_UNKNOWN:
> + default:
> + return MUSB_OTG;
> + }
> +}
> +EXPORT_SYMBOL_GPL(musb_get_mode);
> +
> +#ifdef CONFIG_OF
> +u8 musb_get_power(struct device *dev)
> +{
> + int ret;
> + unsigned power_ma;
> +
> + /* the "mentor,power" value is in milliamperes, whereas
> + * the mentor configuration is in 2mA units
> + */
> + ret = of_property_read_u32(dev->of_node, "mentor,power", &power_ma);
> + if (ret)
> + return 0;
> +
> + return power_ma > 510 ? 255 : power_ma / 2;
> +}
> +EXPORT_SYMBOL_GPL(musb_get_power);
> +#endif
> +
> /*-------------------------------------------------------------------------*/
>
> #ifndef CONFIG_BLACKFIN
> diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
> index fd215fb..c2ee702 100644
> --- a/drivers/usb/musb/musb_core.h
> +++ b/drivers/usb/musb/musb_core.h
> @@ -614,4 +614,19 @@ static inline void
> musb_platform_post_root_reset_end(struct musb *musb)
> musb->ops->post_root_reset_end(musb);
> }
>
> +/* gets the "dr_mode" property from DT and converts it into musb_mode
> + * if the property is not found or not recognized returns MUSB_OTG
> + */
> +extern enum musb_mode musb_get_mode(struct device *dev);
> +
> +#if IS_ENABLED(CONFIG_OF)
> +/* gets the "mentor,power" property from DT
> + * and converts it from mA to 2mA units for the "power" parameter
> + * in struct musb_hdrc_platform_data
> + *
> + * in case the property is not found returns 0
> + */
> +extern u8 musb_get_power(struct device *dev);
> +#endif
> +
> #endif /* __MUSB_CORE_H__ */
> --
> 1.9.1
>
--
balbi
signature.asc
Description: PGP signature
