pcm_lib.c 67.1 KB
Newer Older
1001
1002
int snd_interval_list(struct snd_interval *i, unsigned int count,
		      const unsigned int *list, unsigned int mask)
Linus Torvalds's avatar
Linus Torvalds committed
1003
1004
{
        unsigned int k;
1005
	struct snd_interval list_range;
1006
1007
1008
1009
1010

	if (!count) {
		i->empty = 1;
		return -EINVAL;
	}
1011
1012
1013
	snd_interval_any(&list_range);
	list_range.min = UINT_MAX;
	list_range.max = 0;
Linus Torvalds's avatar
Linus Torvalds committed
1014
1015
1016
        for (k = 0; k < count; k++) {
		if (mask && !(mask & (1 << k)))
			continue;
1017
		if (!snd_interval_test(i, list[k]))
Linus Torvalds's avatar
Linus Torvalds committed
1018
			continue;
1019
1020
		list_range.min = min(list_range.min, list[k]);
		list_range.max = max(list_range.max, list[k]);
Linus Torvalds's avatar
Linus Torvalds committed
1021
        }
1022
	return snd_interval_refine(i, &list_range);
Linus Torvalds's avatar
Linus Torvalds committed
1023
}
1024
1025
EXPORT_SYMBOL(snd_interval_list);

1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
/**
 * snd_interval_ranges - refine the interval value from the list of ranges
 * @i: the interval value to refine
 * @count: the number of elements in the list of ranges
 * @ranges: the ranges list
 * @mask: the bit-mask to evaluate
 *
 * Refines the interval value from the list of ranges.
 * When mask is non-zero, only the elements corresponding to bit 1 are
 * evaluated.
 *
 * Return: Positive if the value is changed, zero if it's not changed, or a
 * negative error code.
 */
int snd_interval_ranges(struct snd_interval *i, unsigned int count,
			const struct snd_interval *ranges, unsigned int mask)
{
	unsigned int k;
	struct snd_interval range_union;
	struct snd_interval range;

	if (!count) {
		snd_interval_none(i);
		return -EINVAL;
	}
	snd_interval_any(&range_union);
	range_union.min = UINT_MAX;
	range_union.max = 0;
	for (k = 0; k < count; k++) {
		if (mask && !(mask & (1 << k)))
			continue;
		snd_interval_copy(&range, &ranges[k]);
		if (snd_interval_refine(&range, i) < 0)
			continue;
		if (snd_interval_empty(&range))
			continue;

		if (range.min < range_union.min) {
			range_union.min = range.min;
			range_union.openmin = 1;
		}
		if (range.min == range_union.min && !range.openmin)
			range_union.openmin = 0;
		if (range.max > range_union.max) {
			range_union.max = range.max;
			range_union.openmax = 1;
		}
		if (range.max == range_union.max && !range.openmax)
			range_union.openmax = 0;
	}
	return snd_interval_refine(i, &range_union);
}
EXPORT_SYMBOL(snd_interval_ranges);

1080
static int snd_interval_step(struct snd_interval *i, unsigned int step)
Linus Torvalds's avatar
Linus Torvalds committed
1081
1082
1083
{
	unsigned int n;
	int changed = 0;
1084
	n = i->min % step;
Linus Torvalds's avatar
Linus Torvalds committed
1085
1086
	if (n != 0 || i->openmin) {
		i->min += step - n;
1087
		i->openmin = 0;
Linus Torvalds's avatar
Linus Torvalds committed
1088
1089
		changed = 1;
	}
1090
	n = i->max % step;
Linus Torvalds's avatar
Linus Torvalds committed
1091
1092
	if (n != 0 || i->openmax) {
		i->max -= n;
1093
		i->openmax = 0;
Linus Torvalds's avatar
Linus Torvalds committed
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
		changed = 1;
	}
	if (snd_interval_checkempty(i)) {
		i->empty = 1;
		return -EINVAL;
	}
	return changed;
}

/* Info constraints helpers */

/**
 * snd_pcm_hw_rule_add - add the hw-constraint rule
 * @runtime: the pcm runtime instance
 * @cond: condition bits
 * @var: the variable to evaluate
 * @func: the evaluation function
 * @private: the private data pointer passed to function
 * @dep: the dependent variables
 *
1114
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1115
 */
1116
int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, unsigned int cond,
Linus Torvalds's avatar
Linus Torvalds committed
1117
1118
1119
1120
			int var,
			snd_pcm_hw_rule_func_t func, void *private,
			int dep, ...)
{
1121
1122
	struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
	struct snd_pcm_hw_rule *c;
Linus Torvalds's avatar
Linus Torvalds committed
1123
1124
1125
1126
	unsigned int k;
	va_list args;
	va_start(args, dep);
	if (constrs->rules_num >= constrs->rules_all) {
1127
		struct snd_pcm_hw_rule *new;
Linus Torvalds's avatar
Linus Torvalds committed
1128
		unsigned int new_rules = constrs->rules_all + 16;
1129
1130
		new = krealloc(constrs->rules, new_rules * sizeof(*c),
			       GFP_KERNEL);
1131
1132
		if (!new) {
			va_end(args);
Linus Torvalds's avatar
Linus Torvalds committed
1133
			return -ENOMEM;
1134
		}
Linus Torvalds's avatar
Linus Torvalds committed
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
		constrs->rules = new;
		constrs->rules_all = new_rules;
	}
	c = &constrs->rules[constrs->rules_num];
	c->cond = cond;
	c->func = func;
	c->var = var;
	c->private = private;
	k = 0;
	while (1) {
1145
1146
		if (snd_BUG_ON(k >= ARRAY_SIZE(c->deps))) {
			va_end(args);
1147
			return -EINVAL;
1148
		}
Linus Torvalds's avatar
Linus Torvalds committed
1149
1150
1151
1152
1153
1154
1155
1156
		c->deps[k++] = dep;
		if (dep < 0)
			break;
		dep = va_arg(args, int);
	}
	constrs->rules_num++;
	va_end(args);
	return 0;
1157
}
1158
1159
EXPORT_SYMBOL(snd_pcm_hw_rule_add);

