]> sigrok.org Git - libsigrok.git/blobdiff - hardware/alsa/api.c
Factor out common hw_init() driver code.
[libsigrok.git] / hardware / alsa / api.c
index 594b95e85bf4c749462f9f2a7b30eacbea5398a3..d9dd83ef1fc0ef329cf7f8113f02851051e099e5 100644 (file)
@@ -52,17 +52,7 @@ static int clear_instances(void)
 
 static int hw_init(struct sr_context *sr_ctx)
 {
-       struct drv_context *drvc;
-
-       if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
-               sr_err("Driver context malloc failed.");
-               return SR_ERR_MALLOC;
-       }
-
-       drvc->sr_ctx = sr_ctx;
-       di->priv = drvc;
-
-       return SR_OK;
+       return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
 }
 
 static GSList *hw_scan(GSList *options)
@@ -144,23 +134,11 @@ static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
-       if (id != SR_DI_HWCAPS) /* For SR_DI_HWCAPS sdi will be NULL. */
-               devc = sdi->priv;
-
        switch (id) {
-       case SR_DI_HWCAPS:
-               *data = hwcaps;
-               break;
-       case SR_DI_CUR_SAMPLERATE:
+       case SR_CONF_SAMPLERATE:
+               devc = sdi->priv;
                *data = &devc->cur_samplerate;
                break;
-       case SR_DI_SAMPLERATES:
-               if (!devc->supp_rates.list) {
-                       sr_err("Instance did not contain a samplerate list.");
-                       return SR_ERR_ARG;
-               }
-               *data = &devc->supp_rates;
-               break;
        default:
                return SR_ERR_ARG;
        }
@@ -196,6 +174,9 @@ static int config_list(int key, const void **data, const struct sr_dev_inst *sdi
        (void)sdi;
 
        switch (key) {
+       case SR_CONF_DEVICE_OPTIONS:
+               *data = hwcaps;
+               break;
        case SR_CONF_SAMPLERATE:
                if (!sdi || !sdi->priv)
                        return SR_ERR_ARG;