blob: 48a16d865834b023704eea64b0c27d062bc6dc94 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Low-level ALSA driver for the ENSONIQ SoundScape PnP
3 * Copyright (c) by Chris Rankin
4 *
5 * This driver was written in part using information obtained from
6 * the OSS/Free SoundScape driver, written by Hannu Savolainen.
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/init.h>
Takashi Iwai277e9262005-11-17 17:13:12 +010025#include <linux/err.h>
Takashi Iwai5e24c1c2007-02-22 12:50:54 +010026#include <linux/isa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/delay.h>
28#include <linux/pnp.h>
29#include <linux/spinlock.h>
30#include <linux/moduleparam.h>
31#include <asm/dma.h>
32#include <sound/core.h>
33#include <sound/hwdep.h>
Krzysztof Helt61ef19d2008-07-31 21:02:42 +020034#include <sound/wss.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <sound/mpu401.h>
36#include <sound/initval.h>
37
38#include <sound/sscape_ioctl.h>
39
40
41MODULE_AUTHOR("Chris Rankin");
42MODULE_DESCRIPTION("ENSONIQ SoundScape PnP driver");
43MODULE_LICENSE("GPL");
44
45static int index[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IDX;
46static char* id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_STR;
Krzysztof Helt4996bca2007-09-17 16:23:13 +020047static long port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT;
48static long wss_port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static int irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ;
50static int mpu_irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ;
51static int dma[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA;
Krzysztof Helt4996bca2007-09-17 16:23:13 +020052static int dma2[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54module_param_array(index, int, NULL, 0444);
55MODULE_PARM_DESC(index, "Index number for SoundScape soundcard");
56
57module_param_array(id, charp, NULL, 0444);
58MODULE_PARM_DESC(id, "Description for SoundScape card");
59
60module_param_array(port, long, NULL, 0444);
61MODULE_PARM_DESC(port, "Port # for SoundScape driver.");
62
Krzysztof Helt4996bca2007-09-17 16:23:13 +020063module_param_array(wss_port, long, NULL, 0444);
64MODULE_PARM_DESC(wss_port, "WSS Port # for SoundScape driver.");
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066module_param_array(irq, int, NULL, 0444);
67MODULE_PARM_DESC(irq, "IRQ # for SoundScape driver.");
68
69module_param_array(mpu_irq, int, NULL, 0444);
70MODULE_PARM_DESC(mpu_irq, "MPU401 IRQ # for SoundScape driver.");
71
72module_param_array(dma, int, NULL, 0444);
73MODULE_PARM_DESC(dma, "DMA # for SoundScape driver.");
Clemens Ladischf7a92752005-12-07 09:13:42 +010074
Krzysztof Helt4996bca2007-09-17 16:23:13 +020075module_param_array(dma2, int, NULL, 0444);
76MODULE_PARM_DESC(dma2, "DMA2 # for SoundScape driver.");
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#ifdef CONFIG_PNP
Rene Herman609d7692007-05-15 11:42:56 +020079static int isa_registered;
Takashi Iwai59b1b342006-01-04 15:06:44 +010080static int pnp_registered;
Rene Herman609d7692007-05-15 11:42:56 +020081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082static struct pnp_card_device_id sscape_pnpids[] = {
Krzysztof Helt4996bca2007-09-17 16:23:13 +020083 { .id = "ENS3081", .devs = { { "ENS0000" } } }, /* Soundscape PnP */
84 { .id = "ENS4081", .devs = { { "ENS1011" } } }, /* VIVO90 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 { .id = "" } /* end */
86};
87
88MODULE_DEVICE_TABLE(pnp_card, sscape_pnpids);
89#endif
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92#define MPU401_IO(i) ((i) + 0)
93#define MIDI_DATA_IO(i) ((i) + 0)
94#define MIDI_CTRL_IO(i) ((i) + 1)
95#define HOST_CTRL_IO(i) ((i) + 2)
96#define HOST_DATA_IO(i) ((i) + 3)
97#define ODIE_ADDR_IO(i) ((i) + 4)
98#define ODIE_DATA_IO(i) ((i) + 5)
99#define CODEC_IO(i) ((i) + 8)
100
101#define IC_ODIE 1
102#define IC_OPUS 2
103
104#define RX_READY 0x01
105#define TX_READY 0x02
106
107#define CMD_ACK 0x80
108#define CMD_SET_MIDI_VOL 0x84
109#define CMD_GET_MIDI_VOL 0x85
110#define CMD_XXX_MIDI_VOL 0x86
111#define CMD_SET_EXTMIDI 0x8a
112#define CMD_GET_EXTMIDI 0x8b
113#define CMD_SET_MT32 0x8c
114#define CMD_GET_MT32 0x8d
115
116enum GA_REG {
117 GA_INTSTAT_REG = 0,
118 GA_INTENA_REG,
119 GA_DMAA_REG,
120 GA_DMAB_REG,
121 GA_INTCFG_REG,
122 GA_DMACFG_REG,
123 GA_CDCFG_REG,
124 GA_SMCFGA_REG,
125 GA_SMCFGB_REG,
126 GA_HMCTL_REG
127};
128
129#define DMA_8BIT 0x80
130
131
132#define AD1845_FREQ_SEL_MSB 0x16
133#define AD1845_FREQ_SEL_LSB 0x17
134
Krzysztof Helt4996bca2007-09-17 16:23:13 +0200135enum card_type {
136 SSCAPE,
137 SSCAPE_PNP,
138 SSCAPE_VIVO,
139};
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141struct soundscape {
142 spinlock_t lock;
143 unsigned io_base;
Krzysztof Heltec1e7942007-09-17 17:57:37 +0200144 unsigned wss_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 int codec_type;
146 int ic_type;
Krzysztof Helt4996bca2007-09-17 16:23:13 +0200147 enum card_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 struct resource *io_res;
Krzysztof Heltec1e7942007-09-17 17:57:37 +0200149 struct resource *wss_res;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200150 struct snd_wss *chip;
Takashi Iwaibe624532005-11-17 14:42:05 +0100151 struct snd_mpu401 *mpu;
152 struct snd_hwdep *hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 /*
155 * The MIDI device won't work until we've loaded
156 * its firmware via a hardware-dependent device IOCTL
157 */
158 spinlock_t fwlock;
159 int hw_in_use;
160 unsigned long midi_usage;
161 unsigned char midi_vol;
162};
163
164#define INVALID_IRQ ((unsigned)-1)
165
166
Takashi Iwaibe624532005-11-17 14:42:05 +0100167static inline struct soundscape *get_card_soundscape(struct snd_card *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
169 return (struct soundscape *) (c->private_data);
170}
171
Takashi Iwaibe624532005-11-17 14:42:05 +0100172static inline struct soundscape *get_mpu401_soundscape(struct snd_mpu401 * mpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 return (struct soundscape *) (mpu->private_data);
175}
176
Takashi Iwaibe624532005-11-17 14:42:05 +0100177static inline struct soundscape *get_hwdep_soundscape(struct snd_hwdep * hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
179 return (struct soundscape *) (hw->private_data);
180}
181
182
183/*
184 * Allocates some kernel memory that we can use for DMA.
185 * I think this means that the memory has to map to
186 * contiguous pages of physical memory.
187 */
188static struct snd_dma_buffer *get_dmabuf(struct snd_dma_buffer *buf, unsigned long size)
189{
190 if (buf) {
191 if (snd_dma_alloc_pages_fallback(SNDRV_DMA_TYPE_DEV, snd_dma_isa_data(),
192 size, buf) < 0) {
193 snd_printk(KERN_ERR "sscape: Failed to allocate %lu bytes for DMA\n", size);
194 return NULL;
195 }
196 }
197
198 return buf;
199}
200
201/*
202 * Release the DMA-able kernel memory ...
203 */
204static void free_dmabuf(struct snd_dma_buffer *buf)
205{
206 if (buf && buf->area)
207 snd_dma_free_pages(buf);
208}
209
210
211/*
212 * This function writes to the SoundScape's control registers,
213 * but doesn't do any locking. It's up to the caller to do that.
214 * This is why this function is "unsafe" ...
215 */
216static inline void sscape_write_unsafe(unsigned io_base, enum GA_REG reg, unsigned char val)
217{
218 outb(reg, ODIE_ADDR_IO(io_base));
219 outb(val, ODIE_DATA_IO(io_base));
220}
221
222/*
223 * Write to the SoundScape's control registers, and do the
224 * necessary locking ...
225 */
226static void sscape_write(struct soundscape *s, enum GA_REG reg, unsigned char val)
227{
228 unsigned long flags;
229
230 spin_lock_irqsave(&s->lock, flags);
231 sscape_write_unsafe(s->io_base, reg, val);
232 spin_unlock_irqrestore(&s->lock, flags);
233}
234
235/*
236 * Read from the SoundScape's control registers, but leave any
237 * locking to the caller. This is why the function is "unsafe" ...
238 */
239static inline unsigned char sscape_read_unsafe(unsigned io_base, enum GA_REG reg)
240{
241 outb(reg, ODIE_ADDR_IO(io_base));
242 return inb(ODIE_DATA_IO(io_base));
243}
244
245/*
246 * Puts the SoundScape into "host" mode, as compared to "MIDI" mode
247 */
248static inline void set_host_mode_unsafe(unsigned io_base)
249{
250 outb(0x0, HOST_CTRL_IO(io_base));
251}
252
253/*
254 * Puts the SoundScape into "MIDI" mode, as compared to "host" mode
255 */
256static inline void set_midi_mode_unsafe(unsigned io_base)
257{
258 outb(0x3, HOST_CTRL_IO(io_base));
259}
260
261/*
262 * Read the SoundScape's host-mode control register, but leave
263 * any locking issues to the caller ...
264 */
265static inline int host_read_unsafe(unsigned io_base)
266{
267 int data = -1;
268 if ((inb(HOST_CTRL_IO(io_base)) & RX_READY) != 0) {
269 data = inb(HOST_DATA_IO(io_base));
270 }
271
272 return data;
273}
274
275/*
276 * Read the SoundScape's host-mode control register, performing
277 * a limited amount of busy-waiting if the register isn't ready.
278 * Also leaves all locking-issues to the caller ...
279 */
280static int host_read_ctrl_unsafe(unsigned io_base, unsigned timeout)
281{
282 int data;
283
284 while (((data = host_read_unsafe(io_base)) < 0) && (timeout != 0)) {
285 udelay(100);
286 --timeout;
287 } /* while */
288
289 return data;
290}
291
292/*
293 * Write to the SoundScape's host-mode control registers, but
294 * leave any locking issues to the caller ...
295 */
296static inline int host_write_unsafe(unsigned io_base, unsigned char data)
297{
298 if ((inb(HOST_CTRL_IO(io_base)) & TX_READY) != 0) {
299 outb(data, HOST_DATA_IO(io_base));
300 return 1;
301 }
302
303 return 0;
304}
305
306/*
307 * Write to the SoundScape's host-mode control registers, performing
308 * a limited amount of busy-waiting if the register isn't ready.
309 * Also leaves all locking-issues to the caller ...
310 */
311static int host_write_ctrl_unsafe(unsigned io_base, unsigned char data,
312 unsigned timeout)
313{
314 int err;
315
316 while (!(err = host_write_unsafe(io_base, data)) && (timeout != 0)) {
317 udelay(100);
318 --timeout;
319 } /* while */
320
321 return err;
322}
323
324
325/*
326 * Check that the MIDI subsystem is operational. If it isn't,
327 * then we will hang the computer if we try to use it ...
328 *
329 * NOTE: This check is based upon observation, not documentation.
330 */
Takashi Iwaibe624532005-11-17 14:42:05 +0100331static inline int verify_mpu401(const struct snd_mpu401 * mpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
333 return ((inb(MIDI_CTRL_IO(mpu->port)) & 0xc0) == 0x80);
334}
335
336/*
337 * This is apparently the standard way to initailise an MPU-401
338 */
Takashi Iwaibe624532005-11-17 14:42:05 +0100339static inline void initialise_mpu401(const struct snd_mpu401 * mpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
341 outb(0, MIDI_DATA_IO(mpu->port));
342}
343
344/*
345 * Tell the SoundScape to activate the AD1845 chip (I think).
346 * The AD1845 detection fails if we *don't* do this, so I
347 * think that this is a good idea ...
348 */
349static inline void activate_ad1845_unsafe(unsigned io_base)
350{
351 sscape_write_unsafe(io_base, GA_HMCTL_REG, (sscape_read_unsafe(io_base, GA_HMCTL_REG) & 0xcf) | 0x10);
352 sscape_write_unsafe(io_base, GA_CDCFG_REG, 0x80);
353}
354
355/*
356 * Do the necessary ALSA-level cleanup to deallocate our driver ...
357 */
Takashi Iwaibe624532005-11-17 14:42:05 +0100358static void soundscape_free(struct snd_card *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Krzysztof Heltec1e7942007-09-17 17:57:37 +0200360 struct soundscape *sscape = get_card_soundscape(c);
Takashi Iwaib1d57762005-10-10 11:56:31 +0200361 release_and_free_resource(sscape->io_res);
Krzysztof Heltec1e7942007-09-17 17:57:37 +0200362 release_and_free_resource(sscape->wss_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 free_dma(sscape->chip->dma1);
364}
365
366/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 * Tell the SoundScape to begin a DMA tranfer using the given channel.
368 * All locking issues are left to the caller.
369 */
370static inline void sscape_start_dma_unsafe(unsigned io_base, enum GA_REG reg)
371{
372 sscape_write_unsafe(io_base, reg, sscape_read_unsafe(io_base, reg) | 0x01);
373 sscape_write_unsafe(io_base, reg, sscape_read_unsafe(io_base, reg) & 0xfe);
374}
375
376/*
377 * Wait for a DMA transfer to complete. This is a "limited busy-wait",
378 * and all locking issues are left to the caller.
379 */
380static int sscape_wait_dma_unsafe(unsigned io_base, enum GA_REG reg, unsigned timeout)
381{
382 while (!(sscape_read_unsafe(io_base, reg) & 0x01) && (timeout != 0)) {
383 udelay(100);
384 --timeout;
385 } /* while */
386
387 return (sscape_read_unsafe(io_base, reg) & 0x01);
388}
389
390/*
391 * Wait for the On-Board Processor to return its start-up
392 * acknowledgement sequence. This wait is too long for
393 * us to perform "busy-waiting", and so we must sleep.
394 * This in turn means that we must not be holding any
395 * spinlocks when we call this function.
396 */
397static int obp_startup_ack(struct soundscape *s, unsigned timeout)
398{
399 while (timeout != 0) {
400 unsigned long flags;
401 unsigned char x;
402
Rene Hermand86d0192007-09-18 18:10:49 +0200403 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 spin_lock_irqsave(&s->lock, flags);
406 x = inb(HOST_DATA_IO(s->io_base));
407 spin_unlock_irqrestore(&s->lock, flags);
408 if ((x & 0xfe) == 0xfe)
409 return 1;
410
411 --timeout;
412 } /* while */
413
414 return 0;
415}
416
417/*
418 * Wait for the host to return its start-up acknowledgement
419 * sequence. This wait is too long for us to perform
420 * "busy-waiting", and so we must sleep. This in turn means
421 * that we must not be holding any spinlocks when we call
422 * this function.
423 */
424static int host_startup_ack(struct soundscape *s, unsigned timeout)
425{
426 while (timeout != 0) {
427 unsigned long flags;
428 unsigned char x;
429
Rene Hermand86d0192007-09-18 18:10:49 +0200430 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 spin_lock_irqsave(&s->lock, flags);
433 x = inb(HOST_DATA_IO(s->io_base));
434 spin_unlock_irqrestore(&s->lock, flags);
435 if (x == 0xfe)
436 return 1;
437
438 --timeout;
439 } /* while */
440
441 return 0;
442}
443
444/*
445 * Upload a byte-stream into the SoundScape using DMA channel A.
446 */
447static int upload_dma_data(struct soundscape *s,
448 const unsigned char __user *data,
449 size_t size)
450{
451 unsigned long flags;
452 struct snd_dma_buffer dma;
453 int ret;
454
455 if (!get_dmabuf(&dma, PAGE_ALIGN(size)))
456 return -ENOMEM;
457
458 spin_lock_irqsave(&s->lock, flags);
459
460 /*
461 * Reset the board ...
462 */
463 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f);
464
465 /*
466 * Enable the DMA channels and configure them ...
467 */
468 sscape_write_unsafe(s->io_base, GA_DMACFG_REG, 0x50);
469 sscape_write_unsafe(s->io_base, GA_DMAA_REG, (s->chip->dma1 << 4) | DMA_8BIT);
470 sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20);
471
472 /*
473 * Take the board out of reset ...
474 */
475 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x80);
476
477 /*
478 * Upload the user's data (firmware?) to the SoundScape
479 * board through the DMA channel ...
480 */
481 while (size != 0) {
482 unsigned long len;
483
484 /*
485 * Apparently, copying to/from userspace can sleep.
486 * We are therefore forbidden from holding any
487 * spinlocks while we copy ...
488 */
489 spin_unlock_irqrestore(&s->lock, flags);
490
491 /*
492 * Remember that the data that we want to DMA
493 * comes from USERSPACE. We have already verified
494 * the userspace pointer ...
495 */
496 len = min(size, dma.bytes);
497 len -= __copy_from_user(dma.area, data, len);
498 data += len;
499 size -= len;
500
501 /*
502 * Grab that spinlock again, now that we've
503 * finished copying!
504 */
505 spin_lock_irqsave(&s->lock, flags);
506
507 snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE);
508 sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG);
509 if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) {
510 /*
511 * Don't forget to release this spinlock we're holding ...
512 */
513 spin_unlock_irqrestore(&s->lock, flags);
514
515 snd_printk(KERN_ERR "sscape: DMA upload has timed out\n");
516 ret = -EAGAIN;
517 goto _release_dma;
518 }
519 } /* while */
520
521 set_host_mode_unsafe(s->io_base);
522
523 /*
524 * Boot the board ... (I think)
525 */
526 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x40);
527 spin_unlock_irqrestore(&s->lock, flags);
528
529 /*
530 * If all has gone well, then the board should acknowledge
531 * the new upload and tell us that it has rebooted OK. We
532 * give it 5 seconds (max) ...
533 */
534 ret = 0;
535 if (!obp_startup_ack(s, 5)) {
536 snd_printk(KERN_ERR "sscape: No response from on-board processor after upload\n");
537 ret = -EAGAIN;
538 } else if (!host_startup_ack(s, 5)) {
539 snd_printk(KERN_ERR "sscape: SoundScape failed to initialise\n");
540 ret = -EAGAIN;
541 }
542
Krzysztof Helt4996bca2007-09-17 16:23:13 +0200543_release_dma:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 /*
545 * NOTE!!! We are NOT holding any spinlocks at this point !!!
546 */
547 sscape_write(s, GA_DMAA_REG, (s->ic_type == IC_ODIE ? 0x70 : 0x40));
548 free_dmabuf(&dma);
549
550 return ret;
551}
552
553/*
554 * Upload the bootblock(?) into the SoundScape. The only
555 * purpose of this block of code seems to be to tell
556 * us which version of the microcode we should be using.
557 *
558 * NOTE: The boot-block data resides in USER-SPACE!!!
559 * However, we have already verified its memory
560 * addresses by the time we get here.
561 */
562static int sscape_upload_bootblock(struct soundscape *sscape, struct sscape_bootblock __user *bb)
563{
564 unsigned long flags;
565 int data = 0;
566 int ret;
567
568 ret = upload_dma_data(sscape, bb->code, sizeof(bb->code));
569
570 spin_lock_irqsave(&sscape->lock, flags);
571 if (ret == 0) {
572 data = host_read_ctrl_unsafe(sscape->io_base, 100);
573 }
574 set_midi_mode_unsafe(sscape->io_base);
575 spin_unlock_irqrestore(&sscape->lock, flags);
576
577 if (ret == 0) {
578 if (data < 0) {
579 snd_printk(KERN_ERR "sscape: timeout reading firmware version\n");
580 ret = -EAGAIN;
581 }
582 else if (__copy_to_user(&bb->version, &data, sizeof(bb->version))) {
583 ret = -EFAULT;
584 }
585 }
586
587 return ret;
588}
589
590/*
591 * Upload the microcode into the SoundScape. The
592 * microcode is 64K of data, and if we try to copy
593 * it into a local variable then we will SMASH THE
594 * KERNEL'S STACK! We therefore leave it in USER
595 * SPACE, and save ourselves from copying it at all.
596 */
597static int sscape_upload_microcode(struct soundscape *sscape,
598 const struct sscape_microcode __user *mc)
599{
600 unsigned long flags;
601 char __user *code;
602 int err;
603
604 /*
605 * We are going to have to copy this data into a special
606 * DMA-able buffer before we can upload it. We shall therefore
607 * just check that the data pointer is valid for now.
608 *
609 * NOTE: This buffer is 64K long! That's WAY too big to
610 * copy into a stack-temporary anyway.
611 */
612 if ( get_user(code, &mc->code) ||
613 !access_ok(VERIFY_READ, code, SSCAPE_MICROCODE_SIZE) )
614 return -EFAULT;
615
616 if ((err = upload_dma_data(sscape, code, SSCAPE_MICROCODE_SIZE)) == 0) {
617 snd_printk(KERN_INFO "sscape: MIDI firmware loaded\n");
618 }
619
620 spin_lock_irqsave(&sscape->lock, flags);
621 set_midi_mode_unsafe(sscape->io_base);
622 spin_unlock_irqrestore(&sscape->lock, flags);
623
624 initialise_mpu401(sscape->mpu);
625
626 return err;
627}
628
629/*
630 * Hardware-specific device functions, to implement special
631 * IOCTLs for the SoundScape card. This is how we upload
632 * the microcode into the card, for example, and so we
633 * must ensure that no two processes can open this device
634 * simultaneously, and that we can't open it at all if
635 * someone is using the MIDI device.
636 */
Takashi Iwaibe624532005-11-17 14:42:05 +0100637static int sscape_hw_open(struct snd_hwdep * hw, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638{
639 register struct soundscape *sscape = get_hwdep_soundscape(hw);
640 unsigned long flags;
641 int err;
642
643 spin_lock_irqsave(&sscape->fwlock, flags);
644
645 if ((sscape->midi_usage != 0) || sscape->hw_in_use) {
646 err = -EBUSY;
647 } else {
648 sscape->hw_in_use = 1;
649 err = 0;
650 }
651
652 spin_unlock_irqrestore(&sscape->fwlock, flags);
653 return err;
654}
655
Takashi Iwaibe624532005-11-17 14:42:05 +0100656static int sscape_hw_release(struct snd_hwdep * hw, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657{
658 register struct soundscape *sscape = get_hwdep_soundscape(hw);
659 unsigned long flags;
660
661 spin_lock_irqsave(&sscape->fwlock, flags);
662 sscape->hw_in_use = 0;
663 spin_unlock_irqrestore(&sscape->fwlock, flags);
664 return 0;
665}
666
Takashi Iwaibe624532005-11-17 14:42:05 +0100667static int sscape_hw_ioctl(struct snd_hwdep * hw, struct file *file,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 unsigned int cmd, unsigned long arg)
669{
670 struct soundscape *sscape = get_hwdep_soundscape(hw);
671 int err = -EBUSY;
672
673 switch (cmd) {
674 case SND_SSCAPE_LOAD_BOOTB:
675 {
676 register struct sscape_bootblock __user *bb = (struct sscape_bootblock __user *) arg;
677
678 /*
679 * We are going to have to copy this data into a special
680 * DMA-able buffer before we can upload it. We shall therefore
681 * just check that the data pointer is valid for now ...
682 */
683 if ( !access_ok(VERIFY_READ, bb->code, sizeof(bb->code)) )
684 return -EFAULT;
685
686 /*
687 * Now check that we can write the firmware version number too...
688 */
689 if ( !access_ok(VERIFY_WRITE, &bb->version, sizeof(bb->version)) )
690 return -EFAULT;
691
692 err = sscape_upload_bootblock(sscape, bb);
693 }
694 break;
695
696 case SND_SSCAPE_LOAD_MCODE:
697 {
698 register const struct sscape_microcode __user *mc = (const struct sscape_microcode __user *) arg;
699
700 err = sscape_upload_microcode(sscape, mc);
701 }
702 break;
703
704 default:
705 err = -EINVAL;
706 break;
707 } /* switch */
708
709 return err;
710}
711
712
713/*
714 * Mixer control for the SoundScape's MIDI device.
715 */
Takashi Iwaibe624532005-11-17 14:42:05 +0100716static int sscape_midi_info(struct snd_kcontrol *ctl,
717 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718{
719 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
720 uinfo->count = 1;
721 uinfo->value.integer.min = 0;
722 uinfo->value.integer.max = 127;
723 return 0;
724}
725
Takashi Iwaibe624532005-11-17 14:42:05 +0100726static int sscape_midi_get(struct snd_kcontrol *kctl,
727 struct snd_ctl_elem_value *uctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200729 struct snd_wss *chip = snd_kcontrol_chip(kctl);
Takashi Iwaibe624532005-11-17 14:42:05 +0100730 struct snd_card *card = chip->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 register struct soundscape *s = get_card_soundscape(card);
732 unsigned long flags;
733
734 spin_lock_irqsave(&s->lock, flags);
735 set_host_mode_unsafe(s->io_base);
736
737 if (host_write_ctrl_unsafe(s->io_base, CMD_GET_MIDI_VOL, 100)) {
738 uctl->value.integer.value[0] = host_read_ctrl_unsafe(s->io_base, 100);
739 }
740
741 set_midi_mode_unsafe(s->io_base);
742 spin_unlock_irqrestore(&s->lock, flags);
743 return 0;
744}
745
Takashi Iwaibe624532005-11-17 14:42:05 +0100746static int sscape_midi_put(struct snd_kcontrol *kctl,
747 struct snd_ctl_elem_value *uctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200749 struct snd_wss *chip = snd_kcontrol_chip(kctl);
Takashi Iwaibe624532005-11-17 14:42:05 +0100750 struct snd_card *card = chip->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 register struct soundscape *s = get_card_soundscape(card);
752 unsigned long flags;
753 int change;
754
755 spin_lock_irqsave(&s->lock, flags);
756
757 /*
758 * We need to put the board into HOST mode before we
759 * can send any volume-changing HOST commands ...
760 */
761 set_host_mode_unsafe(s->io_base);
762
763 /*
764 * To successfully change the MIDI volume setting, you seem to
765 * have to write a volume command, write the new volume value,
766 * and then perform another volume-related command. Perhaps the
767 * first command is an "open" and the second command is a "close"?
768 */
769 if (s->midi_vol == ((unsigned char) uctl->value.integer. value[0] & 127)) {
770 change = 0;
771 goto __skip_change;
772 }
773 change = (host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100)
774 && host_write_ctrl_unsafe(s->io_base, ((unsigned char) uctl->value.integer. value[0]) & 127, 100)
775 && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100));
776 __skip_change:
777
778 /*
779 * Take the board out of HOST mode and back into MIDI mode ...
780 */
781 set_midi_mode_unsafe(s->io_base);
782
783 spin_unlock_irqrestore(&s->lock, flags);
784 return change;
785}
786
Takashi Iwaibe624532005-11-17 14:42:05 +0100787static struct snd_kcontrol_new midi_mixer_ctl = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
789 .name = "MIDI",
790 .info = sscape_midi_info,
791 .get = sscape_midi_get,
792 .put = sscape_midi_put
793};
794
795/*
796 * The SoundScape can use two IRQs from a possible set of four.
797 * These IRQs are encoded as bit patterns so that they can be
798 * written to the control registers.
799 */
800static unsigned __devinit get_irq_config(int irq)
801{
802 static const int valid_irq[] = { 9, 5, 7, 10 };
803 unsigned cfg;
804
805 for (cfg = 0; cfg < ARRAY_SIZE(valid_irq); ++cfg) {
806 if (irq == valid_irq[cfg])
807 return cfg;
808 } /* for */
809
810 return INVALID_IRQ;
811}
812
813
814/*
815 * Perform certain arcane port-checks to see whether there
816 * is a SoundScape board lurking behind the given ports.
817 */
818static int __devinit detect_sscape(struct soundscape *s)
819{
820 unsigned long flags;
821 unsigned d;
822 int retval = 0;
Krzysztof Heltec1e7942007-09-17 17:57:37 +0200823 int codec = s->wss_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 spin_lock_irqsave(&s->lock, flags);
826
827 /*
828 * The following code is lifted from the original OSS driver,
829 * and as I don't have a datasheet I cannot really comment
830 * on what it is doing...
831 */
832 if ((inb(HOST_CTRL_IO(s->io_base)) & 0x78) != 0)
833 goto _done;
834
835 d = inb(ODIE_ADDR_IO(s->io_base)) & 0xf0;
836 if ((d & 0x80) != 0)
837 goto _done;
838
839 if (d == 0) {
840 s->codec_type = 1;
841 s->ic_type = IC_ODIE;
842 } else if ((d & 0x60) != 0) {
843 s->codec_type = 2;
844 s->ic_type = IC_OPUS;
845 } else
846 goto _done;
847
848 outb(0xfa, ODIE_ADDR_IO(s->io_base));
849 if ((inb(ODIE_ADDR_IO(s->io_base)) & 0x9f) != 0x0a)
850 goto _done;
851
852 outb(0xfe, ODIE_ADDR_IO(s->io_base));
853 if ((inb(ODIE_ADDR_IO(s->io_base)) & 0x9f) != 0x0e)
854 goto _done;
Krzysztof Heltec1e7942007-09-17 17:57:37 +0200855
856 outb(0xfe, ODIE_ADDR_IO(s->io_base));
857 d = inb(ODIE_DATA_IO(s->io_base));
858 if (s->type != SSCAPE_VIVO && (d & 0x9f) != 0x0e)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 goto _done;
860
Krzysztof Heltec1e7942007-09-17 17:57:37 +0200861 d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f;
862 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);
863
864 if (s->type == SSCAPE_VIVO)
865 codec += 4;
866 /* wait for WSS codec */
867 for (d = 0; d < 500; d++) {
868 if ((inb(codec) & 0x80) == 0)
869 break;
870 spin_unlock_irqrestore(&s->lock, flags);
871 msleep(1);
872 spin_lock_irqsave(&s->lock, flags);
873 }
874 snd_printd(KERN_INFO "init delay = %d ms\n", d);
875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 /*
877 * SoundScape successfully detected!
878 */
879 retval = 1;
880
881 _done:
882 spin_unlock_irqrestore(&s->lock, flags);
883 return retval;
884}
885
886/*
887 * ALSA callback function, called when attempting to open the MIDI device.
888 * Check that the MIDI firmware has been loaded, because we don't want
889 * to crash the machine. Also check that someone isn't using the hardware
890 * IOCTL device.
891 */
Takashi Iwaibe624532005-11-17 14:42:05 +0100892static int mpu401_open(struct snd_mpu401 * mpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893{
894 int err;
895
896 if (!verify_mpu401(mpu)) {
897 snd_printk(KERN_ERR "sscape: MIDI disabled, please load firmware\n");
898 err = -ENODEV;
899 } else {
900 register struct soundscape *sscape = get_mpu401_soundscape(mpu);
901 unsigned long flags;
902
903 spin_lock_irqsave(&sscape->fwlock, flags);
904
905 if (sscape->hw_in_use || (sscape->midi_usage == ULONG_MAX)) {
906 err = -EBUSY;
907 } else {
908 ++(sscape->midi_usage);
909 err = 0;
910 }
911
912 spin_unlock_irqrestore(&sscape->fwlock, flags);
913 }
914
915 return err;
916}
917
Takashi Iwaibe624532005-11-17 14:42:05 +0100918static void mpu401_close(struct snd_mpu401 * mpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
920 register struct soundscape *sscape = get_mpu401_soundscape(mpu);
921 unsigned long flags;
922
923 spin_lock_irqsave(&sscape->fwlock, flags);
924 --(sscape->midi_usage);
925 spin_unlock_irqrestore(&sscape->fwlock, flags);
926}
927
928/*
929 * Initialse an MPU-401 subdevice for MIDI support on the SoundScape.
930 */
Takashi Iwaibe624532005-11-17 14:42:05 +0100931static int __devinit create_mpu401(struct snd_card *card, int devnum, unsigned long port, int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932{
933 struct soundscape *sscape = get_card_soundscape(card);
Takashi Iwaibe624532005-11-17 14:42:05 +0100934 struct snd_rawmidi *rawmidi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 int err;
936
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 if ((err = snd_mpu401_uart_new(card, devnum,
938 MPU401_HW_MPU401,
Takashi Iwai302e4c22006-05-23 13:24:30 +0200939 port, MPU401_INFO_INTEGRATED,
Thomas Gleixner65ca68b2006-07-01 19:29:46 -0700940 irq, IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 &rawmidi)) == 0) {
Takashi Iwaibe624532005-11-17 14:42:05 +0100942 struct snd_mpu401 *mpu = (struct snd_mpu401 *) rawmidi->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 mpu->open_input = mpu401_open;
944 mpu->open_output = mpu401_open;
945 mpu->close_input = mpu401_close;
946 mpu->close_output = mpu401_close;
947 mpu->private_data = sscape;
948 sscape->mpu = mpu;
949
950 initialise_mpu401(mpu);
951 }
952
953 return err;
954}
955
956
957/*
958 * Override for the CS4231 playback format function.
959 * The AD1845 has much simpler format and rate selection.
960 */
Krzysztof Helt7779f752008-07-31 21:03:41 +0200961static void ad1845_playback_format(struct snd_wss *chip,
962 struct snd_pcm_hw_params *params,
963 unsigned char format)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964{
965 unsigned long flags;
966 unsigned rate = params_rate(params);
967
968 /*
969 * The AD1845 can't handle sample frequencies
970 * outside of 4 kHZ to 50 kHZ
971 */
972 if (rate > 50000)
973 rate = 50000;
974 else if (rate < 4000)
975 rate = 4000;
976
977 spin_lock_irqsave(&chip->reg_lock, flags);
978
979 /*
980 * Program the AD1845 correctly for the playback stream.
981 * Note that we do NOT need to toggle the MCE bit because
982 * the PLAYBACK_ENABLE bit of the Interface Configuration
983 * register is set.
984 *
985 * NOTE: We seem to need to write to the MSB before the LSB
986 * to get the correct sample frequency.
987 */
Krzysztof Helt7779f752008-07-31 21:03:41 +0200988 snd_wss_out(chip, CS4231_PLAYBK_FORMAT, (format & 0xf0));
989 snd_wss_out(chip, AD1845_FREQ_SEL_MSB, (unsigned char) (rate >> 8));
990 snd_wss_out(chip, AD1845_FREQ_SEL_LSB, (unsigned char) rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
992 spin_unlock_irqrestore(&chip->reg_lock, flags);
993}
994
995/*
996 * Override for the CS4231 capture format function.
997 * The AD1845 has much simpler format and rate selection.
998 */
Krzysztof Helt7779f752008-07-31 21:03:41 +0200999static void ad1845_capture_format(struct snd_wss *chip,
1000 struct snd_pcm_hw_params *params,
1001 unsigned char format)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002{
1003 unsigned long flags;
1004 unsigned rate = params_rate(params);
1005
1006 /*
1007 * The AD1845 can't handle sample frequencies
1008 * outside of 4 kHZ to 50 kHZ
1009 */
1010 if (rate > 50000)
1011 rate = 50000;
1012 else if (rate < 4000)
1013 rate = 4000;
1014
1015 spin_lock_irqsave(&chip->reg_lock, flags);
1016
1017 /*
1018 * Program the AD1845 correctly for the playback stream.
1019 * Note that we do NOT need to toggle the MCE bit because
1020 * the CAPTURE_ENABLE bit of the Interface Configuration
1021 * register is set.
1022 *
1023 * NOTE: We seem to need to write to the MSB before the LSB
1024 * to get the correct sample frequency.
1025 */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001026 snd_wss_out(chip, CS4231_REC_FORMAT, (format & 0xf0));
1027 snd_wss_out(chip, AD1845_FREQ_SEL_MSB, (unsigned char) (rate >> 8));
1028 snd_wss_out(chip, AD1845_FREQ_SEL_LSB, (unsigned char) rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 spin_unlock_irqrestore(&chip->reg_lock, flags);
1031}
1032
1033/*
1034 * Create an AD1845 PCM subdevice on the SoundScape. The AD1845
1035 * is very much like a CS4231, with a few extra bits. We will
1036 * try to support at least some of the extra bits by overriding
1037 * some of the CS4231 callback.
1038 */
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001039static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1040 int irq, int dma1, int dma2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
1042 register struct soundscape *sscape = get_card_soundscape(card);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001043 struct snd_wss *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 int err;
1045
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001046 if (sscape->type == SSCAPE_VIVO)
1047 port += 4;
1048
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001049 if (dma1 == dma2)
1050 dma2 = -1;
1051
Krzysztof Helt7779f752008-07-31 21:03:41 +02001052 err = snd_wss_create(card, port, -1, irq, dma1, dma2,
1053 WSS_HW_DETECT, WSS_HWSHARE_DMA1, &chip);
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001054 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 unsigned long flags;
Takashi Iwaibe624532005-11-17 14:42:05 +01001056 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
1058#define AD1845_FREQ_SEL_ENABLE 0x08
1059
1060#define AD1845_PWR_DOWN_CTRL 0x1b
1061#define AD1845_CRYS_CLOCK_SEL 0x1d
1062
1063/*
1064 * It turns out that the PLAYBACK_ENABLE bit is set
1065 * by the lowlevel driver ...
1066 *
1067#define AD1845_IFACE_CONFIG \
1068 (CS4231_AUTOCALIB | CS4231_RECORD_ENABLE | CS4231_PLAYBACK_ENABLE)
Krzysztof Helt7779f752008-07-31 21:03:41 +02001069 snd_wss_mce_up(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001071 snd_wss_out(chip, CS4231_IFACE_CTRL, AD1845_IFACE_CONFIG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 spin_unlock_irqrestore(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001073 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 */
1075
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001076 if (sscape->type != SSCAPE_VIVO) {
1077 int val;
1078 /*
1079 * The input clock frequency on the SoundScape must
1080 * be 14.31818 MHz, because we must set this register
1081 * to get the playback to sound correct ...
1082 */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001083 snd_wss_mce_up(chip);
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001084 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001085 snd_wss_out(chip, AD1845_CRYS_CLOCK_SEL, 0x20);
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001086 spin_unlock_irqrestore(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001087 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001089 /*
1090 * More custom configuration:
1091 * a) select "mode 2" and provide a current drive of 8mA
1092 * b) enable frequency selection (for capture/playback)
1093 */
1094 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001095 snd_wss_out(chip, CS4231_MISC_INFO,
1096 CS4231_MODE2 | 0x10);
1097 val = snd_wss_in(chip, AD1845_PWR_DOWN_CTRL);
1098 snd_wss_out(chip, AD1845_PWR_DOWN_CTRL,
1099 val | AD1845_FREQ_SEL_ENABLE);
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001100 spin_unlock_irqrestore(&chip->reg_lock, flags);
1101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
Krzysztof Helt7779f752008-07-31 21:03:41 +02001103 err = snd_wss_pcm(chip, 0, &pcm);
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001104 if (err < 0) {
1105 snd_printk(KERN_ERR "sscape: No PCM device "
1106 "for AD1845 chip\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 goto _error;
1108 }
1109
Krzysztof Helt7779f752008-07-31 21:03:41 +02001110 err = snd_wss_mixer(chip);
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001111 if (err < 0) {
1112 snd_printk(KERN_ERR "sscape: No mixer device "
1113 "for AD1845 chip\n");
1114 goto _error;
1115 }
Krzysztof Helt7779f752008-07-31 21:03:41 +02001116 err = snd_wss_timer(chip, 0, NULL);
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001117 if (err < 0) {
1118 snd_printk(KERN_ERR "sscape: No timer device "
1119 "for AD1845 chip\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 goto _error;
1121 }
1122
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001123 if (sscape->type != SSCAPE_VIVO) {
1124 err = snd_ctl_add(card,
1125 snd_ctl_new1(&midi_mixer_ctl, chip));
1126 if (err < 0) {
1127 snd_printk(KERN_ERR "sscape: Could not create "
1128 "MIDI mixer control\n");
1129 goto _error;
1130 }
1131 chip->set_playback_format = ad1845_playback_format;
1132 chip->set_capture_format = ad1845_capture_format;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 }
1134
1135 strcpy(card->driver, "SoundScape");
1136 strcpy(card->shortname, pcm->name);
1137 snprintf(card->longname, sizeof(card->longname),
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001138 "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n",
1139 pcm->name, chip->port, chip->irq,
1140 chip->dma1, chip->dma2);
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001141
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 sscape->chip = chip;
1143 }
1144
1145 _error:
1146 return err;
1147}
1148
1149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150/*
1151 * Create an ALSA soundcard entry for the SoundScape, using
1152 * the given list of port, IRQ and DMA resources.
1153 */
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001154static int __devinit create_sscape(int dev, struct snd_card *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155{
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001156 struct soundscape *sscape = get_card_soundscape(card);
1157 unsigned dma_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 unsigned irq_cfg;
1159 unsigned mpu_irq_cfg;
Takashi Iwai277e9262005-11-17 17:13:12 +01001160 unsigned xport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 struct resource *io_res;
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001162 struct resource *wss_res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 unsigned long flags;
1164 int err;
1165
1166 /*
1167 * Check that the user didn't pass us garbage data ...
1168 */
Takashi Iwai277e9262005-11-17 17:13:12 +01001169 irq_cfg = get_irq_config(irq[dev]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 if (irq_cfg == INVALID_IRQ) {
Takashi Iwai277e9262005-11-17 17:13:12 +01001171 snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", irq[dev]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 return -ENXIO;
1173 }
1174
Takashi Iwai277e9262005-11-17 17:13:12 +01001175 mpu_irq_cfg = get_irq_config(mpu_irq[dev]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 if (mpu_irq_cfg == INVALID_IRQ) {
Takashi Iwai277e9262005-11-17 17:13:12 +01001177 printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 return -ENXIO;
1179 }
Takashi Iwai277e9262005-11-17 17:13:12 +01001180 xport = port[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
1182 /*
1183 * Grab IO ports that we will need to probe so that we
1184 * can detect and control this hardware ...
1185 */
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001186 io_res = request_region(xport, 8, "SoundScape");
1187 if (!io_res) {
Takashi Iwai277e9262005-11-17 17:13:12 +01001188 snd_printk(KERN_ERR "sscape: can't grab port 0x%x\n", xport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 return -EBUSY;
1190 }
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001191 wss_res = NULL;
1192 if (sscape->type == SSCAPE_VIVO) {
1193 wss_res = request_region(wss_port[dev], 4, "SoundScape");
1194 if (!wss_res) {
1195 snd_printk(KERN_ERR "sscape: can't grab port 0x%lx\n",
1196 wss_port[dev]);
1197 err = -EBUSY;
1198 goto _release_region;
1199 }
1200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
1202 /*
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001203 * Grab one DMA channel ...
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 */
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001205 err = request_dma(dma[dev], "SoundScape");
1206 if (err < 0) {
Takashi Iwai277e9262005-11-17 17:13:12 +01001207 snd_printk(KERN_ERR "sscape: can't grab DMA %d\n", dma[dev]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 goto _release_region;
1209 }
1210
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 spin_lock_init(&sscape->lock);
1212 spin_lock_init(&sscape->fwlock);
1213 sscape->io_res = io_res;
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001214 sscape->wss_res = wss_res;
Takashi Iwai277e9262005-11-17 17:13:12 +01001215 sscape->io_base = xport;
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001216 sscape->wss_base = wss_port[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
1218 if (!detect_sscape(sscape)) {
1219 printk(KERN_ERR "sscape: hardware not detected at 0x%x\n", sscape->io_base);
1220 err = -ENODEV;
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001221 goto _release_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 }
1223
1224 printk(KERN_INFO "sscape: hardware detected at 0x%x, using IRQ %d, DMA %d\n",
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001225 sscape->io_base, irq[dev], dma[dev]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001227 if (sscape->type != SSCAPE_VIVO) {
1228 /*
1229 * Now create the hardware-specific device so that we can
1230 * load the microcode into the on-board processor.
1231 * We cannot use the MPU-401 MIDI system until this firmware
1232 * has been loaded into the card.
1233 */
1234 err = snd_hwdep_new(card, "MC68EC000", 0, &(sscape->hw));
1235 if (err < 0) {
1236 printk(KERN_ERR "sscape: Failed to create "
1237 "firmware device\n");
1238 goto _release_dma;
1239 }
1240 strlcpy(sscape->hw->name, "SoundScape M68K",
1241 sizeof(sscape->hw->name));
1242 sscape->hw->name[sizeof(sscape->hw->name) - 1] = '\0';
1243 sscape->hw->iface = SNDRV_HWDEP_IFACE_SSCAPE;
1244 sscape->hw->ops.open = sscape_hw_open;
1245 sscape->hw->ops.release = sscape_hw_release;
1246 sscape->hw->ops.ioctl = sscape_hw_ioctl;
1247 sscape->hw->private_data = sscape;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
1250 /*
1251 * Tell the on-board devices where their resources are (I think -
1252 * I can't be sure without a datasheet ... So many magic values!)
1253 */
1254 spin_lock_irqsave(&sscape->lock, flags);
1255
1256 activate_ad1845_unsafe(sscape->io_base);
1257
1258 sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x00); /* disable */
1259 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e);
1260 sscape_write_unsafe(sscape->io_base, GA_SMCFGB_REG, 0x00);
1261
1262 /*
1263 * Enable and configure the DMA channels ...
1264 */
1265 sscape_write_unsafe(sscape->io_base, GA_DMACFG_REG, 0x50);
1266 dma_cfg = (sscape->ic_type == IC_ODIE ? 0x70 : 0x40);
1267 sscape_write_unsafe(sscape->io_base, GA_DMAA_REG, dma_cfg);
1268 sscape_write_unsafe(sscape->io_base, GA_DMAB_REG, 0x20);
1269
1270 sscape_write_unsafe(sscape->io_base,
1271 GA_INTCFG_REG, 0xf0 | (mpu_irq_cfg << 2) | mpu_irq_cfg);
1272 sscape_write_unsafe(sscape->io_base,
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001273 GA_CDCFG_REG, 0x09 | DMA_8BIT
1274 | (dma[dev] << 4) | (irq_cfg << 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 spin_unlock_irqrestore(&sscape->lock, flags);
1277
1278 /*
1279 * We have now enabled the codec chip, and so we should
1280 * detect the AD1845 device ...
1281 */
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001282 err = create_ad1845(card, wss_port[dev], irq[dev],
1283 dma[dev], dma2[dev]);
1284 if (err < 0) {
1285 printk(KERN_ERR "sscape: No AD1845 device at 0x%lx, IRQ %d\n",
1286 wss_port[dev], irq[dev]);
1287 goto _release_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 }
1289#define MIDI_DEVNUM 0
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001290 if (sscape->type != SSCAPE_VIVO) {
1291 err = create_mpu401(card, MIDI_DEVNUM,
1292 MPU401_IO(xport), mpu_irq[dev]);
1293 if (err < 0) {
1294 printk(KERN_ERR "sscape: Failed to create "
1295 "MPU-401 device at 0x%x\n",
1296 MPU401_IO(xport));
1297 goto _release_dma;
1298 }
1299
1300 /*
1301 * Enable the master IRQ ...
1302 */
1303 sscape_write(sscape, GA_INTENA_REG, 0x80);
1304
1305 /*
1306 * Initialize mixer
1307 */
1308 sscape->midi_vol = 0;
1309 host_write_ctrl_unsafe(sscape->io_base, CMD_SET_MIDI_VOL, 100);
1310 host_write_ctrl_unsafe(sscape->io_base, 0, 100);
1311 host_write_ctrl_unsafe(sscape->io_base, CMD_XXX_MIDI_VOL, 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 }
1313
1314 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 * Now that we have successfully created this sound card,
1316 * it is safe to store the pointer.
1317 * NOTE: we only register the sound card's "destructor"
1318 * function now that our "constructor" has completed.
1319 */
1320 card->private_free = soundscape_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
1322 return 0;
1323
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001324_release_dma:
Takashi Iwai277e9262005-11-17 17:13:12 +01001325 free_dma(dma[dev]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001327_release_region:
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001328 release_and_free_resource(wss_res);
Takashi Iwaib1d57762005-10-10 11:56:31 +02001329 release_and_free_resource(io_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
1331 return err;
1332}
1333
1334
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001335static int __devinit snd_sscape_match(struct device *pdev, unsigned int i)
Takashi Iwai277e9262005-11-17 17:13:12 +01001336{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001337 /*
1338 * Make sure we were given ALL of the other parameters.
1339 */
1340 if (port[i] == SNDRV_AUTO_PORT)
1341 return 0;
1342
1343 if (irq[i] == SNDRV_AUTO_IRQ ||
1344 mpu_irq[i] == SNDRV_AUTO_IRQ ||
1345 dma[i] == SNDRV_AUTO_DMA) {
1346 printk(KERN_INFO
1347 "sscape: insufficient parameters, need IO, IRQ, MPU-IRQ and DMA\n");
1348 return 0;
1349 }
1350
1351 return 1;
1352}
1353
1354static int __devinit snd_sscape_probe(struct device *pdev, unsigned int dev)
1355{
Takashi Iwai277e9262005-11-17 17:13:12 +01001356 struct snd_card *card;
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001357 struct soundscape *sscape;
Takashi Iwai277e9262005-11-17 17:13:12 +01001358 int ret;
1359
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001360 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
1361 sizeof(struct soundscape));
1362 if (!card)
1363 return -ENOMEM;
1364
1365 sscape = get_card_soundscape(card);
1366 sscape->type = SSCAPE;
1367
Takashi Iwai277e9262005-11-17 17:13:12 +01001368 dma[dev] &= 0x03;
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001369 ret = create_sscape(dev, card);
Takashi Iwai277e9262005-11-17 17:13:12 +01001370 if (ret < 0)
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001371 goto _release_card;
1372
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001373 snd_card_set_dev(card, pdev);
Takashi Iwai277e9262005-11-17 17:13:12 +01001374 if ((ret = snd_card_register(card)) < 0) {
1375 printk(KERN_ERR "sscape: Failed to register sound card\n");
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001376 goto _release_card;
Takashi Iwai277e9262005-11-17 17:13:12 +01001377 }
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001378 dev_set_drvdata(pdev, card);
Takashi Iwai277e9262005-11-17 17:13:12 +01001379 return 0;
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001380
1381_release_card:
1382 snd_card_free(card);
1383 return ret;
Takashi Iwai277e9262005-11-17 17:13:12 +01001384}
1385
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001386static int __devexit snd_sscape_remove(struct device *devptr, unsigned int dev)
Takashi Iwai277e9262005-11-17 17:13:12 +01001387{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001388 snd_card_free(dev_get_drvdata(devptr));
1389 dev_set_drvdata(devptr, NULL);
Takashi Iwai277e9262005-11-17 17:13:12 +01001390 return 0;
1391}
1392
Rene Herman83c51c02007-03-20 11:33:46 +01001393#define DEV_NAME "sscape"
Takashi Iwai277e9262005-11-17 17:13:12 +01001394
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001395static struct isa_driver snd_sscape_driver = {
1396 .match = snd_sscape_match,
Takashi Iwai277e9262005-11-17 17:13:12 +01001397 .probe = snd_sscape_probe,
1398 .remove = __devexit_p(snd_sscape_remove),
1399 /* FIXME: suspend/resume */
1400 .driver = {
Rene Herman83c51c02007-03-20 11:33:46 +01001401 .name = DEV_NAME
Takashi Iwai277e9262005-11-17 17:13:12 +01001402 },
1403};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
1405#ifdef CONFIG_PNP
1406static inline int __devinit get_next_autoindex(int i)
1407{
Takashi Iwai277e9262005-11-17 17:13:12 +01001408 while (i < SNDRV_CARDS && port[i] != SNDRV_AUTO_PORT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 ++i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 return i;
1411}
1412
1413
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414static int __devinit sscape_pnp_detect(struct pnp_card_link *pcard,
1415 const struct pnp_card_device_id *pid)
1416{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 static int idx = 0;
Takashi Iwai277e9262005-11-17 17:13:12 +01001418 struct pnp_dev *dev;
1419 struct snd_card *card;
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001420 struct soundscape *sscape;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 int ret;
1422
1423 /*
1424 * Allow this function to fail *quietly* if all the ISA PnP
1425 * devices were configured using module parameters instead.
1426 */
Takashi Iwai277e9262005-11-17 17:13:12 +01001427 if ((idx = get_next_autoindex(idx)) >= SNDRV_CARDS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 return -ENOSPC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
1430 /*
1431 * We have found a candidate ISA PnP card. Now we
1432 * have to check that it has the devices that we
1433 * expect it to have.
1434 *
1435 * We will NOT try and autoconfigure all of the resources
1436 * needed and then activate the card as we are assuming that
1437 * has already been done at boot-time using /proc/isapnp.
1438 * We shall simply try to give each active card the resources
1439 * that it wants. This is a sensible strategy for a modular
1440 * system where unused modules are unloaded regularly.
1441 *
1442 * This strategy is utterly useless if we compile the driver
1443 * into the kernel, of course.
1444 */
1445 // printk(KERN_INFO "sscape: %s\n", card->name);
1446
1447 /*
1448 * Check that we still have room for another sound card ...
1449 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
Takashi Iwai277e9262005-11-17 17:13:12 +01001451 if (! dev)
1452 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Takashi Iwai277e9262005-11-17 17:13:12 +01001454 if (!pnp_is_active(dev)) {
1455 if (pnp_activate_dev(dev) < 0) {
1456 printk(KERN_INFO "sscape: device is inactive\n");
1457 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 }
1459 }
1460
Takashi Iwai277e9262005-11-17 17:13:12 +01001461 /*
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001462 * Create a new ALSA sound card entry, in anticipation
1463 * of detecting our hardware ...
1464 */
1465 card = snd_card_new(index[idx], id[idx], THIS_MODULE,
1466 sizeof(struct soundscape));
1467 if (!card)
1468 return -ENOMEM;
1469
1470 sscape = get_card_soundscape(card);
1471
1472 /*
1473 * Identify card model ...
1474 */
1475 if (!strncmp("ENS4081", pid->id, 7))
1476 sscape->type = SSCAPE_VIVO;
1477 else
1478 sscape->type = SSCAPE_PNP;
1479
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001480 /*
Takashi Iwai277e9262005-11-17 17:13:12 +01001481 * Read the correct parameters off the ISA PnP bus ...
1482 */
1483 port[idx] = pnp_port_start(dev, 0);
1484 irq[idx] = pnp_irq(dev, 0);
1485 mpu_irq[idx] = pnp_irq(dev, 1);
1486 dma[idx] = pnp_dma(dev, 0) & 0x03;
Krzysztof Heltec1e7942007-09-17 17:57:37 +02001487 if (sscape->type == SSCAPE_PNP) {
1488 dma2[idx] = dma[idx];
1489 wss_port[idx] = CODEC_IO(port[idx]);
1490 } else {
1491 wss_port[idx] = pnp_port_start(dev, 1);
1492 dma2[idx] = pnp_dma(dev, 1);
1493 }
Takashi Iwai277e9262005-11-17 17:13:12 +01001494
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001495 ret = create_sscape(idx, card);
Takashi Iwai277e9262005-11-17 17:13:12 +01001496 if (ret < 0)
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001497 goto _release_card;
1498
Takashi Iwai277e9262005-11-17 17:13:12 +01001499 snd_card_set_dev(card, &pcard->card->dev);
1500 if ((ret = snd_card_register(card)) < 0) {
1501 printk(KERN_ERR "sscape: Failed to register sound card\n");
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001502 goto _release_card;
Takashi Iwai277e9262005-11-17 17:13:12 +01001503 }
1504
1505 pnp_set_card_drvdata(pcard, card);
1506 ++idx;
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001507 return 0;
Takashi Iwai277e9262005-11-17 17:13:12 +01001508
Krzysztof Helt4996bca2007-09-17 16:23:13 +02001509_release_card:
1510 snd_card_free(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 return ret;
1512}
1513
1514static void __devexit sscape_pnp_remove(struct pnp_card_link * pcard)
1515{
Takashi Iwai277e9262005-11-17 17:13:12 +01001516 snd_card_free(pnp_get_card_drvdata(pcard));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518}
1519
1520static struct pnp_card_driver sscape_pnpc_driver = {
1521 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
1522 .name = "sscape",
1523 .id_table = sscape_pnpids,
1524 .probe = sscape_pnp_detect,
1525 .remove = __devexit_p(sscape_pnp_remove),
1526};
1527
1528#endif /* CONFIG_PNP */
1529
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530static int __init sscape_init(void)
1531{
Rene Herman609d7692007-05-15 11:42:56 +02001532 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Rene Herman609d7692007-05-15 11:42:56 +02001534 err = isa_register_driver(&snd_sscape_driver, SNDRV_CARDS);
Takashi Iwai59b1b342006-01-04 15:06:44 +01001535#ifdef CONFIG_PNP
Rene Herman609d7692007-05-15 11:42:56 +02001536 if (!err)
1537 isa_registered = 1;
1538
1539 err = pnp_register_card_driver(&sscape_pnpc_driver);
1540 if (!err)
Clemens Ladischf7a92752005-12-07 09:13:42 +01001541 pnp_registered = 1;
Rene Herman609d7692007-05-15 11:42:56 +02001542
1543 if (isa_registered)
1544 err = 0;
Takashi Iwai59b1b342006-01-04 15:06:44 +01001545#endif
Rene Herman609d7692007-05-15 11:42:56 +02001546 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547}
1548
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001549static void __exit sscape_exit(void)
1550{
1551#ifdef CONFIG_PNP
1552 if (pnp_registered)
1553 pnp_unregister_card_driver(&sscape_pnpc_driver);
Rene Herman609d7692007-05-15 11:42:56 +02001554 if (isa_registered)
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001555#endif
Rene Herman609d7692007-05-15 11:42:56 +02001556 isa_unregister_driver(&snd_sscape_driver);
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001557}
1558
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559module_init(sscape_init);
1560module_exit(sscape_exit);