pcm_lib.c 70.1 KB
Newer Older
1001
	}
1002
1003
1004
	snd_interval_any(&list_range);
	list_range.min = UINT_MAX;
	list_range.max = 0;
Linus Torvalds's avatar
Linus Torvalds committed
1005
1006
1007
        for (k = 0; k < count; k++) {
		if (mask && !(mask & (1 << k)))
			continue;
1008
		if (!snd_interval_test(i, list[k]))
Linus Torvalds's avatar
Linus Torvalds committed
1009
			continue;
1010
1011
		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
1012
        }
1013
	return snd_interval_refine(i, &list_range);
Linus Torvalds's avatar
Linus Torvalds committed
1014
1015
}

1016
1017
EXPORT_SYMBOL(snd_interval_list);

1018
1019
1020
1021
1022
1023
1024
1025
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
/**
 * 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);

1072
static int snd_interval_step(struct snd_interval *i, unsigned int step)
Linus Torvalds's avatar
Linus Torvalds committed
1073
1074
1075
{
	unsigned int n;
	int changed = 0;
1076
	n = i->min % step;
Linus Torvalds's avatar
Linus Torvalds committed
1077
1078
	if (n != 0 || i->openmin) {
		i->min += step - n;
1079
		i->openmin = 0;
Linus Torvalds's avatar
Linus Torvalds committed
1080
1081
		changed = 1;
	}
1082
	n = i->max % step;
Linus Torvalds's avatar
Linus Torvalds committed
1083
1084
	if (n != 0 || i->openmax) {
		i->max -= n;
1085
		i->openmax = 0;
Linus Torvalds's avatar
Linus Torvalds committed
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
		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
 *
1106
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1107
 */
1108
int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, unsigned int cond,
Linus Torvalds's avatar
Linus Torvalds committed
1109
1110
1111
1112
			int var,
			snd_pcm_hw_rule_func_t func, void *private,
			int dep, ...)
{
1113
1114
	struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
	struct snd_pcm_hw_rule *c;
Linus Torvalds's avatar
Linus Torvalds committed
1115
1116
1117
1118
	unsigned int k;
	va_list args;
	va_start(args, dep);
	if (constrs->rules_num >= constrs->rules_all) {
1119
		struct snd_pcm_hw_rule *new;
Linus Torvalds's avatar
Linus Torvalds committed
1120
1121
		unsigned int new_rules = constrs->rules_all + 16;
		new = kcalloc(new_rules, sizeof(*c), GFP_KERNEL);
1122
1123
		if (!new) {
			va_end(args);
Linus Torvalds's avatar
Linus Torvalds committed
1124
			return -ENOMEM;
1125
		}
Linus Torvalds's avatar
Linus Torvalds committed
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
		if (constrs->rules) {
			memcpy(new, constrs->rules,
			       constrs->rules_num * sizeof(*c));
			kfree(constrs->rules);
		}
		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) {
1141
1142
		if (snd_BUG_ON(k >= ARRAY_SIZE(c->deps))) {
			va_end(args);
1143
			return -EINVAL;
1144
		}
Linus Torvalds's avatar
Linus Torvalds committed
1145
1146
1147
1148
1149
1150
1151
1152
		c->deps[k++] = dep;
		if (dep < 0)
			break;
		dep = va_arg(args, int);
	}
	constrs->rules_num++;
	va_end(args);
	return 0;
1153
}
Linus Torvalds's avatar
Linus Torvalds committed
1154

1155
1156
EXPORT_SYMBOL(snd_pcm_hw_rule_add);

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

/**
1180
 * snd_pcm_hw_constraint_mask64 - apply the given bitmap mask constraint
Takashi Iwai's avatar
Takashi Iwai committed
1181
1182
1183
1184
 * @runtime: PCM runtime instance
 * @var: hw_params variable to apply the mask
 * @mask: the 64bit bitmap mask
 *
1185
 * Apply the constraint of the given bitmap mask to a 64-bit mask parameter.
1186
1187
 *
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1188
 */
1189
int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
Linus Torvalds's avatar
Linus Torvalds committed
1190
1191
				 u_int64_t mask)
{
1192
1193
	struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
	struct snd_mask *maskp = constrs_mask(constrs, var);
Linus Torvalds's avatar
Linus Torvalds committed
1194
1195
1196
1197
1198
1199
1200
	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;
}
1201
EXPORT_SYMBOL(snd_pcm_hw_constraint_mask64);
Linus Torvalds's avatar
Linus Torvalds committed
1202
1203

