Re: [PATCH 4/4] staging: dwc2: load parameters from the devicetree

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

 



On 04/11/2013 06:43 PM, Matthijs Kooijman wrote:
> Each of the parameters in the dwc2_core_params struct can now be changed
> using devicetree parameters.
> 
> Signed-off-by: Matthijs Kooijman <matthijs@xxxxxxxx>
> ---
>  Documentation/devicetree/bindings/staging/dwc2.txt |  36 ++++++++
>  drivers/staging/dwc2/platform.c                    | 100 +++++++++++++++++++++
>  2 files changed, 136 insertions(+)
> 
> This just adds all existing parameters to the devicetree for now. It's
> not unlikely that some of these parameters gets dropped later or turn
> out to be unsuitable for setting from the devicetree, but for now I've
> just added them all without closely looking at each.
> 
> diff --git a/Documentation/devicetree/bindings/staging/dwc2.txt b/Documentation/devicetree/bindings/staging/dwc2.txt
> index 3649c88..05d9c08 100644
> --- a/Documentation/devicetree/bindings/staging/dwc2.txt
> +++ b/Documentation/devicetree/bindings/staging/dwc2.txt
> @@ -5,6 +5,39 @@ Required properties:
>  - compatible : "snps,dwc2"
>  - reg : Should contain 1 register range (address and length)
>  - interrupts : Should contain 1 interrupt
> +Optional properties:
> + - dma-enable
> + - otg-cap
> + - otg-ver
> + - dma-enable
> + - dma-desc-enable
> + - speed
> + - enable-dynamic-fifo
> + - en-multiple-tx-fifo
> + - host-rx-fifo-size
> + - host-nperio-tx-fifo-size
> + - host-perio-tx-fifo-size
> + - max-transfer-size
> + - max-packet-count
> + - host-channels
> + - phy-type
> + - phy-utmi-width
> + - phy-ulpi-ddr
> + - phy-ulpi-ext-vbus
> + - i2c-enable
> + - ulpi-fs-ls
> + - host-support-fs-ls-low-power
> + - host-ls-low-power-phy-clk
> + - ts-dline
> + - reload-ctl
> + - ahb-single
> +
> +Each of the above properties take a single cell containing an integer. See
> +struct dwc2_core_params in dwc2/core.h for their meanings and possible values.
> +
> +If absent, these values have either a driver default or are autodetected.
> +Where possible, the values set through the devicetree are checked against
> +hardware limits and automatically capped or adjusted as needed.
>  
>  Example:
>  
> @@ -12,4 +45,7 @@ Example:
>                  compatible = "ralink,rt3050-otg, snps,dwc2";
>                  reg = <0x101c0000 40000>;
>                  interrupts = <18>;
> +
> +		# Force slave mode, even when dma is advertised to work
> +		dma-enable = <0>;
>          };
> diff --git a/drivers/staging/dwc2/platform.c b/drivers/staging/dwc2/platform.c
> index e65fa0d..9e05865 100644
> --- a/drivers/staging/dwc2/platform.c
> +++ b/drivers/staging/dwc2/platform.c
> @@ -40,6 +40,8 @@
>  #include <linux/device.h>
>  #include <linux/dma-mapping.h>
>  #include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <asm/byteorder.h>
>  
>  #include "core.h"
>  #include "hcd.h"
> @@ -69,6 +71,101 @@ static int dwc2_driver_remove(struct platform_device *dev)
>  }
>  
>  /**
> + * dwc2_load_property() - Load a single property from the devicetree
> + * node into the given variable.
> + *
> + * @dev: Platform device
> + * @res: The variable to put the loaded value into
> + * @name: The name of the devicetree property to load
> + */
> +static void dwc2_load_property(struct platform_device *dev, int *res,
> +			       const char *name)
> +{
> +	int len;
> +	const u32 *val;
> +
> +	val = of_get_property(dev->dev.of_node, name, &len);
> +	if (!val)
> +		return;
> +
> +	if (len != sizeof(*val)) {
> +		dev_warn(&dev->dev,
> +			 "Invalid value in devicetree for %s property, should be a single integer\n",
> +			 name);
> +		return;
> +	}
> +
> +	*res = be32_to_cpu(*val);

What about using of_property_read_u32() instead of open coding it here?

> +
> +	dev_dbg(&dev->dev, "Loaded %s parameter from devicetree: %d\n",
> +		name, *res);
> +}

Marc


-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

Attachment: signature.asc
Description: OpenPGP digital signature


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

  Powered by Linux