1225394Sjchandra/*-
2225394Sjchandra * Copyright 2003-2011 Netlogic Microsystems (Netlogic). All rights
3225394Sjchandra * reserved.
4225394Sjchandra *
5225394Sjchandra * Redistribution and use in source and binary forms, with or without
6225394Sjchandra * modification, are permitted provided that the following conditions are
7225394Sjchandra * met:
8225394Sjchandra *
9225394Sjchandra * 1. Redistributions of source code must retain the above copyright
10225394Sjchandra *    notice, this list of conditions and the following disclaimer.
11225394Sjchandra * 2. Redistributions in binary form must reproduce the above copyright
12225394Sjchandra *    notice, this list of conditions and the following disclaimer in
13225394Sjchandra *    the documentation and/or other materials provided with the
14225394Sjchandra *    distribution.
15225394Sjchandra *
16225394Sjchandra * THIS SOFTWARE IS PROVIDED BY Netlogic Microsystems ``AS IS'' AND
17225394Sjchandra * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18225394Sjchandra * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19225394Sjchandra * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE
20225394Sjchandra * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21225394Sjchandra * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22225394Sjchandra * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23225394Sjchandra * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24225394Sjchandra * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25225394Sjchandra * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26225394Sjchandra * THE POSSIBILITY OF SUCH DAMAGE.
27225394Sjchandra *
28225394Sjchandra * NETLOGIC_BSD */
29225394Sjchandra
30225394Sjchandra#include <sys/cdefs.h>
31225394Sjchandra__FBSDID("$FreeBSD$");
32225394Sjchandra#include <sys/types.h>
33225394Sjchandra#include <sys/systm.h>
34225394Sjchandra#include <sys/param.h>
35225394Sjchandra#include <sys/kernel.h>
36225394Sjchandra
37225394Sjchandra#include <mips/nlm/hal/haldefs.h>
38225394Sjchandra#include <mips/nlm/hal/iomap.h>
39225394Sjchandra#include <mips/nlm/hal/usb.h>
40225394Sjchandra
41225394Sjchandra#include <mips/nlm/xlp.h>
42225394Sjchandra
43225394Sjchandra
44225394Sjchandrastatic void
45225394Sjchandranlm_usb_intr_en(int node, int port)
46225394Sjchandra{
47225394Sjchandra	uint32_t val;
48225394Sjchandra	uint64_t port_addr;
49225394Sjchandra
50279387Sjchandra	port_addr = nlm_get_usb_regbase(node, port);
51225394Sjchandra	val = nlm_read_usb_reg(port_addr, USB_INT_EN);
52279387Sjchandra	val = USB_CTRL_INTERRUPT_EN  | USB_OHCI_INTERRUPT_EN |
53225394Sjchandra		USB_OHCI_INTERRUPT1_EN | USB_CTRL_INTERRUPT_EN  |
54225394Sjchandra		USB_OHCI_INTERRUPT_EN | USB_OHCI_INTERRUPT2_EN;
55225394Sjchandra        nlm_write_usb_reg(port_addr, USB_INT_EN, val);
56225394Sjchandra}
57225394Sjchandra
58279387Sjchandrastatic void
59225394Sjchandranlm_usb_hw_reset(int node, int port)
60225394Sjchandra{
61225394Sjchandra	uint64_t port_addr;
62225394Sjchandra	uint32_t val;
63279387Sjchandra
64225394Sjchandra	/* reset USB phy */
65279387Sjchandra	port_addr = nlm_get_usb_regbase(node, port);
66225394Sjchandra	val = nlm_read_usb_reg(port_addr, USB_PHY_0);
67225394Sjchandra	val &= ~(USB_PHY_RESET | USB_PHY_PORT_RESET_0 | USB_PHY_PORT_RESET_1);
68225394Sjchandra	nlm_write_usb_reg(port_addr, USB_PHY_0, val);
69279387Sjchandra
70225394Sjchandra	DELAY(100);
71225394Sjchandra	val = nlm_read_usb_reg(port_addr, USB_CTL_0);
72225394Sjchandra	val &= ~(USB_CONTROLLER_RESET);
73225394Sjchandra	val |= 0x4;
74225394Sjchandra	nlm_write_usb_reg(port_addr, USB_CTL_0, val);
75225394Sjchandra}
76225394Sjchandra
77279387Sjchandrastatic void
78225394Sjchandranlm_usb_init(void)
79225394Sjchandra{
80225394Sjchandra	/* XXX: should be checking if these are in Device mode here */
81225394Sjchandra	printf("Initialize USB Interface\n");
82279387Sjchandra	nlm_usb_hw_reset(0, 0);
83279387Sjchandra	nlm_usb_hw_reset(0, 3);
84225394Sjchandra
85225394Sjchandra	/* Enable PHY interrupts */
86279387Sjchandra	nlm_usb_intr_en(0, 0);
87279387Sjchandra	nlm_usb_intr_en(0, 3);
88225394Sjchandra}
89225394Sjchandra
90225394SjchandraSYSINIT(nlm_usb_init, SI_SUB_CPU, SI_ORDER_MIDDLE,
91225394Sjchandra    nlm_usb_init, NULL);
92