/**
1204
 * snd_pcm_hw_constraint_integer - apply an integer constraint to an interval
Takashi Iwai's avatar
Takashi Iwai committed
1205
1206
1207
1208
 * @runtime: PCM runtime instance
 * @var: hw_params variable to apply the integer constraint
 *
 * Apply the constraint of integer to an interval parameter.
1209
1210
1211
 *
 * 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
1212
 */
1213
int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var)
Linus Torvalds's avatar
Linus Torvalds committed
1214
{
1215
	struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
Linus Torvalds's avatar
Linus Torvalds committed
1216
1217
1218
	return snd_interval_setinteger(constrs_interval(constrs, var));
}

1219
1220
EXPORT_SYMBOL(snd_pcm_hw_constraint_integer);

Linus Torvalds's avatar
Linus Torvalds committed
1221
/**
1222
 * snd_pcm_hw_constraint_minmax - apply a min/max range constraint to an interval
Takashi Iwai's avatar
Takashi Iwai committed
1223
1224
1225
1226
1227
1228
 * @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.
1229
1230
1231
 *
 * 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
1232
 */
1233
int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
Linus Torvalds's avatar
Linus Torvalds committed
1234
1235
				 unsigned int min, unsigned int max)
{
1236
1237
	struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints;
	struct snd_interval t;
Linus Torvalds's avatar
Linus Torvalds committed
1238
1239
1240
1241
1242
1243
1244
	t.min = min;
	t.max = max;
	t.openmin = t.openmax = 0;
	t.integer = 0;
	return snd_interval_refine(constrs_interval(constrs, var), &t);
}

1245
1246
EXPORT_SYMBOL(snd_pcm_hw_constraint_minmax);

1247
1248
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
1249
{
1250
	struct snd_pcm_hw_constraint_list *list = rule->private;
Linus Torvalds's avatar
Linus Torvalds committed
1251
1252
1253
1254
1255
	return snd_interval_list(hw_param_interval(params, rule->var), list->count, list->list, list->mask);
}		


/**
1256
 * snd_pcm_hw_constraint_list - apply a list of constraints to a parameter
Takashi Iwai's avatar
Takashi Iwai committed
1257
1258
1259
1260
1261
1262
 * @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.
1263
1264
 *
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1265
 */
1266
int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
Linus Torvalds's avatar
Linus Torvalds committed
1267
1268
			       unsigned int cond,
			       snd_pcm_hw_param_t var,
1269
			       const struct snd_pcm_hw_constraint_list *l)
Linus Torvalds's avatar
Linus Torvalds committed
1270
1271
{
	return snd_pcm_hw_rule_add(runtime, cond, var,
1272
				   snd_pcm_hw_rule_list, (void *)l,
Linus Torvalds's avatar
Linus Torvalds committed
1273
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
	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
				  struct snd_pcm_hw_constraint_ratnums *r)
Linus Torvalds's avatar
Linus Torvalds committed
1337
1338
1339
1340
1341
1342
{
	return snd_pcm_hw_rule_add(runtime, cond, var,
				   snd_pcm_hw_rule_ratnums, r,
				   var, -1);
}

1343
1344
EXPORT_SYMBOL(snd_pcm_hw_constraint_ratnums);

1345
1346
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
1347
{
1348
	struct snd_pcm_hw_constraint_ratdens *r = rule->private;
Linus Torvalds's avatar
Linus Torvalds committed
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
	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;
}

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

1378
1379
EXPORT_SYMBOL(snd_pcm_hw_constraint_ratdens);

1380
1381
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
1382
1383
1384
1385
{
	unsigned int l = (unsigned long) rule->private;
	int width = l & 0xffff;
	unsigned int msbits = l >> 16;
1386
	struct snd_interval *i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS);
1387
1388
1389
1390
1391
1392

	if (!snd_interval_single(i))
		return 0;

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

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

/**
1399
 * snd_pcm_hw_constraint_msbits - add a hw constraint msbits rule
Takashi Iwai's avatar
Takashi Iwai committed
1400
1401
1402
1403
 * @runtime: PCM runtime instance
 * @cond: condition bits
 * @width: sample bits width
 * @msbits: msbits width
1404
 *
1405
1406
1407
1408
1409
 * 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.
 *
1410
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1411
 */
1412
int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime, 
Linus Torvalds's avatar
Linus Torvalds committed
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
				 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);
}

