Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * bebob_proc.c - a part of driver for BeBoB based devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2013-2014 Takashi Sakamoto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "./bebob.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) /* contents of information register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) struct hw_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 	u64 manufacturer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 	u32 protocol_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	u32 bld_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	u32 guid[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	u32 model_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	u32 model_rev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	u64 fw_date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	u64 fw_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	u32 fw_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	u32 fw_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	u32 base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	u32 max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	u64 bld_date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	u64 bld_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /* may not used in product
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	u64 dbg_date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	u64 dbg_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	u32 dbg_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	u32 dbg_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) proc_read_hw_info(struct snd_info_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		  struct snd_info_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct snd_bebob *bebob = entry->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct hw_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	info = kzalloc(sizeof(struct hw_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (info == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (snd_bebob_read_block(bebob->unit, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 				   info, sizeof(struct hw_info)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	snd_iprintf(buffer, "Manufacturer:\t%.8s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		    (char *)&info->manufacturer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	snd_iprintf(buffer, "Protocol Ver:\t%d\n", info->protocol_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	snd_iprintf(buffer, "Build Ver:\t%d\n", info->bld_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	snd_iprintf(buffer, "GUID:\t\t0x%.8X%.8X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		    info->guid[0], info->guid[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	snd_iprintf(buffer, "Model ID:\t0x%02X\n", info->model_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	snd_iprintf(buffer, "Model Rev:\t%d\n", info->model_rev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	snd_iprintf(buffer, "Firmware Date:\t%.8s\n", (char *)&info->fw_date);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	snd_iprintf(buffer, "Firmware Time:\t%.8s\n", (char *)&info->fw_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	snd_iprintf(buffer, "Firmware ID:\t0x%X\n", info->fw_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	snd_iprintf(buffer, "Firmware Ver:\t%d\n", info->fw_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	snd_iprintf(buffer, "Base Addr:\t0x%X\n", info->base_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	snd_iprintf(buffer, "Max Size:\t%d\n", info->max_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	snd_iprintf(buffer, "Loader Date:\t%.8s\n", (char *)&info->bld_date);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	snd_iprintf(buffer, "Loader Time:\t%.8s\n", (char *)&info->bld_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) proc_read_meters(struct snd_info_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		 struct snd_info_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct snd_bebob *bebob = entry->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	const struct snd_bebob_meter_spec *spec = bebob->spec->meter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	u32 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	unsigned int i, c, channels, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (spec == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	channels = spec->num * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	size = channels * sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	buf = kmalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (buf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (spec->get(bebob, buf, size) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	for (i = 0, c = 1; i < channels; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		snd_iprintf(buffer, "%s %d:\t%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			    spec->labels[i / 2], c++, buf[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if ((i + 1 < channels - 1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		    (strcmp(spec->labels[i / 2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			    spec->labels[(i + 1) / 2]) != 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			c = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) proc_read_formation(struct snd_info_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		struct snd_info_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct snd_bebob *bebob = entry->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct snd_bebob_stream_formation *formation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	snd_iprintf(buffer, "Output Stream from device:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	snd_iprintf(buffer, "\tRate\tPCM\tMIDI\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	formation = bebob->tx_stream_formations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		snd_iprintf(buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			    "\t%d\t%d\t%d\n", snd_bebob_rate_table[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			    formation[i].pcm, formation[i].midi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	snd_iprintf(buffer, "Input Stream to device:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	snd_iprintf(buffer, "\tRate\tPCM\tMIDI\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	formation = bebob->rx_stream_formations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		snd_iprintf(buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			    "\t%d\t%d\t%d\n", snd_bebob_rate_table[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			    formation[i].pcm, formation[i].midi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) proc_read_clock(struct snd_info_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		struct snd_info_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	static const char *const clk_labels[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		"Internal",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		"External",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		"SYT-Match",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct snd_bebob *bebob = entry->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	const struct snd_bebob_rate_spec *rate_spec = bebob->spec->rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	const struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	enum snd_bebob_clock_type src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	unsigned int rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (rate_spec->get(bebob, &rate) >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		snd_iprintf(buffer, "Sampling rate: %d\n", rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (snd_bebob_stream_get_clock_src(bebob, &src) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		if (clk_spec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			snd_iprintf(buffer, "Clock Source: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				    clk_labels[src]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			snd_iprintf(buffer, "Clock Source: %s (MSU-dest: %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				    clk_labels[src], bebob->sync_input_plug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) add_node(struct snd_bebob *bebob, struct snd_info_entry *root, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 void (*op)(struct snd_info_entry *e, struct snd_info_buffer *b))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct snd_info_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	entry = snd_info_create_card_entry(bebob->card, name, root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		snd_info_set_text_ops(entry, bebob, op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) void snd_bebob_proc_init(struct snd_bebob *bebob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct snd_info_entry *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	 * All nodes are automatically removed at snd_card_disconnect(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 * by following to link list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	root = snd_info_create_card_entry(bebob->card, "firewire",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 					  bebob->card->proc_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (root == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	root->mode = S_IFDIR | 0555;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	add_node(bebob, root, "clock", proc_read_clock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	add_node(bebob, root, "firmware", proc_read_hw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	add_node(bebob, root, "formation", proc_read_formation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (bebob->spec->meter != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		add_node(bebob, root, "meter", proc_read_meters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }