imx23_usb.c revision 1.1
11.1Smatt/* $Id: imx23_usb.c,v 1.1 2013/10/07 17:36:40 matt Exp $ */ 21.1Smatt 31.1Smatt/* 41.1Smatt * Copyright (c) 2013 The NetBSD Foundation, Inc. 51.1Smatt * All rights reserved. 61.1Smatt * 71.1Smatt * This code is derived from software contributed to The NetBSD Foundation 81.1Smatt * by Petri Laakso. 91.1Smatt * 101.1Smatt * Redistribution and use in source and binary forms, with or without 111.1Smatt * modification, are permitted provided that the following conditions 121.1Smatt * are met: 131.1Smatt * 1. Redistributions of source code must retain the above copyright 141.1Smatt * notice, this list of conditions and the following disclaimer. 151.1Smatt * 2. Redistributions in binary form must reproduce the above copyright 161.1Smatt * notice, this list of conditions and the following disclaimer in the 171.1Smatt * documentation and/or other materials provided with the distribution. 181.1Smatt * 191.1Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Smatt * POSSIBILITY OF SUCH DAMAGE. 301.1Smatt */ 311.1Smatt 321.1Smatt#include <sys/param.h> 331.1Smatt#include <sys/types.h> 341.1Smatt#include <sys/bus.h> 351.1Smatt#include <sys/errno.h> 361.1Smatt 371.1Smatt#include <arm/pic/picvar.h> 381.1Smatt 391.1Smatt#include <dev/usb/usb.h> 401.1Smatt#include <dev/usb/usbdi.h> 411.1Smatt#include <dev/usb/usbdivar.h> 421.1Smatt#include <dev/usb/usb_mem.h> 431.1Smatt#include <dev/usb/ehcireg.h> 441.1Smatt#include <dev/usb/ehcivar.h> 451.1Smatt#include <arm/imx/imxusbvar.h> 461.1Smatt 471.1Smatt#include <arm/mainbus/mainbus.h> 481.1Smatt 491.1Smatt#include <arm/imx/imx23_clkctrlvar.h> 501.1Smatt#include <arm/imx/imx23_digctlvar.h> 511.1Smatt#include <arm/imx/imx23_pinctrlvar.h> 521.1Smatt#include <arm/imx/imx23var.h> 531.1Smatt 541.1Smatt#include "locators.h" 551.1Smatt 561.1Smattstruct imx23_usb_softc { 571.1Smatt struct imxusbc_softc sc_imxusbc; 581.1Smatt}; 591.1Smatt 601.1Smattstatic int imx23_usb_match(device_t, cfdata_t, void *); 611.1Smattstatic void imx23_usb_attach(device_t, device_t, void *); 621.1Smattstatic int imx23_usb_activate(device_t, enum devact); 631.1Smatt 641.1Smattstatic int imxusbc_search(device_t, cfdata_t, const int *, void *); 651.1Smattstatic void imx23_usb_init(struct imxehci_softc *); 661.1Smatt 671.1SmattCFATTACH_DECL3_NEW(imxusbc, 681.1Smatt sizeof(struct imx23_usb_softc), 691.1Smatt imx23_usb_match, 701.1Smatt imx23_usb_attach, 711.1Smatt NULL, 721.1Smatt imx23_usb_activate, 731.1Smatt NULL, 741.1Smatt NULL, 751.1Smatt 0 761.1Smatt); 771.1Smatt 781.1Smatt#define AHB_USB 0x80080000 791.1Smatt#define AHB_USB_SIZE 0x40000 801.1Smatt 811.1Smattstatic int 821.1Smattimx23_usb_match(device_t parent, cfdata_t match, void *aux) 831.1Smatt{ 841.1Smatt struct ahb_attach_args *aa = aux; 851.1Smatt 861.1Smatt if ((aa->aa_addr == AHB_USB) && (aa->aa_size == AHB_USB_SIZE)) 871.1Smatt return 1; 881.1Smatt 891.1Smatt return 0; 901.1Smatt} 911.1Smatt 921.1Smattstatic void 931.1Smattimx23_usb_attach(device_t parent, device_t self, void *aux) 941.1Smatt{ 951.1Smatt struct imxusbc_softc *sc = device_private(self); 961.1Smatt 971.1Smatt sc->sc_init_md_hook = imx23_usb_init; 981.1Smatt sc->sc_setup_md_hook = NULL; 991.1Smatt sc->sc_iot = &imx23_bus_space; 1001.1Smatt 1011.1Smatt if (bus_space_map(sc->sc_iot, AHB_USB, AHB_USB_SIZE, 0, &sc->sc_ioh)) { 1021.1Smatt aprint_error_dev(sc->sc_dev, "Unable to map bus space"); 1031.1Smatt return; 1041.1Smatt } 1051.1Smatt 1061.1Smatt /* Enable PLL outputs for USB PHY. */ 1071.1Smatt clkctrl_en_usb(); 1081.1Smatt 1091.1Smatt /* Enable external USB chip. */ 1101.1Smatt pinctrl_en_usb(); 1111.1Smatt 1121.1Smatt /* USB clock on. */ 1131.1Smatt digctl_usb_clkgate(0); 1141.1Smatt 1151.1Smatt aprint_normal("\n"); 1161.1Smatt 1171.1Smatt /* attach OTG/EHCI host controllers */ 1181.1Smatt config_search_ia(imxusbc_search, self, "imxusbc", NULL); 1191.1Smatt 1201.1Smatt return; 1211.1Smatt} 1221.1Smatt 1231.1Smattstatic int 1241.1Smattimx23_usb_activate(device_t self, enum devact act) 1251.1Smatt{ 1261.1Smatt return EOPNOTSUPP; 1271.1Smatt} 1281.1Smatt 1291.1Smattstatic int 1301.1Smattimxusbc_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux) 1311.1Smatt{ 1321.1Smatt struct imxusbc_softc *sc = device_private(parent); 1331.1Smatt struct imxusbc_attach_args aa; 1341.1Smatt 1351.1Smatt aa.aa_iot = sc->sc_iot; 1361.1Smatt aa.aa_ioh = sc->sc_ioh; 1371.1Smatt aa.aa_dmat = &imx23_bus_dma_tag; 1381.1Smatt aa.aa_unit = cf->cf_loc[IMXUSBCCF_UNIT]; 1391.1Smatt aa.aa_irq = cf->cf_loc[IMXUSBCCF_IRQ]; 1401.1Smatt 1411.1Smatt if (config_match(parent, cf, &aa) > 0) 1421.1Smatt config_attach(parent, cf, &aa, NULL); 1431.1Smatt 1441.1Smatt return 0; 1451.1Smatt} 1461.1Smatt 1471.1Smattstatic 1481.1Smattvoid imx23_usb_init(struct imxehci_softc *sc) 1491.1Smatt{ 1501.1Smatt 1511.1Smatt sc->sc_iftype = IMXUSBC_IF_UTMI; 1521.1Smatt 1531.1Smatt return; 1541.1Smatt} 155