summaryrefslogtreecommitdiff
path: root/sys/arch/arm/imx/imx23_usb.c
blob: e550ae5e08be4956b75e022a61b249256c3ad441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* $Id: imx23_usb.c,v 1.6 2023/05/04 17:09:44 bouyer Exp $ */

/*
 * Copyright (c) 2013 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Petri Laakso.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/param.h>
#include <sys/types.h>
#include <sys/bus.h>
#include <sys/errno.h>

#include <arm/pic/picvar.h>

#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdivar.h>
#include <dev/usb/usb_mem.h>
#include <dev/usb/ehcireg.h>
#include <dev/usb/ehcivar.h>
#include <arm/imx/imxusbvar.h>
#include <arm/imx/imxusbreg.h>

#include <arm/mainbus/mainbus.h>

#include <arm/imx/imx23_clkctrlvar.h>
#include <arm/imx/imx23_digctlvar.h>
#include <arm/imx/imx23_pinctrlvar.h>
#include <arm/imx/imx23var.h>

#include "locators.h"

struct imx23_usb_softc {
	struct imxusbc_softc  sc_imxusbc; /* Must be first */
};

static int	imx23_usb_match(device_t, cfdata_t, void *);
static void	imx23_usb_attach(device_t, device_t, void *);
static int	imx23_usb_activate(device_t, enum devact);

static int      imxusbc_search(device_t, cfdata_t, const int *, void *);
static void	imx23_usb_init(struct imxehci_softc *);

CFATTACH_DECL3_NEW(imxusbc,
        sizeof(struct imx23_usb_softc),
        imx23_usb_match,
        imx23_usb_attach,
        NULL,
        imx23_usb_activate,
        NULL,
        NULL,
        0
);

#define AHB_USB		0x80080000
#define AHB_USB_SIZE	0x40000

static int
imx23_usb_match(device_t parent, cfdata_t match, void *aux)
{
	struct ahb_attach_args *aa = aux;

	if ((aa->aa_addr == AHB_USB) && (aa->aa_size == AHB_USB_SIZE))
		return 1;

	return 0;
}

static void
imx23_usb_attach(device_t parent, device_t self, void *aux)
{
	struct imxusbc_softc *sc = device_private(self);

	sc->sc_dev = self;
	sc->sc_iot = &imx23_bus_space;
	sc->sc_ehci_size = IMXUSB_EHCI_SIZE;
	sc->sc_ehci_offset = IMXUSB_EHCI_SIZE;

	sc->sc_init_md_hook = imx23_usb_init;
	sc->sc_intr_establish_md_hook = NULL;
	sc->sc_setup_md_hook = NULL;

	if (bus_space_map(sc->sc_iot, AHB_USB, AHB_USB_SIZE, 0, &sc->sc_ioh)) {
		aprint_error_dev(sc->sc_dev, "Unable to map bus space");
		return;
	}

	/* Enable PLL outputs for USB PHY. */
	clkctrl_en_usb();

	/* Enable external USB chip. */
	imx23_pinctrl_en_usb();

	/* USB clock on. */
	digctl_usb_clkgate(0);

	aprint_normal("\n");

	/* attach OTG/EHCI host controllers */
	config_search(self, NULL,
	    CFARGS(.search = imxusbc_search));

	return;
}

static int
imx23_usb_activate(device_t self, enum devact act)
{
	return EOPNOTSUPP;
}

static int
imxusbc_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
{
        struct imxusbc_softc *sc = device_private(parent);
        struct imxusbc_attach_args aa;

        aa.aa_iot = sc->sc_iot;
        aa.aa_ioh = sc->sc_ioh;
        aa.aa_dmat = &imx23_bus_dma_tag;
        aa.aa_unit = cf->cf_loc[IMXUSBCCF_UNIT];
        aa.aa_irq = cf->cf_loc[IMXUSBCCF_IRQ];

        if (config_probe(parent, cf, &aa))
                config_attach(parent, cf, &aa, NULL, CFARGS_NONE);

        return 0;
}

static
void imx23_usb_init(struct imxehci_softc *sc, uintptr_t data)
{

	sc->sc_iftype = IMXUSBC_IF_UTMI;

	return;
}