/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This is the Beep driver for bbc based beep mechanism.
*
*/
#include <sys/ddi_impldefs.h>
#include <sys/bbc_beep.h>
/* Pointer to the state structure */
static void *bbc_beep_statep;
/*
* Debug stuff
*/
#ifdef DEBUG
int bbc_beep_debug = 0;
#else
#endif
/*
* Prototypes
*/
void **result);
static void bbc_beep_on(void *arg);
static void bbc_beep_off(void *arg);
static void bbc_beep_cleanup(bbc_beep_state_t *);
static unsigned long bbc_beep_hztocounter(int);
nulldev, /* open */
nulldev, /* close */
nulldev, /* strategy */
nulldev, /* print */
nulldev, /* dump */
nulldev, /* read */
nulldev, /* write */
nulldev, /* ioctl */
nulldev, /* devmap */
nulldev, /* mmap */
nulldev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* cb_prop_op */
NULL, /* streamtab */
};
DEVO_REV, /* Devo_rev */
0, /* Refcnt */
bbc_beep_info, /* Info */
nulldev, /* Identify */
nulldev, /* Probe */
bbc_beep_attach, /* Attach */
bbc_beep_detach, /* Detach */
nodev, /* Reset */
&bbc_beep_cb_ops, /* Driver operations */
0, /* Bus operations */
ddi_power, /* Power */
ddi_quiesce_not_supported, /* devo_quiesce */
};
&mod_driverops, /* This one is a driver */
"BBC Beep Driver", /* Name of the module. */
&bbc_beep_ops, /* Driver ops */
};
};
int
_init(void)
{
int error;
/* Initialize the soft state structures */
sizeof (bbc_beep_state_t), 1)) != 0) {
return (error);
}
/* Install the loadable module */
}
return (error);
}
int
{
}
int
_fini(void)
{
int error;
if (error == 0) {
/* Release per module resources */
}
return (error);
}
/*
* Beep entry points
*/
/*
* bbc_beep_attach:
*/
static int
{
/* Pointer to soft state */
switch (cmd) {
case DDI_ATTACH:
break;
case DDI_RESUME:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
/* Get the instance and create soft state */
return (DDI_FAILURE);
}
if (bbc_beeptr == NULL) {
return (DDI_FAILURE);
}
(void *)bbc_beeptr, instance));
/* Save the dip */
/* Initialize beeper mode */
/* Map the Beep Control and Beep counter Registers */
"bbc_beep_attach: Mapping of bbc registers failed."));
return (DDI_FAILURE);
}
/* Display information in the banner */
(void *)dip));
return (DDI_SUCCESS);
}
/*
* bbc_beep_detach:
*/
static int
{
/* Pointer to soft state */
switch (cmd) {
case DDI_SUSPEND:
if (bbc_beeptr == NULL) {
return (DDI_FAILURE);
}
/*
* If a beep is in progress; fail suspend
*/
return (DDI_SUCCESS);
} else {
return (DDI_FAILURE);
}
default:
return (DDI_FAILURE);
}
}
/*
* bbc_beep_info:
*/
/* ARGSUSED */
static int
{
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
return (DDI_FAILURE);
}
error = DDI_SUCCESS;
break;
case DDI_INFO_DEVT2INSTANCE:
error = DDI_SUCCESS;
break;
default:
error = DDI_FAILURE;
}
return (error);
}
/*
* bbc_beep_freq() :
* Set the frequency
*/
static void
{
unsigned long counter;
/* Convert the frequency in hz to the bbc counter value */
/* Extract relevant second and third byte of counter value */
/*
* We need to write individual bytes instead of writing
* all of 32 bits to take care of allignment problem.
* Write 0 to LS 8 bits and MS 8 bits
* Write beep_c3 to bit 8..15 and beep_c2 to bit 16..24
* Little Endian format
*/
BEEP_WRITE_COUNTER_REG(0, 0);
BEEP_WRITE_COUNTER_REG(3, 0);
"bbc_beep_freq: dip = 0x%p, freq = %d, counter = 0x%x : Done",
}
/*
* bbc_beep_on() :
* Turn the beeper on
*/
static void
{
(void *)dip));
}
/*
* bbc_beep_off() :
* Turn the beeper off
*/
static void
{
(void *)dip));
}
/*
* bbc_beep_map_regs() :
*
* The Keyboard Beep Control Register and Keyboard Beep Counter Register
* should be mapped into a non-cacheable portion of the system
* addressable space.
*/
static int
{
/* The host controller will be little endian */
/* Map in operational registers */
if (ddi_regs_map_setup(dip, 0,
0,
sizeof (bbc_beep_regs_t),
&attr,
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* bbc_beep_obtain_state:
*/
static bbc_beep_state_t *
{
return (state);
}
/*
* bbc_beep_cleanup :
* Cleanup soft state
*/
static void
{
}
/*
* bbc_beep_hztocounter() :
* Given a frequency in hz, find out the value to
* be set in the Keyboard Beep Counter register
* BBC beeper uses the following formula to calculate
* frequency. The formulae is :
* frequency generated = system freq /2^(n+2)
* Where n = position of the bit of counter register
* that is turned on and can range between 10 to 18.
* So in this function, the inputs are frequency generated
* and system frequency and we need to find out n, i.e, which
* bit to turn on.(Ref. to Section 4.2.22 of the BBC programming
* manual).
*/
unsigned long
{
int i;
unsigned long counter;
int system_freq;
/*
* Get system frequency for the root dev_info properties
*/
0, "clock-frequency", 0);
oldfreq = 0;
/*
* Calculate frequency by turning on ith bit and
* matching it with the passed frequency and we do this
* in a loop for all the relevant bits
*/
/*
* Calculate the frequency by dividing the system
* frequency by 2^i
*/
newfreq = system_freq >> i;
/*
* Check if we turn on the ith bit, the
* frequency matches exactly or not
*/
/*
* Exact match of passed frequency with the
* counter value
*/
return (counter);
}
/*
* If calculated frequency is bigger
* return the passed frequency
*/
if (i == BBC_BEEP_MIN_SHIFT) {
/* Input freq is less than the possible min */
return (counter);
}
/*
* Find out the nearest frequency to the passed
* frequency by comparing the difference between
* the calculated frequency and the passed frequency
*/
/* Return new counter corres. to newfreq */
return (counter);
}
/* Return old counter corresponding to oldfreq */
return (counter << 1);
}
}
/*
* Input freq is greater than the possible max;
* Back off the counter value and return max counter
* value possible in the register
*/
return (counter << 1);
}