Linus Torvalds's avatar
Linus Torvalds committed
1160
/**
1161
 * snd_pcm_hw_constraint_mask - apply the given bitmap mask constraint
Takashi Iwai's avatar
Takashi Iwai committed
1162
1163
1164
1165
 * @runtime: PCM runtime instance
 * @var: hw_params variable to apply the mask
 * @mask: the bitmap mask
 *
1166
 * Apply the constraint of the given bitmap mask to a 32-bit mask parameter.
1167
1168
 *
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1169
 */
1170
int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
Linus Torvalds's avatar
Linus Torvalds committed
1171
1172
			       u_int32_t mask)
{
1173
1174
	struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
	struct snd_mask *maskp = constrs_mask(constrs, var);
Linus Torvalds's avatar
Linus Torvalds committed
1175
1176
1177
1178
1179
1180
1181
1182
	*maskp->bits &= mask;
	memset(maskp->bits + 1, 0, (SNDRV_MASK_MAX-32) / 8); /* clear rest */
	if (*maskp->bits == 0)
		return -EINVAL;
	return 0;
}

/**
1183
 * snd_pcm_hw_constraint_mask64 - apply the given bitmap mask constraint
Takashi Iwai's avatar
Takashi Iwai committed
1184
1185
1186
1187
 * @runtime: PCM runtime instance
 * @var: hw_params variable to apply the mask
 * @mask: the 64bit bitmap mask
 *
1188
 * Apply the constraint of the given bitmap mask to a 64-bit mask parameter.
1189
1190
 *
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1191
 */
1192
int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
Linus Torvalds's avatar
Linus Torvalds committed
1193
1194
				 u_int64_t mask)
{
1195
1196
	struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
	struct snd_mask *maskp = constrs_mask(constrs, var);
Linus Torvalds's avatar
Linus Torvalds committed
1197
1198
1199
1200
1201
1202
1203
	maskp->bits[0] &= (u_int32_t)mask;
	maskp->bits[1] &= (u_int32_t)(mask >> 32);
	memset(maskp->bits + 2, 0, (SNDRV_MASK_MAX-64) / 8); /* clear rest */
	if (! maskp->bits[0] && ! maskp->bits[1])
		return -EINVAL;
	return 0;
}
1204
EXPORT_SYMBOL(snd_pcm_hw_constraint_mask64);
Linus Torvalds's avatar
Linus Torvalds committed
1205
1206

/**
1207
 * snd_pcm_hw_constraint_integer - apply an integer constraint to an interval
Takashi Iwai's avatar
Takashi Iwai committed
1208
1209
1210
1211
 * @runtime: PCM runtime instance
 * @var: hw_params variable to apply the integer constraint
 *
 * Apply the constraint of integer to an interval parameter.
1212
1213
1214
 *
 * Return: Positive if the value is changed, zero if it's not changed, or a
 * negative error code.
Linus Torvalds's avatar
Linus Torvalds committed
1215
 */
1216
int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var)
Linus Torvalds's avatar
Linus Torvalds committed
1217
{
1218
	struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
Linus Torvalds's avatar
Linus Torvalds committed
1219
1220
	return snd_interval_setinteger(constrs_interval(constrs, var));
}
1221
1222
EXPORT_SYMBOL(snd_pcm_hw_constraint_integer);

Linus Torvalds's avatar
Linus Torvalds committed
1223
/**
1224
 * snd_pcm_hw_constraint_minmax - apply a min/max range constraint to an interval
Takashi Iwai's avatar
Takashi Iwai committed
1225
1226
1227
1228
1229
1230
 * @runtime: PCM runtime instance
 * @var: hw_params variable to apply the range
 * @min: the minimal value
 * @max: the maximal value
 * 
 * Apply the min/max range constraint to an interval parameter.
1231
1232
1233
 *
 * Return: Positive if the value is changed, zero if it's not changed, or a
 * negative error code.
Linus Torvalds's avatar
Linus Torvalds committed
1234
 */
1235
int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
Linus Torvalds's avatar
Linus Torvalds committed
1236
1237
				 unsigned int min, unsigned int max)
{
1238
1239
	struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
	struct snd_interval t;
Linus Torvalds's avatar
Linus Torvalds committed
1240
1241
1242
1243
1244
1245
	t.min = min;
	t.max = max;
	t.openmin = t.openmax = 0;
	t.integer = 0;
	return snd_interval_refine(constrs_interval(constrs, var), &t);
}
1246
1247
EXPORT_SYMBOL(snd_pcm_hw_constraint_minmax);

1248
1249
static int snd_pcm_hw_rule_list(struct snd_pcm_hw_params *params,
				struct snd_pcm_hw_rule *rule)
Linus Torvalds's avatar
Linus Torvalds committed
1250
{
1251
	struct snd_pcm_hw_constraint_list *list = rule->private;
Linus Torvalds's avatar
Linus Torvalds committed
1252
1253
1254
1255
1256
	return snd_interval_list(hw_param_interval(params, rule->var), list->count, list->list, list->mask);
}		


/**
1257
 * snd_pcm_hw_constraint_list - apply a list of constraints to a parameter
Takashi Iwai's avatar
Takashi Iwai committed
1258
1259
1260
1261
1262
1263
 * @runtime: PCM runtime instance
 * @cond: condition bits
 * @var: hw_params variable to apply the list constraint
 * @l: list
 * 
 * Apply the list of constraints to an interval parameter.
1264
1265
 *
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1266
 */
