static int set_userport_rtc_enabled(int value, void *param)
{
    int val = value ? 1 : 0;

    if (userport_rtc_58321a_enabled == val) {
        return 0;
    }

    if (val) {
        rtc58321a_context = rtc58321a_init("USER");
        userport_rtc_list_item = userport_device_register(&rtc_device);
        if (userport_rtc_list_item == NULL) {
            return -1;
        }
    } else {
        if (rtc58321a_context) {
            rtc58321a_destroy(rtc58321a_context, rtc58321a_rtc_save);
            rtc58321a_context = NULL;
        }
        userport_device_unregister(userport_rtc_list_item);
        userport_rtc_list_item = NULL;
    }

    userport_rtc_58321a_enabled = val;
    return 0;
}
static int set_userport_rtc_enabled(int value, void *param)
{
    int val = value ? 1 : 0;

    if (userport_rtc_ds1307_enabled == val) {
        return 0;
    }

    if (val) {
        ds1307_context = ds1307_init("USERDS1307");
        userport_rtc_list_item = userport_device_register(&rtc_device);
        if (userport_rtc_list_item == NULL) {
            return -1;
        }
        ds1307_set_data_line(ds1307_context, 1);
        ds1307_set_clk_line(ds1307_context, 1);
    } else {
        if (ds1307_context) {
            ds1307_destroy(ds1307_context, ds1307_rtc_save);
            ds1307_context = NULL;
        }
        userport_device_unregister(userport_rtc_list_item);
        userport_rtc_list_item = NULL;
    }

    userport_rtc_ds1307_enabled = val;
    return 0;
}
static int set_digimax_enabled(int value, void *param)
{
    int val = value ? 1 : 0;

    if (!digimax_sound_chip.chip_enabled && val) {
        userport_digimax_list_item = userport_device_register(&digimax_device);
        digimax_sound_chip.chip_enabled = 1;
    } else if (digimax_sound_chip.chip_enabled && !val) {
        if (userport_digimax_list_item != NULL) {
            userport_device_unregister(userport_digimax_list_item);
            userport_digimax_list_item = NULL;
        }
        digimax_sound_chip.chip_enabled = 0;
    }
    return 0;
}
static int set_userport_diag_586220_harness_enabled(int value, void *param)
{
    int val = value ? 1 : 0;

    if (userport_diag_586220_harness_enabled == val) {
        return 0;
    }

    if (val) {
        userport_diag_586220_harness_list_item = userport_device_register(&diag_586220_harness_device);
        if (userport_diag_586220_harness_list_item == NULL) {
            return -1;
        }
    } else {
        userport_device_unregister(userport_diag_586220_harness_list_item);
        userport_diag_586220_harness_list_item = NULL;
    }

    userport_diag_586220_harness_enabled = val;
    return 0;
}
static int set_userport_4bit_sampler_enabled(int value, void *param)
{
    int val = value ? 1 : 0;

    if (userport_4bit_sampler_enabled == val) {
        return 0;
    }

    if (val) {
        sampler_start(SAMPLER_OPEN_MONO, "4bit userport sampler");
        userport_4bit_sampler_list_item = userport_device_register(&sampler_device);
        if (userport_4bit_sampler_list_item == NULL) {
            sampler_stop();
            return -1;
        }
    } else {
        userport_device_unregister(userport_4bit_sampler_list_item);
        userport_4bit_sampler_list_item = NULL;
        sampler_stop();
    }

    userport_4bit_sampler_enabled = val;
    return 0;
}