xref: /onnv-gate/usr/src/uts/sun4u/io/i2c/clients/ltc1427.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 2000-2001 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #include <sys/stat.h>		/* ddi_create_minor_node S_IFCHR */
31*0Sstevel@tonic-gate #include <sys/modctl.h>		/* for modldrv */
32*0Sstevel@tonic-gate #include <sys/open.h>		/* for open params.	 */
33*0Sstevel@tonic-gate #include <sys/types.h>
34*0Sstevel@tonic-gate #include <sys/kmem.h>
35*0Sstevel@tonic-gate #include <sys/sunddi.h>
36*0Sstevel@tonic-gate #include <sys/conf.h>		/* req. by dev_ops flags MTSAFE etc. */
37*0Sstevel@tonic-gate #include <sys/ddi.h>
38*0Sstevel@tonic-gate #include <sys/file.h>
39*0Sstevel@tonic-gate #include <sys/note.h>
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate #include <sys/i2c/clients/ltc1427_impl.h>
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate static void *ltc1427soft_statep;
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate static int ltc1427_do_attach(dev_info_t *);
47*0Sstevel@tonic-gate static int ltc1427_do_detach(dev_info_t *);
48*0Sstevel@tonic-gate static int ltc1427_do_resume(void);
49*0Sstevel@tonic-gate static int ltc1427_do_suspend(void);
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate /*
52*0Sstevel@tonic-gate  * cb ops (only need ioctl)
53*0Sstevel@tonic-gate  */
54*0Sstevel@tonic-gate static int ltc1427_open(dev_t *, int, int, cred_t *);
55*0Sstevel@tonic-gate static int ltc1427_close(dev_t, int, int, cred_t *);
56*0Sstevel@tonic-gate static int ltc1427_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate static struct cb_ops ltc1427_cbops = {
59*0Sstevel@tonic-gate 	ltc1427_open,			/* open  */
60*0Sstevel@tonic-gate 	ltc1427_close,			/* close */
61*0Sstevel@tonic-gate 	nodev,				/* strategy */
62*0Sstevel@tonic-gate 	nodev,				/* print */
63*0Sstevel@tonic-gate 	nodev,				/* dump */
64*0Sstevel@tonic-gate 	nodev,				/* read */
65*0Sstevel@tonic-gate 	nodev,				/* write */
66*0Sstevel@tonic-gate 	ltc1427_ioctl,			/* ioctl */
67*0Sstevel@tonic-gate 	nodev,				/* devmap */
68*0Sstevel@tonic-gate 	nodev,				/* mmap */
69*0Sstevel@tonic-gate 	nodev,				/* segmap */
70*0Sstevel@tonic-gate 	nochpoll,			/* poll */
71*0Sstevel@tonic-gate 	ddi_prop_op,			/* cb_prop_op */
72*0Sstevel@tonic-gate 	NULL,				/* streamtab */
73*0Sstevel@tonic-gate 	D_NEW | D_MP | D_HOTPLUG,	/* Driver compatibility flag */
74*0Sstevel@tonic-gate 	CB_REV,				/* rev */
75*0Sstevel@tonic-gate 	nodev,				/* int (*cb_aread)() */
76*0Sstevel@tonic-gate 	nodev				/* int (*cb_awrite)() */
77*0Sstevel@tonic-gate };
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate /*
80*0Sstevel@tonic-gate  * dev ops
81*0Sstevel@tonic-gate  */
82*0Sstevel@tonic-gate static int ltc1427_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
83*0Sstevel@tonic-gate static int ltc1427_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate static struct dev_ops ltc1427_ops = {
86*0Sstevel@tonic-gate 	DEVO_REV,
87*0Sstevel@tonic-gate 	0,
88*0Sstevel@tonic-gate 	ddi_getinfo_1to1,
89*0Sstevel@tonic-gate 	nulldev,
90*0Sstevel@tonic-gate 	nulldev,
91*0Sstevel@tonic-gate 	ltc1427_attach,
92*0Sstevel@tonic-gate 	ltc1427_detach,
93*0Sstevel@tonic-gate 	nodev,
94*0Sstevel@tonic-gate 	&ltc1427_cbops,
95*0Sstevel@tonic-gate 	NULL
96*0Sstevel@tonic-gate };
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate extern struct mod_ops mod_driverops;
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate static struct modldrv ltc1427_modldrv = {
101*0Sstevel@tonic-gate 	&mod_driverops,			/* type of module - driver */
102*0Sstevel@tonic-gate 	"LTC1427 i2c device driver: v%I%",
103*0Sstevel@tonic-gate 	&ltc1427_ops
104*0Sstevel@tonic-gate };
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate static struct modlinkage ltc1427_modlinkage = {
107*0Sstevel@tonic-gate 	MODREV_1,
108*0Sstevel@tonic-gate 	&ltc1427_modldrv,
109*0Sstevel@tonic-gate 	0
110*0Sstevel@tonic-gate };
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate int
114*0Sstevel@tonic-gate _init(void)
115*0Sstevel@tonic-gate {
116*0Sstevel@tonic-gate 	int error;
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate 	error = mod_install(&ltc1427_modlinkage);
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate 	if (!error)
121*0Sstevel@tonic-gate 		(void) ddi_soft_state_init(&ltc1427soft_statep,
122*0Sstevel@tonic-gate 			sizeof (struct ltc1427_unit), 1);
123*0Sstevel@tonic-gate 	return (error);
124*0Sstevel@tonic-gate }
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate int
127*0Sstevel@tonic-gate _fini(void)
128*0Sstevel@tonic-gate {
129*0Sstevel@tonic-gate 	int error;
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate 	error = mod_remove(&ltc1427_modlinkage);
132*0Sstevel@tonic-gate 	if (!error)
133*0Sstevel@tonic-gate 		ddi_soft_state_fini(&ltc1427soft_statep);
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate 	return (error);
136*0Sstevel@tonic-gate }
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate int
139*0Sstevel@tonic-gate _info(struct modinfo *modinfop)
140*0Sstevel@tonic-gate {
141*0Sstevel@tonic-gate 	return (mod_info(&ltc1427_modlinkage, modinfop));
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate static int
145*0Sstevel@tonic-gate ltc1427_open(dev_t *devp, int flags, int otyp, cred_t *credp)
146*0Sstevel@tonic-gate {
147*0Sstevel@tonic-gate 	_NOTE(ARGUNUSED(credp))
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate 	struct ltc1427_unit *unitp;
150*0Sstevel@tonic-gate 	int instance;
151*0Sstevel@tonic-gate 	int error = 0;
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate 	instance = getminor(*devp);
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate 	if (instance < 0) {
156*0Sstevel@tonic-gate 		return (ENXIO);
157*0Sstevel@tonic-gate 	}
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate 	unitp = (struct ltc1427_unit *)
160*0Sstevel@tonic-gate 		ddi_get_soft_state(ltc1427soft_statep, instance);
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate 	if (unitp == NULL) {
163*0Sstevel@tonic-gate 		return (ENXIO);
164*0Sstevel@tonic-gate 	}
165*0Sstevel@tonic-gate 
166*0Sstevel@tonic-gate 	if (otyp != OTYP_CHR) {
167*0Sstevel@tonic-gate 		return (EINVAL);
168*0Sstevel@tonic-gate 	}
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate 	mutex_enter(&unitp->ltc1427_mutex);
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate 	if (flags & FEXCL) {
173*0Sstevel@tonic-gate 		if (unitp->ltc1427_oflag != 0) {
174*0Sstevel@tonic-gate 			error = EBUSY;
175*0Sstevel@tonic-gate 		} else {
176*0Sstevel@tonic-gate 			unitp->ltc1427_oflag = FEXCL;
177*0Sstevel@tonic-gate 		}
178*0Sstevel@tonic-gate 	} else {
179*0Sstevel@tonic-gate 		if (unitp->ltc1427_oflag == FEXCL) {
180*0Sstevel@tonic-gate 			error = EBUSY;
181*0Sstevel@tonic-gate 		} else {
182*0Sstevel@tonic-gate 			unitp->ltc1427_oflag = FOPEN;
183*0Sstevel@tonic-gate 		}
184*0Sstevel@tonic-gate 	}
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate 	mutex_exit(&unitp->ltc1427_mutex);
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate 	return (error);
189*0Sstevel@tonic-gate }
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate static int
192*0Sstevel@tonic-gate ltc1427_close(dev_t dev, int flags, int otyp, cred_t *credp)
193*0Sstevel@tonic-gate {
194*0Sstevel@tonic-gate 	_NOTE(ARGUNUSED(flags, otyp, credp))
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate 	struct ltc1427_unit *unitp;
197*0Sstevel@tonic-gate 	int instance;
198*0Sstevel@tonic-gate 
199*0Sstevel@tonic-gate 	instance = getminor(dev);
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate 	if (instance < 0) {
202*0Sstevel@tonic-gate 		return (ENXIO);
203*0Sstevel@tonic-gate 	}
204*0Sstevel@tonic-gate 
205*0Sstevel@tonic-gate 	unitp = (struct ltc1427_unit *)
206*0Sstevel@tonic-gate 		ddi_get_soft_state(ltc1427soft_statep, instance);
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate 	if (unitp == NULL) {
209*0Sstevel@tonic-gate 		return (ENXIO);
210*0Sstevel@tonic-gate 	}
211*0Sstevel@tonic-gate 
212*0Sstevel@tonic-gate 	mutex_enter(&unitp->ltc1427_mutex);
213*0Sstevel@tonic-gate 
214*0Sstevel@tonic-gate 	unitp->ltc1427_oflag = 0;
215*0Sstevel@tonic-gate 
216*0Sstevel@tonic-gate 	mutex_exit(&unitp->ltc1427_mutex);
217*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
218*0Sstevel@tonic-gate }
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate static int
221*0Sstevel@tonic-gate ltc1427_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
222*0Sstevel@tonic-gate 		cred_t *credp, int *rvalp)
223*0Sstevel@tonic-gate {
224*0Sstevel@tonic-gate 	_NOTE(ARGUNUSED(credp, rvalp))
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate 	struct ltc1427_unit 	*unitp;
227*0Sstevel@tonic-gate 	int 		instance;
228*0Sstevel@tonic-gate 	int 			err = 0;
229*0Sstevel@tonic-gate 	i2c_transfer_t		*i2c_tran_pointer;
230*0Sstevel@tonic-gate 	int32_t			fan_speed;
231*0Sstevel@tonic-gate 
232*0Sstevel@tonic-gate 	if (arg == NULL) {
233*0Sstevel@tonic-gate 		D2CMN_ERR((CE_WARN, "LTC1427: ioctl: arg passed in to ioctl "
234*0Sstevel@tonic-gate 				"= NULL\n"));
235*0Sstevel@tonic-gate 		err = EINVAL;
236*0Sstevel@tonic-gate 		return (err);
237*0Sstevel@tonic-gate 	}
238*0Sstevel@tonic-gate 	instance = getminor(dev);
239*0Sstevel@tonic-gate 	unitp = (struct ltc1427_unit *)
240*0Sstevel@tonic-gate 		ddi_get_soft_state(ltc1427soft_statep, instance);
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate 	mutex_enter(&unitp->ltc1427_mutex);
243*0Sstevel@tonic-gate 
244*0Sstevel@tonic-gate 	switch (cmd) {
245*0Sstevel@tonic-gate 	case I2C_GET_OUTPUT:
246*0Sstevel@tonic-gate 		D1CMN_ERR((CE_NOTE, "current_set_flag = %d\n",
247*0Sstevel@tonic-gate 			unitp->current_set_flag));
248*0Sstevel@tonic-gate 		if (unitp->current_set_flag == 0) {
249*0Sstevel@tonic-gate 			err = EIO;
250*0Sstevel@tonic-gate 			break;
251*0Sstevel@tonic-gate 		} else {
252*0Sstevel@tonic-gate 			if (ddi_copyout((caddr_t)&unitp->current_value,
253*0Sstevel@tonic-gate 				(caddr_t)arg, sizeof (int32_t),
254*0Sstevel@tonic-gate 				mode) != DDI_SUCCESS) {
255*0Sstevel@tonic-gate 				D2CMN_ERR((CE_WARN,
256*0Sstevel@tonic-gate 				"%s: Failed in I2C_GET_OUTPUT "
257*0Sstevel@tonic-gate 				"ddi_copyout routine\n",
258*0Sstevel@tonic-gate 					unitp->ltc1427_name));
259*0Sstevel@tonic-gate 				err = EFAULT;
260*0Sstevel@tonic-gate 				break;
261*0Sstevel@tonic-gate 			}
262*0Sstevel@tonic-gate 		}
263*0Sstevel@tonic-gate 		break;
264*0Sstevel@tonic-gate 
265*0Sstevel@tonic-gate 	case I2C_SET_OUTPUT:
266*0Sstevel@tonic-gate 		if (ddi_copyin((caddr_t)arg, (caddr_t)&fan_speed,
267*0Sstevel@tonic-gate 			sizeof (int32_t), mode) != DDI_SUCCESS) {
268*0Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN,
269*0Sstevel@tonic-gate 				"%s: Failed in I2C_SET_OUTPUT "
270*0Sstevel@tonic-gate 				"ioctl before switch\n",
271*0Sstevel@tonic-gate 					unitp->ltc1427_name));
272*0Sstevel@tonic-gate 			err = EFAULT;
273*0Sstevel@tonic-gate 			break;
274*0Sstevel@tonic-gate 		}
275*0Sstevel@tonic-gate 
276*0Sstevel@tonic-gate 		(void) i2c_transfer_alloc(unitp->ltc1427_hdl,
277*0Sstevel@tonic-gate 		    &i2c_tran_pointer, 2, 0, I2C_SLEEP);
278*0Sstevel@tonic-gate 		if (i2c_tran_pointer == NULL) {
279*0Sstevel@tonic-gate 			D2CMN_ERR((CE_WARN,
280*0Sstevel@tonic-gate 				"%s: Failed in I2C_SET_OUTPUT "
281*0Sstevel@tonic-gate 				"i2c_transfer_pointer not allocated\n",
282*0Sstevel@tonic-gate 					unitp->ltc1427_name));
283*0Sstevel@tonic-gate 			err = ENOMEM;
284*0Sstevel@tonic-gate 			break;
285*0Sstevel@tonic-gate 		}
286*0Sstevel@tonic-gate 		i2c_tran_pointer->i2c_flags = I2C_WR;
287*0Sstevel@tonic-gate 		i2c_tran_pointer->i2c_wbuf[0] =
288*0Sstevel@tonic-gate 		    (uchar_t)((fan_speed >> 8) & 0x03);
289*0Sstevel@tonic-gate 		i2c_tran_pointer->i2c_wbuf[1] =
290*0Sstevel@tonic-gate 		    (uchar_t)((fan_speed) & 0x000000ff);
291*0Sstevel@tonic-gate 
292*0Sstevel@tonic-gate 		err = i2c_transfer(unitp->ltc1427_hdl, i2c_tran_pointer);
293*0Sstevel@tonic-gate 		if (!err) {
294*0Sstevel@tonic-gate 			unitp->current_value = fan_speed;
295*0Sstevel@tonic-gate 			unitp->current_set_flag = 1;
296*0Sstevel@tonic-gate 		}
297*0Sstevel@tonic-gate 		i2c_transfer_free(unitp->ltc1427_hdl, i2c_tran_pointer);
298*0Sstevel@tonic-gate 		break;
299*0Sstevel@tonic-gate 
300*0Sstevel@tonic-gate 	default:
301*0Sstevel@tonic-gate 		D2CMN_ERR((CE_WARN, "%s: Invalid IOCTL cmd: %x\n",
302*0Sstevel@tonic-gate 			unitp->ltc1427_name, cmd));
303*0Sstevel@tonic-gate 		err = EINVAL;
304*0Sstevel@tonic-gate 	}
305*0Sstevel@tonic-gate 
306*0Sstevel@tonic-gate 	mutex_exit(&unitp->ltc1427_mutex);
307*0Sstevel@tonic-gate 	return (err);
308*0Sstevel@tonic-gate }
309*0Sstevel@tonic-gate 
310*0Sstevel@tonic-gate static int
311*0Sstevel@tonic-gate ltc1427_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
312*0Sstevel@tonic-gate {
313*0Sstevel@tonic-gate 	switch (cmd) {
314*0Sstevel@tonic-gate 	case DDI_ATTACH:
315*0Sstevel@tonic-gate 		return (ltc1427_do_attach(dip));
316*0Sstevel@tonic-gate 	case DDI_RESUME:
317*0Sstevel@tonic-gate 		return (ltc1427_do_resume());
318*0Sstevel@tonic-gate 	default:
319*0Sstevel@tonic-gate 		return (DDI_FAILURE);
320*0Sstevel@tonic-gate 	}
321*0Sstevel@tonic-gate }
322*0Sstevel@tonic-gate 
323*0Sstevel@tonic-gate static int
324*0Sstevel@tonic-gate ltc1427_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
325*0Sstevel@tonic-gate {
326*0Sstevel@tonic-gate 	switch (cmd) {
327*0Sstevel@tonic-gate 	case DDI_DETACH:
328*0Sstevel@tonic-gate 		return (ltc1427_do_detach(dip));
329*0Sstevel@tonic-gate 	case DDI_SUSPEND:
330*0Sstevel@tonic-gate 		return (ltc1427_do_suspend());
331*0Sstevel@tonic-gate 	default:
332*0Sstevel@tonic-gate 		return (DDI_FAILURE);
333*0Sstevel@tonic-gate 	}
334*0Sstevel@tonic-gate }
335*0Sstevel@tonic-gate 
336*0Sstevel@tonic-gate static int
337*0Sstevel@tonic-gate ltc1427_do_attach(dev_info_t *dip)
338*0Sstevel@tonic-gate {
339*0Sstevel@tonic-gate 	struct ltc1427_unit *unitp;
340*0Sstevel@tonic-gate 	int instance;
341*0Sstevel@tonic-gate 
342*0Sstevel@tonic-gate 	instance = ddi_get_instance(dip);
343*0Sstevel@tonic-gate 
344*0Sstevel@tonic-gate 	if (ddi_soft_state_zalloc(ltc1427soft_statep, instance) != 0) {
345*0Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d: failed to zalloc softstate\n",
346*0Sstevel@tonic-gate 			ddi_get_name(dip), instance);
347*0Sstevel@tonic-gate 		return (DDI_FAILURE);
348*0Sstevel@tonic-gate 	}
349*0Sstevel@tonic-gate 
350*0Sstevel@tonic-gate 	unitp = ddi_get_soft_state(ltc1427soft_statep, instance);
351*0Sstevel@tonic-gate 
352*0Sstevel@tonic-gate 	if (unitp == NULL) {
353*0Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d: unitp not filled\n",
354*0Sstevel@tonic-gate 			ddi_get_name(dip), instance);
355*0Sstevel@tonic-gate 		return (ENOMEM);
356*0Sstevel@tonic-gate 	}
357*0Sstevel@tonic-gate 
358*0Sstevel@tonic-gate 	(void) snprintf(unitp->ltc1427_name, sizeof (unitp->ltc1427_name),
359*0Sstevel@tonic-gate 			"%s%d", ddi_node_name(dip), instance);
360*0Sstevel@tonic-gate 
361*0Sstevel@tonic-gate 	if (ddi_create_minor_node(dip, "ltc1427", S_IFCHR, instance,
362*0Sstevel@tonic-gate 			"ddi_i2c:adio",	NULL) == DDI_FAILURE) {
363*0Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s ddi_create_minor_node failed for "
364*0Sstevel@tonic-gate 			"%s\n", unitp->ltc1427_name, "ltc1427");
365*0Sstevel@tonic-gate 		ddi_soft_state_free(ltc1427soft_statep, instance);
366*0Sstevel@tonic-gate 
367*0Sstevel@tonic-gate 		return (DDI_FAILURE);
368*0Sstevel@tonic-gate 	}
369*0Sstevel@tonic-gate 
370*0Sstevel@tonic-gate 	if (i2c_client_register(dip, &unitp->ltc1427_hdl) != I2C_SUCCESS) {
371*0Sstevel@tonic-gate 		ddi_remove_minor_node(dip, NULL);
372*0Sstevel@tonic-gate 		ddi_soft_state_free(ltc1427soft_statep, instance);
373*0Sstevel@tonic-gate 
374*0Sstevel@tonic-gate 		return (DDI_FAILURE);
375*0Sstevel@tonic-gate 	}
376*0Sstevel@tonic-gate 
377*0Sstevel@tonic-gate 	mutex_init(&unitp->ltc1427_mutex, NULL, MUTEX_DRIVER, NULL);
378*0Sstevel@tonic-gate 
379*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
380*0Sstevel@tonic-gate }
381*0Sstevel@tonic-gate 
382*0Sstevel@tonic-gate static int
383*0Sstevel@tonic-gate ltc1427_do_resume()
384*0Sstevel@tonic-gate {
385*0Sstevel@tonic-gate 	int ret = DDI_SUCCESS;
386*0Sstevel@tonic-gate 
387*0Sstevel@tonic-gate 	return (ret);
388*0Sstevel@tonic-gate }
389*0Sstevel@tonic-gate 
390*0Sstevel@tonic-gate static int
391*0Sstevel@tonic-gate ltc1427_do_suspend()
392*0Sstevel@tonic-gate {
393*0Sstevel@tonic-gate 	int ret = DDI_SUCCESS;
394*0Sstevel@tonic-gate 
395*0Sstevel@tonic-gate 	return (ret);
396*0Sstevel@tonic-gate }
397*0Sstevel@tonic-gate 
398*0Sstevel@tonic-gate static int
399*0Sstevel@tonic-gate ltc1427_do_detach(dev_info_t *dip)
400*0Sstevel@tonic-gate {
401*0Sstevel@tonic-gate 	struct ltc1427_unit *unitp;
402*0Sstevel@tonic-gate 	int instance;
403*0Sstevel@tonic-gate 
404*0Sstevel@tonic-gate 	instance = ddi_get_instance(dip);
405*0Sstevel@tonic-gate 
406*0Sstevel@tonic-gate 	unitp = ddi_get_soft_state(ltc1427soft_statep, instance);
407*0Sstevel@tonic-gate 
408*0Sstevel@tonic-gate 	if (unitp == NULL) {
409*0Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d: unitp not filled\n",
410*0Sstevel@tonic-gate 			ddi_get_name(dip), instance);
411*0Sstevel@tonic-gate 		return (ENOMEM);
412*0Sstevel@tonic-gate 	}
413*0Sstevel@tonic-gate 
414*0Sstevel@tonic-gate 	i2c_client_unregister(unitp->ltc1427_hdl);
415*0Sstevel@tonic-gate 
416*0Sstevel@tonic-gate 	ddi_remove_minor_node(dip, NULL);
417*0Sstevel@tonic-gate 
418*0Sstevel@tonic-gate 	mutex_destroy(&unitp->ltc1427_mutex);
419*0Sstevel@tonic-gate 
420*0Sstevel@tonic-gate 	ddi_soft_state_free(ltc1427soft_statep, instance);
421*0Sstevel@tonic-gate 
422*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
423*0Sstevel@tonic-gate }
424