1267
int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
Linus Torvalds's avatar
Linus Torvalds committed
1268
1269
			       unsigned int cond,
			       snd_pcm_hw_param_t var,
1270
			       const struct snd_pcm_hw_constraint_list *l)
Linus Torvalds's avatar
Linus Torvalds committed
1271
1272
{
	return snd_pcm_hw_rule_add(runtime, cond, var,
1273
				   snd_pcm_hw_rule_list, (void *)l,
Linus Torvalds's avatar
Linus Torvalds committed
1274
1275
				   var, -1);
}
1276
1277
EXPORT_SYMBOL(snd_pcm_hw_constraint_list);

1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
static int snd_pcm_hw_rule_ranges(struct snd_pcm_hw_params *params,
				  struct snd_pcm_hw_rule *rule)
{
	struct snd_pcm_hw_constraint_ranges *r = rule->private;
	return snd_interval_ranges(hw_param_interval(params, rule->var),
				   r->count, r->ranges, r->mask);
}


/**
 * snd_pcm_hw_constraint_ranges - apply list of range constraints to a parameter
 * @runtime: PCM runtime instance
 * @cond: condition bits
 * @var: hw_params variable to apply the list of range constraints
 * @r: ranges
 *
 * Apply the list of range constraints to an interval parameter.
 *
 * Return: Zero if successful, or a negative error code on failure.
 */
int snd_pcm_hw_constraint_ranges(struct snd_pcm_runtime *runtime,
				 unsigned int cond,
				 snd_pcm_hw_param_t var,
				 const struct snd_pcm_hw_constraint_ranges *r)
{
	return snd_pcm_hw_rule_add(runtime, cond, var,
				   snd_pcm_hw_rule_ranges, (void *)r,
				   var, -1);
}
EXPORT_SYMBOL(snd_pcm_hw_constraint_ranges);

1309
1310
static int snd_pcm_hw_rule_ratnums(struct snd_pcm_hw_params *params,
				   struct snd_pcm_hw_rule *rule)
Linus Torvalds's avatar
Linus Torvalds committed
1311
{
1312
	const struct snd_pcm_hw_constraint_ratnums *r = rule->private;
Linus Torvalds's avatar
Linus Torvalds committed
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
	unsigned int num = 0, den = 0;
	int err;
	err = snd_interval_ratnum(hw_param_interval(params, rule->var),
				  r->nrats, r->rats, &num, &den);
	if (err >= 0 && den && rule->var == SNDRV_PCM_HW_PARAM_RATE) {
		params->rate_num = num;
		params->rate_den = den;
	}
	return err;
}

/**
1325
 * snd_pcm_hw_constraint_ratnums - apply ratnums constraint to a parameter
Takashi Iwai's avatar
Takashi Iwai committed
1326
1327
1328
 * @runtime: PCM runtime instance
 * @cond: condition bits
 * @var: hw_params variable to apply the ratnums constraint
1329
 * @r: struct snd_ratnums constriants
1330
1331
 *
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1332
 */
1333
int snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime, 
Linus Torvalds's avatar
Linus Torvalds committed
1334
1335
				  unsigned int cond,
				  snd_pcm_hw_param_t var,
1336
				  const struct snd_pcm_hw_constraint_ratnums *r)
Linus Torvalds's avatar
Linus Torvalds committed
1337
1338
{
	return snd_pcm_hw_rule_add(runtime, cond, var,
1339
				   snd_pcm_hw_rule_ratnums, (void *)r,
Linus Torvalds's avatar
Linus Torvalds committed
1340
1341
				   var, -1);
}
1342
1343
EXPORT_SYMBOL(snd_pcm_hw_constraint_ratnums);

1344
1345
static int snd_pcm_hw_rule_ratdens(struct snd_pcm_hw_params *params,
				   struct snd_pcm_hw_rule *rule)
Linus Torvalds's avatar
Linus Torvalds committed
1346
{
1347
	const struct snd_pcm_hw_constraint_ratdens *r = rule->private;
Linus Torvalds's avatar
Linus Torvalds committed
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
	unsigned int num = 0, den = 0;
	int err = snd_interval_ratden(hw_param_interval(params, rule->var),
				  r->nrats, r->rats, &num, &den);
	if (err >= 0 && den && rule->var == SNDRV_PCM_HW_PARAM_RATE) {
		params->rate_num = num;
		params->rate_den = den;
	}
	return err;
}

/**
1359
 * snd_pcm_hw_constraint_ratdens - apply ratdens constraint to a parameter
Takashi Iwai's avatar
Takashi Iwai committed
1360
1361
1362
 * @runtime: PCM runtime instance
 * @cond: condition bits
 * @var: hw_params variable to apply the ratdens constraint
1363
 * @r: struct snd_ratdens constriants
1364
1365
 *
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1366
 */
1367
int snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime, 
Linus Torvalds's avatar
Linus Torvalds committed
1368
1369
				  unsigned int cond,
				  snd_pcm_hw_param_t var,
1370
				  const struct snd_pcm_hw_constraint_ratdens *r)
Linus Torvalds's avatar
Linus Torvalds committed
1371
1372
{
	return snd_pcm_hw_rule_add(runtime, cond, var,
1373
				   snd_pcm_hw_rule_ratdens, (void *)r,
Linus Torvalds's avatar
Linus Torvalds committed
1374
1375
				   var, -1);
}
1376
1377
EXPORT_SYMBOL(snd_pcm_hw_constraint_ratdens);