1424
1425
EXPORT_SYMBOL(snd_pcm_hw_constraint_msbits);

1426
1427
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
1428
1429
{
	unsigned long step = (unsigned long) rule->private;
1430
	return snd_interval_step(hw_param_interval(params, rule->var), step);
Linus Torvalds's avatar
Linus Torvalds committed
1431
1432
1433
}

/**
1434
 * snd_pcm_hw_constraint_step - add a hw constraint step rule
Takashi Iwai's avatar
Takashi Iwai committed
1435
1436
1437
1438
 * @runtime: PCM runtime instance
 * @cond: condition bits
 * @var: hw_params variable to apply the step constraint
 * @step: step size
1439
1440
 *
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1441
 */
1442
int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
Linus Torvalds's avatar
Linus Torvalds committed
1443
1444
1445
1446
1447
1448
1449
1450
1451
			       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);
}

1452
1453
EXPORT_SYMBOL(snd_pcm_hw_constraint_step);

1454
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
1455
{
1456
	static unsigned int pow2_sizes[] = {
Linus Torvalds's avatar
Linus Torvalds committed
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
		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);
}		

/**
1467
 * snd_pcm_hw_constraint_pow2 - add a hw constraint power-of-2 rule
Takashi Iwai's avatar
Takashi Iwai committed
1468
1469
1470
 * @runtime: PCM runtime instance
 * @cond: condition bits
 * @var: hw_params variable to apply the power-of-2 constraint
1471
1472
 *
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1473
 */
1474
int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
Linus Torvalds's avatar
Linus Torvalds committed
1475
1476
1477
1478
1479
1480
1481
1482
			       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);
}

1483
1484
EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2);

1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
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
1499
1500
 *
 * Return: Zero if successful, or a negative error code on failure.
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
 */
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);

1513
static void _snd_pcm_hw_param_any(struct snd_pcm_hw_params *params,
1514
				  snd_pcm_hw_param_t var)
Linus Torvalds's avatar
Linus Torvalds committed
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
{
	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();
}

1531
void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params)
Linus Torvalds's avatar
Linus Torvalds committed
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
{
	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;
}

1542
EXPORT_SYMBOL(_snd_pcm_hw_params_any);
Linus Torvalds's avatar
Linus Torvalds committed
1543
1544

/**
1545
 * snd_pcm_hw_param_value - return @params field @var value
Takashi Iwai's avatar
Takashi Iwai committed
1546
1547
 * @params: the hw_params instance
 * @var: parameter to retrieve
1548
 * @dir: pointer to the direction (-1,0,1) or %NULL
Linus Torvalds's avatar
Linus Torvalds committed
1549
 *
1550
1551
 * 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
1552
 */
1553
1554
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
1555
1556
{
	if (hw_is_mask(var)) {
1557
		const struct snd_mask *mask = hw_param_mask_c(params, var);
Linus Torvalds's avatar
Linus Torvalds committed
1558
1559
1560
1561
1562
1563
1564
		if (!snd_mask_single(mask))
			return -EINVAL;
		if (dir)
			*dir = 0;
		return snd_mask_value(mask);
	}
	if (hw_is_interval(var)) {
1565
		const struct snd_interval *i = hw_param_interval_c(params, var);
Linus Torvalds's avatar
Linus Torvalds committed
1566
1567
1568
1569
1570
1571
1572
1573
1574
		if (!snd_interval_single(i))
			return -EINVAL;
		if (dir)
			*dir = i->openmin;
		return snd_interval_value(i);
	}
	return -EINVAL;
}

1575
EXPORT_SYMBOL(snd_pcm_hw_param_value);
Linus Torvalds's avatar
Linus Torvalds committed
1576

1577
void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params,
Linus Torvalds's avatar
Linus Torvalds committed
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
				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();
	}
}

1593
EXPORT_SYMBOL(_snd_pcm_hw_param_setempty);
Linus Torvalds's avatar
Linus Torvalds committed
1594

1595
static int _snd_pcm_hw_param_first(struct snd_pcm_hw_params *params,
1596
				   snd_pcm_hw_param_t var)
