Skip to contentSkip to conversation

usb : musb:Using omap_device_build for musb device registration

PATCH In review Hema HK 2 participants 3 messages Aug 6, 2010 – Aug 10, 2010 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

Hema HK

author
#0 lore raw

PATCH v2 4/8 usb : musb:Using omap_device_build for musb device registration

From: Hema HK <[email protected]>

Using omap_device_build api instead of platform_device_register for musb device registration.The device specific resources defined in centralized database will be used. So removed the resource definitions from the musb platform file.

Cc Felipe Balbi <[email protected]>
Cc Tony Lindgren <[email protected]>
Cc Kevin Hilman <[email protected]>

---

 arch/arm/mach-omap2/usb-musb.c |  100 +++++++++++++++++++++--------------------
 1 file changed, 53 insertions(+), 47 deletions(-)
arch/arm/mach-omap2/usb-musb.c +53 -44
Index: linux-omap-pm/arch/arm/mach-omap2/usb-musb.c
===================================================================
@@ -29,24 +29,12 @@
 #include <mach/hardware.h>
 #include <mach/irqs.h>
 #include <plat/usb.h>
+#include <plat/omap_device.h>
 
 #ifdef CONFIG_USB_MUSB_SOC
 
-static struct resource musb_resources[] = {
-	[0] = { /* start and end set dynamically */
-		.flags	= IORESOURCE_MEM,
-	},
-	[1] = {	/* general IRQ */
-		.start	= INT_243X_HS_USB_MC,
-		.flags	= IORESOURCE_IRQ,
-		.name	= "mc",
-	},
-	[2] = {	/* DMA IRQ */
-		.start	= INT_243X_HS_USB_DMA,
-		.flags	= IORESOURCE_IRQ,
-		.name	= "dma",
-	},
-};
+static const char name[] = "musb_hdrc";
+#define MAX_OMAP_MUSB_HWMOD_NAME_LEN	16
 
 static struct musb_hdrc_config musb_config = {
 	.multipoint	= 1,
@@ -75,43 +63,61 @@
 
 static u64 musb_dmamask = DMA_BIT_MASK(32);
 
-static struct platform_device musb_device = {
-	.name		= "musb_hdrc",
-	.id		= -1,
-	.dev = {
-		.dma_mask		= &musb_dmamask,
-		.coherent_dma_mask	= DMA_BIT_MASK(32),
-		.platform_data		= &musb_plat,
-	},
-	.num_resources	= ARRAY_SIZE(musb_resources),
-	.resource	= musb_resources,
+static struct omap_device_pm_latency omap_musb_latency[] = {
+	  {
+		.deactivate_func = omap_device_idle_hwmods,
+		.activate_func   = omap_device_enable_hwmods,
+		.flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
+	  },
 };
 
 void __init usb_musb_init(struct omap_musb_board_data *board_data)
 {
-	if (cpu_is_omap243x()) {
-		musb_resources[0].start = OMAP243X_HS_BASE;
-	} else if (cpu_is_omap34xx()) {
-		musb_resources[0].start = OMAP34XX_HSUSB_OTG_BASE;
-	} else if (cpu_is_omap44xx()) {
-		musb_resources[0].start = OMAP44XX_HSUSB_OTG_BASE;
-		musb_resources[1].start = OMAP44XX_IRQ_HS_USB_MC_N;
-		musb_resources[2].start = OMAP44XX_IRQ_HS_USB_DMA_N;
+	char oh_name[MAX_OMAP_MUSB_HWMOD_NAME_LEN];
+	struct omap_hwmod *oh;
+	struct omap_device *od;
+	struct platform_device *pdev;
+	struct device	*dev;
+	int l, bus_id = -1;
+	struct musb_hdrc_platform_data *pdata;
+
+	l = snprintf(oh_name, MAX_OMAP_MUSB_HWMOD_NAME_LEN,
+						"usb_otg_hs");
+	WARN(l >= MAX_OMAP_MUSB_HWMOD_NAME_LEN,
+			"String buffer overflow in MUSB device setup\n");
+
+	oh = omap_hwmod_lookup(oh_name);
+
+	if (!oh) {
+		pr_err("Could not look up %s\n", oh_name);
+	} else {
+		/*
+		 * REVISIT: This line can be removed once all the platforms
+		 * using musb_core.c have been converted to use use clkdev.
+		 */
+		musb_plat.clock = "ick";
+		musb_plat.board_data = board_data;
+		musb_plat.power = board_data->power >> 1;
+		musb_plat.mode = board_data->mode;
+		pdata = &musb_plat;
+
+		od = omap_device_build(name, bus_id, oh, pdata,
+				       sizeof(struct musb_hdrc_platform_data),
+							omap_musb_latency,
+				       ARRAY_SIZE(omap_musb_latency), false);
+		if (IS_ERR(od)) {
+			pr_err("Could not build omap_device for %s %s\n",
+						name, oh_name);
+		} else {
+
+			pdev = &od->pdev;
+			dev = &pdev->dev;
+			get_device(dev);
+			dev->dma_mask = &musb_dmamask;
+			dev->coherent_dma_mask = musb_dmamask;
+			put_device(dev);
+		}
 	}
-	musb_resources[0].end = musb_resources[0].start + SZ_4K - 1;
-
-	/*
-	 * REVISIT: This line can be removed once all the platforms using
-	 * musb_core.c have been converted to use use clkdev.
-	 */
-	musb_plat.clock = "ick";
-	musb_plat.board_data = board_data;
-	musb_plat.power = board_data->power >> 1;
-	musb_plat.mode = board_data->mode;
-	musb_plat.extvbus = board_data->extvbus;
#1 lore raw
Quoted 1 line · Hema

From: Hema HK<[email protected]>

<snip>

Quoted 12 lines
  void __init usb_musb_init(struct omap_musb_board_data *board_data)
  {
arch/arm/mach-omap2/usb-musb.c +2 -8
-	if (cpu_is_omap243x()) {
-		musb_resources[0].start = OMAP243X_HS_BASE;
-	} else if (cpu_is_omap34xx()) {
-		musb_resources[0].start = OMAP34XX_HSUSB_OTG_BASE;
-	} else if (cpu_is_omap44xx()) {
-		musb_resources[0].start = OMAP44XX_HSUSB_OTG_BASE;
-		musb_resources[1].start = OMAP44XX_IRQ_HS_USB_MC_N;
-		musb_resources[2].start = OMAP44XX_IRQ_HS_USB_DMA_N;
+	char oh_name[MAX_OMAP_MUSB_HWMOD_NAME_LEN];
+	struct omap_hwmod *oh;

arch/arm/mach-omap2/usb-musb.c line 87

Quoted 10 lines
arch/arm/mach-omap2/usb-musb.c +10 -0
+	struct omap_device *od;
+	struct platform_device *pdev;
+	struct device	*dev;
+	int l, bus_id = -1;
+	struct musb_hdrc_platform_data *pdata;
+
+	l = snprintf(oh_name, MAX_OMAP_MUSB_HWMOD_NAME_LEN,
+						"usb_otg_hs");
+	WARN(l>= MAX_OMAP_MUSB_HWMOD_NAME_LEN,
+			"String buffer overflow in MUSB device setup\n");

This is not needed in your case. Just use a const char*, and you will avoid the useless snprintf and test.

arch/arm/mach-omap2/usb-musb.c line 93

Quoted 6 lines
arch/arm/mach-omap2/usb-musb.c +6 -0
+
+	oh = omap_hwmod_lookup(oh_name);
+
+	if (!oh) {
+		pr_err("Could not look up %s\n", oh_name);
+	} else {

You can avoid that indentation be returning in case of failure.

Quoted 8 lines
arch/arm/mach-omap2/usb-musb.c +8 -0
+		/*
+		 * REVISIT: This line can be removed once all the platforms
+		 * using musb_core.c have been converted to use use clkdev.
+		 */
+		musb_plat.clock = "ick";
+		musb_plat.board_data = board_data;
+		musb_plat.power = board_data->power>>  1;
+		musb_plat.mode = board_data->mode;

arch/arm/mach-omap2/usb-musb.c line 111

Quoted 10 lines
arch/arm/mach-omap2/usb-musb.c +10 -0
+		pdata =&musb_plat;
+
+		od = omap_device_build(name, bus_id, oh, pdata,
+				       sizeof(struct musb_hdrc_platform_data),
+							omap_musb_latency,
+				       ARRAY_SIZE(omap_musb_latency), false);
+		if (IS_ERR(od)) {
+			pr_err("Could not build omap_device for %s %s\n",
+						name, oh_name);
+		} else {

You can avoid that second level of indentation be returning in case of failure as well.

Benoit

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

Hi,

Quoted 38 lines

-----Original Message-----
From: Cousson, Benoit
Sent: Monday, August 09, 2010 6:15 PM
To: Kalliguddi, Hema
Cc: [email protected]; [email protected]; Felipe Balbi; Tony Lindgren; Kevin Hilman
Subject: Re: [PATCH V2 4/8]usb : musb:Using omap_device_build
for musb device registration

Quoted 1 line · Hema

From: Hema HK<[email protected]>

<snip>

Quoted 12 lines
  void __init usb_musb_init(struct omap_musb_board_data *board_data)
  {
arch/arm/mach-omap2/usb-musb.c +2 -8
-	if (cpu_is_omap243x()) {
-		musb_resources[0].start = OMAP243X_HS_BASE;
-	} else if (cpu_is_omap34xx()) {
-		musb_resources[0].start = OMAP34XX_HSUSB_OTG_BASE;
-	} else if (cpu_is_omap44xx()) {
-		musb_resources[0].start = OMAP44XX_HSUSB_OTG_BASE;
-		musb_resources[1].start = OMAP44XX_IRQ_HS_USB_MC_N;
-		musb_resources[2].start = OMAP44XX_IRQ_HS_USB_DMA_N;
+	char oh_name[MAX_OMAP_MUSB_HWMOD_NAME_LEN];
+	struct omap_hwmod *oh;

arch/arm/mach-omap2/usb-musb.c

Quoted 10 lines
arch/arm/mach-omap2/usb-musb.c +10 -0
+	struct omap_device *od;
+	struct platform_device *pdev;
+	struct device	*dev;
+	int l, bus_id = -1;
+	struct musb_hdrc_platform_data *pdata;
+
+	l = snprintf(oh_name, MAX_OMAP_MUSB_HWMOD_NAME_LEN,
+						"usb_otg_hs");
+	WARN(l>= MAX_OMAP_MUSB_HWMOD_NAME_LEN,
+			"String buffer overflow in MUSB device 

setup\n");

Quoted 2 lines

This is not needed in your case. Just use a const char*, and you will avoid the useless snprintf and test.

Ok.

Quoted 9 lines

arch/arm/mach-omap2/usb-musb.c line 93

Quoted 7 lines
arch/arm/mach-omap2/usb-musb.c +6 -0
+
+	oh = omap_hwmod_lookup(oh_name);
+
+	if (!oh) {
+		pr_err("Could not look up %s\n", oh_name);
+	} else {

You can avoid that indentation be returning in case of failure.

Agreed.

Quoted 20 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+		/*
+		 * REVISIT: This line can be removed once all 

the platforms

Review

Quoted 1 line
(quoted diff) +1 -0
+		 * using musb_core.c have been converted to use 

use clkdev.

arch/arm/mach-omap2/usb-musb.c

Quoted 9 lines
arch/arm/mach-omap2/usb-musb.c +9 -0
+		 */
+		musb_plat.clock = "ick";
+		musb_plat.board_data = board_data;
+		musb_plat.power = board_data->power>>  1;
+		musb_plat.mode = board_data->mode;
+		pdata =&musb_plat;
+
+		od = omap_device_build(name, bus_id, oh, pdata,
+				       sizeof(struct 

musb_hdrc_platform_data),

Review

Quoted 1 line
(quoted diff) +1 -0
+							

omap_musb_latency,

Review

Quoted 1 line
(quoted diff) +1 -0
+				       

ARRAY_SIZE(omap_musb_latency), false);

Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		if (IS_ERR(od)) {
+			pr_err("Could not build omap_device for 

%s %s\n",

arch/arm/mach-omap2/usb-musb.c line 111

Quoted 2 lines
arch/arm/mach-omap2/usb-musb.c +2 -0
+						name, oh_name);
+		} else {

You can avoid that second level of indentation be returning in case of failure as well.

Agreed.

Quoted 3 lines

Benoit
--

To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html