1378
1379
static int snd_pcm_hw_rule_msbits(struct snd_pcm_hw_params *params,
				  struct snd_pcm_hw_rule *rule)
Linus Torvalds's avatar
Linus Torvalds committed
1380
1381
1382
1383
{
	unsigned int l = (unsigned long) rule->private;
	int width = l & 0xffff;
	unsigned int msbits = l >> 16;
1384
1385
	const struct snd_interval *i =
		hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS);
1386
1387
1388
1389
1390
1391

	if (!snd_interval_single(i))
		return 0;

	if ((snd_interval_value(i) == width) ||
	    (width == 0 && snd_interval_value(i) > msbits))
1392
		params->msbits = min_not_zero(params->msbits, msbits);
1393

Linus Torvalds's avatar
Linus Torvalds committed
1394
1395
1396
1397
	return 0;
}

/**
1398
 * snd_pcm_hw_constraint_msbits - add a hw constraint msbits rule
Takashi Iwai's avatar
Takashi Iwai committed
1399
1400
1401
1402
 * @runtime: PCM runtime instance
 * @cond: condition bits
 * @width: sample bits width
 * @msbits: msbits width
1403
 *
1404
1405
1406
1407
1408
 * This constraint will set the number of most significant bits (msbits) if a
 * sample format with the specified width has been select. If width is set to 0
 * the msbits will be set for any sample format with a width larger than the
 * specified msbits.
 *
1409
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1410
 */
1411
int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime, 
Linus Torvalds's avatar
Linus Torvalds committed
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
				 unsigned int cond,
				 unsigned int width,
				 unsigned int msbits)
{
	unsigned long l = (msbits << 16) | width;
	return snd_pcm_hw_rule_add(runtime, cond, -1,
				    snd_pcm_hw_rule_msbits,
				    (void*) l,
				    SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1);
}
1422
1423
EXPORT_SYMBOL(snd_pcm_hw_constraint_msbits);

1424
1425
static int snd_pcm_hw_rule_step(struct snd_pcm_hw_params *params,
				struct snd_pcm_hw_rule *rule)
Linus Torvalds's avatar
Linus Torvalds committed
1426
1427
{
	unsigned long step = (unsigned long) rule->private;
1428
	return snd_interval_step(hw_param_interval(params, rule->var), step);
Linus Torvalds's avatar
Linus Torvalds committed
1429
1430
1431
}

/**
1432
 * snd_pcm_hw_constraint_step - add a hw constraint step rule
Takashi Iwai's avatar
Takashi Iwai committed
1433
1434
1435
1436
 * @runtime: PCM runtime instance
 * @cond: condition bits
 * @var: hw_params variable to apply the step constraint
 * @step: step size
1437
1438
 *
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1439
 */
1440
int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
Linus Torvalds's avatar
Linus Torvalds committed
1441
1442
1443
1444
1445
1446
1447
1448
			       unsigned int cond,
			       snd_pcm_hw_param_t var,
			       unsigned long step)
{
	return snd_pcm_hw_rule_add(runtime, cond, var, 
				   snd_pcm_hw_rule_step, (void *) step,
				   var, -1);
}
1449
1450
EXPORT_SYMBOL(snd_pcm_hw_constraint_step);

1451
static int snd_pcm_hw_rule_pow2(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule)
Linus Torvalds's avatar
Linus Torvalds committed
1452
{
1453
	static unsigned int pow2_sizes[] = {
Linus Torvalds's avatar
Linus Torvalds committed
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
		1<<0, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7,
		1<<8, 1<<9, 1<<10, 1<<11, 1<<12, 1<<13, 1<<14, 1<<15,
		1<<16, 1<<17, 1<<18, 1<<19, 1<<20, 1<<21, 1<<22, 1<<23,
		1<<24, 1<<25, 1<<26, 1<<27, 1<<28, 1<<29, 1<<30
	};
	return snd_interval_list(hw_param_interval(params, rule->var),
				 ARRAY_SIZE(pow2_sizes), pow2_sizes, 0);
}		

/**
1464
 * snd_pcm_hw_constraint_pow2 - add a hw constraint power-of-2 rule
Takashi Iwai's avatar
Takashi Iwai committed
1465
1466
1467
 * @runtime: PCM runtime instance
 * @cond: condition bits
 * @var: hw_params variable to apply the power-of-2 constraint
1468
1469
 *
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1470
 */
1471
int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
Linus Torvalds's avatar
Linus Torvalds committed
1472
1473
1474
1475
1476
1477
1478
			       unsigned int cond,
			       snd_pcm_hw_param_t var)
{
	return snd_pcm_hw_rule_add(runtime, cond, var, 
				   snd_pcm_hw_rule_pow2, NULL,
				   var, -1);
}
1479
1480
EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2);

1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
static int snd_pcm_hw_rule_noresample_func(struct snd_pcm_hw_params *params,
					   struct snd_pcm_hw_rule *rule)
{
	unsigned int base_rate = (unsigned int)(uintptr_t)rule->private;
	struct snd_interval *rate;

	rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
	return snd_interval_list(rate, 1, &base_rate, 0);
}

/**
 * snd_pcm_hw_rule_noresample - add a rule to allow disabling hw resampling
 * @runtime: PCM runtime instance
 * @base_rate: the rate at which the hardware does not resample
1495
1496
 *
 * Return: Zero if successful, or a negative error code on failure.
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
 */
int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
			       unsigned int base_rate)
{
	return snd_pcm_hw_rule_add(runtime, SNDRV_PCM_HW_PARAMS_NORESAMPLE,
				   SNDRV_PCM_HW_PARAM_RATE,
				   snd_pcm_hw_rule_noresample_func,
				   (void *)(uintptr_t)base_rate,
				   SNDRV_PCM_HW_PARAM_RATE, -1);
}
EXPORT_SYMBOL(snd_pcm_hw_rule_noresample);