Linus Torvalds's avatar
Linus Torvalds committed
1597
1598
1599
1600
1601
1602
{
	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));
1603
	else
Linus Torvalds's avatar
Linus Torvalds committed
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
		return -EINVAL;
	if (changed) {
		params->cmask |= 1 << var;
		params->rmask |= 1 << var;
	}
	return changed;
}


/**
1614
 * snd_pcm_hw_param_first - refine config space and return minimum value
Takashi Iwai's avatar
Takashi Iwai committed
1615
1616
1617
 * @pcm: PCM instance
 * @params: the hw_params instance
 * @var: parameter to retrieve
1618
 * @dir: pointer to the direction (-1,0,1) or %NULL
Linus Torvalds's avatar
Linus Torvalds committed
1619
 *
1620
 * Inside configuration space defined by @params remove from @var all
Linus Torvalds's avatar
Linus Torvalds committed
1621
 * values > minimum. Reduce configuration space accordingly.
1622
1623
 *
 * Return: The minimum, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1624
 */
1625
1626
1627
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
1628
1629
1630
1631
1632
1633
{
	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);
1634
1635
		if (snd_BUG_ON(err < 0))
			return err;
Linus Torvalds's avatar
Linus Torvalds committed
1636
1637
1638
1639
	}
	return snd_pcm_hw_param_value(params, var, dir);
}

1640
1641
EXPORT_SYMBOL(snd_pcm_hw_param_first);

1642
static int _snd_pcm_hw_param_last(struct snd_pcm_hw_params *params,
1643
				  snd_pcm_hw_param_t var)
Linus Torvalds's avatar
Linus Torvalds committed
1644
1645
1646
1647
1648
1649
{
	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));
1650
	else
Linus Torvalds's avatar
Linus Torvalds committed
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
		return -EINVAL;
	if (changed) {
		params->cmask |= 1 << var;
		params->rmask |= 1 << var;
	}
	return changed;
}


/**
1661
 * snd_pcm_hw_param_last - refine config space and return maximum value
Takashi Iwai's avatar
Takashi Iwai committed
1662
1663
1664
 * @pcm: PCM instance
 * @params: the hw_params instance
 * @var: parameter to retrieve
1665
 * @dir: pointer to the direction (-1,0,1) or %NULL
Linus Torvalds's avatar
Linus Torvalds committed
1666
 *
1667
 * Inside configuration space defined by @params remove from @var all
Linus Torvalds's avatar
Linus Torvalds committed
1668
 * values < maximum. Reduce configuration space accordingly.
1669
1670
 *
 * Return: The maximum, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1671
 */
1672
1673
1674
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
1675
1676
1677
1678
1679
1680
{
	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);
1681
1682
		if (snd_BUG_ON(err < 0))
			return err;
Linus Torvalds's avatar
Linus Torvalds committed
1683
1684
1685
1686
	}
	return snd_pcm_hw_param_value(params, var, dir);
}

1687
EXPORT_SYMBOL(snd_pcm_hw_param_last);
Linus Torvalds's avatar
Linus Torvalds committed
1688
1689

/**
1690
 * snd_pcm_hw_param_choose - choose a configuration defined by @params
Takashi Iwai's avatar
Takashi Iwai committed
1691
1692
 * @pcm: PCM instance
 * @params: the hw_params instance
Linus Torvalds's avatar
Linus Torvalds committed
1693
 *
1694
 * Choose one configuration from configuration space defined by @params.
Linus Torvalds's avatar
Linus Torvalds committed
1695
1696
1697
 * The configuration chosen is that obtained fixing in this order:
 * first access, first format, first subformat, min channels,
 * min rate, min period time, max buffer size, min tick time
1698
1699
 *
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1700
 */
1701
1702
int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm,
			     struct snd_pcm_hw_params *params)
