xref: /openbmc/linux/arch/mips/bcm63xx/dev-usb-usbd.c (revision 799a545b)
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7  * Copyright (C) 2012 Kevin Cernekee <cernekee@gmail.com>
8  * Copyright (C) 2012 Broadcom Corporation
9  */
10 
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/platform_device.h>
14 #include <linux/dma-mapping.h>
15 #include <bcm63xx_cpu.h>
16 #include <bcm63xx_dev_usb_usbd.h>
17 
18 #define NUM_MMIO		2
19 #define NUM_IRQ			7
20 
21 static struct resource usbd_resources[NUM_MMIO + NUM_IRQ];
22 
23 static u64 usbd_dmamask = DMA_BIT_MASK(32);
24 
25 static struct platform_device bcm63xx_usbd_device = {
26 	.name		= "bcm63xx_udc",
27 	.id		= -1,
28 	.num_resources	= ARRAY_SIZE(usbd_resources),
29 	.resource	= usbd_resources,
30 	.dev		= {
31 		.dma_mask		= &usbd_dmamask,
32 		.coherent_dma_mask	= DMA_BIT_MASK(32),
33 	},
34 };
35 
36 int __init bcm63xx_usbd_register(const struct bcm63xx_usbd_platform_data *pd)
37 {
38 	const int irq_list[NUM_IRQ] = { IRQ_USBD,
39 		IRQ_USBD_RXDMA0, IRQ_USBD_TXDMA0,
40 		IRQ_USBD_RXDMA1, IRQ_USBD_TXDMA1,
41 		IRQ_USBD_RXDMA2, IRQ_USBD_TXDMA2 };
42 	int i;
43 
44 	if (!BCMCPU_IS_6328() && !BCMCPU_IS_6368())
45 		return 0;
46 
47 	usbd_resources[0].start = bcm63xx_regset_address(RSET_USBD);
48 	usbd_resources[0].end = usbd_resources[0].start + RSET_USBD_SIZE - 1;
49 	usbd_resources[0].flags = IORESOURCE_MEM;
50 
51 	usbd_resources[1].start = bcm63xx_regset_address(RSET_USBDMA);
52 	usbd_resources[1].end = usbd_resources[1].start + RSET_USBDMA_SIZE - 1;
53 	usbd_resources[1].flags = IORESOURCE_MEM;
54 
55 	for (i = 0; i < NUM_IRQ; i++) {
56 		struct resource *r = &usbd_resources[NUM_MMIO + i];
57 
58 		r->start = r->end = bcm63xx_get_irq_number(irq_list[i]);
59 		r->flags = IORESOURCE_IRQ;
60 	}
61 
62 	platform_device_add_data(&bcm63xx_usbd_device, pd, sizeof(*pd));
63 
64 	return platform_device_register(&bcm63xx_usbd_device);
65 }
66