1509
static void _snd_pcm_hw_param_any(struct snd_pcm_hw_params *params,
1510
				  snd_pcm_hw_param_t var)
Linus Torvalds's avatar
Linus Torvalds committed
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
{
	if (hw_is_mask(var)) {
		snd_mask_any(hw_param_mask(params, var));
		params->cmask |= 1 << var;
		params->rmask |= 1 << var;
		return;
	}
	if (hw_is_interval(var)) {
		snd_interval_any(hw_param_interval(params, var));
		params->cmask |= 1 << var;
		params->rmask |= 1 << var;
		return;
	}
	snd_BUG();
}

1527
void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params)
Linus Torvalds's avatar
Linus Torvalds committed
1528
1529
1530
1531
1532
1533
1534
1535
1536
{
	unsigned int k;
	memset(params, 0, sizeof(*params));
	for (k = SNDRV_PCM_HW_PARAM_FIRST_MASK; k <= SNDRV_PCM_HW_PARAM_LAST_MASK; k++)
		_snd_pcm_hw_param_any(params, k);
	for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++)
		_snd_pcm_hw_param_any(params, k);
	params->info = ~0U;
}
1537
EXPORT_SYMBOL(_snd_pcm_hw_params_any);
Linus Torvalds's avatar
Linus Torvalds committed
1538
1539

/**
1540
 * snd_pcm_hw_param_value - return @params field @var value
Takashi Iwai's avatar
Takashi Iwai committed
1541
1542
 * @params: the hw_params instance
 * @var: parameter to retrieve
1543
 * @dir: pointer to the direction (-1,0,1) or %NULL
Linus Torvalds's avatar
Linus Torvalds committed
1544
 *
1545
1546
 * Return: The value for field @var if it's fixed in configuration space
 * defined by @params. -%EINVAL otherwise.
Linus Torvalds's avatar
Linus Torvalds committed
1547
 */
1548
1549
int snd_pcm_hw_param_value(const struct snd_pcm_hw_params *params,
			   snd_pcm_hw_param_t var, int *dir)
Linus Torvalds's avatar
Linus Torvalds committed
1550
1551
{
	if (hw_is_mask(var)) {
1552
		const struct snd_mask *mask = hw_param_mask_c(params, var);
Linus Torvalds's avatar
Linus Torvalds committed
1553
1554
1555
1556
1557
1558
1559
		if (!snd_mask_single(mask))
			return -EINVAL;
		if (dir)
			*dir = 0;
		return snd_mask_value(mask);
	}
	if (hw_is_interval(var)) {
1560
		const struct snd_interval *i = hw_param_interval_c(params, var);
Linus Torvalds's avatar
Linus Torvalds committed
1561
1562
1563
1564
1565
1566
1567
1568
		if (!snd_interval_single(i))
			return -EINVAL;
		if (dir)
			*dir = i->openmin;
		return snd_interval_value(i);
	}
	return -EINVAL;
}
1569
EXPORT_SYMBOL(snd_pcm_hw_param_value);
Linus Torvalds's avatar
Linus Torvalds committed
1570

1571
void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params,
Linus Torvalds's avatar
Linus Torvalds committed
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
				snd_pcm_hw_param_t var)
{
	if (hw_is_mask(var)) {
		snd_mask_none(hw_param_mask(params, var));
		params->cmask |= 1 << var;
		params->rmask |= 1 << var;
	} else if (hw_is_interval(var)) {
		snd_interval_none(hw_param_interval(params, var));
		params->cmask |= 1 << var;
		params->rmask |= 1 << var;
	} else {
		snd_BUG();
	}
}
1586
EXPORT_SYMBOL(_snd_pcm_hw_param_setempty);
Linus Torvalds's avatar
Linus Torvalds committed
1587

1588
static int _snd_pcm_hw_param_first(struct snd_pcm_hw_params *params,
1589
				   snd_pcm_hw_param_t var)
Linus Torvalds's avatar
Linus Torvalds committed
1590
1591
1592
1593
1594
1595
{
	int changed;
	if (hw_is_mask(var))
		changed = snd_mask_refine_first(hw_param_mask(params, var));
	else if (hw_is_interval(var))
		changed = snd_interval_refine_first(hw_param_interval(params, var));
1596
	else
Linus Torvalds's avatar
Linus Torvalds committed
1597
		return -EINVAL;
1598
	if (changed > 0) {
Linus Torvalds's avatar
Linus Torvalds committed
1599
1600
1601
1602
1603
1604
1605
1606
		params->cmask |= 1 << var;
		params->rmask |= 1 << var;
	}
	return changed;
}


/**
1607
 * snd_pcm_hw_param_first - refine config space and return minimum value
Takashi Iwai's avatar
Takashi Iwai committed
1608
1609
1610
 * @pcm: PCM instance
 * @params: the hw_params instance
 * @var: parameter to retrieve
1611
 * @dir: pointer to the direction (-1,0,1) or %NULL
Linus Torvalds's avatar
Linus Torvalds committed
1612
 *
1613
 * Inside configuration space defined by @params remove from @var all
Linus Torvalds's avatar
Linus Torvalds committed
1614
 * values > minimum. Reduce configuration space accordingly.
1615
1616
 *
 * Return: The minimum, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1617
 */
1618
1619
1620
int snd_pcm_hw_param_first(struct snd_pcm_substream *pcm, 
			   struct snd_pcm_hw_params *params, 
			   snd_pcm_hw_param_t var, int *dir)