Linus Torvalds's avatar
Linus Torvalds committed
1703
{
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
	static int vars[] = {
		SNDRV_PCM_HW_PARAM_ACCESS,
		SNDRV_PCM_HW_PARAM_FORMAT,
		SNDRV_PCM_HW_PARAM_SUBFORMAT,
		SNDRV_PCM_HW_PARAM_CHANNELS,
		SNDRV_PCM_HW_PARAM_RATE,
		SNDRV_PCM_HW_PARAM_PERIOD_TIME,
		SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
		SNDRV_PCM_HW_PARAM_TICK_TIME,
		-1
	};
	int err, *v;
Linus Torvalds's avatar
Linus Torvalds committed
1716

1717
1718
1719
1720
1721
	for (v = vars; *v != -1; v++) {
		if (*v != SNDRV_PCM_HW_PARAM_BUFFER_SIZE)
			err = snd_pcm_hw_param_first(pcm, params, *v, NULL);
		else
			err = snd_pcm_hw_param_last(pcm, params, *v, NULL);
1722
1723
		if (snd_BUG_ON(err < 0))
			return err;
1724
	}
Linus Torvalds's avatar
Linus Torvalds committed
1725
1726
1727
	return 0;
}

1728
static int snd_pcm_lib_ioctl_reset(struct snd_pcm_substream *substream,
Linus Torvalds's avatar
Linus Torvalds committed
1729
1730
				   void *arg)
{
1731
	struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds's avatar
Linus Torvalds committed
1732
1733
1734
1735
1736
	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;
1737
	else {
Linus Torvalds's avatar
Linus Torvalds committed
1738
		runtime->status->hw_ptr = 0;
1739
1740
		runtime->hw_ptr_wrap = 0;
	}
Linus Torvalds's avatar
Linus Torvalds committed
1741
1742
1743
1744
	snd_pcm_stream_unlock_irqrestore(substream, flags);
	return 0;
}

1745
static int snd_pcm_lib_ioctl_channel_info(struct snd_pcm_substream *substream,
Linus Torvalds's avatar
Linus Torvalds committed
1746
1747
					  void *arg)
{
1748
1749
	struct snd_pcm_channel_info *info = arg;
	struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds's avatar
Linus Torvalds committed
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
	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;
}

1780
1781
1782
1783
1784
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;
1785
1786
	int channels;
	ssize_t frame_size;
1787
1788
1789
1790
1791

	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);
1792
1793
1794
		frame_size = snd_pcm_format_size(format, channels);
		if (frame_size > 0)
			params->fifo_size /= (unsigned)frame_size;
1795
1796
1797
1798
	}
	return 0;
}

Linus Torvalds's avatar
Linus Torvalds committed
1799
1800
1801
1802
1803
1804
1805
1806
1807
/**
 * 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.
 *
1808
 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds's avatar
Linus Torvalds committed
1809
 */
1810
int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
Linus Torvalds's avatar
Linus Torvalds committed
1811
1812
1813
1814
1815
1816
1817
1818
1819
		      unsigned int cmd, void *arg)
{
	switch (cmd) {
	case SNDRV_PCM_IOCTL1_INFO:
		return 0;
	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);
1820
1821
	case SNDRV_PCM_IOCTL1_FIFO_SIZE:
		return snd_pcm_lib_ioctl_fifo_size(substream, arg);
Linus Torvalds's avatar
Linus Torvalds committed
1822
1823
1824
1825
	}
	return -ENXIO;
}

1826
1827
EXPORT_SYMBOL(snd_pcm_lib_ioctl);

Linus Torvalds's avatar
Linus Torvalds committed
1828
1829
1830
1831
1832
1833
/**
 * 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
1834
 * pointer, wake up sleepers, etc.
Linus Torvalds's avatar
Linus Torvalds committed
1835
1836
1837
1838
 *
 * Even if more than one periods have elapsed since the last call, you
 * have to call this only once.
 */
1839
void snd_pcm_period_elapsed(struct snd_pcm_substream *substream)
Linus Torvalds's avatar
Linus Torvalds committed
1840
{
1841
	struct snd_pcm_runtime *runtime;
Linus Torvalds's avatar
Linus Torvalds committed
1842
1843
	unsigned long flags;

1844
1845
	if (PCM_RUNTIME_CHECK(substream))
		return;
Linus Torvalds's avatar
Linus Torvalds committed
1846
1847
1848
1849
1850
1851
1852
	runtime = substream->runtime;

	if (runtime->transfer_ack_begin)
		runtime->transfer_ack_begin(substream);

	snd_pcm_stream_lock_irqsave(substream, flags);
	if (!snd_pcm_running(substream) ||
1853
	    snd_pcm_update_hw_ptr0(substream, 1) < 0)
Linus Torvalds's avatar
Linus Torvalds committed
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
		goto _end;

	if (substream->timer_running)
		snd_timer_interrupt(substream->timer, 1);
 _end:
	snd_pcm_stream_unlock_irqrestore(substream, flags);
	if (runtime->transfer_ack_end)
		runtime->transfer_ack_end(substream);
	kill_fasync(&runtime->fasync, SIGIO, POLL_IN);
}

