diff mbox

[v8,06/22] mfd: omap-usb-tll: introduce and use mode_needs_tll()

Message ID 1358511445-26656-7-git-send-email-rogerq@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roger Quadros Jan. 18, 2013, 12:17 p.m. UTC
This is a handy macro to check if the port requires the
USB TLL module or not. Use it to Enable the TLL module and manage
the clocks.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Felipe Balbi <balbi@ti.com>
---
 drivers/mfd/omap-usb-tll.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

Comments

Russell King - ARM Linux Jan. 18, 2013, 3:02 p.m. UTC | #1
On Fri, Jan 18, 2013 at 02:17:09PM +0200, Roger Quadros wrote:
> +/* only PHY and UNUSED modes don't need TLL */
> +#define omap_usb_mode_needs_tll(x)	((x != OMAP_USBHS_PORT_MODE_UNUSED) &&\
> +					 (x != OMAP_EHCI_PORT_MODE_PHY))

Growl.

These parens do not make anything safer at all - they just obfuscate.  The
safe version of the above macro would have been:

#define omap_usb_mode_needs_tll(x)	((x) != OMAP_USBHS_PORT_MODE_UNUSED &&\
					 (x) != OMAP_EHCI_PORT_MODE_PHY)

If you're going to use a macro argument in an expression, it needs parens.
Simple expressions like a != b && c != d do _not_ need parens.
Roger Quadros Jan. 18, 2013, 3:08 p.m. UTC | #2
On 01/18/2013 05:02 PM, Russell King - ARM Linux wrote:
> On Fri, Jan 18, 2013 at 02:17:09PM +0200, Roger Quadros wrote:
>> +/* only PHY and UNUSED modes don't need TLL */
>> +#define omap_usb_mode_needs_tll(x)	((x != OMAP_USBHS_PORT_MODE_UNUSED) &&\
>> +					 (x != OMAP_EHCI_PORT_MODE_PHY))
> 
> Growl.
> 
> These parens do not make anything safer at all - they just obfuscate.  The
> safe version of the above macro would have been:
> 
> #define omap_usb_mode_needs_tll(x)	((x) != OMAP_USBHS_PORT_MODE_UNUSED &&\
> 					 (x) != OMAP_EHCI_PORT_MODE_PHY)
> 
> If you're going to use a macro argument in an expression, it needs parens.
> Simple expressions like a != b && c != d do _not_ need parens.
> 

Yikes, that was brain dead stuff from me ;). Will fix.

cheers,
-roger
diff mbox

Patch

diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
index 4ce134b..6a43391 100644
--- a/drivers/mfd/omap-usb-tll.c
+++ b/drivers/mfd/omap-usb-tll.c
@@ -95,6 +95,10 @@ 
 
 #define is_ehci_tll_mode(x)	(x == OMAP_EHCI_PORT_MODE_TLL)
 
+/* only PHY and UNUSED modes don't need TLL */
+#define omap_usb_mode_needs_tll(x)	((x != OMAP_USBHS_PORT_MODE_UNUSED) &&\
+					 (x != OMAP_EHCI_PORT_MODE_PHY))
+
 struct usbtll_omap {
 	int					nch;	/* num. of channels */
 	struct usbhs_omap_platform_data		*pdata;
@@ -211,6 +215,7 @@  static int usbtll_omap_probe(struct platform_device *pdev)
 	unsigned long				flags;
 	int					ret = 0;
 	int					i, ver;
+	bool needs_tll;
 
 	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
 
@@ -281,12 +286,11 @@  static int usbtll_omap_probe(struct platform_device *pdev)
 
 	spin_lock_irqsave(&tll->lock, flags);
 
-	if (is_ehci_tll_mode(pdata->port_mode[0]) ||
-	    is_ehci_tll_mode(pdata->port_mode[1]) ||
-	    is_ehci_tll_mode(pdata->port_mode[2]) ||
-	    is_ohci_port(pdata->port_mode[0]) ||
-	    is_ohci_port(pdata->port_mode[1]) ||
-	    is_ohci_port(pdata->port_mode[2])) {
+	needs_tll = false;
+	for (i = 0; i < tll->nch; i++)
+		needs_tll |= omap_usb_mode_needs_tll(pdata->port_mode[i]);
+
+	if (needs_tll) {
 
 		/* Program Common TLL register */
 		reg = usbtll_read(base, OMAP_TLL_SHARED_CONF);
@@ -374,7 +378,7 @@  static int usbtll_runtime_resume(struct device *dev)
 	spin_lock_irqsave(&tll->lock, flags);
 
 	for (i = 0; i < tll->nch; i++) {
-		if (is_ehci_tll_mode(pdata->port_mode[i])) {
+		if (omap_usb_mode_needs_tll(pdata->port_mode[i])) {
 			int r;
 
 			if (!tll->ch_clk[i])
@@ -410,7 +414,7 @@  static int usbtll_runtime_suspend(struct device *dev)
 	spin_lock_irqsave(&tll->lock, flags);
 
 	for (i = 0; i < tll->nch; i++) {
-		if (is_ehci_tll_mode(pdata->port_mode[i])) {
+		if (omap_usb_mode_needs_tll(pdata->port_mode[i])) {
 			if (tll->ch_clk[i])
 				clk_disable(tll->ch_clk[i]);
 		}