10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57656SSherry.Moore@Sun.COM * Common Development and Distribution License (the "License").
67656SSherry.Moore@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
217656SSherry.Moore@Sun.COM
220Sstevel@tonic-gate /*
237656SSherry.Moore@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
247656SSherry.Moore@Sun.COM * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #include <sys/stat.h> /* ddi_create_minor_node S_IFCHR */
280Sstevel@tonic-gate #include <sys/modctl.h> /* for modldrv */
290Sstevel@tonic-gate #include <sys/open.h> /* for open params. */
300Sstevel@tonic-gate #include <sys/types.h>
310Sstevel@tonic-gate #include <sys/kmem.h>
320Sstevel@tonic-gate #include <sys/sunddi.h>
330Sstevel@tonic-gate #include <sys/conf.h> /* req. by dev_ops flags MTSAFE etc. */
340Sstevel@tonic-gate #include <sys/ddi.h>
350Sstevel@tonic-gate #include <sys/file.h>
360Sstevel@tonic-gate #include <sys/note.h>
370Sstevel@tonic-gate
380Sstevel@tonic-gate #include <sys/i2c/clients/ltc1427_impl.h>
390Sstevel@tonic-gate
400Sstevel@tonic-gate static void *ltc1427soft_statep;
410Sstevel@tonic-gate
420Sstevel@tonic-gate
430Sstevel@tonic-gate static int ltc1427_do_attach(dev_info_t *);
440Sstevel@tonic-gate static int ltc1427_do_detach(dev_info_t *);
450Sstevel@tonic-gate static int ltc1427_do_resume(void);
460Sstevel@tonic-gate static int ltc1427_do_suspend(void);
470Sstevel@tonic-gate
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate * cb ops (only need ioctl)
500Sstevel@tonic-gate */
510Sstevel@tonic-gate static int ltc1427_open(dev_t *, int, int, cred_t *);
520Sstevel@tonic-gate static int ltc1427_close(dev_t, int, int, cred_t *);
530Sstevel@tonic-gate static int ltc1427_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
540Sstevel@tonic-gate
550Sstevel@tonic-gate static struct cb_ops ltc1427_cbops = {
560Sstevel@tonic-gate ltc1427_open, /* open */
570Sstevel@tonic-gate ltc1427_close, /* close */
580Sstevel@tonic-gate nodev, /* strategy */
590Sstevel@tonic-gate nodev, /* print */
600Sstevel@tonic-gate nodev, /* dump */
610Sstevel@tonic-gate nodev, /* read */
620Sstevel@tonic-gate nodev, /* write */
630Sstevel@tonic-gate ltc1427_ioctl, /* ioctl */
640Sstevel@tonic-gate nodev, /* devmap */
650Sstevel@tonic-gate nodev, /* mmap */
660Sstevel@tonic-gate nodev, /* segmap */
670Sstevel@tonic-gate nochpoll, /* poll */
680Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */
690Sstevel@tonic-gate NULL, /* streamtab */
700Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* Driver compatibility flag */
710Sstevel@tonic-gate CB_REV, /* rev */
720Sstevel@tonic-gate nodev, /* int (*cb_aread)() */
730Sstevel@tonic-gate nodev /* int (*cb_awrite)() */
740Sstevel@tonic-gate };
750Sstevel@tonic-gate
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate * dev ops
780Sstevel@tonic-gate */
790Sstevel@tonic-gate static int ltc1427_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
800Sstevel@tonic-gate static int ltc1427_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
810Sstevel@tonic-gate
820Sstevel@tonic-gate static struct dev_ops ltc1427_ops = {
830Sstevel@tonic-gate DEVO_REV,
840Sstevel@tonic-gate 0,
850Sstevel@tonic-gate ddi_getinfo_1to1,
860Sstevel@tonic-gate nulldev,
870Sstevel@tonic-gate nulldev,
880Sstevel@tonic-gate ltc1427_attach,
890Sstevel@tonic-gate ltc1427_detach,
900Sstevel@tonic-gate nodev,
910Sstevel@tonic-gate <c1427_cbops,
927656SSherry.Moore@Sun.COM NULL,
937656SSherry.Moore@Sun.COM NULL,
947656SSherry.Moore@Sun.COM ddi_quiesce_not_needed, /* quiesce */
950Sstevel@tonic-gate };
960Sstevel@tonic-gate
970Sstevel@tonic-gate extern struct mod_ops mod_driverops;
980Sstevel@tonic-gate
990Sstevel@tonic-gate static struct modldrv ltc1427_modldrv = {
1000Sstevel@tonic-gate &mod_driverops, /* type of module - driver */
101*7696SRichard.Bean@Sun.COM "LTC1427 i2c device driver",
1020Sstevel@tonic-gate <c1427_ops
1030Sstevel@tonic-gate };
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate static struct modlinkage ltc1427_modlinkage = {
1060Sstevel@tonic-gate MODREV_1,
1070Sstevel@tonic-gate <c1427_modldrv,
1080Sstevel@tonic-gate 0
1090Sstevel@tonic-gate };
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate int
_init(void)1130Sstevel@tonic-gate _init(void)
1140Sstevel@tonic-gate {
1150Sstevel@tonic-gate int error;
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate error = mod_install(<c1427_modlinkage);
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate if (!error)
1200Sstevel@tonic-gate (void) ddi_soft_state_init(<c1427soft_statep,
1217656SSherry.Moore@Sun.COM sizeof (struct ltc1427_unit), 1);
1220Sstevel@tonic-gate return (error);
1230Sstevel@tonic-gate }
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate int
_fini(void)1260Sstevel@tonic-gate _fini(void)
1270Sstevel@tonic-gate {
1280Sstevel@tonic-gate int error;
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate error = mod_remove(<c1427_modlinkage);
1310Sstevel@tonic-gate if (!error)
1320Sstevel@tonic-gate ddi_soft_state_fini(<c1427soft_statep);
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate return (error);
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1380Sstevel@tonic-gate _info(struct modinfo *modinfop)
1390Sstevel@tonic-gate {
1400Sstevel@tonic-gate return (mod_info(<c1427_modlinkage, modinfop));
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate static int
ltc1427_open(dev_t * devp,int flags,int otyp,cred_t * credp)1440Sstevel@tonic-gate ltc1427_open(dev_t *devp, int flags, int otyp, cred_t *credp)
1450Sstevel@tonic-gate {
1460Sstevel@tonic-gate _NOTE(ARGUNUSED(credp))
1470Sstevel@tonic-gate
1480Sstevel@tonic-gate struct ltc1427_unit *unitp;
1490Sstevel@tonic-gate int instance;
1500Sstevel@tonic-gate int error = 0;
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate instance = getminor(*devp);
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate if (instance < 0) {
1550Sstevel@tonic-gate return (ENXIO);
1560Sstevel@tonic-gate }
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate unitp = (struct ltc1427_unit *)
1597656SSherry.Moore@Sun.COM ddi_get_soft_state(ltc1427soft_statep, instance);
1600Sstevel@tonic-gate
1610Sstevel@tonic-gate if (unitp == NULL) {
1620Sstevel@tonic-gate return (ENXIO);
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate if (otyp != OTYP_CHR) {
1660Sstevel@tonic-gate return (EINVAL);
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate mutex_enter(&unitp->ltc1427_mutex);
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate if (flags & FEXCL) {
1720Sstevel@tonic-gate if (unitp->ltc1427_oflag != 0) {
1730Sstevel@tonic-gate error = EBUSY;
1740Sstevel@tonic-gate } else {
1750Sstevel@tonic-gate unitp->ltc1427_oflag = FEXCL;
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate } else {
1780Sstevel@tonic-gate if (unitp->ltc1427_oflag == FEXCL) {
1790Sstevel@tonic-gate error = EBUSY;
1800Sstevel@tonic-gate } else {
1810Sstevel@tonic-gate unitp->ltc1427_oflag = FOPEN;
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate }
1840Sstevel@tonic-gate
1850Sstevel@tonic-gate mutex_exit(&unitp->ltc1427_mutex);
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate return (error);
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate
1900Sstevel@tonic-gate static int
ltc1427_close(dev_t dev,int flags,int otyp,cred_t * credp)1910Sstevel@tonic-gate ltc1427_close(dev_t dev, int flags, int otyp, cred_t *credp)
1920Sstevel@tonic-gate {
1930Sstevel@tonic-gate _NOTE(ARGUNUSED(flags, otyp, credp))
1940Sstevel@tonic-gate
1950Sstevel@tonic-gate struct ltc1427_unit *unitp;
1960Sstevel@tonic-gate int instance;
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate instance = getminor(dev);
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate if (instance < 0) {
2010Sstevel@tonic-gate return (ENXIO);
2020Sstevel@tonic-gate }
2030Sstevel@tonic-gate
2040Sstevel@tonic-gate unitp = (struct ltc1427_unit *)
2057656SSherry.Moore@Sun.COM ddi_get_soft_state(ltc1427soft_statep, instance);
2060Sstevel@tonic-gate
2070Sstevel@tonic-gate if (unitp == NULL) {
2080Sstevel@tonic-gate return (ENXIO);
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate mutex_enter(&unitp->ltc1427_mutex);
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate unitp->ltc1427_oflag = 0;
2140Sstevel@tonic-gate
2150Sstevel@tonic-gate mutex_exit(&unitp->ltc1427_mutex);
2160Sstevel@tonic-gate return (DDI_SUCCESS);
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate
2190Sstevel@tonic-gate static int
ltc1427_ioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * credp,int * rvalp)2200Sstevel@tonic-gate ltc1427_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
2210Sstevel@tonic-gate cred_t *credp, int *rvalp)
2220Sstevel@tonic-gate {
2230Sstevel@tonic-gate _NOTE(ARGUNUSED(credp, rvalp))
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate struct ltc1427_unit *unitp;
2260Sstevel@tonic-gate int instance;
2270Sstevel@tonic-gate int err = 0;
2280Sstevel@tonic-gate i2c_transfer_t *i2c_tran_pointer;
2290Sstevel@tonic-gate int32_t fan_speed;
2300Sstevel@tonic-gate
2310Sstevel@tonic-gate if (arg == NULL) {
2320Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "LTC1427: ioctl: arg passed in to ioctl "
2337656SSherry.Moore@Sun.COM "= NULL\n"));
2340Sstevel@tonic-gate err = EINVAL;
2350Sstevel@tonic-gate return (err);
2360Sstevel@tonic-gate }
2370Sstevel@tonic-gate instance = getminor(dev);
2380Sstevel@tonic-gate unitp = (struct ltc1427_unit *)
2397656SSherry.Moore@Sun.COM ddi_get_soft_state(ltc1427soft_statep, instance);
2400Sstevel@tonic-gate
2410Sstevel@tonic-gate mutex_enter(&unitp->ltc1427_mutex);
2420Sstevel@tonic-gate
2430Sstevel@tonic-gate switch (cmd) {
2440Sstevel@tonic-gate case I2C_GET_OUTPUT:
2450Sstevel@tonic-gate D1CMN_ERR((CE_NOTE, "current_set_flag = %d\n",
2467656SSherry.Moore@Sun.COM unitp->current_set_flag));
2470Sstevel@tonic-gate if (unitp->current_set_flag == 0) {
2480Sstevel@tonic-gate err = EIO;
2490Sstevel@tonic-gate break;
2500Sstevel@tonic-gate } else {
2510Sstevel@tonic-gate if (ddi_copyout((caddr_t)&unitp->current_value,
2527656SSherry.Moore@Sun.COM (caddr_t)arg, sizeof (int32_t),
2537656SSherry.Moore@Sun.COM mode) != DDI_SUCCESS) {
2540Sstevel@tonic-gate D2CMN_ERR((CE_WARN,
2550Sstevel@tonic-gate "%s: Failed in I2C_GET_OUTPUT "
2560Sstevel@tonic-gate "ddi_copyout routine\n",
2577656SSherry.Moore@Sun.COM unitp->ltc1427_name));
2580Sstevel@tonic-gate err = EFAULT;
2590Sstevel@tonic-gate break;
2600Sstevel@tonic-gate }
2610Sstevel@tonic-gate }
2620Sstevel@tonic-gate break;
2630Sstevel@tonic-gate
2640Sstevel@tonic-gate case I2C_SET_OUTPUT:
2650Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, (caddr_t)&fan_speed,
2667656SSherry.Moore@Sun.COM sizeof (int32_t), mode) != DDI_SUCCESS) {
2670Sstevel@tonic-gate D2CMN_ERR((CE_WARN,
2687656SSherry.Moore@Sun.COM "%s: Failed in I2C_SET_OUTPUT "
2697656SSherry.Moore@Sun.COM "ioctl before switch\n",
2707656SSherry.Moore@Sun.COM unitp->ltc1427_name));
2710Sstevel@tonic-gate err = EFAULT;
2720Sstevel@tonic-gate break;
2730Sstevel@tonic-gate }
2740Sstevel@tonic-gate
2750Sstevel@tonic-gate (void) i2c_transfer_alloc(unitp->ltc1427_hdl,
2760Sstevel@tonic-gate &i2c_tran_pointer, 2, 0, I2C_SLEEP);
2770Sstevel@tonic-gate if (i2c_tran_pointer == NULL) {
2780Sstevel@tonic-gate D2CMN_ERR((CE_WARN,
2797656SSherry.Moore@Sun.COM "%s: Failed in I2C_SET_OUTPUT "
2807656SSherry.Moore@Sun.COM "i2c_transfer_pointer not allocated\n",
2817656SSherry.Moore@Sun.COM unitp->ltc1427_name));
2820Sstevel@tonic-gate err = ENOMEM;
2830Sstevel@tonic-gate break;
2840Sstevel@tonic-gate }
2850Sstevel@tonic-gate i2c_tran_pointer->i2c_flags = I2C_WR;
2860Sstevel@tonic-gate i2c_tran_pointer->i2c_wbuf[0] =
2870Sstevel@tonic-gate (uchar_t)((fan_speed >> 8) & 0x03);
2880Sstevel@tonic-gate i2c_tran_pointer->i2c_wbuf[1] =
2890Sstevel@tonic-gate (uchar_t)((fan_speed) & 0x000000ff);
2900Sstevel@tonic-gate
2910Sstevel@tonic-gate err = i2c_transfer(unitp->ltc1427_hdl, i2c_tran_pointer);
2920Sstevel@tonic-gate if (!err) {
2930Sstevel@tonic-gate unitp->current_value = fan_speed;
2940Sstevel@tonic-gate unitp->current_set_flag = 1;
2950Sstevel@tonic-gate }
2960Sstevel@tonic-gate i2c_transfer_free(unitp->ltc1427_hdl, i2c_tran_pointer);
2970Sstevel@tonic-gate break;
2980Sstevel@tonic-gate
2990Sstevel@tonic-gate default:
3000Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "%s: Invalid IOCTL cmd: %x\n",
3017656SSherry.Moore@Sun.COM unitp->ltc1427_name, cmd));
3020Sstevel@tonic-gate err = EINVAL;
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate mutex_exit(&unitp->ltc1427_mutex);
3060Sstevel@tonic-gate return (err);
3070Sstevel@tonic-gate }
3080Sstevel@tonic-gate
3090Sstevel@tonic-gate static int
ltc1427_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)3100Sstevel@tonic-gate ltc1427_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
3110Sstevel@tonic-gate {
3120Sstevel@tonic-gate switch (cmd) {
3130Sstevel@tonic-gate case DDI_ATTACH:
3140Sstevel@tonic-gate return (ltc1427_do_attach(dip));
3150Sstevel@tonic-gate case DDI_RESUME:
3160Sstevel@tonic-gate return (ltc1427_do_resume());
3170Sstevel@tonic-gate default:
3180Sstevel@tonic-gate return (DDI_FAILURE);
3190Sstevel@tonic-gate }
3200Sstevel@tonic-gate }
3210Sstevel@tonic-gate
3220Sstevel@tonic-gate static int
ltc1427_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)3230Sstevel@tonic-gate ltc1427_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
3240Sstevel@tonic-gate {
3250Sstevel@tonic-gate switch (cmd) {
3260Sstevel@tonic-gate case DDI_DETACH:
3270Sstevel@tonic-gate return (ltc1427_do_detach(dip));
3280Sstevel@tonic-gate case DDI_SUSPEND:
3290Sstevel@tonic-gate return (ltc1427_do_suspend());
3300Sstevel@tonic-gate default:
3310Sstevel@tonic-gate return (DDI_FAILURE);
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate }
3340Sstevel@tonic-gate
3350Sstevel@tonic-gate static int
ltc1427_do_attach(dev_info_t * dip)3360Sstevel@tonic-gate ltc1427_do_attach(dev_info_t *dip)
3370Sstevel@tonic-gate {
3380Sstevel@tonic-gate struct ltc1427_unit *unitp;
3390Sstevel@tonic-gate int instance;
3400Sstevel@tonic-gate
3410Sstevel@tonic-gate instance = ddi_get_instance(dip);
3420Sstevel@tonic-gate
3430Sstevel@tonic-gate if (ddi_soft_state_zalloc(ltc1427soft_statep, instance) != 0) {
3440Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: failed to zalloc softstate\n",
3457656SSherry.Moore@Sun.COM ddi_get_name(dip), instance);
3460Sstevel@tonic-gate return (DDI_FAILURE);
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate
3490Sstevel@tonic-gate unitp = ddi_get_soft_state(ltc1427soft_statep, instance);
3500Sstevel@tonic-gate
3510Sstevel@tonic-gate if (unitp == NULL) {
3520Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: unitp not filled\n",
3537656SSherry.Moore@Sun.COM ddi_get_name(dip), instance);
3540Sstevel@tonic-gate return (ENOMEM);
3550Sstevel@tonic-gate }
3560Sstevel@tonic-gate
3570Sstevel@tonic-gate (void) snprintf(unitp->ltc1427_name, sizeof (unitp->ltc1427_name),
3587656SSherry.Moore@Sun.COM "%s%d", ddi_node_name(dip), instance);
3590Sstevel@tonic-gate
3600Sstevel@tonic-gate if (ddi_create_minor_node(dip, "ltc1427", S_IFCHR, instance,
3617656SSherry.Moore@Sun.COM "ddi_i2c:adio", NULL) == DDI_FAILURE) {
3620Sstevel@tonic-gate cmn_err(CE_WARN, "%s ddi_create_minor_node failed for "
3637656SSherry.Moore@Sun.COM "%s\n", unitp->ltc1427_name, "ltc1427");
3640Sstevel@tonic-gate ddi_soft_state_free(ltc1427soft_statep, instance);
3650Sstevel@tonic-gate
3660Sstevel@tonic-gate return (DDI_FAILURE);
3670Sstevel@tonic-gate }
3680Sstevel@tonic-gate
3690Sstevel@tonic-gate if (i2c_client_register(dip, &unitp->ltc1427_hdl) != I2C_SUCCESS) {
3700Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL);
3710Sstevel@tonic-gate ddi_soft_state_free(ltc1427soft_statep, instance);
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate return (DDI_FAILURE);
3740Sstevel@tonic-gate }
3750Sstevel@tonic-gate
3760Sstevel@tonic-gate mutex_init(&unitp->ltc1427_mutex, NULL, MUTEX_DRIVER, NULL);
3770Sstevel@tonic-gate
3780Sstevel@tonic-gate return (DDI_SUCCESS);
3790Sstevel@tonic-gate }
3800Sstevel@tonic-gate
3810Sstevel@tonic-gate static int
ltc1427_do_resume()3820Sstevel@tonic-gate ltc1427_do_resume()
3830Sstevel@tonic-gate {
3840Sstevel@tonic-gate int ret = DDI_SUCCESS;
3850Sstevel@tonic-gate
3860Sstevel@tonic-gate return (ret);
3870Sstevel@tonic-gate }
3880Sstevel@tonic-gate
3890Sstevel@tonic-gate static int
ltc1427_do_suspend()3900Sstevel@tonic-gate ltc1427_do_suspend()
3910Sstevel@tonic-gate {
3920Sstevel@tonic-gate int ret = DDI_SUCCESS;
3930Sstevel@tonic-gate
3940Sstevel@tonic-gate return (ret);
3950Sstevel@tonic-gate }
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate static int
ltc1427_do_detach(dev_info_t * dip)3980Sstevel@tonic-gate ltc1427_do_detach(dev_info_t *dip)
3990Sstevel@tonic-gate {
4000Sstevel@tonic-gate struct ltc1427_unit *unitp;
4010Sstevel@tonic-gate int instance;
4020Sstevel@tonic-gate
4030Sstevel@tonic-gate instance = ddi_get_instance(dip);
4040Sstevel@tonic-gate
4050Sstevel@tonic-gate unitp = ddi_get_soft_state(ltc1427soft_statep, instance);
4060Sstevel@tonic-gate
4070Sstevel@tonic-gate if (unitp == NULL) {
4080Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: unitp not filled\n",
4097656SSherry.Moore@Sun.COM ddi_get_name(dip), instance);
4100Sstevel@tonic-gate return (ENOMEM);
4110Sstevel@tonic-gate }
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate i2c_client_unregister(unitp->ltc1427_hdl);
4140Sstevel@tonic-gate
4150Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL);
4160Sstevel@tonic-gate
4170Sstevel@tonic-gate mutex_destroy(&unitp->ltc1427_mutex);
4180Sstevel@tonic-gate
4190Sstevel@tonic-gate ddi_soft_state_free(ltc1427soft_statep, instance);
4200Sstevel@tonic-gate
4210Sstevel@tonic-gate return (DDI_SUCCESS);
4220Sstevel@tonic-gate }
423