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