2 * $Id: plat_aix.c,v 1.7 1999/03/07 08:36:40 dirk Exp $
4 * This file is part of WorkMan, the civilized CD player library
5 * (c) 1991-1997 by Steven Grimm (original author)
6 * (c) by Dirk Försterling (current 'author' = maintainer)
7 * The maintainer can be contacted by his e-mail address:
8 * milliByte@DeathsDoor.com
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the Free
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * plat_aix - AIX 4.x IDE and SCSI support 16 Dec 1998
27 * AIX 4.x Port: Erik O'Shaughnessy
28 * Original AIX IDE Code: Cloyce Spradling (xmcd libdi_d/aixioc.c )
30 * Taken from the ascd distribution.
37 static char plat_aix_id
[] = "$Id: plat_aix.c,v 1.7 1999/03/07 08:36:40 dirk Exp $";
43 #include <sys/types.h>
44 #include <sys/cdrom.h>
45 #include <sys/devinfo.h>
47 #include <sys/scdisk.h>
49 #include "include/wm_config.h"
50 #include "include/wm_struct.h"
52 #define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM
56 extern char *cd_device
;
70 int gen_init(struct wm_drive
*d
){
75 /* NAME: gen_get_trackcount
82 int gen_get_trackcount(struct wm_drive
*d
,int *tracks
){
83 struct cd_audio_cmd cmd
;
85 cmd
.audio_cmds
= CD_TRK_INFO_AUDIO
;
88 if( ioctl(d
->fd
,DKAUDIO
,&cmd
) < 0){
93 *tracks
= cmd
.indexing
.track_index
.last_track
;
99 /* NAME: gen_get_cdlen
106 int gen_get_cdlen(struct wm_drive
*d
,int *frames
){
109 return gen_get_trackinfo(d
,LEADOUT
,&tmp
,frames
);
112 /* NAME: gen_get_trackinfo
119 int gen_get_trackinfo(struct wm_drive
*d
,int track
,int *data
,int *startframe
){
120 struct cd_audio_cmd cmd
;
122 cmd
.audio_cmds
= CD_GET_TRK_MSF
;
125 cmd
.indexing
.track_msf
.track
= track
;
127 if( ioctl(d
->fd
,DKAUDIO
,&cmd
) < 0)
130 *startframe
= cmd
.indexing
.track_msf
.mins
* 60 * 75 +
131 cmd
.indexing
.track_msf
.secs
* 75 +
132 cmd
.indexing
.track_msf
.frames
;
139 /* NAME: gen_get_drive_status
146 int gen_get_drive_status(struct wm_drive
*d
,
147 enum wm_cd_modes oldmode
,
148 enum wm_cd_modes
*mode
,
152 struct cd_audio_cmd cmd
;
154 *mode
= WM_CDM_EJECTED
;
157 switch( wmcd_open(d
) ){
164 cmd
.audio_cmds
= CD_INFO_AUDIO
;
165 if( ioctl(d
->fd
,DKAUDIO
,&cmd
) < 0)
170 *mode
= WM_CDM_PLAYING
;
171 *track
= cmd
.indexing
.info_audio
.current_track
;
172 *index
= cmd
.indexing
.info_audio
.current_index
;
173 *pos
= cmd
.indexing
.info_audio
.current_mins
* 60 * 75 +
174 cmd
.indexing
.info_audio
.current_secs
* 75 +
175 cmd
.indexing
.info_audio
.current_frames
;
179 *mode
= WM_CDM_PAUSED
;
180 *track
= cmd
.indexing
.info_audio
.current_track
;
181 *index
= cmd
.indexing
.info_audio
.current_index
;
182 *pos
= cmd
.indexing
.info_audio
.current_mins
* 60 * 75 +
183 cmd
.indexing
.info_audio
.current_secs
* 75 +
184 cmd
.indexing
.info_audio
.current_frames
;
187 case CD_NO_AUDIO
: /* no play audio in progress */
188 case CD_COMPLETED
: /* play operation completed successfully */
189 case CD_STATUS_ERROR
: /* invalid status or play stopped due to err */
190 case CD_NOT_VALID
: /* audio status is invalid or not supported */
191 *mode
= WM_CDM_STOPPED
;
194 *mode
= WM_CDM_UNKNOWN
;
202 int scale_volume(int vol
,int max
){
203 return ((vol
* (max_volume
- min_volume
)) / max
+ min_volume
);
206 int unscale_volume(int vol
,int max
){
208 n
= ( vol
- min_volume
) * max_volume
/ (max
- min_volume
);
212 /* NAME: gen_get_volume
219 int gen_get_volume(struct wm_drive
*d
,int *left
,int *right
){
220 struct cd_audio_cmd cmd
;
223 fprintf(stderr
,"gen_get_volume\n");
225 cmd
.audio_cmds
= CD_INFO_AUDIO
;
226 if( ioctl(d
->fd
,DKAUDIO
,&cmd
) < 0)
229 *left
= unscale_volume(cmd
.out_port_0_vol
,100);
230 *right
= unscale_volume(cmd
.out_port_1_vol
,100);
235 /* NAME: gen_set_volume
242 int gen_set_volume(struct wm_drive
*d
,int left
,int right
){
243 struct cd_audio_cmd cmd
;
245 cmd
.audio_cmds
= CD_SET_VOLUME
;
246 cmd
.volume_type
= CD_VOLUME_CHNLS
;
248 cmd
.out_port_0_vol
= scale_volume(left
,100);
249 cmd
.out_port_1_vol
= scale_volume(right
,100);
251 if( ioctl(d
->fd
,DKAUDIO
,&cmd
) < 0){
252 perror("CD_SET_VOLUME");
266 int gen_pause(struct wm_drive
*d
){
267 struct cd_audio_cmd cmd
;
269 cmd
.audio_cmds
= CD_PAUSE_AUDIO
;
271 return ioctl(d
->fd
,DKAUDIO
,&cmd
);
281 int gen_resume(struct wm_drive
*d
){
282 struct cd_audio_cmd cmd
;
284 cmd
.audio_cmds
= CD_RESUME_AUDIO
;
285 return ioctl(d
->fd
,DKAUDIO
,&cmd
);
295 int gen_stop(struct wm_drive
*d
){
296 struct cd_audio_cmd cmd
;
298 cmd
.audio_cmds
= CD_STOP_AUDIO
;
299 return ioctl(d
->fd
,DKAUDIO
,&cmd
);
309 int gen_play(struct wm_drive
*d
,int start
,int end
){
310 struct cd_audio_cmd cmd
;
312 cmd
.audio_cmds
= CD_PLAY_AUDIO
;
315 cmd
.indexing
.msf
.first_mins
= start
/ (60*75);
316 cmd
.indexing
.msf
.first_secs
= (start
% (60*75)) / 75;
317 cmd
.indexing
.msf
.first_frames
= start
% 75;
319 cmd
.indexing
.msf
.last_mins
= end
/ (60*75);
320 cmd
.indexing
.msf
.last_secs
= (end
% (60*75)) / 75;
321 cmd
.indexing
.msf
.last_frames
= end
% 75;
323 if( ioctl(d
->fd
,DKAUDIO
,&cmd
) < 0){
324 perror("DKAUDIO:CD_PLAY_AUDIO");
338 int gen_eject(struct wm_drive
*d
){
340 return ioctl(d
->fd
,DKEJECT
,NULL
);
344 /*----------------------------------------*
346 *----------------------------------------*/
347 int gen_closetray(struct wm_drive
*d
)
353 return(wmcd_reopen(d
));
358 /* Always succeed if the drive can't close */
360 #endif /* CAN_CLOSE */
361 } /* gen_closetray() */
373 int wm_scsi(struct wm_drive
*d
,
374 uchar_t
*cdb
, int cdblen
,void *retbuf
,int retbuflen
,int getreply
){
386 int wmcd_open(struct wm_drive
*d
){
387 char vendor
[32] = WM_STR_GENVENDOR
;
388 char model
[32] = WM_STR_GENMODEL
;
389 char rev
[32] = WM_STR_GENREV
;
398 if(d
->fd
> -1) /* device already open? */
401 if( cd_device
== (char *)NULL
)
402 cd_device
= DEFAULT_CD_DEVICE
;
404 if( (fd
=openx(cd_device
,O_RDONLY
,NULL
,SC_SINGLE
)) < 0 ){
409 *d
= *(find_drive_struct(vendor
, model
, rev
));
410 wm_drive_settype(vendor
, model
, rev
);
419 * Re-Open the device if it is open.
422 wmcd_reopen( struct wm_drive
*d
)
427 wm_lib_message(WM_MSG_LEVEL_DEBUG
|WM_MSG_CLASS
, "wmcd_reopen ");
428 if (d
->fd
>= 0) /* Device really open? */
430 wm_lib_message(WM_MSG_LEVEL_DEBUG
|WM_MSG_CLASS
, "closes the device and ");
431 status
= close( d
->fd
); /* close it! */
432 /* we know, that the file is closed, do we? */
436 wm_lib_message(WM_MSG_LEVEL_DEBUG
|WM_MSG_CLASS
, "calls wmcd_open()\n");
437 status
= wmcd_open( d
); /* open it as usual */
439 } while ( status
!= 0 );
441 } /* wmcd_reopen() */