]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/hwinfo/src/hd/parallel.c
13 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 * parallel port device info
16 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
21 static void do_lp(hd_data_t
*hd_data
);
22 static void do_zip(hd_data_t
*hd_data
);
23 static void dump_parallel_data(hd_data_t
*hd_data
, str_list_t
*sl
);
25 void hd_scan_parallel(hd_data_t
*hd_data
)
27 if(!hd_probe_feature(hd_data
, pr_parallel
)) return;
29 hd_data
->module
= mod_parallel
;
32 remove_hd_entries(hd_data
);
34 if(hd_probe_feature(hd_data
, pr_parallel_lp
)) do_lp(hd_data
);
36 if(hd_probe_feature(hd_data
, pr_parallel_zip
)) do_zip(hd_data
);
39 void do_lp(hd_data_t
*hd_data
)
44 char *pp
= NULL
, buf
[256], unix_dev
[] = "/dev/lp0", *s
= NULL
;
45 char *base_class
, *device
, *vendor
, *cmd_set
;
47 str_list_t
*log
= NULL
;
49 PROGRESS(1, 0, "pp mod");
51 for(hd
= hd_data
->hd
; hd
; hd
= hd
->next
) {
52 if(hd
->base_class
.id
== bc_comm
&& hd
->sub_class
.id
== sc_com_par
) break;
55 /* ... if there seems to be a parallel interface, try to load it */
56 if(hd
|| 1) { /* always load it */
57 if(hd_data
->kernel_version
== KERNEL_22
) {
58 unload_module(hd_data
, "parport_probe");
59 probe_module(hd_data
, "parport_probe");
61 unload_module(hd_data
, "lp");
62 unload_module(hd_data
, "parport_pc");
63 probe_module(hd_data
, "parport_pc");
67 for(i
= 0; i
< 3; i
++, unix_dev
[sizeof unix_dev
- 2]++) {
68 PROGRESS(2, 1 + i
, "lp read info");
71 // ##### read modes as well? (e.g: SPP,ECP,ECPEPP,ECPPS2)
72 if(hd_data
->kernel_version
== KERNEL_22
)
73 str_printf(&pp
, 0, PROC_PARPORT_22
"%d/hardware", i
);
75 str_printf(&pp
, 0, PROC_PARPORT_24
"%d/base-addr", i
);
76 sl0
= read_file(pp
, 0, 0);
77 if(!sl0
) continue; /* file doesn't exist -> no parport entry */
78 str_printf(&s
, 0, "%s\n", pp
);
79 add_str_list(&log
, s
);
80 for(sl
= sl0
; sl
; sl
= sl
->next
) {
81 str_printf(&s
, 0, " %s", sl
->str
);
82 add_str_list(&log
, s
);
83 if(hd_data
->kernel_version
== KERNEL_22
) {
84 if(sscanf(sl
->str
, "base: %i", &j
) == 1) port
= j
;
86 if(sscanf(sl
->str
, "%i", &j
) == 1) port
= j
;
91 if(hd_data
->kernel_version
== KERNEL_22
)
92 str_printf(&pp
, 0, PROC_PARPORT_22
"%d/autoprobe", i
);
94 str_printf(&pp
, 0, PROC_PARPORT_24
"%d/autoprobe", i
);
95 sl0
= read_file(pp
, 0, 0);
96 str_printf(&s
, 0, "%s\n", pp
);
97 add_str_list(&log
, s
);
98 base_class
= device
= vendor
= cmd_set
= NULL
;
99 for(sl
= sl0
; sl
; sl
= sl
->next
) {
100 str_printf(&s
, 0, " %s", sl
->str
);
101 add_str_list(&log
, s
);
102 // fprintf(stderr, "str = \"%s\"\n", sl->str);
103 if(sscanf(sl
->str
, "CLASS: %255[^\n;]", buf
) == 1) base_class
= new_str(buf
);
104 if(sscanf(sl
->str
, "MODEL: %255[^\n;]", buf
) == 1) device
= new_str(buf
);
105 if(sscanf(sl
->str
, "MANUFACTURER: %255[^\n;]", buf
) == 1) vendor
= new_str(buf
);
106 if(sscanf(sl
->str
, "COMMAND SET: %255[^\n;]", buf
) == 1) cmd_set
= new_str(buf
);
110 /* default to printer */
111 if(!base_class
&& vendor
&& device
) base_class
= new_str("printer");
115 // fprintf(stderr, "port <0x%x\n", port);
116 // fprintf(stderr, "class <%s>\n", base_class);
117 // fprintf(stderr, "device <%s>\n", device);
118 // fprintf(stderr, "vendor <%s>\n", vendor);
119 // fprintf(stderr, "cmds <%s>\n", cmd_set);
121 for(hd
= hd_data
->hd
; hd
; hd
= hd
->next
) {
123 hd
->base_class
.id
== bc_comm
&&
124 hd
->sub_class
.id
== sc_com_par
&&
126 !strcmp(hd
->unix_dev_name
, unix_dev
)
132 hd
= add_hd_entry(hd_data
, __LINE__
, 0);
133 hd
->base_class
.id
= bc_comm
;
134 hd
->sub_class
.id
= sc_com_par
;
135 hd
->unix_dev_name
= new_str(unix_dev
);
137 res
= add_res_entry(&hd
->res
, new_mem(sizeof *res
));
138 res
->io
.type
= res_io
;
141 res
->io
.access
= acc_rw
;
145 // ##### check if ports match?
149 (device
&& strcmp(device
, "Unknown device")) ||
150 (vendor
&& strcmp(vendor
, "Unknown vendor"))
153 hd
= add_hd_entry(hd_data
, __LINE__
, 0);
154 hd
->attached_to
= hd_i
->idx
;
155 hd
->unix_dev_name
= new_str(hd_i
->unix_dev_name
);
156 hd
->base_class
.id
= bc_none
;
157 if(base_class
&& !strcasecmp(base_class
, "printer")) hd
->base_class
.id
= bc_printer
;
158 hd
->bus
.id
= bus_parallel
;
160 hd
->vendor
.name
= new_str(vendor
);
161 hd
->device
.name
= new_str(device
);
164 free_mem(base_class
);
172 if((hd_data
->debug
& HD_DEB_PARALLEL
)) dump_parallel_data(hd_data
, log
);
178 void do_zip(hd_data_t
*hd_data
)
181 int i
, j
, port
, is_imm
, is_ppa
, is_imm0
, is_ppa0
;
182 char *pp
= NULL
, *s
= NULL
, *unix_dev
= NULL
;
183 str_list_t
*log
= NULL
, *sl
, *sl0
;
184 int do_imm
= hd_probe_feature(hd_data
, pr_parallel_imm
);
186 is_imm
= is_imm0
= hd_module_is_active(hd_data
, "imm");
187 is_ppa
= is_ppa0
= hd_module_is_active(hd_data
, "ppa");
189 if(!(is_imm
|| is_ppa
)) {
190 for(hd
= hd_data
->hd
; hd
; hd
= hd
->next
) {
191 if(hd
->base_class
.id
== bc_comm
&& hd
->sub_class
.id
== sc_com_par
) break;
193 /* ... if there seems to be a parallel interface, try to load it */
196 PROGRESS(5, 0, "imm mod");
197 load_module(hd_data
, "imm");
199 PROGRESS(5, 0, "ppa mod");
200 load_module(hd_data
, "ppa");
201 is_imm
= hd_module_is_active(hd_data
, "imm");
202 is_ppa
= hd_module_is_active(hd_data
, "ppa");
203 if(do_imm
&& !is_imm
) {
205 char flush
[2] = { 4, 12 };
207 fd
= open("/dev/lp0", O_NONBLOCK
| O_WRONLY
);
209 write(fd
, flush
, sizeof flush
);
216 if(!(is_imm
|| is_ppa
)) return;
218 PROGRESS(6, 0, "zip read info");
220 for(i
= 0; i
< 16; i
++) {
221 str_printf(&pp
, 0, PROC_SCSI
"/%s/%d", (i
% 2) ? "ppa" : "imm", i
/ 2);
222 sl0
= read_file(pp
, 0, 0);
224 str_printf(&s
, 0, "%s\n", pp
);
225 add_str_list(&log
, s
);
227 for(sl
= sl0
; sl
; sl
= sl
->next
) {
228 str_printf(&s
, 0, " %s", sl
->str
);
229 add_str_list(&log
, s
);
230 if(sscanf(sl
->str
, "Parport : parport%d", &j
) == 1) port
= j
;
236 unix_dev
= free_mem(unix_dev
);
238 str_printf(&unix_dev
, 0, "/dev/lp%d", port
);
243 for(hd
= hd_data
->hd
; hd
; hd
= hd
->next
) {
245 hd
->base_class
.id
== bc_comm
&&
246 hd
->sub_class
.id
== sc_com_par
&&
248 !strcmp(hd
->unix_dev_name
, unix_dev
)
254 hd
= add_hd_entry(hd_data
, __LINE__
, 0);
255 hd
->base_class
.id
= bc_comm
;
256 hd
->sub_class
.id
= sc_com_par
;
257 hd
->unix_dev_name
= new_str(unix_dev
);
262 hd
= add_hd_entry(hd_data
, __LINE__
, 0);
264 hd
->attached_to
= hd_i
->idx
;
265 hd
->unix_dev_name
= new_str(hd_i
->unix_dev_name
);
267 hd
->base_class
.id
= bc_storage
;
268 hd
->sub_class
.id
= sc_sto_scsi
;
269 hd
->bus
.id
= bus_parallel
;
270 hd
->vendor
.id
= MAKE_ID(TAG_SPECIAL
, 0x1800);
271 hd
->device
.id
= MAKE_ID(TAG_SPECIAL
, (i
% 2) ? 2 : 1);
274 if(!is_imm0
) unload_module(hd_data
, "imm");
275 if(!is_ppa0
) unload_module(hd_data
, "ppa");
277 if((hd_data
->debug
& HD_DEB_PARALLEL
)) dump_parallel_data(hd_data
, log
);
285 void dump_parallel_data(hd_data_t
*hd_data
, str_list_t
*sl
)
287 ADD2LOG("----- parallel info -----\n");
288 for(; sl
; sl
= sl
->next
) {
289 ADD2LOG("%s", sl
->str
);
291 ADD2LOG("----- parallel info end -----\n");
294 #endif /* ifndef LIBHD_TINY */