Lines Matching defs:opl4

19 static inline void snd_opl4_wait(struct snd_opl4 *opl4)
22 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
26 void snd_opl4_write(struct snd_opl4 *opl4, u8 reg, u8 value)
28 snd_opl4_wait(opl4);
29 outb(reg, opl4->pcm_port);
31 snd_opl4_wait(opl4);
32 outb(value, opl4->pcm_port + 1);
37 u8 snd_opl4_read(struct snd_opl4 *opl4, u8 reg)
39 snd_opl4_wait(opl4);
40 outb(reg, opl4->pcm_port);
42 snd_opl4_wait(opl4);
43 return inb(opl4->pcm_port + 1);
48 void snd_opl4_read_memory(struct snd_opl4 *opl4, char *buf, int offset, int size)
53 spin_lock_irqsave(&opl4->reg_lock, flags);
55 memcfg = snd_opl4_read(opl4, OPL4_REG_MEMORY_CONFIGURATION);
56 snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg | OPL4_MODE_BIT);
58 snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_HIGH, offset >> 16);
59 snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_MID, offset >> 8);
60 snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_LOW, offset);
62 snd_opl4_wait(opl4);
63 outb(OPL4_REG_MEMORY_DATA, opl4->pcm_port);
64 snd_opl4_wait(opl4);
65 insb(opl4->pcm_port + 1, buf, size);
67 snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg);
69 spin_unlock_irqrestore(&opl4->reg_lock, flags);
74 void snd_opl4_write_memory(struct snd_opl4 *opl4, const char *buf, int offset, int size)
79 spin_lock_irqsave(&opl4->reg_lock, flags);
81 memcfg = snd_opl4_read(opl4, OPL4_REG_MEMORY_CONFIGURATION);
82 snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg | OPL4_MODE_BIT);
84 snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_HIGH, offset >> 16);
85 snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_MID, offset >> 8);
86 snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_LOW, offset);
88 snd_opl4_wait(opl4);
89 outb(OPL4_REG_MEMORY_DATA, opl4->pcm_port);
90 snd_opl4_wait(opl4);
91 outsb(opl4->pcm_port + 1, buf, size);
93 snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg);
95 spin_unlock_irqrestore(&opl4->reg_lock, flags);
100 static void snd_opl4_enable_opl4(struct snd_opl4 *opl4)
102 outb(OPL3_REG_MODE, opl4->fm_port + 2);
103 inb(opl4->fm_port);
104 inb(opl4->fm_port);
105 outb(OPL3_OPL3_ENABLE | OPL3_OPL4_ENABLE, opl4->fm_port + 3);
106 inb(opl4->fm_port);
107 inb(opl4->fm_port);
110 static int snd_opl4_detect(struct snd_opl4 *opl4)
114 snd_opl4_enable_opl4(opl4);
116 id1 = snd_opl4_read(opl4, OPL4_REG_MEMORY_CONFIGURATION);
120 opl4->hardware = OPL3_HW_OPL4;
123 opl4->hardware = OPL3_HW_OPL4_ML;
129 snd_opl4_write(opl4, OPL4_REG_MIX_CONTROL_FM, 0x00);
130 snd_opl4_write(opl4, OPL4_REG_MIX_CONTROL_PCM, 0xff);
131 id1 = snd_opl4_read(opl4, OPL4_REG_MIX_CONTROL_FM);
132 id2 = snd_opl4_read(opl4, OPL4_REG_MIX_CONTROL_PCM);
137 snd_opl4_write(opl4, OPL4_REG_MIX_CONTROL_FM, 0x3f);
138 snd_opl4_write(opl4, OPL4_REG_MIX_CONTROL_PCM, 0x3f);
139 snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, 0x00);
146 struct snd_opl4 *opl4 = seq_dev->private_data;
147 opl4->seq_dev = NULL;
150 static int snd_opl4_create_seq_dev(struct snd_opl4 *opl4, int seq_device)
152 opl4->seq_dev_num = seq_device;
153 if (snd_seq_device_new(opl4->card, seq_device, SNDRV_SEQ_DEV_ID_OPL4,
154 sizeof(struct snd_opl4 *), &opl4->seq_dev) >= 0) {
155 strcpy(opl4->seq_dev->name, "OPL4 Wavetable");
156 *(struct snd_opl4 **)SNDRV_SEQ_DEVICE_ARGPTR(opl4->seq_dev) = opl4;
157 opl4->seq_dev->private_data = opl4;
158 opl4->seq_dev->private_free = snd_opl4_seq_dev_free;
164 static void snd_opl4_free(struct snd_opl4 *opl4)
166 snd_opl4_free_proc(opl4);
167 release_and_free_resource(opl4->res_fm_port);
168 release_and_free_resource(opl4->res_pcm_port);
169 kfree(opl4);
174 struct snd_opl4 *opl4 = device->device_data;
175 snd_opl4_free(opl4);
184 struct snd_opl4 *opl4;
196 opl4 = kzalloc(sizeof(*opl4), GFP_KERNEL);
197 if (!opl4)
200 opl4->res_fm_port = request_region(fm_port, 8, "OPL4 FM");
201 opl4->res_pcm_port = request_region(pcm_port, 8, "OPL4 PCM/MIX");
202 if (!opl4->res_fm_port || !opl4->res_pcm_port) {
203 snd_printk(KERN_ERR "opl4: can't grab ports 0x%lx, 0x%lx\n", fm_port, pcm_port);
204 snd_opl4_free(opl4);
208 opl4->card = card;
209 opl4->fm_port = fm_port;
210 opl4->pcm_port = pcm_port;
211 spin_lock_init(&opl4->reg_lock);
212 mutex_init(&opl4->access_mutex);
214 err = snd_opl4_detect(opl4);
216 snd_opl4_free(opl4);
221 err = snd_device_new(card, SNDRV_DEV_CODEC, opl4, &ops);
223 snd_opl4_free(opl4);
227 err = snd_opl3_create(card, fm_port, fm_port + 2, opl4->hardware, 1, &opl3);
229 snd_device_free(card, opl4);
233 /* opl3 initialization disabled opl4, so reenable */
234 snd_opl4_enable_opl4(opl4);
236 snd_opl4_create_mixer(opl4);
237 snd_opl4_create_proc(opl4);
240 opl4->seq_client = -1;
241 if (opl4->hardware < OPL3_HW_OPL4_ML)
242 snd_opl4_create_seq_dev(opl4, seq_device);
248 *ropl4 = opl4;