X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/84fdb577b9f2afa1f1c7ffb7eff9e98047331552..a5e3f9b1977f4bfe24df52c2522549f911642d27:/target/linux/adm5120-2.6/files/drivers/usb/host/adm5120-hcd.c diff --git a/target/linux/adm5120-2.6/files/drivers/usb/host/adm5120-hcd.c b/target/linux/adm5120-2.6/files/drivers/usb/host/adm5120-hcd.c index 8dabeeb8f..bd6f7a0aa 100644 --- a/target/linux/adm5120-2.6/files/drivers/usb/host/adm5120-hcd.c +++ b/target/linux/adm5120-2.6/files/drivers/usb/host/adm5120-hcd.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -30,6 +31,8 @@ MODULE_DESCRIPTION("ADM5120 USB Host Controller Driver"); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Jeroen Vreeken (pe1rxq@amsat.org)"); +#define PFX "adm5120-hcd: " + #define ADMHCD_REG_CONTROL 0x00 #define ADMHCD_REG_INTSTATUS 0x04 #define ADMHCD_REG_INTENABLE 0x08 @@ -60,8 +63,17 @@ MODULE_AUTHOR("Jeroen Vreeken (pe1rxq@amsat.org)"); #define ADMHCD_STATE_SUS 0x00000003 /* bus state suspended */ #define ADMHCD_DMA_EN 0x00000004 /* enable dma engine */ -#define ADMHCD_NPS 0x00000020 /* No Power Switch */ +#define ADMHCD_RST_ST 0x00 /* USB reset state */ +#define ADMHCD_RSM_ST 0x01 /* USB resume state */ +#define ADMHCD_OPR_ST 0x10 /* USB operational state */ +#define ADMHCD_SUS_ST 0x11 /* USB suspend state */ + +#define ADMHCD_NPS 0x00000200 /* No Power Switch */ +#define ADMHCD_PSM 0x00000100 /* Power switch mode */ +#define ADMHCD_OPCM 0x00000400 /* Over current protect mode */ +#define ADMHCD_NOCP 0x00000800 /* No over current protect mode */ #define ADMHCD_LPSC 0x04000000 /* Local power switch change */ +#define ADMHCD_LPS 0x01000000 /* Local power switch/global power switch */ #define ADMHCD_CCS 0x00000001 /* current connect status */ #define ADMHCD_PES 0x00000002 /* port enable status */ @@ -147,7 +159,6 @@ static int admhcd_td_err[16] = { struct admhcd { spinlock_t lock; - void __iomem *addr_reg; void __iomem *data_reg; /* Root hub registers */ u32 rhdesca; @@ -328,9 +339,8 @@ static void admhcd_ed_start(struct admhcd *ahcd, struct admhcd_ed *ed) ahcd->dma_en |= ADMHCD_DMA_EN; } -static irqreturn_t adm5120hcd_irq(int irq, void *ptr, struct pt_regs *regs) +static irqreturn_t adm5120hcd_irq(struct usb_hcd *hcd) { - struct usb_hcd *hcd = (struct usb_hcd *)ptr; struct admhcd *ahcd = hcd_to_admhcd(hcd); u32 intstatus; @@ -685,102 +695,193 @@ err: return retval; } +static int admhcd_start(struct usb_hcd *hcd) +{ + struct admhcd *ahcd = hcd_to_admhcd(hcd); + unsigned long flags; + + spin_lock_irqsave(&ahcd->lock, flags); + + /* Initialise the HCD registers */ + admhcd_reg_set(ahcd, ADMHCD_REG_INTENABLE, 0); + mdelay(10); + + admhcd_reg_set(ahcd, ADMHCD_REG_CONTROL, ADMHCD_SW_RESET); + + while (admhcd_reg_get(ahcd, ADMHCD_REG_CONTROL) & ADMHCD_SW_RESET) + mdelay(1); + + /* Enable USB host mode */ + admhcd_reg_set(ahcd, ADMHCD_REG_CONTROL, ADMHCD_HOST_EN); + + /* Set host specific settings */ + admhcd_reg_set(ahcd, ADMHCD_REG_HOSTHEAD, 0x00000000); + admhcd_reg_set(ahcd, ADMHCD_REG_FMINTERVAL, 0x20002edf); + admhcd_reg_set(ahcd, ADMHCD_REG_LSTHRESH, 0x628); + + /* Set interrupts */ + admhcd_reg_set(ahcd, ADMHCD_REG_INTENABLE, + ADMHCD_INT_ACT | ADMHCD_INT_FATAL | ADMHCD_INT_SW | ADMHCD_INT_TD); + admhcd_reg_set(ahcd, ADMHCD_REG_INTSTATUS, + ADMHCD_INT_ACT | ADMHCD_INT_FATAL | ADMHCD_INT_SW | ADMHCD_INT_TD); + + admhcd_reg_set(ahcd, ADMHCD_REG_RHDESCR, ADMHCD_NPS | ADMHCD_LPSC); + admhcd_reg_set(ahcd, ADMHCD_REG_HOSTCONTROL, ADMHCD_STATE_OP); + + + hcd->state = HC_STATE_RUNNING; + + spin_unlock_irqrestore(&ahcd->lock, flags); + return 0; +} + +static int admhcd_sw_reset(struct admhcd *ahcd) +{ + int retries = 15; + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(&ahcd->lock, flags); + + admhcd_reg_set(ahcd, ADMHCD_REG_INTENABLE, 0); + mdelay(10); + + admhcd_reg_set(ahcd, ADMHCD_REG_CONTROL, ADMHCD_SW_RESET); + + while (--retries) { + mdelay(1); + if (!(admhcd_reg_get(ahcd, ADMHCD_REG_CONTROL) & ADMHCD_SW_RESET)) + break; + } + if (!retries) { + printk(KERN_WARNING "%s Software reset timeout\n", hcd_name); + ret = -ETIME; + } + spin_unlock_irqrestore(&ahcd->lock, flags); + return ret; +} + +static int admhcd_reset(struct usb_hcd *hcd) +{ + struct admhcd *ahcd = hcd_to_admhcd(hcd); + u32 val = 0; + int ret, timeout = 15; /* ms */ + unsigned long t; + + ret = admhcd_sw_reset(ahcd); + if (ret) + return ret; + + t = jiffies + msecs_to_jiffies(timeout); + while (time_before_eq(jiffies, t)) { + msleep(4); + spin_lock_irq(&ahcd->lock); + val = admhcd_reg_get(ahcd, ADMHCD_REG_HOSTCONTROL) & ADMHCD_OPR_ST; + spin_unlock_irq(&ahcd->lock); + if (val) + break; + } + if (!val) { + printk(KERN_WARNING "Device not ready after %dms\n", timeout); + ret = -ENODEV; + } + return ret; +} + +static void admhcd_stop(struct usb_hcd *hcd) +{ + struct admhcd *ahcd = hcd_to_admhcd(hcd); + unsigned long flags; + u32 val; + + spin_lock_irqsave(&ahcd->lock, flags); + admhcd_reg_set(ahcd, ADMHCD_REG_INTENABLE, 0); + + /* Set global control of power for ports */ + val = admhcd_reg_get(ahcd, ADMHCD_REG_RHDESCR); + val &= (~ADMHCD_PSM | ADMHCD_LPS); + admhcd_reg_set(ahcd, ADMHCD_REG_RHDESCR, val); + + spin_unlock_irqrestore(&ahcd->lock, flags); + + /* Ask for software reset */ + admhcd_sw_reset(ahcd); +} + + static struct hc_driver adm5120_hc_driver = { .description = hcd_name, .product_desc = "ADM5120 HCD", .hcd_priv_size = sizeof(struct admhcd), - .flags = HCD_USB11, + .irq = adm5120hcd_irq, + .flags = HCD_MEMORY|HCD_USB11, .urb_enqueue = admhcd_urb_enqueue, .urb_dequeue = admhcd_urb_dequeue, .endpoint_disable = admhcd_endpoint_disable, .get_frame_number = admhcd_get_frame_number, .hub_status_data = admhcd_hub_status_data, .hub_control = admhcd_hub_control, + .start = admhcd_start, + .stop = admhcd_stop, + .reset = admhcd_reset, }; #define resource_len(r) (((r)->end - (r)->start) + 1) static int __init adm5120hcd_probe(struct platform_device *pdev) { - struct usb_hcd *hcd; - struct admhcd *ahcd; - struct resource *addr, *data; - void __iomem *addr_reg; + struct usb_hcd *hcd; + struct admhcd *ahcd; + struct resource *data; void __iomem *data_reg; - int irq, err = 0; - if (pdev->num_resources < 3) { - err = -ENODEV; - goto out; - } - - data = platform_get_resource(pdev, IORESOURCE_MEM, 0); - addr = platform_get_resource(pdev, IORESOURCE_MEM, 1); + int err = 0, irq; - if (request_irq(data->start, adm5120hcd_irq, 0, hcd_name, hcd)) { - printk(KERN_WARNING "Could not request IRQ\n"); - err = -EBUSY; - goto out; - } - - if (!addr || !data || irq < 0) { + if (pdev->num_resources < 2) { err = -ENODEV; goto out; - } + } if (pdev->dev.dma_mask) { - printk(KERN_DEBUG "DMA not supported\n"); - err = -EINVAL; - goto out; - } + printk(KERN_DEBUG "no we won't dma\n"); + return -EINVAL; + } - if (!request_mem_region(addr->start, 2, hcd_name)) { - err = -EBUSY; - goto out; - } - addr_reg = ioremap(addr->start, resource_len(addr)); - if (addr_reg == NULL) { - err = -ENOMEM; - goto out_mem; - } - if (!request_mem_region(data->start, 2, hcd_name)) { - err = -EBUSY; - goto out_unmap; - } - data_reg = ioremap(data->start, resource_len(data)); - if (data_reg == NULL) { - err = -ENOMEM; - goto out_mem; - } + irq = platform_get_irq(pdev, 0); + data = platform_get_resource(pdev, IORESOURCE_MEM, 0); + + if (!data || irq < 0) { + err = -ENODEV; + goto out; + } + + if (!request_mem_region(data->start, 2, hcd_name)) { + err = -EBUSY; + goto out_unmap; + } + data_reg = ioremap(data->start, resource_len(data)); + if (data_reg == NULL) { + err = -ENOMEM; + goto out_mem; + } hcd = usb_create_hcd(&adm5120_hc_driver, &pdev->dev, pdev->dev.bus_id); - if (!hcd) - goto out_mem; + if (!hcd) + goto out_mem; + hcd->rsrc_start = data->start; + hcd->rsrc_len = resource_len(data); + hcd->regs = (u32)data_reg; ahcd = hcd_to_admhcd(hcd); - ahcd->data_reg = data_reg; - ahcd->addr_reg = addr_reg; + spin_lock_init(&ahcd->lock); INIT_LIST_HEAD(&ahcd->async); - /* Initialise the HCD registers */ - admhcd_reg_set(ahcd, ADMHCD_REG_INTENABLE, 0); - mdelay(10); - admhcd_reg_set(ahcd, ADMHCD_REG_CONTROL, ADMHCD_SW_RESET); - while (admhcd_reg_get(ahcd, ADMHCD_REG_CONTROL) & ADMHCD_SW_RESET) - mdelay(1); + ahcd->data_reg = data_reg; + ahcd->base = (u32)data_reg; - admhcd_reg_set(ahcd, ADMHCD_REG_CONTROL, ADMHCD_HOST_EN); - admhcd_reg_set(ahcd, ADMHCD_REG_HOSTHEAD, 0x00000000); - admhcd_reg_set(ahcd, ADMHCD_REG_FMINTERVAL, 0x20002edf); - admhcd_reg_set(ahcd, ADMHCD_REG_LSTHRESH, 0x628); - admhcd_reg_set(ahcd, ADMHCD_REG_INTENABLE, - ADMHCD_INT_ACT | ADMHCD_INT_FATAL | ADMHCD_INT_SW | ADMHCD_INT_TD); - admhcd_reg_set(ahcd, ADMHCD_REG_INTSTATUS, - ADMHCD_INT_ACT | ADMHCD_INT_FATAL | ADMHCD_INT_SW | ADMHCD_INT_TD); - admhcd_reg_set(ahcd, ADMHCD_REG_RHDESCR, ADMHCD_NPS | ADMHCD_LPSC); - admhcd_reg_set(ahcd, ADMHCD_REG_HOSTCONTROL, ADMHCD_STATE_OP); + hcd->product_desc = "ADM5120 HCD"; err = usb_add_hcd(hcd, irq, IRQF_DISABLED); if (err) @@ -791,9 +892,9 @@ static int __init adm5120hcd_probe(struct platform_device *pdev) out_dev: usb_put_hcd(hcd); out_unmap: - iounmap(addr_reg); + iounmap(data_reg); out_mem: - release_mem_region(addr->start, 2); + release_mem_region(pdev->resource[0].start, pdev->resource[0].end - pdev->resource[0].start +1); out: return err; } @@ -816,19 +917,30 @@ static struct platform_driver adm5120hcd_driver = { .probe = adm5120hcd_probe, .remove = adm5120hcd_remove, .driver = { - .name = "adm5120-hcd", + .name = "adm5120-usbc", .owner = THIS_MODULE, }, }; static int __init adm5120hcd_init(void) { - if (usb_disabled()) + int ret; + + if (usb_disabled()) { + printk(KERN_DEBUG PFX "USB support is disabled\n"); return -ENODEV; - if (!adm5120_board.has_usb) + } + + if (mips_machgroup != MACH_GROUP_ADM5120) { + printk(KERN_DEBUG PFX "unsupported machine group\n"); return -ENODEV; + } - return platform_driver_register(&adm5120hcd_driver); + ret = platform_driver_register(&adm5120hcd_driver); + if (ret == 0) + printk(KERN_INFO PFX "registered\n"); + + return ret; } static void __exit adm5120hcd_exit(void)