Linus Torvalds's avatar
Linus Torvalds committed
1621
1622
1623
1624
1625
1626
{
	int changed = _snd_pcm_hw_param_first(params, var);
	if (changed < 0)
		return changed;
	if (params->rmask) {
		int err = snd_pcm_hw_refine(pcm, params);
1627
		if (err < 0)
1628
			return err;
Linus Torvalds's avatar
Linus Torvalds committed
1629
1630
1631
	}
	return snd_pcm_hw_param_value(params, var, dir);
}
1632
1633
EXPORT_SYMBOL(snd_pcm_hw_param_first);

1634
static int _snd_pcm_hw_param_last(struct snd_pcm_hw_params *params,
1635
				  snd_pcm_hw_param_t var)
Linus Torvalds's avatar
Linus Torvalds committed
1636
1637
1638
1639
1640
1641
{
	int changed;
	if (hw_is_mask(var))
		changed = snd_mask_refine_last(hw_param_mask(params, var));
	else if (hw_is_interval(var))
		changed = snd_interval_refine_last(hw_param_interval(params, var));
1642
	else
Linus Torvalds's avatar
Linus Torvalds committed
1643
		return -EINVAL;
1644
	if (changed > 0) {
Linus Torvalds's avatar
Linus Torvalds committed
1645
1646
1647
1648
1649
1650
1651
1652
		params->cmask |= 1 << var;
		params->rmask |= 1 << var;
	}
	return changed;
}


/**
1653
 * snd_pcm_hw_param_last - refine config space and return maximum value
Takashi Iwai's avatar
Takashi Iwai committed
1654
1655
1656
 * @pcm: PCM instance
 * @params: the hw_params instance
 * @var: parameter to retrieve
1657
 * @dir: pointer to the direction (-1,0,1) or %NULL
Linus Torvalds's avatar
Linus Torvalds committed
1658
 *
1659
 * Inside configuration space defined by @params remove from @var all
Linus Torvalds's avatar
Linus Torvalds committed
1660
 * values < maximum. Reduce configuration space accordingly.
1661
1662
 *
 * Return: The maximum, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1663
 */
1664
1665
1666
int snd_pcm_hw_param_last(struct snd_pcm_substream *pcm, 
			  struct snd_pcm_hw_params *params,
			  snd_pcm_hw_param_t var, int *dir)
Linus Torvalds's avatar
Linus Torvalds committed
1667
1668
1669
1670
1671
1672
{
	int changed = _snd_pcm_hw_param_last(params, var);
	if (changed < 0)
		return changed;
	if (params->rmask) {
		int err = snd_pcm_hw_refine(pcm, params);
1673
		if (err < 0)
1674
			return err;
Linus Torvalds's avatar
Linus Torvalds committed
1675
1676
1677
	}
	return snd_pcm_hw_param_value(params, var, dir);
}
1678
EXPORT_SYMBOL(snd_pcm_hw_param_last);
Linus Torvalds's avatar
Linus Torvalds committed
1679

1680
static int snd_pcm_lib_ioctl_reset(struct snd_pcm_substream *substream,
Linus Torvalds's avatar
Linus Torvalds committed
1681
1682
				   void *arg)
{
1683
	struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds's avatar
Linus Torvalds committed
1684
1685
1686
1687
1688
	unsigned long flags;
	snd_pcm_stream_lock_irqsave(substream, flags);
	if (snd_pcm_running(substream) &&
	    snd_pcm_update_hw_ptr(substream) >= 0)
		runtime->status->hw_ptr %= runtime->buffer_size;
1689
	else {
Linus Torvalds's avatar
Linus Torvalds committed
1690
		runtime->status->hw_ptr = 0;
1691
1692
		runtime->hw_ptr_wrap = 0;
	}
Linus Torvalds's avatar
Linus Torvalds committed
1693
1694
1695
1696
	snd_pcm_stream_unlock_irqrestore(substream, flags);
	return 0;
}

1697
static int snd_pcm_lib_ioctl_channel_info(struct snd_pcm_substream *substream,
Linus Torvalds's avatar
Linus Torvalds committed
1698
1699
					  void *arg)
{
1700
1701
	struct snd_pcm_channel_info *info = arg;
	struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds's avatar
Linus Torvalds committed
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
	int width;
	if (!(runtime->info & SNDRV_PCM_INFO_MMAP)) {
		info->offset = -1;
		return 0;
	}
	width = snd_pcm_format_physical_width(runtime->format);
	if (width < 0)
		return width;
	info->offset = 0;
	switch (runtime->access) {
	case SNDRV_PCM_ACCESS_MMAP_INTERLEAVED:
	case SNDRV_PCM_ACCESS_RW_INTERLEAVED:
		info->first = info->channel * width;
		info->step = runtime->channels * width;
		break;
	case SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED:
	case SNDRV_PCM_ACCESS_RW_NONINTERLEAVED:
	{
		size_t size = runtime->dma_bytes / runtime->channels;
		info->first = info->channel * size * 8;
		info->step = width;
		break;
	}
	default:
		snd_BUG();
		break;
	}
	return 0;
}

1732
1733
1734
1735
1736
static int snd_pcm_lib_ioctl_fifo_size(struct snd_pcm_substream *substream,
				       void *arg)
{
	struct snd_pcm_hw_params *params = arg;
	snd_pcm_format_t format;
1737
1738
	int channels;
	ssize_t frame_size;
1739
1740
1741
1742
1743

	params->fifo_size = substream->runtime->hw.fifo_size;
	if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_FIFO_IN_FRAMES)) {
		format = params_format(params);
		channels = params_channels(params);
1744
1745
1746
		frame_size = snd_pcm_format_size(format, channels);
		if (frame_size > 0)
			params->fifo_size /= (unsigned)frame_size;
1747
1748
1749
1750
	}
	return 0;
}

