Esempio n. 1
0
static int config_xx(struct usf_xx_type *usf_xx, struct us_xx_info_type *config)
{
    int rc = 0;
    uint16_t data_map_size = 0;
    uint16_t min_map_size = 0;

    if ((usf_xx == NULL) ||
            (config == NULL))
        return -EINVAL;

    if ((config->buf_size == 0) ||
            (config->buf_size > USF_MAX_BUF_SIZE) ||
            (config->buf_num == 0) ||
            (config->buf_num > USF_MAX_BUF_NUM)) {
        pr_err("%s: wrong params: buf_size=%d; buf_num=%d\n",
               __func__, config->buf_size, config->buf_num);
        return -EINVAL;
    }

    data_map_size = sizeof(usf_xx->encdec_cfg.cfg_common.data_map);
    min_map_size = min(data_map_size, config->port_cnt);

    if (config->client_name != NULL) {
        if (strncpy_from_user(usf_xx->client_name,
                              config->client_name,
                              sizeof(usf_xx->client_name) - 1) < 0) {
            pr_err("%s: get client name failed\n", __func__);
            return -EINVAL;
        }
    }

    pr_debug("%s: name=%s; buf_size:%d; dev_id:0x%x; sample_rate:%d\n",
             __func__, usf_xx->client_name, config->buf_size,
             config->dev_id, config->sample_rate);

    pr_debug("%s: buf_num:%d; format:%d; port_cnt:%d; data_size=%d\n",
             __func__, config->buf_num, config->stream_format,
             config->port_cnt, config->params_data_size);

    pr_debug("%s: id[0]=%d, id[1]=%d, id[2]=%d, id[3]=%d, id[4]=%d,\n",
             __func__,
             config->port_id[0],
             config->port_id[1],
             config->port_id[2],
             config->port_id[3],
             config->port_id[4]);

    pr_debug("id[5]=%d, id[6]=%d, id[7]=%d\n",
             config->port_id[5],
             config->port_id[6],
             config->port_id[7]);

    /* q6usm allocation & configuration */
    usf_xx->buffer_size = config->buf_size;
    usf_xx->buffer_count = config->buf_num;
    usf_xx->encdec_cfg.cfg_common.bits_per_sample =
        config->bits_per_sample;
    usf_xx->encdec_cfg.cfg_common.sample_rate = config->sample_rate;
    /* AFE port e.g. AFE_PORT_ID_SLIMBUS_MULTI_CHAN_1_RX */
    usf_xx->encdec_cfg.cfg_common.dev_id = config->dev_id;

    usf_xx->encdec_cfg.cfg_common.ch_cfg = config->port_cnt;
    memcpy((void *)&usf_xx->encdec_cfg.cfg_common.data_map,
           (void *)config->port_id,
           min_map_size);

    if (rc) {
        pr_err("%s: ports offsets copy failure\n", __func__);
        return -EINVAL;
    }

    usf_xx->encdec_cfg.format_id = config->stream_format;
    usf_xx->encdec_cfg.params_size = config->params_data_size;
    usf_xx->user_upd_info_na = 1; /* it's used in US_GET_TX_UPDATE */

    if (config->params_data_size > 0) { /* transparent data copy */
        usf_xx->encdec_cfg.params = kzalloc(config->params_data_size,
                                            GFP_KERNEL);
        if (usf_xx->encdec_cfg.params == NULL) {
            pr_err("%s: params memory alloc[%d] failure\n",
                   __func__,
                   config->params_data_size);
            return -ENOMEM;
        }
        rc = copy_from_user(usf_xx->encdec_cfg.params,
                            config->params_data,
                            config->params_data_size);
        if (rc) {
            pr_err("%s: transparent data copy failure\n",
                   __func__);
            kfree(usf_xx->encdec_cfg.params);
            usf_xx->encdec_cfg.params = NULL;
            return -EFAULT;
        }
        pr_debug("%s: params_size[%d]; params[%d,%d,%d,%d, %d]\n",
                 __func__,
                 config->params_data_size,
                 usf_xx->encdec_cfg.params[0],
                 usf_xx->encdec_cfg.params[1],
                 usf_xx->encdec_cfg.params[2],
                 usf_xx->encdec_cfg.params[3],
                 usf_xx->encdec_cfg.params[4]
                );
    }

    usf_xx->usc = q6usm_us_client_alloc(usf_xx->cb, (void *)usf_xx);
    if (!usf_xx->usc) {
        pr_err("%s: Could not allocate q6usm client\n", __func__);
        rc = -EFAULT;
    }

    return rc;
}
Esempio n. 2
0
static int config_xx(struct usf_xx_type *usf_xx, struct us_xx_info_type *config)
{
	int rc = 0;
	uint16_t data_map_size = 0;

	if ((usf_xx == NULL) ||
	    (config == NULL))
		return -EINVAL;

	data_map_size = sizeof(usf_xx->encdec_cfg.cfg_common.data_map);

	if (config->client_name != NULL) {
		if (strncpy_from_user(usf_xx->client_name,
				      config->client_name,
				      sizeof(usf_xx->client_name) - 1) < 0) {
			pr_err("%s: get client name failed\n", __func__);
			return -EINVAL;
		}
	}

	pr_debug("%s: name=%s; buf_size:%d; dev_id:0x%x; sample_rate:%d\n",
		__func__, usf_xx->client_name, config->buf_size,
		config->dev_id, config->sample_rate);

	pr_debug("%s: buf_num:%d; format:%d; port_cnt:%d; data_size=%d\n",
		__func__, config->buf_num, config->stream_format,
		config->port_cnt, config->params_data_size);

	pr_debug("%s: p_id[0]=%d, p_id[1]=%d, p_id[2]=%d, p_id[3]=%d\n",
		__func__,
		config->port_id[0],
		config->port_id[1],
		config->port_id[2],
		config->port_id[3]);

	if (data_map_size < config->port_cnt) {
		pr_err("%s: number of supported ports:%d < requested:%d\n",
			__func__,
			data_map_size,
			config->port_cnt);
		return -EINVAL;
	}

	
	usf_xx->buffer_size = config->buf_size;
	usf_xx->buffer_count = config->buf_num;
	usf_xx->encdec_cfg.cfg_common.bits_per_sample =
				config->bits_per_sample;
	usf_xx->encdec_cfg.cfg_common.sample_rate = config->sample_rate;
	
	usf_xx->encdec_cfg.cfg_common.dev_id = config->dev_id;

	usf_xx->encdec_cfg.cfg_common.ch_cfg = config->port_cnt;
	memcpy((void *)&usf_xx->encdec_cfg.cfg_common.data_map,
	       (void *)config->port_id,
	       config->port_cnt);
	if (rc) {
		pr_err("%s: ports offsets copy failure\n", __func__);
		return -EINVAL;
	}

	usf_xx->encdec_cfg.format_id = config->stream_format;
	usf_xx->encdec_cfg.params_size = config->params_data_size;
	usf_xx->user_upd_info_na = 1; 

	if (config->params_data_size > 0) { 
		usf_xx->encdec_cfg.params = kzalloc(config->params_data_size,
						    GFP_KERNEL);
		if (usf_xx->encdec_cfg.params == NULL) {
			pr_err("%s: params memory alloc[%d] failure\n",
				__func__,
				config->params_data_size);
			return -ENOMEM;
		}
		rc = copy_from_user(usf_xx->encdec_cfg.params,
				    config->params_data,
				    config->params_data_size);
		if (rc) {
			pr_err("%s: transparent data copy failure\n",
			       __func__);
			kfree(usf_xx->encdec_cfg.params);
			usf_xx->encdec_cfg.params = NULL;
			return -EFAULT;
		}
		pr_debug("%s: params_size[%d]; params[%d,%d,%d,%d, %d]\n",
			 __func__,
			 config->params_data_size,
			 usf_xx->encdec_cfg.params[0],
			 usf_xx->encdec_cfg.params[1],
			 usf_xx->encdec_cfg.params[2],
			 usf_xx->encdec_cfg.params[3],
			 usf_xx->encdec_cfg.params[4]
			);
	}

	usf_xx->usc = q6usm_us_client_alloc(usf_xx->cb, (void *)usf_xx);
	if (!usf_xx->usc) {
		pr_err("%s: Could not allocate q6usm client\n", __func__);
		rc = -EFAULT;
	}

	return rc;
}