devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Kishon Vijay Abraham I <kishon@ti.com>
Cc: "rob.herring@calxeda.com" <rob.herring@calxeda.com>,
	"rob@landley.net" <rob@landley.net>,
	"tony@atomide.com" <tony@atomide.com>,
	"balbi@ti.com" <balbi@ti.com>,
	"b-cousson@ti.com" <b-cousson@ti.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-omap@vger.kernel.org" <linux-omap@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"devicetree-discuss@lists.ozlabs.org"
	<devicetree-discuss@lists.ozlabs.org>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux@arm.linux.org.uk" <linux@arm.linux.org.uk>
Subject: Re: [PATCH v4 1/4] drivers: usb: phy: add a new driver for usb part of control module
Date: Fri, 25 Jan 2013 11:01:41 +0000	[thread overview]
Message-ID: <20130125110141.GK3075@e106331-lin.cambridge.arm.com> (raw)
In-Reply-To: <1359109440-2195-2-git-send-email-kishon@ti.com>

On Fri, Jan 25, 2013 at 10:23:57AM +0000, Kishon Vijay Abraham I wrote:
> Added a new driver for the usb part of control module. This has an API
> to power on the USB2 phy and an API to write to the mailbox depending on
> whether MUSB has to act in host mode or in device mode.
> 
> Writing to control module registers for doing the above task which was
> previously done in omap glue and in omap-usb2 phy will be removed.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  Documentation/devicetree/bindings/usb/omap-usb.txt |   30 +-
>  Documentation/devicetree/bindings/usb/usb-phy.txt  |    5 +
>  drivers/usb/phy/Kconfig                            |   10 +
>  drivers/usb/phy/Makefile                           |    1 +
>  drivers/usb/phy/omap-control-usb.c                 |  295 ++++++++++++++++++++
>  include/linux/usb/omap_control_usb.h               |   92 ++++++
>  6 files changed, 432 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/usb/phy/omap-control-usb.c
>  create mode 100644 include/linux/usb/omap_control_usb.h
> 
> diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt
> index 29a043e..2d8c6c4 100644
> --- a/Documentation/devicetree/bindings/usb/omap-usb.txt
> +++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
> @@ -1,4 +1,4 @@
> -OMAP GLUE
> +OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS
> 
>  OMAP MUSB GLUE
>   - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"
> @@ -16,6 +16,10 @@ OMAP MUSB GLUE
>   - power : Should be "50". This signifies the controller can supply upto
>     100mA when operating in host mode.
> 
> +Optional properties:
> + - ctrl-module : phandle of the control module this glue uses to write to
> +   mailbox
> +
>  SOC specific device node entry
>  usb_otg_hs: usb_otg_hs@4a0ab000 {
>         compatible = "ti,omap4-musb";
> @@ -23,6 +27,7 @@ usb_otg_hs: usb_otg_hs@4a0ab000 {
>         multipoint = <1>;
>         num_eps = <16>;
>         ram_bits = <12>;
> +       ctrl-module = <&omap_control_usb>;
>  };
> 
>  Board specific device node entry
> @@ -31,3 +36,26 @@ Board specific device node entry
>         mode = <3>;
>         power = <50>;
>  };
> +
> +OMAP CONTROL USB
> +
> +Required properties:
> + - compatible: Should be "ti,omap-control-usb"
> + - reg : Address and length of the register set for the device. It contains
> +   the address of "control_dev_conf" and "otghs_control" or "phy_power_usb"

Could you not use '-' over '_' here?

> +   depending upon omap4 or omap5.
> + - reg-names: The names of the register addresses corresponding to the registers
> +   filled in "reg".
> + - ti,type: This is used to differentiate whether the control module has
> +   usb mailbox or usb3 phy power. omap4 has usb mailbox in control module to
> +   notify events to the musb core and omap5 has usb3 phy power register to
> +   power on usb3 phy. Should be "1" if it has mailbox and "2" if it has usb3
> +   phy power.

Why not make this a string property, perhaps values "mailbox" or "register"?

That way it's easy for humans and code to verify the dts, and easy to expand
arbitrarily in future if necessary. It also means you're not leaking
kernel-side constants as an ABI.

> +
> +omap_control_usb: omap-control-usb@4a002300 {
> +       compatible = "ti,omap-control-usb";
> +       reg = <0x4a002300 0x4>,
> +             <0x4a00233c 0x4>;
> +       reg-names = "control_dev_conf", "otghs_control";
> +       ti,type = <1>;
> +};

[...]

