LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6/7] usb: gadget: fsl_udc: purge global pointer usb_sys_regs
From: Christoph Fritz @ 2012-10-19 10:24 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior
In-Reply-To: <1350642156-8034-1-git-send-email-chf.fritz@googlemail.com>

Move global driver pointer usb_sys_regs to private struct fsl_udc.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
Reviewed-by: Teresa Gamez <T.Gamez@phytec.de>
---
 drivers/usb/gadget/fsl_udc_core.c |   26 ++++++++++++--------------
 drivers/usb/gadget/fsl_usb2_udc.h |    1 +
 2 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index deaab62..35ebcd4 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -43,8 +43,6 @@ static const char driver_desc[] = DRIVER_DESC;
 
 static struct usb_dr_device *dr_regs;
 
-static struct usb_sys_interface *usb_sys_regs;
-
 static const struct usb_endpoint_descriptor
 fsl_ep0_desc = {
 	.bLength =		USB_DT_ENDPOINT_SIZE,
@@ -170,10 +168,10 @@ static int dr_controller_setup(struct fsl_udc *udc)
 		if (udc->pdata->have_sysif_regs) {
 			if (udc->pdata->controller_ver) {
 				/* controller version 1.6 or above */
-				ctrl = __raw_readl(&usb_sys_regs->control);
+				ctrl = readl(&udc->usb_sys_regs->control);
 				ctrl &= ~USB_CTRL_UTMI_PHY_EN;
 				ctrl |= USB_CTRL_USB_EN;
-				__raw_writel(ctrl, &usb_sys_regs->control);
+				writel(ctrl, &udc->usb_sys_regs->control);
 			}
 		}
 		portctrl |= PORTSCX_PTS_ULPI;
@@ -185,10 +183,10 @@ static int dr_controller_setup(struct fsl_udc *udc)
 		if (udc->pdata->have_sysif_regs) {
 			if (udc->pdata->controller_ver) {
 				/* controller version 1.6 or above */
-				ctrl = __raw_readl(&usb_sys_regs->control);
+				ctrl = readl(&udc->usb_sys_regs->control);
 				ctrl |= (USB_CTRL_UTMI_PHY_EN |
 					USB_CTRL_USB_EN);
-				__raw_writel(ctrl, &usb_sys_regs->control);
+				writel(ctrl, &udc->usb_sys_regs->control);
 				mdelay(FSL_UTMI_PHY_DLY); /* Delay for UTMI
 					PHY CLK to become stable - 10ms*/
 			}
@@ -254,9 +252,9 @@ static int dr_controller_setup(struct fsl_udc *udc)
 	/* Config control enable i/o output, cpu endian register */
 #ifndef CONFIG_ARCH_MXC
 	if (udc->pdata->have_sysif_regs) {
-		ctrl = __raw_readl(&usb_sys_regs->control);
+		ctrl = readl(&udc->usb_sys_regs->control);
 		ctrl |= USB_CTRL_IOENB;
-		__raw_writel(ctrl, &usb_sys_regs->control);
+		writel(ctrl, &udc->usb_sys_regs->control);
 	}
 #endif
 
@@ -267,9 +265,9 @@ static int dr_controller_setup(struct fsl_udc *udc)
 	if (udc->pdata->have_sysif_regs) {
 		/* Setup Snooping for all the 4GB space */
 		tmp = SNOOP_SIZE_2GB;	/* starts from 0x0, size 2G */
-		__raw_writel(tmp, &usb_sys_regs->snoop1);
+		writel(tmp, &udc->usb_sys_regs->snoop1);
 		tmp |= 0x80000000;	/* starts from 0x8000000, size 2G */
-		__raw_writel(tmp, &usb_sys_regs->snoop2);
+		writel(tmp, &udc->usb_sys_regs->snoop2);
 	}
 #endif
 
@@ -326,7 +324,7 @@ static void dr_controller_stop(struct fsl_udc *udc)
 	udc->stopped = 1;
 
 	/* disable IO output */
-/*	usb_sys_regs->control = 0; */
+/*	udc->usb_sys_regs->control = 0; */
 
 	/* set controller to Stop */
 	tmp = readl(&dr_regs->usbcmd);
@@ -2130,12 +2128,12 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 
 #ifndef CONFIG_ARCH_MXC
 	if (udc->pdata->have_sysif_regs) {
-		tmp_reg = usb_sys_regs->snoop1;
+		tmp_reg = udc->usb_sys_regs->snoop1;
 		t = scnprintf(next, size, "Snoop1 Reg : = [0x%x]\n\n", tmp_reg);
 		size -= t;
 		next += t;
 
-		tmp_reg = usb_sys_regs->control;
+		tmp_reg = udc->usb_sys_regs->control;
 		t = scnprintf(next, size, "General Control Reg : = [0x%x]\n\n",
 				tmp_reg);
 		size -= t;
@@ -2388,7 +2386,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 
 #ifndef CONFIG_ARCH_MXC
 	if (pdata->have_sysif_regs)
-		usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
+		udc->usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
 #endif
 
 	/* Initialize USB clocks */
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index a0123ae..0d888f4 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -498,6 +498,7 @@ struct fsl_udc {
 	dma_addr_t ep_qh_dma;		/* dma address of QH */
 
 	struct ep_td_struct *last_free_td;
+	struct usb_sys_interface *usb_sys_regs;
 
 	u32 max_pipes;          /* Device max pipes */
 	u32 bus_reset;		/* Device is bus resetting */
-- 
1.7.2.5

^ permalink raw reply related

* [PATCH 7/7] usb: gadget: fsl_udc: purge global pointer dr_regs
From: Christoph Fritz @ 2012-10-19 10:24 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior
In-Reply-To: <1350642156-8034-1-git-send-email-chf.fritz@googlemail.com>

Move global driver pointer dr_regs to private struct fsl_udc.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
 drivers/usb/gadget/fsl_udc_core.c |  252 +++++++++++++++++++------------------
 drivers/usb/gadget/fsl_usb2_udc.h |    1 +
 2 files changed, 130 insertions(+), 123 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 35ebcd4..f9c4eb9 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -41,8 +41,6 @@
 static const char driver_name[] = DRIVER_NAME;
 static const char driver_desc[] = DRIVER_DESC;
 
-static struct usb_dr_device *dr_regs;
-
 static const struct usb_endpoint_descriptor
 fsl_ep0_desc = {
 	.bLength =		USB_DT_ENDPOINT_SIZE,
@@ -161,7 +159,7 @@ static int dr_controller_setup(struct fsl_udc *udc)
 #define FSL_UDC_RESET_TIMEOUT 1000
 
 	/* Config PHY interface */
-	portctrl = readl(&dr_regs->portsc1);
+	portctrl = readl(&udc->dr_regs->portsc1);
 	portctrl &= ~(PORTSCX_PHY_TYPE_SEL | PORTSCX_PORT_WIDTH);
 	switch (udc->phy_mode) {
 	case FSL_USB2_PHY_ULPI:
@@ -199,20 +197,20 @@ static int dr_controller_setup(struct fsl_udc *udc)
 	default:
 		return -EINVAL;
 	}
-	writel(portctrl, &dr_regs->portsc1);
+	writel(portctrl, &udc->dr_regs->portsc1);
 
 	/* Stop and reset the usb controller */
-	tmp = readl(&dr_regs->usbcmd);
+	tmp = readl(&udc->dr_regs->usbcmd);
 	tmp &= ~USB_CMD_RUN_STOP;
-	writel(tmp, &dr_regs->usbcmd);
+	writel(tmp, &udc->dr_regs->usbcmd);
 
-	tmp = readl(&dr_regs->usbcmd);
+	tmp = readl(&udc->dr_regs->usbcmd);
 	tmp |= USB_CMD_CTRL_RESET;
-	writel(tmp, &dr_regs->usbcmd);
+	writel(tmp, &udc->dr_regs->usbcmd);
 
 	/* Wait for reset to complete */
 	timeout = jiffies + FSL_UDC_RESET_TIMEOUT;
-	while (readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) {
+	while (readl(&udc->dr_regs->usbcmd) & USB_CMD_CTRL_RESET) {
 		if (time_after(jiffies, timeout)) {
 			ERR("udc reset timeout!\n");
 			return -ETIMEDOUT;
@@ -221,33 +219,33 @@ static int dr_controller_setup(struct fsl_udc *udc)
 	}
 
 	/* Set the controller as device mode */
-	tmp = readl(&dr_regs->usbmode);
+	tmp = readl(&udc->dr_regs->usbmode);
 	tmp &= ~USB_MODE_CTRL_MODE_MASK;	/* clear mode bits */
 	tmp |= USB_MODE_CTRL_MODE_DEVICE;
 	/* Disable Setup Lockout */
 	tmp |= USB_MODE_SETUP_LOCK_OFF;
 	if (udc->pdata->es)
 		tmp |= USB_MODE_ES;
-	writel(tmp, &dr_regs->usbmode);
+	writel(tmp, &udc->dr_regs->usbmode);
 
 	/* Clear the setup status */
-	writel(0, &dr_regs->usbsts);
+	writel(0, &udc->dr_regs->usbsts);
 
 	tmp = udc->ep_qh_dma;
 	tmp &= USB_EP_LIST_ADDRESS_MASK;
-	writel(tmp, &dr_regs->endpointlistaddr);
+	writel(tmp, &udc->dr_regs->endpointlistaddr);
 
 	VDBG("vir[qh_base] is %p phy[qh_base] is 0x%8x reg is 0x%8x",
 		udc->ep_qh, (int)tmp,
-		readl(&dr_regs->endpointlistaddr));
+		readl(&udc->dr_regs->endpointlistaddr));
 
-	max_no_of_ep = (0x0000001F & readl(&dr_regs->dccparams));
+	max_no_of_ep = (0x0000001F & readl(&udc->dr_regs->dccparams));
 	for (ep_num = 1; ep_num < max_no_of_ep; ep_num++) {
-		tmp = readl(&dr_regs->endptctrl[ep_num]);
+		tmp = readl(&udc->dr_regs->endptctrl[ep_num]);
 		tmp &= ~(EPCTRL_TX_TYPE | EPCTRL_RX_TYPE);
 		tmp |= (EPCTRL_EP_TYPE_BULK << EPCTRL_TX_EP_TYPE_SHIFT)
 		| (EPCTRL_EP_TYPE_BULK << EPCTRL_RX_EP_TYPE_SHIFT);
-		writel(tmp, &dr_regs->endptctrl[ep_num]);
+		writel(tmp, &udc->dr_regs->endptctrl[ep_num]);
 	}
 	/* Config control enable i/o output, cpu endian register */
 #ifndef CONFIG_ARCH_MXC
@@ -284,20 +282,20 @@ static void dr_controller_run(struct fsl_udc *udc)
 		| USB_INTR_PTC_DETECT_EN | USB_INTR_RESET_EN
 		| USB_INTR_DEVICE_SUSPEND | USB_INTR_SYS_ERR_EN;
 
-	writel(temp, &dr_regs->usbintr);
+	writel(temp, &udc->dr_regs->usbintr);
 
 	/* Clear stopped bit */
 	udc->stopped = 0;
 
 	/* Set the controller as device mode */
-	temp = readl(&dr_regs->usbmode);
+	temp = readl(&udc->dr_regs->usbmode);
 	temp |= USB_MODE_CTRL_MODE_DEVICE;
-	writel(temp, &dr_regs->usbmode);
+	writel(temp, &udc->dr_regs->usbmode);
 
 	/* Set controller to Run */
-	temp = readl(&dr_regs->usbcmd);
+	temp = readl(&udc->dr_regs->usbcmd);
 	temp |= USB_CMD_RUN_STOP;
-	writel(temp, &dr_regs->usbcmd);
+	writel(temp, &udc->dr_regs->usbcmd);
 }
 
 static void dr_controller_stop(struct fsl_udc *udc)
@@ -311,14 +309,14 @@ static void dr_controller_stop(struct fsl_udc *udc)
 	 * ehci driver
 	 */
 	if (udc->gadget.is_otg) {
-		if (!(readl(&dr_regs->otgsc) & OTGSC_STS_USB_ID)) {
+		if (!(readl(&udc->dr_regs->otgsc) & OTGSC_STS_USB_ID)) {
 			pr_debug("udc: Leaving early\n");
 			return;
 		}
 	}
 
 	/* disable all INTR */
-	writel(0, &dr_regs->usbintr);
+	writel(0, &udc->dr_regs->usbintr);
 
 	/* Set stopped bit for isr */
 	udc->stopped = 1;
@@ -327,17 +325,17 @@ static void dr_controller_stop(struct fsl_udc *udc)
 /*	udc->usb_sys_regs->control = 0; */
 
 	/* set controller to Stop */
-	tmp = readl(&dr_regs->usbcmd);
+	tmp = readl(&udc->dr_regs->usbcmd);
 	tmp &= ~USB_CMD_RUN_STOP;
-	writel(tmp, &dr_regs->usbcmd);
+	writel(tmp, &udc->dr_regs->usbcmd);
 }
 
-static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
-			unsigned char ep_type)
+static void dr_ep_setup(struct fsl_udc *udc, unsigned char ep_num,
+		unsigned char dir, unsigned char ep_type)
 {
 	unsigned int tmp_epctrl = 0;
 
-	tmp_epctrl = readl(&dr_regs->endptctrl[ep_num]);
+	tmp_epctrl = readl(&udc->dr_regs->endptctrl[ep_num]);
 	if (dir) {
 		if (ep_num)
 			tmp_epctrl |= EPCTRL_TX_DATA_TOGGLE_RST;
@@ -354,15 +352,15 @@ static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
 				<< EPCTRL_RX_EP_TYPE_SHIFT);
 	}
 
-	writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(tmp_epctrl, &udc->dr_regs->endptctrl[ep_num]);
 }
 
-static void
-dr_ep_change_stall(unsigned char ep_num, unsigned char dir, int value)
+static void dr_ep_change_stall(struct fsl_udc *udc, unsigned char ep_num,
+		unsigned char dir, int value)
 {
 	u32 tmp_epctrl = 0;
 
-	tmp_epctrl = readl(&dr_regs->endptctrl[ep_num]);
+	tmp_epctrl = readl(&udc->dr_regs->endptctrl[ep_num]);
 
 	if (value) {
 		/* set the stall bit */
@@ -380,16 +378,17 @@ dr_ep_change_stall(unsigned char ep_num, unsigned char dir, int value)
 			tmp_epctrl |= EPCTRL_RX_DATA_TOGGLE_RST;
 		}
 	}
-	writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(tmp_epctrl, &udc->dr_regs->endptctrl[ep_num]);
 }
 
 /* Get stall status of a specific ep
    Return: 0: not stalled; 1:stalled */
-static int dr_ep_get_stall(unsigned char ep_num, unsigned char dir)
+static int dr_ep_get_stall(struct fsl_udc *udc, unsigned char ep_num,
+		unsigned char dir)
 {
 	u32 epctrl;
 
-	epctrl = readl(&dr_regs->endptctrl[ep_num]);
+	epctrl = readl(&udc->dr_regs->endptctrl[ep_num]);
 	if (dir)
 		return (epctrl & EPCTRL_TX_EP_STALL) ? 1 : 0;
 	else
@@ -449,8 +448,8 @@ static void ep0_setup(struct fsl_udc *udc)
 			USB_MAX_CTRL_PAYLOAD, 0, 0);
 	struct_ep_qh_setup(udc, 0, USB_SEND, USB_ENDPOINT_XFER_CONTROL,
 			USB_MAX_CTRL_PAYLOAD, 0, 0);
-	dr_ep_setup(0, USB_RECV, USB_ENDPOINT_XFER_CONTROL);
-	dr_ep_setup(0, USB_SEND, USB_ENDPOINT_XFER_CONTROL);
+	dr_ep_setup(udc, 0, USB_RECV, USB_ENDPOINT_XFER_CONTROL);
+	dr_ep_setup(udc, 0, USB_SEND, USB_ENDPOINT_XFER_CONTROL);
 
 	return;
 
@@ -534,7 +533,7 @@ static int fsl_ep_enable(struct usb_ep *_ep,
 			max, zlt, mult);
 
 	/* Init endpoint ctrl register */
-	dr_ep_setup((unsigned char) ep_index(ep),
+	dr_ep_setup(udc, (unsigned char) ep_index(ep),
 			(unsigned char) ((desc->bEndpointAddress & USB_DIR_IN)
 					? USB_SEND : USB_RECV),
 			(unsigned char) (desc->bmAttributes
@@ -571,7 +570,7 @@ static int fsl_ep_disable(struct usb_ep *_ep)
 
 	/* disable ep on controller */
 	ep_num = ep_index(ep);
-	epctrl = readl(&dr_regs->endptctrl[ep_num]);
+	epctrl = readl(&udc->dr_regs->endptctrl[ep_num]);
 	if (ep_is_in(ep)) {
 		epctrl &= ~(EPCTRL_TX_ENABLE | EPCTRL_TX_TYPE);
 		epctrl |= EPCTRL_EP_TYPE_BULK << EPCTRL_TX_EP_TYPE_SHIFT;
@@ -579,7 +578,7 @@ static int fsl_ep_disable(struct usb_ep *_ep)
 		epctrl &= ~(EPCTRL_RX_ENABLE | EPCTRL_TX_TYPE);
 		epctrl |= EPCTRL_EP_TYPE_BULK << EPCTRL_RX_EP_TYPE_SHIFT;
 	}
-	writel(epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(epctrl, &udc->dr_regs->endptctrl[ep_num]);
 
 	udc = (struct fsl_udc *)ep->udc;
 	spin_lock_irqsave(&udc->lock, flags);
@@ -629,6 +628,7 @@ static void fsl_free_request(struct usb_ep *_ep, struct usb_request *_req)
 static void fsl_prime_ep(struct fsl_ep *ep, struct ep_td_struct *td)
 {
 	struct ep_queue_head *qh = get_qh_by_ep(ep);
+	struct fsl_udc *udc = ep->udc;
 
 	/* Write dQH next pointer and terminate bit to 0 */
 	qh->next_dtd_ptr = cpu_to_le32(td->td_dma
@@ -643,13 +643,14 @@ static void fsl_prime_ep(struct fsl_ep *ep, struct ep_td_struct *td)
 
 	/* Prime endpoint by writing correct bit to ENDPTPRIME */
 	writel(ep_is_in(ep) ? (1 << (ep_index(ep) + 16))
-			: (1 << (ep_index(ep))), &dr_regs->endpointprime);
+			: (1 << (ep_index(ep))), &udc->dr_regs->endpointprime);
 }
 
 /* Add dTD chain to the dQH of an EP */
 static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
 {
 	u32 temp, bitmask, tmp_stat;
+	struct fsl_udc *udc = ep->udc;
 
 	/* VDBG("QH addr Register 0x%8x", dr_regs->endpointlistaddr);
 	VDBG("ep_qh[%d] addr is 0x%8x", i, (u32)&(ep->udc->ep_qh[i])); */
@@ -668,22 +669,22 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
 		/* Ensure dTD's next dtd pointer to be updated */
 		wmb();
 		/* Read prime bit, if 1 goto done */
-		if (readl(&dr_regs->endpointprime) & bitmask)
+		if (readl(&udc->dr_regs->endpointprime) & bitmask)
 			return;
 
 		do {
 			/* Set ATDTW bit in USBCMD */
-			temp = readl(&dr_regs->usbcmd);
-			writel(temp | USB_CMD_ATDTW, &dr_regs->usbcmd);
+			temp = readl(&udc->dr_regs->usbcmd);
+			writel(temp | USB_CMD_ATDTW, &udc->dr_regs->usbcmd);
 
 			/* Read correct status bit */
-			tmp_stat = readl(&dr_regs->endptstatus) & bitmask;
+			tmp_stat = readl(&udc->dr_regs->endptstatus) & bitmask;
 
-		} while (!(readl(&dr_regs->usbcmd) & USB_CMD_ATDTW));
+		} while (!(readl(&udc->dr_regs->usbcmd) & USB_CMD_ATDTW));
 
 		/* Write ATDTW bit to 0 */
-		temp = readl(&dr_regs->usbcmd);
-		writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd);
+		temp = readl(&udc->dr_regs->usbcmd);
+		writel(temp & ~USB_CMD_ATDTW, &udc->dr_regs->usbcmd);
 
 		if (tmp_stat)
 			return;
@@ -866,6 +867,7 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 {
 	struct fsl_ep *ep = container_of(_ep, struct fsl_ep, ep);
 	struct fsl_req *req;
+	struct fsl_udc *udc = ep->udc;
 	unsigned long flags;
 	int ep_num, stopped, ret = 0;
 	u32 epctrl;
@@ -873,18 +875,18 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 	if (!_ep || !_req)
 		return -EINVAL;
 
-	spin_lock_irqsave(&ep->udc->lock, flags);
+	spin_lock_irqsave(&udc->lock, flags);
 	stopped = ep->stopped;
 
 	/* Stop the ep before we deal with the queue */
 	ep->stopped = 1;
 	ep_num = ep_index(ep);
-	epctrl = readl(&dr_regs->endptctrl[ep_num]);
+	epctrl = readl(&udc->dr_regs->endptctrl[ep_num]);
 	if (ep_is_in(ep))
 		epctrl &= ~EPCTRL_TX_ENABLE;
 	else
 		epctrl &= ~EPCTRL_RX_ENABLE;
-	writel(epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(epctrl, &udc->dr_regs->endptctrl[ep_num]);
 
 	/* make sure it's actually queued on this endpoint */
 	list_for_each_entry(req, &ep->queue, queue) {
@@ -922,12 +924,12 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 	done(ep, req, -ECONNRESET);
 
 	/* Enable EP */
-out:	epctrl = readl(&dr_regs->endptctrl[ep_num]);
+out:	epctrl = readl(&udc->dr_regs->endptctrl[ep_num]);
 	if (ep_is_in(ep))
 		epctrl |= EPCTRL_TX_ENABLE;
 	else
 		epctrl |= EPCTRL_RX_ENABLE;
-	writel(epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(epctrl, &udc->dr_regs->endptctrl[ep_num]);
 	ep->stopped = stopped;
 
 	spin_unlock_irqrestore(&ep->udc->lock, flags);
@@ -973,7 +975,7 @@ static int fsl_ep_set_halt(struct usb_ep *_ep, int value)
 	ep_dir = ep_is_in(ep) ? USB_SEND : USB_RECV;
 	ep_num = (unsigned char)(ep_index(ep));
 	spin_lock_irqsave(&ep->udc->lock, flags);
-	dr_ep_change_stall(ep_num, ep_dir, value);
+	dr_ep_change_stall(udc, ep_num, ep_dir, value);
 	spin_unlock_irqrestore(&ep->udc->lock, flags);
 
 	if (ep_index(ep) == 0) {
@@ -1009,7 +1011,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
 	bitmask = (ep_is_in(ep)) ? (1 << (ep_index(ep) + 16)) :
 	    (1 << (ep_index(ep)));
 
-	if (readl(&dr_regs->endptstatus) & bitmask)
+	if (readl(&udc->dr_regs->endptstatus) & bitmask)
 		size = (qh->size_ioc_int_sts & DTD_PACKET_SIZE)
 		    >> DTD_LENGTH_BIT_POS;
 
@@ -1019,6 +1021,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
 
 static void fsl_ep_fifo_flush(struct usb_ep *_ep)
 {
+	struct fsl_udc *udc;
 	struct fsl_ep *ep;
 	int ep_num, ep_dir;
 	u32 bits;
@@ -1031,6 +1034,7 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep)
 		ep = container_of(_ep, struct fsl_ep, ep);
 		if (!ep->ep.desc)
 			return;
+		udc = ep->udc;
 	}
 	ep_num = ep_index(ep);
 	ep_dir = ep_is_in(ep) ? USB_SEND : USB_RECV;
@@ -1044,10 +1048,10 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep)
 
 	timeout = jiffies + FSL_UDC_FLUSH_TIMEOUT;
 	do {
-		writel(bits, &dr_regs->endptflush);
+		writel(bits, &udc->dr_regs->endptflush);
 
 		/* Wait until flush complete */
-		while (readl(&dr_regs->endptflush)) {
+		while (readl(&udc->dr_regs->endptflush)) {
 			if (time_after(jiffies, timeout)) {
 				ERR("ep flush timeout\n");
 				return;
@@ -1055,7 +1059,7 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep)
 			cpu_relax();
 		}
 		/* See if we need to flush again */
-	} while (readl(&dr_regs->endptstatus) & bits);
+	} while (readl(&udc->dr_regs->endptstatus) & bits);
 }
 
 static struct usb_ep_ops fsl_ep_ops = {
@@ -1082,7 +1086,8 @@ static struct usb_ep_ops fsl_ep_ops = {
  *----------------------------------------------------------------------*/
 static int fsl_get_frame(struct usb_gadget *gadget)
 {
-	return (int)(readl(&dr_regs->frindex) & USB_FRINDEX_MASKS);
+	struct fsl_udc *udc = container_of(gadget, struct fsl_udc, gadget);
+	return (int)(readl(&udc->dr_regs->frindex) & USB_FRINDEX_MASKS);
 }
 
 /*-----------------------------------------------------------------------
@@ -1097,13 +1102,13 @@ static int fsl_wakeup(struct usb_gadget *gadget)
 	if (!udc->remote_wakeup)
 		return -ENOTSUPP;
 
-	portsc = readl(&dr_regs->portsc1);
+	portsc = readl(&udc->dr_regs->portsc1);
 	/* not suspended? */
 	if (!(portsc & PORTSCX_PORT_SUSPEND))
 		return 0;
 	/* trigger force resume */
 	portsc |= PORTSCX_PORT_FORCE_RESUME;
-	writel(portsc, &dr_regs->portsc1);
+	writel(portsc, &udc->dr_regs->portsc1);
 	return 0;
 }
 
@@ -1124,11 +1129,11 @@ static int fsl_vbus_session(struct usb_gadget *gadget, int is_active)
 	VDBG("VBUS %s", is_active ? "on" : "off");
 	udc->vbus_active = (is_active != 0);
 	if (can_pullup(udc))
-		writel((readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
-				&dr_regs->usbcmd);
+		writel((readl(&udc->dr_regs->usbcmd) | USB_CMD_RUN_STOP),
+				&udc->dr_regs->usbcmd);
 	else
-		writel((readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
-				&dr_regs->usbcmd);
+		writel((readl(&udc->dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
+				&udc->dr_regs->usbcmd);
 	spin_unlock_irqrestore(&udc->lock, flags);
 	return 0;
 }
@@ -1162,11 +1167,11 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
 	spin_lock_irqsave(&udc->lock, flags);
 	udc->softconnect = (is_on != 0);
 	if (can_pullup(udc))
-		writel((readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
-				&dr_regs->usbcmd);
+		writel((readl(&udc->dr_regs->usbcmd) | USB_CMD_RUN_STOP),
+				&udc->dr_regs->usbcmd);
 	else
-		writel((readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
-				&dr_regs->usbcmd);
+		writel((readl(&udc->dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
+				&udc->dr_regs->usbcmd);
 	spin_unlock_irqrestore(&udc->lock, flags);
 
 	return 0;
@@ -1195,9 +1200,9 @@ static void ep0stall(struct fsl_udc *udc)
 	u32 tmp;
 
 	/* must set tx and rx to stall at the same time */
-	tmp = readl(&dr_regs->endptctrl[0]);
+	tmp = readl(&udc->dr_regs->endptctrl[0]);
 	tmp |= EPCTRL_TX_EP_STALL | EPCTRL_RX_EP_STALL;
-	writel(tmp, &dr_regs->endptctrl[0]);
+	writel(tmp, &udc->dr_regs->endptctrl[0]);
 	udc->ep0_state = WAIT_FOR_SETUP;
 	udc->ep0_dir = 0;
 }
@@ -1290,8 +1295,8 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
 		/* stall if endpoint doesn't exist */
 		if (!target_ep->ep.desc)
 			goto stall;
-		tmp = dr_ep_get_stall(ep_index(target_ep), ep_is_in(target_ep))
-				<< USB_ENDPOINT_HALT;
+		tmp = dr_ep_get_stall(udc, ep_index(target_ep),
+				ep_is_in(target_ep)) << USB_ENDPOINT_HALT;
 	}
 
 	udc->ep0_dir = USB_DIR_IN;
@@ -1407,8 +1412,8 @@ static void setup_received_irq(struct fsl_udc *udc,
 			u32 tmp;
 
 			mdelay(10);
-			tmp = readl(&dr_regs->portsc1) | (ptc << 16);
-			writel(tmp, &dr_regs->portsc1);
+			tmp = readl(&udc->dr_regs->portsc1) | (ptc << 16);
+			writel(tmp, &udc->dr_regs->portsc1);
 			printk(KERN_INFO "udc: switch to test mode %d.\n", ptc);
 		}
 
@@ -1460,7 +1465,7 @@ static void ep0_req_complete(struct fsl_udc *udc, struct fsl_ep *ep0,
 		/* Set the new address */
 		u32 new_address = (u32) udc->device_address;
 		writel(new_address << USB_DEVICE_ADDRESS_BIT_POS,
-				&dr_regs->deviceaddr);
+				&udc->dr_regs->deviceaddr);
 	}
 
 	done(ep0, req, 0);
@@ -1498,14 +1503,14 @@ static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
 	qh = &udc->ep_qh[ep_num * 2 + EP_DIR_OUT];
 
 	/* Clear bit in ENDPTSETUPSTAT */
-	temp = readl(&dr_regs->endptsetupstat);
-	writel(temp | (1 << ep_num), &dr_regs->endptsetupstat);
+	temp = readl(&udc->dr_regs->endptsetupstat);
+	writel(temp | (1 << ep_num), &udc->dr_regs->endptsetupstat);
 
 	/* while a hazard exists when setup package arrives */
 	do {
 		/* Set Setup Tripwire */
-		temp = readl(&dr_regs->usbcmd);
-		writel(temp | USB_CMD_SUTW, &dr_regs->usbcmd);
+		temp = readl(&udc->dr_regs->usbcmd);
+		writel(temp | USB_CMD_SUTW, &udc->dr_regs->usbcmd);
 
 		/* Copy the setup packet to local buffer */
 		if (pdata->le_setup_buf) {
@@ -1518,11 +1523,11 @@ static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
 		} else {
 			memcpy(buffer_ptr, (u8 *) qh->setup_buffer, 8);
 		}
-	} while (!(readl(&dr_regs->usbcmd) & USB_CMD_SUTW));
+	} while (!(readl(&udc->dr_regs->usbcmd) & USB_CMD_SUTW));
 
 	/* Clear Setup Tripwire */
-	temp = readl(&dr_regs->usbcmd);
-	writel(temp & ~USB_CMD_SUTW, &dr_regs->usbcmd);
+	temp = readl(&udc->dr_regs->usbcmd);
+	writel(temp & ~USB_CMD_SUTW, &udc->dr_regs->usbcmd);
 }
 
 /* process-ep_req(): free the completed Tds for this req */
@@ -1609,8 +1614,8 @@ static void dtd_complete_irq(struct fsl_udc *udc)
 	struct fsl_req *curr_req, *temp_req;
 
 	/* Clear the bits in the register */
-	bit_pos = readl(&dr_regs->endptcomplete);
-	writel(bit_pos, &dr_regs->endptcomplete);
+	bit_pos = readl(&udc->dr_regs->endptcomplete);
+	writel(bit_pos, &udc->dr_regs->endptcomplete);
 
 	if (!bit_pos)
 		return;
@@ -1674,10 +1679,10 @@ static void port_change_irq(struct fsl_udc *udc)
 		udc->bus_reset = 0;
 
 	/* Bus resetting is finished */
-	if (!(readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET))
+	if (!(readl(&udc->dr_regs->portsc1) & PORTSCX_PORT_RESET))
 		/* Get the speed */
 		udc->gadget.speed =
-			portscx_device_speed(readl(&dr_regs->portsc1));
+			portscx_device_speed(readl(&udc->dr_regs->portsc1));
 
 	/* Update USB state */
 	if (!udc->resume_state)
@@ -1728,8 +1733,8 @@ static void reset_irq(struct fsl_udc *udc)
 	unsigned long timeout;
 
 	/* Clear the device address */
-	temp = readl(&dr_regs->deviceaddr);
-	writel(temp & ~USB_DEVICE_ADDRESS_MASK, &dr_regs->deviceaddr);
+	temp = readl(&udc->dr_regs->deviceaddr);
+	writel(temp & ~USB_DEVICE_ADDRESS_MASK, &udc->dr_regs->deviceaddr);
 
 	udc->device_address = 0;
 
@@ -1743,15 +1748,15 @@ static void reset_irq(struct fsl_udc *udc)
 	udc->gadget.a_alt_hnp_support = 0;
 
 	/* Clear all the setup token semaphores */
-	temp = readl(&dr_regs->endptsetupstat);
-	writel(temp, &dr_regs->endptsetupstat);
+	temp = readl(&udc->dr_regs->endptsetupstat);
+	writel(temp, &udc->dr_regs->endptsetupstat);
 
 	/* Clear all the endpoint complete status bits */
-	temp = readl(&dr_regs->endptcomplete);
-	writel(temp, &dr_regs->endptcomplete);
+	temp = readl(&udc->dr_regs->endptcomplete);
+	writel(temp, &udc->dr_regs->endptcomplete);
 
 	timeout = jiffies + 100;
-	while (readl(&dr_regs->endpointprime)) {
+	while (readl(&udc->dr_regs->endpointprime)) {
 		/* Wait until all endptprime bits cleared */
 		if (time_after(jiffies, timeout)) {
 			ERR("Timeout for reset\n");
@@ -1761,9 +1766,9 @@ static void reset_irq(struct fsl_udc *udc)
 	}
 
 	/* Write 1s to the flush register */
-	writel(0xffffffff, &dr_regs->endptflush);
+	writel(0xffffffff, &udc->dr_regs->endptflush);
 
-	if (readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) {
+	if (readl(&udc->dr_regs->portsc1) & PORTSCX_PORT_RESET) {
 		VDBG("Bus reset");
 		/* Bus is reseting */
 		udc->bus_reset = 1;
@@ -1802,22 +1807,23 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
 	if (udc->stopped)
 		return IRQ_NONE;
 	spin_lock_irqsave(&udc->lock, flags);
-	irq_src = readl(&dr_regs->usbsts) & readl(&dr_regs->usbintr);
+	irq_src = readl(&udc->dr_regs->usbsts) & readl(&udc->dr_regs->usbintr);
 	/* Clear notification bits */
-	writel(irq_src, &dr_regs->usbsts);
+	writel(irq_src, &udc->dr_regs->usbsts);
 
 	/* VDBG("irq_src [0x%8x]", irq_src); */
 
 	/* Need to resume? */
 	if (udc->usb_state == USB_STATE_SUSPENDED)
-		if ((readl(&dr_regs->portsc1) & PORTSCX_PORT_SUSPEND) == 0)
+		if ((readl(&udc->dr_regs->portsc1) & PORTSCX_PORT_SUSPEND) == 0)
 			bus_resume(udc);
 
 	/* USB Interrupt */
 	if (irq_src & USB_STS_INT) {
 		VDBG("Packet int");
 		/* Setup package, we only support ep0 as control ep */
-		if (readl(&dr_regs->endptsetupstat) & EP_SETUP_STATUS_EP0) {
+		if (readl(&udc->dr_regs->endptsetupstat) &
+				EP_SETUP_STATUS_EP0) {
 			tripwire_handler(udc, 0,
 					(u8 *) (&udc->local_setup_buff));
 			setup_received_irq(udc, &udc->local_setup_buff);
@@ -1825,7 +1831,7 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
 		}
 
 		/* completion of dtd */
-		if (readl(&dr_regs->endptcomplete)) {
+		if (readl(&udc->dr_regs->endptcomplete)) {
 			dtd_complete_irq(udc);
 			status = IRQ_HANDLED;
 		}
@@ -1987,7 +1993,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	next += t;
 
 	/* ------ DR Registers ----- */
-	tmp_reg = readl(&dr_regs->usbcmd);
+	tmp_reg = readl(&udc->dr_regs->usbcmd);
 	t = scnprintf(next, size,
 			"USBCMD reg:\n"
 			"SetupTW: %d\n"
@@ -1997,7 +2003,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->usbsts);
+	tmp_reg = readl(&udc->dr_regs->usbsts);
 	t = scnprintf(next, size,
 			"USB Status Reg:\n"
 			"Dr Suspend: %d Reset Received: %d System Error: %s "
@@ -2009,7 +2015,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->usbintr);
+	tmp_reg = readl(&udc->dr_regs->usbintr);
 	t = scnprintf(next, size,
 			"USB Intrrupt Enable Reg:\n"
 			"Sleep Enable: %d SOF Received Enable: %d "
@@ -2027,21 +2033,21 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->frindex);
+	tmp_reg = readl(&udc->dr_regs->frindex);
 	t = scnprintf(next, size,
 			"USB Frame Index Reg: Frame Number is 0x%x\n\n",
 			(tmp_reg & USB_FRINDEX_MASKS));
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->deviceaddr);
+	tmp_reg = readl(&udc->dr_regs->deviceaddr);
 	t = scnprintf(next, size,
 			"USB Device Address Reg: Device Addr is 0x%x\n\n",
 			(tmp_reg & USB_DEVICE_ADDRESS_MASK));
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->endpointlistaddr);
+	tmp_reg = readl(&udc->dr_regs->endpointlistaddr);
 	t = scnprintf(next, size,
 			"USB Endpoint List Address Reg: "
 			"Device Addr is 0x%x\n\n",
@@ -2049,7 +2055,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->portsc1);
+	tmp_reg = readl(&udc->dr_regs->portsc1);
 	t = scnprintf(next, size,
 		"USB Port Status&Control Reg:\n"
 		"Port Transceiver Type : %s Port Speed: %s\n"
@@ -2088,7 +2094,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->usbmode);
+	tmp_reg = readl(&udc->dr_regs->usbmode);
 	t = scnprintf(next, size,
 			"USB Mode Reg: Controller Mode is: %s\n\n", ( {
 				char *s;
@@ -2107,7 +2113,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->endptsetupstat);
+	tmp_reg = readl(&udc->dr_regs->endptsetupstat);
 	t = scnprintf(next, size,
 			"Endpoint Setup Status Reg: SETUP on ep 0x%x\n\n",
 			(tmp_reg & EP_SETUP_STATUS_MASK));
@@ -2115,13 +2121,13 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	next += t;
 
 	for (i = 0; i < udc->max_ep / 2; i++) {
-		tmp_reg = readl(&dr_regs->endptctrl[i]);
+		tmp_reg = readl(&udc->dr_regs->endptctrl[i]);
 		t = scnprintf(next, size, "EP Ctrl Reg [0x%x]: = [0x%x]\n",
 				i, tmp_reg);
 		size -= t;
 		next += t;
 	}
-	tmp_reg = readl(&dr_regs->endpointprime);
+	tmp_reg = readl(&udc->dr_regs->endpointprime);
 	t = scnprintf(next, size, "EP Prime Reg = [0x%x]\n\n", tmp_reg);
 	size -= t;
 	next += t;
@@ -2368,13 +2374,13 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 		}
 	}
 
-	dr_regs = ioremap(res->start, resource_size(res));
-	if (!dr_regs) {
+	udc->dr_regs = ioremap(res->start, resource_size(res));
+	if (!udc->dr_regs) {
 		ret = -ENOMEM;
 		goto err_release_mem_region;
 	}
 
-	pdata->regs = (void *)dr_regs;
+	pdata->regs = (void *)udc->dr_regs;
 
 	/*
 	 * do platform specific init: check the clock, grab/config pins, etc.
@@ -2386,7 +2392,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 
 #ifndef CONFIG_ARCH_MXC
 	if (pdata->have_sysif_regs)
-		udc->usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
+		udc->usb_sys_regs = (void *)udc->dr_regs + USB_DR_SYS_OFFSET;
 #endif
 
 	/* Initialize USB clocks */
@@ -2395,7 +2401,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 		goto err_iounmap_noclk;
 
 	/* Read Device Controller Capability Parameters register */
-	dccparams = readl(&dr_regs->dccparams);
+	dccparams = readl(&udc->dr_regs->dccparams);
 	if (!(dccparams & DCCPARAMS_DC)) {
 		ERR("This SOC doesn't support device role\n");
 		ret = -ENODEV;
@@ -2505,7 +2511,7 @@ err_iounmap:
 		pdata->exit(pdev);
 	fsl_udc_clk_release();
 err_iounmap_noclk:
-	iounmap(dr_regs);
+	iounmap(udc->dr_regs);
 err_release_mem_region:
 	if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
 		release_mem_region(res->start, resource_size(res));
@@ -2543,7 +2549,7 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
 
 	dma_pool_destroy(udc->td_pool);
 	free_irq(udc->irq, udc);
-	iounmap(dr_regs);
+	iounmap(udc->dr_regs);
 	if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
 		release_mem_region(res->start, resource_size(res));
 
@@ -2595,7 +2601,7 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
 	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
 	u32 mode, usbcmd;
 
-	mode = readl(&dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
+	mode = readl(&udc->dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
 
 	pr_debug("%s(): mode 0x%x stopped %d\n", __func__, mode, udc->stopped);
 
@@ -2616,8 +2622,8 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
 	}
 
 	/* stop the controller */
-	usbcmd = readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP;
-	writel(usbcmd, &dr_regs->usbcmd);
+	usbcmd = readl(&udc->dr_regs->usbcmd) & ~USB_CMD_RUN_STOP;
+	writel(usbcmd, &udc->dr_regs->usbcmd);
 
 	udc->stopped = 1;
 
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index 0d888f4..3b2a5ff 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -499,6 +499,7 @@ struct fsl_udc {
 
 	struct ep_td_struct *last_free_td;
 	struct usb_sys_interface *usb_sys_regs;
+	struct usb_dr_device *dr_regs;
 
 	u32 max_pipes;          /* Device max pipes */
 	u32 bus_reset;		/* Device is bus resetting */
-- 
1.7.2.5

^ permalink raw reply related

* Re: [PATCH 1/7] usb: gadget: fsl_udc: simplify driver init
From: Felipe Balbi @ 2012-10-19 10:24 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Felipe Balbi,
	Hans J. Koch, Daniel Mack, Christian Hemp, linuxppc-dev,
	Teresa Gamez, Sebastian Andrzej Siewior
In-Reply-To: <1350642285-8145-1-git-send-email-chf.fritz@googlemail.com>

[-- Attachment #1: Type: text/plain, Size: 1995 bytes --]

Hi,

On Fri, Oct 19, 2012 at 12:24:39PM +0200, Christoph Fritz wrote:
> To initialize this driver use 'module_platform_driver' instead
> of '__init' and '__exit'.
> 
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |   37 +++++++++++--------------------------
>  1 files changed, 11 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index 6ae70cb..340451d 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -49,13 +49,14 @@
>  
>  #include "fsl_usb2_udc.h"
>  
> +#define	DRIVER_NAME	"fsl-usb2-udc"
>  #define	DRIVER_DESC	"Freescale High-Speed USB SOC Device Controller driver"
>  #define	DRIVER_AUTHOR	"Li Yang/Jiang Bo"
>  #define	DRIVER_VERSION	"Apr 20, 2007"
>  
>  #define	DMA_ADDR_INVALID	(~(dma_addr_t)0)
>  
> -static const char driver_name[] = "fsl-usb2-udc";
> +static const char driver_name[] = DRIVER_NAME;
>  static const char driver_desc[] = DRIVER_DESC;
>  
>  static struct usb_dr_device *dr_regs;
> @@ -2761,35 +2762,19 @@ static int fsl_udc_otg_resume(struct device *dev)
>  	Register entry point for the peripheral controller driver
>  --------------------------------------------------------------------------*/
>  
> -static struct platform_driver udc_driver = {
> -	.remove  = __exit_p(fsl_udc_remove),
> -	/* these suspend and resume are not usb suspend and resume */
> -	.suspend = fsl_udc_suspend,
> -	.resume  = fsl_udc_resume,
> -	.driver  = {
> -		.name = (char *)driver_name,
> -		.owner = THIS_MODULE,
> -		/* udc suspend/resume called from OTG driver */
> +static struct platform_driver fsl_udc_driver = {
> +	.probe		= fsl_udc_probe,

NAK, probe() lies in .init.text section. You need to change __init to
__devinit. Likewise for all functions which are only called during
probe() and for remove() which needs s/__exit/__devexit.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply

* Re: [PATCH 2/7] usb: gadget: fsl_udc: protect fsl_pullup() with spin_lock
From: Felipe Balbi @ 2012-10-19 10:25 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Felipe Balbi,
	Hans J. Koch, Daniel Mack, Christian Hemp, linuxppc-dev,
	Teresa Gamez, Sebastian Andrzej Siewior
In-Reply-To: <1350642285-8145-2-git-send-email-chf.fritz@googlemail.com>

[-- Attachment #1: Type: text/plain, Size: 2057 bytes --]

Hi,

On Fri, Oct 19, 2012 at 12:24:40PM +0200, Christoph Fritz wrote:
> This patch reworks fsl_pullup() against the background of switching over
> to udc_start()/udc_stop() style:
> 
> Protect function fsl_pullup() with a spin_lock. Also set vbus_active as
> default to true. This prevents disabling USB controller if there is no

the vbus_active part should be in a separate patch as it has no relation
with $SUBJECT

> driver support for an external transceiver (or GPIO) that detects a VBUS
> power session starting.
> 
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index 340451d..0a0d6a6 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -1242,8 +1242,10 @@ static int fsl_vbus_draw(struct usb_gadget *gadget, unsigned mA)
>  static int fsl_pullup(struct usb_gadget *gadget, int is_on)
>  {
>  	struct fsl_udc *udc;
> +	unsigned long flags;
>  
>  	udc = container_of(gadget, struct fsl_udc, gadget);
> +	spin_lock_irqsave(&udc->lock, flags);
>  	udc->softconnect = (is_on != 0);
>  	if (can_pullup(udc))
>  		fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
> @@ -1251,6 +1253,7 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
>  	else
>  		fsl_writel((fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
>  				&dr_regs->usbcmd);
> +	spin_unlock_irqrestore(&udc->lock, flags);
>  
>  	return 0;
>  }
> @@ -2557,6 +2560,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  	INIT_LIST_HEAD(&udc_controller->gadget.ep_list);
>  	udc_controller->gadget.speed = USB_SPEED_UNKNOWN;
>  	udc_controller->gadget.name = driver_name;
> +	udc->vbus_active = true;
>  
>  	/* Setup gadget.dev and register with kernel */
>  	dev_set_name(&udc_controller->gadget.dev, "gadget");
> -- 
> 1.7.2.5
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply

* Re: [PATCH 3/7] usb: gadget: fsl_udc: convert to new ulc style
From: Felipe Balbi @ 2012-10-19 10:27 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Felipe Balbi,
	Hans J. Koch, Daniel Mack, Christian Hemp, linuxppc-dev,
	Teresa Gamez, Sebastian Andrzej Siewior
In-Reply-To: <1350642285-8145-3-git-send-email-chf.fritz@googlemail.com>

[-- Attachment #1: Type: text/plain, Size: 22496 bytes --]

Hi,

typo on Subject. Should be udc, not ulc.

On Fri, Oct 19, 2012 at 12:24:41PM +0200, Christoph Fritz wrote:
> Convert to new UDC style registration and remove
> global 'udc_controller' pointer.
> 
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |  289 +++++++++++++++++--------------------
>  1 files changed, 131 insertions(+), 158 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index 0a0d6a6..d113f39 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -63,9 +63,6 @@ static struct usb_dr_device *dr_regs;
>  
>  static struct usb_sys_interface *usb_sys_regs;
>  
> -/* it is initialized in probe()  */
> -static struct fsl_udc *udc_controller = NULL;
> -
>  static const struct usb_endpoint_descriptor
>  fsl_ep0_desc = {
>  	.bLength =		USB_DT_ENDPOINT_SIZE,
> @@ -783,12 +780,14 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
>  }
>  
>  /* Fill in the dTD structure
> + * @udc: driver private data
>   * @req: request that the transfer belongs to
>   * @length: return actually data length of the dTD
>   * @dma: return dma address of the dTD
>   * @is_last: return flag if it is the last dTD of the request
>   * return: pointer to the built dTD */
> -static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
> +static struct ep_td_struct *fsl_build_dtd(struct fsl_udc *udc,
> +		struct fsl_req *req, unsigned *length,
>  		dma_addr_t *dma, int *is_last, gfp_t gfp_flags)

I would split this patch a little. First I would patch the missing
arguments to these functions under the excuse that a later patch will
get rid of the udc_controller pointer, then the next patch would do the
conversion to new style.

It will be a lot easier to review ;-)

>  {
>  	u32 swap_temp;
> @@ -798,7 +797,7 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
>  	*length = min(req->req.length - req->req.actual,
>  			(unsigned)EP_MAX_LENGTH_TRANSFER);
>  
> -	dtd = dma_pool_alloc(udc_controller->td_pool, gfp_flags, dma);
> +	dtd = dma_pool_alloc(udc->td_pool, gfp_flags, dma);
>  	if (dtd == NULL)
>  		return dtd;
>  
> @@ -848,7 +847,8 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
>  }
>  
>  /* Generate dtd chain for a request */
> -static int fsl_req_to_dtd(struct fsl_req *req, gfp_t gfp_flags)
> +static int fsl_req_to_dtd(struct fsl_udc *udc, struct fsl_req *req,
> +		gfp_t gfp_flags)
>  {
>  	unsigned	count;
>  	int		is_last;
> @@ -857,7 +857,8 @@ static int fsl_req_to_dtd(struct fsl_req *req, gfp_t gfp_flags)
>  	dma_addr_t dma;
>  
>  	do {
> -		dtd = fsl_build_dtd(req, &count, &dma, &is_last, gfp_flags);
> +		dtd = fsl_build_dtd(udc, req, &count, &dma, &is_last,
> +				gfp_flags);
>  		if (dtd == NULL)
>  			return -ENOMEM;
>  
> @@ -932,7 +933,7 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
>  	req->dtd_count = 0;
>  
>  	/* build dtds and push them to device queue */
> -	if (!fsl_req_to_dtd(req, gfp_flags)) {
> +	if (!fsl_req_to_dtd(udc, req, gfp_flags)) {
>  		spin_lock_irqsave(&udc->lock, flags);
>  		fsl_queue_td(ep, req);
>  	} else {
> @@ -1258,9 +1259,10 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
>  	return 0;
>  }
>  
> -static int fsl_start(struct usb_gadget_driver *driver,
> -		int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
> -static int fsl_stop(struct usb_gadget_driver *driver);
> +static int fsl_udc_start(struct usb_gadget *gadget,
> +		struct usb_gadget_driver *driver);
> +static int fsl_udc_stop(struct usb_gadget *gadget,
> +		struct usb_gadget_driver *driver);
>  /* defined in gadget.h */
>  static struct usb_gadget_ops fsl_gadget_ops = {
>  	.get_frame = fsl_get_frame,
> @@ -1269,8 +1271,8 @@ static struct usb_gadget_ops fsl_gadget_ops = {
>  	.vbus_session = fsl_vbus_session,
>  	.vbus_draw = fsl_vbus_draw,
>  	.pullup = fsl_pullup,
> -	.start = fsl_start,
> -	.stop = fsl_stop,
> +	.udc_start = fsl_udc_start,
> +	.udc_stop = fsl_udc_stop,
>  };
>  
>  /* Set protocol stall on ep0, protocol stall will automatically be cleared
> @@ -1314,7 +1316,7 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction)
>  			ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
>  	req->mapped = 1;
>  
> -	if (fsl_req_to_dtd(req, GFP_ATOMIC) == 0)
> +	if (fsl_req_to_dtd(udc, req, GFP_ATOMIC) == 0)
>  		fsl_queue_td(ep, req);
>  	else
>  		return -ENOMEM;
> @@ -1398,7 +1400,7 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
>  	req->mapped = 1;
>  
>  	/* prime the data phase */
> -	if ((fsl_req_to_dtd(req, GFP_ATOMIC) == 0))
> +	if ((fsl_req_to_dtd(udc, req, GFP_ATOMIC) == 0))
>  		fsl_queue_td(ep, req);
>  	else			/* no mem */
>  		goto stall;
> @@ -1422,7 +1424,7 @@ static void setup_received_irq(struct fsl_udc *udc,
>  
>  	udc_reset_ep_queue(udc, 0);
>  
> -	/* We process some stardard setup requests here */
> +	/* We process some standard setup requests here */
>  	switch (setup->bRequest) {
>  	case USB_REQ_GET_STATUS:
>  		/* Data+Status phase from udc */
> @@ -1954,114 +1956,82 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
>   * Hook to gadget drivers
>   * Called by initialization code of gadget drivers
>  *----------------------------------------------------------------*/
> -static int fsl_start(struct usb_gadget_driver *driver,
> -		int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
> +static int fsl_udc_start(struct usb_gadget *gadget,
> +	struct usb_gadget_driver *driver)
>  {
> +	struct fsl_udc *udc;
>  	int retval = -ENODEV;
> -	unsigned long flags = 0;
> +	unsigned long flags;
>  
> -	if (!udc_controller)
> +	udc = container_of(gadget, struct fsl_udc, gadget);
> +	if (!udc)
>  		return -ENODEV;
>  
>  	if (!driver || driver->max_speed < USB_SPEED_FULL
> -			|| !bind || !driver->disconnect || !driver->setup)
> +			|| !driver->disconnect || !driver->setup)
>  		return -EINVAL;
>  
> -	if (udc_controller->driver)
> -		return -EBUSY;
> -
>  	/* lock is needed but whether should use this lock or another */
> -	spin_lock_irqsave(&udc_controller->lock, flags);
> +	spin_lock_irqsave(&udc->lock, flags);
>  
>  	driver->driver.bus = NULL;
> -	/* hook up the driver */
> -	udc_controller->driver = driver;
> -	udc_controller->gadget.dev.driver = &driver->driver;
> -	spin_unlock_irqrestore(&udc_controller->lock, flags);
> -
> -	/* bind udc driver to gadget driver */
> -	retval = bind(&udc_controller->gadget, driver);
> -	if (retval) {
> -		VDBG("bind to %s --> %d", driver->driver.name, retval);
> -		udc_controller->gadget.dev.driver = NULL;
> -		udc_controller->driver = NULL;
> -		goto out;
> -	}
>  
> -	if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
> +	if (!IS_ERR_OR_NULL(udc->transceiver)) {
>  		/* Suspend the controller until OTG enable it */
> -		udc_controller->stopped = 1;
> +		udc->stopped = 1;
>  		printk(KERN_INFO "Suspend udc for OTG auto detect\n");
>  
>  		/* connect to bus through transceiver */
> -		if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
> -			retval = otg_set_peripheral(
> -					udc_controller->transceiver->otg,
> -						    &udc_controller->gadget);
> +		if (!IS_ERR_OR_NULL(udc->transceiver)) {
> +			retval = otg_set_peripheral(udc->transceiver->otg,
> +					&udc->gadget);
>  			if (retval < 0) {
>  				ERR("can't bind to transceiver\n");
> -				driver->unbind(&udc_controller->gadget);
> -				udc_controller->gadget.dev.driver = 0;
> -				udc_controller->driver = 0;
>  				return retval;
>  			}
>  		}
>  	} else {
> -		/* Enable DR IRQ reg and set USBCMD reg Run bit */
> -		dr_controller_run(udc_controller);
> -		udc_controller->usb_state = USB_STATE_ATTACHED;
> -		udc_controller->ep0_state = WAIT_FOR_SETUP;
> -		udc_controller->ep0_dir = 0;
> +		/* hook up the driver */
> +		udc->driver = driver;
> +		udc->gadget.dev.driver = &driver->driver;
> +		dr_controller_run(udc);
> +		udc->usb_state = USB_STATE_ATTACHED;
> +		udc->ep0_state = WAIT_FOR_SETUP;
> +		udc->ep0_dir = USB_DIR_OUT;
>  	}
> -	printk(KERN_INFO "%s: bind to driver %s\n",
> -			udc_controller->gadget.name, driver->driver.name);
> +	spin_unlock_irqrestore(&udc->lock, flags);
>  
> -out:
> -	if (retval)
> -		printk(KERN_WARNING "gadget driver register failed %d\n",
> -		       retval);
> -	return retval;
> +	return 0;
>  }
>  
>  /* Disconnect from gadget driver */
> -static int fsl_stop(struct usb_gadget_driver *driver)
> +static int fsl_udc_stop(struct usb_gadget *gadget,
> +	struct usb_gadget_driver *driver)
>  {
> +	struct fsl_udc *udc;
>  	struct fsl_ep *loop_ep;
>  	unsigned long flags;
>  
> -	if (!udc_controller)
> -		return -ENODEV;
> -
> -	if (!driver || driver != udc_controller->driver || !driver->unbind)
> -		return -EINVAL;
> -
> -	if (!IS_ERR_OR_NULL(udc_controller->transceiver))
> -		otg_set_peripheral(udc_controller->transceiver->otg, NULL);
> +	udc = container_of(gadget, struct fsl_udc, gadget);
>  
>  	/* stop DR, disable intr */
> -	dr_controller_stop(udc_controller);
> +	dr_controller_stop(udc);
>  
>  	/* in fact, no needed */
> -	udc_controller->usb_state = USB_STATE_ATTACHED;
> -	udc_controller->ep0_state = WAIT_FOR_SETUP;
> -	udc_controller->ep0_dir = 0;
> +	udc->usb_state = USB_STATE_ATTACHED;
> +	udc->ep0_state = WAIT_FOR_SETUP;
> +	udc->ep0_dir = USB_DIR_OUT;
>  
>  	/* stand operation */
> -	spin_lock_irqsave(&udc_controller->lock, flags);
> -	udc_controller->gadget.speed = USB_SPEED_UNKNOWN;
> -	nuke(&udc_controller->eps[0], -ESHUTDOWN);
> -	list_for_each_entry(loop_ep, &udc_controller->gadget.ep_list,
> -			ep.ep_list)
> +	spin_lock_irqsave(&udc->lock, flags);
> +	udc->gadget.speed = USB_SPEED_UNKNOWN;
> +	nuke(&udc->eps[0], -ESHUTDOWN);
> +	list_for_each_entry(loop_ep, &udc->gadget.ep_list, ep.ep_list)
>  		nuke(loop_ep, -ESHUTDOWN);
> -	spin_unlock_irqrestore(&udc_controller->lock, flags);
> -
> -	/* report disconnect; the controller is already quiesced */
> -	driver->disconnect(&udc_controller->gadget);
> +	spin_unlock_irqrestore(&udc->lock, flags);
>  
> -	/* unbind gadget and unhook driver. */
> -	driver->unbind(&udc_controller->gadget);
> -	udc_controller->gadget.dev.driver = NULL;
> -	udc_controller->driver = NULL;
> +	udc->gadget.dev.driver = NULL;
> +	udc->driver = NULL;
>  
>  	printk(KERN_WARNING "unregistered gadget driver '%s'\n",
>  	       driver->driver.name);
> @@ -2088,8 +2058,8 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	u32 tmp_reg;
>  	struct fsl_ep *ep = NULL;
>  	struct fsl_req *req;
> +	struct fsl_udc *udc = _dev;
>  
> -	struct fsl_udc *udc = udc_controller;
>  	if (off != 0)
>  		return 0;
>  
> @@ -2318,7 +2288,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  }
>  
>  #define create_proc_file()	create_proc_read_entry(proc_filename, \
> -				0, NULL, fsl_proc_read, NULL)
> +				0, NULL, fsl_proc_read, udc)
>  
>  #define remove_proc_file()	remove_proc_entry(proc_filename, NULL)
>  
> @@ -2334,10 +2304,12 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  /* Release udc structures */
>  static void fsl_udc_release(struct device *dev)
>  {
> -	complete(udc_controller->done);
> -	dma_free_coherent(dev->parent, udc_controller->ep_qh_size,
> -			udc_controller->ep_qh, udc_controller->ep_qh_dma);
> -	kfree(udc_controller);
> +	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
> +
> +	complete(udc->done);
> +	dma_free_coherent(dev->parent, udc->ep_qh_size,
> +			udc->ep_qh, udc->ep_qh_dma);
> +	kfree(udc);
>  }
>  
>  /******************************************************************
> @@ -2436,6 +2408,7 @@ static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index,
>   */
>  static int __init fsl_udc_probe(struct platform_device *pdev)
>  {
> +	struct fsl_udc *udc;
>  	struct fsl_usb2_platform_data *pdata;
>  	struct resource *res;
>  	int ret = -ENODEV;
> @@ -2447,21 +2420,21 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  		return -ENODEV;
>  	}
>  
> -	udc_controller = kzalloc(sizeof(struct fsl_udc), GFP_KERNEL);
> -	if (udc_controller == NULL) {
> +	udc = kzalloc(sizeof(struct fsl_udc), GFP_KERNEL);
> +	if (udc == NULL) {
>  		ERR("malloc udc failed\n");
>  		return -ENOMEM;
>  	}
>  
>  	pdata = pdev->dev.platform_data;
> -	udc_controller->pdata = pdata;
> -	spin_lock_init(&udc_controller->lock);
> -	udc_controller->stopped = 1;
> +	udc->pdata = pdata;
> +	spin_lock_init(&udc->lock);
> +	udc->stopped = 1;
>  
>  #ifdef CONFIG_USB_OTG
>  	if (pdata->operating_mode == FSL_USB2_DR_OTG) {
> -		udc_controller->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
> -		if (IS_ERR_OR_NULL(udc_controller->transceiver)) {
> +		udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
> +		if (IS_ERR_OR_NULL(udc->transceiver)) {
>  			ERR("Can't find OTG driver!\n");
>  			ret = -ENODEV;
>  			goto err_kfree;
> @@ -2522,90 +2495,90 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  	}
>  	/* Get max device endpoints */
>  	/* DEN is bidirectional ep number, max_ep doubles the number */
> -	udc_controller->max_ep = (dccparams & DCCPARAMS_DEN_MASK) * 2;
> +	udc->max_ep = (dccparams & DCCPARAMS_DEN_MASK) * 2;
>  
> -	udc_controller->irq = platform_get_irq(pdev, 0);
> -	if (!udc_controller->irq) {
> +	udc->irq = platform_get_irq(pdev, 0);
> +	if (!udc->irq) {
>  		ret = -ENODEV;
>  		goto err_iounmap;
>  	}
>  
> -	ret = request_irq(udc_controller->irq, fsl_udc_irq, IRQF_SHARED,
> -			driver_name, udc_controller);
> +	ret = request_irq(udc->irq, fsl_udc_irq, IRQF_SHARED,
> +			driver_name, udc);
>  	if (ret != 0) {
>  		ERR("cannot request irq %d err %d\n",
> -				udc_controller->irq, ret);
> +				udc->irq, ret);
>  		goto err_iounmap;
>  	}
>  
>  	/* Initialize the udc structure including QH member and other member */
> -	if (struct_udc_setup(udc_controller, pdev)) {
> +	if (struct_udc_setup(udc, pdev)) {
>  		ERR("Can't initialize udc data structure\n");
>  		ret = -ENOMEM;
>  		goto err_free_irq;
>  	}
>  
> -	if (IS_ERR_OR_NULL(udc_controller->transceiver)) {
> +	if (IS_ERR_OR_NULL(udc->transceiver)) {
>  		/* initialize usb hw reg except for regs for EP,
>  		 * leave usbintr reg untouched */
> -		dr_controller_setup(udc_controller);
> +		dr_controller_setup(udc);
>  	}
>  
>  	fsl_udc_clk_finalize(pdev);
>  
>  	/* Setup gadget structure */
> -	udc_controller->gadget.ops = &fsl_gadget_ops;
> -	udc_controller->gadget.max_speed = USB_SPEED_HIGH;
> -	udc_controller->gadget.ep0 = &udc_controller->eps[0].ep;
> -	INIT_LIST_HEAD(&udc_controller->gadget.ep_list);
> -	udc_controller->gadget.speed = USB_SPEED_UNKNOWN;
> -	udc_controller->gadget.name = driver_name;
> +	udc->gadget.ops = &fsl_gadget_ops;
> +	udc->gadget.max_speed = USB_SPEED_HIGH;
> +	udc->gadget.ep0 = &udc->eps[0].ep;
> +	INIT_LIST_HEAD(&udc->gadget.ep_list);
> +	udc->gadget.speed = USB_SPEED_UNKNOWN;
> +	udc->gadget.name = driver_name;
>  	udc->vbus_active = true;
>  
>  	/* Setup gadget.dev and register with kernel */
> -	dev_set_name(&udc_controller->gadget.dev, "gadget");
> -	udc_controller->gadget.dev.release = fsl_udc_release;
> -	udc_controller->gadget.dev.parent = &pdev->dev;
> -	udc_controller->gadget.dev.of_node = pdev->dev.of_node;
> -	ret = device_register(&udc_controller->gadget.dev);
> +	dev_set_name(&udc->gadget.dev, "gadget");
> +	udc->gadget.dev.release = fsl_udc_release;
> +	udc->gadget.dev.parent = &pdev->dev;
> +	udc->gadget.dev.of_node = pdev->dev.of_node;
> +	ret = device_register(&udc->gadget.dev);
>  	if (ret < 0)
>  		goto err_free_irq;
>  
> -	if (!IS_ERR_OR_NULL(udc_controller->transceiver))
> -		udc_controller->gadget.is_otg = 1;
> +	if (!IS_ERR_OR_NULL(udc->transceiver))
> +		udc->gadget.is_otg = 1;
>  
>  	/* setup QH and epctrl for ep0 */
> -	ep0_setup(udc_controller);
> +	ep0_setup(udc);
>  
>  	/* setup udc->eps[] for ep0 */
> -	struct_ep_setup(udc_controller, 0, "ep0", 0);
> +	struct_ep_setup(udc, 0, "ep0", 0);
>  	/* for ep0: the desc defined here;
>  	 * for other eps, gadget layer called ep_enable with defined desc
>  	 */
> -	udc_controller->eps[0].ep.desc = &fsl_ep0_desc;
> -	udc_controller->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD;
> +	udc->eps[0].ep.desc = &fsl_ep0_desc;
> +	udc->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD;
>  
>  	/* setup the udc->eps[] for non-control endpoints and link
>  	 * to gadget.ep_list */
> -	for (i = 1; i < (int)(udc_controller->max_ep / 2); i++) {
> +	for (i = 1; i < (int)(udc->max_ep / 2); i++) {
>  		char name[14];
>  
>  		sprintf(name, "ep%dout", i);
> -		struct_ep_setup(udc_controller, i * 2, name, 1);
> +		struct_ep_setup(udc, i * 2, name, 1);
>  		sprintf(name, "ep%din", i);
> -		struct_ep_setup(udc_controller, i * 2 + 1, name, 1);
> +		struct_ep_setup(udc, i * 2 + 1, name, 1);
>  	}
>  
>  	/* use dma_pool for TD management */
> -	udc_controller->td_pool = dma_pool_create("udc_td", &pdev->dev,
> +	udc->td_pool = dma_pool_create("udc_td", &pdev->dev,
>  			sizeof(struct ep_td_struct),
>  			DTD_ALIGNMENT, UDC_DMA_BOUNDARY);
> -	if (udc_controller->td_pool == NULL) {
> +	if (udc->td_pool == NULL) {
>  		ret = -ENOMEM;
>  		goto err_unregister;
>  	}
>  
> -	ret = usb_add_gadget_udc(&pdev->dev, &udc_controller->gadget);
> +	ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
>  	if (ret)
>  		goto err_del_udc;
>  
> @@ -2613,11 +2586,11 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  	return 0;
>  
>  err_del_udc:
> -	dma_pool_destroy(udc_controller->td_pool);
> +	dma_pool_destroy(udc->td_pool);
>  err_unregister:
> -	device_unregister(&udc_controller->gadget.dev);
> +	device_unregister(&udc->gadget.dev);
>  err_free_irq:
> -	free_irq(udc_controller->irq, udc_controller);
> +	free_irq(udc->irq, udc);
>  err_iounmap:
>  	if (pdata->exit)
>  		pdata->exit(pdev);
> @@ -2628,8 +2601,7 @@ err_release_mem_region:
>  	if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
>  		release_mem_region(res->start, resource_size(res));
>  err_kfree:
> -	kfree(udc_controller);
> -	udc_controller = NULL;
> +	kfree(udc);
>  	return ret;
>  }
>  
> @@ -2638,16 +2610,13 @@ err_kfree:
>   */
>  static int __exit fsl_udc_remove(struct platform_device *pdev)
>  {
> +	struct fsl_udc *udc = dev_get_drvdata(&pdev->dev);
>  	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
> -
>  	DECLARE_COMPLETION(done);
>  
> -	if (!udc_controller)
> -		return -ENODEV;
> -
> -	usb_del_gadget_udc(&udc_controller->gadget);
> -	udc_controller->done = &done;
> +	usb_del_gadget_udc(&udc->gadget);
> +	udc->done = &done;
>  
>  	fsl_udc_clk_release();
>  
> @@ -2655,17 +2624,17 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
>  	remove_proc_file();
>  
>  	/* Free allocated memory */
> -	kfree(udc_controller->status_req->req.buf);
> -	kfree(udc_controller->status_req);
> -	kfree(udc_controller->eps);
> +	kfree(udc->status_req->req.buf);
> +	kfree(udc->status_req);
> +	kfree(udc->eps);
>  
> -	dma_pool_destroy(udc_controller->td_pool);
> -	free_irq(udc_controller->irq, udc_controller);
> +	dma_pool_destroy(udc->td_pool);
> +	free_irq(udc->irq, udc);
>  	iounmap(dr_regs);
>  	if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
>  		release_mem_region(res->start, resource_size(res));
>  
> -	device_unregister(&udc_controller->gadget.dev);
> +	device_unregister(&udc->gadget.dev);
>  	/* free udc --wait for the release() finished */
>  	wait_for_completion(&done);
>  
> @@ -2685,7 +2654,8 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
>   -----------------------------------------------------------------*/
>  static int fsl_udc_suspend(struct platform_device *pdev, pm_message_t state)
>  {
> -	dr_controller_stop(udc_controller);
> +	struct fsl_udc *udc = dev_get_drvdata(&pdev->dev);
> +	dr_controller_stop(udc);
>  	return 0;
>  }
>  
> @@ -2695,20 +2665,21 @@ static int fsl_udc_suspend(struct platform_device *pdev, pm_message_t state)
>   *-----------------------------------------------------------------*/
>  static int fsl_udc_resume(struct platform_device *pdev)
>  {
> +	struct fsl_udc *udc = dev_get_drvdata(&pdev->dev);
>  	/* Enable DR irq reg and set controller Run */
> -	if (udc_controller->stopped) {
> -		dr_controller_setup(udc_controller);
> -		dr_controller_run(udc_controller);
> +	if (udc->stopped) {
> +		dr_controller_setup(udc);
> +		dr_controller_run(udc);
>  	}
> -	udc_controller->usb_state = USB_STATE_ATTACHED;
> -	udc_controller->ep0_state = WAIT_FOR_SETUP;
> -	udc_controller->ep0_dir = 0;
> +	udc->usb_state = USB_STATE_ATTACHED;
> +	udc->ep0_state = WAIT_FOR_SETUP;
> +	udc->ep0_dir = USB_DIR_OUT;
>  	return 0;
>  }
>  
>  static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
>  {
> -	struct fsl_udc *udc = udc_controller;
> +	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
>  	u32 mode, usbcmd;
>  
>  	mode = fsl_readl(&dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
> @@ -2744,15 +2715,17 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
>  
>  static int fsl_udc_otg_resume(struct device *dev)
>  {
> +	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
> +
>  	pr_debug("%s(): stopped %d  already_stopped %d\n", __func__,
> -		 udc_controller->stopped, udc_controller->already_stopped);
> +		 udc->stopped, udc->already_stopped);
>  
>  	/*
>  	 * If the controller was stopped at suspend time, then
>  	 * don't resume it now.
>  	 */
> -	if (udc_controller->already_stopped) {
> -		udc_controller->already_stopped = 0;
> +	if (udc->already_stopped) {
> +		udc->already_stopped = 0;
>  		pr_debug("gadget was already stopped, leaving early\n");
>  		return 0;
>  	}
> -- 
> 1.7.2.5
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply

* Re: [PATCH 4/7] usb: gadget: fsl_udc: drop ARCH dependency
From: Felipe Balbi @ 2012-10-19 10:29 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Felipe Balbi,
	Hans J. Koch, Daniel Mack, Christian Hemp, linuxppc-dev,
	Teresa Gamez, Sebastian Andrzej Siewior
In-Reply-To: <1350642285-8145-4-git-send-email-chf.fritz@googlemail.com>

[-- Attachment #1: Type: text/plain, Size: 33369 bytes --]

On Fri, Oct 19, 2012 at 12:24:42PM +0200, Christoph Fritz wrote:
> Drop the big-/little-endian helpers and make use of generic
> writel()/readl() routines.
> 
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |  331 +++++++++++++------------------------
>  1 files changed, 118 insertions(+), 213 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index d113f39..53df9c0 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -20,32 +20,14 @@
>  #undef VERBOSE
>  
>  #include <linux/module.h>
> -#include <linux/kernel.h>
> -#include <linux/ioport.h>
> -#include <linux/types.h>
> -#include <linux/errno.h>
> -#include <linux/err.h>
> -#include <linux/slab.h>
> -#include <linux/init.h>
> -#include <linux/list.h>

you don't mention removal of these registers anywhere. Why are you
doing this ? Are those really unnecessary or are you now depending on
indirect inclusion of the headers ?

Also, $SUBJECT is a bit misleading since you don't touch Kconfig to
actually drop the ARCH dependency. Maybe rephrase $SUBJECT a little ?

>  #include <linux/interrupt.h>
>  #include <linux/proc_fs.h>
> -#include <linux/mm.h>
> -#include <linux/moduleparam.h>
> -#include <linux/device.h>
> -#include <linux/usb/ch9.h>
>  #include <linux/usb/gadget.h>
>  #include <linux/usb/otg.h>
>  #include <linux/dma-mapping.h>
>  #include <linux/platform_device.h>
>  #include <linux/fsl_devices.h>
>  #include <linux/dmapool.h>
> -#include <linux/delay.h>
> -
> -#include <asm/byteorder.h>
> -#include <asm/io.h>
> -#include <asm/unaligned.h>
> -#include <asm/dma.h>
>  
>  #include "fsl_usb2_udc.h"
>  
> @@ -74,78 +56,6 @@ fsl_ep0_desc = {
>  
>  static void fsl_ep_fifo_flush(struct usb_ep *_ep);
>  
> -#ifdef CONFIG_PPC32
> -/*
> - * On some SoCs, the USB controller registers can be big or little endian,
> - * depending on the version of the chip. In order to be able to run the
> - * same kernel binary on 2 different versions of an SoC, the BE/LE decision
> - * must be made at run time. _fsl_readl and fsl_writel are pointers to the
> - * BE or LE readl() and writel() functions, and fsl_readl() and fsl_writel()
> - * call through those pointers. Platform code for SoCs that have BE USB
> - * registers should set pdata->big_endian_mmio flag.
> - *
> - * This also applies to controller-to-cpu accessors for the USB descriptors,
> - * since their endianness is also SoC dependant. Platform code for SoCs that
> - * have BE USB descriptors should set pdata->big_endian_desc flag.
> - */
> -static u32 _fsl_readl_be(const unsigned __iomem *p)
> -{
> -	return in_be32(p);
> -}
> -
> -static u32 _fsl_readl_le(const unsigned __iomem *p)
> -{
> -	return in_le32(p);
> -}
> -
> -static void _fsl_writel_be(u32 v, unsigned __iomem *p)
> -{
> -	out_be32(p, v);
> -}
> -
> -static void _fsl_writel_le(u32 v, unsigned __iomem *p)
> -{
> -	out_le32(p, v);
> -}
> -
> -static u32 (*_fsl_readl)(const unsigned __iomem *p);
> -static void (*_fsl_writel)(u32 v, unsigned __iomem *p);
> -
> -#define fsl_readl(p)		(*_fsl_readl)((p))
> -#define fsl_writel(v, p)	(*_fsl_writel)((v), (p))
> -
> -static inline void fsl_set_accessors(struct fsl_usb2_platform_data *pdata)
> -{
> -	if (pdata->big_endian_mmio) {
> -		_fsl_readl = _fsl_readl_be;
> -		_fsl_writel = _fsl_writel_be;
> -	} else {
> -		_fsl_readl = _fsl_readl_le;
> -		_fsl_writel = _fsl_writel_le;
> -	}
> -}
> -
> -static inline u32 cpu_to_hc32(const u32 x)
> -{
> -	return udc_controller->pdata->big_endian_desc
> -		? (__force u32)cpu_to_be32(x)
> -		: (__force u32)cpu_to_le32(x);
> -}
> -
> -static inline u32 hc32_to_cpu(const u32 x)
> -{
> -	return udc_controller->pdata->big_endian_desc
> -		? be32_to_cpu((__force __be32)x)
> -		: le32_to_cpu((__force __le32)x);
> -}
> -#else /* !CONFIG_PPC32 */
> -static inline void fsl_set_accessors(struct fsl_usb2_platform_data *pdata) {}
> -
> -#define fsl_readl(addr)		readl(addr)
> -#define fsl_writel(val32, addr) writel(val32, addr)
> -#define cpu_to_hc32(x)		cpu_to_le32(x)
> -#define hc32_to_cpu(x)		le32_to_cpu(x)
> -#endif /* CONFIG_PPC32 */
>  
>  /********************************************************************
>   *	Internal Used Function
> @@ -248,7 +158,7 @@ static int dr_controller_setup(struct fsl_udc *udc)
>  #define FSL_UDC_RESET_TIMEOUT 1000
>  
>  	/* Config PHY interface */
> -	portctrl = fsl_readl(&dr_regs->portsc1);
> +	portctrl = readl(&dr_regs->portsc1);
>  	portctrl &= ~(PORTSCX_PHY_TYPE_SEL | PORTSCX_PORT_WIDTH);
>  	switch (udc->phy_mode) {
>  	case FSL_USB2_PHY_ULPI:
> @@ -286,20 +196,20 @@ static int dr_controller_setup(struct fsl_udc *udc)
>  	default:
>  		return -EINVAL;
>  	}
> -	fsl_writel(portctrl, &dr_regs->portsc1);
> +	writel(portctrl, &dr_regs->portsc1);
>  
>  	/* Stop and reset the usb controller */
> -	tmp = fsl_readl(&dr_regs->usbcmd);
> +	tmp = readl(&dr_regs->usbcmd);
>  	tmp &= ~USB_CMD_RUN_STOP;
> -	fsl_writel(tmp, &dr_regs->usbcmd);
> +	writel(tmp, &dr_regs->usbcmd);
>  
> -	tmp = fsl_readl(&dr_regs->usbcmd);
> +	tmp = readl(&dr_regs->usbcmd);
>  	tmp |= USB_CMD_CTRL_RESET;
> -	fsl_writel(tmp, &dr_regs->usbcmd);
> +	writel(tmp, &dr_regs->usbcmd);
>  
>  	/* Wait for reset to complete */
>  	timeout = jiffies + FSL_UDC_RESET_TIMEOUT;
> -	while (fsl_readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) {
> +	while (readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) {
>  		if (time_after(jiffies, timeout)) {
>  			ERR("udc reset timeout!\n");
>  			return -ETIMEDOUT;
> @@ -308,33 +218,33 @@ static int dr_controller_setup(struct fsl_udc *udc)
>  	}
>  
>  	/* Set the controller as device mode */
> -	tmp = fsl_readl(&dr_regs->usbmode);
> +	tmp = readl(&dr_regs->usbmode);
>  	tmp &= ~USB_MODE_CTRL_MODE_MASK;	/* clear mode bits */
>  	tmp |= USB_MODE_CTRL_MODE_DEVICE;
>  	/* Disable Setup Lockout */
>  	tmp |= USB_MODE_SETUP_LOCK_OFF;
>  	if (udc->pdata->es)
>  		tmp |= USB_MODE_ES;
> -	fsl_writel(tmp, &dr_regs->usbmode);
> +	writel(tmp, &dr_regs->usbmode);
>  
>  	/* Clear the setup status */
> -	fsl_writel(0, &dr_regs->usbsts);
> +	writel(0, &dr_regs->usbsts);
>  
>  	tmp = udc->ep_qh_dma;
>  	tmp &= USB_EP_LIST_ADDRESS_MASK;
> -	fsl_writel(tmp, &dr_regs->endpointlistaddr);
> +	writel(tmp, &dr_regs->endpointlistaddr);
>  
>  	VDBG("vir[qh_base] is %p phy[qh_base] is 0x%8x reg is 0x%8x",
>  		udc->ep_qh, (int)tmp,
> -		fsl_readl(&dr_regs->endpointlistaddr));
> +		readl(&dr_regs->endpointlistaddr));
>  
> -	max_no_of_ep = (0x0000001F & fsl_readl(&dr_regs->dccparams));
> +	max_no_of_ep = (0x0000001F & readl(&dr_regs->dccparams));
>  	for (ep_num = 1; ep_num < max_no_of_ep; ep_num++) {
> -		tmp = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +		tmp = readl(&dr_regs->endptctrl[ep_num]);
>  		tmp &= ~(EPCTRL_TX_TYPE | EPCTRL_RX_TYPE);
>  		tmp |= (EPCTRL_EP_TYPE_BULK << EPCTRL_TX_EP_TYPE_SHIFT)
>  		| (EPCTRL_EP_TYPE_BULK << EPCTRL_RX_EP_TYPE_SHIFT);
> -		fsl_writel(tmp, &dr_regs->endptctrl[ep_num]);
> +		writel(tmp, &dr_regs->endptctrl[ep_num]);
>  	}
>  	/* Config control enable i/o output, cpu endian register */
>  #ifndef CONFIG_ARCH_MXC
> @@ -371,20 +281,20 @@ static void dr_controller_run(struct fsl_udc *udc)
>  		| USB_INTR_PTC_DETECT_EN | USB_INTR_RESET_EN
>  		| USB_INTR_DEVICE_SUSPEND | USB_INTR_SYS_ERR_EN;
>  
> -	fsl_writel(temp, &dr_regs->usbintr);
> +	writel(temp, &dr_regs->usbintr);
>  
>  	/* Clear stopped bit */
>  	udc->stopped = 0;
>  
>  	/* Set the controller as device mode */
> -	temp = fsl_readl(&dr_regs->usbmode);
> +	temp = readl(&dr_regs->usbmode);
>  	temp |= USB_MODE_CTRL_MODE_DEVICE;
> -	fsl_writel(temp, &dr_regs->usbmode);
> +	writel(temp, &dr_regs->usbmode);
>  
>  	/* Set controller to Run */
> -	temp = fsl_readl(&dr_regs->usbcmd);
> +	temp = readl(&dr_regs->usbcmd);
>  	temp |= USB_CMD_RUN_STOP;
> -	fsl_writel(temp, &dr_regs->usbcmd);
> +	writel(temp, &dr_regs->usbcmd);
>  }
>  
>  static void dr_controller_stop(struct fsl_udc *udc)
> @@ -398,14 +308,14 @@ static void dr_controller_stop(struct fsl_udc *udc)
>  	 * ehci driver
>  	 */
>  	if (udc->gadget.is_otg) {
> -		if (!(fsl_readl(&dr_regs->otgsc) & OTGSC_STS_USB_ID)) {
> +		if (!(readl(&dr_regs->otgsc) & OTGSC_STS_USB_ID)) {
>  			pr_debug("udc: Leaving early\n");
>  			return;
>  		}
>  	}
>  
>  	/* disable all INTR */
> -	fsl_writel(0, &dr_regs->usbintr);
> +	writel(0, &dr_regs->usbintr);
>  
>  	/* Set stopped bit for isr */
>  	udc->stopped = 1;
> @@ -414,9 +324,9 @@ static void dr_controller_stop(struct fsl_udc *udc)
>  /*	usb_sys_regs->control = 0; */
>  
>  	/* set controller to Stop */
> -	tmp = fsl_readl(&dr_regs->usbcmd);
> +	tmp = readl(&dr_regs->usbcmd);
>  	tmp &= ~USB_CMD_RUN_STOP;
> -	fsl_writel(tmp, &dr_regs->usbcmd);
> +	writel(tmp, &dr_regs->usbcmd);
>  }
>  
>  static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
> @@ -424,7 +334,7 @@ static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
>  {
>  	unsigned int tmp_epctrl = 0;
>  
> -	tmp_epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +	tmp_epctrl = readl(&dr_regs->endptctrl[ep_num]);
>  	if (dir) {
>  		if (ep_num)
>  			tmp_epctrl |= EPCTRL_TX_DATA_TOGGLE_RST;
> @@ -441,7 +351,7 @@ static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
>  				<< EPCTRL_RX_EP_TYPE_SHIFT);
>  	}
>  
> -	fsl_writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
> +	writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
>  }
>  
>  static void
> @@ -449,7 +359,7 @@ dr_ep_change_stall(unsigned char ep_num, unsigned char dir, int value)
>  {
>  	u32 tmp_epctrl = 0;
>  
> -	tmp_epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +	tmp_epctrl = readl(&dr_regs->endptctrl[ep_num]);
>  
>  	if (value) {
>  		/* set the stall bit */
> @@ -467,7 +377,7 @@ dr_ep_change_stall(unsigned char ep_num, unsigned char dir, int value)
>  			tmp_epctrl |= EPCTRL_RX_DATA_TOGGLE_RST;
>  		}
>  	}
> -	fsl_writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
> +	writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
>  }
>  
>  /* Get stall status of a specific ep
> @@ -476,7 +386,7 @@ static int dr_ep_get_stall(unsigned char ep_num, unsigned char dir)
>  {
>  	u32 epctrl;
>  
> -	epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +	epctrl = readl(&dr_regs->endptctrl[ep_num]);
>  	if (dir)
>  		return (epctrl & EPCTRL_TX_EP_STALL) ? 1 : 0;
>  	else
> @@ -522,7 +432,7 @@ static void struct_ep_qh_setup(struct fsl_udc *udc, unsigned char ep_num,
>  	if (zlt)
>  		tmp |= EP_QUEUE_HEAD_ZLT_SEL;
>  
> -	p_QH->max_pkt_length = cpu_to_hc32(tmp);
> +	p_QH->max_pkt_length = cpu_to_le32(tmp);
>  	p_QH->next_dtd_ptr = 1;
>  	p_QH->size_ioc_int_sts = 0;
>  }
> @@ -658,7 +568,7 @@ static int fsl_ep_disable(struct usb_ep *_ep)
>  
>  	/* disable ep on controller */
>  	ep_num = ep_index(ep);
> -	epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +	epctrl = readl(&dr_regs->endptctrl[ep_num]);
>  	if (ep_is_in(ep)) {
>  		epctrl &= ~(EPCTRL_TX_ENABLE | EPCTRL_TX_TYPE);
>  		epctrl |= EPCTRL_EP_TYPE_BULK << EPCTRL_TX_EP_TYPE_SHIFT;
> @@ -666,7 +576,7 @@ static int fsl_ep_disable(struct usb_ep *_ep)
>  		epctrl &= ~(EPCTRL_RX_ENABLE | EPCTRL_TX_TYPE);
>  		epctrl |= EPCTRL_EP_TYPE_BULK << EPCTRL_RX_EP_TYPE_SHIFT;
>  	}
> -	fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
> +	writel(epctrl, &dr_regs->endptctrl[ep_num]);
>  
>  	udc = (struct fsl_udc *)ep->udc;
>  	spin_lock_irqsave(&udc->lock, flags);
> @@ -718,18 +628,18 @@ static void fsl_prime_ep(struct fsl_ep *ep, struct ep_td_struct *td)
>  	struct ep_queue_head *qh = get_qh_by_ep(ep);
>  
>  	/* Write dQH next pointer and terminate bit to 0 */
> -	qh->next_dtd_ptr = cpu_to_hc32(td->td_dma
> +	qh->next_dtd_ptr = cpu_to_le32(td->td_dma
>  			& EP_QUEUE_HEAD_NEXT_POINTER_MASK);
>  
>  	/* Clear active and halt bit */
> -	qh->size_ioc_int_sts &= cpu_to_hc32(~(EP_QUEUE_HEAD_STATUS_ACTIVE
> +	qh->size_ioc_int_sts &= cpu_to_le32(~(EP_QUEUE_HEAD_STATUS_ACTIVE
>  					| EP_QUEUE_HEAD_STATUS_HALT));
>  
>  	/* Ensure that updates to the QH will occur before priming. */
>  	wmb();
>  
>  	/* Prime endpoint by writing correct bit to ENDPTPRIME */
> -	fsl_writel(ep_is_in(ep) ? (1 << (ep_index(ep) + 16))
> +	writel(ep_is_in(ep) ? (1 << (ep_index(ep) + 16))
>  			: (1 << (ep_index(ep))), &dr_regs->endpointprime);
>  }
>  
> @@ -751,26 +661,26 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
>  		struct fsl_req *lastreq;
>  		lastreq = list_entry(ep->queue.prev, struct fsl_req, queue);
>  		lastreq->tail->next_td_ptr =
> -			cpu_to_hc32(req->head->td_dma & DTD_ADDR_MASK);
> +			cpu_to_le32(req->head->td_dma & DTD_ADDR_MASK);
>  		/* Ensure dTD's next dtd pointer to be updated */
>  		wmb();
>  		/* Read prime bit, if 1 goto done */
> -		if (fsl_readl(&dr_regs->endpointprime) & bitmask)
> +		if (readl(&dr_regs->endpointprime) & bitmask)
>  			return;
>  
>  		do {
>  			/* Set ATDTW bit in USBCMD */
> -			temp = fsl_readl(&dr_regs->usbcmd);
> -			fsl_writel(temp | USB_CMD_ATDTW, &dr_regs->usbcmd);
> +			temp = readl(&dr_regs->usbcmd);
> +			writel(temp | USB_CMD_ATDTW, &dr_regs->usbcmd);
>  
>  			/* Read correct status bit */
> -			tmp_stat = fsl_readl(&dr_regs->endptstatus) & bitmask;
> +			tmp_stat = readl(&dr_regs->endptstatus) & bitmask;
>  
> -		} while (!(fsl_readl(&dr_regs->usbcmd) & USB_CMD_ATDTW));
> +		} while (!(readl(&dr_regs->usbcmd) & USB_CMD_ATDTW));
>  
>  		/* Write ATDTW bit to 0 */
> -		temp = fsl_readl(&dr_regs->usbcmd);
> -		fsl_writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd);
> +		temp = readl(&dr_regs->usbcmd);
> +		writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd);
>  
>  		if (tmp_stat)
>  			return;
> @@ -803,17 +713,17 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_udc *udc,
>  
>  	dtd->td_dma = *dma;
>  	/* Clear reserved field */
> -	swap_temp = hc32_to_cpu(dtd->size_ioc_sts);
> +	swap_temp = dtd->size_ioc_sts;
>  	swap_temp &= ~DTD_RESERVED_FIELDS;
> -	dtd->size_ioc_sts = cpu_to_hc32(swap_temp);
> +	dtd->size_ioc_sts = cpu_to_le32(swap_temp);
>  
>  	/* Init all of buffer page pointers */
>  	swap_temp = (u32) (req->req.dma + req->req.actual);
> -	dtd->buff_ptr0 = cpu_to_hc32(swap_temp);
> -	dtd->buff_ptr1 = cpu_to_hc32(swap_temp + 0x1000);
> -	dtd->buff_ptr2 = cpu_to_hc32(swap_temp + 0x2000);
> -	dtd->buff_ptr3 = cpu_to_hc32(swap_temp + 0x3000);
> -	dtd->buff_ptr4 = cpu_to_hc32(swap_temp + 0x4000);
> +	dtd->buff_ptr0 = cpu_to_le32(swap_temp);
> +	dtd->buff_ptr1 = cpu_to_le32(swap_temp + 0x1000);
> +	dtd->buff_ptr2 = cpu_to_le32(swap_temp + 0x2000);
> +	dtd->buff_ptr3 = cpu_to_le32(swap_temp + 0x3000);
> +	dtd->buff_ptr4 = cpu_to_le32(swap_temp + 0x4000);
>  
>  	req->req.actual += *length;
>  
> @@ -837,7 +747,7 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_udc *udc,
>  	if (*is_last && !req->req.no_interrupt)
>  		swap_temp |= DTD_IOC;
>  
> -	dtd->size_ioc_sts = cpu_to_hc32(swap_temp);
> +	dtd->size_ioc_sts = cpu_to_le32(swap_temp);
>  
>  	mb();
>  
> @@ -866,7 +776,7 @@ static int fsl_req_to_dtd(struct fsl_udc *udc, struct fsl_req *req,
>  			is_first = 0;
>  			req->head = dtd;
>  		} else {
> -			last_dtd->next_td_ptr = cpu_to_hc32(dma);
> +			last_dtd->next_td_ptr = cpu_to_le32(dma);
>  			last_dtd->next_td_virt = dtd;
>  		}
>  		last_dtd = dtd;
> @@ -874,7 +784,7 @@ static int fsl_req_to_dtd(struct fsl_udc *udc, struct fsl_req *req,
>  		req->dtd_count++;
>  	} while (!is_last);
>  
> -	dtd->next_td_ptr = cpu_to_hc32(DTD_NEXT_TERMINATE);
> +	dtd->next_td_ptr = cpu_to_le32(DTD_NEXT_TERMINATE);
>  
>  	req->tail = dtd;
>  
> @@ -966,12 +876,12 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
>  	/* Stop the ep before we deal with the queue */
>  	ep->stopped = 1;
>  	ep_num = ep_index(ep);
> -	epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +	epctrl = readl(&dr_regs->endptctrl[ep_num]);
>  	if (ep_is_in(ep))
>  		epctrl &= ~EPCTRL_TX_ENABLE;
>  	else
>  		epctrl &= ~EPCTRL_RX_ENABLE;
> -	fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
> +	writel(epctrl, &dr_regs->endptctrl[ep_num]);
>  
>  	/* make sure it's actually queued on this endpoint */
>  	list_for_each_entry(req, &ep->queue, queue) {
> @@ -1009,12 +919,12 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
>  	done(ep, req, -ECONNRESET);
>  
>  	/* Enable EP */
> -out:	epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +out:	epctrl = readl(&dr_regs->endptctrl[ep_num]);
>  	if (ep_is_in(ep))
>  		epctrl |= EPCTRL_TX_ENABLE;
>  	else
>  		epctrl |= EPCTRL_RX_ENABLE;
> -	fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
> +	writel(epctrl, &dr_regs->endptctrl[ep_num]);
>  	ep->stopped = stopped;
>  
>  	spin_unlock_irqrestore(&ep->udc->lock, flags);
> @@ -1096,7 +1006,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
>  	bitmask = (ep_is_in(ep)) ? (1 << (ep_index(ep) + 16)) :
>  	    (1 << (ep_index(ep)));
>  
> -	if (fsl_readl(&dr_regs->endptstatus) & bitmask)
> +	if (readl(&dr_regs->endptstatus) & bitmask)
>  		size = (qh->size_ioc_int_sts & DTD_PACKET_SIZE)
>  		    >> DTD_LENGTH_BIT_POS;
>  
> @@ -1131,10 +1041,10 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep)
>  
>  	timeout = jiffies + FSL_UDC_FLUSH_TIMEOUT;
>  	do {
> -		fsl_writel(bits, &dr_regs->endptflush);
> +		writel(bits, &dr_regs->endptflush);
>  
>  		/* Wait until flush complete */
> -		while (fsl_readl(&dr_regs->endptflush)) {
> +		while (readl(&dr_regs->endptflush)) {
>  			if (time_after(jiffies, timeout)) {
>  				ERR("ep flush timeout\n");
>  				return;
> @@ -1142,7 +1052,7 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep)
>  			cpu_relax();
>  		}
>  		/* See if we need to flush again */
> -	} while (fsl_readl(&dr_regs->endptstatus) & bits);
> +	} while (readl(&dr_regs->endptstatus) & bits);
>  }
>  
>  static struct usb_ep_ops fsl_ep_ops = {
> @@ -1169,7 +1079,7 @@ static struct usb_ep_ops fsl_ep_ops = {
>   *----------------------------------------------------------------------*/
>  static int fsl_get_frame(struct usb_gadget *gadget)
>  {
> -	return (int)(fsl_readl(&dr_regs->frindex) & USB_FRINDEX_MASKS);
> +	return (int)(readl(&dr_regs->frindex) & USB_FRINDEX_MASKS);
>  }
>  
>  /*-----------------------------------------------------------------------
> @@ -1184,13 +1094,13 @@ static int fsl_wakeup(struct usb_gadget *gadget)
>  	if (!udc->remote_wakeup)
>  		return -ENOTSUPP;
>  
> -	portsc = fsl_readl(&dr_regs->portsc1);
> +	portsc = readl(&dr_regs->portsc1);
>  	/* not suspended? */
>  	if (!(portsc & PORTSCX_PORT_SUSPEND))
>  		return 0;
>  	/* trigger force resume */
>  	portsc |= PORTSCX_PORT_FORCE_RESUME;
> -	fsl_writel(portsc, &dr_regs->portsc1);
> +	writel(portsc, &dr_regs->portsc1);
>  	return 0;
>  }
>  
> @@ -1211,10 +1121,10 @@ static int fsl_vbus_session(struct usb_gadget *gadget, int is_active)
>  	VDBG("VBUS %s", is_active ? "on" : "off");
>  	udc->vbus_active = (is_active != 0);
>  	if (can_pullup(udc))
> -		fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
> +		writel((readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
>  				&dr_regs->usbcmd);
>  	else
> -		fsl_writel((fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
> +		writel((readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
>  				&dr_regs->usbcmd);
>  	spin_unlock_irqrestore(&udc->lock, flags);
>  	return 0;
> @@ -1249,10 +1159,10 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
>  	spin_lock_irqsave(&udc->lock, flags);
>  	udc->softconnect = (is_on != 0);
>  	if (can_pullup(udc))
> -		fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
> +		writel((readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
>  				&dr_regs->usbcmd);
>  	else
> -		fsl_writel((fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
> +		writel((readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
>  				&dr_regs->usbcmd);
>  	spin_unlock_irqrestore(&udc->lock, flags);
>  
> @@ -1282,9 +1192,9 @@ static void ep0stall(struct fsl_udc *udc)
>  	u32 tmp;
>  
>  	/* must set tx and rx to stall at the same time */
> -	tmp = fsl_readl(&dr_regs->endptctrl[0]);
> +	tmp = readl(&dr_regs->endptctrl[0]);
>  	tmp |= EPCTRL_TX_EP_STALL | EPCTRL_RX_EP_STALL;
> -	fsl_writel(tmp, &dr_regs->endptctrl[0]);
> +	writel(tmp, &dr_regs->endptctrl[0]);
>  	udc->ep0_state = WAIT_FOR_SETUP;
>  	udc->ep0_dir = 0;
>  }
> @@ -1494,8 +1404,8 @@ static void setup_received_irq(struct fsl_udc *udc,
>  			u32 tmp;
>  
>  			mdelay(10);
> -			tmp = fsl_readl(&dr_regs->portsc1) | (ptc << 16);
> -			fsl_writel(tmp, &dr_regs->portsc1);
> +			tmp = readl(&dr_regs->portsc1) | (ptc << 16);
> +			writel(tmp, &dr_regs->portsc1);
>  			printk(KERN_INFO "udc: switch to test mode %d.\n", ptc);
>  		}
>  
> @@ -1546,7 +1456,7 @@ static void ep0_req_complete(struct fsl_udc *udc, struct fsl_ep *ep0,
>  	if (udc->usb_state == USB_STATE_ADDRESS) {
>  		/* Set the new address */
>  		u32 new_address = (u32) udc->device_address;
> -		fsl_writel(new_address << USB_DEVICE_ADDRESS_BIT_POS,
> +		writel(new_address << USB_DEVICE_ADDRESS_BIT_POS,
>  				&dr_regs->deviceaddr);
>  	}
>  
> @@ -1585,14 +1495,14 @@ static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
>  	qh = &udc->ep_qh[ep_num * 2 + EP_DIR_OUT];
>  
>  	/* Clear bit in ENDPTSETUPSTAT */
> -	temp = fsl_readl(&dr_regs->endptsetupstat);
> -	fsl_writel(temp | (1 << ep_num), &dr_regs->endptsetupstat);
> +	temp = readl(&dr_regs->endptsetupstat);
> +	writel(temp | (1 << ep_num), &dr_regs->endptsetupstat);
>  
>  	/* while a hazard exists when setup package arrives */
>  	do {
>  		/* Set Setup Tripwire */
> -		temp = fsl_readl(&dr_regs->usbcmd);
> -		fsl_writel(temp | USB_CMD_SUTW, &dr_regs->usbcmd);
> +		temp = readl(&dr_regs->usbcmd);
> +		writel(temp | USB_CMD_SUTW, &dr_regs->usbcmd);
>  
>  		/* Copy the setup packet to local buffer */
>  		if (pdata->le_setup_buf) {
> @@ -1605,11 +1515,11 @@ static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
>  		} else {
>  			memcpy(buffer_ptr, (u8 *) qh->setup_buffer, 8);
>  		}
> -	} while (!(fsl_readl(&dr_regs->usbcmd) & USB_CMD_SUTW));
> +	} while (!(readl(&dr_regs->usbcmd) & USB_CMD_SUTW));
>  
>  	/* Clear Setup Tripwire */
> -	temp = fsl_readl(&dr_regs->usbcmd);
> -	fsl_writel(temp & ~USB_CMD_SUTW, &dr_regs->usbcmd);
> +	temp = readl(&dr_regs->usbcmd);
> +	writel(temp & ~USB_CMD_SUTW, &dr_regs->usbcmd);
>  }
>  
>  /* process-ep_req(): free the completed Tds for this req */
> @@ -1628,19 +1538,18 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
>  	actual = curr_req->req.length;
>  
>  	for (j = 0; j < curr_req->dtd_count; j++) {
> -		remaining_length = (hc32_to_cpu(curr_td->size_ioc_sts)
> -					& DTD_PACKET_SIZE)
> +		remaining_length = (curr_td->size_ioc_sts & DTD_PACKET_SIZE)
>  				>> DTD_LENGTH_BIT_POS;
>  		actual -= remaining_length;
>  
> -		errors = hc32_to_cpu(curr_td->size_ioc_sts);
> +		errors = curr_td->size_ioc_sts;
>  		if (errors & DTD_ERROR_MASK) {
>  			if (errors & DTD_STATUS_HALTED) {
>  				ERR("dTD error %08x QH=%d\n", errors, pipe);
>  				/* Clear the errors and Halt condition */
> -				tmp = hc32_to_cpu(curr_qh->size_ioc_int_sts);
> +				tmp = curr_qh->size_ioc_int_sts;
>  				tmp &= ~errors;
> -				curr_qh->size_ioc_int_sts = cpu_to_hc32(tmp);
> +				curr_qh->size_ioc_int_sts = cpu_to_le32(tmp);
>  				status = -EPIPE;
>  				/* FIXME: continue with next queued TD? */
>  
> @@ -1658,8 +1567,7 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
>  				ERR("Unknown error has occurred (0x%x)!\n",
>  					errors);
>  
> -		} else if (hc32_to_cpu(curr_td->size_ioc_sts)
> -				& DTD_STATUS_ACTIVE) {
> +		} else if (curr_td->size_ioc_sts & DTD_STATUS_ACTIVE) {
>  			VDBG("Request not complete");
>  			status = REQ_UNCOMPLETE;
>  			return status;
> @@ -1698,8 +1606,8 @@ static void dtd_complete_irq(struct fsl_udc *udc)
>  	struct fsl_req *curr_req, *temp_req;
>  
>  	/* Clear the bits in the register */
> -	bit_pos = fsl_readl(&dr_regs->endptcomplete);
> -	fsl_writel(bit_pos, &dr_regs->endptcomplete);
> +	bit_pos = readl(&dr_regs->endptcomplete);
> +	writel(bit_pos, &dr_regs->endptcomplete);
>  
>  	if (!bit_pos)
>  		return;
> @@ -1763,10 +1671,10 @@ static void port_change_irq(struct fsl_udc *udc)
>  		udc->bus_reset = 0;
>  
>  	/* Bus resetting is finished */
> -	if (!(fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET))
> +	if (!(readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET))
>  		/* Get the speed */
>  		udc->gadget.speed =
> -			portscx_device_speed(fsl_readl(&dr_regs->portsc1));
> +			portscx_device_speed(readl(&dr_regs->portsc1));
>  
>  	/* Update USB state */
>  	if (!udc->resume_state)
> @@ -1817,8 +1725,8 @@ static void reset_irq(struct fsl_udc *udc)
>  	unsigned long timeout;
>  
>  	/* Clear the device address */
> -	temp = fsl_readl(&dr_regs->deviceaddr);
> -	fsl_writel(temp & ~USB_DEVICE_ADDRESS_MASK, &dr_regs->deviceaddr);
> +	temp = readl(&dr_regs->deviceaddr);
> +	writel(temp & ~USB_DEVICE_ADDRESS_MASK, &dr_regs->deviceaddr);
>  
>  	udc->device_address = 0;
>  
> @@ -1832,15 +1740,15 @@ static void reset_irq(struct fsl_udc *udc)
>  	udc->gadget.a_alt_hnp_support = 0;
>  
>  	/* Clear all the setup token semaphores */
> -	temp = fsl_readl(&dr_regs->endptsetupstat);
> -	fsl_writel(temp, &dr_regs->endptsetupstat);
> +	temp = readl(&dr_regs->endptsetupstat);
> +	writel(temp, &dr_regs->endptsetupstat);
>  
>  	/* Clear all the endpoint complete status bits */
> -	temp = fsl_readl(&dr_regs->endptcomplete);
> -	fsl_writel(temp, &dr_regs->endptcomplete);
> +	temp = readl(&dr_regs->endptcomplete);
> +	writel(temp, &dr_regs->endptcomplete);
>  
>  	timeout = jiffies + 100;
> -	while (fsl_readl(&dr_regs->endpointprime)) {
> +	while (readl(&dr_regs->endpointprime)) {
>  		/* Wait until all endptprime bits cleared */
>  		if (time_after(jiffies, timeout)) {
>  			ERR("Timeout for reset\n");
> @@ -1850,9 +1758,9 @@ static void reset_irq(struct fsl_udc *udc)
>  	}
>  
>  	/* Write 1s to the flush register */
> -	fsl_writel(0xffffffff, &dr_regs->endptflush);
> +	writel(0xffffffff, &dr_regs->endptflush);
>  
> -	if (fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) {
> +	if (readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) {
>  		VDBG("Bus reset");
>  		/* Bus is reseting */
>  		udc->bus_reset = 1;
> @@ -1891,22 +1799,22 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
>  	if (udc->stopped)
>  		return IRQ_NONE;
>  	spin_lock_irqsave(&udc->lock, flags);
> -	irq_src = fsl_readl(&dr_regs->usbsts) & fsl_readl(&dr_regs->usbintr);
> +	irq_src = readl(&dr_regs->usbsts) & readl(&dr_regs->usbintr);
>  	/* Clear notification bits */
> -	fsl_writel(irq_src, &dr_regs->usbsts);
> +	writel(irq_src, &dr_regs->usbsts);
>  
>  	/* VDBG("irq_src [0x%8x]", irq_src); */
>  
>  	/* Need to resume? */
>  	if (udc->usb_state == USB_STATE_SUSPENDED)
> -		if ((fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_SUSPEND) == 0)
> +		if ((readl(&dr_regs->portsc1) & PORTSCX_PORT_SUSPEND) == 0)
>  			bus_resume(udc);
>  
>  	/* USB Interrupt */
>  	if (irq_src & USB_STS_INT) {
>  		VDBG("Packet int");
>  		/* Setup package, we only support ep0 as control ep */
> -		if (fsl_readl(&dr_regs->endptsetupstat) & EP_SETUP_STATUS_EP0) {
> +		if (readl(&dr_regs->endptsetupstat) & EP_SETUP_STATUS_EP0) {
>  			tripwire_handler(udc, 0,
>  					(u8 *) (&udc->local_setup_buff));
>  			setup_received_irq(udc, &udc->local_setup_buff);
> @@ -1914,7 +1822,7 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
>  		}
>  
>  		/* completion of dtd */
> -		if (fsl_readl(&dr_regs->endptcomplete)) {
> +		if (readl(&dr_regs->endptcomplete)) {
>  			dtd_complete_irq(udc);
>  			status = IRQ_HANDLED;
>  		}
> @@ -2076,7 +1984,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	next += t;
>  
>  	/* ------ DR Registers ----- */
> -	tmp_reg = fsl_readl(&dr_regs->usbcmd);
> +	tmp_reg = readl(&dr_regs->usbcmd);
>  	t = scnprintf(next, size,
>  			"USBCMD reg:\n"
>  			"SetupTW: %d\n"
> @@ -2086,7 +1994,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->usbsts);
> +	tmp_reg = readl(&dr_regs->usbsts);
>  	t = scnprintf(next, size,
>  			"USB Status Reg:\n"
>  			"Dr Suspend: %d Reset Received: %d System Error: %s "
> @@ -2098,7 +2006,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->usbintr);
> +	tmp_reg = readl(&dr_regs->usbintr);
>  	t = scnprintf(next, size,
>  			"USB Intrrupt Enable Reg:\n"
>  			"Sleep Enable: %d SOF Received Enable: %d "
> @@ -2116,21 +2024,21 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->frindex);
> +	tmp_reg = readl(&dr_regs->frindex);
>  	t = scnprintf(next, size,
>  			"USB Frame Index Reg: Frame Number is 0x%x\n\n",
>  			(tmp_reg & USB_FRINDEX_MASKS));
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->deviceaddr);
> +	tmp_reg = readl(&dr_regs->deviceaddr);
>  	t = scnprintf(next, size,
>  			"USB Device Address Reg: Device Addr is 0x%x\n\n",
>  			(tmp_reg & USB_DEVICE_ADDRESS_MASK));
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->endpointlistaddr);
> +	tmp_reg = readl(&dr_regs->endpointlistaddr);
>  	t = scnprintf(next, size,
>  			"USB Endpoint List Address Reg: "
>  			"Device Addr is 0x%x\n\n",
> @@ -2138,7 +2046,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->portsc1);
> +	tmp_reg = readl(&dr_regs->portsc1);
>  	t = scnprintf(next, size,
>  		"USB Port Status&Control Reg:\n"
>  		"Port Transceiver Type : %s Port Speed: %s\n"
> @@ -2177,7 +2085,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->usbmode);
> +	tmp_reg = readl(&dr_regs->usbmode);
>  	t = scnprintf(next, size,
>  			"USB Mode Reg: Controller Mode is: %s\n\n", ( {
>  				char *s;
> @@ -2196,7 +2104,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->endptsetupstat);
> +	tmp_reg = readl(&dr_regs->endptsetupstat);
>  	t = scnprintf(next, size,
>  			"Endpoint Setup Status Reg: SETUP on ep 0x%x\n\n",
>  			(tmp_reg & EP_SETUP_STATUS_MASK));
> @@ -2204,13 +2112,13 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	next += t;
>  
>  	for (i = 0; i < udc->max_ep / 2; i++) {
> -		tmp_reg = fsl_readl(&dr_regs->endptctrl[i]);
> +		tmp_reg = readl(&dr_regs->endptctrl[i]);
>  		t = scnprintf(next, size, "EP Ctrl Reg [0x%x]: = [0x%x]\n",
>  				i, tmp_reg);
>  		size -= t;
>  		next += t;
>  	}
> -	tmp_reg = fsl_readl(&dr_regs->endpointprime);
> +	tmp_reg = readl(&dr_regs->endpointprime);
>  	t = scnprintf(next, size, "EP Prime Reg = [0x%x]\n\n", tmp_reg);
>  	size -= t;
>  	next += t;
> @@ -2473,9 +2381,6 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  		goto err_iounmap_noclk;
>  	}
>  
> -	/* Set accessors only after pdata->init() ! */
> -	fsl_set_accessors(pdata);
> -
>  #ifndef CONFIG_ARCH_MXC
>  	if (pdata->have_sysif_regs)
>  		usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
> @@ -2487,7 +2392,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  		goto err_iounmap_noclk;
>  
>  	/* Read Device Controller Capability Parameters register */
> -	dccparams = fsl_readl(&dr_regs->dccparams);
> +	dccparams = readl(&dr_regs->dccparams);
>  	if (!(dccparams & DCCPARAMS_DC)) {
>  		ERR("This SOC doesn't support device role\n");
>  		ret = -ENODEV;
> @@ -2682,7 +2587,7 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
>  	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
>  	u32 mode, usbcmd;
>  
> -	mode = fsl_readl(&dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
> +	mode = readl(&dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
>  
>  	pr_debug("%s(): mode 0x%x stopped %d\n", __func__, mode, udc->stopped);
>  
> @@ -2703,8 +2608,8 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
>  	}
>  
>  	/* stop the controller */
> -	usbcmd = fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP;
> -	fsl_writel(usbcmd, &dr_regs->usbcmd);
> +	usbcmd = readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP;
> +	writel(usbcmd, &dr_regs->usbcmd);
>  
>  	udc->stopped = 1;
>  
> -- 
> 1.7.2.5
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply

* Re: [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD
From: Felipe Balbi @ 2012-10-19 10:30 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Felipe Balbi,
	Hans J. Koch, Daniel Mack, Christian Hemp, linuxppc-dev,
	Teresa Gamez, Sebastian Andrzej Siewior
In-Reply-To: <1350642285-8145-5-git-send-email-chf.fritz@googlemail.com>

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

On Fri, Oct 19, 2012 at 12:24:43PM +0200, Christoph Fritz wrote:
> USB controller may access a wrong address for the dTD (endpoint transfer
> descriptor) and then hang. This happens a lot when doing tests with
> g_ether module and iperf, a tool for measuring maximum TCP and UDP
> bandwidth.
> 
> This hardware bug is explained in detail by errata number 2858 for i.MX23:
> http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
> 
> All (?) SOCs with an IP from chipidea suffer from this problem.
> mv_udc_core fixes this bug by commit daec765.  There still may be
> unfixed drivers.

why aren't you using that driver instead ? Is it really necessary to
keep this driver around ? I would really like to see uniformization
towards that, if you use the same IP, then the same driver ought to
suffice.

What's the reason for not using drivers/usb/chipidea ?

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply

* Re: [PATCH 1/10] memory-hotplug : check whether memory is offline or not when removing memory
From: Wen Congyang @ 2012-10-19 10:44 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: linux-s390, linux-ia64, len.brown, linux-acpi, linux-sh, x86,
	linux-kernel, cmetcalf, linux-mm, Yasuaki Ishimatsu, minchan.kim,
	rientjes, sparclinux, cl, linuxppc-dev, akpm, liuj97
In-Reply-To: <CAHGf_=rVDm-JygjPoLHbmF28Dgd52HFc4-b5KCxhEieG60okuw@mail.gmail.com>

At 10/06/2012 03:27 AM, KOSAKI Motohiro Wrote:
> On Thu, Oct 4, 2012 at 10:25 PM, Yasuaki Ishimatsu
> <isimatu.yasuaki@jp.fujitsu.com> wrote:
>> When calling remove_memory(), the memory should be offline. If the function
>> is used to online memory, kernel panic may occur.
>>
>> So the patch checks whether memory is offline or not.
> 
> You don't explain WHY we need the check.

This patch is no necessary now, because the newest kernel has checked
it.

Thanks
Wen Congyang

> 
> 
>> CC: David Rientjes <rientjes@google.com>
>> CC: Jiang Liu <liuj97@gmail.com>
>> CC: Len Brown <len.brown@intel.com>
>> CC: Christoph Lameter <cl@linux.com>
>> Cc: Minchan Kim <minchan.kim@gmail.com>
>> CC: Andrew Morton <akpm@linux-foundation.org>
>> CC: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
>> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
>> Signed-off-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
>>
>> ---
>>  drivers/base/memory.c  |   39 +++++++++++++++++++++++++++++++++++++++
>>  include/linux/memory.h |    5 +++++
>>  mm/memory_hotplug.c    |   17 +++++++++++++++--
>>  3 files changed, 59 insertions(+), 2 deletions(-)
>>
>> Index: linux-3.6/drivers/base/memory.c
>> ===================================================================
>> --- linux-3.6.orig/drivers/base/memory.c        2012-10-04 14:22:57.000000000 +0900
>> +++ linux-3.6/drivers/base/memory.c     2012-10-04 14:45:46.653585860 +0900
>> @@ -70,6 +70,45 @@ void unregister_memory_isolate_notifier(
>>  }
>>  EXPORT_SYMBOL(unregister_memory_isolate_notifier);
>>
>> +bool is_memblk_offline(unsigned long start, unsigned long size)
> 
> Don't use memblk. Usually memblk mean struct numa_meminfo for x86/numa.
> Maybe memory_range_offlined() is better.
> 
> And, this function don't take struct memory_block, then this file may be no good
> place.
> 
> And you need to write down function comment.
> 
> 
>> +{
>> +       struct memory_block *mem = NULL;
>> +       struct mem_section *section;
>> +       unsigned long start_pfn, end_pfn;
>> +       unsigned long pfn, section_nr;
>> +
>> +       start_pfn = PFN_DOWN(start);
>> +       end_pfn = PFN_UP(start + size);
>> +
>> +       for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
>> +               section_nr = pfn_to_section_nr(pfn);
>> +               if (!present_section_nr(section_nr))
>> +                       continue;
>> +
>> +               section = __nr_to_section(section_nr);
>> +               /* same memblock? */
>> +               if (mem)
>> +                       if ((section_nr >= mem->start_section_nr) &&
>> +                           (section_nr <= mem->end_section_nr))
>> +                               continue;
>> +
>> +               mem = find_memory_block_hinted(section, mem);
>> +               if (!mem)
>> +                       continue;
>> +               if (mem->state == MEM_OFFLINE)
>> +                       continue;
>> +
>> +               kobject_put(&mem->dev.kobj);
>> +               return false;
>> +       }
>> +
>> +       if (mem)
>> +               kobject_put(&mem->dev.kobj);
>> +
>> +       return true;
>> +}
>> +EXPORT_SYMBOL(is_memblk_offline);
>> +
>>  /*
>>   * register_memory - Setup a sysfs device for a memory block
>>   */
>> Index: linux-3.6/include/linux/memory.h
>> ===================================================================
>> --- linux-3.6.orig/include/linux/memory.h       2012-10-02 18:00:22.000000000 +0900
>> +++ linux-3.6/include/linux/memory.h    2012-10-04 14:44:40.902581028 +0900
>> @@ -106,6 +106,10 @@ static inline int memory_isolate_notify(
>>  {
>>         return 0;
>>  }
>> +static inline bool is_memblk_offline(unsigned long start, unsigned long size)
>> +{
>> +       return false;
>> +}
>>  #else
>>  extern int register_memory_notifier(struct notifier_block *nb);
>>  extern void unregister_memory_notifier(struct notifier_block *nb);
>> @@ -120,6 +124,7 @@ extern int memory_isolate_notify(unsigne
>>  extern struct memory_block *find_memory_block_hinted(struct mem_section *,
>>                                                         struct memory_block *);
>>  extern struct memory_block *find_memory_block(struct mem_section *);
>> +extern bool is_memblk_offline(unsigned long start, unsigned long size);
>>  #define CONFIG_MEM_BLOCK_SIZE  (PAGES_PER_SECTION<<PAGE_SHIFT)
>>  enum mem_add_context { BOOT, HOTPLUG };
>>  #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
>> Index: linux-3.6/mm/memory_hotplug.c
>> ===================================================================
>> --- linux-3.6.orig/mm/memory_hotplug.c  2012-10-04 14:31:08.000000000 +0900
>> +++ linux-3.6/mm/memory_hotplug.c       2012-10-04 14:58:22.449687986 +0900
>> @@ -1045,8 +1045,21 @@ int offline_memory(u64 start, u64 size)
>>
>>  int remove_memory(int nid, u64 start, u64 size)
>>  {
> 
> Your remove_memory() don't remove anything. that's strange.
> 
> 
>> -       /* It is not implemented yet*/
>> -       return 0;
>> +       int ret = 0;
>> +       lock_memory_hotplug();
>> +       /*
>> +        * The memory might become online by other task, even if you offine it.
>> +        * So we check whether the memory has been onlined or not.
>> +        */
>> +       if (!is_memblk_offline(start, size)) {
>> +               pr_warn("memory removing [mem %#010llx-%#010llx] failed, "
>> +                       "because the memmory range is online\n",
>> +                       start, start + size);
> 
> No good warning. You should output which memory block can't be
> offlined, I think.
> 
> 
>> +               ret = -EAGAIN;
>> +       }
>> +
>> +       unlock_memory_hotplug();
>> +       return ret;
>>  }
>>  EXPORT_SYMBOL_GPL(remove_memory);
>>  #else
>>
>> --
>> To unsubscribe, send a message with 'unsubscribe linux-mm' in
>> the body to majordomo@kvack.org.  For more info on Linux MM,
>> see: http://www.linux-mm.org/ .
>> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
> 

^ permalink raw reply

* Re: [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD
From: Christoph Fritz @ 2012-10-19 10:46 UTC (permalink / raw)
  To: balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior
In-Reply-To: <20121019103039.GF11191@arwen.pp.htv.fi>

On Fri, 2012-10-19 at 13:30 +0300, Felipe Balbi wrote:
> On Fri, Oct 19, 2012 at 12:24:43PM +0200, Christoph Fritz wrote:
> > USB controller may access a wrong address for the dTD (endpoint transfer
> > descriptor) and then hang. This happens a lot when doing tests with
> > g_ether module and iperf, a tool for measuring maximum TCP and UDP
> > bandwidth.
> > 
> > This hardware bug is explained in detail by errata number 2858 for i.MX23:
> > http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
> > 
> > All (?) SOCs with an IP from chipidea suffer from this problem.
> > mv_udc_core fixes this bug by commit daec765.  There still may be
> > unfixed drivers.
> 
> why aren't you using that driver instead ? Is it really necessary to
> keep this driver around ? I would really like to see uniformization
> towards that, if you use the same IP, then the same driver ought to
> suffice.
> 
> What's the reason for not using drivers/usb/chipidea ?
> 

I thought about this too but wasn't able to use chipidea with
MXC_EHCI_INTERNAL_PHY as it's called in fsl_udc.

Sascha, do you know if i.mx35 works with usb/chipidea?

Thanks
 -- Christoph

^ permalink raw reply

* Re: [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD
From: Felipe Balbi @ 2012-10-19 10:44 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, balbi, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior
In-Reply-To: <1350643608.3709.78.camel@mars>

[-- Attachment #1: Type: text/plain, Size: 1334 bytes --]

Hi,

On Fri, Oct 19, 2012 at 12:46:48PM +0200, Christoph Fritz wrote:
> On Fri, 2012-10-19 at 13:30 +0300, Felipe Balbi wrote:
> > On Fri, Oct 19, 2012 at 12:24:43PM +0200, Christoph Fritz wrote:
> > > USB controller may access a wrong address for the dTD (endpoint transfer
> > > descriptor) and then hang. This happens a lot when doing tests with
> > > g_ether module and iperf, a tool for measuring maximum TCP and UDP
> > > bandwidth.
> > > 
> > > This hardware bug is explained in detail by errata number 2858 for i.MX23:
> > > http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
> > > 
> > > All (?) SOCs with an IP from chipidea suffer from this problem.
> > > mv_udc_core fixes this bug by commit daec765.  There still may be
> > > unfixed drivers.
> > 
> > why aren't you using that driver instead ? Is it really necessary to
> > keep this driver around ? I would really like to see uniformization
> > towards that, if you use the same IP, then the same driver ought to
> > suffice.
> > 
> > What's the reason for not using drivers/usb/chipidea ?
> > 
> 
> I thought about this too but wasn't able to use chipidea with
> MXC_EHCI_INTERNAL_PHY as it's called in fsl_udc.

that's a matter of writing the PHY driver, right ;-) It has nothing to
do with chipidea, actually :-)

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply

* Re: [PATCH 1/10] memory-hotplug : check whether memory is offline or not when removing memory
From: Wen Congyang @ 2012-10-19 14:15 UTC (permalink / raw)
  To: Wen Congyang
  Cc: linux-s390, linux-ia64, len.brown, linux-acpi, linux-sh, x86,
	linux-kernel, cmetcalf, linux-mm, Yasuaki Ishimatsu, minchan.kim,
	KOSAKI Motohiro, rientjes, sparclinux, cl, linuxppc-dev, akpm,
	liuj97
In-Reply-To: <50812F13.20503@cn.fujitsu.com>

At 2012/10/19 18:44, Wen Congyang Wrote:
> At 10/06/2012 03:27 AM, KOSAKI Motohiro Wrote:
>> On Thu, Oct 4, 2012 at 10:25 PM, Yasuaki Ishimatsu
>> <isimatu.yasuaki@jp.fujitsu.com>  wrote:
>>> When calling remove_memory(), the memory should be offline. If the function
>>> is used to online memory, kernel panic may occur.
>>>
>>> So the patch checks whether memory is offline or not.
>>
>> You don't explain WHY we need the check.
>
> This patch is no necessary now, because the newest kernel has checked
> it.

I think it again, and found that this check is necessary. Because we only
lock memory hotplug when offlining pages. Here is the steps to offline and
remove memory:

1. lock memory hotplug
2. offline a memory section
3. unlock memory hotplug
4. repeat 1-3 to offline all memory sections
5. lock memory hotplug
6. remove memory
7. unlock memory hotplug

All memory sections must be offlined before removing memory. But we 
don't hold
the lock in the whole operation. So we should check whether all memory 
sections
are offlined before step6.

>
> Thanks
> Wen Congyang
>
>>
>>
>>> CC: David Rientjes<rientjes@google.com>
>>> CC: Jiang Liu<liuj97@gmail.com>
>>> CC: Len Brown<len.brown@intel.com>
>>> CC: Christoph Lameter<cl@linux.com>
>>> Cc: Minchan Kim<minchan.kim@gmail.com>
>>> CC: Andrew Morton<akpm@linux-foundation.org>
>>> CC: KOSAKI Motohiro<kosaki.motohiro@jp.fujitsu.com>
>>> Signed-off-by: Wen Congyang<wency@cn.fujitsu.com>
>>> Signed-off-by: Yasuaki Ishimatsu<isimatu.yasuaki@jp.fujitsu.com>
>>>
>>> ---
>>>   drivers/base/memory.c  |   39 +++++++++++++++++++++++++++++++++++++++
>>>   include/linux/memory.h |    5 +++++
>>>   mm/memory_hotplug.c    |   17 +++++++++++++++--
>>>   3 files changed, 59 insertions(+), 2 deletions(-)
>>>
>>> Index: linux-3.6/drivers/base/memory.c
>>> ===================================================================
>>> --- linux-3.6.orig/drivers/base/memory.c        2012-10-04 14:22:57.000000000 +0900
>>> +++ linux-3.6/drivers/base/memory.c     2012-10-04 14:45:46.653585860 +0900
>>> @@ -70,6 +70,45 @@ void unregister_memory_isolate_notifier(
>>>   }
>>>   EXPORT_SYMBOL(unregister_memory_isolate_notifier);
>>>
>>> +bool is_memblk_offline(unsigned long start, unsigned long size)
>>
>> Don't use memblk. Usually memblk mean struct numa_meminfo for x86/numa.
>> Maybe memory_range_offlined() is better.
>>
>> And, this function don't take struct memory_block, then this file may be no good
>> place.
>>
>> And you need to write down function comment.
>>
>>
>>> +{
>>> +       struct memory_block *mem = NULL;
>>> +       struct mem_section *section;
>>> +       unsigned long start_pfn, end_pfn;
>>> +       unsigned long pfn, section_nr;
>>> +
>>> +       start_pfn = PFN_DOWN(start);
>>> +       end_pfn = PFN_UP(start + size);
>>> +
>>> +       for (pfn = start_pfn; pfn<  end_pfn; pfn += PAGES_PER_SECTION) {
>>> +               section_nr = pfn_to_section_nr(pfn);
>>> +               if (!present_section_nr(section_nr))
>>> +                       continue;
>>> +
>>> +               section = __nr_to_section(section_nr);
>>> +               /* same memblock? */
>>> +               if (mem)
>>> +                       if ((section_nr>= mem->start_section_nr)&&
>>> +                           (section_nr<= mem->end_section_nr))
>>> +                               continue;
>>> +
>>> +               mem = find_memory_block_hinted(section, mem);
>>> +               if (!mem)
>>> +                       continue;
>>> +               if (mem->state == MEM_OFFLINE)
>>> +                       continue;
>>> +
>>> +               kobject_put(&mem->dev.kobj);
>>> +               return false;
>>> +       }
>>> +
>>> +       if (mem)
>>> +               kobject_put(&mem->dev.kobj);
>>> +
>>> +       return true;
>>> +}
>>> +EXPORT_SYMBOL(is_memblk_offline);
>>> +
>>>   /*
>>>    * register_memory - Setup a sysfs device for a memory block
>>>    */
>>> Index: linux-3.6/include/linux/memory.h
>>> ===================================================================
>>> --- linux-3.6.orig/include/linux/memory.h       2012-10-02 18:00:22.000000000 +0900
>>> +++ linux-3.6/include/linux/memory.h    2012-10-04 14:44:40.902581028 +0900
>>> @@ -106,6 +106,10 @@ static inline int memory_isolate_notify(
>>>   {
>>>          return 0;
>>>   }
>>> +static inline bool is_memblk_offline(unsigned long start, unsigned long size)
>>> +{
>>> +       return false;
>>> +}
>>>   #else
>>>   extern int register_memory_notifier(struct notifier_block *nb);
>>>   extern void unregister_memory_notifier(struct notifier_block *nb);
>>> @@ -120,6 +124,7 @@ extern int memory_isolate_notify(unsigne
>>>   extern struct memory_block *find_memory_block_hinted(struct mem_section *,
>>>                                                          struct memory_block *);
>>>   extern struct memory_block *find_memory_block(struct mem_section *);
>>> +extern bool is_memblk_offline(unsigned long start, unsigned long size);
>>>   #define CONFIG_MEM_BLOCK_SIZE  (PAGES_PER_SECTION<<PAGE_SHIFT)
>>>   enum mem_add_context { BOOT, HOTPLUG };
>>>   #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
>>> Index: linux-3.6/mm/memory_hotplug.c
>>> ===================================================================
>>> --- linux-3.6.orig/mm/memory_hotplug.c  2012-10-04 14:31:08.000000000 +0900
>>> +++ linux-3.6/mm/memory_hotplug.c       2012-10-04 14:58:22.449687986 +0900
>>> @@ -1045,8 +1045,21 @@ int offline_memory(u64 start, u64 size)
>>>
>>>   int remove_memory(int nid, u64 start, u64 size)
>>>   {
>>
>> Your remove_memory() don't remove anything. that's strange.

IIUC, this batch is based on another patchset.

>>
>>
>>> -       /* It is not implemented yet*/
>>> -       return 0;
>>> +       int ret = 0;
>>> +       lock_memory_hotplug();
>>> +       /*
>>> +        * The memory might become online by other task, even if you offine it.
>>> +        * So we check whether the memory has been onlined or not.
>>> +        */
>>> +       if (!is_memblk_offline(start, size)) {
>>> +               pr_warn("memory removing [mem %#010llx-%#010llx] failed, "
>>> +                       "because the memmory range is online\n",
>>> +                       start, start + size);
>>
>> No good warning. You should output which memory block can't be
>> offlined, I think.

OK. I'll update it.

Thanks
Wen Congyang

>>
>>
>>> +               ret = -EAGAIN;
>>> +       }
>>> +
>>> +       unlock_memory_hotplug();
>>> +       return ret;
>>>   }
>>>   EXPORT_SYMBOL_GPL(remove_memory);
>>>   #else
>>>
>>> --
>>> To unsubscribe, send a message with 'unsubscribe linux-mm' in
>>> the body to majordomo@kvack.org.  For more info on Linux MM,
>>> see: http://www.linux-mm.org/ .
>>> Don't email:<a href=mailto:"dont@kvack.org">  email@kvack.org</a>
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply

* Re: [PATCH 0/7] update USB gadget driver fsl-usb2-udc
From: Sascha Hauer @ 2012-10-19 15:36 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sebastian Andrzej Siewior, linux-usb,
	Felipe Balbi, Hans J. Koch, Daniel Mack, Christian Hemp,
	linuxppc-dev, Teresa Gamez
In-Reply-To: <1350642156-8034-1-git-send-email-chf.fritz@googlemail.com>

Hi Christoph,

What system are you working on? If it's i.MX you should use/work on the
chipidea driver instead.

Sascha

On Fri, Oct 19, 2012 at 12:22:36PM +0200, Christoph Fritz wrote:
> This series updates USB gadget driver fsl-usb2-udc.
> 
> Christoph Fritz (7):
>   usb: gadget: fsl_udc: simplify driver init
>   usb: gadget: fsl_udc: protect fsl_pullup() with spin_lock
>   usb: gadget: fsl_udc: convert to new ulc style
>   usb: gadget: fsl_udc: drop ARCH dependency
>   usb: gadget: fsl_udc: postpone freeing current dTD
>   usb: gadget: fsl_udc: purge global pointer usb_sys_regs
>   usb: gadget: fsl_udc: purge global pointer dr_regs
> 
>  drivers/usb/gadget/fsl_udc_core.c |  755 ++++++++++++++++---------------------
>  drivers/usb/gadget/fsl_usb2_udc.h |    4 +
>  2 files changed, 322 insertions(+), 437 deletions(-)
> 
> -- 
> 1.7.2.5
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply

* Re: [ath9k-devel] [PATCH net-next 00/21] treewide: Use consistent api style for address testing
From: Pavel Roskin @ 2012-10-19 15:55 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: linux-mips, b.a.t.m.a.n, linux-doc, brcm80211-dev-list, users,
	linux-sctp, devel, dev, linux-s390, wimax, linux-scsi, linux-rdma,
	bridge, lvs-devel, coreteam, b43-dev, cbe-oss-dev, devel,
	user-mode-linux-devel, devicetree-discuss,
	davinci-linux-open-source, netfilter, user-mode-linux-user,
	linux-arm-kernel, linux-nfs, linux-parisc, netdev, linux-usb,
	linux-wireless, linux-kernel, e1000-devel, ath9k-devel,
	netfilter-devel, Joe Perches, uclinux-dist-devel, linuxppc-dev
In-Reply-To: <1350630254.2293.183.camel@edumazet-glaptop>

On Fri, 19 Oct 2012 09:04:14 +0200
Eric Dumazet <eric.dumazet@gmail.com> wrote:

> Yes they are some names discrepancies, thats a big deal.
> 
> And we have alloc_skb() / kfree_skb() / skb_clone() 
> 
> Why not skb_alloc() / skb_free() / skb_clone() ?
> 
> Some people actually know current code by name of functions, they dont
> want to change their mind and having to grep include files and git log
> to learn the new names of an old function, especially when traveling
> and using a laptop.

I agree.

Also, it makes sense to introduce a more consistent name for a function
when it's improved in some way and the callers need to be adjusted or
re-checked.

That way, the old name can be phased out as the code is made compatible
with the new function.

-- 
Regards,
Pavel Roskin

^ permalink raw reply

* Re: [RFC][PATCH] perf: Add a few generic stalled-cycles events
From: Sukadev Bhattiprolu @ 2012-10-19 17:05 UTC (permalink / raw)
  To: Stephane Eranian
  Cc: linuxppc-dev, Robert Richter, Anton Blanchard, LKML,
	Arnaldo Carvalho de Melo, Peter Zijlstra, Paul Mackerras, mpjohn,
	Ingo Molnar, Arun Sharma
In-Reply-To: <CABPqkBRd2wfjd1ObCkM+TSSwt7C9WP65dEE9POSyDK1ccvNL8A@mail.gmail.com>

Stephane Eranian [eranian@google.com] wrote:
| So all in all, I think this is not a very good idea. You have to put
| this into the tool or a library that auto-detects the
| host CPU and programs the right set of events.
| 
| We've had that discussion many times. Just reiterating my personal
| opinion on this.

Yes that would work too. One drawback is that the hardware events
will be in the tool, while the software/tracepoint events in the
kernel sysfs representation.

Or is that the reason we want all events in one place (sysfs) ?

Sukadev

^ permalink raw reply

* Re: [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware
From: Felipe Balbi @ 2012-10-19 17:37 UTC (permalink / raw)
  To: Simon Haggett
  Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, Felipe Balbi,
	Laurent Pinchart, linuxppc-dev
In-Reply-To: <1350667166-3559-1-git-send-email-simon.haggett@realvnc.com>

[-- Attachment #1: Type: text/plain, Size: 1972 bytes --]

Hi,

On Fri, Oct 19, 2012 at 06:19:26PM +0100, Simon Haggett wrote:
> Some gadget drivers may attempt to dequeue requests for an endpoint that has
> already been disabled. For example, in the UVC gadget driver, uvc_function_set_alt()
> will call usb_ep_disable() when alt setting 0 is selected. When the userspace
> application subsequently issues the VIDIOC_STREAMOFF ioctl, uvc_video_enable()
> invokes usb_ep_dequeue() to ensure that all requests have been cancelled.

bug is on uvc gadget, then. Laurent ?

Also, fsl should be removed from the tree, I'm trying to persuade iMX
folks to use drivers/usb/chipidea instead.

> For the Freescale High Speed Dual-Role USB controller, fsl_ep_dequeue() provides
> the implementation of usb_ep_dequeue(). If this is called for a disabled endpoint,
> a kernel oops will occur when the ep->ep.desc field is dereferenced (by ep_index()).
> fsl_ep_disable() sets this field to NULL, as well as deleting all pending requests
> for the endpoint.
> 
> This patch adds an additional check to fsl_ep_dequeue() to ensure that the
> endpoint has not already been disabled before attempting to dequeue requests.
> 
> Signed-off-by: Simon Haggett <simon.haggett@realvnc.com>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index 6ae70cb..acd513b 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -955,7 +955,10 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
>  	int ep_num, stopped, ret = 0;
>  	u32 epctrl;
>  
> -	if (!_ep || !_req)
> +	/* Ensure that the ep and request are valid, and the ep is not
> +	 * disabled
> +	 */
> +	if (!_ep || !_req || !ep->ep.desc)
>  		return -EINVAL;
>  
>  	spin_lock_irqsave(&ep->udc->lock, flags);
> -- 
> 1.7.4.1
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply

* [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware
From: Simon Haggett @ 2012-10-19 17:19 UTC (permalink / raw)
  To: Li Yang, Felipe Balbi
  Cc: Simon Haggett, Greg Kroah-Hartman, linux-usb, linuxppc-dev,
	linux-kernel

Some gadget drivers may attempt to dequeue requests for an endpoint that has
already been disabled. For example, in the UVC gadget driver, uvc_function_set_alt()
will call usb_ep_disable() when alt setting 0 is selected. When the userspace
application subsequently issues the VIDIOC_STREAMOFF ioctl, uvc_video_enable()
invokes usb_ep_dequeue() to ensure that all requests have been cancelled.

For the Freescale High Speed Dual-Role USB controller, fsl_ep_dequeue() provides
the implementation of usb_ep_dequeue(). If this is called for a disabled endpoint,
a kernel oops will occur when the ep->ep.desc field is dereferenced (by ep_index()).
fsl_ep_disable() sets this field to NULL, as well as deleting all pending requests
for the endpoint.

This patch adds an additional check to fsl_ep_dequeue() to ensure that the
endpoint has not already been disabled before attempting to dequeue requests.

Signed-off-by: Simon Haggett <simon.haggett@realvnc.com>
---
 drivers/usb/gadget/fsl_udc_core.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 6ae70cb..acd513b 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -955,7 +955,10 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 	int ep_num, stopped, ret = 0;
 	u32 epctrl;
 
-	if (!_ep || !_req)
+	/* Ensure that the ep and request are valid, and the ep is not
+	 * disabled
+	 */
+	if (!_ep || !_req || !ep->ep.desc)
 		return -EINVAL;
 
 	spin_lock_irqsave(&ep->udc->lock, flags);
-- 
1.7.4.1

^ permalink raw reply related

* Re: [PATCH 1/10] memory-hotplug : check whether memory is offline or not when removing memory
From: KOSAKI Motohiro @ 2012-10-19 18:33 UTC (permalink / raw)
  To: Wen Congyang
  Cc: linux-s390, linux-ia64, Wen Congyang, linux-acpi, linux-sh,
	len.brown, x86, linux-kernel, cmetcalf, linux-mm,
	Yasuaki Ishimatsu, minchan.kim, rientjes, sparclinux, cl,
	linuxppc-dev, akpm, liuj97
In-Reply-To: <5081609C.9080702@gmail.com>

> I think it again, and found that this check is necessary. Because we only
> lock memory hotplug when offlining pages. Here is the steps to offline and
> remove memory:
>
> 1. lock memory hotplug
> 2. offline a memory section
> 3. unlock memory hotplug
> 4. repeat 1-3 to offline all memory sections
> 5. lock memory hotplug
> 6. remove memory
> 7. unlock memory hotplug
>
> All memory sections must be offlined before removing memory. But we don't
> hold
> the lock in the whole operation. So we should check whether all memory
> sections
> are offlined before step6.

You should describe the race scenario in the patch description. OK?

^ permalink raw reply

* Re: [PATCH 1/10] memory-hotplug : check whether memory is offline or not when removing memory
From: Wen Congyang @ 2012-10-20  0:50 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: linux-s390, linux-ia64, len.brown, linux-acpi, linux-sh, x86,
	linux-kernel, cmetcalf, Wen Congyang, linux-mm, Yasuaki Ishimatsu,
	minchan.kim, rientjes, sparclinux, cl, linuxppc-dev, akpm, liuj97
In-Reply-To: <CAHGf_=q=Agidyj_j6jhBdhNmJBy2u1dP+UMAoXbM=_=DyZJs_w@mail.gmail.com>

At 10/20/2012 02:33 AM, KOSAKI Motohiro Wrote:
>> I think it again, and found that this check is necessary. Because we only
>> lock memory hotplug when offlining pages. Here is the steps to offline and
>> remove memory:
>>
>> 1. lock memory hotplug
>> 2. offline a memory section
>> 3. unlock memory hotplug
>> 4. repeat 1-3 to offline all memory sections
>> 5. lock memory hotplug
>> 6. remove memory
>> 7. unlock memory hotplug
>>
>> All memory sections must be offlined before removing memory. But we don't
>> hold
>> the lock in the whole operation. So we should check whether all memory
>> sections
>> are offlined before step6.
> 
> You should describe the race scenario in the patch description. OK?
> 

OK

Thanks
Wen Congyang

^ permalink raw reply

* Re: [PATCH v2] powerpc: 52xx: nop out unsupported critical IRQs
From: Wolfram Sang @ 2012-10-20  6:54 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: John Bonesio, Anatolij Gustschin
In-Reply-To: <1349947155-11540-1-git-send-email-w.sang@pengutronix.de>

[-- Attachment #1: Type: text/plain, Size: 2180 bytes --]

On Thu, Oct 11, 2012 at 11:19:15AM +0200, Wolfram Sang wrote:
> Currently, when booting MPC52xx based platforms, we get:
> 
>         mpc52xx_irqhost_map: invalid irq: virq=16, l1=0, l2=3
>         irq: irq-16==>hwirq-0x3 mapping failed: -22
>         [WARNing skipped]
> 
> The warning is wrong since the mapping itself is valid. However, there is no
> support for that type of IRQ currently. Print a proper warning and bind the irq
> to a no_irq chip.
> 
> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
> Cc: John Bonesio <bones@secretlab.ca>
> Cc: Anatolij Gustschin <agust@denx.de>
> Cc: Grant Likely <grant.likely@secretlab.ca>

Ping. I'd really like to get rid of the WARNing for all MPC52xx boards.
It looks pretty scary to people who don't know the issues behind it.

> ---
> 
> Change since V1: drop the default state since all possibilities for l1 are now
> 		 covered in the switch-statement.
> 
>  arch/powerpc/platforms/52xx/mpc52xx_pic.c |    9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/52xx/mpc52xx_pic.c b/arch/powerpc/platforms/52xx/mpc52xx_pic.c
> index 8520b58..b89ef65 100644
> --- a/arch/powerpc/platforms/52xx/mpc52xx_pic.c
> +++ b/arch/powerpc/platforms/52xx/mpc52xx_pic.c
> @@ -372,10 +372,11 @@ static int mpc52xx_irqhost_map(struct irq_domain *h, unsigned int virq,
>  	case MPC52xx_IRQ_L1_MAIN: irqchip = &mpc52xx_main_irqchip; break;
>  	case MPC52xx_IRQ_L1_PERP: irqchip = &mpc52xx_periph_irqchip; break;
>  	case MPC52xx_IRQ_L1_SDMA: irqchip = &mpc52xx_sdma_irqchip; break;
> -	default:
> -		pr_err("%s: invalid irq: virq=%i, l1=%i, l2=%i\n",
> -		       __func__, virq, l1irq, l2irq);
> -		return -EINVAL;
> +	case MPC52xx_IRQ_L1_CRIT:
> +		pr_warn("%s: Critical IRQ #%d is unsupported! Nopping it.\n",
> +			__func__, l2irq);
> +		irq_set_chip(virq, &no_irq_chip);
> +		return 0;
>  	}
>  
>  	irq_set_chip_and_handler(virq, irqchip, handle_level_irq);
> -- 
> 1.7.10.4
> 

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply

* Re: [PATCH v2] powerpc: 52xx: nop out unsupported critical IRQs
From: Anatolij Gustschin @ 2012-10-20 11:59 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: John Bonesio, linuxppc-dev
In-Reply-To: <1349947155-11540-1-git-send-email-w.sang@pengutronix.de>

Hi,

On Thu, 11 Oct 2012 11:19:15 +0200
Wolfram Sang <w.sang@pengutronix.de> wrote:

> Currently, when booting MPC52xx based platforms, we get:
> 
>         mpc52xx_irqhost_map: invalid irq: virq=16, l1=0, l2=3
>         irq: irq-16==>hwirq-0x3 mapping failed: -22
>         [WARNing skipped]
> 
> The warning is wrong since the mapping itself is valid. However, there is no
> support for that type of IRQ currently. Print a proper warning and bind the irq
> to a no_irq chip.
> 
> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
> Cc: John Bonesio <bones@secretlab.ca>
> Cc: Anatolij Gustschin <agust@denx.de>
> Cc: Grant Likely <grant.likely@secretlab.ca>
> ---
> 
> Change since V1: drop the default state since all possibilities for l1 are now
> 		 covered in the switch-statement.
> 
>  arch/powerpc/platforms/52xx/mpc52xx_pic.c |    9 +++++----

applied, thanks!

Anatolij

^ permalink raw reply

* Re: [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD
From: Christoph Fritz @ 2012-10-20 19:12 UTC (permalink / raw)
  To: balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior
In-Reply-To: <20121019104416.GH11191@arwen.pp.htv.fi>

On Fri, 2012-10-19 at 13:44 +0300, Felipe Balbi wrote:
> > I thought about this too but wasn't able to use chipidea with
> > MXC_EHCI_INTERNAL_PHY as it's called in fsl_udc.
> 
> that's a matter of writing the PHY driver, right ;-) It has nothing to
> do with chipidea, actually :-)

Okay, I'll do. But then we should purge the old buggy fsl_udc.

 Thanks
   -- Christoph

^ permalink raw reply

* Re: [PATCH v3 0/7] mv643xx.c: Add basic device tree support.
From: Jason Cooper @ 2012-10-21  1:52 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: thomas.petazzoni, andrew, Arnd Bergmann, netdev,
	devicetree-discuss, ben.dooks, Ian Molton, dale, linuxppc-dev,
	David Miller, linux-arm-kernel
In-Reply-To: <1347343411.2603.42.camel@pasglop>

Pong.  ;-)

On Tue, Sep 11, 2012 at 04:03:31PM +1000, Benjamin Herrenschmidt wrote:
> On Mon, 2012-09-10 at 14:22 +0000, Arnd Bergmann wrote:
> > Following up on the old discussion, I talked briefly about this
> > issue with BenH at the kernel summit. The outcome basically is that
> > it's a bit sad to have incompatible bindings, but it's not the end
> > of the world,and it's more important to do it right this time.
> > 
> > Just make sure that you use different values for the 'compatible'
> > strings and then do what you need to get the ARM hardware working.
> > 
> > Ideally, the new binding should be written in a way that powerpc
> > machines can use the same one, but the existing ones all use
> > an version of Open Firmware that is not going to get updated
> > and it's also not too likely that we are going to see new
> > powerpc machines based on this chip.
> 
> Right, mostly these machines where the Pegasos. Those came with a fairly
> busted variant of Open Firmware which generated a pretty gross
> device-tree.
> 
> For some reason, the manufacturer of those things was never willing to
> fix anything in their firmware (despite the distributor providing
> patches etc...), seemingly on the assumption that whatever they were
> doing was perfect and operating system people like us didn't matter one
> little bit :-)
> 
> So I don't care much about it. It would be nice to keep them working
> since people in the community still have them but if it goes through
> some "compat" code that detects old/broken device-trees and eventually
> disappears when we finally drop support, then so be it.

Ian,

What is the status of this work?

thx,

Jason.

^ permalink raw reply

* Re: PowerMac PMU programming
From: Justin Hibbits @ 2012-10-21  2:56 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev
In-Reply-To: <1339449862.9220.13.camel@pasglop>

Hi Ben,

Looking at this again, so bringing up this thread, although it is 4
months old.

On Tue, 12 Jun 2012 07:24:22 +1000
Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:

> On Sun, 2012-06-10 at 23:31 -0400, Justin Hibbits wrote:
>=20
> > I'll settle on just getting the CPU speed change working, losing
> > 333MHz on my TiBook is a few too many MHz for the poor thing to
> > lose :)  I do have a desktop, but that's my development platform,
> > so needs to be at least somewhat stable, so my TiBook is my guinea
> > pig.
> >=20
> > I've googled everything I can think of, but do you know of any
> > definitive PMU documentation?  Or can you give me any hints on
> > what's needed just for that simple operation?
>=20
> No doco no, Darwin and Linux source code are your best bet.
>=20
> It works like sleep as in: you send the switch command and the PMU
> will reboot the processor with the new frequency whenever the
> processor enters NAP mode.
>=20
> This is tricky because there's a loss of cache coherency vs. ongoing
> DMAs, hence tricky bits of code in there to deal with the various
> caches.
>=20
> > I noticed that you wind down the ADB queue before killing the PMU.
> > Is this necessary?  I only disable the interrupt by writing 0x10 to
> > the IER, but our interrupt model for the PMU is different from the
> > Linux one.=20
>=20
> Well that will not disable CB1 (or the external GPIO one). You need to
> make sure no other communication with the PMU takes place once you've
> sent the sleep command and until you're back.
>=20
> >  Is it also necessary to disable the interrupt input, even though
> > the register write should be disabling the PMU's asserting of the
> > line?  There doesn't seem to be much more different than that, and
> > setting the openpic priority, Linux sets it to 0x0f but I didn't see
> > anything in OS X doing that (might that be a problem, too?)
> >=20
> > I would love to get my TiBook using the full 1GHz.
>=20
> I don't remember what openpic does in Darwin, I think interrupts are
> all masked there as a side effect of the code in KeyLargo.cpp but I'm
> not sure that applies to frequency changes.
>=20
> Cheers,
> Ben.

=46rom looking at the Linux PMU source, and the FreeBSD source, I can see
only cosmetic differences.  However, the biggest thing I see between
the Linux PPC code and the FreeBSD code is that Linux quiesces Open
Firmware right away.  I haven't tried this with FreeBSD yet, but from
your experience with development on this platform, would you think that
not quiescing OFW might cause the catatonic state?

- Justin

^ permalink raw reply

* [PATCH 3/5] arch/powerpc/kernel/rtas_flash.c: eliminate possible double free
From: Julia Lawall @ 2012-10-21 10:52 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Paul Mackerras, kernel-janitors, linuxppc-dev, linux-kernel
In-Reply-To: <1350816727-1381-1-git-send-email-Julia.Lawall@lip6.fr>

From: Julia Lawall <Julia.Lawall@lip6.fr>

The function initialize_flash_pde_data is only called four times.  All four
calls are in the function rtas_flash_init, and on the failure of any of the
calls, remove_flash_pde is called on the third argument of each of the
calls.  There is thus no need for initialize_flash_pde_data to call
remove_flash_pde on the same argument.  remove_flash_pde kfrees the data
field of its argument, and does not clear that field, so this amounts ot a
possible double free.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier f,free,a;
parameter list[n] ps;
type T;
expression e;
@@

f(ps,T a,...) {
  ... when any
      when != a = e
  if(...) { ... free(a); ... return ...; }
  ... when any
}

@@
identifier r.f,r.free;
expression x,a;
expression list[r.n] xs;
@@

* x = f(xs,a,...);
  if (...) { ... free(a); ... return ...; }
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
Not tested.

 arch/powerpc/kernel/rtas_flash.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/rtas_flash.c b/arch/powerpc/kernel/rtas_flash.c
index 20b0120..8329190 100644
--- a/arch/powerpc/kernel/rtas_flash.c
+++ b/arch/powerpc/kernel/rtas_flash.c
@@ -650,10 +650,8 @@ static int initialize_flash_pde_data(const char *rtas_call_name,
 	int token;
 
 	dp->data = kzalloc(buf_size, GFP_KERNEL);
-	if (dp->data == NULL) {
-		remove_flash_pde(dp);
+	if (dp->data == NULL)
 		return -ENOMEM;
-	}
 
 	/*
 	 * This code assumes that the status int is the first member of the

^ permalink raw reply related

* Re: ELDK 4.2/kilauea/3.5+ kernel broken
From: Robert Berger @ 2012-10-21 15:39 UTC (permalink / raw)
  To: linuxppc-dev
In-Reply-To: <1350587006.2476.12.camel__24873.815305955$1350587085$gmane$org@pasglop>

Hi,

On 10/18/2012 10:03 PM, Benjamin Herrenschmidt wrote:
>
> Which looks correct. So this might be something specific to ELDK ?

I just tried with the ELDK 5.2.1 and have exactly the same behavior as
with ELDK 4.2, so I guess there is something not correct in
arch/powerpc/sysdev/ppc4xx_msi.c.

Just to exclude the case that I'm doing something stupid which only
affects kernel versions 3.5+ and not 3.4 can someone else give it a try
with a kilauea board or something similar?

Regards,

Robert

>
> Cheers,
> Ben.
>

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox