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 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 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/pic16f819_impl.h> 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate static void *pic16f819soft_statep; 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate static int pic16f819_set(struct pic16f819_unit *, int, uchar_t); 46*0Sstevel@tonic-gate static int pic16f819_get(struct pic16f819_unit *, int, uchar_t *, int); 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate static int pic16f819_do_attach(dev_info_t *); 50*0Sstevel@tonic-gate static int pic16f819_do_detach(dev_info_t *); 51*0Sstevel@tonic-gate static int pic16f819_do_resume(void); 52*0Sstevel@tonic-gate static int pic16f819_do_suspend(void); 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate /* 55*0Sstevel@tonic-gate * cb ops (only need ioctl) 56*0Sstevel@tonic-gate */ 57*0Sstevel@tonic-gate static int pic16f819_open(dev_t *, int, int, cred_t *); 58*0Sstevel@tonic-gate static int pic16f819_close(dev_t, int, int, cred_t *); 59*0Sstevel@tonic-gate static int pic16f819_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate static struct cb_ops pic16f819_cbops = { 62*0Sstevel@tonic-gate pic16f819_open, /* open */ 63*0Sstevel@tonic-gate pic16f819_close, /* close */ 64*0Sstevel@tonic-gate nodev, /* strategy */ 65*0Sstevel@tonic-gate nodev, /* print */ 66*0Sstevel@tonic-gate nodev, /* dump */ 67*0Sstevel@tonic-gate nodev, /* read */ 68*0Sstevel@tonic-gate nodev, /* write */ 69*0Sstevel@tonic-gate pic16f819_ioctl, /* ioctl */ 70*0Sstevel@tonic-gate nodev, /* devmap */ 71*0Sstevel@tonic-gate nodev, /* mmap */ 72*0Sstevel@tonic-gate nodev, /* segmap */ 73*0Sstevel@tonic-gate nochpoll, /* poll */ 74*0Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 75*0Sstevel@tonic-gate NULL, /* streamtab */ 76*0Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* Driver compatibility flag */ 77*0Sstevel@tonic-gate CB_REV, /* rev */ 78*0Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 79*0Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 80*0Sstevel@tonic-gate }; 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate /* 83*0Sstevel@tonic-gate * dev ops 84*0Sstevel@tonic-gate */ 85*0Sstevel@tonic-gate static int pic16f819_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); 86*0Sstevel@tonic-gate static int pic16f819_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate static struct dev_ops pic16f819_ops = { 89*0Sstevel@tonic-gate DEVO_REV, 90*0Sstevel@tonic-gate 0, 91*0Sstevel@tonic-gate ddi_no_info, 92*0Sstevel@tonic-gate nulldev, 93*0Sstevel@tonic-gate nulldev, 94*0Sstevel@tonic-gate pic16f819_attach, 95*0Sstevel@tonic-gate pic16f819_detach, 96*0Sstevel@tonic-gate nodev, 97*0Sstevel@tonic-gate &pic16f819_cbops, 98*0Sstevel@tonic-gate NULL 99*0Sstevel@tonic-gate }; 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate extern struct mod_ops mod_driverops; 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate static struct modldrv pic16f819_modldrv = { 104*0Sstevel@tonic-gate &mod_driverops, /* type of module - driver */ 105*0Sstevel@tonic-gate "PIC16F819 i2c device driver: v%I%", 106*0Sstevel@tonic-gate &pic16f819_ops 107*0Sstevel@tonic-gate }; 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate static struct modlinkage pic16f819_modlinkage = { 110*0Sstevel@tonic-gate MODREV_1, 111*0Sstevel@tonic-gate &pic16f819_modldrv, 112*0Sstevel@tonic-gate 0 113*0Sstevel@tonic-gate }; 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate int 117*0Sstevel@tonic-gate _init(void) 118*0Sstevel@tonic-gate { 119*0Sstevel@tonic-gate int error; 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate error = mod_install(&pic16f819_modlinkage); 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate if (!error) 124*0Sstevel@tonic-gate (void) ddi_soft_state_init(&pic16f819soft_statep, 125*0Sstevel@tonic-gate sizeof (struct pic16f819_unit), 1); 126*0Sstevel@tonic-gate return (error); 127*0Sstevel@tonic-gate } 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate int 130*0Sstevel@tonic-gate _fini(void) 131*0Sstevel@tonic-gate { 132*0Sstevel@tonic-gate int error; 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate error = mod_remove(&pic16f819_modlinkage); 135*0Sstevel@tonic-gate if (!error) 136*0Sstevel@tonic-gate ddi_soft_state_fini(&pic16f819soft_statep); 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate return (error); 139*0Sstevel@tonic-gate } 140*0Sstevel@tonic-gate 141*0Sstevel@tonic-gate int 142*0Sstevel@tonic-gate _info(struct modinfo *modinfop) 143*0Sstevel@tonic-gate { 144*0Sstevel@tonic-gate return (mod_info(&pic16f819_modlinkage, modinfop)); 145*0Sstevel@tonic-gate } 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate static int 148*0Sstevel@tonic-gate pic16f819_get(struct pic16f819_unit *unitp, int reg, uchar_t *byte, int flags) 149*0Sstevel@tonic-gate { 150*0Sstevel@tonic-gate i2c_transfer_t *i2c_tran_pointer; 151*0Sstevel@tonic-gate int err; 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate (void) i2c_transfer_alloc(unitp->pic16f819_hdl, &i2c_tran_pointer, 154*0Sstevel@tonic-gate 1, 1, flags); 155*0Sstevel@tonic-gate if (i2c_tran_pointer == NULL) { 156*0Sstevel@tonic-gate return (ENOMEM); 157*0Sstevel@tonic-gate } 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gate i2c_tran_pointer->i2c_flags = I2C_WR_RD; 160*0Sstevel@tonic-gate i2c_tran_pointer->i2c_wbuf[0] = (uchar_t)reg; 161*0Sstevel@tonic-gate err = i2c_transfer(unitp->pic16f819_hdl, i2c_tran_pointer); 162*0Sstevel@tonic-gate if (err) { 163*0Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "%s: pic16f819_get failed reg=%x", 164*0Sstevel@tonic-gate unitp->pic16f819_name, reg)); 165*0Sstevel@tonic-gate } else { 166*0Sstevel@tonic-gate *byte = i2c_tran_pointer->i2c_rbuf[0]; 167*0Sstevel@tonic-gate } 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate i2c_transfer_free(unitp->pic16f819_hdl, i2c_tran_pointer); 170*0Sstevel@tonic-gate return (err); 171*0Sstevel@tonic-gate } 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate static int 174*0Sstevel@tonic-gate pic16f819_set(struct pic16f819_unit *unitp, int reg, uchar_t byte) 175*0Sstevel@tonic-gate { 176*0Sstevel@tonic-gate i2c_transfer_t *i2c_tran_pointer; 177*0Sstevel@tonic-gate int err; 178*0Sstevel@tonic-gate 179*0Sstevel@tonic-gate (void) i2c_transfer_alloc(unitp->pic16f819_hdl, &i2c_tran_pointer, 180*0Sstevel@tonic-gate 2, 0, I2C_SLEEP); 181*0Sstevel@tonic-gate if (i2c_tran_pointer == NULL) { 182*0Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "%s: Failed in pic16f819_set " 183*0Sstevel@tonic-gate "i2c_tran_pointer not allocated", unitp->pic16f819_name)); 184*0Sstevel@tonic-gate return (ENOMEM); 185*0Sstevel@tonic-gate } 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate i2c_tran_pointer->i2c_flags = I2C_WR; 188*0Sstevel@tonic-gate i2c_tran_pointer->i2c_wbuf[0] = (uchar_t)reg; 189*0Sstevel@tonic-gate i2c_tran_pointer->i2c_wbuf[1] = byte; 190*0Sstevel@tonic-gate D1CMN_ERR((CE_NOTE, "%s: set reg %x to %x", 191*0Sstevel@tonic-gate unitp->pic16f819_name, reg, byte)); 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate err = i2c_transfer(unitp->pic16f819_hdl, i2c_tran_pointer); 194*0Sstevel@tonic-gate if (err) { 195*0Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "%s: Failed in the pic16f819_set" 196*0Sstevel@tonic-gate " i2c_transfer routine", unitp->pic16f819_name)); 197*0Sstevel@tonic-gate } 198*0Sstevel@tonic-gate i2c_transfer_free(unitp->pic16f819_hdl, i2c_tran_pointer); 199*0Sstevel@tonic-gate return (err); 200*0Sstevel@tonic-gate } 201*0Sstevel@tonic-gate 202*0Sstevel@tonic-gate static int 203*0Sstevel@tonic-gate pic16f819_open(dev_t *devp, int flags, int otyp, cred_t *credp) 204*0Sstevel@tonic-gate { 205*0Sstevel@tonic-gate _NOTE(ARGUNUSED(credp)) 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gate struct pic16f819_unit *unitp; 208*0Sstevel@tonic-gate int instance; 209*0Sstevel@tonic-gate int error = 0; 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate instance = getminor(*devp); 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate if (instance < 0) { 214*0Sstevel@tonic-gate return (ENXIO); 215*0Sstevel@tonic-gate } 216*0Sstevel@tonic-gate 217*0Sstevel@tonic-gate unitp = (struct pic16f819_unit *) 218*0Sstevel@tonic-gate ddi_get_soft_state(pic16f819soft_statep, instance); 219*0Sstevel@tonic-gate 220*0Sstevel@tonic-gate if (unitp == NULL) { 221*0Sstevel@tonic-gate return (ENXIO); 222*0Sstevel@tonic-gate } 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate if (otyp != OTYP_CHR) { 225*0Sstevel@tonic-gate return (EINVAL); 226*0Sstevel@tonic-gate } 227*0Sstevel@tonic-gate 228*0Sstevel@tonic-gate mutex_enter(&unitp->pic16f819_mutex); 229*0Sstevel@tonic-gate 230*0Sstevel@tonic-gate if (flags & FEXCL) { 231*0Sstevel@tonic-gate if (unitp->pic16f819_oflag != 0) { 232*0Sstevel@tonic-gate error = EBUSY; 233*0Sstevel@tonic-gate } else { 234*0Sstevel@tonic-gate unitp->pic16f819_oflag = FEXCL; 235*0Sstevel@tonic-gate } 236*0Sstevel@tonic-gate } else { 237*0Sstevel@tonic-gate if (unitp->pic16f819_oflag == FEXCL) { 238*0Sstevel@tonic-gate error = EBUSY; 239*0Sstevel@tonic-gate } else { 240*0Sstevel@tonic-gate unitp->pic16f819_oflag = FOPEN; 241*0Sstevel@tonic-gate } 242*0Sstevel@tonic-gate } 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gate mutex_exit(&unitp->pic16f819_mutex); 245*0Sstevel@tonic-gate 246*0Sstevel@tonic-gate return (error); 247*0Sstevel@tonic-gate } 248*0Sstevel@tonic-gate 249*0Sstevel@tonic-gate static int 250*0Sstevel@tonic-gate pic16f819_close(dev_t dev, int flags, int otyp, cred_t *credp) 251*0Sstevel@tonic-gate { 252*0Sstevel@tonic-gate _NOTE(ARGUNUSED(flags, otyp, credp)) 253*0Sstevel@tonic-gate 254*0Sstevel@tonic-gate struct pic16f819_unit *unitp; 255*0Sstevel@tonic-gate int instance; 256*0Sstevel@tonic-gate 257*0Sstevel@tonic-gate instance = getminor(dev); 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate if (instance < 0) { 260*0Sstevel@tonic-gate return (ENXIO); 261*0Sstevel@tonic-gate } 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate unitp = (struct pic16f819_unit *) 264*0Sstevel@tonic-gate ddi_get_soft_state(pic16f819soft_statep, instance); 265*0Sstevel@tonic-gate 266*0Sstevel@tonic-gate if (unitp == NULL) { 267*0Sstevel@tonic-gate return (ENXIO); 268*0Sstevel@tonic-gate } 269*0Sstevel@tonic-gate 270*0Sstevel@tonic-gate mutex_enter(&unitp->pic16f819_mutex); 271*0Sstevel@tonic-gate 272*0Sstevel@tonic-gate unitp->pic16f819_oflag = 0; 273*0Sstevel@tonic-gate 274*0Sstevel@tonic-gate mutex_exit(&unitp->pic16f819_mutex); 275*0Sstevel@tonic-gate return (DDI_SUCCESS); 276*0Sstevel@tonic-gate } 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate static int 279*0Sstevel@tonic-gate pic16f819_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, 280*0Sstevel@tonic-gate cred_t *credp, int *rvalp) 281*0Sstevel@tonic-gate { 282*0Sstevel@tonic-gate _NOTE(ARGUNUSED(credp, rvalp)) 283*0Sstevel@tonic-gate 284*0Sstevel@tonic-gate struct pic16f819_unit *unitp; 285*0Sstevel@tonic-gate int instance; 286*0Sstevel@tonic-gate int err = 0; 287*0Sstevel@tonic-gate i2c_reg_t ioctl_reg; 288*0Sstevel@tonic-gate uchar_t val8; 289*0Sstevel@tonic-gate 290*0Sstevel@tonic-gate if (arg == NULL) { 291*0Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "PIC16F819: ioctl: arg passed in to ioctl " 292*0Sstevel@tonic-gate "= NULL\n")); 293*0Sstevel@tonic-gate err = EINVAL; 294*0Sstevel@tonic-gate return (err); 295*0Sstevel@tonic-gate } 296*0Sstevel@tonic-gate instance = getminor(dev); 297*0Sstevel@tonic-gate unitp = (struct pic16f819_unit *) 298*0Sstevel@tonic-gate ddi_get_soft_state(pic16f819soft_statep, instance); 299*0Sstevel@tonic-gate 300*0Sstevel@tonic-gate mutex_enter(&unitp->pic16f819_mutex); 301*0Sstevel@tonic-gate 302*0Sstevel@tonic-gate switch (cmd) { 303*0Sstevel@tonic-gate 304*0Sstevel@tonic-gate case I2C_GET_REG: 305*0Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, (caddr_t)&ioctl_reg, 306*0Sstevel@tonic-gate sizeof (i2c_reg_t), mode) != DDI_SUCCESS) { 307*0Sstevel@tonic-gate err = EFAULT; 308*0Sstevel@tonic-gate break; 309*0Sstevel@tonic-gate } 310*0Sstevel@tonic-gate err = pic16f819_get(unitp, ioctl_reg.reg_num, &val8, 311*0Sstevel@tonic-gate I2C_SLEEP); 312*0Sstevel@tonic-gate if (err != I2C_SUCCESS) { 313*0Sstevel@tonic-gate break; 314*0Sstevel@tonic-gate } 315*0Sstevel@tonic-gate 316*0Sstevel@tonic-gate ioctl_reg.reg_value = val8; 317*0Sstevel@tonic-gate if (ddi_copyout((caddr_t)&ioctl_reg, (caddr_t)arg, 318*0Sstevel@tonic-gate sizeof (i2c_reg_t), mode) != DDI_SUCCESS) { 319*0Sstevel@tonic-gate err = EFAULT; 320*0Sstevel@tonic-gate } 321*0Sstevel@tonic-gate break; 322*0Sstevel@tonic-gate 323*0Sstevel@tonic-gate case I2C_SET_REG: 324*0Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, (caddr_t)&ioctl_reg, 325*0Sstevel@tonic-gate sizeof (i2c_reg_t), mode) != DDI_SUCCESS) { 326*0Sstevel@tonic-gate err = EFAULT; 327*0Sstevel@tonic-gate break; 328*0Sstevel@tonic-gate } 329*0Sstevel@tonic-gate err = pic16f819_set(unitp, ioctl_reg.reg_num, 330*0Sstevel@tonic-gate ioctl_reg.reg_value); 331*0Sstevel@tonic-gate break; 332*0Sstevel@tonic-gate default: 333*0Sstevel@tonic-gate D2CMN_ERR((CE_WARN, "%s: Invalid IOCTL cmd: %x\n", 334*0Sstevel@tonic-gate unitp->pic16f819_name, cmd)); 335*0Sstevel@tonic-gate err = EINVAL; 336*0Sstevel@tonic-gate } 337*0Sstevel@tonic-gate 338*0Sstevel@tonic-gate mutex_exit(&unitp->pic16f819_mutex); 339*0Sstevel@tonic-gate return (err); 340*0Sstevel@tonic-gate } 341*0Sstevel@tonic-gate 342*0Sstevel@tonic-gate static int 343*0Sstevel@tonic-gate pic16f819_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 344*0Sstevel@tonic-gate { 345*0Sstevel@tonic-gate switch (cmd) { 346*0Sstevel@tonic-gate case DDI_ATTACH: 347*0Sstevel@tonic-gate return (pic16f819_do_attach(dip)); 348*0Sstevel@tonic-gate case DDI_RESUME: 349*0Sstevel@tonic-gate return (pic16f819_do_resume()); 350*0Sstevel@tonic-gate default: 351*0Sstevel@tonic-gate return (DDI_FAILURE); 352*0Sstevel@tonic-gate } 353*0Sstevel@tonic-gate } 354*0Sstevel@tonic-gate 355*0Sstevel@tonic-gate static int 356*0Sstevel@tonic-gate pic16f819_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 357*0Sstevel@tonic-gate { 358*0Sstevel@tonic-gate switch (cmd) { 359*0Sstevel@tonic-gate case DDI_DETACH: 360*0Sstevel@tonic-gate return (pic16f819_do_detach(dip)); 361*0Sstevel@tonic-gate case DDI_SUSPEND: 362*0Sstevel@tonic-gate return (pic16f819_do_suspend()); 363*0Sstevel@tonic-gate default: 364*0Sstevel@tonic-gate return (DDI_FAILURE); 365*0Sstevel@tonic-gate } 366*0Sstevel@tonic-gate } 367*0Sstevel@tonic-gate 368*0Sstevel@tonic-gate static int 369*0Sstevel@tonic-gate pic16f819_do_attach(dev_info_t *dip) 370*0Sstevel@tonic-gate { 371*0Sstevel@tonic-gate struct pic16f819_unit *unitp; 372*0Sstevel@tonic-gate int instance; 373*0Sstevel@tonic-gate 374*0Sstevel@tonic-gate instance = ddi_get_instance(dip); 375*0Sstevel@tonic-gate 376*0Sstevel@tonic-gate if (ddi_soft_state_zalloc(pic16f819soft_statep, instance) != 0) { 377*0Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: failed to zalloc softstate\n", 378*0Sstevel@tonic-gate ddi_get_name(dip), instance); 379*0Sstevel@tonic-gate return (DDI_FAILURE); 380*0Sstevel@tonic-gate } 381*0Sstevel@tonic-gate 382*0Sstevel@tonic-gate unitp = ddi_get_soft_state(pic16f819soft_statep, instance); 383*0Sstevel@tonic-gate 384*0Sstevel@tonic-gate if (unitp == NULL) { 385*0Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: unitp not filled\n", 386*0Sstevel@tonic-gate ddi_get_name(dip), instance); 387*0Sstevel@tonic-gate return (ENOMEM); 388*0Sstevel@tonic-gate } 389*0Sstevel@tonic-gate 390*0Sstevel@tonic-gate (void) snprintf(unitp->pic16f819_name, sizeof (unitp->pic16f819_name), 391*0Sstevel@tonic-gate "%s%d", ddi_node_name(dip), instance); 392*0Sstevel@tonic-gate 393*0Sstevel@tonic-gate if (ddi_create_minor_node(dip, "fan_1", S_IFCHR, instance, 394*0Sstevel@tonic-gate "ddi_i2c:pic", NULL) == DDI_FAILURE) { 395*0Sstevel@tonic-gate cmn_err(CE_WARN, "%s ddi_create_minor_node failed for " 396*0Sstevel@tonic-gate "%s\n", unitp->pic16f819_name, "pic16f819"); 397*0Sstevel@tonic-gate ddi_soft_state_free(pic16f819soft_statep, instance); 398*0Sstevel@tonic-gate 399*0Sstevel@tonic-gate return (DDI_FAILURE); 400*0Sstevel@tonic-gate } 401*0Sstevel@tonic-gate 402*0Sstevel@tonic-gate if (i2c_client_register(dip, &unitp->pic16f819_hdl) != I2C_SUCCESS) { 403*0Sstevel@tonic-gate cmn_err(CE_WARN, "%s i2c_client_register failed\n", 404*0Sstevel@tonic-gate unitp->pic16f819_name); 405*0Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 406*0Sstevel@tonic-gate ddi_soft_state_free(pic16f819soft_statep, instance); 407*0Sstevel@tonic-gate 408*0Sstevel@tonic-gate return (DDI_FAILURE); 409*0Sstevel@tonic-gate } 410*0Sstevel@tonic-gate 411*0Sstevel@tonic-gate mutex_init(&unitp->pic16f819_mutex, NULL, MUTEX_DRIVER, NULL); 412*0Sstevel@tonic-gate 413*0Sstevel@tonic-gate return (DDI_SUCCESS); 414*0Sstevel@tonic-gate } 415*0Sstevel@tonic-gate 416*0Sstevel@tonic-gate static int 417*0Sstevel@tonic-gate pic16f819_do_resume() 418*0Sstevel@tonic-gate { 419*0Sstevel@tonic-gate int ret = DDI_SUCCESS; 420*0Sstevel@tonic-gate 421*0Sstevel@tonic-gate return (ret); 422*0Sstevel@tonic-gate } 423*0Sstevel@tonic-gate 424*0Sstevel@tonic-gate static int 425*0Sstevel@tonic-gate pic16f819_do_suspend() 426*0Sstevel@tonic-gate { 427*0Sstevel@tonic-gate int ret = DDI_SUCCESS; 428*0Sstevel@tonic-gate 429*0Sstevel@tonic-gate return (ret); 430*0Sstevel@tonic-gate } 431*0Sstevel@tonic-gate 432*0Sstevel@tonic-gate static int 433*0Sstevel@tonic-gate pic16f819_do_detach(dev_info_t *dip) 434*0Sstevel@tonic-gate { 435*0Sstevel@tonic-gate struct pic16f819_unit *unitp; 436*0Sstevel@tonic-gate int instance; 437*0Sstevel@tonic-gate 438*0Sstevel@tonic-gate instance = ddi_get_instance(dip); 439*0Sstevel@tonic-gate 440*0Sstevel@tonic-gate unitp = ddi_get_soft_state(pic16f819soft_statep, instance); 441*0Sstevel@tonic-gate 442*0Sstevel@tonic-gate if (unitp == NULL) { 443*0Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: unitp not filled\n", 444*0Sstevel@tonic-gate ddi_get_name(dip), instance); 445*0Sstevel@tonic-gate return (ENOMEM); 446*0Sstevel@tonic-gate } 447*0Sstevel@tonic-gate 448*0Sstevel@tonic-gate i2c_client_unregister(unitp->pic16f819_hdl); 449*0Sstevel@tonic-gate 450*0Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 451*0Sstevel@tonic-gate 452*0Sstevel@tonic-gate mutex_destroy(&unitp->pic16f819_mutex); 453*0Sstevel@tonic-gate 454*0Sstevel@tonic-gate ddi_soft_state_free(pic16f819soft_statep, instance); 455*0Sstevel@tonic-gate 456*0Sstevel@tonic-gate return (DDI_SUCCESS); 457*0Sstevel@tonic-gate } 458