1 /* $NetBSD: hd64461.c,v 1.22 2009/04/05 00:56:20 uwe Exp $ */ 2 3 /*- 4 * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by UCHIYAMA Yasushi. 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/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: hd64461.c,v 1.22 2009/04/05 00:56:20 uwe Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/device.h> 38 #include <sys/reboot.h> 39 40 #include <machine/bus.h> 41 #include <machine/intr.h> 42 #include <machine/debug.h> 43 44 #include <hpcsh/dev/hd64461/hd64461reg.h> 45 #include <hpcsh/dev/hd64461/hd64461intcreg.h> 46 #include <hpcsh/dev/hd64461/hd64461var.h> 47 48 /* HD64461 modules. INTC, TIMER, POWER modules are included in hd64461if */ 49 STATIC const struct hd64461_module { 50 const char *name; 51 } hd64461_modules[] = { 52 [HD64461_MODULE_VIDEO] = { "hd64461video" }, 53 [HD64461_MODULE_PCMCIA] = { "hd64461pcmcia" }, 54 [HD64461_MODULE_UART] = { "hd64461uart" }, 55 #if 0 /* there are no drivers, so don't bother */ 56 [HD64461_MODULE_GPIO] = { "hd64461gpio" }, 57 [HD64461_MODULE_AFE] = { "hd64461afe" }, 58 [HD64461_MODULE_FIR] = { "hd64461fir" }, 59 #endif 60 }; 61 62 STATIC int hd64461_match(device_t, cfdata_t, void *); 63 STATIC void hd64461_attach(device_t, device_t, void *); 64 STATIC int hd64461_print(void *, const char *); 65 #ifdef DEBUG 66 STATIC void hd64461_info(void); 67 #endif 68 69 CFATTACH_DECL_NEW(hd64461if, 0, 70 hd64461_match, hd64461_attach, NULL, NULL); 71 72 STATIC int 73 hd64461_match(device_t parent, cfdata_t cf, void *aux) 74 { 75 76 switch (cpu_product) { 77 case CPU_PRODUCT_7709: 78 case CPU_PRODUCT_7709A: 79 break; 80 81 default: 82 return (0); /* HD64461 only supports SH7709 interface */ 83 } 84 85 if (strcmp("hd64461if", cf->cf_name) != 0) 86 return (0); 87 88 return (1); 89 } 90 91 STATIC void 92 hd64461_attach(device_t parent, device_t self, void *aux) 93 { 94 struct hd64461_attach_args ha; 95 const struct hd64461_module *module; 96 uint16_t stbcr; 97 int i; 98 99 aprint_naive("\n"); 100 aprint_normal("\n"); 101 #ifdef DEBUG 102 if (bootverbose) 103 hd64461_info(); 104 #endif 105 106 stbcr = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16); 107 108 /* we don't use TIMER */ 109 stbcr |= HD64461_SYSSTBCR_STM0ST | HD64461_SYSSTBCR_STM1ST; 110 111 /* no drivers for FIR and AFE */ 112 stbcr |= HD64461_SYSSTBCR_SIRST 113 | HD64461_SYSSTBCR_SAFEST 114 | HD64461_SYSSTBCR_SAFECKE_IST 115 | HD64461_SYSSTBCR_SAFECKE_OST; 116 117 hd64461_reg_write_2(HD64461_SYSSTBCR_REG16, stbcr); 118 119 120 /* Attach all sub modules */ 121 for (i = 0; i < __arraycount(hd64461_modules); ++i) { 122 module = &hd64461_modules[i]; 123 if (module->name == NULL) 124 continue; 125 ha.ha_module_id = i; 126 config_found(self, &ha, hd64461_print); 127 } 128 129 /* XXX: TODO */ 130 if (!pmf_device_register(self, NULL, NULL)) 131 aprint_error_dev(self, "unable to establish power handler\n"); 132 } 133 134 STATIC int 135 hd64461_print(void *aux, const char *pnp) 136 { 137 struct hd64461_attach_args *ha = aux; 138 139 if (pnp) 140 aprint_normal("%s at %s", 141 hd64461_modules[ha->ha_module_id].name, pnp); 142 143 return (UNCONF); 144 } 145 146 147 #ifdef DEBUG 148 149 STATIC void 150 hd64461_info(void) 151 { 152 uint16_t r16; 153 154 dbg_banner_function(); 155 156 /* 157 * System 158 */ 159 printf("STBCR (Standby Control Register)\n"); 160 r16 = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16); 161 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_SYSSTBCR_##m, #m) 162 DBG_BITMASK_PRINT(r16, CKIO_STBY); 163 DBG_BITMASK_PRINT(r16, SAFECKE_IST); 164 DBG_BITMASK_PRINT(r16, SLCKE_IST); 165 DBG_BITMASK_PRINT(r16, SAFECKE_OST); 166 DBG_BITMASK_PRINT(r16, SLCKE_OST); 167 DBG_BITMASK_PRINT(r16, SMIAST); 168 DBG_BITMASK_PRINT(r16, SLCDST); 169 DBG_BITMASK_PRINT(r16, SPC0ST); 170 DBG_BITMASK_PRINT(r16, SPC1ST); 171 DBG_BITMASK_PRINT(r16, SAFEST); 172 DBG_BITMASK_PRINT(r16, STM0ST); 173 DBG_BITMASK_PRINT(r16, STM1ST); 174 DBG_BITMASK_PRINT(r16, SIRST); 175 DBG_BITMASK_PRINT(r16, SURTSD); 176 #undef DBG_BITMASK_PRINT 177 printf("\n"); 178 179 printf("SYSCR (System Configuration Register)\n"); 180 r16 = hd64461_reg_read_2(HD64461_SYSSYSCR_REG16); 181 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_SYSSYSCR_##m, #m) 182 DBG_BITMASK_PRINT(r16, SCPU_BUS_IGAT); 183 DBG_BITMASK_PRINT(r16, SPTA_IR); 184 DBG_BITMASK_PRINT(r16, SPTA_TM); 185 DBG_BITMASK_PRINT(r16, SPTB_UR); 186 DBG_BITMASK_PRINT(r16, WAIT_CTL_SEL); 187 DBG_BITMASK_PRINT(r16, SMODE1); 188 DBG_BITMASK_PRINT(r16, SMODE0); 189 #undef DBG_BITMASK_PRINT 190 printf("\n"); 191 192 printf("SCPUCR (CPU Data Bus Control Register)\n"); 193 r16 = hd64461_reg_read_2(HD64461_SYSSCPUCR_REG16); 194 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_SYSSCPUCR_##m, #m) 195 DBG_BITMASK_PRINT(r16, SPDSTOF); 196 DBG_BITMASK_PRINT(r16, SPDSTIG); 197 DBG_BITMASK_PRINT(r16, SPCSTOF); 198 DBG_BITMASK_PRINT(r16, SPCSTIG); 199 DBG_BITMASK_PRINT(r16, SPBSTOF); 200 DBG_BITMASK_PRINT(r16, SPBSTIG); 201 DBG_BITMASK_PRINT(r16, SPASTOF); 202 DBG_BITMASK_PRINT(r16, SPASTIG); 203 DBG_BITMASK_PRINT(r16, SLCDSTIG); 204 DBG_BITMASK_PRINT(r16, SCPU_CS56_EP); 205 DBG_BITMASK_PRINT(r16, SCPU_CMD_EP); 206 DBG_BITMASK_PRINT(r16, SCPU_ADDR_EP); 207 DBG_BITMASK_PRINT(r16, SCPDPU); 208 DBG_BITMASK_PRINT(r16, SCPU_A2319_EP); 209 #undef DBG_BITMASK_PRINT 210 printf("\n"); 211 212 printf("\n"); 213 /* 214 * INTC 215 */ 216 printf("NIRR (Interrupt Request Register)\n"); 217 r16 = hd64461_reg_read_2(HD64461_INTCNIRR_REG16); 218 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_INTCNIRR_##m, #m) 219 DBG_BITMASK_PRINT(r16, PCC0R); 220 DBG_BITMASK_PRINT(r16, PCC1R); 221 DBG_BITMASK_PRINT(r16, AFER); 222 DBG_BITMASK_PRINT(r16, GPIOR); 223 DBG_BITMASK_PRINT(r16, TMU0R); 224 DBG_BITMASK_PRINT(r16, TMU1R); 225 DBG_BITMASK_PRINT(r16, IRDAR); 226 DBG_BITMASK_PRINT(r16, UARTR); 227 #undef DBG_BITMASK_PRINT 228 printf("\n"); 229 230 printf("NIMR (Interrupt Mask Register)\n"); 231 r16 = hd64461_reg_read_2(HD64461_INTCNIMR_REG16); 232 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_INTCNIMR_##m, #m) 233 DBG_BITMASK_PRINT(r16, PCC0M); 234 DBG_BITMASK_PRINT(r16, PCC1M); 235 DBG_BITMASK_PRINT(r16, AFEM); 236 DBG_BITMASK_PRINT(r16, GPIOM); 237 DBG_BITMASK_PRINT(r16, TMU0M); 238 DBG_BITMASK_PRINT(r16, TMU1M); 239 DBG_BITMASK_PRINT(r16, IRDAM); 240 DBG_BITMASK_PRINT(r16, UARTM); 241 #undef DBG_BITMASK_PRINT 242 printf("\n"); 243 244 dbg_banner_line(); 245 } 246 #endif /* DEBUG */ 247