File: hdsploader.c

package info (click to toggle)
alsa-tools 1.0.13-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,432 kB
  • ctags: 5,011
  • sloc: ansic: 25,566; cpp: 13,672; sh: 10,786; pascal: 1,140; asm: 1,053; xml: 988; makefile: 689
file content (135 lines) | stat: -rw-r--r-- 3,655 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 *   hdsploader - firmware loader for RME Hammerfall DSP cards
 *    
 *   Copyright (C) 2003 Thomas Charbonnel (thomas@undata.org)
 *    
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <stdio.h>
#include <stdlib.h>
#include <endian.h>
#include <sys/ioctl.h>
#include <alsa/asoundlib.h>
#include <alsa/sound/hdsp.h>

static u_int32_t code[24413];

int read_bin_file(u_int32_t *array, const char *filename)
{
	FILE *out;

	if ((out = fopen(filename, "r")) == NULL) {
		fprintf(stderr, "Unable to open file '%s' for reading\n", filename);
		return -1;
	}
	if (fread(array, 4, 24413, out) != 24413) {
		fclose(out);
		return -1;
	}
	fclose(out);

	return 0;
}

void upload_firmware(int card)
{
    int err;
    snd_hwdep_t *hw;
    snd_hwdep_info_t *info;
    char card_name[6];
    hdsp_version_t version;
    
    hdsp_firmware_t firmware;
    
    snd_hwdep_info_alloca(&info);
    snprintf(card_name, 6, "hw:%i", card);

    printf("Upload firmware for card %s\n", card_name);			    

    if ((err = snd_hwdep_open(&hw, card_name, SND_HWDEP_OPEN_DUPLEX)) != 0) {
	fprintf(stderr, "Error opening hwdep device on card %s.\n", card_name);
	return; 
    }

    if ((err = snd_hwdep_ioctl(hw, SNDRV_HDSP_IOCTL_GET_VERSION, &version)) < 0) {
	fprintf(stderr, "Hwdep ioctl error on card %s : %s.\n", card_name, snd_strerror(err));
	snd_hwdep_close(hw);
	return;
    }

    firmware.firmware_data = code;
    switch (version.io_type) {
    case Multiface:
	if (version.firmware_rev == 0xa) {
	    err = read_bin_file(code, DATAPATH "/multiface_firmware.bin");
	} else {
	    err = read_bin_file(code, DATAPATH "/multiface_firmware_rev11.bin");
	}
	break;
    case Digiface:
	if (version.firmware_rev == 0xa) {
	    err = read_bin_file(code, DATAPATH "/digiface_firmware.bin");
	} else {
	    err = read_bin_file(code, DATAPATH "/digiface_firmware_rev11.bin");
	}
	break;
    default:
	fprintf(stderr, "Unknown iobox or firmware revision\n");
	snd_hwdep_close(hw);
	return;
    }	
    if (err < 0)
    	return;
    
    if ((err = snd_hwdep_ioctl(hw, SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE, &firmware)) < 0) {
	fprintf(stderr, "Hwdep ioctl error on card %s : %s.\n", card_name, snd_strerror(err));
	snd_hwdep_close(hw);
	return;
    }

    printf("Firmware uploaded for card %s\n", card_name);
    
    snd_hwdep_close(hw);

    return;
}

int main(int argc, char **argv)
{
    char *name;
    int card;

    snd_ctl_card_info_t *info;
    snd_pcm_info_t *pcminfo;
    
    snd_ctl_card_info_alloca(&info);
    snd_pcm_info_alloca(&pcminfo);    
    card = -1;
    printf("hdsploader - firmware loader for RME Hammerfall DSP cards\n");
    printf("Looking for HDSP + Multiface or Digiface cards :\n");
    while (snd_card_next(&card) >= 0) {
	if (card < 0) {
	    break;
	} else {
	    snd_card_get_longname(card, &name);
	    printf("Card %d : %s\n", card, name);
	    if (!strncmp(name, "RME Hammerfall DSP", 18)) {
		upload_firmware(card);
	    } 
	}
    }
    return 0;    
}