Re: [PATCH v1 07/20] usb: dwc2: set parameter values in probe function

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

 



On 3/17/2015 2:54 AM, Mian Yousaf Kaukab wrote:
> So the parameters can be used in both host and gadget modes.
> Also consolidate param functions in the core.h
> 
> Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@xxxxxxxxx>
> ---
>  drivers/usb/dwc2/core.c     | 19 +++++++++++++++++++
>  drivers/usb/dwc2/core.h     | 13 ++++++++++---
>  drivers/usb/dwc2/hcd.c      | 34 +---------------------------------
>  drivers/usb/dwc2/hcd.h      |  7 +------
>  drivers/usb/dwc2/platform.c | 17 ++++++++++++++++-
>  5 files changed, 47 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
> index e8e389f..a1eeebb 100644
> --- a/drivers/usb/dwc2/core.c
> +++ b/drivers/usb/dwc2/core.c
> @@ -3049,6 +3049,7 @@ void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
>  	dwc2_set_param_uframe_sched(hsotg, params->uframe_sched);
>  	dwc2_set_param_external_id_pin_ctl(hsotg, params->external_id_pin_ctl);
>  }
> +EXPORT_SYMBOL_GPL(dwc2_set_parameters);
>  
>  /**
>   * During device initialization, read various hardware configuration
> @@ -3215,6 +3216,24 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
>  
>  	return 0;
>  }
> +EXPORT_SYMBOL_GPL(dwc2_get_hwparams);
> +
> +/*
> + * Sets all parameters to the given value.
> + *
> + * Assumes that the dwc2_core_params struct contains only integers.
> + */
> +void dwc2_set_all_params(struct dwc2_core_params *params, int value)
> +{
> +	int *p = (int *)params;
> +	size_t size = sizeof(*params) / sizeof(*p);
> +	int i;
> +
> +	for (i = 0; i < size; i++)
> +		p[i] = value;
> +}
> +EXPORT_SYMBOL_GPL(dwc2_set_all_params);
> +
>  
>  u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg)
>  {
> diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
> index e46304d..d7fb1f7 100644
> --- a/drivers/usb/dwc2/core.h
> +++ b/drivers/usb/dwc2/core.h
> @@ -1071,6 +1071,15 @@ extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
>  
>  extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
>  
> +extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
> +				const struct dwc2_core_params *params);
> +
> +extern void dwc2_set_all_params(struct dwc2_core_params *params, int value);
> +
> +extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
> +
> +
> +
>  /*
>   * Dump core registers and SPRAM
>   */
> @@ -1119,14 +1128,12 @@ extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
>  extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
>  extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
>  #else
> -static inline void dwc2_set_all_params(struct dwc2_core_params *params, int value) {}
>  static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
>  { return 0; }
>  static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {}
>  static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
>  static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
> -static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
> -				const struct dwc2_core_params *params)
> +static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
>  { return 0; }
>  #endif
>  
> diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
> index c78c874..a387e9f 100644
> --- a/drivers/usb/dwc2/hcd.c
> +++ b/drivers/usb/dwc2/hcd.c
> @@ -2754,29 +2754,12 @@ static void dwc2_hcd_release(struct dwc2_hsotg *hsotg)
>  }
>  
>  /*
> - * Sets all parameters to the given value.
> - *
> - * Assumes that the dwc2_core_params struct contains only integers.
> - */
> -void dwc2_set_all_params(struct dwc2_core_params *params, int value)
> -{
> -	int *p = (int *)params;
> -	size_t size = sizeof(*params) / sizeof(*p);
> -	int i;
> -
> -	for (i = 0; i < size; i++)
> -		p[i] = value;
> -}
> -EXPORT_SYMBOL_GPL(dwc2_set_all_params);
> -
> -/*
>   * Initializes the HCD. This function allocates memory for and initializes the
>   * static parts of the usb_hcd and dwc2_hsotg structures. It also registers the
>   * USB bus with the core and calls the hc_driver->start() function. It returns
>   * a negative error on failure.
>   */
> -int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
> -		  const struct dwc2_core_params *params)
> +int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
>  {
>  	struct usb_hcd *hcd;
>  	struct dwc2_host_chan *channel;
> @@ -2789,12 +2772,6 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
>  
>  	dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n");
>  
> -	/* Detect config values from hardware */
> -	retval = dwc2_get_hwparams(hsotg);
> -
> -	if (retval)
> -		return retval;
> -
>  	retval = -ENOMEM;
>  
>  	hcfg = readl(hsotg->regs + HCFG);
> @@ -2813,15 +2790,6 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
>  	hsotg->last_frame_num = HFNUM_MAX_FRNUM;
>  #endif
>  
> -	hsotg->core_params = kzalloc(sizeof(*hsotg->core_params), GFP_KERNEL);
> -	if (!hsotg->core_params)
> -		goto error1;
> -
> -	dwc2_set_all_params(hsotg->core_params, -1);
> -
> -	/* Validate parameter values */
> -	dwc2_set_parameters(hsotg, params);
> -
>  	/* Check if the bus driver or platform code has setup a dma_mask */
>  	if (hsotg->core_params->dma_enable > 0 &&
>  	    hsotg->dev->dma_mask == NULL) {
> diff --git a/drivers/usb/dwc2/hcd.h b/drivers/usb/dwc2/hcd.h
> index e69a843..7b5841c 100644
> --- a/drivers/usb/dwc2/hcd.h
> +++ b/drivers/usb/dwc2/hcd.h
> @@ -451,13 +451,8 @@ static inline u8 dwc2_hcd_is_pipe_out(struct dwc2_hcd_pipe_info *pipe)
>  	return !dwc2_hcd_is_pipe_in(pipe);
>  }
>  
> -extern int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
> -			 const struct dwc2_core_params *params);
> +extern int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq);
>  extern void dwc2_hcd_remove(struct dwc2_hsotg *hsotg);
> -extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
> -				const struct dwc2_core_params *params);
> -extern void dwc2_set_all_params(struct dwc2_core_params *params, int value);
> -extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
>  
>  /* Transaction Execution Functions */
>  extern enum dwc2_transaction_type dwc2_hcd_select_transactions(
> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index ce39e8a0..2562c90 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -241,6 +241,21 @@ static int dwc2_driver_probe(struct platform_device *dev)
>  	spin_lock_init(&hsotg->lock);
>  	mutex_init(&hsotg->init_mutex);
>  
> +	/* Detect config values from hardware */
> +	retval = dwc2_get_hwparams(hsotg);
> +	if (retval)
> +		return retval;
> +
> +	hsotg->core_params = devm_kzalloc(&dev->dev,
> +				sizeof(*hsotg->core_params), GFP_KERNEL);

Since you initialize this here, you don't need to free it in
dwc2_hcd_free(). This causes crash when you unload the module.

John


--
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