devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chris Ruehl <chris.ruehl-CR359r9tUDPXPF5Rlphj1Q@public.gmane.org>
To: balbi-l0cyMroinI0@public.gmane.org,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org
Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Chris Ruehl <chris.ruehl-CR359r9tUDPXPF5Rlphj1Q@public.gmane.org>
Subject: [PATCH 1/3] usb: phy-generic: Add GPIO based ChipSelect
Date: Mon,  2 Dec 2013 15:05:17 +0800	[thread overview]
Message-ID: <1385967919-13258-2-git-send-email-chris.ruehl@gtsys.com.hk> (raw)
In-Reply-To: <1385967919-13258-1-git-send-email-chris.ruehl-CR359r9tUDPXPF5Rlphj1Q@public.gmane.org>

usb: phy-generic: Add GPIO based ChipSelect

The ULPI ISP1504 uses the CHIP_SELECT_N (low active) pin to active the
chip. This patch add support for GPIO based ChipSelect almost the same
way implemented for the Reset feature.

Sample DT configuration:
pinctrl_usbphy2: usbphy-2 {
fsl,pins = <
	/* chip select and reset gpio output */
	MX27_PAD_PC_CD1_B__GPIO6_20 0x0
	MX27_PAD_PC_CD2_B__GPIO6_19 0x0
	>;
};

&usbphy2 {
        cs-gpios = <&gpio6 20 1>;
	reset-gpios = <&gpio6 19 1>;
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_usbphy2>;
};

Signed-off-by: Chris Ruehl <chris.ruehl-CR359r9tUDPXPF5Rlphj1Q@public.gmane.org>
---
 drivers/usb/phy/phy-generic.c |   31 +++++++++++++++++++++++++++++++
 drivers/usb/phy/phy-generic.h |    2 ++
 2 files changed, 33 insertions(+)

diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index fce3a9e..ff4d68c 100644
--- a/drivers/usb/phy/phy-generic.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -181,6 +181,24 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
 			return -EPROBE_DEFER;
 	}
 
+	if(gpio_is_valid(nop->gpio_chipselect)) {
+		unsigned long gpio_flags;
+		dev_dbg(dev, "Requesting Chipselect GPIO %d\n",
+				nop->gpio_chipselect);
+		if (nop->cs_active_low)
+			gpio_flags = GPIOF_OUT_INIT_LOW;
+		else
+			gpio_flags = GPIOF_OUT_INIT_HIGH;
+
+		err = devm_gpio_request_one(dev, nop->gpio_chipselect,
+				gpio_flags, dev_name(dev));
+		if (err) {
+			dev_err(dev, "Error requesting Chipselect GPIO %d err=%d\n",
+					nop->gpio_chipselect, err);
+			return err;
+		}
+	}
+
 	if (gpio_is_valid(nop->gpio_reset)) {
 		unsigned long gpio_flags;
 
@@ -231,27 +249,40 @@ static int usb_phy_gen_xceiv_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	nop->reset_active_low = true;	/* default behaviour */
+	nop->cs_active_low = true;
 
 	if (dev->of_node) {
 		struct device_node *node = dev->of_node;
 		enum of_gpio_flags flags;
+		enum of_gpio_flags csflags;
 
 		if (of_property_read_u32(node, "clock-frequency", &clk_rate))
 			clk_rate = 0;
 
 		needs_vcc = of_property_read_bool(node, "vcc-supply");
+
 		nop->gpio_reset = of_get_named_gpio_flags(node, "reset-gpios",
 								0, &flags);
+
 		if (nop->gpio_reset == -EPROBE_DEFER)
 			return -EPROBE_DEFER;
 
 		nop->reset_active_low = flags & OF_GPIO_ACTIVE_LOW;
 
+		nop->gpio_chipselect = of_get_named_gpio_flags(node, "cs-gpios",
+								0, &csflags);
+		if (gpio_is_valid(nop->gpio_chipselect))
+			nop->cs_active_low = csflags & OF_GPIO_ACTIVE_LOW;
+
 	} else if (pdata) {
 		type = pdata->type;
 		clk_rate = pdata->clk_rate;
 		needs_vcc = pdata->needs_vcc;
 		nop->gpio_reset = pdata->gpio_reset;
+		nop->gpio_chipselect = pdata->gpio_chipselect;
+	} else {
+		nop->gpio_reset = -1;
+		nop->gpio_chipselect = -1;
 	}
 
 	err = usb_phy_gen_create_phy(dev, nop, type, clk_rate, needs_vcc);
diff --git a/drivers/usb/phy/phy-generic.h b/drivers/usb/phy/phy-generic.h
index d2a220d..97eafc2 100644
--- a/drivers/usb/phy/phy-generic.h
+++ b/drivers/usb/phy/phy-generic.h
@@ -7,7 +7,9 @@ struct usb_phy_gen_xceiv {
 	struct clk *clk;
 	struct regulator *vcc;
 	int gpio_reset;
+	int gpio_chipselect;
 	bool reset_active_low;
+	bool cs_active_low;
 };
 
 int usb_gen_phy_init(struct usb_phy *phy);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2013-12-02  7:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-02  7:05 [PATCH] usb: phy-generic, phy-ulpi patch set Chris Ruehl
     [not found] ` <1385967919-13258-1-git-send-email-chris.ruehl-CR359r9tUDPXPF5Rlphj1Q@public.gmane.org>
2013-12-02  7:05   ` Chris Ruehl [this message]
     [not found]     ` <1385967919-13258-2-git-send-email-chris.ruehl-CR359r9tUDPXPF5Rlphj1Q@public.gmane.org>
2013-12-06 20:24       ` [PATCH 1/3] usb: phy-generic: Add GPIO based ChipSelect Felipe Balbi
     [not found]         ` <20131206202453.GF21086-HgARHv6XitL9zxVx7UNMDg@public.gmane.org>
2013-12-09  1:45           ` Chris Ruehl
2013-12-09  4:07             ` Felipe Balbi
     [not found]               ` <20131209040705.GB20608-HgARHv6XitL9zxVx7UNMDg@public.gmane.org>
2013-12-09  4:11                 ` Chris Ruehl
2013-12-02  7:05   ` [PATCH 2/3] usb: phy-ulpi: Add EXTVBUSIND,CHRGVBUS flag support Chris Ruehl
2013-12-02 18:59     ` Sergei Shtylyov
2013-12-02  7:05 ` [PATCH 3/3] usb: phy-generic: Add ULPI VBUS support Chris Ruehl
     [not found]   ` <1385967919-13258-4-git-send-email-chris.ruehl-CR359r9tUDPXPF5Rlphj1Q@public.gmane.org>
2013-12-02 18:22     ` Mark Rutland
     [not found]       ` <20131202182204.GQ12952-NuALmloUBlrZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2013-12-03  2:46         ` Chris Ruehl
2013-12-03  5:24       ` Chris Ruehl
2013-12-03  8:15   ` Heikki Krogerus
2013-12-04  7:16     ` Chris Ruehl
     [not found]       ` <529ED6C5.3000608-CR359r9tUDPXPF5Rlphj1Q@public.gmane.org>
2013-12-04  9:49         ` Heikki Krogerus
2013-12-05  4:15           ` Chris Ruehl

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=1385967919-13258-2-git-send-email-chris.ruehl@gtsys.com.hk \
    --to=chris.ruehl-cr359r9tudpxpf5rlphj1q@public.gmane.org \
    --cc=balbi-l0cyMroinI0@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /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).