SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type, unsigned int addr, int prb_num) { struct sr_channel_group *cg; struct channel_group_priv *cgp; int hwmon; /* Obtain the hwmon index. */ hwmon = get_hwmon_index(addr); if (hwmon < 0) return FALSE; cg = g_malloc0(sizeof(struct sr_channel_group)); cgp = g_malloc0(sizeof(struct channel_group_priv)); cgp->hwmon_num = hwmon; cgp->probe_type = type; cgp->index = prb_num - 1; cg->name = g_strdup_printf("Probe_%d", prb_num); cg->priv = cgp; if (type == PROBE_ENRG) { append_channel(sdi, cg, prb_num, ENRG_PWR); append_channel(sdi, cg, prb_num, ENRG_CURR); append_channel(sdi, cg, prb_num, ENRG_VOL); } else if (type == PROBE_TEMP) { append_channel(sdi, cg, prb_num, TEMP_IN); append_channel(sdi, cg, prb_num, TEMP_OUT); } else { sr_err("Invalid probe type: %d.", type); } sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); return TRUE; }
SR_PRIV gboolean gen_iio_register_probe(struct sr_dev_inst *sdi, int type, unsigned int addr, int prb_num) { struct sr_channel_group *cg; struct channel_group_priv *cgp; struct probe_eeprom eeprom; int hwmon, status; uint32_t gpio; /* Obtain the hwmon index. */ hwmon = get_hwmon_index(addr); if (hwmon < 0) return FALSE; cg = g_malloc0(sizeof(struct sr_channel_group)); cgp = g_malloc0(sizeof(struct channel_group_priv)); cg->priv = cgp; /* * See if we can read the EEPROM contents. If not, assume it's * a revision A probe. */ memset(&eeprom, 0, sizeof(struct probe_eeprom)); status = read_probe_eeprom(addr, &eeprom); cgp->rev = status < 0 ? ACME_REV_A : ACME_REV_B; prb_num = cgp->rev == ACME_REV_A ? prb_num : revB_addr_to_num(addr); cgp->hwmon_num = hwmon; cgp->probe_type = type; cgp->index = prb_num - 1; cg->name = g_strdup_printf("Probe_%d", prb_num); if (cgp->rev == ACME_REV_A) { gpio = revA_pws_info_gpios[cgp->index]; cgp->has_pws = sr_gpio_getval_export(gpio); cgp->pws_gpio = revA_pws_gpios[cgp->index]; } else { cgp->has_pws = eeprom.pwr_sw; cgp->pws_gpio = revB_pws_gpios[cgp->index]; /* * For revision B we can already try to set the shunt * resistance according to the EEPROM contents. * * Keep the default value if shunt in EEPROM == 0. */ if (eeprom.shunt > 0) gen_iio_set_shunt(cg, UOHM_TO_MOHM(eeprom.shunt)); } if (type == PROBE_ENRG) { append_channel(sdi, cg, prb_num, ENRG_PWR); append_channel(sdi, cg, prb_num, ENRG_CURR); append_channel(sdi, cg, prb_num, ENRG_VOL); } else if (type == PROBE_TEMP) { append_channel(sdi, cg, prb_num, TEMP_IN); append_channel(sdi, cg, prb_num, TEMP_OUT); } else { sr_err("Invalid probe type: %d.", type); } sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); return TRUE; }