patch-2.3.24 linux/drivers/sound/nm256.h

Next file: linux/drivers/sound/nm256_audio.c
Previous file: linux/drivers/sound/ac97.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.23/linux/drivers/sound/nm256.h linux/drivers/sound/nm256.h
@@ -3,10 +3,12 @@
 
 #include "ac97.h"
 
+/* The revisions that we currently handle.  */
 enum nm256rev {
     REV_NM256AV, REV_NM256ZX
 };
 
+/* Per-card structure. */
 struct nm256_info 
 {
     /* Magic number used to verify that this struct is valid. */
@@ -34,10 +36,12 @@
     /* The mixer device. */
     int mixer_oss_dev;
 
-    /* Can only be opened once for each operation.  These aren't set
-       until an actual I/O operation is performed; this allows one
-       device to be open for read/write without inhibiting I/O to
-       the other device.  */
+    /* 
+     * Can only be opened once for each operation.  These aren't set
+     * until an actual I/O operation is performed; this allows one
+     * device to be open for read/write without inhibiting I/O to
+     * the other device.
+     */
     int is_open_play;
     int is_open_record;
 
@@ -46,25 +50,40 @@
     /* Ditto for recording a sample. */
     int recording;
 
-    /* The two memory ports. */
-    char *ports[2];
-
-    /* Starting offset of the port1 area mapped into memory. */
-    u32 port1_start;
-    /* Ending offset. */
-    u32 port1_end;
-    /* The offset of the end of the actual buffer area.  */
-    u32 bufend;
+    /* The two memory ports.  */
+    struct nm256_ports {
+	/* Physical address of the port. */
+	u32 physaddr;
+	/* Our mapped-in pointer. */
+	char *ptr;
+	/* PTR's offset within the physical port.  */
+	u32 start_offset;
+	/* And the offset of the end of the buffer.  */
+	u32 end_offset;
+    } port[2];
 
     /* The following are offsets within memory port 1. */
     u32 coeffBuf;
     u32 allCoeffBuf;
+
     /* Record and playback buffers. */
     u32 abuf1, abuf2;
 
     /* Offset of the AC97 mixer in memory port 2. */
     u32 mixer;
 
+    /* Offset of the mixer status register in memory port 2.  */
+    u32 mixer_status_offset;
+
+    /* Non-zero if we have written initial values to the mixer. */
+    u8 mixer_values_init;
+
+    /* 
+     * Status mask bit; (*mixer_status_loc & mixer_status_mask) == 0 means
+     * it's ready.  
+     */
+    u16 mixer_status_mask;
+
     /* The sizes of the playback and record ring buffers. */
     u32 playbackBufferSize;
     u32 recordBufferSize;
@@ -77,7 +96,7 @@
     /* The start of the block currently playing. */
     u32 curPlayPos;
 
-    /* The amount of data we requested to record. */
+    /* The amount of data we were requested to record. */
     u32 requestedRecAmt;
     /* The offset of the currently-recording block. */
     u32 curRecPos;
@@ -107,10 +126,17 @@
 /* Debug flag--bigger numbers mean more output. */
 extern int nm256_debug;
 
-/* Size of the second memory port. */
+/* The BIOS signature. */
+#define NM_SIGNATURE 0x4e4d0000
+/* Signature mask. */
+#define NM_SIG_MASK 0xffff0000
+
+/* Size of the second memory area. */
 #define NM_PORT2_SIZE 4096
-/* The location of the mixer. */
-#define NM_MIXER_BASE 0x600
+
+/* The base offset of the mixer in the second memory area. */
+#define NM_MIXER_OFFSET 0x600
+
 /* The maximum size of a coefficient entry. */
 #define NM_MAX_COEFFICIENT 0x5000
 
@@ -123,21 +149,33 @@
 #define NM_MISC_INT_2 0x1
 #define NM_ACK_INT(CARD, X) nm256_writePort16((CARD), 2, NM_INT_REG, (X) << 1)
 
-/* For the second revision.  It uses the same interrupt register, but it
-   holds 32 bits instead of 16.  */
+/* The AV's "mixer ready" status bit and location. */
+#define NM_MIXER_STATUS_OFFSET 0xa04
+#define NM_MIXER_READY_MASK 0x0800
+#define NM_MIXER_PRESENCE 0xa06
+#define NM_PRESENCE_MASK 0x0050
+#define NM_PRESENCE_VALUE 0x0040
+
+/*
+ * For the ZX.  It uses the same interrupt register, but it holds 32
+ * bits instead of 16.
+ */
 #define NM2_PLAYBACK_INT 0x10000
 #define NM2_RECORD_INT 0x80000
 #define NM2_MISC_INT_1 0x8
 #define NM2_MISC_INT_2 0x2
 #define NM2_ACK_INT(CARD, X) nm256_writePort32((CARD), 2, NM_INT_REG, (X))
 
+/* The ZX's "mixer ready" status bit and location. */
+#define NM2_MIXER_STATUS_OFFSET 0xa06
+#define NM2_MIXER_READY_MASK 0x0800
+
 /* The playback registers start from here. */
 #define NM_PLAYBACK_REG_OFFSET 0x0
 /* The record registers start from here. */
 #define NM_RECORD_REG_OFFSET 0x200
 
-/* The rate register is located 2 bytes from the start of the register
-   area. */
+/* The rate register is located 2 bytes from the start of the register area. */
 #define NM_RATE_REG_OFFSET 2
 
 /* Mono/stereo flag, number of bits on playback, and rate mask. */
@@ -156,7 +194,7 @@
 #define NM_AUDIO_MUTE_LEFT 0x8000
 #define NM_AUDIO_MUTE_RIGHT 0x0080
 
-/* Recording enable register */
+/* Recording enable register. */
 #define NM_RECORD_ENABLE_REG (NM_RECORD_REG_OFFSET + 0)
 #define NM_RECORD_ENABLE_FLAG 1
 #define NM_RECORD_FREERUN 2
@@ -179,26 +217,25 @@
   if (port < 1 || port > 2 || card == NULL) \
       return -1; \
 \
-  if (port == 1) { \
-        if (offset < card->port1_start || offset >= card->port1_end) { \
-	    printk (KERN_ERR "Bad port request port 1:0x%x\n", offset); \
-            return -1; \
-        } \
-        offset -= card->port1_start; \
-   } else if (offset < 0 || offset > 4096) { \
-        printk (KERN_ERR "Bad port request port 2: 0x%x\n", offset); \
-        return -1; \
-   }
+    if (offset < card->port[port - 1].start_offset \
+	|| offset >= card->port[port - 1].end_offset) { \
+	printk (KERN_ERR "Bad access: port %d, offset 0x%x\n", port, offset); \
+	return -1; \
+    } \
+    offset -= card->port[port - 1].start_offset;
 
 #define DEFwritePortX(X, func) \
 static inline int nm256_writePort##X (struct nm256_info *card,\
-					int port, int offset, int value)\
+				      int port, int offset, int value)\
 {\
     u##X *addr;\
 \
+    if (nm256_debug > 1)\
+        printk (KERN_DEBUG "Writing 0x%x to %d:0x%x\n", value, port, offset);\
+\
     NM_FIX_PORT;\
 \
-    addr = (u##X *)(card->ports[port - 1] + offset);\
+    addr = (u##X *)(card->port[port - 1].ptr + offset);\
     func (value, addr);\
     return 0;\
 }
@@ -207,29 +244,28 @@
 DEFwritePortX (16, writew)
 DEFwritePortX (32, writel)
 
-#define DEFreadPortX(X) \
+#define DEFreadPortX(X, func) \
 static inline u##X nm256_readPort##X (struct nm256_info *card,\
 					int port, int offset)\
 {\
-    u##X *addr, res;\
+    u##X *addr;\
 \
     NM_FIX_PORT\
 \
-    addr = (u##X *)(card->ports[port - 1] + offset);\
-    memcpy_fromio (&res, addr, sizeof (res));\
-    return res;\
+    addr = (u##X *)(card->port[port - 1].ptr + offset);\
+    return func(addr);\
 }
 
-DEFreadPortX (8)
-DEFreadPortX (16)
-DEFreadPortX (32)
+DEFreadPortX (8, readb)
+DEFreadPortX (16, readw)
+DEFreadPortX (32, readl)
 
 static inline int
 nm256_writeBuffer8 (struct nm256_info *card, u8 *src, int port, int offset,
 		      int amt)
 {
     NM_FIX_PORT;
-    memcpy_toio (card->ports[port - 1] + offset, src, amt);
+    memcpy_toio (card->port[port - 1].ptr + offset, src, amt);
     return 0;
 }
 
@@ -238,7 +274,7 @@
 		     int amt)
 {
     NM_FIX_PORT;
-    memcpy_fromio (dst, card->ports[port - 1] + offset, amt);
+    memcpy_fromio (dst, card->port[port - 1].ptr + offset, amt);
     return 0;
 }
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)