Linus Torvalds's avatar
Linus Torvalds committed
1751
1752
1753
1754
1755
1756
1757
1758
1759
/**
 * snd_pcm_lib_ioctl - a generic PCM ioctl callback
 * @substream: the pcm substream instance
 * @cmd: ioctl command
 * @arg: ioctl argument
 *
 * Processes the generic ioctl commands for PCM.
 * Can be passed as the ioctl callback for PCM ops.
 *
1760
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1761
 */
1762
int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
Linus Torvalds's avatar
Linus Torvalds committed
1763
1764
1765
1766
1767
1768
1769
		      unsigned int cmd, void *arg)
{
	switch (cmd) {
	case SNDRV_PCM_IOCTL1_RESET:
		return snd_pcm_lib_ioctl_reset(substream, arg);
	case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
		return snd_pcm_lib_ioctl_channel_info(substream, arg);
1770
1771
	case SNDRV_PCM_IOCTL1_FIFO_SIZE:
		return snd_pcm_lib_ioctl_fifo_size(substream, arg);
Linus Torvalds's avatar
Linus Torvalds committed
1772
1773
1774
	}
	return -ENXIO;
}
1775
1776
EXPORT_SYMBOL(snd_pcm_lib_ioctl);

Linus Torvalds's avatar
Linus Torvalds committed
1777
1778
1779
1780
1781
1782
/**
 * snd_pcm_period_elapsed - update the pcm status for the next period
 * @substream: the pcm substream instance
 *
 * This function is called from the interrupt handler when the
 * PCM has processed the period size.  It will update the current
1783
 * pointer, wake up sleepers, etc.
Linus Torvalds's avatar
Linus Torvalds committed
1784
1785
1786
1787
 *
 * Even if more than one periods have elapsed since the last call, you
 * have to call this only once.
 */
1788
void snd_pcm_period_elapsed(struct snd_pcm_substream *substream)
Linus Torvalds's avatar
Linus Torvalds committed
1789
{
1790
	struct snd_pcm_runtime *runtime;
Linus Torvalds's avatar
Linus Torvalds committed
1791
1792
	unsigned long flags;

1793
1794
	if (PCM_RUNTIME_CHECK(substream))
		return;
Linus Torvalds's avatar
Linus Torvalds committed
1795
1796
1797
1798
	runtime = substream->runtime;

	snd_pcm_stream_lock_irqsave(substream, flags);
	if (!snd_pcm_running(substream) ||
1799
	    snd_pcm_update_hw_ptr0(substream, 1) < 0)
Linus Torvalds's avatar
Linus Torvalds committed
1800
1801
		goto _end;

1802
#ifdef CONFIG_SND_PCM_TIMER
Linus Torvalds's avatar
Linus Torvalds committed
1803
1804
	if (substream->timer_running)
		snd_timer_interrupt(substream->timer, 1);
1805
#endif
Linus Torvalds's avatar
Linus Torvalds committed
1806
1807
 _end:
	kill_fasync(&runtime->fasync, SIGIO, POLL_IN);
1808
	snd_pcm_stream_unlock_irqrestore(substream, flags);
Linus Torvalds's avatar
Linus Torvalds committed
1809
}
1810
1811
EXPORT_SYMBOL(snd_pcm_period_elapsed);

1812
1813
1814
1815
1816
1817
/*
 * Wait until avail_min data becomes available
 * Returns a negative error code if any error occurs during operation.
 * The available space is stored on availp.  When err = 0 and avail = 0
 * on the capture stream, it indicates the stream is in DRAINING state.
 */
1818
static int wait_for_avail(struct snd_pcm_substream *substream,
1819
1820
1821
1822
			      snd_pcm_uframes_t *availp)
{
	struct snd_pcm_runtime *runtime = substream->runtime;
	int is_playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
1823
	wait_queue_entry_t wait;
1824
1825
	int err = 0;
	snd_pcm_uframes_t avail = 0;
1826
1827
	long wait_time, tout;

1828
1829
1830
1831
	init_waitqueue_entry(&wait, current);
	set_current_state(TASK_INTERRUPTIBLE);
	add_wait_queue(&runtime->tsleep, &wait);

1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
	if (runtime->no_period_wakeup)
		wait_time = MAX_SCHEDULE_TIMEOUT;
	else {
		wait_time = 10;
		if (runtime->rate) {
			long t = runtime->period_size * 2 / runtime->rate;
			wait_time = max(t, wait_time);
		}
		wait_time = msecs_to_jiffies(wait_time * 1000);
	}
1842

1843
1844
1845
1846
1847
	for (;;) {
		if (signal_pending(current)) {
			err = -ERESTARTSYS;
			break;
		}
1848
1849
1850
1851
1852
1853
1854
1855

		/*
		 * We need to check if space became available already
		 * (and thus the wakeup happened already) first to close
		 * the race of space already having become available.
		 * This check must happen after been added to the waitqueue
		 * and having current state be INTERRUPTIBLE.
		 */
1856
		avail = snd_pcm_avail(substream);
1857
1858
		if (avail >= runtime->twake)
			break;
1859
		snd_pcm_stream_unlock_irq(substream);
1860
1861
1862

		tout = schedule_timeout(wait_time);

1863
		snd_pcm_stream_lock_irq(substream);
1864
		set_current_state(TASK_INTERRUPTIBLE);
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
		switch (runtime->status->state) {
		case SNDRV_PCM_STATE_SUSPENDED:
			err = -ESTRPIPE;
			goto _endloop;
		case SNDRV_PCM_STATE_XRUN:
			err = -EPIPE;
			goto _endloop;
		case SNDRV_PCM_STATE_DRAINING:
			if (is_playback)
				err = -EPIPE;
			else 
				avail = 0; /* indicate draining */
			goto _endloop;
		case SNDRV_PCM_STATE_OPEN:
		case SNDRV_PCM_STATE_SETUP:
		case SNDRV_PCM_STATE_DISCONNECTED:
			err = -EBADFD;
			goto _endloop;
1883
1884
		case SNDRV_PCM_STATE_PAUSED:
			continue;
1885
1886
		}
		if (!tout) {
1887
1888
1889
			pcm_dbg(substream->pcm,
				"%s write error (DMA or IRQ trouble?)\n",
				is_playback ? "playback" : "capture");
1890
1891
1892
1893
1894
			err = -EIO;
			break;
		}
	}
 _endloop:
1895
	set_current_state(TASK_RUNNING);
1896
	remove_wait_queue(&runtime->tsleep, &wait);
1897
1898
1899
1900
	*availp = avail;
	return err;
}
	
