Add enable/disable and power management hooks for serial ports.

Port states : always on / on when open (default) / always off
This commit is contained in:
jdc 2000-03-14 21:18:27 +00:00
parent db94f2dea3
commit fa4417ef0c
2 changed files with 91 additions and 17 deletions

View File

@ -1,7 +1,7 @@
/* $NetBSD: auxiotwo.c,v 1.1 2000/02/25 18:17:24 jdc Exp $ */
/* $NetBSD: auxiotwo.c,v 1.2 2000/03/14 21:18:27 jdc Exp $ */
/*
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -48,8 +48,12 @@
#include <machine/autoconf.h>
#include <sparc/sparc/vaddrs.h>
#include <sparc/include/tctrl.h>
#include <sparc/sparc/auxiotwo.h>
#include <sparc/sparc/vaddrs.h>
static int serial_refcount;
static int serial_power;
static int auxiotwomatch __P((struct device *, struct cfdata *, void *));
@ -97,18 +101,9 @@ auxiotwoattach(parent, self, aux)
auxiotwo_reg = (volatile u_char *)bh;
auxiotwo_regval = *auxiotwo_reg;
serial_refcount = 0;
serial_power = PORT_PWR_STANDBY;
printf("\n");
/*
* This powers on the serial ports
* XXX: this should probably be in the serial attach code.
*/
auxiotwobisc(AUXIOTWO_SON, 0);
/*
* This powers them off :
* auxiotwobisc(AUXIOTWO_SOF, 1);
*/
}
unsigned int
@ -130,3 +125,72 @@ auxiotwobisc(bis, bic)
splx(s);
return (auxiotwo_regval);
}
/*
* Serial port state - called from zs_enable()/zs_disable()
*/
void
auxiotwoserialendis (state)
int state;
{
switch (state) {
case ZS_ENABLE:
/* Power on the serial ports? */
serial_refcount++;
if (serial_refcount == 1 && serial_power == PORT_PWR_STANDBY)
auxiotwobisc(AUXIOTWO_SON, 0);
break;
case ZS_DISABLE:
/* Power off the serial ports? */
serial_refcount--;
if (!serial_refcount && serial_power == PORT_PWR_STANDBY)
auxiotwobisc(AUXIOTWO_SOF, 1);
break;
}
}
/*
* Set power management - called by tctrl
*/
void
auxiotwoserialsetapm (state)
int state;
{
switch (state) {
case PORT_PWR_ON:
/* Change to: power always on */
if (serial_power == PORT_PWR_OFF ||
(serial_power == PORT_PWR_STANDBY && !serial_refcount))
auxiotwobisc(AUXIOTWO_SON, 0);
serial_power = PORT_PWR_ON;
break;
case PORT_PWR_STANDBY:
/* Change to: power on if open */
if (serial_power == PORT_PWR_ON && !serial_refcount)
auxiotwobisc(AUXIOTWO_SOF, 1);
if (serial_power == PORT_PWR_OFF && serial_refcount)
auxiotwobisc(AUXIOTWO_SON, 0);
serial_power = PORT_PWR_STANDBY;
break;
case PORT_PWR_OFF:
/* Change to: power always off */
if (serial_power == PORT_PWR_ON ||
(serial_power == PORT_PWR_STANDBY && serial_refcount))
auxiotwobisc(AUXIOTWO_SOF, 1);
serial_power = PORT_PWR_OFF;
break;
}
}
/*
* Get power management - called by tctrl
*/
int
auxiotwoserialgetapm ()
{
return (serial_power);
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: auxiotwo.h,v 1.1 2000/02/25 18:17:24 jdc Exp $ */
/* $NetBSD: auxiotwo.h,v 1.2 2000/03/14 21:18:27 jdc Exp $ */
/*
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Julian Coleman, Waldi Ravens and Leo Weppelman.
* by Julian Coleman.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -54,8 +54,18 @@
#define AUXIOTWO_CPF 0x02 /* Clear Power Fail Detect */
#define AUXIOTWO_SON 0x01 /* Serial ports on (when cleared) */
/*
* Serial port open/close
*/
#define ZS_ENABLE 0
#define ZS_DISABLE 1
#ifndef _LOCORE
volatile u_char *auxiotwo_reg;
u_char auxiotwo_regval;
unsigned int auxiotwobisc __P((int, int));
void auxiotwoserialendis __P((int));
void auxiotwoserialsetapm __P((int));
int auxiotwoserialgetapm __P((void));
#endif