2 * $Id: drv_sony.c,v 1.3 1999/02/14 09:50:42 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 * Vendor-specific drive control routines for Sony CDU-8012 series.
28 static char drv_sony_id
[] = "$Id: drv_sony.c,v 1.3 1999/02/14 09:50:42 dirk Exp $";
32 #include "include/wm_config.h"
33 #include "include/wm_struct.h"
34 #include "include/wm_scsi.h"
36 #define PAGE_AUDIO 0x0e
38 /* local prototypes */
39 static int sony_init( struct wm_drive
*d
);
40 static int sony_set_volume(struct wm_drive
*d
, int left
, int right
);
41 static int sony_get_volume( struct wm_drive
*d
, int *left
, int *right
);
44 extern int min_volume
, max_volume
;
46 struct wm_drive sony_proto
= {
49 "CDU-8012", /* model */
54 sony_init
, /* functions... */
70 * Initialize the driver.
72 static int sony_init( struct wm_drive
*d
) {
74 /* Sun use Sony drives as well */
75 #if defined(SYSV) && defined(CODEC)
84 * On the Sony CDU-8012 drive, the amount of sound coming out the jack
85 * increases much faster toward the top end of the volume scale than it
86 * does at the bottom. To make up for this, we make the volume scale look
87 * sort of logarithmic (actually an upside-down inverse square curve) so
88 * that the volume value passed to the drive changes less and less as you
89 * approach the maximum slider setting. Additionally, only the top half
90 * of the volume scale is valid; the bottom half is all silent. The actual
93 * max^2 - (max - vol)^2 max
94 * v = --------------------- + ---
97 * Where "max" is the maximum value of the volume scale, usually 100.
100 scale_volume(vol
, max
)
103 vol
= (max
*max
- (max
- vol
) * (max
- vol
)) / max
;
104 return ((vol
+ max
) / 2);
108 * Given a value between min_volume and max_volume, return the standard-scale
109 * volume value needed to achieve that hardware value.
111 * Rather than perform floating-point calculations to reverse the above
112 * formula, we simply do a binary search of scale_volume()'s return values.
115 unscale_volume(cd_vol
, max
)
118 int vol
= 0, top
= max
, bot
= 0, scaled
= 0;
120 cd_vol
= (cd_vol
* 100 + (max_volume
- 1)) / max_volume
;
124 vol
= (top
+ bot
) / 2;
125 scaled
= scale_volume(vol
, max
);
126 if (cd_vol
<= scaled
)
132 /* Might have looked down too far for repeated scaled values */
145 * Get the volume. Sun's CD-ROM driver doesn't support this operation, even
146 * though their drive does. Dumb.
149 sony_get_volume( struct wm_drive
*d
, int *left
, int *right
)
151 unsigned char mode
[16];
153 /* Get the current audio parameters first. */
154 if (wm_scsi_mode_sense(d
, PAGE_AUDIO
, mode
))
157 *left
= unscale_volume(mode
[9], 100);
158 *right
= unscale_volume(mode
[11], 100);
164 * Set the volume using the wacky scale outlined above. The Sony drive
165 * responds to the standard set-volume command.
168 sony_set_volume(struct wm_drive
*d
, int left
, int right
)
170 left
= scale_volume(left
, 100);
171 right
= scale_volume(right
, 100);
172 return (gen_set_volume(d
, left
, right
));