2005-04-17 02:20:36 +04:00
/*
* Access to HP - HIL MLC through HP System Device Controller .
*
* Copyright ( c ) 2001 Brian S . Julin
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
* 1. Redistributions of source code must retain the above copyright
* notice , this list of conditions , and the following disclaimer ,
* without modification .
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* Alternatively , this software may be distributed under the terms of the
* GNU General Public License ( " GPL " ) .
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ` ` AS IS ' ' AND
* ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED . IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL
* DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION )
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT
* LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY
*
* References :
* HP - HIL Technical Reference Manual . Hewlett Packard Product No . 45918 A
* System Device Controller Microprocessor Firmware Theory of Operation
* for Part Number 1820 - 4784 Revision B . Dwg No . A - 1820 - 4784 - 2
*
*/
# include <linux/hil_mlc.h>
# include <linux/hp_sdc.h>
# include <linux/errno.h>
# include <linux/kernel.h>
# include <linux/module.h>
# include <linux/init.h>
# include <linux/string.h>
2008-04-19 06:21:05 +04:00
# include <linux/semaphore.h>
2005-04-17 02:20:36 +04:00
# define PREFIX "HP SDC MLC: "
static hil_mlc hp_sdc_mlc ;
MODULE_AUTHOR ( " Brian S. Julin <bri@calyx.com> " ) ;
MODULE_DESCRIPTION ( " Glue for onboard HIL MLC in HP-PARISC machines " ) ;
MODULE_LICENSE ( " Dual BSD/GPL " ) ;
2008-06-26 18:46:39 +04:00
static struct hp_sdc_mlc_priv_s {
2005-04-17 02:20:36 +04:00
int emtestmode ;
hp_sdc_transaction trans ;
u8 tseq [ 16 ] ;
int got5x ;
} hp_sdc_mlc_priv ;
/************************* Interrupt context ******************************/
2007-03-01 07:51:29 +03:00
static void hp_sdc_mlc_isr ( int irq , void * dev_id ,
uint8_t status , uint8_t data )
{
int idx ;
2005-04-17 02:20:36 +04:00
hil_mlc * mlc = & hp_sdc_mlc ;
2007-03-01 07:51:29 +03:00
write_lock ( & mlc - > lock ) ;
2005-04-17 02:20:36 +04:00
if ( mlc - > icount < 0 ) {
printk ( KERN_WARNING PREFIX " HIL Overflow! \n " ) ;
up ( & mlc - > isem ) ;
goto out ;
}
idx = 15 - mlc - > icount ;
if ( ( status & HP_SDC_STATUS_IRQMASK ) = = HP_SDC_STATUS_HILDATA ) {
mlc - > ipacket [ idx ] | = data | HIL_ERR_INT ;
mlc - > icount - - ;
2007-03-01 07:51:29 +03:00
if ( hp_sdc_mlc_priv . got5x | | ! idx )
goto check ;
if ( ( mlc - > ipacket [ idx - 1 ] & HIL_PKT_ADDR_MASK ) ! =
2005-04-17 02:20:36 +04:00
( mlc - > ipacket [ idx ] & HIL_PKT_ADDR_MASK ) ) {
mlc - > ipacket [ idx ] & = ~ HIL_PKT_ADDR_MASK ;
2007-03-01 07:51:29 +03:00
mlc - > ipacket [ idx ] | = ( mlc - > ipacket [ idx - 1 ]
& HIL_PKT_ADDR_MASK ) ;
2005-04-17 02:20:36 +04:00
}
goto check ;
}
/* We know status is 5X */
2007-03-01 07:51:29 +03:00
if ( data & HP_SDC_HIL_ISERR )
goto err ;
mlc - > ipacket [ idx ] =
2005-04-17 02:20:36 +04:00
( data & HP_SDC_HIL_R1MASK ) < < HIL_PKT_ADDR_SHIFT ;
hp_sdc_mlc_priv . got5x = 1 ;
goto out ;
check :
hp_sdc_mlc_priv . got5x = 0 ;
2007-03-01 07:51:29 +03:00
if ( mlc - > imatch = = 0 )
goto done ;
if ( ( mlc - > imatch = = ( HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL ) )
& & ( mlc - > ipacket [ idx ] = = ( mlc - > imatch | idx ) ) )
goto done ;
if ( mlc - > ipacket [ idx ] = = mlc - > imatch )
goto done ;
2005-04-17 02:20:36 +04:00
goto out ;
2007-03-01 07:51:29 +03:00
err :
2005-04-17 02:20:36 +04:00
printk ( KERN_DEBUG PREFIX " err code %x \n " , data ) ;
2007-03-01 07:51:29 +03:00
2005-04-17 02:20:36 +04:00
switch ( data ) {
case HP_SDC_HIL_RC_DONE :
printk ( KERN_WARNING PREFIX " Bastard SDC reconfigured loop! \n " ) ;
break ;
2007-03-01 07:51:29 +03:00
2005-04-17 02:20:36 +04:00
case HP_SDC_HIL_ERR :
2007-03-01 07:51:29 +03:00
mlc - > ipacket [ idx ] | = HIL_ERR_INT | HIL_ERR_PERR |
HIL_ERR_FERR | HIL_ERR_FOF ;
2005-04-17 02:20:36 +04:00
break ;
2007-03-01 07:51:29 +03:00
2005-04-17 02:20:36 +04:00
case HP_SDC_HIL_TO :
mlc - > ipacket [ idx ] | = HIL_ERR_INT | HIL_ERR_LERR ;
break ;
2007-03-01 07:51:29 +03:00
2005-04-17 02:20:36 +04:00
case HP_SDC_HIL_RC :
printk ( KERN_WARNING PREFIX " Bastard SDC decided to reconfigure loop! \n " ) ;
break ;
2007-03-01 07:51:29 +03:00
2005-04-17 02:20:36 +04:00
default :
tree-wide: fix assorted typos all over the place
That is "success", "unknown", "through", "performance", "[re|un]mapping"
, "access", "default", "reasonable", "[con]currently", "temperature"
, "channel", "[un]used", "application", "example","hierarchy", "therefore"
, "[over|under]flow", "contiguous", "threshold", "enough" and others.
Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2009-11-14 18:09:05 +03:00
printk ( KERN_WARNING PREFIX " Unknown HIL Error status (%x)! \n " , data ) ;
2005-04-17 02:20:36 +04:00
break ;
}
2007-03-01 07:51:29 +03:00
2005-04-17 02:20:36 +04:00
/* No more data will be coming due to an error. */
done :
tasklet_schedule ( mlc - > tasklet ) ;
2007-03-01 07:51:29 +03:00
up ( & mlc - > isem ) ;
2005-04-17 02:20:36 +04:00
out :
2007-03-01 07:51:29 +03:00
write_unlock ( & mlc - > lock ) ;
2005-04-17 02:20:36 +04:00
}
/******************** Tasklet or userspace context functions ****************/
2007-03-01 07:51:29 +03:00
static int hp_sdc_mlc_in ( hil_mlc * mlc , suseconds_t timeout )
{
2005-04-17 02:20:36 +04:00
struct hp_sdc_mlc_priv_s * priv ;
int rc = 2 ;
priv = mlc - > priv ;
/* Try to down the semaphore */
2007-03-01 07:51:29 +03:00
if ( down_trylock ( & mlc - > isem ) ) {
2005-04-17 02:20:36 +04:00
if ( priv - > emtestmode ) {
2007-03-01 07:51:29 +03:00
mlc - > ipacket [ 0 ] =
HIL_ERR_INT | ( mlc - > opacket &
( HIL_PKT_CMD |
HIL_PKT_ADDR_MASK |
2005-04-17 02:20:36 +04:00
HIL_PKT_DATA_MASK ) ) ;
mlc - > icount = 14 ;
/* printk(KERN_DEBUG PREFIX ">[%x]\n", mlc->ipacket[0]); */
goto wasup ;
}
2018-01-02 08:31:18 +03:00
if ( time_after ( jiffies , mlc - > instart + mlc - > intimeout ) ) {
2007-03-01 07:51:29 +03:00
/* printk("!%i %i",
tv . tv_usec - mlc - > instart . tv_usec ,
mlc - > intimeout ) ;
*/
2005-04-17 02:20:36 +04:00
rc = 1 ;
2007-03-01 07:51:29 +03:00
up ( & mlc - > isem ) ;
2005-04-17 02:20:36 +04:00
}
goto done ;
}
wasup :
2007-03-01 07:51:29 +03:00
up ( & mlc - > isem ) ;
2005-04-17 02:20:36 +04:00
rc = 0 ;
done :
return rc ;
}
2007-03-01 07:51:29 +03:00
static int hp_sdc_mlc_cts ( hil_mlc * mlc )
{
2005-04-17 02:20:36 +04:00
struct hp_sdc_mlc_priv_s * priv ;
2007-03-01 07:51:29 +03:00
priv = mlc - > priv ;
2005-04-17 02:20:36 +04:00
/* Try to down the semaphores -- they should be up. */
2007-03-01 07:51:29 +03:00
BUG_ON ( down_trylock ( & mlc - > isem ) ) ;
BUG_ON ( down_trylock ( & mlc - > osem ) ) ;
2005-04-17 02:20:36 +04:00
2007-03-01 07:51:29 +03:00
up ( & mlc - > isem ) ;
up ( & mlc - > osem ) ;
if ( down_trylock ( & mlc - > csem ) ) {
if ( priv - > trans . act . semaphore ! = & mlc - > csem )
goto poll ;
else
goto busy ;
2005-04-17 02:20:36 +04:00
}
2007-03-01 07:51:29 +03:00
if ( ! ( priv - > tseq [ 4 ] & HP_SDC_USE_LOOP ) )
goto done ;
2005-04-17 02:20:36 +04:00
poll :
2007-03-01 07:51:29 +03:00
priv - > trans . act . semaphore = & mlc - > csem ;
2005-04-17 02:20:36 +04:00
priv - > trans . actidx = 0 ;
priv - > trans . idx = 1 ;
priv - > trans . endidx = 5 ;
2007-03-01 07:51:29 +03:00
priv - > tseq [ 0 ] =
2005-04-17 02:20:36 +04:00
HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN | HP_SDC_ACT_SEMAPHORE ;
priv - > tseq [ 1 ] = HP_SDC_CMD_READ_USE ;
priv - > tseq [ 2 ] = 1 ;
priv - > tseq [ 3 ] = 0 ;
priv - > tseq [ 4 ] = 0 ;
2007-03-16 07:59:29 +03:00
__hp_sdc_enqueue_transaction ( & priv - > trans ) ;
2005-04-17 02:20:36 +04:00
busy :
return 1 ;
done :
2007-03-01 07:51:29 +03:00
priv - > trans . act . semaphore = & mlc - > osem ;
up ( & mlc - > csem ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
}
2007-03-01 07:51:29 +03:00
static void hp_sdc_mlc_out ( hil_mlc * mlc )
{
2005-04-17 02:20:36 +04:00
struct hp_sdc_mlc_priv_s * priv ;
priv = mlc - > priv ;
/* Try to down the semaphore -- it should be up. */
2007-03-01 07:51:29 +03:00
BUG_ON ( down_trylock ( & mlc - > osem ) ) ;
2005-04-17 02:20:36 +04:00
2007-03-01 07:51:29 +03:00
if ( mlc - > opacket & HIL_DO_ALTER_CTRL )
goto do_control ;
2005-04-17 02:20:36 +04:00
do_data :
if ( priv - > emtestmode ) {
2007-03-01 07:51:29 +03:00
up ( & mlc - > osem ) ;
2007-03-16 07:59:29 +03:00
return ;
2005-04-17 02:20:36 +04:00
}
/* Shouldn't be sending commands when loop may be busy */
2007-03-01 07:51:29 +03:00
BUG_ON ( down_trylock ( & mlc - > csem ) ) ;
up ( & mlc - > csem ) ;
2005-04-17 02:20:36 +04:00
priv - > trans . actidx = 0 ;
priv - > trans . idx = 1 ;
2007-03-01 07:51:29 +03:00
priv - > trans . act . semaphore = & mlc - > osem ;
2005-04-17 02:20:36 +04:00
priv - > trans . endidx = 6 ;
2007-03-01 07:51:29 +03:00
priv - > tseq [ 0 ] =
2005-04-17 02:20:36 +04:00
HP_SDC_ACT_DATAREG | HP_SDC_ACT_POSTCMD | HP_SDC_ACT_SEMAPHORE ;
priv - > tseq [ 1 ] = 0x7 ;
2007-03-01 07:51:29 +03:00
priv - > tseq [ 2 ] =
( mlc - > opacket &
2005-04-17 02:20:36 +04:00
( HIL_PKT_ADDR_MASK | HIL_PKT_CMD ) )
> > HIL_PKT_ADDR_SHIFT ;
2007-03-01 07:51:29 +03:00
priv - > tseq [ 3 ] =
( mlc - > opacket & HIL_PKT_DATA_MASK )
2005-04-17 02:20:36 +04:00
> > HIL_PKT_DATA_SHIFT ;
priv - > tseq [ 4 ] = 0 ; /* No timeout */
2007-03-01 07:51:29 +03:00
if ( priv - > tseq [ 3 ] = = HIL_CMD_DHR )
priv - > tseq [ 4 ] = 1 ;
2005-04-17 02:20:36 +04:00
priv - > tseq [ 5 ] = HP_SDC_CMD_DO_HIL ;
goto enqueue ;
do_control :
priv - > emtestmode = mlc - > opacket & HIL_CTRL_TEST ;
2007-03-01 07:51:29 +03:00
2006-03-26 20:23:47 +04:00
/* we cannot emulate this, it should not be used. */
BUG_ON ( ( mlc - > opacket & ( HIL_CTRL_APE | HIL_CTRL_IPF ) ) = = HIL_CTRL_APE ) ;
2007-03-01 07:51:29 +03:00
if ( ( mlc - > opacket & HIL_CTRL_ONLY ) = = HIL_CTRL_ONLY )
goto control_only ;
/* Should not send command/data after engaging APE */
BUG_ON ( mlc - > opacket & HIL_CTRL_APE ) ;
/* Disengaging APE this way would not be valid either since
2005-04-17 02:20:36 +04:00
* the loop must be allowed to idle .
*
2007-03-01 07:51:29 +03:00
* So , it works out that we really never actually send control
* and data when using SDC , we just send the data .
2005-04-17 02:20:36 +04:00
*/
goto do_data ;
control_only :
priv - > trans . actidx = 0 ;
priv - > trans . idx = 1 ;
2007-03-01 07:51:29 +03:00
priv - > trans . act . semaphore = & mlc - > osem ;
2005-04-17 02:20:36 +04:00
priv - > trans . endidx = 4 ;
2007-03-01 07:51:29 +03:00
priv - > tseq [ 0 ] =
2005-04-17 02:20:36 +04:00
HP_SDC_ACT_PRECMD | HP_SDC_ACT_DATAOUT | HP_SDC_ACT_SEMAPHORE ;
priv - > tseq [ 1 ] = HP_SDC_CMD_SET_LPC ;
priv - > tseq [ 2 ] = 1 ;
2007-03-01 07:51:29 +03:00
/* priv->tseq[3] = (mlc->ddc + 1) | HP_SDC_LPS_ACSUCC; */
2005-04-17 02:20:36 +04:00
priv - > tseq [ 3 ] = 0 ;
if ( mlc - > opacket & HIL_CTRL_APE ) {
priv - > tseq [ 3 ] | = HP_SDC_LPC_APE_IPF ;
2009-08-02 17:13:29 +04:00
BUG_ON ( down_trylock ( & mlc - > csem ) ) ;
2007-03-01 07:51:29 +03:00
}
2005-04-17 02:20:36 +04:00
enqueue :
2007-03-01 07:51:29 +03:00
hp_sdc_enqueue_transaction ( & priv - > trans ) ;
2005-04-17 02:20:36 +04:00
}
static int __init hp_sdc_mlc_init ( void )
{
hil_mlc * mlc = & hp_sdc_mlc ;
2010-11-21 00:36:49 +03:00
int err ;
2005-04-17 02:20:36 +04:00
2008-05-18 22:47:17 +04:00
# ifdef __mc68000__
if ( ! MACH_IS_HP300 )
return - ENODEV ;
# endif
2005-04-17 02:20:36 +04:00
printk ( KERN_INFO PREFIX " Registering the System Domain Controller's HIL MLC. \n " ) ;
hp_sdc_mlc_priv . emtestmode = 0 ;
hp_sdc_mlc_priv . trans . seq = hp_sdc_mlc_priv . tseq ;
2007-03-01 07:51:29 +03:00
hp_sdc_mlc_priv . trans . act . semaphore = & mlc - > osem ;
2005-04-17 02:20:36 +04:00
hp_sdc_mlc_priv . got5x = 0 ;
2007-03-01 07:51:29 +03:00
mlc - > cts = & hp_sdc_mlc_cts ;
mlc - > in = & hp_sdc_mlc_in ;
mlc - > out = & hp_sdc_mlc_out ;
mlc - > priv = & hp_sdc_mlc_priv ;
2007-03-01 07:51:19 +03:00
2010-11-21 00:36:49 +03:00
err = hil_mlc_register ( mlc ) ;
if ( err ) {
2005-04-17 02:20:36 +04:00
printk ( KERN_WARNING PREFIX " Failed to register MLC structure with hil_mlc \n " ) ;
2010-11-21 00:36:49 +03:00
return err ;
2005-04-17 02:20:36 +04:00
}
if ( hp_sdc_request_hil_irq ( & hp_sdc_mlc_isr ) ) {
printk ( KERN_WARNING PREFIX " Request for raw HIL ISR hook denied \n " ) ;
2010-11-21 00:36:49 +03:00
if ( hil_mlc_unregister ( mlc ) )
printk ( KERN_ERR PREFIX " Failed to unregister MLC structure with hil_mlc. \n "
" This is bad. Could cause an oops. \n " ) ;
return - EBUSY ;
2005-04-17 02:20:36 +04:00
}
2010-11-21 00:36:49 +03:00
2005-04-17 02:20:36 +04:00
return 0 ;
}
static void __exit hp_sdc_mlc_exit ( void )
{
hil_mlc * mlc = & hp_sdc_mlc ;
2007-03-01 07:51:29 +03:00
if ( hp_sdc_release_hil_irq ( & hp_sdc_mlc_isr ) )
2005-04-17 02:20:36 +04:00
printk ( KERN_ERR PREFIX " Failed to release the raw HIL ISR hook. \n "
" This is bad. Could cause an oops. \n " ) ;
2007-03-01 07:51:29 +03:00
if ( hil_mlc_unregister ( mlc ) )
2005-04-17 02:20:36 +04:00
printk ( KERN_ERR PREFIX " Failed to unregister MLC structure with hil_mlc. \n "
" This is bad. Could cause an oops. \n " ) ;
}
module_init ( hp_sdc_mlc_init ) ;
module_exit ( hp_sdc_mlc_exit ) ;