1 /* $NetBSD: pq3diic.c,v 1.3 2011/08/01 17:05:17 matt Exp $ */ 2 /*- 3 * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to The NetBSD Foundation 7 * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects 8 * Agency and which was developed by Matt Thomas of 3am Software Foundry. 9 * 10 * This material is based upon work supported by the Defense Advanced Research 11 * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under 12 * Contract No. N66001-09-C-2073. 13 * Approved for Public Release, Distribution Unlimited 14 * 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions 17 * are met: 18 * 1. Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in the 22 * documentation and/or other materials provided with the distribution. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGE. 35 */ 36 37 #include <sys/cdefs.h> 38 39 __KERNEL_RCSID(0, "$NetBSD: pq3diic.c,v 1.3 2011/08/01 17:05:17 matt Exp $"); 40 41 #include <sys/param.h> 42 #include <sys/cpu.h> 43 #include <sys/device.h> 44 #include <sys/tty.h> 45 46 #include "ioconf.h" 47 48 #include <sys/intr.h> 49 #include <sys/bus.h> 50 51 #include <dev/i2c/i2cvar.h> 52 53 #include <dev/i2c/motoi2creg.h> 54 #include <dev/i2c/motoi2cvar.h> 55 56 #include <powerpc/booke/cpuvar.h> 57 #include <powerpc/booke/e500var.h> 58 #include <powerpc/booke/e500reg.h> 59 60 struct pq3diic_softc { 61 device_t sc_dev; 62 void *sc_ih; 63 struct motoi2c_softc sc_motoi2c[2]; 64 }; 65 66 static int pq3diic_match(device_t, cfdata_t, void *); 67 static void pq3diic_attach(device_t, device_t, void *); 68 69 CFATTACH_DECL_NEW(pq3diic, sizeof(struct pq3diic_softc), 70 pq3diic_match, pq3diic_attach, NULL, NULL); 71 72 static int 73 pq3diic_match(device_t parent, cfdata_t cf, void *aux) 74 { 75 76 if (!e500_cpunode_submatch(parent, cf, cf->cf_name, aux)) 77 return 0; 78 79 return 1; 80 } 81 82 static int 83 pq3diic_intr(void *arg) 84 { 85 struct pq3diic_softc * const sc = arg; 86 int rv = 0; 87 88 rv += motoi2c_intr(&sc->sc_motoi2c[0]); 89 rv += motoi2c_intr(&sc->sc_motoi2c[1]); 90 91 return rv; 92 } 93 94 static void 95 pq3diic_attach(device_t parent, device_t self, void *aux) 96 { 97 struct cpunode_softc * const psc = device_private(parent); 98 struct pq3diic_softc * const sc = device_private(self); 99 struct cpunode_attach_args * const cna = aux; 100 struct cpunode_locators * const cnl = &cna->cna_locs; 101 u_int nports = cnl->cnl_size / I2C_SIZE; 102 int error; 103 104 psc->sc_children |= cna->cna_childmask; 105 sc->sc_dev = self; 106 107 aprint_normal(": %u port%s\n", nports, nports == 1 ? "" : "s"); 108 109 for (u_int port = 0; port <= min(1, nports); port++) { 110 struct motoi2c_softc * const msc = &sc->sc_motoi2c[port]; 111 msc->sc_iot = cna->cna_memt; 112 error = bus_space_map(msc->sc_iot, 113 cnl->cnl_addr + port * I2C_SIZE, 114 I2C_SIZE, 0, &msc->sc_ioh); 115 if (error) { 116 aprint_error_dev(self, 117 "can't map registers for i2c#%uL %d\n", 118 port, error); 119 } else { 120 motoi2c_attach_common(self, msc, NULL); 121 } 122 } 123 124 sc->sc_ih = intr_establish(cnl->cnl_intrs[0], IPL_VM, IST_ONCHIP, 125 pq3diic_intr, sc); 126 if (sc->sc_ih == NULL) 127 aprint_error_dev(self, "failed to establish interrupt %d\n", 128 cnl->cnl_intrs[0]); 129 else 130 aprint_normal_dev(self, "interrupting on irq %d\n", 131 cnl->cnl_intrs[0]); 132 } 133