1 /* $NetBSD: asc.c,v 1.9 1995/11/01 04:58:21 briggs Exp $ */ 2 3 /*- 4 * Copyright (C) 1993 Allen K. Briggs, Chris P. Caputo, 5 * Michael L. Finch, Bradley A. Grantham, and 6 * Lawrence A. Kesteloot 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the Alice Group. 20 * 4. The names of the Alice Group or any of its members may not be used 21 * to endorse or promote products derived from this software without 22 * specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT, 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 /* 37 * ASC driver code and asc_ringbell() support 38 */ 39 40 #include <sys/types.h> 41 #include <sys/cdefs.h> 42 #include <sys/errno.h> 43 #include <sys/time.h> 44 #include <sys/systm.h> 45 #include <sys/param.h> 46 #include <sys/device.h> 47 #include <machine/cpu.h> 48 49 50 /* Global ASC location */ 51 volatile unsigned char *ASCBase = (unsigned char *) 0x14000; 52 53 54 /* bell support data */ 55 static int bell_freq = 1880; 56 static int bell_length = 10; 57 static int bell_volume = 100; 58 static int bell_ringing = 0; 59 60 static int ascprobe __P((struct device *, struct cfdata *, void *)); 61 static void ascattach __P((struct device *, struct device *, void *)); 62 extern int matchbyname __P((struct device *, void *, void *)); 63 64 struct cfdriver asccd = 65 {NULL, "asc", matchbyname, ascattach, 66 DV_DULL, sizeof(struct device), NULL, 0}; 67 68 static int 69 ascprobe(parent, cf, aux) 70 struct device *parent; 71 struct cfdata *cf; 72 void *aux; 73 { 74 if (strcmp(*((char **) aux), asccd.cd_name)) 75 return 0; 76 77 return 1; 78 } 79 80 81 static void 82 ascattach(parent, dev, aux) 83 struct device *parent, *dev; 84 void *aux; 85 { 86 printf(" Apple sound chip.\n"); 87 } 88 89 int 90 asc_setbellparams( 91 int freq, 92 int length, 93 int volume) 94 { 95 /* I only perform these checks for sanity. */ 96 /* I suppose someone might want a bell that rings */ 97 /* all day, but then the can make kernel mods themselves. */ 98 99 if (freq < 10 || freq > 40000) 100 return (EINVAL); 101 if (length < 0 || length > 3600) 102 return (EINVAL); 103 if (volume < 0 || volume > 100) 104 return (EINVAL); 105 106 bell_freq = freq; 107 bell_length = length; 108 bell_volume = volume; 109 110 return (0); 111 } 112 113 114 int 115 asc_getbellparams( 116 int *freq, 117 int *length, 118 int *volume) 119 { 120 *freq = bell_freq; 121 *length = bell_length; 122 *volume = bell_volume; 123 124 return (0); 125 } 126 127 128 void 129 asc_bellstop( 130 int param) 131 { 132 if (bell_ringing > 1000 || bell_ringing < 0) 133 panic("bell got out of synch?????"); 134 if (--bell_ringing == 0) { 135 ASCBase[0x801] = 0; 136 } 137 /* disable ASC */ 138 } 139 140 141 int 142 asc_ringbell() 143 { 144 int i; 145 unsigned long freq; 146 147 if (bell_ringing == 0) { 148 for (i = 0; i < 0x800; i++) 149 ASCBase[i] = 0; 150 151 for (i = 0; i < 256; i++) { 152 ASCBase[i] = i / 4; 153 ASCBase[i + 512] = i / 4; 154 ASCBase[i + 1024] = i / 4; 155 ASCBase[i + 1536] = i / 4; 156 } /* up part of wave, four voices ? */ 157 for (i = 0; i < 256; i++) { 158 ASCBase[i + 256] = 0x3f - (i / 4); 159 ASCBase[i + 768] = 0x3f - (i / 4); 160 ASCBase[i + 1280] = 0x3f - (i / 4); 161 ASCBase[i + 1792] = 0x3f - (i / 4); 162 } /* down part of wave, four voices ? */ 163 164 /* Fix this. Need to find exact ASC sampling freq */ 165 freq = 65536 * bell_freq / 466; 166 167 /* printf("beep: from %d, %02x %02x %02x %02x\n", 168 * cur_beep.freq, (freq >> 24) & 0xff, (freq >> 16) & 0xff, 169 * (freq >> 8) & 0xff, (freq) & 0xff); */ 170 for (i = 0; i < 8; i++) { 171 ASCBase[0x814 + 8 * i] = (freq >> 24) & 0xff; 172 ASCBase[0x815 + 8 * i] = (freq >> 16) & 0xff; 173 ASCBase[0x816 + 8 * i] = (freq >> 8) & 0xff; 174 ASCBase[0x817 + 8 * i] = (freq) & 0xff; 175 } /* frequency; should put cur_beep.freq in here 176 * somewhere. */ 177 178 ASCBase[0x807] = 3; /* 44 ? */ 179 ASCBase[0x806] = 255 * bell_volume / 100; 180 ASCBase[0x805] = 0; 181 ASCBase[0x80f] = 0; 182 ASCBase[0x802] = 2; /* sampled */ 183 ASCBase[0x801] = 2; /* enable sampled */ 184 } 185 bell_ringing++; 186 timeout((void *) asc_bellstop, 0, bell_length); 187 } 188