1 /*
2  * $Id: drv_toshiba.c,v 1.3 1999/02/14 09:50:42 dirk Exp $
3  *
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
9  *
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.
14  *
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.
19  *
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
23  *
24  *
25  * Vendor-specific drive control routines for Toshiba XM-3401 series.
26  */
27 
28 static char drv_toshiba_id[] = "$Id: drv_toshiba.c,v 1.3 1999/02/14 09:50:42 dirk Exp $";
29 
30 #include <stdio.h>
31 #include <errno.h>
32 #include "include/wm_config.h"
33 #include "include/wm_struct.h"
34 #include "include/wm_scsi.h"
35 
36 #define	SCMD_TOSH_EJECT		0xc4
37 
38 /* local prototypes */
39 static int	tosh_init( struct wm_drive *d );
40 static int	tosh_eject( struct wm_drive *d );
41 static int	tosh_set_volume( struct wm_drive *d, int left, int right );
42 static int	tosh_get_volume( struct wm_drive *d, int *left, int *right );
43 
44 struct wm_drive toshiba_proto = {
45 	-1,			/* fd */
46 	"Toshiba",		/* vendor */
47 	"",			/* model */
48 	"",			/* revision */
49 	NULL,			/* aux */
50 	NULL,			/* daux */
51 
52 	tosh_init,		/* functions... */
53 	gen_get_trackcount,
54 	gen_get_cdlen,
55 	gen_get_trackinfo,
56 	gen_get_drive_status,
57 	tosh_get_volume,
58 	tosh_set_volume,
59 	gen_pause,
60 	gen_resume,
61 	gen_stop,
62 	gen_play,
63 	tosh_eject,
64 	gen_closetray
65 };
66 
67 /*
68  * Initialize the driver.
69  */
70 static int
tosh_init(struct wm_drive * d)71 tosh_init( struct wm_drive *d )
72 {
73 	extern int	min_volume;
74 
75 /* Sun use Toshiba drives as well */
76 #if defined(SYSV) && defined(CODEC)
77         codec_init();
78 #endif
79 	min_volume = 0;
80 	return ( 0 );
81 }
82 
83 /*
84  * Send the Toshiba code to eject the CD.
85  */
86 static int
tosh_eject(struct wm_drive * d)87 tosh_eject( struct wm_drive *d )
88 {
89 	return (sendscsi(d, NULL, 0, 0, SCMD_TOSH_EJECT, 1, 0,0,0,0,0,0,0,0,0,0));
90 }
91 
92 /*
93  * Set the volume.  The low end of the scale is more sensitive than the high
94  * end, so make up for that by transforming the volume parameters to a square
95  * curve.
96  */
97 static int
tosh_set_volume(struct wm_drive * d,int left,int right)98 tosh_set_volume( struct wm_drive *d, int left, int right )
99 {
100 	left = (left * left * left) / 10000;
101 	right = (right * right * right) / 10000;
102 	return (gen_set_volume(d, left, right));
103 }
104 
105 /*
106  * Undo the transformation above using a binary search (so no floating-point
107  * math is required.)
108  */
109 static int
unscale_volume(cd_vol,max)110 unscale_volume(cd_vol, max)
111 	int	cd_vol, max;
112 {
113 	int	vol = 0, top = max, bot = 0, scaled = 0;
114 
115 	/*cd_vol = (cd_vol * 100 + (max_volume - 1)) / max_volume;*/
116 
117 	while (bot <= top)
118 	{
119 		vol = (top + bot) / 2;
120 		scaled = (vol * vol) / max;
121 		if (cd_vol <= scaled)
122 			top = vol - 1;
123 		else
124 			bot = vol + 1;
125 	}
126 
127 	/* Might have looked down too far for repeated scaled values */
128 	if (cd_vol < scaled)
129 		vol++;
130 
131 	if (vol < 0)
132 		vol = 0;
133 	else if (vol > max)
134 		vol = max;
135 
136 	return (vol);
137 }
138 
139 /*
140  * Get the volume.
141  */
142 static int
tosh_get_volume(struct wm_drive * d,int * left,int * right)143 tosh_get_volume( struct wm_drive *d, int *left, int *right )
144 {
145 	int		status;
146 
147 	status = gen_get_volume(d, left, right);
148 	if (status < 0)
149 		return (status);
150 	*left = unscale_volume(*left, 100);
151 	*right = unscale_volume(*right, 100);
152 
153 	return (0);
154 }
155