Re: [PATCH 2/5] usb: musb: core: added helper functions for parsing DT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Fri, Feb 12, 2016 at 03:58:40PM +0100, Petr Kulhavy wrote:
> This adds two functions to get DT properties "mentor,power" and "dr_mode":
> musb_get_power() and musb_mode musb_get_mode()

Please add revision # in the [PATCH...] prefix in subject.

> 
> Signed-off-by: Petr Kulhavy <petr@xxxxxxxxx>
> ---
>  drivers/usb/musb/musb_core.c | 37 +++++++++++++++++++++++++++++++++++++
>  drivers/usb/musb/musb_core.h | 20 ++++++++++++++++++++
>  2 files changed, 57 insertions(+)
> 
> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
> index c3791a0..0836375 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:
> +		return MUSB_OTG;
> +	default:
> +		return MUSB_UNDEFINED;

return MUSB_OTG in non-HOST or non-PERIPHERAL case. I am wondering if
MUSB_UNDEFINED will cause regression if dr_mode is not defined in DT.

	case USB_DR_MODE_UNKNOWN:
	case USB_DR_MODE_OTG:
	default:
		return MUSB_OTG;

Regards,
-Bin.

> +	}
> +}
> +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..89d6290 100644
> --- a/drivers/usb/musb/musb_core.h
> +++ b/drivers/usb/musb/musb_core.h
> @@ -614,4 +614,24 @@ 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 returns MUSB_UNDEFINED
> + */
> +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);
> +#else
> +static inline u8 musb_get_power(struct device *dev)
> +{
> +	return 0;
> +}
> +#endif
> +
>  #endif	/* __MUSB_CORE_H__ */
> -- 
> 1.9.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux