dwctwo_plb.c revision 1.1 1 1.1 kiyohara /* $NetBSD: dwctwo_plb.c,v 1.1 2013/11/21 13:33:15 kiyohara Exp $ */
2 1.1 kiyohara /*
3 1.1 kiyohara * Copyright (c) 2013 KIYOHARA Takashi
4 1.1 kiyohara * All rights reserved.
5 1.1 kiyohara *
6 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
7 1.1 kiyohara * modification, are permitted provided that the following conditions
8 1.1 kiyohara * are met:
9 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
10 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
11 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
13 1.1 kiyohara * documentation and/or other materials provided with the distribution.
14 1.1 kiyohara *
15 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 kiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 1.1 kiyohara * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 1.1 kiyohara * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 1.1 kiyohara * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 1.1 kiyohara * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 1.1 kiyohara * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 kiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 1.1 kiyohara * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 1.1 kiyohara * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 kiyohara * POSSIBILITY OF SUCH DAMAGE.
26 1.1 kiyohara */
27 1.1 kiyohara
28 1.1 kiyohara #include <sys/cdefs.h>
29 1.1 kiyohara __KERNEL_RCSID(0, "$NetBSD: dwctwo_plb.c,v 1.1 2013/11/21 13:33:15 kiyohara Exp $");
30 1.1 kiyohara
31 1.1 kiyohara #include <sys/param.h>
32 1.1 kiyohara #include <sys/bus.h>
33 1.1 kiyohara #include <sys/device.h>
34 1.1 kiyohara #include <sys/errno.h>
35 1.1 kiyohara #include <sys/extent.h>
36 1.1 kiyohara
37 1.1 kiyohara #include <powerpc/ibm4xx/cpu.h>
38 1.1 kiyohara #include <powerpc/ibm4xx/dev/plbvar.h>
39 1.1 kiyohara
40 1.1 kiyohara #include <dev/usb/usb.h>
41 1.1 kiyohara #include <dev/usb/usbdi.h>
42 1.1 kiyohara #include <dev/usb/usbdivar.h>
43 1.1 kiyohara #include <dev/usb/usb_mem.h>
44 1.1 kiyohara
45 1.1 kiyohara #include <dwc2/dwc2.h>
46 1.1 kiyohara #include <dwc2/dwc2var.h>
47 1.1 kiyohara #include "dwc2_core.h"
48 1.1 kiyohara
49 1.1 kiyohara #include "locators.h"
50 1.1 kiyohara
51 1.1 kiyohara #define DWCTWO_SIZE 0x40000
52 1.1 kiyohara
53 1.1 kiyohara static int dwctwo_plb_match(device_t, cfdata_t, void *);
54 1.1 kiyohara static void dwctwo_plb_attach(device_t, device_t, void *);
55 1.1 kiyohara
56 1.1 kiyohara static void dwctwo_plb_deferred(device_t);
57 1.1 kiyohara
58 1.1 kiyohara CFATTACH_DECL_NEW(dwctwo_plb, sizeof(struct dwc2_softc),
59 1.1 kiyohara dwctwo_plb_match, dwctwo_plb_attach, NULL, NULL);
60 1.1 kiyohara
61 1.1 kiyohara static struct powerpc_bus_space dwctwo_tag = {
62 1.1 kiyohara _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE,
63 1.1 kiyohara 0x00000000,
64 1.1 kiyohara 0x00000000,
65 1.1 kiyohara DWCTWO_SIZE
66 1.1 kiyohara };
67 1.1 kiyohara static char ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
68 1.1 kiyohara __attribute__((aligned(8)));
69 1.1 kiyohara
70 1.1 kiyohara static struct dwc2_core_params dwctwo_405ex_params = {
71 1.1 kiyohara .otg_cap = 0, /* HNP/SRP capable */
72 1.1 kiyohara .otg_ver = 0, /* 1.3 */
73 1.1 kiyohara .dma_enable = 1,
74 1.1 kiyohara .dma_desc_enable = 0,
75 1.1 kiyohara .speed = 0, /* High Speed */
76 1.1 kiyohara .enable_dynamic_fifo = 1,
77 1.1 kiyohara .en_multiple_tx_fifo = 0,
78 1.1 kiyohara .host_rx_fifo_size = 531, /* 531 DWORDs */
79 1.1 kiyohara .host_nperio_tx_fifo_size = 256, /* 256 DWORDs */
80 1.1 kiyohara .host_perio_tx_fifo_size = 256, /* 256 DWORDs */
81 1.1 kiyohara .max_transfer_size = 524287,
82 1.1 kiyohara .max_packet_count = 1023,
83 1.1 kiyohara .host_channels = 4,
84 1.1 kiyohara .phy_type = 2, /* ULPI */
85 1.1 kiyohara .phy_utmi_width = 8, /* 8 bits */
86 1.1 kiyohara .phy_ulpi_ddr = 0, /* Single */
87 1.1 kiyohara .phy_ulpi_ext_vbus = 0,
88 1.1 kiyohara .i2c_enable = 0,
89 1.1 kiyohara .ulpi_fs_ls = 0,
90 1.1 kiyohara .host_support_fs_ls_low_power = 0,
91 1.1 kiyohara .host_ls_low_power_phy_clk = 0, /* 48 MHz */
92 1.1 kiyohara .ts_dline = 0,
93 1.1 kiyohara .reload_ctl = 0,
94 1.1 kiyohara .ahbcfg = 0x10,
95 1.1 kiyohara .uframe_sched = 1,
96 1.1 kiyohara };
97 1.1 kiyohara
98 1.1 kiyohara
99 1.1 kiyohara static int
100 1.1 kiyohara dwctwo_plb_match(device_t parent, cfdata_t match, void *aux)
101 1.1 kiyohara {
102 1.1 kiyohara struct plb_attach_args *paa = aux;
103 1.1 kiyohara
104 1.1 kiyohara if (strcmp(paa->plb_name, match->cf_name) != 0)
105 1.1 kiyohara return 0;
106 1.1 kiyohara
107 1.1 kiyohara if (match->cf_loc[PLBCF_ADDR] == PLBCF_ADDR_DEFAULT)
108 1.1 kiyohara panic("dwctwo_plb_match: wildcard addr not allowed");
109 1.1 kiyohara if (match->cf_loc[PLBCF_IRQ] == PLBCF_IRQ_DEFAULT)
110 1.1 kiyohara panic("dwctwo_plb_match: wildcard IRQ not allowed");
111 1.1 kiyohara
112 1.1 kiyohara paa->plb_addr = match->cf_loc[PLBCF_ADDR];
113 1.1 kiyohara paa->plb_irq = match->cf_loc[PLBCF_IRQ];
114 1.1 kiyohara return 1;
115 1.1 kiyohara }
116 1.1 kiyohara
117 1.1 kiyohara static void
118 1.1 kiyohara dwctwo_plb_attach(device_t parent, device_t self, void *aux)
119 1.1 kiyohara {
120 1.1 kiyohara struct dwc2_softc *sc = device_private(self);
121 1.1 kiyohara struct plb_attach_args *paa = aux;
122 1.1 kiyohara uint32_t srst0;
123 1.1 kiyohara
124 1.1 kiyohara sc->sc_dev = self;
125 1.1 kiyohara sc->sc_params = &dwctwo_405ex_params;
126 1.1 kiyohara
127 1.1 kiyohara dwctwo_tag.pbs_base = paa->plb_addr;
128 1.1 kiyohara dwctwo_tag.pbs_limit += paa->plb_addr;
129 1.1 kiyohara if (bus_space_init(&dwctwo_tag, "dwctwotag", ex_storage,
130 1.1 kiyohara sizeof(ex_storage)))
131 1.1 kiyohara panic("dwctwo_attach: Failed to initialise opb_tag");
132 1.1 kiyohara sc->sc_iot = &dwctwo_tag;
133 1.1 kiyohara bus_space_map(sc->sc_iot, paa->plb_addr, DWCTWO_SIZE, 0, &sc->sc_ioh);
134 1.1 kiyohara sc->sc_bus.dmatag = paa->plb_dmat;
135 1.1 kiyohara
136 1.1 kiyohara intr_establish(paa->plb_irq, IST_LEVEL, IPL_USB, dwc2_intr, sc);
137 1.1 kiyohara
138 1.1 kiyohara /* Enable the USB interface. */
139 1.1 kiyohara mtsdr(DCR_SDR0_PFC1, mfsdr(DCR_SDR0_PFC1) | SDR0_PFC1_USBEN);
140 1.1 kiyohara srst0 = mfsdr(DCR_SDR0_SRST0);
141 1.1 kiyohara mtsdr(DCR_SDR0_SRST0, srst0 | SDR0_SRST0_UPRST | SDR0_SRST0_AHB);
142 1.1 kiyohara delay(200 * 1000); /* XXXX */
143 1.1 kiyohara mtsdr(DCR_SDR0_SRST0, srst0);
144 1.1 kiyohara
145 1.1 kiyohara config_defer(self, dwctwo_plb_deferred);
146 1.1 kiyohara }
147 1.1 kiyohara
148 1.1 kiyohara static void
149 1.1 kiyohara dwctwo_plb_deferred(device_t self)
150 1.1 kiyohara {
151 1.1 kiyohara struct dwc2_softc *sc = device_private(self);
152 1.1 kiyohara int error;
153 1.1 kiyohara
154 1.1 kiyohara error = dwc2_init(sc);
155 1.1 kiyohara if (error != 0) {
156 1.1 kiyohara aprint_error_dev(self, "couldn't initialize host, error=%d\n",
157 1.1 kiyohara error);
158 1.1 kiyohara return;
159 1.1 kiyohara }
160 1.1 kiyohara sc->sc_child = config_found(sc->sc_dev, &sc->sc_bus, usbctlprint);
161 1.1 kiyohara }
162