10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
55129Smarx * Common Development and Distribution License (the "License").
65129Smarx * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*7656SSherry.Moore@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate
270Sstevel@tonic-gate /*
280Sstevel@tonic-gate * This is the Beep driver for SMBUS based beep mechanism.
290Sstevel@tonic-gate * The driver exports the interfaces to set frequency,
300Sstevel@tonic-gate * turn on beeper and turn off beeper to the generic beep
310Sstevel@tonic-gate * module. If a beep is in progress, the driver discards a
320Sstevel@tonic-gate * second beep. This driver uses the 8254 timer to program
330Sstevel@tonic-gate * the beeper ports.
340Sstevel@tonic-gate */
350Sstevel@tonic-gate #include <sys/types.h>
360Sstevel@tonic-gate #include <sys/conf.h>
370Sstevel@tonic-gate #include <sys/ddi.h>
380Sstevel@tonic-gate #include <sys/sunddi.h>
390Sstevel@tonic-gate #include <sys/modctl.h>
400Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
410Sstevel@tonic-gate #include <sys/kmem.h>
420Sstevel@tonic-gate #include <sys/devops.h>
430Sstevel@tonic-gate #include <sys/grbeep.h>
445129Smarx #include <sys/beep.h>
450Sstevel@tonic-gate
460Sstevel@tonic-gate
470Sstevel@tonic-gate /* Pointer to the state structure */
480Sstevel@tonic-gate static void *grbeep_statep;
490Sstevel@tonic-gate
500Sstevel@tonic-gate
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate * Debug stuff
530Sstevel@tonic-gate */
540Sstevel@tonic-gate #ifdef DEBUG
550Sstevel@tonic-gate int grbeep_debug = 0;
560Sstevel@tonic-gate #define GRBEEP_DEBUG(args) if (grbeep_debug) cmn_err args
570Sstevel@tonic-gate #define GRBEEP_DEBUG1(args) if (grbeep_debug > 1) cmn_err args
580Sstevel@tonic-gate #else
590Sstevel@tonic-gate #define GRBEEP_DEBUG(args)
600Sstevel@tonic-gate #define GRBEEP_DEBUG1(args)
610Sstevel@tonic-gate #endif
620Sstevel@tonic-gate
630Sstevel@tonic-gate
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate * Prototypes
660Sstevel@tonic-gate */
670Sstevel@tonic-gate static int grbeep_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
680Sstevel@tonic-gate static int grbeep_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
690Sstevel@tonic-gate static int grbeep_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
700Sstevel@tonic-gate void **result);
715129Smarx static void grbeep_freq(void *arg, int freq);
725129Smarx static void grbeep_on(void *arg);
735129Smarx static void grbeep_off(void *arg);
740Sstevel@tonic-gate static void grbeep_cleanup(grbeep_state_t *);
750Sstevel@tonic-gate static int grbeep_map_regs(dev_info_t *, grbeep_state_t *);
760Sstevel@tonic-gate static grbeep_state_t *grbeep_obtain_state(dev_info_t *);
770Sstevel@tonic-gate
780Sstevel@tonic-gate
790Sstevel@tonic-gate struct cb_ops grbeep_cb_ops = {
800Sstevel@tonic-gate nulldev, /* open */
810Sstevel@tonic-gate nulldev, /* close */
820Sstevel@tonic-gate nulldev, /* strategy */
830Sstevel@tonic-gate nulldev, /* print */
840Sstevel@tonic-gate nulldev, /* dump */
850Sstevel@tonic-gate nulldev, /* read */
860Sstevel@tonic-gate nulldev, /* write */
870Sstevel@tonic-gate nulldev, /* ioctl */
880Sstevel@tonic-gate nulldev, /* devmap */
890Sstevel@tonic-gate nulldev, /* mmap */
900Sstevel@tonic-gate nulldev, /* segmap */
910Sstevel@tonic-gate nochpoll, /* poll */
920Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */
930Sstevel@tonic-gate NULL, /* streamtab */
940Sstevel@tonic-gate D_MP | D_NEW
950Sstevel@tonic-gate };
960Sstevel@tonic-gate
970Sstevel@tonic-gate
980Sstevel@tonic-gate static struct dev_ops grbeep_ops = {
990Sstevel@tonic-gate DEVO_REV, /* Devo_rev */
1000Sstevel@tonic-gate 0, /* Refcnt */
1010Sstevel@tonic-gate grbeep_info, /* Info */
1020Sstevel@tonic-gate nulldev, /* Identify */
1030Sstevel@tonic-gate nulldev, /* Probe */
1040Sstevel@tonic-gate grbeep_attach, /* Attach */
1050Sstevel@tonic-gate grbeep_detach, /* Detach */
1060Sstevel@tonic-gate nodev, /* Reset */
1070Sstevel@tonic-gate &grbeep_cb_ops, /* Driver operations */
1080Sstevel@tonic-gate 0, /* Bus operations */
109*7656SSherry.Moore@Sun.COM NULL, /* Power */
110*7656SSherry.Moore@Sun.COM ddi_quiesce_not_supported, /* devo_quiesce */
1110Sstevel@tonic-gate };
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate static struct modldrv modldrv = {
1150Sstevel@tonic-gate &mod_driverops, /* This one is a driver */
116*7656SSherry.Moore@Sun.COM "SMBUS Beep Driver", /* Name of the module. */
1170Sstevel@tonic-gate &grbeep_ops, /* Driver ops */
1180Sstevel@tonic-gate };
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate static struct modlinkage modlinkage = {
1220Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL
1230Sstevel@tonic-gate };
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate int
_init(void)1270Sstevel@tonic-gate _init(void)
1280Sstevel@tonic-gate {
1290Sstevel@tonic-gate int error;
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate /* Initialize the soft state structures */
1320Sstevel@tonic-gate if ((error = ddi_soft_state_init(&grbeep_statep,
1335129Smarx sizeof (grbeep_state_t), 1)) != 0) {
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate return (error);
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate /* Install the loadable module */
1390Sstevel@tonic-gate if ((error = mod_install(&modlinkage)) != 0) {
1400Sstevel@tonic-gate ddi_soft_state_fini(&grbeep_statep);
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate return (error);
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1480Sstevel@tonic-gate _info(struct modinfo *modinfop)
1490Sstevel@tonic-gate {
1500Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1510Sstevel@tonic-gate }
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate int
_fini(void)1550Sstevel@tonic-gate _fini(void)
1560Sstevel@tonic-gate {
1570Sstevel@tonic-gate int error;
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate error = mod_remove(&modlinkage);
1600Sstevel@tonic-gate
1610Sstevel@tonic-gate if (error == 0) {
1620Sstevel@tonic-gate /* Release per module resources */
1630Sstevel@tonic-gate ddi_soft_state_fini(&grbeep_statep);
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate return (error);
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate /*
1710Sstevel@tonic-gate * Beep entry points
1720Sstevel@tonic-gate */
1730Sstevel@tonic-gate
1740Sstevel@tonic-gate /*
1750Sstevel@tonic-gate * grbeep_attach:
1760Sstevel@tonic-gate */
1770Sstevel@tonic-gate static int
grbeep_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)1780Sstevel@tonic-gate grbeep_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
1790Sstevel@tonic-gate {
1800Sstevel@tonic-gate int instance;
1810Sstevel@tonic-gate
1820Sstevel@tonic-gate /* Pointer to soft state */
1830Sstevel@tonic-gate grbeep_state_t *grbeeptr = NULL;
1840Sstevel@tonic-gate
1850Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_attach: Start"));
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate switch (cmd) {
1880Sstevel@tonic-gate case DDI_ATTACH:
1890Sstevel@tonic-gate break;
1900Sstevel@tonic-gate case DDI_RESUME:
1910Sstevel@tonic-gate
1920Sstevel@tonic-gate return (DDI_SUCCESS);
1930Sstevel@tonic-gate default:
1940Sstevel@tonic-gate
1950Sstevel@tonic-gate return (DDI_FAILURE);
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate /* Get the instance and create soft state */
1990Sstevel@tonic-gate instance = ddi_get_instance(dip);
2000Sstevel@tonic-gate
2010Sstevel@tonic-gate if (ddi_soft_state_zalloc(grbeep_statep, instance) != 0) {
2020Sstevel@tonic-gate
2030Sstevel@tonic-gate return (DDI_FAILURE);
2040Sstevel@tonic-gate }
2050Sstevel@tonic-gate
2060Sstevel@tonic-gate grbeeptr = ddi_get_soft_state(grbeep_statep, instance);
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate if (grbeeptr == NULL) {
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate return (DDI_FAILURE);
2110Sstevel@tonic-gate }
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeeptr = 0x%p, instance %x",
2140Sstevel@tonic-gate (void *)grbeeptr, instance));
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate /* Save the dip */
2170Sstevel@tonic-gate grbeeptr->grbeep_dip = dip;
2180Sstevel@tonic-gate
2190Sstevel@tonic-gate /* Initialize beeper mode */
2200Sstevel@tonic-gate grbeeptr->grbeep_mode = GRBEEP_OFF;
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate /* Map the Beep Control and Beep counter Registers */
2230Sstevel@tonic-gate if (grbeep_map_regs(dip, grbeeptr) != DDI_SUCCESS) {
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate GRBEEP_DEBUG((CE_WARN,
2265129Smarx "grbeep_attach: Mapping of beep registers failed."));
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate grbeep_cleanup(grbeeptr);
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate return (DDI_FAILURE);
2310Sstevel@tonic-gate }
2320Sstevel@tonic-gate
2335129Smarx (void) beep_init((void *)dip, grbeep_on, grbeep_off, grbeep_freq);
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate /* Display information in the banner */
2360Sstevel@tonic-gate ddi_report_dev(dip);
2370Sstevel@tonic-gate
2380Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_attach: dip = 0x%p done",
2390Sstevel@tonic-gate (void *)dip));
2400Sstevel@tonic-gate
2410Sstevel@tonic-gate return (DDI_SUCCESS);
2420Sstevel@tonic-gate }
2430Sstevel@tonic-gate
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate /*
2460Sstevel@tonic-gate * grbeep_detach:
2470Sstevel@tonic-gate */
2480Sstevel@tonic-gate static int
grbeep_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)2490Sstevel@tonic-gate grbeep_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
2500Sstevel@tonic-gate {
2510Sstevel@tonic-gate /* Pointer to soft state */
2520Sstevel@tonic-gate grbeep_state_t *grbeeptr = NULL;
2530Sstevel@tonic-gate
2540Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_detach: Start"));
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate switch (cmd) {
2570Sstevel@tonic-gate case DDI_SUSPEND:
2580Sstevel@tonic-gate grbeeptr = grbeep_obtain_state(dip);
2590Sstevel@tonic-gate
2600Sstevel@tonic-gate if (grbeeptr == NULL) {
2610Sstevel@tonic-gate
2620Sstevel@tonic-gate return (DDI_FAILURE);
2630Sstevel@tonic-gate }
2640Sstevel@tonic-gate
2650Sstevel@tonic-gate /*
2660Sstevel@tonic-gate * If a beep is in progress; fail suspend
2670Sstevel@tonic-gate */
2680Sstevel@tonic-gate if (grbeeptr->grbeep_mode == GRBEEP_OFF) {
2690Sstevel@tonic-gate
2700Sstevel@tonic-gate return (DDI_SUCCESS);
2710Sstevel@tonic-gate } else {
2720Sstevel@tonic-gate
2730Sstevel@tonic-gate return (DDI_FAILURE);
2740Sstevel@tonic-gate }
2750Sstevel@tonic-gate default:
2760Sstevel@tonic-gate
2770Sstevel@tonic-gate return (DDI_FAILURE);
2780Sstevel@tonic-gate }
2790Sstevel@tonic-gate }
2800Sstevel@tonic-gate
2810Sstevel@tonic-gate
2820Sstevel@tonic-gate /*
2830Sstevel@tonic-gate * grbeep_info:
2840Sstevel@tonic-gate */
2850Sstevel@tonic-gate /* ARGSUSED */
2860Sstevel@tonic-gate static int
grbeep_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)2870Sstevel@tonic-gate grbeep_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
2880Sstevel@tonic-gate void *arg, void **result)
2890Sstevel@tonic-gate {
2900Sstevel@tonic-gate dev_t dev;
2910Sstevel@tonic-gate grbeep_state_t *grbeeptr;
2920Sstevel@tonic-gate int instance, error;
2930Sstevel@tonic-gate
2940Sstevel@tonic-gate switch (infocmd) {
2950Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO:
2960Sstevel@tonic-gate dev = (dev_t)arg;
2970Sstevel@tonic-gate instance = GRBEEP_UNIT(dev);
2980Sstevel@tonic-gate
2990Sstevel@tonic-gate if ((grbeeptr = ddi_get_soft_state(grbeep_statep,
3000Sstevel@tonic-gate instance)) == NULL) {
3010Sstevel@tonic-gate
3020Sstevel@tonic-gate return (DDI_FAILURE);
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate *result = (void *)grbeeptr->grbeep_dip;
3060Sstevel@tonic-gate
3070Sstevel@tonic-gate error = DDI_SUCCESS;
3080Sstevel@tonic-gate break;
3090Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE:
3100Sstevel@tonic-gate dev = (dev_t)arg;
3110Sstevel@tonic-gate instance = GRBEEP_UNIT(dev);
3120Sstevel@tonic-gate
3130Sstevel@tonic-gate *result = (void *)(uintptr_t)instance;
3140Sstevel@tonic-gate
3150Sstevel@tonic-gate error = DDI_SUCCESS;
3160Sstevel@tonic-gate break;
3170Sstevel@tonic-gate default:
3180Sstevel@tonic-gate error = DDI_FAILURE;
3190Sstevel@tonic-gate
3200Sstevel@tonic-gate }
3210Sstevel@tonic-gate
3220Sstevel@tonic-gate return (error);
3230Sstevel@tonic-gate }
3240Sstevel@tonic-gate
3250Sstevel@tonic-gate
3260Sstevel@tonic-gate /*
3270Sstevel@tonic-gate * grbeep_freq() :
3280Sstevel@tonic-gate * Set beep frequency
3290Sstevel@tonic-gate */
3300Sstevel@tonic-gate static void
grbeep_freq(void * arg,int freq)3315129Smarx grbeep_freq(void *arg, int freq)
3320Sstevel@tonic-gate {
3335129Smarx dev_info_t *dip = (dev_info_t *)arg;
3340Sstevel@tonic-gate grbeep_state_t *grbeeptr = grbeep_obtain_state(dip);
3350Sstevel@tonic-gate int divisor = 0;
3360Sstevel@tonic-gate
3370Sstevel@tonic-gate ASSERT(freq != 0);
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_freq: dip=0x%p freq=%d mode=%d",
3400Sstevel@tonic-gate (void *)dip, freq, grbeeptr->grbeep_mode));
3410Sstevel@tonic-gate
3420Sstevel@tonic-gate GRBEEP_WRITE_FREQ_CONTROL_REG(GRBEEP_CONTROL);
3430Sstevel@tonic-gate
3440Sstevel@tonic-gate divisor = GRBEEP_INPUT_FREQ / freq;
3450Sstevel@tonic-gate
3460Sstevel@tonic-gate if (divisor > GRBEEP_DIVISOR_MAX) {
3470Sstevel@tonic-gate divisor = GRBEEP_DIVISOR_MAX;
3480Sstevel@tonic-gate } else if (divisor < GRBEEP_DIVISOR_MIN) {
3490Sstevel@tonic-gate divisor = GRBEEP_DIVISOR_MIN;
3500Sstevel@tonic-gate }
3510Sstevel@tonic-gate
3520Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_freq: first=0x%x second=0x%x",
3535129Smarx (divisor & 0xff), ((divisor & 0xff00) >> 8)));
3540Sstevel@tonic-gate
3550Sstevel@tonic-gate GRBEEP_WRITE_FREQ_DIVISOR_REG(divisor & 0xff);
3560Sstevel@tonic-gate GRBEEP_WRITE_FREQ_DIVISOR_REG((divisor & 0xff00) >> 8);
3570Sstevel@tonic-gate }
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate
3600Sstevel@tonic-gate /*
3610Sstevel@tonic-gate * grbeep_on() :
3620Sstevel@tonic-gate * Turn the beeper on
3630Sstevel@tonic-gate */
3640Sstevel@tonic-gate static void
grbeep_on(void * arg)3655129Smarx grbeep_on(void *arg)
3660Sstevel@tonic-gate {
3675129Smarx dev_info_t *dip = (dev_info_t *)arg;
3680Sstevel@tonic-gate grbeep_state_t *grbeeptr = grbeep_obtain_state(dip);
3690Sstevel@tonic-gate
3700Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_on: dip = 0x%p mode=%d",
3710Sstevel@tonic-gate (void *)dip, grbeeptr->grbeep_mode));
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate if (grbeeptr->grbeep_mode == GRBEEP_OFF) {
3740Sstevel@tonic-gate
3750Sstevel@tonic-gate grbeeptr->grbeep_mode = GRBEEP_ON;
3760Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_on: Starting beep"));
3770Sstevel@tonic-gate GRBEEP_WRITE_START_STOP_REG(GRBEEP_START);
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate }
3800Sstevel@tonic-gate
3810Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_on: dip = 0x%p done", (void *)dip));
3820Sstevel@tonic-gate }
3830Sstevel@tonic-gate
3840Sstevel@tonic-gate
3850Sstevel@tonic-gate /*
3860Sstevel@tonic-gate * grbeep_off() :
3870Sstevel@tonic-gate * Turn the beeper off
3880Sstevel@tonic-gate */
3890Sstevel@tonic-gate static void
grbeep_off(void * arg)3905129Smarx grbeep_off(void *arg)
3910Sstevel@tonic-gate {
3925129Smarx dev_info_t *dip = (dev_info_t *)arg;
3930Sstevel@tonic-gate grbeep_state_t *grbeeptr = grbeep_obtain_state(dip);
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_off: dip = 0x%p mode=%d",
3960Sstevel@tonic-gate (void *)dip, grbeeptr->grbeep_mode));
3970Sstevel@tonic-gate
3980Sstevel@tonic-gate if (grbeeptr->grbeep_mode == GRBEEP_ON) {
3990Sstevel@tonic-gate
4000Sstevel@tonic-gate grbeeptr->grbeep_mode = GRBEEP_OFF;
4010Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_off: Stopping beep"));
4020Sstevel@tonic-gate GRBEEP_WRITE_START_STOP_REG(GRBEEP_STOP);
4030Sstevel@tonic-gate
4040Sstevel@tonic-gate }
4050Sstevel@tonic-gate
4060Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_off: dip = 0x%p done", (void *)dip));
4070Sstevel@tonic-gate }
4080Sstevel@tonic-gate
4090Sstevel@tonic-gate /*
4100Sstevel@tonic-gate * grbeep_map_regs() :
4110Sstevel@tonic-gate *
4120Sstevel@tonic-gate * The write beep port register and spkr control register
4130Sstevel@tonic-gate * should be mapped into a non-cacheable portion of the system
4140Sstevel@tonic-gate * addressable space.
4150Sstevel@tonic-gate */
4160Sstevel@tonic-gate static int
grbeep_map_regs(dev_info_t * dip,grbeep_state_t * grbeeptr)4170Sstevel@tonic-gate grbeep_map_regs(dev_info_t *dip, grbeep_state_t *grbeeptr)
4180Sstevel@tonic-gate {
4190Sstevel@tonic-gate ddi_device_acc_attr_t attr;
4200Sstevel@tonic-gate
4210Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_map_regs: Start"));
4220Sstevel@tonic-gate
4230Sstevel@tonic-gate /* The host controller will be little endian */
4240Sstevel@tonic-gate attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
4250Sstevel@tonic-gate attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
4260Sstevel@tonic-gate attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
4270Sstevel@tonic-gate
4280Sstevel@tonic-gate /* Map in operational registers */
4290Sstevel@tonic-gate if (ddi_regs_map_setup(dip, 2,
4300Sstevel@tonic-gate (caddr_t *)&grbeeptr->grbeep_freq_regs,
4310Sstevel@tonic-gate 0,
4320Sstevel@tonic-gate sizeof (grbeep_freq_regs_t),
4330Sstevel@tonic-gate &attr,
4340Sstevel@tonic-gate &grbeeptr->grbeep_freq_regs_handle)
4355129Smarx != DDI_SUCCESS) {
4360Sstevel@tonic-gate
4370Sstevel@tonic-gate GRBEEP_DEBUG((CE_CONT, "grbeep_map_regs: Failed to map"));
4380Sstevel@tonic-gate return (DDI_FAILURE);
4390Sstevel@tonic-gate }
4400Sstevel@tonic-gate
4410Sstevel@tonic-gate /* Map in operational registers */
4420Sstevel@tonic-gate if (ddi_regs_map_setup(dip, 3,
4430Sstevel@tonic-gate (caddr_t *)&grbeeptr->grbeep_start_stop_reg,
4440Sstevel@tonic-gate 0,
4450Sstevel@tonic-gate 1,
4460Sstevel@tonic-gate &attr,
4470Sstevel@tonic-gate &grbeeptr->grbeep_start_stop_reg_handle)
4485129Smarx != DDI_SUCCESS) {
4490Sstevel@tonic-gate
4500Sstevel@tonic-gate GRBEEP_DEBUG((CE_CONT, "grbeep_map_regs: Failed to map"));
4510Sstevel@tonic-gate ddi_regs_map_free((void *)&grbeeptr->grbeep_freq_regs_handle);
4520Sstevel@tonic-gate
4530Sstevel@tonic-gate return (DDI_FAILURE);
4540Sstevel@tonic-gate }
4550Sstevel@tonic-gate
4560Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_map_regs: done"));
4570Sstevel@tonic-gate
4580Sstevel@tonic-gate return (DDI_SUCCESS);
4590Sstevel@tonic-gate }
4600Sstevel@tonic-gate
4610Sstevel@tonic-gate
4620Sstevel@tonic-gate /*
4630Sstevel@tonic-gate * grbeep_obtain_state:
4640Sstevel@tonic-gate */
4650Sstevel@tonic-gate static grbeep_state_t *
grbeep_obtain_state(dev_info_t * dip)4660Sstevel@tonic-gate grbeep_obtain_state(dev_info_t *dip)
4670Sstevel@tonic-gate {
4680Sstevel@tonic-gate int instance = ddi_get_instance(dip);
4690Sstevel@tonic-gate
4700Sstevel@tonic-gate grbeep_state_t *state = ddi_get_soft_state(grbeep_statep, instance);
4710Sstevel@tonic-gate
4720Sstevel@tonic-gate ASSERT(state != NULL);
4730Sstevel@tonic-gate
4740Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_obtain_state: done"));
4750Sstevel@tonic-gate
4760Sstevel@tonic-gate return (state);
4770Sstevel@tonic-gate }
4780Sstevel@tonic-gate
4790Sstevel@tonic-gate
4800Sstevel@tonic-gate /*
4810Sstevel@tonic-gate * grbeep_cleanup :
4820Sstevel@tonic-gate * Cleanup soft state
4830Sstevel@tonic-gate */
4840Sstevel@tonic-gate static void
grbeep_cleanup(grbeep_state_t * grbeeptr)4850Sstevel@tonic-gate grbeep_cleanup(grbeep_state_t *grbeeptr)
4860Sstevel@tonic-gate {
4870Sstevel@tonic-gate int instance = ddi_get_instance(grbeeptr->grbeep_dip);
4880Sstevel@tonic-gate
4890Sstevel@tonic-gate ddi_soft_state_free(grbeep_statep, instance);
4900Sstevel@tonic-gate
4910Sstevel@tonic-gate GRBEEP_DEBUG1((CE_CONT, "grbeep_cleanup: done"));
4920Sstevel@tonic-gate }
493