2
generate_driver (char *name, conf_t * conf, char *cfg_name, char *cfg_header,
3
char *dirname, char *topdir)
8
char tmp[256], line[256], *p, *s;
10
char *options[MAXOPTS];
11
char *option_desc[MAXOPTS];
15
sprintf (tmp, "target/build/%s.c", name);
16
if ((src = fopen (tmp, "w")) == NULL)
22
fprintf (src, "/*\n");
23
fprintf (src, " * Automatically generated file - do not edit.\n");
24
fprintf (src, " */\n");
26
fprintf (src, "#define DRIVER_NAME\t%s\n", name);
27
fprintf (src, "#define DRIVER_NICK\t\"%s\"\n", name);
28
fprintf (src, "#define DRIVER_PURPOSE\t\"%s\"\n", conf->purpose);
29
fprintf (src, "#define DRIVER_STR_INFO\t%s_str_info\n", name);
30
fprintf (src, "#define DRIVER_ATTACH\t%s_attach\n", name);
31
fprintf (src, "#define DRIVER_DETACH\t%s_detach\n", name);
32
fprintf (src, "#define DRIVER_TYPE\tDRV_%s\n", conf->bus);
36
* Handle driver specific configuration options
39
sprintf (tmp, "%s/.params", dirname);
40
if ((f = fopen (tmp, "r")) != NULL)
42
while (fgets (line, sizeof (line) - 1, f) != NULL)
44
p = line + strlen (line) - 1;
48
fprintf (src, "%s\n", line);
49
if (strncmp (line, "int ", 4) == 0)
51
char *s = line + 4, *p = s;
53
while (*p && *p != '=' && *p != ';')
58
fprintf (stderr, "Too many options for driver '%s' (%d)\n",
63
if (nopts != 0 && *desc != 0)
64
option_desc[nopts - 1] = strdup (desc);
65
option_desc[nopts] = 0;
66
options[nopts++] = strdup (s);
73
while (*s == ' ' || *s == '/' || *s == '*')
87
p = desc + strlen (desc);
88
sprintf (p, "\n\"%s\\n\"", tmp);
95
if (nopts > 0 && *desc != 0)
96
option_desc[nopts - 1] = strdup (desc);
98
if ((f = fopen ("devices.list", "r")) == NULL)
100
perror ("devices.list");
104
if (strcmp (conf->bus, "PCI") == 0)
106
fprintf (src, "#include <linux/mod_devicetable.h>\n\n");
107
fprintf (src, "#include <linux/pci_ids.h>\n\n");
108
fprintf (src, "static struct pci_device_id id_table[] = {\n");
110
while (fgets (line, sizeof (line) - 1, f) != NULL)
113
p = line + strlen (line) - 1;
118
while (*p && *p != '\t')
123
if (strcmp (line, name) != 0)
129
while (*p && *p != '\t')
134
if (strncmp (s, "pci", 3) == 0)
136
if (sscanf (s + 3, "%x,%x", &vendor, &product) != 2)
138
fprintf (stderr, "Bad PCI id %s\n", s);
142
"\t{.vendor=0x%x,\t.device=0x%x,\t.subvendor=PCI_ANY_ID,\t.subdevice=PCI_ANY_ID,\t.class=PCI_CLASS_MULTIMEDIA_AUDIO},\n",
150
fprintf (src, "\t{0}\n");
151
fprintf (src, "};\n");
155
if (strcmp (conf->bus, "USB") == 0)
157
fprintf (src, "#include <linux/mod_devicetable.h>\n\n");
158
fprintf (src, "#undef strcpy\n");
159
fprintf (src, "#define strcpy dummy_strcpy\n");
160
fprintf (src, "#include <linux/usb.h>\n");
161
fprintf (src, "#undef strcpy\n");
162
fprintf (src, "static struct usb_device_id udi_usb_table[] = {\n");
164
while (fgets (line, sizeof (line) - 1, f) != NULL)
167
p = line + strlen (line) - 1;
172
while (*p && *p != '\t')
177
if (strcmp (line, name) != 0)
183
while (*p && *p != '\t')
188
if (strcmp (s, "usbif,class1") == 0)
191
if (strncmp (s, "usbi", 4) == 0)
193
if (sscanf (s + 4, "%x,%x", &vendor, &product) != 2)
195
fprintf (stderr, "Bad USB id %s\n", s);
199
"\t{.match_flags=USB_DEVICE_ID_MATCH_DEVICE,\t.idVendor=0x%x,\t.idProduct=0x%x},\n",
204
if (strncmp (s, "usb", 3) == 0)
206
if (sscanf (s + 3, "%x,%x", &vendor, &product) != 2)
208
fprintf (stderr, "Bad USB id %s\n", s);
212
"\t{.match_flags=USB_DEVICE_ID_MATCH_DEVICE,\t.idVendor=0x%x,\t.idProduct=0x%x},\n",
222
fprintf (src, "\t{match_flags:USB_DEVICE_ID_MATCH_INT_CLASS,\n");
223
fprintf (src, "\tbInterfaceClass: USB_CLASS_AUDIO},\n");
224
fprintf (src, "\t{0}\n");
225
fprintf (src, "};\n");
229
fprintf (src, "#include \"module.inc\"\n");
232
for (i = 0; i < nopts; i++)
234
fprintf (src, "module_param(%s, int, S_IRUGO);\n", options[i]);
235
if (option_desc[i] != NULL)
236
fprintf (src, "MODULE_PARM_DESC(%s, %s);\n", options[i],
244
sprintf (tmp, "%s/%s", dirname, cfg_header);
245
if ((src = fopen (tmp, "w")) == NULL)
251
fprintf (src, "/*\n");
252
fprintf (src, " * Automatically generated file - do not edit.\n");
253
fprintf (src, " */\n");
255
fprintf (src, "#include <oss_config.h>\n");
258
fprintf (src, "#define DRIVER_NAME\t%s\n", name);
259
fprintf (src, "#define DRIVER_NICK\t\"%s\"\n", name);
260
fprintf (src, "#define DRIVER_STR_INFO\t%s_str_info\n", name);
261
fprintf (src, "#define DRIVER_ATTACH\t%s_attach\n", name);
262
fprintf (src, "#define DRIVER_DETACH\t%s_detach\n", name);
263
fprintf (src, "#define DRIVER_TYPE\tDRV_%s\n", conf->bus);
266
fprintf (src, "extern int DRIVER_ATTACH(oss_device_t *ossdev);\n");
267
fprintf (src, "extern int DRIVER_DETACH(oss_device_t *ossdev);\n");