提交 0ee6d1ee 编写于 作者: N Nicolas Ferre

USB: ohci-at91: change maximum number of ports

Change number of ports to 3 for newer SoCs. Modify pdata structure
and ohci-at91 code that was dealing with ports information and check
of port indexes.
Several coding style errors have been addresses as the patch was touching
affected lines of code and was producing errors while run through
checkpatch.pl.
Signed-off-by: NNicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: NJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: NAlan Stern <stern@rowland.harvard.edu>
上级 aaf9f5fc
...@@ -86,14 +86,15 @@ extern void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *d ...@@ -86,14 +86,15 @@ extern void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *d
extern void __init at91_add_device_eth(struct macb_platform_data *data); extern void __init at91_add_device_eth(struct macb_platform_data *data);
/* USB Host */ /* USB Host */
#define AT91_MAX_USBH_PORTS 3
struct at91_usbh_data { struct at91_usbh_data {
u8 ports; /* number of ports on root hub */ int vbus_pin[AT91_MAX_USBH_PORTS]; /* port power-control pin */
int vbus_pin[2]; /* port power-control pin */ int overcurrent_pin[AT91_MAX_USBH_PORTS];
u8 vbus_pin_active_low[2]; u8 ports; /* number of ports on root hub */
u8 overcurrent_supported; u8 overcurrent_supported;
int overcurrent_pin[2]; u8 vbus_pin_active_low[AT91_MAX_USBH_PORTS];
u8 overcurrent_status[2]; u8 overcurrent_status[AT91_MAX_USBH_PORTS];
u8 overcurrent_changed[2]; u8 overcurrent_changed[AT91_MAX_USBH_PORTS];
}; };
extern void __init at91_add_device_usbh(struct at91_usbh_data *data); extern void __init at91_add_device_usbh(struct at91_usbh_data *data);
extern void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data); extern void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data);
......
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
#error "CONFIG_ARCH_AT91 must be defined." #error "CONFIG_ARCH_AT91 must be defined."
#endif #endif
#define valid_port(index) ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS)
#define at91_for_each_port(index) \
for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++)
/* interface and function clocks; sometimes also an AHB clock */ /* interface and function clocks; sometimes also an AHB clock */
static struct clk *iclk, *fclk, *hclk; static struct clk *iclk, *fclk, *hclk;
static int clocked; static int clocked;
...@@ -240,7 +244,7 @@ ohci_at91_start (struct usb_hcd *hcd) ...@@ -240,7 +244,7 @@ ohci_at91_start (struct usb_hcd *hcd)
static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable) static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable)
{ {
if (port < 0 || port >= 2) if (!valid_port(port))
return; return;
if (!gpio_is_valid(pdata->vbus_pin[port])) if (!gpio_is_valid(pdata->vbus_pin[port]))
...@@ -252,7 +256,7 @@ static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int ...@@ -252,7 +256,7 @@ static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int
static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port) static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
{ {
if (port < 0 || port >= 2) if (!valid_port(port))
return -EINVAL; return -EINVAL;
if (!gpio_is_valid(pdata->vbus_pin[port])) if (!gpio_is_valid(pdata->vbus_pin[port]))
...@@ -271,9 +275,9 @@ static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf) ...@@ -271,9 +275,9 @@ static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
int length = ohci_hub_status_data(hcd, buf); int length = ohci_hub_status_data(hcd, buf);
int port; int port;
for (port = 0; port < ARRAY_SIZE(pdata->overcurrent_pin); port++) { at91_for_each_port(port) {
if (pdata->overcurrent_changed[port]) { if (pdata->overcurrent_changed[port]) {
if (! length) if (!length)
length = 1; length = 1;
buf[0] |= 1 << (port + 1); buf[0] |= 1 << (port + 1);
} }
...@@ -297,11 +301,17 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, ...@@ -297,11 +301,17 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
"ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n", "ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
hcd, typeReq, wValue, wIndex, buf, wLength); hcd, typeReq, wValue, wIndex, buf, wLength);
wIndex--;
switch (typeReq) { switch (typeReq) {
case SetPortFeature: case SetPortFeature:
if (wValue == USB_PORT_FEAT_POWER) { if (wValue == USB_PORT_FEAT_POWER) {
dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n"); dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
ohci_at91_usb_set_power(pdata, wIndex - 1, 1); if (valid_port(wIndex)) {
ohci_at91_usb_set_power(pdata, wIndex, 1);
ret = 0;
}
goto out; goto out;
} }
break; break;
...@@ -312,9 +322,9 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, ...@@ -312,9 +322,9 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
dev_dbg(hcd->self.controller, dev_dbg(hcd->self.controller,
"ClearPortFeature: C_OVER_CURRENT\n"); "ClearPortFeature: C_OVER_CURRENT\n");
if (wIndex == 1 || wIndex == 2) { if (valid_port(wIndex)) {
pdata->overcurrent_changed[wIndex-1] = 0; pdata->overcurrent_changed[wIndex] = 0;
pdata->overcurrent_status[wIndex-1] = 0; pdata->overcurrent_status[wIndex] = 0;
} }
goto out; goto out;
...@@ -323,9 +333,8 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, ...@@ -323,9 +333,8 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
dev_dbg(hcd->self.controller, dev_dbg(hcd->self.controller,
"ClearPortFeature: OVER_CURRENT\n"); "ClearPortFeature: OVER_CURRENT\n");
if (wIndex == 1 || wIndex == 2) { if (valid_port(wIndex))
pdata->overcurrent_status[wIndex-1] = 0; pdata->overcurrent_status[wIndex] = 0;
}
goto out; goto out;
...@@ -333,15 +342,15 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, ...@@ -333,15 +342,15 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
dev_dbg(hcd->self.controller, dev_dbg(hcd->self.controller,
"ClearPortFeature: POWER\n"); "ClearPortFeature: POWER\n");
if (wIndex == 1 || wIndex == 2) { if (valid_port(wIndex)) {
ohci_at91_usb_set_power(pdata, wIndex - 1, 0); ohci_at91_usb_set_power(pdata, wIndex, 0);
return 0; return 0;
} }
} }
break; break;
} }
ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength);
if (ret) if (ret)
goto out; goto out;
...@@ -377,18 +386,15 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, ...@@ -377,18 +386,15 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex); dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
if (wIndex == 1 || wIndex == 2) { if (valid_port(wIndex)) {
if (! ohci_at91_usb_get_power(pdata, wIndex-1)) { if (!ohci_at91_usb_get_power(pdata, wIndex))
*data &= ~cpu_to_le32(RH_PS_PPS); *data &= ~cpu_to_le32(RH_PS_PPS);
}
if (pdata->overcurrent_changed[wIndex-1]) { if (pdata->overcurrent_changed[wIndex])
*data |= cpu_to_le32(RH_PS_OCIC); *data |= cpu_to_le32(RH_PS_OCIC);
}
if (pdata->overcurrent_status[wIndex-1]) { if (pdata->overcurrent_status[wIndex])
*data |= cpu_to_le32(RH_PS_POCI); *data |= cpu_to_le32(RH_PS_POCI);
}
} }
} }
...@@ -450,14 +456,14 @@ static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data) ...@@ -450,14 +456,14 @@ static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
/* From the GPIO notifying the over-current situation, find /* From the GPIO notifying the over-current situation, find
* out the corresponding port */ * out the corresponding port */
for (port = 0; port < ARRAY_SIZE(pdata->overcurrent_pin); port++) { at91_for_each_port(port) {
if (gpio_to_irq(pdata->overcurrent_pin[port]) == irq) { if (gpio_to_irq(pdata->overcurrent_pin[port]) == irq) {
gpio = pdata->overcurrent_pin[port]; gpio = pdata->overcurrent_pin[port];
break; break;
} }
} }
if (port == ARRAY_SIZE(pdata->overcurrent_pin)) { if (port == AT91_MAX_USBH_PORTS) {
dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n"); dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n");
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -467,7 +473,7 @@ static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data) ...@@ -467,7 +473,7 @@ static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
/* When notified of an over-current situation, disable power /* When notified of an over-current situation, disable power
on the corresponding port, and mark this port in on the corresponding port, and mark this port in
over-current. */ over-current. */
if (! val) { if (!val) {
ohci_at91_usb_set_power(pdata, port, 0); ohci_at91_usb_set_power(pdata, port, 0);
pdata->overcurrent_status[port] = 1; pdata->overcurrent_status[port] = 1;
pdata->overcurrent_changed[port] = 1; pdata->overcurrent_changed[port] = 1;
...@@ -514,7 +520,7 @@ static int __devinit ohci_at91_of_init(struct platform_device *pdev) ...@@ -514,7 +520,7 @@ static int __devinit ohci_at91_of_init(struct platform_device *pdev)
if (!of_property_read_u32(np, "num-ports", &ports)) if (!of_property_read_u32(np, "num-ports", &ports))
pdata->ports = ports; pdata->ports = ports;
for (i = 0; i < 2; i++) { at91_for_each_port(i) {
gpio = of_get_named_gpio_flags(np, "atmel,vbus-gpio", i, &flags); gpio = of_get_named_gpio_flags(np, "atmel,vbus-gpio", i, &flags);
pdata->vbus_pin[i] = gpio; pdata->vbus_pin[i] = gpio;
if (!gpio_is_valid(gpio)) if (!gpio_is_valid(gpio))
...@@ -522,7 +528,7 @@ static int __devinit ohci_at91_of_init(struct platform_device *pdev) ...@@ -522,7 +528,7 @@ static int __devinit ohci_at91_of_init(struct platform_device *pdev)
pdata->vbus_pin_active_low[i] = flags & OF_GPIO_ACTIVE_LOW; pdata->vbus_pin_active_low[i] = flags & OF_GPIO_ACTIVE_LOW;
} }
for (i = 0; i < 2; i++) at91_for_each_port(i)
pdata->overcurrent_pin[i] = pdata->overcurrent_pin[i] =
of_get_named_gpio_flags(np, "atmel,oc-gpio", i, &flags); of_get_named_gpio_flags(np, "atmel,oc-gpio", i, &flags);
...@@ -554,7 +560,7 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev) ...@@ -554,7 +560,7 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
pdata = pdev->dev.platform_data; pdata = pdev->dev.platform_data;
if (pdata) { if (pdata) {
for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) { at91_for_each_port(i) {
if (!gpio_is_valid(pdata->vbus_pin[i])) if (!gpio_is_valid(pdata->vbus_pin[i]))
continue; continue;
gpio = pdata->vbus_pin[i]; gpio = pdata->vbus_pin[i];
...@@ -578,7 +584,7 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev) ...@@ -578,7 +584,7 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
ohci_at91_usb_set_power(pdata, i, 1); ohci_at91_usb_set_power(pdata, i, 1);
} }
for (i = 0; i < ARRAY_SIZE(pdata->overcurrent_pin); i++) { at91_for_each_port(i) {
if (!gpio_is_valid(pdata->overcurrent_pin[i])) if (!gpio_is_valid(pdata->overcurrent_pin[i]))
continue; continue;
gpio = pdata->overcurrent_pin[i]; gpio = pdata->overcurrent_pin[i];
...@@ -621,14 +627,14 @@ static int ohci_hcd_at91_drv_remove(struct platform_device *pdev) ...@@ -621,14 +627,14 @@ static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
int i; int i;
if (pdata) { if (pdata) {
for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) { at91_for_each_port(i) {
if (!gpio_is_valid(pdata->vbus_pin[i])) if (!gpio_is_valid(pdata->vbus_pin[i]))
continue; continue;
ohci_at91_usb_set_power(pdata, i, 0); ohci_at91_usb_set_power(pdata, i, 0);
gpio_free(pdata->vbus_pin[i]); gpio_free(pdata->vbus_pin[i]);
} }
for (i = 0; i < ARRAY_SIZE(pdata->overcurrent_pin); i++) { at91_for_each_port(i) {
if (!gpio_is_valid(pdata->overcurrent_pin[i])) if (!gpio_is_valid(pdata->overcurrent_pin[i]))
continue; continue;
free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev); free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册