> +static int omap_control_usb_probe(struct platform_device *pdev)
> +{
> +       struct resource *res;
> +       struct device_node *np = pdev->dev.of_node;
> +       struct omap_control_usb_platform_data *pdata = pdev->dev.platform_data;
> +
> +       control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb),
> +               GFP_KERNEL);
> +       if (!control_usb) {
> +               dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
> +               return -ENOMEM;
> +       }
> +
> +       if (np) {
> +               of_property_read_u32(np, "ti,type", &control_usb->type);
> +       } else if (pdata) {
> +               control_usb->type = pdata->type;
> +       } else {
> +               dev_err(&pdev->dev, "no pdata present\n");
> +               return -EINVAL;
> +       }

Please do some sanity checking here on type. What if it's not
OMAP_CTRL_DEV_TYPE1 or OMAP_CTRL_DEV_TYPE2?

What if the values for OMAP_CTRL_DEV_TYPE{1,2} change? The binding will be
broken.

If you change ti,type to a string, the parsing also becomes sanity checking:

if (np) {
	char *type;
	if (of_property_read_string(np, "ti,type", &type) != 0)
		return -EINVAL;

	if (strcmp(type, "mailbox") == 0)
		control_usb->type = OMAP_CTRL_DEV_TYPE1;
	else if (strcmp(type, "register") == 0)
		control_usb->type = OMAP_CTRL_DEV_TYPE2;
	else
		return -EINVAL;
} else {
	... pdata case ...
}

Also, TYPE1 and TYPE2 aren't very descriptive. These could probably be better
named.

> +
> +       control_usb->dev        = &pdev->dev;
> +
> +       res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
> +               "control_dev_conf");
> +       control_usb->dev_conf = devm_request_and_ioremap(&pdev->dev, res);
> +       if (!control_usb->dev_conf) {
> +               dev_err(&pdev->dev, "Failed to obtain io memory\n");
> +               return -EADDRNOTAVAIL;
> +       }
> +
> +       if (control_usb->type == OMAP_CTRL_DEV_TYPE1) {
> +               res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
> +                       "otghs_control");
> +               control_usb->otghs_control = devm_request_and_ioremap(
> +                       &pdev->dev, res);
> +               if (!control_usb->otghs_control) {
> +                       dev_err(&pdev->dev, "Failed to obtain io memory\n");
> +                       return -EADDRNOTAVAIL;
> +               }
> +       }
> +
> +       if (control_usb->type == OMAP_CTRL_DEV_TYPE2) {
> +               res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
> +                       "phy_power_usb");
> +               control_usb->phy_power = devm_request_and_ioremap(
> +                       &pdev->dev, res);
> +               if (!control_usb->phy_power) {
> +                       dev_dbg(&pdev->dev, "Failed to obtain io memory\n");
> +                       return -EADDRNOTAVAIL;
> +               }
> +
> +               control_usb->sys_clk = devm_clk_get(control_usb->dev,
> +                       "sys_clkin");
> +               if (IS_ERR(control_usb->sys_clk)) {
> +                       pr_err("%s: unable to get sys_clkin\n", __func__);
> +                       return -EINVAL;
> +               }
> +       }
> +
> +
> +       dev_set_drvdata(control_usb->dev, control_usb);
> +
> +       return 0;
> +}

[...]

Thanks,
Mark.


  reply	other threads:[~2013-01-25 11:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-25 10:23 [PATCH v4 0/4] usb: musb/dwc3: add driver for control module Kishon Vijay Abraham I
2013-01-25 10:23 ` [PATCH v4 1/4] drivers: usb: phy: add a new driver for usb part of " Kishon Vijay Abraham I
2013-01-25 11:01   ` Mark Rutland [this message]
2013-01-25 11:11     ` Felipe Balbi
2013-01-25 12:29       ` Mark Rutland
2013-01-25 14:59         ` Felipe Balbi
2013-01-25 16:14           ` Mark Rutland
2013-01-25 16:23             ` Felipe Balbi
2013-01-25 17:08               ` Mark Rutland
2013-01-25 10:23 ` [PATCH v4 2/4] ARM: OMAP: devices: create device " Kishon Vijay Abraham I
     [not found] ` <1359109440-2195-1-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2013-01-25 10:23   ` [PATCH v4 3/4] ARM: OMAP2: MUSB: Specify omap4 has mailbox Kishon Vijay Abraham I
2013-01-25 10:24   ` [PATCH v4 4/4] drivers: usb: start using the control module driver Kishon Vijay Abraham I
     [not found]     ` <1359109440-2195-5-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2013-01-25 10:27       ` Felipe Balbi
     [not found]         ` <20130125102700.GO15886-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2013-01-25 11:45           ` kishon
2013-02-01 19:14         ` Tony Lindgren
     [not found]           ` <20130201191424.GQ22517-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2013-02-04 15:53             ` Felipe Balbi
2013-02-04 17:22               ` Tony Lindgren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130125110141.GK3075@e106331-lin.cambridge.arm.com \
    --to=mark.rutland@arm.com \
    --cc=b-cousson@ti.com \
    --cc=balbi@ti.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kishon@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).