/*
* Copyright (c) 1982, 1990, 1993
* The Regents of the University of California. 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.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)ct.c 8.1 (Berkeley) 7/15/93
*/
int
ctident(int ctlr, int unit)
{
struct cs80_describe desc;
uint8_t stat, cmd[3];
char name[7];
int id, i;
id = hpibid(ctlr, unit);
if ((id & 0x200) == 0)
return -1;
for (i = 0; i < nctinfo; i++)
if (id == ctinfo[i].hwid)
break;
if (i == nctinfo)
return -1;
ct_softc[ctlr][unit].sc_punit = ctinfo[i].punit;
id = i;
/*
* Collect device description.
* Right now we only need this to differentiate 7945 from 7946.
* Note that we always issue the describe command to unit 0.
*/
cmd[0] = C_SUNIT(0);
cmd[1] = C_SVOL(0);
cmd[2] = C_DESC;
hpibsend(ctlr, unit, C_CMD, cmd, sizeof(cmd));
hpibrecv(ctlr, unit, C_EXEC, (uint8_t *)&desc, sizeof(desc));
hpibrecv(ctlr, unit, C_QSTAT, &stat, sizeof(stat));
memset(name, 0, sizeof(name));
if (!stat) {
int n = desc.d_name;
for (i = 5; i >= 0; i--) {
name[i] = (n & 0xf) + '0';
n >>= 4;
}
}
switch (ctinfo[id].hwid) {
case CT7946ID:
if (memcmp(name, "079450", 6) == 0)
id = -1; /* not really a 7946 */
break;
default:
break;
}
return id;
}
int
ctpunit(int ctlr, int slave, int *punit)
{
struct ct_softc *rs;
if (ctlr >= NHPIB || hpibalive(ctlr) == 0)
return EADAPT;
if (slave >= NCT)
return ECTLR;
rs = &ct_softc[ctlr][slave];
if (rs->sc_alive == 0)
return ENXIO;
*punit = rs->sc_punit;
return 0;
}
int
ctopen(struct open_file *f, ...)
{
va_list ap;
int ctlr, unit, part;
struct ct_softc *rs;
int skip;
size_t resid;
va_start(ap, f);
ctlr = va_arg(ap, int);
unit = va_arg(ap, int);
part = va_arg(ap, int);
va_end(ap);