1 /*
2  * This file is part of WorkMan, the civilized CD player library
3  * Copyright (C) 1991-1997 by Steven Grimm (original author)
4  * Copyright (C) by Dirk Försterling <milliByte@DeathsDoor.com>
5  * Copyright (C) 2004-2006 Alexander Kern <alex.kern@gmx.de>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the Free
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20  *
21  *
22  * Vendor-specific drive control routines for Toshiba XM-3401 series.
23  */
24 
25 #include <stdio.h>
26 #include <errno.h>
27 #include "include/wm_config.h"
28 #include "include/wm_struct.h"
29 #include "include/wm_scsi.h"
30 
31 #define SCMD_TOSH_EJECT 0xc4
32 
33 /* local prototypes */
34 /* static int min_volume = 0, max_volume = 255; */
35 
36 /*
37  * Undo the transformation above using a binary search (so no floating-point
38  * math is required.)
39  */
unscale_volume(int cd_vol,int max)40 static int unscale_volume(int cd_vol, int max)
41 {
42 	int vol = 0, top = max, bot = 0, scaled = 0;
43 
44 	/*cd_vol = (cd_vol * 100 + (max_volume - 1)) / max_volume;*/
45 
46 	while (bot <= top)
47 	{
48 		vol = (top + bot) / 2;
49 		scaled = (vol * vol) / max;
50 		if (cd_vol <= scaled)
51 			top = vol - 1;
52 		else
53 			bot = vol + 1;
54 	}
55 
56 	/* Might have looked down too far for repeated scaled values */
57 	if (cd_vol < scaled)
58 		vol++;
59 
60 	if (vol < 0)
61 		vol = 0;
62 	else if (vol > max)
63 		vol = max;
64 
65 	return (vol);
66 }
67 
68 /*
69  * Send the Toshiba code to eject the CD.
70  */
tosh_eject(struct wm_drive * d)71 static int tosh_eject(struct wm_drive *d)
72 {
73 	return sendscsi(d, NULL, 0, 0, SCMD_TOSH_EJECT, 1, 0,0,0,0,0,0,0,0,0,0);
74 }
75 
76 /*
77  * Set the volume.  The low end of the scale is more sensitive than the high
78  * end, so make up for that by transforming the volume parameters to a square
79  * curve.
80  */
tosh_scale_volume(int * left,int * right)81 static int tosh_scale_volume(int *left, int *right)
82 {
83 	*left = (*left * *left * *left) / 10000;
84 	*right = (*right * *right * *right) / 10000;
85 
86 	return 0;
87 }
88 
tosh_unscale_volume(int * left,int * right)89 static int tosh_unscale_volume(int *left, int *right)
90 {
91 	*left = unscale_volume(*left, 100);
92 	*right = unscale_volume(*right, 100);
93 
94 	return 0;
95 }
96 
toshiba_fixup(struct wm_drive * d)97 int toshiba_fixup(struct wm_drive *d)
98 {
99 	d->proto.eject = tosh_eject;
100 	d->proto.scale_volume = tosh_scale_volume;
101 	d->proto.unscale_volume = tosh_unscale_volume;
102 
103 	return 0;
104 }
105