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
53611c136Smb158278 * Common Development and Distribution License (the "License").
63611c136Smb158278 * 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.
23f47a9c50Smathue * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #include <sys/stat.h> /* ddi_create_minor_node S_IFCHR */
277c478bd9Sstevel@tonic-gate #include <sys/modctl.h> /* for modldrv */
287c478bd9Sstevel@tonic-gate #include <sys/open.h> /* for open params. */
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
317c478bd9Sstevel@tonic-gate #include <sys/conf.h> /* req. by dev_ops flags MTSAFE etc. */
327c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
337c478bd9Sstevel@tonic-gate #include <sys/file.h>
347c478bd9Sstevel@tonic-gate #include <sys/note.h>
357c478bd9Sstevel@tonic-gate #include <sys/i2c/clients/i2c_client.h>
367c478bd9Sstevel@tonic-gate #include <sys/i2c/clients/ssc050.h>
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate #define SSC050_NUM_PORTS 5
397c478bd9Sstevel@tonic-gate #define SSC050_DATADIRECTION_REG(port) (0x10 | (port))
407c478bd9Sstevel@tonic-gate #define SSC050_COUNT_REG(port) (0x32 | ((port) << 2))
417c478bd9Sstevel@tonic-gate #define SSC050_GP_REG(port) (port)
427c478bd9Sstevel@tonic-gate #define SSC050_BIT_REG(port, bit) (SSC050_PORT_BIT_REG(port) | (bit))
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate #define SSC050_FAN_SPEED(div, count) (1200000 / ((count) * (1<<(div))))
457c478bd9Sstevel@tonic-gate #define SSC050_FAN_CONTROL_ENABLE 0x80
467c478bd9Sstevel@tonic-gate #define SSC050_FAN_CONTROL_DIVISOR 0x03
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate #define SSC050_DATADIRECTION_BIT 0x02
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate struct ssc050_unit {
517c478bd9Sstevel@tonic-gate kmutex_t mutex;
527c478bd9Sstevel@tonic-gate int oflag;
537c478bd9Sstevel@tonic-gate i2c_client_hdl_t hdl;
547c478bd9Sstevel@tonic-gate char name[12];
557c478bd9Sstevel@tonic-gate };
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate #ifdef DEBUG
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate static int ssc050debug = 0;
607c478bd9Sstevel@tonic-gate #define D1CMN_ERR(ARGS) if (ssc050debug & 0x01) cmn_err ARGS;
617c478bd9Sstevel@tonic-gate #define D2CMN_ERR(ARGS) if (ssc050debug & 0x02) cmn_err ARGS;
627c478bd9Sstevel@tonic-gate #define D3CMN_ERR(ARGS) if (ssc050debug & 0x04) cmn_err ARGS;
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate #else
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate #define D1CMN_ERR(ARGS)
677c478bd9Sstevel@tonic-gate #define D2CMN_ERR(ARGS)
687c478bd9Sstevel@tonic-gate #define D3CMN_ERR(ARGS)
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate #endif
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate static void *ssc050soft_statep;
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate static int ssc050_do_attach(dev_info_t *);
757c478bd9Sstevel@tonic-gate static int ssc050_do_detach(dev_info_t *);
767c478bd9Sstevel@tonic-gate static int ssc050_set(struct ssc050_unit *, int, uchar_t);
777c478bd9Sstevel@tonic-gate static int ssc050_get(struct ssc050_unit *, int, uchar_t *, int);
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate * cb ops
817c478bd9Sstevel@tonic-gate */
827c478bd9Sstevel@tonic-gate static int ssc050_open(dev_t *, int, int, cred_t *);
837c478bd9Sstevel@tonic-gate static int ssc050_close(dev_t, int, int, cred_t *);
847c478bd9Sstevel@tonic-gate static int ssc050_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate static struct cb_ops ssc050_cbops = {
887c478bd9Sstevel@tonic-gate ssc050_open, /* open */
897c478bd9Sstevel@tonic-gate ssc050_close, /* close */
907c478bd9Sstevel@tonic-gate nodev, /* strategy */
917c478bd9Sstevel@tonic-gate nodev, /* print */
927c478bd9Sstevel@tonic-gate nodev, /* dump */
937c478bd9Sstevel@tonic-gate nodev, /* read */
947c478bd9Sstevel@tonic-gate nodev, /* write */
957c478bd9Sstevel@tonic-gate ssc050_ioctl, /* ioctl */
967c478bd9Sstevel@tonic-gate nodev, /* devmap */
977c478bd9Sstevel@tonic-gate nodev, /* mmap */
987c478bd9Sstevel@tonic-gate nodev, /* segmap */
997c478bd9Sstevel@tonic-gate nochpoll, /* poll */
1007c478bd9Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */
1017c478bd9Sstevel@tonic-gate NULL, /* streamtab */
1027c478bd9Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* Driver compatibility flag */
1037c478bd9Sstevel@tonic-gate CB_REV, /* rev */
1047c478bd9Sstevel@tonic-gate nodev, /* int (*cb_aread)() */
1057c478bd9Sstevel@tonic-gate nodev /* int (*cb_awrite)() */
1067c478bd9Sstevel@tonic-gate };
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate * dev ops
1107c478bd9Sstevel@tonic-gate */
1117c478bd9Sstevel@tonic-gate static int ssc050_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
1127c478bd9Sstevel@tonic-gate void **result);
1137c478bd9Sstevel@tonic-gate static int ssc050_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
1147c478bd9Sstevel@tonic-gate static int ssc050_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate static struct dev_ops ssc050_ops = {
1177c478bd9Sstevel@tonic-gate DEVO_REV,
1187c478bd9Sstevel@tonic-gate 0,
1197c478bd9Sstevel@tonic-gate ssc050_info,
1207c478bd9Sstevel@tonic-gate nulldev,
1217c478bd9Sstevel@tonic-gate nulldev,
1227c478bd9Sstevel@tonic-gate ssc050_attach,
1237c478bd9Sstevel@tonic-gate ssc050_detach,
1247c478bd9Sstevel@tonic-gate nodev,
1257c478bd9Sstevel@tonic-gate &ssc050_cbops,
12619397407SSherry Moore NULL,
12719397407SSherry Moore NULL,
12819397407SSherry Moore ddi_quiesce_not_needed, /* quiesce */
1297c478bd9Sstevel@tonic-gate };
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate extern struct mod_ops mod_driverops;
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate static struct modldrv ssc050_modldrv = {
1347c478bd9Sstevel@tonic-gate &mod_driverops, /* type of module - driver */
135*88294e09SRichard Bean "SSC050 i2c device driver",
1367c478bd9Sstevel@tonic-gate &ssc050_ops
1377c478bd9Sstevel@tonic-gate };
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate static struct modlinkage ssc050_modlinkage = {
1407c478bd9Sstevel@tonic-gate MODREV_1,
1417c478bd9Sstevel@tonic-gate &ssc050_modldrv,
1427c478bd9Sstevel@tonic-gate 0
1437c478bd9Sstevel@tonic-gate };
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate int
_init(void)1477c478bd9Sstevel@tonic-gate _init(void)
1487c478bd9Sstevel@tonic-gate {
1497c478bd9Sstevel@tonic-gate int error;
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate error = mod_install(&ssc050_modlinkage);
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate if (!error)
1547c478bd9Sstevel@tonic-gate (void) ddi_soft_state_init(&ssc050soft_statep,
1557c478bd9Sstevel@tonic-gate sizeof (struct ssc050_unit), 1);
1567c478bd9Sstevel@tonic-gate return (error);
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate int
_fini(void)1607c478bd9Sstevel@tonic-gate _fini(void)
1617c478bd9Sstevel@tonic-gate {
1627c478bd9Sstevel@tonic-gate int error;
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate error = mod_remove(&ssc050_modlinkage);
1657c478bd9Sstevel@tonic-gate if (!error)
1667c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&ssc050soft_statep);
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate return (error);
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1727c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1737c478bd9Sstevel@tonic-gate {
1747c478bd9Sstevel@tonic-gate return (mod_info(&ssc050_modlinkage, modinfop));
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate static int
ssc050_open(dev_t * devp,int flags,int otyp,cred_t * credp)1787c478bd9Sstevel@tonic-gate ssc050_open(dev_t *devp, int flags, int otyp, cred_t *credp)
1797c478bd9Sstevel@tonic-gate {
1807c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(credp))
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate struct ssc050_unit *unitp;
1837c478bd9Sstevel@tonic-gate int instance;
1847c478bd9Sstevel@tonic-gate int error = 0;
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate instance = MINOR_TO_INST(getminor(*devp));
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate if (instance < 0) {
1897c478bd9Sstevel@tonic-gate return (ENXIO);
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate unitp = (struct ssc050_unit *)
1937c478bd9Sstevel@tonic-gate ddi_get_soft_state(ssc050soft_statep, instance);
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate if (unitp == NULL) {
1967c478bd9Sstevel@tonic-gate return (ENXIO);
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) {
2007c478bd9Sstevel@tonic-gate return (EINVAL);
2017c478bd9Sstevel@tonic-gate }
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate mutex_enter(&unitp->mutex);
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate if (flags & FEXCL) {
2067c478bd9Sstevel@tonic-gate if (unitp->oflag != 0) {
2077c478bd9Sstevel@tonic-gate error = EBUSY;
2087c478bd9Sstevel@tonic-gate } else {
2097c478bd9Sstevel@tonic-gate unitp->oflag = FEXCL;
2107c478bd9Sstevel@tonic-gate }
2117c478bd9Sstevel@tonic-gate } else {
2127c478bd9Sstevel@tonic-gate if (unitp->oflag == FEXCL) {
2137c478bd9Sstevel@tonic-gate error = EBUSY;
2147c478bd9Sstevel@tonic-gate } else {
2157c478bd9Sstevel@tonic-gate unitp->oflag = FOPEN;
2167c478bd9Sstevel@tonic-gate }
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate mutex_exit(&unitp->mutex);
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate return (error);
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate static int
ssc050_close(dev_t dev,int flags,int otyp,cred_t * credp)2257c478bd9Sstevel@tonic-gate ssc050_close(dev_t dev, int flags, int otyp, cred_t *credp)
2267c478bd9Sstevel@tonic-gate {
2277c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(flags, otyp, credp))
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate struct ssc050_unit *unitp;
2307c478bd9Sstevel@tonic-gate int instance;
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate instance = MINOR_TO_INST(getminor(dev));
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate if (instance < 0) {
2357c478bd9Sstevel@tonic-gate return (ENXIO);
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate unitp = (struct ssc050_unit *)
2397c478bd9Sstevel@tonic-gate ddi_get_soft_state(ssc050soft_statep, instance);
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate if (unitp == NULL) {
2427c478bd9Sstevel@tonic-gate return (ENXIO);
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate mutex_enter(&unitp->mutex);
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate unitp->oflag = 0;
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate mutex_exit(&unitp->mutex);
2507c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
2517c478bd9Sstevel@tonic-gate }
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate static int
ssc050_get(struct ssc050_unit * unitp,int reg,uchar_t * byte,int flags)2547c478bd9Sstevel@tonic-gate ssc050_get(struct ssc050_unit *unitp, int reg, uchar_t *byte, int flags)
2557c478bd9Sstevel@tonic-gate {
2567c478bd9Sstevel@tonic-gate i2c_transfer_t *i2c_tran_pointer;
2577c478bd9Sstevel@tonic-gate int err;
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gate (void) i2c_transfer_alloc(unitp->hdl, &i2c_tran_pointer,
2607c478bd9Sstevel@tonic-gate 1, 1, flags);
2617c478bd9Sstevel@tonic-gate if (i2c_tran_pointer == NULL) {
2627c478bd9Sstevel@tonic-gate return (ENOMEM);
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate i2c_tran_pointer->i2c_flags = I2C_WR_RD;
2667c478bd9Sstevel@tonic-gate i2c_tran_pointer->i2c_wbuf[0] = (uchar_t)reg;
2677c478bd9Sstevel@tonic-gate err = i2c_transfer(unitp->hdl, i2c_tran_pointer);
2687c478bd9Sstevel@tonic-gate if (err) {
2697c478bd9Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "%s: ssc050_get failed reg=%x",
2707c478bd9Sstevel@tonic-gate unitp->name, reg));
2717c478bd9Sstevel@tonic-gate } else {
2727c478bd9Sstevel@tonic-gate *byte = i2c_tran_pointer->i2c_rbuf[0];
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gate i2c_transfer_free(unitp->hdl, i2c_tran_pointer);
2767c478bd9Sstevel@tonic-gate return (err);
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate static int
ssc050_set(struct ssc050_unit * unitp,int reg,uchar_t byte)2807c478bd9Sstevel@tonic-gate ssc050_set(struct ssc050_unit *unitp, int reg, uchar_t byte)
2817c478bd9Sstevel@tonic-gate {
2827c478bd9Sstevel@tonic-gate i2c_transfer_t *i2c_tran_pointer;
2837c478bd9Sstevel@tonic-gate int err;
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate (void) i2c_transfer_alloc(unitp->hdl, &i2c_tran_pointer,
2867c478bd9Sstevel@tonic-gate 2, 0, I2C_SLEEP);
2877c478bd9Sstevel@tonic-gate if (i2c_tran_pointer == NULL) {
2887c478bd9Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "%s: Failed in ssc050_set "
2897c478bd9Sstevel@tonic-gate "i2c_tran_pointer not allocated", unitp->name));
2907c478bd9Sstevel@tonic-gate return (ENOMEM);
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate i2c_tran_pointer->i2c_flags = I2C_WR;
2947c478bd9Sstevel@tonic-gate i2c_tran_pointer->i2c_wbuf[0] = (uchar_t)reg;
2957c478bd9Sstevel@tonic-gate i2c_tran_pointer->i2c_wbuf[1] = byte;
2967c478bd9Sstevel@tonic-gate D1CMN_ERR((CE_NOTE, "%s: set reg %x to %x", unitp->name, reg, byte));
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate err = i2c_transfer(unitp->hdl, i2c_tran_pointer);
2997c478bd9Sstevel@tonic-gate if (err) {
3007c478bd9Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "%s: Failed in the ssc050_set"
3017c478bd9Sstevel@tonic-gate " i2c_transfer routine", unitp->name));
3027c478bd9Sstevel@tonic-gate }
3037c478bd9Sstevel@tonic-gate i2c_transfer_free(unitp->hdl, i2c_tran_pointer);
3047c478bd9Sstevel@tonic-gate return (err);
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate static int
ssc050_ioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * credp,int * rvalp)3087c478bd9Sstevel@tonic-gate ssc050_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
3097c478bd9Sstevel@tonic-gate int *rvalp)
3107c478bd9Sstevel@tonic-gate {
3117c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(credp, rvalp))
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gate struct ssc050_unit *unitp;
3147c478bd9Sstevel@tonic-gate int err = 0;
3157c478bd9Sstevel@tonic-gate i2c_bit_t ioctl_bit;
3167c478bd9Sstevel@tonic-gate i2c_port_t ioctl_port;
3177c478bd9Sstevel@tonic-gate i2c_reg_t ioctl_reg;
3187c478bd9Sstevel@tonic-gate int port = MINOR_TO_PORT(getminor(dev));
3197c478bd9Sstevel@tonic-gate int instance = MINOR_TO_INST(getminor(dev));
3207c478bd9Sstevel@tonic-gate uchar_t reg, val8;
3217c478bd9Sstevel@tonic-gate uchar_t control;
3227c478bd9Sstevel@tonic-gate uchar_t fan_count;
3237c478bd9Sstevel@tonic-gate int divisor;
3247c478bd9Sstevel@tonic-gate int32_t fan_speed;
3257c478bd9Sstevel@tonic-gate uint8_t inverted_mask;
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate if (arg == NULL) {
3287c478bd9Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "SSC050: ioctl: arg passed in to ioctl "
3297c478bd9Sstevel@tonic-gate "= NULL"));
3307c478bd9Sstevel@tonic-gate return (EINVAL);
3317c478bd9Sstevel@tonic-gate }
3327c478bd9Sstevel@tonic-gate unitp = (struct ssc050_unit *)
3337c478bd9Sstevel@tonic-gate ddi_get_soft_state(ssc050soft_statep, instance);
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gate if (unitp == NULL) {
3367c478bd9Sstevel@tonic-gate return (ENXIO);
3377c478bd9Sstevel@tonic-gate }
3387c478bd9Sstevel@tonic-gate
3397c478bd9Sstevel@tonic-gate mutex_enter(&unitp->mutex);
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate D3CMN_ERR((CE_NOTE, "%s: ioctl: port = %d", unitp->name, port));
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate switch (cmd) {
3447c478bd9Sstevel@tonic-gate case I2C_GET_PORT:
3457c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, (caddr_t)&ioctl_port,
3467c478bd9Sstevel@tonic-gate sizeof (i2c_port_t), mode) != DDI_SUCCESS) {
3477c478bd9Sstevel@tonic-gate err = EFAULT;
3487c478bd9Sstevel@tonic-gate break;
3497c478bd9Sstevel@tonic-gate }
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate if (ioctl_port.direction == DIR_INPUT) {
3527c478bd9Sstevel@tonic-gate reg = SSC050_DATADIRECTION_REG(port);
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate err = ssc050_get(unitp, reg, &val8, I2C_SLEEP);
3557c478bd9Sstevel@tonic-gate if (err != I2C_SUCCESS) {
3567c478bd9Sstevel@tonic-gate break;
3577c478bd9Sstevel@tonic-gate }
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate if (val8 != ioctl_port.dir_mask) {
3607c478bd9Sstevel@tonic-gate D2CMN_ERR((CE_NOTE, "GET_PORT sleeping! "
3617c478bd9Sstevel@tonic-gate "wanted %x, had %x",
3627c478bd9Sstevel@tonic-gate ioctl_port.dir_mask, val8));
3637c478bd9Sstevel@tonic-gate err = ssc050_set(unitp, reg,
3647c478bd9Sstevel@tonic-gate ioctl_port.dir_mask);
3657c478bd9Sstevel@tonic-gate if (err != I2C_SUCCESS) {
3667c478bd9Sstevel@tonic-gate break;
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate delay(10);
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate err = ssc050_get(unitp, port, &val8, I2C_SLEEP);
3737c478bd9Sstevel@tonic-gate if (err != I2C_SUCCESS) {
3747c478bd9Sstevel@tonic-gate break;
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate ioctl_port.value = val8;
3777c478bd9Sstevel@tonic-gate if (ddi_copyout((caddr_t)&ioctl_port, (caddr_t)arg,
3787c478bd9Sstevel@tonic-gate sizeof (i2c_port_t), mode) != DDI_SUCCESS) {
3797c478bd9Sstevel@tonic-gate err = EFAULT;
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate break;
3827c478bd9Sstevel@tonic-gate
3837c478bd9Sstevel@tonic-gate case I2C_SET_PORT:
3847c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, (caddr_t)&ioctl_port,
3857c478bd9Sstevel@tonic-gate sizeof (i2c_port_t), mode) != DDI_SUCCESS) {
3867c478bd9Sstevel@tonic-gate err = EFAULT;
3877c478bd9Sstevel@tonic-gate break;
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate reg = SSC050_DATADIRECTION_REG(port);
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate err = ssc050_get(unitp, reg, &val8, I2C_SLEEP);
3937c478bd9Sstevel@tonic-gate if (err != I2C_SUCCESS) {
3947c478bd9Sstevel@tonic-gate break;
3957c478bd9Sstevel@tonic-gate }
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate D1CMN_ERR((CE_NOTE, "%s: ioctl: Data Direction Register "
3987c478bd9Sstevel@tonic-gate "contains %x", unitp->name, val8));
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gate inverted_mask = ioctl_port.dir_mask ^ 0xff;
4017c478bd9Sstevel@tonic-gate val8 = val8 & inverted_mask;
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate D1CMN_ERR((CE_NOTE, "%s: ioctl: Data Direction Register "
4047c478bd9Sstevel@tonic-gate "NOW contains %x", unitp->name, val8));
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate err = ssc050_set(unitp, reg, val8);
4077c478bd9Sstevel@tonic-gate if (err != I2C_SUCCESS) {
4087c478bd9Sstevel@tonic-gate break;
4097c478bd9Sstevel@tonic-gate }
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate err = ssc050_get(unitp, port, &val8, I2C_SLEEP);
4127c478bd9Sstevel@tonic-gate if (err != I2C_SUCCESS) {
4137c478bd9Sstevel@tonic-gate break;
4147c478bd9Sstevel@tonic-gate }
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate D1CMN_ERR((CE_NOTE, "%s: ioctl: GP Register "
4177c478bd9Sstevel@tonic-gate "contains %x", unitp->name, val8));
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate val8 = val8 & inverted_mask;
4207c478bd9Sstevel@tonic-gate val8 = val8 | ioctl_port.value;
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate D1CMN_ERR((CE_NOTE, "%s: ioctl: GP Register "
4237c478bd9Sstevel@tonic-gate "NOW contains %x", unitp->name, val8));
4247c478bd9Sstevel@tonic-gate
4257c478bd9Sstevel@tonic-gate err = ssc050_set(unitp, SSC050_GP_REG(port), val8);
4267c478bd9Sstevel@tonic-gate break;
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate case I2C_GET_FAN_SPEED:
4297c478bd9Sstevel@tonic-gate err = ssc050_get(unitp, SSC050_FAN_CONTROL_REG(port),
4307c478bd9Sstevel@tonic-gate &control, I2C_SLEEP);
4317c478bd9Sstevel@tonic-gate if (err != I2C_SUCCESS) {
4327c478bd9Sstevel@tonic-gate break;
4337c478bd9Sstevel@tonic-gate }
4347c478bd9Sstevel@tonic-gate
4357c478bd9Sstevel@tonic-gate D1CMN_ERR((CE_NOTE, "%s: port %d: control = %x", unitp->name,
4367c478bd9Sstevel@tonic-gate port, control));
4377c478bd9Sstevel@tonic-gate
4387c478bd9Sstevel@tonic-gate if (!(control & SSC050_FAN_CONTROL_ENABLE)) {
4397c478bd9Sstevel@tonic-gate err = EIO;
4407c478bd9Sstevel@tonic-gate break;
4417c478bd9Sstevel@tonic-gate }
4427c478bd9Sstevel@tonic-gate
4437c478bd9Sstevel@tonic-gate err = ssc050_get(unitp, SSC050_COUNT_REG(port), &fan_count,
4447c478bd9Sstevel@tonic-gate I2C_SLEEP);
4457c478bd9Sstevel@tonic-gate if (err != I2C_SUCCESS) {
4467c478bd9Sstevel@tonic-gate break;
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate
4497c478bd9Sstevel@tonic-gate if (fan_count == 0) {
4507c478bd9Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "%s: Failed in I2C_GET_FAN_SPEED "
4517c478bd9Sstevel@tonic-gate "i2c_rbuf = 0", unitp->name));
4527c478bd9Sstevel@tonic-gate err = EIO;
4537c478bd9Sstevel@tonic-gate break;
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate if (fan_count == 0xff) {
4567c478bd9Sstevel@tonic-gate fan_speed = 0;
4577c478bd9Sstevel@tonic-gate if (ddi_copyout((caddr_t)&fan_speed, (caddr_t)arg,
4587c478bd9Sstevel@tonic-gate sizeof (int32_t), mode) != DDI_SUCCESS) {
4597c478bd9Sstevel@tonic-gate err = EFAULT;
4607c478bd9Sstevel@tonic-gate break;
4617c478bd9Sstevel@tonic-gate }
4627c478bd9Sstevel@tonic-gate break;
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate
4657c478bd9Sstevel@tonic-gate divisor = control & SSC050_FAN_CONTROL_DIVISOR;
4667c478bd9Sstevel@tonic-gate fan_speed = SSC050_FAN_SPEED(divisor, fan_count);
4677c478bd9Sstevel@tonic-gate if (ddi_copyout((caddr_t)&fan_speed, (caddr_t)arg,
4687c478bd9Sstevel@tonic-gate sizeof (int32_t), mode) != DDI_SUCCESS) {
4697c478bd9Sstevel@tonic-gate err = EFAULT;
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate break;
4727c478bd9Sstevel@tonic-gate
4737c478bd9Sstevel@tonic-gate case I2C_GET_BIT:
4747c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, (caddr_t)&ioctl_bit,
4757c478bd9Sstevel@tonic-gate sizeof (i2c_bit_t), mode) != DDI_SUCCESS) {
4767c478bd9Sstevel@tonic-gate err = EFAULT;
4777c478bd9Sstevel@tonic-gate break;
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate
480f47a9c50Smathue if (ioctl_bit.bit_num > 7) {
4817c478bd9Sstevel@tonic-gate err = EINVAL;
4827c478bd9Sstevel@tonic-gate break;
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate
4857c478bd9Sstevel@tonic-gate reg = (uchar_t)SSC050_BIT_REG(port, ioctl_bit.bit_num);
4867c478bd9Sstevel@tonic-gate D3CMN_ERR((CE_NOTE, "%s: reg = %x", unitp->name, reg));
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate if (ioctl_bit.direction == DIR_INPUT) {
4897c478bd9Sstevel@tonic-gate err = ssc050_get(unitp, reg, &val8, I2C_SLEEP);
4907c478bd9Sstevel@tonic-gate if (err != I2C_SUCCESS) {
4917c478bd9Sstevel@tonic-gate break;
4927c478bd9Sstevel@tonic-gate }
4937c478bd9Sstevel@tonic-gate
4947c478bd9Sstevel@tonic-gate if (!(val8 & SSC050_DATADIRECTION_BIT)) {
4957c478bd9Sstevel@tonic-gate D2CMN_ERR((CE_NOTE, "GET_PORT sleeping! "
4967c478bd9Sstevel@tonic-gate "wanted %x, had %x",
4977c478bd9Sstevel@tonic-gate val8 | SSC050_DATADIRECTION_BIT,
4987c478bd9Sstevel@tonic-gate val8));
4997c478bd9Sstevel@tonic-gate err = ssc050_set(unitp, reg,
5007c478bd9Sstevel@tonic-gate val8 | SSC050_DATADIRECTION_BIT);
5017c478bd9Sstevel@tonic-gate if (err != I2C_SUCCESS) {
5027c478bd9Sstevel@tonic-gate break;
5037c478bd9Sstevel@tonic-gate }
5047c478bd9Sstevel@tonic-gate delay(10);
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate }
5077c478bd9Sstevel@tonic-gate
5087c478bd9Sstevel@tonic-gate err = ssc050_get(unitp, reg, &val8, I2C_SLEEP);
5097c478bd9Sstevel@tonic-gate if (err != I2C_SUCCESS) {
5107c478bd9Sstevel@tonic-gate break;
5117c478bd9Sstevel@tonic-gate }
5127c478bd9Sstevel@tonic-gate D3CMN_ERR((CE_NOTE, "byte back from device = %x", val8));
5137c478bd9Sstevel@tonic-gate val8 = val8 & 0x01;
5147c478bd9Sstevel@tonic-gate ioctl_bit.bit_value = (boolean_t)val8;
5157c478bd9Sstevel@tonic-gate if (ddi_copyout((caddr_t)&ioctl_bit, (caddr_t)arg,
5167c478bd9Sstevel@tonic-gate sizeof (i2c_bit_t), mode) != DDI_SUCCESS) {
5177c478bd9Sstevel@tonic-gate err = EFAULT;
5187c478bd9Sstevel@tonic-gate }
5197c478bd9Sstevel@tonic-gate break;
5207c478bd9Sstevel@tonic-gate
5217c478bd9Sstevel@tonic-gate case I2C_SET_BIT:
5227c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, (caddr_t)&ioctl_bit,
5237c478bd9Sstevel@tonic-gate sizeof (i2c_bit_t), mode) != DDI_SUCCESS) {
5247c478bd9Sstevel@tonic-gate err = EFAULT;
5257c478bd9Sstevel@tonic-gate break;
5267c478bd9Sstevel@tonic-gate }
5277c478bd9Sstevel@tonic-gate
528f47a9c50Smathue if (ioctl_bit.bit_num > 7) {
5297c478bd9Sstevel@tonic-gate err = EINVAL;
5307c478bd9Sstevel@tonic-gate break;
5317c478bd9Sstevel@tonic-gate }
5327c478bd9Sstevel@tonic-gate
5337c478bd9Sstevel@tonic-gate reg = (uchar_t)SSC050_BIT_REG(port, ioctl_bit.bit_num);
5347c478bd9Sstevel@tonic-gate D3CMN_ERR((CE_NOTE, "%s: reg = %x", unitp->name, reg));
5357c478bd9Sstevel@tonic-gate
5367c478bd9Sstevel@tonic-gate val8 = (uchar_t)ioctl_bit.bit_value;
5377c478bd9Sstevel@tonic-gate err = ssc050_set(unitp, reg, val8);
5387c478bd9Sstevel@tonic-gate break;
5397c478bd9Sstevel@tonic-gate
5407c478bd9Sstevel@tonic-gate case I2C_GET_REG:
5417c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, (caddr_t)&ioctl_reg,
5427c478bd9Sstevel@tonic-gate sizeof (i2c_reg_t), mode) != DDI_SUCCESS) {
5437c478bd9Sstevel@tonic-gate err = EFAULT;
5447c478bd9Sstevel@tonic-gate break;
5457c478bd9Sstevel@tonic-gate }
5467c478bd9Sstevel@tonic-gate err = ssc050_get(unitp, ioctl_reg.reg_num, &val8,
5477c478bd9Sstevel@tonic-gate I2C_SLEEP);
5487c478bd9Sstevel@tonic-gate if (err != I2C_SUCCESS) {
5497c478bd9Sstevel@tonic-gate break;
5507c478bd9Sstevel@tonic-gate }
5517c478bd9Sstevel@tonic-gate
5527c478bd9Sstevel@tonic-gate ioctl_reg.reg_value = val8;
5537c478bd9Sstevel@tonic-gate if (ddi_copyout((caddr_t)&ioctl_reg, (caddr_t)arg,
5547c478bd9Sstevel@tonic-gate sizeof (i2c_reg_t), mode) != DDI_SUCCESS) {
5557c478bd9Sstevel@tonic-gate err = EFAULT;
5567c478bd9Sstevel@tonic-gate }
5577c478bd9Sstevel@tonic-gate break;
5587c478bd9Sstevel@tonic-gate
5597c478bd9Sstevel@tonic-gate case I2C_SET_REG:
5607c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, (caddr_t)&ioctl_reg,
5617c478bd9Sstevel@tonic-gate sizeof (i2c_reg_t), mode) != DDI_SUCCESS) {
5627c478bd9Sstevel@tonic-gate err = EFAULT;
5637c478bd9Sstevel@tonic-gate break;
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate err = ssc050_set(unitp, ioctl_reg.reg_num,
5667c478bd9Sstevel@tonic-gate ioctl_reg.reg_value);
5677c478bd9Sstevel@tonic-gate break;
5687c478bd9Sstevel@tonic-gate
5697c478bd9Sstevel@tonic-gate default:
5707c478bd9Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "%s: Invalid IOCTL cmd: %x",
5717c478bd9Sstevel@tonic-gate unitp->name, cmd));
5727c478bd9Sstevel@tonic-gate err = EINVAL;
5737c478bd9Sstevel@tonic-gate }
5747c478bd9Sstevel@tonic-gate
5757c478bd9Sstevel@tonic-gate mutex_exit(&unitp->mutex);
5767c478bd9Sstevel@tonic-gate return (err);
5777c478bd9Sstevel@tonic-gate }
5787c478bd9Sstevel@tonic-gate
5797c478bd9Sstevel@tonic-gate /* ARGSUSED */
5807c478bd9Sstevel@tonic-gate static int
ssc050_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)5817c478bd9Sstevel@tonic-gate ssc050_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
5827c478bd9Sstevel@tonic-gate {
5837c478bd9Sstevel@tonic-gate dev_t dev;
5847c478bd9Sstevel@tonic-gate int instance;
5857c478bd9Sstevel@tonic-gate
5867c478bd9Sstevel@tonic-gate if (infocmd == DDI_INFO_DEVT2INSTANCE) {
5877c478bd9Sstevel@tonic-gate dev = (dev_t)arg;
5887c478bd9Sstevel@tonic-gate instance = MINOR_TO_INST(getminor(dev));
5897c478bd9Sstevel@tonic-gate *result = (void *)(uintptr_t)instance;
5907c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
5917c478bd9Sstevel@tonic-gate }
5927c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
5937c478bd9Sstevel@tonic-gate }
5947c478bd9Sstevel@tonic-gate
5957c478bd9Sstevel@tonic-gate static int
ssc050_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)5967c478bd9Sstevel@tonic-gate ssc050_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
5977c478bd9Sstevel@tonic-gate {
5987c478bd9Sstevel@tonic-gate switch (cmd) {
5997c478bd9Sstevel@tonic-gate case DDI_ATTACH:
6007c478bd9Sstevel@tonic-gate return (ssc050_do_attach(dip));
6017c478bd9Sstevel@tonic-gate case DDI_RESUME:
6027c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
6037c478bd9Sstevel@tonic-gate default:
6047c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
6057c478bd9Sstevel@tonic-gate }
6067c478bd9Sstevel@tonic-gate }
6077c478bd9Sstevel@tonic-gate
6087c478bd9Sstevel@tonic-gate static int
ssc050_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)6097c478bd9Sstevel@tonic-gate ssc050_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
6107c478bd9Sstevel@tonic-gate {
6117c478bd9Sstevel@tonic-gate switch (cmd) {
6127c478bd9Sstevel@tonic-gate case DDI_DETACH:
6137c478bd9Sstevel@tonic-gate return (ssc050_do_detach(dip));
6147c478bd9Sstevel@tonic-gate
6157c478bd9Sstevel@tonic-gate case DDI_SUSPEND:
6167c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
6177c478bd9Sstevel@tonic-gate
6187c478bd9Sstevel@tonic-gate default:
6197c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
6207c478bd9Sstevel@tonic-gate }
6217c478bd9Sstevel@tonic-gate }
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate static int
ssc050_do_attach(dev_info_t * dip)6247c478bd9Sstevel@tonic-gate ssc050_do_attach(dev_info_t *dip)
6257c478bd9Sstevel@tonic-gate {
6267c478bd9Sstevel@tonic-gate struct ssc050_unit *unitp;
6277c478bd9Sstevel@tonic-gate int instance;
6287c478bd9Sstevel@tonic-gate char name[MAXNAMELEN];
6297c478bd9Sstevel@tonic-gate minor_t minor_number;
6307c478bd9Sstevel@tonic-gate int i;
6317c478bd9Sstevel@tonic-gate
6327c478bd9Sstevel@tonic-gate instance = ddi_get_instance(dip);
6337c478bd9Sstevel@tonic-gate
6347c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(ssc050soft_statep, instance) != 0) {
6357c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
6367c478bd9Sstevel@tonic-gate }
6377c478bd9Sstevel@tonic-gate
6387c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ssc050soft_statep, instance);
6397c478bd9Sstevel@tonic-gate
6407c478bd9Sstevel@tonic-gate (void) snprintf(unitp->name, sizeof (unitp->name),
6417c478bd9Sstevel@tonic-gate "%s%d", ddi_node_name(dip), instance);
6427c478bd9Sstevel@tonic-gate
6437c478bd9Sstevel@tonic-gate for (i = 0; i < SSC050_NUM_PORTS; i++) {
6447c478bd9Sstevel@tonic-gate (void) sprintf(name, "port_%d", i);
6457c478bd9Sstevel@tonic-gate
6467c478bd9Sstevel@tonic-gate minor_number = INST_TO_MINOR(instance) |
6477c478bd9Sstevel@tonic-gate PORT_TO_MINOR(I2C_PORT(i));
6487c478bd9Sstevel@tonic-gate
6497c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, name, S_IFCHR, minor_number,
6507c478bd9Sstevel@tonic-gate "ddi_i2c:ioexp", NULL) == DDI_FAILURE) {
6517c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s: failed to create node for %s",
6527c478bd9Sstevel@tonic-gate unitp->name, name);
6537c478bd9Sstevel@tonic-gate ddi_soft_state_free(ssc050soft_statep, instance);
6547c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
6557c478bd9Sstevel@tonic-gate }
6567c478bd9Sstevel@tonic-gate }
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate if (i2c_client_register(dip, &unitp->hdl) != I2C_SUCCESS) {
6597c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL);
6607c478bd9Sstevel@tonic-gate ddi_soft_state_free(ssc050soft_statep, instance);
6617c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
6627c478bd9Sstevel@tonic-gate }
6637c478bd9Sstevel@tonic-gate
6647c478bd9Sstevel@tonic-gate mutex_init(&unitp->mutex, NULL, MUTEX_DRIVER, NULL);
6657c478bd9Sstevel@tonic-gate
6667c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
6677c478bd9Sstevel@tonic-gate }
6687c478bd9Sstevel@tonic-gate
6697c478bd9Sstevel@tonic-gate static int
ssc050_do_detach(dev_info_t * dip)6707c478bd9Sstevel@tonic-gate ssc050_do_detach(dev_info_t *dip)
6717c478bd9Sstevel@tonic-gate {
6727c478bd9Sstevel@tonic-gate struct ssc050_unit *unitp;
6737c478bd9Sstevel@tonic-gate int instance;
6747c478bd9Sstevel@tonic-gate
6757c478bd9Sstevel@tonic-gate instance = ddi_get_instance(dip);
6767c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ssc050soft_statep, instance);
6777c478bd9Sstevel@tonic-gate i2c_client_unregister(unitp->hdl);
6787c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL);
6797c478bd9Sstevel@tonic-gate mutex_destroy(&unitp->mutex);
6807c478bd9Sstevel@tonic-gate ddi_soft_state_free(ssc050soft_statep, instance);
6817c478bd9Sstevel@tonic-gate
6827c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
6837c478bd9Sstevel@tonic-gate }
6847c478bd9Sstevel@tonic-gate
6857c478bd9Sstevel@tonic-gate int
ssc050_get_port_bit(dev_info_t * dip,int port,int bit,uchar_t * rval,int flags)6867c478bd9Sstevel@tonic-gate ssc050_get_port_bit(dev_info_t *dip, int port, int bit, uchar_t *rval,
6877c478bd9Sstevel@tonic-gate int flags)
6887c478bd9Sstevel@tonic-gate {
6897c478bd9Sstevel@tonic-gate struct ssc050_unit *unitp;
6907c478bd9Sstevel@tonic-gate int instance;
6917c478bd9Sstevel@tonic-gate int reg = (uchar_t)SSC050_BIT_REG(port, bit);
6927c478bd9Sstevel@tonic-gate
6937c478bd9Sstevel@tonic-gate if (rval == NULL || dip == NULL)
6947c478bd9Sstevel@tonic-gate return (EINVAL);
6957c478bd9Sstevel@tonic-gate
6967c478bd9Sstevel@tonic-gate instance = ddi_get_instance(dip);
6977c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ssc050soft_statep, instance);
6983611c136Smb158278 if (unitp == NULL) {
6993611c136Smb158278 return (ENXIO);
7003611c136Smb158278 }
7017c478bd9Sstevel@tonic-gate return (ssc050_get(unitp, reg, rval, flags));
7027c478bd9Sstevel@tonic-gate }
703