Lines Matching refs:unitp

72 	mutex_enter(&unitp->umutex);	\
73 while (unitp->pcf8574_flags == PCF8574_BUSY) { \
74 if (cv_wait_sig(&unitp->pcf8574_cv, \
75 &unitp->umutex) <= 0) { \
76 mutex_exit(&unitp->umutex); \
80 unitp->pcf8574_flags = PCF8574_BUSY; \
81 mutex_exit(&unitp->umutex); \
86 mutex_enter(&unitp->umutex); \
87 unitp->pcf8574_flags = 0; \
88 cv_signal(&unitp->pcf8574_cv); \
89 mutex_exit(&unitp->umutex); \
137 static int pcf8574_read_chip(struct pcf8574_unit *unitp,
139 static int pcf8574_write_chip(struct pcf8574_unit *unitp,
141 static int pcf8574_read_props(struct pcf8574_unit *unitp);
142 static int pcf8574_init_chip(struct pcf8574_unit *unitp, int);
218 struct pcf8574_unit *unitp;
227 unitp = (struct pcf8574_unit *)
230 if (unitp == NULL) {
238 mutex_enter(&unitp->umutex);
241 if (unitp->pcf8574_oflag != 0) {
244 unitp->pcf8574_oflag = FEXCL;
247 if (unitp->pcf8574_oflag == FEXCL) {
250 unitp->pcf8574_oflag = FOPEN;
254 mutex_exit(&unitp->umutex);
263 struct pcf8574_unit *unitp;
277 unitp = (struct pcf8574_unit *)
280 if (unitp == NULL) {
284 mutex_enter(&unitp->umutex);
286 unitp->pcf8574_oflag = 0;
288 mutex_exit(&unitp->umutex);
304 struct pcf8574_unit *unitp;
316 unitp = (struct pcf8574_unit *)
318 if (unitp == NULL) {
328 err = uiomove(unitp->i2c_tran->i2c_wbuf,
332 err = pcf8574_write_chip(unitp, bytes_to_rw,
333 unitp->writemask);
337 err = pcf8574_read_chip(unitp, bytes_to_rw);
339 err = uiomove(unitp->i2c_tran->i2c_rbuf,
355 struct pcf8574_unit *unitp =
358 if (unitp == NULL) {
370 struct pcf8574_unit *unitp;
375 unitp = ddi_get_soft_state(pcf8574_soft_statep, instance);
377 attach_flag = unitp->attach_flag;
381 (fru_id_t)unitp->props.slave_address);
385 pcf8574_delete_kstat(unitp);
389 mutex_destroy(&unitp->umutex);
390 cv_destroy(&unitp->pcf8574_cv);
393 scsb_fru_unregister((void *)unitp,
394 (fru_id_t)unitp->props.slave_address);
401 unitp->i2c_tran->i2c_wlen = MAX_WLEN;
402 unitp->i2c_tran->i2c_rlen = MAX_RLEN;
403 i2c_transfer_free(unitp->pcf8574_hdl, unitp->i2c_tran);
407 i2c_client_unregister(unitp->pcf8574_hdl);
415 if (unitp->pcf8574_type == PCF8574_ADR_CPUVOLTAGE &&
416 unitp->props.num_chans_used != 0) {
417 ddi_prop_free(unitp->props.channels_in_use);
449 register struct pcf8574_unit *unitp;
467 unitp = ddi_get_soft_state(pcf8574_soft_statep, instance);
469 if (unitp == NULL) {
474 unitp->dip = dip;
476 unitp->attach_flag = PCF8574_SOFT_STATE_ALLOC;
478 if (pcf8574_read_props(unitp) != DDI_PROP_SUCCESS) {
483 unitp->attach_flag |= PCF8574_PROPS_READ;
488 unitp->current_mode = ENVCTRL_NORMAL_MODE;
490 (void) snprintf(unitp->pcf8574_name, PCF8574_NAMELEN,
493 if (unitp->pcf8574_type == PCF8574_TYPE_PWRSUPP) {
504 if (unitp->pcf8574_type == PCF8574_TYPE_FANTRAY) {
515 if (unitp->pcf8574_type == PCF8574_TYPE_CPUVOLTAGE) {
528 unitp->attach_flag |= PCF8574_MINORS_CREATED;
535 if (unitp->pcf8574_type == PCF8574_TYPE_FANTRAY) {
536 unitp->readmask = PCF8574_FAN_READMASK;
537 unitp->writemask = PCF8574_FAN_WRITEMASK;
539 if (unitp->pcf8574_type == PCF8574_TYPE_PWRSUPP) {
540 unitp->readmask = PCF8574_PS_READMASK;
541 unitp->writemask = PCF8574_PS_WRITEMASK;
544 for (i = unitp->props.num_chans_used,
545 chp = unitp->props.channels_in_use; i; --i, ++chp) {
546 unitp->readmask |= (uint8_t)(
549 unitp->writemask |= (uint8_t)(
556 writemask = 0x%x\n", unitp->readmask, unitp->writemask);
559 if (i2c_client_register(dip, &unitp->pcf8574_hdl)
564 unitp->attach_flag |= PCF8574_REGISTER_CLIENT;
570 if (i2c_transfer_alloc(unitp->pcf8574_hdl, &unitp->i2c_tran,
575 unitp->attach_flag |= PCF8574_ALLOC_TRANSFER;
580 unitp->i2c_tran->i2c_flags = I2C_RD;
581 unitp->i2c_tran->i2c_version = I2C_XFER_REV;
586 unitp->pcf8574_flags = 0;
587 unitp->pcf8574_oflag = 0;
589 mutex_init(&unitp->umutex, NULL, MUTEX_DRIVER, NULL);
590 cv_init(&unitp->pcf8574_cv, NULL, CV_DRIVER, NULL);
592 unitp->attach_flag |= PCF8574_LOCK_INIT;
598 dev_presence = scsb_fru_register(pcf8574_callback, (void *)unitp,
599 (fru_id_t)unitp->props.slave_address);
601 scsb_fru_unregister((void *)unitp,
602 (fru_id_t)unitp->props.slave_address);
614 if (pcf8574_add_kstat(unitp, dev_presence) != DDI_SUCCESS) {
619 unitp->attach_flag |= PCF8574_KSTAT_INIT;
629 (void) pcf8574_init_chip(unitp, 0); /* Disable intr first */
632 if (unitp->pcf8574_canintr == PCF8574_INTR_ON) {
638 if (scsb_intr_register(pcf8574_intr, (void *)unitp,
639 (fru_id_t)unitp->props.slave_address) == DDI_SUCCESS) {
640 unitp->pcf8574_canintr |= PCF8574_INTR_ENABLED;
641 unitp->attach_flag |= PCF8574_INTR_ADDED;
670 struct pcf8574_unit *unitp =
673 if (unitp == NULL) {
703 struct pcf8574_unit *unitp;
707 if ((unitp = (struct pcf8574_unit *)ddi_get_soft_state(
712 mutex_enter(&unitp->umutex);
713 if (unitp->poll_event) {
714 *reventsp = unitp->poll_event;
715 unitp->poll_event = 0;
717 *phpp = &unitp->poll;
718 mutex_exit(&unitp->umutex);
734 struct pcf8574_unit *unitp = (struct pcf8574_unit *)(void *)arg;
736 i2c_transfer_t *tp = unitp->i2c_tran;
741 unitp->props.slave_address);
748 mutex_enter(&unitp->umutex);
749 while (unitp->pcf8574_flags == PCF8574_BUSY) {
750 if (cv_wait_sig(&unitp->pcf8574_cv, &unitp->umutex) <= 0) {
751 mutex_exit(&unitp->umutex);
756 unitp->pcf8574_flags = PCF8574_BUSY;
757 mutex_exit(&unitp->umutex);
759 switch (unitp->pcf8574_type) {
766 (envctrl_pwrsupp_t *)unitp->envctrl_kstat;
772 (envctrl_fantray_t *)unitp->envctrl_kstat;
781 if (pcf8574_read_chip(unitp, 1) != I2C_SUCCESS) {
785 value = unitp->i2c_tran->i2c_rbuf[0];
797 switch (unitp->pcf8574_type) {
801 (envctrl_pwrsupp_t *)unitp->envctrl_kstat;
820 unitp->i2c_status =
821 nct_i2c_transfer(unitp->pcf8574_hdl, tp);
823 unitp->poll_event = POLLIN;
824 pollwakeup(&unitp->poll, POLLIN);
834 (envctrl_fantray_t *)unitp->envctrl_kstat;
848 unitp->i2c_status =
849 nct_i2c_transfer(unitp->pcf8574_hdl, tp);
851 unitp->poll_event = POLLIN;
852 pollwakeup(&unitp->poll, POLLIN);
865 mutex_enter(&unitp->umutex);
866 unitp->pcf8574_flags = 0;
867 cv_signal(&unitp->pcf8574_cv);
868 mutex_exit(&unitp->umutex);
874 call_copyin(caddr_t arg, struct pcf8574_unit *unitp, int mode)
879 i2c_transfer_t *i2ctp = unitp->i2c_tran;
916 call_copyout(caddr_t arg, struct pcf8574_unit *unitp, int mode)
919 i2c_transfer_t *i2ctp = unitp->i2c_tran;
978 struct pcf8574_unit *unitp;
989 unitp = (struct pcf8574_unit *)
992 if (unitp == NULL) {
997 scsb_fru_status((uchar_t)unitp->props.slave_address);
1016 unitp->i2c_tran->i2c_wbuf[0] =
1018 if (pcf8574_write_chip(unitp, 1, PCF8574_INTRMASK_BIT)
1026 if (unitp->pcf8574_type != PCF8574_TYPE_FANTRAY) {
1045 unitp->i2c_tran->i2c_wbuf[0] = PCF8574_FAN_SPEED(inval);
1047 if (pcf8574_write_chip(unitp, 1, PCF8574_FANSPEED_BIT)
1057 if (unitp->current_mode != ENVCTRL_DIAG_MODE) {
1068 unitp->i2c_tran->i2c_wbuf[0] = inval & 0xff;
1069 if (pcf8574_write_chip(unitp, 1, 0xff)
1088 if (pcf8574_read_chip(unitp, 1)
1093 value = unitp->i2c_tran->i2c_rbuf[0];
1095 if (unitp->pcf8574_type != PCF8574_TYPE_FANTRAY) {
1108 if (unitp->pcf8574_type == PCF8574_TYPE_PWRSUPP)
1110 if (unitp->pcf8574_type == PCF8574_TYPE_FANTRAY)
1115 if (unitp->pcf8574_type == PCF8574_TYPE_PWRSUPP)
1117 if (unitp->pcf8574_type == PCF8574_TYPE_FANTRAY)
1143 uint8_t curr_mode = unitp->current_mode;
1161 unitp->current_mode = curr_mode; /* Don't do anything */
1168 if (call_copyin((caddr_t)arg, unitp, mode) != DDI_SUCCESS) {
1172 unitp->i2c_status = err =
1173 nct_i2c_transfer(unitp->pcf8574_hdl, unitp->i2c_tran);
1178 if (call_copyout((caddr_t)arg, unitp, mode)
1196 pcf8574_add_kstat(struct pcf8574_unit *unitp, scsb_fru_status_t dev_presence)
1200 uint8_t i2c_address = unitp->props.slave_address;
1207 unitp->envctrl_kstat = NULL;
1208 switch (unitp->pcf8574_type) {
1211 if ((unitp->kstatp = kstat_create(I2C_PCF8574_NAME,
1212 unitp->instance, I2C_KSTAT_CPUVOLTAGE, "misc",
1216 if ((unitp->envctrl_kstat = kmem_zalloc(
1219 kstat_delete(unitp->kstatp);
1239 if ((unitp->kstatp = kstat_create(I2C_PCF8574_NAME,
1240 unitp->instance, ksname, "misc",
1244 if ((unitp->envctrl_kstat = kmem_zalloc(
1247 kstat_delete(unitp->kstatp);
1254 envp = (envctrl_pwrsupp_t *)unitp->envctrl_kstat;
1279 if ((unitp->kstatp = kstat_create(I2C_PCF8574_NAME,
1280 unitp->instance, ksname, "misc",
1284 if ((unitp->envctrl_kstat = kmem_zalloc(
1287 kstat_delete(unitp->kstatp);
1295 envp = (envctrl_fantray_t *)unitp->envctrl_kstat;
1311 unitp->kstatp->ks_private = (void *)unitp;
1312 unitp->kstatp->ks_update = pcf8574_kstat_update;
1314 kstat_install(unitp->kstatp);
1325 pcf8574_read_chip(struct pcf8574_unit *unitp, uint16_t size)
1328 i2c_transfer_t *tp = unitp->i2c_tran;
1340 unitp->i2c_status = retval =
1341 nct_i2c_transfer(unitp->pcf8574_hdl, unitp->i2c_tran);
1348 tp->i2c_rbuf[i] &= unitp->readmask;
1363 pcf8574_write_chip(struct pcf8574_unit *unitp,
1366 i2c_transfer_t *tp = unitp->i2c_tran;
1379 unitp->i2c_status = nct_i2c_transfer(unitp->pcf8574_hdl, tp);
1381 if (unitp->i2c_status != I2C_SUCCESS) {
1407 tp->i2c_rbuf[i] |= ~(unitp->writemask);
1417 unitp->i2c_status = nct_i2c_transfer(unitp->pcf8574_hdl, tp);
1419 return (unitp->i2c_status);
1425 struct pcf8574_unit *unitp;
1431 unitp = (struct pcf8574_unit *)ksp->ks_private;
1432 if (unitp->envctrl_kstat == NULL) { /* May be detaching */
1442 if (unitp->pcf8574_type == PCF8574_TYPE_CPUVOLTAGE) {
1446 scsb_fru_status((uchar_t)unitp->props.slave_address);
1460 if (unitp->pcf8574_type != PCF8574_TYPE_FANTRAY) {
1471 unitp->i2c_tran->i2c_wbuf[0] = PCF8574_FAN_SPEED(value);
1474 pcf8574_write_chip(unitp, 1, PCF8574_FANSPEED_BIT)
1488 pcf8574_read_chip(unitp, 1) != I2C_SUCCESS) {
1498 value = unitp->i2c_tran->i2c_rbuf[0];
1502 switch (unitp->pcf8574_type) {
1505 (envctrl_cpuvoltage_t *)unitp->envctrl_kstat;
1514 (envctrl_pwrsupp_t *)unitp->envctrl_kstat;
1530 (envctrl_fantray_t *)unitp->envctrl_kstat;
1537 bcopy((caddr_t)unitp->envctrl_kstat, kstatp,
1556 pcf8574_delete_kstat(struct pcf8574_unit *unitp)
1562 if (unitp->kstatp != NULL) {
1563 kstat_delete(unitp->kstatp);
1566 switch (unitp->pcf8574_type) {
1568 if (unitp->envctrl_kstat != NULL) {
1569 kmem_free(unitp->envctrl_kstat,
1575 if (unitp->envctrl_kstat != NULL) {
1576 kmem_free(unitp->envctrl_kstat,
1583 if (unitp->envctrl_kstat != NULL) {
1584 kmem_free(unitp->envctrl_kstat,
1593 unitp->envctrl_kstat = NULL;
1597 pcf8574_read_props(struct pcf8574_unit *unitp)
1599 dev_info_t *dip = unitp->dip;
1619 unitp->pcf8574_type = PCF8574_TYPE_FANTRAY;
1626 "fantary:address %x,%x", unitp->props.i2c_bus,
1627 unitp->props.slave_address);
1634 unitp->pcf8574_type = PCF8574_TYPE_PWRSUPP;
1648 unitp->props.i2c_bus = (uint16_t)prop_value[0];
1649 unitp->props.slave_address = i2c_address =
1654 unitp->sensor_type = PCF8574A;
1656 unitp->sensor_type = PCF8574;
1658 unitp->sensor_type = PCF8574A;
1663 unitp->props.i2c_bus = (uint16_t)-1;
1664 unitp->props.slave_address = (uint16_t)-1;
1672 unitp->pcf8574_canintr = 0;
1677 unitp->pcf8574_canintr |= PCF8574_INTR_ON;
1696 unitp->props.num_chans_used = 0;
1703 (uchar_t **)&unitp->props.channels_in_use,
1704 &unitp->props.num_chans_used);
1706 unitp->props.num_chans_used = 0;
1708 unitp->props.num_chans_used /=
1726 struct pcf8574_unit *unitp = (struct pcf8574_unit *)softstate;
1729 cmn_err(CE_NOTE, "pcf8574_callback(unitp,%d,%d)",
1733 switch (unitp->pcf8574_type) {
1744 envp = (envctrl_pwrsupp_t *)unitp->envctrl_kstat;
1754 (void) pcf8574_init_chip(unitp, 0);
1757 unitp->poll_event = POLLIN;
1758 pollwakeup(&unitp->poll, POLLIN);
1764 envp = (envctrl_fantray_t *)unitp->envctrl_kstat;
1773 (void) pcf8574_init_chip(unitp, 0);
1776 unitp->poll_event = POLLIN;
1777 pollwakeup(&unitp->poll, POLLIN);
1790 pcf8574_init_chip(struct pcf8574_unit *unitp, int intron)
1793 i2c_transfer_t *tp = unitp->i2c_tran;
1797 if (unitp->pcf8574_type != PCF8574_TYPE_PWRSUPP &&
1798 unitp->pcf8574_type != PCF8574_TYPE_FANTRAY) {
1801 switch (unitp->pcf8574_type) {
1824 unitp->i2c_status = ret = nct_i2c_transfer(unitp->pcf8574_hdl, tp);
1832 switch (unitp->pcf8574_type) {
1836 (envctrl_pwrsupp_t *)unitp->envctrl_kstat;
1853 (envctrl_fantray_t *)unitp->envctrl_kstat;
1878 unitp->i2c_status = nct_i2c_transfer(unitp->pcf8574_hdl, tp);
1880 return (unitp->i2c_status);