1901
1902
1903
typedef int (*pcm_transfer_f)(struct snd_pcm_substream *substream,
			      int channel, unsigned long hwoff,
			      void *buf, unsigned long bytes);
Takashi Iwai's avatar
Takashi Iwai committed
1904

1905
1906
1907
1908
1909
1910
typedef int (*pcm_copy_f)(struct snd_pcm_substream *, snd_pcm_uframes_t, void *,
			  snd_pcm_uframes_t, snd_pcm_uframes_t, pcm_transfer_f);

/* calculate the target DMA-buffer position to be written/read */
static void *get_dma_ptr(struct snd_pcm_runtime *runtime,
			   int channel, unsigned long hwoff)
Linus Torvalds's avatar
Linus Torvalds committed
1911
{
1912
1913
1914
1915
	return runtime->dma_area + hwoff +
		channel * (runtime->dma_bytes / runtime->channels);
}

1916
1917
1918
1919
/* default copy_user ops for write; used for both interleaved and non- modes */
static int default_write_copy(struct snd_pcm_substream *substream,
			      int channel, unsigned long hwoff,
			      void *buf, unsigned long bytes)
1920
1921
{
	if (copy_from_user(get_dma_ptr(substream->runtime, channel, hwoff),
1922
			   (void __user *)buf, bytes))
1923
1924
1925
1926
		return -EFAULT;
	return 0;
}

1927
1928
1929
1930
1931
1932
/* default copy_kernel ops for write */
static int default_write_copy_kernel(struct snd_pcm_substream *substream,
				     int channel, unsigned long hwoff,
				     void *buf, unsigned long bytes)
{
	memcpy(get_dma_ptr(substream->runtime, channel, hwoff), buf, bytes);
Linus Torvalds's avatar
Linus Torvalds committed
1933
1934
1935
	return 0;
}

1936
1937
1938
1939
1940
1941
/* fill silence instead of copy data; called as a transfer helper
 * from __snd_pcm_lib_write() or directly from noninterleaved_copy() when
 * a NULL buffer is passed
 */
static int fill_silence(struct snd_pcm_substream *substream, int channel,
			unsigned long hwoff, void *buf, unsigned long bytes)
Linus Torvalds's avatar
Linus Torvalds committed
1942
{
1943
	struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds's avatar
Linus Torvalds committed
1944

1945
	if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
Linus Torvalds's avatar
Linus Torvalds committed
1946
		return 0;
1947
1948
1949
	if (substream->ops->fill_silence)
		return substream->ops->fill_silence(substream, channel,
						    hwoff, bytes);
Linus Torvalds's avatar
Linus Torvalds committed
1950

1951
1952
1953
	snd_pcm_format_set_silence(runtime->format,
				   get_dma_ptr(runtime, channel, hwoff),
				   bytes_to_samples(runtime, bytes));
Linus Torvalds's avatar
Linus Torvalds committed
1954
1955
1956
	return 0;
}

1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
/* default copy_user ops for read; used for both interleaved and non- modes */
static int default_read_copy(struct snd_pcm_substream *substream,
			     int channel, unsigned long hwoff,
			     void *buf, unsigned long bytes)
{
	if (copy_to_user((void __user *)buf,
			 get_dma_ptr(substream->runtime, channel, hwoff),
			 bytes))
		return -EFAULT;
	return 0;
}
Linus Torvalds's avatar
Linus Torvalds committed
1968

1969
1970
1971
1972
1973
1974
1975
1976
1977
/* default copy_kernel ops for read */
static int default_read_copy_kernel(struct snd_pcm_substream *substream,
				    int channel, unsigned long hwoff,
				    void *buf, unsigned long bytes)
{
	memcpy(buf, get_dma_ptr(substream->runtime, channel, hwoff), bytes);
	return 0;
}

1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
/* call transfer function with the converted pointers and sizes;
 * for interleaved mode, it's one shot for all samples
 */
static int interleaved_copy(struct snd_pcm_substream *substream,
			    snd_pcm_uframes_t hwoff, void *data,
			    snd_pcm_uframes_t off,
			    snd_pcm_uframes_t frames,
			    pcm_transfer_f transfer)
{
	struct snd_pcm_runtime *runtime = substream->runtime;

	/* convert to bytes */
	hwoff = frames_to_bytes(runtime, hwoff);
	off = frames_to_bytes(runtime, off);
	frames = frames_to_bytes(runtime, frames);
	return transfer(substream, 0, hwoff, data + off, frames);
}

/* call transfer function with the converted pointers and sizes for each
 * non-interleaved channel; when buffer is NULL, silencing instead of copying
 */
static int noninterleaved_copy(struct snd_pcm_substream *substream,
			       snd_pcm_uframes_t hwoff, void *data,
For faster browsing, not all history is shown. View entire blame