imx23_ahb.c revision 1.2
1/* $Id: imx23_ahb.c,v 1.2 2021/04/24 23:36:27 thorpej Exp $ */ 2 3/* 4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Petri Laakso. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <sys/param.h> 33#include <sys/bus.h> 34#include <sys/device.h> 35#include <sys/errno.h> 36 37#include <arm/mainbus/mainbus.h> 38 39#include <arm/imx/imx23var.h> 40 41#include "locators.h" 42 43static int ahb_match(device_t, cfdata_t, void *); 44static void ahb_attach(device_t, device_t, void *); 45static int ahb_detach(device_t, int); 46static int ahb_activate(device_t, enum devact); 47 48static int ahb_search_cb(device_t, cfdata_t, const int *, void *); 49static int ahb_print(void *,const char *); 50 51CFATTACH_DECL3_NEW(ahb, 52 sizeof(struct ahb_softc), 53 ahb_match, 54 ahb_attach, 55 ahb_detach, 56 ahb_activate, 57 NULL, 58 NULL, 59 0); 60 61static int 62ahb_match(device_t parent, cfdata_t match, void *aux) 63{ 64 struct mainbus_attach_args *mb = aux; 65 66 if ((mb->mb_iobase == AHB_BASE) && (mb->mb_iosize == AHB_SIZE)) 67 return 1; 68 69 return 0; 70} 71 72static void 73ahb_attach(device_t parent, device_t self, void *aux) 74{ 75 struct ahb_attach_args aa; 76 static int ahb_attached = 0; 77 78 if (ahb_attached) 79 return; 80 81 aa.aa_iot = &imx23_bus_space; 82 aa.aa_dmat = &imx23_bus_dma_tag; 83 84 aprint_normal("\n"); 85 86 config_search(self, &aa, 87 CFARG_SEARCH, ahb_search_cb, 88 CFARG_EOL); 89 90 ahb_attached = 1; 91 92 return; 93} 94 95static int 96ahb_detach(device_t self, int flags) 97{ 98 return 0; 99} 100 101static int 102ahb_activate(device_t self, enum devact act) 103{ 104 return EOPNOTSUPP; 105} 106 107/* 108 * config_search_ia() callback function. 109 */ 110static int 111ahb_search_cb(device_t parent, cfdata_t cf, const int *locs, void *aux) 112{ 113 struct apb_attach_args *aa = aux; 114 115 aa->aa_name = cf->cf_name; 116 aa->aa_addr = cf->cf_loc[AHBCF_ADDR]; 117 aa->aa_size = cf->cf_loc[AHBCF_SIZE]; 118 aa->aa_irq = cf->cf_loc[AHBCF_IRQ]; 119 120 if (config_probe(parent, cf, aux)) 121 config_attach(parent, cf, aux, ahb_print, CFARG_EOL); 122 123 return 0; 124} 125 126/* 127 * Called from config_attach() 128 */ 129static int 130ahb_print(void *aux, const char *name __unused) 131{ 132 struct apb_attach_args *aa = aux; 133 134 if (aa->aa_addr != AHBCF_ADDR_DEFAULT) { 135 aprint_normal(" addr 0x%lx", aa->aa_addr); 136 if (aa->aa_size > AHBCF_SIZE_DEFAULT) 137 aprint_normal("-0x%lx", aa->aa_addr + aa->aa_size-1); 138 } 139 140 if (aa->aa_irq != AHBCF_IRQ_DEFAULT) 141 aprint_normal(" irq %d", aa->aa_irq); 142 143 return UNCONF; 144} 145