aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-02-01 17:09:23 -0500
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-02-01 17:09:23 -0500
commitba3fab24d210544cba74b3fd640123baf33ed331 (patch)
tree89de9013b96917bdd7249234f3220d978ab22b6d /drivers/ide
parent972560fb9d9ea7bc7082c0c79c99c24e3f56606c (diff)
ide-cd: factor out ioctl handlers from ide_cdrom_audio_ioctl()
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide')
-rw-r--r--drivers/ide/ide-cd.c142
1 files changed, 75 insertions, 67 deletions
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index f4a0264bea6d..1826c58d2f85 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -1998,6 +1998,24 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
1998 return 0; 1998 return 0;
1999} 1999}
2000 2000
2001static int ide_cd_read_tochdr(ide_drive_t *drive, void *arg)
2002{
2003 struct cdrom_info *cd = drive->driver_data;
2004 struct cdrom_tochdr *tochdr = arg;
2005 struct atapi_toc *toc;
2006 int stat;
2007
2008 /* Make sure our saved TOC is valid. */
2009 stat = cdrom_read_toc(drive, NULL);
2010 if (stat)
2011 return stat;
2012
2013 toc = cd->toc;
2014 tochdr->cdth_trk0 = toc->hdr.first_track;
2015 tochdr->cdth_trk1 = toc->hdr.last_track;
2016
2017 return 0;
2018}
2001 2019
2002static int cdrom_read_subchannel(ide_drive_t *drive, int format, char *buf, 2020static int cdrom_read_subchannel(ide_drive_t *drive, int format, char *buf,
2003 int buflen, struct request_sense *sense) 2021 int buflen, struct request_sense *sense)
@@ -2092,6 +2110,55 @@ static int cdrom_get_toc_entry(ide_drive_t *drive, int track,
2092 return 0; 2110 return 0;
2093} 2111}
2094 2112
2113static int ide_cd_read_tocentry(ide_drive_t *drive, void *arg)
2114{
2115 struct cdrom_tocentry *tocentry = arg;
2116 struct atapi_toc_entry *toce;
2117 int stat;
2118
2119 stat = cdrom_get_toc_entry(drive, tocentry->cdte_track, &toce);
2120 if (stat)
2121 return stat;
2122
2123 tocentry->cdte_ctrl = toce->control;
2124 tocentry->cdte_adr = toce->adr;
2125 if (tocentry->cdte_format == CDROM_MSF) {
2126 lba_to_msf(toce->addr.lba,
2127 &tocentry->cdte_addr.msf.minute,
2128 &tocentry->cdte_addr.msf.second,
2129 &tocentry->cdte_addr.msf.frame);
2130 } else
2131 tocentry->cdte_addr.lba = toce->addr.lba;
2132
2133 return 0;
2134}
2135
2136static int ide_cd_fake_play_trkind(ide_drive_t *drive, void *arg)
2137{
2138 struct cdrom_ti *ti = arg;
2139 struct atapi_toc_entry *first_toc, *last_toc;
2140 unsigned long lba_start, lba_end;
2141 int stat;
2142
2143 stat = cdrom_get_toc_entry(drive, ti->cdti_trk0, &first_toc);
2144 if (stat)
2145 return stat;
2146
2147 stat = cdrom_get_toc_entry(drive, ti->cdti_trk1, &last_toc);
2148 if (stat)
2149 return stat;
2150
2151 if (ti->cdti_trk1 != CDROM_LEADOUT)
2152 ++last_toc;
2153 lba_start = first_toc->addr.lba;
2154 lba_end = last_toc->addr.lba;
2155
2156 if (lba_end <= lba_start)
2157 return -EINVAL;
2158
2159 return cdrom_play_audio(drive, lba_start, lba_end);
2160}
2161
2095/* the generic packet interface to cdrom.c */ 2162/* the generic packet interface to cdrom.c */
2096static int ide_cdrom_packet(struct cdrom_device_info *cdi, 2163static int ide_cdrom_packet(struct cdrom_device_info *cdi,
2097 struct packet_command *cgc) 2164 struct packet_command *cgc)
@@ -2123,81 +2190,22 @@ static int ide_cdrom_packet(struct cdrom_device_info *cdi,
2123 return cgc->stat; 2190 return cgc->stat;
2124} 2191}
2125 2192
2126static 2193static int ide_cdrom_audio_ioctl(struct cdrom_device_info *cdi,
2127int ide_cdrom_audio_ioctl (struct cdrom_device_info *cdi, 2194 unsigned int cmd, void *arg)
2128 unsigned int cmd, void *arg)
2129
2130{ 2195{
2131 ide_drive_t *drive = cdi->handle; 2196 ide_drive_t *drive = cdi->handle;
2132 struct cdrom_info *info = drive->driver_data;
2133 int stat;
2134 2197
2135 switch (cmd) { 2198 switch (cmd) {
2136 /* 2199 /*
2137 * emulate PLAY_AUDIO_TI command with PLAY_AUDIO_10, since 2200 * emulate PLAY_AUDIO_TI command with PLAY_AUDIO_10, since
2138 * atapi doesn't support it 2201 * atapi doesn't support it
2139 */ 2202 */
2140 case CDROMPLAYTRKIND: { 2203 case CDROMPLAYTRKIND:
2141 unsigned long lba_start, lba_end; 2204 return ide_cd_fake_play_trkind(drive, arg);
2142 struct cdrom_ti *ti = arg; 2205 case CDROMREADTOCHDR:
2143 struct atapi_toc_entry *first_toc, *last_toc; 2206 return ide_cd_read_tochdr(drive, arg);
2144 2207 case CDROMREADTOCENTRY:
2145 stat = cdrom_get_toc_entry(drive, ti->cdti_trk0, &first_toc); 2208 return ide_cd_read_tocentry(drive, arg);
2146 if (stat)
2147 return stat;
2148
2149 stat = cdrom_get_toc_entry(drive, ti->cdti_trk1, &last_toc);
2150 if (stat)
2151 return stat;
2152
2153 if (ti->cdti_trk1 != CDROM_LEADOUT)
2154 ++last_toc;
2155 lba_start = first_toc->addr.lba;
2156 lba_end = last_toc->addr.lba;
2157
2158 if (lba_end <= lba_start)
2159 return -EINVAL;
2160
2161 return cdrom_play_audio(drive, lba_start, lba_end);
2162 }
2163
2164 case CDROMREADTOCHDR: {
2165 struct cdrom_tochdr *tochdr = arg;
2166 struct atapi_toc *toc;
2167
2168 /* Make sure our saved TOC is valid. */
2169 stat = cdrom_read_toc(drive, NULL);
2170 if (stat)
2171 return stat;
2172
2173 toc = info->toc;
2174 tochdr->cdth_trk0 = toc->hdr.first_track;
2175 tochdr->cdth_trk1 = toc->hdr.last_track;
2176
2177 return 0;
2178 }
2179
2180 case CDROMREADTOCENTRY: {
2181 struct cdrom_tocentry *tocentry = arg;
2182 struct atapi_toc_entry *toce;
2183
2184 stat = cdrom_get_toc_entry(drive, tocentry->cdte_track, &toce);
2185 if (stat)
2186 return stat;
2187
2188 tocentry->cdte_ctrl = toce->control;
2189 tocentry->cdte_adr = toce->adr;
2190 if (tocentry->cdte_format == CDROM_MSF) {
2191 lba_to_msf (toce->addr.lba,
2192 &tocentry->cdte_addr.msf.minute,
2193 &tocentry->cdte_addr.msf.second,
2194 &tocentry->cdte_addr.msf.frame);
2195 } else
2196 tocentry->cdte_addr.lba = toce->addr.lba;
2197
2198 return 0;
2199 }
2200
2201 default: 2209 default:
2202 return -EINVAL; 2210 return -EINVAL;
2203 } 2211 }