1865
1866
EXPORT_SYMBOL(snd_pcm_period_elapsed);

1867
1868
1869
1870
1871
1872
/*
 * 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.
 */
1873
static int wait_for_avail(struct snd_pcm_substream *substream,
1874
1875
1876
1877
1878
1879
1880
			      snd_pcm_uframes_t *availp)
{
	struct snd_pcm_runtime *runtime = substream->runtime;
	int is_playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
	wait_queue_t wait;
	int err = 0;
	snd_pcm_uframes_t avail = 0;
1881
1882
	long wait_time, tout;

1883
1884
1885
1886
	init_waitqueue_entry(&wait, current);
	set_current_state(TASK_INTERRUPTIBLE);
	add_wait_queue(&runtime->tsleep, &wait);

1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
	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);
	}
1897

1898
1899
1900
1901
1902
	for (;;) {
		if (signal_pending(current)) {
			err = -ERESTARTSYS;
			break;
		}
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916

		/*
		 * 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.
		 */
		if (is_playback)
			avail = snd_pcm_playback_avail(runtime);
		else
			avail = snd_pcm_capture_avail(runtime);
		if (avail >= runtime->twake)
			break;
1917
		snd_pcm_stream_unlock_irq(substream);
1918
1919
1920

		tout = schedule_timeout(wait_time);

1921
		snd_pcm_stream_lock_irq(substream);
1922
		set_current_state(TASK_INTERRUPTIBLE);
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
		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;
1941
1942
		case SNDRV_PCM_STATE_PAUSED:
			continue;
1943
1944
		}
		if (!tout) {
1945
1946
1947
			pcm_dbg(substream->pcm,
				"%s write error (DMA or IRQ trouble?)\n",
				is_playback ? "playback" : "capture");
1948
1949
1950
1951
1952
			err = -EIO;
			break;
		}
	}
 _endloop:
1953
	set_current_state(TASK_RUNNING);
1954
	remove_wait_queue(&runtime->tsleep, &wait);
1955
1956
1957
1958
	*availp = avail;
	return err;
}
	
1959
static int snd_pcm_lib_write_transfer(struct snd_pcm_substream *substream,
Linus Torvalds's avatar
Linus Torvalds committed
1960
1961
1962
1963
				      unsigned int hwoff,
				      unsigned long data, unsigned int off,
				      snd_pcm_uframes_t frames)
{
1964
	struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds's avatar
Linus Torvalds committed
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
	int err;
	char __user *buf = (char __user *) data + frames_to_bytes(runtime, off);
	if (substream->ops->copy) {
		if ((err = substream->ops->copy(substream, -1, hwoff, buf, frames)) < 0)
			return err;
	} else {
		char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, hwoff);
		if (copy_from_user(hwbuf, buf, frames_to_bytes(runtime, frames)))
			return -EFAULT;
	}
	return 0;
}
 
1978
typedef int (*transfer_f)(struct snd_pcm_substream *substream, unsigned int hwoff,
Linus Torvalds's avatar
Linus Torvalds committed
1979
1980
1981
			  unsigned long data, unsigned int off,
			  snd_pcm_uframes_t size);

1982
static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream, 
Linus Torvalds's avatar
Linus Torvalds committed
1983
1984
1985
1986
1987
					    unsigned long data,
					    snd_pcm_uframes_t size,
					    int nonblock,
					    transfer_f transfer)
{
1988
	struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds's avatar
Linus Torvalds committed
1989
1990
	snd_pcm_uframes_t xfer = 0;
	snd_pcm_uframes_t offset = 0;
1991
	snd_pcm_uframes_t avail;
Linus Torvalds's avatar
Linus Torvalds committed
1992
1993
1994
1995
1996
1997
1998
1999
2000
	int err = 0;

	if (size == 0)
		return 0;

	snd_pcm_stream_lock_irq(substream);
	switch (runtime->status->state) {
	case SNDRV_PCM_STATE_PREPARED:
	case SNDRV_PCM_STATE_RUNNING:
For faster browsing, not all history is shown. View entire blame