sound/soc/codecs/max98396.c

Source file repositories/reference/linux-study-clean/sound/soc/codecs/max98396.c

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/max98396.c
Extension
.c
Size
63439 bytes
Lines
1915
Domain
Driver Families
Bucket
sound/soc
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (format != (reg & format_mask)) {
			update = true;
		} else {
			ret = regmap_read(max98396->regmap,
					  MAX98396_R2042_PCM_CLK_SETUP, &reg);
			if (ret < 0)
				return -EINVAL;
			if (bclk_pol != (reg & MAX98396_PCM_MODE_CFG_BCLKEDGE))
				update = true;
		}
		/* GLOBAL_EN OFF prior to pcm mode, clock configuration change */
		if (update)
			max98396_global_enable_onoff(max98396->regmap, false);
	}

	regmap_update_bits(max98396->regmap,
			   MAX98396_R2041_PCM_MODE_CFG,
			   format_mask, format);

	regmap_update_bits(max98396->regmap,
			   MAX98396_R2042_PCM_CLK_SETUP,
			   MAX98396_PCM_MODE_CFG_BCLKEDGE,
			   bclk_pol);

	if (status && update)
		max98396_global_enable_onoff(max98396->regmap, true);

	return 0;
}

#define MAX98396_BSEL_32	0x2
#define MAX98396_BSEL_48	0x3
#define MAX98396_BSEL_64	0x4
#define MAX98396_BSEL_96	0x5
#define MAX98396_BSEL_128	0x6
#define MAX98396_BSEL_192	0x7
#define MAX98396_BSEL_256	0x8
#define MAX98396_BSEL_384	0x9
#define MAX98396_BSEL_512	0xa
#define MAX98396_BSEL_320	0xb
#define MAX98396_BSEL_250	0xc
#define MAX98396_BSEL_125	0xd

/* Refer to table 5 in the datasheet */
static const struct max98396_pcm_config {
	int in, out, width, bsel, max_sr;
} max98396_pcm_configs[] = {
	{ .in = 2,  .out = 4,  .width = 16, .bsel = MAX98396_BSEL_32,  .max_sr = 192000 },
	{ .in = 2,  .out = 6,  .width = 24, .bsel = MAX98396_BSEL_48,  .max_sr = 192000 },
	{ .in = 2,  .out = 8,  .width = 32, .bsel = MAX98396_BSEL_64,  .max_sr = 192000 },
	{ .in = 3,  .out = 15, .width = 32, .bsel = MAX98396_BSEL_125, .max_sr = 192000 },
	{ .in = 4,  .out = 8,  .width = 16, .bsel = MAX98396_BSEL_64,  .max_sr = 192000 },
	{ .in = 4,  .out = 12, .width = 24, .bsel = MAX98396_BSEL_96,  .max_sr = 192000 },
	{ .in = 4,  .out = 16, .width = 32, .bsel = MAX98396_BSEL_128, .max_sr = 192000 },
	{ .in = 5,  .out = 15, .width = 24, .bsel = MAX98396_BSEL_125, .max_sr = 192000 },
	{ .in = 7,  .out = 15, .width = 16, .bsel = MAX98396_BSEL_125, .max_sr = 192000 },
	{ .in = 2,  .out = 4,  .width = 16, .bsel = MAX98396_BSEL_32,  .max_sr = 96000  },
	{ .in = 2,  .out = 6,  .width = 24, .bsel = MAX98396_BSEL_48,  .max_sr = 96000  },
	{ .in = 2,  .out = 8,  .width = 32, .bsel = MAX98396_BSEL_64,  .max_sr = 96000  },
	{ .in = 3,  .out = 15, .width = 32, .bsel = MAX98396_BSEL_125, .max_sr = 96000  },
	{ .in = 4,  .out = 8,  .width = 16, .bsel = MAX98396_BSEL_64,  .max_sr = 96000  },
	{ .in = 4,  .out = 12, .width = 24, .bsel = MAX98396_BSEL_96,  .max_sr = 96000  },
	{ .in = 4,  .out = 16, .width = 32, .bsel = MAX98396_BSEL_128, .max_sr = 96000  },
	{ .in = 5,  .out = 15, .width = 24, .bsel = MAX98396_BSEL_125, .max_sr = 96000  },
	{ .in = 7,  .out = 15, .width = 16, .bsel = MAX98396_BSEL_125, .max_sr = 96000  },
	{ .in = 7,  .out = 31, .width = 32, .bsel = MAX98396_BSEL_250, .max_sr = 96000  },
	{ .in = 8,  .out = 16, .width = 16, .bsel = MAX98396_BSEL_128, .max_sr = 96000  },
	{ .in = 8,  .out = 24, .width = 24, .bsel = MAX98396_BSEL_192, .max_sr = 96000  },
	{ .in = 8,  .out = 32, .width = 32, .bsel = MAX98396_BSEL_256, .max_sr = 96000  },
	{ .in = 10, .out = 31, .width = 24, .bsel = MAX98396_BSEL_250, .max_sr = 96000  },
	{ .in = 15, .out = 31, .width = 16, .bsel = MAX98396_BSEL_250, .max_sr = 96000  },
	{ .in = 16, .out = 32, .width = 16, .bsel = MAX98396_BSEL_256, .max_sr = 96000  },
	{ .in = 7,  .out = 31, .width = 32, .bsel = MAX98396_BSEL_250, .max_sr = 48000  },
	{ .in = 10, .out = 31, .width = 24, .bsel = MAX98396_BSEL_250, .max_sr = 48000  },
	{ .in = 10, .out = 40, .width = 32, .bsel = MAX98396_BSEL_320, .max_sr = 48000  },
	{ .in = 15, .out = 31, .width = 16, .bsel = MAX98396_BSEL_250, .max_sr = 48000  },
	{ .in = 16, .out = 48, .width = 24, .bsel = MAX98396_BSEL_384, .max_sr = 48000  },
	{ .in = 16, .out = 64, .width = 32, .bsel = MAX98396_BSEL_512, .max_sr = 48000  },
};

static int max98396_pcm_config_index(int in_slots, int out_slots, int width)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(max98396_pcm_configs); i++) {
		const struct max98396_pcm_config *c = &max98396_pcm_configs[i];

		if (in_slots == c->in && out_slots <= c->out && width == c->width)
			return i;
	}

Annotation

Implementation Notes