17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
519397407SSherry Moore  * Common Development and Distribution License (the "License").
619397407SSherry Moore  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2219397407SSherry Moore  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
2304580fdfSmathue  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/stat.h>		/* ddi_create_minor_node S_IFCHR */
297c478bd9Sstevel@tonic-gate #include <sys/modctl.h>		/* for modldrv */
307c478bd9Sstevel@tonic-gate #include <sys/open.h>		/* for open params.	 */
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
337c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
347c478bd9Sstevel@tonic-gate #include <sys/conf.h>		/* req. by dev_ops flags MTSAFE etc. */
357c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
367c478bd9Sstevel@tonic-gate #include <sys/file.h>
377c478bd9Sstevel@tonic-gate #include <sys/note.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/i2c/clients/pcf8574_impl.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate static void *pcf8574soft_statep;
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate static int pcf8574_do_attach(dev_info_t *);
447c478bd9Sstevel@tonic-gate static int pcf8574_do_detach(dev_info_t *);
457c478bd9Sstevel@tonic-gate static int pcf8574_do_resume(void);
467c478bd9Sstevel@tonic-gate static int pcf8574_do_suspend(void);
477c478bd9Sstevel@tonic-gate static int pcf8574_get(struct pcf8574_unit *, uchar_t *);
487c478bd9Sstevel@tonic-gate static int pcf8574_set(struct pcf8574_unit *, uchar_t);
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate static void littleneck_abort_seq_handler(char *msg);
517c478bd9Sstevel@tonic-gate extern void (*abort_seq_handler)();
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate static void littleneck_ks_poll(void *);
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * cb ops (only need ioctl)
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate static int pcf8574_open(dev_t *, int, int, cred_t *);
597c478bd9Sstevel@tonic-gate static int pcf8574_close(dev_t, int, int, cred_t *);
607c478bd9Sstevel@tonic-gate static int pcf8574_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate static struct cb_ops pcf8574_cbops = {
637c478bd9Sstevel@tonic-gate 	pcf8574_open,			/* open  */
647c478bd9Sstevel@tonic-gate 	pcf8574_close,			/* close */
657c478bd9Sstevel@tonic-gate 	nodev,				/* strategy */
667c478bd9Sstevel@tonic-gate 	nodev,				/* print */
677c478bd9Sstevel@tonic-gate 	nodev,				/* dump */
687c478bd9Sstevel@tonic-gate 	nodev,				/* read */
697c478bd9Sstevel@tonic-gate 	nodev,				/* write */
707c478bd9Sstevel@tonic-gate 	pcf8574_ioctl,			/* ioctl */
717c478bd9Sstevel@tonic-gate 	nodev,				/* devmap */
727c478bd9Sstevel@tonic-gate 	nodev,				/* mmap */
737c478bd9Sstevel@tonic-gate 	nodev,				/* segmap */
747c478bd9Sstevel@tonic-gate 	nochpoll,			/* poll */
757c478bd9Sstevel@tonic-gate 	ddi_prop_op,			/* cb_prop_op */
767c478bd9Sstevel@tonic-gate 	NULL,				/* streamtab */
777c478bd9Sstevel@tonic-gate 	D_NEW | D_MP | D_HOTPLUG,	/* Driver compatibility flag */
787c478bd9Sstevel@tonic-gate 	CB_REV,				/* rev */
797c478bd9Sstevel@tonic-gate 	nodev,				/* int (*cb_aread)() */
807c478bd9Sstevel@tonic-gate 	nodev				/* int (*cb_awrite)() */
817c478bd9Sstevel@tonic-gate };
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * dev ops
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate static int pcf8574_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
877c478bd9Sstevel@tonic-gate static int pcf8574_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate static struct dev_ops pcf8574_ops = {
907c478bd9Sstevel@tonic-gate 	DEVO_REV,
917c478bd9Sstevel@tonic-gate 	0,
927c478bd9Sstevel@tonic-gate 	ddi_getinfo_1to1,
937c478bd9Sstevel@tonic-gate 	nulldev,
947c478bd9Sstevel@tonic-gate 	nulldev,
957c478bd9Sstevel@tonic-gate 	pcf8574_attach,
967c478bd9Sstevel@tonic-gate 	pcf8574_detach,
977c478bd9Sstevel@tonic-gate 	nodev,
987c478bd9Sstevel@tonic-gate 	&pcf8574_cbops,
9919397407SSherry Moore 	NULL,			/* bus_ops */
10019397407SSherry Moore 	NULL,			/* power */
10119397407SSherry Moore 	ddi_quiesce_not_needed,		/* quiesce */
1027c478bd9Sstevel@tonic-gate };
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate extern struct mod_ops mod_driverops;
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate static struct modldrv pcf8574_modldrv = {
1077c478bd9Sstevel@tonic-gate 	&mod_driverops,			/* type of module - driver */
10819397407SSherry Moore 	"PCF8574 i2c device driver: v1.9",
1097c478bd9Sstevel@tonic-gate 	&pcf8574_ops
1107c478bd9Sstevel@tonic-gate };
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate static struct modlinkage pcf8574_modlinkage = {
1137c478bd9Sstevel@tonic-gate 	MODREV_1,
1147c478bd9Sstevel@tonic-gate 	&pcf8574_modldrv,
1157c478bd9Sstevel@tonic-gate 	0
1167c478bd9Sstevel@tonic-gate };
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #define	LNECK_KEY_POLL_BIT 5
1197c478bd9Sstevel@tonic-gate #define	LNECK_KEY_POLL_INTVL 10		/* 10 seconds poll interval */
1207c478bd9Sstevel@tonic-gate static timeout_id_t keypoll_timeout_id;
1217c478bd9Sstevel@tonic-gate static clock_t keypoll_timeout_hz;
1227c478bd9Sstevel@tonic-gate static boolean_t key_locked_bit;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate int
_init(void)1267c478bd9Sstevel@tonic-gate _init(void)
1277c478bd9Sstevel@tonic-gate {
1287c478bd9Sstevel@tonic-gate 	int error;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	error = mod_install(&pcf8574_modlinkage);
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	if (!error)
1337c478bd9Sstevel@tonic-gate 		(void) ddi_soft_state_init(&pcf8574soft_statep,
13419397407SSherry Moore 		    sizeof (struct pcf8574_unit), 1);
1357c478bd9Sstevel@tonic-gate 	return (error);
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate int
_fini(void)1397c478bd9Sstevel@tonic-gate _fini(void)
1407c478bd9Sstevel@tonic-gate {
1417c478bd9Sstevel@tonic-gate 	int error;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	error = mod_remove(&pcf8574_modlinkage);
1447c478bd9Sstevel@tonic-gate 	if (!error)
1457c478bd9Sstevel@tonic-gate 		ddi_soft_state_fini(&pcf8574soft_statep);
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	return (error);
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1517c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1527c478bd9Sstevel@tonic-gate {
1537c478bd9Sstevel@tonic-gate 	return (mod_info(&pcf8574_modlinkage, modinfop));
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate static int
pcf8574_open(dev_t * devp,int flags,int otyp,cred_t * credp)1577c478bd9Sstevel@tonic-gate pcf8574_open(dev_t *devp, int flags, int otyp, cred_t *credp)
1587c478bd9Sstevel@tonic-gate {
1597c478bd9Sstevel@tonic-gate 	_NOTE(ARGUNUSED(credp))
1607c478bd9Sstevel@tonic-gate 	struct pcf8574_unit *unitp;
1617c478bd9Sstevel@tonic-gate 	int instance;
1627c478bd9Sstevel@tonic-gate 	int error = 0;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	D1CMN_ERR((CE_WARN, "Opening the PCF8574 device\n"));
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	instance = getminor(*devp);
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	if (instance < 0) {
1697c478bd9Sstevel@tonic-gate 		return (ENXIO);
1707c478bd9Sstevel@tonic-gate 	}
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	unitp = (struct pcf8574_unit *)
17319397407SSherry Moore 	    ddi_get_soft_state(pcf8574soft_statep, instance);
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	if (unitp == NULL) {
1767c478bd9Sstevel@tonic-gate 		return (ENXIO);
1777c478bd9Sstevel@tonic-gate 	}
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	if (otyp != OTYP_CHR) {
1807c478bd9Sstevel@tonic-gate 		return (EINVAL);
1817c478bd9Sstevel@tonic-gate 	}
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	mutex_enter(&unitp->pcf8574_mutex);
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	if (flags & FEXCL) {
1867c478bd9Sstevel@tonic-gate 		if (unitp->pcf8574_oflag != 0) {
1877c478bd9Sstevel@tonic-gate 			error = EBUSY;
1887c478bd9Sstevel@tonic-gate 		} else {
1897c478bd9Sstevel@tonic-gate 			unitp->pcf8574_oflag = FEXCL;
1907c478bd9Sstevel@tonic-gate 		}
1917c478bd9Sstevel@tonic-gate 	} else {
1927c478bd9Sstevel@tonic-gate 		if (unitp->pcf8574_oflag == FEXCL) {
1937c478bd9Sstevel@tonic-gate 			error = EBUSY;
1947c478bd9Sstevel@tonic-gate 		} else {
1957c478bd9Sstevel@tonic-gate 			unitp->pcf8574_oflag = FOPEN;
1967c478bd9Sstevel@tonic-gate 		}
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	mutex_exit(&unitp->pcf8574_mutex);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	return (error);
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate static int
pcf8574_close(dev_t dev,int flags,int otyp,cred_t * credp)2057c478bd9Sstevel@tonic-gate pcf8574_close(dev_t dev, int flags, int otyp, cred_t *credp)
2067c478bd9Sstevel@tonic-gate {
2077c478bd9Sstevel@tonic-gate 	_NOTE(ARGUNUSED(flags, otyp, credp))
2087c478bd9Sstevel@tonic-gate 	struct pcf8574_unit *unitp;
2097c478bd9Sstevel@tonic-gate 	int instance;
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	instance = getminor(dev);
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	if (instance < 0) {
2147c478bd9Sstevel@tonic-gate 		return (ENXIO);
2157c478bd9Sstevel@tonic-gate 	}
2167c478bd9Sstevel@tonic-gate 	unitp = (struct pcf8574_unit *)
21719397407SSherry Moore 	    ddi_get_soft_state(pcf8574soft_statep, instance);
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	if (unitp == NULL) {
2207c478bd9Sstevel@tonic-gate 		return (ENXIO);
2217c478bd9Sstevel@tonic-gate 	}
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	mutex_enter(&unitp->pcf8574_mutex);
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	unitp->pcf8574_oflag = 0;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	mutex_exit(&unitp->pcf8574_mutex);
2287c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate static int
pcf8574_get(struct pcf8574_unit * unitp,uchar_t * byte)232*f23a396bSToomas Soome pcf8574_get(struct pcf8574_unit *unitp, uchar_t *byte)
233*f23a396bSToomas Soome {
2347c478bd9Sstevel@tonic-gate 	i2c_transfer_t		*i2c_tran_pointer;
2357c478bd9Sstevel@tonic-gate 	int			err = I2C_SUCCESS;
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 	D1CMN_ERR((CE_WARN, "Entered the pcf8574_get routine\n"));
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	(void) i2c_transfer_alloc(unitp->pcf8574_hdl, &i2c_tran_pointer,
240*f23a396bSToomas Soome 	    0, 1, I2C_SLEEP);
2417c478bd9Sstevel@tonic-gate 	if (i2c_tran_pointer == NULL) {
2427c478bd9Sstevel@tonic-gate 		D2CMN_ERR((CE_WARN, "%s: Failed in pcf8574_get "
243*f23a396bSToomas Soome 		    "i2c_tran_pointer not allocated\n", unitp->pcf8574_name));
2447c478bd9Sstevel@tonic-gate 		return (ENOMEM);
2457c478bd9Sstevel@tonic-gate 	}
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	i2c_tran_pointer->i2c_flags = I2C_RD;
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	err = i2c_transfer(unitp->pcf8574_hdl, i2c_tran_pointer);
2507c478bd9Sstevel@tonic-gate 	if (err) {
2517c478bd9Sstevel@tonic-gate 		D2CMN_ERR((CE_WARN, "%s: Failed in the i2c_transfer routine\n",
252*f23a396bSToomas Soome 		    unitp->pcf8574_name));
2537c478bd9Sstevel@tonic-gate 		i2c_transfer_free(unitp->pcf8574_hdl, i2c_tran_pointer);
2547c478bd9Sstevel@tonic-gate 		return (err);
2557c478bd9Sstevel@tonic-gate 	}
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	D1CMN_ERR((CE_WARN, "Back from a transfer value is %x\n",
258*f23a396bSToomas Soome 	    i2c_tran_pointer->i2c_rbuf[0]));
2597c478bd9Sstevel@tonic-gate 	*byte = i2c_tran_pointer->i2c_rbuf[0];
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	i2c_transfer_free(unitp->pcf8574_hdl, i2c_tran_pointer);
2627c478bd9Sstevel@tonic-gate 	return (err);
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate static int
pcf8574_set(struct pcf8574_unit * unitp,uchar_t byte)266*f23a396bSToomas Soome pcf8574_set(struct pcf8574_unit *unitp, uchar_t byte)
267*f23a396bSToomas Soome {
2687c478bd9Sstevel@tonic-gate 	i2c_transfer_t		*i2c_tran_pointer;
2697c478bd9Sstevel@tonic-gate 	int			err = I2C_SUCCESS;
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 	(void) i2c_transfer_alloc(unitp->pcf8574_hdl, &i2c_tran_pointer,
272*f23a396bSToomas Soome 	    1, 0, I2C_SLEEP);
2737c478bd9Sstevel@tonic-gate 	if (i2c_tran_pointer == NULL) {
2747c478bd9Sstevel@tonic-gate 		D2CMN_ERR((CE_WARN, "%s: Failed in pcf8574_set "
275*f23a396bSToomas Soome 		    "i2c_tran_pointer not allocated\n",
276*f23a396bSToomas Soome 		    unitp->pcf8574_name));
2777c478bd9Sstevel@tonic-gate 		return (ENOMEM);
2787c478bd9Sstevel@tonic-gate 	}
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	i2c_tran_pointer->i2c_flags = I2C_WR;
2817c478bd9Sstevel@tonic-gate 	i2c_tran_pointer->i2c_wbuf[0] = byte;
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	D1CMN_ERR((CE_NOTE, "%s: contains %x\n", unitp->pcf8574_name,
284*f23a396bSToomas Soome 	    i2c_tran_pointer->i2c_wbuf[0]));
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	err = i2c_transfer(unitp->pcf8574_hdl, i2c_tran_pointer);
2877c478bd9Sstevel@tonic-gate 	if (err) {
2887c478bd9Sstevel@tonic-gate 		D2CMN_ERR((CE_WARN, "%s: Failed in the pcf8574_set"
289*f23a396bSToomas Soome 		    " i2c_transfer routine\n", unitp->pcf8574_name));
2907c478bd9Sstevel@tonic-gate 		i2c_transfer_free(unitp->pcf8574_hdl, i2c_tran_pointer);
2917c478bd9Sstevel@tonic-gate 		return (err);
2927c478bd9Sstevel@tonic-gate 	}
2937c478bd9Sstevel@tonic-gate 	i2c_transfer_free(unitp->pcf8574_hdl, i2c_tran_pointer);
2947c478bd9Sstevel@tonic-gate 	return (err);
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate static int
pcf8574_ioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * credp,int * rvalp)2987c478bd9Sstevel@tonic-gate pcf8574_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
299*f23a396bSToomas Soome     cred_t *credp, int *rvalp)
3007c478bd9Sstevel@tonic-gate {
3017c478bd9Sstevel@tonic-gate 	_NOTE(ARGUNUSED(credp, rvalp))
3027c478bd9Sstevel@tonic-gate 	struct pcf8574_unit	*unitp;
3037c478bd9Sstevel@tonic-gate 	int		instance;
3047c478bd9Sstevel@tonic-gate 	int			err = 0;
3057c478bd9Sstevel@tonic-gate 	i2c_bit_t		ioctl_bit;
3067c478bd9Sstevel@tonic-gate 	i2c_port_t		ioctl_port;
3077c478bd9Sstevel@tonic-gate 	uchar_t			byte;
3087c478bd9Sstevel@tonic-gate 
309*f23a396bSToomas Soome 	if (arg == (intptr_t)NULL) {
3107c478bd9Sstevel@tonic-gate 		D2CMN_ERR((CE_WARN, "PCF8574: ioctl: arg passed in to ioctl "
31119397407SSherry Moore 		    "= NULL\n"));
3127c478bd9Sstevel@tonic-gate 		err = EINVAL;
3137c478bd9Sstevel@tonic-gate 		return (err);
3147c478bd9Sstevel@tonic-gate 	}
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	instance = getminor(dev);
3177c478bd9Sstevel@tonic-gate 	unitp = (struct pcf8574_unit *)
31819397407SSherry Moore 	    ddi_get_soft_state(pcf8574soft_statep, instance);
3197c478bd9Sstevel@tonic-gate 	if (unitp == NULL) {
3207c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "PCF8574: ioctl: unitp not filled\n");
3217c478bd9Sstevel@tonic-gate 		return (ENOMEM);
3227c478bd9Sstevel@tonic-gate 	}
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	mutex_enter(&unitp->pcf8574_mutex);
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	switch (cmd) {
3277c478bd9Sstevel@tonic-gate 	case I2C_GET_PORT:
3287c478bd9Sstevel@tonic-gate 		if (ddi_copyin((caddr_t)arg, (caddr_t)&ioctl_port,
32919397407SSherry Moore 		    sizeof (i2c_port_t), mode) != DDI_SUCCESS) {
3307c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: Failed in the I2C_GET_PORT"
33119397407SSherry Moore 			    " ddi_copyin routine\n",
33219397407SSherry Moore 			    unitp->pcf8574_name));
3337c478bd9Sstevel@tonic-gate 			err = EFAULT;
3347c478bd9Sstevel@tonic-gate 			break;
3357c478bd9Sstevel@tonic-gate 		}
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 		err = pcf8574_get(unitp, &byte);
3387c478bd9Sstevel@tonic-gate 		if (err != I2C_SUCCESS) {
3397c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: Failed in the I2C_GET_PORT"
34019397407SSherry Moore 			    " pcf8574_get routine\n",
34119397407SSherry Moore 			    unitp->pcf8574_name));
3427c478bd9Sstevel@tonic-gate 			break;
3437c478bd9Sstevel@tonic-gate 		}
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 		ioctl_port.value = byte;
3467c478bd9Sstevel@tonic-gate 		if (ddi_copyout((caddr_t)&ioctl_port, (caddr_t)arg,
34719397407SSherry Moore 		    sizeof (i2c_port_t), mode) != DDI_SUCCESS) {
3487c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: Failed in I2C_GET_PORT "
34919397407SSherry Moore 			    "ddi_copyout routine\n",
35019397407SSherry Moore 			    unitp->pcf8574_name));
3517c478bd9Sstevel@tonic-gate 			err = EFAULT;
3527c478bd9Sstevel@tonic-gate 		}
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 		D1CMN_ERR((CE_NOTE, "%s: contains %x\n", unitp->pcf8574_name,
35519397407SSherry Moore 		    byte));
3567c478bd9Sstevel@tonic-gate 		break;
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 	case I2C_SET_PORT:
3597c478bd9Sstevel@tonic-gate 		if (ddi_copyin((caddr_t)arg, (caddr_t)&ioctl_port,
36019397407SSherry Moore 		    sizeof (uint8_t), mode) != DDI_SUCCESS) {
3617c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: Failed in the I2C_SET_PORT"
36219397407SSherry Moore 			    "ddi_cpoyin routine\n",
36319397407SSherry Moore 			    unitp->pcf8574_name));
3647c478bd9Sstevel@tonic-gate 			err = EFAULT;
3657c478bd9Sstevel@tonic-gate 			break;
3667c478bd9Sstevel@tonic-gate 		}
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 		err = pcf8574_set(unitp, ioctl_port.value);
3697c478bd9Sstevel@tonic-gate 		if (err != I2C_SUCCESS) {
3707c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: Failed in the I2C_SET_PORT"
37119397407SSherry Moore 			    " pcf8574_set routine\n",
37219397407SSherry Moore 			    unitp->pcf8574_name));
3737c478bd9Sstevel@tonic-gate 			break;
3747c478bd9Sstevel@tonic-gate 		}
3757c478bd9Sstevel@tonic-gate 		break;
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 	case I2C_GET_BIT:
3787c478bd9Sstevel@tonic-gate 		if (ddi_copyin((caddr_t)arg, (caddr_t)&ioctl_bit,
37919397407SSherry Moore 		    sizeof (i2c_bit_t), mode) != DDI_SUCCESS) {
3807c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: Failed in the I2C_GET_BIT"
38119397407SSherry Moore 			    " ddi_copyin routine\n",
38219397407SSherry Moore 			    unitp->pcf8574_name));
3837c478bd9Sstevel@tonic-gate 			err = EFAULT;
3847c478bd9Sstevel@tonic-gate 			break;
3857c478bd9Sstevel@tonic-gate 		}
3867c478bd9Sstevel@tonic-gate 
38704580fdfSmathue 		if (ioctl_bit.bit_num > 7) {
3887c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: In I2C_GET_BIT bit num"
38919397407SSherry Moore 			    " was not between 0 and 7\n",
39019397407SSherry Moore 			    unitp->pcf8574_name));
3917c478bd9Sstevel@tonic-gate 			err = EIO;
3927c478bd9Sstevel@tonic-gate 			break;
3937c478bd9Sstevel@tonic-gate 		}
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 		err = pcf8574_get(unitp, &byte);
3967c478bd9Sstevel@tonic-gate 		if (err != I2C_SUCCESS) {
3977c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: Failed in the I2C_GET_BIT"
39819397407SSherry Moore 			    " pcf8574_get routine\n",
39919397407SSherry Moore 			    unitp->pcf8574_name));
4007c478bd9Sstevel@tonic-gate 			break;
4017c478bd9Sstevel@tonic-gate 		}
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 		D1CMN_ERR((CE_NOTE, "%s: byte returned from device is %x\n",
40419397407SSherry Moore 		    unitp->pcf8574_name, byte));
4057c478bd9Sstevel@tonic-gate 		ioctl_bit.bit_value = (boolean_t)PCF8574_BIT_READ_MASK(byte,
40619397407SSherry Moore 		    ioctl_bit.bit_num);
4077c478bd9Sstevel@tonic-gate 		D1CMN_ERR((CE_NOTE, "%s: byte now contains %x\n",
40819397407SSherry Moore 		    unitp->pcf8574_name, byte));
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 		if (ddi_copyout((caddr_t)&ioctl_bit, (caddr_t)arg,
41119397407SSherry Moore 		    sizeof (i2c_bit_t), mode) != DDI_SUCCESS) {
4127c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: Failed in I2C_GET_BIT"
41319397407SSherry Moore 			    " ddi_copyout routine\n",
41419397407SSherry Moore 			    unitp->pcf8574_name));
4157c478bd9Sstevel@tonic-gate 			err = EFAULT;
4167c478bd9Sstevel@tonic-gate 		}
4177c478bd9Sstevel@tonic-gate 		break;
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 	case I2C_SET_BIT:
4207c478bd9Sstevel@tonic-gate 		if (ddi_copyin((caddr_t)arg, (caddr_t)&ioctl_bit,
42119397407SSherry Moore 		    sizeof (i2c_bit_t), mode) != DDI_SUCCESS) {
4227c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: Failed in I2C_SET_BIT"
42319397407SSherry Moore 			    " ddi_copyin routine\n",
42419397407SSherry Moore 			    unitp->pcf8574_name));
4257c478bd9Sstevel@tonic-gate 			err = EFAULT;
4267c478bd9Sstevel@tonic-gate 			break;
4277c478bd9Sstevel@tonic-gate 		}
4287c478bd9Sstevel@tonic-gate 
42904580fdfSmathue 		if (ioctl_bit.bit_num > 7) {
4307c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: I2C_SET_BIT: bit_num sent"
43119397407SSherry Moore 			    " in was not between 0 and 7",
43219397407SSherry Moore 			    unitp->pcf8574_name));
4337c478bd9Sstevel@tonic-gate 			err = EIO;
4347c478bd9Sstevel@tonic-gate 			break;
4357c478bd9Sstevel@tonic-gate 		}
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 		err = pcf8574_get(unitp, &byte);
4387c478bd9Sstevel@tonic-gate 		if (err != I2C_SUCCESS) {
4397c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: Failed in the I2C_SET_BIT"
44019397407SSherry Moore 			    " pcf8574_get routine\n",
44119397407SSherry Moore 			    unitp->pcf8574_name));
4427c478bd9Sstevel@tonic-gate 			break;
4437c478bd9Sstevel@tonic-gate 		}
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 		D1CMN_ERR((CE_NOTE, "%s: byte returned from device is %x\n",
44619397407SSherry Moore 		    unitp->pcf8574_name, byte));
4477c478bd9Sstevel@tonic-gate 		byte = PCF8574_BIT_WRITE_MASK(byte, ioctl_bit.bit_num,
44819397407SSherry Moore 		    ioctl_bit.bit_value);
4497c478bd9Sstevel@tonic-gate 		D1CMN_ERR((CE_NOTE, "%s: byte after shifting is %x\n",
45019397407SSherry Moore 		    unitp->pcf8574_name, byte));
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate 		err = pcf8574_set(unitp, byte);
4537c478bd9Sstevel@tonic-gate 		if (err != I2C_SUCCESS) {
4547c478bd9Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN, "%s: Failed in the I2C_SET_BIT"
45519397407SSherry Moore 			    " pcf8574_set routine\n",
45619397407SSherry Moore 			    unitp->pcf8574_name));
4577c478bd9Sstevel@tonic-gate 			break;
4587c478bd9Sstevel@tonic-gate 		}
4597c478bd9Sstevel@tonic-gate 		break;
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	default:
4627c478bd9Sstevel@tonic-gate 		D2CMN_ERR((CE_WARN, "%s: Invalid IOCTL cmd: %x\n",
46319397407SSherry Moore 		    unitp->pcf8574_name, cmd));
4647c478bd9Sstevel@tonic-gate 		err = EINVAL;
4657c478bd9Sstevel@tonic-gate 	}
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	mutex_exit(&unitp->pcf8574_mutex);
4687c478bd9Sstevel@tonic-gate 	return (err);
4697c478bd9Sstevel@tonic-gate }
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate static int
pcf8574_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)4727c478bd9Sstevel@tonic-gate pcf8574_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
4737c478bd9Sstevel@tonic-gate {
4747c478bd9Sstevel@tonic-gate 	switch (cmd) {
4757c478bd9Sstevel@tonic-gate 	case DDI_ATTACH:
4767c478bd9Sstevel@tonic-gate 		return (pcf8574_do_attach(dip));
4777c478bd9Sstevel@tonic-gate 	case DDI_RESUME:
4787c478bd9Sstevel@tonic-gate 		return (pcf8574_do_resume());
4797c478bd9Sstevel@tonic-gate 	default:
4807c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4817c478bd9Sstevel@tonic-gate 	}
4827c478bd9Sstevel@tonic-gate }
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate static int
pcf8574_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)4857c478bd9Sstevel@tonic-gate pcf8574_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
4867c478bd9Sstevel@tonic-gate {
4877c478bd9Sstevel@tonic-gate 	switch (cmd) {
4887c478bd9Sstevel@tonic-gate 	case DDI_DETACH:
4897c478bd9Sstevel@tonic-gate 		return (pcf8574_do_detach(dip));
4907c478bd9Sstevel@tonic-gate 	case DDI_SUSPEND:
4917c478bd9Sstevel@tonic-gate 		return (pcf8574_do_suspend());
4927c478bd9Sstevel@tonic-gate 	default:
4937c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4947c478bd9Sstevel@tonic-gate 	}
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate static int
pcf8574_do_attach(dev_info_t * dip)4987c478bd9Sstevel@tonic-gate pcf8574_do_attach(dev_info_t *dip)
4997c478bd9Sstevel@tonic-gate {
5007c478bd9Sstevel@tonic-gate 	struct pcf8574_unit *unitp;
5017c478bd9Sstevel@tonic-gate 	int instance, err;
5027c478bd9Sstevel@tonic-gate 	uint_t len;
5037c478bd9Sstevel@tonic-gate 	int *regs;
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 	instance = ddi_get_instance(dip);
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 	if (ddi_soft_state_zalloc(pcf8574soft_statep, instance) != 0) {
5087c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d: failed to zalloc softstate\n",
50919397407SSherry Moore 		    ddi_get_name(dip), instance);
5107c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
5117c478bd9Sstevel@tonic-gate 	}
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 	unitp = ddi_get_soft_state(pcf8574soft_statep, instance);
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate 	if (unitp == NULL) {
5167c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d: unitp not filled\n",
51719397407SSherry Moore 		    ddi_get_name(dip), instance);
5187c478bd9Sstevel@tonic-gate 		return (ENOMEM);
5197c478bd9Sstevel@tonic-gate 	}
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 	(void) snprintf(unitp->pcf8574_name, sizeof (unitp->pcf8574_name),
52219397407SSherry Moore 	    "%s%d", ddi_node_name(dip), instance);
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate 	if (ddi_create_minor_node(dip, "pcf8574", S_IFCHR, instance,
526*f23a396bSToomas Soome 	    "ddi_i2c:ioexp", 0) == DDI_FAILURE) {
5277c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s ddi_create_minor_node failed for "
52819397407SSherry Moore 		    "%s\n", unitp->pcf8574_name, "pcf8574");
5297c478bd9Sstevel@tonic-gate 		ddi_soft_state_free(pcf8574soft_statep, instance);
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
5327c478bd9Sstevel@tonic-gate 	}
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 	if (i2c_client_register(dip, &unitp->pcf8574_hdl) != I2C_SUCCESS) {
5357c478bd9Sstevel@tonic-gate 		ddi_remove_minor_node(dip, NULL);
5367c478bd9Sstevel@tonic-gate 		ddi_soft_state_free(pcf8574soft_statep, instance);
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
5397c478bd9Sstevel@tonic-gate 	}
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate 	err = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
54219397407SSherry Moore 	    DDI_PROP_DONTPASS,
54319397407SSherry Moore 	    "reg", (int **)&regs, &len);
5447c478bd9Sstevel@tonic-gate 	if (err != DDI_PROP_SUCCESS) {
5457c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
5467c478bd9Sstevel@tonic-gate 	}
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate 	/*
5497c478bd9Sstevel@tonic-gate 	 * regs[0] contains the bus number and regs[1] contains the device
5507c478bd9Sstevel@tonic-gate 	 * address of the i2c device. 0x7c is the device address of the
5517c478bd9Sstevel@tonic-gate 	 * i2c device from which the key switch position is read.
5527c478bd9Sstevel@tonic-gate 	 */
5537c478bd9Sstevel@tonic-gate 	if (regs[0] == 0 && regs[1] == 0x7c) {
5547c478bd9Sstevel@tonic-gate 		abort_seq_handler = littleneck_abort_seq_handler;
5557c478bd9Sstevel@tonic-gate 		keypoll_timeout_hz =
55619397407SSherry Moore 		    drv_usectohz(LNECK_KEY_POLL_INTVL * MICROSEC);
5577c478bd9Sstevel@tonic-gate 		littleneck_ks_poll(unitp);
5587c478bd9Sstevel@tonic-gate 	}
5597c478bd9Sstevel@tonic-gate 
5607c478bd9Sstevel@tonic-gate 	ddi_prop_free(regs);
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 	mutex_init(&unitp->pcf8574_mutex, NULL, MUTEX_DRIVER, NULL);
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
5657c478bd9Sstevel@tonic-gate }
5667c478bd9Sstevel@tonic-gate 
5677c478bd9Sstevel@tonic-gate static int
pcf8574_do_resume()5687c478bd9Sstevel@tonic-gate pcf8574_do_resume()
5697c478bd9Sstevel@tonic-gate {
5707c478bd9Sstevel@tonic-gate 	int ret = DDI_SUCCESS;
5717c478bd9Sstevel@tonic-gate 
5727c478bd9Sstevel@tonic-gate 	return (ret);
5737c478bd9Sstevel@tonic-gate }
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate static int
pcf8574_do_suspend()5767c478bd9Sstevel@tonic-gate pcf8574_do_suspend()
5777c478bd9Sstevel@tonic-gate {
5787c478bd9Sstevel@tonic-gate 	int ret = DDI_SUCCESS;
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate 	return (ret);
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate static int
pcf8574_do_detach(dev_info_t * dip)5847c478bd9Sstevel@tonic-gate pcf8574_do_detach(dev_info_t *dip)
5857c478bd9Sstevel@tonic-gate {
5867c478bd9Sstevel@tonic-gate 	struct pcf8574_unit *unitp;
5877c478bd9Sstevel@tonic-gate 	int instance;
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate 	instance = ddi_get_instance(dip);
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 	unitp = ddi_get_soft_state(pcf8574soft_statep, instance);
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate 	if (unitp == NULL) {
5947c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d: unitp not filled\n",
59519397407SSherry Moore 		    ddi_get_name(dip), instance);
5967c478bd9Sstevel@tonic-gate 		return (ENOMEM);
5977c478bd9Sstevel@tonic-gate 	}
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate 	(void) untimeout(keypoll_timeout_id);
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate 	i2c_client_unregister(unitp->pcf8574_hdl);
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate 	ddi_remove_minor_node(dip, NULL);
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate 	mutex_destroy(&unitp->pcf8574_mutex);
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate 	ddi_soft_state_free(pcf8574soft_statep, instance);
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate }
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate static void
littleneck_ks_poll(void * arg)6147c478bd9Sstevel@tonic-gate littleneck_ks_poll(void *arg)
6157c478bd9Sstevel@tonic-gate {
6167c478bd9Sstevel@tonic-gate 	struct pcf8574_unit *unitp = (struct pcf8574_unit *)arg;
6177c478bd9Sstevel@tonic-gate 	uint8_t byte;
6187c478bd9Sstevel@tonic-gate 
6197c478bd9Sstevel@tonic-gate 	mutex_enter(&unitp->pcf8574_mutex);
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 	if (pcf8574_get(unitp, &byte) != I2C_SUCCESS) {
6227c478bd9Sstevel@tonic-gate 		D2CMN_ERR((CE_WARN, "%s: Failed in littleneck_ks_poll"
62319397407SSherry Moore 		    " pcf8574_get routine\n", unitp->pcf8574_name));
6247c478bd9Sstevel@tonic-gate 		mutex_exit(&unitp->pcf8574_mutex);
6257c478bd9Sstevel@tonic-gate 		return;
6267c478bd9Sstevel@tonic-gate 	}
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 	/*
6297c478bd9Sstevel@tonic-gate 	 * 5th bit in the byte is the key LOCKED position
6307c478bd9Sstevel@tonic-gate 	 */
6317c478bd9Sstevel@tonic-gate 	key_locked_bit = (boolean_t)PCF8574_BIT_READ_MASK(byte,
63219397407SSherry Moore 	    LNECK_KEY_POLL_BIT);
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate 	keypoll_timeout_id = (timeout(littleneck_ks_poll,
63519397407SSherry Moore 	    (caddr_t)unitp, keypoll_timeout_hz));
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate 	mutex_exit(&unitp->pcf8574_mutex);
6387c478bd9Sstevel@tonic-gate }
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate static void
littleneck_abort_seq_handler(char * msg)6417c478bd9Sstevel@tonic-gate littleneck_abort_seq_handler(char *msg)
6427c478bd9Sstevel@tonic-gate {
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate 	if (key_locked_bit == 0)
6457c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "KEY in LOCKED position, "
64619397407SSherry Moore 		    "ignoring debug enter sequence\n");
6477c478bd9Sstevel@tonic-gate 	else  {
6487c478bd9Sstevel@tonic-gate 		D1CMN_ERR((CE_CONT, "debug enter sequence \n"));
6497c478bd9Sstevel@tonic-gate 		debug_enter(msg);
6507c478bd9Sstevel@tonic-gate 	}
6517c478bd9Sstevel@tonic-gate }
652