1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2000-2002 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * This is the Beep driver for SMBUS based beep mechanism. 31*0Sstevel@tonic-gate * The driver exports the interfaces to set frequency, 32*0Sstevel@tonic-gate * turn on beeper and turn off beeper to the generic beep 33*0Sstevel@tonic-gate * module. If a beep is in progress, the driver discards a 34*0Sstevel@tonic-gate * second beep. This driver uses the 8254 timer to program 35*0Sstevel@tonic-gate * the beeper ports. 36*0Sstevel@tonic-gate */ 37*0Sstevel@tonic-gate #include <sys/types.h> 38*0Sstevel@tonic-gate #include <sys/conf.h> 39*0Sstevel@tonic-gate #include <sys/ddi.h> 40*0Sstevel@tonic-gate #include <sys/sunddi.h> 41*0Sstevel@tonic-gate #include <sys/modctl.h> 42*0Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 43*0Sstevel@tonic-gate #include <sys/kmem.h> 44*0Sstevel@tonic-gate #include <sys/devops.h> 45*0Sstevel@tonic-gate #include <sys/grbeep.h> 46*0Sstevel@tonic-gate #include <sys/beep_driver.h> 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate /* Pointer to the state structure */ 50*0Sstevel@tonic-gate static void *grbeep_statep; 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate /* 54*0Sstevel@tonic-gate * Debug stuff 55*0Sstevel@tonic-gate */ 56*0Sstevel@tonic-gate #ifdef DEBUG 57*0Sstevel@tonic-gate int grbeep_debug = 0; 58*0Sstevel@tonic-gate #define GRBEEP_DEBUG(args) if (grbeep_debug) cmn_err args 59*0Sstevel@tonic-gate #define GRBEEP_DEBUG1(args) if (grbeep_debug > 1) cmn_err args 60*0Sstevel@tonic-gate #else 61*0Sstevel@tonic-gate #define GRBEEP_DEBUG(args) 62*0Sstevel@tonic-gate #define GRBEEP_DEBUG1(args) 63*0Sstevel@tonic-gate #endif 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate /* 67*0Sstevel@tonic-gate * Prototypes 68*0Sstevel@tonic-gate */ 69*0Sstevel@tonic-gate static int grbeep_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); 70*0Sstevel@tonic-gate static int grbeep_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); 71*0Sstevel@tonic-gate static int grbeep_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, 72*0Sstevel@tonic-gate void **result); 73*0Sstevel@tonic-gate static void grbeep_freq(dev_info_t *, int); 74*0Sstevel@tonic-gate static void grbeep_on(dev_info_t *); 75*0Sstevel@tonic-gate static void grbeep_off(dev_info_t *); 76*0Sstevel@tonic-gate static void grbeep_cleanup(grbeep_state_t *); 77*0Sstevel@tonic-gate static int grbeep_map_regs(dev_info_t *, grbeep_state_t *); 78*0Sstevel@tonic-gate static grbeep_state_t *grbeep_obtain_state(dev_info_t *); 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate struct cb_ops grbeep_cb_ops = { 82*0Sstevel@tonic-gate nulldev, /* open */ 83*0Sstevel@tonic-gate nulldev, /* close */ 84*0Sstevel@tonic-gate nulldev, /* strategy */ 85*0Sstevel@tonic-gate nulldev, /* print */ 86*0Sstevel@tonic-gate nulldev, /* dump */ 87*0Sstevel@tonic-gate nulldev, /* read */ 88*0Sstevel@tonic-gate nulldev, /* write */ 89*0Sstevel@tonic-gate nulldev, /* ioctl */ 90*0Sstevel@tonic-gate nulldev, /* devmap */ 91*0Sstevel@tonic-gate nulldev, /* mmap */ 92*0Sstevel@tonic-gate nulldev, /* segmap */ 93*0Sstevel@tonic-gate nochpoll, /* poll */ 94*0Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 95*0Sstevel@tonic-gate NULL, /* streamtab */ 96*0Sstevel@tonic-gate D_MP | D_NEW 97*0Sstevel@tonic-gate }; 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate static struct dev_ops grbeep_ops = { 101*0Sstevel@tonic-gate DEVO_REV, /* Devo_rev */ 102*0Sstevel@tonic-gate 0, /* Refcnt */ 103*0Sstevel@tonic-gate grbeep_info, /* Info */ 104*0Sstevel@tonic-gate nulldev, /* Identify */ 105*0Sstevel@tonic-gate nulldev, /* Probe */ 106*0Sstevel@tonic-gate grbeep_attach, /* Attach */ 107*0Sstevel@tonic-gate grbeep_detach, /* Detach */ 108*0Sstevel@tonic-gate nodev, /* Reset */ 109*0Sstevel@tonic-gate &grbeep_cb_ops, /* Driver operations */ 110*0Sstevel@tonic-gate 0, /* Bus operations */ 111*0Sstevel@tonic-gate NULL /* Power */ 112*0Sstevel@tonic-gate }; 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate static struct modldrv modldrv = { 116*0Sstevel@tonic-gate &mod_driverops, /* This one is a driver */ 117*0Sstevel@tonic-gate "SMBUS Beep Driver %I%", /* Name of the module. */ 118*0Sstevel@tonic-gate &grbeep_ops, /* Driver ops */ 119*0Sstevel@tonic-gate }; 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate static struct modlinkage modlinkage = { 123*0Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL 124*0Sstevel@tonic-gate }; 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate int 128*0Sstevel@tonic-gate _init(void) 129*0Sstevel@tonic-gate { 130*0Sstevel@tonic-gate int error; 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate /* Initialize the soft state structures */ 133*0Sstevel@tonic-gate if ((error = ddi_soft_state_init(&grbeep_statep, 134*0Sstevel@tonic-gate sizeof (grbeep_state_t), 1)) != 0) { 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate return (error); 137*0Sstevel@tonic-gate } 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate /* Install the loadable module */ 140*0Sstevel@tonic-gate if ((error = mod_install(&modlinkage)) != 0) { 141*0Sstevel@tonic-gate ddi_soft_state_fini(&grbeep_statep); 142*0Sstevel@tonic-gate } 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate return (error); 145*0Sstevel@tonic-gate } 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate int 149*0Sstevel@tonic-gate _info(struct modinfo *modinfop) 150*0Sstevel@tonic-gate { 151*0Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 152*0Sstevel@tonic-gate } 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate int 156*0Sstevel@tonic-gate _fini(void) 157*0Sstevel@tonic-gate { 158*0Sstevel@tonic-gate int error; 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate error = mod_remove(&modlinkage); 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate if (error == 0) { 163*0Sstevel@tonic-gate /* Release per module resources */ 164*0Sstevel@tonic-gate ddi_soft_state_fini(&grbeep_statep); 165*0Sstevel@tonic-gate } 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate return (error); 168*0Sstevel@tonic-gate } 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate /* 172*0Sstevel@tonic-gate * Beep entry points 173*0Sstevel@tonic-gate */ 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate /* 176*0Sstevel@tonic-gate * grbeep_attach: 177*0Sstevel@tonic-gate */ 178*0Sstevel@tonic-gate static int 179*0Sstevel@tonic-gate grbeep_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 180*0Sstevel@tonic-gate { 181*0Sstevel@tonic-gate int instance; 182*0Sstevel@tonic-gate 183*0Sstevel@tonic-gate /* Pointer to soft state */ 184*0Sstevel@tonic-gate grbeep_state_t *grbeeptr = NULL; 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_attach: Start")); 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate switch (cmd) { 189*0Sstevel@tonic-gate case DDI_ATTACH: 190*0Sstevel@tonic-gate break; 191*0Sstevel@tonic-gate case DDI_RESUME: 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate return (DDI_SUCCESS); 194*0Sstevel@tonic-gate default: 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate return (DDI_FAILURE); 197*0Sstevel@tonic-gate } 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate /* Get the instance and create soft state */ 200*0Sstevel@tonic-gate instance = ddi_get_instance(dip); 201*0Sstevel@tonic-gate 202*0Sstevel@tonic-gate if (ddi_soft_state_zalloc(grbeep_statep, instance) != 0) { 203*0Sstevel@tonic-gate 204*0Sstevel@tonic-gate return (DDI_FAILURE); 205*0Sstevel@tonic-gate } 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gate grbeeptr = ddi_get_soft_state(grbeep_statep, instance); 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gate if (grbeeptr == NULL) { 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate return (DDI_FAILURE); 212*0Sstevel@tonic-gate } 213*0Sstevel@tonic-gate 214*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeeptr = 0x%p, instance %x", 215*0Sstevel@tonic-gate (void *)grbeeptr, instance)); 216*0Sstevel@tonic-gate 217*0Sstevel@tonic-gate /* Save the dip */ 218*0Sstevel@tonic-gate grbeeptr->grbeep_dip = dip; 219*0Sstevel@tonic-gate 220*0Sstevel@tonic-gate /* Initialize beeper mode */ 221*0Sstevel@tonic-gate grbeeptr->grbeep_mode = GRBEEP_OFF; 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate /* Map the Beep Control and Beep counter Registers */ 224*0Sstevel@tonic-gate if (grbeep_map_regs(dip, grbeeptr) != DDI_SUCCESS) { 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gate GRBEEP_DEBUG((CE_WARN, 227*0Sstevel@tonic-gate "grbeep_attach: Mapping of beep registers failed.")); 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate grbeep_cleanup(grbeeptr); 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate return (DDI_FAILURE); 232*0Sstevel@tonic-gate } 233*0Sstevel@tonic-gate 234*0Sstevel@tonic-gate (void) beep_init(dip, grbeep_on, grbeep_off, grbeep_freq); 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gate /* Display information in the banner */ 237*0Sstevel@tonic-gate ddi_report_dev(dip); 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gate mutex_init(&grbeeptr->grbeep_mutex, NULL, MUTEX_DRIVER, NULL); 240*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_attach: dip = 0x%p done", 241*0Sstevel@tonic-gate (void *)dip)); 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate return (DDI_SUCCESS); 244*0Sstevel@tonic-gate } 245*0Sstevel@tonic-gate 246*0Sstevel@tonic-gate 247*0Sstevel@tonic-gate /* 248*0Sstevel@tonic-gate * grbeep_detach: 249*0Sstevel@tonic-gate */ 250*0Sstevel@tonic-gate /* ARGSUSED */ 251*0Sstevel@tonic-gate static int 252*0Sstevel@tonic-gate grbeep_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 253*0Sstevel@tonic-gate { 254*0Sstevel@tonic-gate /* Pointer to soft state */ 255*0Sstevel@tonic-gate grbeep_state_t *grbeeptr = NULL; 256*0Sstevel@tonic-gate 257*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_detach: Start")); 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate switch (cmd) { 260*0Sstevel@tonic-gate case DDI_SUSPEND: 261*0Sstevel@tonic-gate grbeeptr = grbeep_obtain_state(dip); 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate if (grbeeptr == NULL) { 264*0Sstevel@tonic-gate 265*0Sstevel@tonic-gate return (DDI_FAILURE); 266*0Sstevel@tonic-gate } 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gate /* 269*0Sstevel@tonic-gate * If a beep is in progress; fail suspend 270*0Sstevel@tonic-gate */ 271*0Sstevel@tonic-gate if (grbeeptr->grbeep_mode == GRBEEP_OFF) { 272*0Sstevel@tonic-gate 273*0Sstevel@tonic-gate return (DDI_SUCCESS); 274*0Sstevel@tonic-gate } else { 275*0Sstevel@tonic-gate 276*0Sstevel@tonic-gate return (DDI_FAILURE); 277*0Sstevel@tonic-gate } 278*0Sstevel@tonic-gate default: 279*0Sstevel@tonic-gate 280*0Sstevel@tonic-gate return (DDI_FAILURE); 281*0Sstevel@tonic-gate } 282*0Sstevel@tonic-gate } 283*0Sstevel@tonic-gate 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gate /* 286*0Sstevel@tonic-gate * grbeep_info: 287*0Sstevel@tonic-gate */ 288*0Sstevel@tonic-gate /* ARGSUSED */ 289*0Sstevel@tonic-gate static int 290*0Sstevel@tonic-gate grbeep_info(dev_info_t *dip, ddi_info_cmd_t infocmd, 291*0Sstevel@tonic-gate void *arg, void **result) 292*0Sstevel@tonic-gate { 293*0Sstevel@tonic-gate dev_t dev; 294*0Sstevel@tonic-gate grbeep_state_t *grbeeptr; 295*0Sstevel@tonic-gate int instance, error; 296*0Sstevel@tonic-gate 297*0Sstevel@tonic-gate switch (infocmd) { 298*0Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 299*0Sstevel@tonic-gate dev = (dev_t)arg; 300*0Sstevel@tonic-gate instance = GRBEEP_UNIT(dev); 301*0Sstevel@tonic-gate 302*0Sstevel@tonic-gate if ((grbeeptr = ddi_get_soft_state(grbeep_statep, 303*0Sstevel@tonic-gate instance)) == NULL) { 304*0Sstevel@tonic-gate 305*0Sstevel@tonic-gate return (DDI_FAILURE); 306*0Sstevel@tonic-gate } 307*0Sstevel@tonic-gate 308*0Sstevel@tonic-gate *result = (void *)grbeeptr->grbeep_dip; 309*0Sstevel@tonic-gate 310*0Sstevel@tonic-gate error = DDI_SUCCESS; 311*0Sstevel@tonic-gate break; 312*0Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 313*0Sstevel@tonic-gate dev = (dev_t)arg; 314*0Sstevel@tonic-gate instance = GRBEEP_UNIT(dev); 315*0Sstevel@tonic-gate 316*0Sstevel@tonic-gate *result = (void *)(uintptr_t)instance; 317*0Sstevel@tonic-gate 318*0Sstevel@tonic-gate error = DDI_SUCCESS; 319*0Sstevel@tonic-gate break; 320*0Sstevel@tonic-gate default: 321*0Sstevel@tonic-gate error = DDI_FAILURE; 322*0Sstevel@tonic-gate 323*0Sstevel@tonic-gate } 324*0Sstevel@tonic-gate 325*0Sstevel@tonic-gate return (error); 326*0Sstevel@tonic-gate } 327*0Sstevel@tonic-gate 328*0Sstevel@tonic-gate 329*0Sstevel@tonic-gate /* 330*0Sstevel@tonic-gate * grbeep_freq() : 331*0Sstevel@tonic-gate * Set beep frequency 332*0Sstevel@tonic-gate */ 333*0Sstevel@tonic-gate /*ARGSUSED*/ 334*0Sstevel@tonic-gate static void 335*0Sstevel@tonic-gate grbeep_freq(dev_info_t *dip, int freq) 336*0Sstevel@tonic-gate { 337*0Sstevel@tonic-gate grbeep_state_t *grbeeptr = grbeep_obtain_state(dip); 338*0Sstevel@tonic-gate int divisor = 0; 339*0Sstevel@tonic-gate 340*0Sstevel@tonic-gate ASSERT(freq != 0); 341*0Sstevel@tonic-gate 342*0Sstevel@tonic-gate mutex_enter(&grbeeptr->grbeep_mutex); 343*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_freq: dip=0x%p freq=%d mode=%d", 344*0Sstevel@tonic-gate (void *)dip, freq, grbeeptr->grbeep_mode)); 345*0Sstevel@tonic-gate 346*0Sstevel@tonic-gate GRBEEP_WRITE_FREQ_CONTROL_REG(GRBEEP_CONTROL); 347*0Sstevel@tonic-gate 348*0Sstevel@tonic-gate divisor = GRBEEP_INPUT_FREQ / freq; 349*0Sstevel@tonic-gate 350*0Sstevel@tonic-gate if (divisor > GRBEEP_DIVISOR_MAX) { 351*0Sstevel@tonic-gate divisor = GRBEEP_DIVISOR_MAX; 352*0Sstevel@tonic-gate } else if (divisor < GRBEEP_DIVISOR_MIN) { 353*0Sstevel@tonic-gate divisor = GRBEEP_DIVISOR_MIN; 354*0Sstevel@tonic-gate } 355*0Sstevel@tonic-gate 356*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_freq: first=0x%x second=0x%x", 357*0Sstevel@tonic-gate (divisor & 0xff), ((divisor & 0xff00) >> 8))); 358*0Sstevel@tonic-gate 359*0Sstevel@tonic-gate GRBEEP_WRITE_FREQ_DIVISOR_REG(divisor & 0xff); 360*0Sstevel@tonic-gate GRBEEP_WRITE_FREQ_DIVISOR_REG((divisor & 0xff00) >> 8); 361*0Sstevel@tonic-gate 362*0Sstevel@tonic-gate mutex_exit(&grbeeptr->grbeep_mutex); 363*0Sstevel@tonic-gate } 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gate 366*0Sstevel@tonic-gate /* 367*0Sstevel@tonic-gate * grbeep_on() : 368*0Sstevel@tonic-gate * Turn the beeper on 369*0Sstevel@tonic-gate */ 370*0Sstevel@tonic-gate static void 371*0Sstevel@tonic-gate grbeep_on(dev_info_t *dip) 372*0Sstevel@tonic-gate { 373*0Sstevel@tonic-gate grbeep_state_t *grbeeptr = grbeep_obtain_state(dip); 374*0Sstevel@tonic-gate 375*0Sstevel@tonic-gate mutex_enter(&grbeeptr->grbeep_mutex); 376*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_on: dip = 0x%p mode=%d", 377*0Sstevel@tonic-gate (void *)dip, grbeeptr->grbeep_mode)); 378*0Sstevel@tonic-gate 379*0Sstevel@tonic-gate if (grbeeptr->grbeep_mode == GRBEEP_OFF) { 380*0Sstevel@tonic-gate 381*0Sstevel@tonic-gate grbeeptr->grbeep_mode = GRBEEP_ON; 382*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_on: Starting beep")); 383*0Sstevel@tonic-gate GRBEEP_WRITE_START_STOP_REG(GRBEEP_START); 384*0Sstevel@tonic-gate 385*0Sstevel@tonic-gate } 386*0Sstevel@tonic-gate 387*0Sstevel@tonic-gate mutex_exit(&grbeeptr->grbeep_mutex); 388*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_on: dip = 0x%p done", (void *)dip)); 389*0Sstevel@tonic-gate } 390*0Sstevel@tonic-gate 391*0Sstevel@tonic-gate 392*0Sstevel@tonic-gate /* 393*0Sstevel@tonic-gate * grbeep_off() : 394*0Sstevel@tonic-gate * Turn the beeper off 395*0Sstevel@tonic-gate */ 396*0Sstevel@tonic-gate /*ARGSUSED*/ 397*0Sstevel@tonic-gate static void 398*0Sstevel@tonic-gate grbeep_off(dev_info_t *dip) 399*0Sstevel@tonic-gate { 400*0Sstevel@tonic-gate grbeep_state_t *grbeeptr = grbeep_obtain_state(dip); 401*0Sstevel@tonic-gate 402*0Sstevel@tonic-gate mutex_enter(&grbeeptr->grbeep_mutex); 403*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_off: dip = 0x%p mode=%d", 404*0Sstevel@tonic-gate (void *)dip, grbeeptr->grbeep_mode)); 405*0Sstevel@tonic-gate 406*0Sstevel@tonic-gate if (grbeeptr->grbeep_mode == GRBEEP_ON) { 407*0Sstevel@tonic-gate 408*0Sstevel@tonic-gate grbeeptr->grbeep_mode = GRBEEP_OFF; 409*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_off: Stopping beep")); 410*0Sstevel@tonic-gate GRBEEP_WRITE_START_STOP_REG(GRBEEP_STOP); 411*0Sstevel@tonic-gate 412*0Sstevel@tonic-gate } 413*0Sstevel@tonic-gate 414*0Sstevel@tonic-gate mutex_exit(&grbeeptr->grbeep_mutex); 415*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_off: dip = 0x%p done", (void *)dip)); 416*0Sstevel@tonic-gate } 417*0Sstevel@tonic-gate 418*0Sstevel@tonic-gate /* 419*0Sstevel@tonic-gate * grbeep_map_regs() : 420*0Sstevel@tonic-gate * 421*0Sstevel@tonic-gate * The write beep port register and spkr control register 422*0Sstevel@tonic-gate * should be mapped into a non-cacheable portion of the system 423*0Sstevel@tonic-gate * addressable space. 424*0Sstevel@tonic-gate */ 425*0Sstevel@tonic-gate static int 426*0Sstevel@tonic-gate grbeep_map_regs(dev_info_t *dip, grbeep_state_t *grbeeptr) 427*0Sstevel@tonic-gate { 428*0Sstevel@tonic-gate ddi_device_acc_attr_t attr; 429*0Sstevel@tonic-gate 430*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_map_regs: Start")); 431*0Sstevel@tonic-gate 432*0Sstevel@tonic-gate /* The host controller will be little endian */ 433*0Sstevel@tonic-gate attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 434*0Sstevel@tonic-gate attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC; 435*0Sstevel@tonic-gate attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 436*0Sstevel@tonic-gate 437*0Sstevel@tonic-gate /* Map in operational registers */ 438*0Sstevel@tonic-gate if (ddi_regs_map_setup(dip, 2, 439*0Sstevel@tonic-gate (caddr_t *)&grbeeptr->grbeep_freq_regs, 440*0Sstevel@tonic-gate 0, 441*0Sstevel@tonic-gate sizeof (grbeep_freq_regs_t), 442*0Sstevel@tonic-gate &attr, 443*0Sstevel@tonic-gate &grbeeptr->grbeep_freq_regs_handle) 444*0Sstevel@tonic-gate != DDI_SUCCESS) { 445*0Sstevel@tonic-gate 446*0Sstevel@tonic-gate GRBEEP_DEBUG((CE_CONT, "grbeep_map_regs: Failed to map")); 447*0Sstevel@tonic-gate return (DDI_FAILURE); 448*0Sstevel@tonic-gate } 449*0Sstevel@tonic-gate 450*0Sstevel@tonic-gate /* Map in operational registers */ 451*0Sstevel@tonic-gate if (ddi_regs_map_setup(dip, 3, 452*0Sstevel@tonic-gate (caddr_t *)&grbeeptr->grbeep_start_stop_reg, 453*0Sstevel@tonic-gate 0, 454*0Sstevel@tonic-gate 1, 455*0Sstevel@tonic-gate &attr, 456*0Sstevel@tonic-gate &grbeeptr->grbeep_start_stop_reg_handle) 457*0Sstevel@tonic-gate != DDI_SUCCESS) { 458*0Sstevel@tonic-gate 459*0Sstevel@tonic-gate GRBEEP_DEBUG((CE_CONT, "grbeep_map_regs: Failed to map")); 460*0Sstevel@tonic-gate ddi_regs_map_free((void *)&grbeeptr->grbeep_freq_regs_handle); 461*0Sstevel@tonic-gate 462*0Sstevel@tonic-gate return (DDI_FAILURE); 463*0Sstevel@tonic-gate } 464*0Sstevel@tonic-gate 465*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_map_regs: done")); 466*0Sstevel@tonic-gate 467*0Sstevel@tonic-gate return (DDI_SUCCESS); 468*0Sstevel@tonic-gate } 469*0Sstevel@tonic-gate 470*0Sstevel@tonic-gate 471*0Sstevel@tonic-gate /* 472*0Sstevel@tonic-gate * grbeep_obtain_state: 473*0Sstevel@tonic-gate */ 474*0Sstevel@tonic-gate static grbeep_state_t * 475*0Sstevel@tonic-gate grbeep_obtain_state(dev_info_t *dip) 476*0Sstevel@tonic-gate { 477*0Sstevel@tonic-gate int instance = ddi_get_instance(dip); 478*0Sstevel@tonic-gate 479*0Sstevel@tonic-gate grbeep_state_t *state = ddi_get_soft_state(grbeep_statep, instance); 480*0Sstevel@tonic-gate 481*0Sstevel@tonic-gate ASSERT(state != NULL); 482*0Sstevel@tonic-gate 483*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_obtain_state: done")); 484*0Sstevel@tonic-gate 485*0Sstevel@tonic-gate return (state); 486*0Sstevel@tonic-gate } 487*0Sstevel@tonic-gate 488*0Sstevel@tonic-gate 489*0Sstevel@tonic-gate /* 490*0Sstevel@tonic-gate * grbeep_cleanup : 491*0Sstevel@tonic-gate * Cleanup soft state 492*0Sstevel@tonic-gate */ 493*0Sstevel@tonic-gate static void 494*0Sstevel@tonic-gate grbeep_cleanup(grbeep_state_t *grbeeptr) 495*0Sstevel@tonic-gate { 496*0Sstevel@tonic-gate int instance = ddi_get_instance(grbeeptr->grbeep_dip); 497*0Sstevel@tonic-gate 498*0Sstevel@tonic-gate mutex_destroy(&grbeeptr->grbeep_mutex); 499*0Sstevel@tonic-gate ddi_soft_state_free(grbeep_statep, instance); 500*0Sstevel@tonic-gate 501*0Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_cleanup: done")); 502*0Sstevel@tonic-gate } 503